maidr 3.23.1 → 3.23.3

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 CHANGED
@@ -634,7 +634,7 @@ Learn more: https://react.dev/warnings/version-mismatch`))})(),typeof Map=="func
634
634
  You might need to use a local HTTP server (instead of file://): https://react.dev/link/react-devtools-faq`:""),"font-weight:bold")}Jf.createRoot=function(r,T){if(!x(r))throw Error("Target container is not a DOM element.");lc(r);var m=!1,E="",w=Ag,D=x9,F=L9,Z=null;return T!=null&&(T.hydrate?console.warn("hydrate through createRoot is deprecated. Use ReactDOMClient.hydrateRoot(container, <App />) instead."):typeof T=="object"&&T!==null&&T.$$typeof===S5&&console.error(`You passed a JSX element to createRoot. You probably meant to call root.render instead. Example usage:
635
635
 
636
636
  let root = createRoot(domContainer);
637
- root.render(<App />);`),T.unstable_strictMode===!0&&(m=!0),T.identifierPrefix!==void 0&&(E=T.identifierPrefix),T.onUncaughtError!==void 0&&(w=T.onUncaughtError),T.onCaughtError!==void 0&&(D=T.onCaughtError),T.onRecoverableError!==void 0&&(F=T.onRecoverableError),T.unstable_transitionCallbacks!==void 0&&(Z=T.unstable_transitionCallbacks)),T=Xh(r,1,!1,null,null,m,E,w,D,F,Z,null),r[Ni]=T.current,ts(r),new ac(T)},Jf.hydrateRoot=function(r,T,m){if(!x(r))throw Error("Target container is not a DOM element.");lc(r),T===void 0&&console.error("Must provide initial children as second argument to hydrateRoot. Example usage: hydrateRoot(domContainer, <App />)");var E=!1,w="",D=Ag,F=x9,Z=L9,ae=null,le=null;return m!=null&&(m.unstable_strictMode===!0&&(E=!0),m.identifierPrefix!==void 0&&(w=m.identifierPrefix),m.onUncaughtError!==void 0&&(D=m.onUncaughtError),m.onCaughtError!==void 0&&(F=m.onCaughtError),m.onRecoverableError!==void 0&&(Z=m.onRecoverableError),m.unstable_transitionCallbacks!==void 0&&(ae=m.unstable_transitionCallbacks),m.formState!==void 0&&(le=m.formState)),T=Xh(r,1,!0,T,m??null,E,w,D,F,Z,ae,le),T.context=F1(null),m=T.current,E=z4(m),E=Ke(E),w=o6(E),w.callback=null,l6(m,w,E),m=E,T.current.lanes=m,r1(T,m),mn(T),r[Ni]=T.current,ts(r),new oc(T)},Jf.version="19.1.1",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})(),Jf}var bP;function w0e(){if(bP)return lg.exports;bP=1;var e={};function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function")){if(e.NODE_ENV!=="production")throw new Error("^_^");try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(n){console.error(n)}}}return e.NODE_ENV==="production"?(t(),lg.exports=O0e()):lg.exports=C0e(),lg.exports}var V0e=w0e();class uH{constructor(){oe(this,"items");this.items=new Array}push(t){this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}removeLast(t,n=1){const l=this.items.lastIndexOf(t);return l!==-1?(this.items.splice(l,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}}const cH=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function TH(e,t,n,l){e.addEventListener?e.addEventListener(t,n,l):e.attachEvent&&e.attachEvent("on".concat(t),n)}function ed(e,t,n,l){e.removeEventListener?e.removeEventListener(t,n,l):e.detachEvent&&e.detachEvent("on".concat(t),n)}function HP(e,t){const n=t.slice(0,t.length-1);for(let l=0;l<n.length;l++)n[l]=e[n[l].toLowerCase()];return n}function EP(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function D0e(e,t){const n=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let a=!0;for(let o=0;o<n.length;o++)l.indexOf(n[o])===-1&&(a=!1);return a}const td={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":cH?173:189,"=":cH?61:187,";":cH?59:186,"'":222,"[":219,"]":221,"\\":220},Jr={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},nd={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},P3={16:!1,18:!1,17:!1,91:!1},E2={};for(let e=1;e<20;e++)td["f".concat(e)]=111+e;let m2=[],rd=null,SP="all";const e0=new Map,id=e=>td[e.toLowerCase()]||Jr[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),R0e=e=>Object.keys(td).find(t=>td[t]===e),k0e=e=>Object.keys(Jr).find(t=>Jr[t]===e);function MP(e){SP=e||"all"}function ad(){return SP||"all"}function N0e(){return m2.slice(0)}function B0e(){return m2.map(e=>R0e(e)||k0e(e)||String.fromCharCode(e))}function P0e(){const e=[];return Object.keys(E2).forEach(t=>{E2[t].forEach(n=>{let{key:l,scope:a,mods:o,shortcut:i}=n;e.push({scope:a,shortcut:i,mods:o,keys:l.split("+").map(s=>id(s))})})}),e}function I0e(e){const t=e.target||e.srcElement,{tagName:n}=t;let l=!0;const a=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(a||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(l=!1),l}function j0e(e){return typeof e=="string"&&(e=id(e)),m2.indexOf(e)!==-1}function F0e(e,t){let n,l;e||(e=ad());for(const a in E2)if(Object.prototype.hasOwnProperty.call(E2,a))for(n=E2[a],l=0;l<n.length;)n[l].scope===e?n.splice(l,1).forEach(i=>{let{element:s}=i;return QH(s)}):l++;ad()===e&&MP(t||"all")}function z0e(e){let t=e.keyCode||e.which||e.charCode;const n=m2.indexOf(t);if(n>=0&&m2.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&m2.splice(0,m2.length),(t===93||t===224)&&(t=91),t in P3){P3[t]=!1;for(const l in Jr)Jr[l]===t&&(o4[l]=!1)}}function AP(e){if(typeof e>"u")Object.keys(E2).forEach(a=>{Array.isArray(E2[a])&&E2[a].forEach(o=>ug(o)),delete E2[a]}),QH(null);else if(Array.isArray(e))e.forEach(a=>{a.key&&ug(a)});else if(typeof e=="object")e.key&&ug(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),l=1;l<t;l++)n[l-1]=arguments[l];let[a,o]=n;typeof a=="function"&&(o=a,a=""),ug({key:e,scope:a,method:o,splitKey:"+"})}}const ug=e=>{let{key:t,scope:n,method:l,splitKey:a="+"}=e;EP(t).forEach(i=>{const s=i.split(a),c=s.length,u=s[c-1],Q=u==="*"?"*":id(u);if(!E2[Q])return;n||(n=ad());const f=c>1?HP(Jr,s):[],h=[];E2[Q]=E2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===n&&D0e(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>QH(p))})};function _P(e,t,n,l){if(t.element!==l)return;let a;if(t.scope===n||t.scope==="all"){a=t.mods.length>0;for(const o in P3)Object.prototype.hasOwnProperty.call(P3,o)&&(!P3[o]&&t.mods.indexOf(+o)>-1||P3[o]&&t.mods.indexOf(+o)===-1)&&(a=!1);(t.mods.length===0&&!P3[16]&&!P3[18]&&!P3[17]&&!P3[91]||a||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(m2),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function OP(e,t){const n=E2["*"];let l=e.keyCode||e.which||e.charCode;if(!o4.filter.call(this,e))return;if((l===93||l===224)&&(l=91),m2.indexOf(l)===-1&&l!==229&&m2.push(l),["metaKey","ctrlKey","altKey","shiftKey"].forEach(s=>{const c=nd[s];e[s]&&m2.indexOf(c)===-1?m2.push(c):!e[s]&&m2.indexOf(c)>-1?m2.splice(m2.indexOf(c),1):s==="metaKey"&&e[s]&&(m2=m2.filter(u=>u in nd||u===l))}),l in P3){P3[l]=!0;for(const s in Jr)if(Object.prototype.hasOwnProperty.call(Jr,s)){const c=nd[Jr[s]];o4[s]=e[c]}if(!n)return}for(const s in P3)Object.prototype.hasOwnProperty.call(P3,s)&&(P3[s]=e[nd[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(m2.indexOf(17)===-1&&m2.push(17),m2.indexOf(18)===-1&&m2.push(18),P3[17]=!0,P3[18]=!0);const a=ad();if(n)for(let s=0;s<n.length;s++)n[s].scope===a&&(e.type==="keydown"&&n[s].keydown||e.type==="keyup"&&n[s].keyup)&&_P(e,n[s],a,t);if(!(l in E2))return;const o=E2[l],i=o.length;for(let s=0;s<i;s++)if((e.type==="keydown"&&o[s].keydown||e.type==="keyup"&&o[s].keyup)&&o[s].key){const c=o[s],{splitKey:u}=c,Q=c.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(id(Q[h]));f.sort().join("")===m2.sort().join("")&&_P(e,c,a,t)}}function o4(e,t,n){m2=[];const l=EP(e);let a=[],o="all",i=document,s=0,c=!1,u=!0,Q="+",f=!1,h=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(o=t.scope),t.element&&(i=t.element),t.keyup&&(c=t.keyup),t.keydown!==void 0&&(u=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(Q=t.splitKey),t.single===!0&&(h=!0)),typeof t=="string"&&(o=t),h&&AP(e,o);s<l.length;s++)e=l[s].split(Q),a=[],e.length>1&&(a=HP(Jr,e)),e=e[e.length-1],e=e==="*"?"*":id(e),e in E2||(E2[e]=[]),E2[e].push({keyup:c,keydown:u,scope:o,mods:a,shortcut:l[s],method:n,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!e0.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return OP(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;OP(v,i),z0e(v)};e0.set(i,{keydownListener:p,keyupListenr:g,capture:f}),TH(i,"keydown",p,f),TH(i,"keyup",g,f)}if(!rd){const p=()=>{m2=[]};rd={listener:p,capture:f},TH(window,"focus",p,f)}}}function q0e(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(E2).forEach(n=>{E2[n].filter(a=>a.scope===t&&a.shortcut===e).forEach(a=>{a&&a.method&&a.method()})})}function QH(e){const t=Object.values(E2).flat();if(t.findIndex(l=>{let{element:a}=l;return a===e})<0){const{keydownListener:l,keyupListenr:a,capture:o}=e0.get(e)||{};l&&a&&(ed(e,"keyup",a,o),ed(e,"keydown",l,o),e0.delete(e))}if((t.length<=0||e0.size<=0)&&(Object.keys(e0).forEach(a=>{const{keydownListener:o,keyupListenr:i,capture:s}=e0.get(a)||{};o&&i&&(ed(a,"keyup",i,s),ed(a,"keydown",o,s),e0.delete(a))}),e0.clear(),Object.keys(E2).forEach(a=>delete E2[a]),rd)){const{listener:a,capture:o}=rd;ed(window,"focus",a,o),rd=null}}const fH={getPressedKeyString:B0e,setScope:MP,getScope:ad,deleteScope:F0e,getPressedKeyCodes:N0e,getAllKeyCodes:P0e,isPressed:j0e,filter:I0e,trigger:q0e,unbind:AP,keyMap:td,modifier:Jr,modifierMap:nd};for(const e in fH)Object.prototype.hasOwnProperty.call(fH,e)&&(o4[e]=fH[e]);if(typeof window<"u"){const e=window.hotkeys;o4.noConflict=t=>(t&&window.hotkeys===o4&&(window.hotkeys=e),o4),window.hotkeys=o4}class $0e{constructor(t){oe(this,"id");oe(this,"instructionContext");oe(this,"plotContext");oe(this,"scopeContext");oe(this,"figure");this.figure=t,this.id=t.id,this.plotContext=new uH,this.scopeContext=new uH;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(m1.SUBPLOT);return}this.scopeContext.push(m1.TRACE);const l=t.activeSubplot.state;if(l.empty||l.size!==1){this.instructionContext=t.activeSubplot,this.plotContext.push(t.activeSubplot),this.plotContext.push(t.activeSubplot.activeTrace);return}this.instructionContext=t.activeSubplot.activeTrace,this.plotContext.push(t.activeSubplot.activeTrace)}dispose(){this.plotContext.clear(),this.scopeContext.clear()}get active(){return this.plotContext.peek()}get state(){return this.active.state}toggleScope(t){this.scopeContext.clear(),this.scopeContext.push(t),o4.setScope(t)}get scope(){return this.scopeContext.peek()}isMovable(t){return this.active.isMovable(t)}moveOnce(t){this.active.moveOnce(t)}moveToExtreme(t){this.active.moveToExtreme(t)}moveToIndex(t,n){this.active.moveToIndex(t,n)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const n=this.active,l=n.activeTrace;if(!l)return;const a=l.getCurrentXValue();n.moveOnce(t);const o=n.activeTrace;if(this.plotContext.push(o),o.getId()===l.getId()){o.notifyOutOfBounds(),n.notifyOutOfBounds();return}if(o.moveToXValue(a),o.state.empty)o.notifyStateUpdate();else{const i=n.getRow()+1,s=n.getSize(),c={...o.state,isLayerSwitch:!0,index:i,size:s};o.notifyObserversWithState(c)}}else{const n=this.figure.subplots[0][0];this.active.notifyOutOfBounds(),n.notifyOutOfBounds()}}enterSubplot(){if(this.active.state.type==="figure"){const n=this.active;this.plotContext.push(n.activeSubplot);const l=n.activeSubplot.activeTrace;l.resetToInitialEntry(),this.plotContext.push(l),this.toggleScope(m1.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(m1.TRACE))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const l=t?"Click to activate.":Le.EMPTY;switch(n.type){case"figure":return`This is a maidr figure containing ${n.size} subplots. ${l} Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a maidr plot containing ${n.size} layers, and this is layer 1 of ${n.size}: ${n.trace.traceType} plot. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`;case"trace":{let a=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(a="single line");const o=a==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${a}${o}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}function U0e(e){return e!==null&&typeof e=="object"&&"x"in e}function G0e(e){return typeof e=="string"||typeof e=="number"}function Z0e(e){return e!==null&&typeof e=="object"&&"x"in e}class CP{computeIndexAndSegment(t,n,l,a){return l===F2.HORIZONTAL?{pointIndex:t,segmentType:a[n]}:{pointIndex:n,segmentType:a[t]}}computeVisualCoordinates(t,n,l){return l===F2.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const a=t[0][l];return this.extractXFromPoint(a)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][l]){const a=t[n][l];return this.extractXFromPoint(a)}return null}extractXValueFromValues(t,n,l){if(this.isValidPosition(t,n,l)){const a=t[n][l];return this.extractXFromValue(a)}return null}moveToXValueInPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const c=this.findPointIndexByX(t[0],n);if(c!==-1)return l(0,c),!0;{const u=this.findNearestPointIndexByX(t[0],n);if(u!==-1){const Q=ni(t[0][u]);if(typeof n=="number"&&typeof Q=="number")return l(0,u),!0;if(typeof n=="string"&&typeof Q=="string")return l(0,u),!0}}}let a=-1,o=-1,i=Number.POSITIVE_INFINITY,s=null;if(Array.isArray(t))for(let c=0;c<t.length;c++){const u=t[c];if(Array.isArray(u)){const Q=this.findPointIndexByX(u,n);if(Q!==-1)return l(c,Q),!0;const f=this.findNearestPointIndexByX(u,n);if(f!==-1){const h=ni(u[f]);let p=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof h=="number"?(p=Math.abs(h-n),p<i&&(i=p,a=c,o=f,s="numeric")):typeof n=="string"&&typeof h=="string"?a===-1&&(a=c,o=f,s="categorical"):a===-1&&(a=c,o=f,s="generic")}}}if(a!==-1&&o!==-1){const c=t[a];if(Array.isArray(c)&&ni(c[o]),s!==null)return l(a,o),!0}return!1}moveToXValueInValues(t,n,l){let a=-1,o=-1,i=Number.POSITIVE_INFINITY,s=null;for(let c=0;c<t.length;c++)for(let u=0;u<t[c].length;u++){const Q=t[c][u],f=this.extractXFromValue(Q);if(f===n)return l(c,u),!0;if(typeof n=="number"&&typeof f=="number"){const h=Math.abs(f-n);h<i&&(i=h,a=c,o=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?a===-1&&(a=c,o=u,s="categorical"):a===-1&&(a=c,o=u,s="generic")}return a!==-1&&o!==-1?(this.extractXFromValue(t[a][o]),l(a,o),!0):!1}extractXFromPoint(t){return Z0e(t)?t.x:null}extractXFromValue(t){return U0e(t)?t.x:G0e(t)?t:null}findPointIndexByX(t,n){return t.findIndex(l=>l.x===n)}isValidPosition(t,n,l){return n>=0&&n<t.length&&l>=0&&l<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let l=-1,a=Number.POSITIVE_INFINITY;for(let o=0;o<t.length;o++){const i=ni(t[o]);if(typeof i=="number"){const s=Math.abs(i-n);s<a&&(a=s,l=o)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<a&&(a=c,l=o)}}}if(l!==-1)return ni(t[l]),l}else if(typeof n=="string"){for(let a=0;a<t.length;a++)if(ni(t[a])===n)return a;const l=Number(n);if(!Number.isNaN(l)){let a=-1,o=Number.POSITIVE_INFINITY;for(let i=0;i<t.length;i++){const s=ni(t[i]);if(typeof s=="number"){const c=Math.abs(s-l);c<o&&(o=c,a=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-l);u<o&&(o=u,a=i)}}}if(a!==-1)return ni(t[a]),a}for(let a=0;a<t.length;a++)if(typeof ni(t[a])=="string")return a}return t.length>0?(ni(t[0]),0):-1}dispose(){}}function X0e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function W0e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function Y0e(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function K0e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function J0e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function eoe(e){return e&&typeof e=="object"&&"value"in e}function ni(e){return e?X0e(e)||W0e(e)||K0e(e)||J0e(e)||Y0e(e)?e.x:eoe(e)?e.value:null:null}const toe="unavailable",noe="X",roe="Y",ioe="unavailable";class dH{constructor(){oe(this,"observers");oe(this,"isInitialEntry");oe(this,"isOutOfBounds");oe(this,"row");oe(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}getSafeIndices(){var a;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,l=this.col>=0&&this.col<(((a=t[n])==null?void 0:a.length)||0)?this.col:0;return{row:n,col:l}}moveToExtreme(t){var n;switch(this.isInitialEntry&&this.handleInitialEntry(),t){case"UPWARD":this.row=this.values.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":{const{row:l}=this.getSafeIndices();this.col=(n=this.values[l])!=null&&n.length?this.values[l].length-1:0;break}case"BACKWARD":this.col=0;break}this.notifyStateUpdate()}moveToIndex(t,n){this.isMovable([t,n])&&(this.row=t,this.col=n,this.isInitialEntry=!1,this.notifyStateUpdate())}isMovable(t){var n,l;if(Array.isArray(t)){const[a,o]=t,{row:i}=this.getSafeIndices();return a>=0&&a<this.values.length&&o>=0&&o<(((n=this.values[i])==null?void 0:n.length)||0)}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":{const{row:a}=this.getSafeIndices();return this.col<(((l=this.values[a])==null?void 0:l.length)||0)-1}case"BACKWARD":return this.col>0}}handleInitialEntry(){var n;this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.values.length-1));const{row:t}=this.getSafeIndices();this.col=Math.max(0,Math.min(this.col,(((n=this.values[t])==null?void 0:n.length)||0)-1))}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){const t=this.state;for(const n of this.observers)n.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}}class Ru extends dH{constructor(n){var l,a,o;super();oe(this,"id");oe(this,"type");oe(this,"title");oe(this,"xAxis");oe(this,"yAxis");oe(this,"fill");oe(this,"navigationService");this.navigationService=new CP,this.id=n.id,this.type=n.type,this.title=n.title??toe,this.xAxis=((l=n.axes)==null?void 0:l.x)??noe,this.yAxis=((a=n.axes)==null?void 0:a.y)??roe,this.fill=((o=n.axes)==null?void 0:o.fill)??ioe}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(o=>o.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const l=this.values,a=this.row,o=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=l[a])==null?void 0:n.length)||0,index:o}}}return{empty:!1,type:"trace",traceType:this.type,plotType:this.type,title:this.title,xAxis:this.xAxis,yAxis:this.yAxis,fill:this.fill,hasMultiPoints:this.hasMultiPoints(),audio:this.audio(),braille:this.braille(),text:this.text(),autoplay:this.autoplay,highlight:this.highlight()}}highlight(){var n;if(this.highlightValues===null||this.isInitialEntry){const l=this.values,a=this.row,o=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=l[a])==null?void 0:n.length)||0,index:o}}}return{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){var a;const{row:n}=this.getSafeIndices(),l=((a=this.values[n])==null?void 0:a.length)||0;return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:l,BACKWARD:l}}hasMultiPoints(){return!1}getCurrentXValue(){if(this.hasPointsArray()){const n=this.getPointsArray();if(this.isValidPointsArray(n))return this.navigationService.extractXValueFromPoints(n,this.row,this.col)}if(this.hasValuesArray()){const n=this.values;if(this.isValidValuesArray(n))return this.navigationService.extractXValueFromValues(n,this.row,this.col)}return null}moveToXValue(n){if(this.hasPointsArray()){const l=this.getPointsArray();if(this.isValidPointsArray(l))return this.navigationService.moveToXValueInPoints(l,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const l=this.values;if(this.isValidValuesArray(l))return this.navigationService.moveToXValueInValues(l,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}getId(){return this.id}}class l4{constructor(){}static safeMin(t){return t.length===0?1/0:Math.min(...t)}static safeMax(t){return t.length===0?-1/0:Math.max(...t)}static minFrom2D(t){const n=t.flat();return this.safeMin(n)}static maxFrom2D(t){const n=t.flat();return this.safeMax(n)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let n=t[0],l=t[0];for(let a=1;a<t.length;a++){const o=t[a];o<n&&(n=o),o>l&&(l=o)}return{min:n,max:l}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class cg{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let a=n.substring(1).split("");return a.length===3&&(a=[a[0],a[0],a[1],a[1],a[2],a[2]]),{r:Number.parseInt(a[0]+a[1],16),g:Number.parseInt(a[2]+a[3],16),b:Number.parseInt(a[4]+a[5],16)}}const l=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return l?{r:Number.parseInt(l[1],10),g:Number.parseInt(l[2],10),b:Number.parseInt(l[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const l=this.calculateLuminance(t),a=this.calculateLuminance(n);return(Math.max(l,a)+.05)/(Math.min(l,a)+.05)}static calculateLuminance(t){const[n,l,a]=[t.r,t.g,t.b].map(o=>{const i=o/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*l+.0722*a}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class zt{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),a=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,o=await new Promise((c,u)=>{const Q=new Image;Q.onload=()=>c(Q),Q.onerror=()=>u(new Error("Failed to load SVG image")),Q.src=a}),i=document.createElement("canvas");[i.width,i.height]=[o.naturalWidth,o.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(o,0,0),i.toDataURL("image/jpeg",.92)):(console.error("Error converting SVG to Base 64: Canvas context unavailable"),"")}catch(n){return console.error("Error converting SVG to Base 64:",n instanceof Error?n.message:n),""}}static selectAllElements(t,n=!0){return Array.from(document.querySelectorAll(t)).map(l=>{if(!n)return l;const a=l.cloneNode(!0);return a.setAttribute(Le.VISIBILITY,Le.HIDDEN),l.insertAdjacentElement(Le.AFTER_END,a),a})}static selectElement(t,n=!0){const l=document.querySelector(t);if(!n)return l;const a=l==null?void 0:l.cloneNode(!0);return a==null||a.setAttribute(Le.VISIBILITY,Le.HIDDEN),l==null||l.insertAdjacentElement(Le.AFTER_END,a),a}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(Le.FILL,Le.TRANSPARENT),n.setAttribute(Le.STROKE,Le.TRANSPARENT),n.setAttribute(Le.VISIBILITY,Le.HIDDEN),n}static createCircleElement(t,n,l){var u;const a=window.getComputedStyle(l),o=a.stroke||a.fill,i=a.strokeWidth||"2",s=Number.parseFloat(i)*2,c=document.createElementNS(this.SVG_NAMESPACE,Le.CIRCLE);return c.setAttribute(Le.CIRCLE_X,String(t)),c.setAttribute(Le.CIRCLE_Y,String(n)),c.setAttribute(Le.RADIUS,String(s)),c.setAttribute(Le.FILL,o),c.setAttribute(Le.STROKE,o),c.setAttribute(Le.STROKE_WIDTH,i),c.setAttribute(Le.VISIBILITY,Le.HIDDEN),(u=l.parentElement)==null||u.insertAdjacentElement(Le.AFTER_END,c),c}static createLineElement(t,n){const a=t.getBBox();let o,i,s,c;switch(n){case"top":[o,i,s,c]=[a.x,a.y,a.x+a.width,a.y];break;case"bottom":[o,i,s,c]=[a.x,a.y+a.height,a.x+a.width,a.y+a.height];break;case"left":[o,i,s,c]=[a.x,a.y,a.x,a.y+a.height];break;case"right":[o,i,s,c]=[a.x+a.width,a.y,a.x+a.width,a.y+a.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,Le.LINE);return Q.setAttribute(Le.X1,String(o)),Q.setAttribute(Le.Y1,String(i)),Q.setAttribute(Le.X2,String(s)),Q.setAttribute(Le.Y2,String(c)),Q.setAttribute(Le.STROKE,u.stroke),Q.setAttribute(Le.STROKE_WIDTH,u.strokeWidth||"2"),Q.setAttribute(Le.VISIBILITY,Le.HIDDEN),t.insertAdjacentElement(Le.AFTER_END,Q),Q}static createHighlightElement(t,n){const l=t.cloneNode(!0),a=t.tagName.toLowerCase(),o=a===Le.POLYLINE||a===Le.LINE,i=o?window.getComputedStyle(t).getPropertyValue(Le.STROKE):window.getComputedStyle(t).getPropertyValue(Le.FILL),s=this.getHighlightColor(i,n);if(l.setAttribute(Le.VISIBILITY,Le.VISIBLE),l.setAttribute(Le.STROKE,s),l.setAttribute(Le.FILL,s),l.style.fill=s,l.style.stroke=s,o){const c=window.getComputedStyle(l).getPropertyValue(Le.STROKE_WIDTH);l.setAttribute(Le.STROKE_WIDTH,`${c+2}`)}return t.insertAdjacentElement(Le.AFTER_END,l),l}static getHighlightColor(t,n){const l=cg.parse(t);if(!l||!(cg.getContrastRatio(l,Le.HIGHLIGHT_BASE_COLOR)<Le.HIGHLIGHT_CONTRAST_RATIO))return n;const i={...l};return l.r===l.g&&l.g===l.b?(i.r=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*Le.HIGHLIGHT_COLOR_RATIO)),i.g=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*Le.HIGHLIGHT_COLOR_RATIO)),i.b=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*Le.HIGHLIGHT_COLOR_RATIO))):l.r>=l.g&&l.r>=l.b?i.r=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*Le.HIGHLIGHT_COLOR_RATIO)):l.g>=l.r&&l.g>=l.b?i.g=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*Le.HIGHLIGHT_COLOR_RATIO)):i.b=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*Le.HIGHLIGHT_COLOR_RATIO)),cg.rgbToString(i)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",l=cg.parse(n);return l?(.2126*l.r+.7152*l.g+.0722*l.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,n){t.style.outline=`4px solid ${n}`,t.style.outlineOffset="3px",t.style.borderRadius="3px",t.style.overflow="visible"}static removeSubplotHighlightCss(t){t.style.removeProperty("outline"),t.style.removeProperty("outline-offset"),t.style.removeProperty("border-radius"),t.style.removeProperty("overflow")}static setSubplotHighlightSvgWithAdaptiveColor(t,n,l){const a=t.querySelector("rect, path");let o="";if(a){o=window.getComputedStyle(a).getPropertyValue("fill"),(!o||o==="none"||o==="transparent"||o==="rgba(0, 0, 0, 0)")&&(l?o=window.getComputedStyle(l).getPropertyValue("fill"):o=n);const i=this.getHighlightColor(o,n);a.setAttribute("stroke",i),a.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}oe(zt,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class hH extends Ru{constructor(n,l){super(n);oe(this,"points");oe(this,"barValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"min");oe(this,"max");this.points=l,this.orientation=n.orientation??F2.VERTICAL,this.barValues=l.map(a=>a.map(o=>this.orientation===F2.VERTICAL?Number(o.y):Number(o.x))),this.min=this.barValues.map(a=>l4.safeMin(a)),this.max=this.barValues.map(a=>l4.safeMax(a)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const n=this.orientation===F2.VERTICAL,l=n?this.barValues[this.row].length:this.barValues.length,a=n?this.col:this.row,o=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:l4.safeMin(this.min),max:l4.safeMax(this.max),size:l,index:a,value:o,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){const n=this.orientation===F2.VERTICAL,l=this.points[this.row][this.col],a=n?this.xAxis:this.yAxis,o=n?l.x:l.y,i=n?this.yAxis:this.xAxis,s=n?l.y:l.x;return{main:{label:a,value:o},cross:{label:i,value:s}}}mapToSvgElements(n){if(!n)return null;const l=[zt.selectAllElements(n)];if(l.length!==this.points.length)return null;for(let a=0;a<this.points.length;a++)if(l[a].length!==this.points[a].length)return null;return l}}class aoe extends hH{constructor(t){super(t,[t.data])}}const e5={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class ooe extends Ru{constructor(n){super(n);oe(this,"points");oe(this,"boxValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"sections");oe(this,"min");oe(this,"max");this.points=n.data,this.orientation=n.orientation??F2.VERTICAL,this.sections=[e5.LOWER_OUTLIER,e5.MIN,e5.Q1,e5.Q2,e5.Q3,e5.MAX,e5.UPPER_OUTLIER];const l=[o=>o.lowerOutliers,o=>o.min,o=>o.q1,o=>o.q2,o=>o.q3,o=>o.max,o=>o.upperOutliers];this.orientation===F2.HORIZONTAL?this.boxValues=this.points.map(o=>l.map(i=>i(o))):this.boxValues=l.map(o=>this.points.map(i=>o(i)));const a=this.boxValues.map(o=>o.flatMap(i=>Array.isArray(i)?i:[i]));this.min=l4.minFrom2D(a),this.max=l4.maxFrom2D(a),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,l){const a=this.orientation===F2.HORIZONTAL;n=a?n:l,l=a?l:n,super.moveToIndex(n,l)}get values(){return this.boxValues}audio(){const n=this.boxValues[this.row][this.col],l=Array.isArray(n)?n.map(a=>a-this.min):n-this.min;return{min:this.min,max:this.max,value:n,size:this.max-this.min,index:l}}braille(){const n=this.orientation===F2.HORIZONTAL,l=n?this.row:this.col,a=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:l,col:a}}text(){const n=this.orientation===F2.HORIZONTAL,l=n?this.points[this.row]:this.points[this.col],a=n?this.yAxis:this.xAxis,o=n?this.sections[this.col]:this.sections[this.row],i=n?this.xAxis:this.yAxis,s=this.boxValues[this.row][this.col];return{main:{label:a,value:l.fill},cross:{label:i,value:s},section:o}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const l=this.orientation===F2.VERTICAL,a=new Array;if(l)for(let o=0;o<this.sections.length;o++)a.push(Array.from({length:n.length}));return n.forEach((o,i)=>{const s=o.lowerOutliers.flatMap(L=>zt.selectAllElements(L)),c=o.upperOutliers.flatMap(L=>zt.selectAllElements(L)),u=zt.selectElement(o.min)??zt.createEmptyElement(),Q=zt.selectElement(o.max)??zt.createEmptyElement(),f=zt.selectElement(o.iq)??zt.createEmptyElement(),h=zt.selectElement(o.q2)??zt.createEmptyElement(),[p,g]=l?[zt.createLineElement(f,"top"),zt.createLineElement(f,"bottom")]:[zt.createLineElement(f,"left"),zt.createLineElement(f,"right")],v=[s,u,p,h,g,Q,c];l?v.forEach((L,x)=>{a[x][i]=L}):a.push(v)}),a}}const loe="trend",wP=100;class soe extends Ru{constructor(n){super(n);oe(this,"candles");oe(this,"candleValues");oe(this,"orientation");oe(this,"sections",["volatility","open","high","low","close"]);oe(this,"currentSegmentType","open");oe(this,"currentPointIndex",0);oe(this,"sortedSegmentsByPoint");oe(this,"segmentPositionMaps");oe(this,"min");oe(this,"max");oe(this,"highlightValues");oe(this,"navigationService");this.navigationService=new CP;const l=n.data;this.candles=l.map(a=>({...a,volatility:Math.round((a.high-a.low)*wP)/wP,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=n.orientation??F2.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(o=>o[a])),this.min=l4.minFrom2D(this.candleValues),this.max=l4.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===F2.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors)}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(o=>[o,n[o]]).sort((o,i)=>o[1]-i[1]).map(o=>o[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const l=new Map;return n.forEach((a,o)=>{l.set(a,o)}),l})}getSegmentPositionInSortedOrder(n,l){return this.segmentPositionMaps[n].get(l)??0}getSegmentTypeAtSortedPosition(n,l){return this.sortedSegmentsByPoint[n][l]??"open"}updateVisualSegmentPosition(){const l=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===F2.HORIZONTAL?this.col=l:this.row=l}updateVisualPointPosition(){this.orientation===F2.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex}handleInitialEntry(){this.isInitialEntry=!1,this.currentPointIndex=Math.max(0,Math.min(this.currentPointIndex,this.candles.length-1)),this.currentSegmentType="close",this.updateVisualSegmentPosition()}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex],a=l.indexOf(this.currentSegmentType??"open");if(a===-1){this.notifyOutOfBounds();return}const o=n==="UPWARD"?a+1:a-1;if(o>=0&&o<l.length)this.currentSegmentType=l[o],this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(l>=0&&l<this.candles.length)this.currentPointIndex=l,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[l.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[0],this.updateVisualSegmentPosition();break}case"FORWARD":{this.currentPointIndex=this.candles.length-1,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}case"BACKWARD":{this.currentPointIndex=0,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}}this.notifyStateUpdate()}moveToIndex(n,l){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:a,segmentType:o}=this.navigationService.computeIndexAndSegment(n,l,this.orientation,this.sections);this.currentPointIndex=a,this.currentSegmentType=o,this.row=n,this.col=l,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex],a=l.indexOf(this.currentSegmentType??"open"),o=n==="UPWARD"?a+1:a-1;return o>=0&&o<l.length}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return l>=0&&l<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){let n;return this.currentSegmentType==="volatility"?n=this.candles[this.currentPointIndex].volatility:this.currentSegmentType?n=this.candles[this.currentPointIndex][this.currentSegmentType]:n=this.candles[this.currentPointIndex].open,{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:n,trend:this.candles[this.currentPointIndex].trend}}braille(){const n=this.candles.map(i=>i.trend),l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=l;const a=this.candleValues.map(i=>Math.min(...i)),o=this.candleValues.map(i=>Math.max(...i));return{empty:!1,id:this.id,values:this.candleValues,min:a,max:o,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const l=Array.isArray(n)?n:[n],a=[];for(const o of l)a.push(...zt.selectAllElements(o));return a}getElementAt(n,l){return l<n.length?n[l]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const g=Array.isArray(n)?n[0]||"":n,v=zt.selectAllElements(g),L=[];for(let x=0;x<this.sections.length;x++){L[x]=[];for(let S=0;S<this.candles.length;S++){const _=S<v.length?S:0;L[x][S]=v[_]}}return L}const l=n,a=this.candles.length,o=this.collectElements(l.body);let i=this.collectElements(l.wickHigh),s=this.collectElements(l.wickLow);if(i.length===0||s.length===0){const g=this.collectElements(l.wick);g.length>0&&(i.length===0&&(i=g),s.length===0&&(s=g))}const c=this.collectElements(l.open),u=this.collectElements(l.close),Q=Array.from({length:a},()=>zt.createEmptyElement()),f=Array.from({length:a},()=>zt.createEmptyElement()),h=Array.from({length:a},()=>zt.createEmptyElement());for(let g=0;g<a;g++){let v=this.getElementAt(c,g);if(!v){const x=this.getElementAt(o,g);if(x){const{open:S,close:_}=this.candles[g],O=_>S?"bottom":_<S?"top":"bottom";v=zt.createLineElement(x,O)}else v=zt.createEmptyElement()}Q[g]=v;let L=this.getElementAt(u,g);if(!L){const x=this.getElementAt(o,g);if(x){const{open:S,close:_}=this.candles[g],O=_>S?"top":_<S?"bottom":"top";L=zt.createLineElement(x,O)}else L=zt.createEmptyElement()}f[g]=L,h[g]=zt.createEmptyElement()}const p=Array.from({length:this.sections.length},()=>Array.from({length:a},()=>zt.createEmptyElement()));for(let g=0;g<a;g++){const v=this.sortedSegmentsByPoint[g];for(let L=0;L<v.length;L++){const x=v[L];let S;switch(x){case"volatility":{const _=[],O=this.getElementAt(o,g),M=this.getElementAt(i,g)??O,A=this.getElementAt(s,g)??O;M&&_.push(M),O&&_.push(O),A&&_.push(A);const V=Array.from(new Set(_));S=V.length>0?V:[zt.createEmptyElement()]}break;case"open":S=Q[g];break;case"close":S=f[g];break;case"high":S=this.getElementAt(i,g)??this.getElementAt(o,g)??zt.createEmptyElement();break;case"low":S=this.getElementAt(s,g)??this.getElementAt(o,g)??zt.createEmptyElement();break;default:S=zt.createEmptyElement()}p[L][g]=S}}return p}text(){const n=this.candles[this.currentPointIndex];let l;return this.currentSegmentType==="volatility"?l=n.volatility:this.currentSegmentType?l=n[this.currentSegmentType]:l=n.open,{main:{label:this.orientation===F2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===F2.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType??"open",fill:{label:loe,value:n.trend}}}getCurrentTrend(){return this.candles[this.currentPointIndex].trend}getCurrentXValue(){return this.currentPointIndex>=0&&this.currentPointIndex<this.candles.length?this.candles[this.currentPointIndex].value:null}moveToXValue(n){const l=this.candles.findIndex(a=>a.value===n);return l!==-1?(this.currentPointIndex=l,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getExtremaTargets(){const n=[],l=this.currentSegmentType??"open";if(l==="volatility"){const a=this.candles.map(s=>s.volatility),o=a.indexOf(Math.max(...a)),i=a.indexOf(Math.min(...a));n.push({label:"Max Volatility",value:this.candles[o].volatility,pointIndex:o,segment:"volatility",type:"max"}),n.push({label:"Min Volatility",value:this.candles[i].volatility,pointIndex:i,segment:"volatility",type:"min"})}else{const a=this.candles.map(s=>s[l]),o=a.indexOf(Math.max(...a)),i=a.indexOf(Math.min(...a));n.push({label:`Max ${l.charAt(0).toUpperCase()+l.slice(1)}`,value:this.candles[o][l],pointIndex:o,segment:l,type:"max"}),n.push({label:`Min ${l.charAt(0).toUpperCase()+l.slice(1)}`,value:this.candles[i][l],pointIndex:i,segment:l,type:"min"})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate()}}class uoe extends Ru{constructor(n){super(n);oe(this,"heatmapValues");oe(this,"highlightValues");oe(this,"x");oe(this,"y");oe(this,"min");oe(this,"max");const l=n.data;this.x=l.x,this.y=[...l.y].reverse(),this.heatmapValues=[...l.points].reverse();const{min:a,max:o}=l4.minMaxFrom2D(this.heatmapValues);this.min=a,this.max=o,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get values(){return this.heatmapValues}audio(){return{min:this.min,max:this.max,size:this.heatmapValues.length,index:this.col,value:this.heatmapValues[this.row][this.col]}}braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){return{main:{label:this.xAxis,value:this.x[this.col]},cross:{label:this.yAxis,value:this.y[this.row]},fill:{label:this.fill,value:String(this.heatmapValues[this.row][this.col])}}}mapToSvgElements(n){if(!n)return null;const l=this.heatmapValues.length,a=this.heatmapValues[0].length,o=zt.selectAllElements(n);if(o.length===0||o.length!==l*a)return null;const i=new Array;if(o[0]instanceof SVGPathElement)for(let s=0;s<l;s++){const c=l-1-s,u=new Array;for(let Q=0;Q<a;Q++){const f=c*a+Q;u.push(o[f])}i.push(u)}else if(o[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const c=new Array;for(let u=0;u<a;u++){const Q=u*l+s;c.push(o[Q])}i.push(c)}return i}}class coe extends hH{constructor(t){super(t,[t.data])}text(){const t=this.orientation===F2.VERTICAL,n=this.points[this.row][this.col],l=t?n.xMin:n.yMin,a=t?n.xMax:n.yMax;return{...super.text(),range:{min:l,max:a}}}}const VP="Group",pH=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class DP extends Ru{constructor(n){super(n);oe(this,"points");oe(this,"lineValues");oe(this,"highlightValues");oe(this,"min");oe(this,"max");oe(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(l=>l.map(a=>Number(a.y))),this.min=this.lineValues.map(l=>l4.safeMin(l)),this.max=this.lineValues.map(l=>l4.safeMax(l)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.lineValues}audio(){return{min:this.min[this.row],max:this.max[this.row],size:this.points[this.row].length,index:this.col,value:this.points[this.row][this.col].y,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){var o;const n=this.points[this.row][this.col],l=this.findIntersections();let a={};if(l.length>1){let i=l.map(s=>{var u;const c=s.groupIndex;return((u=this.points[c][0])==null?void 0:u.fill)||`l${c+1}`});if(this.previousRow!==null){const s=((o=this.points[this.previousRow][0])==null?void 0:o.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}a={fill:{label:VP,value:`intersection at (${i.join(", ")})`}}}else a=n.fill?{fill:{label:VP,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...a}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const a=this.findLineByXAndYDirection(n),o=this.points[this.row][this.col].x;if(a!==null&&a!==this.row){const i=this.findColumnByXValue(a,o);if(i!==-1){this.row=a,this.col=i;const s=this.findIntersections();if(s.length>1){const u={...super.state,intersections:s};for(const Q of this.observers)Q.update(u)}else this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}else{this.notifyOutOfBounds();return}}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const l=this.findIntersections();if(l.length>1){const o={...super.state,intersections:l};for(const i of this.observers)i.update(o)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,l=this.points[this.row][this.col].y,a=[];for(let o=0;o<this.points.length;o++){const i=this.points[o].findIndex(s=>s.x===n&&s.y===l);i!==-1&&a.push({min:this.min[o],max:this.max[o],size:this.points[o].length,index:i,value:l,groupIndex:o})}return a}isMovable(n){if(Array.isArray(n)){const[l,a]=n;return l>=0&&l<this.values.length&&a>=0&&a<this.values[l].length}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.findLineByXAndYDirection(n);if(l===null)return!1;const a=this.points[this.row][this.col].x;return this.findColumnByXValue(l,a)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const l=this.points[this.row][this.col].x;let a=null,o=Number.POSITIVE_INFINITY;for(let i=0;i<this.points.length;i++){if(i===this.row)continue;const s=this.points[i].findIndex(f=>f.x===l);if(s===-1)continue;const c=this.points[i][s].y,u=n==="UPWARD"?c>this.points[this.row][this.col].y:c<this.points[this.row][this.col].y,Q=Math.abs(c-this.points[this.row][this.col].y);u&&Q<o&&(o=Q,a=i)}return a}findColumnByXValue(n,l){return this.points[n].findIndex(a=>a.x===l)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const l=[];let a=!0;for(let o=0;o<n.length;o++){const i=zt.selectElement(n[o],!1);if(!i){l.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(Le.D)||Le.EMPTY;pH.lastIndex=0;let f=pH.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=pH.exec(Q)}else if(i instanceof SVGPolylineElement){const f=(i.getAttribute(Le.POINTS)||Le.EMPTY).split(/\s+/).filter(Boolean);for(const h of f){const[p,g]=h.split(Le.COMMA);s.push({x:Number.parseFloat(p),y:Number.parseFloat(g)})}}if(s.length!==this.lineValues[o].length)if(s.length<this.lineValues[o].length)for(;s.length<this.lineValues[o].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[o].length&&(s.length=this.lineValues[o].length);const c=[];let u=!1;for(const Q of s){if(Number.isNaN(Q.x)||Number.isNaN(Q.y)){u=!0;break}c.push(zt.createCircleElement(Q.x,Q.y,i))}if(u){l.push([]);continue}c.length>0&&(a=!1),l.push(c)}return a?null:l}get state(){const n=super.state;if(n.empty)return n;const l=this.points.length>1,a={...n,plotType:l?"multiline":"single line",...l&&{groupCount:this.points.length}},o=this.findIntersections();return o.length>1?{...a,intersections:o}:a}}class Toe extends Ru{constructor(n){super(n);oe(this,"mode");oe(this,"xPoints");oe(this,"yPoints");oe(this,"xValues");oe(this,"yValues");oe(this,"highlightXValues");oe(this,"highlightYValues");oe(this,"minX");oe(this,"maxX");oe(this,"minY");oe(this,"maxY");this.mode="column";const l=n.data,a=[...l].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let o=null;for(const c of a)(!o||o.x!==c.x)&&(o={x:c.x,y:[]},this.xPoints.push(o)),o.y.push(c.y);const i=[...l].sort((c,u)=>c.y-u.y||c.x-u.x);this.yPoints=new Array;let s=null;for(const c of i)(!s||s.y!==c.y)&&(s={y:c.y,x:[]},this.yPoints.push(s)),s.x.push(c.x);this.xValues=this.xPoints.map(c=>c.x),this.yValues=this.yPoints.map(c=>c.y),this.minX=l4.safeMin(this.xValues),this.maxX=l4.safeMax(this.xValues),this.minY=l4.safeMin(this.yValues),this.maxY=l4.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors)}dispose(){this.xPoints.length=0,this.yPoints.length=0,this.xValues.length=0,this.yValues.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightYValues.length=0),super.dispose()}get values(){const n=[this.xValues,this.yValues];return this.mode==="column"?this.row!==0&&(this.row=0):(this.row<0||this.row>=this.yPoints.length)&&(this.row=0),n}get highlightValues(){return this.mode==="column"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}audio(){if(this.mode==="column"){const n=this.xPoints[this.col];return{min:this.minY,max:this.maxY,size:n.y.length,index:this.col,value:n.y,...this.getAudioGroupIndex()}}else{const n=this.yPoints[this.row];return{min:this.minX,max:this.maxX,size:n.x.length,index:this.row,value:n.x,...this.getAudioGroupIndex()}}}braille(){return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}text(){if(this.mode==="column"){const n=this.xPoints[this.col];return{main:{label:this.xAxis,value:n.x},cross:{label:this.yAxis,value:n.y}}}else{const n=this.yPoints[this.row];return{main:{label:this.yAxis,value:n.y},cross:{label:this.xAxis,value:n.x}}}}get autoplay(){return{UPWARD:this.yValues.length,DOWNWARD:this.yValues.length,FORWARD:this.xValues.length,BACKWARD:this.xValues.length}}highlight(){if(this.highlightValues===null)return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}};const n=this.mode==="column"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return n?{empty:!1,elements:n}:{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}hasMultiPoints(){return!0}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0,this.mode="column"}toggleNavigation(){if(this.mode==="column"){const n=this.xPoints[this.col],l=n.y[Math.floor(n.y.length/2)],a=this.yValues.indexOf(l);a===-1||a>=this.yPoints.length?this.row=0:this.row=a,this.mode="row"}else{const n=this.yPoints[this.row],l=n.x[Math.floor(n.x.length/2)],a=this.xValues.indexOf(l);a===-1||a>=this.xPoints.length?this.col=0:this.col=a,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const l=zt.selectAllElements(n);if(l.length===0)return[null,null];const a=new Map,o=new Map;l.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(a.has(u)||a.set(u,[]),a.get(u).push(c)),Number.isNaN(Q)||(o.has(Q)||o.set(Q,[]),o.get(Q).push(c))});const i=Array.from(a.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(o.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const RP="Sum",Qoe="Level",foe="undefined";class doe extends hH{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let o=0;o<this.barValues[0].length;o++){const i=this.barValues.reduce((c,u)=>c+u[o],0);t.push(i);const s=this.orientation===F2.VERTICAL?{x:this.points[0][o].x,y:i,fill:RP}:{x:i,y:this.points[0][o].y,fill:RP};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:l,max:a}=l4.minMax(t);this.min.push(l),this.max.push(a)}text(){return{...super.text(),fill:{label:Qoe,value:this.points[this.row][this.col].fill??foe}}}highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}hasMultiPoints(){return!1}mapToSvgElements(t){if(!t)return new Array;const n=zt.selectAllElements(t);if(n.length===0)return new Array;const l=new Array;if(n[0]instanceof SVGPathElement)for(let a=0,o=0;a<this.barValues.length;a++){const i=new Array;for(let s=0;s<this.barValues[a].length;s++){if(o>=n.length)return new Array;this.barValues[a][s]===0?i.push(zt.createEmptyElement()):i.push(n[o++])}l.push(i)}else if(n[0]instanceof SVGRectElement){for(let a=0;a<this.barValues.length;a++)l.push(new Array);for(let a=0,o=0;a<this.barValues[0].length;a++)for(let i=this.barValues.length-1;i>=0;i--){if(o>=n.length)return new Array;this.barValues[i][a]===0?l[i].push(zt.createEmptyElement()):l[i].push(n[o++])}}return l}}class kP extends DP{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],n=this.col,l=s=>t[Math.max(0,Math.min(s,t.length-1))],a=n>0?l(n-1):l(n),o=l(n),i=n<t.length-1?l(n+1):l(n);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:n,value:[a,o,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class hoe extends kP{constructor(t){super(t)}mapToSvgElements(t){var a;if(!t||t.length!==this.lineValues.length)return null;const n=[];let l=!0;for(let o=0;o<t.length;o++){const i=zt.selectElement(t[o],!1);if(!i){n.push([]);continue}const s=(a=this.points)==null?void 0:a[o],c=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&c.push(zt.createCircleElement(u.svg_x,u.svg_y,i));c.length>0&&(l=!1),n.push(c)}return l?null:n}}function poe(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function moe(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&poe(e.data[0][0])?new hoe(e):new kP(e)}class yoe{static create(t){switch(t.type){case H2.BAR:return new aoe(t);case H2.BOX:return new ooe(t);case H2.CANDLESTICK:return new soe(t);case H2.HEATMAP:return new uoe(t);case H2.HISTOGRAM:return new coe(t);case H2.LINE:return new DP(t);case H2.SCATTER:return new Toe(t);case H2.SMOOTH:return moe(t);case H2.DODGED:case H2.NORMALIZED:case H2.STACKED:return new doe(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const goe="MAIDR Plot",voe="unavailable",xoe="unavailable";class Loe extends dH{constructor(n){super();oe(this,"id");oe(this,"title");oe(this,"subtitle");oe(this,"caption");oe(this,"subplots");oe(this,"size");this.id=n.id,this.title=n.title??goe,this.subtitle=n.subtitle??voe,this.caption=n.caption??xoe;const l=n.subplots;this.subplots=l.map(a=>a.map(o=>new boe(o))),this.size=this.subplots.reduce((a,o)=>a+o.length,0)}dispose(){this.subplots.forEach(n=>n.forEach(l=>l.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((a,o)=>a+o.length,0),l=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:l.getStateWithFigurePosition(this.row,this.col),traceTypes:l.traceTypes,highlight:this.highlight()}}highlight(){var l;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}};try{const a=((l=this.subplots[0])==null?void 0:l.length)||1,o=this.row*a+this.col+1,i=`g[id="axes_${o}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&o-1<c.length)return{empty:!1,elements:c[o-1]}}catch{return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}isMovable(n){switch(n){case"UPWARD":return this.row<this.subplots.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.subplots[this.row].length-1;case"BACKWARD":return this.col>0;default:return!1}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}}class boe extends dH{constructor(n){super();oe(this,"traces");oe(this,"traceTypes");oe(this,"size");this.isInitialEntry=!1;const l=n.layers;this.size=l.length,this.traces=l.map(a=>[yoe.create(a)]),this.traceTypes=this.traces.flat().map(a=>{const o=a.state;return o.empty?Le.EMPTY:o.traceType})}getRow(){return this.row}getSize(){return this.size}dispose(){this.traces.forEach(n=>n.forEach(l=>l.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}highlight(){return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}get state(){return this.isOutOfBounds?{empty:!0,type:"subplot"}:{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight()}}getStateWithFigurePosition(n,l){return this.state}}const s4={SINE_BASIC:0,SQUARE_BASIC:1,SAWTOOTH_BASIC:2,TRIANGLE_BASIC:3,SAWTOOTH_DARK:4,SINE_HARMONIC:5,TRIANGLE_HARMONIC:6,SQUARE_HARMONIC:7,TRIANGLE_MELLOW:8,SINE_SUBTLE:9,SAWTOOTH_SOFT:10},ku=class ku{constructor(){oe(this,"basePalette");oe(this,"extendedPalette");this.basePalette=[{index:s4.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:s4.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:s4.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:s4.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:s4.SAWTOOTH_DARK,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.2},{frequency:3,amplitude:.1},{frequency:5,amplitude:.05}]},timbreModulation:{attack:.005,decay:.3,sustain:.4,release:.5}},{index:s4.SINE_HARMONIC,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.15},{frequency:4,amplitude:.05}]},timbreModulation:{attack:.02,decay:.2,sustain:.6,release:.3}},{index:s4.TRIANGLE_HARMONIC,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.2},{frequency:6,amplitude:.1}]},timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:s4.SQUARE_HARMONIC,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.1},{frequency:7,amplitude:.05}]},timbreModulation:{attack:.005,decay:.05,sustain:.5,release:.1}},{index:s4.TRIANGLE_MELLOW,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:2.5,amplitude:.15},{frequency:4.5,amplitude:.08}]},timbreModulation:{attack:.01,decay:.4,sustain:.3,release:.5}},{index:s4.SINE_SUBTLE,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.1},{frequency:3,amplitude:.05}]},timbreModulation:{attack:.02,decay:.1,sustain:.9,release:.15}},{index:s4.SAWTOOTH_SOFT,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.05},{frequency:6,amplitude:.02}]},timbreModulation:{attack:.005,decay:.4,sustain:.2,release:.6}}],this.validateBasePalette(),this.extendedPalette=new Map,this.generateExtendedPalette()}dispose(){this.extendedPalette.clear()}getPaletteEntry(t){if(t<this.basePalette.length)return this.basePalette[t];const n=this.extendedPalette.get(t);if(n)return n;const l=this.generateExtendedEntry(t);return this.extendedPalette.set(t,l),l}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return s4.SINE_BASIC;case"Bear":return s4.SAWTOOTH_SOFT;case"Neutral":return s4.TRIANGLE_BASIC;default:return s4.SINE_BASIC}}generateExtendedPalette(){[{index:this.basePalette.length,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.3},{frequency:3,amplitude:.15}]},timbreModulation:{attack:.02,decay:.15,sustain:.7,release:.3}},{index:this.basePalette.length+1,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:1.5,amplitude:.4},{frequency:2.5,amplitude:.2}]},timbreModulation:{attack:.01,decay:.08,sustain:.6,release:.4}},{index:this.basePalette.length+2,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:1.25,amplitude:.35},{frequency:2,amplitude:.25},{frequency:3,amplitude:.1}]},timbreModulation:{attack:.03,decay:.2,sustain:.5,release:.35}},{index:this.basePalette.length+3,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:.5,amplitude:.2},{frequency:4,amplitude:.15}]},timbreModulation:{attack:.025,decay:.18,sustain:.8,release:.25}}].forEach((n,l)=>{this.extendedPalette.set(this.basePalette.length+l,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,l=this.basePalette[n],a=Math.floor((t-this.basePalette.length)/this.basePalette.length),o=this.generateHarmonics(a),i=this.generateTimbreModulation(a,l.timbreModulation);return{index:t,waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:o},timbreModulation:i}}generateHarmonics(t){const n=[],l=ku.MIN_HARMONICS+t%ku.HARMONIC_VARIATION;for(let a=0;a<l;a++){const o=1+(a+1)*(.5+t*.3%1),i=.4/(a+1)*(1-t*.1%.3);n.push({frequency:o,amplitude:i})}return n}generateTimbreModulation(t,n){const l=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*l)),decay:Math.max(.05,Math.min(.3,n.decay*l)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*l))}}validateBasePalette(){this.basePalette.forEach((t,n)=>{if(t.index!==n)throw new Error(`AudioPalette validation error: Entry at array position ${n} has index ${t.index}. Array position must match the index property to prevent audio palette mismatches.`)})}};oe(ku,"MIN_HARMONICS",2),oe(ku,"HARMONIC_VARIATION",3);let mH=ku;const Hoe=100,Eoe=440,Soe=880,yH=.3,gH=s4.SINE_BASIC;class Moe{constructor(t,n,l){oe(this,"notification");oe(this,"audioPalette");oe(this,"settings");oe(this,"isCombinedAudio");oe(this,"mode");oe(this,"activeAudioIds");oe(this,"audioContext");oe(this,"compressor");oe(this,"currentVolume");oe(this,"currentMinFrequency");oe(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new mH,this.settings=l,this.isCombinedAudio=!1,this.mode="on",this.updateMode(n),this.activeAudioIds=new Map,this.audioContext=new AudioContext,this.compressor=this.initCompressor();const a=this.settings.loadSettings();this.currentVolume=a.general.volume/100,this.currentMinFrequency=a.general.minFrequency,this.currentMaxFrequency=a.general.maxFrequency,this.settings.addObserver(this)}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close()),this.settings.removeObserver(this)}update(t){"general"in t?this.onSettingsChange(t):this.onStateChange(t)}onSettingsChange(t){this.currentVolume=t.general.volume/100,this.currentMinFrequency=t.general.minFrequency,this.currentMaxFrequency=t.general.maxFrequency}onStateChange(t){if(this.mode==="off"||(this.updateMode(t),t.type==="figure"))return;let n;if(t.type==="subplot"){if(t.empty)return;n=t.trace}else n=t;this.handleTraceState(n)}handleTraceState(t){if(this.mode==="off"||t.type!=="trace")return;if(t.empty){this.stopAll(),this.playEmptyTone(t.audio.size,t.audio.index);return}if(t.traceType==="line"&&!t.empty&&Array.isArray(t.intersections)&&t.intersections.length>1){this.stopAll(),this.playSimultaneousTones(t.intersections);return}const n=t.audio;let l=n.groupIndex;n.trend&&l===void 0&&(l=this.audioPalette.getCandlestickGroupIndex(n.trend));const o=l!==void 0?this.audioPalette.getPaletteEntry(l):void 0;if(n.isContinuous)this.playSmooth(n.value,n.min,n.max,n.size,Array.isArray(n.index)?n.index[0]:n.index,o);else if(Array.isArray(n.value)){const i=n.value;if(i.length===0){this.playZeroTone();return}let s=0;const c=this.mode==="on"?50:0,u=new Array,Q=()=>{if(s<i.length){const f=Array.isArray(n.index)?n.index[s]:n.index;this.playTone(n.min,n.max,i[s++],n.size,f,o),u.push(setTimeout(Q,c))}else this.stop(u)};Q()}else{const i=n.value;if(i===0)this.playZeroTone();else{const s=Array.isArray(n.index)?n.index[0]:n.index;this.playTone(n.min,n.max,i,n.size,s,o)}}}getVolume(){return Math.min(Math.max(this.currentVolume,0),1)}getFrequencyRange(){return{min:this.currentMinFrequency,max:this.currentMaxFrequency}}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const n=this.audioContext.createGain();return n.gain.value=.5,t.connect(n),n.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;n.empty||n.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=n.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}playTone(t,n,l,a,o,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(l,s,c),Q={min:0,max:a},f={min:-1,max:1},h=this.clamp(this.interpolate(o,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const l=[],a=this.audioContext.createOscillator();if(a.type=t.waveType,a.frequency.value=n,l.push(a),t.harmonicMix)for(const o of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=o.frequency*n,l.push(i)}return l}createGainNodes(t,n,l,a){const o=[],i=this.audioContext.currentTime,s=this.getVolume();for(let c=0;c<t.length;c++){const u=this.audioContext.createGain();let Q=s;if(c===0)n.harmonicMix&&(Q*=n.harmonicMix.fundamental);else{const h=n.harmonicMix.harmonics[c-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,n,Q,i,a);f!==null&&u.gain.setValueCurveAtTime(f,i,a),o.push(u)}return o}playOscillator(t,n=0,l){const a=yH,o=this.getVolume();l||(l=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,o,a),c=this.audioContext.createStereoPanner();c.pan.value=n;const u=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let h=0;h<i.length;h++)i[h].connect(s[h]),s[h].connect(c);c.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),c.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(c),i[p].stop(),i[p].disconnect(s[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),a*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,l,a,o){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=o*i,f=o*s,h=o*u,p=o-Q-f-h;return t.gain.setValueAtTime(1e-4*l,a),t.gain.linearRampToValueAtTime(l,a+Q),t.gain.linearRampToValueAtTime(c*l,a+Q+f),p>0&&t.gain.setValueAtTime(c*l,a+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*l,a+o),null}else return[.5*l,l,.5*l,.5*l,.5*l,.1*l,1e-4*l]}playSmooth(t,n,l,a,o,i){const s=this.audioContext,c=s.currentTime,u=yH,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(O=>this.interpolate(O,{min:n,max:l},Q));p.length<2&&p.push(p[0]);const g=this.clamp(this.interpolate(o,{min:0,max:a-1},{min:-1,max:1}),-1,1),v=s.createOscillator();v.type=h,v.frequency.setValueCurveAtTime(p,c,u);const L=s.createGain(),x=this.createAdsrEnvelope(L,i,f,c,u);x!==null&&L.gain.setValueCurveAtTime(x,c,u);const S=s.createStereoPanner();S.pan.value=g,v.connect(L),L.connect(S),S.connect(this.compressor),v.start(c),v.stop(c+u);const _=setTimeout(()=>{v.disconnect(),L.disconnect(),S.disconnect(),this.activeAudioIds.delete(_)},u*1e3*2);this.activeAudioIds.set(_,[v])}playEmptyTone(t,n){const l=this.audioContext,a=l.currentTime,o=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=l.createGain();u.gain.setValueAtTime(.3*i,a),u.gain.exponentialRampToValueAtTime(.01*i,a+o),u.connect(this.compressor);const Q={min:0,max:t},f={min:-1,max:1},h=this.clamp(this.interpolate(n,Q,f),-1,1),p=[];for(let L=0;L<s.length;L++){const x=l.createOscillator(),S=l.createGain(),_=this.audioContext.createStereoPanner(),O=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});x.frequency.value=s[L],x.type="sine",S.gain.setValueAtTime(c[L]*i,a),S.gain.exponentialRampToValueAtTime(.001*i,a+o),_.pan.value=h,x.connect(S),S.connect(_),_.connect(O),O.connect(u),x.start(a),x.stop(a+o),p.push(x)}const g=L=>{u.disconnect(),p.forEach(x=>{x.disconnect()}),this.activeAudioIds.delete(L)},v=setTimeout(()=>g(v),o*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(Hoe,0,{index:gH,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(Eoe,0,{index:gH,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(Soe,0,{index:gH,waveType:"sine"})}interpolate(t,n,l){return n.min===0&&n.max===0?0:(t-n.min)/(n.max-n.min)*(l.max-l.min)+l.min}clamp(t,n,l){return Math.max(n,Math.min(t,l))}toggle(){switch(this.mode){case"off":this.mode=this.isCombinedAudio?"combined":"on";break;case"on":this.mode="off";break;case"combined":this.mode="on";break}const n=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(n)}stop(t){(Array.isArray(t)?t:[t]).forEach(l=>{const a=this.activeAudioIds.get(l);if(!a){clearInterval(l);return}a.forEach(o=>{o==null||o.disconnect(),o==null||o.stop()}),clearTimeout(l),this.activeAudioIds.delete(l)})}stopAll(){this.activeAudioIds.entries().forEach(([t,n])=>{clearTimeout(t),n.forEach(l=>{l.disconnect(),l.stop()})}),this.activeAudioIds.clear()}playSimultaneousTones(t){const n=this.getVolume(),l=yH,a=this.audioContext,o=a.currentTime,i=this.getFrequencyRange(),s=Array.isArray(t[0].value)?t[0].value[1]??t[0].value[0]:t[0].value,c=t[0].min,u=t[0].max,Q=this.interpolate(s,{min:c,max:u},i);t.forEach((f,h)=>{const p=Q,v=this.audioPalette.getPaletteEntry(h).waveType,L=a.createOscillator();L.type=v,L.frequency.value=p;const x=a.createGain();x.gain.setValueAtTime(n,o),x.gain.exponentialRampToValueAtTime(.01*n,o+l),L.connect(x),x.connect(this.compressor),L.start(o),L.stop(o+l);const S=setTimeout(()=>{L.disconnect(),x.disconnect()},l*1e3*2);this.activeAudioIds.set(S,[L])})}}const Aoe=250,_oe=50,Ooe=500,Coe=20;class woe{constructor(t,n,l){oe(this,"context");oe(this,"notification");oe(this,"settings");oe(this,"autoplayId");oe(this,"currentDirection");oe(this,"userSpeed");oe(this,"defaultSpeed");oe(this,"minSpeed");oe(this,"maxSpeed");oe(this,"autoplayRate");oe(this,"interval");oe(this,"currentDuration");oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=n,this.context=t,this.settings=l,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Aoe,this.minSpeed=_oe,this.maxSpeed=Ooe,this.autoplayRate=this.defaultSpeed,this.interval=Coe,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event,this.settings.addObserver(this)}dispose(){this.stop(),this.onChangeEmitter.dispose(),this.settings.removeObserver(this)}update(t){this.updateSettings(t)}updateSettings(t){this.currentDuration=t.general.autoplayDuration,this.currentDirection&&this.restart()}start(t,n){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,n),this.currentDirection=t,this.autoplayId=setInterval(()=>{this.context.isMovable(t)?this.context.moveOnce(t):this.stop()},this.autoplayRate)}stop(){this.autoplayId&&clearInterval(this.autoplayId),this.autoplayId=null,this.currentDirection=null,this.onChangeEmitter.fire({type:"stop"})}restart(){this.autoplayId&&clearInterval(this.autoplayId),this.currentDirection&&this.start(this.currentDirection)}speedUp(){const t=this.userSpeed??this.autoplayRate;t-this.interval>this.minSpeed?(this.userSpeed=t-this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed up")):this.notification.notify("Max speed")}speedDown(){const t=this.userSpeed??this.autoplayRate;t+this.interval<=this.maxSpeed?(this.userSpeed=t+this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed down")):this.notification.notify("Min speed")}resetSpeed(){this.userSpeed=null,this.autoplayRate=this.defaultSpeed,this.restart(),this.notification.notify("Reset speed")}getAutoplayRate(t,n){if(this.userSpeed!==null)return this.userSpeed;if(n&&!n.empty){const l=Math.ceil(this.currentDuration/n.autoplay[t]);return this.defaultSpeed=l,this.minSpeed=Math.min(this.minSpeed,l),l}return this.defaultSpeed}}const NP=32;class od{encode(t){const n=new Array,l=new Array,a=new Array;for(let o=0;o<t.values.length;o++){l.push(new Array);const i=(t.max[o]-t.min[o])/4,s=t.min[o]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[o].length;Q++)t.values[o][Q]===0?n.push(" "):t.values[o][Q]<=s||t.values[o][Q]<=c?n.push("⠤"):t.values[o][Q]<=u?n.push("⠒"):n.push("⠉"),l[o].push(a.length),a.push({row:o,col:Q});n.push(Le.NEW_LINE),l[o].push(a.length),a.push({row:o,col:t.values[o].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}}class Voe{constructor(){oe(this,"GLOBAL_MIN","globalMin");oe(this,"GLOBAL_MAX","globalMax");oe(this,"BLANK","blank");oe(this,"LOWER_OUTLIER","lowerOutlier");oe(this,"UPPER_OUTLIER","upperOutlier");oe(this,"MIN","min");oe(this,"MAX","max");oe(this,"Q1","q1");oe(this,"Q2","q2");oe(this,"Q3","q3")}encode(t,n=NP){const l=new Array,a=new Array,o=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],c=[{type:this.GLOBAL_MIN,value:t.min},...s.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:s.min},{type:this.Q1,value:s.q1},{type:this.Q2,value:s.q2},{type:this.Q3,value:s.q3},{type:this.MAX,value:s.max},...s.upperOutliers.map(V=>({type:this.UPPER_OUTLIER,value:V})),{type:this.GLOBAL_MAX,value:t.max}],u=new Array;let Q=!0;for(let V=0;V<c.length-1;V++){const R=c[V],N=c[V+1],B=Math.abs(Q?N.value-R.value:R.value-c[V-1].value);R.type===this.LOWER_OUTLIER||R.type===this.UPPER_OUTLIER?(u.push({type:R.type,length:0,numChars:1}),u.push({type:this.BLANK,length:B,numChars:0})):R.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):R.type===this.GLOBAL_MIN||R.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:B,numChars:0}):u.push({type:R.type,length:B,numChars:1})}let f=u.reduce((V,R)=>V+(R.numChars>0?R.numChars:0),0),[h,p,g,v]=[-1,-1,-1,-1];for(let V=0;V<u.length;V++)u[V].type===this.MIN&&u[V].length>0&&(h=V),u[V].type===this.MAX&&u[V].length>0&&(p=V),u[V].type===this.Q1&&(g=V),u[V].type===this.Q3&&(v=V);h!==-1&&p!==-1&&u[h].length!==u[p].length&&(u[h].length>u[p].length?(u[h].numChars++,f++):(u[p].numChars++,f++)),g!==-1&&v!==-1&&u[g].length!==u[v].length&&(u[g].length>u[v].length?(u[g].numChars++,f++):(u[v].numChars++,f++));const L=Math.max(0,n-f),x=u.reduce((V,R)=>V+(R.type!==this.Q2&&R.length>0?R.length:0),0);for(const V of u)if(V.type!==this.Q2&&V.length>0){const R=Math.round(V.length/x*L);V.numChars+=R}const S=u.reduce((V,R)=>V+R.numChars,0);let _=n-S,O=0;for(;_!==0;){const V=u[O%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=_>0?1:-1,_+=_>0?-1:1),O++}let M=-1;const A=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];o.push(Array.from({length:A.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(M=A.indexOf(V.type),o[i][M]=l.length);for(let R=0;R<V.numChars;R++){let N="⠀";V.type===this.MIN||V.type===this.MAX?N="⠒":V.type===this.Q1||V.type===this.Q3?N="⠿":V.type===this.Q2?N=R===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?N="⠂":V.type===this.BLANK&&(N="⠀"),l.push(N),a.push({row:i,col:M})}}for(let V=0;V<3;V++)if(o[i][V]===-1){for(let R=V+1;R<=3;R++)if(o[i][R]!==-1){o[i][V]=o[i][R];break}}for(let V=6;V>3;V--)if(o[i][V]===-1){for(let R=V-1;R>=3;R--)if(o[i][R]!==-1){o[i][V]=o[i][R];break}}l.push(Le.NEW_LINE),a.push({row:i,col:M})}return{value:l.join(Le.EMPTY),cellToIndex:o,indexToCell:a}}}class Doe{encode(t){const n=new Array,l=new Array,a=new Array,o=(t.max-t.min)/3,i=t.min+o,s=i+o;for(let c=0;c<t.values.length;c++){l.push(new Array);for(let u=0;u<t.values[c].length;u++)t.values[c][u]===0?n.push(" "):t.values[c][u]<=i?n.push("⠤"):t.values[c][u]<=s?n.push("⠒"):n.push("⠉"),l[c].push(a.length),a.push({row:c,col:u});n.push(Le.NEW_LINE),l[c].push(a.length),a.push({row:c,col:t.values[c].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}}class BP{encode(t){const n=new Array,l=new Array,a=new Array;for(let o=0;o<t.values.length;o++){l.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(o,t);for(let Q=0;Q<t.values[o].length;Q++){const f=t.values[o][Q],h=Q>0?t.values[o][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),l[o].push(a.length),a.push({row:o,col:Q})}n.push(Le.NEW_LINE),l[o].push(a.length),a.push({row:o,col:t.values[o].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}getBrailleChar(t,n,l,a,o,i){return i===void 0&&(i=o),t<=l&&n!==null&&n>l?n<=a?"⢄":n<=i?"⢆":"⢇":t<=l?"⣀":n!==null&&n<=l?t<=a?"⡠":t<=i?"⡰":"⡸":t<=a&&n!==null&&n>a?n<=i?"⠢":"⠣":t<=a?"⠤":n!==null&&n<=a?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=o?"⠉":""}getBraille6Char(t,n,l,a,o){const i=f=>f<=l?"low":f<=a?"medium":(f<=o,"high"),s=i(t),c=n!==null?i(n):null,u={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},Q=`${s},${c}`;return u[Q]||""}addDot8(t){if(!t||t.length===0)return"⢀";const a=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+a)}}class Roe extends BP{getThresholds(t,n){const l=Array.isArray(n.min)?n.min[t]:n.min,a=Array.isArray(n.max)?n.max[t]:n.max,o=(a-l)/3,i=l+o,s=i+o;return{low:i,medium:s,high:a}}encode(t){var o;const n=new Array,l=new Array,a=new Array;for(let i=0;i<t.values.length;i++){l.push(new Array);const{low:s,medium:c,high:u}=this.getThresholds(i,t);for(let Q=0;Q<t.values[i].length;Q++){const f=t.values[i][Q],h=Q>0?t.values[i][Q-1]:null;let p=this.getBraille6Char(f,h,s,c,u);((o=t.custom)==null?void 0:o[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),l[i].push(a.length),a.push({row:i,col:Q})}n.push(Le.NEW_LINE),l[i].push(a.length),a.push({row:i,col:t.values[i].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}}class koe extends BP{getThresholds(t,n){const l=(n.max[t]-n.min[t])/4,a=n.min[t]+l,o=a+l,i=o+l,s=n.max[t];return{low:a,medium:o,mediumHigh:i,high:s}}}class Noe{constructor(t,n,l){oe(this,"context");oe(this,"notification");oe(this,"display");oe(this,"enabled");oe(this,"cacheId");oe(this,"cache");oe(this,"encoders");oe(this,"onChangeEmitter");oe(this,"onChange");this.context=t,this.notification=n,this.display=l,this.enabled=!1,this.cacheId=Le.EMPTY,this.cache=null,this.encoders=new Map([[H2.BAR,new od],[H2.BOX,new Voe],[H2.CANDLESTICK,new Roe],[H2.DODGED,new od],[H2.HEATMAP,new Doe],[H2.HISTOGRAM,new od],[H2.LINE,new koe],[H2.NORMALIZED,new od],[H2.STACKED,new od]]),this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const n=t.type==="subplot"?t.trace:t;if(n.empty||n.braille.empty||!this.encoders.has(n.traceType))return;const l=n.braille;if(this.cacheId!==l.id||this.cache===null){const a=this.encoders.get(n.traceType);this.cache=a.encode(l,NP),this.cacheId=l.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[l.row][l.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:l}=this.cache.indexToCell[t];this.context.moveToIndex(n,l)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const l=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(l);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(m1.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var PP=(e=>(e[e.OK=200]="OK",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.SERVER_ERROR=500]="SERVER_ERROR",e))(PP||{});class IP{constructor(){}static async post(t,n,l){const a={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",a,n)}static async request(t,n,l,a){try{const o=await fetch(t,{method:n,headers:l,body:a});return o.ok?{success:!0,data:await o.json()}:{success:!1,error:{statusCode:o.status,message:`API Error: ${o.status} - ${o.statusText}`}}}catch(o){return console.error(`Error in API ${n} request to ${t}:`,o),{success:!1,error:{statusCode:PP.SERVER_ERROR,message:o instanceof Error?o.message:"Unknown error occurred"}}}}}oe(IP,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Boe=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
637
+ root.render(<App />);`),T.unstable_strictMode===!0&&(m=!0),T.identifierPrefix!==void 0&&(E=T.identifierPrefix),T.onUncaughtError!==void 0&&(w=T.onUncaughtError),T.onCaughtError!==void 0&&(D=T.onCaughtError),T.onRecoverableError!==void 0&&(F=T.onRecoverableError),T.unstable_transitionCallbacks!==void 0&&(Z=T.unstable_transitionCallbacks)),T=Xh(r,1,!1,null,null,m,E,w,D,F,Z,null),r[Ni]=T.current,ts(r),new ac(T)},Jf.hydrateRoot=function(r,T,m){if(!x(r))throw Error("Target container is not a DOM element.");lc(r),T===void 0&&console.error("Must provide initial children as second argument to hydrateRoot. Example usage: hydrateRoot(domContainer, <App />)");var E=!1,w="",D=Ag,F=x9,Z=L9,ae=null,le=null;return m!=null&&(m.unstable_strictMode===!0&&(E=!0),m.identifierPrefix!==void 0&&(w=m.identifierPrefix),m.onUncaughtError!==void 0&&(D=m.onUncaughtError),m.onCaughtError!==void 0&&(F=m.onCaughtError),m.onRecoverableError!==void 0&&(Z=m.onRecoverableError),m.unstable_transitionCallbacks!==void 0&&(ae=m.unstable_transitionCallbacks),m.formState!==void 0&&(le=m.formState)),T=Xh(r,1,!0,T,m??null,E,w,D,F,Z,ae,le),T.context=F1(null),m=T.current,E=z4(m),E=Ke(E),w=o6(E),w.callback=null,l6(m,w,E),m=E,T.current.lanes=m,r1(T,m),mn(T),r[Ni]=T.current,ts(r),new oc(T)},Jf.version="19.1.1",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})(),Jf}var bP;function w0e(){if(bP)return lg.exports;bP=1;var e={};function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function")){if(e.NODE_ENV!=="production")throw new Error("^_^");try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(n){console.error(n)}}}return e.NODE_ENV==="production"?(t(),lg.exports=O0e()):lg.exports=C0e(),lg.exports}var V0e=w0e();class uH{constructor(){oe(this,"items");this.items=new Array}push(t){this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}removeLast(t,n=1){const l=this.items.lastIndexOf(t);return l!==-1?(this.items.splice(l,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}}const cH=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function TH(e,t,n,l){e.addEventListener?e.addEventListener(t,n,l):e.attachEvent&&e.attachEvent("on".concat(t),n)}function ed(e,t,n,l){e.removeEventListener?e.removeEventListener(t,n,l):e.detachEvent&&e.detachEvent("on".concat(t),n)}function HP(e,t){const n=t.slice(0,t.length-1);for(let l=0;l<n.length;l++)n[l]=e[n[l].toLowerCase()];return n}function EP(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function D0e(e,t){const n=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let a=!0;for(let o=0;o<n.length;o++)l.indexOf(n[o])===-1&&(a=!1);return a}const td={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":cH?173:189,"=":cH?61:187,";":cH?59:186,"'":222,"[":219,"]":221,"\\":220},Jr={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},nd={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},P3={16:!1,18:!1,17:!1,91:!1},E2={};for(let e=1;e<20;e++)td["f".concat(e)]=111+e;let m2=[],rd=null,SP="all";const e0=new Map,id=e=>td[e.toLowerCase()]||Jr[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),R0e=e=>Object.keys(td).find(t=>td[t]===e),k0e=e=>Object.keys(Jr).find(t=>Jr[t]===e);function MP(e){SP=e||"all"}function ad(){return SP||"all"}function N0e(){return m2.slice(0)}function B0e(){return m2.map(e=>R0e(e)||k0e(e)||String.fromCharCode(e))}function P0e(){const e=[];return Object.keys(E2).forEach(t=>{E2[t].forEach(n=>{let{key:l,scope:a,mods:o,shortcut:i}=n;e.push({scope:a,shortcut:i,mods:o,keys:l.split("+").map(s=>id(s))})})}),e}function I0e(e){const t=e.target||e.srcElement,{tagName:n}=t;let l=!0;const a=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(a||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(l=!1),l}function j0e(e){return typeof e=="string"&&(e=id(e)),m2.indexOf(e)!==-1}function F0e(e,t){let n,l;e||(e=ad());for(const a in E2)if(Object.prototype.hasOwnProperty.call(E2,a))for(n=E2[a],l=0;l<n.length;)n[l].scope===e?n.splice(l,1).forEach(i=>{let{element:s}=i;return QH(s)}):l++;ad()===e&&MP(t||"all")}function z0e(e){let t=e.keyCode||e.which||e.charCode;const n=m2.indexOf(t);if(n>=0&&m2.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&m2.splice(0,m2.length),(t===93||t===224)&&(t=91),t in P3){P3[t]=!1;for(const l in Jr)Jr[l]===t&&(o4[l]=!1)}}function AP(e){if(typeof e>"u")Object.keys(E2).forEach(a=>{Array.isArray(E2[a])&&E2[a].forEach(o=>ug(o)),delete E2[a]}),QH(null);else if(Array.isArray(e))e.forEach(a=>{a.key&&ug(a)});else if(typeof e=="object")e.key&&ug(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),l=1;l<t;l++)n[l-1]=arguments[l];let[a,o]=n;typeof a=="function"&&(o=a,a=""),ug({key:e,scope:a,method:o,splitKey:"+"})}}const ug=e=>{let{key:t,scope:n,method:l,splitKey:a="+"}=e;EP(t).forEach(i=>{const s=i.split(a),c=s.length,u=s[c-1],Q=u==="*"?"*":id(u);if(!E2[Q])return;n||(n=ad());const f=c>1?HP(Jr,s):[],h=[];E2[Q]=E2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===n&&D0e(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>QH(p))})};function _P(e,t,n,l){if(t.element!==l)return;let a;if(t.scope===n||t.scope==="all"){a=t.mods.length>0;for(const o in P3)Object.prototype.hasOwnProperty.call(P3,o)&&(!P3[o]&&t.mods.indexOf(+o)>-1||P3[o]&&t.mods.indexOf(+o)===-1)&&(a=!1);(t.mods.length===0&&!P3[16]&&!P3[18]&&!P3[17]&&!P3[91]||a||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(m2),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function OP(e,t){const n=E2["*"];let l=e.keyCode||e.which||e.charCode;if(!o4.filter.call(this,e))return;if((l===93||l===224)&&(l=91),m2.indexOf(l)===-1&&l!==229&&m2.push(l),["metaKey","ctrlKey","altKey","shiftKey"].forEach(s=>{const c=nd[s];e[s]&&m2.indexOf(c)===-1?m2.push(c):!e[s]&&m2.indexOf(c)>-1?m2.splice(m2.indexOf(c),1):s==="metaKey"&&e[s]&&(m2=m2.filter(u=>u in nd||u===l))}),l in P3){P3[l]=!0;for(const s in Jr)if(Object.prototype.hasOwnProperty.call(Jr,s)){const c=nd[Jr[s]];o4[s]=e[c]}if(!n)return}for(const s in P3)Object.prototype.hasOwnProperty.call(P3,s)&&(P3[s]=e[nd[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(m2.indexOf(17)===-1&&m2.push(17),m2.indexOf(18)===-1&&m2.push(18),P3[17]=!0,P3[18]=!0);const a=ad();if(n)for(let s=0;s<n.length;s++)n[s].scope===a&&(e.type==="keydown"&&n[s].keydown||e.type==="keyup"&&n[s].keyup)&&_P(e,n[s],a,t);if(!(l in E2))return;const o=E2[l],i=o.length;for(let s=0;s<i;s++)if((e.type==="keydown"&&o[s].keydown||e.type==="keyup"&&o[s].keyup)&&o[s].key){const c=o[s],{splitKey:u}=c,Q=c.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(id(Q[h]));f.sort().join("")===m2.sort().join("")&&_P(e,c,a,t)}}function o4(e,t,n){m2=[];const l=EP(e);let a=[],o="all",i=document,s=0,c=!1,u=!0,Q="+",f=!1,h=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(o=t.scope),t.element&&(i=t.element),t.keyup&&(c=t.keyup),t.keydown!==void 0&&(u=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(Q=t.splitKey),t.single===!0&&(h=!0)),typeof t=="string"&&(o=t),h&&AP(e,o);s<l.length;s++)e=l[s].split(Q),a=[],e.length>1&&(a=HP(Jr,e)),e=e[e.length-1],e=e==="*"?"*":id(e),e in E2||(E2[e]=[]),E2[e].push({keyup:c,keydown:u,scope:o,mods:a,shortcut:l[s],method:n,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!e0.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return OP(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;OP(v,i),z0e(v)};e0.set(i,{keydownListener:p,keyupListenr:g,capture:f}),TH(i,"keydown",p,f),TH(i,"keyup",g,f)}if(!rd){const p=()=>{m2=[]};rd={listener:p,capture:f},TH(window,"focus",p,f)}}}function q0e(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(E2).forEach(n=>{E2[n].filter(a=>a.scope===t&&a.shortcut===e).forEach(a=>{a&&a.method&&a.method()})})}function QH(e){const t=Object.values(E2).flat();if(t.findIndex(l=>{let{element:a}=l;return a===e})<0){const{keydownListener:l,keyupListenr:a,capture:o}=e0.get(e)||{};l&&a&&(ed(e,"keyup",a,o),ed(e,"keydown",l,o),e0.delete(e))}if((t.length<=0||e0.size<=0)&&(Object.keys(e0).forEach(a=>{const{keydownListener:o,keyupListenr:i,capture:s}=e0.get(a)||{};o&&i&&(ed(a,"keyup",i,s),ed(a,"keydown",o,s),e0.delete(a))}),e0.clear(),Object.keys(E2).forEach(a=>delete E2[a]),rd)){const{listener:a,capture:o}=rd;ed(window,"focus",a,o),rd=null}}const fH={getPressedKeyString:B0e,setScope:MP,getScope:ad,deleteScope:F0e,getPressedKeyCodes:N0e,getAllKeyCodes:P0e,isPressed:j0e,filter:I0e,trigger:q0e,unbind:AP,keyMap:td,modifier:Jr,modifierMap:nd};for(const e in fH)Object.prototype.hasOwnProperty.call(fH,e)&&(o4[e]=fH[e]);if(typeof window<"u"){const e=window.hotkeys;o4.noConflict=t=>(t&&window.hotkeys===o4&&(window.hotkeys=e),o4),window.hotkeys=o4}class $0e{constructor(t){oe(this,"id");oe(this,"instructionContext");oe(this,"plotContext");oe(this,"scopeContext");oe(this,"figure");this.figure=t,this.id=t.id,this.plotContext=new uH,this.scopeContext=new uH;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(m1.SUBPLOT);return}this.scopeContext.push(m1.TRACE);const l=t.activeSubplot.state;if(l.empty||l.size!==1){this.instructionContext=t.activeSubplot,this.plotContext.push(t.activeSubplot),this.plotContext.push(t.activeSubplot.activeTrace);return}this.instructionContext=t.activeSubplot.activeTrace,this.plotContext.push(t.activeSubplot.activeTrace)}dispose(){this.plotContext.clear(),this.scopeContext.clear()}get active(){return this.plotContext.peek()}get state(){return this.active.state}toggleScope(t){this.scopeContext.removeLast(t)||this.scopeContext.push(t),o4.setScope(this.scope)}get scope(){return this.scopeContext.peek()}isMovable(t){return this.active.isMovable(t)}moveOnce(t){this.active.moveOnce(t)}moveToExtreme(t){this.active.moveToExtreme(t)}moveToIndex(t,n){this.active.moveToIndex(t,n)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const n=this.active,l=n.activeTrace;if(!l)return;const a=l.getCurrentXValue();n.moveOnce(t);const o=n.activeTrace;if(this.plotContext.push(o),o.getId()===l.getId()){o.notifyOutOfBounds(),n.notifyOutOfBounds();return}if(o.moveToXValue(a),o.state.empty)o.notifyStateUpdate();else{const i=n.getRow()+1,s=n.getSize(),c={...o.state,isLayerSwitch:!0,index:i,size:s};o.notifyObserversWithState(c)}}else{const n=this.figure.subplots[0][0];this.active.notifyOutOfBounds(),n.notifyOutOfBounds()}}enterSubplot(){if(this.active.state.type==="figure"){const n=this.active;this.plotContext.push(n.activeSubplot);const l=n.activeSubplot.activeTrace;l.resetToInitialEntry(),this.plotContext.push(l),this.toggleScope(m1.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(m1.TRACE))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const l=t?"Click to activate.":Le.EMPTY;switch(n.type){case"figure":return`This is a maidr figure containing ${n.size} subplots. ${l} Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a maidr plot containing ${n.size} layers, and this is layer 1 of ${n.size}: ${n.trace.traceType} plot. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`;case"trace":{let a=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(a="single line");const o=a==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${a}${o}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}function U0e(e){return e!==null&&typeof e=="object"&&"x"in e}function G0e(e){return typeof e=="string"||typeof e=="number"}function Z0e(e){return e!==null&&typeof e=="object"&&"x"in e}class CP{computeIndexAndSegment(t,n,l,a){return l===F2.HORIZONTAL?{pointIndex:t,segmentType:a[n]}:{pointIndex:n,segmentType:a[t]}}computeVisualCoordinates(t,n,l){return l===F2.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const a=t[0][l];return this.extractXFromPoint(a)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][l]){const a=t[n][l];return this.extractXFromPoint(a)}return null}extractXValueFromValues(t,n,l){if(this.isValidPosition(t,n,l)){const a=t[n][l];return this.extractXFromValue(a)}return null}moveToXValueInPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const c=this.findPointIndexByX(t[0],n);if(c!==-1)return l(0,c),!0;{const u=this.findNearestPointIndexByX(t[0],n);if(u!==-1){const Q=ni(t[0][u]);if(typeof n=="number"&&typeof Q=="number")return l(0,u),!0;if(typeof n=="string"&&typeof Q=="string")return l(0,u),!0}}}let a=-1,o=-1,i=Number.POSITIVE_INFINITY,s=null;if(Array.isArray(t))for(let c=0;c<t.length;c++){const u=t[c];if(Array.isArray(u)){const Q=this.findPointIndexByX(u,n);if(Q!==-1)return l(c,Q),!0;const f=this.findNearestPointIndexByX(u,n);if(f!==-1){const h=ni(u[f]);let p=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof h=="number"?(p=Math.abs(h-n),p<i&&(i=p,a=c,o=f,s="numeric")):typeof n=="string"&&typeof h=="string"?a===-1&&(a=c,o=f,s="categorical"):a===-1&&(a=c,o=f,s="generic")}}}if(a!==-1&&o!==-1){const c=t[a];if(Array.isArray(c)&&ni(c[o]),s!==null)return l(a,o),!0}return!1}moveToXValueInValues(t,n,l){let a=-1,o=-1,i=Number.POSITIVE_INFINITY,s=null;for(let c=0;c<t.length;c++)for(let u=0;u<t[c].length;u++){const Q=t[c][u],f=this.extractXFromValue(Q);if(f===n)return l(c,u),!0;if(typeof n=="number"&&typeof f=="number"){const h=Math.abs(f-n);h<i&&(i=h,a=c,o=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?a===-1&&(a=c,o=u,s="categorical"):a===-1&&(a=c,o=u,s="generic")}return a!==-1&&o!==-1?(this.extractXFromValue(t[a][o]),l(a,o),!0):!1}extractXFromPoint(t){return Z0e(t)?t.x:null}extractXFromValue(t){return U0e(t)?t.x:G0e(t)?t:null}findPointIndexByX(t,n){return t.findIndex(l=>l.x===n)}isValidPosition(t,n,l){return n>=0&&n<t.length&&l>=0&&l<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let l=-1,a=Number.POSITIVE_INFINITY;for(let o=0;o<t.length;o++){const i=ni(t[o]);if(typeof i=="number"){const s=Math.abs(i-n);s<a&&(a=s,l=o)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<a&&(a=c,l=o)}}}if(l!==-1)return ni(t[l]),l}else if(typeof n=="string"){for(let a=0;a<t.length;a++)if(ni(t[a])===n)return a;const l=Number(n);if(!Number.isNaN(l)){let a=-1,o=Number.POSITIVE_INFINITY;for(let i=0;i<t.length;i++){const s=ni(t[i]);if(typeof s=="number"){const c=Math.abs(s-l);c<o&&(o=c,a=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-l);u<o&&(o=u,a=i)}}}if(a!==-1)return ni(t[a]),a}for(let a=0;a<t.length;a++)if(typeof ni(t[a])=="string")return a}return t.length>0?(ni(t[0]),0):-1}dispose(){}}function X0e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function W0e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function Y0e(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function K0e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function J0e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function eoe(e){return e&&typeof e=="object"&&"value"in e}function ni(e){return e?X0e(e)||W0e(e)||K0e(e)||J0e(e)||Y0e(e)?e.x:eoe(e)?e.value:null:null}const toe="unavailable",noe="X",roe="Y",ioe="unavailable";class dH{constructor(){oe(this,"observers");oe(this,"isInitialEntry");oe(this,"isOutOfBounds");oe(this,"row");oe(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}getSafeIndices(){var a;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,l=this.col>=0&&this.col<(((a=t[n])==null?void 0:a.length)||0)?this.col:0;return{row:n,col:l}}moveToExtreme(t){var n;switch(this.isInitialEntry&&this.handleInitialEntry(),t){case"UPWARD":this.row=this.values.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":{const{row:l}=this.getSafeIndices();this.col=(n=this.values[l])!=null&&n.length?this.values[l].length-1:0;break}case"BACKWARD":this.col=0;break}this.notifyStateUpdate()}moveToIndex(t,n){this.isMovable([t,n])&&(this.row=t,this.col=n,this.isInitialEntry=!1,this.notifyStateUpdate())}isMovable(t){var n,l;if(Array.isArray(t)){const[a,o]=t,{row:i}=this.getSafeIndices();return a>=0&&a<this.values.length&&o>=0&&o<(((n=this.values[i])==null?void 0:n.length)||0)}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":{const{row:a}=this.getSafeIndices();return this.col<(((l=this.values[a])==null?void 0:l.length)||0)-1}case"BACKWARD":return this.col>0}}handleInitialEntry(){var n;this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.values.length-1));const{row:t}=this.getSafeIndices();this.col=Math.max(0,Math.min(this.col,(((n=this.values[t])==null?void 0:n.length)||0)-1))}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){const t=this.state;for(const n of this.observers)n.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}}class Ru extends dH{constructor(n){var l,a,o;super();oe(this,"id");oe(this,"type");oe(this,"title");oe(this,"xAxis");oe(this,"yAxis");oe(this,"fill");oe(this,"navigationService");this.navigationService=new CP,this.id=n.id,this.type=n.type,this.title=n.title??toe,this.xAxis=((l=n.axes)==null?void 0:l.x)??noe,this.yAxis=((a=n.axes)==null?void 0:a.y)??roe,this.fill=((o=n.axes)==null?void 0:o.fill)??ioe}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(o=>o.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const l=this.values,a=this.row,o=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=l[a])==null?void 0:n.length)||0,index:o}}}return{empty:!1,type:"trace",traceType:this.type,plotType:this.type,title:this.title,xAxis:this.xAxis,yAxis:this.yAxis,fill:this.fill,hasMultiPoints:this.hasMultiPoints(),audio:this.audio(),braille:this.braille(),text:this.text(),autoplay:this.autoplay,highlight:this.highlight()}}highlight(){var n;if(this.highlightValues===null||this.isInitialEntry){const l=this.values,a=this.row,o=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=l[a])==null?void 0:n.length)||0,index:o}}}return{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){var a;const{row:n}=this.getSafeIndices(),l=((a=this.values[n])==null?void 0:a.length)||0;return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:l,BACKWARD:l}}hasMultiPoints(){return!1}getCurrentXValue(){if(this.hasPointsArray()){const n=this.getPointsArray();if(this.isValidPointsArray(n))return this.navigationService.extractXValueFromPoints(n,this.row,this.col)}if(this.hasValuesArray()){const n=this.values;if(this.isValidValuesArray(n))return this.navigationService.extractXValueFromValues(n,this.row,this.col)}return null}moveToXValue(n){if(this.hasPointsArray()){const l=this.getPointsArray();if(this.isValidPointsArray(l))return this.navigationService.moveToXValueInPoints(l,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const l=this.values;if(this.isValidValuesArray(l))return this.navigationService.moveToXValueInValues(l,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}getId(){return this.id}}class l4{constructor(){}static safeMin(t){return t.length===0?1/0:Math.min(...t)}static safeMax(t){return t.length===0?-1/0:Math.max(...t)}static minFrom2D(t){const n=t.flat();return this.safeMin(n)}static maxFrom2D(t){const n=t.flat();return this.safeMax(n)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let n=t[0],l=t[0];for(let a=1;a<t.length;a++){const o=t[a];o<n&&(n=o),o>l&&(l=o)}return{min:n,max:l}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class cg{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let a=n.substring(1).split("");return a.length===3&&(a=[a[0],a[0],a[1],a[1],a[2],a[2]]),{r:Number.parseInt(a[0]+a[1],16),g:Number.parseInt(a[2]+a[3],16),b:Number.parseInt(a[4]+a[5],16)}}const l=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return l?{r:Number.parseInt(l[1],10),g:Number.parseInt(l[2],10),b:Number.parseInt(l[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const l=this.calculateLuminance(t),a=this.calculateLuminance(n);return(Math.max(l,a)+.05)/(Math.min(l,a)+.05)}static calculateLuminance(t){const[n,l,a]=[t.r,t.g,t.b].map(o=>{const i=o/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*l+.0722*a}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class zt{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),a=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,o=await new Promise((c,u)=>{const Q=new Image;Q.onload=()=>c(Q),Q.onerror=()=>u(new Error("Failed to load SVG image")),Q.src=a}),i=document.createElement("canvas");[i.width,i.height]=[o.naturalWidth,o.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(o,0,0),i.toDataURL("image/jpeg",.92)):(console.error("Error converting SVG to Base 64: Canvas context unavailable"),"")}catch(n){return console.error("Error converting SVG to Base 64:",n instanceof Error?n.message:n),""}}static selectAllElements(t,n=!0){return Array.from(document.querySelectorAll(t)).map(l=>{if(!n)return l;const a=l.cloneNode(!0);return a.setAttribute(Le.VISIBILITY,Le.HIDDEN),l.insertAdjacentElement(Le.AFTER_END,a),a})}static selectElement(t,n=!0){const l=document.querySelector(t);if(!n)return l;const a=l==null?void 0:l.cloneNode(!0);return a==null||a.setAttribute(Le.VISIBILITY,Le.HIDDEN),l==null||l.insertAdjacentElement(Le.AFTER_END,a),a}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(Le.FILL,Le.TRANSPARENT),n.setAttribute(Le.STROKE,Le.TRANSPARENT),n.setAttribute(Le.VISIBILITY,Le.HIDDEN),n}static createCircleElement(t,n,l){var u;const a=window.getComputedStyle(l),o=a.stroke||a.fill,i=a.strokeWidth||"2",s=Number.parseFloat(i)*2,c=document.createElementNS(this.SVG_NAMESPACE,Le.CIRCLE);return c.setAttribute(Le.CIRCLE_X,String(t)),c.setAttribute(Le.CIRCLE_Y,String(n)),c.setAttribute(Le.RADIUS,String(s)),c.setAttribute(Le.FILL,o),c.setAttribute(Le.STROKE,o),c.setAttribute(Le.STROKE_WIDTH,i),c.setAttribute(Le.VISIBILITY,Le.HIDDEN),(u=l.parentElement)==null||u.insertAdjacentElement(Le.AFTER_END,c),c}static createLineElement(t,n){const a=t.getBBox();let o,i,s,c;switch(n){case"top":[o,i,s,c]=[a.x,a.y,a.x+a.width,a.y];break;case"bottom":[o,i,s,c]=[a.x,a.y+a.height,a.x+a.width,a.y+a.height];break;case"left":[o,i,s,c]=[a.x,a.y,a.x,a.y+a.height];break;case"right":[o,i,s,c]=[a.x+a.width,a.y,a.x+a.width,a.y+a.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,Le.LINE);return Q.setAttribute(Le.X1,String(o)),Q.setAttribute(Le.Y1,String(i)),Q.setAttribute(Le.X2,String(s)),Q.setAttribute(Le.Y2,String(c)),Q.setAttribute(Le.STROKE,u.stroke),Q.setAttribute(Le.STROKE_WIDTH,u.strokeWidth||"2"),Q.setAttribute(Le.VISIBILITY,Le.HIDDEN),t.insertAdjacentElement(Le.AFTER_END,Q),Q}static createHighlightElement(t,n){const l=t.cloneNode(!0),a=t.tagName.toLowerCase(),o=a===Le.POLYLINE||a===Le.LINE,i=o?window.getComputedStyle(t).getPropertyValue(Le.STROKE):window.getComputedStyle(t).getPropertyValue(Le.FILL),s=this.getHighlightColor(i,n);if(l.setAttribute(Le.VISIBILITY,Le.VISIBLE),l.setAttribute(Le.STROKE,s),l.setAttribute(Le.FILL,s),l.style.fill=s,l.style.stroke=s,o){const c=window.getComputedStyle(l).getPropertyValue(Le.STROKE_WIDTH);l.setAttribute(Le.STROKE_WIDTH,`${c+2}`)}return t.insertAdjacentElement(Le.AFTER_END,l),l}static getHighlightColor(t,n){const l=cg.parse(t);if(!l||!(cg.getContrastRatio(l,Le.HIGHLIGHT_BASE_COLOR)<Le.HIGHLIGHT_CONTRAST_RATIO))return n;const i={...l};return l.r===l.g&&l.g===l.b?(i.r=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*Le.HIGHLIGHT_COLOR_RATIO)),i.g=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*Le.HIGHLIGHT_COLOR_RATIO)),i.b=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*Le.HIGHLIGHT_COLOR_RATIO))):l.r>=l.g&&l.r>=l.b?i.r=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*Le.HIGHLIGHT_COLOR_RATIO)):l.g>=l.r&&l.g>=l.b?i.g=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*Le.HIGHLIGHT_COLOR_RATIO)):i.b=Math.min(Le.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*Le.HIGHLIGHT_COLOR_RATIO)),cg.rgbToString(i)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",l=cg.parse(n);return l?(.2126*l.r+.7152*l.g+.0722*l.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,n){t.style.outline=`4px solid ${n}`,t.style.outlineOffset="3px",t.style.borderRadius="3px",t.style.overflow="visible"}static removeSubplotHighlightCss(t){t.style.removeProperty("outline"),t.style.removeProperty("outline-offset"),t.style.removeProperty("border-radius"),t.style.removeProperty("overflow")}static setSubplotHighlightSvgWithAdaptiveColor(t,n,l){const a=t.querySelector("rect, path");let o="";if(a){o=window.getComputedStyle(a).getPropertyValue("fill"),(!o||o==="none"||o==="transparent"||o==="rgba(0, 0, 0, 0)")&&(l?o=window.getComputedStyle(l).getPropertyValue("fill"):o=n);const i=this.getHighlightColor(o,n);a.setAttribute("stroke",i),a.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}oe(zt,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class hH extends Ru{constructor(n,l){super(n);oe(this,"points");oe(this,"barValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"min");oe(this,"max");this.points=l,this.orientation=n.orientation??F2.VERTICAL,this.barValues=l.map(a=>a.map(o=>this.orientation===F2.VERTICAL?Number(o.y):Number(o.x))),this.min=this.barValues.map(a=>l4.safeMin(a)),this.max=this.barValues.map(a=>l4.safeMax(a)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const n=this.orientation===F2.VERTICAL,l=n?this.barValues[this.row].length:this.barValues.length,a=n?this.col:this.row,o=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:l4.safeMin(this.min),max:l4.safeMax(this.max),size:l,index:a,value:o,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){const n=this.orientation===F2.VERTICAL,l=this.points[this.row][this.col],a=n?this.xAxis:this.yAxis,o=n?l.x:l.y,i=n?this.yAxis:this.xAxis,s=n?l.y:l.x;return{main:{label:a,value:o},cross:{label:i,value:s}}}mapToSvgElements(n){if(!n)return null;const l=[zt.selectAllElements(n)];if(l.length!==this.points.length)return null;for(let a=0;a<this.points.length;a++)if(l[a].length!==this.points[a].length)return null;return l}}class aoe extends hH{constructor(t){super(t,[t.data])}}const e5={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class ooe extends Ru{constructor(n){super(n);oe(this,"points");oe(this,"boxValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"sections");oe(this,"min");oe(this,"max");this.points=n.data,this.orientation=n.orientation??F2.VERTICAL,this.sections=[e5.LOWER_OUTLIER,e5.MIN,e5.Q1,e5.Q2,e5.Q3,e5.MAX,e5.UPPER_OUTLIER];const l=[o=>o.lowerOutliers,o=>o.min,o=>o.q1,o=>o.q2,o=>o.q3,o=>o.max,o=>o.upperOutliers];this.orientation===F2.HORIZONTAL?this.boxValues=this.points.map(o=>l.map(i=>i(o))):this.boxValues=l.map(o=>this.points.map(i=>o(i)));const a=this.boxValues.map(o=>o.flatMap(i=>Array.isArray(i)?i:[i]));this.min=l4.minFrom2D(a),this.max=l4.maxFrom2D(a),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,l){const a=this.orientation===F2.HORIZONTAL;n=a?n:l,l=a?l:n,super.moveToIndex(n,l)}get values(){return this.boxValues}audio(){const n=this.boxValues[this.row][this.col],l=Array.isArray(n)?n.map(a=>a-this.min):n-this.min;return{min:this.min,max:this.max,value:n,size:this.max-this.min,index:l}}braille(){const n=this.orientation===F2.HORIZONTAL,l=n?this.row:this.col,a=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:l,col:a}}text(){const n=this.orientation===F2.HORIZONTAL,l=n?this.points[this.row]:this.points[this.col],a=n?this.yAxis:this.xAxis,o=n?this.sections[this.col]:this.sections[this.row],i=n?this.xAxis:this.yAxis,s=this.boxValues[this.row][this.col];return{main:{label:a,value:l.fill},cross:{label:i,value:s},section:o}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const l=this.orientation===F2.VERTICAL,a=new Array;if(l)for(let o=0;o<this.sections.length;o++)a.push(Array.from({length:n.length}));return n.forEach((o,i)=>{const s=o.lowerOutliers.flatMap(L=>zt.selectAllElements(L)),c=o.upperOutliers.flatMap(L=>zt.selectAllElements(L)),u=zt.selectElement(o.min)??zt.createEmptyElement(),Q=zt.selectElement(o.max)??zt.createEmptyElement(),f=zt.selectElement(o.iq)??zt.createEmptyElement(),h=zt.selectElement(o.q2)??zt.createEmptyElement(),[p,g]=l?[zt.createLineElement(f,"top"),zt.createLineElement(f,"bottom")]:[zt.createLineElement(f,"left"),zt.createLineElement(f,"right")],v=[s,u,p,h,g,Q,c];l?v.forEach((L,x)=>{a[x][i]=L}):a.push(v)}),a}}const loe="trend",wP=100;class soe extends Ru{constructor(n){super(n);oe(this,"candles");oe(this,"candleValues");oe(this,"orientation");oe(this,"sections",["volatility","open","high","low","close"]);oe(this,"currentSegmentType","open");oe(this,"currentPointIndex",0);oe(this,"sortedSegmentsByPoint");oe(this,"segmentPositionMaps");oe(this,"min");oe(this,"max");oe(this,"highlightValues");oe(this,"navigationService");this.navigationService=new CP;const l=n.data;this.candles=l.map(a=>({...a,volatility:Math.round((a.high-a.low)*wP)/wP,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=n.orientation??F2.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(o=>o[a])),this.min=l4.minFrom2D(this.candleValues),this.max=l4.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===F2.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors)}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(o=>[o,n[o]]).sort((o,i)=>o[1]-i[1]).map(o=>o[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const l=new Map;return n.forEach((a,o)=>{l.set(a,o)}),l})}getSegmentPositionInSortedOrder(n,l){return this.segmentPositionMaps[n].get(l)??0}getSegmentTypeAtSortedPosition(n,l){return this.sortedSegmentsByPoint[n][l]??"open"}updateVisualSegmentPosition(){const l=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===F2.HORIZONTAL?this.col=l:this.row=l}updateVisualPointPosition(){this.orientation===F2.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex}handleInitialEntry(){this.isInitialEntry=!1,this.currentPointIndex=Math.max(0,Math.min(this.currentPointIndex,this.candles.length-1)),this.currentSegmentType="close",this.updateVisualSegmentPosition()}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex],a=l.indexOf(this.currentSegmentType??"open");if(a===-1){this.notifyOutOfBounds();return}const o=n==="UPWARD"?a+1:a-1;if(o>=0&&o<l.length)this.currentSegmentType=l[o],this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(l>=0&&l<this.candles.length)this.currentPointIndex=l,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[l.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[0],this.updateVisualSegmentPosition();break}case"FORWARD":{this.currentPointIndex=this.candles.length-1,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}case"BACKWARD":{this.currentPointIndex=0,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}}this.notifyStateUpdate()}moveToIndex(n,l){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:a,segmentType:o}=this.navigationService.computeIndexAndSegment(n,l,this.orientation,this.sections);this.currentPointIndex=a,this.currentSegmentType=o,this.row=n,this.col=l,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex],a=l.indexOf(this.currentSegmentType??"open"),o=n==="UPWARD"?a+1:a-1;return o>=0&&o<l.length}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return l>=0&&l<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){let n;return this.currentSegmentType==="volatility"?n=this.candles[this.currentPointIndex].volatility:this.currentSegmentType?n=this.candles[this.currentPointIndex][this.currentSegmentType]:n=this.candles[this.currentPointIndex].open,{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:n,trend:this.candles[this.currentPointIndex].trend}}braille(){const n=this.candles.map(i=>i.trend),l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=l;const a=this.candleValues.map(i=>Math.min(...i)),o=this.candleValues.map(i=>Math.max(...i));return{empty:!1,id:this.id,values:this.candleValues,min:a,max:o,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const l=Array.isArray(n)?n:[n],a=[];for(const o of l)a.push(...zt.selectAllElements(o));return a}getElementAt(n,l){return l<n.length?n[l]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const g=Array.isArray(n)?n[0]||"":n,v=zt.selectAllElements(g),L=[];for(let x=0;x<this.sections.length;x++){L[x]=[];for(let S=0;S<this.candles.length;S++){const _=S<v.length?S:0;L[x][S]=v[_]}}return L}const l=n,a=this.candles.length,o=this.collectElements(l.body);let i=this.collectElements(l.wickHigh),s=this.collectElements(l.wickLow);if(i.length===0||s.length===0){const g=this.collectElements(l.wick);g.length>0&&(i.length===0&&(i=g),s.length===0&&(s=g))}const c=this.collectElements(l.open),u=this.collectElements(l.close),Q=Array.from({length:a},()=>zt.createEmptyElement()),f=Array.from({length:a},()=>zt.createEmptyElement()),h=Array.from({length:a},()=>zt.createEmptyElement());for(let g=0;g<a;g++){let v=this.getElementAt(c,g);if(!v){const x=this.getElementAt(o,g);if(x){const{open:S,close:_}=this.candles[g],O=_>S?"bottom":_<S?"top":"bottom";v=zt.createLineElement(x,O)}else v=zt.createEmptyElement()}Q[g]=v;let L=this.getElementAt(u,g);if(!L){const x=this.getElementAt(o,g);if(x){const{open:S,close:_}=this.candles[g],O=_>S?"top":_<S?"bottom":"top";L=zt.createLineElement(x,O)}else L=zt.createEmptyElement()}f[g]=L,h[g]=zt.createEmptyElement()}const p=Array.from({length:this.sections.length},()=>Array.from({length:a},()=>zt.createEmptyElement()));for(let g=0;g<a;g++){const v=this.sortedSegmentsByPoint[g];for(let L=0;L<v.length;L++){const x=v[L];let S;switch(x){case"volatility":{const _=[],O=this.getElementAt(o,g),M=this.getElementAt(i,g)??O,A=this.getElementAt(s,g)??O;M&&_.push(M),O&&_.push(O),A&&_.push(A);const V=Array.from(new Set(_));S=V.length>0?V:[zt.createEmptyElement()]}break;case"open":S=Q[g];break;case"close":S=f[g];break;case"high":S=this.getElementAt(i,g)??this.getElementAt(o,g)??zt.createEmptyElement();break;case"low":S=this.getElementAt(s,g)??this.getElementAt(o,g)??zt.createEmptyElement();break;default:S=zt.createEmptyElement()}p[L][g]=S}}return p}text(){const n=this.candles[this.currentPointIndex];let l;return this.currentSegmentType==="volatility"?l=n.volatility:this.currentSegmentType?l=n[this.currentSegmentType]:l=n.open,{main:{label:this.orientation===F2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===F2.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType??"open",fill:{label:loe,value:n.trend}}}getCurrentTrend(){return this.candles[this.currentPointIndex].trend}getCurrentXValue(){return this.currentPointIndex>=0&&this.currentPointIndex<this.candles.length?this.candles[this.currentPointIndex].value:null}moveToXValue(n){const l=this.candles.findIndex(a=>a.value===n);return l!==-1?(this.currentPointIndex=l,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getExtremaTargets(){const n=[],l=this.currentSegmentType??"open";if(l==="volatility"){const a=this.candles.map(s=>s.volatility),o=a.indexOf(Math.max(...a)),i=a.indexOf(Math.min(...a));n.push({label:"Max Volatility",value:this.candles[o].volatility,pointIndex:o,segment:"volatility",type:"max"}),n.push({label:"Min Volatility",value:this.candles[i].volatility,pointIndex:i,segment:"volatility",type:"min"})}else{const a=this.candles.map(s=>s[l]),o=a.indexOf(Math.max(...a)),i=a.indexOf(Math.min(...a));n.push({label:`Max ${l.charAt(0).toUpperCase()+l.slice(1)}`,value:this.candles[o][l],pointIndex:o,segment:l,type:"max"}),n.push({label:`Min ${l.charAt(0).toUpperCase()+l.slice(1)}`,value:this.candles[i][l],pointIndex:i,segment:l,type:"min"})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate()}}class uoe extends Ru{constructor(n){super(n);oe(this,"heatmapValues");oe(this,"highlightValues");oe(this,"x");oe(this,"y");oe(this,"min");oe(this,"max");const l=n.data;this.x=l.x,this.y=[...l.y].reverse(),this.heatmapValues=[...l.points].reverse();const{min:a,max:o}=l4.minMaxFrom2D(this.heatmapValues);this.min=a,this.max=o,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get values(){return this.heatmapValues}audio(){return{min:this.min,max:this.max,size:this.heatmapValues.length,index:this.col,value:this.heatmapValues[this.row][this.col]}}braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){return{main:{label:this.xAxis,value:this.x[this.col]},cross:{label:this.yAxis,value:this.y[this.row]},fill:{label:this.fill,value:String(this.heatmapValues[this.row][this.col])}}}mapToSvgElements(n){if(!n)return null;const l=this.heatmapValues.length,a=this.heatmapValues[0].length,o=zt.selectAllElements(n);if(o.length===0||o.length!==l*a)return null;const i=new Array;if(o[0]instanceof SVGPathElement)for(let s=0;s<l;s++){const c=l-1-s,u=new Array;for(let Q=0;Q<a;Q++){const f=c*a+Q;u.push(o[f])}i.push(u)}else if(o[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const c=new Array;for(let u=0;u<a;u++){const Q=u*l+s;c.push(o[Q])}i.push(c)}return i}}class coe extends hH{constructor(t){super(t,[t.data])}text(){const t=this.orientation===F2.VERTICAL,n=this.points[this.row][this.col],l=t?n.xMin:n.yMin,a=t?n.xMax:n.yMax;return{...super.text(),range:{min:l,max:a}}}}const VP="Group",pH=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class DP extends Ru{constructor(n){super(n);oe(this,"points");oe(this,"lineValues");oe(this,"highlightValues");oe(this,"min");oe(this,"max");oe(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(l=>l.map(a=>Number(a.y))),this.min=this.lineValues.map(l=>l4.safeMin(l)),this.max=this.lineValues.map(l=>l4.safeMax(l)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.lineValues}audio(){return{min:this.min[this.row],max:this.max[this.row],size:this.points[this.row].length,index:this.col,value:this.points[this.row][this.col].y,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){var o;const n=this.points[this.row][this.col],l=this.findIntersections();let a={};if(l.length>1){let i=l.map(s=>{var u;const c=s.groupIndex;return((u=this.points[c][0])==null?void 0:u.fill)||`l${c+1}`});if(this.previousRow!==null){const s=((o=this.points[this.previousRow][0])==null?void 0:o.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}a={fill:{label:VP,value:`intersection at (${i.join(", ")})`}}}else a=n.fill?{fill:{label:VP,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...a}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const a=this.findLineByXAndYDirection(n),o=this.points[this.row][this.col].x;if(a!==null&&a!==this.row){const i=this.findColumnByXValue(a,o);if(i!==-1){this.row=a,this.col=i;const s=this.findIntersections();if(s.length>1){const u={...super.state,intersections:s};for(const Q of this.observers)Q.update(u)}else this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}else{this.notifyOutOfBounds();return}}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const l=this.findIntersections();if(l.length>1){const o={...super.state,intersections:l};for(const i of this.observers)i.update(o)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,l=this.points[this.row][this.col].y,a=[];for(let o=0;o<this.points.length;o++){const i=this.points[o].findIndex(s=>s.x===n&&s.y===l);i!==-1&&a.push({min:this.min[o],max:this.max[o],size:this.points[o].length,index:i,value:l,groupIndex:o})}return a}isMovable(n){if(Array.isArray(n)){const[l,a]=n;return l>=0&&l<this.values.length&&a>=0&&a<this.values[l].length}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.findLineByXAndYDirection(n);if(l===null)return!1;const a=this.points[this.row][this.col].x;return this.findColumnByXValue(l,a)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const l=this.points[this.row][this.col].x;let a=null,o=Number.POSITIVE_INFINITY;for(let i=0;i<this.points.length;i++){if(i===this.row)continue;const s=this.points[i].findIndex(f=>f.x===l);if(s===-1)continue;const c=this.points[i][s].y,u=n==="UPWARD"?c>this.points[this.row][this.col].y:c<this.points[this.row][this.col].y,Q=Math.abs(c-this.points[this.row][this.col].y);u&&Q<o&&(o=Q,a=i)}return a}findColumnByXValue(n,l){return this.points[n].findIndex(a=>a.x===l)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const l=[];let a=!0;for(let o=0;o<n.length;o++){const i=zt.selectElement(n[o],!1);if(!i){l.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(Le.D)||Le.EMPTY;pH.lastIndex=0;let f=pH.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=pH.exec(Q)}else if(i instanceof SVGPolylineElement){const f=(i.getAttribute(Le.POINTS)||Le.EMPTY).split(/\s+/).filter(Boolean);for(const h of f){const[p,g]=h.split(Le.COMMA);s.push({x:Number.parseFloat(p),y:Number.parseFloat(g)})}}if(s.length!==this.lineValues[o].length)if(s.length<this.lineValues[o].length)for(;s.length<this.lineValues[o].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[o].length&&(s.length=this.lineValues[o].length);const c=[];let u=!1;for(const Q of s){if(Number.isNaN(Q.x)||Number.isNaN(Q.y)){u=!0;break}c.push(zt.createCircleElement(Q.x,Q.y,i))}if(u){l.push([]);continue}c.length>0&&(a=!1),l.push(c)}return a?null:l}get state(){const n=super.state;if(n.empty)return n;const l=this.points.length>1,a={...n,plotType:l?"multiline":"single line",...l&&{groupCount:this.points.length}},o=this.findIntersections();return o.length>1?{...a,intersections:o}:a}}class Toe extends Ru{constructor(n){super(n);oe(this,"mode");oe(this,"xPoints");oe(this,"yPoints");oe(this,"xValues");oe(this,"yValues");oe(this,"highlightXValues");oe(this,"highlightYValues");oe(this,"minX");oe(this,"maxX");oe(this,"minY");oe(this,"maxY");this.mode="column";const l=n.data,a=[...l].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let o=null;for(const c of a)(!o||o.x!==c.x)&&(o={x:c.x,y:[]},this.xPoints.push(o)),o.y.push(c.y);const i=[...l].sort((c,u)=>c.y-u.y||c.x-u.x);this.yPoints=new Array;let s=null;for(const c of i)(!s||s.y!==c.y)&&(s={y:c.y,x:[]},this.yPoints.push(s)),s.x.push(c.x);this.xValues=this.xPoints.map(c=>c.x),this.yValues=this.yPoints.map(c=>c.y),this.minX=l4.safeMin(this.xValues),this.maxX=l4.safeMax(this.xValues),this.minY=l4.safeMin(this.yValues),this.maxY=l4.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors)}dispose(){this.xPoints.length=0,this.yPoints.length=0,this.xValues.length=0,this.yValues.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightYValues.length=0),super.dispose()}get values(){const n=[this.xValues,this.yValues];return this.mode==="column"?this.row!==0&&(this.row=0):(this.row<0||this.row>=this.yPoints.length)&&(this.row=0),n}get highlightValues(){return this.mode==="column"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}audio(){if(this.mode==="column"){const n=this.xPoints[this.col];return{min:this.minY,max:this.maxY,size:n.y.length,index:this.col,value:n.y,...this.getAudioGroupIndex()}}else{const n=this.yPoints[this.row];return{min:this.minX,max:this.maxX,size:n.x.length,index:this.row,value:n.x,...this.getAudioGroupIndex()}}}braille(){return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}text(){if(this.mode==="column"){const n=this.xPoints[this.col];return{main:{label:this.xAxis,value:n.x},cross:{label:this.yAxis,value:n.y}}}else{const n=this.yPoints[this.row];return{main:{label:this.yAxis,value:n.y},cross:{label:this.xAxis,value:n.x}}}}get autoplay(){return{UPWARD:this.yValues.length,DOWNWARD:this.yValues.length,FORWARD:this.xValues.length,BACKWARD:this.xValues.length}}highlight(){if(this.highlightValues===null)return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}};const n=this.mode==="column"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return n?{empty:!1,elements:n}:{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}hasMultiPoints(){return!0}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0,this.mode="column"}toggleNavigation(){if(this.mode==="column"){const n=this.xPoints[this.col],l=n.y[Math.floor(n.y.length/2)],a=this.yValues.indexOf(l);a===-1||a>=this.yPoints.length?this.row=0:this.row=a,this.mode="row"}else{const n=this.yPoints[this.row],l=n.x[Math.floor(n.x.length/2)],a=this.xValues.indexOf(l);a===-1||a>=this.xPoints.length?this.col=0:this.col=a,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const l=zt.selectAllElements(n);if(l.length===0)return[null,null];const a=new Map,o=new Map;l.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(a.has(u)||a.set(u,[]),a.get(u).push(c)),Number.isNaN(Q)||(o.has(Q)||o.set(Q,[]),o.get(Q).push(c))});const i=Array.from(a.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(o.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const RP="Sum",Qoe="Level",foe="undefined";class doe extends hH{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let o=0;o<this.barValues[0].length;o++){const i=this.barValues.reduce((c,u)=>c+u[o],0);t.push(i);const s=this.orientation===F2.VERTICAL?{x:this.points[0][o].x,y:i,fill:RP}:{x:i,y:this.points[0][o].y,fill:RP};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:l,max:a}=l4.minMax(t);this.min.push(l),this.max.push(a)}text(){return{...super.text(),fill:{label:Qoe,value:this.points[this.row][this.col].fill??foe}}}highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}hasMultiPoints(){return!1}mapToSvgElements(t){if(!t)return new Array;const n=zt.selectAllElements(t);if(n.length===0)return new Array;const l=new Array;if(n[0]instanceof SVGPathElement)for(let a=0,o=0;a<this.barValues.length;a++){const i=new Array;for(let s=0;s<this.barValues[a].length;s++){if(o>=n.length)return new Array;this.barValues[a][s]===0?i.push(zt.createEmptyElement()):i.push(n[o++])}l.push(i)}else if(n[0]instanceof SVGRectElement){for(let a=0;a<this.barValues.length;a++)l.push(new Array);for(let a=0,o=0;a<this.barValues[0].length;a++)for(let i=this.barValues.length-1;i>=0;i--){if(o>=n.length)return new Array;this.barValues[i][a]===0?l[i].push(zt.createEmptyElement()):l[i].push(n[o++])}}return l}}class kP extends DP{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],n=this.col,l=s=>t[Math.max(0,Math.min(s,t.length-1))],a=n>0?l(n-1):l(n),o=l(n),i=n<t.length-1?l(n+1):l(n);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:n,value:[a,o,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class hoe extends kP{constructor(t){super(t)}mapToSvgElements(t){var a;if(!t||t.length!==this.lineValues.length)return null;const n=[];let l=!0;for(let o=0;o<t.length;o++){const i=zt.selectElement(t[o],!1);if(!i){n.push([]);continue}const s=(a=this.points)==null?void 0:a[o],c=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&c.push(zt.createCircleElement(u.svg_x,u.svg_y,i));c.length>0&&(l=!1),n.push(c)}return l?null:n}}function poe(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function moe(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&poe(e.data[0][0])?new hoe(e):new kP(e)}class yoe{static create(t){switch(t.type){case H2.BAR:return new aoe(t);case H2.BOX:return new ooe(t);case H2.CANDLESTICK:return new soe(t);case H2.HEATMAP:return new uoe(t);case H2.HISTOGRAM:return new coe(t);case H2.LINE:return new DP(t);case H2.SCATTER:return new Toe(t);case H2.SMOOTH:return moe(t);case H2.DODGED:case H2.NORMALIZED:case H2.STACKED:return new doe(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const goe="MAIDR Plot",voe="unavailable",xoe="unavailable";class Loe extends dH{constructor(n){super();oe(this,"id");oe(this,"title");oe(this,"subtitle");oe(this,"caption");oe(this,"subplots");oe(this,"size");this.id=n.id,this.title=n.title??goe,this.subtitle=n.subtitle??voe,this.caption=n.caption??xoe;const l=n.subplots;this.subplots=l.map(a=>a.map(o=>new boe(o))),this.size=this.subplots.reduce((a,o)=>a+o.length,0)}dispose(){this.subplots.forEach(n=>n.forEach(l=>l.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((a,o)=>a+o.length,0),l=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:l.getStateWithFigurePosition(this.row,this.col),traceTypes:l.traceTypes,highlight:this.highlight()}}highlight(){var l;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}};try{const a=((l=this.subplots[0])==null?void 0:l.length)||1,o=this.row*a+this.col+1,i=`g[id="axes_${o}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&o-1<c.length)return{empty:!1,elements:c[o-1]}}catch{return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}isMovable(n){switch(n){case"UPWARD":return this.row<this.subplots.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.subplots[this.row].length-1;case"BACKWARD":return this.col>0;default:return!1}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}}class boe extends dH{constructor(n){super();oe(this,"traces");oe(this,"traceTypes");oe(this,"size");this.isInitialEntry=!1;const l=n.layers;this.size=l.length,this.traces=l.map(a=>[yoe.create(a)]),this.traceTypes=this.traces.flat().map(a=>{const o=a.state;return o.empty?Le.EMPTY:o.traceType})}getRow(){return this.row}getSize(){return this.size}dispose(){this.traces.forEach(n=>n.forEach(l=>l.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}highlight(){return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}get state(){return this.isOutOfBounds?{empty:!0,type:"subplot"}:{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight()}}getStateWithFigurePosition(n,l){return this.state}}const s4={SINE_BASIC:0,SQUARE_BASIC:1,SAWTOOTH_BASIC:2,TRIANGLE_BASIC:3,SAWTOOTH_DARK:4,SINE_HARMONIC:5,TRIANGLE_HARMONIC:6,SQUARE_HARMONIC:7,TRIANGLE_MELLOW:8,SINE_SUBTLE:9,SAWTOOTH_SOFT:10},ku=class ku{constructor(){oe(this,"basePalette");oe(this,"extendedPalette");this.basePalette=[{index:s4.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:s4.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:s4.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:s4.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:s4.SAWTOOTH_DARK,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.2},{frequency:3,amplitude:.1},{frequency:5,amplitude:.05}]},timbreModulation:{attack:.005,decay:.3,sustain:.4,release:.5}},{index:s4.SINE_HARMONIC,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.15},{frequency:4,amplitude:.05}]},timbreModulation:{attack:.02,decay:.2,sustain:.6,release:.3}},{index:s4.TRIANGLE_HARMONIC,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.2},{frequency:6,amplitude:.1}]},timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:s4.SQUARE_HARMONIC,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.1},{frequency:7,amplitude:.05}]},timbreModulation:{attack:.005,decay:.05,sustain:.5,release:.1}},{index:s4.TRIANGLE_MELLOW,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:2.5,amplitude:.15},{frequency:4.5,amplitude:.08}]},timbreModulation:{attack:.01,decay:.4,sustain:.3,release:.5}},{index:s4.SINE_SUBTLE,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.1},{frequency:3,amplitude:.05}]},timbreModulation:{attack:.02,decay:.1,sustain:.9,release:.15}},{index:s4.SAWTOOTH_SOFT,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.05},{frequency:6,amplitude:.02}]},timbreModulation:{attack:.005,decay:.4,sustain:.2,release:.6}}],this.validateBasePalette(),this.extendedPalette=new Map,this.generateExtendedPalette()}dispose(){this.extendedPalette.clear()}getPaletteEntry(t){if(t<this.basePalette.length)return this.basePalette[t];const n=this.extendedPalette.get(t);if(n)return n;const l=this.generateExtendedEntry(t);return this.extendedPalette.set(t,l),l}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return s4.SINE_BASIC;case"Bear":return s4.SAWTOOTH_SOFT;case"Neutral":return s4.TRIANGLE_BASIC;default:return s4.SINE_BASIC}}generateExtendedPalette(){[{index:this.basePalette.length,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.3},{frequency:3,amplitude:.15}]},timbreModulation:{attack:.02,decay:.15,sustain:.7,release:.3}},{index:this.basePalette.length+1,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:1.5,amplitude:.4},{frequency:2.5,amplitude:.2}]},timbreModulation:{attack:.01,decay:.08,sustain:.6,release:.4}},{index:this.basePalette.length+2,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:1.25,amplitude:.35},{frequency:2,amplitude:.25},{frequency:3,amplitude:.1}]},timbreModulation:{attack:.03,decay:.2,sustain:.5,release:.35}},{index:this.basePalette.length+3,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:.5,amplitude:.2},{frequency:4,amplitude:.15}]},timbreModulation:{attack:.025,decay:.18,sustain:.8,release:.25}}].forEach((n,l)=>{this.extendedPalette.set(this.basePalette.length+l,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,l=this.basePalette[n],a=Math.floor((t-this.basePalette.length)/this.basePalette.length),o=this.generateHarmonics(a),i=this.generateTimbreModulation(a,l.timbreModulation);return{index:t,waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:o},timbreModulation:i}}generateHarmonics(t){const n=[],l=ku.MIN_HARMONICS+t%ku.HARMONIC_VARIATION;for(let a=0;a<l;a++){const o=1+(a+1)*(.5+t*.3%1),i=.4/(a+1)*(1-t*.1%.3);n.push({frequency:o,amplitude:i})}return n}generateTimbreModulation(t,n){const l=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*l)),decay:Math.max(.05,Math.min(.3,n.decay*l)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*l))}}validateBasePalette(){this.basePalette.forEach((t,n)=>{if(t.index!==n)throw new Error(`AudioPalette validation error: Entry at array position ${n} has index ${t.index}. Array position must match the index property to prevent audio palette mismatches.`)})}};oe(ku,"MIN_HARMONICS",2),oe(ku,"HARMONIC_VARIATION",3);let mH=ku;const Hoe=100,Eoe=440,Soe=880,yH=.3,gH=s4.SINE_BASIC;class Moe{constructor(t,n,l){oe(this,"notification");oe(this,"audioPalette");oe(this,"settings");oe(this,"isCombinedAudio");oe(this,"mode");oe(this,"activeAudioIds");oe(this,"audioContext");oe(this,"compressor");oe(this,"currentVolume");oe(this,"currentMinFrequency");oe(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new mH,this.settings=l,this.isCombinedAudio=!1,this.mode="on",this.updateMode(n),this.activeAudioIds=new Map,this.audioContext=new AudioContext,this.compressor=this.initCompressor();const a=this.settings.loadSettings();this.currentVolume=a.general.volume/100,this.currentMinFrequency=a.general.minFrequency,this.currentMaxFrequency=a.general.maxFrequency,this.settings.addObserver(this)}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close()),this.settings.removeObserver(this)}update(t){"general"in t?this.onSettingsChange(t):this.onStateChange(t)}onSettingsChange(t){this.currentVolume=t.general.volume/100,this.currentMinFrequency=t.general.minFrequency,this.currentMaxFrequency=t.general.maxFrequency}onStateChange(t){if(this.mode==="off")return;if(this.updateMode(t),t.type==="figure"){if(t.empty){this.playEmptyTone(1,0);return}return}let n;if(t.type==="subplot"){if(t.empty)return;n=t.trace}else n=t;this.handleTraceState(n)}handleTraceState(t){if(this.mode==="off"||t.type!=="trace")return;if(t.empty){this.stopAll(),this.playEmptyTone(t.audio.size,t.audio.index);return}if(t.traceType==="line"&&!t.empty&&Array.isArray(t.intersections)&&t.intersections.length>1){this.stopAll(),this.playSimultaneousTones(t.intersections);return}const n=t.audio;let l=n.groupIndex;n.trend&&l===void 0&&(l=this.audioPalette.getCandlestickGroupIndex(n.trend));const o=l!==void 0?this.audioPalette.getPaletteEntry(l):void 0;if(n.isContinuous)this.playSmooth(n.value,n.min,n.max,n.size,Array.isArray(n.index)?n.index[0]:n.index,o);else if(Array.isArray(n.value)){const i=n.value;if(i.length===0){this.playZeroTone();return}let s=0;const c=this.mode==="on"?50:0,u=new Array,Q=()=>{if(s<i.length){const f=Array.isArray(n.index)?n.index[s]:n.index;this.playTone(n.min,n.max,i[s++],n.size,f,o),u.push(setTimeout(Q,c))}else this.stop(u)};Q()}else{const i=n.value;if(i===0)this.playZeroTone();else{const s=Array.isArray(n.index)?n.index[0]:n.index;this.playTone(n.min,n.max,i,n.size,s,o)}}}getVolume(){return Math.min(Math.max(this.currentVolume,0),1)}getFrequencyRange(){return{min:this.currentMinFrequency,max:this.currentMaxFrequency}}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const n=this.audioContext.createGain();return n.gain.value=.5,t.connect(n),n.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;n.empty||n.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=n.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}playTone(t,n,l,a,o,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(l,s,c),Q={min:0,max:a},f={min:-1,max:1},h=this.clamp(this.interpolate(o,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const l=[],a=this.audioContext.createOscillator();if(a.type=t.waveType,a.frequency.value=n,l.push(a),t.harmonicMix)for(const o of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=o.frequency*n,l.push(i)}return l}createGainNodes(t,n,l,a){const o=[],i=this.audioContext.currentTime,s=this.getVolume();for(let c=0;c<t.length;c++){const u=this.audioContext.createGain();let Q=s;if(c===0)n.harmonicMix&&(Q*=n.harmonicMix.fundamental);else{const h=n.harmonicMix.harmonics[c-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,n,Q,i,a);f!==null&&u.gain.setValueCurveAtTime(f,i,a),o.push(u)}return o}playOscillator(t,n=0,l){const a=yH,o=this.getVolume();l||(l=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,o,a),c=this.audioContext.createStereoPanner();c.pan.value=n;const u=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let h=0;h<i.length;h++)i[h].connect(s[h]),s[h].connect(c);c.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),c.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(c),i[p].stop(),i[p].disconnect(s[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),a*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,l,a,o){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=o*i,f=o*s,h=o*u,p=o-Q-f-h;return t.gain.setValueAtTime(1e-4*l,a),t.gain.linearRampToValueAtTime(l,a+Q),t.gain.linearRampToValueAtTime(c*l,a+Q+f),p>0&&t.gain.setValueAtTime(c*l,a+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*l,a+o),null}else return[.5*l,l,.5*l,.5*l,.5*l,.1*l,1e-4*l]}playSmooth(t,n,l,a,o,i){const s=this.audioContext,c=s.currentTime,u=yH,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(O=>this.interpolate(O,{min:n,max:l},Q));p.length<2&&p.push(p[0]);const g=this.clamp(this.interpolate(o,{min:0,max:a-1},{min:-1,max:1}),-1,1),v=s.createOscillator();v.type=h,v.frequency.setValueCurveAtTime(p,c,u);const L=s.createGain(),x=this.createAdsrEnvelope(L,i,f,c,u);x!==null&&L.gain.setValueCurveAtTime(x,c,u);const S=s.createStereoPanner();S.pan.value=g,v.connect(L),L.connect(S),S.connect(this.compressor),v.start(c),v.stop(c+u);const _=setTimeout(()=>{v.disconnect(),L.disconnect(),S.disconnect(),this.activeAudioIds.delete(_)},u*1e3*2);this.activeAudioIds.set(_,[v])}playEmptyTone(t,n){const l=this.audioContext,a=l.currentTime,o=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=l.createGain();u.gain.setValueAtTime(.3*i,a),u.gain.exponentialRampToValueAtTime(.01*i,a+o),u.connect(this.compressor);const Q={min:0,max:t},f={min:-1,max:1},h=this.clamp(this.interpolate(n,Q,f),-1,1),p=[];for(let L=0;L<s.length;L++){const x=l.createOscillator(),S=l.createGain(),_=this.audioContext.createStereoPanner(),O=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});x.frequency.value=s[L],x.type="sine",S.gain.setValueAtTime(c[L]*i,a),S.gain.exponentialRampToValueAtTime(.001*i,a+o),_.pan.value=h,x.connect(S),S.connect(_),_.connect(O),O.connect(u),x.start(a),x.stop(a+o),p.push(x)}const g=L=>{u.disconnect(),p.forEach(x=>{x.disconnect()}),this.activeAudioIds.delete(L)},v=setTimeout(()=>g(v),o*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(Hoe,0,{index:gH,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(Eoe,0,{index:gH,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(Soe,0,{index:gH,waveType:"sine"})}interpolate(t,n,l){return n.min===0&&n.max===0?0:(t-n.min)/(n.max-n.min)*(l.max-l.min)+l.min}clamp(t,n,l){return Math.max(n,Math.min(t,l))}toggle(){switch(this.mode){case"off":this.mode=this.isCombinedAudio?"combined":"on";break;case"on":this.mode="off";break;case"combined":this.mode="on";break}const n=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(n)}stop(t){(Array.isArray(t)?t:[t]).forEach(l=>{const a=this.activeAudioIds.get(l);if(!a){clearInterval(l);return}a.forEach(o=>{o==null||o.disconnect(),o==null||o.stop()}),clearTimeout(l),this.activeAudioIds.delete(l)})}stopAll(){this.activeAudioIds.entries().forEach(([t,n])=>{clearTimeout(t),n.forEach(l=>{l.disconnect(),l.stop()})}),this.activeAudioIds.clear()}playSimultaneousTones(t){const n=this.getVolume(),l=yH,a=this.audioContext,o=a.currentTime,i=this.getFrequencyRange(),s=Array.isArray(t[0].value)?t[0].value[1]??t[0].value[0]:t[0].value,c=t[0].min,u=t[0].max,Q=this.interpolate(s,{min:c,max:u},i);t.forEach((f,h)=>{const p=Q,v=this.audioPalette.getPaletteEntry(h).waveType,L=a.createOscillator();L.type=v,L.frequency.value=p;const x=a.createGain();x.gain.setValueAtTime(n,o),x.gain.exponentialRampToValueAtTime(.01*n,o+l),L.connect(x),x.connect(this.compressor),L.start(o),L.stop(o+l);const S=setTimeout(()=>{L.disconnect(),x.disconnect()},l*1e3*2);this.activeAudioIds.set(S,[L])})}}const Aoe=250,_oe=50,Ooe=500,Coe=20;class woe{constructor(t,n,l){oe(this,"context");oe(this,"notification");oe(this,"settings");oe(this,"autoplayId");oe(this,"currentDirection");oe(this,"userSpeed");oe(this,"defaultSpeed");oe(this,"minSpeed");oe(this,"maxSpeed");oe(this,"autoplayRate");oe(this,"interval");oe(this,"currentDuration");oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=n,this.context=t,this.settings=l,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Aoe,this.minSpeed=_oe,this.maxSpeed=Ooe,this.autoplayRate=this.defaultSpeed,this.interval=Coe,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event,this.settings.addObserver(this)}dispose(){this.stop(),this.onChangeEmitter.dispose(),this.settings.removeObserver(this)}update(t){this.updateSettings(t)}updateSettings(t){this.currentDuration=t.general.autoplayDuration,this.currentDirection&&this.restart()}start(t,n){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,n),this.currentDirection=t,this.autoplayId=setInterval(()=>{this.context.isMovable(t)?this.context.moveOnce(t):this.stop()},this.autoplayRate)}stop(){this.autoplayId&&clearInterval(this.autoplayId),this.autoplayId=null,this.currentDirection=null,this.onChangeEmitter.fire({type:"stop"})}restart(){this.autoplayId&&clearInterval(this.autoplayId),this.currentDirection&&this.start(this.currentDirection)}speedUp(){const t=this.userSpeed??this.autoplayRate;t-this.interval>this.minSpeed?(this.userSpeed=t-this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed up")):this.notification.notify("Max speed")}speedDown(){const t=this.userSpeed??this.autoplayRate;t+this.interval<=this.maxSpeed?(this.userSpeed=t+this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed down")):this.notification.notify("Min speed")}resetSpeed(){this.userSpeed=null,this.autoplayRate=this.defaultSpeed,this.restart(),this.notification.notify("Reset speed")}getAutoplayRate(t,n){if(this.userSpeed!==null)return this.userSpeed;if(n&&!n.empty){const l=Math.ceil(this.currentDuration/n.autoplay[t]);return this.defaultSpeed=l,this.minSpeed=Math.min(this.minSpeed,l),l}return this.defaultSpeed}}const NP=32;class od{encode(t){const n=new Array,l=new Array,a=new Array;for(let o=0;o<t.values.length;o++){l.push(new Array);const i=(t.max[o]-t.min[o])/4,s=t.min[o]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[o].length;Q++)t.values[o][Q]===0?n.push(" "):t.values[o][Q]<=s||t.values[o][Q]<=c?n.push("⠤"):t.values[o][Q]<=u?n.push("⠒"):n.push("⠉"),l[o].push(a.length),a.push({row:o,col:Q});n.push(Le.NEW_LINE),l[o].push(a.length),a.push({row:o,col:t.values[o].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}}class Voe{constructor(){oe(this,"GLOBAL_MIN","globalMin");oe(this,"GLOBAL_MAX","globalMax");oe(this,"BLANK","blank");oe(this,"LOWER_OUTLIER","lowerOutlier");oe(this,"UPPER_OUTLIER","upperOutlier");oe(this,"MIN","min");oe(this,"MAX","max");oe(this,"Q1","q1");oe(this,"Q2","q2");oe(this,"Q3","q3")}encode(t,n=NP){const l=new Array,a=new Array,o=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],c=[{type:this.GLOBAL_MIN,value:t.min},...s.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:s.min},{type:this.Q1,value:s.q1},{type:this.Q2,value:s.q2},{type:this.Q3,value:s.q3},{type:this.MAX,value:s.max},...s.upperOutliers.map(V=>({type:this.UPPER_OUTLIER,value:V})),{type:this.GLOBAL_MAX,value:t.max}],u=new Array;let Q=!0;for(let V=0;V<c.length-1;V++){const R=c[V],N=c[V+1],B=Math.abs(Q?N.value-R.value:R.value-c[V-1].value);R.type===this.LOWER_OUTLIER||R.type===this.UPPER_OUTLIER?(u.push({type:R.type,length:0,numChars:1}),u.push({type:this.BLANK,length:B,numChars:0})):R.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):R.type===this.GLOBAL_MIN||R.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:B,numChars:0}):u.push({type:R.type,length:B,numChars:1})}let f=u.reduce((V,R)=>V+(R.numChars>0?R.numChars:0),0),[h,p,g,v]=[-1,-1,-1,-1];for(let V=0;V<u.length;V++)u[V].type===this.MIN&&u[V].length>0&&(h=V),u[V].type===this.MAX&&u[V].length>0&&(p=V),u[V].type===this.Q1&&(g=V),u[V].type===this.Q3&&(v=V);h!==-1&&p!==-1&&u[h].length!==u[p].length&&(u[h].length>u[p].length?(u[h].numChars++,f++):(u[p].numChars++,f++)),g!==-1&&v!==-1&&u[g].length!==u[v].length&&(u[g].length>u[v].length?(u[g].numChars++,f++):(u[v].numChars++,f++));const L=Math.max(0,n-f),x=u.reduce((V,R)=>V+(R.type!==this.Q2&&R.length>0?R.length:0),0);for(const V of u)if(V.type!==this.Q2&&V.length>0){const R=Math.round(V.length/x*L);V.numChars+=R}const S=u.reduce((V,R)=>V+R.numChars,0);let _=n-S,O=0;for(;_!==0;){const V=u[O%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=_>0?1:-1,_+=_>0?-1:1),O++}let M=-1;const A=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];o.push(Array.from({length:A.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(M=A.indexOf(V.type),o[i][M]=l.length);for(let R=0;R<V.numChars;R++){let N="⠀";V.type===this.MIN||V.type===this.MAX?N="⠒":V.type===this.Q1||V.type===this.Q3?N="⠿":V.type===this.Q2?N=R===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?N="⠂":V.type===this.BLANK&&(N="⠀"),l.push(N),a.push({row:i,col:M})}}for(let V=0;V<3;V++)if(o[i][V]===-1){for(let R=V+1;R<=3;R++)if(o[i][R]!==-1){o[i][V]=o[i][R];break}}for(let V=6;V>3;V--)if(o[i][V]===-1){for(let R=V-1;R>=3;R--)if(o[i][R]!==-1){o[i][V]=o[i][R];break}}l.push(Le.NEW_LINE),a.push({row:i,col:M})}return{value:l.join(Le.EMPTY),cellToIndex:o,indexToCell:a}}}class Doe{encode(t){const n=new Array,l=new Array,a=new Array,o=(t.max-t.min)/3,i=t.min+o,s=i+o;for(let c=0;c<t.values.length;c++){l.push(new Array);for(let u=0;u<t.values[c].length;u++)t.values[c][u]===0?n.push(" "):t.values[c][u]<=i?n.push("⠤"):t.values[c][u]<=s?n.push("⠒"):n.push("⠉"),l[c].push(a.length),a.push({row:c,col:u});n.push(Le.NEW_LINE),l[c].push(a.length),a.push({row:c,col:t.values[c].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}}class BP{encode(t){const n=new Array,l=new Array,a=new Array;for(let o=0;o<t.values.length;o++){l.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(o,t);for(let Q=0;Q<t.values[o].length;Q++){const f=t.values[o][Q],h=Q>0?t.values[o][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),l[o].push(a.length),a.push({row:o,col:Q})}n.push(Le.NEW_LINE),l[o].push(a.length),a.push({row:o,col:t.values[o].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}getBrailleChar(t,n,l,a,o,i){return i===void 0&&(i=o),t<=l&&n!==null&&n>l?n<=a?"⢄":n<=i?"⢆":"⢇":t<=l?"⣀":n!==null&&n<=l?t<=a?"⡠":t<=i?"⡰":"⡸":t<=a&&n!==null&&n>a?n<=i?"⠢":"⠣":t<=a?"⠤":n!==null&&n<=a?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=o?"⠉":""}getBraille6Char(t,n,l,a,o){const i=f=>f<=l?"low":f<=a?"medium":(f<=o,"high"),s=i(t),c=n!==null?i(n):null,u={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},Q=`${s},${c}`;return u[Q]||""}addDot8(t){if(!t||t.length===0)return"⢀";const a=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+a)}}class Roe extends BP{getThresholds(t,n){const l=Array.isArray(n.min)?n.min[t]:n.min,a=Array.isArray(n.max)?n.max[t]:n.max,o=(a-l)/3,i=l+o,s=i+o;return{low:i,medium:s,high:a}}encode(t){var o;const n=new Array,l=new Array,a=new Array;for(let i=0;i<t.values.length;i++){l.push(new Array);const{low:s,medium:c,high:u}=this.getThresholds(i,t);for(let Q=0;Q<t.values[i].length;Q++){const f=t.values[i][Q],h=Q>0?t.values[i][Q-1]:null;let p=this.getBraille6Char(f,h,s,c,u);((o=t.custom)==null?void 0:o[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),l[i].push(a.length),a.push({row:i,col:Q})}n.push(Le.NEW_LINE),l[i].push(a.length),a.push({row:i,col:t.values[i].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:a}}}class koe extends BP{getThresholds(t,n){const l=(n.max[t]-n.min[t])/4,a=n.min[t]+l,o=a+l,i=o+l,s=n.max[t];return{low:a,medium:o,mediumHigh:i,high:s}}}class Noe{constructor(t,n,l){oe(this,"context");oe(this,"notification");oe(this,"display");oe(this,"enabled");oe(this,"cacheId");oe(this,"cache");oe(this,"encoders");oe(this,"onChangeEmitter");oe(this,"onChange");this.context=t,this.notification=n,this.display=l,this.enabled=!1,this.cacheId=Le.EMPTY,this.cache=null,this.encoders=new Map([[H2.BAR,new od],[H2.BOX,new Voe],[H2.CANDLESTICK,new Roe],[H2.DODGED,new od],[H2.HEATMAP,new Doe],[H2.HISTOGRAM,new od],[H2.LINE,new koe],[H2.NORMALIZED,new od],[H2.STACKED,new od]]),this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const n=t.type==="subplot"?t.trace:t;if(n.empty||n.braille.empty||!this.encoders.has(n.traceType))return;const l=n.braille;if(this.cacheId!==l.id||this.cache===null){const a=this.encoders.get(n.traceType);this.cache=a.encode(l,NP),this.cacheId=l.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[l.row][l.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:l}=this.cache.indexToCell[t];this.context.moveToIndex(n,l)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const l=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(l);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(m1.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var PP=(e=>(e[e.OK=200]="OK",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.SERVER_ERROR=500]="SERVER_ERROR",e))(PP||{});class IP{constructor(){}static async post(t,n,l){const a={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",a,n)}static async request(t,n,l,a){try{const o=await fetch(t,{method:n,headers:l,body:a});return o.ok?{success:!0,data:await o.json()}:{success:!1,error:{statusCode:o.status,message:`API Error: ${o.status} - ${o.statusText}`}}}catch(o){return console.error(`Error in API ${n} request to ${t}:`,o),{success:!1,error:{statusCode:PP.SERVER_ERROR,message:o instanceof Error?o.message:"Unknown error occurred"}}}}}oe(IP,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Boe=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
638
638
  1. Provide simple, straightforward descriptions of charts and graphs
639
639
  2. Focus on basic patterns and key points
640
640
  3. Use simple, everyday language with minimal statistical terms
@@ -665,9 +665,9 @@ Focus on providing a clear, structured response that helps me understand the key
665
665
 
666
666
  ${e}`}function xH(e){return joe.replace("{maidrJson}",e.maidrJson).replace("{currentPositionText}",e.currentPositionText).replace("{message}",e.message)}class qoe{constructor(t,n){oe(this,"display");oe(this,"models");this.display=t,this.models={OPENAI:new $oe(t.plot,n,"gpt-4o"),ANTHROPIC_CLAUDE:new Uoe(t.plot,n,"claude-3-7-sonnet-latest"),GOOGLE_GEMINI:new Goe(t.plot,n,"gemini-2.0-flash")}}async sendMessage(t,n){return this.models[t].getLlmResponse(n)}toggle(){this.display.toggleFocus(m1.CHAT)}}class LH{constructor(t,n){oe(this,"svg");oe(this,"json");oe(this,"maidrBaseUrl");oe(this,"codeQueryParam");this.svg=t,this.json=JSON.stringify(n),this.maidrBaseUrl="https://maidr-service.azurewebsites.net/api",this.codeQueryParam="I8Aa2PlPspjQ8Hks0QzGyszP8_i2-XJ3bq7Xh8-ykEe4AzFuYn_QWA%3D%3D"}async getLlmResponse(t){var n;try{const l=await zt.toBase64(this.svg),a=t.expertise==="custom"?"advanced":t.expertise,o=this.getPayload(t.customInstruction,this.json,l,"",t.message,a),i=t.clientToken?this.getMaidrUrl():this.getApiUrl(t.apiKey),s=this.getHeaders(t),c=await IP.post(i,o,s);return c.success?c.data?this.formatResponse(c.data):{success:!1,error:"Response unavailable"}:{success:!1,error:(n=c.error)==null?void 0:n.message}}catch(l){return{success:!1,error:l instanceof Error?l.message:"Unknown error occurred"}}}getMaidrUrl(){return`${this.maidrBaseUrl}/${this.getEndPoint()}?code=${this.codeQueryParam}`}getHeaders(t){const n={"Content-Type":"application/json"};return t.clientToken?n.Authentication=`${t.email} ${t.clientToken}`:n.Authorization=`Bearer ${t.apiKey}`,n}}class $oe extends LH{constructor(n,l,a){super(n,l);oe(this,"version");this.version=a}getApiUrl(){return"https://api.openai.com/v1/chat/completions"}getEndPoint(){return"openai"}getPayload(n,l,a,o,i,s){const c={maidrJson:l,currentPositionText:o,message:i,expertiseLevel:s};return JSON.stringify({model:this.version,max_tokens:1e3,messages:[{role:"system",content:vH(n,c.expertiseLevel)},{role:"user",content:[{type:"text",text:xH(c)},{type:"image_url",image_url:{url:a}}]}]})}formatResponse(n){return n.choices.length===0?{success:!1,error:"Invalid response format"}:{success:!0,data:n.choices[0].message.content}}getHeaders(n){return super.getHeaders(n)}}class Uoe extends LH{constructor(n,l,a){super(n,l);oe(this,"version");this.version=a}getApiUrl(){return"https://api.anthropic.com"}getEndPoint(){return"claude"}getPayload(n,l,a,o,i,s){const c={maidrJson:l,currentPositionText:o,message:i,expertiseLevel:s};return JSON.stringify({anthropic_version:this.version,max_tokens:256,messages:[{role:"user",content:[{type:"image",source:{type:"base64",media_type:"image/jpeg",data:a}},{type:"text",text:`${vH(n,c.expertiseLevel)}
667
667
 
668
- ${xH(c)}`}]}]})}formatResponse(n){return n.content.length===0?{success:!1,error:"Invalid response format"}:{success:!0,data:n.content[0].text}}getHeaders(n){const l=super.getHeaders(n);return l["anthropic-version"]=this.version,l}}class Goe extends LH{constructor(n,l,a){super(n,l);oe(this,"version");this.version=a}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,l,a,o,i,s){const c={maidrJson:l,currentPositionText:o,message:i,expertiseLevel:s};return JSON.stringify({generationConfig:{},safetySettings:[],contents:[{role:"user",parts:[{text:vH(n,c.expertiseLevel)}]},{role:"user",parts:[{text:xH(c)},{inlineData:{data:a.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 l=super.getHeaders(n);return delete l.Authorization,l}}class Zoe{constructor(t,n){oe(this,"context");oe(this,"focusStack");oe(this,"plot");oe(this,"onChangeEmitter");oe(this,"onChange");oe(this,"hasEnteredInteractive",!1);this.context=t,this.focusStack=new uH,this.focusStack.push(this.context.scope),this.plot=n,this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event,this.removeInstruction()}dispose(){this.addInstruction(),this.onChangeEmitter.dispose()}getInstruction(t=!0){return this.context.getInstruction(t)}addInstruction(){this.plot.setAttribute(Le.ARIA_LABEL,this.getInstruction()),this.plot.setAttribute(Le.TITLE,this.getInstruction()),this.plot.setAttribute(Le.ROLE,Le.IMAGE),this.plot.tabIndex=0}removeInstruction(){const t=this.hasEnteredInteractive?"":this.getInstruction(!1);this.plot.setAttribute(Le.ARIA_LABEL,t),this.plot.removeAttribute(Le.TITLE),this.plot.setAttribute(Le.ROLE,Le.APPLICATION),this.plot.tabIndex=0}setAriaLabel(){const t=this.hasEnteredInteractive?"":this.getInstruction(!1);this.plot.setAttribute(Le.ARIA_LABEL,t)}toggleFocus(t){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(()=>{this.plot.focus(),this.hasEnteredInteractive?this.setAriaLabel():(this.hasEnteredInteractive=!0,this.setAriaLabel())},0)),this.onChangeEmitter.fire({value:t})}}class Xoe{constructor(t,n){oe(this,"context");oe(this,"display");this.context=t,this.display=n}toggle(t){if(t.empty||t.traceType!==H2.CANDLESTICK)return;const n=this.context.active;n&&"getExtremaTargets"in n&&this.display.toggleFocus(m1.GO_TO_EXTREMA)}returnToTraceScope(){this.display.toggleFocus(m1.GO_TO_EXTREMA)}}const Nu=class Nu{constructor(){}static get ctrl(){return Nu.IS_MAC?"command":"ctrl"}static get alt(){return Nu.IS_MAC?"option":"alt"}static get enter(){return Nu.IS_MAC?"return":"enter"}};oe(Nu,"IS_MAC",(()=>{var n;return(((n=navigator.userAgentData)==null?void 0:n.platform)??navigator.platform).toLowerCase().includes("mac")})());let Pt=Nu;const bH=[{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:`${Pt.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:`${Pt.ctrl} + shift + arrow keys`},{description:"Stop Autoplay",key:`${Pt.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:`${Pt.ctrl} + ,`},{description:"Open Chat",key:"?"}],jP=[{description:"Move around Subplot",key:"arrow keys"},{description:"Activate Current Subplot",key:`${Pt.enter}`},{description:"Announce Plot Title",key:"l t"},{description:"Announce Subtitle",key:"l s"},{description:"Announce Caption",key:"l c"},{description:"Open Settings",key:`${Pt.ctrl} + ,`}];class Woe{constructor(t,n){oe(this,"context");oe(this,"display");oe(this,"scopedMenuItems");this.context=t,this.display=n,this.scopedMenuItems={[m1.TRACE]:bH,[m1.TRACE_LABEL]:bH,[m1.BRAILLE]:bH,[m1.SUBPLOT]:jP,[m1.FIGURE_LABEL]:jP}}getMenuItems(){return this.scopedMenuItems[this.context.scope]??[]}toggle(){this.display.toggleFocus(m1.HELP)}}class Yoe{constructor(t){oe(this,"highlightedElements");oe(this,"highlightedSubplots");oe(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=zt.createHighlightElement(t,this.currentHighlightColor);return n.id=`${Le.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 l=this.createHighlightElement(n);this.highlightedElements.set(n,l)}catch(l){console.error("Failed to highlight element:",l)}}highlightSubplotElements(t){var a;this.unhighlightSubplotElements();const n=(a=document.querySelector('g[id^="maidr-"] > path[style*="fill"]'))==null?void 0:a.parentElement,l=(n==null?void 0:n.querySelector('path[style*="fill"]'))||void 0;for(const o of t)zt.setSubplotHighlightSvgWithAdaptiveColor(o,this.currentHighlightColor,l),this.highlightedSubplots.add(o)}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(l){console.error("Failed to unhighlight element:",l)}}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=>{zt.removeSubplotHighlightSvg(t)}),this.highlightedSubplots.clear()}unhighlightAll(){this.unhighlightTraceElements(),this.unhighlightSubplotElements()}}class Koe{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.context=t,this.autoplay=n}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("UPWARD",t)}}class Joe{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.autoplay=n,this.context=t}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("DOWNWARD",t)}}class e7e{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.autoplay=n,this.context=t}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("FORWARD",t)}}class t7e{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.autoplay=n,this.context=t}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("BACKWARD",t)}}class n7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.stop()}}class r7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.speedUp()}}class i7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.speedDown()}}class a7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.resetSpeed()}}class o8{constructor(t,n){oe(this,"context");oe(this,"textViewModel");this.context=t,this.textViewModel=n}}class o7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="trace"&&!t.empty){const n=`X label is ${t.xAxis}`;this.textViewModel.update(n)}}}class l7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="trace"&&!t.empty){const n=`Y label is ${t.yAxis}`;this.textViewModel.update(n)}}}class s7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="trace"&&!t.empty){const n=`Fill is ${t.fill}`;this.textViewModel.update(n)}}}class u7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(!t.empty){if(t.type==="figure"){const n=`Figure title is ${t.title}`;this.textViewModel.update(n)}else if(t.type==="trace"){const n=`Subplot title is ${t.title}`;this.textViewModel.update(n)}}}}class c7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="figure"&&!t.empty){const n=`Subtitle is ${t.subtitle}`;this.textViewModel.update(n)}}}class T7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="figure"&&!t.empty){const n=`Caption is ${t.caption}`;this.textViewModel.update(n)}}}class Q7e extends o8{constructor(n,l,a,o,i){super(n,i);oe(this,"audio");oe(this,"brailleViewModel");oe(this,"highlight");this.audio=l,this.highlight=a,this.brailleViewModel=o}execute(){const n=this.context.state;switch(n.type){case"figure":case"subplot":this.textViewModel.update(n);break;case"trace":this.textViewModel.update(n),this.audio.update(n),this.brailleViewModel.update(n),this.highlight.update(n);break}}}class f7e{constructor(t,n){oe(this,"context");oe(this,"goToExtremaViewModel");this.context=t,this.goToExtremaViewModel=n}execute(){const t=this.context.state;t.type==="trace"&&this.goToExtremaViewModel.toggle(t)}}class d7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.moveUp()}}class h7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.moveDown()}}class p7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.selectCurrent()}}class m7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.hide()}}class y7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("UPWARD")}}class g7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("DOWNWARD")}}class v7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("BACKWARD")}}class x7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("FORWARD")}}class L7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("UPWARD")}}class b7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("DOWNWARD")}}class H7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("BACKWARD")}}class E7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("FORWARD")}}class S7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.enterSubplot()}}class M7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.exitSubplot()}}class A7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.stepTrace("UPWARD")}}class _7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.stepTrace("DOWNWARD")}}class O7e{constructor(t,n){oe(this,"context");oe(this,"brailleViewModel");this.context=t,this.brailleViewModel=n}execute(){const t=this.context.state;t.type==="trace"&&this.brailleViewModel.toggle(t)}}class C7e{constructor(t){oe(this,"textViewModel");this.textViewModel=t}execute(){this.textViewModel.toggle()}}class w7e{constructor(t){oe(this,"audio");this.audio=t}execute(){this.audio.toggle()}}class V7e{constructor(t,n){oe(this,"context");oe(this,"reviewViewModel");this.context=t,this.reviewViewModel=n}execute(){const t=this.context.state;t.type==="trace"&&this.reviewViewModel.toggle(t)}}class D7e{constructor(t){oe(this,"helpViewModel");this.helpViewModel=t}execute(){this.helpViewModel.toggle()}}class R7e{constructor(t){oe(this,"chatViewModel");this.chatViewModel=t}execute(){this.chatViewModel.toggle()}}class k7e{constructor(t){oe(this,"settingsViewModel");this.settingsViewModel=t}execute(){this.settingsViewModel.toggle()}}class FP{constructor(t,n){oe(this,"context");oe(this,"scope");this.context=t,this.scope=n}execute(){this.context.toggleScope(this.scope)}}class N7e{constructor(t){oe(this,"context");oe(this,"audioService");oe(this,"autoplayService");oe(this,"highlightService");oe(this,"brailleViewModel");oe(this,"chatViewModel");oe(this,"goToExtremaViewModel");oe(this,"helpViewModel");oe(this,"reviewViewModel");oe(this,"settingsViewModel");oe(this,"textViewModel");this.context=t.context,this.audioService=t.audioService,this.autoplayService=t.autoplayService,this.highlightService=t.highlightService,this.brailleViewModel=t.brailleViewModel,this.chatViewModel=t.chatViewModel,this.goToExtremaViewModel=t.goToExtremaViewModel,this.helpViewModel=t.helpViewModel,this.reviewViewModel=t.reviewViewModel,this.settingsViewModel=t.settingsViewModel,this.textViewModel=t.textViewModel}create(t){switch(t){case"MOVE_UP":return new y7e(this.context);case"MOVE_DOWN":return new g7e(this.context);case"MOVE_LEFT":return new v7e(this.context);case"MOVE_RIGHT":return new x7e(this.context);case"MOVE_TO_TOP_EXTREME":return new L7e(this.context);case"MOVE_TO_BOTTOM_EXTREME":return new b7e(this.context);case"MOVE_TO_LEFT_EXTREME":return new H7e(this.context);case"MOVE_TO_RIGHT_EXTREME":return new E7e(this.context);case"MOVE_TO_TRACE_CONTEXT":return new S7e(this.context);case"MOVE_TO_SUBPLOT_CONTEXT":return new M7e(this.context);case"MOVE_TO_NEXT_TRACE":return new A7e(this.context);case"MOVE_TO_PREV_TRACE":return new _7e(this.context);case"TOGGLE_AUDIO":return new w7e(this.audioService);case"TOGGLE_BRAILLE":return new O7e(this.context,this.brailleViewModel);case"TOGGLE_TEXT":return new C7e(this.textViewModel);case"TOGGLE_REVIEW":return new V7e(this.context,this.reviewViewModel);case"TOGGLE_HELP":return new D7e(this.helpViewModel);case"TOGGLE_CHAT":return new R7e(this.chatViewModel);case"TOGGLE_SETTINGS":return new k7e(this.settingsViewModel);case"GO_TO_EXTREMA":return new f7e(this.context,this.goToExtremaViewModel);case"GO_TO_EXTREMA_MOVE_UP":return new d7e(this.goToExtremaViewModel);case"GO_TO_EXTREMA_MOVE_DOWN":return new h7e(this.goToExtremaViewModel);case"GO_TO_EXTREMA_SELECT":return new p7e(this.goToExtremaViewModel);case"GO_TO_EXTREMA_CLOSE":return new m7e(this.goToExtremaViewModel);case"DESCRIBE_X":return new o7e(this.context,this.textViewModel);case"DESCRIBE_Y":return new l7e(this.context,this.textViewModel);case"DESCRIBE_FILL":return new s7e(this.context,this.textViewModel);case"DESCRIBE_POINT":return new Q7e(this.context,this.audioService,this.highlightService,this.brailleViewModel,this.textViewModel);case"DESCRIBE_TITLE":return new u7e(this.context,this.textViewModel);case"DESCRIBE_SUBTITLE":return new c7e(this.context,this.textViewModel);case"DESCRIBE_CAPTION":return new T7e(this.context,this.textViewModel);case"ACTIVATE_FIGURE_LABEL_SCOPE":case"DEACTIVATE_FIGURE_LABEL_SCOPE":return new FP(this.context,m1.FIGURE_LABEL);case"ACTIVATE_TRACE_LABEL_SCOPE":case"DEACTIVATE_TRACE_LABEL_SCOPE":return new FP(this.context,m1.TRACE_LABEL);case"AUTOPLAY_UPWARD":return new Koe(this.context,this.autoplayService);case"AUTOPLAY_DOWNWARD":return new Joe(this.context,this.autoplayService);case"AUTOPLAY_FORWARD":return new e7e(this.context,this.autoplayService);case"AUTOPLAY_BACKWARD":return new t7e(this.context,this.autoplayService);case"STOP_AUTOPLAY":return new n7e(this.autoplayService);case"SPEED_UP_AUTOPLAY":return new r7e(this.autoplayService);case"SPEED_DOWN_AUTOPLAY":return new i7e(this.autoplayService);case"RESET_AUTOPLAY_SPEED":return new a7e(this.autoplayService);default:throw new Error(`Invalid command name: ${t}`)}}}const B7e={ACTIVATE_TRACE_LABEL_SCOPE:"l",AUTOPLAY_UPWARD:`${Pt.ctrl}+shift+up`,AUTOPLAY_DOWNWARD:`${Pt.ctrl}+shift+down`,AUTOPLAY_FORWARD:`${Pt.ctrl}+shift+right`,AUTOPLAY_BACKWARD:`${Pt.ctrl}+shift+left`,STOP_AUTOPLAY:`${Pt.ctrl}, up, down, left, right`,SPEED_UP_AUTOPLAY:".",SPEED_DOWN_AUTOPLAY:",",RESET_AUTOPLAY_SPEED:"/",MOVE_UP:"up",MOVE_DOWN:"down",MOVE_RIGHT:"right",MOVE_LEFT:"left",MOVE_TO_TOP_EXTREME:`${Pt.ctrl}+up`,MOVE_TO_BOTTOM_EXTREME:`${Pt.ctrl}+down`,MOVE_TO_LEFT_EXTREME:`${Pt.ctrl}+left`,MOVE_TO_RIGHT_EXTREME:`${Pt.ctrl}+right`,MOVE_TO_NEXT_TRACE:"pageup",MOVE_TO_PREV_TRACE:"pagedown",TOGGLE_BRAILLE:"b",TOGGLE_TEXT:"t",TOGGLE_AUDIO:"s",TOGGLE_REVIEW:"r",TOGGLE_HELP:`${Pt.ctrl}+/`,TOGGLE_CHAT:"shift+/",TOGGLE_SETTINGS:`${Pt.ctrl}+,`,DESCRIBE_POINT:"space"},P7e={TOGGLE_CHAT:"esc"},I7e={DEACTIVATE_FIGURE_LABEL_SCOPE:"*",DESCRIBE_TITLE:"t",DESCRIBE_SUBTITLE:"s",DESCRIBE_CAPTION:"c",TOGGLE_HELP:`${Pt.ctrl}+/`},j7e={TOGGLE_HELP:"esc"},F7e={ACTIVATE_FIGURE_LABEL_SCOPE:"l",DESCRIBE_TITLE:"t",DESCRIBE_POINT:"space",MOVE_UP:"up",MOVE_DOWN:"down",MOVE_RIGHT:"right",MOVE_LEFT:"left",MOVE_TO_TOP_EXTREME:`${Pt.ctrl}+up`,MOVE_TO_BOTTOM_EXTREME:`${Pt.ctrl}+down`,MOVE_TO_LEFT_EXTREME:`${Pt.ctrl}+left`,MOVE_TO_RIGHT_EXTREME:`${Pt.ctrl}+right`,MOVE_TO_TRACE_CONTEXT:`${Pt.enter}`,TOGGLE_HELP:`${Pt.ctrl}+/`,TOGGLE_CHAT:"shift+/",TOGGLE_SETTINGS:`${Pt.ctrl}+,`},z7e={DEACTIVATE_TRACE_LABEL_SCOPE:"*",DESCRIBE_X:"x",DESCRIBE_Y:"y",DESCRIBE_FILL:"f",DESCRIBE_TITLE:"t",DESCRIBE_SUBTITLE:"s",DESCRIBE_CAPTION:"c",TOGGLE_HELP:`${Pt.ctrl}+/`},q7e={TOGGLE_BRAILLE:"b",TOGGLE_REVIEW:"r",ALLOW_DEFAULT:`up, down, left, right,
668
+ ${xH(c)}`}]}]})}formatResponse(n){return n.content.length===0?{success:!1,error:"Invalid response format"}:{success:!0,data:n.content[0].text}}getHeaders(n){const l=super.getHeaders(n);return l["anthropic-version"]=this.version,l}}class Goe extends LH{constructor(n,l,a){super(n,l);oe(this,"version");this.version=a}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,l,a,o,i,s){const c={maidrJson:l,currentPositionText:o,message:i,expertiseLevel:s};return JSON.stringify({generationConfig:{},safetySettings:[],contents:[{role:"user",parts:[{text:vH(n,c.expertiseLevel)}]},{role:"user",parts:[{text:xH(c)},{inlineData:{data:a.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 l=super.getHeaders(n);return delete l.Authorization,l}}class Zoe{constructor(t,n){oe(this,"context");oe(this,"focusStack");oe(this,"plot");oe(this,"onChangeEmitter");oe(this,"onChange");oe(this,"hasEnteredInteractive",!1);this.context=t,this.focusStack=new uH,this.focusStack.push(this.context.scope),this.plot=n,this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event,this.removeInstruction()}dispose(){this.addInstruction(),this.onChangeEmitter.dispose()}getInstruction(t=!0){return this.context.getInstruction(t)}addInstruction(){this.plot.setAttribute(Le.ARIA_LABEL,this.getInstruction()),this.plot.setAttribute(Le.TITLE,this.getInstruction()),this.plot.setAttribute(Le.ROLE,Le.IMAGE),this.plot.tabIndex=0}removeInstruction(){const t=this.hasEnteredInteractive?"":this.getInstruction(!1);this.plot.setAttribute(Le.ARIA_LABEL,t),this.plot.removeAttribute(Le.TITLE),this.plot.setAttribute(Le.ROLE,Le.APPLICATION),this.plot.tabIndex=0}setAriaLabel(){const t=this.hasEnteredInteractive?"":this.getInstruction(!1);this.plot.setAttribute(Le.ARIA_LABEL,t)}toggleFocus(t){this.focusStack.removeLast(t)||this.focusStack.push(t),this.context.toggleScope(t),this.updateFocus(this.focusStack.peek())}updateFocus(t){(t==="TRACE"||t==="SUBPLOT")&&(this.plot.tabIndex=0,setTimeout(()=>{this.plot.focus(),this.hasEnteredInteractive?this.setAriaLabel():(this.hasEnteredInteractive=!0,this.setAriaLabel())},0)),this.onChangeEmitter.fire({value:t})}}class Xoe{constructor(t,n){oe(this,"context");oe(this,"display");this.context=t,this.display=n}toggle(t){if(t.empty||t.traceType!==H2.CANDLESTICK)return;const n=this.context.active;n&&"getExtremaTargets"in n&&this.display.toggleFocus(m1.GO_TO_EXTREMA)}returnToTraceScope(){this.display.toggleFocus(m1.GO_TO_EXTREMA)}}const Nu=class Nu{constructor(){}static get ctrl(){return Nu.IS_MAC?"command":"ctrl"}static get alt(){return Nu.IS_MAC?"option":"alt"}static get enter(){return Nu.IS_MAC?"return":"enter"}};oe(Nu,"IS_MAC",(()=>{var n;return(((n=navigator.userAgentData)==null?void 0:n.platform)??navigator.platform).toLowerCase().includes("mac")})());let Pt=Nu;const bH=[{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:`${Pt.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:`${Pt.ctrl} + shift + arrow keys`},{description:"Stop Autoplay",key:`${Pt.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:`${Pt.ctrl} + ,`},{description:"Open Chat",key:"?"}],jP=[{description:"Move around Subplot",key:"arrow keys"},{description:"Activate Current Subplot",key:`${Pt.enter}`},{description:"Announce Plot Title",key:"l t"},{description:"Announce Subtitle",key:"l s"},{description:"Announce Caption",key:"l c"},{description:"Open Settings",key:`${Pt.ctrl} + ,`}];class Woe{constructor(t,n){oe(this,"context");oe(this,"display");oe(this,"scopedMenuItems");this.context=t,this.display=n,this.scopedMenuItems={[m1.TRACE]:bH,[m1.TRACE_LABEL]:bH,[m1.BRAILLE]:bH,[m1.SUBPLOT]:jP,[m1.FIGURE_LABEL]:jP}}getMenuItems(){return this.scopedMenuItems[this.context.scope]??[]}toggle(){this.display.toggleFocus(m1.HELP)}}class Yoe{constructor(t){oe(this,"highlightedElements");oe(this,"highlightedSubplots");oe(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=zt.createHighlightElement(t,this.currentHighlightColor);return n.id=`${Le.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 l=this.createHighlightElement(n);this.highlightedElements.set(n,l)}catch(l){console.error("Failed to highlight element:",l)}}highlightSubplotElements(t){var a;this.unhighlightSubplotElements();const n=(a=document.querySelector('g[id^="maidr-"] > path[style*="fill"]'))==null?void 0:a.parentElement,l=(n==null?void 0:n.querySelector('path[style*="fill"]'))||void 0;for(const o of t)zt.setSubplotHighlightSvgWithAdaptiveColor(o,this.currentHighlightColor,l),this.highlightedSubplots.add(o)}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(l){console.error("Failed to unhighlight element:",l)}}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=>{zt.removeSubplotHighlightSvg(t)}),this.highlightedSubplots.clear()}unhighlightAll(){this.unhighlightTraceElements(),this.unhighlightSubplotElements()}}class Koe{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.context=t,this.autoplay=n}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("UPWARD",t)}}class Joe{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.autoplay=n,this.context=t}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("DOWNWARD",t)}}class e7e{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.autoplay=n,this.context=t}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("FORWARD",t)}}class t7e{constructor(t,n){oe(this,"context");oe(this,"autoplay");this.autoplay=n,this.context=t}execute(){const t=this.context.state;t.type==="trace"&&!t.empty&&this.autoplay.start("BACKWARD",t)}}class n7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.stop()}}class r7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.speedUp()}}class i7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.speedDown()}}class a7e{constructor(t){oe(this,"autoplay");this.autoplay=t}execute(){this.autoplay.resetSpeed()}}class o8{constructor(t,n){oe(this,"context");oe(this,"textViewModel");this.context=t,this.textViewModel=n}}class o7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="trace"&&!t.empty){const n=`X label is ${t.xAxis}`;this.textViewModel.update(n)}}}class l7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="trace"&&!t.empty){const n=`Y label is ${t.yAxis}`;this.textViewModel.update(n)}}}class s7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="trace"&&!t.empty){const n=`Fill is ${t.fill}`;this.textViewModel.update(n)}}}class u7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(!t.empty){if(t.type==="figure"){const n=`Figure title is ${t.title}`;this.textViewModel.update(n)}else if(t.type==="trace"){const n=`Subplot title is ${t.title}`;this.textViewModel.update(n)}}}}class c7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="figure"&&!t.empty){const n=`Subtitle is ${t.subtitle}`;this.textViewModel.update(n)}}}class T7e extends o8{constructor(t,n){super(t,n)}execute(){const t=this.context.state;if(t.type==="figure"&&!t.empty){const n=`Caption is ${t.caption}`;this.textViewModel.update(n)}}}class Q7e extends o8{constructor(n,l,a,o,i){super(n,i);oe(this,"audio");oe(this,"brailleViewModel");oe(this,"highlight");this.audio=l,this.highlight=a,this.brailleViewModel=o}execute(){const n=this.context.state;switch(n.type){case"figure":case"subplot":this.textViewModel.update(n);break;case"trace":this.textViewModel.update(n),this.audio.update(n),this.brailleViewModel.update(n),this.highlight.update(n);break}}}class f7e{constructor(t,n){oe(this,"context");oe(this,"goToExtremaViewModel");this.context=t,this.goToExtremaViewModel=n}execute(){const t=this.context.state;t.type==="trace"&&this.goToExtremaViewModel.toggle(t)}}class d7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.moveUp()}}class h7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.moveDown()}}class p7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.selectCurrent()}}class m7e{constructor(t){oe(this,"goToExtremaViewModel");this.goToExtremaViewModel=t}execute(){this.goToExtremaViewModel.hide()}}class y7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("UPWARD")}}class g7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("DOWNWARD")}}class v7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("BACKWARD")}}class x7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveOnce("FORWARD")}}class L7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("UPWARD")}}class b7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("DOWNWARD")}}class H7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("BACKWARD")}}class E7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.moveToExtreme("FORWARD")}}class S7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.enterSubplot()}}class M7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.exitSubplot()}}class A7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.stepTrace("UPWARD")}}class _7e{constructor(t){oe(this,"context");this.context=t}execute(){this.context.stepTrace("DOWNWARD")}}class O7e{constructor(t,n){oe(this,"context");oe(this,"brailleViewModel");this.context=t,this.brailleViewModel=n}execute(){const t=this.context.state;t.type==="trace"&&this.brailleViewModel.toggle(t)}}class C7e{constructor(t){oe(this,"textViewModel");this.textViewModel=t}execute(){this.textViewModel.toggle()}}class w7e{constructor(t){oe(this,"audio");this.audio=t}execute(){this.audio.toggle()}}class V7e{constructor(t,n){oe(this,"context");oe(this,"reviewViewModel");this.context=t,this.reviewViewModel=n}execute(){const t=this.context.state;t.type==="trace"&&this.reviewViewModel.toggle(t)}}class D7e{constructor(t){oe(this,"helpViewModel");this.helpViewModel=t}execute(){this.helpViewModel.toggle()}}class R7e{constructor(t){oe(this,"chatViewModel");this.chatViewModel=t}execute(){this.chatViewModel.toggle()}}class k7e{constructor(t){oe(this,"settingsViewModel");this.settingsViewModel=t}execute(){this.settingsViewModel.toggle()}}class FP{constructor(t,n){oe(this,"context");oe(this,"scope");this.context=t,this.scope=n}execute(){this.context.toggleScope(this.scope)}}class N7e{constructor(t){oe(this,"context");oe(this,"audioService");oe(this,"autoplayService");oe(this,"highlightService");oe(this,"brailleViewModel");oe(this,"chatViewModel");oe(this,"goToExtremaViewModel");oe(this,"helpViewModel");oe(this,"reviewViewModel");oe(this,"settingsViewModel");oe(this,"textViewModel");this.context=t.context,this.audioService=t.audioService,this.autoplayService=t.autoplayService,this.highlightService=t.highlightService,this.brailleViewModel=t.brailleViewModel,this.chatViewModel=t.chatViewModel,this.goToExtremaViewModel=t.goToExtremaViewModel,this.helpViewModel=t.helpViewModel,this.reviewViewModel=t.reviewViewModel,this.settingsViewModel=t.settingsViewModel,this.textViewModel=t.textViewModel}create(t){switch(t){case"MOVE_UP":return new y7e(this.context);case"MOVE_DOWN":return new g7e(this.context);case"MOVE_LEFT":return new v7e(this.context);case"MOVE_RIGHT":return new x7e(this.context);case"MOVE_TO_TOP_EXTREME":return new L7e(this.context);case"MOVE_TO_BOTTOM_EXTREME":return new b7e(this.context);case"MOVE_TO_LEFT_EXTREME":return new H7e(this.context);case"MOVE_TO_RIGHT_EXTREME":return new E7e(this.context);case"MOVE_TO_TRACE_CONTEXT":return new S7e(this.context);case"MOVE_TO_SUBPLOT_CONTEXT":return new M7e(this.context);case"MOVE_TO_NEXT_TRACE":return new A7e(this.context);case"MOVE_TO_PREV_TRACE":return new _7e(this.context);case"TOGGLE_AUDIO":return new w7e(this.audioService);case"TOGGLE_BRAILLE":return new O7e(this.context,this.brailleViewModel);case"TOGGLE_TEXT":return new C7e(this.textViewModel);case"TOGGLE_REVIEW":return new V7e(this.context,this.reviewViewModel);case"TOGGLE_HELP":return new D7e(this.helpViewModel);case"TOGGLE_CHAT":return new R7e(this.chatViewModel);case"TOGGLE_SETTINGS":return new k7e(this.settingsViewModel);case"GO_TO_EXTREMA":return new f7e(this.context,this.goToExtremaViewModel);case"GO_TO_EXTREMA_MOVE_UP":return new d7e(this.goToExtremaViewModel);case"GO_TO_EXTREMA_MOVE_DOWN":return new h7e(this.goToExtremaViewModel);case"GO_TO_EXTREMA_SELECT":return new p7e(this.goToExtremaViewModel);case"GO_TO_EXTREMA_CLOSE":return new m7e(this.goToExtremaViewModel);case"DESCRIBE_X":return new o7e(this.context,this.textViewModel);case"DESCRIBE_Y":return new l7e(this.context,this.textViewModel);case"DESCRIBE_FILL":return new s7e(this.context,this.textViewModel);case"DESCRIBE_POINT":return new Q7e(this.context,this.audioService,this.highlightService,this.brailleViewModel,this.textViewModel);case"DESCRIBE_TITLE":return new u7e(this.context,this.textViewModel);case"DESCRIBE_SUBTITLE":return new c7e(this.context,this.textViewModel);case"DESCRIBE_CAPTION":return new T7e(this.context,this.textViewModel);case"ACTIVATE_FIGURE_LABEL_SCOPE":case"DEACTIVATE_FIGURE_LABEL_SCOPE":return new FP(this.context,m1.FIGURE_LABEL);case"ACTIVATE_TRACE_LABEL_SCOPE":case"DEACTIVATE_TRACE_LABEL_SCOPE":return new FP(this.context,m1.TRACE_LABEL);case"AUTOPLAY_UPWARD":return new Koe(this.context,this.autoplayService);case"AUTOPLAY_DOWNWARD":return new Joe(this.context,this.autoplayService);case"AUTOPLAY_FORWARD":return new e7e(this.context,this.autoplayService);case"AUTOPLAY_BACKWARD":return new t7e(this.context,this.autoplayService);case"STOP_AUTOPLAY":return new n7e(this.autoplayService);case"SPEED_UP_AUTOPLAY":return new r7e(this.autoplayService);case"SPEED_DOWN_AUTOPLAY":return new i7e(this.autoplayService);case"RESET_AUTOPLAY_SPEED":return new a7e(this.autoplayService);default:throw new Error(`Invalid command name: ${t}`)}}}const B7e={ACTIVATE_TRACE_LABEL_SCOPE:"l",AUTOPLAY_UPWARD:`${Pt.ctrl}+shift+up`,AUTOPLAY_DOWNWARD:`${Pt.ctrl}+shift+down`,AUTOPLAY_FORWARD:`${Pt.ctrl}+shift+right`,AUTOPLAY_BACKWARD:`${Pt.ctrl}+shift+left`,STOP_AUTOPLAY:`${Pt.ctrl}, up, down, left, right`,SPEED_UP_AUTOPLAY:".",SPEED_DOWN_AUTOPLAY:",",RESET_AUTOPLAY_SPEED:"/",MOVE_UP:"up",MOVE_DOWN:"down",MOVE_RIGHT:"right",MOVE_LEFT:"left",MOVE_TO_TOP_EXTREME:`${Pt.ctrl}+up`,MOVE_TO_BOTTOM_EXTREME:`${Pt.ctrl}+down`,MOVE_TO_LEFT_EXTREME:`${Pt.ctrl}+left`,MOVE_TO_RIGHT_EXTREME:`${Pt.ctrl}+right`,MOVE_TO_NEXT_TRACE:"pageup",MOVE_TO_PREV_TRACE:"pagedown",TOGGLE_BRAILLE:"b",TOGGLE_TEXT:"t",TOGGLE_AUDIO:"s",TOGGLE_REVIEW:"r",TOGGLE_HELP:`${Pt.ctrl}+/`,TOGGLE_CHAT:"shift+/",TOGGLE_SETTINGS:`${Pt.ctrl}+,`,DESCRIBE_POINT:"space"},P7e={TOGGLE_CHAT:"esc"},I7e={DEACTIVATE_FIGURE_LABEL_SCOPE:"*",DESCRIBE_TITLE:"t",DESCRIBE_SUBTITLE:"s",DESCRIBE_CAPTION:"c",TOGGLE_HELP:`${Pt.ctrl}+/`},j7e={TOGGLE_HELP:"esc"},F7e={ACTIVATE_FIGURE_LABEL_SCOPE:"l",DESCRIBE_TITLE:"t",DESCRIBE_POINT:"space",MOVE_UP:"up",MOVE_DOWN:"down",MOVE_RIGHT:"right",MOVE_LEFT:"left",MOVE_TO_TOP_EXTREME:`${Pt.ctrl}+up`,MOVE_TO_BOTTOM_EXTREME:`${Pt.ctrl}+down`,MOVE_TO_LEFT_EXTREME:`${Pt.ctrl}+left`,MOVE_TO_RIGHT_EXTREME:`${Pt.ctrl}+right`,MOVE_TO_TRACE_CONTEXT:`${Pt.enter}`,TOGGLE_HELP:`${Pt.ctrl}+/`,TOGGLE_CHAT:"shift+/",TOGGLE_SETTINGS:`${Pt.ctrl}+,`},z7e={DEACTIVATE_TRACE_LABEL_SCOPE:"*",DESCRIBE_X:"x",DESCRIBE_Y:"y",DESCRIBE_FILL:"f",DESCRIBE_TITLE:"t",DESCRIBE_SUBTITLE:"s",DESCRIBE_CAPTION:"c",TOGGLE_HELP:`${Pt.ctrl}+/`},q7e={TOGGLE_BRAILLE:"b",TOGGLE_REVIEW:"r",ALLOW_DEFAULT:`up, down, left, right,
669
669
  ${Pt.ctrl}+up, ${Pt.ctrl}+down,
670
670
  ${Pt.ctrl}+left, ${Pt.ctrl}+right,
671
671
  pageup, pagedown, home, end,
672
- tab, ${Pt.ctrl}+a, ${Pt.ctrl}+c`},$7e={TOGGLE_SETTINGS:"esc"},U7e={ACTIVATE_TRACE_LABEL_SCOPE:"l",AUTOPLAY_UPWARD:`${Pt.ctrl}+shift+up`,AUTOPLAY_DOWNWARD:`${Pt.ctrl}+shift+down`,AUTOPLAY_FORWARD:`${Pt.ctrl}+shift+right`,AUTOPLAY_BACKWARD:`${Pt.ctrl}+shift+left`,STOP_AUTOPLAY:`${Pt.ctrl}, up, down, left, right`,SPEED_UP_AUTOPLAY:".",SPEED_DOWN_AUTOPLAY:",",RESET_AUTOPLAY_SPEED:"/",MOVE_UP:"up",MOVE_DOWN:"down",MOVE_RIGHT:"right",MOVE_LEFT:"left",MOVE_TO_TOP_EXTREME:`${Pt.ctrl}+up`,MOVE_TO_BOTTOM_EXTREME:`${Pt.ctrl}+down`,MOVE_TO_LEFT_EXTREME:`${Pt.ctrl}+left`,MOVE_TO_RIGHT_EXTREME:`${Pt.ctrl}+right`,MOVE_TO_SUBPLOT_CONTEXT:"esc",MOVE_TO_NEXT_TRACE:"pageup",MOVE_TO_PREV_TRACE:"pagedown",TOGGLE_BRAILLE:"b",TOGGLE_TEXT:"t",TOGGLE_AUDIO:"s",TOGGLE_REVIEW:"r",TOGGLE_HELP:`${Pt.ctrl}+/`,TOGGLE_CHAT:"shift+/",TOGGLE_SETTINGS:`${Pt.ctrl}+,`,DESCRIBE_POINT:"space",GO_TO_EXTREMA:"g"},G7e={GO_TO_EXTREMA_MOVE_UP:"up",GO_TO_EXTREMA_MOVE_DOWN:"down",GO_TO_EXTREMA_SELECT:"enter",GO_TO_EXTREMA_CLOSE:"esc"},Z7e={[m1.BRAILLE]:B7e,[m1.CHAT]:P7e,[m1.FIGURE_LABEL]:I7e,[m1.GO_TO_EXTREMA]:G7e,[m1.HELP]:j7e,[m1.REVIEW]:q7e,[m1.SETTINGS]:$7e,[m1.SUBPLOT]:F7e,[m1.TRACE]:U7e,[m1.TRACE_LABEL]:z7e};class X7e{constructor(t){oe(this,"commandFactory");this.commandFactory=new N7e(t)}register(t){o4.filter=n=>{const l=n.target;return l.tagName.toLowerCase()===Le.INPUT?l.id.startsWith(Le.REVIEW_INPUT):l.tagName.toLowerCase()===Le.TEXT_AREA?l.id.startsWith(Le.BRAILLE_TEXT_AREA):!0};for(const[n,l]of Object.entries(Z7e))for(const[a,o]of Object.entries(l))a==="STOP_AUTOPLAY"&&o4("*",m1.TRACE,i=>{(o4.command||o4.ctrl)&&this.commandFactory.create(a).execute(i)}),o4(o,{scope:n},i=>{a!=="ALLOW_DEFAULT"&&(i.preventDefault(),this.commandFactory.create(a).execute(i))});o4.setScope(t)}unregister(){o4.unbind()}}class W7e{constructor(){oe(this,"onChangeEmitter");oe(this,"onChange");this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose()}notify(t){t&&this.onChangeEmitter.fire({value:t})}}class Y7e{constructor(t,n,l){oe(this,"notification");oe(this,"display");oe(this,"text");oe(this,"enabled");oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=t,this.display=n,this.text=l,this.enabled=!1,this.onChangeEmitter=new zs,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(m1.REVIEW);const n=`Review is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}const HH="maidr-settings";class K7e{constructor(t,n){oe(this,"storage");oe(this,"display");oe(this,"defaultSettings");oe(this,"currentSettings");oe(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"},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 l=this.storage.load(HH);this.currentSettings=l??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(HH,this.currentSettings),this.notifyStateUpdate()}resetSettings(){return this.currentSettings=this.defaultSettings,this.storage.remove(HH),this.notifyStateUpdate(),this.currentSettings}toggle(){this.display.toggleFocus(m1.SETTINGS)}}class J7e{save(t,n){try{const l=JSON.stringify(n);localStorage.setItem(t,l)}catch(l){console.error(`Error while saving ${t} to storage`,l)}}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 zP(e){return!e.empty&&e.isLayerSwitch===!0&&typeof e.index=="number"&&typeof e.size=="number"}class ele{constructor(t){oe(this,"notification");oe(this,"mode");oe(this,"currentState",null);oe(this,"currentSubplotIndex",null);oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=t,this.mode="verbose",this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.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}formatCoordinateText(t){if(t.empty||!t.text)return null;const{text:n}=t,l=[];if(n.main&&n.main.value!==void 0){const a=Array.isArray(n.main.value)?n.main.value.join(", "):String(n.main.value);l.push(`${n.main.label} is ${a}`)}if(n.cross&&n.cross.value!==void 0){const a=Array.isArray(n.cross.value)?n.cross.value.join(", "):String(n.cross.value);l.push(`${n.cross.label} is ${a}`)}return n.fill&&n.fill.value!==void 0&&l.push(`${n.fill.label} is ${n.fill.value}`),l.length>0?l.join(", "):null}formatLayerSwitchAnnouncement(t){if(!zP(t))return"";let n=`Layer ${t.index} of ${t.size}: ${t.plotType||t.traceType} plot`;if(t.text){const l=[];t.text.main&&t.text.main.value!==void 0&&l.push(`${t.text.main.label} is ${t.text.main.value}`),t.text.cross&&t.text.cross.value!==void 0&&l.push(`${t.text.cross.label} is ${t.text.cross.value}`),t.text.fill&&t.text.fill.value!==void 0&&l.push(`${t.text.fill.label} is ${t.text.fill.value}`),l.length>0&&(n+=` at ${l.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,l){const a=l.length===1?`This is a ${l[0]} plot`:`This is a multi-layered plot containing ${l.join(Le.COMMA_SPACE)} plots`;return`Subplot ${t} of ${n}: ${a}. Press 'ENTER' to select this subplot.`}formatSubplotText(t,n,l,a){const o=a&&!a.empty?a.plotType:l;return`Layer ${t} of ${n}: ${o} plot`}isBoxPlotWithSection(t){return t.section!==void 0&&t.fill===void 0}formatVerboseTraceText(t){const n=new Array;if(n.push(t.main.label,Le.IS),t.range!==void 0?n.push(String(t.range.min),Le.THROUGH,String(t.range.max)):Array.isArray(t.main.value)?n.push(t.main.value.join(Le.COMMA_SPACE)):n.push(String(t.main.value)),t.section&&this.isBoxPlotWithSection(t)&&(t.section===e5.UPPER_OUTLIER||t.section===e5.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const l=typeof t.cross.label=="string"?t.cross.label.toLowerCase():t.cross.label,a=t.cross.value,o=`[${a.join(", ")}]`;if(a.length===0)return`${t.main.label} is ${t.main.value}, no ${t.section.toLowerCase()} for ${l}`;{const i=a.length===1?"is":"are";return`${t.main.label} is ${t.main.value}, ${t.section.toLowerCase()} for ${l} ${i} ${o}`}}if(t.section!==void 0)if(this.isBoxPlotWithSection(t)){const l=typeof t.cross.label=="string"?t.cross.label.toLowerCase():t.cross.label;n.push(Le.COMMA_SPACE,t.section.toLowerCase(),Le.SPACE,l)}else n.push(Le.COMMA_SPACE,t.section,Le.SPACE,t.cross.label);else n.push(Le.COMMA_SPACE,t.cross.label);if(Array.isArray(t.cross.value)?t.cross.value.length>1?n.push(Le.ARE,t.cross.value.join(Le.COMMA_SPACE)):t.cross.value.length>0&&n.push(Le.IS,t.cross.value.join(Le.COMMA_SPACE)):n.push(Le.IS,String(t.cross.value)),t.fill!==void 0){const l=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;n.push(Le.COMMA_SPACE,t.fill.label,Le.IS,l)}return n.join(Le.EMPTY)}formatTerseTraceText(t){const n=new Array;if(Array.isArray(t.main.value)?n.push(Le.OPEN_BRACKET,t.main.value.join(Le.COMMA_SPACE),Le.CLOSE_BRACKET):n.push(String(t.main.value),Le.COMMA_SPACE),t.section&&this.isBoxPlotWithSection(t)&&(t.section===e5.UPPER_OUTLIER||t.section===e5.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const l=t.cross.value,a=`[${l.join(", ")}]`;return l.length===0?`${t.main.value}, no ${t.section.toLowerCase()}`:`${t.main.value}, ${l.length} ${t.section.toLowerCase()} ${a}`}if(t.section!==void 0&&t.fill!==void 0?(n.push(t.section,Le.SPACE),Array.isArray(t.cross.value)?n.push(Le.OPEN_BRACKET,t.cross.value.join(Le.COMMA_SPACE),Le.CLOSE_BRACKET):n.push(String(t.cross.value))):(t.section!==void 0&&t.fill===void 0&&n.push(t.section,Le.SPACE),Array.isArray(t.cross.value)?n.push(Le.OPEN_BRACKET,t.cross.value.join(Le.COMMA_SPACE),Le.CLOSE_BRACKET):n.push(String(t.cross.value))),t.fill!==void 0){const l=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;t.section,n.push(Le.COMMA_SPACE,l)}return n.join(Le.EMPTY)}update(t){if(this.mode==="off")return;if(this.currentState=t,t.type==="trace"&&zP(t)){const l=this.formatLayerSwitchAnnouncement(t);this.notification.notify(l);return}if(t.type==="subplot"){const l=this.format(t);l&&this.notification.notify(l);return}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 EH{constructor(t,n){oe(this,"figure");oe(this,"context");oe(this,"displayService");oe(this,"notificationService");oe(this,"settingsService");oe(this,"audioService");oe(this,"brailleService");oe(this,"goToExtremaService");oe(this,"textService");oe(this,"reviewService");oe(this,"autoplayService");oe(this,"highlightService");oe(this,"helpService");oe(this,"chatService");oe(this,"textViewModel");oe(this,"brailleViewModel");oe(this,"goToExtremaViewModel");oe(this,"reviewViewModel");oe(this,"displayViewModel");oe(this,"helpViewModel");oe(this,"chatViewModel");oe(this,"settingsViewModel");oe(this,"keybinding");this.figure=new Loe(t),this.context=new $0e(this.figure),this.displayService=new Zoe(this.context,n),this.notificationService=new W7e,this.settingsService=new K7e(new J7e,this.displayService),this.audioService=new Moe(this.notificationService,this.context.state,this.settingsService),this.brailleService=new Noe(this.context,this.notificationService,this.displayService),this.goToExtremaService=new Xoe(this.context,this.displayService),this.textService=new ele(this.notificationService),this.reviewService=new Y7e(this.notificationService,this.displayService,this.textService),this.autoplayService=new woe(this.context,this.notificationService,this.settingsService),this.highlightService=new Yoe(this.settingsService),this.helpService=new Woe(this.context,this.displayService),this.chatService=new qoe(this.displayService,t),this.textViewModel=new oq(Ui,this.textService,this.notificationService,this.autoplayService),this.brailleViewModel=new Hz(Ui,this.brailleService),this.goToExtremaViewModel=new jz(Ui,this.goToExtremaService,this.context),this.reviewViewModel=new Xz(Ui,this.reviewService),this.displayViewModel=new Bz(Ui,this.displayService),this.helpViewModel=new $z(Ui,this.helpService),this.chatViewModel=new wz(Ui,this.chatService,this.audioService),this.settingsViewModel=new Kz(Ui,this.settingsService),this.keybinding=new X7e({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel}),this.registerViewModels(),this.registerObservers(),this.keybinding.register(this.context.scope)}announceInitialInstruction(){this.notificationService.notify(this.displayService.getInstruction(!1))}dispose(){this.keybinding.unregister(),O6.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.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(){O6.instance.register("text",this.textViewModel),O6.instance.register("braille",this.brailleViewModel),O6.instance.register("goToExtrema",this.goToExtremaViewModel),O6.instance.register("review",this.reviewViewModel),O6.instance.register("display",this.displayViewModel),O6.instance.register("help",this.helpViewModel),O6.instance.register("chat",this.chatViewModel),O6.instance.register("settings",this.settingsViewModel)}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(l=>l.forEach(a=>{a.addObserver(this.audioService),a.addObserver(this.brailleService),a.addObserver(this.textService),a.addObserver(this.reviewService),a.addObserver(this.highlightService)}))}))}}document.readyState==="loading"?document.addEventListener(_2.DOM_LOADED,qP):qP();function qP(){const e=document.querySelectorAll(`[${Le.MAIDR_DATA}]`);if(e.forEach(l=>{const a=l.getAttribute(Le.MAIDR_DATA);if(a)try{const o=JSON.parse(a);$P(o,l)}catch(o){console.error("Error parsing maidr attribute:",o)}}),e.length!==0)return;const t=window.maidr;if(!t)return;const n=document.getElementById(t.id);n&&$P(t,n)}function $P(e,t){let n=null,l=null;const a=()=>{setTimeout(()=>{if(!n)return;const f=document.activeElement;n.contains(f)||(l==null||l.dispose(),l=null)},0)},o=()=>{setTimeout(()=>{if(n&&!l){const f=JSON.parse(JSON.stringify(e));l=new EH(f,t),l.announceInitialInstruction()}},0)},i=()=>{if(document.visibilityState==="visible"){l&&(l.dispose(),l=null);const f=JSON.parse(JSON.stringify(e));l=new EH(f,t)}},s=document.createElement(Le.FIGURE);s.id=`${Le.MAIDR_FIGURE}-${e.id}`,t.parentNode.replaceChild(s,t),s.appendChild(t);const c=document.createElement(Le.ARTICLE);c.id=`${Le.MAIDR_ARTICLE}-${e.id}`,s.parentNode.replaceChild(c,s),c.appendChild(s);const u=document.createElement(Le.DIV);u.id=`${Le.REACT_CONTAINER}-${e.id}`,s.appendChild(u),n=s,t.addEventListener(_2.FOCUS_IN,o),t.addEventListener(_2.CLICK,o),n.addEventListener(_2.FOCUS_OUT,a),document.addEventListener(_2.VISIBILITY_CHANGE,i),V0e.createRoot(u,{identifierPrefix:e.id}).render(M0e(t)),(()=>{const f=JSON.parse(JSON.stringify(e));new EH(f,t).dispose()})()}}));
672
+ tab, ${Pt.ctrl}+a, ${Pt.ctrl}+c`},$7e={TOGGLE_SETTINGS:"esc"},U7e={ACTIVATE_TRACE_LABEL_SCOPE:"l",AUTOPLAY_UPWARD:`${Pt.ctrl}+shift+up`,AUTOPLAY_DOWNWARD:`${Pt.ctrl}+shift+down`,AUTOPLAY_FORWARD:`${Pt.ctrl}+shift+right`,AUTOPLAY_BACKWARD:`${Pt.ctrl}+shift+left`,STOP_AUTOPLAY:`${Pt.ctrl}, up, down, left, right`,SPEED_UP_AUTOPLAY:".",SPEED_DOWN_AUTOPLAY:",",RESET_AUTOPLAY_SPEED:"/",MOVE_UP:"up",MOVE_DOWN:"down",MOVE_RIGHT:"right",MOVE_LEFT:"left",MOVE_TO_TOP_EXTREME:`${Pt.ctrl}+up`,MOVE_TO_BOTTOM_EXTREME:`${Pt.ctrl}+down`,MOVE_TO_LEFT_EXTREME:`${Pt.ctrl}+left`,MOVE_TO_RIGHT_EXTREME:`${Pt.ctrl}+right`,MOVE_TO_SUBPLOT_CONTEXT:"esc",MOVE_TO_NEXT_TRACE:"pageup",MOVE_TO_PREV_TRACE:"pagedown",TOGGLE_BRAILLE:"b",TOGGLE_TEXT:"t",TOGGLE_AUDIO:"s",TOGGLE_REVIEW:"r",TOGGLE_HELP:`${Pt.ctrl}+/`,TOGGLE_CHAT:"shift+/",TOGGLE_SETTINGS:`${Pt.ctrl}+,`,DESCRIBE_POINT:"space",GO_TO_EXTREMA:"g"},G7e={GO_TO_EXTREMA_MOVE_UP:"up",GO_TO_EXTREMA_MOVE_DOWN:"down",GO_TO_EXTREMA_SELECT:"enter",GO_TO_EXTREMA_CLOSE:"esc"},Z7e={[m1.BRAILLE]:B7e,[m1.CHAT]:P7e,[m1.FIGURE_LABEL]:I7e,[m1.GO_TO_EXTREMA]:G7e,[m1.HELP]:j7e,[m1.REVIEW]:q7e,[m1.SETTINGS]:$7e,[m1.SUBPLOT]:F7e,[m1.TRACE]:U7e,[m1.TRACE_LABEL]:z7e};class X7e{constructor(t){oe(this,"commandFactory");this.commandFactory=new N7e(t)}register(t){o4.filter=n=>{const l=n.target;return l.tagName.toLowerCase()===Le.INPUT?l.id.startsWith(Le.REVIEW_INPUT):l.tagName.toLowerCase()===Le.TEXT_AREA?l.id.startsWith(Le.BRAILLE_TEXT_AREA):!0};for(const[n,l]of Object.entries(Z7e))for(const[a,o]of Object.entries(l))a==="STOP_AUTOPLAY"&&o4("*",m1.TRACE,i=>{(o4.command||o4.ctrl)&&this.commandFactory.create(a).execute(i)}),o4(o,{scope:n},i=>{a!=="ALLOW_DEFAULT"&&(i.preventDefault(),this.commandFactory.create(a).execute(i))});o4.setScope(t)}unregister(){o4.unbind()}}class W7e{constructor(){oe(this,"onChangeEmitter");oe(this,"onChange");this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose()}notify(t){t&&this.onChangeEmitter.fire({value:t})}}class Y7e{constructor(t,n,l){oe(this,"notification");oe(this,"display");oe(this,"text");oe(this,"enabled");oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=t,this.display=n,this.text=l,this.enabled=!1,this.onChangeEmitter=new zs,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(m1.REVIEW);const n=`Review is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}const HH="maidr-settings";class K7e{constructor(t,n){oe(this,"storage");oe(this,"display");oe(this,"defaultSettings");oe(this,"currentSettings");oe(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"},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 l=this.storage.load(HH);this.currentSettings=l??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(HH,this.currentSettings),this.notifyStateUpdate()}resetSettings(){return this.currentSettings=this.defaultSettings,this.storage.remove(HH),this.notifyStateUpdate(),this.currentSettings}toggle(){this.display.toggleFocus(m1.SETTINGS)}}class J7e{save(t,n){try{const l=JSON.stringify(n);localStorage.setItem(t,l)}catch(l){console.error(`Error while saving ${t} to storage`,l)}}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 zP(e){return!e.empty&&e.isLayerSwitch===!0&&typeof e.index=="number"&&typeof e.size=="number"}class ele{constructor(t){oe(this,"notification");oe(this,"mode");oe(this,"currentState",null);oe(this,"currentSubplotIndex",null);oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=t,this.mode="verbose",this.onChangeEmitter=new zs,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.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}formatCoordinateText(t){if(t.empty||!t.text)return null;const{text:n}=t,l=[];if(n.main&&n.main.value!==void 0){const a=Array.isArray(n.main.value)?n.main.value.join(", "):String(n.main.value);l.push(`${n.main.label} is ${a}`)}if(n.cross&&n.cross.value!==void 0){const a=Array.isArray(n.cross.value)?n.cross.value.join(", "):String(n.cross.value);l.push(`${n.cross.label} is ${a}`)}return n.fill&&n.fill.value!==void 0&&l.push(`${n.fill.label} is ${n.fill.value}`),l.length>0?l.join(", "):null}formatLayerSwitchAnnouncement(t){if(!zP(t))return"";let n=`Layer ${t.index} of ${t.size}: ${t.plotType||t.traceType} plot`;if(t.text){const l=[];t.text.main&&t.text.main.value!==void 0&&l.push(`${t.text.main.label} is ${t.text.main.value}`),t.text.cross&&t.text.cross.value!==void 0&&l.push(`${t.text.cross.label} is ${t.text.cross.value}`),t.text.fill&&t.text.fill.value!==void 0&&l.push(`${t.text.fill.label} is ${t.text.fill.value}`),l.length>0&&(n+=` at ${l.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,l){const a=l.length===1?`This is a ${l[0]} plot`:`This is a multi-layered plot containing ${l.join(Le.COMMA_SPACE)} plots`;return`Subplot ${t} of ${n}: ${a}. Press 'ENTER' to select this subplot.`}formatSubplotText(t,n,l,a){const o=a&&!a.empty?a.plotType:l;return`Layer ${t} of ${n}: ${o} plot`}isBoxPlotWithSection(t){return t.section!==void 0&&t.fill===void 0}formatVerboseTraceText(t){const n=new Array;if(n.push(t.main.label,Le.IS),t.range!==void 0?n.push(String(t.range.min),Le.THROUGH,String(t.range.max)):Array.isArray(t.main.value)?n.push(t.main.value.join(Le.COMMA_SPACE)):n.push(String(t.main.value)),t.section&&this.isBoxPlotWithSection(t)&&(t.section===e5.UPPER_OUTLIER||t.section===e5.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const l=typeof t.cross.label=="string"?t.cross.label.toLowerCase():t.cross.label,a=t.cross.value,o=`[${a.join(", ")}]`;if(a.length===0)return`${t.main.label} is ${t.main.value}, no ${t.section.toLowerCase()} for ${l}`;{const i=a.length===1?"is":"are";return`${t.main.label} is ${t.main.value}, ${t.section.toLowerCase()} for ${l} ${i} ${o}`}}if(t.section!==void 0)if(this.isBoxPlotWithSection(t)){const l=typeof t.cross.label=="string"?t.cross.label.toLowerCase():t.cross.label;n.push(Le.COMMA_SPACE,t.section.toLowerCase(),Le.SPACE,l)}else n.push(Le.COMMA_SPACE,t.section,Le.SPACE,t.cross.label);else n.push(Le.COMMA_SPACE,t.cross.label);if(Array.isArray(t.cross.value)?t.cross.value.length>1?n.push(Le.ARE,t.cross.value.join(Le.COMMA_SPACE)):t.cross.value.length>0&&n.push(Le.IS,t.cross.value.join(Le.COMMA_SPACE)):n.push(Le.IS,String(t.cross.value)),t.fill!==void 0){const l=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;n.push(Le.COMMA_SPACE,t.fill.label,Le.IS,l)}return n.join(Le.EMPTY)}formatTerseTraceText(t){const n=new Array;if(Array.isArray(t.main.value)?n.push(Le.OPEN_BRACKET,t.main.value.join(Le.COMMA_SPACE),Le.CLOSE_BRACKET):n.push(String(t.main.value),Le.COMMA_SPACE),t.section&&this.isBoxPlotWithSection(t)&&(t.section===e5.UPPER_OUTLIER||t.section===e5.LOWER_OUTLIER)&&Array.isArray(t.cross.value)){const l=t.cross.value,a=`[${l.join(", ")}]`;return l.length===0?`${t.main.value}, no ${t.section.toLowerCase()}`:`${t.main.value}, ${l.length} ${t.section.toLowerCase()} ${a}`}if(t.section!==void 0&&t.fill!==void 0?(n.push(t.section,Le.SPACE),Array.isArray(t.cross.value)?n.push(Le.OPEN_BRACKET,t.cross.value.join(Le.COMMA_SPACE),Le.CLOSE_BRACKET):n.push(String(t.cross.value))):(t.section!==void 0&&t.fill===void 0&&n.push(t.section,Le.SPACE),Array.isArray(t.cross.value)?n.push(Le.OPEN_BRACKET,t.cross.value.join(Le.COMMA_SPACE),Le.CLOSE_BRACKET):n.push(String(t.cross.value))),t.fill!==void 0){const l=t.fill.value==="Bull"||t.fill.value==="Bear"?t.fill.value.toLowerCase():t.fill.value;t.section,n.push(Le.COMMA_SPACE,l)}return n.join(Le.EMPTY)}update(t){if(this.mode==="off")return;if(this.currentState=t,t.type==="trace"&&zP(t)){const l=this.formatLayerSwitchAnnouncement(t);this.notification.notify(l);return}if(t.type==="subplot"){const l=this.format(t);l&&this.notification.notify(l);return}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 EH{constructor(t,n){oe(this,"figure");oe(this,"context");oe(this,"displayService");oe(this,"notificationService");oe(this,"settingsService");oe(this,"audioService");oe(this,"brailleService");oe(this,"goToExtremaService");oe(this,"textService");oe(this,"reviewService");oe(this,"autoplayService");oe(this,"highlightService");oe(this,"helpService");oe(this,"chatService");oe(this,"textViewModel");oe(this,"brailleViewModel");oe(this,"goToExtremaViewModel");oe(this,"reviewViewModel");oe(this,"displayViewModel");oe(this,"helpViewModel");oe(this,"chatViewModel");oe(this,"settingsViewModel");oe(this,"keybinding");this.figure=new Loe(t),this.context=new $0e(this.figure),this.displayService=new Zoe(this.context,n),this.notificationService=new W7e,this.settingsService=new K7e(new J7e,this.displayService),this.audioService=new Moe(this.notificationService,this.context.state,this.settingsService),this.brailleService=new Noe(this.context,this.notificationService,this.displayService),this.goToExtremaService=new Xoe(this.context,this.displayService),this.textService=new ele(this.notificationService),this.reviewService=new Y7e(this.notificationService,this.displayService,this.textService),this.autoplayService=new woe(this.context,this.notificationService,this.settingsService),this.highlightService=new Yoe(this.settingsService),this.helpService=new Woe(this.context,this.displayService),this.chatService=new qoe(this.displayService,t),this.textViewModel=new oq(Ui,this.textService,this.notificationService,this.autoplayService),this.brailleViewModel=new Hz(Ui,this.brailleService),this.goToExtremaViewModel=new jz(Ui,this.goToExtremaService,this.context),this.reviewViewModel=new Xz(Ui,this.reviewService),this.displayViewModel=new Bz(Ui,this.displayService),this.helpViewModel=new $z(Ui,this.helpService),this.chatViewModel=new wz(Ui,this.chatService,this.audioService),this.settingsViewModel=new Kz(Ui,this.settingsService),this.keybinding=new X7e({context:this.context,audioService:this.audioService,autoplayService:this.autoplayService,highlightService:this.highlightService,brailleViewModel:this.brailleViewModel,chatViewModel:this.chatViewModel,goToExtremaViewModel:this.goToExtremaViewModel,helpViewModel:this.helpViewModel,reviewViewModel:this.reviewViewModel,settingsViewModel:this.settingsViewModel,textViewModel:this.textViewModel}),this.registerViewModels(),this.registerObservers(),this.keybinding.register(this.context.scope)}announceInitialInstruction(){this.notificationService.notify(this.displayService.getInstruction(!1))}dispose(){this.keybinding.unregister(),O6.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.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(){O6.instance.register("text",this.textViewModel),O6.instance.register("braille",this.brailleViewModel),O6.instance.register("goToExtrema",this.goToExtremaViewModel),O6.instance.register("review",this.reviewViewModel),O6.instance.register("display",this.displayViewModel),O6.instance.register("help",this.helpViewModel),O6.instance.register("chat",this.chatViewModel),O6.instance.register("settings",this.settingsViewModel)}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(l=>l.forEach(a=>{a.addObserver(this.audioService),a.addObserver(this.brailleService),a.addObserver(this.textService),a.addObserver(this.reviewService),a.addObserver(this.highlightService)}))}))}}document.readyState==="loading"?document.addEventListener(_2.DOM_LOADED,qP):qP();function qP(){const e=document.querySelectorAll(`[${Le.MAIDR_DATA}]`);if(e.forEach(l=>{const a=l.getAttribute(Le.MAIDR_DATA);if(a)try{const o=JSON.parse(a);$P(o,l)}catch(o){console.error("Error parsing maidr attribute:",o)}}),e.length!==0)return;const t=window.maidr;if(!t)return;const n=document.getElementById(t.id);n&&$P(t,n)}function $P(e,t){let n=null,l=null;const a=()=>{setTimeout(()=>{if(!n)return;const f=document.activeElement;n.contains(f)||(l==null||l.dispose(),l=null)},0)},o=()=>{setTimeout(()=>{if(n&&!l){const f=JSON.parse(JSON.stringify(e));l=new EH(f,t),l.announceInitialInstruction()}},0)},i=()=>{if(document.visibilityState==="visible"){l&&(l.dispose(),l=null);const f=JSON.parse(JSON.stringify(e));l=new EH(f,t),l.announceInitialInstruction()}},s=document.createElement(Le.FIGURE);s.id=`${Le.MAIDR_FIGURE}-${e.id}`,t.parentNode.replaceChild(s,t),s.appendChild(t);const c=document.createElement(Le.ARTICLE);c.id=`${Le.MAIDR_ARTICLE}-${e.id}`,s.parentNode.replaceChild(c,s),c.appendChild(s);const u=document.createElement(Le.DIV);u.id=`${Le.REACT_CONTAINER}-${e.id}`,s.appendChild(u),n=s,t.addEventListener(_2.FOCUS_IN,o),t.addEventListener(_2.CLICK,o),n.addEventListener(_2.FOCUS_OUT,a),document.addEventListener(_2.VISIBILITY_CHANGE,i),V0e.createRoot(u,{identifierPrefix:e.id}).render(M0e(t)),(()=>{const f=JSON.parse(JSON.stringify(e));new EH(f,t).dispose()})()}}));
673
673
  //# sourceMappingURL=maidr.js.map