maidr 3.37.0 → 3.37.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/maidr.js +1 -1
- package/dist/maidr.js.map +1 -1
- package/package.json +1 -1
package/dist/maidr.js
CHANGED
|
@@ -890,5 +890,5 @@ ${e}`}function KT(e){return Sse.replace("{maidrJson}",e.maidrJson).replace("{cur
|
|
|
890
890
|
|
|
891
891
|
${KT(h)}`}]}]})}formatResponse(n){return n.content.length===0?{success:!1,error:"Invalid response format"}:{success:!0,data:n.content[0].text}}getHeaders(n){const a=super.getHeaders(n);return a["anthropic-version"]=this.version,a}}class Rse extends ZT{constructor(n,a,o,s){super(n,a,o);F(this,"version");this.version=s}getApiUrl(n){if(!n)throw new Error("API key is required for Gemini API");return`https://generativelanguage.googleapis.com/v1beta/models/${this.version}:generateContent?key=${n}`}getEndPoint(){return"gemini"}getPayload(n,a,o,s,f,d){const h={maidrJson:a,currentPositionText:s,message:f,expertiseLevel:d},y=QT(n,h.expertiseLevel),S=KT(h),E=`${y}
|
|
892
892
|
|
|
893
|
-
${S}`;return JSON.stringify({generationConfig:{maxOutputTokens:Ase},safetySettings:[],contents:[{role:"user",parts:[{text:E},{inlineData:{data:o.split(",")[1],mimeType:"image/svg+xml"}}]}]})}formatResponse(n){return n.candidates.length===0?{success:!1,error:"Invalid response format"}:{success:!0,data:n.candidates[0].content.parts[0].text}}getHeaders(n){const a=super.getHeaders(n);return delete a.Authorization,a}}class _se{constructor(t,n){F(this,"commandFactory");F(this,"currentScope");F(this,"context");this.commandFactory=new EA(t),this.currentScope=n,this.context=t}getContext(){return this.context}executeCommand(t){const n=R7[this.currentScope];if(!n||!(t in n)){console.warn(`Command ${t} is not available in scope ${this.currentScope}`);return}try{this.commandFactory.create(t).execute()}catch(a){console.error(`Failed to execute command ${t}:`,a)}}setScope(t){this.currentScope=t}getCurrentScope(){return this.currentScope}}class kse{constructor(t,n){F(this,"context");F(this,"display");this.context=t,this.display=n}toggle(){this.context.scope!==cn.COMMAND_PALETTE&&this.display.toggleFocus(cn.COMMAND_PALETTE)}returnToTraceScope(){this.context.scope!==cn.TRACE&&this.display.toggleFocus(cn.COMMAND_PALETTE)}}function Dse(e){return e!==null&&typeof e=="object"&&"ensureInitialized"in e&&typeof e.ensureInitialized=="function"}class Nse{constructor(t,n,a){F(this,"context");F(this,"focusStack");F(this,"plot");F(this,"onChangeEmitter");F(this,"onChange");F(this,"hasEnteredInteractive",!1);F(this,"textService");F(this,"isReturningFromModeToggle",!1);F(this,"textChangeDisposer",null);F(this,"hasClearedOnFirstNav",!1);this.context=t,this.focusStack=new HT,this.focusStack.push(this.context.scope),this.plot=n,this.textService=a,this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event,this.removeInstruction(),this.textChangeDisposer=this.textService.onChange(()=>{this.hasClearedOnFirstNav||(this.plot.removeAttribute(ge.ARIA_LABEL),this.hasClearedOnFirstNav=!0)})}dispose(){var t;this.addInstruction(),(t=this.textChangeDisposer)==null||t.dispose(),this.textChangeDisposer=null,this.onChangeEmitter.dispose()}getInstruction(t=!0){return this.context.getInstruction(t)}addInstruction(){this.plot.setAttribute(ge.ARIA_LABEL,this.getInstruction()),this.plot.setAttribute(ge.TITLE,this.getInstruction()),this.plot.setAttribute(ge.ROLE,ge.IMAGE),this.plot.tabIndex=0}removeInstruction(){const t=this.hasEnteredInteractive?"":this.getInstruction(!1);t?(this.plot.setAttribute(ge.ARIA_LABEL,t),this.plot.removeAttribute(ge.TITLE),this.plot.setAttribute(ge.ROLE,ge.APPLICATION),this.plot.tabIndex=0):(this.plot.removeAttribute(ge.ARIA_LABEL),this.plot.removeAttribute(ge.TITLE),this.plot.setAttribute(ge.ROLE,ge.APPLICATION),this.plot.tabIndex=0)}getTraceAriaLabel(){const t=this.textService.format(this.context.state);return t&&t.trim().length>0?t:this.getInstruction(!1)}toggleFocus(t){this.isReturningFromModeToggle=t==="BRAILLE"||t==="REVIEW"||t==="GO_TO_EXTREMA"||t==="COMMAND_PALETTE"||t==="ROTOR"||t==="SETTINGS"||t==="CHAT"||t==="HELP",this.isReturningFromModeToggle&&this.plot.removeAttribute(ge.ARIA_LABEL),this.focusStack.removeLast(t)||this.focusStack.push(t);const n=this.focusStack.peek();this.context.toggleScope(n),this.updateFocus(n)}updateFocus(t){t==="TRACE"||t==="SUBPLOT"?(this.plot.tabIndex=0,setTimeout(()=>{if(this.isReturningFromModeToggle)this.isReturningFromModeToggle=!1,this.plot.removeAttribute(ge.ARIA_LABEL);else{const n=this.context.active;n&&Dse(n)&&n.ensureInitialized(),this.hasEnteredInteractive||this.plot.removeAttribute(ge.ARIA_LABEL)}this.plot.setAttribute(ge.ROLE,ge.APPLICATION),this.plot.focus(),this.hasEnteredInteractive||(this.hasEnteredInteractive=!0),this.onChangeEmitter.fire({value:t})},0)):this.onChangeEmitter.fire({value:t})}}class zse{constructor(t,n){F(this,"context");F(this,"display");this.context=t,this.display=n}toggle(t){if(t.empty)return;const n=this.context.active;n&&this.isExtremaNavigable(n)&&this.context.scope!==cn.GO_TO_EXTREMA&&this.display.toggleFocus(cn.GO_TO_EXTREMA)}isExtremaNavigable(t){return t instanceof Zl&&t.supportsExtremaNavigation()}returnToTraceScope(){this.context.scope!==cn.TRACE&&this.display.toggleFocus(cn.GO_TO_EXTREMA)}}const JT=[{description:"Navigate Data Points",key:"arrow keys"},{description:"Move to Next Layer",key:"page up"},{description:"Move to Previous Layer",key:"page down"},{description:"Go to Left/Right/Top/Bottom Extreme Point",key:`${$t.ctrl} + arrow keys`},{description:"Toggle Braille Mode",key:"b"},{description:"Toggle Text Mode",key:"t"},{description:"Toggle Sonification Mode",key:"s"},{description:"Toggle Review Mode",key:"r"},{description:"Autoplay Outward",key:`${$t.ctrl} + shift + arrow keys`},{description:"Stop Autoplay",key:`${$t.ctrl}`},{description:"Speed Up Autoplay",key:". (period)"},{description:"Speed Down Autoplay",key:", (comma)"},{description:"Reset Autoplay Speed",key:"/ (slash)"},{description:"Replay Current Point",key:"space"},{description:"Announce Plot Title",key:"l t"},{description:"Announce X Label",key:"l x"},{description:"Announce Y Label",key:"l y"},{description:"Announce Fill (Z) Label",key:"l f"},{description:"Open Settings",key:`${$t.ctrl} + ,`},{description:"Open Chat",key:"?"},{description:"Move to next navigation mode in Rotor",key:`${$t.alt}+shift+up`},{description:"Move to previous navigation mode in Rotor",key:`${$t.alt}+shift+down`}],az=[{description:"Move around Subplot",key:"arrow keys"},{description:"Activate Current Subplot",key:`${$t.enter}`},{description:"Announce Plot Title",key:"l t"},{description:"Announce Subtitle",key:"l s"},{description:"Announce Caption",key:"l c"},{description:"Open Settings",key:`${$t.ctrl} + ,`}];class Lse{constructor(t,n){F(this,"context");F(this,"display");F(this,"scopedMenuItems");this.context=t,this.display=n,this.scopedMenuItems={[cn.TRACE]:JT,[cn.TRACE_LABEL]:JT,[cn.BRAILLE]:JT,[cn.SUBPLOT]:az,[cn.FIGURE_LABEL]:az}}getMenuItems(){return this.scopedMenuItems[this.context.scope]??[]}toggle(){this.display.toggleFocus(cn.HELP)}}class Ise{constructor(t){F(this,"highlightedElements");F(this,"highlightedSubplots");F(this,"currentHighlightColor");this.highlightedElements=new Map,this.highlightedSubplots=new Set;const n=t.loadSettings();this.currentHighlightColor=n.general.highlightColor}dispose(){this.unhighlightAll()}isSettings(t){return"general"in t}createHighlightElement(t){if(!(t instanceof SVGElement))throw new TypeError("Invalid element provided for highlight creation");const n=Jt.createHighlightElement(t,this.currentHighlightColor);return n.id=`${ge.MAIDR_HIGHLIGHT}-${Date.now()}-${Math.random()}`,n}handleSettingsUpdate(t){this.currentHighlightColor=t.general.highlightColor}handleStateUpdate(t){t.empty||(this.unhighlightTraceElements(),t.type==="figure"?this.handleFigureState(t):t.type==="subplot"?this.handleSubplotState(t):this.handleTraceState(t))}handleFigureState(t){t.empty||this.processHighlighting(t.highlight)}handleSubplotState(t){t.empty||this.processHighlighting(t.highlight)}handleTraceState(t){if(t.empty||t.highlight.empty)return;const n=this.getElementsFromHighlight(t.highlight);this.highlightTraceElements(n)}processHighlighting(t){if(t.empty)return;const n=this.getElementsFromHighlight(t);this.isMultiPlotScenario()?this.highlightSubplotElements(n):this.unhighlightSubplotElements()}getElementsFromHighlight(t){return t.empty?[]:Array.isArray(t.elements)?t.elements:[t.elements]}isMultiPlotScenario(){return document.querySelectorAll('g[id^="axes_"]').length>1}highlightTraceElements(t){for(const n of t)try{const a=this.createHighlightElement(n);this.highlightedElements.set(n,a)}catch(a){console.error("Failed to highlight element:",a)}}highlightSubplotElements(t){var o;this.unhighlightSubplotElements();const n=(o=document.querySelector('g[id^="maidr-"] > path[style*="fill"]'))==null?void 0:o.parentElement,a=(n==null?void 0:n.querySelector('path[style*="fill"]'))||void 0;for(const s of t)Jt.setSubplotHighlightSvgWithAdaptiveColor(s,this.currentHighlightColor,a),this.highlightedSubplots.add(s)}update(t){try{this.isSettings(t)?this.handleSettingsUpdate(t):this.handleStateUpdate(t)}catch(n){console.error("Failed to update highlight service:",n)}}highlight(t){if(!(t instanceof SVGElement)){console.warn("Invalid element provided to highlight method");return}try{this.unhighlight(t);const n=this.createHighlightElement(t);this.highlightedElements.set(t,n)}catch(n){console.error("Failed to highlight element:",n)}}unhighlight(t){if(!(t instanceof SVGElement))return;const n=this.highlightedElements.get(t);if(n)try{n.remove(),this.highlightedElements.delete(t)}catch(a){console.error("Failed to unhighlight element:",a)}}clear(){try{this.highlightedElements.forEach(t=>{t.remove()}),this.highlightedElements.clear(),this.unhighlightSubplotElements()}catch(t){console.error("Failed to clear highlights:",t)}}unhighlightTraceElements(){this.highlightedElements.forEach(t=>{t.remove()}),this.highlightedElements.clear()}unhighlightSubplotElements(){this.highlightedSubplots.forEach(t=>{Jt.removeSubplotHighlightSvg(t)}),this.highlightedSubplots.clear()}unhighlightAll(){this.unhighlightTraceElements(),this.unhighlightSubplotElements()}}class Bse{constructor(){F(this,"onChangeEmitter");F(this,"onChange");this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose()}notify(t){t&&this.onChangeEmitter.fire({value:t})}}class Vse{constructor(t,n,a){F(this,"notification");F(this,"display");F(this,"text");F(this,"enabled");F(this,"onChangeEmitter");F(this,"onChange");this.notification=t,this.display=n,this.text=a,this.enabled=!1,this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose()}update(t){if(!this.enabled||t.empty)return;const n=this.text.format(t);n&&this.onChangeEmitter.fire({value:n})}toggle(t){if(t.empty){this.notification.notify("No info for review");return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(cn.REVIEW);const n=`Review is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}const iz={0:ge.DATA_MODE,1:ge.LOWER_VALUE_MODE,2:ge.HIGHER_VALUE_MODE};class Use{constructor(t){F(this,"context");F(this,"rotorIndex");this.context=t,this.rotorIndex=0}moveToNextRotorUnit(){return this.rotorIndex=(this.rotorIndex+1)%ge.NO_OF_ROTOR_NAV_MODES,this.setMode(),this.getMode()}moveToPrevRotorUnit(){return this.rotorIndex=(this.rotorIndex-1+ge.NO_OF_ROTOR_NAV_MODES)%ge.NO_OF_ROTOR_NAV_MODES,this.setMode(),this.getMode()}getCurrentUnit(){return this.rotorIndex}callMoveToNextCompareMethod(t){const n=this.context.active,a=this.getCompareType();if(a!=="lower"&&a!=="higher")return console.error(`Unexpected compare type: ${a}`),null;if(n instanceof Zl)if(n.getCurrentXValue()!==null){if(!n.moveToNextCompareValue(t,a)){const f=`No ${a} value found to the ${t} of the current value.`;return console.warn(f),f}}else console.error("Unable to retrieve the current X value.");else console.error("The active trace does not support 'callMoveToNextCompareMethod'.");return null}moveUp(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveUpRotor(this.getCompareType())){const a=`No ${this.getCompareType()} value found above the current value.`;return console.warn(a),a}}catch{return this.moveRight()}return null}moveDown(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveDownRotor(this.getCompareType())){const a=`No ${this.getCompareType()} value found below the current value.`;return console.warn(a),a}}catch{return this.moveLeft()}return null}moveLeft(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveLeftRotor(this.getCompareType())){const a=`No ${this.getCompareType()} value found to the left of the current value.`;return console.warn(a),a}}catch{return this.callMoveToNextCompareMethod("left")}return null}moveRight(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveRightRotor(this.getCompareType())){const a=`No ${this.getCompareType()} value found to the right of the current value.`;return console.warn(a),a}}catch{return this.callMoveToNextCompareMethod("right")}return null}setMode(){if(iz[this.rotorIndex]===ge.DATA_MODE){this.context.setRotorEnabled(!1);return}this.context.setRotorEnabled(!0)}getMode(){return iz[this.rotorIndex]}getCompareType(){const t=this.getMode();return t===ge.HIGHER_VALUE_MODE?"higher":(t===ge.LOWER_VALUE_MODE,"lower")}}const e8="maidr-settings";class Pse{constructor(t,n){F(this,"storage");F(this,"display");F(this,"defaultSettings");F(this,"currentSettings");F(this,"observers");this.storage=t,this.display=n,this.observers=[],this.defaultSettings={general:{volume:50,highlightColor:"#03c809",brailleDisplaySize:32,minFrequency:200,maxFrequency:1e3,autoplayDuration:4e3,ariaMode:"assertive",hoverMode:"pointermove"},llm:{expertiseLevel:"basic",customInstruction:"",models:{OPENAI:{enabled:!1,apiKey:"",name:"OpenAI",version:"gpt-4o"},ANTHROPIC_CLAUDE:{enabled:!1,apiKey:"",name:"Anthropic Claude",version:"claude-3-7-sonnet-latest"},GOOGLE_GEMINI:{enabled:!1,apiKey:"",name:"Google Gemini",version:"gemini-2.0-flash"}}}};const a=this.storage.load(e8);this.currentSettings=a??this.defaultSettings}get state(){return this.currentSettings}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){for(const t of this.observers)t.update(this.currentSettings)}loadSettings(){return this.currentSettings}saveSettings(t){this.currentSettings=t,this.storage.save(e8,this.currentSettings),this.notifyStateUpdate()}resetSettings(){return this.currentSettings=this.defaultSettings,this.storage.remove(e8),this.notifyStateUpdate(),this.currentSettings}toggle(){this.display.toggleFocus(cn.SETTINGS)}}class jse{save(t,n){try{const a=JSON.stringify(n);localStorage.setItem(t,a)}catch(a){console.error(`Error while saving ${t} to storage`,a)}}load(t){try{const n=localStorage.getItem(t);return n===null?null:JSON.parse(n)}catch(n){return console.error(`Error while loading ${t} from storage`,n),null}}remove(t){try{localStorage.removeItem(t)}catch(n){console.error(`Error while removing ${t} from storage`,n)}}}function oz(e){return!e.empty&&e.isLayerSwitch===!0&&typeof e.index=="number"&&typeof e.size=="number"}class $se{constructor(t){F(this,"notification");F(this,"mode");F(this,"currentState",null);F(this,"currentSubplotIndex",null);F(this,"hasHadFirstNavigation",!1);F(this,"onChangeEmitter");F(this,"onChange");F(this,"onNavigationEmitter");F(this,"onNavigation");this.notification=t,this.mode="verbose",this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event,this.onNavigationEmitter=new tp,this.onNavigation=this.onNavigationEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.onNavigationEmitter.dispose()}getCurrentState(){return this.currentState}getCoordinateText(){return!this.currentState||this.currentState.empty?null:this.currentState.type==="subplot"&&!this.currentState.trace.empty?this.formatCoordinateText(this.currentState.trace):this.currentState.type==="trace"&&!this.currentState.empty?this.formatCoordinateText(this.currentState):null}isLayerSwitch(){if(!this.currentState||this.currentState.empty||this.currentState.type!=="subplot")return!1;const t=this.currentState.index;return this.currentSubplotIndex!==null&&this.currentSubplotIndex!==t?(this.currentSubplotIndex=t,!0):this.currentSubplotIndex===null?(this.currentSubplotIndex=t,t!==0):!1}getHasHadFirstNavigation(){return this.hasHadFirstNavigation}enableAnnouncements(){this.onNavigationEmitter.fire({type:"first_navigation"})}formatCoordinateText(t){if(t.empty||!t.text)return null;const{text:n}=t,a=[];if(n.main&&n.main.value!==void 0){const o=Array.isArray(n.main.value)?n.main.value.join(", "):String(n.main.value);a.push(`${n.main.label} is ${o}`)}if(n.cross&&n.cross.value!==void 0){const o=Array.isArray(n.cross.value)?n.cross.value.join(", "):String(n.cross.value);a.push(`${n.cross.label} is ${o}`)}return n.fill&&n.fill.value!==void 0&&a.push(`${n.fill.label} is ${n.fill.value}`),a.length>0?a.join(", "):null}formatLayerSwitchAnnouncement(t){if(!oz(t))return"";let n=`Layer ${t.index} of ${t.size}: ${t.plotType||t.traceType} plot`;if(t.text){const a=[];t.text.main&&t.text.main.value!==void 0&&a.push(`${t.text.main.label} is ${t.text.main.value}`),t.text.cross&&t.text.cross.value!==void 0&&a.push(`${t.text.cross.label} is ${t.text.cross.value}`),t.text.fill&&t.text.fill.value!==void 0&&a.push(`${t.text.fill.label} is ${t.text.fill.value}`),a.length>0&&(n+=` at ${a.join(", ")}`)}return n}format(t){return typeof t=="string"?t:!t||t.empty?t.type==="subplot"?"No additional layer":`No ${t.type==="trace"?"plot":t.type} info to display`:t.type==="figure"?this.formatFigureText(t.index,t.size,t.traceTypes):t.type==="subplot"?this.formatSubplotText(t.index,t.size,t.trace.traceType,t.trace):this.mode==="verbose"?this.formatVerboseTraceText(t.text):this.formatTerseTraceText(t.text)}formatFigureText(t,n,a){const o=a.length===1?`This is a ${a[0]} plot`:`This is a multi-layered plot containing ${a.join(ge.COMMA_SPACE)} plots`;return`Subplot ${t} of ${n}: ${o}. Press 'ENTER' to select this subplot.`}formatSubplotText(t,n,a,o){const s=o&&!o.empty?o.plotType:a;return`Layer ${t} of ${n}: ${s} plot`}isBoxPlotWithSection(t){return t.section!==void 0&&t.fill===void 0}formatVerboseTraceText(t){const n=new Array;if(n.push(t.main.label,ge.IS),t.range!==void 0?n.push(String(t.range.min),ge.THROUGH,String(t.range.max)):Array.isArray(t.main.value)?n.push(t.main.value.join(ge.COMMA_SPACE)):n.push(String(t.main.value)),t.section&&this.isBoxPlotWithSection(t)&&(t.section===ou.UPPER_OUTLIER||t.section===ou.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const a=t.cross.label,o=t.cross.value,s=`[${o.join(", ")}]`;if(o.length===0)return`${t.main.label} is ${t.main.value}, no ${t.section.toLowerCase()} for ${a}`;{const f=o.length===1?"is":"are";return`${t.main.label} is ${t.main.value}, ${t.section.toLowerCase()} for ${a} ${f} ${s}`}}if(t.section!==void 0)if(this.isBoxPlotWithSection(t)){const a=t.cross.label;n.push(ge.COMMA_SPACE,t.section.toLowerCase(),ge.SPACE,a)}else n.push(ge.COMMA_SPACE,t.section,ge.SPACE,t.cross.label);else n.push(ge.COMMA_SPACE,t.cross.label);if(Array.isArray(t.cross.value)?t.cross.value.length>1?n.push(ge.ARE,t.cross.value.join(ge.COMMA_SPACE)):t.cross.value.length>0&&n.push(ge.IS,t.cross.value.join(ge.COMMA_SPACE)):n.push(ge.IS,String(t.cross.value)),t.fill!==void 0){const a=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;n.push(ge.COMMA_SPACE,t.fill.label,ge.IS,a)}return n.join(ge.EMPTY)}formatTerseTraceText(t){const n=new Array;if(Array.isArray(t.main.value)?n.push(ge.OPEN_BRACKET,t.main.value.join(ge.COMMA_SPACE),ge.CLOSE_BRACKET):n.push(String(t.main.value),ge.COMMA_SPACE),t.section&&this.isBoxPlotWithSection(t)&&(t.section===ou.UPPER_OUTLIER||t.section===ou.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const a=t.cross.value,o=`[${a.join(", ")}]`;return a.length===0?`${t.main.value}, no ${t.section.toLowerCase()}`:`${t.main.value}, ${a.length} ${t.section.toLowerCase()} ${o}`}if(t.section!==void 0&&t.fill!==void 0?(n.push(t.section,ge.SPACE),Array.isArray(t.cross.value)?n.push(ge.OPEN_BRACKET,t.cross.value.join(ge.COMMA_SPACE),ge.CLOSE_BRACKET):n.push(String(t.cross.value))):(t.section!==void 0&&t.fill===void 0&&n.push(t.section,ge.SPACE),Array.isArray(t.cross.value)?n.push(ge.OPEN_BRACKET,t.cross.value.join(ge.COMMA_SPACE),ge.CLOSE_BRACKET):n.push(String(t.cross.value))),t.fill!==void 0){const a=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;t.section,n.push(ge.COMMA_SPACE,a)}return n.join(ge.EMPTY)}update(t){if(this.mode==="off")return;if(this.currentState=t,t.type==="trace"&&oz(t)){const a=this.formatLayerSwitchAnnouncement(t);this.notification.notify(a);return}if(t.type==="subplot"){const a=this.format(t);a&&this.notification.notify(a);return}t.type==="figure"&&!t.empty&&!this.hasHadFirstNavigation&&(this.hasHadFirstNavigation=!0,this.onNavigationEmitter.fire({type:"first_navigation"}));const n=this.format(t);n&&this.onChangeEmitter.fire({value:n})}toggle(){switch(this.mode){case"off":this.mode="verbose";break;case"terse":this.mode="off";break;case"verbose":this.mode="terse";break}const t=`Text mode is ${this.mode}`;return this.notification.notify(t),this.mode!=="off"}}class t8{constructor(t,n){F(this,"figure");F(this,"context");F(this,"displayService");F(this,"notificationService");F(this,"settingsService");F(this,"audioService");F(this,"brailleService");F(this,"goToExtremaService");F(this,"textService");F(this,"reviewService");F(this,"rotorNavigationService");F(this,"autoplayService");F(this,"highlightService");F(this,"helpService");F(this,"chatService");F(this,"textViewModel");F(this,"brailleViewModel");F(this,"goToExtremaViewModel");F(this,"reviewViewModel");F(this,"displayViewModel");F(this,"helpViewModel");F(this,"chatViewModel");F(this,"settingsViewModel");F(this,"rotorNavigationViewModel");F(this,"commandPaletteViewModel");F(this,"keybinding");F(this,"mousebinding");F(this,"commandExecutor");this.figure=new nse(t),this.context=new Ale(this.figure),this.notificationService=new Bse,this.textService=new $se(this.notificationService),this.displayService=new Nse(this.context,n,this.textService),this.settingsService=new Pse(new jse,this.displayService),this.audioService=new lse(this.notificationService,this.context.state,this.settingsService),this.brailleService=new gse(this.context,this.notificationService,this.displayService),this.goToExtremaService=new zse(this.context,this.displayService),this.reviewService=new Vse(this.notificationService,this.displayService,this.textService),this.autoplayService=new dse(this.context,this.notificationService,this.settingsService),this.highlightService=new Ise(this.settingsService),this.helpService=new Lse(this.context,this.displayService),this.chatService=new Cse(this.displayService,this.textService,t),this.textViewModel=new cP(Js,this.textService,this.notificationService,this.autoplayService),this.brailleViewModel=new nV(Js,this.brailleService),this.goToExtremaViewModel=new HU(Js,this.goToExtremaService,this.context),this.reviewViewModel=new KU(Js,this.reviewService),this.displayViewModel=new PU(Js,this.displayService),this.helpViewModel=new YU(Js,this.helpService),this.settingsViewModel=new nP(Js,this.settingsService),this.rotorNavigationService=new Use(this.context),this.rotorNavigationViewModel=new JU(Js,this.rotorNavigationService),this.chatViewModel=new cV(Js,this.chatService,this.audioService);const a=new kse(this.context,this.displayService);this.commandPaletteViewModel=new zU(Js,a),this.keybinding=new _U({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,commandPaletteViewModel:this.commandPaletteViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel,rotorNavigationViewModel:this.rotorNavigationViewModel,rotorNavigationService:this.rotorNavigationService}),this.mousebinding=new kU({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,commandPaletteViewModel:this.commandPaletteViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel,rotorNavigationViewModel:this.rotorNavigationViewModel,rotorNavigationService:this.rotorNavigationService},this.settingsService,this.displayService),this.commandExecutor=new _se({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,commandPaletteViewModel:this.commandPaletteViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel,rotorNavigationViewModel:this.rotorNavigationViewModel,rotorNavigationService:this.rotorNavigationService},this.context.scope),this.registerViewModels(),this.registerObservers(),this.keybinding.register(this.context.scope),this.mousebinding.registerEvents()}announceInitialInstruction(){this.notificationService.notify(""),setTimeout(()=>{this.notificationService.notify(this.displayService.getInstruction(!1))},50)}getInitialInstruction(){return this.displayService.getInstruction(!1)}showInitialInstructionInText(){const t=this.displayService.getInstruction(!1);this.textViewModel.setAnnounce(!1),this.textViewModel.update(t)}dispose(){this.keybinding.unregister(),this.mousebinding.dispose(),lo.instance.dispose(),this.settingsViewModel.dispose(),this.chatViewModel.dispose(),this.helpViewModel.dispose(),this.displayViewModel.dispose(),this.goToExtremaViewModel.dispose(),this.reviewViewModel.dispose(),this.brailleViewModel.dispose(),this.textViewModel.dispose(),this.commandPaletteViewModel.dispose(),this.highlightService.dispose(),this.autoplayService.dispose(),this.textService.dispose(),this.reviewService.dispose(),this.brailleService.dispose(),this.audioService.dispose(),this.notificationService.dispose(),this.displayService.dispose(),this.context.dispose(),this.figure.dispose()}registerViewModels(){lo.instance.register("text",this.textViewModel),lo.instance.register("braille",this.brailleViewModel),lo.instance.register("goToExtrema",this.goToExtremaViewModel),lo.instance.register("review",this.reviewViewModel),lo.instance.register("display",this.displayViewModel),lo.instance.register("help",this.helpViewModel),lo.instance.register("chat",this.chatViewModel),lo.instance.register("settings",this.settingsViewModel),lo.instance.register("commandPalette",this.commandPaletteViewModel),lo.instance.register("commandExecutor",this.commandExecutor)}registerObservers(){this.figure.addObserver(this.textService),this.figure.addObserver(this.audioService),this.figure.addObserver(this.highlightService),this.figure.subplots.forEach(t=>t.forEach(n=>{n.addObserver(this.textService),n.addObserver(this.brailleService),n.addObserver(this.highlightService),n.traces.forEach(a=>a.forEach(o=>{o.addObserver(this.audioService),o.addObserver(this.brailleService),o.addObserver(this.textService),o.addObserver(this.reviewService),o.addObserver(this.highlightService)}))}))}}document.readyState==="loading"?document.addEventListener(sa.DOM_LOADED,sz):sz();function lz(e,t,n){try{const a=JSON.parse(t);uz(a,e)}catch(a){console.error(`Error parsing ${n} attribute:`,a)}}function sz(){const e=document.querySelectorAll(ge.MAIDR_JSON_SELECTOR);if(e.length>0){e.forEach(o=>{const s=o.getAttribute(ge.MAIDR);s&&lz(o,s,"maidr")});return}const t=document.querySelectorAll(`[${ge.MAIDR_DATA}]`);if(t.forEach(o=>{const s=o.getAttribute(ge.MAIDR_DATA);s&&lz(o,s,"maidr-data")}),t.length!==0)return;const n=window.maidr;if(!n)return;const a=document.getElementById(n.id);if(!a){console.error("Plot not found for maidr:",n.id);return}uz(n,a)}function uz(e,t){let n=null,a=null,o=!1;const s=()=>{setTimeout(()=>{if(!n)return;const T=document.activeElement;n.contains(T)||(a&&a.dispose(),a=null,o=!1)},0)},f=()=>{setTimeout(()=>{if(n){if(!a){const T=JSON.parse(JSON.stringify(e));a=new t8(T,t)}o||(o=!0,a.showInitialInstructionInText())}},0)},d=()=>{if(document.visibilityState==="visible"){a&&(a.dispose(),a=null);const T=JSON.parse(JSON.stringify(e));a=new t8(T,t),o=!1}},h=document.createElement(ge.FIGURE);h.id=`${ge.MAIDR_FIGURE}-${e.id}`,t.parentNode.replaceChild(h,t),h.appendChild(t);const y=document.createElement(ge.ARTICLE);y.id=`${ge.MAIDR_ARTICLE}-${e.id}`,h.parentNode.replaceChild(y,h),y.appendChild(h);const S=document.createElement(ge.DIV);S.id=`${ge.REACT_CONTAINER}-${e.id}`,h.appendChild(S),n=h,t.addEventListener(sa.FOCUS_IN,f),n.addEventListener(sa.FOCUS_OUT,s),document.addEventListener(sa.VISIBILITY_CHANGE,d),t.addEventListener(sa.CLICK,f),Tle.createRoot(S,{identifierPrefix:e.id}).render(vle(t)),(()=>{const T=JSON.parse(JSON.stringify(e));new t8(T,t).dispose()})()}}));
|
|
893
|
+
${S}`;return JSON.stringify({generationConfig:{maxOutputTokens:Ase},safetySettings:[],contents:[{role:"user",parts:[{text:E},{inlineData:{data:o.split(",")[1],mimeType:"image/svg+xml"}}]}]})}formatResponse(n){return n.candidates.length===0?{success:!1,error:"Invalid response format"}:{success:!0,data:n.candidates[0].content.parts[0].text}}getHeaders(n){const a=super.getHeaders(n);return delete a.Authorization,a}}class _se{constructor(t,n){F(this,"commandFactory");F(this,"currentScope");F(this,"context");this.commandFactory=new EA(t),this.currentScope=n,this.context=t}getContext(){return this.context}executeCommand(t){const n=R7[this.currentScope];if(!n||!(t in n)){console.warn(`Command ${t} is not available in scope ${this.currentScope}`);return}try{this.commandFactory.create(t).execute()}catch(a){console.error(`Failed to execute command ${t}:`,a)}}setScope(t){this.currentScope=t}getCurrentScope(){return this.currentScope}}class kse{constructor(t,n){F(this,"context");F(this,"display");this.context=t,this.display=n}toggle(){this.context.scope!==cn.COMMAND_PALETTE&&this.display.toggleFocus(cn.COMMAND_PALETTE)}returnToTraceScope(){this.context.scope!==cn.TRACE&&this.display.toggleFocus(cn.COMMAND_PALETTE)}}function Dse(e){return e!==null&&typeof e=="object"&&"ensureInitialized"in e&&typeof e.ensureInitialized=="function"}class Nse{constructor(t,n,a){F(this,"context");F(this,"focusStack");F(this,"plot");F(this,"onChangeEmitter");F(this,"onChange");F(this,"hasEnteredInteractive",!1);F(this,"textService");F(this,"isReturningFromModeToggle",!1);F(this,"textChangeDisposer",null);F(this,"hasClearedOnFirstNav",!1);this.context=t,this.focusStack=new HT,this.focusStack.push(this.context.scope),this.plot=n,this.textService=a,this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event,this.removeInstruction(),this.textChangeDisposer=this.textService.onChange(()=>{this.hasClearedOnFirstNav||(this.plot.removeAttribute(ge.ARIA_LABEL),this.hasClearedOnFirstNav=!0)})}dispose(){var t;this.addInstruction(),(t=this.textChangeDisposer)==null||t.dispose(),this.textChangeDisposer=null,this.onChangeEmitter.dispose()}getInstruction(t=!0){return this.context.getInstruction(t)}addInstruction(){this.plot.setAttribute(ge.ARIA_LABEL,this.getInstruction()),this.plot.setAttribute(ge.TITLE,this.getInstruction()),this.plot.setAttribute(ge.ROLE,ge.IMAGE),this.plot.tabIndex=0}removeInstruction(){const t=this.hasEnteredInteractive?"":this.getInstruction(!1);t?(this.plot.setAttribute(ge.ARIA_LABEL,t),this.plot.removeAttribute(ge.TITLE),this.plot.setAttribute(ge.ROLE,ge.APPLICATION),this.plot.tabIndex=0):(this.plot.removeAttribute(ge.ARIA_LABEL),this.plot.removeAttribute(ge.TITLE),this.plot.setAttribute(ge.ROLE,ge.APPLICATION),this.plot.tabIndex=0)}getTraceAriaLabel(){const t=this.textService.format(this.context.state);return t&&t.trim().length>0?t:this.getInstruction(!1)}toggleFocus(t){this.isReturningFromModeToggle=t==="BRAILLE"||t==="REVIEW"||t==="GO_TO_EXTREMA"||t==="COMMAND_PALETTE"||t==="ROTOR"||t==="SETTINGS"||t==="CHAT"||t==="HELP",this.isReturningFromModeToggle&&this.plot.removeAttribute(ge.ARIA_LABEL),this.focusStack.removeLast(t)||this.focusStack.push(t);const n=this.focusStack.peek();this.context.toggleScope(n),this.updateFocus(n)}updateFocus(t){t==="TRACE"||t==="SUBPLOT"?(this.plot.tabIndex=0,setTimeout(()=>{if(this.isReturningFromModeToggle)this.isReturningFromModeToggle=!1,this.plot.removeAttribute(ge.ARIA_LABEL);else{const n=this.context.active;n&&Dse(n)&&n.ensureInitialized(),this.hasEnteredInteractive||this.plot.removeAttribute(ge.ARIA_LABEL)}this.plot.setAttribute(ge.ROLE,ge.APPLICATION),this.plot.focus(),this.hasEnteredInteractive||(this.hasEnteredInteractive=!0),this.onChangeEmitter.fire({value:t})},0)):this.onChangeEmitter.fire({value:t})}}class zse{constructor(t,n){F(this,"context");F(this,"display");this.context=t,this.display=n}toggle(t){if(t.empty)return;const n=this.context.active;n&&this.isExtremaNavigable(n)&&this.context.scope!==cn.GO_TO_EXTREMA&&this.display.toggleFocus(cn.GO_TO_EXTREMA)}isExtremaNavigable(t){return t instanceof Zl&&t.supportsExtremaNavigation()}returnToTraceScope(){this.context.scope!==cn.TRACE&&this.display.toggleFocus(cn.GO_TO_EXTREMA)}}const JT=[{description:"Navigate Data Points",key:"arrow keys"},{description:"Move to Next Layer",key:"page up"},{description:"Move to Previous Layer",key:"page down"},{description:"Go to Left/Right/Top/Bottom Extreme Point",key:`${$t.ctrl} + arrow keys`},{description:"Toggle Braille Mode",key:"b"},{description:"Toggle Text Mode",key:"t"},{description:"Toggle Sonification Mode",key:"s"},{description:"Toggle Review Mode",key:"r"},{description:"Autoplay Outward",key:`${$t.ctrl} + shift + arrow keys`},{description:"Stop Autoplay",key:`${$t.ctrl}`},{description:"Speed Up Autoplay",key:". (period)"},{description:"Speed Down Autoplay",key:", (comma)"},{description:"Reset Autoplay Speed",key:"/ (slash)"},{description:"Replay Current Point",key:"space"},{description:"Announce Plot Title",key:"l t"},{description:"Announce X Label",key:"l x"},{description:"Announce Y Label",key:"l y"},{description:"Announce Fill (Z) Label",key:"l f"},{description:"Open Settings",key:`${$t.ctrl} + ,`},{description:"Open Chat",key:"?"},{description:"Move to next navigation mode in Rotor",key:`${$t.alt}+shift+up`},{description:"Move to previous navigation mode in Rotor",key:`${$t.alt}+shift+down`}],az=[{description:"Move around Subplot",key:"arrow keys"},{description:"Activate Current Subplot",key:`${$t.enter}`},{description:"Announce Plot Title",key:"l t"},{description:"Announce Subtitle",key:"l s"},{description:"Announce Caption",key:"l c"},{description:"Open Settings",key:`${$t.ctrl} + ,`}];class Lse{constructor(t,n){F(this,"context");F(this,"display");F(this,"scopedMenuItems");this.context=t,this.display=n,this.scopedMenuItems={[cn.TRACE]:JT,[cn.TRACE_LABEL]:JT,[cn.BRAILLE]:JT,[cn.SUBPLOT]:az,[cn.FIGURE_LABEL]:az}}getMenuItems(){return this.scopedMenuItems[this.context.scope]??[]}toggle(){this.display.toggleFocus(cn.HELP)}}class Ise{constructor(t){F(this,"highlightedElements");F(this,"highlightedSubplots");F(this,"currentHighlightColor");this.highlightedElements=new Map,this.highlightedSubplots=new Set;const n=t.loadSettings();this.currentHighlightColor=n.general.highlightColor}dispose(){this.unhighlightAll()}isSettings(t){return"general"in t}createHighlightElement(t){if(!(t instanceof SVGElement))throw new TypeError("Invalid element provided for highlight creation");const n=Jt.createHighlightElement(t,this.currentHighlightColor);return n.id=`${ge.MAIDR_HIGHLIGHT}-${Date.now()}-${Math.random()}`,n}handleSettingsUpdate(t){this.currentHighlightColor=t.general.highlightColor}handleStateUpdate(t){t.empty||(this.unhighlightTraceElements(),t.type==="figure"?this.handleFigureState(t):t.type==="subplot"?this.handleSubplotState(t):this.handleTraceState(t))}handleFigureState(t){t.empty||this.processHighlighting(t.highlight)}handleSubplotState(t){t.empty||this.processHighlighting(t.highlight)}handleTraceState(t){if(t.empty||t.highlight.empty)return;const n=this.getElementsFromHighlight(t.highlight);this.highlightTraceElements(n)}processHighlighting(t){if(t.empty)return;const n=this.getElementsFromHighlight(t);this.isMultiPlotScenario()?this.highlightSubplotElements(n):this.unhighlightSubplotElements()}getElementsFromHighlight(t){return t.empty?[]:Array.isArray(t.elements)?t.elements:[t.elements]}isMultiPlotScenario(){return document.querySelectorAll('g[id^="axes_"]').length>1}highlightTraceElements(t){for(const n of t)try{const a=this.createHighlightElement(n);this.highlightedElements.set(n,a)}catch(a){console.error("Failed to highlight element:",a)}}highlightSubplotElements(t){var o;this.unhighlightSubplotElements();const n=(o=document.querySelector('g[id^="maidr-"] > path[style*="fill"]'))==null?void 0:o.parentElement,a=(n==null?void 0:n.querySelector('path[style*="fill"]'))||void 0;for(const s of t)Jt.setSubplotHighlightSvgWithAdaptiveColor(s,this.currentHighlightColor,a),this.highlightedSubplots.add(s)}update(t){try{this.isSettings(t)?this.handleSettingsUpdate(t):this.handleStateUpdate(t)}catch(n){console.error("Failed to update highlight service:",n)}}highlight(t){if(!(t instanceof SVGElement)){console.warn("Invalid element provided to highlight method");return}try{this.unhighlight(t);const n=this.createHighlightElement(t);this.highlightedElements.set(t,n)}catch(n){console.error("Failed to highlight element:",n)}}unhighlight(t){if(!(t instanceof SVGElement))return;const n=this.highlightedElements.get(t);if(n)try{n.remove(),this.highlightedElements.delete(t)}catch(a){console.error("Failed to unhighlight element:",a)}}clear(){try{this.highlightedElements.forEach(t=>{t.remove()}),this.highlightedElements.clear(),this.unhighlightSubplotElements()}catch(t){console.error("Failed to clear highlights:",t)}}unhighlightTraceElements(){this.highlightedElements.forEach(t=>{t.remove()}),this.highlightedElements.clear()}unhighlightSubplotElements(){this.highlightedSubplots.forEach(t=>{Jt.removeSubplotHighlightSvg(t)}),this.highlightedSubplots.clear()}unhighlightAll(){this.unhighlightTraceElements(),this.unhighlightSubplotElements()}}class Bse{constructor(){F(this,"onChangeEmitter");F(this,"onChange");this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose()}notify(t){t&&this.onChangeEmitter.fire({value:t})}}class Vse{constructor(t,n,a){F(this,"notification");F(this,"display");F(this,"text");F(this,"enabled");F(this,"onChangeEmitter");F(this,"onChange");this.notification=t,this.display=n,this.text=a,this.enabled=!1,this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose()}update(t){if(!this.enabled||t.empty)return;const n=this.text.format(t);n&&this.onChangeEmitter.fire({value:n})}toggle(t){if(t.empty){this.notification.notify("No info for review");return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(cn.REVIEW);const n=`Review is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}const iz={0:ge.DATA_MODE,1:ge.LOWER_VALUE_MODE,2:ge.HIGHER_VALUE_MODE};class Use{constructor(t,n){F(this,"context");F(this,"text");F(this,"rotorIndex");this.context=t,this.rotorIndex=0,this.text=n}moveToNextRotorUnit(){return this.rotorIndex=(this.rotorIndex+1)%ge.NO_OF_ROTOR_NAV_MODES,this.setMode(),this.getMode()}moveToPrevRotorUnit(){return this.rotorIndex=(this.rotorIndex-1+ge.NO_OF_ROTOR_NAV_MODES)%ge.NO_OF_ROTOR_NAV_MODES,this.setMode(),this.getMode()}getCurrentUnit(){return this.rotorIndex}callMoveToNextCompareMethod(t){const n=this.context.active,a=this.getCompareType();if(a!=="lower"&&a!=="higher")return console.error(`Unexpected compare type: ${a}`),null;if(n instanceof Zl)if(n.getCurrentXValue()!==null){if(!n.moveToNextCompareValue(t,a)){const f=this.getMessage(a,t);return console.warn(f),f}}else console.error("Unable to retrieve the current X value.");else console.error("The active trace does not support 'callMoveToNextCompareMethod'.");return null}moveUp(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveUpRotor(this.getCompareType())){const a=this.getMessage(this.getCompareType(),"above");return console.warn(a),a}}catch{return this.moveRight()}return null}moveDown(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveDownRotor(this.getCompareType())){const a=this.getMessage(this.getCompareType(),"below");return console.warn(a),a}}catch{return this.moveLeft()}return null}moveLeft(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveLeftRotor(this.getCompareType())){const a=this.getMessage(this.getCompareType(),"left");return console.warn(a),a}}catch{return this.callMoveToNextCompareMethod("left")}return null}moveRight(){const t=this.context.active;try{if(t instanceof Zl&&!t.moveRightRotor(this.getCompareType())){const a=this.getMessage(this.getCompareType(),"right");return console.warn(a),a}}catch{return this.callMoveToNextCompareMethod("right")}return null}setMode(){if(iz[this.rotorIndex]===ge.DATA_MODE){this.context.setRotorEnabled(!1);return}this.context.setRotorEnabled(!0)}getMode(){return iz[this.rotorIndex]}getCompareType(){const t=this.getMode();return t===ge.HIGHER_VALUE_MODE?"higher":(t===ge.LOWER_VALUE_MODE,"lower")}getMessage(t,n){if(this.text.isOff())return"";if(this.text.isTerse())return`No ${t} value found ${n==="above"||n==="below"?"":"on the"} ${n}`;const a=n==="above"||n==="below"?"":`to the ${n} of`;return`No ${t} value found ${a} the current value.`}}const e8="maidr-settings";class Pse{constructor(t,n){F(this,"storage");F(this,"display");F(this,"defaultSettings");F(this,"currentSettings");F(this,"observers");this.storage=t,this.display=n,this.observers=[],this.defaultSettings={general:{volume:50,highlightColor:"#03c809",brailleDisplaySize:32,minFrequency:200,maxFrequency:1e3,autoplayDuration:4e3,ariaMode:"assertive",hoverMode:"pointermove"},llm:{expertiseLevel:"basic",customInstruction:"",models:{OPENAI:{enabled:!1,apiKey:"",name:"OpenAI",version:"gpt-4o"},ANTHROPIC_CLAUDE:{enabled:!1,apiKey:"",name:"Anthropic Claude",version:"claude-3-7-sonnet-latest"},GOOGLE_GEMINI:{enabled:!1,apiKey:"",name:"Google Gemini",version:"gemini-2.0-flash"}}}};const a=this.storage.load(e8);this.currentSettings=a??this.defaultSettings}get state(){return this.currentSettings}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){for(const t of this.observers)t.update(this.currentSettings)}loadSettings(){return this.currentSettings}saveSettings(t){this.currentSettings=t,this.storage.save(e8,this.currentSettings),this.notifyStateUpdate()}resetSettings(){return this.currentSettings=this.defaultSettings,this.storage.remove(e8),this.notifyStateUpdate(),this.currentSettings}toggle(){this.display.toggleFocus(cn.SETTINGS)}}class jse{save(t,n){try{const a=JSON.stringify(n);localStorage.setItem(t,a)}catch(a){console.error(`Error while saving ${t} to storage`,a)}}load(t){try{const n=localStorage.getItem(t);return n===null?null:JSON.parse(n)}catch(n){return console.error(`Error while loading ${t} from storage`,n),null}}remove(t){try{localStorage.removeItem(t)}catch(n){console.error(`Error while removing ${t} from storage`,n)}}}function oz(e){return!e.empty&&e.isLayerSwitch===!0&&typeof e.index=="number"&&typeof e.size=="number"}class $se{constructor(t){F(this,"notification");F(this,"mode");F(this,"currentState",null);F(this,"currentSubplotIndex",null);F(this,"hasHadFirstNavigation",!1);F(this,"onChangeEmitter");F(this,"onChange");F(this,"onNavigationEmitter");F(this,"onNavigation");this.notification=t,this.mode="verbose",this.onChangeEmitter=new tp,this.onChange=this.onChangeEmitter.event,this.onNavigationEmitter=new tp,this.onNavigation=this.onNavigationEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.onNavigationEmitter.dispose()}getCurrentState(){return this.currentState}getCoordinateText(){return!this.currentState||this.currentState.empty?null:this.currentState.type==="subplot"&&!this.currentState.trace.empty?this.formatCoordinateText(this.currentState.trace):this.currentState.type==="trace"&&!this.currentState.empty?this.formatCoordinateText(this.currentState):null}isLayerSwitch(){if(!this.currentState||this.currentState.empty||this.currentState.type!=="subplot")return!1;const t=this.currentState.index;return this.currentSubplotIndex!==null&&this.currentSubplotIndex!==t?(this.currentSubplotIndex=t,!0):this.currentSubplotIndex===null?(this.currentSubplotIndex=t,t!==0):!1}getHasHadFirstNavigation(){return this.hasHadFirstNavigation}enableAnnouncements(){this.onNavigationEmitter.fire({type:"first_navigation"})}formatCoordinateText(t){if(t.empty||!t.text)return null;const{text:n}=t,a=[];if(n.main&&n.main.value!==void 0){const o=Array.isArray(n.main.value)?n.main.value.join(", "):String(n.main.value);a.push(`${n.main.label} is ${o}`)}if(n.cross&&n.cross.value!==void 0){const o=Array.isArray(n.cross.value)?n.cross.value.join(", "):String(n.cross.value);a.push(`${n.cross.label} is ${o}`)}return n.fill&&n.fill.value!==void 0&&a.push(`${n.fill.label} is ${n.fill.value}`),a.length>0?a.join(", "):null}formatLayerSwitchAnnouncement(t){if(!oz(t))return"";let n=`Layer ${t.index} of ${t.size}: ${t.plotType||t.traceType} plot`;if(t.text){const a=[];t.text.main&&t.text.main.value!==void 0&&a.push(`${t.text.main.label} is ${t.text.main.value}`),t.text.cross&&t.text.cross.value!==void 0&&a.push(`${t.text.cross.label} is ${t.text.cross.value}`),t.text.fill&&t.text.fill.value!==void 0&&a.push(`${t.text.fill.label} is ${t.text.fill.value}`),a.length>0&&(n+=` at ${a.join(", ")}`)}return n}format(t){return typeof t=="string"?t:!t||t.empty?t.type==="subplot"?"No additional layer":`No ${t.type==="trace"?"plot":t.type} info to display`:t.type==="figure"?this.formatFigureText(t.index,t.size,t.traceTypes):t.type==="subplot"?this.formatSubplotText(t.index,t.size,t.trace.traceType,t.trace):this.mode==="verbose"?this.formatVerboseTraceText(t.text):this.formatTerseTraceText(t.text)}formatFigureText(t,n,a){const o=a.length===1?`This is a ${a[0]} plot`:`This is a multi-layered plot containing ${a.join(ge.COMMA_SPACE)} plots`;return`Subplot ${t} of ${n}: ${o}. Press 'ENTER' to select this subplot.`}formatSubplotText(t,n,a,o){const s=o&&!o.empty?o.plotType:a;return`Layer ${t} of ${n}: ${s} plot`}isBoxPlotWithSection(t){return t.section!==void 0&&t.fill===void 0}formatVerboseTraceText(t){const n=new Array;if(n.push(t.main.label,ge.IS),t.range!==void 0?n.push(String(t.range.min),ge.THROUGH,String(t.range.max)):Array.isArray(t.main.value)?n.push(t.main.value.join(ge.COMMA_SPACE)):n.push(String(t.main.value)),t.section&&this.isBoxPlotWithSection(t)&&(t.section===ou.UPPER_OUTLIER||t.section===ou.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const a=t.cross.label,o=t.cross.value,s=`[${o.join(", ")}]`;if(o.length===0)return`${t.main.label} is ${t.main.value}, no ${t.section.toLowerCase()} for ${a}`;{const f=o.length===1?"is":"are";return`${t.main.label} is ${t.main.value}, ${t.section.toLowerCase()} for ${a} ${f} ${s}`}}if(t.section!==void 0)if(this.isBoxPlotWithSection(t)){const a=t.cross.label;n.push(ge.COMMA_SPACE,t.section.toLowerCase(),ge.SPACE,a)}else n.push(ge.COMMA_SPACE,t.section,ge.SPACE,t.cross.label);else n.push(ge.COMMA_SPACE,t.cross.label);if(Array.isArray(t.cross.value)?t.cross.value.length>1?n.push(ge.ARE,t.cross.value.join(ge.COMMA_SPACE)):t.cross.value.length>0&&n.push(ge.IS,t.cross.value.join(ge.COMMA_SPACE)):n.push(ge.IS,String(t.cross.value)),t.fill!==void 0){const a=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;n.push(ge.COMMA_SPACE,t.fill.label,ge.IS,a)}return n.join(ge.EMPTY)}formatTerseTraceText(t){const n=new Array;if(Array.isArray(t.main.value)?n.push(ge.OPEN_BRACKET,t.main.value.join(ge.COMMA_SPACE),ge.CLOSE_BRACKET):n.push(String(t.main.value),ge.COMMA_SPACE),t.section&&this.isBoxPlotWithSection(t)&&(t.section===ou.UPPER_OUTLIER||t.section===ou.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const a=t.cross.value,o=`[${a.join(", ")}]`;return a.length===0?`${t.main.value}, no ${t.section.toLowerCase()}`:`${t.main.value}, ${a.length} ${t.section.toLowerCase()} ${o}`}if(t.section!==void 0&&t.fill!==void 0?(n.push(t.section,ge.SPACE),Array.isArray(t.cross.value)?n.push(ge.OPEN_BRACKET,t.cross.value.join(ge.COMMA_SPACE),ge.CLOSE_BRACKET):n.push(String(t.cross.value))):(t.section!==void 0&&t.fill===void 0&&n.push(t.section,ge.SPACE),Array.isArray(t.cross.value)?n.push(ge.OPEN_BRACKET,t.cross.value.join(ge.COMMA_SPACE),ge.CLOSE_BRACKET):n.push(String(t.cross.value))),t.fill!==void 0){const a=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;t.section,n.push(ge.COMMA_SPACE,a)}return n.join(ge.EMPTY)}update(t){if(this.mode==="off")return;if(this.currentState=t,t.type==="trace"&&oz(t)){const a=this.formatLayerSwitchAnnouncement(t);this.notification.notify(a);return}if(t.type==="subplot"){const a=this.format(t);a&&this.notification.notify(a);return}t.type==="figure"&&!t.empty&&!this.hasHadFirstNavigation&&(this.hasHadFirstNavigation=!0,this.onNavigationEmitter.fire({type:"first_navigation"}));const n=this.format(t);n&&this.onChangeEmitter.fire({value:n})}isVerbose(){return this.mode==="verbose"}isTerse(){return this.mode==="terse"}isOff(){return this.mode==="off"}toggle(){switch(this.mode){case"off":this.mode="verbose";break;case"terse":this.mode="off";break;case"verbose":this.mode="terse";break}const t=`Text mode is ${this.mode}`;return this.notification.notify(t),this.mode!=="off"}}class t8{constructor(t,n){F(this,"figure");F(this,"context");F(this,"displayService");F(this,"notificationService");F(this,"settingsService");F(this,"audioService");F(this,"brailleService");F(this,"goToExtremaService");F(this,"textService");F(this,"reviewService");F(this,"rotorNavigationService");F(this,"autoplayService");F(this,"highlightService");F(this,"helpService");F(this,"chatService");F(this,"textViewModel");F(this,"brailleViewModel");F(this,"goToExtremaViewModel");F(this,"reviewViewModel");F(this,"displayViewModel");F(this,"helpViewModel");F(this,"chatViewModel");F(this,"settingsViewModel");F(this,"rotorNavigationViewModel");F(this,"commandPaletteViewModel");F(this,"keybinding");F(this,"mousebinding");F(this,"commandExecutor");this.figure=new nse(t),this.context=new Ale(this.figure),this.notificationService=new Bse,this.textService=new $se(this.notificationService),this.displayService=new Nse(this.context,n,this.textService),this.settingsService=new Pse(new jse,this.displayService),this.audioService=new lse(this.notificationService,this.context.state,this.settingsService),this.brailleService=new gse(this.context,this.notificationService,this.displayService),this.goToExtremaService=new zse(this.context,this.displayService),this.reviewService=new Vse(this.notificationService,this.displayService,this.textService),this.autoplayService=new dse(this.context,this.notificationService,this.settingsService),this.highlightService=new Ise(this.settingsService),this.helpService=new Lse(this.context,this.displayService),this.chatService=new Cse(this.displayService,this.textService,t),this.textViewModel=new cP(Js,this.textService,this.notificationService,this.autoplayService),this.brailleViewModel=new nV(Js,this.brailleService),this.goToExtremaViewModel=new HU(Js,this.goToExtremaService,this.context),this.reviewViewModel=new KU(Js,this.reviewService),this.displayViewModel=new PU(Js,this.displayService),this.helpViewModel=new YU(Js,this.helpService),this.settingsViewModel=new nP(Js,this.settingsService),this.rotorNavigationService=new Use(this.context,this.textService),this.rotorNavigationViewModel=new JU(Js,this.rotorNavigationService),this.chatViewModel=new cV(Js,this.chatService,this.audioService);const a=new kse(this.context,this.displayService);this.commandPaletteViewModel=new zU(Js,a),this.keybinding=new _U({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,commandPaletteViewModel:this.commandPaletteViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel,rotorNavigationViewModel:this.rotorNavigationViewModel,rotorNavigationService:this.rotorNavigationService}),this.mousebinding=new kU({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,commandPaletteViewModel:this.commandPaletteViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel,rotorNavigationViewModel:this.rotorNavigationViewModel,rotorNavigationService:this.rotorNavigationService},this.settingsService,this.displayService),this.commandExecutor=new _se({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,commandPaletteViewModel:this.commandPaletteViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel,rotorNavigationViewModel:this.rotorNavigationViewModel,rotorNavigationService:this.rotorNavigationService},this.context.scope),this.registerViewModels(),this.registerObservers(),this.keybinding.register(this.context.scope),this.mousebinding.registerEvents()}announceInitialInstruction(){this.notificationService.notify(""),setTimeout(()=>{this.notificationService.notify(this.displayService.getInstruction(!1))},50)}getInitialInstruction(){return this.displayService.getInstruction(!1)}showInitialInstructionInText(){const t=this.displayService.getInstruction(!1);this.textViewModel.setAnnounce(!1),this.textViewModel.update(t)}dispose(){this.keybinding.unregister(),this.mousebinding.dispose(),lo.instance.dispose(),this.settingsViewModel.dispose(),this.chatViewModel.dispose(),this.helpViewModel.dispose(),this.displayViewModel.dispose(),this.goToExtremaViewModel.dispose(),this.reviewViewModel.dispose(),this.brailleViewModel.dispose(),this.textViewModel.dispose(),this.commandPaletteViewModel.dispose(),this.highlightService.dispose(),this.autoplayService.dispose(),this.textService.dispose(),this.reviewService.dispose(),this.brailleService.dispose(),this.audioService.dispose(),this.notificationService.dispose(),this.displayService.dispose(),this.context.dispose(),this.figure.dispose()}registerViewModels(){lo.instance.register("text",this.textViewModel),lo.instance.register("braille",this.brailleViewModel),lo.instance.register("goToExtrema",this.goToExtremaViewModel),lo.instance.register("review",this.reviewViewModel),lo.instance.register("display",this.displayViewModel),lo.instance.register("help",this.helpViewModel),lo.instance.register("chat",this.chatViewModel),lo.instance.register("settings",this.settingsViewModel),lo.instance.register("commandPalette",this.commandPaletteViewModel),lo.instance.register("commandExecutor",this.commandExecutor)}registerObservers(){this.figure.addObserver(this.textService),this.figure.addObserver(this.audioService),this.figure.addObserver(this.highlightService),this.figure.subplots.forEach(t=>t.forEach(n=>{n.addObserver(this.textService),n.addObserver(this.brailleService),n.addObserver(this.highlightService),n.traces.forEach(a=>a.forEach(o=>{o.addObserver(this.audioService),o.addObserver(this.brailleService),o.addObserver(this.textService),o.addObserver(this.reviewService),o.addObserver(this.highlightService)}))}))}}document.readyState==="loading"?document.addEventListener(sa.DOM_LOADED,sz):sz();function lz(e,t,n){try{const a=JSON.parse(t);uz(a,e)}catch(a){console.error(`Error parsing ${n} attribute:`,a)}}function sz(){const e=document.querySelectorAll(ge.MAIDR_JSON_SELECTOR);if(e.length>0){e.forEach(o=>{const s=o.getAttribute(ge.MAIDR);s&&lz(o,s,"maidr")});return}const t=document.querySelectorAll(`[${ge.MAIDR_DATA}]`);if(t.forEach(o=>{const s=o.getAttribute(ge.MAIDR_DATA);s&&lz(o,s,"maidr-data")}),t.length!==0)return;const n=window.maidr;if(!n)return;const a=document.getElementById(n.id);if(!a){console.error("Plot not found for maidr:",n.id);return}uz(n,a)}function uz(e,t){let n=null,a=null,o=!1;const s=()=>{setTimeout(()=>{if(!n)return;const T=document.activeElement;n.contains(T)||(a&&a.dispose(),a=null,o=!1)},0)},f=()=>{setTimeout(()=>{if(n){if(!a){const T=JSON.parse(JSON.stringify(e));a=new t8(T,t)}o||(o=!0,a.showInitialInstructionInText())}},0)},d=()=>{if(document.visibilityState==="visible"){a&&(a.dispose(),a=null);const T=JSON.parse(JSON.stringify(e));a=new t8(T,t),o=!1}},h=document.createElement(ge.FIGURE);h.id=`${ge.MAIDR_FIGURE}-${e.id}`,t.parentNode.replaceChild(h,t),h.appendChild(t);const y=document.createElement(ge.ARTICLE);y.id=`${ge.MAIDR_ARTICLE}-${e.id}`,h.parentNode.replaceChild(y,h),y.appendChild(h);const S=document.createElement(ge.DIV);S.id=`${ge.REACT_CONTAINER}-${e.id}`,h.appendChild(S),n=h,t.addEventListener(sa.FOCUS_IN,f),n.addEventListener(sa.FOCUS_OUT,s),document.addEventListener(sa.VISIBILITY_CHANGE,d),t.addEventListener(sa.CLICK,f),Tle.createRoot(S,{identifierPrefix:e.id}).render(vle(t)),(()=>{const T=JSON.parse(JSON.stringify(e));new t8(T,t).dispose()})()}}));
|
|
894
894
|
//# sourceMappingURL=maidr.js.map
|