@khanacademy/perseus-core 27.0.2 → 27.1.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/es/index.js
CHANGED
|
@@ -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="27.0
|
|
231
|
+
const libName="@khanacademy/perseus-core";const libVersion="27.1.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
|
|
|
@@ -286,9 +286,11 @@ const defaultWidgetOptions$g={graph:{box:[400,400],labels:["x","y"],range:[[-10,
|
|
|
286
286
|
|
|
287
287
|
const svgLabelsRegex=/^web\+graphie:/;const svgLocalLabelsRegex=/^file\+graphie:/;function getRealImageUrl(graphieUrl){if(isLabeledSVG(graphieUrl)){return getSvgUrl(graphieUrl)}return graphieUrl}function isLabeledSVG(graphieUrl){return svgLabelsRegex.test(graphieUrl)||svgLocalLabelsRegex.test(graphieUrl)}function getBaseUrl(graphieUrl){return graphieUrl.replace(svgLabelsRegex,"https:").replace(svgLocalLabelsRegex,"file:")}function getSvgUrl(graphieUrl){return getBaseUrl(graphieUrl)+".svg"}function getDataUrl(graphieUrl){return getBaseUrl(graphieUrl)+"-data.json"}async function getImageSizeModern(url){const image=new Image;return new Promise((resolve,reject)=>{image.onload=()=>{resolve([image.naturalWidth,image.naturalHeight]);};image.onerror=reject;image.src=getRealImageUrl(url);})}
|
|
288
288
|
|
|
289
|
+
function accessible(widgetOptions){if(widgetOptions.showProtractor){return false}if(widgetOptions.backgroundImage?.url&&isLabeledSVG(widgetOptions.backgroundImage?.url)){return false}if(widgetOptions.lockedFigures.length>0&&!widgetOptions.fullGraphAriaDescription){return false}return true}
|
|
290
|
+
|
|
289
291
|
function getInteractiveGraphPublicWidgetOptions(options){const{correct:_,...publicOptions}=options;return publicOptions}
|
|
290
292
|
|
|
291
|
-
const defaultWidgetOptions$f={labels:["$x$","$y$"],labelLocation:"onAxis",lockedFigures:[],range:[[-10,10],[-10,10]],step:[1,1],backgroundImage:{url:null},markings:"graph",showAxisArrows:{xMin:true,xMax:true,yMin:true,yMax:true},showAxisTicks:{x:true,y:true},showTooltips:false,showProtractor:false,graph:{type:"linear"},correct:{type:"linear",coords:null}};const interactiveGraphWidgetLogic={name:"interactive-graph",defaultWidgetOptions: defaultWidgetOptions$f,getPublicWidgetOptions:getInteractiveGraphPublicWidgetOptions,accessible
|
|
293
|
+
const defaultWidgetOptions$f={labels:["$x$","$y$"],labelLocation:"onAxis",lockedFigures:[],range:[[-10,10],[-10,10]],step:[1,1],backgroundImage:{url:null},markings:"graph",showAxisArrows:{xMin:true,xMax:true,yMin:true,yMax:true},showAxisTicks:{x:true,y:true},showTooltips:false,showProtractor:false,graph:{type:"linear"},correct:{type:"linear",coords:null}};const interactiveGraphWidgetLogic={name:"interactive-graph",defaultWidgetOptions: defaultWidgetOptions$f,getPublicWidgetOptions:getInteractiveGraphPublicWidgetOptions,accessible};
|
|
292
294
|
|
|
293
295
|
function getLabelImagePublicWidgetOptions(options){return {...options,markers:options.markers.map(getLabelImageMarkerPublicData)}}function getLabelImageMarkerPublicData(marker){const{answers:_,...publicData}=marker;return publicData}function isLabelImageAccessible(options){const labelImageOptions=options;if(labelImageOptions.imageUrl!==""&&labelImageOptions.imageAlt===""){return false}for(const marker of labelImageOptions.markers){if(marker.label===""){return false}}return true}
|
|
294
296
|
|
|
@@ -373,7 +375,7 @@ const DEFAULT_COLOR="grayH";function getDefaultFigureForType(type){switch(type){
|
|
|
373
375
|
|
|
374
376
|
function splitPerseusItem(original){const item=deepClone(original);return {...item,question:splitPerseusRenderer(item.question),hints:original.hints.map(()=>({content:"",widgets:{},images:{},placeholder:true}))}}function splitPerseusItemJSON(data){const parseResult=parseAndMigratePerseusItem(data);if(isFailure(parseResult)){throw new SyntaxError(parseResult.detail.message)}const item=parseResult.value;return JSON.stringify(splitPerseusItem(item))}
|
|
375
377
|
|
|
376
|
-
const PerseusFeatureFlags=["image-widget-upgrade-gif-controls","
|
|
378
|
+
const PerseusFeatureFlags=["image-widget-upgrade-gif-controls","input-number-to-numeric-input"];function isFeatureOn(props,flag){return props.apiOptions?.flags?.[flag]??false}
|
|
377
379
|
|
|
378
380
|
const noop=function(){};const deepCallbackFor=function(contentCallback,widgetCallback,optionsCallback){const deepCallback=function(widgetInfo,widgetId){const newWidgetInfo=traverseChildWidgets$1(widgetInfo,rendererOptions=>{return traverseRenderer(rendererOptions,contentCallback,deepCallback,optionsCallback)});const userWidgetInfo=widgetCallback(newWidgetInfo,widgetId);if(userWidgetInfo!==undefined){return userWidgetInfo}return newWidgetInfo};return deepCallback};const traverseRenderer=function(rendererOptions,contentCallback,deepWidgetCallback,optionsCallback){let newContent=rendererOptions.content;if(rendererOptions.content!=null){const modifiedContent=contentCallback(rendererOptions.content);if(modifiedContent!==undefined){newContent=modifiedContent;}}const newWidgets=mapObject(rendererOptions.widgets||{},function(widgetInfo,widgetId){if(widgetInfo==null||widgetInfo.type==null){return widgetInfo}return deepWidgetCallback(widgetInfo,widgetId)});const newOptions=_.extend({},rendererOptions,{content:newContent,widgets:newWidgets});const userOptions=optionsCallback(newOptions);if(userOptions!==undefined){return userOptions}return newOptions};const traverse=function(rendererOptions,contentCallback,widgetCallback,optionsCallback){contentCallback=contentCallback||noop;widgetCallback=widgetCallback||noop;optionsCallback=optionsCallback||noop;return traverseRenderer(rendererOptions,contentCallback,deepCallbackFor(contentCallback,widgetCallback,optionsCallback),optionsCallback)};
|
|
379
381
|
|