maidr 3.18.1 → 3.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/maidr.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function(Ar){typeof define=="function"&&define.amd?define(Ar):Ar()})(function(){"use strict";var Qoe=Object.defineProperty;var foe=(Ar,S4,H1)=>S4 in Ar?Qoe(Ar,S4,{enumerable:!0,configurable:!0,writable:!0,value:H1}):Ar[S4]=H1;var ae=(Ar,S4,H1)=>foe(Ar,typeof S4!="symbol"?S4+"":S4,H1);function Ar(e,t){for(var n=0;n<t.length;n++){const l=t[n];if(typeof l!="string"&&!Array.isArray(l)){for(const o in l)if(o!=="default"&&!(o in e)){const a=Object.getOwnPropertyDescriptor(l,o);a&&Object.defineProperty(e,o,a.get?a:{enumerable:!0,get:()=>l[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var S4=(e=>(e.CLICK="click",e.DOM_LOADED="DOMContentLoaded",e.FOCUS_IN="focusin",e.FOCUS_OUT="focusout",e.SELECTION_CHANGE="selectionchange",e))(S4||{}),H1=(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))(H1||{});class Ms{constructor(){ae(this,"listeners");ae(this,"event",t=>(this.listeners.add(t),{dispose:()=>this.listeners.delete(t)}));this.listeners=new Set}dispose(){this.listeners.clear()}fire(t){for(const n of this.listeners)n(t)}}class xe{constructor(){}}ae(xe,"ARTICLE","article"),ae(xe,"DIV","div"),ae(xe,"FIGURE","figure"),ae(xe,"IMAGE","img"),ae(xe,"INPUT","input"),ae(xe,"TEXT_AREA","textarea"),ae(xe,"BRAILLE_TEXT_AREA","maidr-braille-textarea"),ae(xe,"MAIDR_ARTICLE","maidr-article"),ae(xe,"MAIDR_FIGURE","maidr-figure"),ae(xe,"MAIDR_HIGHLIGHT","maidr-highlight"),ae(xe,"REACT_CONTAINER","maidr-react-container"),ae(xe,"REVIEW_INPUT","maidr-review-input"),ae(xe,"TEXT_CONTAINER","maidr-text-container"),ae(xe,"ARIA_LABEL","aria-label"),ae(xe,"CIRCLE_X","cx"),ae(xe,"CIRCLE_Y","cy"),ae(xe,"D","d"),ae(xe,"FILL","fill"),ae(xe,"POINTS","points"),ae(xe,"RADIUS","r"),ae(xe,"ROLE","role"),ae(xe,"STROKE","stroke"),ae(xe,"STROKE_WIDTH","stroke-width"),ae(xe,"TITLE","title"),ae(xe,"VISIBILITY","visibility"),ae(xe,"X1","x1"),ae(xe,"X2","x2"),ae(xe,"Y1","y1"),ae(xe,"Y2","y2"),ae(xe,"MAIDR_SUBPLOT","subplot"),ae(xe,"AFTER_END","afterend"),ae(xe,"APPLICATION","application"),ae(xe,"ARE"," are "),ae(xe,"CIRCLE","circle"),ae(xe,"CLOSE_BRACKET","]"),ae(xe,"COMMA",","),ae(xe,"COMMA_SPACE",", "),ae(xe,"EMPTY",""),ae(xe,"HIDDEN","hidden"),ae(xe,"IS"," is "),ae(xe,"LINE","line"),ae(xe,"MAIDR_DATA","maidr-data"),ae(xe,"MAIDR_HIGHLIGHT_COLOR","#BADA55"),ae(xe,"NEW_LINE",`
2
- `),ae(xe,"OPEN_BRACKET","["),ae(xe,"POLYLINE","polyline"),ae(xe,"SPACE"," "),ae(xe,"THROUGH"," through "),ae(xe,"TRANSPARENT","transparent"),ae(xe,"VISIBLE","visible"),ae(xe,"X","x"),ae(xe,"Y","y"),ae(xe,"HIGHLIGHT_BASE_COLOR",{r:255,g:255,b:255}),ae(xe,"HIGHLIGHT_CONTRAST_RATIO",3),ae(xe,"HIGHLIGHT_COLOR_RATIO",.6),ae(xe,"HIGHLIGHT_MAX_COLOR",255);let pv=class{constructor(){ae(this,"items");this.items=new Array}push(t){this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}removeLast(t,n=1){const l=this.items.lastIndexOf(t);return l!==-1?(this.items.splice(l,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}};const mv=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function yv(e,t,n,l){e.addEventListener?e.addEventListener(t,n,l):e.attachEvent&&e.attachEvent("on".concat(t),n)}function _c(e,t,n,l){e.removeEventListener?e.removeEventListener(t,n,l):e.detachEvent&&e.detachEvent("on".concat(t),n)}function WH(e,t){const n=t.slice(0,t.length-1);for(let l=0;l<n.length;l++)n[l]=e[n[l].toLowerCase()];return n}function YH(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function HI(e,t){const n=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let o=!0;for(let a=0;a<n.length;a++)l.indexOf(n[a])===-1&&(o=!1);return o}const Oc={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,"-":mv?173:189,"=":mv?61:187,";":mv?59:186,"'":222,"[":219,"]":221,"\\":220},c5={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Cc={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},_3={16:!1,18:!1,17:!1,91:!1},b2={};for(let e=1;e<20;e++)Oc["f".concat(e)]=111+e;let p2=[],wc=null,KH="all";const wi=new Map,Vc=e=>Oc[e.toLowerCase()]||c5[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),SI=e=>Object.keys(Oc).find(t=>Oc[t]===e),EI=e=>Object.keys(c5).find(t=>c5[t]===e);function JH(e){KH=e||"all"}function Dc(){return KH||"all"}function MI(){return p2.slice(0)}function AI(){return p2.map(e=>SI(e)||EI(e)||String.fromCharCode(e))}function _I(){const e=[];return Object.keys(b2).forEach(t=>{b2[t].forEach(n=>{let{key:l,scope:o,mods:a,shortcut:i}=n;e.push({scope:o,shortcut:i,mods:a,keys:l.split("+").map(s=>Vc(s))})})}),e}function OI(e){const t=e.target||e.srcElement,{tagName:n}=t;let l=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(l=!1),l}function CI(e){return typeof e=="string"&&(e=Vc(e)),p2.indexOf(e)!==-1}function wI(e,t){let n,l;e||(e=Dc());for(const o in b2)if(Object.prototype.hasOwnProperty.call(b2,o))for(n=b2[o],l=0;l<n.length;)n[l].scope===e?n.splice(l,1).forEach(i=>{let{element:s}=i;return gv(s)}):l++;Dc()===e&&JH(t||"all")}function VI(e){let t=e.keyCode||e.which||e.charCode;const n=p2.indexOf(t);if(n>=0&&p2.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&p2.splice(0,p2.length),(t===93||t===224)&&(t=91),t in _3){_3[t]=!1;for(const l in c5)c5[l]===t&&(q3[l]=!1)}}function eS(e){if(typeof e>"u")Object.keys(b2).forEach(o=>{Array.isArray(b2[o])&&b2[o].forEach(a=>Ep(a)),delete b2[o]}),gv(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Ep(o)});else if(typeof e=="object")e.key&&Ep(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),l=1;l<t;l++)n[l-1]=arguments[l];let[o,a]=n;typeof o=="function"&&(a=o,o=""),Ep({key:e,scope:o,method:a,splitKey:"+"})}}const Ep=e=>{let{key:t,scope:n,method:l,splitKey:o="+"}=e;YH(t).forEach(i=>{const s=i.split(o),c=s.length,u=s[c-1],Q=u==="*"?"*":Vc(u);if(!b2[Q])return;n||(n=Dc());const f=c>1?WH(c5,s):[],h=[];b2[Q]=b2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===n&&HI(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>gv(p))})};function tS(e,t,n,l){if(t.element!==l)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const a in _3)Object.prototype.hasOwnProperty.call(_3,a)&&(!_3[a]&&t.mods.indexOf(+a)>-1||_3[a]&&t.mods.indexOf(+a)===-1)&&(o=!1);(t.mods.length===0&&!_3[16]&&!_3[18]&&!_3[17]&&!_3[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(p2),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function nS(e,t){const n=b2["*"];let l=e.keyCode||e.which||e.charCode;if(!q3.filter.call(this,e))return;if((l===93||l===224)&&(l=91),p2.indexOf(l)===-1&&l!==229&&p2.push(l),["metaKey","ctrlKey","altKey","shiftKey"].forEach(s=>{const c=Cc[s];e[s]&&p2.indexOf(c)===-1?p2.push(c):!e[s]&&p2.indexOf(c)>-1?p2.splice(p2.indexOf(c),1):s==="metaKey"&&e[s]&&(p2=p2.filter(u=>u in Cc||u===l))}),l in _3){_3[l]=!0;for(const s in c5)if(Object.prototype.hasOwnProperty.call(c5,s)){const c=Cc[c5[s]];q3[s]=e[c]}if(!n)return}for(const s in _3)Object.prototype.hasOwnProperty.call(_3,s)&&(_3[s]=e[Cc[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(p2.indexOf(17)===-1&&p2.push(17),p2.indexOf(18)===-1&&p2.push(18),_3[17]=!0,_3[18]=!0);const o=Dc();if(n)for(let s=0;s<n.length;s++)n[s].scope===o&&(e.type==="keydown"&&n[s].keydown||e.type==="keyup"&&n[s].keyup)&&tS(e,n[s],o,t);if(!(l in b2))return;const a=b2[l],i=a.length;for(let s=0;s<i;s++)if((e.type==="keydown"&&a[s].keydown||e.type==="keyup"&&a[s].keyup)&&a[s].key){const c=a[s],{splitKey:u}=c,Q=c.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(Vc(Q[h]));f.sort().join("")===p2.sort().join("")&&tS(e,c,o,t)}}function q3(e,t,n){p2=[];const l=YH(e);let o=[],a="all",i=document,s=0,c=!1,u=!0,Q="+",f=!1,h=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(a=t.scope),t.element&&(i=t.element),t.keyup&&(c=t.keyup),t.keydown!==void 0&&(u=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(Q=t.splitKey),t.single===!0&&(h=!0)),typeof t=="string"&&(a=t),h&&eS(e,a);s<l.length;s++)e=l[s].split(Q),o=[],e.length>1&&(o=WH(c5,e)),e=e[e.length-1],e=e==="*"?"*":Vc(e),e in b2||(b2[e]=[]),b2[e].push({keyup:c,keydown:u,scope:a,mods:o,shortcut:l[s],method:n,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!wi.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return nS(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;nS(v,i),VI(v)};wi.set(i,{keydownListener:p,keyupListenr:g,capture:f}),yv(i,"keydown",p,f),yv(i,"keyup",g,f)}if(!wc){const p=()=>{p2=[]};wc={listener:p,capture:f},yv(window,"focus",p,f)}}}function DI(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(b2).forEach(n=>{b2[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function gv(e){const t=Object.values(b2).flat();if(t.findIndex(l=>{let{element:o}=l;return o===e})<0){const{keydownListener:l,keyupListenr:o,capture:a}=wi.get(e)||{};l&&o&&(_c(e,"keyup",o,a),_c(e,"keydown",l,a),wi.delete(e))}if((t.length<=0||wi.size<=0)&&(Object.keys(wi).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:s}=wi.get(o)||{};a&&i&&(_c(o,"keyup",i,s),_c(o,"keydown",a,s),wi.delete(o))}),wi.clear(),Object.keys(b2).forEach(o=>delete b2[o]),wc)){const{listener:o,capture:a}=wc;_c(window,"focus",o,a),wc=null}}const vv={getPressedKeyString:AI,setScope:JH,getScope:Dc,deleteScope:wI,getPressedKeyCodes:MI,getAllKeyCodes:_I,isPressed:CI,filter:OI,trigger:DI,unbind:eS,keyMap:Oc,modifier:c5,modifierMap:Cc};for(const e in vv)Object.prototype.hasOwnProperty.call(vv,e)&&(q3[e]=vv[e]);if(typeof window<"u"){const e=window.hotkeys;q3.noConflict=t=>(t&&window.hotkeys===q3&&(window.hotkeys=e),q3),window.hotkeys=q3}class RI{constructor(t){ae(this,"id");ae(this,"instructionContext");ae(this,"plotContext");ae(this,"scopeContext");this.id=t.id,this.plotContext=new pv,this.scopeContext=new pv;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(H1.SUBPLOT);return}this.scopeContext.push(H1.TRACE);const l=t.activeSubplot.state;if(l.empty||l.size!==1){this.instructionContext=t.activeSubplot,this.plotContext.push(t.activeSubplot),this.plotContext.push(t.activeSubplot.activeTrace);return}this.instructionContext=t.activeSubplot.activeTrace,this.plotContext.push(t.activeSubplot.activeTrace)}dispose(){this.plotContext.clear(),this.scopeContext.clear()}get active(){return this.plotContext.peek()}get state(){return this.active.state}toggleScope(t){this.scopeContext.removeLast(t)||this.scopeContext.push(t),q3.setScope(this.scope)}get scope(){return this.scopeContext.peek()}isMovable(t){return this.active.isMovable(t)}moveOnce(t){this.active.moveOnce(t)}moveToExtreme(t){this.active.moveToExtreme(t)}moveToIndex(t,n){this.active.moveToIndex(t,n)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const n=this.active,o=n.activeTrace.getCurrentXValue();n.moveOnce(t);const a=n.activeTrace;this.plotContext.push(a),a.moveToXValue(o)}}enterSubplot(){if(this.active.state.type==="figure"){const n=this.active;this.plotContext.push(n.activeSubplot),this.active.notifyStateUpdate(),this.plotContext.push(n.activeSubplot.activeTrace),this.toggleScope(H1.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(H1.TRACE))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const l=t?"Click to activate.":xe.EMPTY;switch(n.type){case"figure":return`This is a MAIDR figure containing ${n.size} subplots. ${l} Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a MAIDR subplot containing ${n.size} layers, and this is layer 1 of ${n.size}: ${n.trace.traceType} plot. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`;case"trace":return`This is a maidr plot of type: ${n.plotType}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}var B2=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(B2||{}),P2=(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))(P2||{});function kI(e){return e!==null&&typeof e=="object"&&"x"in e}function NI(e){return typeof e=="string"||typeof e=="number"}function BI(e){return e!==null&&typeof e=="object"&&"x"in e}class rS{computeIndexAndSegment(t,n,l,o){return l===B2.HORIZONTAL?{pointIndex:t,segmentType:o[n]}:{pointIndex:n,segmentType:o[t]}}computeVisualCoordinates(t,n,l){return l===B2.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const o=t[0][l];return this.extractXFromPoint(o)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][l]){const o=t[n][l];return this.extractXFromPoint(o)}return null}extractXValueFromValues(t,n,l){if(this.isValidPosition(t,n,l)){const o=t[n][l];return this.extractXFromValue(o)}return null}moveToXValueInPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const c=this.findPointIndexByX(t[0],n);if(c!==-1)return l(0,c),!0;{const u=this.findNearestPointIndexByX(t[0],n);if(u!==-1){const Q=_r(t[0][u]);if(typeof n=="number"&&typeof Q=="number")return l(0,u),!0;if(typeof n=="string"&&typeof Q=="string")return l(0,u),!0}}}let o=-1,a=-1,i=Number.POSITIVE_INFINITY,s=null;if(Array.isArray(t))for(let c=0;c<t.length;c++){const u=t[c];if(Array.isArray(u)){const Q=this.findPointIndexByX(u,n);if(Q!==-1)return l(c,Q),!0;const f=this.findNearestPointIndexByX(u,n);if(f!==-1){const h=_r(u[f]);let p=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof h=="number"?(p=Math.abs(h-n),p<i&&(i=p,o=c,a=f,s="numeric")):typeof n=="string"&&typeof h=="string"?o===-1&&(o=c,a=f,s="categorical"):o===-1&&(o=c,a=f,s="generic")}}}if(o!==-1&&a!==-1){const c=t[o];if(Array.isArray(c)&&_r(c[a]),s!==null)return l(o,a),!0}return!1}moveToXValueInValues(t,n,l){let o=-1,a=-1,i=Number.POSITIVE_INFINITY,s=null;for(let c=0;c<t.length;c++)for(let u=0;u<t[c].length;u++){const Q=t[c][u],f=this.extractXFromValue(Q);if(f===n)return l(c,u),!0;if(typeof n=="number"&&typeof f=="number"){const h=Math.abs(f-n);h<i&&(i=h,o=c,a=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?o===-1&&(o=c,a=u,s="categorical"):o===-1&&(o=c,a=u,s="generic")}return o!==-1&&a!==-1?(this.extractXFromValue(t[o][a]),l(o,a),!0):!1}extractXFromPoint(t){return BI(t)?t.x:null}extractXFromValue(t){return kI(t)?t.x:NI(t)?t:null}findPointIndexByX(t,n){return t.findIndex(l=>l.x===n)}isValidPosition(t,n,l){return n>=0&&n<t.length&&l>=0&&l<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let l=-1,o=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a++){const i=_r(t[a]);if(typeof i=="number"){const s=Math.abs(i-n);s<o&&(o=s,l=a)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<o&&(o=c,l=a)}}}if(l!==-1)return _r(t[l]),l}else if(typeof n=="string"){for(let o=0;o<t.length;o++)if(_r(t[o])===n)return o;const l=Number(n);if(!Number.isNaN(l)){let o=-1,a=Number.POSITIVE_INFINITY;for(let i=0;i<t.length;i++){const s=_r(t[i]);if(typeof s=="number"){const c=Math.abs(s-l);c<a&&(a=c,o=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-l);u<a&&(a=u,o=i)}}}if(o!==-1)return _r(t[o]),o}for(let o=0;o<t.length;o++)if(typeof _r(t[o])=="string")return o}return t.length>0?(_r(t[0]),0):-1}dispose(){}}function PI(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function II(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function jI(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function FI(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function zI(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function qI(e){return e&&typeof e=="object"&&"value"in e}function _r(e){return e?PI(e)||II(e)||FI(e)||zI(e)||jI(e)?e.x:qI(e)?e.value:null:null}const $I="unavailable",UI="X",GI="Y",ZI="unavailable";class Lv{constructor(){ae(this,"observers");ae(this,"isInitialEntry");ae(this,"isOutOfBounds");ae(this,"row");ae(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}getSafeIndices(){var o;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,l=this.col>=0&&this.col<(((o=t[n])==null?void 0:o.length)||0)?this.col:0;return{row:n,col:l}}moveToExtreme(t){var n;switch(this.isInitialEntry&&this.handleInitialEntry(),t){case"UPWARD":this.row=this.values.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":{const{row:l}=this.getSafeIndices();this.col=(n=this.values[l])!=null&&n.length?this.values[l].length-1:0;break}case"BACKWARD":this.col=0;break}this.notifyStateUpdate()}moveToIndex(t,n){this.isMovable([t,n])&&(this.row=t,this.col=n,this.isInitialEntry=!1,this.notifyStateUpdate())}isMovable(t){var n,l;if(Array.isArray(t)){const[o,a]=t,{row:i}=this.getSafeIndices();return o>=0&&o<this.values.length&&a>=0&&a<(((n=this.values[i])==null?void 0:n.length)||0)}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":{const{row:o}=this.getSafeIndices();return this.col<(((l=this.values[o])==null?void 0:l.length)||0)-1}case"BACKWARD":return this.col>0}}handleInitialEntry(){var n;this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.values.length-1));const{row:t}=this.getSafeIndices();this.col=Math.max(0,Math.min(this.col,(((n=this.values[t])==null?void 0:n.length)||0)-1))}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){const t=this.state;for(const n of this.observers)n.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}}class As extends Lv{constructor(n){var l,o,a;super();ae(this,"id");ae(this,"type");ae(this,"title");ae(this,"xAxis");ae(this,"yAxis");ae(this,"fill");ae(this,"navigationService");this.navigationService=new rS,this.id=n.id,this.type=n.type,this.title=n.title??$I,this.xAxis=((l=n.axes)==null?void 0:l.x)??UI,this.yAxis=((o=n.axes)==null?void 0:o.y)??GI,this.fill=((a=n.axes)==null?void 0:a.fill)??ZI}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(a=>a.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==null?void 0:n.length)||0,index:o}}}return{empty:!1,type:"trace",traceType:this.type,plotType:this.type,title:this.title,xAxis:this.xAxis,yAxis:this.yAxis,fill:this.fill,hasMultiPoints:this.hasMultiPoints(),audio:this.audio(),braille:this.braille(),text:this.text(),autoplay:this.autoplay,highlight:this.highlight()}}highlight(){var n;if(this.highlightValues===null||this.isInitialEntry){const{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==null?void 0:n.length)||0,index:o}}}return{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){var o;const{row:n}=this.getSafeIndices(),l=((o=this.values[n])==null?void 0:o.length)||0;return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:l,BACKWARD:l}}hasMultiPoints(){return!1}getCurrentXValue(){if(this.hasPointsArray()){const n=this.getPointsArray();if(this.isValidPointsArray(n))return this.navigationService.extractXValueFromPoints(n,this.row,this.col)}if(this.hasValuesArray()){const n=this.values;if(this.isValidValuesArray(n))return this.navigationService.extractXValueFromValues(n,this.row,this.col)}return null}moveToXValue(n){if(this.hasPointsArray()){const l=this.getPointsArray();if(this.isValidPointsArray(l))return this.navigationService.moveToXValueInPoints(l,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const l=this.values;if(this.isValidValuesArray(l))return this.navigationService.moveToXValueInValues(l,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}}class $3{constructor(){}static safeMin(t){return t.length===0?1/0:Math.min(...t)}static safeMax(t){return t.length===0?-1/0:Math.max(...t)}static minFrom2D(t){const n=t.flat();return this.safeMin(n)}static maxFrom2D(t){const n=t.flat();return this.safeMax(n)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let n=t[0],l=t[0];for(let o=1;o<t.length;o++){const a=t[o];a<n&&(n=a),a>l&&(l=a)}return{min:n,max:l}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class Mp{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[5],16)}}const l=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return l?{r:Number.parseInt(l[1],10),g:Number.parseInt(l[2],10),b:Number.parseInt(l[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const l=this.calculateLuminance(t),o=this.calculateLuminance(n);return(Math.max(l,o)+.05)/(Math.min(l,o)+.05)}static calculateLuminance(t){const[n,l,o]=[t.r,t.g,t.b].map(a=>{const i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*l+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class C1{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,a=await new Promise((c,u)=>{const Q=new Image;Q.onload=()=>c(Q),Q.onerror=()=>u(new Error("Failed to load SVG image")),Q.src=o}),i=document.createElement("canvas");[i.width,i.height]=[a.naturalWidth,a.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(a,0,0),i.toDataURL("image/jpeg",.92)):(console.error("Error converting SVG to Base 64: Canvas context unavailable"),"")}catch(n){return console.error("Error converting SVG to Base 64:",n instanceof Error?n.message:n),""}}static selectAllElements(t,n=!0){return Array.from(document.querySelectorAll(t)).map(l=>{if(!n)return l;const o=l.cloneNode(!0);return o.setAttribute(xe.VISIBILITY,xe.HIDDEN),l.insertAdjacentElement(xe.AFTER_END,o),o})}static selectElement(t,n=!0){const l=document.querySelector(t);if(!n)return l;const o=l==null?void 0:l.cloneNode(!0);return o==null||o.setAttribute(xe.VISIBILITY,xe.HIDDEN),l==null||l.insertAdjacentElement(xe.AFTER_END,o),o}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(xe.FILL,xe.TRANSPARENT),n.setAttribute(xe.STROKE,xe.TRANSPARENT),n.setAttribute(xe.VISIBILITY,xe.HIDDEN),n}static createCircleElement(t,n,l){var u;const o=window.getComputedStyle(l),a=o.stroke||o.fill,i=o.strokeWidth||"2",s=Number.parseFloat(i)*2,c=document.createElementNS(this.SVG_NAMESPACE,xe.CIRCLE);return c.setAttribute(xe.CIRCLE_X,String(t)),c.setAttribute(xe.CIRCLE_Y,String(n)),c.setAttribute(xe.RADIUS,String(s)),c.setAttribute(xe.FILL,a),c.setAttribute(xe.STROKE,a),c.setAttribute(xe.STROKE_WIDTH,i),c.setAttribute(xe.VISIBILITY,xe.HIDDEN),(u=l.parentElement)==null||u.insertAdjacentElement(xe.AFTER_END,c),c}static createLineElement(t,n){const o=t.getBBox();let a,i,s,c;switch(n){case"top":[a,i,s,c]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,s,c]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,s,c]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,s,c]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,xe.LINE);return Q.setAttribute(xe.X1,String(a)),Q.setAttribute(xe.Y1,String(i)),Q.setAttribute(xe.X2,String(s)),Q.setAttribute(xe.Y2,String(c)),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,n){const l=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),s=this.getHighlightColor(i,n);if(l.setAttribute(xe.VISIBILITY,xe.VISIBLE),l.setAttribute(xe.STROKE,s),l.setAttribute(xe.FILL,s),l.style.fill=s,l.style.stroke=s,a){const c=window.getComputedStyle(l).getPropertyValue(xe.STROKE_WIDTH);l.setAttribute(xe.STROKE_WIDTH,`${c+2}`)}return t.insertAdjacentElement(xe.AFTER_END,l),l}static getHighlightColor(t,n){const l=Mp.parse(t);if(!l||!(Mp.getContrastRatio(l,xe.HIGHLIGHT_BASE_COLOR)<xe.HIGHLIGHT_CONTRAST_RATIO))return n;const i={...l};return l.r===l.g&&l.g===l.b?(i.r=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*xe.HIGHLIGHT_COLOR_RATIO)),i.g=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*xe.HIGHLIGHT_COLOR_RATIO)),i.b=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*xe.HIGHLIGHT_COLOR_RATIO))):l.r>=l.g&&l.r>=l.b?i.r=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*xe.HIGHLIGHT_COLOR_RATIO)):l.g>=l.r&&l.g>=l.b?i.g=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*xe.HIGHLIGHT_COLOR_RATIO)):i.b=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*xe.HIGHLIGHT_COLOR_RATIO)),Mp.rgbToString(i)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",l=Mp.parse(n);return l?(.2126*l.r+.7152*l.g+.0722*l.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,n){t.style.outline=`4px solid ${n}`,t.style.outlineOffset="3px",t.style.borderRadius="3px",t.style.overflow="visible"}static removeSubplotHighlightCss(t){t.style.removeProperty("outline"),t.style.removeProperty("outline-offset"),t.style.removeProperty("border-radius"),t.style.removeProperty("overflow")}static setSubplotHighlightSvgWithAdaptiveColor(t,n,l){const o=t.querySelector("rect, path");let a="";if(o){a=window.getComputedStyle(o).getPropertyValue("fill"),(!a||a==="none"||a==="transparent"||a==="rgba(0, 0, 0, 0)")&&(l?a=window.getComputedStyle(l).getPropertyValue("fill"):a=n);const i=this.getHighlightColor(a,n);o.setAttribute("stroke",i),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}ae(C1,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class xv extends As{constructor(n,l){super(n);ae(this,"points");ae(this,"barValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"min");ae(this,"max");this.points=l,this.orientation=n.orientation??B2.VERTICAL,this.barValues=l.map(o=>o.map(a=>this.orientation===B2.VERTICAL?Number(a.y):Number(a.x))),this.min=this.barValues.map(o=>$3.safeMin(o)),this.max=this.barValues.map(o=>$3.safeMax(o)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const n=this.orientation===B2.VERTICAL,l=n?this.barValues[this.row].length:this.barValues.length,o=n?this.col:this.row,a=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:$3.safeMin(this.min),max:$3.safeMax(this.max),size:l,index:o,value:a,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){const n=this.orientation===B2.VERTICAL,l=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,a=n?l.x:l.y,i=n?this.yAxis:this.xAxis,s=n?l.y:l.x;return{main:{label:o,value:a},cross:{label:i,value:s}}}mapToSvgElements(n){if(!n)return null;const l=[C1.selectAllElements(n)];if(l.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(l[o].length!==this.points[o].length)return null;return l}}class XI extends xv{constructor(t){super(t,[t.data])}}const WI="Lower outlier(s)",YI="Upper outlier(s)",KI="Minimum",JI="Maximum",ej="25%",tj="50%",nj="75%";class rj extends As{constructor(n){super(n);ae(this,"points");ae(this,"boxValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"sections");ae(this,"min");ae(this,"max");this.points=n.data,this.orientation=n.orientation??B2.VERTICAL,this.sections=[WI,KI,ej,tj,nj,JI,YI];const l=[a=>a.lowerOutliers,a=>a.min,a=>a.q1,a=>a.q2,a=>a.q3,a=>a.max,a=>a.upperOutliers];this.orientation===B2.HORIZONTAL?this.boxValues=this.points.map(a=>l.map(i=>i(a))):this.boxValues=l.map(a=>this.points.map(i=>a(i)));const o=this.boxValues.map(a=>a.flatMap(i=>Array.isArray(i)?i:[i]));this.min=$3.minFrom2D(o),this.max=$3.maxFrom2D(o),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,l){const o=this.orientation===B2.HORIZONTAL;n=o?n:l,l=o?l:n,super.moveToIndex(n,l)}get values(){return this.boxValues}audio(){const n=this.boxValues[this.row][this.col],l=Array.isArray(n)?n.map(o=>o-this.min):n-this.min;return{min:this.min,max:this.max,value:n,size:this.max-this.min,index:l}}braille(){const n=this.orientation===B2.HORIZONTAL,l=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:l,col:o}}text(){const n=this.orientation===B2.HORIZONTAL,l=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,a=n?this.sections[this.col]:this.sections[this.row],i=n?this.xAxis:this.yAxis,s=this.boxValues[this.row][this.col];return{main:{label:o,value:l.fill},cross:{label:i,value:s},section:a}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const l=this.orientation===B2.VERTICAL,o=new Array;if(l)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:n.length}));return n.forEach((a,i)=>{const s=a.lowerOutliers.flatMap(b=>C1.selectAllElements(b)),c=a.upperOutliers.flatMap(b=>C1.selectAllElements(b)),u=C1.selectElement(a.min)??C1.createEmptyElement(),Q=C1.selectElement(a.max)??C1.createEmptyElement(),f=C1.selectElement(a.iq)??C1.createEmptyElement(),h=C1.selectElement(a.q2)??C1.createEmptyElement(),[p,g]=l?[C1.createLineElement(f,"top"),C1.createLineElement(f,"bottom")]:[C1.createLineElement(f,"left"),C1.createLineElement(f,"right")],v=[s,u,p,h,g,Q,c];l?v.forEach((b,L)=>{o[L][i]=b}):o.push(v)}),o}}const ij="Trend";class aj extends As{constructor(n){super(n);ae(this,"candles");ae(this,"candleValues");ae(this,"orientation");ae(this,"sections",["open","high","low","close"]);ae(this,"currentSegmentType","open");ae(this,"currentPointIndex",0);ae(this,"sortedSegmentsByPoint");ae(this,"segmentPositionMaps");ae(this,"min");ae(this,"max");ae(this,"highlightValues");ae(this,"navigationService");this.navigationService=new rS;const l=n.data;this.candles=l.map(a=>({...a,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=n.orientation??B2.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(i=>i[a])),this.min=$3.minFrom2D(this.candleValues),this.max=$3.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="open",this.orientation===B2.HORIZONTAL?this.col=0:this.row=0;const o=typeof n.selectors=="string"?n.selectors:"";this.highlightValues=this.mapToSvgElements(o)}precomputeSortedSegments(){return this.candles.map(n=>this.sections.map(o=>[o,n[o]]).sort((o,a)=>o[1]-a[1]).map(o=>o[0]))}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const l=new Map;return n.forEach((o,a)=>{l.set(o,a)}),l})}getSegmentPositionInSortedOrder(n,l){return this.segmentPositionMaps[n].get(l)??0}getSegmentTypeAtSortedPosition(n,l){return this.sortedSegmentsByPoint[n][l]??"open"}updateVisualSegmentPosition(){const n=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType);this.orientation===B2.HORIZONTAL?this.col=n:this.row=n}updateVisualPointPosition(){this.orientation===B2.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=n==="UPWARD"?l+1:l-1;if(o>=0&&o<this.sections.length)this.currentSegmentType=this.getSegmentTypeAtSortedPosition(this.currentPointIndex,o),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(l>=0&&l<this.candles.length)this.currentPointIndex=l,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[l.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[0],this.updateVisualSegmentPosition();break}case"FORWARD":{this.currentPointIndex=this.candles.length-1,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}case"BACKWARD":{this.currentPointIndex=0,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}}this.notifyStateUpdate()}moveToIndex(n,l){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:o,segmentType:a}=this.navigationService.computeIndexAndSegment(n,l,this.orientation,this.sections);this.currentPointIndex=o,this.currentSegmentType=a,this.row=n,this.col=l,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=n==="UPWARD"?l+1:l-1;return o>=0&&o<this.sections.length}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return l>=0&&l<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){const n=this.candles[this.currentPointIndex][this.currentSegmentType];return{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:n,trend:this.candles[this.currentPointIndex].trend}}braille(){const n=this.candles.map(l=>l.trend);return{empty:!1,id:this.id,values:this.candleValues,min:this.min,max:this.max,row:this.row,col:this.col,custom:n}}mapToSvgElements(n){if(!n)return null;const l=C1.selectAllElements(n),o=[];for(let a=0;a<this.sections.length;a++){o[a]=[];for(let i=0;i<this.candles.length;i++){const s=i<l.length?i:0;o[a][i]=l[s]}}return o}text(){const n=this.candles[this.currentPointIndex],l=n[this.currentSegmentType];return{main:{label:this.orientation===B2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===B2.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType,fill:{label:ij,value:n.trend}}}getCurrentTrend(){return this.candles[this.currentPointIndex].trend}getCurrentXValue(){return this.currentPointIndex>=0&&this.currentPointIndex<this.candles.length?this.candles[this.currentPointIndex].value:null}moveToXValue(n){const l=this.candles.findIndex(o=>o.value===n);return l!==-1?(this.currentPointIndex=l,this.currentSegmentType="open",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}}class oj extends As{constructor(n){super(n);ae(this,"heatmapValues");ae(this,"highlightValues");ae(this,"x");ae(this,"y");ae(this,"min");ae(this,"max");const l=n.data;this.x=l.x,this.y=[...l.y].reverse(),this.heatmapValues=[...l.points].reverse();const{min:o,max:a}=$3.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=a,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get values(){return this.heatmapValues}audio(){return{min:this.min,max:this.max,size:this.heatmapValues.length,index:this.col,value:this.heatmapValues[this.row][this.col]}}braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){return{main:{label:this.xAxis,value:this.x[this.col]},cross:{label:this.yAxis,value:this.y[this.row]},fill:{label:this.fill,value:String(this.heatmapValues[this.row][this.col])}}}mapToSvgElements(n){if(!n)return null;const l=this.heatmapValues.length,o=this.heatmapValues[0].length,a=C1.selectAllElements(n);if(a.length===0||a.length!==l*o)return null;const i=new Array;if(a[0]instanceof SVGPathElement)for(let s=0;s<l;s++){const c=l-1-s,u=new Array;for(let Q=0;Q<o;Q++){const f=c*o+Q;u.push(a[f])}i.push(u)}else if(a[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const c=new Array;for(let u=0;u<o;u++){const Q=u*l+s;c.push(a[Q])}i.push(c)}return i}}class lj extends xv{constructor(t){super(t,[t.data])}text(){const t=this.orientation===B2.VERTICAL,n=this.points[this.row][this.col],l=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text(),range:{min:l,max:o}}}}const iS="Group",bv=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class aS extends As{constructor(n){super(n);ae(this,"points");ae(this,"lineValues");ae(this,"highlightValues");ae(this,"min");ae(this,"max");ae(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(l=>l.map(o=>Number(o.y))),this.min=this.lineValues.map(l=>$3.safeMin(l)),this.max=this.lineValues.map(l=>$3.safeMax(l)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.lineValues}audio(){return{min:this.min[this.row],max:this.max[this.row],size:this.points[this.row].length,index:this.col,value:this.points[this.row][this.col].y,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){var a;const n=this.points[this.row][this.col],l=this.findIntersections();let o={};if(l.length>1){let i=l.map(s=>{var u;const c=s.groupIndex;return((u=this.points[c][0])==null?void 0:u.fill)||`l${c+1}`});if(this.previousRow!==null){const s=((a=this.points[this.previousRow][0])==null?void 0:a.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}o={fill:{label:iS,value:`intersection at (${i.join(", ")})`}}}else o=n.fill?{fill:{label:iS,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...o}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const o=this.findLineByXAndYDirection(n),a=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const i=this.findColumnByXValue(o,a);if(i!==-1){this.row=o,this.col=i;const s=this.findIntersections();if(s.length>1){const u={...super.state,intersections:s};for(const Q of this.observers)Q.update(u)}else this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}else{this.notifyOutOfBounds();return}}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const l=this.findIntersections();if(l.length>1){const a={...super.state,intersections:l};for(const i of this.observers)i.update(a)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,l=this.points[this.row][this.col].y,o=[];for(let a=0;a<this.points.length;a++){const i=this.points[a].findIndex(s=>s.x===n&&s.y===l);i!==-1&&o.push({min:this.min[a],max:this.max[a],size:this.points[a].length,index:i,value:l,groupIndex:a})}return o}isMovable(n){if(Array.isArray(n)){const[l,o]=n;return l>=0&&l<this.values.length&&o>=0&&o<this.values[l].length}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.findLineByXAndYDirection(n);if(l===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(l,o)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const l=this.points[this.row][this.col].x;let o=null,a=Number.POSITIVE_INFINITY;for(let i=0;i<this.points.length;i++){if(i===this.row)continue;const s=this.points[i].findIndex(f=>f.x===l);if(s===-1)continue;const c=this.points[i][s].y,u=n==="UPWARD"?c>this.points[this.row][this.col].y:c<this.points[this.row][this.col].y,Q=Math.abs(c-this.points[this.row][this.col].y);u&&Q<a&&(a=Q,o=i)}return o}findColumnByXValue(n,l){return this.points[n].findIndex(o=>o.x===l)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const l=[];let o=!0;for(let a=0;a<n.length;a++){const i=C1.selectElement(n[a],!1);if(!i){l.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(xe.D)||xe.EMPTY;bv.lastIndex=0;let f=bv.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=bv.exec(Q)}else if(i instanceof SVGPolylineElement){const f=(i.getAttribute(xe.POINTS)||xe.EMPTY).split(/\s+/).filter(Boolean);for(const h of f){const[p,g]=h.split(xe.COMMA);s.push({x:Number.parseFloat(p),y:Number.parseFloat(g)})}}if(s.length!==this.lineValues[a].length)if(s.length<this.lineValues[a].length)for(;s.length<this.lineValues[a].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[a].length&&(s.length=this.lineValues[a].length);const c=[];let u=!1;for(const Q of s){if(Number.isNaN(Q.x)||Number.isNaN(Q.y)){u=!0;break}c.push(C1.createCircleElement(Q.x,Q.y,i))}if(u){l.push([]);continue}c.length>0&&(o=!1),l.push(c)}return o?null:l}get state(){const n=super.state;if(n.empty)return n;const l={...n,plotType:this.points.length>1?"multiline":"line"},o=this.findIntersections();return o.length>1?{...l,intersections:o}:l}}class sj extends As{constructor(n){super(n);ae(this,"mode");ae(this,"xPoints");ae(this,"yPoints");ae(this,"xValues");ae(this,"yValues");ae(this,"highlightXValues");ae(this,"highlightYValues");ae(this,"minX");ae(this,"maxX");ae(this,"minY");ae(this,"maxY");this.mode="column";const l=n.data,o=[...l].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let a=null;for(const c of o)(!a||a.x!==c.x)&&(a={x:c.x,y:[]},this.xPoints.push(a)),a.y.push(c.y);const i=[...l].sort((c,u)=>c.y-u.y||c.x-u.x);this.yPoints=new Array;let s=null;for(const c of i)(!s||s.y!==c.y)&&(s={y:c.y,x:[]},this.yPoints.push(s)),s.x.push(c.x);this.xValues=this.xPoints.map(c=>c.x),this.yValues=this.yPoints.map(c=>c.y),this.minX=$3.safeMin(this.xValues),this.maxX=$3.safeMax(this.xValues),this.minY=$3.safeMin(this.yValues),this.maxY=$3.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors)}dispose(){this.xPoints.length=0,this.yPoints.length=0,this.xValues.length=0,this.yValues.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightYValues.length=0),super.dispose()}get values(){const n=[this.xValues,this.yValues];return this.mode==="column"?this.row!==0&&(this.row=0):(this.row<0||this.row>=this.yPoints.length)&&(this.row=0),n}get highlightValues(){return this.mode==="column"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}audio(){if(this.mode==="column"){const n=this.xPoints[this.col];return{min:this.minY,max:this.maxY,size:n.y.length,index:this.col,value:n.y,...this.getAudioGroupIndex()}}else{const n=this.yPoints[this.row];return{min:this.minX,max:this.maxX,size:n.x.length,index:this.row,value:n.x,...this.getAudioGroupIndex()}}}braille(){return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}text(){if(this.mode==="column"){const n=this.xPoints[this.col];return{main:{label:this.xAxis,value:n.x},cross:{label:this.yAxis,value:n.y}}}else{const n=this.yPoints[this.row];return{main:{label:this.yAxis,value:n.y},cross:{label:this.xAxis,value:n.x}}}}get autoplay(){return{UPWARD:this.yValues.length,DOWNWARD:this.yValues.length,FORWARD:this.xValues.length,BACKWARD:this.xValues.length}}highlight(){if(this.highlightValues===null)return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}};const n=this.mode==="column"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return n?{empty:!1,elements:n}:{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}hasMultiPoints(){return!0}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0,this.mode="column"}toggleNavigation(){if(this.mode==="column"){const n=this.xPoints[this.col],l=n.y[Math.floor(n.y.length/2)],o=this.yValues.indexOf(l);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],l=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(l);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const l=C1.selectAllElements(n);if(l.length===0)return[null,null];const o=new Map,a=new Map;l.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(o.has(u)||o.set(u,[]),o.get(u).push(c)),Number.isNaN(Q)||(a.has(Q)||a.set(Q,[]),a.get(Q).push(c))});const i=Array.from(o.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(a.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const oS="Sum",uj="Level",cj="undefined";class Tj extends xv{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let a=0;a<this.barValues[0].length;a++){const i=this.barValues.reduce((c,u)=>c+u[a],0);t.push(i);const s=this.orientation===B2.VERTICAL?{x:this.points[0][a].x,y:i,fill:oS}:{x:i,y:this.points[0][a].y,fill:oS};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:l,max:o}=$3.minMax(t);this.min.push(l),this.max.push(o)}text(){return{...super.text(),fill:{label:uj,value:this.points[this.row][this.col].fill??cj}}}highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}hasMultiPoints(){return!1}mapToSvgElements(t){if(!t)return new Array;const n=C1.selectAllElements(t);if(n.length===0)return new Array;const l=new Array;if(n[0]instanceof SVGPathElement)for(let o=0,a=0;o<this.barValues.length;o++){const i=new Array;for(let s=0;s<this.barValues[o].length;s++){if(a>=n.length)return new Array;this.barValues[o][s]===0?i.push(C1.createEmptyElement()):i.push(n[a++])}l.push(i)}else if(n[0]instanceof SVGRectElement){for(let o=0;o<this.barValues.length;o++)l.push(new Array);for(let o=0,a=0;o<this.barValues[0].length;o++)for(let i=this.barValues.length-1;i>=0;i--){if(a>=n.length)return new Array;this.barValues[i][o]===0?l[i].push(C1.createEmptyElement()):l[i].push(n[a++])}}return l}}class lS extends aS{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],n=this.col,l=s=>t[Math.max(0,Math.min(s,t.length-1))],o=n>0?l(n-1):l(n),a=l(n),i=n<t.length-1?l(n+1):l(n);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:n,value:[o,a,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class Qj extends lS{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let l=!0;for(let a=0;a<t.length;a++){const i=C1.selectElement(t[a],!1);if(!i){n.push([]);continue}const s=(o=this.points)==null?void 0:o[a],c=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&c.push(C1.createCircleElement(u.svg_x,u.svg_y,i));c.length>0&&(l=!1),n.push(c)}return l?null:n}}function fj(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function dj(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&fj(e.data[0][0])?new Qj(e):new lS(e)}class hj{static create(t){switch(t.type){case P2.BAR:return new XI(t);case P2.BOX:return new rj(t);case P2.CANDLESTICK:return new aj(t);case P2.HEATMAP:return new oj(t);case P2.HISTOGRAM:return new lj(t);case P2.LINE:return new aS(t);case P2.SCATTER:return new sj(t);case P2.SMOOTH:return dj(t);case P2.DODGED:case P2.NORMALIZED:case P2.STACKED:return new Tj(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const pj="MAIDR Plot",mj="unavailable",yj="unavailable";class gj extends Lv{constructor(n){super();ae(this,"id");ae(this,"title");ae(this,"subtitle");ae(this,"caption");ae(this,"subplots");ae(this,"size");this.id=n.id,this.title=n.title??pj,this.subtitle=n.subtitle??mj,this.caption=n.caption??yj;const l=n.subplots;this.subplots=l.map(o=>o.map(a=>new vj(a))),this.size=this.subplots.reduce((o,a)=>o+a.length,0)}dispose(){this.subplots.forEach(n=>n.forEach(l=>l.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((o,a)=>o+a.length,0),l=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:l.getStateWithFigurePosition(this.row,this.col),traceTypes:l.traceTypes,highlight:this.highlight()}}highlight(){var l;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}};try{const o=((l=this.subplots[0])==null?void 0:l.length)||1,a=this.row*o+this.col+1,i=`g[id="axes_${a}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&a-1<c.length)return{empty:!1,elements:c[a-1]}}catch{return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}}class vj extends Lv{constructor(n){super();ae(this,"traces");ae(this,"traceTypes");ae(this,"size");this.isInitialEntry=!1;const l=n.layers;this.size=l.length,this.traces=l.map(o=>[hj.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?xe.EMPTY:a.traceType})}dispose(){this.traces.forEach(n=>n.forEach(l=>l.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}highlight(){return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}get state(){return this.isOutOfBounds?{empty:!0,type:"subplot"}:{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight()}}getStateWithFigurePosition(n,l){return this.state}}const U3={SINE_BASIC:0,SQUARE_BASIC:1,SAWTOOTH_BASIC:2,TRIANGLE_BASIC:3,SAWTOOTH_DARK:4,SINE_HARMONIC:5,TRIANGLE_HARMONIC:6,SQUARE_HARMONIC:7,TRIANGLE_MELLOW:8,SINE_SUBTLE:9,SAWTOOTH_SOFT:10},Q9=class Q9{constructor(){ae(this,"basePalette");ae(this,"extendedPalette");this.basePalette=[{index:U3.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:U3.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:U3.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:U3.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:U3.SAWTOOTH_DARK,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.2},{frequency:3,amplitude:.1},{frequency:5,amplitude:.05}]},timbreModulation:{attack:.005,decay:.3,sustain:.4,release:.5}},{index:U3.SINE_HARMONIC,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.15},{frequency:4,amplitude:.05}]},timbreModulation:{attack:.02,decay:.2,sustain:.6,release:.3}},{index:U3.TRIANGLE_HARMONIC,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.2},{frequency:6,amplitude:.1}]},timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:U3.SQUARE_HARMONIC,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.1},{frequency:7,amplitude:.05}]},timbreModulation:{attack:.005,decay:.05,sustain:.5,release:.1}},{index:U3.TRIANGLE_MELLOW,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:2.5,amplitude:.15},{frequency:4.5,amplitude:.08}]},timbreModulation:{attack:.01,decay:.4,sustain:.3,release:.5}},{index:U3.SINE_SUBTLE,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.1},{frequency:3,amplitude:.05}]},timbreModulation:{attack:.02,decay:.1,sustain:.9,release:.15}},{index:U3.SAWTOOTH_SOFT,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.05},{frequency:6,amplitude:.02}]},timbreModulation:{attack:.005,decay:.4,sustain:.2,release:.6}}],this.validateBasePalette(),this.extendedPalette=new Map,this.generateExtendedPalette()}dispose(){this.extendedPalette.clear()}getPaletteEntry(t){if(t<this.basePalette.length)return this.basePalette[t];const n=this.extendedPalette.get(t);if(n)return n;const l=this.generateExtendedEntry(t);return this.extendedPalette.set(t,l),l}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return U3.SINE_BASIC;case"Bear":return U3.SAWTOOTH_SOFT;case"Neutral":return U3.TRIANGLE_BASIC;default:return U3.SINE_BASIC}}generateExtendedPalette(){[{index:this.basePalette.length,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.3},{frequency:3,amplitude:.15}]},timbreModulation:{attack:.02,decay:.15,sustain:.7,release:.3}},{index:this.basePalette.length+1,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:1.5,amplitude:.4},{frequency:2.5,amplitude:.2}]},timbreModulation:{attack:.01,decay:.08,sustain:.6,release:.4}},{index:this.basePalette.length+2,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:1.25,amplitude:.35},{frequency:2,amplitude:.25},{frequency:3,amplitude:.1}]},timbreModulation:{attack:.03,decay:.2,sustain:.5,release:.35}},{index:this.basePalette.length+3,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:.5,amplitude:.2},{frequency:4,amplitude:.15}]},timbreModulation:{attack:.025,decay:.18,sustain:.8,release:.25}}].forEach((n,l)=>{this.extendedPalette.set(this.basePalette.length+l,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,l=this.basePalette[n],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,l.timbreModulation);return{index:t,waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const n=[],l=Q9.MIN_HARMONICS+t%Q9.HARMONIC_VARIATION;for(let o=0;o<l;o++){const a=1+(o+1)*(.5+t*.3%1),i=.4/(o+1)*(1-t*.1%.3);n.push({frequency:a,amplitude:i})}return n}generateTimbreModulation(t,n){const l=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*l)),decay:Math.max(.05,Math.min(.3,n.decay*l)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*l))}}validateBasePalette(){this.basePalette.forEach((t,n)=>{if(t.index!==n)throw new Error(`AudioPalette validation error: Entry at array position ${n} has index ${t.index}. Array position must match the index property to prevent audio palette mismatches.`)})}};ae(Q9,"MIN_HARMONICS",2),ae(Q9,"HARMONIC_VARIATION",3);let Hv=Q9;const Lj=100,xj=440,bj=880,Sv=.3,Ev=U3.SINE_BASIC;class Hj{constructor(t,n,l){ae(this,"notification");ae(this,"audioPalette");ae(this,"settings");ae(this,"isCombinedAudio");ae(this,"mode");ae(this,"activeAudioIds");ae(this,"audioContext");ae(this,"compressor");ae(this,"currentVolume");ae(this,"currentMinFrequency");ae(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new Hv,this.settings=l,this.isCombinedAudio=!1,this.mode="on",this.updateMode(n),this.activeAudioIds=new Map,this.audioContext=new AudioContext,this.compressor=this.initCompressor();const o=this.settings.loadSettings();this.currentVolume=o.general.volume/100,this.currentMinFrequency=o.general.minFrequency,this.currentMaxFrequency=o.general.maxFrequency,this.settings.addObserver(this)}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close()),this.settings.removeObserver(this)}update(t){"general"in t?this.onSettingsChange(t):this.onStateChange(t)}onSettingsChange(t){this.currentVolume=t.general.volume/100,this.currentMinFrequency=t.general.minFrequency,this.currentMaxFrequency=t.general.maxFrequency}onStateChange(t){if(this.updateMode(t),this.mode==="off"||t.type!=="trace")return;const n=t;if(n.empty){this.playEmptyTone(n.audio.size,n.audio.index);return}if(n.traceType==="line"&&!n.empty&&Array.isArray(n.intersections)&&n.intersections.length>1){this.stopAll(),this.playSimultaneousTones(n.intersections);return}const l=n.audio;let o=l.groupIndex;l.trend&&o===void 0&&(o=this.audioPalette.getCandlestickGroupIndex(l.trend));const i=o!==void 0?this.audioPalette.getPaletteEntry(o):void 0;if(l.isContinuous)this.playSmooth(l.value,l.min,l.max,l.size,Array.isArray(l.index)?l.index[0]:l.index,i);else if(Array.isArray(l.value)){const s=l.value;if(s.length===0){this.playZeroTone();return}let c=0;const u=this.mode==="on"?50:0,Q=new Array,f=()=>{if(c<s.length){const h=Array.isArray(l.index)?l.index[c]:l.index;this.playTone(l.min,l.max,s[c++],l.size,h,i),Q.push(setTimeout(f,u))}else this.stop(Q)};f()}else{const s=l.value;if(s===0)this.playZeroTone();else{const c=Array.isArray(l.index)?l.index[0]:l.index;this.playTone(l.min,l.max,s,l.size,c,i)}}}getVolume(){return Math.min(Math.max(this.currentVolume,0),1)}getFrequencyRange(){return{min:this.currentMinFrequency,max:this.currentMaxFrequency}}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const n=this.audioContext.createGain();return n.gain.value=.5,t.connect(n),n.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;n.empty||n.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=n.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}playTone(t,n,l,o,a,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(l,s,c),Q={min:0,max:o},f={min:-1,max:1},h=this.clamp(this.interpolate(a,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const l=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=n,l.push(o),t.harmonicMix)for(const a of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=a.frequency*n,l.push(i)}return l}createGainNodes(t,n,l,o){const a=[],i=this.audioContext.currentTime,s=this.getVolume();for(let c=0;c<t.length;c++){const u=this.audioContext.createGain();let Q=s;if(c===0)n.harmonicMix&&(Q*=n.harmonicMix.fundamental);else{const h=n.harmonicMix.harmonics[c-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,n,Q,i,o);f!==null&&u.gain.setValueCurveAtTime(f,i,o),a.push(u)}return a}playOscillator(t,n=0,l){const o=Sv,a=this.getVolume();l||(l=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,a,o),c=this.audioContext.createStereoPanner();c.pan.value=n;const u=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let h=0;h<i.length;h++)i[h].connect(s[h]),s[h].connect(c);c.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),c.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(c),i[p].stop(),i[p].disconnect(s[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),o*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,l,o,a){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=a*i,f=a*s,h=a*u,p=a-Q-f-h;return t.gain.setValueAtTime(1e-4*l,o),t.gain.linearRampToValueAtTime(l,o+Q),t.gain.linearRampToValueAtTime(c*l,o+Q+f),p>0&&t.gain.setValueAtTime(c*l,o+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*l,o+a),null}else return[.5*l,l,.5*l,.5*l,.5*l,.1*l,1e-4*l]}playSmooth(t,n,l,o,a,i){const s=this.audioContext,c=s.currentTime,u=Sv,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(O=>this.interpolate(O,{min:n,max:l},Q));p.length<2&&p.push(p[0]);const g=this.clamp(this.interpolate(a,{min:0,max:o-1},{min:-1,max:1}),-1,1),v=s.createOscillator();v.type=h,v.frequency.setValueCurveAtTime(p,c,u);const b=s.createGain(),L=this.createAdsrEnvelope(b,i,f,c,u);L!==null&&b.gain.setValueCurveAtTime(L,c,u);const S=s.createStereoPanner();S.pan.value=g,v.connect(b),b.connect(S),S.connect(this.compressor),v.start(c),v.stop(c+u);const _=setTimeout(()=>{v.disconnect(),b.disconnect(),S.disconnect(),this.activeAudioIds.delete(_)},u*1e3*2);this.activeAudioIds.set(_,[v])}playEmptyTone(t,n){const l=this.audioContext,o=l.currentTime,a=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=l.createGain();u.gain.setValueAtTime(.3*i,o),u.gain.exponentialRampToValueAtTime(.01*i,o+a),u.connect(this.compressor);const Q={min:0,max:t},f={min:-1,max:1},h=this.clamp(this.interpolate(n,Q,f),-1,1),p=[];for(let b=0;b<s.length;b++){const L=l.createOscillator(),S=l.createGain(),_=this.audioContext.createStereoPanner(),O=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});L.frequency.value=s[b],L.type="sine",S.gain.setValueAtTime(c[b]*i,o),S.gain.exponentialRampToValueAtTime(.001*i,o+a),_.pan.value=h,L.connect(S),S.connect(_),_.connect(O),O.connect(u),L.start(o),L.stop(o+a),p.push(L)}const g=b=>{u.disconnect(),p.forEach(L=>{L.disconnect()}),this.activeAudioIds.delete(b)},v=setTimeout(()=>g(v),a*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(Lj,0,{index:Ev,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(xj,0,{index:Ev,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(bj,0,{index:Ev,waveType:"sine"})}interpolate(t,n,l){return n.min===0&&n.max===0?0:(t-n.min)/(n.max-n.min)*(l.max-l.min)+l.min}clamp(t,n,l){return Math.max(n,Math.min(t,l))}toggle(){switch(this.mode){case"off":this.mode=this.isCombinedAudio?"combined":"on";break;case"on":this.mode="off";break;case"combined":this.mode="on";break}const n=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(n)}stop(t){(Array.isArray(t)?t:[t]).forEach(l=>{const o=this.activeAudioIds.get(l);if(!o){clearInterval(l);return}o.forEach(a=>{a==null||a.disconnect(),a==null||a.stop()}),clearTimeout(l),this.activeAudioIds.delete(l)})}stopAll(){this.activeAudioIds.entries().forEach(([t,n])=>{clearTimeout(t),n.forEach(l=>{l.disconnect(),l.stop()})}),this.activeAudioIds.clear()}playSimultaneousTones(t){const n=this.getVolume(),l=Sv,o=this.audioContext,a=o.currentTime,i=this.getFrequencyRange(),s=Array.isArray(t[0].value)?t[0].value[1]??t[0].value[0]:t[0].value,c=t[0].min,u=t[0].max,Q=this.interpolate(s,{min:c,max:u},i);t.forEach((f,h)=>{const p=Q,v=this.audioPalette.getPaletteEntry(h).waveType,b=o.createOscillator();b.type=v,b.frequency.value=p;const L=o.createGain();L.gain.setValueAtTime(n,a),L.gain.exponentialRampToValueAtTime(.01*n,a+l),b.connect(L),L.connect(this.compressor),b.start(a),b.stop(a+l);const S=setTimeout(()=>{b.disconnect(),L.disconnect()},l*1e3*2);this.activeAudioIds.set(S,[b])})}}const Sj=250,Ej=50,Mj=500,Aj=20;class _j{constructor(t,n,l){ae(this,"context");ae(this,"notification");ae(this,"settings");ae(this,"autoplayId");ae(this,"currentDirection");ae(this,"userSpeed");ae(this,"defaultSpeed");ae(this,"minSpeed");ae(this,"maxSpeed");ae(this,"autoplayRate");ae(this,"interval");ae(this,"currentDuration");ae(this,"onChangeEmitter");ae(this,"onChange");this.notification=n,this.context=t,this.settings=l,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Sj,this.minSpeed=Ej,this.maxSpeed=Mj,this.autoplayRate=this.defaultSpeed,this.interval=Aj,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new Ms,this.onChange=this.onChangeEmitter.event,this.settings.addObserver(this)}dispose(){this.stop(),this.onChangeEmitter.dispose(),this.settings.removeObserver(this)}update(t){this.updateSettings(t)}updateSettings(t){this.currentDuration=t.general.autoplayDuration,this.currentDirection&&this.restart()}start(t,n){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,n),this.currentDirection=t,this.autoplayId=setInterval(()=>{this.context.isMovable(t)?this.context.moveOnce(t):this.stop()},this.autoplayRate)}stop(){this.autoplayId&&clearInterval(this.autoplayId),this.autoplayId=null,this.currentDirection=null,this.onChangeEmitter.fire({type:"stop"})}restart(){this.autoplayId&&clearInterval(this.autoplayId),this.currentDirection&&this.start(this.currentDirection)}speedUp(){const t=this.userSpeed??this.autoplayRate;t-this.interval>this.minSpeed?(this.userSpeed=t-this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed up")):this.notification.notify("Max speed")}speedDown(){const t=this.userSpeed??this.autoplayRate;t+this.interval<=this.maxSpeed?(this.userSpeed=t+this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed down")):this.notification.notify("Min speed")}resetSpeed(){this.userSpeed=null,this.autoplayRate=this.defaultSpeed,this.restart(),this.notification.notify("Reset speed")}getAutoplayRate(t,n){if(this.userSpeed!==null)return this.userSpeed;if(n&&!n.empty){const l=Math.ceil(this.currentDuration/n.autoplay[t]);return this.defaultSpeed=l,this.minSpeed=Math.min(this.minSpeed,l),l}return this.defaultSpeed}}const sS=32;class Rc{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const i=(t.max[a]-t.min[a])/4,s=t.min[a]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[a].length;Q++)t.values[a][Q]===0?n.push(" "):t.values[a][Q]<=s||t.values[a][Q]<=c?n.push("⠤"):t.values[a][Q]<=u?n.push("⠒"):n.push("⠉"),l[a].push(o.length),o.push({row:a,col:Q});n.push(xe.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}}class Oj{constructor(){ae(this,"GLOBAL_MIN","globalMin");ae(this,"GLOBAL_MAX","globalMax");ae(this,"BLANK","blank");ae(this,"LOWER_OUTLIER","lowerOutlier");ae(this,"UPPER_OUTLIER","upperOutlier");ae(this,"MIN","min");ae(this,"MAX","max");ae(this,"Q1","q1");ae(this,"Q2","q2");ae(this,"Q3","q3")}encode(t,n=sS){const l=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],c=[{type:this.GLOBAL_MIN,value:t.min},...s.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:s.min},{type:this.Q1,value:s.q1},{type:this.Q2,value:s.q2},{type:this.Q3,value:s.q3},{type:this.MAX,value:s.max},...s.upperOutliers.map(V=>({type:this.UPPER_OUTLIER,value:V})),{type:this.GLOBAL_MAX,value:t.max}],u=new Array;let Q=!0;for(let V=0;V<c.length-1;V++){const k=c[V],B=c[V+1],R=Math.abs(Q?B.value-k.value:k.value-c[V-1].value);k.type===this.LOWER_OUTLIER||k.type===this.UPPER_OUTLIER?(u.push({type:k.type,length:0,numChars:1}),u.push({type:this.BLANK,length:R,numChars:0})):k.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):k.type===this.GLOBAL_MIN||k.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:R,numChars:0}):u.push({type:k.type,length:R,numChars:1})}let f=u.reduce((V,k)=>V+(k.numChars>0?k.numChars:0),0),[h,p,g,v]=[-1,-1,-1,-1];for(let V=0;V<u.length;V++)u[V].type===this.MIN&&u[V].length>0&&(h=V),u[V].type===this.MAX&&u[V].length>0&&(p=V),u[V].type===this.Q1&&(g=V),u[V].type===this.Q3&&(v=V);h!==-1&&p!==-1&&u[h].length!==u[p].length&&(u[h].length>u[p].length?(u[h].numChars++,f++):(u[p].numChars++,f++)),g!==-1&&v!==-1&&u[g].length!==u[v].length&&(u[g].length>u[v].length?(u[g].numChars++,f++):(u[v].numChars++,f++));const b=Math.max(0,n-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 S=u.reduce((V,k)=>V+k.numChars,0);let _=n-S,O=0;for(;_!==0;){const V=u[O%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=_>0?1:-1,_+=_>0?-1:1),O++}let E=-1;const A=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];a.push(Array.from({length:A.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(E=A.indexOf(V.type),a[i][E]=l.length);for(let k=0;k<V.numChars;k++){let B="⠀";V.type===this.MIN||V.type===this.MAX?B="⠒":V.type===this.Q1||V.type===this.Q3?B="⠿":V.type===this.Q2?B=k===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?B="⠂":V.type===this.BLANK&&(B="⠀"),l.push(B),o.push({row:i,col:E})}}for(let V=0;V<3;V++)if(a[i][V]===-1){for(let k=V+1;k<=3;k++)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}for(let V=6;V>3;V--)if(a[i][V]===-1){for(let k=V-1;k>=3;k--)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}l.push(xe.NEW_LINE),o.push({row:i,col:E})}return{value:l.join(xe.EMPTY),cellToIndex:a,indexToCell:o}}}class Cj{encode(t){const n=new Array,l=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,s=i+a;for(let c=0;c<t.values.length;c++){l.push(new Array);for(let u=0;u<t.values[c].length;u++)t.values[c][u]===0?n.push(" "):t.values[c][u]<=i?n.push("⠤"):t.values[c][u]<=s?n.push("⠒"):n.push("⠉"),l[c].push(o.length),o.push({row:c,col:u});n.push(xe.NEW_LINE),l[c].push(o.length),o.push({row:c,col:t.values[c].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}}class uS{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(a,t);for(let Q=0;Q<t.values[a].length;Q++){const f=t.values[a][Q],h=Q>0?t.values[a][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),l[a].push(o.length),o.push({row:a,col:Q})}n.push(xe.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}getBrailleChar(t,n,l,o,a,i){return i===void 0&&(i=a),t<=l&&n!==null&&n>l?n<=o?"⢄":n<=i?"⢆":"⢇":t<=l?"⣀":n!==null&&n<=l?t<=o?"⡠":t<=i?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=i?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=a?"⠉":""}getBraille6Char(t,n,l,o,a){const i=f=>f<=l?"low":f<=o?"medium":(f<=a,"high"),s=i(t),c=n!==null?i(n):null,u={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},Q=`${s},${c}`;return u[Q]||""}addDot8(t){if(!t||t.length===0)return"⢀";const o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class wj extends uS{getThresholds(t,n){const l=(n.max-n.min)/3,o=n.min+l,a=o+l,i=n.max;return{low:o,medium:a,high:i}}encode(t){var a;const n=new Array,l=new Array,o=new Array;for(let i=0;i<t.values.length;i++){l.push(new Array);const{low:s,medium:c,high:u}=this.getThresholds(i,t);for(let Q=0;Q<t.values[i].length;Q++){const f=t.values[i][Q],h=Q>0?t.values[i][Q-1]:null;let p=this.getBraille6Char(f,h,s,c,u);((a=t.custom)==null?void 0:a[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),l[i].push(o.length),o.push({row:i,col:Q})}n.push(xe.NEW_LINE),l[i].push(o.length),o.push({row:i,col:t.values[i].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}}class Vj extends uS{getThresholds(t,n){const l=(n.max[t]-n.min[t])/4,o=n.min[t]+l,a=o+l,i=a+l,s=n.max[t];return{low:o,medium:a,mediumHigh:i,high:s}}}class Dj{constructor(t,n,l){ae(this,"context");ae(this,"notification");ae(this,"display");ae(this,"enabled");ae(this,"cacheId");ae(this,"cache");ae(this,"encoders");ae(this,"onChangeEmitter");ae(this,"onChange");this.context=t,this.notification=n,this.display=l,this.enabled=!1,this.cacheId=xe.EMPTY,this.cache=null,this.encoders=new Map([[P2.BAR,new Rc],[P2.BOX,new Oj],[P2.CANDLESTICK,new wj],[P2.DODGED,new Rc],[P2.HEATMAP,new Cj],[P2.HISTOGRAM,new Rc],[P2.LINE,new Vj],[P2.NORMALIZED,new Rc],[P2.STACKED,new Rc]]),this.onChangeEmitter=new Ms,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const n=t.type==="subplot"?t.trace:t;if(n.empty||n.braille.empty||!this.encoders.has(n.traceType))return;const l=n.braille;if(this.cacheId!==l.id||this.cache===null){const o=this.encoders.get(n.traceType);this.cache=o.encode(l,sS),this.cacheId=l.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[l.row][l.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:l}=this.cache.indexToCell[t];this.context.moveToIndex(n,l)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const l=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(l);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(H1.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var cS=(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))(cS||{});class TS{constructor(){}static async post(t,n,l){const o={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",o,n)}static async request(t,n,l,o){try{const a=await fetch(t,{method:n,headers:l,body:o});return a.ok?{success:!0,data:await a.json()}:{success:!1,error:{statusCode:a.status,message:`API Error: ${a.status} - ${a.statusText}`}}}catch(a){return console.error(`Error in API ${n} request to ${t}:`,a),{success:!1,error:{statusCode:cS.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}ae(TS,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Rj=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
2
+ `),ae(xe,"OPEN_BRACKET","["),ae(xe,"POLYLINE","polyline"),ae(xe,"SPACE"," "),ae(xe,"THROUGH"," through "),ae(xe,"TRANSPARENT","transparent"),ae(xe,"VISIBLE","visible"),ae(xe,"X","x"),ae(xe,"Y","y"),ae(xe,"HIGHLIGHT_BASE_COLOR",{r:255,g:255,b:255}),ae(xe,"HIGHLIGHT_CONTRAST_RATIO",3),ae(xe,"HIGHLIGHT_COLOR_RATIO",.6),ae(xe,"HIGHLIGHT_MAX_COLOR",255);let pv=class{constructor(){ae(this,"items");this.items=new Array}push(t){this.items.push(t)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}removeLast(t,n=1){const l=this.items.lastIndexOf(t);return l!==-1?(this.items.splice(l,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}};const mv=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function yv(e,t,n,l){e.addEventListener?e.addEventListener(t,n,l):e.attachEvent&&e.attachEvent("on".concat(t),n)}function _c(e,t,n,l){e.removeEventListener?e.removeEventListener(t,n,l):e.detachEvent&&e.detachEvent("on".concat(t),n)}function WH(e,t){const n=t.slice(0,t.length-1);for(let l=0;l<n.length;l++)n[l]=e[n[l].toLowerCase()];return n}function YH(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function HI(e,t){const n=e.length>=t.length?e:t,l=e.length>=t.length?t:e;let o=!0;for(let a=0;a<n.length;a++)l.indexOf(n[a])===-1&&(o=!1);return o}const Oc={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,"-":mv?173:189,"=":mv?61:187,";":mv?59:186,"'":222,"[":219,"]":221,"\\":220},c5={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Cc={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},_3={16:!1,18:!1,17:!1,91:!1},b2={};for(let e=1;e<20;e++)Oc["f".concat(e)]=111+e;let p2=[],wc=null,KH="all";const wi=new Map,Vc=e=>Oc[e.toLowerCase()]||c5[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),SI=e=>Object.keys(Oc).find(t=>Oc[t]===e),EI=e=>Object.keys(c5).find(t=>c5[t]===e);function JH(e){KH=e||"all"}function Dc(){return KH||"all"}function MI(){return p2.slice(0)}function AI(){return p2.map(e=>SI(e)||EI(e)||String.fromCharCode(e))}function _I(){const e=[];return Object.keys(b2).forEach(t=>{b2[t].forEach(n=>{let{key:l,scope:o,mods:a,shortcut:i}=n;e.push({scope:o,shortcut:i,mods:a,keys:l.split("+").map(s=>Vc(s))})})}),e}function OI(e){const t=e.target||e.srcElement,{tagName:n}=t;let l=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(l=!1),l}function CI(e){return typeof e=="string"&&(e=Vc(e)),p2.indexOf(e)!==-1}function wI(e,t){let n,l;e||(e=Dc());for(const o in b2)if(Object.prototype.hasOwnProperty.call(b2,o))for(n=b2[o],l=0;l<n.length;)n[l].scope===e?n.splice(l,1).forEach(i=>{let{element:s}=i;return gv(s)}):l++;Dc()===e&&JH(t||"all")}function VI(e){let t=e.keyCode||e.which||e.charCode;const n=p2.indexOf(t);if(n>=0&&p2.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&p2.splice(0,p2.length),(t===93||t===224)&&(t=91),t in _3){_3[t]=!1;for(const l in c5)c5[l]===t&&(q3[l]=!1)}}function eS(e){if(typeof e>"u")Object.keys(b2).forEach(o=>{Array.isArray(b2[o])&&b2[o].forEach(a=>Ep(a)),delete b2[o]}),gv(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Ep(o)});else if(typeof e=="object")e.key&&Ep(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),l=1;l<t;l++)n[l-1]=arguments[l];let[o,a]=n;typeof o=="function"&&(a=o,o=""),Ep({key:e,scope:o,method:a,splitKey:"+"})}}const Ep=e=>{let{key:t,scope:n,method:l,splitKey:o="+"}=e;YH(t).forEach(i=>{const s=i.split(o),c=s.length,u=s[c-1],Q=u==="*"?"*":Vc(u);if(!b2[Q])return;n||(n=Dc());const f=c>1?WH(c5,s):[],h=[];b2[Q]=b2[Q].filter(p=>{const v=(l?p.method===l:!0)&&p.scope===n&&HI(p.mods,f);return v&&h.push(p.element),!v}),h.forEach(p=>gv(p))})};function tS(e,t,n,l){if(t.element!==l)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const a in _3)Object.prototype.hasOwnProperty.call(_3,a)&&(!_3[a]&&t.mods.indexOf(+a)>-1||_3[a]&&t.mods.indexOf(+a)===-1)&&(o=!1);(t.mods.length===0&&!_3[16]&&!_3[18]&&!_3[17]&&!_3[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(p2),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function nS(e,t){const n=b2["*"];let l=e.keyCode||e.which||e.charCode;if(!q3.filter.call(this,e))return;if((l===93||l===224)&&(l=91),p2.indexOf(l)===-1&&l!==229&&p2.push(l),["metaKey","ctrlKey","altKey","shiftKey"].forEach(s=>{const c=Cc[s];e[s]&&p2.indexOf(c)===-1?p2.push(c):!e[s]&&p2.indexOf(c)>-1?p2.splice(p2.indexOf(c),1):s==="metaKey"&&e[s]&&(p2=p2.filter(u=>u in Cc||u===l))}),l in _3){_3[l]=!0;for(const s in c5)if(Object.prototype.hasOwnProperty.call(c5,s)){const c=Cc[c5[s]];q3[s]=e[c]}if(!n)return}for(const s in _3)Object.prototype.hasOwnProperty.call(_3,s)&&(_3[s]=e[Cc[s]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(p2.indexOf(17)===-1&&p2.push(17),p2.indexOf(18)===-1&&p2.push(18),_3[17]=!0,_3[18]=!0);const o=Dc();if(n)for(let s=0;s<n.length;s++)n[s].scope===o&&(e.type==="keydown"&&n[s].keydown||e.type==="keyup"&&n[s].keyup)&&tS(e,n[s],o,t);if(!(l in b2))return;const a=b2[l],i=a.length;for(let s=0;s<i;s++)if((e.type==="keydown"&&a[s].keydown||e.type==="keyup"&&a[s].keyup)&&a[s].key){const c=a[s],{splitKey:u}=c,Q=c.key.split(u),f=[];for(let h=0;h<Q.length;h++)f.push(Vc(Q[h]));f.sort().join("")===p2.sort().join("")&&tS(e,c,o,t)}}function q3(e,t,n){p2=[];const l=YH(e);let o=[],a="all",i=document,s=0,c=!1,u=!0,Q="+",f=!1,h=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(a=t.scope),t.element&&(i=t.element),t.keyup&&(c=t.keyup),t.keydown!==void 0&&(u=t.keydown),t.capture!==void 0&&(f=t.capture),typeof t.splitKey=="string"&&(Q=t.splitKey),t.single===!0&&(h=!0)),typeof t=="string"&&(a=t),h&&eS(e,a);s<l.length;s++)e=l[s].split(Q),o=[],e.length>1&&(o=WH(c5,e)),e=e[e.length-1],e=e==="*"?"*":Vc(e),e in b2||(b2[e]=[]),b2[e].push({keyup:c,keydown:u,scope:a,mods:o,shortcut:l[s],method:n,key:l[s],splitKey:Q,element:i});if(typeof i<"u"&&window){if(!wi.has(i)){const p=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return nS(v,i)},g=function(){let v=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;nS(v,i),VI(v)};wi.set(i,{keydownListener:p,keyupListenr:g,capture:f}),yv(i,"keydown",p,f),yv(i,"keyup",g,f)}if(!wc){const p=()=>{p2=[]};wc={listener:p,capture:f},yv(window,"focus",p,f)}}}function DI(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(b2).forEach(n=>{b2[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function gv(e){const t=Object.values(b2).flat();if(t.findIndex(l=>{let{element:o}=l;return o===e})<0){const{keydownListener:l,keyupListenr:o,capture:a}=wi.get(e)||{};l&&o&&(_c(e,"keyup",o,a),_c(e,"keydown",l,a),wi.delete(e))}if((t.length<=0||wi.size<=0)&&(Object.keys(wi).forEach(o=>{const{keydownListener:a,keyupListenr:i,capture:s}=wi.get(o)||{};a&&i&&(_c(o,"keyup",i,s),_c(o,"keydown",a,s),wi.delete(o))}),wi.clear(),Object.keys(b2).forEach(o=>delete b2[o]),wc)){const{listener:o,capture:a}=wc;_c(window,"focus",o,a),wc=null}}const vv={getPressedKeyString:AI,setScope:JH,getScope:Dc,deleteScope:wI,getPressedKeyCodes:MI,getAllKeyCodes:_I,isPressed:CI,filter:OI,trigger:DI,unbind:eS,keyMap:Oc,modifier:c5,modifierMap:Cc};for(const e in vv)Object.prototype.hasOwnProperty.call(vv,e)&&(q3[e]=vv[e]);if(typeof window<"u"){const e=window.hotkeys;q3.noConflict=t=>(t&&window.hotkeys===q3&&(window.hotkeys=e),q3),window.hotkeys=q3}class RI{constructor(t){ae(this,"id");ae(this,"instructionContext");ae(this,"plotContext");ae(this,"scopeContext");this.id=t.id,this.plotContext=new pv,this.scopeContext=new pv;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(H1.SUBPLOT);return}this.scopeContext.push(H1.TRACE);const l=t.activeSubplot.state;if(l.empty||l.size!==1){this.instructionContext=t.activeSubplot,this.plotContext.push(t.activeSubplot),this.plotContext.push(t.activeSubplot.activeTrace);return}this.instructionContext=t.activeSubplot.activeTrace,this.plotContext.push(t.activeSubplot.activeTrace)}dispose(){this.plotContext.clear(),this.scopeContext.clear()}get active(){return this.plotContext.peek()}get state(){return this.active.state}toggleScope(t){this.scopeContext.removeLast(t)||this.scopeContext.push(t),q3.setScope(this.scope)}get scope(){return this.scopeContext.peek()}isMovable(t){return this.active.isMovable(t)}moveOnce(t){this.active.moveOnce(t)}moveToExtreme(t){this.active.moveToExtreme(t)}moveToIndex(t,n){this.active.moveToIndex(t,n)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const n=this.active,o=n.activeTrace.getCurrentXValue();n.moveOnce(t);const a=n.activeTrace;this.plotContext.push(a),a.moveToXValue(o)}}enterSubplot(){if(this.active.state.type==="figure"){const n=this.active;this.plotContext.push(n.activeSubplot),this.active.notifyStateUpdate(),this.plotContext.push(n.activeSubplot.activeTrace),this.toggleScope(H1.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(H1.TRACE))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const l=t?"Click to activate.":xe.EMPTY;switch(n.type){case"figure":return`This is a maidr figure containing ${n.size} subplots. ${l} Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a maidr plot containing ${n.size} layers, and this is layer 1 of ${n.size}: ${n.trace.traceType} plot. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`;case"trace":return`This is a maidr plot of type: ${n.plotType}. ${l} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}var B2=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(B2||{}),P2=(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))(P2||{});function kI(e){return e!==null&&typeof e=="object"&&"x"in e}function NI(e){return typeof e=="string"||typeof e=="number"}function BI(e){return e!==null&&typeof e=="object"&&"x"in e}class rS{computeIndexAndSegment(t,n,l,o){return l===B2.HORIZONTAL?{pointIndex:t,segmentType:o[n]}:{pointIndex:n,segmentType:o[t]}}computeVisualCoordinates(t,n,l){return l===B2.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const o=t[0][l];return this.extractXFromPoint(o)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][l]){const o=t[n][l];return this.extractXFromPoint(o)}return null}extractXValueFromValues(t,n,l){if(this.isValidPosition(t,n,l)){const o=t[n][l];return this.extractXFromValue(o)}return null}moveToXValueInPoints(t,n,l){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const c=this.findPointIndexByX(t[0],n);if(c!==-1)return l(0,c),!0;{const u=this.findNearestPointIndexByX(t[0],n);if(u!==-1){const Q=_r(t[0][u]);if(typeof n=="number"&&typeof Q=="number")return l(0,u),!0;if(typeof n=="string"&&typeof Q=="string")return l(0,u),!0}}}let o=-1,a=-1,i=Number.POSITIVE_INFINITY,s=null;if(Array.isArray(t))for(let c=0;c<t.length;c++){const u=t[c];if(Array.isArray(u)){const Q=this.findPointIndexByX(u,n);if(Q!==-1)return l(c,Q),!0;const f=this.findNearestPointIndexByX(u,n);if(f!==-1){const h=_r(u[f]);let p=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof h=="number"?(p=Math.abs(h-n),p<i&&(i=p,o=c,a=f,s="numeric")):typeof n=="string"&&typeof h=="string"?o===-1&&(o=c,a=f,s="categorical"):o===-1&&(o=c,a=f,s="generic")}}}if(o!==-1&&a!==-1){const c=t[o];if(Array.isArray(c)&&_r(c[a]),s!==null)return l(o,a),!0}return!1}moveToXValueInValues(t,n,l){let o=-1,a=-1,i=Number.POSITIVE_INFINITY,s=null;for(let c=0;c<t.length;c++)for(let u=0;u<t[c].length;u++){const Q=t[c][u],f=this.extractXFromValue(Q);if(f===n)return l(c,u),!0;if(typeof n=="number"&&typeof f=="number"){const h=Math.abs(f-n);h<i&&(i=h,o=c,a=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?o===-1&&(o=c,a=u,s="categorical"):o===-1&&(o=c,a=u,s="generic")}return o!==-1&&a!==-1?(this.extractXFromValue(t[o][a]),l(o,a),!0):!1}extractXFromPoint(t){return BI(t)?t.x:null}extractXFromValue(t){return kI(t)?t.x:NI(t)?t:null}findPointIndexByX(t,n){return t.findIndex(l=>l.x===n)}isValidPosition(t,n,l){return n>=0&&n<t.length&&l>=0&&l<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let l=-1,o=Number.POSITIVE_INFINITY;for(let a=0;a<t.length;a++){const i=_r(t[a]);if(typeof i=="number"){const s=Math.abs(i-n);s<o&&(o=s,l=a)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<o&&(o=c,l=a)}}}if(l!==-1)return _r(t[l]),l}else if(typeof n=="string"){for(let o=0;o<t.length;o++)if(_r(t[o])===n)return o;const l=Number(n);if(!Number.isNaN(l)){let o=-1,a=Number.POSITIVE_INFINITY;for(let i=0;i<t.length;i++){const s=_r(t[i]);if(typeof s=="number"){const c=Math.abs(s-l);c<a&&(a=c,o=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-l);u<a&&(a=u,o=i)}}}if(o!==-1)return _r(t[o]),o}for(let o=0;o<t.length;o++)if(typeof _r(t[o])=="string")return o}return t.length>0?(_r(t[0]),0):-1}dispose(){}}function PI(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function II(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function jI(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function FI(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function zI(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function qI(e){return e&&typeof e=="object"&&"value"in e}function _r(e){return e?PI(e)||II(e)||FI(e)||zI(e)||jI(e)?e.x:qI(e)?e.value:null:null}const $I="unavailable",UI="X",GI="Y",ZI="unavailable";class Lv{constructor(){ae(this,"observers");ae(this,"isInitialEntry");ae(this,"isOutOfBounds");ae(this,"row");ae(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}getSafeIndices(){var o;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,l=this.col>=0&&this.col<(((o=t[n])==null?void 0:o.length)||0)?this.col:0;return{row:n,col:l}}moveToExtreme(t){var n;switch(this.isInitialEntry&&this.handleInitialEntry(),t){case"UPWARD":this.row=this.values.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":{const{row:l}=this.getSafeIndices();this.col=(n=this.values[l])!=null&&n.length?this.values[l].length-1:0;break}case"BACKWARD":this.col=0;break}this.notifyStateUpdate()}moveToIndex(t,n){this.isMovable([t,n])&&(this.row=t,this.col=n,this.isInitialEntry=!1,this.notifyStateUpdate())}isMovable(t){var n,l;if(Array.isArray(t)){const[o,a]=t,{row:i}=this.getSafeIndices();return o>=0&&o<this.values.length&&a>=0&&a<(((n=this.values[i])==null?void 0:n.length)||0)}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":{const{row:o}=this.getSafeIndices();return this.col<(((l=this.values[o])==null?void 0:l.length)||0)-1}case"BACKWARD":return this.col>0}}handleInitialEntry(){var n;this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.values.length-1));const{row:t}=this.getSafeIndices();this.col=Math.max(0,Math.min(this.col,(((n=this.values[t])==null?void 0:n.length)||0)-1))}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){const t=this.state;for(const n of this.observers)n.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}}class As extends Lv{constructor(n){var l,o,a;super();ae(this,"id");ae(this,"type");ae(this,"title");ae(this,"xAxis");ae(this,"yAxis");ae(this,"fill");ae(this,"navigationService");this.navigationService=new rS,this.id=n.id,this.type=n.type,this.title=n.title??$I,this.xAxis=((l=n.axes)==null?void 0:l.x)??UI,this.yAxis=((o=n.axes)==null?void 0:o.y)??GI,this.fill=((a=n.axes)==null?void 0:a.fill)??ZI}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(l=>{(Array.isArray(l)?l:[l]).forEach(a=>a.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==null?void 0:n.length)||0,index:o}}}return{empty:!1,type:"trace",traceType:this.type,plotType:this.type,title:this.title,xAxis:this.xAxis,yAxis:this.yAxis,fill:this.fill,hasMultiPoints:this.hasMultiPoints(),audio:this.audio(),braille:this.braille(),text:this.text(),autoplay:this.autoplay,highlight:this.highlight()}}highlight(){var n;if(this.highlightValues===null||this.isInitialEntry){const{row:l,col:o}=this.getSafeIndices(),a=this.values;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=a[l])==null?void 0:n.length)||0,index:o}}}return{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){var o;const{row:n}=this.getSafeIndices(),l=((o=this.values[n])==null?void 0:o.length)||0;return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:l,BACKWARD:l}}hasMultiPoints(){return!1}getCurrentXValue(){if(this.hasPointsArray()){const n=this.getPointsArray();if(this.isValidPointsArray(n))return this.navigationService.extractXValueFromPoints(n,this.row,this.col)}if(this.hasValuesArray()){const n=this.values;if(this.isValidValuesArray(n))return this.navigationService.extractXValueFromValues(n,this.row,this.col)}return null}moveToXValue(n){if(this.hasPointsArray()){const l=this.getPointsArray();if(this.isValidPointsArray(l))return this.navigationService.moveToXValueInPoints(l,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const l=this.values;if(this.isValidValuesArray(l))return this.navigationService.moveToXValueInValues(l,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}}class $3{constructor(){}static safeMin(t){return t.length===0?1/0:Math.min(...t)}static safeMax(t){return t.length===0?-1/0:Math.max(...t)}static minFrom2D(t){const n=t.flat();return this.safeMin(n)}static maxFrom2D(t){const n=t.flat();return this.safeMax(n)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let n=t[0],l=t[0];for(let o=1;o<t.length;o++){const a=t[o];a<n&&(n=a),a>l&&(l=a)}return{min:n,max:l}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class Mp{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[5],16)}}const l=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return l?{r:Number.parseInt(l[1],10),g:Number.parseInt(l[2],10),b:Number.parseInt(l[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const l=this.calculateLuminance(t),o=this.calculateLuminance(n);return(Math.max(l,o)+.05)/(Math.min(l,o)+.05)}static calculateLuminance(t){const[n,l,o]=[t.r,t.g,t.b].map(a=>{const i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*l+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class C1{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,a=await new Promise((c,u)=>{const Q=new Image;Q.onload=()=>c(Q),Q.onerror=()=>u(new Error("Failed to load SVG image")),Q.src=o}),i=document.createElement("canvas");[i.width,i.height]=[a.naturalWidth,a.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(a,0,0),i.toDataURL("image/jpeg",.92)):(console.error("Error converting SVG to Base 64: Canvas context unavailable"),"")}catch(n){return console.error("Error converting SVG to Base 64:",n instanceof Error?n.message:n),""}}static selectAllElements(t,n=!0){return Array.from(document.querySelectorAll(t)).map(l=>{if(!n)return l;const o=l.cloneNode(!0);return o.setAttribute(xe.VISIBILITY,xe.HIDDEN),l.insertAdjacentElement(xe.AFTER_END,o),o})}static selectElement(t,n=!0){const l=document.querySelector(t);if(!n)return l;const o=l==null?void 0:l.cloneNode(!0);return o==null||o.setAttribute(xe.VISIBILITY,xe.HIDDEN),l==null||l.insertAdjacentElement(xe.AFTER_END,o),o}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(xe.FILL,xe.TRANSPARENT),n.setAttribute(xe.STROKE,xe.TRANSPARENT),n.setAttribute(xe.VISIBILITY,xe.HIDDEN),n}static createCircleElement(t,n,l){var u;const o=window.getComputedStyle(l),a=o.stroke||o.fill,i=o.strokeWidth||"2",s=Number.parseFloat(i)*2,c=document.createElementNS(this.SVG_NAMESPACE,xe.CIRCLE);return c.setAttribute(xe.CIRCLE_X,String(t)),c.setAttribute(xe.CIRCLE_Y,String(n)),c.setAttribute(xe.RADIUS,String(s)),c.setAttribute(xe.FILL,a),c.setAttribute(xe.STROKE,a),c.setAttribute(xe.STROKE_WIDTH,i),c.setAttribute(xe.VISIBILITY,xe.HIDDEN),(u=l.parentElement)==null||u.insertAdjacentElement(xe.AFTER_END,c),c}static createLineElement(t,n){const o=t.getBBox();let a,i,s,c;switch(n){case"top":[a,i,s,c]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[a,i,s,c]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[a,i,s,c]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[a,i,s,c]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,xe.LINE);return Q.setAttribute(xe.X1,String(a)),Q.setAttribute(xe.Y1,String(i)),Q.setAttribute(xe.X2,String(s)),Q.setAttribute(xe.Y2,String(c)),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,n){const l=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),s=this.getHighlightColor(i,n);if(l.setAttribute(xe.VISIBILITY,xe.VISIBLE),l.setAttribute(xe.STROKE,s),l.setAttribute(xe.FILL,s),l.style.fill=s,l.style.stroke=s,a){const c=window.getComputedStyle(l).getPropertyValue(xe.STROKE_WIDTH);l.setAttribute(xe.STROKE_WIDTH,`${c+2}`)}return t.insertAdjacentElement(xe.AFTER_END,l),l}static getHighlightColor(t,n){const l=Mp.parse(t);if(!l||!(Mp.getContrastRatio(l,xe.HIGHLIGHT_BASE_COLOR)<xe.HIGHLIGHT_CONTRAST_RATIO))return n;const i={...l};return l.r===l.g&&l.g===l.b?(i.r=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*xe.HIGHLIGHT_COLOR_RATIO)),i.g=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*xe.HIGHLIGHT_COLOR_RATIO)),i.b=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*xe.HIGHLIGHT_COLOR_RATIO))):l.r>=l.g&&l.r>=l.b?i.r=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.r*xe.HIGHLIGHT_COLOR_RATIO)):l.g>=l.r&&l.g>=l.b?i.g=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.g*xe.HIGHLIGHT_COLOR_RATIO)):i.b=Math.min(xe.HIGHLIGHT_MAX_COLOR,Math.floor(l.b*xe.HIGHLIGHT_COLOR_RATIO)),Mp.rgbToString(i)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",l=Mp.parse(n);return l?(.2126*l.r+.7152*l.g+.0722*l.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,n){t.style.outline=`4px solid ${n}`,t.style.outlineOffset="3px",t.style.borderRadius="3px",t.style.overflow="visible"}static removeSubplotHighlightCss(t){t.style.removeProperty("outline"),t.style.removeProperty("outline-offset"),t.style.removeProperty("border-radius"),t.style.removeProperty("overflow")}static setSubplotHighlightSvgWithAdaptiveColor(t,n,l){const o=t.querySelector("rect, path");let a="";if(o){a=window.getComputedStyle(o).getPropertyValue("fill"),(!a||a==="none"||a==="transparent"||a==="rgba(0, 0, 0, 0)")&&(l?a=window.getComputedStyle(l).getPropertyValue("fill"):a=n);const i=this.getHighlightColor(a,n);o.setAttribute("stroke",i),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}ae(C1,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class xv extends As{constructor(n,l){super(n);ae(this,"points");ae(this,"barValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"min");ae(this,"max");this.points=l,this.orientation=n.orientation??B2.VERTICAL,this.barValues=l.map(o=>o.map(a=>this.orientation===B2.VERTICAL?Number(a.y):Number(a.x))),this.min=this.barValues.map(o=>$3.safeMin(o)),this.max=this.barValues.map(o=>$3.safeMax(o)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const n=this.orientation===B2.VERTICAL,l=n?this.barValues[this.row].length:this.barValues.length,o=n?this.col:this.row,a=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:$3.safeMin(this.min),max:$3.safeMax(this.max),size:l,index:o,value:a,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){const n=this.orientation===B2.VERTICAL,l=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,a=n?l.x:l.y,i=n?this.yAxis:this.xAxis,s=n?l.y:l.x;return{main:{label:o,value:a},cross:{label:i,value:s}}}mapToSvgElements(n){if(!n)return null;const l=[C1.selectAllElements(n)];if(l.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(l[o].length!==this.points[o].length)return null;return l}}class XI extends xv{constructor(t){super(t,[t.data])}}const WI="Lower outlier(s)",YI="Upper outlier(s)",KI="Minimum",JI="Maximum",ej="25%",tj="50%",nj="75%";class rj extends As{constructor(n){super(n);ae(this,"points");ae(this,"boxValues");ae(this,"highlightValues");ae(this,"orientation");ae(this,"sections");ae(this,"min");ae(this,"max");this.points=n.data,this.orientation=n.orientation??B2.VERTICAL,this.sections=[WI,KI,ej,tj,nj,JI,YI];const l=[a=>a.lowerOutliers,a=>a.min,a=>a.q1,a=>a.q2,a=>a.q3,a=>a.max,a=>a.upperOutliers];this.orientation===B2.HORIZONTAL?this.boxValues=this.points.map(a=>l.map(i=>i(a))):this.boxValues=l.map(a=>this.points.map(i=>a(i)));const o=this.boxValues.map(a=>a.flatMap(i=>Array.isArray(i)?i:[i]));this.min=$3.minFrom2D(o),this.max=$3.maxFrom2D(o),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,l){const o=this.orientation===B2.HORIZONTAL;n=o?n:l,l=o?l:n,super.moveToIndex(n,l)}get values(){return this.boxValues}audio(){const n=this.boxValues[this.row][this.col],l=Array.isArray(n)?n.map(o=>o-this.min):n-this.min;return{min:this.min,max:this.max,value:n,size:this.max-this.min,index:l}}braille(){const n=this.orientation===B2.HORIZONTAL,l=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:l,col:o}}text(){const n=this.orientation===B2.HORIZONTAL,l=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,a=n?this.sections[this.col]:this.sections[this.row],i=n?this.xAxis:this.yAxis,s=this.boxValues[this.row][this.col];return{main:{label:o,value:l.fill},cross:{label:i,value:s},section:a}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const l=this.orientation===B2.VERTICAL,o=new Array;if(l)for(let a=0;a<this.sections.length;a++)o.push(Array.from({length:n.length}));return n.forEach((a,i)=>{const s=a.lowerOutliers.flatMap(b=>C1.selectAllElements(b)),c=a.upperOutliers.flatMap(b=>C1.selectAllElements(b)),u=C1.selectElement(a.min)??C1.createEmptyElement(),Q=C1.selectElement(a.max)??C1.createEmptyElement(),f=C1.selectElement(a.iq)??C1.createEmptyElement(),h=C1.selectElement(a.q2)??C1.createEmptyElement(),[p,g]=l?[C1.createLineElement(f,"top"),C1.createLineElement(f,"bottom")]:[C1.createLineElement(f,"left"),C1.createLineElement(f,"right")],v=[s,u,p,h,g,Q,c];l?v.forEach((b,L)=>{o[L][i]=b}):o.push(v)}),o}}const ij="Trend";class aj extends As{constructor(n){super(n);ae(this,"candles");ae(this,"candleValues");ae(this,"orientation");ae(this,"sections",["open","high","low","close"]);ae(this,"currentSegmentType","open");ae(this,"currentPointIndex",0);ae(this,"sortedSegmentsByPoint");ae(this,"segmentPositionMaps");ae(this,"min");ae(this,"max");ae(this,"highlightValues");ae(this,"navigationService");this.navigationService=new rS;const l=n.data;this.candles=l.map(a=>({...a,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=n.orientation??B2.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(i=>i[a])),this.min=$3.minFrom2D(this.candleValues),this.max=$3.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="open",this.orientation===B2.HORIZONTAL?this.col=0:this.row=0;const o=typeof n.selectors=="string"?n.selectors:"";this.highlightValues=this.mapToSvgElements(o)}precomputeSortedSegments(){return this.candles.map(n=>this.sections.map(o=>[o,n[o]]).sort((o,a)=>o[1]-a[1]).map(o=>o[0]))}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const l=new Map;return n.forEach((o,a)=>{l.set(o,a)}),l})}getSegmentPositionInSortedOrder(n,l){return this.segmentPositionMaps[n].get(l)??0}getSegmentTypeAtSortedPosition(n,l){return this.sortedSegmentsByPoint[n][l]??"open"}updateVisualSegmentPosition(){const n=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType);this.orientation===B2.HORIZONTAL?this.col=n:this.row=n}updateVisualPointPosition(){this.orientation===B2.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=n==="UPWARD"?l+1:l-1;if(o>=0&&o<this.sections.length)this.currentSegmentType=this.getSegmentTypeAtSortedPosition(this.currentPointIndex,o),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(l>=0&&l<this.candles.length)this.currentPointIndex=l,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[l.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const l=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=l[0],this.updateVisualSegmentPosition();break}case"FORWARD":{this.currentPointIndex=this.candles.length-1,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}case"BACKWARD":{this.currentPointIndex=0,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}}this.notifyStateUpdate()}moveToIndex(n,l){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:o,segmentType:a}=this.navigationService.computeIndexAndSegment(n,l,this.orientation,this.sections);this.currentPointIndex=o,this.currentSegmentType=a,this.row=n,this.col=l,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const l=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType),o=n==="UPWARD"?l+1:l-1;return o>=0&&o<this.sections.length}case"FORWARD":case"BACKWARD":{const l=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return l>=0&&l<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){const n=this.candles[this.currentPointIndex][this.currentSegmentType];return{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:n,trend:this.candles[this.currentPointIndex].trend}}braille(){const n=this.candles.map(l=>l.trend);return{empty:!1,id:this.id,values:this.candleValues,min:this.min,max:this.max,row:this.row,col:this.col,custom:n}}mapToSvgElements(n){if(!n)return null;const l=C1.selectAllElements(n),o=[];for(let a=0;a<this.sections.length;a++){o[a]=[];for(let i=0;i<this.candles.length;i++){const s=i<l.length?i:0;o[a][i]=l[s]}}return o}text(){const n=this.candles[this.currentPointIndex],l=n[this.currentSegmentType];return{main:{label:this.orientation===B2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===B2.HORIZONTAL?this.xAxis:this.yAxis,value:l},section:this.currentSegmentType,fill:{label:ij,value:n.trend}}}getCurrentTrend(){return this.candles[this.currentPointIndex].trend}getCurrentXValue(){return this.currentPointIndex>=0&&this.currentPointIndex<this.candles.length?this.candles[this.currentPointIndex].value:null}moveToXValue(n){const l=this.candles.findIndex(o=>o.value===n);return l!==-1?(this.currentPointIndex=l,this.currentSegmentType="open",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}}class oj extends As{constructor(n){super(n);ae(this,"heatmapValues");ae(this,"highlightValues");ae(this,"x");ae(this,"y");ae(this,"min");ae(this,"max");const l=n.data;this.x=l.x,this.y=[...l.y].reverse(),this.heatmapValues=[...l.points].reverse();const{min:o,max:a}=$3.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=a,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get values(){return this.heatmapValues}audio(){return{min:this.min,max:this.max,size:this.heatmapValues.length,index:this.col,value:this.heatmapValues[this.row][this.col]}}braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){return{main:{label:this.xAxis,value:this.x[this.col]},cross:{label:this.yAxis,value:this.y[this.row]},fill:{label:this.fill,value:String(this.heatmapValues[this.row][this.col])}}}mapToSvgElements(n){if(!n)return null;const l=this.heatmapValues.length,o=this.heatmapValues[0].length,a=C1.selectAllElements(n);if(a.length===0||a.length!==l*o)return null;const i=new Array;if(a[0]instanceof SVGPathElement)for(let s=0;s<l;s++){const c=l-1-s,u=new Array;for(let Q=0;Q<o;Q++){const f=c*o+Q;u.push(a[f])}i.push(u)}else if(a[0]instanceof SVGRectElement)for(let s=0;s<l;s++){const c=new Array;for(let u=0;u<o;u++){const Q=u*l+s;c.push(a[Q])}i.push(c)}return i}}class lj extends xv{constructor(t){super(t,[t.data])}text(){const t=this.orientation===B2.VERTICAL,n=this.points[this.row][this.col],l=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text(),range:{min:l,max:o}}}}const iS="Group",bv=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class aS extends As{constructor(n){super(n);ae(this,"points");ae(this,"lineValues");ae(this,"highlightValues");ae(this,"min");ae(this,"max");ae(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(l=>l.map(o=>Number(o.y))),this.min=this.lineValues.map(l=>$3.safeMin(l)),this.max=this.lineValues.map(l=>$3.safeMax(l)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.lineValues}audio(){return{min:this.min[this.row],max:this.max[this.row],size:this.points[this.row].length,index:this.col,value:this.points[this.row][this.col].y,...this.getAudioGroupIndex()}}braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}text(){var a;const n=this.points[this.row][this.col],l=this.findIntersections();let o={};if(l.length>1){let i=l.map(s=>{var u;const c=s.groupIndex;return((u=this.points[c][0])==null?void 0:u.fill)||`l${c+1}`});if(this.previousRow!==null){const s=((a=this.points[this.previousRow][0])==null?void 0:a.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}o={fill:{label:iS,value:`intersection at (${i.join(", ")})`}}}else o=n.fill?{fill:{label:iS,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...o}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const o=this.findLineByXAndYDirection(n),a=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const i=this.findColumnByXValue(o,a);if(i!==-1){this.row=o,this.col=i;const s=this.findIntersections();if(s.length>1){const u={...super.state,intersections:s};for(const Q of this.observers)Q.update(u)}else this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}else{this.notifyOutOfBounds();return}}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const l=this.findIntersections();if(l.length>1){const a={...super.state,intersections:l};for(const i of this.observers)i.update(a)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,l=this.points[this.row][this.col].y,o=[];for(let a=0;a<this.points.length;a++){const i=this.points[a].findIndex(s=>s.x===n&&s.y===l);i!==-1&&o.push({min:this.min[a],max:this.max[a],size:this.points[a].length,index:i,value:l,groupIndex:a})}return o}isMovable(n){if(Array.isArray(n)){const[l,o]=n;return l>=0&&l<this.values.length&&o>=0&&o<this.values[l].length}switch(n){case"UPWARD":case"DOWNWARD":{const l=this.findLineByXAndYDirection(n);if(l===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(l,o)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const l=this.points[this.row][this.col].x;let o=null,a=Number.POSITIVE_INFINITY;for(let i=0;i<this.points.length;i++){if(i===this.row)continue;const s=this.points[i].findIndex(f=>f.x===l);if(s===-1)continue;const c=this.points[i][s].y,u=n==="UPWARD"?c>this.points[this.row][this.col].y:c<this.points[this.row][this.col].y,Q=Math.abs(c-this.points[this.row][this.col].y);u&&Q<a&&(a=Q,o=i)}return o}findColumnByXValue(n,l){return this.points[n].findIndex(o=>o.x===l)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const l=[];let o=!0;for(let a=0;a<n.length;a++){const i=C1.selectElement(n[a],!1);if(!i){l.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(xe.D)||xe.EMPTY;bv.lastIndex=0;let f=bv.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=bv.exec(Q)}else if(i instanceof SVGPolylineElement){const f=(i.getAttribute(xe.POINTS)||xe.EMPTY).split(/\s+/).filter(Boolean);for(const h of f){const[p,g]=h.split(xe.COMMA);s.push({x:Number.parseFloat(p),y:Number.parseFloat(g)})}}if(s.length!==this.lineValues[a].length)if(s.length<this.lineValues[a].length)for(;s.length<this.lineValues[a].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[a].length&&(s.length=this.lineValues[a].length);const c=[];let u=!1;for(const Q of s){if(Number.isNaN(Q.x)||Number.isNaN(Q.y)){u=!0;break}c.push(C1.createCircleElement(Q.x,Q.y,i))}if(u){l.push([]);continue}c.length>0&&(o=!1),l.push(c)}return o?null:l}get state(){const n=super.state;if(n.empty)return n;const l={...n,plotType:this.points.length>1?"multiline":"single line"},o=this.findIntersections();return o.length>1?{...l,intersections:o}:l}}class sj extends As{constructor(n){super(n);ae(this,"mode");ae(this,"xPoints");ae(this,"yPoints");ae(this,"xValues");ae(this,"yValues");ae(this,"highlightXValues");ae(this,"highlightYValues");ae(this,"minX");ae(this,"maxX");ae(this,"minY");ae(this,"maxY");this.mode="column";const l=n.data,o=[...l].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let a=null;for(const c of o)(!a||a.x!==c.x)&&(a={x:c.x,y:[]},this.xPoints.push(a)),a.y.push(c.y);const i=[...l].sort((c,u)=>c.y-u.y||c.x-u.x);this.yPoints=new Array;let s=null;for(const c of i)(!s||s.y!==c.y)&&(s={y:c.y,x:[]},this.yPoints.push(s)),s.x.push(c.x);this.xValues=this.xPoints.map(c=>c.x),this.yValues=this.yPoints.map(c=>c.y),this.minX=$3.safeMin(this.xValues),this.maxX=$3.safeMax(this.xValues),this.minY=$3.safeMin(this.yValues),this.maxY=$3.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors)}dispose(){this.xPoints.length=0,this.yPoints.length=0,this.xValues.length=0,this.yValues.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(l=>l.remove())),this.highlightYValues.length=0),super.dispose()}get values(){const n=[this.xValues,this.yValues];return this.mode==="column"?this.row!==0&&(this.row=0):(this.row<0||this.row>=this.yPoints.length)&&(this.row=0),n}get highlightValues(){return this.mode==="column"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}audio(){if(this.mode==="column"){const n=this.xPoints[this.col];return{min:this.minY,max:this.maxY,size:n.y.length,index:this.col,value:n.y,...this.getAudioGroupIndex()}}else{const n=this.yPoints[this.row];return{min:this.minX,max:this.maxX,size:n.x.length,index:this.row,value:n.x,...this.getAudioGroupIndex()}}}braille(){return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}text(){if(this.mode==="column"){const n=this.xPoints[this.col];return{main:{label:this.xAxis,value:n.x},cross:{label:this.yAxis,value:n.y}}}else{const n=this.yPoints[this.row];return{main:{label:this.yAxis,value:n.y},cross:{label:this.xAxis,value:n.x}}}}get autoplay(){return{UPWARD:this.yValues.length,DOWNWARD:this.yValues.length,FORWARD:this.xValues.length,BACKWARD:this.xValues.length}}highlight(){if(this.highlightValues===null)return{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}};const n=this.mode==="column"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return n?{empty:!1,elements:n}:{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}}hasMultiPoints(){return!0}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0,this.mode="column"}toggleNavigation(){if(this.mode==="column"){const n=this.xPoints[this.col],l=n.y[Math.floor(n.y.length/2)],o=this.yValues.indexOf(l);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],l=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(l);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const l=C1.selectAllElements(n);if(l.length===0)return[null,null];const o=new Map,a=new Map;l.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(o.has(u)||o.set(u,[]),o.get(u).push(c)),Number.isNaN(Q)||(a.has(Q)||a.set(Q,[]),a.get(Q).push(c))});const i=Array.from(o.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(a.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const oS="Sum",uj="Level",cj="undefined";class Tj extends xv{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let a=0;a<this.barValues[0].length;a++){const i=this.barValues.reduce((c,u)=>c+u[a],0);t.push(i);const s=this.orientation===B2.VERTICAL?{x:this.points[0][a].x,y:i,fill:oS}:{x:i,y:this.points[0][a].y,fill:oS};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:l,max:o}=$3.minMax(t);this.min.push(l),this.max.push(o)}text(){return{...super.text(),fill:{label:uj,value:this.points[this.row][this.col].fill??cj}}}highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?{empty:!0,type:"trace",traceType:this.type,audio:{index:0,size:0,groupIndex:0}}:{empty:!1,elements:this.highlightValues[this.row][this.col]}}hasMultiPoints(){return!1}mapToSvgElements(t){if(!t)return new Array;const n=C1.selectAllElements(t);if(n.length===0)return new Array;const l=new Array;if(n[0]instanceof SVGPathElement)for(let o=0,a=0;o<this.barValues.length;o++){const i=new Array;for(let s=0;s<this.barValues[o].length;s++){if(a>=n.length)return new Array;this.barValues[o][s]===0?i.push(C1.createEmptyElement()):i.push(n[a++])}l.push(i)}else if(n[0]instanceof SVGRectElement){for(let o=0;o<this.barValues.length;o++)l.push(new Array);for(let o=0,a=0;o<this.barValues[0].length;o++)for(let i=this.barValues.length-1;i>=0;i--){if(a>=n.length)return new Array;this.barValues[i][o]===0?l[i].push(C1.createEmptyElement()):l[i].push(n[a++])}}return l}}class lS extends aS{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],n=this.col,l=s=>t[Math.max(0,Math.min(s,t.length-1))],o=n>0?l(n-1):l(n),a=l(n),i=n<t.length-1?l(n+1):l(n);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:n,value:[o,a,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class Qj extends lS{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let l=!0;for(let a=0;a<t.length;a++){const i=C1.selectElement(t[a],!1);if(!i){n.push([]);continue}const s=(o=this.points)==null?void 0:o[a],c=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&c.push(C1.createCircleElement(u.svg_x,u.svg_y,i));c.length>0&&(l=!1),n.push(c)}return l?null:n}}function fj(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function dj(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&fj(e.data[0][0])?new Qj(e):new lS(e)}class hj{static create(t){switch(t.type){case P2.BAR:return new XI(t);case P2.BOX:return new rj(t);case P2.CANDLESTICK:return new aj(t);case P2.HEATMAP:return new oj(t);case P2.HISTOGRAM:return new lj(t);case P2.LINE:return new aS(t);case P2.SCATTER:return new sj(t);case P2.SMOOTH:return dj(t);case P2.DODGED:case P2.NORMALIZED:case P2.STACKED:return new Tj(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const pj="MAIDR Plot",mj="unavailable",yj="unavailable";class gj extends Lv{constructor(n){super();ae(this,"id");ae(this,"title");ae(this,"subtitle");ae(this,"caption");ae(this,"subplots");ae(this,"size");this.id=n.id,this.title=n.title??pj,this.subtitle=n.subtitle??mj,this.caption=n.caption??yj;const l=n.subplots;this.subplots=l.map(o=>o.map(a=>new vj(a))),this.size=this.subplots.reduce((o,a)=>o+a.length,0)}dispose(){this.subplots.forEach(n=>n.forEach(l=>l.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((o,a)=>o+a.length,0),l=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:l.getStateWithFigurePosition(this.row,this.col),traceTypes:l.traceTypes,highlight:this.highlight()}}highlight(){var l;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}};try{const o=((l=this.subplots[0])==null?void 0:l.length)||1,a=this.row*o+this.col+1,i=`g[id="axes_${a}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&a-1<c.length)return{empty:!1,elements:c[a-1]}}catch{return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}}class vj extends Lv{constructor(n){super();ae(this,"traces");ae(this,"traceTypes");ae(this,"size");this.isInitialEntry=!1;const l=n.layers;this.size=l.length,this.traces=l.map(o=>[hj.create(o)]),this.traceTypes=this.traces.flat().map(o=>{const a=o.state;return a.empty?xe.EMPTY:a.traceType})}dispose(){this.traces.forEach(n=>n.forEach(l=>l.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}highlight(){return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}get state(){return this.isOutOfBounds?{empty:!0,type:"subplot"}:{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight()}}getStateWithFigurePosition(n,l){return this.state}}const U3={SINE_BASIC:0,SQUARE_BASIC:1,SAWTOOTH_BASIC:2,TRIANGLE_BASIC:3,SAWTOOTH_DARK:4,SINE_HARMONIC:5,TRIANGLE_HARMONIC:6,SQUARE_HARMONIC:7,TRIANGLE_MELLOW:8,SINE_SUBTLE:9,SAWTOOTH_SOFT:10},Q9=class Q9{constructor(){ae(this,"basePalette");ae(this,"extendedPalette");this.basePalette=[{index:U3.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:U3.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:U3.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:U3.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:U3.SAWTOOTH_DARK,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.2},{frequency:3,amplitude:.1},{frequency:5,amplitude:.05}]},timbreModulation:{attack:.005,decay:.3,sustain:.4,release:.5}},{index:U3.SINE_HARMONIC,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.15},{frequency:4,amplitude:.05}]},timbreModulation:{attack:.02,decay:.2,sustain:.6,release:.3}},{index:U3.TRIANGLE_HARMONIC,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.2},{frequency:6,amplitude:.1}]},timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:U3.SQUARE_HARMONIC,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:3,amplitude:.1},{frequency:7,amplitude:.05}]},timbreModulation:{attack:.005,decay:.05,sustain:.5,release:.1}},{index:U3.TRIANGLE_MELLOW,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:2.5,amplitude:.15},{frequency:4.5,amplitude:.08}]},timbreModulation:{attack:.01,decay:.4,sustain:.3,release:.5}},{index:U3.SINE_SUBTLE,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.1},{frequency:3,amplitude:.05}]},timbreModulation:{attack:.02,decay:.1,sustain:.9,release:.15}},{index:U3.SAWTOOTH_SOFT,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.05},{frequency:6,amplitude:.02}]},timbreModulation:{attack:.005,decay:.4,sustain:.2,release:.6}}],this.validateBasePalette(),this.extendedPalette=new Map,this.generateExtendedPalette()}dispose(){this.extendedPalette.clear()}getPaletteEntry(t){if(t<this.basePalette.length)return this.basePalette[t];const n=this.extendedPalette.get(t);if(n)return n;const l=this.generateExtendedEntry(t);return this.extendedPalette.set(t,l),l}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return U3.SINE_BASIC;case"Bear":return U3.SAWTOOTH_SOFT;case"Neutral":return U3.TRIANGLE_BASIC;default:return U3.SINE_BASIC}}generateExtendedPalette(){[{index:this.basePalette.length,waveType:"sine",harmonicMix:{fundamental:1,harmonics:[{frequency:2,amplitude:.3},{frequency:3,amplitude:.15}]},timbreModulation:{attack:.02,decay:.15,sustain:.7,release:.3}},{index:this.basePalette.length+1,waveType:"square",harmonicMix:{fundamental:1,harmonics:[{frequency:1.5,amplitude:.4},{frequency:2.5,amplitude:.2}]},timbreModulation:{attack:.01,decay:.08,sustain:.6,release:.4}},{index:this.basePalette.length+2,waveType:"sawtooth",harmonicMix:{fundamental:1,harmonics:[{frequency:1.25,amplitude:.35},{frequency:2,amplitude:.25},{frequency:3,amplitude:.1}]},timbreModulation:{attack:.03,decay:.2,sustain:.5,release:.35}},{index:this.basePalette.length+3,waveType:"triangle",harmonicMix:{fundamental:1,harmonics:[{frequency:.5,amplitude:.2},{frequency:4,amplitude:.15}]},timbreModulation:{attack:.025,decay:.18,sustain:.8,release:.25}}].forEach((n,l)=>{this.extendedPalette.set(this.basePalette.length+l,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,l=this.basePalette[n],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),a=this.generateHarmonics(o),i=this.generateTimbreModulation(o,l.timbreModulation);return{index:t,waveType:l.waveType,harmonicMix:{fundamental:1,harmonics:a},timbreModulation:i}}generateHarmonics(t){const n=[],l=Q9.MIN_HARMONICS+t%Q9.HARMONIC_VARIATION;for(let o=0;o<l;o++){const a=1+(o+1)*(.5+t*.3%1),i=.4/(o+1)*(1-t*.1%.3);n.push({frequency:a,amplitude:i})}return n}generateTimbreModulation(t,n){const l=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*l)),decay:Math.max(.05,Math.min(.3,n.decay*l)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*l))}}validateBasePalette(){this.basePalette.forEach((t,n)=>{if(t.index!==n)throw new Error(`AudioPalette validation error: Entry at array position ${n} has index ${t.index}. Array position must match the index property to prevent audio palette mismatches.`)})}};ae(Q9,"MIN_HARMONICS",2),ae(Q9,"HARMONIC_VARIATION",3);let Hv=Q9;const Lj=100,xj=440,bj=880,Sv=.3,Ev=U3.SINE_BASIC;class Hj{constructor(t,n,l){ae(this,"notification");ae(this,"audioPalette");ae(this,"settings");ae(this,"isCombinedAudio");ae(this,"mode");ae(this,"activeAudioIds");ae(this,"audioContext");ae(this,"compressor");ae(this,"currentVolume");ae(this,"currentMinFrequency");ae(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new Hv,this.settings=l,this.isCombinedAudio=!1,this.mode="on",this.updateMode(n),this.activeAudioIds=new Map,this.audioContext=new AudioContext,this.compressor=this.initCompressor();const o=this.settings.loadSettings();this.currentVolume=o.general.volume/100,this.currentMinFrequency=o.general.minFrequency,this.currentMaxFrequency=o.general.maxFrequency,this.settings.addObserver(this)}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close()),this.settings.removeObserver(this)}update(t){"general"in t?this.onSettingsChange(t):this.onStateChange(t)}onSettingsChange(t){this.currentVolume=t.general.volume/100,this.currentMinFrequency=t.general.minFrequency,this.currentMaxFrequency=t.general.maxFrequency}onStateChange(t){if(this.updateMode(t),this.mode==="off"||t.type!=="trace")return;const n=t;if(n.empty){this.playEmptyTone(n.audio.size,n.audio.index);return}if(n.traceType==="line"&&!n.empty&&Array.isArray(n.intersections)&&n.intersections.length>1){this.stopAll(),this.playSimultaneousTones(n.intersections);return}const l=n.audio;let o=l.groupIndex;l.trend&&o===void 0&&(o=this.audioPalette.getCandlestickGroupIndex(l.trend));const i=o!==void 0?this.audioPalette.getPaletteEntry(o):void 0;if(l.isContinuous)this.playSmooth(l.value,l.min,l.max,l.size,Array.isArray(l.index)?l.index[0]:l.index,i);else if(Array.isArray(l.value)){const s=l.value;if(s.length===0){this.playZeroTone();return}let c=0;const u=this.mode==="on"?50:0,Q=new Array,f=()=>{if(c<s.length){const h=Array.isArray(l.index)?l.index[c]:l.index;this.playTone(l.min,l.max,s[c++],l.size,h,i),Q.push(setTimeout(f,u))}else this.stop(Q)};f()}else{const s=l.value;if(s===0)this.playZeroTone();else{const c=Array.isArray(l.index)?l.index[0]:l.index;this.playTone(l.min,l.max,s,l.size,c,i)}}}getVolume(){return Math.min(Math.max(this.currentVolume,0),1)}getFrequencyRange(){return{min:this.currentMinFrequency,max:this.currentMaxFrequency}}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const n=this.audioContext.createGain();return n.gain.value=.5,t.connect(n),n.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;n.empty||n.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=n.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}playTone(t,n,l,o,a,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(l,s,c),Q={min:0,max:o},f={min:-1,max:1},h=this.clamp(this.interpolate(a,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const l=[],o=this.audioContext.createOscillator();if(o.type=t.waveType,o.frequency.value=n,l.push(o),t.harmonicMix)for(const a of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=a.frequency*n,l.push(i)}return l}createGainNodes(t,n,l,o){const a=[],i=this.audioContext.currentTime,s=this.getVolume();for(let c=0;c<t.length;c++){const u=this.audioContext.createGain();let Q=s;if(c===0)n.harmonicMix&&(Q*=n.harmonicMix.fundamental);else{const h=n.harmonicMix.harmonics[c-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,n,Q,i,o);f!==null&&u.gain.setValueCurveAtTime(f,i,o),a.push(u)}return a}playOscillator(t,n=0,l){const o=Sv,a=this.getVolume();l||(l=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(l,t),s=this.createGainNodes(i,l,a,o),c=this.audioContext.createStereoPanner();c.pan.value=n;const u=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let h=0;h<i.length;h++)i[h].connect(s[h]),s[h].connect(c);c.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),c.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(c),i[p].stop(),i[p].disconnect(s[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),o*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,l,o,a){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=a*i,f=a*s,h=a*u,p=a-Q-f-h;return t.gain.setValueAtTime(1e-4*l,o),t.gain.linearRampToValueAtTime(l,o+Q),t.gain.linearRampToValueAtTime(c*l,o+Q+f),p>0&&t.gain.setValueAtTime(c*l,o+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*l,o+a),null}else return[.5*l,l,.5*l,.5*l,.5*l,.1*l,1e-4*l]}playSmooth(t,n,l,o,a,i){const s=this.audioContext,c=s.currentTime,u=Sv,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(O=>this.interpolate(O,{min:n,max:l},Q));p.length<2&&p.push(p[0]);const g=this.clamp(this.interpolate(a,{min:0,max:o-1},{min:-1,max:1}),-1,1),v=s.createOscillator();v.type=h,v.frequency.setValueCurveAtTime(p,c,u);const b=s.createGain(),L=this.createAdsrEnvelope(b,i,f,c,u);L!==null&&b.gain.setValueCurveAtTime(L,c,u);const S=s.createStereoPanner();S.pan.value=g,v.connect(b),b.connect(S),S.connect(this.compressor),v.start(c),v.stop(c+u);const _=setTimeout(()=>{v.disconnect(),b.disconnect(),S.disconnect(),this.activeAudioIds.delete(_)},u*1e3*2);this.activeAudioIds.set(_,[v])}playEmptyTone(t,n){const l=this.audioContext,o=l.currentTime,a=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=l.createGain();u.gain.setValueAtTime(.3*i,o),u.gain.exponentialRampToValueAtTime(.01*i,o+a),u.connect(this.compressor);const Q={min:0,max:t},f={min:-1,max:1},h=this.clamp(this.interpolate(n,Q,f),-1,1),p=[];for(let b=0;b<s.length;b++){const L=l.createOscillator(),S=l.createGain(),_=this.audioContext.createStereoPanner(),O=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});L.frequency.value=s[b],L.type="sine",S.gain.setValueAtTime(c[b]*i,o),S.gain.exponentialRampToValueAtTime(.001*i,o+a),_.pan.value=h,L.connect(S),S.connect(_),_.connect(O),O.connect(u),L.start(o),L.stop(o+a),p.push(L)}const g=b=>{u.disconnect(),p.forEach(L=>{L.disconnect()}),this.activeAudioIds.delete(b)},v=setTimeout(()=>g(v),a*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(Lj,0,{index:Ev,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(xj,0,{index:Ev,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(bj,0,{index:Ev,waveType:"sine"})}interpolate(t,n,l){return n.min===0&&n.max===0?0:(t-n.min)/(n.max-n.min)*(l.max-l.min)+l.min}clamp(t,n,l){return Math.max(n,Math.min(t,l))}toggle(){switch(this.mode){case"off":this.mode=this.isCombinedAudio?"combined":"on";break;case"on":this.mode="off";break;case"combined":this.mode="on";break}const n=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(n)}stop(t){(Array.isArray(t)?t:[t]).forEach(l=>{const o=this.activeAudioIds.get(l);if(!o){clearInterval(l);return}o.forEach(a=>{a==null||a.disconnect(),a==null||a.stop()}),clearTimeout(l),this.activeAudioIds.delete(l)})}stopAll(){this.activeAudioIds.entries().forEach(([t,n])=>{clearTimeout(t),n.forEach(l=>{l.disconnect(),l.stop()})}),this.activeAudioIds.clear()}playSimultaneousTones(t){const n=this.getVolume(),l=Sv,o=this.audioContext,a=o.currentTime,i=this.getFrequencyRange(),s=Array.isArray(t[0].value)?t[0].value[1]??t[0].value[0]:t[0].value,c=t[0].min,u=t[0].max,Q=this.interpolate(s,{min:c,max:u},i);t.forEach((f,h)=>{const p=Q,v=this.audioPalette.getPaletteEntry(h).waveType,b=o.createOscillator();b.type=v,b.frequency.value=p;const L=o.createGain();L.gain.setValueAtTime(n,a),L.gain.exponentialRampToValueAtTime(.01*n,a+l),b.connect(L),L.connect(this.compressor),b.start(a),b.stop(a+l);const S=setTimeout(()=>{b.disconnect(),L.disconnect()},l*1e3*2);this.activeAudioIds.set(S,[b])})}}const Sj=250,Ej=50,Mj=500,Aj=20;class _j{constructor(t,n,l){ae(this,"context");ae(this,"notification");ae(this,"settings");ae(this,"autoplayId");ae(this,"currentDirection");ae(this,"userSpeed");ae(this,"defaultSpeed");ae(this,"minSpeed");ae(this,"maxSpeed");ae(this,"autoplayRate");ae(this,"interval");ae(this,"currentDuration");ae(this,"onChangeEmitter");ae(this,"onChange");this.notification=n,this.context=t,this.settings=l,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=Sj,this.minSpeed=Ej,this.maxSpeed=Mj,this.autoplayRate=this.defaultSpeed,this.interval=Aj,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new Ms,this.onChange=this.onChangeEmitter.event,this.settings.addObserver(this)}dispose(){this.stop(),this.onChangeEmitter.dispose(),this.settings.removeObserver(this)}update(t){this.updateSettings(t)}updateSettings(t){this.currentDuration=t.general.autoplayDuration,this.currentDirection&&this.restart()}start(t,n){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,n),this.currentDirection=t,this.autoplayId=setInterval(()=>{this.context.isMovable(t)?this.context.moveOnce(t):this.stop()},this.autoplayRate)}stop(){this.autoplayId&&clearInterval(this.autoplayId),this.autoplayId=null,this.currentDirection=null,this.onChangeEmitter.fire({type:"stop"})}restart(){this.autoplayId&&clearInterval(this.autoplayId),this.currentDirection&&this.start(this.currentDirection)}speedUp(){const t=this.userSpeed??this.autoplayRate;t-this.interval>this.minSpeed?(this.userSpeed=t-this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed up")):this.notification.notify("Max speed")}speedDown(){const t=this.userSpeed??this.autoplayRate;t+this.interval<=this.maxSpeed?(this.userSpeed=t+this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed down")):this.notification.notify("Min speed")}resetSpeed(){this.userSpeed=null,this.autoplayRate=this.defaultSpeed,this.restart(),this.notification.notify("Reset speed")}getAutoplayRate(t,n){if(this.userSpeed!==null)return this.userSpeed;if(n&&!n.empty){const l=Math.ceil(this.currentDuration/n.autoplay[t]);return this.defaultSpeed=l,this.minSpeed=Math.min(this.minSpeed,l),l}return this.defaultSpeed}}const sS=32;class Rc{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const i=(t.max[a]-t.min[a])/4,s=t.min[a]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[a].length;Q++)t.values[a][Q]===0?n.push(" "):t.values[a][Q]<=s||t.values[a][Q]<=c?n.push("⠤"):t.values[a][Q]<=u?n.push("⠒"):n.push("⠉"),l[a].push(o.length),o.push({row:a,col:Q});n.push(xe.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}}class Oj{constructor(){ae(this,"GLOBAL_MIN","globalMin");ae(this,"GLOBAL_MAX","globalMax");ae(this,"BLANK","blank");ae(this,"LOWER_OUTLIER","lowerOutlier");ae(this,"UPPER_OUTLIER","upperOutlier");ae(this,"MIN","min");ae(this,"MAX","max");ae(this,"Q1","q1");ae(this,"Q2","q2");ae(this,"Q3","q3")}encode(t,n=sS){const l=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],c=[{type:this.GLOBAL_MIN,value:t.min},...s.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:s.min},{type:this.Q1,value:s.q1},{type:this.Q2,value:s.q2},{type:this.Q3,value:s.q3},{type:this.MAX,value:s.max},...s.upperOutliers.map(V=>({type:this.UPPER_OUTLIER,value:V})),{type:this.GLOBAL_MAX,value:t.max}],u=new Array;let Q=!0;for(let V=0;V<c.length-1;V++){const k=c[V],B=c[V+1],R=Math.abs(Q?B.value-k.value:k.value-c[V-1].value);k.type===this.LOWER_OUTLIER||k.type===this.UPPER_OUTLIER?(u.push({type:k.type,length:0,numChars:1}),u.push({type:this.BLANK,length:R,numChars:0})):k.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):k.type===this.GLOBAL_MIN||k.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:R,numChars:0}):u.push({type:k.type,length:R,numChars:1})}let f=u.reduce((V,k)=>V+(k.numChars>0?k.numChars:0),0),[h,p,g,v]=[-1,-1,-1,-1];for(let V=0;V<u.length;V++)u[V].type===this.MIN&&u[V].length>0&&(h=V),u[V].type===this.MAX&&u[V].length>0&&(p=V),u[V].type===this.Q1&&(g=V),u[V].type===this.Q3&&(v=V);h!==-1&&p!==-1&&u[h].length!==u[p].length&&(u[h].length>u[p].length?(u[h].numChars++,f++):(u[p].numChars++,f++)),g!==-1&&v!==-1&&u[g].length!==u[v].length&&(u[g].length>u[v].length?(u[g].numChars++,f++):(u[v].numChars++,f++));const b=Math.max(0,n-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 S=u.reduce((V,k)=>V+k.numChars,0);let _=n-S,O=0;for(;_!==0;){const V=u[O%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=_>0?1:-1,_+=_>0?-1:1),O++}let E=-1;const A=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];a.push(Array.from({length:A.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(E=A.indexOf(V.type),a[i][E]=l.length);for(let k=0;k<V.numChars;k++){let B="⠀";V.type===this.MIN||V.type===this.MAX?B="⠒":V.type===this.Q1||V.type===this.Q3?B="⠿":V.type===this.Q2?B=k===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?B="⠂":V.type===this.BLANK&&(B="⠀"),l.push(B),o.push({row:i,col:E})}}for(let V=0;V<3;V++)if(a[i][V]===-1){for(let k=V+1;k<=3;k++)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}for(let V=6;V>3;V--)if(a[i][V]===-1){for(let k=V-1;k>=3;k--)if(a[i][k]!==-1){a[i][V]=a[i][k];break}}l.push(xe.NEW_LINE),o.push({row:i,col:E})}return{value:l.join(xe.EMPTY),cellToIndex:a,indexToCell:o}}}class Cj{encode(t){const n=new Array,l=new Array,o=new Array,a=(t.max-t.min)/3,i=t.min+a,s=i+a;for(let c=0;c<t.values.length;c++){l.push(new Array);for(let u=0;u<t.values[c].length;u++)t.values[c][u]===0?n.push(" "):t.values[c][u]<=i?n.push("⠤"):t.values[c][u]<=s?n.push("⠒"):n.push("⠉"),l[c].push(o.length),o.push({row:c,col:u});n.push(xe.NEW_LINE),l[c].push(o.length),o.push({row:c,col:t.values[c].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}}class uS{encode(t){const n=new Array,l=new Array,o=new Array;for(let a=0;a<t.values.length;a++){l.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(a,t);for(let Q=0;Q<t.values[a].length;Q++){const f=t.values[a][Q],h=Q>0?t.values[a][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),l[a].push(o.length),o.push({row:a,col:Q})}n.push(xe.NEW_LINE),l[a].push(o.length),o.push({row:a,col:t.values[a].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}getBrailleChar(t,n,l,o,a,i){return i===void 0&&(i=a),t<=l&&n!==null&&n>l?n<=o?"⢄":n<=i?"⢆":"⢇":t<=l?"⣀":n!==null&&n<=l?t<=o?"⡠":t<=i?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=i?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=a?"⠉":""}getBraille6Char(t,n,l,o,a){const i=f=>f<=l?"low":f<=o?"medium":(f<=a,"high"),s=i(t),c=n!==null?i(n):null,u={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},Q=`${s},${c}`;return u[Q]||""}addDot8(t){if(!t||t.length===0)return"⢀";const o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class wj extends uS{getThresholds(t,n){const l=(n.max-n.min)/3,o=n.min+l,a=o+l,i=n.max;return{low:o,medium:a,high:i}}encode(t){var a;const n=new Array,l=new Array,o=new Array;for(let i=0;i<t.values.length;i++){l.push(new Array);const{low:s,medium:c,high:u}=this.getThresholds(i,t);for(let Q=0;Q<t.values[i].length;Q++){const f=t.values[i][Q],h=Q>0?t.values[i][Q-1]:null;let p=this.getBraille6Char(f,h,s,c,u);((a=t.custom)==null?void 0:a[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),l[i].push(o.length),o.push({row:i,col:Q})}n.push(xe.NEW_LINE),l[i].push(o.length),o.push({row:i,col:t.values[i].length})}return{value:n.join(xe.EMPTY),cellToIndex:l,indexToCell:o}}}class Vj extends uS{getThresholds(t,n){const l=(n.max[t]-n.min[t])/4,o=n.min[t]+l,a=o+l,i=a+l,s=n.max[t];return{low:o,medium:a,mediumHigh:i,high:s}}}class Dj{constructor(t,n,l){ae(this,"context");ae(this,"notification");ae(this,"display");ae(this,"enabled");ae(this,"cacheId");ae(this,"cache");ae(this,"encoders");ae(this,"onChangeEmitter");ae(this,"onChange");this.context=t,this.notification=n,this.display=l,this.enabled=!1,this.cacheId=xe.EMPTY,this.cache=null,this.encoders=new Map([[P2.BAR,new Rc],[P2.BOX,new Oj],[P2.CANDLESTICK,new wj],[P2.DODGED,new Rc],[P2.HEATMAP,new Cj],[P2.HISTOGRAM,new Rc],[P2.LINE,new Vj],[P2.NORMALIZED,new Rc],[P2.STACKED,new Rc]]),this.onChangeEmitter=new Ms,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const n=t.type==="subplot"?t.trace:t;if(n.empty||n.braille.empty||!this.encoders.has(n.traceType))return;const l=n.braille;if(this.cacheId!==l.id||this.cache===null){const o=this.encoders.get(n.traceType);this.cache=o.encode(l,sS),this.cacheId=l.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[l.row][l.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:l}=this.cache.indexToCell[t];this.context.moveToIndex(n,l)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const l=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(l);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(H1.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var cS=(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))(cS||{});class TS{constructor(){}static async post(t,n,l){const o={...this.DEFAULT_HEADERS,...l};return this.request(t,"POST",o,n)}static async request(t,n,l,o){try{const a=await fetch(t,{method:n,headers:l,body:o});return a.ok?{success:!0,data:await a.json()}:{success:!1,error:{statusCode:a.status,message:`API Error: ${a.status} - ${a.statusText}`}}}catch(a){return console.error(`Error in API ${n} request to ${t}:`,a),{success:!1,error:{statusCode:cS.SERVER_ERROR,message:a instanceof Error?a.message:"Unknown error occurred"}}}}}ae(TS,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Rj=`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