@khanacademy/perseus-core 41.2.2 → 42.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.
@@ -29,6 +29,22 @@ export type PerseusAnalyticsEvent = {
29
29
  widgetType: string;
30
30
  widgetId: string;
31
31
  };
32
+ } | {
33
+ type: "perseus:widget:unsupported";
34
+ payload: {
35
+ widgetSubType: string;
36
+ widgetType: string;
37
+ widgetId: string;
38
+ /**
39
+ * Additional reason why this widget is not supported. This is
40
+ * primarily becase we've deprecated the widget or it's bad data
41
+ * (an invalid widget type), but in some cases we may mark _some_
42
+ * widget configurations for a supported widget type as not
43
+ * supported without deprecating the entire widget (eg. sorter
44
+ * with too many cards; circa Oct 2026).
45
+ */
46
+ reason: string;
47
+ };
32
48
  } | {
33
49
  type: "perseus:label-image:toggle-answers-hidden";
34
50
  payload: null;
@@ -100,10 +100,10 @@ export type MakeWidgetMap<TRegistry> = {
100
100
  * `@khanacademy/perseus` (for UI support) and `@khanacademy/perseus-score`
101
101
  * (for scoring support)).
102
102
  *
103
- * Importantly, the key should be the name that is used in widget IDs. For most
104
- * widgets that is the same as the widget option's `type` field. In cases where
105
- * a widget has been deprecated and replaced with the deprecated-standin
106
- * widget, it should be the original widget type!
103
+ * TODO(jeremy): Move away from widget IDs that embed the widget type (to GUIDs or something).
104
+ * Today, the key should match the widget's `type` field. Also (sadly) it needs
105
+ * to match the prefix of widget IDs for the widget type also in order to allow
106
+ * us to properly type (and narrow) the PerseusWidgetsMap entries.
107
107
  *
108
108
  * If you define the widget outside of this package, you can still add the new
109
109
  * widget to this interface by writing the following in that package that
@@ -115,17 +115,11 @@ export type MakeWidgetMap<TRegistry> = {
115
115
  * interface PerseusWidgetTypes {
116
116
  * // A new widget
117
117
  * "new-awesomeness": MyAwesomeNewWidget;
118
- *
119
- * // A deprecated widget
120
- * "super-old-widget": DeprecatedStandinWidget;
121
118
  * }
122
119
  * }
123
120
  *
124
121
  * // The new widget's options definition
125
122
  * type MyAwesomeNewWidget = WidgetOptions<'new-awesomeness', MyAwesomeNewWidgetOptions>;
126
- *
127
- * // The deprecated widget's options definition
128
- * type SuperOldWidget = WidgetOptions<'super-old-widget', object>;
129
123
  * ```
130
124
  *
131
125
  * This interface can be extended through the magic of TypeScript "Declaration
@@ -166,14 +160,6 @@ export interface PerseusWidgetTypes {
166
160
  sorter: SorterWidget;
167
161
  table: TableWidget;
168
162
  video: VideoWidget;
169
- "molecule-renderer": DeprecatedStandinWidget<"molecule-renderer">;
170
- "passage-ref-target": DeprecatedStandinWidget<"passage-ref-target">;
171
- "passage-ref": DeprecatedStandinWidget<"passage-ref">;
172
- passage: DeprecatedStandinWidget<"passage">;
173
- "lights-puzzle": DeprecatedStandinWidget<"lights-puzzle">;
174
- sequence: DeprecatedStandinWidget<"sequence">;
175
- simulator: DeprecatedStandinWidget<"simulator">;
176
- transformer: DeprecatedStandinWidget<"transformer">;
177
163
  }
178
164
  /**
179
165
  * A map of widget IDs to widget options. This is most often used as the type
@@ -184,19 +170,17 @@ export interface PerseusWidgetTypes {
184
170
  * reading/parsing the widget id to derive any information from it, except in
185
171
  * the case of this map.
186
172
  *
187
- * @see {@link PerseusWidgetTypes} additional widgets can be added to this map type
188
- * by augmenting the PerseusWidgetTypes with new widget types!
173
+ * @see {@link PerseusWidgetTypes} additional widgets can be added to this map
174
+ * type by augmenting the PerseusWidgetTypes with new widget types!
189
175
  */
190
176
  export type PerseusWidgetsMap = MakeWidgetMap<PerseusWidgetTypes>;
191
177
  /**
192
- * PerseusWidget is a union of all the different types of widget options that
193
- * Perseus knows about.
194
- *
195
- * Thanks to it being based on PerseusWidgetTypes interface, this union is
196
- * automatically extended to include widgets used in tests without those widget
197
- * option types seeping into our production types.
178
+ * {@link PerseusWidget} is a union of all the different types of widget
179
+ * options that Perseus knows about.
198
180
  *
199
- * @see MockWidget for an example
181
+ * Thanks to it being based on the {@link PerseusWidgetTypes} interface, this
182
+ * union is automatically extended to include widgets used in tests without
183
+ * those widget option types seeping into our production types.
200
184
  */
201
185
  export type PerseusWidget = PerseusWidgetTypes[keyof PerseusWidgetTypes];
202
186
  /**
@@ -394,7 +378,6 @@ export type SorterWidget = WidgetOptions<'sorter', PerseusSorterWidgetOptions>;
394
378
  export type TableWidget = WidgetOptions<'table', PerseusTableWidgetOptions>;
395
379
  export type InputNumberWidget = WidgetOptions<'input-number', PerseusInputNumberWidgetOptions>;
396
380
  export type VideoWidget = WidgetOptions<'video', PerseusVideoWidgetOptions>;
397
- export type DeprecatedStandinWidget<Type extends string> = WidgetOptions<Type, object>;
398
381
  /**
399
382
  * A background image applied to various widgets.
400
383
  */
package/dist/index.js CHANGED
@@ -66,7 +66,7 @@ function nullable(parseValue){return (rawValue,ctx)=>{if(rawValue===null){return
66
66
 
67
67
  const number=(rawValue,ctx)=>{if(typeof rawValue==="number"&&Number.isFinite(rawValue)){return ctx.success(rawValue)}return ctx.failure("number",rawValue)};
68
68
 
69
- 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)}}
69
+ function object(schema){return objectParserWithInitializer(()=>({}),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)}}
70
70
 
71
71
  function optional(parseValue){return (rawValue,ctx)=>{if(rawValue===undefined){return ctx.success(rawValue)}return parseValue(rawValue,ctx)}}
72
72
 
@@ -178,7 +178,7 @@ const parseVideoWidget=parseWidget(constant("video"),object({location:string}),{
178
178
 
179
179
  const parseStringToNonNegativeInt=(rawValue,ctx)=>{if(typeof rawValue!=="string"||!/^(0|[1-9][0-9]*)$/.test(rawValue)){return ctx.failure("a string representing a non-negative integer",rawValue)}return ctx.success(+rawValue)};const parseWidgetIdComponents=pair(string,parseStringToNonNegativeInt);
180
180
 
181
- const parseWidgetsMap=(rawValue,ctx)=>{if(!isPlainObject(rawValue)){return ctx.failure("PerseusWidgetsMap",rawValue)}const widgetsMap={};for(const key of Object.keys(rawValue)){const entryResult=parseWidgetsMapEntry([key,rawValue[key]],widgetsMap,ctx.forSubtree(key));if(isFailure(entryResult)){return entryResult}}return ctx.success(widgetsMap)};const parseWidgetsMapEntry=([id,widget],widgetMap,ctx)=>{const idComponentsResult=parseWidgetIdComponents(id.split(" "),ctx.forSubtree("(widget ID)"));if(isFailure(idComponentsResult)){return idComponentsResult}const[type,n]=idComponentsResult.value;function parseAndAssign(key,parse){const widgetResult=parse(widget,ctx);if(isFailure(widgetResult)){return widgetResult}widgetMap[key]=widgetResult.value;return ctx.success(undefined)}switch(type){case "blank":return parseAndAssign(`blank ${n}`,parseBlankWidget);case "categorizer":return parseAndAssign(`categorizer ${n}`,parseCategorizerWidget);case "cs-program":return parseAndAssign(`cs-program ${n}`,parseCSProgramWidget);case "definition":return parseAndAssign(`definition ${n}`,parseDefinitionWidget);case "dropdown":return parseAndAssign(`dropdown ${n}`,parseDropdownWidget);case "explanation":return parseAndAssign(`explanation ${n}`,parseExplanationWidget);case "expression":return parseAndAssign(`expression ${n}`,parseExpressionWidget);case "fill-in-the-blank":return parseAndAssign(`fill-in-the-blank ${n}`,parseFillInTheBlankWidget);case "free-response":return parseAndAssign(`free-response ${n}`,parseFreeResponseWidget);case "grapher":return parseAndAssign(`grapher ${n}`,parseGrapherWidget);case "group":return parseAndAssign(`group ${n}`,parseGroupWidget);case "graded-group":return parseAndAssign(`graded-group ${n}`,parseGradedGroupWidget);case "graded-group-set":return parseAndAssign(`graded-group-set ${n}`,parseGradedGroupSetWidget);case "iframe":return parseAndAssign(`iframe ${n}`,parseIframeWidget);case "image":return parseAndAssign(`image ${n}`,parseImageWidget);case "input-number":return parseAndAssign(`input-number ${n}`,parseInputNumberWidget);case "interaction":return parseAndAssign(`interaction ${n}`,parseInteractionWidget);case "interactive-graph":return parseAndAssign(`interactive-graph ${n}`,parseInteractiveGraphWidget);case "label-image":return parseAndAssign(`label-image ${n}`,parseLabelImageWidget);case "matcher":return parseAndAssign(`matcher ${n}`,parseMatcherWidget);case "matrix":return parseAndAssign(`matrix ${n}`,parseMatrixWidget);case "measurer":return parseAndAssign(`measurer ${n}`,parseMeasurerWidget);case "molecule-renderer":return parseAndAssign(`molecule-renderer ${n}`,parseDeprecatedWidget("molecule-renderer"));case "number-line":return parseAndAssign(`number-line ${n}`,parseNumberLineWidget);case "numeric-input":return parseAndAssign(`numeric-input ${n}`,parseNumericInputWidget);case "orderer":return parseAndAssign(`orderer ${n}`,parseOrdererWidget);case "phet-simulation":return parseAndAssign(`phet-simulation ${n}`,parsePhetSimulationWidget);case "plotter":return parseAndAssign(`plotter ${n}`,parsePlotterWidget);case "python-program":return parseAndAssign(`python-program ${n}`,parsePythonProgramWidget);case "radio":return parseAndAssign(`radio ${n}`,parseRadioWidget);case "sorter":return parseAndAssign(`sorter ${n}`,parseSorterWidget);case "table":return parseAndAssign(`table ${n}`,parseTableWidget);case "video":return parseAndAssign(`video ${n}`,parseVideoWidget);case "sequence":return parseAndAssign(`sequence ${n}`,parseDeprecatedWidget("sequence"));case "lights-puzzle":return parseAndAssign(`lights-puzzle ${n}`,parseDeprecatedWidget("lights-puzzle"));case "simulator":return parseAndAssign(`simulator ${n}`,parseDeprecatedWidget("simulator"));case "transformer":return parseAndAssign(`transformer ${n}`,parseDeprecatedWidget("transformer"));case "passage":return parseAndAssign(`passage ${n}`,parseDeprecatedWidget("passage"));case "passage-ref":return parseAndAssign(`passage-ref ${n}`,parseDeprecatedWidget("passage-ref"));case "passage-ref-target":return parseAndAssign(`passage-ref-target ${n}`,parseDeprecatedWidget("passage-ref-target"));default:return parseAndAssign(`${type} ${n}`,parseWidget(constant(type),any))}};function parseDeprecatedWidget(type){return parseWidget(constant(type),looseObject({}))}
181
+ const parseWidgetsMap=(rawValue,ctx)=>{if(!isPlainObject(rawValue)){return ctx.failure("PerseusWidgetsMap",rawValue)}const widgetsMap={};for(const key of Object.keys(rawValue)){const entryResult=parseWidgetsMapEntry([key,rawValue[key]],widgetsMap,ctx.forSubtree(key));if(isFailure(entryResult)){return entryResult}}return ctx.success(widgetsMap)};const parseWidgetsMapEntry=([id,widget],widgetMap,ctx)=>{const idComponentsResult=parseWidgetIdComponents(id.split(" "),ctx.forSubtree("(widget ID)"));if(isFailure(idComponentsResult)){return idComponentsResult}const[type,n]=idComponentsResult.value;function parseAndAssign(key,parse){const widgetResult=parse(widget,ctx);if(isFailure(widgetResult)){return widgetResult}widgetMap[key]=widgetResult.value;return ctx.success(undefined)}switch(type){case "blank":return parseAndAssign(`blank ${n}`,parseBlankWidget);case "categorizer":return parseAndAssign(`categorizer ${n}`,parseCategorizerWidget);case "cs-program":return parseAndAssign(`cs-program ${n}`,parseCSProgramWidget);case "definition":return parseAndAssign(`definition ${n}`,parseDefinitionWidget);case "dropdown":return parseAndAssign(`dropdown ${n}`,parseDropdownWidget);case "explanation":return parseAndAssign(`explanation ${n}`,parseExplanationWidget);case "expression":return parseAndAssign(`expression ${n}`,parseExpressionWidget);case "fill-in-the-blank":return parseAndAssign(`fill-in-the-blank ${n}`,parseFillInTheBlankWidget);case "free-response":return parseAndAssign(`free-response ${n}`,parseFreeResponseWidget);case "grapher":return parseAndAssign(`grapher ${n}`,parseGrapherWidget);case "group":return parseAndAssign(`group ${n}`,parseGroupWidget);case "graded-group":return parseAndAssign(`graded-group ${n}`,parseGradedGroupWidget);case "graded-group-set":return parseAndAssign(`graded-group-set ${n}`,parseGradedGroupSetWidget);case "iframe":return parseAndAssign(`iframe ${n}`,parseIframeWidget);case "image":return parseAndAssign(`image ${n}`,parseImageWidget);case "input-number":return parseAndAssign(`input-number ${n}`,parseInputNumberWidget);case "interaction":return parseAndAssign(`interaction ${n}`,parseInteractionWidget);case "interactive-graph":return parseAndAssign(`interactive-graph ${n}`,parseInteractiveGraphWidget);case "label-image":return parseAndAssign(`label-image ${n}`,parseLabelImageWidget);case "matcher":return parseAndAssign(`matcher ${n}`,parseMatcherWidget);case "matrix":return parseAndAssign(`matrix ${n}`,parseMatrixWidget);case "measurer":return parseAndAssign(`measurer ${n}`,parseMeasurerWidget);case "number-line":return parseAndAssign(`number-line ${n}`,parseNumberLineWidget);case "numeric-input":return parseAndAssign(`numeric-input ${n}`,parseNumericInputWidget);case "orderer":return parseAndAssign(`orderer ${n}`,parseOrdererWidget);case "phet-simulation":return parseAndAssign(`phet-simulation ${n}`,parsePhetSimulationWidget);case "plotter":return parseAndAssign(`plotter ${n}`,parsePlotterWidget);case "python-program":return parseAndAssign(`python-program ${n}`,parsePythonProgramWidget);case "radio":return parseAndAssign(`radio ${n}`,parseRadioWidget);case "sorter":return parseAndAssign(`sorter ${n}`,parseSorterWidget);case "table":return parseAndAssign(`table ${n}`,parseTableWidget);case "video":return parseAndAssign(`video ${n}`,parseVideoWidget);default:return parseAndAssign(`${type} ${n}`,parseWidget(constant(type),any))}};
182
182
 
183
183
  const parsePerseusRenderer=defaulted(object({content:defaulted(string,()=>""),widgets:defaulted((rawVal,ctx)=>parseWidgetsMap(rawVal,ctx),()=>({})),images:parseImages,metadata:any}),()=>({content:"",widgets:{},images:{}}));
184
184
 
@@ -232,7 +232,7 @@ const parseUserInputMap=(rawValue,ctx)=>{if(!isPlainObject(rawValue)){return ctx
232
232
 
233
233
  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}
234
234
 
235
- const libName="@khanacademy/perseus-core";const libVersion="41.2.2";addLibraryVersionToPerseusDebug(libName,libVersion);
235
+ const libName="@khanacademy/perseus-core";const libVersion="42.0.0";addLibraryVersionToPerseusDebug(libName,libVersion);
236
236
 
237
237
  const Errors=Object.freeze({Unknown:"Unknown",Internal:"Internal",InvalidInput:"InvalidInput",NotAllowed:"NotAllowed",TransientService:"TransientService",Service:"Service"});
238
238
 
@@ -268,8 +268,6 @@ const currentVersion$1={major:2,minor:0};const defaultWidgetOptions$p={answerFor
268
268
 
269
269
  class Registry{throwIfUnregistered(){if(!this.anythingRegistered){throw new Error(`${this.name} accessed before initialization!`)}}has(key){this.throwIfUnregistered();return Object.prototype.hasOwnProperty.call(this.contents,key)}get(key){this.throwIfUnregistered();return this.contents[key]}keys(){this.throwIfUnregistered();return Object.keys(this.contents)}entries(){this.throwIfUnregistered();return Object.entries(this.contents)}set(key,value){this.anythingRegistered=true;this.contents[key]=value;}constructor(name="Registry"){this.contents={};this.anythingRegistered=false;this.name=name;}}
270
270
 
271
- const deprecatedStandinWidgetLogic={name:"deprecated-standin",defaultWidgetOptions:{},accessible:true};
272
-
273
271
  const defaultWidgetOptions$o={title:"",content:"",widgets:{},images:{},hint:null};const traverseChildWidgets$3=function(props,traverseRenderer){return {...props,...traverseRenderer(props)}};const gradedGroupWidgetLogic={name:"graded-group",defaultWidgetOptions: defaultWidgetOptions$o,accessible:true,traverseChildWidgets:traverseChildWidgets$3};
274
272
 
275
273
  const defaultWidgetOptions$n={gradedGroups:[]};const traverseChildWidgets$2=function(props,traverseRenderer){return {...props,...traverseRenderer(props)}};const gradedGroupSetWidgetLogic={name:"graded-group-set",defaultWidgetOptions: defaultWidgetOptions$n,accessible:true,traverseChildWidgets:traverseChildWidgets$2};
@@ -352,7 +350,7 @@ const defaultRows=4;const defaultColumns=1;const answers=new Array(defaultRows).
352
350
 
353
351
  const defaultWidgetOptions$2={location:""};const videoWidgetLogic={name:"video",defaultWidgetOptions: defaultWidgetOptions$2,supportedAlignments:["block","full-width"],defaultAlignment:"block",accessible:true};
354
352
 
355
- const widgets=new Registry("Core widget registry");function registerWidget(type,logic){widgets.set(type,logic);}function isWidgetRegistered(type){const widgetLogic=widgets.get(type);return Boolean(widgetLogic)}function getCurrentVersion(type){const widgetLogic=widgets.get(type);return widgetLogic?.version||{major:0,minor:0}}const getPublicWidgetOptionsFunction=type=>{return widgets.get(type)?.getPublicWidgetOptions??(i=>i)};function getDefaultWidgetOptions(type){const widgetLogic=widgets.get(type);return widgetLogic?.defaultWidgetOptions||{}}function isAccessible(type,widgetOptions){const accessible=widgets.get(type)?.accessible;return typeof accessible==="function"?accessible(widgetOptions):!!accessible}const traverseChildWidgets=(widgetInfo,traverseRenderer)=>{if(!traverseRenderer){throw new PerseusError("traverseRenderer must be provided, but was not",Errors.Internal)}if(!widgetInfo||!widgetInfo.type||!widgets.get(widgetInfo.type)){return widgetInfo}const widgetExports=widgets.get(widgetInfo.type);const props=widgetInfo.options;if(widgetExports?.traverseChildWidgets!=null&&props!=null){const newProps=widgetExports.traverseChildWidgets(props,traverseRenderer);return {...widgetInfo,options:newProps}}return widgetInfo};const getSupportedAlignments=type=>{const widgetLogic=widgets.get(type);if(!widgetLogic?.supportedAlignments?.[0]){return ["default"]}return widgetLogic?.supportedAlignments};const getDefaultAlignment=type=>{const widgetLogic=widgets.get(type);if(!widgetLogic?.defaultAlignment){return "block"}return widgetLogic.defaultAlignment};const isInlineWidget=(type,alignment)=>{if(alignment==null||alignment==="default"){alignment=getDefaultAlignment(type);}return alignment.startsWith("inline")};const getAlignmentClassName=(type,alignment)=>{switch(alignment){case "block":return " widget-block";case "inline-block":return " widget-inline-block";case "inline":return " widget-inline";case "wrap-left":return " widget-wrap-left";case "wrap-right":return " widget-wrap-right";case "full-width":return " widget-full-width";case "default":return getDefaultAlignment(type);default:return ""}};function registerCoreWidgets(){const widgets=[blankWidgetLogic,categorizerWidgetLogic,csProgramWidgetLogic,definitionWidgetLogic,deprecatedStandinWidgetLogic,dropdownWidgetLogic,explanationWidgetLogic,expressionWidgetLogic,fillInTheBlankWidgetLogic,gradedGroupWidgetLogic,gradedGroupSetWidgetLogic,grapherWidgetLogic,groupWidgetLogic,iframeWidgetLogic,imageWidgetLogic,inputNumberWidgetLogic,interactionWidgetLogic,interactiveGraphWidgetLogic,labelImageWidgetLogic,matcherWidgetLogic,matrixWidgetLogic,measurerWidgetLogic,numberLineWidgetLogic,numericInputWidgetLogic,ordererWidgetLogic,phetSimulationWidgetLogic,plotterWidgetLogic,pythonProgramWidgetLogic,radioWidgetLogic,sorterWidgetLogic,tableWidgetLogic,videoWidgetLogic];widgets.forEach(w=>{registerWidget(w.name,w);});}
353
+ const widgets=new Registry("Core widget registry");function registerWidget(type,logic){widgets.set(type,logic);}function isWidgetRegistered(type){const widgetLogic=widgets.get(type);return Boolean(widgetLogic)}function getCurrentVersion(type){const widgetLogic=widgets.get(type);return widgetLogic?.version||{major:0,minor:0}}const getPublicWidgetOptionsFunction=type=>{return widgets.get(type)?.getPublicWidgetOptions??(i=>i)};function getDefaultWidgetOptions(type){const widgetLogic=widgets.get(type);return widgetLogic?.defaultWidgetOptions||{}}function isAccessible(type,widgetOptions){const accessible=widgets.get(type)?.accessible;return typeof accessible==="function"?accessible(widgetOptions):!!accessible}const traverseChildWidgets=(widgetInfo,traverseRenderer)=>{if(!traverseRenderer){throw new PerseusError("traverseRenderer must be provided, but was not",Errors.Internal)}if(!widgetInfo||!widgetInfo.type||!widgets.get(widgetInfo.type)){return widgetInfo}const widgetExports=widgets.get(widgetInfo.type);const props=widgetInfo.options;if(widgetExports?.traverseChildWidgets!=null&&props!=null){const newProps=widgetExports.traverseChildWidgets(props,traverseRenderer);return {...widgetInfo,options:newProps}}return widgetInfo};const getSupportedAlignments=type=>{const widgetLogic=widgets.get(type);if(!widgetLogic?.supportedAlignments?.[0]){return ["default"]}return widgetLogic?.supportedAlignments};const getDefaultAlignment=type=>{const widgetLogic=widgets.get(type);if(!widgetLogic?.defaultAlignment){return "block"}return widgetLogic.defaultAlignment};const isInlineWidget=(type,alignment)=>{if(alignment==null||alignment==="default"){alignment=getDefaultAlignment(type);}return alignment.startsWith("inline")};const getAlignmentClassName=(type,alignment)=>{switch(alignment){case "block":return " widget-block";case "inline-block":return " widget-inline-block";case "inline":return " widget-inline";case "wrap-left":return " widget-wrap-left";case "wrap-right":return " widget-wrap-right";case "full-width":return " widget-full-width";case "default":return getDefaultAlignment(type);default:return ""}};function registerCoreWidgets(){const widgets=[blankWidgetLogic,categorizerWidgetLogic,csProgramWidgetLogic,definitionWidgetLogic,dropdownWidgetLogic,explanationWidgetLogic,expressionWidgetLogic,fillInTheBlankWidgetLogic,gradedGroupWidgetLogic,gradedGroupSetWidgetLogic,grapherWidgetLogic,groupWidgetLogic,iframeWidgetLogic,imageWidgetLogic,inputNumberWidgetLogic,interactionWidgetLogic,interactiveGraphWidgetLogic,labelImageWidgetLogic,matcherWidgetLogic,matrixWidgetLogic,measurerWidgetLogic,numberLineWidgetLogic,numericInputWidgetLogic,ordererWidgetLogic,phetSimulationWidgetLogic,plotterWidgetLogic,pythonProgramWidgetLogic,radioWidgetLogic,sorterWidgetLogic,tableWidgetLogic,videoWidgetLogic];widgets.forEach(w=>{registerWidget(w.name,w);});}
356
354
 
357
355
  var coreWidgetRegistry = /*#__PURE__*/Object.freeze({
358
356
  __proto__: null,