maidr 3.15.1 → 3.15.2

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
@@ -1,5 +1,5 @@
1
1
  (function(Hr){typeof define=="function"&&define.amd?define(Hr):Hr()})(function(){"use strict";var pae=Object.defineProperty;var mae=(Hr,v4,b1)=>v4 in Hr?pae(Hr,v4,{enumerable:!0,configurable:!0,writable:!0,value:b1}):Hr[v4]=b1;var ae=(Hr,v4,b1)=>mae(Hr,typeof v4!="symbol"?v4+"":v4,b1);function Hr(e,t){for(var r=0;r<t.length;r++){const l=t[r];if(typeof l!="string"&&!Array.isArray(l)){for(const o in l)if(o!=="default"&&!(o in e)){const a=Object.getOwnPropertyDescriptor(l,o);a&&Object.defineProperty(e,o,a.get?a:{enumerable:!0,get:()=>l[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var v4=(e=>(e.CLICK="click",e.DOM_LOADED="DOMContentLoaded",e.FOCUS_IN="focusin",e.FOCUS_OUT="focusout",e.SELECTION_CHANGE="selectionchange",e))(v4||{}),b1=(e=>(e.BRAILLE="BRAILLE",e.CHAT="CHAT",e.HELP="HELP",e.FIGURE_LABEL="FIGURE_LABEL",e.SUBPLOT="SUBPLOT",e.TRACE="TRACE",e.TRACE_LABEL="TRACE_LABEL",e.REVIEW="REVIEW",e.SETTINGS="SETTINGS",e))(b1||{});class f9{constructor(){ae(this,"listeners");ae(this,"event",t=>(this.listeners.add(t),{dispose:()=>this.listeners.delete(t)}));this.listeners=new Set}dispose(){this.listeners.clear()}fire(t){for(const r of this.listeners)r(t)}}class Le{constructor(){}}ae(Le,"ARTICLE","article"),ae(Le,"DIV","div"),ae(Le,"FIGURE","figure"),ae(Le,"IMAGE","img"),ae(Le,"INPUT","input"),ae(Le,"TEXT_AREA","textarea"),ae(Le,"BRAILLE_TEXT_AREA","maidr-braille-textarea"),ae(Le,"MAIDR_ARTICLE","maidr-article"),ae(Le,"MAIDR_FIGURE","maidr-figure"),ae(Le,"MAIDR_HIGHLIGHT","maidr-highlight"),ae(Le,"REACT_CONTAINER","maidr-react-container"),ae(Le,"REVIEW_INPUT","maidr-review-input"),ae(Le,"TEXT_CONTAINER","maidr-text-container"),ae(Le,"ARIA_LABEL","aria-label"),ae(Le,"CIRCLE_X","cx"),ae(Le,"CIRCLE_Y","cy"),ae(Le,"D","d"),ae(Le,"FILL","fill"),ae(Le,"POINTS","points"),ae(Le,"RADIUS","r"),ae(Le,"ROLE","role"),ae(Le,"STROKE","stroke"),ae(Le,"STROKE_WIDTH","stroke-width"),ae(Le,"TITLE","title"),ae(Le,"VISIBILITY","visibility"),ae(Le,"X1","x1"),ae(Le,"X2","x2"),ae(Le,"Y1","y1"),ae(Le,"Y2","y2"),ae(Le,"AFTER_END","afterend"),ae(Le,"APPLICATION","application"),ae(Le,"ARE"," are "),ae(Le,"CIRCLE","circle"),ae(Le,"CLOSE_BRACKET","]"),ae(Le,"COMMA",","),ae(Le,"COMMA_SPACE",", "),ae(Le,"EMPTY",""),ae(Le,"HIDDEN","hidden"),ae(Le,"IS"," is "),ae(Le,"LINE","line"),ae(Le,"MAIDR_DATA","maidr-data"),ae(Le,"MAIDR_HIGHLIGHT_COLOR","#BADA55"),ae(Le,"NEW_LINE",`
2
- `),ae(Le,"OPEN_BRACKET","["),ae(Le,"POLYLINE","polyline"),ae(Le,"SPACE"," "),ae(Le,"THROUGH"," through "),ae(Le,"TRANSPARENT","transparent"),ae(Le,"VISIBLE","visible"),ae(Le,"X","x"),ae(Le,"Y","y"),ae(Le,"HIGHLIGHT_BASE_COLOR",{r:255,g:255,b:255}),ae(Le,"HIGHLIGHT_CONTRAST_RATIO",3),ae(Le,"HIGHLIGHT_COLOR_RATIO",.6),ae(Le,"HIGHLIGHT_MAX_COLOR",255);let lv=class{constructor(){ae(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,r=1){const l=this.items.lastIndexOf(t);return l!==-1?(this.items.splice(l,r),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}};const sv=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function uv(e,t,r,l){e.addEventListener?e.addEventListener(t,r,l):e.attachEvent&&e.attachEvent("on".concat(t),r)}function mc(e,t,r,l){e.removeEventListener?e.removeEventListener(t,r,l):e.detachEvent&&e.detachEvent("on".concat(t),r)}function BH(e,t){const r=t.slice(0,t.length-1);for(let l=0;l<r.length;l++)r[l]=e[r[l].toLowerCase()];return r}function PH(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let r=t.lastIndexOf("");for(;r>=0;)t[r-1]+=",",t.splice(r,1),r=t.lastIndexOf("");return t}function tj(e,t){const r=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let o=!0;for(let a=0;a<r.length;a++)l.indexOf(r[a])===-1&&(o=!1);return o}const yc={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,"-":sv?173:189,"=":sv?61:187,";":sv?59:186,"'":222,"[":219,"]":221,"\\":220},o5={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},gc={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},M3={16:!1,18:!1,17:!1,91:!1},L2={};for(let e=1;e<20;e++)yc["f".concat(e)]=111+e;let d2=[],vc=null,jH="all";const S0=new Map,Lc=e=>yc[e.toLowerCase()]||o5[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),nj=e=>Object.keys(yc).find(t=>yc[t]===e),rj=e=>Object.keys(o5).find(t=>o5[t]===e);function IH(e){jH=e||"all"}function xc(){return jH||"all"}function ij(){return d2.slice(0)}function aj(){return d2.map(e=>nj(e)||rj(e)||String.fromCharCode(e))}function oj(){const e=[];return Object.keys(L2).forEach(t=>{L2[t].forEach(r=>{let{key:l,scope:o,mods:a,shortcut:i}=r;e.push({scope:o,shortcut:i,mods:a,keys:l.split("+").map(s=>Lc(s))})})}),e}function lj(e){const t=e.target||e.srcElement,{tagName:r}=t;let l=!0;const o=r==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||r==="TEXTAREA"||r==="SELECT")&&!t.readOnly)&&(l=!1),l}function sj(e){return typeof e=="string"&&(e=Lc(e)),d2.indexOf(e)!==-1}function uj(e,t){let r,l;e||(e=xc());for(const o in L2)if(Object.prototype.hasOwnProperty.call(L2,o))for(r=L2[o],l=0;l<r.length;)r[l].scope===e?r.splice(l,1).forEach(i=>{let{element:s}=i;return cv(s)}):l++;xc()===e&&IH(t||"all")}function cj(e){let t=e.keyCode||e.which||e.charCode;const r=d2.indexOf(t);if(r>=0&&d2.splice(r,1),e.key&&e.key.toLowerCase()==="meta"&&d2.splice(0,d2.length),(t===93||t===224)&&(t=91),t in M3){M3[t]=!1;for(const l in o5)o5[l]===t&&(F3[l]=!1)}}function FH(e){if(typeof e>"u")Object.keys(L2).forEach(o=>{Array.isArray(L2[o])&&L2[o].forEach(a=>mp(a)),delete L2[o]}),cv(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&mp(o)});else if(typeof e=="object")e.key&&mp(e);else if(typeof e=="string"){for(var t=arguments.length,r=new Array(t>1?t-1:0),l=1;l<t;l++)r[l-1]=arguments[l];let[o,a]=r;typeof o=="function"&&(a=o,o=""),mp({key:e,scope:o,method:a,splitKey:"+"})}}const mp=e=>{let{key:t,scope:r,method:l,splitKey:o="+"}=e;PH(t).forEach(i=>{const s=i.split(o),T=s.length,u=s[T-1],Q=u==="*"?"*":Lc(u);if(!L2[Q])return;r||(r=xc());const f=T>1?BH(o5,s):[],h=[];L2[Q]=L2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===r&&tj(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>cv(p))})};function zH(e,t,r,l){if(t.element!==l)return;let o;if(t.scope===r||t.scope==="all"){o=t.mods.length>0;for(const a in M3)Object.prototype.hasOwnProperty.call(M3,a)&&(!M3[a]&&t.mods.indexOf(+a)>-1||M3[a]&&t.mods.indexOf(+a)===-1)&&(o=!1);(t.mods.length===0&&!M3[16]&&!M3[18]&&!M3[17]&&!M3[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(d2),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function qH(e,t){const r=L2["*"];let l=e.keyCode||e.which||e.charCode;if(!F3.filter.call(this,e))return;if((l===93||l===224)&&(l=91),d2.indexOf(l)===-1&&l!==229&&d2.push(l),["metaKey","ctrlKey","altKey","shiftKey"].forEach(s=>{const T=gc[s];e[s]&&d2.indexOf(T)===-1?d2.push(T):!e[s]&&d2.indexOf(T)>-1?d2.splice(d2.indexOf(T),1):s==="metaKey"&&e[s]&&(d2=d2.filter(u=>u in gc||u===l))}),l in M3){M3[l]=!0;for(const s in o5)if(Object.prototype.hasOwnProperty.call(o5,s)){const T=gc[o5[s]];F3[s]=e[T]}if(!r)return}for(const s in M3)Object.prototype.hasOwnProperty.call(M3,s)&&(M3[s]=e[gc[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(d2.indexOf(17)===-1&&d2.push(17),d2.indexOf(18)===-1&&d2.push(18),M3[17]=!0,M3[18]=!0);const o=xc();if(r)for(let s=0;s<r.length;s++)r[s].scope===o&&(e.type==="keydown"&&r[s].keydown||e.type==="keyup"&&r[s].keyup)&&zH(e,r[s],o,t);if(!(l in L2))return;const a=L2[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 T=a[s],{splitKey:u}=T,Q=T.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(Lc(Q[h]));f.sort().join("")===d2.sort().join("")&&zH(e,T,o,t)}}function F3(e,t,r){d2=[];const l=PH(e);let o=[],a="all",i=document,s=0,T=!1,u=!0,Q="+",f=!1,h=!1;for(r===void 0&&typeof t=="function"&&(r=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(a=t.scope),t.element&&(i=t.element),t.keyup&&(T=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&&FH(e,a);s<l.length;s++)e=l[s].split(Q),o=[],e.length>1&&(o=BH(o5,e)),e=e[e.length-1],e=e==="*"?"*":Lc(e),e in L2||(L2[e]=[]),L2[e].push({keyup:T,keydown:u,scope:a,mods:o,shortcut:l[s],method:r,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!S0.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return qH(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;qH(v,i),cj(v)};S0.set(i,{keydownListener:p,keyupListenr:g,capture:f}),uv(i,"keydown",p,f),uv(i,"keyup",g,f)}if(!vc){const p=()=>{d2=[]};vc={listener:p,capture:f},uv(window,"focus",p,f)}}}function Tj(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(L2).forEach(r=>{L2[r].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function cv(e){const t=Object.values(L2).flat();if(t.findIndex(l=>{let{element:o}=l;return o===e})<0){const{keydownListener:l,keyupListenr:o,capture:a}=S0.get(e)||{};l&&o&&(mc(e,"keyup",o,a),mc(e,"keydown",l,a),S0.delete(e))}if((t.length<=0||S0.size<=0)&&(Object.keys(S0).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:s}=S0.get(o)||{};a&&i&&(mc(o,"keyup",i,s),mc(o,"keydown",a,s),S0.delete(o))}),S0.clear(),Object.keys(L2).forEach(o=>delete L2[o]),vc)){const{listener:o,capture:a}=vc;mc(window,"focus",o,a),vc=null}}const Tv={getPressedKeyString:aj,setScope:IH,getScope:xc,deleteScope:uj,getPressedKeyCodes:ij,getAllKeyCodes:oj,isPressed:sj,filter:lj,trigger:Tj,unbind:FH,keyMap:yc,modifier:o5,modifierMap:gc};for(const e in Tv)Object.prototype.hasOwnProperty.call(Tv,e)&&(F3[e]=Tv[e]);if(typeof window<"u"){const e=window.hotkeys;F3.noConflict=t=>(t&&window.hotkeys===F3&&(window.hotkeys=e),F3),window.hotkeys=F3}class Qj{constructor(t){ae(this,"id");ae(this,"instructionContext");ae(this,"plotContext");ae(this,"scopeContext");this.id=t.id,this.plotContext=new lv,this.scopeContext=new lv;const r=t.state;if(r.empty||r.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(b1.SUBPLOT);return}this.scopeContext.push(b1.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),F3.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,r){this.active.moveToIndex(t,r)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const r=this.active;r.moveOnce(t),this.active.notifyStateUpdate(),this.plotContext.push(r.activeTrace)}}enterSubplot(){if(this.active.state.type==="figure"){const r=this.active;this.plotContext.push(r.activeSubplot),this.active.notifyStateUpdate(),this.plotContext.push(r.activeSubplot.activeTrace),this.toggleScope(b1.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(b1.TRACE))}getInstruction(t){const r=this.instructionContext.state;if(r.empty)return`No ${r.type} info available`;const l=t?"Click to activate.":Le.EMPTY;switch(r.type){case"figure":return`This is a MAIDR figure containing ${r.size} subplots. ${l} Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a MAIDR subplot containing ${r.size} layers, and this is layer 1 of ${r.size}: ${r.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: ${r.traceType}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}const fj="unavailable",dj="X",hj="Y",pj="unavailable";class Qv{constructor(){ae(this,"observers");ae(this,"isInitialEntry");ae(this,"isOutOfBounds");ae(this,"row");ae(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()}moveToExtreme(t){switch(this.isInitialEntry&&this.handleInitialEntry(),t){case"UPWARD":this.row=this.values.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.col=this.values[this.row].length-1;break;case"BACKWARD":this.col=0;break}this.notifyStateUpdate()}moveToIndex(t,r){this.isMovable([t,r])&&(this.row=t,this.col=r,this.isInitialEntry=!1,this.notifyStateUpdate())}isMovable(t){if(Array.isArray(t)){const[r,l]=t;return r>=0&&r<this.values.length&&l>=0&&l<this.values[this.row].length}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.values.length-1)),this.col=Math.max(0,Math.min(this.col,this.values[this.row].length-1))}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(r=>r!==t)}notifyStateUpdate(){const t=this.state;for(const r of this.observers)r.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}}class d9 extends Qv{constructor(r){var l,o,a;super();ae(this,"id");ae(this,"type");ae(this,"title");ae(this,"xAxis");ae(this,"yAxis");ae(this,"fill");this.id=r.id,this.type=r.type,this.title=r.title??fj,this.xAxis=((l=r.axes)==null?void 0:l.x)??dj,this.yAxis=((o=r.axes)==null?void 0:o.y)??hj,this.fill=((a=r.axes)==null?void 0:a.fill)??pj}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(r=>r.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(a=>a.remove())})),this.highlightValues.length=0),super.dispose()}get state(){return this.isOutOfBounds?{empty:!0,type:"trace",traceType:this.type,audio:{size:this.values[this.row].length,index:this.col}}:{empty:!1,type:"trace",traceType: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(){return this.highlightValues===null||this.isInitialEntry?{empty:!0,type:"trace",traceType:this.type,audio:{size:this.values[this.row].length,index:this.col}}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:this.values[this.row].length,BACKWARD:this.values[this.row].length}}hasMultiPoints(){return!1}}var r3=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(r3||{}),R2=(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))(R2||{});class z3{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 r=t.flat();return this.safeMin(r)}static maxFrom2D(t){const r=t.flat();return this.safeMax(r)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let r=t[0],l=t[0];for(let o=1;o<t.length;o++){const a=t[o];a<r&&(r=a),a>l&&(l=a)}return{min:r,max:l}}static minMaxFrom2D(t){const r=t.flat();return this.minMax(r)}}class yp{constructor(){}static parse(t){const r=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(r)){let o=r.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=r.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,r){const l=this.calculateLuminance(t),o=this.calculateLuminance(r);return(Math.max(l,o)+.05)/(Math.min(l,o)+.05)}static calculateLuminance(t){const[r,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*r+.7152*l+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class O1{constructor(){}static async toBase64(t){try{const r=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r).replace(/'/g,"%27").replace(/"/g,"%22")}`,a=await new Promise((T,u)=>{const Q=new Image;Q.onload=()=>T(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(r){return console.error("Error converting SVG to Base 64:",r instanceof Error?r.message:r),""}}static selectAllElements(t,r=!0){return Array.from(document.querySelectorAll(t)).map(l=>{if(!r)return l;const o=l.cloneNode(!0);return o.setAttribute(Le.VISIBILITY,Le.HIDDEN),l.insertAdjacentElement(Le.AFTER_END,o),o})}static selectElement(t,r=!0){const l=document.querySelector(t);if(!r)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 r=document.createElementNS(this.SVG_NAMESPACE,t);return r.setAttribute(Le.FILL,Le.TRANSPARENT),r.setAttribute(Le.STROKE,Le.TRANSPARENT),r.setAttribute(Le.VISIBILITY,Le.HIDDEN),r}static createCircleElement(t,r,l){var u;const o=window.getComputedStyle(l),a=o.stroke||o.fill,i=o.strokeWidth||"2",s=Number.parseFloat(i)*2,T=document.createElementNS(this.SVG_NAMESPACE,Le.CIRCLE);return T.setAttribute(Le.CIRCLE_X,String(t)),T.setAttribute(Le.CIRCLE_Y,String(r)),T.setAttribute(Le.RADIUS,String(s)),T.setAttribute(Le.FILL,a),T.setAttribute(Le.STROKE,a),T.setAttribute(Le.STROKE_WIDTH,i),T.setAttribute(Le.VISIBILITY,Le.HIDDEN),(u=l.parentElement)==null||u.insertAdjacentElement(Le.AFTER_END,T),T}static createLineElement(t,r){const o=t.getBBox();let a,i,s,T;switch(r){case"top":[a,i,s,T]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,s,T]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,s,T]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,s,T]=[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(T)),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,r){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,r);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 T=window.getComputedStyle(l).getPropertyValue(Le.STROKE_WIDTH);l.setAttribute(Le.STROKE_WIDTH,`${T+2}`)}return t.insertAdjacentElement(Le.AFTER_END,l),l}static getHighlightColor(t,r){const l=yp.parse(t);if(!l||!(yp.getContrastRatio(l,Le.HIGHLIGHT_BASE_COLOR)<Le.HIGHLIGHT_CONTRAST_RATIO))return r;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)),yp.rgbToString(i)}static getContrastingColorForElement(t){const r=window.getComputedStyle(t).fill||"rgb(255,255,255)",l=yp.parse(r);return l?(.2126*l.r+.7152*l.g+.0722*l.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,r){t.style.outline=`4px solid ${r}`,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,r,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=r);const i=this.getHighlightColor(a,r);o.setAttribute("stroke",i),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const r=t.querySelector("rect, path");r&&(r.removeAttribute("stroke"),r.removeAttribute("stroke-width"))}}ae(O1,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class fv extends d9{constructor(r,l){super(r);ae(this,"points");ae(this,"barValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"min");ae(this,"max");this.points=l,this.orientation=r.orientation??r3.VERTICAL,this.barValues=l.map(o=>o.map(a=>this.orientation===r3.VERTICAL?Number(a.y):Number(a.x))),this.min=this.barValues.map(o=>z3.safeMin(o)),this.max=this.barValues.map(o=>z3.safeMax(o)),this.highlightValues=this.mapToSvgElements(r.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const r=this.orientation===r3.VERTICAL,l=r?this.barValues[this.row].length:this.barValues.length,o=r?this.col:this.row,a=r?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:z3.safeMin(this.min),max:z3.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 r=this.orientation===r3.VERTICAL,l=this.points[this.row][this.col],o=r?this.xAxis:this.yAxis,a=r?l.x:l.y,i=r?this.yAxis:this.xAxis,s=r?l.y:l.x;return{main:{label:o,value:a},cross:{label:i,value:s}}}mapToSvgElements(r){if(!r)return null;const l=[O1.selectAllElements(r)];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 mj extends fv{constructor(t){super(t,[t.data])}}const yj="Lower outlier(s)",gj="Upper outlier(s)",vj="Minimum",Lj="Maximum",xj="25%",bj="50%",Hj="75%";class Ej extends d9{constructor(r){super(r);ae(this,"points");ae(this,"boxValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"sections");ae(this,"min");ae(this,"max");this.points=r.data,this.orientation=r.orientation??r3.VERTICAL,this.sections=[yj,vj,xj,bj,Hj,Lj,gj];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===r3.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=z3.minFrom2D(o),this.max=z3.maxFrom2D(o),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(r.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(r,l){const o=this.orientation===r3.HORIZONTAL;r=o?r:l,l=o?l:r,super.moveToIndex(r,l)}get values(){return this.boxValues}audio(){const r=this.boxValues[this.row][this.col],l=Array.isArray(r)?r.map(o=>o-this.min):r-this.min;return{min:this.min,max:this.max,value:r,size:this.max-this.min,index:l}}braille(){const r=this.orientation===r3.HORIZONTAL,l=r?this.row:this.col,o=r?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 r=this.orientation===r3.HORIZONTAL,l=r?this.points[this.row]:this.points[this.col],o=r?this.yAxis:this.xAxis,a=r?this.sections[this.col]:this.sections[this.row],i=r?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(r){if(!r||r.length!==this.points.length)return null;const l=this.orientation===r3.VERTICAL,o=new Array;if(l)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:r.length}));return r.forEach((a,i)=>{const s=a.lowerOutliers.flatMap(b=>O1.selectAllElements(b)),T=a.upperOutliers.flatMap(b=>O1.selectAllElements(b)),u=O1.selectElement(a.min)??O1.createEmptyElement(),Q=O1.selectElement(a.max)??O1.createEmptyElement(),f=O1.selectElement(a.iq)??O1.createEmptyElement(),h=O1.selectElement(a.q2)??O1.createEmptyElement(),[p,g]=l?[O1.createLineElement(f,"top"),O1.createLineElement(f,"bottom")]:[O1.createLineElement(f,"left"),O1.createLineElement(f,"right")],v=[s,u,p,h,g,Q,T];l?v.forEach((b,L)=>{o[L][i]=b}):o.push(v)}),o}}const Mj="Trend";class Sj extends d9{constructor(r){super(r);ae(this,"candles");ae(this,"candleValues");ae(this,"orientation");ae(this,"sections",["open","high","low","close"]);ae(this,"currentSegmentType","open");ae(this,"currentPointIndex",0);ae(this,"sortedSegmentsByPoint");ae(this,"segmentPositionMaps");ae(this,"min");ae(this,"max");ae(this,"highlightValues");const l=r.data;this.candles=l.map(a=>({...a,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=r.orientation??r3.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(i=>i[a])),this.min=z3.minFrom2D(this.candleValues),this.max=z3.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="open",this.orientation===r3.HORIZONTAL?this.col=0:this.row=0;const o=typeof r.selectors=="string"?r.selectors:"";this.highlightValues=this.mapToSvgElements(o)}precomputeSortedSegments(){return this.candles.map(r=>this.sections.map(o=>[o,r[o]]).sort((o,a)=>o[1]-a[1]).map(o=>o[0]))}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(r=>{const l=new Map;return r.forEach((o,a)=>{l.set(o,a)}),l})}getSegmentPositionInSortedOrder(r,l){return this.segmentPositionMaps[r].get(l)??0}getSegmentTypeAtSortedPosition(r,l){return this.sortedSegmentsByPoint[r][l]??"open"}updateVisualSegmentPosition(){const r=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType);this.orientation===r3.HORIZONTAL?this.col=r:this.row=r}updateVisualPointPosition(){this.orientation===r3.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}switch(r){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?l+1:l-1;if(o>=0&&o<this.sections.length)this.currentSegmentType=this.getSegmentTypeAtSortedPosition(this.currentPointIndex,o),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const l=r==="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(r){switch(this.isInitialEntry&&this.handleInitialEntry(),r){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()}isMovable(r){if(Array.isArray(r))return super.isMovable(r);if(this.isInitialEntry)return!0;switch(r){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?l+1:l-1;return o>=0&&o<this.sections.length}case"FORWARD":case"BACKWARD":{const l=r==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return l>=0&&l<this.candles.length}}}dispose(){this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){const r=this.candles[this.currentPointIndex][this.currentSegmentType],l=this.candles[this.currentPointIndex].trend==="Bull"?0:9;return{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:r,groupIndex:l}}braille(){return{empty:!1,id:this.id,values:this.candleValues,min:this.min,max:this.max,row:this.row,col:this.col}}mapToSvgElements(r){if(!r)return null;const l=O1.selectAllElements(r),o=[];for(let a=0;a<this.sections.length;a++){o[a]=[];for(let i=0;i<this.candles.length;i++){const s=i<l.length?i:0;o[a][i]=l[s]}}return o}text(){const r=this.candles[this.currentPointIndex],l=r[this.currentSegmentType];return{main:{label:this.orientation===r3.HORIZONTAL?this.yAxis:this.xAxis,value:r.value},cross:{label:this.orientation===r3.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType,fill:{label:Mj,value:r.trend}}}}class _j extends d9{constructor(r){super(r);ae(this,"heatmapValues");ae(this,"highlightValues");ae(this,"x");ae(this,"y");ae(this,"min");ae(this,"max");const l=r.data;this.x=l.x,this.y=l.y,this.heatmapValues=l.points;const{min:o,max:a}=z3.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=a,this.highlightValues=this.mapToSvgElements(r.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(r){if(!r)return null;const l=this.heatmapValues.length,o=this.heatmapValues[0].length,a=O1.selectAllElements(r);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 T=l-1-s,u=new Array;for(let Q=0;Q<o;Q++){const f=T*o+Q;u.push(a[f])}i.push(u)}else if(a[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const T=new Array;for(let u=0;u<o;u++){const Q=u*l+s;T.push(a[Q])}i.push(T)}return i}}class Aj extends fv{constructor(t){super(t,[t.data])}text(){const t=this.orientation===r3.VERTICAL,r=this.points[this.row][this.col],l=t?r.xMin:r.yMin,o=t?r.xMax:r.yMax;return{...super.text(),range:{min:l,max:o}}}}const Oj="Type",dv=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class $H extends d9{constructor(r){super(r);ae(this,"points");ae(this,"lineValues");ae(this,"highlightValues");ae(this,"min");ae(this,"max");this.points=r.data,this.lineValues=this.points.map(l=>l.map(o=>Number(o.y))),this.min=this.lineValues.map(l=>z3.safeMin(l)),this.max=this.lineValues.map(l=>z3.safeMax(l)),this.highlightValues=this.mapToSvgElements(r.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(){const r=this.points[this.row][this.col],l=r.fill?{fill:{label:Oj,value:r.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},...l}}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}if(r==="UPWARD"||r==="DOWNWARD"){const l=this.findNearestLineByYValue(r);if(l!==null&&l!==this.row){this.row=l,this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}switch(r){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}isMovable(r){if(Array.isArray(r)){const[l,o]=r;return l>=0&&l<this.values.length&&o>=0&&o<this.values[this.row].length}switch(r){case"UPWARD":case"DOWNWARD":return this.findNearestLineByYValue(r)!==null;case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findNearestLineByYValue(r){const l=this.col,o=this.values[this.row][l];let a=null,i=Number.POSITIVE_INFINITY;for(let s=0;s<this.values.length;s++){if(s===this.row||l>=this.values[s].length)continue;const T=this.values[s][l];if(!(r==="UPWARD"?T>o:T<o))continue;const Q=Math.abs(T-o);Q<i&&(i=Q,a=s)}return a}mapToSvgElements(r){if(!r||r.length!==this.lineValues.length)return null;const l=[];let o=!0;for(let a=0;a<r.length;a++){const i=O1.selectElement(r[a],!1);if(!i){l.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(Le.D)||Le.EMPTY;dv.lastIndex=0;let f=dv.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=dv.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 T=[];let u=!1;for(const Q of s){if(Number.isNaN(Q.x)||Number.isNaN(Q.y)){u=!0;break}T.push(O1.createCircleElement(Q.x,Q.y,i))}if(u){l.push([]);continue}T.length>0&&(o=!1),l.push(T)}return o?null:l}}class Cj extends d9{constructor(r){super(r);ae(this,"mode");ae(this,"xPoints");ae(this,"yPoints");ae(this,"xValues");ae(this,"yValues");ae(this,"highlightXValues");ae(this,"highlightYValues");ae(this,"minX");ae(this,"maxX");ae(this,"minY");ae(this,"maxY");this.mode="column";const l=r.data,o=[...l].sort((T,u)=>T.x-u.x||T.y-u.y);this.xPoints=new Array;let a=null;for(const T of o)(!a||a.x!==T.x)&&(a={x:T.x,y:[]},this.xPoints.push(a)),a.y.push(T.y);const i=[...l].sort((T,u)=>T.y-u.y||T.x-u.x);this.yPoints=new Array;let s=null;for(const T of i)(!s||s.y!==T.y)&&(s={y:T.y,x:[]},this.yPoints.push(s)),s.x.push(T.x);this.xValues=this.xPoints.map(T=>T.x),this.yValues=this.yPoints.map(T=>T.y),this.minX=z3.safeMin(this.xValues),this.maxX=z3.safeMax(this.xValues),this.minY=z3.safeMin(this.yValues),this.maxY=z3.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(r.selectors)}dispose(){this.xPoints.length=0,this.yPoints.length=0,this.xValues.length=0,this.yValues.length=0,this.highlightXValues&&(this.highlightXValues.forEach(r=>r.forEach(l=>l.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(r=>r.forEach(l=>l.remove())),this.highlightYValues.length=0),super.dispose()}get values(){return this.mode==="column"?[this.xValues]:[this.yValues]}get highlightValues(){return this.mode==="column"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}audio(){if(this.mode==="column"){const r=this.xPoints[this.col];return{min:this.minY,max:this.maxY,size:r.y.length,index:this.col,value:r.y,...this.getAudioGroupIndex()}}else{const r=this.yPoints[this.row];return{min:this.minX,max:this.maxX,size:r.x.length,index:this.row,value:r.x,...this.getAudioGroupIndex()}}}braille(){return{empty:!0,type:"trace",traceType:this.type}}text(){if(this.mode==="column"){const r=this.xPoints[this.col];return{main:{label:this.xAxis,value:r.x},cross:{label:this.yAxis,value:r.y}}}else{const r=this.yPoints[this.row];return{main:{label:this.yAxis,value:r.y},cross:{label:this.xAxis,value:r.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};const r=this.mode==="column"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return r?{empty:!1,elements:r}:{empty:!0,type:"trace",traceType:this.type}}hasMultiPoints(){return!0}toggleNavigation(){if(this.mode==="column"){const r=this.xPoints[this.col],l=r.y[Math.floor(r.y.length/2)];this.row=this.yValues.indexOf(l),this.mode="row"}else{const r=this.yPoints[this.row],l=r.x[Math.floor(r.x.length/2)];this.col=this.xValues.indexOf(l),this.mode="column"}}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(r){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(r){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(r){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(r){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(r){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(r){if(Array.isArray(r))return!1;if(this.mode==="column")switch(r){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(r){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(r){if(!r)return[null,null];const l=O1.selectAllElements(r);if(l.length===0)return[null,null];const o=new Map,a=new Map;l.forEach(T=>{const u=Number.parseFloat(T.getAttribute("x")||""),Q=Number.parseFloat(T.getAttribute("y")||"");Number.isNaN(u)||(o.has(u)||o.set(u,[]),o.get(u).push(T)),Number.isNaN(Q)||(a.has(Q)||a.set(Q,[]),a.get(Q).push(T))});const i=Array.from(o.entries()).sort(([T],[u])=>T-u).map(([T,u])=>u),s=Array.from(a.entries()).sort(([T],[u])=>u-T).map(([T,u])=>u);return[i,s]}}const UH="Sum",wj="Level",Vj="undefined";class Dj extends fv{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,r=new Array;for(let a=0;a<this.barValues[0].length;a++){const i=this.barValues.reduce((T,u)=>T+u[a],0);t.push(i);const s=this.orientation===r3.VERTICAL?{x:this.points[0][a].x,y:i,fill:UH}:{x:i,y:this.points[0][a].y,fill:UH};r.push(s)}this.points.push(r),this.barValues.push(t);const{min:l,max:o}=z3.minMax(t);this.min.push(l),this.max.push(o)}text(){return{...super.text(),fill:{label:wj,value:this.points[this.row][this.col].fill??Vj}}}highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?{empty:!0,type:"trace",traceType:this.type}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}hasMultiPoints(){return!0}mapToSvgElements(t){if(!t)return new Array;const r=O1.selectAllElements(t);if(r.length===0)return new Array;const l=new Array;if(r[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>=r.length)return new Array;this.barValues[o][s]===0?i.push(O1.createEmptyElement()):i.push(r[a++])}l.push(i)}else if(r[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>=r.length)return new Array;this.barValues[i][o]===0?l[i].push(O1.createEmptyElement()):l[i].push(r[a++])}}return l}}class GH extends $H{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],r=this.col,l=s=>t[Math.max(0,Math.min(s,t.length-1))],o=r>0?l(r-1):l(r),a=l(r),i=r<t.length-1?l(r+1):l(r);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:r,value:[o,a,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class Rj extends GH{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const r=[];let l=!0;for(let a=0;a<t.length;a++){const i=O1.selectElement(t[a],!1);if(!i){r.push([]);continue}const s=(o=this.points)==null?void 0:o[a],T=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&T.push(O1.createCircleElement(u.svg_x,u.svg_y,i));T.length>0&&(l=!1),r.push(T)}return l?null:r}}function kj(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function Nj(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&kj(e.data[0][0])?new Rj(e):new GH(e)}class Bj{static create(t){switch(t.type){case R2.BAR:return new mj(t);case R2.BOX:return new Ej(t);case R2.CANDLESTICK:return new Sj(t);case R2.HEATMAP:return new _j(t);case R2.HISTOGRAM:return new Aj(t);case R2.LINE:return new $H(t);case R2.SCATTER:return new Cj(t);case R2.SMOOTH:return Nj(t);case R2.DODGED:case R2.NORMALIZED:case R2.STACKED:return new Dj(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const Pj="MAIDR Plot",jj="unavailable",Ij="unavailable";class Fj extends Qv{constructor(r){super();ae(this,"id");ae(this,"title");ae(this,"subtitle");ae(this,"caption");ae(this,"subplots");ae(this,"size");this.id=r.id,this.title=r.title??Pj,this.subtitle=r.subtitle??jj,this.caption=r.caption??Ij;const l=r.subplots;this.subplots=l.map(o=>o.map(a=>new zj(a))),this.size=this.subplots.reduce((o,a)=>o+a.length,0)}dispose(){this.subplots.forEach(r=>r.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 r=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:r,subplot:l.getStateWithFigurePosition(this.row,this.col),traceTypes:l.traceTypes,highlight:this.highlight()}}highlight(){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=`g[id="axes_${this.row+1}"]`,a=document.querySelector(o);if(a)return{empty:!1,elements:a};const i=document.querySelectorAll('g[id^="axes_"]');if(i.length>0&&this.row<i.length)return{empty:!1,elements:i[this.row]}}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}}}}class zj extends Qv{constructor(r){super();ae(this,"traces");ae(this,"traceTypes");ae(this,"size");this.isInitialEntry=!1;const l=r.layers;this.size=l.length,this.traces=l.map(o=>[Bj.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?Le.EMPTY:a.traceType})}dispose(){this.traces.forEach(r=>r.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}}}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(r,l){return this.state}}const es=class es{constructor(){ae(this,"basePalette");ae(this,"extendedPalette");this.basePalette=[{waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{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}},{waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.15},{frequency:4,amplitude:.05}]},timbreModulation:{attack:.02,decay:.2,sustain:.6,release:.3}},{waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.2},{frequency:6,amplitude:.1}]},timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.1},{frequency:7,amplitude:.05}]},timbreModulation:{attack:.005,decay:.05,sustain:.5,release:.1}},{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}},{waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.1},{frequency:3,amplitude:.05}]},timbreModulation:{attack:.02,decay:.1,sustain:.9,release:.15}}],this.extendedPalette=new Map,this.generateExtendedPalette()}dispose(){this.extendedPalette.clear()}getPaletteEntry(t){if(t<this.basePalette.length)return this.basePalette[t];const r=this.extendedPalette.get(t);if(r)return r;const l=this.generateExtendedEntry(t);return this.extendedPalette.set(t,l),l}get basePaletteSize(){return this.basePalette.length}generateExtendedPalette(){[{waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.3},{frequency:3,amplitude:.15}]},timbreModulation:{attack:.02,decay:.15,sustain:.7,release:.3}},{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}},{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}},{waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:.5,amplitude:.2},{frequency:4,amplitude:.15}]},timbreModulation:{attack:.025,decay:.18,sustain:.8,release:.25}}].forEach((r,l)=>{this.extendedPalette.set(this.basePalette.length+l,r)})}generateExtendedEntry(t){const r=t%this.basePalette.length,l=this.basePalette[r],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,l.timbreModulation);return{waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const r=[],l=es.MIN_HARMONICS+t%es.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);r.push({frequency:a,amplitude:i})}return r}generateTimbreModulation(t,r){const l=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,r.attack*l)),decay:Math.max(.05,Math.min(.3,r.decay*l)),sustain:Math.max(.4,Math.min(.9,r.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,r.release*l))}}};ae(es,"MIN_HARMONICS",2),ae(es,"HARMONIC_VARIATION",3);let hv=es;const qj=100,$j=440,Uj=880,ZH=.3;class Gj{constructor(t,r,l){ae(this,"notification");ae(this,"audioPalette");ae(this,"settings");ae(this,"isCombinedAudio");ae(this,"mode");ae(this,"activeAudioIds");ae(this,"audioContext");ae(this,"compressor");ae(this,"currentVolume");ae(this,"currentMinFrequency");ae(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new hv,this.settings=l,this.isCombinedAudio=!1,this.mode="on",this.updateMode(r),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.updateMode(t),this.mode==="off"||t.type!=="trace")return;if(t.empty){this.playEmptyTone(t.audio.size,t.audio.index);return}const r=t.audio,l=r.groupIndex,a=l!==void 0?this.audioPalette.getPaletteEntry(l):void 0;if(r.isContinuous)this.playSmooth(r.value,r.min,r.max,r.size,Array.isArray(r.index)?r.index[0]:r.index,a);else if(Array.isArray(r.value)){const i=r.value;if(i.length===0){this.playZeroTone();return}let s=0;const T=this.mode==="on"?50:0,u=new Array,Q=()=>{if(s<i.length){const f=Array.isArray(r.index)?r.index[s]:r.index;this.playTone(r.min,r.max,i[s++],r.size,f,a),u.push(setTimeout(Q,T))}else this.stop(u)};Q()}else{const i=r.value;if(i===0)this.playZeroTone();else{const s=Array.isArray(r.index)?r.index[0]:r.index;this.playTone(r.min,r.max,i,r.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 r=this.audioContext.createGain();return r.gain.value=.5,t.connect(r),r.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const r=t.type==="subplot"?t.trace:t;r.empty||r.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=r.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}playTone(t,r,l,o,a,i){const s={min:t,max:r},T=this.getFrequencyRange(),u=this.interpolate(l,s,T),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,r){const l=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=r,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*r,l.push(i)}return l}createGainNodes(t,r,l,o){const a=[],i=this.audioContext.currentTime,s=this.getVolume();for(let T=0;T<t.length;T++){const u=this.audioContext.createGain();let Q=s;if(T===0)r.harmonicMix&&(Q*=r.harmonicMix.fundamental);else{const h=r.harmonicMix.harmonics[T-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,r,Q,i,o);f!==null&&u.gain.setValueCurveAtTime(f,i,o),a.push(u)}return a}playOscillator(t,r=0,l){const o=ZH,a=this.getVolume();l||(l={waveType:"sine"});const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,a,o),T=this.audioContext.createStereoPanner();T.pan.value=r;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(T);T.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),T.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(T),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,r,l,o,a){if(r!=null&&r.timbreModulation){const{attack:i,decay:s,sustain:T,release:u}=r.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(T*l,o+Q+f),p>0&&t.gain.setValueAtTime(T*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,r,l,o,a,i){const s=this.audioContext,T=s.currentTime,u=ZH,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(C=>this.interpolate(C,{min:r,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,T,u);const b=s.createGain(),L=this.createAdsrEnvelope(b,i,f,T,u);L!==null&&b.gain.setValueCurveAtTime(L,T,u);const M=s.createStereoPanner();M.pan.value=g,v.connect(b),b.connect(M),M.connect(this.compressor),v.start(T),v.stop(T+u);const A=setTimeout(()=>{v.disconnect(),b.disconnect(),M.disconnect(),this.activeAudioIds.delete(A)},u*1e3*2);this.activeAudioIds.set(A,[v])}playEmptyTone(t,r){const l=this.audioContext,o=l.currentTime,a=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],T=[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(r,Q,f),-1,1),p=[];for(let b=0;b<s.length;b++){const L=l.createOscillator(),M=l.createGain(),A=this.audioContext.createStereoPanner(),C=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});L.frequency.value=s[b],L.type="sine",M.gain.setValueAtTime(T[b]*i,o),M.gain.exponentialRampToValueAtTime(.001*i,o+a),A.pan.value=h,L.connect(M),M.connect(A),A.connect(C),C.connect(u),L.start(o),L.stop(o+a),p.push(L)}const g=b=>{u.disconnect(),p.forEach(L=>{L.disconnect()}),this.activeAudioIds.delete(b)},v=setTimeout(()=>g(v),a*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(qj,0,{waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator($j,0,{waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(Uj,0,{waveType:"sine"})}interpolate(t,r,l){return r.min===0&&r.max===0?0:(t-r.min)/(r.max-r.min)*(l.max-l.min)+l.min}clamp(t,r,l){return Math.max(r,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 r=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(r)}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,r])=>{clearTimeout(t),r.forEach(l=>{l.disconnect(),l.stop()})}),this.activeAudioIds.clear()}}const Zj=250,Xj=50,Wj=500,Yj=20;class Kj{constructor(t,r,l){ae(this,"context");ae(this,"notification");ae(this,"settings");ae(this,"autoplayId");ae(this,"currentDirection");ae(this,"userSpeed");ae(this,"defaultSpeed");ae(this,"minSpeed");ae(this,"maxSpeed");ae(this,"autoplayRate");ae(this,"interval");ae(this,"currentDuration");ae(this,"onChangeEmitter");ae(this,"onChange");this.notification=r,this.context=t,this.settings=l,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Zj,this.minSpeed=Xj,this.maxSpeed=Wj,this.autoplayRate=this.defaultSpeed,this.interval=Yj,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new f9,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,r){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,r),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,r){if(this.userSpeed!==null)return this.userSpeed;if(r&&!r.empty){const l=Math.ceil(this.currentDuration/r.autoplay[t]);return this.defaultSpeed=l,this.minSpeed=Math.min(this.minSpeed,l),l}return this.defaultSpeed}}const XH=32;class bc{encode(t){const r=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,T=s+i,u=T+i;for(let Q=0;Q<t.values[a].length;Q++)t.values[a][Q]===0?r.push(" "):t.values[a][Q]<=s||t.values[a][Q]<=T?r.push("⠤"):t.values[a][Q]<=u?r.push("⠒"):r.push("⠉"),l[a].push(o.length),o.push({row:a,col:Q});r.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class Jj{constructor(){ae(this,"GLOBAL_MIN","globalMin");ae(this,"GLOBAL_MAX","globalMax");ae(this,"BLANK","blank");ae(this,"LOWER_OUTLIER","lowerOutlier");ae(this,"UPPER_OUTLIER","upperOutlier");ae(this,"MIN","min");ae(this,"MAX","max");ae(this,"Q1","q1");ae(this,"Q2","q2");ae(this,"Q3","q3")}encode(t,r=XH){const l=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],T=[{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<T.length-1;V++){const k=T[V],B=T[V+1],R=Math.abs(Q?B.value-k.value:k.value-T[V-1].value);k.type===this.LOWER_OUTLIER||k.type===this.UPPER_OUTLIER?(u.push({type:k.type,length:0,numChars:1}),u.push({type:this.BLANK,length:R,numChars:0})):k.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):k.type===this.GLOBAL_MIN||k.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:R,numChars:0}):u.push({type:k.type,length:R,numChars:1})}let f=u.reduce((V,k)=>V+(k.numChars>0?k.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 b=Math.max(0,r-f),L=u.reduce((V,k)=>V+(k.type!==this.Q2&&k.length>0?k.length:0),0);for(const V of u)if(V.type!==this.Q2&&V.length>0){const k=Math.round(V.length/L*b);V.numChars+=k}const M=u.reduce((V,k)=>V+k.numChars,0);let A=r-M,C=0;for(;A!==0;){const V=u[C%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=A>0?1:-1,A+=A>0?-1:1),C++}let E=-1;const _=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];a.push(Array.from({length:_.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(E=_.indexOf(V.type),a[i][E]=l.length);for(let k=0;k<V.numChars;k++){let B="⠀";V.type===this.MIN||V.type===this.MAX?B="⠒":V.type===this.Q1||V.type===this.Q3?B="⠿":V.type===this.Q2?B=k===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?B="⠂":V.type===this.BLANK&&(B="⠀"),l.push(B),o.push({row:i,col:E})}}for(let V=0;V<3;V++)if(a[i][V]===-1){for(let k=V+1;k<=3;k++)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}for(let V=6;V>3;V--)if(a[i][V]===-1){for(let k=V-1;k>=3;k--)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}l.push(Le.NEW_LINE),o.push({row:i,col:E})}return{value:l.join(Le.EMPTY),cellToIndex:a,indexToCell:o}}}class eI{encode(t){const r=new Array,l=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,s=i+a;for(let T=0;T<t.values.length;T++){l.push(new Array);for(let u=0;u<t.values[T].length;u++)t.values[T][u]===0?r.push(" "):t.values[T][u]<=i?r.push("⠤"):t.values[T][u]<=s?r.push("⠒"):r.push("⠉"),l[T].push(o.length),o.push({row:T,col:u});r.push(Le.NEW_LINE),l[T].push(o.length),o.push({row:T,col:t.values[T].length})}return{value:r.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class WH{encode(t){const r=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:T,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,T,u);r.push(p),l[a].push(o.length),o.push({row:a,col:Q})}r.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}getBrailleChar(t,r,l,o,a,i){return t<=l&&r!==null&&r>l?r<=o?"⢄":r<=a?"⢆":"⢇":t<=l?"⣀":r!==null&&r<=l?t<=o?"⡠":t<=a?"⡰":"⡸":t<=o&&r!==null&&r>o?r<=a?"⠢":"⠣":t<=o?"⠤":r!==null&&r<=o?t<=a?"⠔":"⠜":t<=a&&r!==null&&r>a?"⠑":t<=a?"⠒":r!==null&&r<=a?"⠊":t<=i?"⠉":""}}class tI extends WH{getThresholds(t,r){const l=(r.max-r.min)/4,o=r.min+l,a=o+l,i=a+l,s=r.max;return{low:o,medium:a,mediumHigh:i,high:s}}}class nI extends WH{getThresholds(t,r){const l=(r.max[t]-r.min[t])/4,o=r.min[t]+l,a=o+l,i=a+l,s=r.max[t];return{low:o,medium:a,mediumHigh:i,high:s}}}class rI{constructor(t,r,l){ae(this,"context");ae(this,"notification");ae(this,"display");ae(this,"enabled");ae(this,"cacheId");ae(this,"cache");ae(this,"encoders");ae(this,"onChangeEmitter");ae(this,"onChange");this.context=t,this.notification=r,this.display=l,this.enabled=!1,this.cacheId=Le.EMPTY,this.cache=null,this.encoders=new Map([[R2.BAR,new bc],[R2.BOX,new Jj],[R2.CANDLESTICK,new tI],[R2.DODGED,new bc],[R2.HEATMAP,new eI],[R2.HISTOGRAM,new bc],[R2.LINE,new nI],[R2.NORMALIZED,new bc],[R2.STACKED,new bc]]),this.onChangeEmitter=new f9,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const r=t.type==="subplot"?t.trace:t;if(r.empty||r.braille.empty||!this.encoders.has(r.traceType))return;const l=r.braille;if(this.cacheId!==l.id||this.cache===null){const o=this.encoders.get(r.traceType);this.cache=o.encode(l,XH),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:r,col:l}=this.cache.indexToCell[t];this.context.moveToIndex(r,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(b1.BRAILLE);const r=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(r)}}var YH=(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))(YH||{});class KH{constructor(){}static async post(t,r,l){const o={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",o,r)}static async request(t,r,l,o){try{const a=await fetch(t,{method:r,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 ${r} request to ${t}:`,a),{success:!1,error:{statusCode:YH.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}ae(KH,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const iI=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
2
+ `),ae(Le,"OPEN_BRACKET","["),ae(Le,"POLYLINE","polyline"),ae(Le,"SPACE"," "),ae(Le,"THROUGH"," through "),ae(Le,"TRANSPARENT","transparent"),ae(Le,"VISIBLE","visible"),ae(Le,"X","x"),ae(Le,"Y","y"),ae(Le,"HIGHLIGHT_BASE_COLOR",{r:255,g:255,b:255}),ae(Le,"HIGHLIGHT_CONTRAST_RATIO",3),ae(Le,"HIGHLIGHT_COLOR_RATIO",.6),ae(Le,"HIGHLIGHT_MAX_COLOR",255);let lv=class{constructor(){ae(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,r=1){const l=this.items.lastIndexOf(t);return l!==-1?(this.items.splice(l,r),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}};const sv=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function uv(e,t,r,l){e.addEventListener?e.addEventListener(t,r,l):e.attachEvent&&e.attachEvent("on".concat(t),r)}function mc(e,t,r,l){e.removeEventListener?e.removeEventListener(t,r,l):e.detachEvent&&e.detachEvent("on".concat(t),r)}function BH(e,t){const r=t.slice(0,t.length-1);for(let l=0;l<r.length;l++)r[l]=e[r[l].toLowerCase()];return r}function PH(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let r=t.lastIndexOf("");for(;r>=0;)t[r-1]+=",",t.splice(r,1),r=t.lastIndexOf("");return t}function tj(e,t){const r=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let o=!0;for(let a=0;a<r.length;a++)l.indexOf(r[a])===-1&&(o=!1);return o}const yc={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,"-":sv?173:189,"=":sv?61:187,";":sv?59:186,"'":222,"[":219,"]":221,"\\":220},o5={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},gc={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},M3={16:!1,18:!1,17:!1,91:!1},L2={};for(let e=1;e<20;e++)yc["f".concat(e)]=111+e;let d2=[],vc=null,jH="all";const S0=new Map,Lc=e=>yc[e.toLowerCase()]||o5[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),nj=e=>Object.keys(yc).find(t=>yc[t]===e),rj=e=>Object.keys(o5).find(t=>o5[t]===e);function IH(e){jH=e||"all"}function xc(){return jH||"all"}function ij(){return d2.slice(0)}function aj(){return d2.map(e=>nj(e)||rj(e)||String.fromCharCode(e))}function oj(){const e=[];return Object.keys(L2).forEach(t=>{L2[t].forEach(r=>{let{key:l,scope:o,mods:a,shortcut:i}=r;e.push({scope:o,shortcut:i,mods:a,keys:l.split("+").map(s=>Lc(s))})})}),e}function lj(e){const t=e.target||e.srcElement,{tagName:r}=t;let l=!0;const o=r==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||r==="TEXTAREA"||r==="SELECT")&&!t.readOnly)&&(l=!1),l}function sj(e){return typeof e=="string"&&(e=Lc(e)),d2.indexOf(e)!==-1}function uj(e,t){let r,l;e||(e=xc());for(const o in L2)if(Object.prototype.hasOwnProperty.call(L2,o))for(r=L2[o],l=0;l<r.length;)r[l].scope===e?r.splice(l,1).forEach(i=>{let{element:s}=i;return cv(s)}):l++;xc()===e&&IH(t||"all")}function cj(e){let t=e.keyCode||e.which||e.charCode;const r=d2.indexOf(t);if(r>=0&&d2.splice(r,1),e.key&&e.key.toLowerCase()==="meta"&&d2.splice(0,d2.length),(t===93||t===224)&&(t=91),t in M3){M3[t]=!1;for(const l in o5)o5[l]===t&&(F3[l]=!1)}}function FH(e){if(typeof e>"u")Object.keys(L2).forEach(o=>{Array.isArray(L2[o])&&L2[o].forEach(a=>mp(a)),delete L2[o]}),cv(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&mp(o)});else if(typeof e=="object")e.key&&mp(e);else if(typeof e=="string"){for(var t=arguments.length,r=new Array(t>1?t-1:0),l=1;l<t;l++)r[l-1]=arguments[l];let[o,a]=r;typeof o=="function"&&(a=o,o=""),mp({key:e,scope:o,method:a,splitKey:"+"})}}const mp=e=>{let{key:t,scope:r,method:l,splitKey:o="+"}=e;PH(t).forEach(i=>{const s=i.split(o),T=s.length,u=s[T-1],Q=u==="*"?"*":Lc(u);if(!L2[Q])return;r||(r=xc());const f=T>1?BH(o5,s):[],h=[];L2[Q]=L2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===r&&tj(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>cv(p))})};function zH(e,t,r,l){if(t.element!==l)return;let o;if(t.scope===r||t.scope==="all"){o=t.mods.length>0;for(const a in M3)Object.prototype.hasOwnProperty.call(M3,a)&&(!M3[a]&&t.mods.indexOf(+a)>-1||M3[a]&&t.mods.indexOf(+a)===-1)&&(o=!1);(t.mods.length===0&&!M3[16]&&!M3[18]&&!M3[17]&&!M3[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(d2),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function qH(e,t){const r=L2["*"];let l=e.keyCode||e.which||e.charCode;if(!F3.filter.call(this,e))return;if((l===93||l===224)&&(l=91),d2.indexOf(l)===-1&&l!==229&&d2.push(l),["metaKey","ctrlKey","altKey","shiftKey"].forEach(s=>{const T=gc[s];e[s]&&d2.indexOf(T)===-1?d2.push(T):!e[s]&&d2.indexOf(T)>-1?d2.splice(d2.indexOf(T),1):s==="metaKey"&&e[s]&&(d2=d2.filter(u=>u in gc||u===l))}),l in M3){M3[l]=!0;for(const s in o5)if(Object.prototype.hasOwnProperty.call(o5,s)){const T=gc[o5[s]];F3[s]=e[T]}if(!r)return}for(const s in M3)Object.prototype.hasOwnProperty.call(M3,s)&&(M3[s]=e[gc[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(d2.indexOf(17)===-1&&d2.push(17),d2.indexOf(18)===-1&&d2.push(18),M3[17]=!0,M3[18]=!0);const o=xc();if(r)for(let s=0;s<r.length;s++)r[s].scope===o&&(e.type==="keydown"&&r[s].keydown||e.type==="keyup"&&r[s].keyup)&&zH(e,r[s],o,t);if(!(l in L2))return;const a=L2[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 T=a[s],{splitKey:u}=T,Q=T.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(Lc(Q[h]));f.sort().join("")===d2.sort().join("")&&zH(e,T,o,t)}}function F3(e,t,r){d2=[];const l=PH(e);let o=[],a="all",i=document,s=0,T=!1,u=!0,Q="+",f=!1,h=!1;for(r===void 0&&typeof t=="function"&&(r=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(a=t.scope),t.element&&(i=t.element),t.keyup&&(T=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&&FH(e,a);s<l.length;s++)e=l[s].split(Q),o=[],e.length>1&&(o=BH(o5,e)),e=e[e.length-1],e=e==="*"?"*":Lc(e),e in L2||(L2[e]=[]),L2[e].push({keyup:T,keydown:u,scope:a,mods:o,shortcut:l[s],method:r,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!S0.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return qH(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;qH(v,i),cj(v)};S0.set(i,{keydownListener:p,keyupListenr:g,capture:f}),uv(i,"keydown",p,f),uv(i,"keyup",g,f)}if(!vc){const p=()=>{d2=[]};vc={listener:p,capture:f},uv(window,"focus",p,f)}}}function Tj(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(L2).forEach(r=>{L2[r].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function cv(e){const t=Object.values(L2).flat();if(t.findIndex(l=>{let{element:o}=l;return o===e})<0){const{keydownListener:l,keyupListenr:o,capture:a}=S0.get(e)||{};l&&o&&(mc(e,"keyup",o,a),mc(e,"keydown",l,a),S0.delete(e))}if((t.length<=0||S0.size<=0)&&(Object.keys(S0).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:s}=S0.get(o)||{};a&&i&&(mc(o,"keyup",i,s),mc(o,"keydown",a,s),S0.delete(o))}),S0.clear(),Object.keys(L2).forEach(o=>delete L2[o]),vc)){const{listener:o,capture:a}=vc;mc(window,"focus",o,a),vc=null}}const Tv={getPressedKeyString:aj,setScope:IH,getScope:xc,deleteScope:uj,getPressedKeyCodes:ij,getAllKeyCodes:oj,isPressed:sj,filter:lj,trigger:Tj,unbind:FH,keyMap:yc,modifier:o5,modifierMap:gc};for(const e in Tv)Object.prototype.hasOwnProperty.call(Tv,e)&&(F3[e]=Tv[e]);if(typeof window<"u"){const e=window.hotkeys;F3.noConflict=t=>(t&&window.hotkeys===F3&&(window.hotkeys=e),F3),window.hotkeys=F3}class Qj{constructor(t){ae(this,"id");ae(this,"instructionContext");ae(this,"plotContext");ae(this,"scopeContext");this.id=t.id,this.plotContext=new lv,this.scopeContext=new lv;const r=t.state;if(r.empty||r.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(b1.SUBPLOT);return}this.scopeContext.push(b1.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),F3.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,r){this.active.moveToIndex(t,r)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const r=this.active;r.moveOnce(t),this.active.notifyStateUpdate(),this.plotContext.push(r.activeTrace)}}enterSubplot(){if(this.active.state.type==="figure"){const r=this.active;this.plotContext.push(r.activeSubplot),this.active.notifyStateUpdate(),this.plotContext.push(r.activeSubplot.activeTrace),this.toggleScope(b1.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(b1.TRACE))}getInstruction(t){const r=this.instructionContext.state;if(r.empty)return`No ${r.type} info available`;const l=t?"Click to activate.":Le.EMPTY;switch(r.type){case"figure":return`This is a MAIDR figure containing ${r.size} subplots. ${l} Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a MAIDR subplot containing ${r.size} layers, and this is layer 1 of ${r.size}: ${r.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: ${r.traceType}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}const fj="unavailable",dj="X",hj="Y",pj="unavailable";class Qv{constructor(){ae(this,"observers");ae(this,"isInitialEntry");ae(this,"isOutOfBounds");ae(this,"row");ae(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()}moveToExtreme(t){switch(this.isInitialEntry&&this.handleInitialEntry(),t){case"UPWARD":this.row=this.values.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.col=this.values[this.row].length-1;break;case"BACKWARD":this.col=0;break}this.notifyStateUpdate()}moveToIndex(t,r){this.isMovable([t,r])&&(this.row=t,this.col=r,this.isInitialEntry=!1,this.notifyStateUpdate())}isMovable(t){if(Array.isArray(t)){const[r,l]=t;return r>=0&&r<this.values.length&&l>=0&&l<this.values[this.row].length}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.values.length-1)),this.col=Math.max(0,Math.min(this.col,this.values[this.row].length-1))}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(r=>r!==t)}notifyStateUpdate(){const t=this.state;for(const r of this.observers)r.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}}class d9 extends Qv{constructor(r){var l,o,a;super();ae(this,"id");ae(this,"type");ae(this,"title");ae(this,"xAxis");ae(this,"yAxis");ae(this,"fill");this.id=r.id,this.type=r.type,this.title=r.title??fj,this.xAxis=((l=r.axes)==null?void 0:l.x)??dj,this.yAxis=((o=r.axes)==null?void 0:o.y)??hj,this.fill=((a=r.axes)==null?void 0:a.fill)??pj}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(r=>r.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(a=>a.remove())})),this.highlightValues.length=0),super.dispose()}get state(){return this.isOutOfBounds?{empty:!0,type:"trace",traceType:this.type,audio:{size:this.values[this.row].length,index:this.col}}:{empty:!1,type:"trace",traceType: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(){return this.highlightValues===null||this.isInitialEntry?{empty:!0,type:"trace",traceType:this.type,audio:{size:this.values[this.row].length,index:this.col}}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:this.values[this.row].length,BACKWARD:this.values[this.row].length}}hasMultiPoints(){return!1}}var r3=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(r3||{}),R2=(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))(R2||{});class z3{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 r=t.flat();return this.safeMin(r)}static maxFrom2D(t){const r=t.flat();return this.safeMax(r)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let r=t[0],l=t[0];for(let o=1;o<t.length;o++){const a=t[o];a<r&&(r=a),a>l&&(l=a)}return{min:r,max:l}}static minMaxFrom2D(t){const r=t.flat();return this.minMax(r)}}class yp{constructor(){}static parse(t){const r=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(r)){let o=r.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=r.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,r){const l=this.calculateLuminance(t),o=this.calculateLuminance(r);return(Math.max(l,o)+.05)/(Math.min(l,o)+.05)}static calculateLuminance(t){const[r,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*r+.7152*l+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class O1{constructor(){}static async toBase64(t){try{const r=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r).replace(/'/g,"%27").replace(/"/g,"%22")}`,a=await new Promise((T,u)=>{const Q=new Image;Q.onload=()=>T(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(r){return console.error("Error converting SVG to Base 64:",r instanceof Error?r.message:r),""}}static selectAllElements(t,r=!0){return Array.from(document.querySelectorAll(t)).map(l=>{if(!r)return l;const o=l.cloneNode(!0);return o.setAttribute(Le.VISIBILITY,Le.HIDDEN),l.insertAdjacentElement(Le.AFTER_END,o),o})}static selectElement(t,r=!0){const l=document.querySelector(t);if(!r)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 r=document.createElementNS(this.SVG_NAMESPACE,t);return r.setAttribute(Le.FILL,Le.TRANSPARENT),r.setAttribute(Le.STROKE,Le.TRANSPARENT),r.setAttribute(Le.VISIBILITY,Le.HIDDEN),r}static createCircleElement(t,r,l){var u;const o=window.getComputedStyle(l),a=o.stroke||o.fill,i=o.strokeWidth||"2",s=Number.parseFloat(i)*2,T=document.createElementNS(this.SVG_NAMESPACE,Le.CIRCLE);return T.setAttribute(Le.CIRCLE_X,String(t)),T.setAttribute(Le.CIRCLE_Y,String(r)),T.setAttribute(Le.RADIUS,String(s)),T.setAttribute(Le.FILL,a),T.setAttribute(Le.STROKE,a),T.setAttribute(Le.STROKE_WIDTH,i),T.setAttribute(Le.VISIBILITY,Le.HIDDEN),(u=l.parentElement)==null||u.insertAdjacentElement(Le.AFTER_END,T),T}static createLineElement(t,r){const o=t.getBBox();let a,i,s,T;switch(r){case"top":[a,i,s,T]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,s,T]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,s,T]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,s,T]=[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(T)),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,r){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,r);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 T=window.getComputedStyle(l).getPropertyValue(Le.STROKE_WIDTH);l.setAttribute(Le.STROKE_WIDTH,`${T+2}`)}return t.insertAdjacentElement(Le.AFTER_END,l),l}static getHighlightColor(t,r){const l=yp.parse(t);if(!l||!(yp.getContrastRatio(l,Le.HIGHLIGHT_BASE_COLOR)<Le.HIGHLIGHT_CONTRAST_RATIO))return r;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)),yp.rgbToString(i)}static getContrastingColorForElement(t){const r=window.getComputedStyle(t).fill||"rgb(255,255,255)",l=yp.parse(r);return l?(.2126*l.r+.7152*l.g+.0722*l.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,r){t.style.outline=`4px solid ${r}`,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,r,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=r);const i=this.getHighlightColor(a,r);o.setAttribute("stroke",i),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const r=t.querySelector("rect, path");r&&(r.removeAttribute("stroke"),r.removeAttribute("stroke-width"))}}ae(O1,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class fv extends d9{constructor(r,l){super(r);ae(this,"points");ae(this,"barValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"min");ae(this,"max");this.points=l,this.orientation=r.orientation??r3.VERTICAL,this.barValues=l.map(o=>o.map(a=>this.orientation===r3.VERTICAL?Number(a.y):Number(a.x))),this.min=this.barValues.map(o=>z3.safeMin(o)),this.max=this.barValues.map(o=>z3.safeMax(o)),this.highlightValues=this.mapToSvgElements(r.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const r=this.orientation===r3.VERTICAL,l=r?this.barValues[this.row].length:this.barValues.length,o=r?this.col:this.row,a=r?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:z3.safeMin(this.min),max:z3.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 r=this.orientation===r3.VERTICAL,l=this.points[this.row][this.col],o=r?this.xAxis:this.yAxis,a=r?l.x:l.y,i=r?this.yAxis:this.xAxis,s=r?l.y:l.x;return{main:{label:o,value:a},cross:{label:i,value:s}}}mapToSvgElements(r){if(!r)return null;const l=[O1.selectAllElements(r)];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 mj extends fv{constructor(t){super(t,[t.data])}}const yj="Lower outlier(s)",gj="Upper outlier(s)",vj="Minimum",Lj="Maximum",xj="25%",bj="50%",Hj="75%";class Ej extends d9{constructor(r){super(r);ae(this,"points");ae(this,"boxValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"sections");ae(this,"min");ae(this,"max");this.points=r.data,this.orientation=r.orientation??r3.VERTICAL,this.sections=[yj,vj,xj,bj,Hj,Lj,gj];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===r3.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=z3.minFrom2D(o),this.max=z3.maxFrom2D(o),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(r.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(r,l){const o=this.orientation===r3.HORIZONTAL;r=o?r:l,l=o?l:r,super.moveToIndex(r,l)}get values(){return this.boxValues}audio(){const r=this.boxValues[this.row][this.col],l=Array.isArray(r)?r.map(o=>o-this.min):r-this.min;return{min:this.min,max:this.max,value:r,size:this.max-this.min,index:l}}braille(){const r=this.orientation===r3.HORIZONTAL,l=r?this.row:this.col,o=r?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 r=this.orientation===r3.HORIZONTAL,l=r?this.points[this.row]:this.points[this.col],o=r?this.yAxis:this.xAxis,a=r?this.sections[this.col]:this.sections[this.row],i=r?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(r){if(!r||r.length!==this.points.length)return null;const l=this.orientation===r3.VERTICAL,o=new Array;if(l)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:r.length}));return r.forEach((a,i)=>{const s=a.lowerOutliers.flatMap(b=>O1.selectAllElements(b)),T=a.upperOutliers.flatMap(b=>O1.selectAllElements(b)),u=O1.selectElement(a.min)??O1.createEmptyElement(),Q=O1.selectElement(a.max)??O1.createEmptyElement(),f=O1.selectElement(a.iq)??O1.createEmptyElement(),h=O1.selectElement(a.q2)??O1.createEmptyElement(),[p,g]=l?[O1.createLineElement(f,"top"),O1.createLineElement(f,"bottom")]:[O1.createLineElement(f,"left"),O1.createLineElement(f,"right")],v=[s,u,p,h,g,Q,T];l?v.forEach((b,L)=>{o[L][i]=b}):o.push(v)}),o}}const Mj="Trend";class Sj extends d9{constructor(r){super(r);ae(this,"candles");ae(this,"candleValues");ae(this,"orientation");ae(this,"sections",["open","high","low","close"]);ae(this,"currentSegmentType","open");ae(this,"currentPointIndex",0);ae(this,"sortedSegmentsByPoint");ae(this,"segmentPositionMaps");ae(this,"min");ae(this,"max");ae(this,"highlightValues");const l=r.data;this.candles=l.map(a=>({...a,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=r.orientation??r3.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(i=>i[a])),this.min=z3.minFrom2D(this.candleValues),this.max=z3.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="open",this.orientation===r3.HORIZONTAL?this.col=0:this.row=0;const o=typeof r.selectors=="string"?r.selectors:"";this.highlightValues=this.mapToSvgElements(o)}precomputeSortedSegments(){return this.candles.map(r=>this.sections.map(o=>[o,r[o]]).sort((o,a)=>o[1]-a[1]).map(o=>o[0]))}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(r=>{const l=new Map;return r.forEach((o,a)=>{l.set(o,a)}),l})}getSegmentPositionInSortedOrder(r,l){return this.segmentPositionMaps[r].get(l)??0}getSegmentTypeAtSortedPosition(r,l){return this.sortedSegmentsByPoint[r][l]??"open"}updateVisualSegmentPosition(){const r=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType);this.orientation===r3.HORIZONTAL?this.col=r:this.row=r}updateVisualPointPosition(){this.orientation===r3.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}switch(r){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?l+1:l-1;if(o>=0&&o<this.sections.length)this.currentSegmentType=this.getSegmentTypeAtSortedPosition(this.currentPointIndex,o),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const l=r==="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(r){switch(this.isInitialEntry&&this.handleInitialEntry(),r){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()}isMovable(r){if(Array.isArray(r))return super.isMovable(r);if(this.isInitialEntry)return!0;switch(r){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?l+1:l-1;return o>=0&&o<this.sections.length}case"FORWARD":case"BACKWARD":{const l=r==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return l>=0&&l<this.candles.length}}}dispose(){this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){const r=this.candles[this.currentPointIndex][this.currentSegmentType],l=this.candles[this.currentPointIndex].trend==="Bull"?0:9;return{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:r,groupIndex:l}}braille(){return{empty:!1,id:this.id,values:this.candleValues,min:this.min,max:this.max,row:this.row,col:this.col}}mapToSvgElements(r){if(!r)return null;const l=O1.selectAllElements(r),o=[];for(let a=0;a<this.sections.length;a++){o[a]=[];for(let i=0;i<this.candles.length;i++){const s=i<l.length?i:0;o[a][i]=l[s]}}return o}text(){const r=this.candles[this.currentPointIndex],l=r[this.currentSegmentType];return{main:{label:this.orientation===r3.HORIZONTAL?this.yAxis:this.xAxis,value:r.value},cross:{label:this.orientation===r3.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType,fill:{label:Mj,value:r.trend}}}}class _j extends d9{constructor(r){super(r);ae(this,"heatmapValues");ae(this,"highlightValues");ae(this,"x");ae(this,"y");ae(this,"min");ae(this,"max");const l=r.data;this.x=l.x,this.y=l.y,this.heatmapValues=l.points;const{min:o,max:a}=z3.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=a,this.highlightValues=this.mapToSvgElements(r.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(r){if(!r)return null;const l=this.heatmapValues.length,o=this.heatmapValues[0].length,a=O1.selectAllElements(r);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 T=l-1-s,u=new Array;for(let Q=0;Q<o;Q++){const f=T*o+Q;u.push(a[f])}i.push(u)}else if(a[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const T=new Array;for(let u=0;u<o;u++){const Q=u*l+s;T.push(a[Q])}i.push(T)}return i}}class Aj extends fv{constructor(t){super(t,[t.data])}text(){const t=this.orientation===r3.VERTICAL,r=this.points[this.row][this.col],l=t?r.xMin:r.yMin,o=t?r.xMax:r.yMax;return{...super.text(),range:{min:l,max:o}}}}const Oj="Type",dv=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class $H extends d9{constructor(r){super(r);ae(this,"points");ae(this,"lineValues");ae(this,"highlightValues");ae(this,"min");ae(this,"max");this.points=r.data,this.lineValues=this.points.map(l=>l.map(o=>Number(o.y))),this.min=this.lineValues.map(l=>z3.safeMin(l)),this.max=this.lineValues.map(l=>z3.safeMax(l)),this.highlightValues=this.mapToSvgElements(r.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(){const r=this.points[this.row][this.col],l=r.fill?{fill:{label:Oj,value:r.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},...l}}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}if(r==="UPWARD"||r==="DOWNWARD"){const l=this.findNearestLineByYValue(r);if(l!==null&&l!==this.row){this.row=l,this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}switch(r){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}isMovable(r){if(Array.isArray(r)){const[l,o]=r;return l>=0&&l<this.values.length&&o>=0&&o<this.values[this.row].length}switch(r){case"UPWARD":case"DOWNWARD":return this.findNearestLineByYValue(r)!==null;case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findNearestLineByYValue(r){const l=this.col,o=this.values[this.row][l];let a=null,i=Number.POSITIVE_INFINITY;for(let s=0;s<this.values.length;s++){if(s===this.row||l>=this.values[s].length)continue;const T=this.values[s][l];if(!(r==="UPWARD"?T>o:T<o))continue;const Q=Math.abs(T-o);Q<i&&(i=Q,a=s)}return a}mapToSvgElements(r){if(!r||r.length!==this.lineValues.length)return null;const l=[];let o=!0;for(let a=0;a<r.length;a++){const i=O1.selectElement(r[a],!1);if(!i){l.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(Le.D)||Le.EMPTY;dv.lastIndex=0;let f=dv.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=dv.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 T=[];let u=!1;for(const Q of s){if(Number.isNaN(Q.x)||Number.isNaN(Q.y)){u=!0;break}T.push(O1.createCircleElement(Q.x,Q.y,i))}if(u){l.push([]);continue}T.length>0&&(o=!1),l.push(T)}return o?null:l}}class Cj extends d9{constructor(r){super(r);ae(this,"mode");ae(this,"xPoints");ae(this,"yPoints");ae(this,"xValues");ae(this,"yValues");ae(this,"highlightXValues");ae(this,"highlightYValues");ae(this,"minX");ae(this,"maxX");ae(this,"minY");ae(this,"maxY");this.mode="column";const l=r.data,o=[...l].sort((T,u)=>T.x-u.x||T.y-u.y);this.xPoints=new Array;let a=null;for(const T of o)(!a||a.x!==T.x)&&(a={x:T.x,y:[]},this.xPoints.push(a)),a.y.push(T.y);const i=[...l].sort((T,u)=>T.y-u.y||T.x-u.x);this.yPoints=new Array;let s=null;for(const T of i)(!s||s.y!==T.y)&&(s={y:T.y,x:[]},this.yPoints.push(s)),s.x.push(T.x);this.xValues=this.xPoints.map(T=>T.x),this.yValues=this.yPoints.map(T=>T.y),this.minX=z3.safeMin(this.xValues),this.maxX=z3.safeMax(this.xValues),this.minY=z3.safeMin(this.yValues),this.maxY=z3.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(r.selectors)}dispose(){this.xPoints.length=0,this.yPoints.length=0,this.xValues.length=0,this.yValues.length=0,this.highlightXValues&&(this.highlightXValues.forEach(r=>r.forEach(l=>l.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(r=>r.forEach(l=>l.remove())),this.highlightYValues.length=0),super.dispose()}get values(){return this.mode==="column"?[this.xValues]:[this.yValues]}get highlightValues(){return this.mode==="column"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}audio(){if(this.mode==="column"){const r=this.xPoints[this.col];return{min:this.minY,max:this.maxY,size:r.y.length,index:this.col,value:r.y,...this.getAudioGroupIndex()}}else{const r=this.yPoints[this.row];return{min:this.minX,max:this.maxX,size:r.x.length,index:this.row,value:r.x,...this.getAudioGroupIndex()}}}braille(){return{empty:!0,type:"trace",traceType:this.type}}text(){if(this.mode==="column"){const r=this.xPoints[this.col];return{main:{label:this.xAxis,value:r.x},cross:{label:this.yAxis,value:r.y}}}else{const r=this.yPoints[this.row];return{main:{label:this.yAxis,value:r.y},cross:{label:this.xAxis,value:r.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};const r=this.mode==="column"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return r?{empty:!1,elements:r}:{empty:!0,type:"trace",traceType:this.type}}hasMultiPoints(){return!0}toggleNavigation(){if(this.mode==="column"){const r=this.xPoints[this.col],l=r.y[Math.floor(r.y.length/2)];this.row=this.yValues.indexOf(l),this.mode="row"}else{const r=this.yPoints[this.row],l=r.x[Math.floor(r.x.length/2)];this.col=this.xValues.indexOf(l),this.mode="column"}}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(r){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(r){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(r){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(r){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(r){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(r){if(Array.isArray(r))return!1;if(this.mode==="column")switch(r){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(r){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(r){if(!r)return[null,null];const l=O1.selectAllElements(r);if(l.length===0)return[null,null];const o=new Map,a=new Map;l.forEach(T=>{const u=Number.parseFloat(T.getAttribute("x")||""),Q=Number.parseFloat(T.getAttribute("y")||"");Number.isNaN(u)||(o.has(u)||o.set(u,[]),o.get(u).push(T)),Number.isNaN(Q)||(a.has(Q)||a.set(Q,[]),a.get(Q).push(T))});const i=Array.from(o.entries()).sort(([T],[u])=>T-u).map(([T,u])=>u),s=Array.from(a.entries()).sort(([T],[u])=>u-T).map(([T,u])=>u);return[i,s]}}const UH="Sum",wj="Level",Vj="undefined";class Dj extends fv{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,r=new Array;for(let a=0;a<this.barValues[0].length;a++){const i=this.barValues.reduce((T,u)=>T+u[a],0);t.push(i);const s=this.orientation===r3.VERTICAL?{x:this.points[0][a].x,y:i,fill:UH}:{x:i,y:this.points[0][a].y,fill:UH};r.push(s)}this.points.push(r),this.barValues.push(t);const{min:l,max:o}=z3.minMax(t);this.min.push(l),this.max.push(o)}text(){return{...super.text(),fill:{label:wj,value:this.points[this.row][this.col].fill??Vj}}}highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?{empty:!0,type:"trace",traceType:this.type}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}hasMultiPoints(){return!0}mapToSvgElements(t){if(!t)return new Array;const r=O1.selectAllElements(t);if(r.length===0)return new Array;const l=new Array;if(r[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>=r.length)return new Array;this.barValues[o][s]===0?i.push(O1.createEmptyElement()):i.push(r[a++])}l.push(i)}else if(r[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>=r.length)return new Array;this.barValues[i][o]===0?l[i].push(O1.createEmptyElement()):l[i].push(r[a++])}}return l}}class GH extends $H{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],r=this.col,l=s=>t[Math.max(0,Math.min(s,t.length-1))],o=r>0?l(r-1):l(r),a=l(r),i=r<t.length-1?l(r+1):l(r);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:r,value:[o,a,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class Rj extends GH{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const r=[];let l=!0;for(let a=0;a<t.length;a++){const i=O1.selectElement(t[a],!1);if(!i){r.push([]);continue}const s=(o=this.points)==null?void 0:o[a],T=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&T.push(O1.createCircleElement(u.svg_x,u.svg_y,i));T.length>0&&(l=!1),r.push(T)}return l?null:r}}function kj(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function Nj(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&kj(e.data[0][0])?new Rj(e):new GH(e)}class Bj{static create(t){switch(t.type){case R2.BAR:return new mj(t);case R2.BOX:return new Ej(t);case R2.CANDLESTICK:return new Sj(t);case R2.HEATMAP:return new _j(t);case R2.HISTOGRAM:return new Aj(t);case R2.LINE:return new $H(t);case R2.SCATTER:return new Cj(t);case R2.SMOOTH:return Nj(t);case R2.DODGED:case R2.NORMALIZED:case R2.STACKED:return new Dj(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const Pj="MAIDR Plot",jj="unavailable",Ij="unavailable";class Fj extends Qv{constructor(r){super();ae(this,"id");ae(this,"title");ae(this,"subtitle");ae(this,"caption");ae(this,"subplots");ae(this,"size");this.id=r.id,this.title=r.title??Pj,this.subtitle=r.subtitle??jj,this.caption=r.caption??Ij;const l=r.subplots;this.subplots=l.map(o=>o.map(a=>new zj(a))),this.size=this.subplots.reduce((o,a)=>o+a.length,0)}dispose(){this.subplots.forEach(r=>r.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 r=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:r,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 T=document.querySelectorAll('g[id^="axes_"]');if(T.length>0&&a-1<T.length)return{empty:!1,elements:T[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}}}}class zj extends Qv{constructor(r){super();ae(this,"traces");ae(this,"traceTypes");ae(this,"size");this.isInitialEntry=!1;const l=r.layers;this.size=l.length,this.traces=l.map(o=>[Bj.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?Le.EMPTY:a.traceType})}dispose(){this.traces.forEach(r=>r.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}}}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(r,l){return this.state}}const es=class es{constructor(){ae(this,"basePalette");ae(this,"extendedPalette");this.basePalette=[{waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{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}},{waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.15},{frequency:4,amplitude:.05}]},timbreModulation:{attack:.02,decay:.2,sustain:.6,release:.3}},{waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.2},{frequency:6,amplitude:.1}]},timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.1},{frequency:7,amplitude:.05}]},timbreModulation:{attack:.005,decay:.05,sustain:.5,release:.1}},{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}},{waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.1},{frequency:3,amplitude:.05}]},timbreModulation:{attack:.02,decay:.1,sustain:.9,release:.15}}],this.extendedPalette=new Map,this.generateExtendedPalette()}dispose(){this.extendedPalette.clear()}getPaletteEntry(t){if(t<this.basePalette.length)return this.basePalette[t];const r=this.extendedPalette.get(t);if(r)return r;const l=this.generateExtendedEntry(t);return this.extendedPalette.set(t,l),l}get basePaletteSize(){return this.basePalette.length}generateExtendedPalette(){[{waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.3},{frequency:3,amplitude:.15}]},timbreModulation:{attack:.02,decay:.15,sustain:.7,release:.3}},{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}},{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}},{waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:.5,amplitude:.2},{frequency:4,amplitude:.15}]},timbreModulation:{attack:.025,decay:.18,sustain:.8,release:.25}}].forEach((r,l)=>{this.extendedPalette.set(this.basePalette.length+l,r)})}generateExtendedEntry(t){const r=t%this.basePalette.length,l=this.basePalette[r],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,l.timbreModulation);return{waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const r=[],l=es.MIN_HARMONICS+t%es.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);r.push({frequency:a,amplitude:i})}return r}generateTimbreModulation(t,r){const l=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,r.attack*l)),decay:Math.max(.05,Math.min(.3,r.decay*l)),sustain:Math.max(.4,Math.min(.9,r.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,r.release*l))}}};ae(es,"MIN_HARMONICS",2),ae(es,"HARMONIC_VARIATION",3);let hv=es;const qj=100,$j=440,Uj=880,ZH=.3;class Gj{constructor(t,r,l){ae(this,"notification");ae(this,"audioPalette");ae(this,"settings");ae(this,"isCombinedAudio");ae(this,"mode");ae(this,"activeAudioIds");ae(this,"audioContext");ae(this,"compressor");ae(this,"currentVolume");ae(this,"currentMinFrequency");ae(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new hv,this.settings=l,this.isCombinedAudio=!1,this.mode="on",this.updateMode(r),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.updateMode(t),this.mode==="off"||t.type!=="trace")return;if(t.empty){this.playEmptyTone(t.audio.size,t.audio.index);return}const r=t.audio,l=r.groupIndex,a=l!==void 0?this.audioPalette.getPaletteEntry(l):void 0;if(r.isContinuous)this.playSmooth(r.value,r.min,r.max,r.size,Array.isArray(r.index)?r.index[0]:r.index,a);else if(Array.isArray(r.value)){const i=r.value;if(i.length===0){this.playZeroTone();return}let s=0;const T=this.mode==="on"?50:0,u=new Array,Q=()=>{if(s<i.length){const f=Array.isArray(r.index)?r.index[s]:r.index;this.playTone(r.min,r.max,i[s++],r.size,f,a),u.push(setTimeout(Q,T))}else this.stop(u)};Q()}else{const i=r.value;if(i===0)this.playZeroTone();else{const s=Array.isArray(r.index)?r.index[0]:r.index;this.playTone(r.min,r.max,i,r.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 r=this.audioContext.createGain();return r.gain.value=.5,t.connect(r),r.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const r=t.type==="subplot"?t.trace:t;r.empty||r.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=r.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}playTone(t,r,l,o,a,i){const s={min:t,max:r},T=this.getFrequencyRange(),u=this.interpolate(l,s,T),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,r){const l=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=r,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*r,l.push(i)}return l}createGainNodes(t,r,l,o){const a=[],i=this.audioContext.currentTime,s=this.getVolume();for(let T=0;T<t.length;T++){const u=this.audioContext.createGain();let Q=s;if(T===0)r.harmonicMix&&(Q*=r.harmonicMix.fundamental);else{const h=r.harmonicMix.harmonics[T-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,r,Q,i,o);f!==null&&u.gain.setValueCurveAtTime(f,i,o),a.push(u)}return a}playOscillator(t,r=0,l){const o=ZH,a=this.getVolume();l||(l={waveType:"sine"});const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,a,o),T=this.audioContext.createStereoPanner();T.pan.value=r;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(T);T.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),T.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(T),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,r,l,o,a){if(r!=null&&r.timbreModulation){const{attack:i,decay:s,sustain:T,release:u}=r.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(T*l,o+Q+f),p>0&&t.gain.setValueAtTime(T*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,r,l,o,a,i){const s=this.audioContext,T=s.currentTime,u=ZH,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(C=>this.interpolate(C,{min:r,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,T,u);const b=s.createGain(),L=this.createAdsrEnvelope(b,i,f,T,u);L!==null&&b.gain.setValueCurveAtTime(L,T,u);const M=s.createStereoPanner();M.pan.value=g,v.connect(b),b.connect(M),M.connect(this.compressor),v.start(T),v.stop(T+u);const A=setTimeout(()=>{v.disconnect(),b.disconnect(),M.disconnect(),this.activeAudioIds.delete(A)},u*1e3*2);this.activeAudioIds.set(A,[v])}playEmptyTone(t,r){const l=this.audioContext,o=l.currentTime,a=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],T=[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(r,Q,f),-1,1),p=[];for(let b=0;b<s.length;b++){const L=l.createOscillator(),M=l.createGain(),A=this.audioContext.createStereoPanner(),C=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});L.frequency.value=s[b],L.type="sine",M.gain.setValueAtTime(T[b]*i,o),M.gain.exponentialRampToValueAtTime(.001*i,o+a),A.pan.value=h,L.connect(M),M.connect(A),A.connect(C),C.connect(u),L.start(o),L.stop(o+a),p.push(L)}const g=b=>{u.disconnect(),p.forEach(L=>{L.disconnect()}),this.activeAudioIds.delete(b)},v=setTimeout(()=>g(v),a*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(qj,0,{waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator($j,0,{waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(Uj,0,{waveType:"sine"})}interpolate(t,r,l){return r.min===0&&r.max===0?0:(t-r.min)/(r.max-r.min)*(l.max-l.min)+l.min}clamp(t,r,l){return Math.max(r,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 r=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(r)}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,r])=>{clearTimeout(t),r.forEach(l=>{l.disconnect(),l.stop()})}),this.activeAudioIds.clear()}}const Zj=250,Xj=50,Wj=500,Yj=20;class Kj{constructor(t,r,l){ae(this,"context");ae(this,"notification");ae(this,"settings");ae(this,"autoplayId");ae(this,"currentDirection");ae(this,"userSpeed");ae(this,"defaultSpeed");ae(this,"minSpeed");ae(this,"maxSpeed");ae(this,"autoplayRate");ae(this,"interval");ae(this,"currentDuration");ae(this,"onChangeEmitter");ae(this,"onChange");this.notification=r,this.context=t,this.settings=l,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Zj,this.minSpeed=Xj,this.maxSpeed=Wj,this.autoplayRate=this.defaultSpeed,this.interval=Yj,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new f9,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,r){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,r),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,r){if(this.userSpeed!==null)return this.userSpeed;if(r&&!r.empty){const l=Math.ceil(this.currentDuration/r.autoplay[t]);return this.defaultSpeed=l,this.minSpeed=Math.min(this.minSpeed,l),l}return this.defaultSpeed}}const XH=32;class bc{encode(t){const r=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,T=s+i,u=T+i;for(let Q=0;Q<t.values[a].length;Q++)t.values[a][Q]===0?r.push(" "):t.values[a][Q]<=s||t.values[a][Q]<=T?r.push("⠤"):t.values[a][Q]<=u?r.push("⠒"):r.push("⠉"),l[a].push(o.length),o.push({row:a,col:Q});r.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class Jj{constructor(){ae(this,"GLOBAL_MIN","globalMin");ae(this,"GLOBAL_MAX","globalMax");ae(this,"BLANK","blank");ae(this,"LOWER_OUTLIER","lowerOutlier");ae(this,"UPPER_OUTLIER","upperOutlier");ae(this,"MIN","min");ae(this,"MAX","max");ae(this,"Q1","q1");ae(this,"Q2","q2");ae(this,"Q3","q3")}encode(t,r=XH){const l=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],T=[{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<T.length-1;V++){const k=T[V],B=T[V+1],R=Math.abs(Q?B.value-k.value:k.value-T[V-1].value);k.type===this.LOWER_OUTLIER||k.type===this.UPPER_OUTLIER?(u.push({type:k.type,length:0,numChars:1}),u.push({type:this.BLANK,length:R,numChars:0})):k.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):k.type===this.GLOBAL_MIN||k.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:R,numChars:0}):u.push({type:k.type,length:R,numChars:1})}let f=u.reduce((V,k)=>V+(k.numChars>0?k.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 b=Math.max(0,r-f),L=u.reduce((V,k)=>V+(k.type!==this.Q2&&k.length>0?k.length:0),0);for(const V of u)if(V.type!==this.Q2&&V.length>0){const k=Math.round(V.length/L*b);V.numChars+=k}const M=u.reduce((V,k)=>V+k.numChars,0);let A=r-M,C=0;for(;A!==0;){const V=u[C%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=A>0?1:-1,A+=A>0?-1:1),C++}let E=-1;const _=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];a.push(Array.from({length:_.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(E=_.indexOf(V.type),a[i][E]=l.length);for(let k=0;k<V.numChars;k++){let B="⠀";V.type===this.MIN||V.type===this.MAX?B="⠒":V.type===this.Q1||V.type===this.Q3?B="⠿":V.type===this.Q2?B=k===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?B="⠂":V.type===this.BLANK&&(B="⠀"),l.push(B),o.push({row:i,col:E})}}for(let V=0;V<3;V++)if(a[i][V]===-1){for(let k=V+1;k<=3;k++)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}for(let V=6;V>3;V--)if(a[i][V]===-1){for(let k=V-1;k>=3;k--)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}l.push(Le.NEW_LINE),o.push({row:i,col:E})}return{value:l.join(Le.EMPTY),cellToIndex:a,indexToCell:o}}}class eI{encode(t){const r=new Array,l=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,s=i+a;for(let T=0;T<t.values.length;T++){l.push(new Array);for(let u=0;u<t.values[T].length;u++)t.values[T][u]===0?r.push(" "):t.values[T][u]<=i?r.push("⠤"):t.values[T][u]<=s?r.push("⠒"):r.push("⠉"),l[T].push(o.length),o.push({row:T,col:u});r.push(Le.NEW_LINE),l[T].push(o.length),o.push({row:T,col:t.values[T].length})}return{value:r.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}}class WH{encode(t){const r=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:T,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,T,u);r.push(p),l[a].push(o.length),o.push({row:a,col:Q})}r.push(Le.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(Le.EMPTY),cellToIndex:l,indexToCell:o}}getBrailleChar(t,r,l,o,a,i){return t<=l&&r!==null&&r>l?r<=o?"⢄":r<=a?"⢆":"⢇":t<=l?"⣀":r!==null&&r<=l?t<=o?"⡠":t<=a?"⡰":"⡸":t<=o&&r!==null&&r>o?r<=a?"⠢":"⠣":t<=o?"⠤":r!==null&&r<=o?t<=a?"⠔":"⠜":t<=a&&r!==null&&r>a?"⠑":t<=a?"⠒":r!==null&&r<=a?"⠊":t<=i?"⠉":""}}class tI extends WH{getThresholds(t,r){const l=(r.max-r.min)/4,o=r.min+l,a=o+l,i=a+l,s=r.max;return{low:o,medium:a,mediumHigh:i,high:s}}}class nI extends WH{getThresholds(t,r){const l=(r.max[t]-r.min[t])/4,o=r.min[t]+l,a=o+l,i=a+l,s=r.max[t];return{low:o,medium:a,mediumHigh:i,high:s}}}class rI{constructor(t,r,l){ae(this,"context");ae(this,"notification");ae(this,"display");ae(this,"enabled");ae(this,"cacheId");ae(this,"cache");ae(this,"encoders");ae(this,"onChangeEmitter");ae(this,"onChange");this.context=t,this.notification=r,this.display=l,this.enabled=!1,this.cacheId=Le.EMPTY,this.cache=null,this.encoders=new Map([[R2.BAR,new bc],[R2.BOX,new Jj],[R2.CANDLESTICK,new tI],[R2.DODGED,new bc],[R2.HEATMAP,new eI],[R2.HISTOGRAM,new bc],[R2.LINE,new nI],[R2.NORMALIZED,new bc],[R2.STACKED,new bc]]),this.onChangeEmitter=new f9,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const r=t.type==="subplot"?t.trace:t;if(r.empty||r.braille.empty||!this.encoders.has(r.traceType))return;const l=r.braille;if(this.cacheId!==l.id||this.cache===null){const o=this.encoders.get(r.traceType);this.cache=o.encode(l,XH),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:r,col:l}=this.cache.indexToCell[t];this.context.moveToIndex(r,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(b1.BRAILLE);const r=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(r)}}var YH=(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))(YH||{});class KH{constructor(){}static async post(t,r,l){const o={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",o,r)}static async request(t,r,l,o){try{const a=await fetch(t,{method:r,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 ${r} request to ${t}:`,a),{success:!1,error:{statusCode:YH.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}ae(KH,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const iI=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
3
3
  1. Provide simple, straightforward descriptions of charts and graphs
4
4
  2. Focus on basic patterns and key points
5
5
  3. Use simple, everyday language with minimal statistical terms