maidr 3.21.1 → 3.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/maidr.js CHANGED
@@ -634,7 +634,7 @@ Learn more: https://react.dev/warnings/version-mismatch`))}(),typeof Map=="funct
634
634
  You might need to use a local HTTP server (instead of file://): https://react.dev/link/react-devtools-faq`:""),"font-weight:bold")}Kf.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=Zh(r,1,!1,null,null,m,E,w,D,F,Z,null),r[Ni]=T.current,ts(r),new ac(T)},Kf.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=Zh(r,1,!0,T,m??null,E,w,D,F,Z,ae,le),T.context=F1(null),m=T.current,E=F4(m),E=Ke(E),w=a6(E),w.callback=null,o6(m,w,E),m=E,T.current.lanes=m,r1(T,m),pn(T),r[Ni]=T.current,ts(r),new oc(T)},Kf.version="19.1.1",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}(),Kf}var gP;function Eae(){if(gP)return lg.exports;gP=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=bae()):lg.exports=Hae(),lg.exports}var Sae=Eae();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 Jf(e,t,n,l){e.removeEventListener?e.removeEventListener(t,n,l):e.detachEvent&&e.detachEvent("on".concat(t),n)}function vP(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 xP(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 Mae(e,t){const n=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let o=!0;for(let a=0;a<n.length;a++)l.indexOf(n[a])===-1&&(o=!1);return o}const ed={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},td={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},B3={16:!1,18:!1,17:!1,91:!1},H2={};for(let e=1;e<20;e++)ed["f".concat(e)]=111+e;let m2=[],nd=null,LP="all";const K0=new Map,rd=e=>ed[e.toLowerCase()]||Jr[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Aae=e=>Object.keys(ed).find(t=>ed[t]===e),_ae=e=>Object.keys(Jr).find(t=>Jr[t]===e);function bP(e){LP=e||"all"}function id(){return LP||"all"}function Oae(){return m2.slice(0)}function Cae(){return m2.map(e=>Aae(e)||_ae(e)||String.fromCharCode(e))}function wae(){const e=[];return Object.keys(H2).forEach(t=>{H2[t].forEach(n=>{let{key:l,scope:o,mods:a,shortcut:i}=n;e.push({scope:o,shortcut:i,mods:a,keys:l.split("+").map(s=>rd(s))})})}),e}function Vae(e){const t=e.target||e.srcElement,{tagName:n}=t;let l=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(l=!1),l}function Dae(e){return typeof e=="string"&&(e=rd(e)),m2.indexOf(e)!==-1}function Rae(e,t){let n,l;e||(e=id());for(const o in H2)if(Object.prototype.hasOwnProperty.call(H2,o))for(n=H2[o],l=0;l<n.length;)n[l].scope===e?n.splice(l,1).forEach(i=>{let{element:s}=i;return QH(s)}):l++;id()===e&&bP(t||"all")}function kae(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 B3){B3[t]=!1;for(const l in Jr)Jr[l]===t&&(a4[l]=!1)}}function HP(e){if(typeof e>"u")Object.keys(H2).forEach(o=>{Array.isArray(H2[o])&&H2[o].forEach(a=>ug(a)),delete H2[o]}),QH(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&ug(o)});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[o,a]=n;typeof o=="function"&&(a=o,o=""),ug({key:e,scope:o,method:a,splitKey:"+"})}}const ug=e=>{let{key:t,scope:n,method:l,splitKey:o="+"}=e;xP(t).forEach(i=>{const s=i.split(o),c=s.length,u=s[c-1],Q=u==="*"?"*":rd(u);if(!H2[Q])return;n||(n=id());const f=c>1?vP(Jr,s):[],h=[];H2[Q]=H2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===n&&Mae(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>QH(p))})};function EP(e,t,n,l){if(t.element!==l)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const a in B3)Object.prototype.hasOwnProperty.call(B3,a)&&(!B3[a]&&t.mods.indexOf(+a)>-1||B3[a]&&t.mods.indexOf(+a)===-1)&&(o=!1);(t.mods.length===0&&!B3[16]&&!B3[18]&&!B3[17]&&!B3[91]||o||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 SP(e,t){const n=H2["*"];let l=e.keyCode||e.which||e.charCode;if(!a4.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=td[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 td||u===l))}),l in B3){B3[l]=!0;for(const s in Jr)if(Object.prototype.hasOwnProperty.call(Jr,s)){const c=td[Jr[s]];a4[s]=e[c]}if(!n)return}for(const s in B3)Object.prototype.hasOwnProperty.call(B3,s)&&(B3[s]=e[td[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(m2.indexOf(17)===-1&&m2.push(17),m2.indexOf(18)===-1&&m2.push(18),B3[17]=!0,B3[18]=!0);const o=id();if(n)for(let s=0;s<n.length;s++)n[s].scope===o&&(e.type==="keydown"&&n[s].keydown||e.type==="keyup"&&n[s].keyup)&&EP(e,n[s],o,t);if(!(l in H2))return;const a=H2[l],i=a.length;for(let s=0;s<i;s++)if((e.type==="keydown"&&a[s].keydown||e.type==="keyup"&&a[s].keyup)&&a[s].key){const c=a[s],{splitKey:u}=c,Q=c.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(rd(Q[h]));f.sort().join("")===m2.sort().join("")&&EP(e,c,o,t)}}function a4(e,t,n){m2=[];const l=xP(e);let o=[],a="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&&(a=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"&&(a=t),h&&HP(e,a);s<l.length;s++)e=l[s].split(Q),o=[],e.length>1&&(o=vP(Jr,e)),e=e[e.length-1],e=e==="*"?"*":rd(e),e in H2||(H2[e]=[]),H2[e].push({keyup:c,keydown:u,scope:a,mods:o,shortcut:l[s],method:n,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!K0.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return SP(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;SP(v,i),kae(v)};K0.set(i,{keydownListener:p,keyupListenr:g,capture:f}),TH(i,"keydown",p,f),TH(i,"keyup",g,f)}if(!nd){const p=()=>{m2=[]};nd={listener:p,capture:f},TH(window,"focus",p,f)}}}function Nae(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(H2).forEach(n=>{H2[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function QH(e){const t=Object.values(H2).flat();if(t.findIndex(l=>{let{element:o}=l;return o===e})<0){const{keydownListener:l,keyupListenr:o,capture:a}=K0.get(e)||{};l&&o&&(Jf(e,"keyup",o,a),Jf(e,"keydown",l,a),K0.delete(e))}if((t.length<=0||K0.size<=0)&&(Object.keys(K0).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:s}=K0.get(o)||{};a&&i&&(Jf(o,"keyup",i,s),Jf(o,"keydown",a,s),K0.delete(o))}),K0.clear(),Object.keys(H2).forEach(o=>delete H2[o]),nd)){const{listener:o,capture:a}=nd;Jf(window,"focus",o,a),nd=null}}const fH={getPressedKeyString:Cae,setScope:bP,getScope:id,deleteScope:Rae,getPressedKeyCodes:Oae,getAllKeyCodes:wae,isPressed:Dae,filter:Vae,trigger:Nae,unbind:HP,keyMap:ed,modifier:Jr,modifierMap:td};for(const e in fH)Object.prototype.hasOwnProperty.call(fH,e)&&(a4[e]=fH[e]);if(typeof window<"u"){const e=window.hotkeys;a4.noConflict=t=>(t&&window.hotkeys===a4&&(window.hotkeys=e),a4),window.hotkeys=a4}class Bae{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),a4.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 o=l.getCurrentXValue();n.moveOnce(t);const a=n.activeTrace;if(this.plotContext.push(a),a.getId()===l.getId()){a.notifyOutOfBounds(),n.notifyOutOfBounds();return}if(a.moveToXValue(o),a.state.empty)a.notifyStateUpdate();else{const i=n.getRow()+1,s=n.getSize(),c={...a.state,isLayerSwitch:!0,index:i,size:s};a.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":return`This is a maidr plot of type: ${n.plotType}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}var q2=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(q2||{}),$2=(e=>(e.BAR="bar",e.BOX="box",e.CANDLESTICK="candlestick",e.DODGED="dodged_bar",e.HEATMAP="heat",e.HISTOGRAM="hist",e.LINE="line",e.NORMALIZED="stacked_normalized_bar",e.SCATTER="point",e.SMOOTH="smooth",e.STACKED="stacked_bar",e))($2||{});function Pae(e){return e!==null&&typeof e=="object"&&"x"in e}function jae(e){return typeof e=="string"||typeof e=="number"}function Iae(e){return e!==null&&typeof e=="object"&&"x"in e}class MP{computeIndexAndSegment(t,n,l,o){return l===q2.HORIZONTAL?{pointIndex:t,segmentType:o[n]}:{pointIndex:n,segmentType:o[t]}}computeVisualCoordinates(t,n,l){return l===q2.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 o=t[0][l];return this.extractXFromPoint(o)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][l]){const o=t[n][l];return this.extractXFromPoint(o)}return null}extractXValueFromValues(t,n,l){if(this.isValidPosition(t,n,l)){const o=t[n][l];return this.extractXFromValue(o)}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 o=-1,a=-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,o=c,a=f,s="numeric")):typeof n=="string"&&typeof h=="string"?o===-1&&(o=c,a=f,s="categorical"):o===-1&&(o=c,a=f,s="generic")}}}if(o!==-1&&a!==-1){const c=t[o];if(Array.isArray(c)&&ni(c[a]),s!==null)return l(o,a),!0}return!1}moveToXValueInValues(t,n,l){let o=-1,a=-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,o=c,a=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?o===-1&&(o=c,a=u,s="categorical"):o===-1&&(o=c,a=u,s="generic")}return o!==-1&&a!==-1?(this.extractXFromValue(t[o][a]),l(o,a),!0):!1}extractXFromPoint(t){return Iae(t)?t.x:null}extractXFromValue(t){return Pae(t)?t.x:jae(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,o=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a++){const i=ni(t[a]);if(typeof i=="number"){const s=Math.abs(i-n);s<o&&(o=s,l=a)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<o&&(o=c,l=a)}}}if(l!==-1)return ni(t[l]),l}else if(typeof n=="string"){for(let o=0;o<t.length;o++)if(ni(t[o])===n)return o;const l=Number(n);if(!Number.isNaN(l)){let o=-1,a=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<a&&(a=c,o=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-l);u<a&&(a=u,o=i)}}}if(o!==-1)return ni(t[o]),o}for(let o=0;o<t.length;o++)if(typeof ni(t[o])=="string")return o}return t.length>0?(ni(t[0]),0):-1}dispose(){}}function Fae(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function zae(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function qae(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function $ae(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function Uae(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function Gae(e){return e&&typeof e=="object"&&"value"in e}function ni(e){return e?Fae(e)||zae(e)||$ae(e)||Uae(e)||qae(e)?e.x:Gae(e)?e.value:null:null}const Zae="unavailable",Xae="X",Wae="Y",Yae="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 o;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,l=this.col>=0&&this.col<(((o=t[n])==null?void 0:o.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[o,a]=t,{row:i}=this.getSafeIndices();return o>=0&&o<this.values.length&&a>=0&&a<(((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:o}=this.getSafeIndices();return this.col<(((l=this.values[o])==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,o,a;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 MP,this.id=n.id,this.type=n.type,this.title=n.title??Zae,this.xAxis=((l=n.axes)==null?void 0:l.x)??Xae,this.yAxis=((o=n.axes)==null?void 0:o.y)??Wae,this.fill=((a=n.axes)==null?void 0:a.fill)??Yae}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(a=>a.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==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{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==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 o;const{row:n}=this.getSafeIndices(),l=((o=this.values[n])==null?void 0:o.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 o4{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 o=1;o<t.length;o++){const a=t[o];a<n&&(n=a),a>l&&(l=a)}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 o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[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),o=this.calculateLuminance(n);return(Math.max(l,o)+.05)/(Math.min(l,o)+.05)}static calculateLuminance(t){const[n,l,o]=[t.r,t.g,t.b].map(a=>{const i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*l+.0722*o}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(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,a=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=o}),i=document.createElement("canvas");[i.width,i.height]=[a.naturalWidth,a.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(a,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 o=l.cloneNode(!0);return o.setAttribute(Le.VISIBILITY,Le.HIDDEN),l.insertAdjacentElement(Le.AFTER_END,o),o})}static selectElement(t,n=!0){const l=document.querySelector(t);if(!n)return l;const o=l==null?void 0:l.cloneNode(!0);return o==null||o.setAttribute(Le.VISIBILITY,Le.HIDDEN),l==null||l.insertAdjacentElement(Le.AFTER_END,o),o}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 o=window.getComputedStyle(l),a=o.stroke||o.fill,i=o.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,a),c.setAttribute(Le.STROKE,a),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 o=t.getBBox();let a,i,s,c;switch(n){case"top":[a,i,s,c]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,s,c]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,s,c]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,s,c]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,Le.LINE);return Q.setAttribute(Le.X1,String(a)),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),o=t.tagName.toLowerCase(),a=o===Le.POLYLINE||o===Le.LINE,i=a?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,a){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 o=t.querySelector("rect, path");let a="";if(o){a=window.getComputedStyle(o).getPropertyValue("fill"),(!a||a==="none"||a==="transparent"||a==="rgba(0, 0, 0, 0)")&&(l?a=window.getComputedStyle(l).getPropertyValue("fill"):a=n);const i=this.getHighlightColor(a,n);o.setAttribute("stroke",i),o.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??q2.VERTICAL,this.barValues=l.map(o=>o.map(a=>this.orientation===q2.VERTICAL?Number(a.y):Number(a.x))),this.min=this.barValues.map(o=>o4.safeMin(o)),this.max=this.barValues.map(o=>o4.safeMax(o)),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===q2.VERTICAL,l=n?this.barValues[this.row].length:this.barValues.length,o=n?this.col:this.row,a=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:o4.safeMin(this.min),max:o4.safeMax(this.max),size:l,index:o,value:a,...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===q2.VERTICAL,l=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,a=n?l.x:l.y,i=n?this.yAxis:this.xAxis,s=n?l.y:l.x;return{main:{label:o,value:a},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 o=0;o<this.points.length;o++)if(l[o].length!==this.points[o].length)return null;return l}}class Kae 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 Jae 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??q2.VERTICAL,this.sections=[e5.LOWER_OUTLIER,e5.MIN,e5.Q1,e5.Q2,e5.Q3,e5.MAX,e5.UPPER_OUTLIER];const l=[a=>a.lowerOutliers,a=>a.min,a=>a.q1,a=>a.q2,a=>a.q3,a=>a.max,a=>a.upperOutliers];this.orientation===q2.HORIZONTAL?this.boxValues=this.points.map(a=>l.map(i=>i(a))):this.boxValues=l.map(a=>this.points.map(i=>a(i)));const o=this.boxValues.map(a=>a.flatMap(i=>Array.isArray(i)?i:[i]));this.min=o4.minFrom2D(o),this.max=o4.maxFrom2D(o),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 o=this.orientation===q2.HORIZONTAL;n=o?n:l,l=o?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(o=>o-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===q2.HORIZONTAL,l=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:l,col:o}}text(){const n=this.orientation===q2.HORIZONTAL,l=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,a=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:o,value:l.fill},cross:{label:i,value:s},section:a}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const l=this.orientation===q2.VERTICAL,o=new Array;if(l)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:n.length}));return n.forEach((a,i)=>{const s=a.lowerOutliers.flatMap(L=>zt.selectAllElements(L)),c=a.upperOutliers.flatMap(L=>zt.selectAllElements(L)),u=zt.selectElement(a.min)??zt.createEmptyElement(),Q=zt.selectElement(a.max)??zt.createEmptyElement(),f=zt.selectElement(a.iq)??zt.createEmptyElement(),h=zt.selectElement(a.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)=>{o[x][i]=L}):o.push(v)}),o}}const eoe="trend",AP=100;class toe 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 MP;const l=n.data;this.candles=l.map(o=>({...o,volatility:Math.round((o.high-o.low)*AP)/AP,trend:o.close>o.open?"Bull":o.close<o.open?"Bear":"Neutral"})),this.orientation=n.orientation??q2.VERTICAL,this.candleValues=this.sections.map(o=>this.candles.map(a=>a[o])),this.min=o4.minFrom2D(this.candleValues),this.max=o4.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===q2.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(a=>[a,n[a]]).sort((a,i)=>a[1]-i[1]).map(a=>a[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const l=new Map;return n.forEach((o,a)=>{l.set(o,a)}),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===q2.HORIZONTAL?this.col=l:this.row=l}updateVisualPointPosition(){this.orientation===q2.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],o=l.indexOf(this.currentSegmentType??"open");if(o===-1){this.notifyOutOfBounds();return}const a=n==="UPWARD"?o+1:o-1;if(a>=0&&a<l.length)this.currentSegmentType=l[a],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:o,segmentType:a}=this.navigationService.computeIndexAndSegment(n,l,this.orientation,this.sections);this.currentPointIndex=o,this.currentSegmentType=a,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],o=l.indexOf(this.currentSegmentType??"open"),a=n==="UPWARD"?o+1:o-1;return a>=0&&a<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 o=this.candleValues.map(i=>Math.min(...i)),a=this.candleValues.map(i=>Math.max(...i));return{empty:!1,id:this.id,values:this.candleValues,min:o,max:a,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const l=Array.isArray(n)?n:[n],o=[];for(const a of l)o.push(...zt.selectAllElements(a));return o}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,o=this.candles.length,a=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:o},()=>zt.createEmptyElement()),f=Array.from({length:o},()=>zt.createEmptyElement()),h=Array.from({length:o},()=>zt.createEmptyElement());for(let g=0;g<o;g++){let v=this.getElementAt(c,g);if(!v){const x=this.getElementAt(a,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(a,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:o},()=>zt.createEmptyElement()));for(let g=0;g<o;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(a,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(a,g)??zt.createEmptyElement();break;case"low":S=this.getElementAt(s,g)??this.getElementAt(a,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===q2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===q2.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType??"open",fill:{label:eoe,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(o=>o.value===n);return l!==-1?(this.currentPointIndex=l,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}}class noe 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:o,max:a}=o4.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=a,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,o=this.heatmapValues[0].length,a=zt.selectAllElements(n);if(a.length===0||a.length!==l*o)return null;const i=new Array;if(a[0]instanceof SVGPathElement)for(let s=0;s<l;s++){const c=l-1-s,u=new Array;for(let Q=0;Q<o;Q++){const f=c*o+Q;u.push(a[f])}i.push(u)}else if(a[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const c=new Array;for(let u=0;u<o;u++){const Q=u*l+s;c.push(a[Q])}i.push(c)}return i}}class roe extends hH{constructor(t){super(t,[t.data])}text(){const t=this.orientation===q2.VERTICAL,n=this.points[this.row][this.col],l=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text(),range:{min:l,max:o}}}}const _P="Group",pH=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class OP 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(o=>Number(o.y))),this.min=this.lineValues.map(l=>o4.safeMin(l)),this.max=this.lineValues.map(l=>o4.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 a;const n=this.points[this.row][this.col],l=this.findIntersections();let o={};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=((a=this.points[this.previousRow][0])==null?void 0:a.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}o={fill:{label:_P,value:`intersection at (${i.join(", ")})`}}}else o=n.fill?{fill:{label:_P,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},...o}}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 o=this.findLineByXAndYDirection(n),a=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const i=this.findColumnByXValue(o,a);if(i!==-1){this.row=o,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 a={...super.state,intersections:l};for(const i of this.observers)i.update(a)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,l=this.points[this.row][this.col].y,o=[];for(let a=0;a<this.points.length;a++){const i=this.points[a].findIndex(s=>s.x===n&&s.y===l);i!==-1&&o.push({min:this.min[a],max:this.max[a],size:this.points[a].length,index:i,value:l,groupIndex:a})}return o}isMovable(n){if(Array.isArray(n)){const[l,o]=n;return l>=0&&l<this.values.length&&o>=0&&o<this.values[l].length}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.findLineByXAndYDirection(n);if(l===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(l,o)!==-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 o=null,a=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<a&&(a=Q,o=i)}return o}findColumnByXValue(n,l){return this.points[n].findIndex(o=>o.x===l)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const l=[];let o=!0;for(let a=0;a<n.length;a++){const i=zt.selectElement(n[a],!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[a].length)if(s.length<this.lineValues[a].length)for(;s.length<this.lineValues[a].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[a].length&&(s.length=this.lineValues[a].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&&(o=!1),l.push(c)}return o?null:l}get state(){const n=super.state;if(n.empty)return n;const l={...n,plotType:this.points.length>1?"multiline":"single line"},o=this.findIntersections();return o.length>1?{...l,intersections:o}:l}}class ioe 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,o=[...l].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let a=null;for(const c of o)(!a||a.x!==c.x)&&(a={x:c.x,y:[]},this.xPoints.push(a)),a.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=o4.safeMin(this.xValues),this.maxX=o4.safeMax(this.xValues),this.minY=o4.safeMin(this.yValues),this.maxY=o4.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)],o=this.yValues.indexOf(l);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],l=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(l);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,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 o=new Map,a=new Map;l.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(o.has(u)||o.set(u,[]),o.get(u).push(c)),Number.isNaN(Q)||(a.has(Q)||a.set(Q,[]),a.get(Q).push(c))});const i=Array.from(o.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(a.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const CP="Sum",aoe="Level",ooe="undefined";class loe extends hH{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let a=0;a<this.barValues[0].length;a++){const i=this.barValues.reduce((c,u)=>c+u[a],0);t.push(i);const s=this.orientation===q2.VERTICAL?{x:this.points[0][a].x,y:i,fill:CP}:{x:i,y:this.points[0][a].y,fill:CP};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:l,max:o}=o4.minMax(t);this.min.push(l),this.max.push(o)}text(){return{...super.text(),fill:{label:aoe,value:this.points[this.row][this.col].fill??ooe}}}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 o=0,a=0;o<this.barValues.length;o++){const i=new Array;for(let s=0;s<this.barValues[o].length;s++){if(a>=n.length)return new Array;this.barValues[o][s]===0?i.push(zt.createEmptyElement()):i.push(n[a++])}l.push(i)}else if(n[0]instanceof SVGRectElement){for(let o=0;o<this.barValues.length;o++)l.push(new Array);for(let o=0,a=0;o<this.barValues[0].length;o++)for(let i=this.barValues.length-1;i>=0;i--){if(a>=n.length)return new Array;this.barValues[i][o]===0?l[i].push(zt.createEmptyElement()):l[i].push(n[a++])}}return l}}class wP extends OP{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))],o=n>0?l(n-1):l(n),a=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:[o,a,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class soe extends wP{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let l=!0;for(let a=0;a<t.length;a++){const i=zt.selectElement(t[a],!1);if(!i){n.push([]);continue}const s=(o=this.points)==null?void 0:o[a],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 uoe(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function coe(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&uoe(e.data[0][0])?new soe(e):new wP(e)}class Toe{static create(t){switch(t.type){case $2.BAR:return new Kae(t);case $2.BOX:return new Jae(t);case $2.CANDLESTICK:return new toe(t);case $2.HEATMAP:return new noe(t);case $2.HISTOGRAM:return new roe(t);case $2.LINE:return new OP(t);case $2.SCATTER:return new ioe(t);case $2.SMOOTH:return coe(t);case $2.DODGED:case $2.NORMALIZED:case $2.STACKED:return new loe(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const Qoe="MAIDR Plot",foe="unavailable",doe="unavailable";class hoe 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??Qoe,this.subtitle=n.subtitle??foe,this.caption=n.caption??doe;const l=n.subplots;this.subplots=l.map(o=>o.map(a=>new poe(a))),this.size=this.subplots.reduce((o,a)=>o+a.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((o,a)=>o+a.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 o=((l=this.subplots[0])==null?void 0:l.length)||1,a=this.row*o+this.col+1,i=`g[id="axes_${a}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&a-1<c.length)return{empty:!1,elements:c[a-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 poe 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(o=>[Toe.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?Le.EMPTY:a.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 l4={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:l4.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:l4.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:l4.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:l4.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:l4.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:l4.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:l4.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:l4.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:l4.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:l4.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:l4.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 l4.SINE_BASIC;case"Bear":return l4.SAWTOOTH_SOFT;case"Neutral":return l4.TRIANGLE_BASIC;default:return l4.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],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,l.timbreModulation);return{index:t,waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const n=[],l=ku.MIN_HARMONICS+t%ku.HARMONIC_VARIATION;for(let o=0;o<l;o++){const a=1+(o+1)*(.5+t*.3%1),i=.4/(o+1)*(1-t*.1%.3);n.push({frequency:a,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 moe=100,yoe=440,goe=880,yH=.3,gH=l4.SINE_BASIC;class voe{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 o=this.settings.loadSettings();this.currentVolume=o.general.volume/100,this.currentMinFrequency=o.general.minFrequency,this.currentMaxFrequency=o.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.empty){this.playBoundaryAudio();return}if(t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;this.handleTraceState(n)}playBoundaryAudio(){this.stopAll(),this.playEmptyTone(1,0)}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 a=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,a);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,a),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,a)}}}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,o,a,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(l,s,c),Q={min:0,max:o},f={min:-1,max:1},h=this.clamp(this.interpolate(a,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const l=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=n,l.push(o),t.harmonicMix)for(const a of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=a.frequency*n,l.push(i)}return l}createGainNodes(t,n,l,o){const a=[],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,o);f!==null&&u.gain.setValueCurveAtTime(f,i,o),a.push(u)}return a}playOscillator(t,n=0,l){const o=yH,a=this.getVolume();l||(l=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,a,o),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),o*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,l,o,a){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=a*i,f=a*s,h=a*u,p=a-Q-f-h;return t.gain.setValueAtTime(1e-4*l,o),t.gain.linearRampToValueAtTime(l,o+Q),t.gain.linearRampToValueAtTime(c*l,o+Q+f),p>0&&t.gain.setValueAtTime(c*l,o+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*l,o+a),null}else return[.5*l,l,.5*l,.5*l,.5*l,.1*l,1e-4*l]}playSmooth(t,n,l,o,a,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(a,{min:0,max:o-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,o=l.currentTime,a=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=l.createGain();u.gain.setValueAtTime(.3*i,o),u.gain.exponentialRampToValueAtTime(.01*i,o+a),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,o),S.gain.exponentialRampToValueAtTime(.001*i,o+a),_.pan.value=h,x.connect(S),S.connect(_),_.connect(O),O.connect(u),x.start(o),x.stop(o+a),p.push(x)}const g=L=>{u.disconnect(),p.forEach(x=>{x.disconnect()}),this.activeAudioIds.delete(L)},v=setTimeout(()=>g(v),a*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(moe,0,{index:gH,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(yoe,0,{index:gH,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(goe,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 o=this.activeAudioIds.get(l);if(!o){clearInterval(l);return}o.forEach(a=>{a==null||a.disconnect(),a==null||a.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,o=this.audioContext,a=o.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=o.createOscillator();L.type=v,L.frequency.value=p;const x=o.createGain();x.gain.setValueAtTime(n,a),x.gain.exponentialRampToValueAtTime(.01*n,a+l),L.connect(x),x.connect(this.compressor),L.start(a),L.stop(a+l);const S=setTimeout(()=>{L.disconnect(),x.disconnect()},l*1e3*2);this.activeAudioIds.set(S,[L])})}}const xoe=250,Loe=50,boe=500,Hoe=20;class Eoe{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=xoe,this.minSpeed=Loe,this.maxSpeed=boe,this.autoplayRate=this.defaultSpeed,this.interval=Hoe,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 VP=32;class ad{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const i=(t.max[a]-t.min[a])/4,s=t.min[a]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[a].length;Q++)t.values[a][Q]===0?n.push(" "):t.values[a][Q]<=s||t.values[a][Q]<=c?n.push("⠤"):t.values[a][Q]<=u?n.push("⠒"):n.push("⠉"),l[a].push(o.length),o.push({row:a,col:Q});n.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class Soe{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=VP){const l=new Array,o=new Array,a=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];a.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),a[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),o.push({row:i,col:M})}}for(let V=0;V<3;V++)if(a[i][V]===-1){for(let R=V+1;R<=3;R++)if(a[i][R]!==-1){a[i][V]=a[i][R];break}}for(let V=6;V>3;V--)if(a[i][V]===-1){for(let R=V-1;R>=3;R--)if(a[i][R]!==-1){a[i][V]=a[i][R];break}}l.push(Le.NEW_LINE),o.push({row:i,col:M})}return{value:l.join(Le.EMPTY),cellToIndex:a,indexToCell:o}}}class Moe{encode(t){const n=new Array,l=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,s=i+a;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(o.length),o.push({row:c,col:u});n.push(Le.NEW_LINE),l[c].push(o.length),o.push({row:c,col:t.values[c].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class DP{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(a,t);for(let Q=0;Q<t.values[a].length;Q++){const f=t.values[a][Q],h=Q>0?t.values[a][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),l[a].push(o.length),o.push({row:a,col:Q})}n.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}getBrailleChar(t,n,l,o,a,i){return i===void 0&&(i=a),t<=l&&n!==null&&n>l?n<=o?"⢄":n<=i?"⢆":"⢇":t<=l?"⣀":n!==null&&n<=l?t<=o?"⡠":t<=i?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=i?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=a?"⠉":""}getBraille6Char(t,n,l,o,a){const i=f=>f<=l?"low":f<=o?"medium":(f<=a,"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 o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class Aoe extends DP{getThresholds(t,n){const l=Array.isArray(n.min)?n.min[t]:n.min,o=Array.isArray(n.max)?n.max[t]:n.max,a=(o-l)/3,i=l+a,s=i+a;return{low:i,medium:s,high:o}}encode(t){var a;const n=new Array,l=new Array,o=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);((a=t.custom)==null?void 0:a[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),l[i].push(o.length),o.push({row:i,col:Q})}n.push(Le.NEW_LINE),l[i].push(o.length),o.push({row:i,col:t.values[i].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class _oe extends DP{getThresholds(t,n){const l=(n.max[t]-n.min[t])/4,o=n.min[t]+l,a=o+l,i=a+l,s=n.max[t];return{low:o,medium:a,mediumHigh:i,high:s}}}class Ooe{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([[$2.BAR,new ad],[$2.BOX,new Soe],[$2.CANDLESTICK,new Aoe],[$2.DODGED,new ad],[$2.HEATMAP,new Moe],[$2.HISTOGRAM,new ad],[$2.LINE,new _oe],[$2.NORMALIZED,new ad],[$2.STACKED,new ad]]),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 o=this.encoders.get(n.traceType);this.cache=o.encode(l,VP),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 RP=(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))(RP||{});class kP{constructor(){}static async post(t,n,l){const o={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",o,n)}static async request(t,n,l,o){try{const a=await fetch(t,{method:n,headers:l,body:o});return a.ok?{success:!0,data:await a.json()}:{success:!1,error:{statusCode:a.status,message:`API Error: ${a.status} - ${a.statusText}`}}}catch(a){return console.error(`Error in API ${n} request to ${t}:`,a),{success:!1,error:{statusCode:RP.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}oe(kP,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Coe=`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=Zh(r,1,!1,null,null,m,E,w,D,F,Z,null),r[Ni]=T.current,ts(r),new ac(T)},Kf.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=Zh(r,1,!0,T,m??null,E,w,D,F,Z,ae,le),T.context=F1(null),m=T.current,E=F4(m),E=Ke(E),w=a6(E),w.callback=null,o6(m,w,E),m=E,T.current.lanes=m,r1(T,m),pn(T),r[Ni]=T.current,ts(r),new oc(T)},Kf.version="19.1.1",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}(),Kf}var gP;function Eae(){if(gP)return lg.exports;gP=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=bae()):lg.exports=Hae(),lg.exports}var Sae=Eae();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 Jf(e,t,n,l){e.removeEventListener?e.removeEventListener(t,n,l):e.detachEvent&&e.detachEvent("on".concat(t),n)}function vP(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 xP(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 Mae(e,t){const n=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let o=!0;for(let a=0;a<n.length;a++)l.indexOf(n[a])===-1&&(o=!1);return o}const ed={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},td={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},B3={16:!1,18:!1,17:!1,91:!1},H2={};for(let e=1;e<20;e++)ed["f".concat(e)]=111+e;let m2=[],nd=null,LP="all";const K0=new Map,rd=e=>ed[e.toLowerCase()]||Jr[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Aae=e=>Object.keys(ed).find(t=>ed[t]===e),_ae=e=>Object.keys(Jr).find(t=>Jr[t]===e);function bP(e){LP=e||"all"}function id(){return LP||"all"}function Oae(){return m2.slice(0)}function Cae(){return m2.map(e=>Aae(e)||_ae(e)||String.fromCharCode(e))}function wae(){const e=[];return Object.keys(H2).forEach(t=>{H2[t].forEach(n=>{let{key:l,scope:o,mods:a,shortcut:i}=n;e.push({scope:o,shortcut:i,mods:a,keys:l.split("+").map(s=>rd(s))})})}),e}function Vae(e){const t=e.target||e.srcElement,{tagName:n}=t;let l=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(l=!1),l}function Dae(e){return typeof e=="string"&&(e=rd(e)),m2.indexOf(e)!==-1}function Rae(e,t){let n,l;e||(e=id());for(const o in H2)if(Object.prototype.hasOwnProperty.call(H2,o))for(n=H2[o],l=0;l<n.length;)n[l].scope===e?n.splice(l,1).forEach(i=>{let{element:s}=i;return QH(s)}):l++;id()===e&&bP(t||"all")}function kae(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 B3){B3[t]=!1;for(const l in Jr)Jr[l]===t&&(a4[l]=!1)}}function HP(e){if(typeof e>"u")Object.keys(H2).forEach(o=>{Array.isArray(H2[o])&&H2[o].forEach(a=>ug(a)),delete H2[o]}),QH(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&ug(o)});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[o,a]=n;typeof o=="function"&&(a=o,o=""),ug({key:e,scope:o,method:a,splitKey:"+"})}}const ug=e=>{let{key:t,scope:n,method:l,splitKey:o="+"}=e;xP(t).forEach(i=>{const s=i.split(o),c=s.length,u=s[c-1],Q=u==="*"?"*":rd(u);if(!H2[Q])return;n||(n=id());const f=c>1?vP(Jr,s):[],h=[];H2[Q]=H2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===n&&Mae(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>QH(p))})};function EP(e,t,n,l){if(t.element!==l)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const a in B3)Object.prototype.hasOwnProperty.call(B3,a)&&(!B3[a]&&t.mods.indexOf(+a)>-1||B3[a]&&t.mods.indexOf(+a)===-1)&&(o=!1);(t.mods.length===0&&!B3[16]&&!B3[18]&&!B3[17]&&!B3[91]||o||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 SP(e,t){const n=H2["*"];let l=e.keyCode||e.which||e.charCode;if(!a4.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=td[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 td||u===l))}),l in B3){B3[l]=!0;for(const s in Jr)if(Object.prototype.hasOwnProperty.call(Jr,s)){const c=td[Jr[s]];a4[s]=e[c]}if(!n)return}for(const s in B3)Object.prototype.hasOwnProperty.call(B3,s)&&(B3[s]=e[td[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(m2.indexOf(17)===-1&&m2.push(17),m2.indexOf(18)===-1&&m2.push(18),B3[17]=!0,B3[18]=!0);const o=id();if(n)for(let s=0;s<n.length;s++)n[s].scope===o&&(e.type==="keydown"&&n[s].keydown||e.type==="keyup"&&n[s].keyup)&&EP(e,n[s],o,t);if(!(l in H2))return;const a=H2[l],i=a.length;for(let s=0;s<i;s++)if((e.type==="keydown"&&a[s].keydown||e.type==="keyup"&&a[s].keyup)&&a[s].key){const c=a[s],{splitKey:u}=c,Q=c.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(rd(Q[h]));f.sort().join("")===m2.sort().join("")&&EP(e,c,o,t)}}function a4(e,t,n){m2=[];const l=xP(e);let o=[],a="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&&(a=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"&&(a=t),h&&HP(e,a);s<l.length;s++)e=l[s].split(Q),o=[],e.length>1&&(o=vP(Jr,e)),e=e[e.length-1],e=e==="*"?"*":rd(e),e in H2||(H2[e]=[]),H2[e].push({keyup:c,keydown:u,scope:a,mods:o,shortcut:l[s],method:n,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!K0.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return SP(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;SP(v,i),kae(v)};K0.set(i,{keydownListener:p,keyupListenr:g,capture:f}),TH(i,"keydown",p,f),TH(i,"keyup",g,f)}if(!nd){const p=()=>{m2=[]};nd={listener:p,capture:f},TH(window,"focus",p,f)}}}function Nae(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(H2).forEach(n=>{H2[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function QH(e){const t=Object.values(H2).flat();if(t.findIndex(l=>{let{element:o}=l;return o===e})<0){const{keydownListener:l,keyupListenr:o,capture:a}=K0.get(e)||{};l&&o&&(Jf(e,"keyup",o,a),Jf(e,"keydown",l,a),K0.delete(e))}if((t.length<=0||K0.size<=0)&&(Object.keys(K0).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:s}=K0.get(o)||{};a&&i&&(Jf(o,"keyup",i,s),Jf(o,"keydown",a,s),K0.delete(o))}),K0.clear(),Object.keys(H2).forEach(o=>delete H2[o]),nd)){const{listener:o,capture:a}=nd;Jf(window,"focus",o,a),nd=null}}const fH={getPressedKeyString:Cae,setScope:bP,getScope:id,deleteScope:Rae,getPressedKeyCodes:Oae,getAllKeyCodes:wae,isPressed:Dae,filter:Vae,trigger:Nae,unbind:HP,keyMap:ed,modifier:Jr,modifierMap:td};for(const e in fH)Object.prototype.hasOwnProperty.call(fH,e)&&(a4[e]=fH[e]);if(typeof window<"u"){const e=window.hotkeys;a4.noConflict=t=>(t&&window.hotkeys===a4&&(window.hotkeys=e),a4),window.hotkeys=a4}class Bae{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),a4.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 o=l.getCurrentXValue();n.moveOnce(t);const a=n.activeTrace;if(this.plotContext.push(a),a.getId()===l.getId()){a.notifyOutOfBounds(),n.notifyOutOfBounds();return}if(a.moveToXValue(o),a.state.empty)a.notifyStateUpdate();else{const i=n.getRow()+1,s=n.getSize(),c={...a.state,isLayerSwitch:!0,index:i,size:s};a.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 o=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(o="single line");const a=o==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${o}${a}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}var q2=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(q2||{}),$2=(e=>(e.BAR="bar",e.BOX="box",e.CANDLESTICK="candlestick",e.DODGED="dodged_bar",e.HEATMAP="heat",e.HISTOGRAM="hist",e.LINE="line",e.NORMALIZED="stacked_normalized_bar",e.SCATTER="point",e.SMOOTH="smooth",e.STACKED="stacked_bar",e))($2||{});function Pae(e){return e!==null&&typeof e=="object"&&"x"in e}function jae(e){return typeof e=="string"||typeof e=="number"}function Iae(e){return e!==null&&typeof e=="object"&&"x"in e}class MP{computeIndexAndSegment(t,n,l,o){return l===q2.HORIZONTAL?{pointIndex:t,segmentType:o[n]}:{pointIndex:n,segmentType:o[t]}}computeVisualCoordinates(t,n,l){return l===q2.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 o=t[0][l];return this.extractXFromPoint(o)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][l]){const o=t[n][l];return this.extractXFromPoint(o)}return null}extractXValueFromValues(t,n,l){if(this.isValidPosition(t,n,l)){const o=t[n][l];return this.extractXFromValue(o)}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 o=-1,a=-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,o=c,a=f,s="numeric")):typeof n=="string"&&typeof h=="string"?o===-1&&(o=c,a=f,s="categorical"):o===-1&&(o=c,a=f,s="generic")}}}if(o!==-1&&a!==-1){const c=t[o];if(Array.isArray(c)&&ni(c[a]),s!==null)return l(o,a),!0}return!1}moveToXValueInValues(t,n,l){let o=-1,a=-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,o=c,a=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?o===-1&&(o=c,a=u,s="categorical"):o===-1&&(o=c,a=u,s="generic")}return o!==-1&&a!==-1?(this.extractXFromValue(t[o][a]),l(o,a),!0):!1}extractXFromPoint(t){return Iae(t)?t.x:null}extractXFromValue(t){return Pae(t)?t.x:jae(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,o=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a++){const i=ni(t[a]);if(typeof i=="number"){const s=Math.abs(i-n);s<o&&(o=s,l=a)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<o&&(o=c,l=a)}}}if(l!==-1)return ni(t[l]),l}else if(typeof n=="string"){for(let o=0;o<t.length;o++)if(ni(t[o])===n)return o;const l=Number(n);if(!Number.isNaN(l)){let o=-1,a=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<a&&(a=c,o=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-l);u<a&&(a=u,o=i)}}}if(o!==-1)return ni(t[o]),o}for(let o=0;o<t.length;o++)if(typeof ni(t[o])=="string")return o}return t.length>0?(ni(t[0]),0):-1}dispose(){}}function Fae(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function zae(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function qae(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function $ae(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function Uae(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function Gae(e){return e&&typeof e=="object"&&"value"in e}function ni(e){return e?Fae(e)||zae(e)||$ae(e)||Uae(e)||qae(e)?e.x:Gae(e)?e.value:null:null}const Zae="unavailable",Xae="X",Wae="Y",Yae="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 o;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,l=this.col>=0&&this.col<(((o=t[n])==null?void 0:o.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[o,a]=t,{row:i}=this.getSafeIndices();return o>=0&&o<this.values.length&&a>=0&&a<(((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:o}=this.getSafeIndices();return this.col<(((l=this.values[o])==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,o,a;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 MP,this.id=n.id,this.type=n.type,this.title=n.title??Zae,this.xAxis=((l=n.axes)==null?void 0:l.x)??Xae,this.yAxis=((o=n.axes)==null?void 0:o.y)??Wae,this.fill=((a=n.axes)==null?void 0:a.fill)??Yae}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(a=>a.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==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{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==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 o;const{row:n}=this.getSafeIndices(),l=((o=this.values[n])==null?void 0:o.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 o4{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 o=1;o<t.length;o++){const a=t[o];a<n&&(n=a),a>l&&(l=a)}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 o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[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),o=this.calculateLuminance(n);return(Math.max(l,o)+.05)/(Math.min(l,o)+.05)}static calculateLuminance(t){const[n,l,o]=[t.r,t.g,t.b].map(a=>{const i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*l+.0722*o}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(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,a=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=o}),i=document.createElement("canvas");[i.width,i.height]=[a.naturalWidth,a.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(a,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 o=l.cloneNode(!0);return o.setAttribute(Le.VISIBILITY,Le.HIDDEN),l.insertAdjacentElement(Le.AFTER_END,o),o})}static selectElement(t,n=!0){const l=document.querySelector(t);if(!n)return l;const o=l==null?void 0:l.cloneNode(!0);return o==null||o.setAttribute(Le.VISIBILITY,Le.HIDDEN),l==null||l.insertAdjacentElement(Le.AFTER_END,o),o}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 o=window.getComputedStyle(l),a=o.stroke||o.fill,i=o.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,a),c.setAttribute(Le.STROKE,a),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 o=t.getBBox();let a,i,s,c;switch(n){case"top":[a,i,s,c]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,s,c]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,s,c]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,s,c]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,Le.LINE);return Q.setAttribute(Le.X1,String(a)),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),o=t.tagName.toLowerCase(),a=o===Le.POLYLINE||o===Le.LINE,i=a?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,a){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 o=t.querySelector("rect, path");let a="";if(o){a=window.getComputedStyle(o).getPropertyValue("fill"),(!a||a==="none"||a==="transparent"||a==="rgba(0, 0, 0, 0)")&&(l?a=window.getComputedStyle(l).getPropertyValue("fill"):a=n);const i=this.getHighlightColor(a,n);o.setAttribute("stroke",i),o.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??q2.VERTICAL,this.barValues=l.map(o=>o.map(a=>this.orientation===q2.VERTICAL?Number(a.y):Number(a.x))),this.min=this.barValues.map(o=>o4.safeMin(o)),this.max=this.barValues.map(o=>o4.safeMax(o)),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===q2.VERTICAL,l=n?this.barValues[this.row].length:this.barValues.length,o=n?this.col:this.row,a=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:o4.safeMin(this.min),max:o4.safeMax(this.max),size:l,index:o,value:a,...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===q2.VERTICAL,l=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,a=n?l.x:l.y,i=n?this.yAxis:this.xAxis,s=n?l.y:l.x;return{main:{label:o,value:a},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 o=0;o<this.points.length;o++)if(l[o].length!==this.points[o].length)return null;return l}}class Kae 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 Jae 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??q2.VERTICAL,this.sections=[e5.LOWER_OUTLIER,e5.MIN,e5.Q1,e5.Q2,e5.Q3,e5.MAX,e5.UPPER_OUTLIER];const l=[a=>a.lowerOutliers,a=>a.min,a=>a.q1,a=>a.q2,a=>a.q3,a=>a.max,a=>a.upperOutliers];this.orientation===q2.HORIZONTAL?this.boxValues=this.points.map(a=>l.map(i=>i(a))):this.boxValues=l.map(a=>this.points.map(i=>a(i)));const o=this.boxValues.map(a=>a.flatMap(i=>Array.isArray(i)?i:[i]));this.min=o4.minFrom2D(o),this.max=o4.maxFrom2D(o),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 o=this.orientation===q2.HORIZONTAL;n=o?n:l,l=o?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(o=>o-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===q2.HORIZONTAL,l=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:l,col:o}}text(){const n=this.orientation===q2.HORIZONTAL,l=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,a=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:o,value:l.fill},cross:{label:i,value:s},section:a}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const l=this.orientation===q2.VERTICAL,o=new Array;if(l)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:n.length}));return n.forEach((a,i)=>{const s=a.lowerOutliers.flatMap(L=>zt.selectAllElements(L)),c=a.upperOutliers.flatMap(L=>zt.selectAllElements(L)),u=zt.selectElement(a.min)??zt.createEmptyElement(),Q=zt.selectElement(a.max)??zt.createEmptyElement(),f=zt.selectElement(a.iq)??zt.createEmptyElement(),h=zt.selectElement(a.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)=>{o[x][i]=L}):o.push(v)}),o}}const eoe="trend",AP=100;class toe 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 MP;const l=n.data;this.candles=l.map(o=>({...o,volatility:Math.round((o.high-o.low)*AP)/AP,trend:o.close>o.open?"Bull":o.close<o.open?"Bear":"Neutral"})),this.orientation=n.orientation??q2.VERTICAL,this.candleValues=this.sections.map(o=>this.candles.map(a=>a[o])),this.min=o4.minFrom2D(this.candleValues),this.max=o4.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===q2.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(a=>[a,n[a]]).sort((a,i)=>a[1]-i[1]).map(a=>a[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const l=new Map;return n.forEach((o,a)=>{l.set(o,a)}),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===q2.HORIZONTAL?this.col=l:this.row=l}updateVisualPointPosition(){this.orientation===q2.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],o=l.indexOf(this.currentSegmentType??"open");if(o===-1){this.notifyOutOfBounds();return}const a=n==="UPWARD"?o+1:o-1;if(a>=0&&a<l.length)this.currentSegmentType=l[a],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:o,segmentType:a}=this.navigationService.computeIndexAndSegment(n,l,this.orientation,this.sections);this.currentPointIndex=o,this.currentSegmentType=a,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],o=l.indexOf(this.currentSegmentType??"open"),a=n==="UPWARD"?o+1:o-1;return a>=0&&a<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 o=this.candleValues.map(i=>Math.min(...i)),a=this.candleValues.map(i=>Math.max(...i));return{empty:!1,id:this.id,values:this.candleValues,min:o,max:a,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const l=Array.isArray(n)?n:[n],o=[];for(const a of l)o.push(...zt.selectAllElements(a));return o}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,o=this.candles.length,a=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:o},()=>zt.createEmptyElement()),f=Array.from({length:o},()=>zt.createEmptyElement()),h=Array.from({length:o},()=>zt.createEmptyElement());for(let g=0;g<o;g++){let v=this.getElementAt(c,g);if(!v){const x=this.getElementAt(a,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(a,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:o},()=>zt.createEmptyElement()));for(let g=0;g<o;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(a,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(a,g)??zt.createEmptyElement();break;case"low":S=this.getElementAt(s,g)??this.getElementAt(a,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===q2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===q2.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType??"open",fill:{label:eoe,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(o=>o.value===n);return l!==-1?(this.currentPointIndex=l,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}}class noe 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:o,max:a}=o4.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=a,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,o=this.heatmapValues[0].length,a=zt.selectAllElements(n);if(a.length===0||a.length!==l*o)return null;const i=new Array;if(a[0]instanceof SVGPathElement)for(let s=0;s<l;s++){const c=l-1-s,u=new Array;for(let Q=0;Q<o;Q++){const f=c*o+Q;u.push(a[f])}i.push(u)}else if(a[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const c=new Array;for(let u=0;u<o;u++){const Q=u*l+s;c.push(a[Q])}i.push(c)}return i}}class roe extends hH{constructor(t){super(t,[t.data])}text(){const t=this.orientation===q2.VERTICAL,n=this.points[this.row][this.col],l=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text(),range:{min:l,max:o}}}}const _P="Group",pH=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class OP 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(o=>Number(o.y))),this.min=this.lineValues.map(l=>o4.safeMin(l)),this.max=this.lineValues.map(l=>o4.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 a;const n=this.points[this.row][this.col],l=this.findIntersections();let o={};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=((a=this.points[this.previousRow][0])==null?void 0:a.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}o={fill:{label:_P,value:`intersection at (${i.join(", ")})`}}}else o=n.fill?{fill:{label:_P,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},...o}}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 o=this.findLineByXAndYDirection(n),a=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const i=this.findColumnByXValue(o,a);if(i!==-1){this.row=o,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 a={...super.state,intersections:l};for(const i of this.observers)i.update(a)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,l=this.points[this.row][this.col].y,o=[];for(let a=0;a<this.points.length;a++){const i=this.points[a].findIndex(s=>s.x===n&&s.y===l);i!==-1&&o.push({min:this.min[a],max:this.max[a],size:this.points[a].length,index:i,value:l,groupIndex:a})}return o}isMovable(n){if(Array.isArray(n)){const[l,o]=n;return l>=0&&l<this.values.length&&o>=0&&o<this.values[l].length}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.findLineByXAndYDirection(n);if(l===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(l,o)!==-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 o=null,a=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<a&&(a=Q,o=i)}return o}findColumnByXValue(n,l){return this.points[n].findIndex(o=>o.x===l)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const l=[];let o=!0;for(let a=0;a<n.length;a++){const i=zt.selectElement(n[a],!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[a].length)if(s.length<this.lineValues[a].length)for(;s.length<this.lineValues[a].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[a].length&&(s.length=this.lineValues[a].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&&(o=!1),l.push(c)}return o?null:l}get state(){const n=super.state;if(n.empty)return n;const l=this.points.length>1,o={...n,plotType:l?"multiline":"single line",...l&&{groupCount:this.points.length}},a=this.findIntersections();return a.length>1?{...o,intersections:a}:o}}class ioe 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,o=[...l].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let a=null;for(const c of o)(!a||a.x!==c.x)&&(a={x:c.x,y:[]},this.xPoints.push(a)),a.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=o4.safeMin(this.xValues),this.maxX=o4.safeMax(this.xValues),this.minY=o4.safeMin(this.yValues),this.maxY=o4.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)],o=this.yValues.indexOf(l);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],l=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(l);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,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 o=new Map,a=new Map;l.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(o.has(u)||o.set(u,[]),o.get(u).push(c)),Number.isNaN(Q)||(a.has(Q)||a.set(Q,[]),a.get(Q).push(c))});const i=Array.from(o.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(a.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const CP="Sum",aoe="Level",ooe="undefined";class loe extends hH{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let a=0;a<this.barValues[0].length;a++){const i=this.barValues.reduce((c,u)=>c+u[a],0);t.push(i);const s=this.orientation===q2.VERTICAL?{x:this.points[0][a].x,y:i,fill:CP}:{x:i,y:this.points[0][a].y,fill:CP};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:l,max:o}=o4.minMax(t);this.min.push(l),this.max.push(o)}text(){return{...super.text(),fill:{label:aoe,value:this.points[this.row][this.col].fill??ooe}}}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 o=0,a=0;o<this.barValues.length;o++){const i=new Array;for(let s=0;s<this.barValues[o].length;s++){if(a>=n.length)return new Array;this.barValues[o][s]===0?i.push(zt.createEmptyElement()):i.push(n[a++])}l.push(i)}else if(n[0]instanceof SVGRectElement){for(let o=0;o<this.barValues.length;o++)l.push(new Array);for(let o=0,a=0;o<this.barValues[0].length;o++)for(let i=this.barValues.length-1;i>=0;i--){if(a>=n.length)return new Array;this.barValues[i][o]===0?l[i].push(zt.createEmptyElement()):l[i].push(n[a++])}}return l}}class wP extends OP{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))],o=n>0?l(n-1):l(n),a=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:[o,a,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class soe extends wP{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let l=!0;for(let a=0;a<t.length;a++){const i=zt.selectElement(t[a],!1);if(!i){n.push([]);continue}const s=(o=this.points)==null?void 0:o[a],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 uoe(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function coe(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&uoe(e.data[0][0])?new soe(e):new wP(e)}class Toe{static create(t){switch(t.type){case $2.BAR:return new Kae(t);case $2.BOX:return new Jae(t);case $2.CANDLESTICK:return new toe(t);case $2.HEATMAP:return new noe(t);case $2.HISTOGRAM:return new roe(t);case $2.LINE:return new OP(t);case $2.SCATTER:return new ioe(t);case $2.SMOOTH:return coe(t);case $2.DODGED:case $2.NORMALIZED:case $2.STACKED:return new loe(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const Qoe="MAIDR Plot",foe="unavailable",doe="unavailable";class hoe 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??Qoe,this.subtitle=n.subtitle??foe,this.caption=n.caption??doe;const l=n.subplots;this.subplots=l.map(o=>o.map(a=>new poe(a))),this.size=this.subplots.reduce((o,a)=>o+a.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((o,a)=>o+a.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 o=((l=this.subplots[0])==null?void 0:l.length)||1,a=this.row*o+this.col+1,i=`g[id="axes_${a}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&a-1<c.length)return{empty:!1,elements:c[a-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 poe 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(o=>[Toe.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?Le.EMPTY:a.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 l4={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:l4.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:l4.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:l4.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:l4.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:l4.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:l4.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:l4.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:l4.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:l4.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:l4.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:l4.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 l4.SINE_BASIC;case"Bear":return l4.SAWTOOTH_SOFT;case"Neutral":return l4.TRIANGLE_BASIC;default:return l4.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],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,l.timbreModulation);return{index:t,waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const n=[],l=ku.MIN_HARMONICS+t%ku.HARMONIC_VARIATION;for(let o=0;o<l;o++){const a=1+(o+1)*(.5+t*.3%1),i=.4/(o+1)*(1-t*.1%.3);n.push({frequency:a,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 moe=100,yoe=440,goe=880,yH=.3,gH=l4.SINE_BASIC;class voe{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 o=this.settings.loadSettings();this.currentVolume=o.general.volume/100,this.currentMinFrequency=o.general.minFrequency,this.currentMaxFrequency=o.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.empty){this.playBoundaryAudio();return}if(t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;this.handleTraceState(n)}playBoundaryAudio(){this.stopAll(),this.playEmptyTone(1,0)}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 a=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,a);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,a),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,a)}}}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,o,a,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(l,s,c),Q={min:0,max:o},f={min:-1,max:1},h=this.clamp(this.interpolate(a,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const l=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=n,l.push(o),t.harmonicMix)for(const a of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=a.frequency*n,l.push(i)}return l}createGainNodes(t,n,l,o){const a=[],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,o);f!==null&&u.gain.setValueCurveAtTime(f,i,o),a.push(u)}return a}playOscillator(t,n=0,l){const o=yH,a=this.getVolume();l||(l=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,a,o),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),o*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,l,o,a){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=a*i,f=a*s,h=a*u,p=a-Q-f-h;return t.gain.setValueAtTime(1e-4*l,o),t.gain.linearRampToValueAtTime(l,o+Q),t.gain.linearRampToValueAtTime(c*l,o+Q+f),p>0&&t.gain.setValueAtTime(c*l,o+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*l,o+a),null}else return[.5*l,l,.5*l,.5*l,.5*l,.1*l,1e-4*l]}playSmooth(t,n,l,o,a,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(a,{min:0,max:o-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,o=l.currentTime,a=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=l.createGain();u.gain.setValueAtTime(.3*i,o),u.gain.exponentialRampToValueAtTime(.01*i,o+a),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,o),S.gain.exponentialRampToValueAtTime(.001*i,o+a),_.pan.value=h,x.connect(S),S.connect(_),_.connect(O),O.connect(u),x.start(o),x.stop(o+a),p.push(x)}const g=L=>{u.disconnect(),p.forEach(x=>{x.disconnect()}),this.activeAudioIds.delete(L)},v=setTimeout(()=>g(v),a*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(moe,0,{index:gH,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(yoe,0,{index:gH,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(goe,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 o=this.activeAudioIds.get(l);if(!o){clearInterval(l);return}o.forEach(a=>{a==null||a.disconnect(),a==null||a.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,o=this.audioContext,a=o.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=o.createOscillator();L.type=v,L.frequency.value=p;const x=o.createGain();x.gain.setValueAtTime(n,a),x.gain.exponentialRampToValueAtTime(.01*n,a+l),L.connect(x),x.connect(this.compressor),L.start(a),L.stop(a+l);const S=setTimeout(()=>{L.disconnect(),x.disconnect()},l*1e3*2);this.activeAudioIds.set(S,[L])})}}const xoe=250,Loe=50,boe=500,Hoe=20;class Eoe{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=xoe,this.minSpeed=Loe,this.maxSpeed=boe,this.autoplayRate=this.defaultSpeed,this.interval=Hoe,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 VP=32;class ad{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const i=(t.max[a]-t.min[a])/4,s=t.min[a]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[a].length;Q++)t.values[a][Q]===0?n.push(" "):t.values[a][Q]<=s||t.values[a][Q]<=c?n.push("⠤"):t.values[a][Q]<=u?n.push("⠒"):n.push("⠉"),l[a].push(o.length),o.push({row:a,col:Q});n.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class Soe{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=VP){const l=new Array,o=new Array,a=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];a.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),a[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),o.push({row:i,col:M})}}for(let V=0;V<3;V++)if(a[i][V]===-1){for(let R=V+1;R<=3;R++)if(a[i][R]!==-1){a[i][V]=a[i][R];break}}for(let V=6;V>3;V--)if(a[i][V]===-1){for(let R=V-1;R>=3;R--)if(a[i][R]!==-1){a[i][V]=a[i][R];break}}l.push(Le.NEW_LINE),o.push({row:i,col:M})}return{value:l.join(Le.EMPTY),cellToIndex:a,indexToCell:o}}}class Moe{encode(t){const n=new Array,l=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,s=i+a;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(o.length),o.push({row:c,col:u});n.push(Le.NEW_LINE),l[c].push(o.length),o.push({row:c,col:t.values[c].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class DP{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(a,t);for(let Q=0;Q<t.values[a].length;Q++){const f=t.values[a][Q],h=Q>0?t.values[a][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),l[a].push(o.length),o.push({row:a,col:Q})}n.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}getBrailleChar(t,n,l,o,a,i){return i===void 0&&(i=a),t<=l&&n!==null&&n>l?n<=o?"⢄":n<=i?"⢆":"⢇":t<=l?"⣀":n!==null&&n<=l?t<=o?"⡠":t<=i?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=i?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=a?"⠉":""}getBraille6Char(t,n,l,o,a){const i=f=>f<=l?"low":f<=o?"medium":(f<=a,"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 o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class Aoe extends DP{getThresholds(t,n){const l=Array.isArray(n.min)?n.min[t]:n.min,o=Array.isArray(n.max)?n.max[t]:n.max,a=(o-l)/3,i=l+a,s=i+a;return{low:i,medium:s,high:o}}encode(t){var a;const n=new Array,l=new Array,o=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);((a=t.custom)==null?void 0:a[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),l[i].push(o.length),o.push({row:i,col:Q})}n.push(Le.NEW_LINE),l[i].push(o.length),o.push({row:i,col:t.values[i].length})}return{value:n.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class _oe extends DP{getThresholds(t,n){const l=(n.max[t]-n.min[t])/4,o=n.min[t]+l,a=o+l,i=a+l,s=n.max[t];return{low:o,medium:a,mediumHigh:i,high:s}}}class Ooe{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([[$2.BAR,new ad],[$2.BOX,new Soe],[$2.CANDLESTICK,new Aoe],[$2.DODGED,new ad],[$2.HEATMAP,new Moe],[$2.HISTOGRAM,new ad],[$2.LINE,new _oe],[$2.NORMALIZED,new ad],[$2.STACKED,new ad]]),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 o=this.encoders.get(n.traceType);this.cache=o.encode(l,VP),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 RP=(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))(RP||{});class kP{constructor(){}static async post(t,n,l){const o={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",o,n)}static async request(t,n,l,o){try{const a=await fetch(t,{method:n,headers:l,body:o});return a.ok?{success:!0,data:await a.json()}:{success:!1,error:{statusCode:a.status,message:`API Error: ${a.status} - ${a.statusText}`}}}catch(a){return console.error(`Error in API ${n} request to ${t}:`,a),{success:!1,error:{statusCode:RP.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}oe(kP,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Coe=`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