maidr 3.10.2 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maidr.js +1 -1
- package/dist/maidr.js.map +1 -1
- package/package.json +1 -1
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 mae=Object.defineProperty;var yae=(Hr,g4,b1)=>g4 in Hr?mae(Hr,g4,{enumerable:!0,configurable:!0,writable:!0,value:b1}):Hr[g4]=b1;var oe=(Hr,g4,b1)=>yae(Hr,typeof g4!="symbol"?g4+"":g4,b1);function Hr(e,t){for(var r=0;r<t.length;r++){const s=t[r];if(typeof s!="string"&&!Array.isArray(s)){for(const o in s)if(o!=="default"&&!(o in e)){const a=Object.getOwnPropertyDescriptor(s,o);a&&Object.defineProperty(e,o,a.get?a:{enumerable:!0,get:()=>s[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var g4=(e=>(e.CLICK="click",e.DOM_LOADED="DOMContentLoaded",e.FOCUS_IN="focusin",e.FOCUS_OUT="focusout",e.SELECTION_CHANGE="selectionchange",e))(g4||{}),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 Q9{constructor(){oe(this,"listeners");oe(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 xe{constructor(){}}oe(xe,"ARTICLE","article"),oe(xe,"DIV","div"),oe(xe,"FIGURE","figure"),oe(xe,"IMAGE","img"),oe(xe,"INPUT","input"),oe(xe,"TEXT_AREA","textarea"),oe(xe,"BRAILLE_TEXT_AREA","maidr-braille-textarea"),oe(xe,"MAIDR_ARTICLE","maidr-article"),oe(xe,"MAIDR_FIGURE","maidr-figure"),oe(xe,"MAIDR_HIGHLIGHT","maidr-highlight"),oe(xe,"REACT_CONTAINER","maidr-react-container"),oe(xe,"REVIEW_INPUT","maidr-review-input"),oe(xe,"TEXT_CONTAINER","maidr-text-container"),oe(xe,"ARIA_LABEL","aria-label"),oe(xe,"CIRCLE_X","cx"),oe(xe,"CIRCLE_Y","cy"),oe(xe,"D","d"),oe(xe,"FILL","fill"),oe(xe,"POINTS","points"),oe(xe,"RADIUS","r"),oe(xe,"ROLE","role"),oe(xe,"STROKE","stroke"),oe(xe,"STROKE_WIDTH","stroke-width"),oe(xe,"TITLE","title"),oe(xe,"VISIBILITY","visibility"),oe(xe,"X1","x1"),oe(xe,"X2","x2"),oe(xe,"Y1","y1"),oe(xe,"Y2","y2"),oe(xe,"AFTER_END","afterend"),oe(xe,"APPLICATION","application"),oe(xe,"ARE"," are "),oe(xe,"CIRCLE","circle"),oe(xe,"CLOSE_BRACKET","]"),oe(xe,"COMMA",","),oe(xe,"COMMA_SPACE",", "),oe(xe,"EMPTY",""),oe(xe,"HIDDEN","hidden"),oe(xe,"IS"," is "),oe(xe,"LINE","line"),oe(xe,"MAIDR_DATA","maidr-data"),oe(xe,"MAIDR_HIGHLIGHT_COLOR","#BADA55"),oe(xe,"NEW_LINE",`
|
|
2
|
-
`),oe(xe,"OPEN_BRACKET","["),oe(xe,"POLYLINE","polyline"),oe(xe,"SPACE"," "),oe(xe,"THROUGH"," through "),oe(xe,"TRANSPARENT","transparent"),oe(xe,"VISIBLE","visible"),oe(xe,"X","x"),oe(xe,"Y","y");let og=class{constructor(){oe(this,"items");this.items=new Array}push(t){this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}removeLast(t,r=1){const s=this.items.lastIndexOf(t);return s!==-1?(this.items.splice(s,r),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}};const lg=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function sg(e,t,r,s){e.addEventListener?e.addEventListener(t,r,s):e.attachEvent&&e.attachEvent("on".concat(t),r)}function mc(e,t,r,s){e.removeEventListener?e.removeEventListener(t,r,s):e.detachEvent&&e.detachEvent("on".concat(t),r)}function NH(e,t){const r=t.slice(0,t.length-1);for(let s=0;s<r.length;s++)r[s]=e[r[s].toLowerCase()];return r}function BH(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 nj(e,t){const r=e.length>=t.length?e:t,s=e.length>=t.length?t:e;let o=!0;for(let a=0;a<r.length;a++)s.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,"-":lg?173:189,"=":lg?61:187,";":lg?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},vc={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=[],gc=null,PH="all";const S0=new Map,Lc=e=>yc[e.toLowerCase()]||o5[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),rj=e=>Object.keys(yc).find(t=>yc[t]===e),ij=e=>Object.keys(o5).find(t=>o5[t]===e);function jH(e){PH=e||"all"}function xc(){return PH||"all"}function aj(){return d2.slice(0)}function oj(){return d2.map(e=>rj(e)||ij(e)||String.fromCharCode(e))}function lj(){const e=[];return Object.keys(L2).forEach(t=>{L2[t].forEach(r=>{let{key:s,scope:o,mods:a,shortcut:i}=r;e.push({scope:o,shortcut:i,mods:a,keys:s.split("+").map(l=>Lc(l))})})}),e}function sj(e){const t=e.target||e.srcElement,{tagName:r}=t;let s=!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)&&(s=!1),s}function uj(e){return typeof e=="string"&&(e=Lc(e)),d2.indexOf(e)!==-1}function cj(e,t){let r,s;e||(e=xc());for(const o in L2)if(Object.prototype.hasOwnProperty.call(L2,o))for(r=L2[o],s=0;s<r.length;)r[s].scope===e?r.splice(s,1).forEach(i=>{let{element:l}=i;return ug(l)}):s++;xc()===e&&jH(t||"all")}function Tj(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 s in o5)o5[s]===t&&(F3[s]=!1)}}function IH(e){if(typeof e>"u")Object.keys(L2).forEach(o=>{Array.isArray(L2[o])&&L2[o].forEach(a=>mp(a)),delete L2[o]}),ug(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),s=1;s<t;s++)r[s-1]=arguments[s];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:s,splitKey:o="+"}=e;BH(t).forEach(i=>{const l=i.split(o),T=l.length,u=l[T-1],Q=u==="*"?"*":Lc(u);if(!L2[Q])return;r||(r=xc());const f=T>1?NH(o5,l):[],h=[];L2[Q]=L2[Q].filter(p=>{const g=(s?p.method===s:!0)&&p.scope===r&&nj(p.mods,f);return g&&h.push(p.element),!g}),h.forEach(p=>ug(p))})};function FH(e,t,r,s){if(t.element!==s)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 zH(e,t){const r=L2["*"];let s=e.keyCode||e.which||e.charCode;if(!F3.filter.call(this,e))return;if((s===93||s===224)&&(s=91),d2.indexOf(s)===-1&&s!==229&&d2.push(s),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const T=vc[l];e[l]&&d2.indexOf(T)===-1?d2.push(T):!e[l]&&d2.indexOf(T)>-1?d2.splice(d2.indexOf(T),1):l==="metaKey"&&e[l]&&(d2=d2.filter(u=>u in vc||u===s))}),s in M3){M3[s]=!0;for(const l in o5)if(Object.prototype.hasOwnProperty.call(o5,l)){const T=vc[o5[l]];F3[l]=e[T]}if(!r)return}for(const l in M3)Object.prototype.hasOwnProperty.call(M3,l)&&(M3[l]=e[vc[l]]);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 l=0;l<r.length;l++)r[l].scope===o&&(e.type==="keydown"&&r[l].keydown||e.type==="keyup"&&r[l].keyup)&&FH(e,r[l],o,t);if(!(s in L2))return;const a=L2[s],i=a.length;for(let l=0;l<i;l++)if((e.type==="keydown"&&a[l].keydown||e.type==="keyup"&&a[l].keyup)&&a[l].key){const T=a[l],{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("")&&FH(e,T,o,t)}}function F3(e,t,r){d2=[];const s=BH(e);let o=[],a="all",i=document,l=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&&IH(e,a);l<s.length;l++)e=s[l].split(Q),o=[],e.length>1&&(o=NH(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:s[l],method:r,key:s[l],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!S0.has(i)){const p=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return zH(g,i)},v=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;zH(g,i),Tj(g)};S0.set(i,{keydownListener:p,keyupListenr:v,capture:f}),sg(i,"keydown",p,f),sg(i,"keyup",v,f)}if(!gc){const p=()=>{d2=[]};gc={listener:p,capture:f},sg(window,"focus",p,f)}}}function Qj(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 ug(e){const t=Object.values(L2).flat();if(t.findIndex(s=>{let{element:o}=s;return o===e})<0){const{keydownListener:s,keyupListenr:o,capture:a}=S0.get(e)||{};s&&o&&(mc(e,"keyup",o,a),mc(e,"keydown",s,a),S0.delete(e))}if((t.length<=0||S0.size<=0)&&(Object.keys(S0).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:l}=S0.get(o)||{};a&&i&&(mc(o,"keyup",i,l),mc(o,"keydown",a,l),S0.delete(o))}),S0.clear(),Object.keys(L2).forEach(o=>delete L2[o]),gc)){const{listener:o,capture:a}=gc;mc(window,"focus",o,a),gc=null}}const cg={getPressedKeyString:oj,setScope:jH,getScope:xc,deleteScope:cj,getPressedKeyCodes:aj,getAllKeyCodes:lj,isPressed:uj,filter:sj,trigger:Qj,unbind:IH,keyMap:yc,modifier:o5,modifierMap:vc};for(const e in cg)Object.prototype.hasOwnProperty.call(cg,e)&&(F3[e]=cg[e]);if(typeof window<"u"){const e=window.hotkeys;F3.noConflict=t=>(t&&window.hotkeys===F3&&(window.hotkeys=e),F3),window.hotkeys=F3}class fj{constructor(t){oe(this,"id");oe(this,"instructionContext");oe(this,"plotContext");oe(this,"scopeContext");this.id=t.id,this.plotContext=new og,this.scopeContext=new og;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 s=t.activeSubplot.state;if(s.empty||s.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 s=t?"Click to activate.":xe.EMPTY;switch(r.type){case"figure":return`This is a MAIDR figure containing ${r.size} subplots. ${s} 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. ${s} 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}. ${s} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}const dj="unavailable",hj="X",pj="Y",mj="unavailable";class Tg{constructor(){oe(this,"observers");oe(this,"isInitialEntry");oe(this,"isOutOfBounds");oe(this,"row");oe(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}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,s]=t;return r>=0&&r<this.values.length&&s>=0&&s<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 f9 extends Tg{constructor(r){var s,o,a;super();oe(this,"id");oe(this,"type");oe(this,"title");oe(this,"xAxis");oe(this,"yAxis");oe(this,"fill");this.id=r.id,this.type=r.type,this.title=r.title??dj,this.xAxis=((s=r.axes)==null?void 0:s.x)??hj,this.yAxis=((o=r.axes)==null?void 0:o.y)??pj,this.fill=((a=r.axes)==null?void 0:a.fill)??mj}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(r=>r.forEach(s=>{(Array.isArray(s)?s:[s]).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],s=t[0];for(let o=1;o<t.length;o++){const a=t[o];a<r&&(r=a),a>s&&(s=a)}return{min:r,max:s}}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 s=r.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return s?{r:Number.parseInt(s[1],10),g:Number.parseInt(s[2],10),b:Number.parseInt(s[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,r){const s=this.calculateLuminance(t),o=this.calculateLuminance(r);return(Math.max(s,o)+.05)/(Math.min(s,o)+.05)}static calculateLuminance(t){const[r,s,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*s+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class u2{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 l=i.getContext("2d");return l?(l.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(s=>{if(!r)return s;const o=s.cloneNode(!0);return o.setAttribute(xe.VISIBILITY,xe.HIDDEN),s.insertAdjacentElement(xe.AFTER_END,o),o})}static selectElement(t,r=!0){const s=document.querySelector(t);if(!r)return s;const o=s==null?void 0:s.cloneNode(!0);return o==null||o.setAttribute(xe.VISIBILITY,xe.HIDDEN),s==null||s.insertAdjacentElement(xe.AFTER_END,o),o}static createEmptyElement(t="rect"){const r=document.createElementNS(this.SVG_NAMESPACE,t);return r.setAttribute(xe.FILL,xe.TRANSPARENT),r.setAttribute(xe.STROKE,xe.TRANSPARENT),r.setAttribute(xe.VISIBILITY,xe.HIDDEN),r}static createCircleElement(t,r,s){var u;const o=window.getComputedStyle(s),a=o.stroke||o.fill,i=o.strokeWidth||"2",l=Number.parseFloat(i)*2,T=document.createElementNS(this.SVG_NAMESPACE,xe.CIRCLE);return T.setAttribute(xe.CIRCLE_X,String(t)),T.setAttribute(xe.CIRCLE_Y,String(r)),T.setAttribute(xe.RADIUS,String(l)),T.setAttribute(xe.FILL,a),T.setAttribute(xe.STROKE,a),T.setAttribute(xe.STROKE_WIDTH,i),T.setAttribute(xe.VISIBILITY,xe.HIDDEN),(u=s.parentElement)==null||u.insertAdjacentElement(xe.AFTER_END,T),T}static createLineElement(t,r){const o=t.getBBox();let a,i,l,T;switch(r){case"top":[a,i,l,T]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,l,T]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,l,T]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,l,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,xe.LINE);return Q.setAttribute(xe.X1,String(a)),Q.setAttribute(xe.Y1,String(i)),Q.setAttribute(xe.X2,String(l)),Q.setAttribute(xe.Y2,String(T)),Q.setAttribute(xe.STROKE,u.stroke),Q.setAttribute(xe.STROKE_WIDTH,u.strokeWidth||"2"),Q.setAttribute(xe.VISIBILITY,xe.HIDDEN),t.insertAdjacentElement(xe.AFTER_END,Q),Q}static createHighlightElement(t,r){const s=t.cloneNode(!0),o=t.tagName.toLowerCase(),a=o===xe.POLYLINE||o===xe.LINE,i=a?window.getComputedStyle(t).getPropertyValue(xe.STROKE):window.getComputedStyle(t).getPropertyValue(xe.FILL),l=this.getHighlightColor(i,r);if(s.setAttribute(xe.VISIBILITY,xe.VISIBLE),s.setAttribute(xe.STROKE,l),s.setAttribute(xe.FILL,l),s.style.fill=l,s.style.stroke=l,a){const T=window.getComputedStyle(s).getPropertyValue(xe.STROKE_WIDTH);s.setAttribute(xe.STROKE_WIDTH,`${T+2}`)}return t.insertAdjacentElement(xe.AFTER_END,s),s}static getHighlightColor(t,r){const s=yp.parse(t);if(!s)return r;const o=yp.invert(s);return yp.getContrastRatio(s,o)>=4.5?yp.rgbToString(o):r}}oe(u2,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class Qg extends f9{constructor(r,s){super(r);oe(this,"points");oe(this,"barValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"min");oe(this,"max");this.points=s,this.orientation=r.orientation??r3.VERTICAL,this.barValues=s.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,s=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:s,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,s=this.points[this.row][this.col],o=r?this.xAxis:this.yAxis,a=r?s.x:s.y,i=r?this.yAxis:this.xAxis,l=r?s.y:s.x;return{main:{label:o,value:a},cross:{label:i,value:l}}}mapToSvgElements(r){if(!r)return null;const s=[u2.selectAllElements(r)];if(s.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(s[o].length!==this.points[o].length)return null;return s}}class yj extends Qg{constructor(t){super(t,[t.data])}}const vj="Lower outlier(s)",gj="Upper outlier(s)",Lj="Minimum",xj="Maximum",bj="25%",Hj="50%",Ej="75%";class Mj extends f9{constructor(r){super(r);oe(this,"points");oe(this,"boxValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"sections");oe(this,"min");oe(this,"max");this.points=r.data,this.orientation=r.orientation??r3.VERTICAL,this.sections=[vj,Lj,bj,Hj,Ej,xj,gj];const s=[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=>s.map(i=>i(a))):this.boxValues=s.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,s){const o=this.orientation===r3.HORIZONTAL;r=o?r:s,s=o?s:r,super.moveToIndex(r,s)}get values(){return this.boxValues}audio(){const r=this.boxValues[this.row][this.col],s=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:s}}braille(){const r=this.orientation===r3.HORIZONTAL,s=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:s,col:o}}text(){const r=this.orientation===r3.HORIZONTAL,s=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,l=this.boxValues[this.row][this.col];return{main:{label:o,value:s.fill},cross:{label:i,value:l},section:a}}mapToSvgElements(r){if(!r||r.length!==this.points.length)return null;const s=this.orientation===r3.VERTICAL,o=new Array;if(s)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:r.length}));return r.forEach((a,i)=>{const l=a.lowerOutliers.flatMap(b=>u2.selectAllElements(b)),T=a.upperOutliers.flatMap(b=>u2.selectAllElements(b)),u=u2.selectElement(a.min)??u2.createEmptyElement(),Q=u2.selectElement(a.max)??u2.createEmptyElement(),f=u2.selectElement(a.iq)??u2.createEmptyElement(),h=u2.selectElement(a.q2)??u2.createEmptyElement(),[p,v]=s?[u2.createLineElement(f,"top"),u2.createLineElement(f,"bottom")]:[u2.createLineElement(f,"left"),u2.createLineElement(f,"right")],g=[l,u,p,h,v,Q,T];s?g.forEach((b,L)=>{o[L][i]=b}):o.push(g)}),o}}const Sj="Trend";class _j extends f9{constructor(r){super(r);oe(this,"candles");oe(this,"candleValues");oe(this,"orientation");oe(this,"sections",["open","high","low","close"]);oe(this,"currentSegmentType","open");oe(this,"currentPointIndex",0);oe(this,"sortedSegmentsByPoint");oe(this,"segmentPositionMaps");oe(this,"min");oe(this,"max");const s=r.data;this.candles=s.map(o=>({...o,trend:o.close>o.open?"Bull":o.close<o.open?"Bear":"Neutral"})),this.orientation=r.orientation??r3.VERTICAL,this.candleValues=this.sections.map(o=>this.candles.map(a=>a[o])),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}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 s=new Map;return r.forEach((o,a)=>{s.set(o,a)}),s})}getSegmentPositionInSortedOrder(r,s){return this.segmentPositionMaps[r].get(s)??0}getSegmentTypeAtSortedPosition(r,s){return this.sortedSegmentsByPoint[r][s]??"open"}updateVisualSegmentPosition(){const r=this.sections.indexOf(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 s=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?s+1:s-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 s=r==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(s>=0&&s<this.candles.length)this.currentPointIndex=s,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(r){switch(this.isInitialEntry&&this.handleInitialEntry(),r){case"UPWARD":{const s=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=s[s.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const s=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=s[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 s=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?s+1:s-1;return o>=0&&o<this.sections.length}case"FORWARD":case"BACKWARD":{const s=r==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return s>=0&&s<this.candles.length}}}dispose(){this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){const r=this.candles[this.currentPointIndex][this.currentSegmentType];return{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:r}}braille(){return{empty:!1,id:this.id,values:this.candleValues,min:this.min,max:this.max,row:this.row,col:this.col}}get highlightValues(){return null}text(){const r=this.candles[this.currentPointIndex],s=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:s},section:this.currentSegmentType,fill:{label:Sj,value:r.trend}}}}class Aj extends f9{constructor(r){super(r);oe(this,"heatmapValues");oe(this,"highlightValues");oe(this,"x");oe(this,"y");oe(this,"min");oe(this,"max");const s=r.data;this.x=s.x,this.y=s.y,this.heatmapValues=s.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 s=this.heatmapValues.length,o=this.heatmapValues[0].length,a=u2.selectAllElements(r);if(a.length===0||a.length!==s*o)return null;const i=new Array;if(a[0]instanceof SVGPathElement)for(let l=0;l<s;l++){const T=s-1-l,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 l=0;l<s;l++){const T=new Array;for(let u=0;u<o;u++){const Q=u*s+l;T.push(a[Q])}i.push(T)}return i}}class Oj extends Qg{constructor(t){super(t,[t.data])}text(){const t=this.orientation===r3.VERTICAL,r=this.points[this.row][this.col],s=t?r.xMin:r.yMin,o=t?r.xMax:r.yMax;return{...super.text(),range:{min:s,max:o}}}}const Cj="Type",qH=/[ML]\s*(-?\d+(\.\d+)?)\s+(-?\d+(\.\d+)?)/g;class $H extends f9{constructor(r){super(r);oe(this,"points");oe(this,"lineValues");oe(this,"highlightValues");oe(this,"min");oe(this,"max");this.points=r.data,this.lineValues=this.points.map(s=>s.map(o=>Number(o.y))),this.min=this.lineValues.map(s=>z3.safeMin(s)),this.max=this.lineValues.map(s=>z3.safeMax(s)),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],s=r.fill?{fill:{label:Cj,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},...s}}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}if(r==="UPWARD"||r==="DOWNWARD"){const s=this.findNearestLineByYValue(r);if(s!==null&&s!==this.row){this.row=s,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[s,o]=r;return s>=0&&s<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 s=this.col,o=this.values[this.row][s];let a=null,i=Number.POSITIVE_INFINITY;for(let l=0;l<this.values.length;l++){if(l===this.row||s>=this.values[l].length)continue;const T=this.values[l][s];if(!(r==="UPWARD"?T>o:T<o))continue;const Q=Math.abs(T-o);Q<i&&(i=Q,a=l)}return a}mapToSvgElements(r){if(!r||r.length!==this.lineValues.length)return null;const s=new Array;for(let o=0;o<r.length;o++){const a=u2.selectElement(r[o],!1);if(!a)return null;const i=new Array;if(a instanceof SVGPathElement){const T=a.getAttribute(xe.D)||xe.EMPTY;let u=qH.exec(T);for(;u!==null;)i.push({x:Number.parseFloat(u[1]),y:Number.parseFloat(u[3])}),u=qH.exec(T)}else if(a instanceof SVGPolylineElement){const u=(a.getAttribute(xe.POINTS)||xe.EMPTY).split(/\s+/).filter(Boolean);for(const Q of u){const[f,h]=Q.split(xe.COMMA);i.push({x:Number.parseFloat(f),y:Number.parseFloat(h)})}}if(i.length!==this.lineValues[o].length)return null;const l=new Array;for(const T of i){if(Number.isNaN(T.x)||Number.isNaN(T.y))return null;l.push(u2.createCircleElement(T.x,T.y,a))}s.push(l)}return s}}class wj extends f9{constructor(r){super(r);oe(this,"mode");oe(this,"xPoints");oe(this,"yPoints");oe(this,"xValues");oe(this,"yValues");oe(this,"highlightXValues");oe(this,"highlightYValues");oe(this,"minX");oe(this,"maxX");oe(this,"minY");oe(this,"maxY");this.mode="column";const s=r.data,o=[...s].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=[...s].sort((T,u)=>T.y-u.y||T.x-u.x);this.yPoints=new Array;let l=null;for(const T of i)(!l||l.y!==T.y)&&(l={y:T.y,x:[]},this.yPoints.push(l)),l.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(s=>s.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(r=>r.forEach(s=>s.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],s=r.y[Math.floor(r.y.length/2)];this.row=this.yValues.indexOf(s),this.mode="row"}else{const r=this.yPoints[this.row],s=r.x[Math.floor(r.x.length/2)];this.col=this.xValues.indexOf(s),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 s=u2.selectAllElements(r);if(s.length===0)return[null,null];const o=new Map,a=new Map;s.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),l=Array.from(a.entries()).sort(([T],[u])=>u-T).map(([T,u])=>u);return[i,l]}}const UH="Sum",Vj="Level",Dj="undefined";class Rj extends Qg{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 l=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(l)}this.points.push(r),this.barValues.push(t);const{min:s,max:o}=z3.minMax(t);this.min.push(s),this.max.push(o)}text(){return{...super.text(),fill:{label:Vj,value:this.points[this.row][this.col].fill??Dj}}}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=u2.selectAllElements(t);if(r.length===0)return new Array;const s=new Array;if(r[0]instanceof SVGPathElement)for(let o=0,a=0;o<this.barValues.length;o++){const i=new Array;for(let l=0;l<this.barValues[o].length;l++){if(a>=r.length)return new Array;this.barValues[o][l]===0?i.push(u2.createEmptyElement()):i.push(r[a++])}s.push(i)}else if(r[0]instanceof SVGRectElement){for(let o=0;o<this.barValues.length;o++)s.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?s[i].push(u2.createEmptyElement()):s[i].push(r[a++])}}return s}}class kj extends $H{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],r=this.col,s=l=>t[Math.max(0,Math.min(l,t.length-1))],o=r>0?s(r-1):s(r),a=s(r),i=r<t.length-1?s(r+1):s(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 Nj{static create(t){switch(t.type){case R2.BAR:return new yj(t);case R2.BOX:return new Mj(t);case R2.CANDLESTICK:return new _j(t);case R2.HEATMAP:return new Aj(t);case R2.HISTOGRAM:return new Oj(t);case R2.LINE:return new $H(t);case R2.SCATTER:return new wj(t);case R2.SMOOTH:return new kj(t);case R2.DODGED:case R2.NORMALIZED:case R2.STACKED:return new Rj(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const Bj="MAIDR Plot",Pj="unavailable",jj="unavailable";class Ij extends Tg{constructor(r){super();oe(this,"id");oe(this,"title");oe(this,"subtitle");oe(this,"caption");oe(this,"subplots");oe(this,"size");this.id=r.id,this.title=r.title??Bj,this.subtitle=r.subtitle??Pj,this.caption=r.caption??jj;const s=r.subplots;this.subplots=s.map(o=>o.map(a=>new Fj(a))),this.size=this.subplots.reduce((o,a)=>o+a.length,0)}dispose(){this.subplots.forEach(r=>r.forEach(s=>s.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((s,o)=>s+o.length,0);return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:r,subplot:this.activeSubplot.state,traceTypes:this.activeSubplot.traceTypes}}}class Fj extends Tg{constructor(r){super();oe(this,"traces");oe(this,"traceTypes");oe(this,"size");this.isInitialEntry=!1;const s=r.layers;this.size=s.length,this.traces=s.map(o=>[Nj.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?xe.EMPTY:a.traceType})}dispose(){this.traces.forEach(r=>r.forEach(s=>s.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][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}}}const es=class es{constructor(){oe(this,"basePalette");oe(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}}],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 s=this.generateExtendedEntry(t);return this.extendedPalette.set(t,s),s}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,s)=>{this.extendedPalette.set(this.basePalette.length+s,r)})}generateExtendedEntry(t){const r=t%this.basePalette.length,s=this.basePalette[r],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,s.timbreModulation);return{waveType:s.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const r=[],s=es.MIN_HARMONICS+t%es.HARMONIC_VARIATION;for(let o=0;o<s;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 s=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,r.attack*s)),decay:Math.max(.05,Math.min(.3,r.decay*s)),sustain:Math.max(.4,Math.min(.9,r.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,r.release*s))}}};oe(es,"MIN_HARMONICS",2),oe(es,"HARMONIC_VARIATION",3);let fg=es;const GH=200,ZH=1e3,zj=100,qj=440,$j=880,XH=.3,Uj=.5;class Gj{constructor(t,r){oe(this,"notification");oe(this,"audioPalette");oe(this,"isCombinedAudio");oe(this,"mode");oe(this,"activeAudioIds");oe(this,"volume");oe(this,"audioContext");oe(this,"compressor");this.notification=t,this.audioPalette=new fg,this.isCombinedAudio=!1,this.mode="on",this.updateMode(r),this.activeAudioIds=new Map,this.volume=Uj,this.audioContext=new AudioContext,this.compressor=this.initCompressor()}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close())}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"))}update(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,s=r.groupIndex,a=s!==void 0?this.audioPalette.getPaletteEntry(s):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 l=0;const T=this.mode==="on"?50:0,u=new Array,Q=()=>{if(l<i.length){const f=Array.isArray(r.index)?r.index[l]:r.index;this.playTone(r.min,r.max,i[l++],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 l=Array.isArray(r.index)?r.index[0]:r.index;this.playTone(r.min,r.max,i,r.size,l,a)}}}playTone(t,r,s,o,a,i){const l={min:t,max:r},T={min:GH,max:ZH},u=this.interpolate(s,l,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 s=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=r,s.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,s.push(i)}return s}createGainNodes(t,r,s,o){const a=[],i=this.audioContext.currentTime;for(let l=0;l<t.length;l++){const T=this.audioContext.createGain();let u=s;if(l===0)r.harmonicMix&&(u*=r.harmonicMix.fundamental);else{const f=r.harmonicMix.harmonics[l-1];u*=f.amplitude}const Q=this.createAdsrEnvelope(T,r,u,i,o);Q!==null&&T.gain.setValueCurveAtTime(Q,i,o),a.push(T)}return a}playOscillator(t,r=0,s){const o=XH,a=this.volume;s||(s={waveType:"sine"});const i=this.createOscillators(s,t),l=this.createGainNodes(i,s,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(l[h]),l[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++)l[p].disconnect(T),i[p].stop(),i[p].disconnect(l[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),o*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,r,s,o,a){if(r!=null&&r.timbreModulation){const{attack:i,decay:l,sustain:T,release:u}=r.timbreModulation,Q=a*i,f=a*l,h=a*u,p=a-Q-f-h;return t.gain.setValueAtTime(1e-4*s,o),t.gain.linearRampToValueAtTime(s,o+Q),t.gain.linearRampToValueAtTime(T*s,o+Q+f),p>0&&t.gain.setValueAtTime(T*s,o+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*s,o+a),null}else return[.5*s,s,.5*s,.5*s,.5*s,.1*s,1e-4*s]}playSmooth(t,r,s,o,a,i){const l=this.audioContext,T=l.currentTime,u=XH,Q=(i==null?void 0:i.waveType)||"sine",f=t.map(M=>this.interpolate(M,{min:r,max:s},{min:GH,max:ZH}));f.length<2&&f.push(f[0]);const h=this.clamp(this.interpolate(a,{min:0,max:o-1},{min:-1,max:1}),-1,1),p=l.createOscillator();p.type=Q,p.frequency.setValueCurveAtTime(f,T,u);const v=l.createGain(),g=this.createAdsrEnvelope(v,i,this.volume,T,u);g!==null&&v.gain.setValueCurveAtTime(g,T,u);const b=l.createStereoPanner();b.pan.value=h,p.connect(v),v.connect(b),b.connect(this.compressor),p.start(T),p.stop(T+u);const L=setTimeout(()=>{p.disconnect(),v.disconnect(),b.disconnect(),this.activeAudioIds.delete(L)},u*1e3*2);this.activeAudioIds.set(L,[p])}playEmptyTone(t,r){const s=this.audioContext,o=s.currentTime,a=.2,i=[500,1e3,1500,2100,2700],l=[1,.6,.4,.2,.1],T=s.createGain();T.gain.setValueAtTime(.3,o),T.gain.exponentialRampToValueAtTime(.01,o+a),T.connect(this.compressor);const u={min:0,max:t},Q={min:-1,max:1},f=this.clamp(this.interpolate(r,u,Q),-1,1),h=[];for(let g=0;g<i.length;g++){const b=s.createOscillator(),L=s.createGain(),M=this.audioContext.createStereoPanner(),A=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});b.frequency.value=i[g],b.type="sine",L.gain.setValueAtTime(l[g]*this.volume,o),L.gain.exponentialRampToValueAtTime(.001,o+a),M.pan.value=f,b.connect(L),L.connect(M),M.connect(A),A.connect(T),b.start(o),b.stop(o+a),h.push(b)}const p=g=>{T.disconnect(),h.forEach(b=>{b.disconnect()}),this.activeAudioIds.delete(g)},v=setTimeout(()=>p(v),a*1e3*2);return this.activeAudioIds.set(v,h),v}playZeroTone(){return this.playOscillator(zj,0,{waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(qj,0,{waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator($j,0,{waveType:"sine"})}interpolate(t,r,s){return r.min===0&&r.max===0?0:(t-r.min)/(r.max-r.min)*(s.max-s.min)+s.min}clamp(t,r,s){return Math.max(r,Math.min(t,s))}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(s=>{const o=this.activeAudioIds.get(s);if(!o){clearInterval(s);return}o.forEach(a=>{a==null||a.disconnect(),a==null||a.stop()}),clearTimeout(s),this.activeAudioIds.delete(s)})}stopAll(){this.activeAudioIds.entries().forEach(([t,r])=>{clearTimeout(t),r.forEach(s=>{s.disconnect(),s.stop()})}),this.activeAudioIds.clear()}setVolume(t){this.volume=Math.min(Math.max(t/100,0),1)}}const Zj=250,Xj=50,Wj=500,Yj=4e3,Kj=20;class Jj{constructor(t,r){oe(this,"context");oe(this,"notification");oe(this,"autoplayId");oe(this,"currentDirection");oe(this,"userSpeed");oe(this,"defaultSpeed");oe(this,"minSpeed");oe(this,"maxSpeed");oe(this,"autoplayRate");oe(this,"totalDuration");oe(this,"interval");oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=r,this.context=t,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Zj,this.minSpeed=Xj,this.maxSpeed=Wj,this.autoplayRate=this.defaultSpeed,this.totalDuration=Yj,this.interval=Kj,this.onChangeEmitter=new Q9,this.onChange=this.onChangeEmitter.event}dispose(){this.stop(),this.onChangeEmitter.dispose()}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 s=Math.ceil(this.totalDuration/r.autoplay[t]);return this.defaultSpeed=s,this.minSpeed=Math.min(this.minSpeed,s),s}return this.defaultSpeed}}const WH=32;class bc{encode(t){const r=new Array,s=new Array,o=new Array;for(let a=0;a<t.values.length;a++){s.push(new Array);const i=(t.max[a]-t.min[a])/4,l=t.min[a]+i,T=l+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]<=l||t.values[a][Q]<=T?r.push("⠤"):t.values[a][Q]<=u?r.push("⠒"):r.push("⠉"),s[a].push(o.length),o.push({row:a,col:Q});r.push(xe.NEW_LINE),s[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(xe.EMPTY),cellToIndex:s,indexToCell:o}}}class eI{constructor(){oe(this,"GLOBAL_MIN","globalMin");oe(this,"GLOBAL_MAX","globalMax");oe(this,"BLANK","blank");oe(this,"LOWER_OUTLIER","lowerOutlier");oe(this,"UPPER_OUTLIER","upperOutlier");oe(this,"MIN","min");oe(this,"MAX","max");oe(this,"Q1","q1");oe(this,"Q2","q2");oe(this,"Q3","q3")}encode(t,r=WH){const s=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){const l=t.values[i],T=[{type:this.GLOBAL_MIN,value:t.min},...l.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:l.min},{type:this.Q1,value:l.q1},{type:this.Q2,value:l.q2},{type:this.Q3,value:l.q3},{type:this.MAX,value:l.max},...l.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,v,g]=[-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&&(v=V),u[V].type===this.Q3&&(g=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++)),v!==-1&&g!==-1&&u[v].length!==u[g].length&&(u[v].length>u[g].length?(u[v].numChars++,f++):(u[g].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]=s.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="⠀"),s.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}}s.push(xe.NEW_LINE),o.push({row:i,col:E})}return{value:s.join(xe.EMPTY),cellToIndex:a,indexToCell:o}}}class tI{encode(t){const r=new Array,s=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,l=i+a;for(let T=0;T<t.values.length;T++){s.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]<=l?r.push("⠒"):r.push("⠉"),s[T].push(o.length),o.push({row:T,col:u});r.push(xe.NEW_LINE),s[T].push(o.length),o.push({row:T,col:t.values[T].length})}return{value:r.join(xe.EMPTY),cellToIndex:s,indexToCell:o}}}class YH{encode(t){const r=new Array,s=new Array,o=new Array;for(let a=0;a<t.values.length;a++){s.push(new Array);const{low:i,medium:l,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,l,T,u);r.push(p),s[a].push(o.length),o.push({row:a,col:Q})}r.push(xe.NEW_LINE),s[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(xe.EMPTY),cellToIndex:s,indexToCell:o}}getBrailleChar(t,r,s,o,a,i){return t<=s&&r!==null&&r>s?r<=o?"⢄":r<=a?"⢆":"⢇":t<=s?"⣀":r!==null&&r<=s?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 nI extends YH{getThresholds(t,r){const s=(r.max-r.min)/4,o=r.min+s,a=o+s,i=a+s,l=r.max;return{low:o,medium:a,mediumHigh:i,high:l}}}class rI extends YH{getThresholds(t,r){const s=(r.max[t]-r.min[t])/4,o=r.min[t]+s,a=o+s,i=a+s,l=r.max[t];return{low:o,medium:a,mediumHigh:i,high:l}}}class iI{constructor(t,r,s){oe(this,"context");oe(this,"notification");oe(this,"display");oe(this,"enabled");oe(this,"cacheId");oe(this,"cache");oe(this,"encoders");oe(this,"onChangeEmitter");oe(this,"onChange");this.context=t,this.notification=r,this.display=s,this.enabled=!1,this.cacheId=xe.EMPTY,this.cache=null,this.encoders=new Map([[R2.BAR,new bc],[R2.BOX,new eI],[R2.CANDLESTICK,new nI],[R2.DODGED,new bc],[R2.HEATMAP,new tI],[R2.HISTOGRAM,new bc],[R2.LINE,new rI],[R2.NORMALIZED,new bc],[R2.STACKED,new bc]]),this.onChangeEmitter=new Q9,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 s=r.braille;if(this.cacheId!==s.id||this.cache===null){const o=this.encoders.get(r.traceType);this.cache=o.encode(s,WH),this.cacheId=s.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[s.row][s.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:r,col:s}=this.cache.indexToCell[t];this.context.moveToIndex(r,s)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const s=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(s);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 KH=(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))(KH||{});class JH{constructor(){}static async post(t,r,s){const o={...this.DEFAULT_HEADERS,...s};return this.request(t,"POST",o,r)}static async request(t,r,s,o){try{const a=await fetch(t,{method:r,headers:s,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:KH.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}oe(JH,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const aI=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
|
|
2
|
+
`),oe(xe,"OPEN_BRACKET","["),oe(xe,"POLYLINE","polyline"),oe(xe,"SPACE"," "),oe(xe,"THROUGH"," through "),oe(xe,"TRANSPARENT","transparent"),oe(xe,"VISIBLE","visible"),oe(xe,"X","x"),oe(xe,"Y","y");let og=class{constructor(){oe(this,"items");this.items=new Array}push(t){this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}removeLast(t,r=1){const s=this.items.lastIndexOf(t);return s!==-1?(this.items.splice(s,r),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}};const lg=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function sg(e,t,r,s){e.addEventListener?e.addEventListener(t,r,s):e.attachEvent&&e.attachEvent("on".concat(t),r)}function mc(e,t,r,s){e.removeEventListener?e.removeEventListener(t,r,s):e.detachEvent&&e.detachEvent("on".concat(t),r)}function NH(e,t){const r=t.slice(0,t.length-1);for(let s=0;s<r.length;s++)r[s]=e[r[s].toLowerCase()];return r}function BH(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 nj(e,t){const r=e.length>=t.length?e:t,s=e.length>=t.length?t:e;let o=!0;for(let a=0;a<r.length;a++)s.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,"-":lg?173:189,"=":lg?61:187,";":lg?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},vc={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=[],gc=null,PH="all";const S0=new Map,Lc=e=>yc[e.toLowerCase()]||o5[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),rj=e=>Object.keys(yc).find(t=>yc[t]===e),ij=e=>Object.keys(o5).find(t=>o5[t]===e);function jH(e){PH=e||"all"}function xc(){return PH||"all"}function aj(){return d2.slice(0)}function oj(){return d2.map(e=>rj(e)||ij(e)||String.fromCharCode(e))}function lj(){const e=[];return Object.keys(L2).forEach(t=>{L2[t].forEach(r=>{let{key:s,scope:o,mods:a,shortcut:i}=r;e.push({scope:o,shortcut:i,mods:a,keys:s.split("+").map(l=>Lc(l))})})}),e}function sj(e){const t=e.target||e.srcElement,{tagName:r}=t;let s=!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)&&(s=!1),s}function uj(e){return typeof e=="string"&&(e=Lc(e)),d2.indexOf(e)!==-1}function cj(e,t){let r,s;e||(e=xc());for(const o in L2)if(Object.prototype.hasOwnProperty.call(L2,o))for(r=L2[o],s=0;s<r.length;)r[s].scope===e?r.splice(s,1).forEach(i=>{let{element:l}=i;return ug(l)}):s++;xc()===e&&jH(t||"all")}function Tj(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 s in o5)o5[s]===t&&(F3[s]=!1)}}function IH(e){if(typeof e>"u")Object.keys(L2).forEach(o=>{Array.isArray(L2[o])&&L2[o].forEach(a=>mp(a)),delete L2[o]}),ug(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),s=1;s<t;s++)r[s-1]=arguments[s];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:s,splitKey:o="+"}=e;BH(t).forEach(i=>{const l=i.split(o),T=l.length,u=l[T-1],Q=u==="*"?"*":Lc(u);if(!L2[Q])return;r||(r=xc());const f=T>1?NH(o5,l):[],h=[];L2[Q]=L2[Q].filter(p=>{const g=(s?p.method===s:!0)&&p.scope===r&&nj(p.mods,f);return g&&h.push(p.element),!g}),h.forEach(p=>ug(p))})};function FH(e,t,r,s){if(t.element!==s)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 zH(e,t){const r=L2["*"];let s=e.keyCode||e.which||e.charCode;if(!F3.filter.call(this,e))return;if((s===93||s===224)&&(s=91),d2.indexOf(s)===-1&&s!==229&&d2.push(s),["metaKey","ctrlKey","altKey","shiftKey"].forEach(l=>{const T=vc[l];e[l]&&d2.indexOf(T)===-1?d2.push(T):!e[l]&&d2.indexOf(T)>-1?d2.splice(d2.indexOf(T),1):l==="metaKey"&&e[l]&&(d2=d2.filter(u=>u in vc||u===s))}),s in M3){M3[s]=!0;for(const l in o5)if(Object.prototype.hasOwnProperty.call(o5,l)){const T=vc[o5[l]];F3[l]=e[T]}if(!r)return}for(const l in M3)Object.prototype.hasOwnProperty.call(M3,l)&&(M3[l]=e[vc[l]]);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 l=0;l<r.length;l++)r[l].scope===o&&(e.type==="keydown"&&r[l].keydown||e.type==="keyup"&&r[l].keyup)&&FH(e,r[l],o,t);if(!(s in L2))return;const a=L2[s],i=a.length;for(let l=0;l<i;l++)if((e.type==="keydown"&&a[l].keydown||e.type==="keyup"&&a[l].keyup)&&a[l].key){const T=a[l],{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("")&&FH(e,T,o,t)}}function F3(e,t,r){d2=[];const s=BH(e);let o=[],a="all",i=document,l=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&&IH(e,a);l<s.length;l++)e=s[l].split(Q),o=[],e.length>1&&(o=NH(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:s[l],method:r,key:s[l],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!S0.has(i)){const p=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return zH(g,i)},v=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;zH(g,i),Tj(g)};S0.set(i,{keydownListener:p,keyupListenr:v,capture:f}),sg(i,"keydown",p,f),sg(i,"keyup",v,f)}if(!gc){const p=()=>{d2=[]};gc={listener:p,capture:f},sg(window,"focus",p,f)}}}function Qj(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 ug(e){const t=Object.values(L2).flat();if(t.findIndex(s=>{let{element:o}=s;return o===e})<0){const{keydownListener:s,keyupListenr:o,capture:a}=S0.get(e)||{};s&&o&&(mc(e,"keyup",o,a),mc(e,"keydown",s,a),S0.delete(e))}if((t.length<=0||S0.size<=0)&&(Object.keys(S0).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:l}=S0.get(o)||{};a&&i&&(mc(o,"keyup",i,l),mc(o,"keydown",a,l),S0.delete(o))}),S0.clear(),Object.keys(L2).forEach(o=>delete L2[o]),gc)){const{listener:o,capture:a}=gc;mc(window,"focus",o,a),gc=null}}const cg={getPressedKeyString:oj,setScope:jH,getScope:xc,deleteScope:cj,getPressedKeyCodes:aj,getAllKeyCodes:lj,isPressed:uj,filter:sj,trigger:Qj,unbind:IH,keyMap:yc,modifier:o5,modifierMap:vc};for(const e in cg)Object.prototype.hasOwnProperty.call(cg,e)&&(F3[e]=cg[e]);if(typeof window<"u"){const e=window.hotkeys;F3.noConflict=t=>(t&&window.hotkeys===F3&&(window.hotkeys=e),F3),window.hotkeys=F3}class fj{constructor(t){oe(this,"id");oe(this,"instructionContext");oe(this,"plotContext");oe(this,"scopeContext");this.id=t.id,this.plotContext=new og,this.scopeContext=new og;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 s=t.activeSubplot.state;if(s.empty||s.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 s=t?"Click to activate.":xe.EMPTY;switch(r.type){case"figure":return`This is a MAIDR figure containing ${r.size} subplots. ${s} 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. ${s} 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}. ${s} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}const dj="unavailable",hj="X",pj="Y",mj="unavailable";class Tg{constructor(){oe(this,"observers");oe(this,"isInitialEntry");oe(this,"isOutOfBounds");oe(this,"row");oe(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}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,s]=t;return r>=0&&r<this.values.length&&s>=0&&s<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 f9 extends Tg{constructor(r){var s,o,a;super();oe(this,"id");oe(this,"type");oe(this,"title");oe(this,"xAxis");oe(this,"yAxis");oe(this,"fill");this.id=r.id,this.type=r.type,this.title=r.title??dj,this.xAxis=((s=r.axes)==null?void 0:s.x)??hj,this.yAxis=((o=r.axes)==null?void 0:o.y)??pj,this.fill=((a=r.axes)==null?void 0:a.fill)??mj}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(r=>r.forEach(s=>{(Array.isArray(s)?s:[s]).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],s=t[0];for(let o=1;o<t.length;o++){const a=t[o];a<r&&(r=a),a>s&&(s=a)}return{min:r,max:s}}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 s=r.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return s?{r:Number.parseInt(s[1],10),g:Number.parseInt(s[2],10),b:Number.parseInt(s[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,r){const s=this.calculateLuminance(t),o=this.calculateLuminance(r);return(Math.max(s,o)+.05)/(Math.min(s,o)+.05)}static calculateLuminance(t){const[r,s,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*s+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class u2{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 l=i.getContext("2d");return l?(l.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(s=>{if(!r)return s;const o=s.cloneNode(!0);return o.setAttribute(xe.VISIBILITY,xe.HIDDEN),s.insertAdjacentElement(xe.AFTER_END,o),o})}static selectElement(t,r=!0){const s=document.querySelector(t);if(!r)return s;const o=s==null?void 0:s.cloneNode(!0);return o==null||o.setAttribute(xe.VISIBILITY,xe.HIDDEN),s==null||s.insertAdjacentElement(xe.AFTER_END,o),o}static createEmptyElement(t="rect"){const r=document.createElementNS(this.SVG_NAMESPACE,t);return r.setAttribute(xe.FILL,xe.TRANSPARENT),r.setAttribute(xe.STROKE,xe.TRANSPARENT),r.setAttribute(xe.VISIBILITY,xe.HIDDEN),r}static createCircleElement(t,r,s){var u;const o=window.getComputedStyle(s),a=o.stroke||o.fill,i=o.strokeWidth||"2",l=Number.parseFloat(i)*2,T=document.createElementNS(this.SVG_NAMESPACE,xe.CIRCLE);return T.setAttribute(xe.CIRCLE_X,String(t)),T.setAttribute(xe.CIRCLE_Y,String(r)),T.setAttribute(xe.RADIUS,String(l)),T.setAttribute(xe.FILL,a),T.setAttribute(xe.STROKE,a),T.setAttribute(xe.STROKE_WIDTH,i),T.setAttribute(xe.VISIBILITY,xe.HIDDEN),(u=s.parentElement)==null||u.insertAdjacentElement(xe.AFTER_END,T),T}static createLineElement(t,r){const o=t.getBBox();let a,i,l,T;switch(r){case"top":[a,i,l,T]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,l,T]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,l,T]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,l,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,xe.LINE);return Q.setAttribute(xe.X1,String(a)),Q.setAttribute(xe.Y1,String(i)),Q.setAttribute(xe.X2,String(l)),Q.setAttribute(xe.Y2,String(T)),Q.setAttribute(xe.STROKE,u.stroke),Q.setAttribute(xe.STROKE_WIDTH,u.strokeWidth||"2"),Q.setAttribute(xe.VISIBILITY,xe.HIDDEN),t.insertAdjacentElement(xe.AFTER_END,Q),Q}static createHighlightElement(t,r){const s=t.cloneNode(!0),o=t.tagName.toLowerCase(),a=o===xe.POLYLINE||o===xe.LINE,i=a?window.getComputedStyle(t).getPropertyValue(xe.STROKE):window.getComputedStyle(t).getPropertyValue(xe.FILL),l=this.getHighlightColor(i,r);if(s.setAttribute(xe.VISIBILITY,xe.VISIBLE),s.setAttribute(xe.STROKE,l),s.setAttribute(xe.FILL,l),s.style.fill=l,s.style.stroke=l,a){const T=window.getComputedStyle(s).getPropertyValue(xe.STROKE_WIDTH);s.setAttribute(xe.STROKE_WIDTH,`${T+2}`)}return t.insertAdjacentElement(xe.AFTER_END,s),s}static getHighlightColor(t,r){const s=yp.parse(t);if(!s)return r;const o=yp.invert(s);return yp.getContrastRatio(s,o)>=4.5?yp.rgbToString(o):r}}oe(u2,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class Qg extends f9{constructor(r,s){super(r);oe(this,"points");oe(this,"barValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"min");oe(this,"max");this.points=s,this.orientation=r.orientation??r3.VERTICAL,this.barValues=s.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,s=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:s,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,s=this.points[this.row][this.col],o=r?this.xAxis:this.yAxis,a=r?s.x:s.y,i=r?this.yAxis:this.xAxis,l=r?s.y:s.x;return{main:{label:o,value:a},cross:{label:i,value:l}}}mapToSvgElements(r){if(!r)return null;const s=[u2.selectAllElements(r)];if(s.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(s[o].length!==this.points[o].length)return null;return s}}class yj extends Qg{constructor(t){super(t,[t.data])}}const vj="Lower outlier(s)",gj="Upper outlier(s)",Lj="Minimum",xj="Maximum",bj="25%",Hj="50%",Ej="75%";class Mj extends f9{constructor(r){super(r);oe(this,"points");oe(this,"boxValues");oe(this,"highlightValues");oe(this,"orientation");oe(this,"sections");oe(this,"min");oe(this,"max");this.points=r.data,this.orientation=r.orientation??r3.VERTICAL,this.sections=[vj,Lj,bj,Hj,Ej,xj,gj];const s=[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=>s.map(i=>i(a))):this.boxValues=s.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,s){const o=this.orientation===r3.HORIZONTAL;r=o?r:s,s=o?s:r,super.moveToIndex(r,s)}get values(){return this.boxValues}audio(){const r=this.boxValues[this.row][this.col],s=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:s}}braille(){const r=this.orientation===r3.HORIZONTAL,s=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:s,col:o}}text(){const r=this.orientation===r3.HORIZONTAL,s=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,l=this.boxValues[this.row][this.col];return{main:{label:o,value:s.fill},cross:{label:i,value:l},section:a}}mapToSvgElements(r){if(!r||r.length!==this.points.length)return null;const s=this.orientation===r3.VERTICAL,o=new Array;if(s)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:r.length}));return r.forEach((a,i)=>{const l=a.lowerOutliers.flatMap(b=>u2.selectAllElements(b)),T=a.upperOutliers.flatMap(b=>u2.selectAllElements(b)),u=u2.selectElement(a.min)??u2.createEmptyElement(),Q=u2.selectElement(a.max)??u2.createEmptyElement(),f=u2.selectElement(a.iq)??u2.createEmptyElement(),h=u2.selectElement(a.q2)??u2.createEmptyElement(),[p,v]=s?[u2.createLineElement(f,"top"),u2.createLineElement(f,"bottom")]:[u2.createLineElement(f,"left"),u2.createLineElement(f,"right")],g=[l,u,p,h,v,Q,T];s?g.forEach((b,L)=>{o[L][i]=b}):o.push(g)}),o}}const Sj="Trend";class _j extends f9{constructor(r){super(r);oe(this,"candles");oe(this,"candleValues");oe(this,"orientation");oe(this,"sections",["open","high","low","close"]);oe(this,"currentSegmentType","open");oe(this,"currentPointIndex",0);oe(this,"sortedSegmentsByPoint");oe(this,"segmentPositionMaps");oe(this,"min");oe(this,"max");const s=r.data;this.candles=s.map(o=>({...o,trend:o.close>o.open?"Bull":o.close<o.open?"Bear":"Neutral"})),this.orientation=r.orientation??r3.VERTICAL,this.candleValues=this.sections.map(o=>this.candles.map(a=>a[o])),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}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 s=new Map;return r.forEach((o,a)=>{s.set(o,a)}),s})}getSegmentPositionInSortedOrder(r,s){return this.segmentPositionMaps[r].get(s)??0}getSegmentTypeAtSortedPosition(r,s){return this.sortedSegmentsByPoint[r][s]??"open"}updateVisualSegmentPosition(){const r=this.sections.indexOf(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 s=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?s+1:s-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 s=r==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(s>=0&&s<this.candles.length)this.currentPointIndex=s,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(r){switch(this.isInitialEntry&&this.handleInitialEntry(),r){case"UPWARD":{const s=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=s[s.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const s=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=s[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 s=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=r==="UPWARD"?s+1:s-1;return o>=0&&o<this.sections.length}case"FORWARD":case"BACKWARD":{const s=r==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return s>=0&&s<this.candles.length}}}dispose(){this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){const r=this.candles[this.currentPointIndex][this.currentSegmentType],s=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:s}}braille(){return{empty:!1,id:this.id,values:this.candleValues,min:this.min,max:this.max,row:this.row,col:this.col}}get highlightValues(){return null}text(){const r=this.candles[this.currentPointIndex],s=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:s},section:this.currentSegmentType,fill:{label:Sj,value:r.trend}}}}class Aj extends f9{constructor(r){super(r);oe(this,"heatmapValues");oe(this,"highlightValues");oe(this,"x");oe(this,"y");oe(this,"min");oe(this,"max");const s=r.data;this.x=s.x,this.y=s.y,this.heatmapValues=s.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 s=this.heatmapValues.length,o=this.heatmapValues[0].length,a=u2.selectAllElements(r);if(a.length===0||a.length!==s*o)return null;const i=new Array;if(a[0]instanceof SVGPathElement)for(let l=0;l<s;l++){const T=s-1-l,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 l=0;l<s;l++){const T=new Array;for(let u=0;u<o;u++){const Q=u*s+l;T.push(a[Q])}i.push(T)}return i}}class Oj extends Qg{constructor(t){super(t,[t.data])}text(){const t=this.orientation===r3.VERTICAL,r=this.points[this.row][this.col],s=t?r.xMin:r.yMin,o=t?r.xMax:r.yMax;return{...super.text(),range:{min:s,max:o}}}}const Cj="Type",qH=/[ML]\s*(-?\d+(\.\d+)?)\s+(-?\d+(\.\d+)?)/g;class $H extends f9{constructor(r){super(r);oe(this,"points");oe(this,"lineValues");oe(this,"highlightValues");oe(this,"min");oe(this,"max");this.points=r.data,this.lineValues=this.points.map(s=>s.map(o=>Number(o.y))),this.min=this.lineValues.map(s=>z3.safeMin(s)),this.max=this.lineValues.map(s=>z3.safeMax(s)),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],s=r.fill?{fill:{label:Cj,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},...s}}moveOnce(r){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(r)){this.notifyOutOfBounds();return}if(r==="UPWARD"||r==="DOWNWARD"){const s=this.findNearestLineByYValue(r);if(s!==null&&s!==this.row){this.row=s,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[s,o]=r;return s>=0&&s<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 s=this.col,o=this.values[this.row][s];let a=null,i=Number.POSITIVE_INFINITY;for(let l=0;l<this.values.length;l++){if(l===this.row||s>=this.values[l].length)continue;const T=this.values[l][s];if(!(r==="UPWARD"?T>o:T<o))continue;const Q=Math.abs(T-o);Q<i&&(i=Q,a=l)}return a}mapToSvgElements(r){if(!r||r.length!==this.lineValues.length)return null;const s=new Array;for(let o=0;o<r.length;o++){const a=u2.selectElement(r[o],!1);if(!a)return null;const i=new Array;if(a instanceof SVGPathElement){const T=a.getAttribute(xe.D)||xe.EMPTY;let u=qH.exec(T);for(;u!==null;)i.push({x:Number.parseFloat(u[1]),y:Number.parseFloat(u[3])}),u=qH.exec(T)}else if(a instanceof SVGPolylineElement){const u=(a.getAttribute(xe.POINTS)||xe.EMPTY).split(/\s+/).filter(Boolean);for(const Q of u){const[f,h]=Q.split(xe.COMMA);i.push({x:Number.parseFloat(f),y:Number.parseFloat(h)})}}if(i.length!==this.lineValues[o].length)return null;const l=new Array;for(const T of i){if(Number.isNaN(T.x)||Number.isNaN(T.y))return null;l.push(u2.createCircleElement(T.x,T.y,a))}s.push(l)}return s}}class wj extends f9{constructor(r){super(r);oe(this,"mode");oe(this,"xPoints");oe(this,"yPoints");oe(this,"xValues");oe(this,"yValues");oe(this,"highlightXValues");oe(this,"highlightYValues");oe(this,"minX");oe(this,"maxX");oe(this,"minY");oe(this,"maxY");this.mode="column";const s=r.data,o=[...s].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=[...s].sort((T,u)=>T.y-u.y||T.x-u.x);this.yPoints=new Array;let l=null;for(const T of i)(!l||l.y!==T.y)&&(l={y:T.y,x:[]},this.yPoints.push(l)),l.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(s=>s.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(r=>r.forEach(s=>s.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],s=r.y[Math.floor(r.y.length/2)];this.row=this.yValues.indexOf(s),this.mode="row"}else{const r=this.yPoints[this.row],s=r.x[Math.floor(r.x.length/2)];this.col=this.xValues.indexOf(s),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 s=u2.selectAllElements(r);if(s.length===0)return[null,null];const o=new Map,a=new Map;s.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),l=Array.from(a.entries()).sort(([T],[u])=>u-T).map(([T,u])=>u);return[i,l]}}const UH="Sum",Vj="Level",Dj="undefined";class Rj extends Qg{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 l=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(l)}this.points.push(r),this.barValues.push(t);const{min:s,max:o}=z3.minMax(t);this.min.push(s),this.max.push(o)}text(){return{...super.text(),fill:{label:Vj,value:this.points[this.row][this.col].fill??Dj}}}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=u2.selectAllElements(t);if(r.length===0)return new Array;const s=new Array;if(r[0]instanceof SVGPathElement)for(let o=0,a=0;o<this.barValues.length;o++){const i=new Array;for(let l=0;l<this.barValues[o].length;l++){if(a>=r.length)return new Array;this.barValues[o][l]===0?i.push(u2.createEmptyElement()):i.push(r[a++])}s.push(i)}else if(r[0]instanceof SVGRectElement){for(let o=0;o<this.barValues.length;o++)s.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?s[i].push(u2.createEmptyElement()):s[i].push(r[a++])}}return s}}class kj extends $H{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],r=this.col,s=l=>t[Math.max(0,Math.min(l,t.length-1))],o=r>0?s(r-1):s(r),a=s(r),i=r<t.length-1?s(r+1):s(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 Nj{static create(t){switch(t.type){case R2.BAR:return new yj(t);case R2.BOX:return new Mj(t);case R2.CANDLESTICK:return new _j(t);case R2.HEATMAP:return new Aj(t);case R2.HISTOGRAM:return new Oj(t);case R2.LINE:return new $H(t);case R2.SCATTER:return new wj(t);case R2.SMOOTH:return new kj(t);case R2.DODGED:case R2.NORMALIZED:case R2.STACKED:return new Rj(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const Bj="MAIDR Plot",Pj="unavailable",jj="unavailable";class Ij extends Tg{constructor(r){super();oe(this,"id");oe(this,"title");oe(this,"subtitle");oe(this,"caption");oe(this,"subplots");oe(this,"size");this.id=r.id,this.title=r.title??Bj,this.subtitle=r.subtitle??Pj,this.caption=r.caption??jj;const s=r.subplots;this.subplots=s.map(o=>o.map(a=>new Fj(a))),this.size=this.subplots.reduce((o,a)=>o+a.length,0)}dispose(){this.subplots.forEach(r=>r.forEach(s=>s.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((s,o)=>s+o.length,0);return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:r,subplot:this.activeSubplot.state,traceTypes:this.activeSubplot.traceTypes}}}class Fj extends Tg{constructor(r){super();oe(this,"traces");oe(this,"traceTypes");oe(this,"size");this.isInitialEntry=!1;const s=r.layers;this.size=s.length,this.traces=s.map(o=>[Nj.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?xe.EMPTY:a.traceType})}dispose(){this.traces.forEach(r=>r.forEach(s=>s.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][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}}}const es=class es{constructor(){oe(this,"basePalette");oe(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 s=this.generateExtendedEntry(t);return this.extendedPalette.set(t,s),s}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,s)=>{this.extendedPalette.set(this.basePalette.length+s,r)})}generateExtendedEntry(t){const r=t%this.basePalette.length,s=this.basePalette[r],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,s.timbreModulation);return{waveType:s.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const r=[],s=es.MIN_HARMONICS+t%es.HARMONIC_VARIATION;for(let o=0;o<s;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 s=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,r.attack*s)),decay:Math.max(.05,Math.min(.3,r.decay*s)),sustain:Math.max(.4,Math.min(.9,r.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,r.release*s))}}};oe(es,"MIN_HARMONICS",2),oe(es,"HARMONIC_VARIATION",3);let fg=es;const GH=200,ZH=1e3,zj=100,qj=440,$j=880,XH=.3,Uj=.5;class Gj{constructor(t,r){oe(this,"notification");oe(this,"audioPalette");oe(this,"isCombinedAudio");oe(this,"mode");oe(this,"activeAudioIds");oe(this,"volume");oe(this,"audioContext");oe(this,"compressor");this.notification=t,this.audioPalette=new fg,this.isCombinedAudio=!1,this.mode="on",this.updateMode(r),this.activeAudioIds=new Map,this.volume=Uj,this.audioContext=new AudioContext,this.compressor=this.initCompressor()}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close())}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"))}update(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,s=r.groupIndex,a=s!==void 0?this.audioPalette.getPaletteEntry(s):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 l=0;const T=this.mode==="on"?50:0,u=new Array,Q=()=>{if(l<i.length){const f=Array.isArray(r.index)?r.index[l]:r.index;this.playTone(r.min,r.max,i[l++],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 l=Array.isArray(r.index)?r.index[0]:r.index;this.playTone(r.min,r.max,i,r.size,l,a)}}}playTone(t,r,s,o,a,i){const l={min:t,max:r},T={min:GH,max:ZH},u=this.interpolate(s,l,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 s=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=r,s.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,s.push(i)}return s}createGainNodes(t,r,s,o){const a=[],i=this.audioContext.currentTime;for(let l=0;l<t.length;l++){const T=this.audioContext.createGain();let u=s;if(l===0)r.harmonicMix&&(u*=r.harmonicMix.fundamental);else{const f=r.harmonicMix.harmonics[l-1];u*=f.amplitude}const Q=this.createAdsrEnvelope(T,r,u,i,o);Q!==null&&T.gain.setValueCurveAtTime(Q,i,o),a.push(T)}return a}playOscillator(t,r=0,s){const o=XH,a=this.volume;s||(s={waveType:"sine"});const i=this.createOscillators(s,t),l=this.createGainNodes(i,s,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(l[h]),l[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++)l[p].disconnect(T),i[p].stop(),i[p].disconnect(l[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),o*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,r,s,o,a){if(r!=null&&r.timbreModulation){const{attack:i,decay:l,sustain:T,release:u}=r.timbreModulation,Q=a*i,f=a*l,h=a*u,p=a-Q-f-h;return t.gain.setValueAtTime(1e-4*s,o),t.gain.linearRampToValueAtTime(s,o+Q),t.gain.linearRampToValueAtTime(T*s,o+Q+f),p>0&&t.gain.setValueAtTime(T*s,o+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*s,o+a),null}else return[.5*s,s,.5*s,.5*s,.5*s,.1*s,1e-4*s]}playSmooth(t,r,s,o,a,i){const l=this.audioContext,T=l.currentTime,u=XH,Q=(i==null?void 0:i.waveType)||"sine",f=t.map(M=>this.interpolate(M,{min:r,max:s},{min:GH,max:ZH}));f.length<2&&f.push(f[0]);const h=this.clamp(this.interpolate(a,{min:0,max:o-1},{min:-1,max:1}),-1,1),p=l.createOscillator();p.type=Q,p.frequency.setValueCurveAtTime(f,T,u);const v=l.createGain(),g=this.createAdsrEnvelope(v,i,this.volume,T,u);g!==null&&v.gain.setValueCurveAtTime(g,T,u);const b=l.createStereoPanner();b.pan.value=h,p.connect(v),v.connect(b),b.connect(this.compressor),p.start(T),p.stop(T+u);const L=setTimeout(()=>{p.disconnect(),v.disconnect(),b.disconnect(),this.activeAudioIds.delete(L)},u*1e3*2);this.activeAudioIds.set(L,[p])}playEmptyTone(t,r){const s=this.audioContext,o=s.currentTime,a=.2,i=[500,1e3,1500,2100,2700],l=[1,.6,.4,.2,.1],T=s.createGain();T.gain.setValueAtTime(.3,o),T.gain.exponentialRampToValueAtTime(.01,o+a),T.connect(this.compressor);const u={min:0,max:t},Q={min:-1,max:1},f=this.clamp(this.interpolate(r,u,Q),-1,1),h=[];for(let g=0;g<i.length;g++){const b=s.createOscillator(),L=s.createGain(),M=this.audioContext.createStereoPanner(),A=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});b.frequency.value=i[g],b.type="sine",L.gain.setValueAtTime(l[g]*this.volume,o),L.gain.exponentialRampToValueAtTime(.001,o+a),M.pan.value=f,b.connect(L),L.connect(M),M.connect(A),A.connect(T),b.start(o),b.stop(o+a),h.push(b)}const p=g=>{T.disconnect(),h.forEach(b=>{b.disconnect()}),this.activeAudioIds.delete(g)},v=setTimeout(()=>p(v),a*1e3*2);return this.activeAudioIds.set(v,h),v}playZeroTone(){return this.playOscillator(zj,0,{waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(qj,0,{waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator($j,0,{waveType:"sine"})}interpolate(t,r,s){return r.min===0&&r.max===0?0:(t-r.min)/(r.max-r.min)*(s.max-s.min)+s.min}clamp(t,r,s){return Math.max(r,Math.min(t,s))}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(s=>{const o=this.activeAudioIds.get(s);if(!o){clearInterval(s);return}o.forEach(a=>{a==null||a.disconnect(),a==null||a.stop()}),clearTimeout(s),this.activeAudioIds.delete(s)})}stopAll(){this.activeAudioIds.entries().forEach(([t,r])=>{clearTimeout(t),r.forEach(s=>{s.disconnect(),s.stop()})}),this.activeAudioIds.clear()}setVolume(t){this.volume=Math.min(Math.max(t/100,0),1)}}const Zj=250,Xj=50,Wj=500,Yj=4e3,Kj=20;class Jj{constructor(t,r){oe(this,"context");oe(this,"notification");oe(this,"autoplayId");oe(this,"currentDirection");oe(this,"userSpeed");oe(this,"defaultSpeed");oe(this,"minSpeed");oe(this,"maxSpeed");oe(this,"autoplayRate");oe(this,"totalDuration");oe(this,"interval");oe(this,"onChangeEmitter");oe(this,"onChange");this.notification=r,this.context=t,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Zj,this.minSpeed=Xj,this.maxSpeed=Wj,this.autoplayRate=this.defaultSpeed,this.totalDuration=Yj,this.interval=Kj,this.onChangeEmitter=new Q9,this.onChange=this.onChangeEmitter.event}dispose(){this.stop(),this.onChangeEmitter.dispose()}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 s=Math.ceil(this.totalDuration/r.autoplay[t]);return this.defaultSpeed=s,this.minSpeed=Math.min(this.minSpeed,s),s}return this.defaultSpeed}}const WH=32;class bc{encode(t){const r=new Array,s=new Array,o=new Array;for(let a=0;a<t.values.length;a++){s.push(new Array);const i=(t.max[a]-t.min[a])/4,l=t.min[a]+i,T=l+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]<=l||t.values[a][Q]<=T?r.push("⠤"):t.values[a][Q]<=u?r.push("⠒"):r.push("⠉"),s[a].push(o.length),o.push({row:a,col:Q});r.push(xe.NEW_LINE),s[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(xe.EMPTY),cellToIndex:s,indexToCell:o}}}class eI{constructor(){oe(this,"GLOBAL_MIN","globalMin");oe(this,"GLOBAL_MAX","globalMax");oe(this,"BLANK","blank");oe(this,"LOWER_OUTLIER","lowerOutlier");oe(this,"UPPER_OUTLIER","upperOutlier");oe(this,"MIN","min");oe(this,"MAX","max");oe(this,"Q1","q1");oe(this,"Q2","q2");oe(this,"Q3","q3")}encode(t,r=WH){const s=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){const l=t.values[i],T=[{type:this.GLOBAL_MIN,value:t.min},...l.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:l.min},{type:this.Q1,value:l.q1},{type:this.Q2,value:l.q2},{type:this.Q3,value:l.q3},{type:this.MAX,value:l.max},...l.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,v,g]=[-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&&(v=V),u[V].type===this.Q3&&(g=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++)),v!==-1&&g!==-1&&u[v].length!==u[g].length&&(u[v].length>u[g].length?(u[v].numChars++,f++):(u[g].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]=s.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="⠀"),s.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}}s.push(xe.NEW_LINE),o.push({row:i,col:E})}return{value:s.join(xe.EMPTY),cellToIndex:a,indexToCell:o}}}class tI{encode(t){const r=new Array,s=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,l=i+a;for(let T=0;T<t.values.length;T++){s.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]<=l?r.push("⠒"):r.push("⠉"),s[T].push(o.length),o.push({row:T,col:u});r.push(xe.NEW_LINE),s[T].push(o.length),o.push({row:T,col:t.values[T].length})}return{value:r.join(xe.EMPTY),cellToIndex:s,indexToCell:o}}}class YH{encode(t){const r=new Array,s=new Array,o=new Array;for(let a=0;a<t.values.length;a++){s.push(new Array);const{low:i,medium:l,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,l,T,u);r.push(p),s[a].push(o.length),o.push({row:a,col:Q})}r.push(xe.NEW_LINE),s[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:r.join(xe.EMPTY),cellToIndex:s,indexToCell:o}}getBrailleChar(t,r,s,o,a,i){return t<=s&&r!==null&&r>s?r<=o?"⢄":r<=a?"⢆":"⢇":t<=s?"⣀":r!==null&&r<=s?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 nI extends YH{getThresholds(t,r){const s=(r.max-r.min)/4,o=r.min+s,a=o+s,i=a+s,l=r.max;return{low:o,medium:a,mediumHigh:i,high:l}}}class rI extends YH{getThresholds(t,r){const s=(r.max[t]-r.min[t])/4,o=r.min[t]+s,a=o+s,i=a+s,l=r.max[t];return{low:o,medium:a,mediumHigh:i,high:l}}}class iI{constructor(t,r,s){oe(this,"context");oe(this,"notification");oe(this,"display");oe(this,"enabled");oe(this,"cacheId");oe(this,"cache");oe(this,"encoders");oe(this,"onChangeEmitter");oe(this,"onChange");this.context=t,this.notification=r,this.display=s,this.enabled=!1,this.cacheId=xe.EMPTY,this.cache=null,this.encoders=new Map([[R2.BAR,new bc],[R2.BOX,new eI],[R2.CANDLESTICK,new nI],[R2.DODGED,new bc],[R2.HEATMAP,new tI],[R2.HISTOGRAM,new bc],[R2.LINE,new rI],[R2.NORMALIZED,new bc],[R2.STACKED,new bc]]),this.onChangeEmitter=new Q9,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 s=r.braille;if(this.cacheId!==s.id||this.cache===null){const o=this.encoders.get(r.traceType);this.cache=o.encode(s,WH),this.cacheId=s.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[s.row][s.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:r,col:s}=this.cache.indexToCell[t];this.context.moveToIndex(r,s)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const s=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(s);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 KH=(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))(KH||{});class JH{constructor(){}static async post(t,r,s){const o={...this.DEFAULT_HEADERS,...s};return this.request(t,"POST",o,r)}static async request(t,r,s,o){try{const a=await fetch(t,{method:r,headers:s,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:KH.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}oe(JH,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const aI=`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
|