maidr 3.26.0 → 3.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maidr.js +1 -1
- package/dist/maidr.js.map +1 -1
- package/package.json +1 -1
package/dist/maidr.js
CHANGED
|
@@ -638,7 +638,7 @@ Learn more: https://react.dev/warnings/version-mismatch`))})(),typeof Map=="func
|
|
|
638
638
|
You might need to use a local HTTP server (instead of file://): https://react.dev/link/react-devtools-faq`:""),"font-weight:bold")}Td.createRoot=function(r,T){if(!x(r))throw Error("Target container is not a DOM element.");Tc(r);var m=!1,S="",w=wg,D=E9,F=S9,X=null;return T!=null&&(T.hydrate?console.warn("hydrate through createRoot is deprecated. Use ReactDOMClient.hydrateRoot(container, <App />) instead."):typeof T=="object"&&T!==null&&T.$$typeof===M5&&console.error(`You passed a JSX element to createRoot. You probably meant to call root.render instead. Example usage:
|
|
639
639
|
|
|
640
640
|
let root = createRoot(domContainer);
|
|
641
|
-
root.render(<App />);`),T.unstable_strictMode===!0&&(m=!0),T.identifierPrefix!==void 0&&(S=T.identifierPrefix),T.onUncaughtError!==void 0&&(w=T.onUncaughtError),T.onCaughtError!==void 0&&(D=T.onCaughtError),T.onRecoverableError!==void 0&&(F=T.onRecoverableError),T.unstable_transitionCallbacks!==void 0&&(X=T.unstable_transitionCallbacks)),T=tp(r,1,!1,null,null,m,S,w,D,F,X,null),r[ji]=T.current,ns(r),new uc(T)},Td.hydrateRoot=function(r,T,m){if(!x(r))throw Error("Target container is not a DOM element.");Tc(r),T===void 0&&console.error("Must provide initial children as second argument to hydrateRoot. Example usage: hydrateRoot(domContainer, <App />)");var S=!1,w="",D=wg,F=E9,X=S9,oe=null,le=null;return m!=null&&(m.unstable_strictMode===!0&&(S=!0),m.identifierPrefix!==void 0&&(w=m.identifierPrefix),m.onUncaughtError!==void 0&&(D=m.onUncaughtError),m.onCaughtError!==void 0&&(F=m.onCaughtError),m.onRecoverableError!==void 0&&(X=m.onRecoverableError),m.unstable_transitionCallbacks!==void 0&&(oe=m.unstable_transitionCallbacks),m.formState!==void 0&&(le=m.formState)),T=tp(r,1,!0,T,m??null,S,w,D,F,X,oe,le),T.context=F1(null),m=T.current,S=$n(m),S=Ke(S),w=o6(S),w.callback=null,l6(m,w,S),m=S,T.current.lanes=m,i1(T,m),y4(T),r[ji]=T.current,ns(r),new cc(T)},Td.version="19.1.1",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})(),Td}var zP;function _7e(){if(zP)return Qg.exports;zP=1;var e={};function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function")){if(e.NODE_ENV!=="production")throw new Error("^_^");try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(n){console.error(n)}}}return e.NODE_ENV==="production"?(t(),Qg.exports=M7e()):Qg.exports=A7e(),Qg.exports}var O7e=_7e();class xH{constructor(){ie(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 o=this.items.lastIndexOf(t);return o!==-1?(this.items.splice(o,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}}class C7e{constructor(t){ie(this,"id");ie(this,"instructionContext");ie(this,"plotContext");ie(this,"scopeContext");ie(this,"figure");this.figure=t,this.id=t.id,this.plotContext=new xH,this.scopeContext=new xH;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(Yt.SUBPLOT);return}this.scopeContext.push(Yt.TRACE);const o=t.activeSubplot.state;if(o.empty||o.size!==1){this.instructionContext=t.activeSubplot,this.plotContext.push(t.activeSubplot),this.plotContext.push(t.activeSubplot.activeTrace);return}this.instructionContext=t.activeSubplot.activeTrace,this.plotContext.push(t.activeSubplot.activeTrace)}dispose(){this.plotContext.clear(),this.scopeContext.clear()}get active(){return this.plotContext.peek()}get state(){return this.active.state}toggleScope(t){this.scopeContext.clear(),this.scopeContext.push(t),W3.setScope(t)}get scope(){return this.scopeContext.peek()}isMovable(t){return this.active.isMovable(t)}moveOnce(t){this.active.moveOnce(t)}moveToExtreme(t){this.active.moveToExtreme(t)}moveToIndex(t,n){this.active.moveToIndex(t,n)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const n=this.active,o=n.activeTrace;if(!o)return;const a=o.getCurrentXValue();n.moveOnce(t);const l=n.activeTrace;if(this.plotContext.push(l),l.getId()===o.getId()){l.notifyOutOfBounds(),n.notifyOutOfBounds();return}if(l.moveToXValue(a),l.state.empty)l.notifyStateUpdate();else{const i=n.getRow()+1,s=n.getSize(),c={...l.state,isLayerSwitch:!0,index:i,size:s};l.notifyObserversWithState(c)}}else{const n=this.figure.subplots[0][0];this.active.notifyOutOfBounds(),n.notifyOutOfBounds()}}enterSubplot(){if(this.active.state.type==="figure"){const n=this.active;this.plotContext.push(n.activeSubplot);const o=n.activeSubplot.activeTrace;o.resetToInitialEntry(),this.plotContext.push(o),this.toggleScope(Yt.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(Yt.TRACE))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const o=t?"Click to activate.":ve.EMPTY;switch(n.type){case"figure":return`This is a maidr figure containing ${n.size} subplots. ${o} 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. ${o} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`;case"trace":{let a=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(a="single line");const l=a==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${a}${l}. ${o} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}var M2=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(M2||{}),U2=(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))(U2||{});function w7e(e){return e!==null&&typeof e=="object"&&"x"in e}function V7e(e){return typeof e=="string"||typeof e=="number"}function D7e(e){return e!==null&&typeof e=="object"&&"x"in e}class qP{computeIndexAndSegment(t,n,o,a){return o===M2.HORIZONTAL?{pointIndex:t,segmentType:a[n]}:{pointIndex:n,segmentType:a[t]}}computeVisualCoordinates(t,n,o){return o===M2.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,o){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const a=t[0][o];return this.extractXFromPoint(a)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][o]){const a=t[n][o];return this.extractXFromPoint(a)}return null}extractXValueFromValues(t,n,o){if(this.isValidPosition(t,n,o)){const a=t[n][o];return this.extractXFromValue(a)}return null}moveToXValueInPoints(t,n,o){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const c=this.findPointIndexByX(t[0],n);if(c!==-1)return o(0,c),!0;{const u=this.findNearestPointIndexByX(t[0],n);if(u!==-1){const Q=oi(t[0][u]);if(typeof n=="number"&&typeof Q=="number")return o(0,u),!0;if(typeof n=="string"&&typeof Q=="string")return o(0,u),!0}}}let a=-1,l=-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 o(c,Q),!0;const f=this.findNearestPointIndexByX(u,n);if(f!==-1){const h=oi(u[f]);let p=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof h=="number"?(p=Math.abs(h-n),p<i&&(i=p,a=c,l=f,s="numeric")):typeof n=="string"&&typeof h=="string"?a===-1&&(a=c,l=f,s="categorical"):a===-1&&(a=c,l=f,s="generic")}}}if(a!==-1&&l!==-1){const c=t[a];if(Array.isArray(c)&&oi(c[l]),s!==null)return o(a,l),!0}return!1}moveToXValueInValues(t,n,o){let a=-1,l=-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 o(c,u),!0;if(typeof n=="number"&&typeof f=="number"){const h=Math.abs(f-n);h<i&&(i=h,a=c,l=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?a===-1&&(a=c,l=u,s="categorical"):a===-1&&(a=c,l=u,s="generic")}return a!==-1&&l!==-1?(this.extractXFromValue(t[a][l]),o(a,l),!0):!1}extractXFromPoint(t){return D7e(t)?t.x:null}extractXFromValue(t){return w7e(t)?t.x:V7e(t)?t:null}findPointIndexByX(t,n){return t.findIndex(o=>o.x===n)}isValidPosition(t,n,o){return n>=0&&n<t.length&&o>=0&&o<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let o=-1,a=Number.POSITIVE_INFINITY;for(let l=0;l<t.length;l++){const i=oi(t[l]);if(typeof i=="number"){const s=Math.abs(i-n);s<a&&(a=s,o=l)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<a&&(a=c,o=l)}}}if(o!==-1)return oi(t[o]),o}else if(typeof n=="string"){for(let a=0;a<t.length;a++)if(oi(t[a])===n)return a;const o=Number(n);if(!Number.isNaN(o)){let a=-1,l=Number.POSITIVE_INFINITY;for(let i=0;i<t.length;i++){const s=oi(t[i]);if(typeof s=="number"){const c=Math.abs(s-o);c<l&&(l=c,a=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-o);u<l&&(l=u,a=i)}}}if(a!==-1)return oi(t[a]),a}for(let a=0;a<t.length;a++)if(typeof oi(t[a])=="string")return a}return t.length>0?(oi(t[0]),0):-1}dispose(){}}function R7e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function k7e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function N7e(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function B7e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function P7e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function I7e(e){return e&&typeof e=="object"&&"value"in e}function oi(e){return e?R7e(e)||k7e(e)||B7e(e)||P7e(e)||N7e(e)?e.x:I7e(e)?e.value:null:null}const j7e="unavailable",F7e="X",z7e="Y",q7e="unavailable";class LH{constructor(){ie(this,"observers");ie(this,"isInitialEntry");ie(this,"isOutOfBounds");ie(this,"row");ie(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}getSafeIndices(){var a;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,o=this.col>=0&&this.col<(((a=t[n])==null?void 0:a.length)||0)?this.col:0;return{row:n,col:o}}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:o}=this.getSafeIndices();this.col=(n=this.values[o])!=null&&n.length?this.values[o].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,o;if(Array.isArray(t)){const[a,l]=t,{row:i}=this.getSafeIndices();return a>=0&&a<this.values.length&&l>=0&&l<(((n=this.values[i])==null?void 0:n.length)||0)}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":{const{row:a}=this.getSafeIndices();return this.col<(((o=this.values[a])==null?void 0:o.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))}ensureInitialized(){this.isInitialEntry&&(this.handleInitialEntry(),this.notifyStateUpdate())}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){const t=this.state;for(const n of this.observers)n.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}}class l8 extends LH{constructor(n){var o,a,l;super();ie(this,"id");ie(this,"type");ie(this,"title");ie(this,"xAxis");ie(this,"yAxis");ie(this,"fill");ie(this,"navigationService");this.navigationService=new qP,this.id=n.id,this.type=n.type,this.title=n.title??j7e,this.xAxis=((o=n.axes)==null?void 0:o.x)??F7e,this.yAxis=((a=n.axes)==null?void 0:a.y)??z7e,this.fill=((l=n.axes)==null?void 0:l.fill)??q7e}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(o=>{(Array.isArray(o)?o:[o]).forEach(l=>l.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const o=this.values,a=this.row,l=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=o[a])==null?void 0:n.length)||0,index:l}}}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 o=this.values,a=this.row,l=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=o[a])==null?void 0:n.length)||0,index:l}}}return{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){var a;const{row:n}=this.getSafeIndices(),o=((a=this.values[n])==null?void 0:a.length)||0;return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:o,BACKWARD:o}}hasMultiPoints(){return!1}getExtremaTargets(){return[]}navigateToExtrema(n){if(this.supportsExtrema)throw new Error("Extrema navigation not implemented by this plot type")}finalizeExtremaNavigation(){this.isInitialEntry&&(this.isInitialEntry=!1),this.updateVisualPointPosition(),this.notifyStateUpdate()}updateVisualPointPosition(){}supportsExtremaNavigation(){return this.supportsExtrema}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 o=this.getPointsArray();if(this.isValidPointsArray(o))return this.navigationService.moveToXValueInPoints(o,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const o=this.values;if(this.isValidValuesArray(o))return this.navigationService.moveToXValueInValues(o,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}getId(){return this.id}}class un{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],o=t[0];for(let a=1;a<t.length;a++){const l=t[a];l<n&&(n=l),l>o&&(o=l)}return{min:n,max:o}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class dg{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let a=n.substring(1).split("");return a.length===3&&(a=[a[0],a[0],a[1],a[1],a[2],a[2]]),{r:Number.parseInt(a[0]+a[1],16),g:Number.parseInt(a[2]+a[3],16),b:Number.parseInt(a[4]+a[5],16)}}const o=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return o?{r:Number.parseInt(o[1],10),g:Number.parseInt(o[2],10),b:Number.parseInt(o[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const o=this.calculateLuminance(t),a=this.calculateLuminance(n);return(Math.max(o,a)+.05)/(Math.min(o,a)+.05)}static calculateLuminance(t){const[n,o,a]=[t.r,t.g,t.b].map(l=>{const i=l/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*o+.0722*a}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class $t{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),a=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,l=await new Promise((c,u)=>{const Q=new Image;Q.onload=()=>c(Q),Q.onerror=()=>u(new Error("Failed to load SVG image")),Q.src=a}),i=document.createElement("canvas");[i.width,i.height]=[l.naturalWidth,l.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(l,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(o=>{if(!n)return o;const a=o.cloneNode(!0);return a.setAttribute(ve.VISIBILITY,ve.HIDDEN),o.insertAdjacentElement(ve.AFTER_END,a),a})}static selectElement(t,n=!0){const o=document.querySelector(t);if(!n)return o;const a=o==null?void 0:o.cloneNode(!0);return a==null||a.setAttribute(ve.VISIBILITY,ve.HIDDEN),o==null||o.insertAdjacentElement(ve.AFTER_END,a),a}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(ve.FILL,ve.TRANSPARENT),n.setAttribute(ve.STROKE,ve.TRANSPARENT),n.setAttribute(ve.VISIBILITY,ve.HIDDEN),n}static createCircleElement(t,n,o){var u;const a=window.getComputedStyle(o),l=a.stroke||a.fill,i=a.strokeWidth||"2",s=Number.parseFloat(i)*2,c=document.createElementNS(this.SVG_NAMESPACE,ve.CIRCLE);return c.setAttribute(ve.CIRCLE_X,String(t)),c.setAttribute(ve.CIRCLE_Y,String(n)),c.setAttribute(ve.RADIUS,String(s)),c.setAttribute(ve.FILL,l),c.setAttribute(ve.STROKE,l),c.setAttribute(ve.STROKE_WIDTH,i),c.setAttribute(ve.VISIBILITY,ve.HIDDEN),(u=o.parentElement)==null||u.insertAdjacentElement(ve.AFTER_END,c),c}static createLineElement(t,n){const a=t.getBBox();let l,i,s,c;switch(n){case"top":[l,i,s,c]=[a.x,a.y,a.x+a.width,a.y];break;case"bottom":[l,i,s,c]=[a.x,a.y+a.height,a.x+a.width,a.y+a.height];break;case"left":[l,i,s,c]=[a.x,a.y,a.x,a.y+a.height];break;case"right":[l,i,s,c]=[a.x+a.width,a.y,a.x+a.width,a.y+a.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,ve.LINE);return Q.setAttribute(ve.X1,String(l)),Q.setAttribute(ve.Y1,String(i)),Q.setAttribute(ve.X2,String(s)),Q.setAttribute(ve.Y2,String(c)),Q.setAttribute(ve.STROKE,u.stroke),Q.setAttribute(ve.STROKE_WIDTH,u.strokeWidth||"2"),Q.setAttribute(ve.VISIBILITY,ve.HIDDEN),t.insertAdjacentElement(ve.AFTER_END,Q),Q}static createHighlightElement(t,n){const o=t.cloneNode(!0),a=t.tagName.toLowerCase(),l=a===ve.POLYLINE||a===ve.LINE,i=l?window.getComputedStyle(t).getPropertyValue(ve.STROKE):window.getComputedStyle(t).getPropertyValue(ve.FILL),s=this.getHighlightColor(i,n);if(o.setAttribute(ve.VISIBILITY,ve.VISIBLE),o.setAttribute(ve.STROKE,s),o.setAttribute(ve.FILL,s),o.style.fill=s,o.style.stroke=s,l){const c=window.getComputedStyle(o).getPropertyValue(ve.STROKE_WIDTH);o.setAttribute(ve.STROKE_WIDTH,`${c+2}`)}return t.insertAdjacentElement(ve.AFTER_END,o),o}static getHighlightColor(t,n){const o=dg.parse(t);if(!o||!(dg.getContrastRatio(o,ve.HIGHLIGHT_BASE_COLOR)<ve.HIGHLIGHT_CONTRAST_RATIO))return n;const i={...o};return o.r===o.g&&o.g===o.b?(i.r=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.r*ve.HIGHLIGHT_COLOR_RATIO)),i.g=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.g*ve.HIGHLIGHT_COLOR_RATIO)),i.b=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.b*ve.HIGHLIGHT_COLOR_RATIO))):o.r>=o.g&&o.r>=o.b?i.r=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.r*ve.HIGHLIGHT_COLOR_RATIO)):o.g>=o.r&&o.g>=o.b?i.g=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.g*ve.HIGHLIGHT_COLOR_RATIO)):i.b=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.b*ve.HIGHLIGHT_COLOR_RATIO)),dg.rgbToString(i)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",o=dg.parse(n);return o?(.2126*o.r+.7152*o.g+.0722*o.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,o){const a=t.querySelector("rect, path");let l="";if(a){l=window.getComputedStyle(a).getPropertyValue("fill"),(!l||l==="none"||l==="transparent"||l==="rgba(0, 0, 0, 0)")&&(o?l=window.getComputedStyle(o).getPropertyValue("fill"):l=n);const i=this.getHighlightColor(l,n);a.setAttribute("stroke",i),a.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}ie($t,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class bH extends l8{constructor(n,o){super(n);ie(this,"points");ie(this,"barValues");ie(this,"highlightValues");ie(this,"orientation");ie(this,"min");ie(this,"max");ie(this,"supportsExtrema",!0);this.points=o,this.orientation=n.orientation??M2.VERTICAL,this.barValues=o.map(a=>a.map(l=>this.orientation===M2.VERTICAL?Number(l.y):Number(l.x))),this.min=this.barValues.map(a=>un.safeMin(a)),this.max=this.barValues.map(a=>un.safeMax(a)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const n=this.orientation===M2.VERTICAL,o=n?this.barValues[this.row].length:this.barValues.length,a=n?this.col:this.row,l=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:un.safeMin(this.min),max:un.safeMax(this.max),size:o,index:a,value:l,...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===M2.VERTICAL,o=this.points[this.row][this.col],a=n?this.xAxis:this.yAxis,l=n?o.x:o.y,i=n?this.yAxis:this.xAxis,s=n?o.y:o.x;return{main:{label:a,value:l},cross:{label:i,value:s}}}mapToSvgElements(n){if(!n)return null;const o=[$t.selectAllElements(n)];if(o.length!==this.points.length)return null;for(let a=0;a<this.points.length;a++)if(o[a].length!==this.points[a].length)return null;return o}}class $7e extends bH{constructor(t){super(t,[t.data])}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const o=this.barValues[n];if(!o||o.length===0)return t;const a=this.min[n],l=this.max[n],i=o.indexOf(l),s=o.indexOf(a);return t.push({label:`Max Bar at ${this.getPointLabel(i)}`,value:l,pointIndex:i,segment:"bar",type:"max",navigationType:"point"}),t.push({label:`Min Bar at ${this.getPointLabel(s)}`,value:a,pointIndex:s,segment:"bar",type:"min",navigationType:"point"}),t}navigateToExtrema(t){this.col=t.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(t){if(this.points[this.row]&&this.points[this.row][t]){const n=this.points[this.row][t];return this.orientation===M2.VERTICAL?`${n.x}`:`${n.y}`}return`Point ${t}`}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}}const t5={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class U7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!1);ie(this,"points");ie(this,"boxValues");ie(this,"highlightValues");ie(this,"orientation");ie(this,"sections");ie(this,"min");ie(this,"max");this.points=n.data,this.orientation=n.orientation??M2.VERTICAL,this.sections=[t5.LOWER_OUTLIER,t5.MIN,t5.Q1,t5.Q2,t5.Q3,t5.MAX,t5.UPPER_OUTLIER];const o=[l=>l.lowerOutliers,l=>l.min,l=>l.q1,l=>l.q2,l=>l.q3,l=>l.max,l=>l.upperOutliers];this.orientation===M2.HORIZONTAL?this.boxValues=this.points.map(l=>o.map(i=>i(l))):this.boxValues=o.map(l=>this.points.map(i=>l(i)));const a=this.boxValues.map(l=>l.flatMap(i=>Array.isArray(i)?i:[i]));this.min=un.minFrom2D(a),this.max=un.maxFrom2D(a),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,o){const a=this.orientation===M2.HORIZONTAL;n=a?n:o,o=a?o:n,super.moveToIndex(n,o)}get values(){return this.boxValues}audio(){const n=this.boxValues[this.row][this.col],o=Array.isArray(n)?n.map(a=>a-this.min):n-this.min;return{min:this.min,max:this.max,value:n,size:this.max-this.min,index:o}}braille(){const n=this.orientation===M2.HORIZONTAL,o=n?this.row:this.col,a=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:o,col:a}}text(){const n=this.orientation===M2.HORIZONTAL,o=n?this.points[this.row]:this.points[this.col],a=n?this.yAxis:this.xAxis,l=n?this.sections[this.col]:this.sections[this.row],i=n?this.xAxis:this.yAxis,s=this.boxValues[this.row][this.col];return{main:{label:a,value:o.fill},cross:{label:i,value:s},section:l}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const o=this.orientation===M2.VERTICAL,a=new Array;if(o)for(let l=0;l<this.sections.length;l++)a.push(Array.from({length:n.length}));return n.forEach((l,i)=>{const s=l.lowerOutliers.flatMap(b=>$t.selectAllElements(b)),c=l.upperOutliers.flatMap(b=>$t.selectAllElements(b)),u=$t.selectElement(l.min)??$t.createEmptyElement(),Q=$t.selectElement(l.max)??$t.createEmptyElement(),f=$t.selectElement(l.iq)??$t.createEmptyElement(),h=$t.selectElement(l.q2)??$t.createEmptyElement(),[p,g]=o?[$t.createLineElement(f,"top"),$t.createLineElement(f,"bottom")]:[$t.createLineElement(f,"left"),$t.createLineElement(f,"right")],v=[s,u,p,h,g,Q,c];o?v.forEach((b,x)=>{a[x][i]=b}):a.push(v)}),a}}const G7e="trend",$P=100;class Z7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!0);ie(this,"candles");ie(this,"candleValues");ie(this,"orientation");ie(this,"sections",["volatility","open","high","low","close"]);ie(this,"currentSegmentType","open");ie(this,"currentPointIndex",0);ie(this,"sortedSegmentsByPoint");ie(this,"segmentPositionMaps");ie(this,"min");ie(this,"max");ie(this,"highlightValues");ie(this,"navigationService");this.navigationService=new qP;const o=n.data;this.candles=o.map(a=>({...a,volatility:Math.round((a.high-a.low)*$P)/$P,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=n.orientation??M2.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(l=>l[a])),this.min=un.minFrom2D(this.candleValues),this.max=un.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===M2.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors)}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(l=>[l,n[l]]).sort((l,i)=>l[1]-i[1]).map(l=>l[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const o=new Map;return n.forEach((a,l)=>{o.set(a,l)}),o})}getSegmentPositionInSortedOrder(n,o){return this.segmentPositionMaps[n].get(o)??0}getSegmentTypeAtSortedPosition(n,o){return this.sortedSegmentsByPoint[n][o]??"open"}updateVisualSegmentPosition(){const o=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===M2.HORIZONTAL?this.col=o:this.row=o}updateVisualPointPosition(){this.orientation===M2.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex,this.updateVisualSegmentPosition()}handleInitialEntry(){this.isInitialEntry=!1,this.currentPointIndex=Math.max(0,Math.min(this.currentPointIndex,this.candles.length-1)),this.currentSegmentType="close",this.updateVisualSegmentPosition()}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":case"DOWNWARD":{const o=this.sortedSegmentsByPoint[this.currentPointIndex],a=o.indexOf(this.currentSegmentType??"open");if(a===-1){this.notifyOutOfBounds();return}const l=n==="UPWARD"?a+1:a-1;if(l>=0&&l<o.length)this.currentSegmentType=o[l],this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const o=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(o>=0&&o<this.candles.length)this.currentPointIndex=o,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const o=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=o[o.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const o=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=o[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,o){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:a,segmentType:l}=this.navigationService.computeIndexAndSegment(n,o,this.orientation,this.sections);this.currentPointIndex=a,this.currentSegmentType=l,this.row=n,this.col=o,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 o=this.sortedSegmentsByPoint[this.currentPointIndex],a=o.indexOf(this.currentSegmentType??"open"),l=n==="UPWARD"?a+1:a-1;return l>=0&&l<o.length}case"FORWARD":case"BACKWARD":{const o=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return o>=0&&o<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){let n;return this.currentSegmentType==="volatility"?n=this.candles[this.currentPointIndex].volatility:this.currentSegmentType?n=this.candles[this.currentPointIndex][this.currentSegmentType]:n=this.candles[this.currentPointIndex].open,{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:n,trend:this.candles[this.currentPointIndex].trend}}braille(){const n=this.candles.map(i=>i.trend),o=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=o;const a=this.candleValues.map(i=>Math.min(...i)),l=this.candleValues.map(i=>Math.max(...i));return{empty:!1,id:this.id,values:this.candleValues,min:a,max:l,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const o=Array.isArray(n)?n:[n],a=[];for(const l of o)a.push(...$t.selectAllElements(l));return a}getElementAt(n,o){return o<n.length?n[o]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const g=Array.isArray(n)?n[0]||"":n,v=$t.selectAllElements(g),b=[];for(let x=0;x<this.sections.length;x++){b[x]=[];for(let E=0;E<this.candles.length;E++){const _=E<v.length?E:0;b[x][E]=v[_]}}return b}const o=n,a=this.candles.length,l=this.collectElements(o.body);let i=this.collectElements(o.wickHigh),s=this.collectElements(o.wickLow);if(i.length===0||s.length===0){const g=this.collectElements(o.wick);g.length>0&&(i.length===0&&(i=g),s.length===0&&(s=g))}const c=this.collectElements(o.open),u=this.collectElements(o.close),Q=Array.from({length:a},()=>$t.createEmptyElement()),f=Array.from({length:a},()=>$t.createEmptyElement()),h=Array.from({length:a},()=>$t.createEmptyElement());for(let g=0;g<a;g++){let v=this.getElementAt(c,g);if(!v){const x=this.getElementAt(l,g);if(x){const{open:E,close:_}=this.candles[g],O=_>E?"bottom":_<E?"top":"bottom";v=$t.createLineElement(x,O)}else v=$t.createEmptyElement()}Q[g]=v;let b=this.getElementAt(u,g);if(!b){const x=this.getElementAt(l,g);if(x){const{open:E,close:_}=this.candles[g],O=_>E?"top":_<E?"bottom":"top";b=$t.createLineElement(x,O)}else b=$t.createEmptyElement()}f[g]=b,h[g]=$t.createEmptyElement()}const p=Array.from({length:this.sections.length},()=>Array.from({length:a},()=>$t.createEmptyElement()));for(let g=0;g<a;g++){const v=this.sortedSegmentsByPoint[g];for(let b=0;b<v.length;b++){const x=v[b];let E;switch(x){case"volatility":{const _=[],O=this.getElementAt(l,g),M=this.getElementAt(i,g)??O,A=this.getElementAt(s,g)??O;M&&_.push(M),O&&_.push(O),A&&_.push(A);const V=Array.from(new Set(_));E=V.length>0?V:[$t.createEmptyElement()]}break;case"open":E=Q[g];break;case"close":E=f[g];break;case"high":E=this.getElementAt(i,g)??this.getElementAt(l,g)??$t.createEmptyElement();break;case"low":E=this.getElementAt(s,g)??this.getElementAt(l,g)??$t.createEmptyElement();break;default:E=$t.createEmptyElement()}p[b][g]=E}}return p}text(){const n=this.candles[this.currentPointIndex];let o;return this.currentSegmentType==="volatility"?o=n.volatility:this.currentSegmentType?o=n[this.currentSegmentType]:o=n.open,{main:{label:this.orientation===M2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===M2.HORIZONTAL?this.xAxis:this.yAxis,value:o},section:this.currentSegmentType??"open",fill:{label:G7e,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 o=this.candles.findIndex(a=>a.value===n);return o!==-1?(this.currentPointIndex=o,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getAvailableXValues(){return this.candles.map(n=>n.value)}getExtremaTargets(){const n=[],o=this.currentSegmentType??"open";if(o==="volatility"){const a=this.candles.map((u,Q)=>({value:u.volatility,index:Q})),l=Math.max(...a.map(u=>u.value)),i=a.filter(u=>u.value===l).map(u=>u.index),s=Math.min(...a.map(u=>u.value)),c=a.filter(u=>u.value===s).map(u=>u.index);i.forEach((u,Q)=>{const f=this.candles[u];n.push({label:`Max Volatility at ${f.value}`,value:f.volatility,pointIndex:u,segment:"volatility",type:"max",navigationType:"point"})}),c.forEach((u,Q)=>{const f=this.candles[u];n.push({label:`Min Volatility at ${f.value}`,value:f.volatility,pointIndex:u,segment:"volatility",type:"min",navigationType:"point"})})}else{const a=this.candles.map((u,Q)=>({value:u[o],index:Q,xValue:u.value})),l=Math.max(...a.map(u=>u.value)),i=a.filter(u=>u.value===l).map(u=>u.index),s=Math.min(...a.map(u=>u.value)),c=a.filter(u=>u.value===s).map(u=>u.index);i.forEach((u,Q)=>{const f=this.candles[u],h=o.charAt(0).toUpperCase()+o.slice(1);n.push({label:`Max ${h} at ${f.value}`,value:f[o],pointIndex:u,segment:o,type:"max",navigationType:"point"})}),c.forEach((u,Q)=>{const f=this.candles[u],h=o.charAt(0).toUpperCase()+o.slice(1);n.push({label:`Min ${h} at ${f.value}`,value:f[o],pointIndex:u,segment:o,type:"min",navigationType:"point"})})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.finalizeExtremaNavigation()}}class X7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!1);ie(this,"heatmapValues");ie(this,"highlightValues");ie(this,"x");ie(this,"y");ie(this,"min");ie(this,"max");const o=n.data;this.x=o.x,this.y=[...o.y].reverse(),this.heatmapValues=[...o.points].reverse();const{min:a,max:l}=un.minMaxFrom2D(this.heatmapValues);this.min=a,this.max=l,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 o=this.heatmapValues.length,a=this.heatmapValues[0].length,l=$t.selectAllElements(n);if(l.length===0||l.length!==o*a)return null;const i=new Array;if(l[0]instanceof SVGPathElement)for(let s=0;s<o;s++){const c=o-1-s,u=new Array;for(let Q=0;Q<a;Q++){const f=c*a+Q;u.push(l[f])}i.push(u)}else if(l[0]instanceof SVGRectElement)for(let s=0;s<o;s++){const c=new Array;for(let u=0;u<a;u++){const Q=u*o+s;c.push(l[Q])}i.push(c)}return i}}class W7e extends bH{constructor(t){super(t,[t.data])}text(){const t=this.orientation===M2.VERTICAL,n=this.points[this.row][this.col],o=t?n.xMin:n.yMin,a=t?n.xMax:n.yMax;return{...super.text(),range:{min:o,max:a}}}}const UP="Group",HH=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class GP extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!0);ie(this,"points");ie(this,"lineValues");ie(this,"highlightValues");ie(this,"min");ie(this,"max");ie(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(o=>o.map(a=>Number(a.y))),this.min=this.lineValues.map(o=>un.safeMin(o)),this.max=this.lineValues.map(o=>un.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.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 l;const n=this.points[this.row][this.col],o=this.findIntersections();let a={};if(o.length>1){let i=o.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=((l=this.points[this.previousRow][0])==null?void 0:l.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}a={fill:{label:UP,value:`intersection at (${i.join(", ")})`}}}else a=n.fill?{fill:{label:UP,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...a}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const a=this.findLineByXAndYDirection(n),l=this.points[this.row][this.col].x;if(a!==null&&a!==this.row){const i=this.findColumnByXValue(a,l);if(i!==-1){this.row=a,this.col=i;const s=this.findIntersections();if(s.length>1){const u={...super.state,intersections:s};for(const Q of this.observers)Q.update(u)}else this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}else{this.notifyOutOfBounds();return}}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const o=this.findIntersections();if(o.length>1){const l={...super.state,intersections:o};for(const i of this.observers)i.update(l)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,o=this.points[this.row][this.col].y,a=[];for(let l=0;l<this.points.length;l++){const i=this.points[l].findIndex(s=>s.x===n&&s.y===o);i!==-1&&a.push({min:this.min[l],max:this.max[l],size:this.points[l].length,index:i,value:o,groupIndex:l})}return a}isMovable(n){if(Array.isArray(n)){const[o,a]=n;return o>=0&&o<this.values.length&&a>=0&&a<this.values[o].length}switch(n){case"UPWARD":case"DOWNWARD":{const o=this.findLineByXAndYDirection(n);if(o===null)return!1;const a=this.points[this.row][this.col].x;return this.findColumnByXValue(o,a)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const o=this.points[this.row][this.col].x;let a=null,l=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===o);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<l&&(l=Q,a=i)}return a}findColumnByXValue(n,o){return this.points[n].findIndex(a=>a.x===o)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const o=[];let a=!0;for(let l=0;l<n.length;l++){const i=$t.selectElement(n[l],!1);if(!i){o.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(ve.D)||ve.EMPTY;HH.lastIndex=0;let f=HH.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=HH.exec(Q)}else if(i instanceof SVGPolylineElement){const f=(i.getAttribute(ve.POINTS)||ve.EMPTY).split(/\s+/).filter(Boolean);for(const h of f){const[p,g]=h.split(ve.COMMA);s.push({x:Number.parseFloat(p),y:Number.parseFloat(g)})}}if(s.length!==this.lineValues[l].length)if(s.length<this.lineValues[l].length)for(;s.length<this.lineValues[l].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[l].length&&(s.length=this.lineValues[l].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($t.createCircleElement(Q.x,Q.y,i))}if(u){o.push([]);continue}c.length>0&&(a=!1),o.push(c)}return a?null:o}get state(){const n=super.state;if(n.empty)return n;const o=this.points.length>1,a={...n,plotType:o?"multiline":"single line",...o&&{groupCount:this.points.length}},l=this.findIntersections();return l.length>1?{...a,intersections:l}:a}getExtremaTargets(){const n=[],o=this.row;if(o<0||o>=this.lineValues.length)return n;const a=this.lineValues[o];if(!a||a.length===0)return n;const l=this.min[o],i=this.max[o],s=[],c=[];for(let u=0;u<a.length;u++){const Q=a[u];Q===i&&s.push(u),Q===l&&c.push(u)}for(const u of s)n.push({label:`Max point at ${this.getPointLabel(u)}`,value:i,pointIndex:u,segment:"line",type:"max",navigationType:"point"});for(const u of c)n.push({label:`Min point at ${this.getPointLabel(u)}`,value:l,pointIndex:u,segment:"line",type:"min",navigationType:"point"});return n}navigateToExtrema(n){this.col=n.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(n){return this.points[this.row]&&this.points[this.row][n]?`${this.points[this.row][n].x}`:`Point ${n}`}updateVisualPointPosition(){const{row:n,col:o}=this.getSafeIndices();this.row=n,this.col=o}getAvailableXValues(){return this.points[this.row].map(n=>n.x)}moveToXValue(n){const o=this.points[this.row].findIndex(a=>a.x===n);return o!==-1?(this.col=o,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0):!1}}class Y7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!1);ie(this,"mode");ie(this,"xPoints");ie(this,"yPoints");ie(this,"xValues");ie(this,"yValues");ie(this,"highlightXValues");ie(this,"highlightYValues");ie(this,"minX");ie(this,"maxX");ie(this,"minY");ie(this,"maxY");this.mode="column";const o=n.data,a=[...o].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let l=null;for(const c of a)(!l||l.x!==c.x)&&(l={x:c.x,y:[]},this.xPoints.push(l)),l.y.push(c.y);const i=[...o].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=un.safeMin(this.xValues),this.maxX=un.safeMax(this.xValues),this.minY=un.safeMin(this.yValues),this.maxY=un.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(o=>o.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(o=>o.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],o=n.y[Math.floor(n.y.length/2)],a=this.yValues.indexOf(o);a===-1||a>=this.yPoints.length?this.row=0:this.row=a,this.mode="row"}else{const n=this.yPoints[this.row],o=n.x[Math.floor(n.x.length/2)],a=this.xValues.indexOf(o);a===-1||a>=this.xPoints.length?this.col=0:this.col=a,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const o=$t.selectAllElements(n);if(o.length===0)return[null,null];const a=new Map,l=new Map;o.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(a.has(u)||a.set(u,[]),a.get(u).push(c)),Number.isNaN(Q)||(l.has(Q)||l.set(Q,[]),l.get(Q).push(c))});const i=Array.from(a.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(l.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const ZP="Sum",K7e="Level",J7e="undefined";class ele extends bH{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let l=0;l<this.barValues[0].length;l++){const i=this.barValues.reduce((c,u)=>c+u[l],0);t.push(i);const s=this.orientation===M2.VERTICAL?{x:this.points[0][l].x,y:i,fill:ZP}:{x:i,y:this.points[0][l].y,fill:ZP};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:o,max:a}=un.minMax(t);this.min.push(o),this.max.push(a)}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const o=this.min[n],a=this.max[n],l=this.barValues[n];if(!l||l.length===0)return t;const i=l.indexOf(a),s=l.indexOf(o),c=this.getGroupLabel(n),u=this.getCategoryLabel(i),Q=this.getCategoryLabel(s);return t.push({label:`Max ${c} at ${u}`,value:a,pointIndex:i,segment:c,type:"max",groupIndex:n,categoryIndex:i,navigationType:"group"}),t.push({label:`Min ${c} at ${Q}`,value:o,pointIndex:s,segment:c,type:"min",groupIndex:n,categoryIndex:s,navigationType:"group"}),t}navigateToExtrema(t){t.groupIndex!==void 0&&t.categoryIndex!==void 0?(this.row=t.groupIndex,this.col=t.categoryIndex):this.col=t.pointIndex,this.finalizeExtremaNavigation()}getGroupLabel(t){if(this.points[t]&&this.points[t].length>0){const n=this.points[t][0];if(t===this.barValues.length-1)return"Total";if(n.fill)return`${this.getFillAxisLabel()}: '${n.fill}'`}return`Group ${t}`}getCategoryLabel(t){if(this.points[0]&&this.points[0][t]){const n=this.points[0][t];return this.orientation===M2.VERTICAL?`${n.x}`:`${n.y}`}return`Category ${t}`}getFillAxisLabel(){return"Category"}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}text(){return{...super.text(),fill:{label:K7e,value:this.points[this.row][this.col].fill??J7e}}}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=$t.selectAllElements(t);if(n.length===0)return new Array;const o=new Array;if(n[0]instanceof SVGPathElement)for(let a=0,l=0;a<this.barValues.length;a++){const i=new Array;for(let s=0;s<this.barValues[a].length;s++){if(l>=n.length)return new Array;this.barValues[a][s]===0?i.push($t.createEmptyElement()):i.push(n[l++])}o.push(i)}else if(n[0]instanceof SVGRectElement){for(let a=0;a<this.barValues.length;a++)o.push(new Array);for(let a=0,l=0;a<this.barValues[0].length;a++)for(let i=this.barValues.length-1;i>=0;i--){if(l>=n.length)return new Array;this.barValues[i][a]===0?o[i].push($t.createEmptyElement()):o[i].push(n[l++])}}return o}}class XP extends GP{constructor(t){super(t)}audio(){const t=this.lineValues[this.row],n=this.col,o=s=>t[Math.max(0,Math.min(s,t.length-1))],a=n>0?o(n-1):o(n),l=o(n),i=n<t.length-1?o(n+1):o(n);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:n,value:[a,l,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class tle extends XP{constructor(t){super(t)}mapToSvgElements(t){var a;if(!t||t.length!==this.lineValues.length)return null;const n=[];let o=!0;for(let l=0;l<t.length;l++){const i=$t.selectElement(t[l],!1);if(!i){n.push([]);continue}const s=(a=this.points)==null?void 0:a[l],c=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&c.push($t.createCircleElement(u.svg_x,u.svg_y,i));c.length>0&&(o=!1),n.push(c)}return o?null:n}}function nle(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function rle(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&nle(e.data[0][0])?new tle(e):new XP(e)}class ile{static create(t){switch(t.type){case U2.BAR:return new $7e(t);case U2.BOX:return new U7e(t);case U2.CANDLESTICK:return new Z7e(t);case U2.HEATMAP:return new X7e(t);case U2.HISTOGRAM:return new W7e(t);case U2.LINE:return new GP(t);case U2.SCATTER:return new Y7e(t);case U2.SMOOTH:return rle(t);case U2.DODGED:case U2.NORMALIZED:case U2.STACKED:return new ele(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const ale="MAIDR Plot",ole="unavailable",lle="unavailable";class sle extends LH{constructor(n){super();ie(this,"id");ie(this,"title");ie(this,"subtitle");ie(this,"caption");ie(this,"subplots");ie(this,"size");this.id=n.id,this.title=n.title??ale,this.subtitle=n.subtitle??ole,this.caption=n.caption??lle;const o=n.subplots;this.subplots=o.map(a=>a.map(l=>new ule(l))),this.size=this.subplots.reduce((a,l)=>a+l.length,0)}dispose(){this.subplots.forEach(n=>n.forEach(o=>o.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((a,l)=>a+l.length,0),o=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:o.getStateWithFigurePosition(this.row,this.col),traceTypes:o.traceTypes,highlight:this.highlight()}}highlight(){var o;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}};try{const a=((o=this.subplots[0])==null?void 0:o.length)||1,l=this.row*a+this.col+1,i=`g[id="axes_${l}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&l-1<c.length)return{empty:!1,elements:c[l-1]}}catch{return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}isMovable(n){switch(n){case"UPWARD":return this.row<this.subplots.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.subplots[this.row].length-1;case"BACKWARD":return this.col>0;default:return!1}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}}class ule extends LH{constructor(n){super();ie(this,"traces");ie(this,"traceTypes");ie(this,"size");this.isInitialEntry=!1;const o=n.layers;this.size=o.length,this.traces=o.map(a=>[ile.create(a)]),this.traceTypes=this.traces.flat().map(a=>{const l=a.state;return l.empty?ve.EMPTY:l.traceType})}getRow(){return this.row}getSize(){return this.size}dispose(){this.traces.forEach(n=>n.forEach(o=>o.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}highlight(){return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}get state(){return this.isOutOfBounds?{empty:!0,type:"subplot"}:{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight()}}getStateWithFigurePosition(n,o){return this.state}}const cn={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},ju=class ju{constructor(){ie(this,"basePalette");ie(this,"extendedPalette");this.basePalette=[{index:cn.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:cn.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:cn.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:cn.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:cn.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:cn.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:cn.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:cn.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:cn.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:cn.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:cn.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 o=this.generateExtendedEntry(t);return this.extendedPalette.set(t,o),o}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return cn.SINE_BASIC;case"Bear":return cn.SAWTOOTH_SOFT;case"Neutral":return cn.TRIANGLE_BASIC;default:return cn.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,o)=>{this.extendedPalette.set(this.basePalette.length+o,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,o=this.basePalette[n],a=Math.floor((t-this.basePalette.length)/this.basePalette.length),l=this.generateHarmonics(a),i=this.generateTimbreModulation(a,o.timbreModulation);return{index:t,waveType:o.waveType,harmonicMix:{fundamental:1,harmonics:l},timbreModulation:i}}generateHarmonics(t){const n=[],o=ju.MIN_HARMONICS+t%ju.HARMONIC_VARIATION;for(let a=0;a<o;a++){const l=1+(a+1)*(.5+t*.3%1),i=.4/(a+1)*(1-t*.1%.3);n.push({frequency:l,amplitude:i})}return n}generateTimbreModulation(t,n){const o=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*o)),decay:Math.max(.05,Math.min(.3,n.decay*o)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*o))}}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.`)})}};ie(ju,"MIN_HARMONICS",2),ie(ju,"HARMONIC_VARIATION",3);let EH=ju;const cle=100,Tle=440,Qle=880,SH=.3,MH=cn.SINE_BASIC;class fle{constructor(t,n,o){ie(this,"notification");ie(this,"audioPalette");ie(this,"settings");ie(this,"isCombinedAudio");ie(this,"mode");ie(this,"activeAudioIds");ie(this,"audioContext");ie(this,"compressor");ie(this,"currentVolume");ie(this,"currentMinFrequency");ie(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new EH,this.settings=o,this.isCombinedAudio=!1,this.mode="on",this.updateMode(n),this.activeAudioIds=new Map,this.audioContext=new AudioContext,this.compressor=this.initCompressor();const a=this.settings.loadSettings();this.currentVolume=a.general.volume/100,this.currentMinFrequency=a.general.minFrequency,this.currentMaxFrequency=a.general.maxFrequency,this.settings.addObserver(this)}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close()),this.settings.removeObserver(this)}update(t){"general"in t?this.onSettingsChange(t):this.onStateChange(t)}onSettingsChange(t){this.currentVolume=t.general.volume/100,this.currentMinFrequency=t.general.minFrequency,this.currentMaxFrequency=t.general.maxFrequency}onStateChange(t){if(this.mode==="off")return;if(this.updateMode(t),t.type==="figure"){if(t.empty){this.playEmptyTone(1,0);return}return}let n;if(t.type==="subplot"){if(t.empty)return;n=t.trace}else n=t;this.handleTraceState(n)}handleTraceState(t){if(this.mode==="off"||t.type!=="trace")return;if(t.empty){this.stopAll(),this.playEmptyTone(t.audio.size,t.audio.index);return}if(t.traceType==="line"&&!t.empty&&Array.isArray(t.intersections)&&t.intersections.length>1){this.stopAll(),this.playSimultaneousTones(t.intersections);return}const n=t.audio;let o=n.groupIndex;n.trend&&o===void 0&&(o=this.audioPalette.getCandlestickGroupIndex(n.trend));const l=o!==void 0?this.audioPalette.getPaletteEntry(o):void 0;if(n.isContinuous)this.playSmooth(n.value,n.min,n.max,n.size,Array.isArray(n.index)?n.index[0]:n.index,l);else if(Array.isArray(n.value)){const i=n.value;if(i.length===0){this.playZeroTone();return}let s=0;const c=this.mode==="on"?50:0,u=new Array,Q=()=>{if(s<i.length){const f=Array.isArray(n.index)?n.index[s]:n.index;this.playTone(n.min,n.max,i[s++],n.size,f,l),u.push(setTimeout(Q,c))}else this.stop(u)};Q()}else{const i=n.value;if(i===0)this.playZeroTone();else{const s=Array.isArray(n.index)?n.index[0]:n.index;this.playTone(n.min,n.max,i,n.size,s,l)}}}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,o,a,l,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(o,s,c),Q={min:0,max:a},f={min:-1,max:1},h=this.clamp(this.interpolate(l,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const o=[],a=this.audioContext.createOscillator();if(a.type=t.waveType,a.frequency.value=n,o.push(a),t.harmonicMix)for(const l of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=l.frequency*n,o.push(i)}return o}createGainNodes(t,n,o,a){const l=[],i=this.audioContext.currentTime,s=this.getVolume();for(let c=0;c<t.length;c++){const u=this.audioContext.createGain();let Q=s;if(c===0)n.harmonicMix&&(Q*=n.harmonicMix.fundamental);else{const h=n.harmonicMix.harmonics[c-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,n,Q,i,a);f!==null&&u.gain.setValueCurveAtTime(f,i,a),l.push(u)}return l}playOscillator(t,n=0,o){const a=SH,l=this.getVolume();o||(o=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(o,t),s=this.createGainNodes(i,o,l,a),c=this.audioContext.createStereoPanner();c.pan.value=n;const u=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let h=0;h<i.length;h++)i[h].connect(s[h]),s[h].connect(c);c.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),c.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(c),i[p].stop(),i[p].disconnect(s[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),a*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,o,a,l){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=l*i,f=l*s,h=l*u,p=l-Q-f-h;return t.gain.setValueAtTime(1e-4*o,a),t.gain.linearRampToValueAtTime(o,a+Q),t.gain.linearRampToValueAtTime(c*o,a+Q+f),p>0&&t.gain.setValueAtTime(c*o,a+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*o,a+l),null}else return[.5*o,o,.5*o,.5*o,.5*o,.1*o,1e-4*o]}playSmooth(t,n,o,a,l,i){const s=this.audioContext,c=s.currentTime,u=SH,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(O=>this.interpolate(O,{min:n,max:o},Q));p.length<2&&p.push(p[0]);const g=this.clamp(this.interpolate(l,{min:0,max:a-1},{min:-1,max:1}),-1,1),v=s.createOscillator();v.type=h,v.frequency.setValueCurveAtTime(p,c,u);const b=s.createGain(),x=this.createAdsrEnvelope(b,i,f,c,u);x!==null&&b.gain.setValueCurveAtTime(x,c,u);const E=s.createStereoPanner();E.pan.value=g,v.connect(b),b.connect(E),E.connect(this.compressor),v.start(c),v.stop(c+u);const _=setTimeout(()=>{v.disconnect(),b.disconnect(),E.disconnect(),this.activeAudioIds.delete(_)},u*1e3*2);this.activeAudioIds.set(_,[v])}playEmptyTone(t,n){const o=this.audioContext,a=o.currentTime,l=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=o.createGain();u.gain.setValueAtTime(.3*i,a),u.gain.exponentialRampToValueAtTime(.01*i,a+l),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 x=o.createOscillator(),E=o.createGain(),_=this.audioContext.createStereoPanner(),O=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});x.frequency.value=s[b],x.type="sine",E.gain.setValueAtTime(c[b]*i,a),E.gain.exponentialRampToValueAtTime(.001*i,a+l),_.pan.value=h,x.connect(E),E.connect(_),_.connect(O),O.connect(u),x.start(a),x.stop(a+l),p.push(x)}const g=b=>{u.disconnect(),p.forEach(x=>{x.disconnect()}),this.activeAudioIds.delete(b)},v=setTimeout(()=>g(v),l*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(cle,0,{index:MH,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(Tle,0,{index:MH,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(Qle,0,{index:MH,waveType:"sine"})}interpolate(t,n,o){return n.min===0&&n.max===0?0:(t-n.min)/(n.max-n.min)*(o.max-o.min)+o.min}clamp(t,n,o){return Math.max(n,Math.min(t,o))}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(o=>{const a=this.activeAudioIds.get(o);if(!a){clearInterval(o);return}a.forEach(l=>{l==null||l.disconnect(),l==null||l.stop()}),clearTimeout(o),this.activeAudioIds.delete(o)})}stopAll(){this.activeAudioIds.entries().forEach(([t,n])=>{clearTimeout(t),n.forEach(o=>{o.disconnect(),o.stop()})}),this.activeAudioIds.clear()}playSimultaneousTones(t){const n=this.getVolume(),o=SH,a=this.audioContext,l=a.currentTime,i=this.getFrequencyRange(),s=Array.isArray(t[0].value)?t[0].value[1]??t[0].value[0]:t[0].value,c=t[0].min,u=t[0].max,Q=this.interpolate(s,{min:c,max:u},i);t.forEach((f,h)=>{const p=Q,v=this.audioPalette.getPaletteEntry(h).waveType,b=a.createOscillator();b.type=v,b.frequency.value=p;const x=a.createGain();x.gain.setValueAtTime(n,l),x.gain.exponentialRampToValueAtTime(.01*n,l+o),b.connect(x),x.connect(this.compressor),b.start(l),b.stop(l+o);const E=setTimeout(()=>{b.disconnect(),x.disconnect()},o*1e3*2);this.activeAudioIds.set(E,[b])})}}const dle=250,hle=50,ple=500,mle=20;class yle{constructor(t,n,o){ie(this,"context");ie(this,"notification");ie(this,"settings");ie(this,"autoplayId");ie(this,"currentDirection");ie(this,"userSpeed");ie(this,"defaultSpeed");ie(this,"minSpeed");ie(this,"maxSpeed");ie(this,"autoplayRate");ie(this,"interval");ie(this,"currentDuration");ie(this,"onChangeEmitter");ie(this,"onChange");this.notification=n,this.context=t,this.settings=o,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=dle,this.minSpeed=hle,this.maxSpeed=ple,this.autoplayRate=this.defaultSpeed,this.interval=mle,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new qs,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 o=Math.ceil(this.currentDuration/n.autoplay[t]);return this.defaultSpeed=o,this.minSpeed=Math.min(this.minSpeed,o),o}return this.defaultSpeed}}const WP=32;class Qd{encode(t){const n=new Array,o=new Array,a=new Array;for(let l=0;l<t.values.length;l++){o.push(new Array);const i=(t.max[l]-t.min[l])/4,s=t.min[l]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[l].length;Q++)t.values[l][Q]===0?n.push(" "):t.values[l][Q]<=s||t.values[l][Q]<=c?n.push("⠤"):t.values[l][Q]<=u?n.push("⠒"):n.push("⠉"),o[l].push(a.length),a.push({row:l,col:Q});n.push(ve.NEW_LINE),o[l].push(a.length),a.push({row:l,col:t.values[l].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}}class gle{constructor(){ie(this,"GLOBAL_MIN","globalMin");ie(this,"GLOBAL_MAX","globalMax");ie(this,"BLANK","blank");ie(this,"LOWER_OUTLIER","lowerOutlier");ie(this,"UPPER_OUTLIER","upperOutlier");ie(this,"MIN","min");ie(this,"MAX","max");ie(this,"Q1","q1");ie(this,"Q2","q2");ie(this,"Q3","q3")}encode(t,n=WP){const o=new Array,a=new Array,l=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],c=[{type:this.GLOBAL_MIN,value:t.min},...s.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:s.min},{type:this.Q1,value:s.q1},{type:this.Q2,value:s.q2},{type:this.Q3,value:s.q3},{type:this.MAX,value:s.max},...s.upperOutliers.map(V=>({type:this.UPPER_OUTLIER,value:V})),{type:this.GLOBAL_MAX,value:t.max}],u=new Array;let Q=!0;for(let V=0;V<c.length-1;V++){const R=c[V],N=c[V+1],B=Math.abs(Q?N.value-R.value:R.value-c[V-1].value);R.type===this.LOWER_OUTLIER||R.type===this.UPPER_OUTLIER?(u.push({type:R.type,length:0,numChars:1}),u.push({type:this.BLANK,length:B,numChars:0})):R.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):R.type===this.GLOBAL_MIN||R.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:B,numChars:0}):u.push({type:R.type,length:B,numChars:1})}let f=u.reduce((V,R)=>V+(R.numChars>0?R.numChars:0),0),[h,p,g,v]=[-1,-1,-1,-1];for(let V=0;V<u.length;V++)u[V].type===this.MIN&&u[V].length>0&&(h=V),u[V].type===this.MAX&&u[V].length>0&&(p=V),u[V].type===this.Q1&&(g=V),u[V].type===this.Q3&&(v=V);h!==-1&&p!==-1&&u[h].length!==u[p].length&&(u[h].length>u[p].length?(u[h].numChars++,f++):(u[p].numChars++,f++)),g!==-1&&v!==-1&&u[g].length!==u[v].length&&(u[g].length>u[v].length?(u[g].numChars++,f++):(u[v].numChars++,f++));const b=Math.max(0,n-f),x=u.reduce((V,R)=>V+(R.type!==this.Q2&&R.length>0?R.length:0),0);for(const V of u)if(V.type!==this.Q2&&V.length>0){const R=Math.round(V.length/x*b);V.numChars+=R}const E=u.reduce((V,R)=>V+R.numChars,0);let _=n-E,O=0;for(;_!==0;){const V=u[O%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=_>0?1:-1,_+=_>0?-1:1),O++}let M=-1;const A=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];l.push(Array.from({length:A.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(M=A.indexOf(V.type),l[i][M]=o.length);for(let R=0;R<V.numChars;R++){let N="⠀";V.type===this.MIN||V.type===this.MAX?N="⠒":V.type===this.Q1||V.type===this.Q3?N="⠿":V.type===this.Q2?N=R===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?N="⠂":V.type===this.BLANK&&(N="⠀"),o.push(N),a.push({row:i,col:M})}}for(let V=0;V<3;V++)if(l[i][V]===-1){for(let R=V+1;R<=3;R++)if(l[i][R]!==-1){l[i][V]=l[i][R];break}}for(let V=6;V>3;V--)if(l[i][V]===-1){for(let R=V-1;R>=3;R--)if(l[i][R]!==-1){l[i][V]=l[i][R];break}}o.push(ve.NEW_LINE),a.push({row:i,col:M})}return{value:o.join(ve.EMPTY),cellToIndex:l,indexToCell:a}}}class vle{encode(t){const n=new Array,o=new Array,a=new Array,l=(t.max-t.min)/3,i=t.min+l,s=i+l;for(let c=0;c<t.values.length;c++){o.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("⠉"),o[c].push(a.length),a.push({row:c,col:u});n.push(ve.NEW_LINE),o[c].push(a.length),a.push({row:c,col:t.values[c].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}}class YP{encode(t){const n=new Array,o=new Array,a=new Array;for(let l=0;l<t.values.length;l++){o.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(l,t);for(let Q=0;Q<t.values[l].length;Q++){const f=t.values[l][Q],h=Q>0?t.values[l][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),o[l].push(a.length),a.push({row:l,col:Q})}n.push(ve.NEW_LINE),o[l].push(a.length),a.push({row:l,col:t.values[l].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}getBrailleChar(t,n,o,a,l,i){return i===void 0&&(i=l),t<=o&&n!==null&&n>o?n<=a?"⢄":n<=i?"⢆":"⢇":t<=o?"⣀":n!==null&&n<=o?t<=a?"⡠":t<=i?"⡰":"⡸":t<=a&&n!==null&&n>a?n<=i?"⠢":"⠣":t<=a?"⠤":n!==null&&n<=a?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=l?"⠉":""}getBraille6Char(t,n,o,a,l){const i=f=>f<=o?"low":f<=a?"medium":(f<=l,"high"),s=i(t),c=n!==null?i(n):null,u={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},Q=`${s},${c}`;return u[Q]||""}addDot8(t){if(!t||t.length===0)return"⢀";const a=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+a)}}class xle extends YP{getThresholds(t,n){const o=Array.isArray(n.min)?n.min[t]:n.min,a=Array.isArray(n.max)?n.max[t]:n.max,l=(a-o)/3,i=o+l,s=i+l;return{low:i,medium:s,high:a}}encode(t){var l;const n=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){o.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);((l=t.custom)==null?void 0:l[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),o[i].push(a.length),a.push({row:i,col:Q})}n.push(ve.NEW_LINE),o[i].push(a.length),a.push({row:i,col:t.values[i].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}}class Lle extends YP{getThresholds(t,n){const o=(n.max[t]-n.min[t])/4,a=n.min[t]+o,l=a+o,i=l+o,s=n.max[t];return{low:a,medium:l,mediumHigh:i,high:s}}}class ble{constructor(t,n,o){ie(this,"context");ie(this,"notification");ie(this,"display");ie(this,"enabled");ie(this,"cacheId");ie(this,"cache");ie(this,"encoders");ie(this,"onChangeEmitter");ie(this,"onChange");this.context=t,this.notification=n,this.display=o,this.enabled=!1,this.cacheId=ve.EMPTY,this.cache=null,this.encoders=new Map([[U2.BAR,new Qd],[U2.BOX,new gle],[U2.CANDLESTICK,new xle],[U2.DODGED,new Qd],[U2.HEATMAP,new vle],[U2.HISTOGRAM,new Qd],[U2.LINE,new Lle],[U2.NORMALIZED,new Qd],[U2.STACKED,new Qd]]),this.onChangeEmitter=new qs,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 o=n.braille;if(this.cacheId!==o.id||this.cache===null){const a=this.encoders.get(n.traceType);this.cache=a.encode(o,WP),this.cacheId=o.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[o.row][o.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:o}=this.cache.indexToCell[t];this.context.moveToIndex(n,o)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const o=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(o);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(Yt.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var KP=(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))(KP||{});class JP{constructor(){}static async post(t,n,o){const a={...this.DEFAULT_HEADERS,...o};return this.request(t,"POST",a,n)}static async request(t,n,o,a){try{const l=await fetch(t,{method:n,headers:o,body:a});return l.ok?{success:!0,data:await l.json()}:{success:!1,error:{statusCode:l.status,message:`API Error: ${l.status} - ${l.statusText}`}}}catch(l){return console.error(`Error in API ${n} request to ${t}:`,l),{success:!1,error:{statusCode:KP.SERVER_ERROR,message:l instanceof Error?l.message:"Unknown error occurred"}}}}}ie(JP,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Hle=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
|
|
641
|
+
root.render(<App />);`),T.unstable_strictMode===!0&&(m=!0),T.identifierPrefix!==void 0&&(S=T.identifierPrefix),T.onUncaughtError!==void 0&&(w=T.onUncaughtError),T.onCaughtError!==void 0&&(D=T.onCaughtError),T.onRecoverableError!==void 0&&(F=T.onRecoverableError),T.unstable_transitionCallbacks!==void 0&&(X=T.unstable_transitionCallbacks)),T=tp(r,1,!1,null,null,m,S,w,D,F,X,null),r[ji]=T.current,ns(r),new uc(T)},Td.hydrateRoot=function(r,T,m){if(!x(r))throw Error("Target container is not a DOM element.");Tc(r),T===void 0&&console.error("Must provide initial children as second argument to hydrateRoot. Example usage: hydrateRoot(domContainer, <App />)");var S=!1,w="",D=wg,F=E9,X=S9,oe=null,le=null;return m!=null&&(m.unstable_strictMode===!0&&(S=!0),m.identifierPrefix!==void 0&&(w=m.identifierPrefix),m.onUncaughtError!==void 0&&(D=m.onUncaughtError),m.onCaughtError!==void 0&&(F=m.onCaughtError),m.onRecoverableError!==void 0&&(X=m.onRecoverableError),m.unstable_transitionCallbacks!==void 0&&(oe=m.unstable_transitionCallbacks),m.formState!==void 0&&(le=m.formState)),T=tp(r,1,!0,T,m??null,S,w,D,F,X,oe,le),T.context=F1(null),m=T.current,S=$n(m),S=Ke(S),w=o6(S),w.callback=null,l6(m,w,S),m=S,T.current.lanes=m,i1(T,m),y4(T),r[ji]=T.current,ns(r),new cc(T)},Td.version="19.1.1",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})(),Td}var zP;function _7e(){if(zP)return Qg.exports;zP=1;var e={};function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function")){if(e.NODE_ENV!=="production")throw new Error("^_^");try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(n){console.error(n)}}}return e.NODE_ENV==="production"?(t(),Qg.exports=M7e()):Qg.exports=A7e(),Qg.exports}var O7e=_7e();class xH{constructor(){ie(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 o=this.items.lastIndexOf(t);return o!==-1?(this.items.splice(o,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}}class C7e{constructor(t){ie(this,"id");ie(this,"instructionContext");ie(this,"plotContext");ie(this,"scopeContext");ie(this,"figure");this.figure=t,this.id=t.id,this.plotContext=new xH,this.scopeContext=new xH;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(Yt.SUBPLOT);return}this.scopeContext.push(Yt.TRACE);const o=t.activeSubplot.state;if(o.empty||o.size!==1){this.instructionContext=t.activeSubplot,this.plotContext.push(t.activeSubplot),this.plotContext.push(t.activeSubplot.activeTrace);return}this.instructionContext=t.activeSubplot.activeTrace,this.plotContext.push(t.activeSubplot.activeTrace)}dispose(){this.plotContext.clear(),this.scopeContext.clear()}get active(){return this.plotContext.peek()}get state(){return this.active.state}toggleScope(t){this.scopeContext.clear(),this.scopeContext.push(t),W3.setScope(t)}get scope(){return this.scopeContext.peek()}isMovable(t){return this.active.isMovable(t)}moveOnce(t){this.active.moveOnce(t)}moveToExtreme(t){this.active.moveToExtreme(t)}moveToIndex(t,n){this.active.moveToIndex(t,n)}stepTrace(t){if(this.plotContext.size()>1){this.plotContext.pop();const n=this.active,o=n.activeTrace;if(!o)return;const a=o.getCurrentXValue();n.moveOnce(t);const l=n.activeTrace;if(this.plotContext.push(l),l.getId()===o.getId()){l.notifyOutOfBounds(),n.notifyOutOfBounds();return}if(l.moveToXValue(a),l.state.empty)l.notifyStateUpdate();else{const i=n.getRow()+1,s=n.getSize(),c={...l.state,isLayerSwitch:!0,index:i,size:s};l.notifyObserversWithState(c)}}else{const n=this.figure.subplots[0][0];this.active.notifyOutOfBounds(),n.notifyOutOfBounds()}}enterSubplot(){if(this.active.state.type==="figure"){const n=this.active;this.plotContext.push(n.activeSubplot);const o=n.activeSubplot.activeTrace;o.resetToInitialEntry(),this.plotContext.push(o),this.toggleScope(Yt.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(Yt.SUBPLOT))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const o=t?"Click to activate.":ve.EMPTY;switch(n.type){case"figure":return`This is a maidr figure containing ${n.size} subplots. ${o} 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. ${o} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`;case"trace":{let a=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(a="single line");const l=a==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${a}${l}. ${o} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}var M2=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(M2||{}),U2=(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))(U2||{});function w7e(e){return e!==null&&typeof e=="object"&&"x"in e}function V7e(e){return typeof e=="string"||typeof e=="number"}function D7e(e){return e!==null&&typeof e=="object"&&"x"in e}class qP{computeIndexAndSegment(t,n,o,a){return o===M2.HORIZONTAL?{pointIndex:t,segmentType:a[n]}:{pointIndex:n,segmentType:a[t]}}computeVisualCoordinates(t,n,o){return o===M2.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,o){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const a=t[0][o];return this.extractXFromPoint(a)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][o]){const a=t[n][o];return this.extractXFromPoint(a)}return null}extractXValueFromValues(t,n,o){if(this.isValidPosition(t,n,o)){const a=t[n][o];return this.extractXFromValue(a)}return null}moveToXValueInPoints(t,n,o){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const c=this.findPointIndexByX(t[0],n);if(c!==-1)return o(0,c),!0;{const u=this.findNearestPointIndexByX(t[0],n);if(u!==-1){const Q=oi(t[0][u]);if(typeof n=="number"&&typeof Q=="number")return o(0,u),!0;if(typeof n=="string"&&typeof Q=="string")return o(0,u),!0}}}let a=-1,l=-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 o(c,Q),!0;const f=this.findNearestPointIndexByX(u,n);if(f!==-1){const h=oi(u[f]);let p=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof h=="number"?(p=Math.abs(h-n),p<i&&(i=p,a=c,l=f,s="numeric")):typeof n=="string"&&typeof h=="string"?a===-1&&(a=c,l=f,s="categorical"):a===-1&&(a=c,l=f,s="generic")}}}if(a!==-1&&l!==-1){const c=t[a];if(Array.isArray(c)&&oi(c[l]),s!==null)return o(a,l),!0}return!1}moveToXValueInValues(t,n,o){let a=-1,l=-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 o(c,u),!0;if(typeof n=="number"&&typeof f=="number"){const h=Math.abs(f-n);h<i&&(i=h,a=c,l=u,s="numeric")}else typeof n=="string"&&typeof f=="string"?a===-1&&(a=c,l=u,s="categorical"):a===-1&&(a=c,l=u,s="generic")}return a!==-1&&l!==-1?(this.extractXFromValue(t[a][l]),o(a,l),!0):!1}extractXFromPoint(t){return D7e(t)?t.x:null}extractXFromValue(t){return w7e(t)?t.x:V7e(t)?t:null}findPointIndexByX(t,n){return t.findIndex(o=>o.x===n)}isValidPosition(t,n,o){return n>=0&&n<t.length&&o>=0&&o<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let o=-1,a=Number.POSITIVE_INFINITY;for(let l=0;l<t.length;l++){const i=oi(t[l]);if(typeof i=="number"){const s=Math.abs(i-n);s<a&&(a=s,o=l)}else if(typeof i=="string"){const s=Number(i);if(!Number.isNaN(s)){const c=Math.abs(s-n);c<a&&(a=c,o=l)}}}if(o!==-1)return oi(t[o]),o}else if(typeof n=="string"){for(let a=0;a<t.length;a++)if(oi(t[a])===n)return a;const o=Number(n);if(!Number.isNaN(o)){let a=-1,l=Number.POSITIVE_INFINITY;for(let i=0;i<t.length;i++){const s=oi(t[i]);if(typeof s=="number"){const c=Math.abs(s-o);c<l&&(l=c,a=i)}else if(typeof s=="string"){const c=Number(s);if(!Number.isNaN(c)){const u=Math.abs(c-o);u<l&&(l=u,a=i)}}}if(a!==-1)return oi(t[a]),a}for(let a=0;a<t.length;a++)if(typeof oi(t[a])=="string")return a}return t.length>0?(oi(t[0]),0):-1}dispose(){}}function R7e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function k7e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function N7e(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function B7e(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function P7e(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function I7e(e){return e&&typeof e=="object"&&"value"in e}function oi(e){return e?R7e(e)||k7e(e)||B7e(e)||P7e(e)||N7e(e)?e.x:I7e(e)?e.value:null:null}const j7e="unavailable",F7e="X",z7e="Y",q7e="unavailable";class LH{constructor(){ie(this,"observers");ie(this,"isInitialEntry");ie(this,"isOutOfBounds");ie(this,"row");ie(this,"col");this.observers=new Array,this.isInitialEntry=!0,this.isOutOfBounds=!1,this.row=0,this.col=0}dispose(){for(const t of this.observers)this.removeObserver(t);this.observers.length=0}moveOnce(t){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(t)){this.notifyOutOfBounds();return}switch(t){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}getSafeIndices(){var a;const t=this.values,n=this.row>=0&&this.row<t.length?this.row:0,o=this.col>=0&&this.col<(((a=t[n])==null?void 0:a.length)||0)?this.col:0;return{row:n,col:o}}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:o}=this.getSafeIndices();this.col=(n=this.values[o])!=null&&n.length?this.values[o].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,o;if(Array.isArray(t)){const[a,l]=t,{row:i}=this.getSafeIndices();return a>=0&&a<this.values.length&&l>=0&&l<(((n=this.values[i])==null?void 0:n.length)||0)}switch(t){case"UPWARD":return this.row<this.values.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":{const{row:a}=this.getSafeIndices();return this.col<(((o=this.values[a])==null?void 0:o.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))}ensureInitialized(){this.isInitialEntry&&(this.handleInitialEntry(),this.notifyStateUpdate())}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}addObserver(t){this.observers.push(t)}removeObserver(t){this.observers=this.observers.filter(n=>n!==t)}notifyStateUpdate(){const t=this.state;for(const n of this.observers)n.update(t)}notifyOutOfBounds(){this.isOutOfBounds=!0,this.notifyStateUpdate(),this.isOutOfBounds=!1}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}}class l8 extends LH{constructor(n){var o,a,l;super();ie(this,"id");ie(this,"type");ie(this,"title");ie(this,"xAxis");ie(this,"yAxis");ie(this,"fill");ie(this,"navigationService");this.navigationService=new qP,this.id=n.id,this.type=n.type,this.title=n.title??j7e,this.xAxis=((o=n.axes)==null?void 0:o.x)??F7e,this.yAxis=((a=n.axes)==null?void 0:a.y)??z7e,this.fill=((l=n.axes)==null?void 0:l.fill)??q7e}dispose(){this.values.length=0,this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(o=>{(Array.isArray(o)?o:[o]).forEach(l=>l.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;if(this.isOutOfBounds){const o=this.values,a=this.row,l=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=o[a])==null?void 0:n.length)||0,index:l}}}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 o=this.values,a=this.row,l=this.col;return{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=o[a])==null?void 0:n.length)||0,index:l}}}return{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){var a;const{row:n}=this.getSafeIndices(),o=((a=this.values[n])==null?void 0:a.length)||0;return{UPWARD:this.values.length,DOWNWARD:this.values.length,FORWARD:o,BACKWARD:o}}hasMultiPoints(){return!1}getExtremaTargets(){return[]}navigateToExtrema(n){if(this.supportsExtrema)throw new Error("Extrema navigation not implemented by this plot type")}finalizeExtremaNavigation(){this.isInitialEntry&&(this.isInitialEntry=!1),this.updateVisualPointPosition(),this.notifyStateUpdate()}updateVisualPointPosition(){}supportsExtremaNavigation(){return this.supportsExtrema}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 o=this.getPointsArray();if(this.isValidPointsArray(o))return this.navigationService.moveToXValueInPoints(o,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const o=this.values;if(this.isValidValuesArray(o))return this.navigationService.moveToXValueInValues(o,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}getId(){return this.id}}class un{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],o=t[0];for(let a=1;a<t.length;a++){const l=t[a];l<n&&(n=l),l>o&&(o=l)}return{min:n,max:o}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class dg{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let a=n.substring(1).split("");return a.length===3&&(a=[a[0],a[0],a[1],a[1],a[2],a[2]]),{r:Number.parseInt(a[0]+a[1],16),g:Number.parseInt(a[2]+a[3],16),b:Number.parseInt(a[4]+a[5],16)}}const o=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return o?{r:Number.parseInt(o[1],10),g:Number.parseInt(o[2],10),b:Number.parseInt(o[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const o=this.calculateLuminance(t),a=this.calculateLuminance(n);return(Math.max(o,a)+.05)/(Math.min(o,a)+.05)}static calculateLuminance(t){const[n,o,a]=[t.r,t.g,t.b].map(l=>{const i=l/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*o+.0722*a}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}}class $t{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),a=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,l=await new Promise((c,u)=>{const Q=new Image;Q.onload=()=>c(Q),Q.onerror=()=>u(new Error("Failed to load SVG image")),Q.src=a}),i=document.createElement("canvas");[i.width,i.height]=[l.naturalWidth,l.naturalHeight];const s=i.getContext("2d");return s?(s.drawImage(l,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(o=>{if(!n)return o;const a=o.cloneNode(!0);return a.setAttribute(ve.VISIBILITY,ve.HIDDEN),o.insertAdjacentElement(ve.AFTER_END,a),a})}static selectElement(t,n=!0){const o=document.querySelector(t);if(!n)return o;const a=o==null?void 0:o.cloneNode(!0);return a==null||a.setAttribute(ve.VISIBILITY,ve.HIDDEN),o==null||o.insertAdjacentElement(ve.AFTER_END,a),a}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(ve.FILL,ve.TRANSPARENT),n.setAttribute(ve.STROKE,ve.TRANSPARENT),n.setAttribute(ve.VISIBILITY,ve.HIDDEN),n}static createCircleElement(t,n,o){var u;const a=window.getComputedStyle(o),l=a.stroke||a.fill,i=a.strokeWidth||"2",s=Number.parseFloat(i)*2,c=document.createElementNS(this.SVG_NAMESPACE,ve.CIRCLE);return c.setAttribute(ve.CIRCLE_X,String(t)),c.setAttribute(ve.CIRCLE_Y,String(n)),c.setAttribute(ve.RADIUS,String(s)),c.setAttribute(ve.FILL,l),c.setAttribute(ve.STROKE,l),c.setAttribute(ve.STROKE_WIDTH,i),c.setAttribute(ve.VISIBILITY,ve.HIDDEN),(u=o.parentElement)==null||u.insertAdjacentElement(ve.AFTER_END,c),c}static createLineElement(t,n){const a=t.getBBox();let l,i,s,c;switch(n){case"top":[l,i,s,c]=[a.x,a.y,a.x+a.width,a.y];break;case"bottom":[l,i,s,c]=[a.x,a.y+a.height,a.x+a.width,a.y+a.height];break;case"left":[l,i,s,c]=[a.x,a.y,a.x,a.y+a.height];break;case"right":[l,i,s,c]=[a.x+a.width,a.y,a.x+a.width,a.y+a.height];break}const u=window.getComputedStyle(t),Q=document.createElementNS(this.SVG_NAMESPACE,ve.LINE);return Q.setAttribute(ve.X1,String(l)),Q.setAttribute(ve.Y1,String(i)),Q.setAttribute(ve.X2,String(s)),Q.setAttribute(ve.Y2,String(c)),Q.setAttribute(ve.STROKE,u.stroke),Q.setAttribute(ve.STROKE_WIDTH,u.strokeWidth||"2"),Q.setAttribute(ve.VISIBILITY,ve.HIDDEN),t.insertAdjacentElement(ve.AFTER_END,Q),Q}static createHighlightElement(t,n){const o=t.cloneNode(!0),a=t.tagName.toLowerCase(),l=a===ve.POLYLINE||a===ve.LINE,i=l?window.getComputedStyle(t).getPropertyValue(ve.STROKE):window.getComputedStyle(t).getPropertyValue(ve.FILL),s=this.getHighlightColor(i,n);if(o.setAttribute(ve.VISIBILITY,ve.VISIBLE),o.setAttribute(ve.STROKE,s),o.setAttribute(ve.FILL,s),o.style.fill=s,o.style.stroke=s,l){const c=window.getComputedStyle(o).getPropertyValue(ve.STROKE_WIDTH);o.setAttribute(ve.STROKE_WIDTH,`${c+2}`)}return t.insertAdjacentElement(ve.AFTER_END,o),o}static getHighlightColor(t,n){const o=dg.parse(t);if(!o||!(dg.getContrastRatio(o,ve.HIGHLIGHT_BASE_COLOR)<ve.HIGHLIGHT_CONTRAST_RATIO))return n;const i={...o};return o.r===o.g&&o.g===o.b?(i.r=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.r*ve.HIGHLIGHT_COLOR_RATIO)),i.g=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.g*ve.HIGHLIGHT_COLOR_RATIO)),i.b=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.b*ve.HIGHLIGHT_COLOR_RATIO))):o.r>=o.g&&o.r>=o.b?i.r=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.r*ve.HIGHLIGHT_COLOR_RATIO)):o.g>=o.r&&o.g>=o.b?i.g=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.g*ve.HIGHLIGHT_COLOR_RATIO)):i.b=Math.min(ve.HIGHLIGHT_MAX_COLOR,Math.floor(o.b*ve.HIGHLIGHT_COLOR_RATIO)),dg.rgbToString(i)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",o=dg.parse(n);return o?(.2126*o.r+.7152*o.g+.0722*o.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,o){const a=t.querySelector("rect, path");let l="";if(a){l=window.getComputedStyle(a).getPropertyValue("fill"),(!l||l==="none"||l==="transparent"||l==="rgba(0, 0, 0, 0)")&&(o?l=window.getComputedStyle(o).getPropertyValue("fill"):l=n);const i=this.getHighlightColor(l,n);a.setAttribute("stroke",i),a.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}ie($t,"SVG_NAMESPACE","http://www.w3.org/2000/svg");class bH extends l8{constructor(n,o){super(n);ie(this,"points");ie(this,"barValues");ie(this,"highlightValues");ie(this,"orientation");ie(this,"min");ie(this,"max");ie(this,"supportsExtrema",!0);this.points=o,this.orientation=n.orientation??M2.VERTICAL,this.barValues=o.map(a=>a.map(l=>this.orientation===M2.VERTICAL?Number(l.y):Number(l.x))),this.min=this.barValues.map(a=>un.safeMin(a)),this.max=this.barValues.map(a=>un.safeMax(a)),this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get values(){return this.barValues}audio(){const n=this.orientation===M2.VERTICAL,o=n?this.barValues[this.row].length:this.barValues.length,a=n?this.col:this.row,l=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{min:un.safeMin(this.min),max:un.safeMax(this.max),size:o,index:a,value:l,...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===M2.VERTICAL,o=this.points[this.row][this.col],a=n?this.xAxis:this.yAxis,l=n?o.x:o.y,i=n?this.yAxis:this.xAxis,s=n?o.y:o.x;return{main:{label:a,value:l},cross:{label:i,value:s}}}mapToSvgElements(n){if(!n)return null;const o=[$t.selectAllElements(n)];if(o.length!==this.points.length)return null;for(let a=0;a<this.points.length;a++)if(o[a].length!==this.points[a].length)return null;return o}}class $7e extends bH{constructor(t){super(t,[t.data])}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const o=this.barValues[n];if(!o||o.length===0)return t;const a=this.min[n],l=this.max[n],i=o.indexOf(l),s=o.indexOf(a);return t.push({label:`Max Bar at ${this.getPointLabel(i)}`,value:l,pointIndex:i,segment:"bar",type:"max",navigationType:"point"}),t.push({label:`Min Bar at ${this.getPointLabel(s)}`,value:a,pointIndex:s,segment:"bar",type:"min",navigationType:"point"}),t}navigateToExtrema(t){this.col=t.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(t){if(this.points[this.row]&&this.points[this.row][t]){const n=this.points[this.row][t];return this.orientation===M2.VERTICAL?`${n.x}`:`${n.y}`}return`Point ${t}`}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}}const t5={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class U7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!1);ie(this,"points");ie(this,"boxValues");ie(this,"highlightValues");ie(this,"orientation");ie(this,"sections");ie(this,"min");ie(this,"max");this.points=n.data,this.orientation=n.orientation??M2.VERTICAL,this.sections=[t5.LOWER_OUTLIER,t5.MIN,t5.Q1,t5.Q2,t5.Q3,t5.MAX,t5.UPPER_OUTLIER];const o=[l=>l.lowerOutliers,l=>l.min,l=>l.q1,l=>l.q2,l=>l.q3,l=>l.max,l=>l.upperOutliers];this.orientation===M2.HORIZONTAL?this.boxValues=this.points.map(l=>o.map(i=>i(l))):this.boxValues=o.map(l=>this.points.map(i=>l(i)));const a=this.boxValues.map(l=>l.flatMap(i=>Array.isArray(i)?i:[i]));this.min=un.minFrom2D(a),this.max=un.maxFrom2D(a),this.row=this.boxValues.length-1,this.highlightValues=this.mapToSvgElements(n.selectors)}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,o){const a=this.orientation===M2.HORIZONTAL;n=a?n:o,o=a?o:n,super.moveToIndex(n,o)}get values(){return this.boxValues}audio(){const n=this.boxValues[this.row][this.col],o=Array.isArray(n)?n.map(a=>a-this.min):n-this.min;return{min:this.min,max:this.max,value:n,size:this.max-this.min,index:o}}braille(){const n=this.orientation===M2.HORIZONTAL,o=n?this.row:this.col,a=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:o,col:a}}text(){const n=this.orientation===M2.HORIZONTAL,o=n?this.points[this.row]:this.points[this.col],a=n?this.yAxis:this.xAxis,l=n?this.sections[this.col]:this.sections[this.row],i=n?this.xAxis:this.yAxis,s=this.boxValues[this.row][this.col];return{main:{label:a,value:o.fill},cross:{label:i,value:s},section:l}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const o=this.orientation===M2.VERTICAL,a=new Array;if(o)for(let l=0;l<this.sections.length;l++)a.push(Array.from({length:n.length}));return n.forEach((l,i)=>{const s=l.lowerOutliers.flatMap(b=>$t.selectAllElements(b)),c=l.upperOutliers.flatMap(b=>$t.selectAllElements(b)),u=$t.selectElement(l.min)??$t.createEmptyElement(),Q=$t.selectElement(l.max)??$t.createEmptyElement(),f=$t.selectElement(l.iq)??$t.createEmptyElement(),h=$t.selectElement(l.q2)??$t.createEmptyElement(),[p,g]=o?[$t.createLineElement(f,"top"),$t.createLineElement(f,"bottom")]:[$t.createLineElement(f,"left"),$t.createLineElement(f,"right")],v=[s,u,p,h,g,Q,c];o?v.forEach((b,x)=>{a[x][i]=b}):a.push(v)}),a}}const G7e="trend",$P=100;class Z7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!0);ie(this,"candles");ie(this,"candleValues");ie(this,"orientation");ie(this,"sections",["volatility","open","high","low","close"]);ie(this,"currentSegmentType","open");ie(this,"currentPointIndex",0);ie(this,"sortedSegmentsByPoint");ie(this,"segmentPositionMaps");ie(this,"min");ie(this,"max");ie(this,"highlightValues");ie(this,"navigationService");this.navigationService=new qP;const o=n.data;this.candles=o.map(a=>({...a,volatility:Math.round((a.high-a.low)*$P)/$P,trend:a.close>a.open?"Bull":a.close<a.open?"Bear":"Neutral"})),this.orientation=n.orientation??M2.VERTICAL,this.candleValues=this.sections.map(a=>this.candles.map(l=>l[a])),this.min=un.minFrom2D(this.candleValues),this.max=un.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===M2.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors)}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(l=>[l,n[l]]).sort((l,i)=>l[1]-i[1]).map(l=>l[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const o=new Map;return n.forEach((a,l)=>{o.set(a,l)}),o})}getSegmentPositionInSortedOrder(n,o){return this.segmentPositionMaps[n].get(o)??0}getSegmentTypeAtSortedPosition(n,o){return this.sortedSegmentsByPoint[n][o]??"open"}updateVisualSegmentPosition(){const o=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===M2.HORIZONTAL?this.col=o:this.row=o}updateVisualPointPosition(){this.orientation===M2.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex,this.updateVisualSegmentPosition()}handleInitialEntry(){this.isInitialEntry=!1,this.currentPointIndex=Math.max(0,Math.min(this.currentPointIndex,this.candles.length-1)),this.currentSegmentType="close",this.updateVisualSegmentPosition()}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":case"DOWNWARD":{const o=this.sortedSegmentsByPoint[this.currentPointIndex],a=o.indexOf(this.currentSegmentType??"open");if(a===-1){this.notifyOutOfBounds();return}const l=n==="UPWARD"?a+1:a-1;if(l>=0&&l<o.length)this.currentSegmentType=o[l],this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}case"FORWARD":case"BACKWARD":{const o=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(o>=0&&o<this.candles.length)this.currentPointIndex=o,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else{this.notifyOutOfBounds();return}break}}this.notifyStateUpdate()}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const o=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=o[o.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const o=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=o[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,o){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:a,segmentType:l}=this.navigationService.computeIndexAndSegment(n,o,this.orientation,this.sections);this.currentPointIndex=a,this.currentSegmentType=l,this.row=n,this.col=o,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 o=this.sortedSegmentsByPoint[this.currentPointIndex],a=o.indexOf(this.currentSegmentType??"open"),l=n==="UPWARD"?a+1:a-1;return l>=0&&l<o.length}case"FORWARD":case"BACKWARD":{const o=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return o>=0&&o<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}audio(){let n;return this.currentSegmentType==="volatility"?n=this.candles[this.currentPointIndex].volatility:this.currentSegmentType?n=this.candles[this.currentPointIndex][this.currentSegmentType]:n=this.candles[this.currentPointIndex].open,{min:this.min,max:this.max,size:this.candles.length,index:this.currentPointIndex,value:n,trend:this.candles[this.currentPointIndex].trend}}braille(){const n=this.candles.map(i=>i.trend),o=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=o;const a=this.candleValues.map(i=>Math.min(...i)),l=this.candleValues.map(i=>Math.max(...i));return{empty:!1,id:this.id,values:this.candleValues,min:a,max:l,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const o=Array.isArray(n)?n:[n],a=[];for(const l of o)a.push(...$t.selectAllElements(l));return a}getElementAt(n,o){return o<n.length?n[o]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const g=Array.isArray(n)?n[0]||"":n,v=$t.selectAllElements(g),b=[];for(let x=0;x<this.sections.length;x++){b[x]=[];for(let E=0;E<this.candles.length;E++){const _=E<v.length?E:0;b[x][E]=v[_]}}return b}const o=n,a=this.candles.length,l=this.collectElements(o.body);let i=this.collectElements(o.wickHigh),s=this.collectElements(o.wickLow);if(i.length===0||s.length===0){const g=this.collectElements(o.wick);g.length>0&&(i.length===0&&(i=g),s.length===0&&(s=g))}const c=this.collectElements(o.open),u=this.collectElements(o.close),Q=Array.from({length:a},()=>$t.createEmptyElement()),f=Array.from({length:a},()=>$t.createEmptyElement()),h=Array.from({length:a},()=>$t.createEmptyElement());for(let g=0;g<a;g++){let v=this.getElementAt(c,g);if(!v){const x=this.getElementAt(l,g);if(x){const{open:E,close:_}=this.candles[g],O=_>E?"bottom":_<E?"top":"bottom";v=$t.createLineElement(x,O)}else v=$t.createEmptyElement()}Q[g]=v;let b=this.getElementAt(u,g);if(!b){const x=this.getElementAt(l,g);if(x){const{open:E,close:_}=this.candles[g],O=_>E?"top":_<E?"bottom":"top";b=$t.createLineElement(x,O)}else b=$t.createEmptyElement()}f[g]=b,h[g]=$t.createEmptyElement()}const p=Array.from({length:this.sections.length},()=>Array.from({length:a},()=>$t.createEmptyElement()));for(let g=0;g<a;g++){const v=this.sortedSegmentsByPoint[g];for(let b=0;b<v.length;b++){const x=v[b];let E;switch(x){case"volatility":{const _=[],O=this.getElementAt(l,g),M=this.getElementAt(i,g)??O,A=this.getElementAt(s,g)??O;M&&_.push(M),O&&_.push(O),A&&_.push(A);const V=Array.from(new Set(_));E=V.length>0?V:[$t.createEmptyElement()]}break;case"open":E=Q[g];break;case"close":E=f[g];break;case"high":E=this.getElementAt(i,g)??this.getElementAt(l,g)??$t.createEmptyElement();break;case"low":E=this.getElementAt(s,g)??this.getElementAt(l,g)??$t.createEmptyElement();break;default:E=$t.createEmptyElement()}p[b][g]=E}}return p}text(){const n=this.candles[this.currentPointIndex];let o;return this.currentSegmentType==="volatility"?o=n.volatility:this.currentSegmentType?o=n[this.currentSegmentType]:o=n.open,{main:{label:this.orientation===M2.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===M2.HORIZONTAL?this.xAxis:this.yAxis,value:o},section:this.currentSegmentType??"open",fill:{label:G7e,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 o=this.candles.findIndex(a=>a.value===n);return o!==-1?(this.currentPointIndex=o,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getAvailableXValues(){return this.candles.map(n=>n.value)}getExtremaTargets(){const n=[],o=this.currentSegmentType??"open";if(o==="volatility"){const a=this.candles.map((u,Q)=>({value:u.volatility,index:Q})),l=Math.max(...a.map(u=>u.value)),i=a.filter(u=>u.value===l).map(u=>u.index),s=Math.min(...a.map(u=>u.value)),c=a.filter(u=>u.value===s).map(u=>u.index);i.forEach((u,Q)=>{const f=this.candles[u];n.push({label:`Max Volatility at ${f.value}`,value:f.volatility,pointIndex:u,segment:"volatility",type:"max",navigationType:"point"})}),c.forEach((u,Q)=>{const f=this.candles[u];n.push({label:`Min Volatility at ${f.value}`,value:f.volatility,pointIndex:u,segment:"volatility",type:"min",navigationType:"point"})})}else{const a=this.candles.map((u,Q)=>({value:u[o],index:Q,xValue:u.value})),l=Math.max(...a.map(u=>u.value)),i=a.filter(u=>u.value===l).map(u=>u.index),s=Math.min(...a.map(u=>u.value)),c=a.filter(u=>u.value===s).map(u=>u.index);i.forEach((u,Q)=>{const f=this.candles[u],h=o.charAt(0).toUpperCase()+o.slice(1);n.push({label:`Max ${h} at ${f.value}`,value:f[o],pointIndex:u,segment:o,type:"max",navigationType:"point"})}),c.forEach((u,Q)=>{const f=this.candles[u],h=o.charAt(0).toUpperCase()+o.slice(1);n.push({label:`Min ${h} at ${f.value}`,value:f[o],pointIndex:u,segment:o,type:"min",navigationType:"point"})})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.finalizeExtremaNavigation()}}class X7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!1);ie(this,"heatmapValues");ie(this,"highlightValues");ie(this,"x");ie(this,"y");ie(this,"min");ie(this,"max");const o=n.data;this.x=o.x,this.y=[...o.y].reverse(),this.heatmapValues=[...o.points].reverse();const{min:a,max:l}=un.minMaxFrom2D(this.heatmapValues);this.min=a,this.max=l,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 o=this.heatmapValues.length,a=this.heatmapValues[0].length,l=$t.selectAllElements(n);if(l.length===0||l.length!==o*a)return null;const i=new Array;if(l[0]instanceof SVGPathElement)for(let s=0;s<o;s++){const c=o-1-s,u=new Array;for(let Q=0;Q<a;Q++){const f=c*a+Q;u.push(l[f])}i.push(u)}else if(l[0]instanceof SVGRectElement)for(let s=0;s<o;s++){const c=new Array;for(let u=0;u<a;u++){const Q=u*o+s;c.push(l[Q])}i.push(c)}return i}}class W7e extends bH{constructor(t){super(t,[t.data])}text(){const t=this.orientation===M2.VERTICAL,n=this.points[this.row][this.col],o=t?n.xMin:n.yMin,a=t?n.xMax:n.yMax;return{...super.text(),range:{min:o,max:a}}}}const UP="Group",HH=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class GP extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!0);ie(this,"points");ie(this,"lineValues");ie(this,"highlightValues");ie(this,"min");ie(this,"max");ie(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(o=>o.map(a=>Number(a.y))),this.min=this.lineValues.map(o=>un.safeMin(o)),this.max=this.lineValues.map(o=>un.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.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 l;const n=this.points[this.row][this.col],o=this.findIntersections();let a={};if(o.length>1){let i=o.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=((l=this.points[this.previousRow][0])==null?void 0:l.fill)||`l${this.previousRow+1}`;i.includes(s)&&(i=[s,...i.filter(c=>c!==s)])}a={fill:{label:UP,value:`intersection at (${i.join(", ")})`}}}else a=n.fill?{fill:{label:UP,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...a}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const a=this.findLineByXAndYDirection(n),l=this.points[this.row][this.col].x;if(a!==null&&a!==this.row){const i=this.findColumnByXValue(a,l);if(i!==-1){this.row=a,this.col=i;const s=this.findIntersections();if(s.length>1){const u={...super.state,intersections:s};for(const Q of this.observers)Q.update(u)}else this.notifyStateUpdate();return}else{this.notifyOutOfBounds();return}}else{this.notifyOutOfBounds();return}}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const o=this.findIntersections();if(o.length>1){const l={...super.state,intersections:o};for(const i of this.observers)i.update(l)}else this.notifyStateUpdate()}findIntersections(){const n=this.points[this.row][this.col].x,o=this.points[this.row][this.col].y,a=[];for(let l=0;l<this.points.length;l++){const i=this.points[l].findIndex(s=>s.x===n&&s.y===o);i!==-1&&a.push({min:this.min[l],max:this.max[l],size:this.points[l].length,index:i,value:o,groupIndex:l})}return a}isMovable(n){if(Array.isArray(n)){const[o,a]=n;return o>=0&&o<this.values.length&&a>=0&&a<this.values[o].length}switch(n){case"UPWARD":case"DOWNWARD":{const o=this.findLineByXAndYDirection(n);if(o===null)return!1;const a=this.points[this.row][this.col].x;return this.findColumnByXValue(o,a)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const o=this.points[this.row][this.col].x;let a=null,l=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===o);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<l&&(l=Q,a=i)}return a}findColumnByXValue(n,o){return this.points[n].findIndex(a=>a.x===o)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const o=[];let a=!0;for(let l=0;l<n.length;l++){const i=$t.selectElement(n[l],!1);if(!i){o.push([]);continue}const s=[];if(i instanceof SVGPathElement){const Q=i.getAttribute(ve.D)||ve.EMPTY;HH.lastIndex=0;let f=HH.exec(Q);for(;f!==null;)s.push({x:Number.parseFloat(f[1]),y:Number.parseFloat(f[2])}),f=HH.exec(Q)}else if(i instanceof SVGPolylineElement){const f=(i.getAttribute(ve.POINTS)||ve.EMPTY).split(/\s+/).filter(Boolean);for(const h of f){const[p,g]=h.split(ve.COMMA);s.push({x:Number.parseFloat(p),y:Number.parseFloat(g)})}}if(s.length!==this.lineValues[l].length)if(s.length<this.lineValues[l].length)for(;s.length<this.lineValues[l].length;)s.push({x:Number.NaN,y:Number.NaN});else s.length>this.lineValues[l].length&&(s.length=this.lineValues[l].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($t.createCircleElement(Q.x,Q.y,i))}if(u){o.push([]);continue}c.length>0&&(a=!1),o.push(c)}return a?null:o}get state(){const n=super.state;if(n.empty)return n;const o=this.points.length>1,a={...n,plotType:o?"multiline":"single line",...o&&{groupCount:this.points.length}},l=this.findIntersections();return l.length>1?{...a,intersections:l}:a}getExtremaTargets(){const n=[],o=this.row;if(o<0||o>=this.lineValues.length)return n;const a=this.lineValues[o];if(!a||a.length===0)return n;const l=this.min[o],i=this.max[o],s=[],c=[];for(let u=0;u<a.length;u++){const Q=a[u];Q===i&&s.push(u),Q===l&&c.push(u)}for(const u of s)n.push({label:`Max point at ${this.getPointLabel(u)}`,value:i,pointIndex:u,segment:"line",type:"max",navigationType:"point"});for(const u of c)n.push({label:`Min point at ${this.getPointLabel(u)}`,value:l,pointIndex:u,segment:"line",type:"min",navigationType:"point"});return n}navigateToExtrema(n){this.col=n.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(n){return this.points[this.row]&&this.points[this.row][n]?`${this.points[this.row][n].x}`:`Point ${n}`}updateVisualPointPosition(){const{row:n,col:o}=this.getSafeIndices();this.row=n,this.col=o}getAvailableXValues(){return this.points[this.row].map(n=>n.x)}moveToXValue(n){return this.isInitialEntry&&this.handleInitialEntry(),super.moveToXValue(n)}}class Y7e extends l8{constructor(n){super(n);ie(this,"supportsExtrema",!1);ie(this,"mode");ie(this,"xPoints");ie(this,"yPoints");ie(this,"xValues");ie(this,"yValues");ie(this,"highlightXValues");ie(this,"highlightYValues");ie(this,"minX");ie(this,"maxX");ie(this,"minY");ie(this,"maxY");this.mode="column";const o=n.data,a=[...o].sort((c,u)=>c.x-u.x||c.y-u.y);this.xPoints=new Array;let l=null;for(const c of a)(!l||l.x!==c.x)&&(l={x:c.x,y:[]},this.xPoints.push(l)),l.y.push(c.y);const i=[...o].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=un.safeMin(this.xValues),this.maxX=un.safeMax(this.xValues),this.minY=un.safeMin(this.yValues),this.maxY=un.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(o=>o.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(o=>o.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],o=n.y[Math.floor(n.y.length/2)],a=this.yValues.indexOf(o);a===-1||a>=this.yPoints.length?this.row=0:this.row=a,this.mode="row"}else{const n=this.yPoints[this.row],o=n.x[Math.floor(n.x.length/2)],a=this.xValues.indexOf(o);a===-1||a>=this.xPoints.length?this.col=0:this.col=a,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}this.notifyStateUpdate()}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}this.notifyStateUpdate()}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const o=$t.selectAllElements(n);if(o.length===0)return[null,null];const a=new Map,l=new Map;o.forEach(c=>{const u=Number.parseFloat(c.getAttribute("x")||""),Q=Number.parseFloat(c.getAttribute("y")||"");Number.isNaN(u)||(a.has(u)||a.set(u,[]),a.get(u).push(c)),Number.isNaN(Q)||(l.has(Q)||l.set(Q,[]),l.get(Q).push(c))});const i=Array.from(a.entries()).sort(([c],[u])=>c-u).map(([c,u])=>u),s=Array.from(l.entries()).sort(([c],[u])=>u-c).map(([c,u])=>u);return[i,s]}}const ZP="Sum",K7e="Level",J7e="undefined";class ele extends bH{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let l=0;l<this.barValues[0].length;l++){const i=this.barValues.reduce((c,u)=>c+u[l],0);t.push(i);const s=this.orientation===M2.VERTICAL?{x:this.points[0][l].x,y:i,fill:ZP}:{x:i,y:this.points[0][l].y,fill:ZP};n.push(s)}this.points.push(n),this.barValues.push(t);const{min:o,max:a}=un.minMax(t);this.min.push(o),this.max.push(a)}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const o=this.min[n],a=this.max[n],l=this.barValues[n];if(!l||l.length===0)return t;const i=l.indexOf(a),s=l.indexOf(o),c=this.getGroupLabel(n),u=this.getCategoryLabel(i),Q=this.getCategoryLabel(s);return t.push({label:`Max ${c} at ${u}`,value:a,pointIndex:i,segment:c,type:"max",groupIndex:n,categoryIndex:i,navigationType:"group"}),t.push({label:`Min ${c} at ${Q}`,value:o,pointIndex:s,segment:c,type:"min",groupIndex:n,categoryIndex:s,navigationType:"group"}),t}navigateToExtrema(t){t.groupIndex!==void 0&&t.categoryIndex!==void 0?(this.row=t.groupIndex,this.col=t.categoryIndex):this.col=t.pointIndex,this.finalizeExtremaNavigation()}getGroupLabel(t){if(this.points[t]&&this.points[t].length>0){const n=this.points[t][0];if(t===this.barValues.length-1)return"Total";if(n.fill)return`${this.getFillAxisLabel()}: '${n.fill}'`}return`Group ${t}`}getCategoryLabel(t){if(this.points[0]&&this.points[0][t]){const n=this.points[0][t];return this.orientation===M2.VERTICAL?`${n.x}`:`${n.y}`}return`Category ${t}`}getFillAxisLabel(){return"Category"}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}text(){return{...super.text(),fill:{label:K7e,value:this.points[this.row][this.col].fill??J7e}}}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=$t.selectAllElements(t);if(n.length===0)return new Array;const o=new Array;if(n[0]instanceof SVGPathElement)for(let a=0,l=0;a<this.barValues.length;a++){const i=new Array;for(let s=0;s<this.barValues[a].length;s++){if(l>=n.length)return new Array;this.barValues[a][s]===0?i.push($t.createEmptyElement()):i.push(n[l++])}o.push(i)}else if(n[0]instanceof SVGRectElement){for(let a=0;a<this.barValues.length;a++)o.push(new Array);for(let a=0,l=0;a<this.barValues[0].length;a++)for(let i=this.barValues.length-1;i>=0;i--){if(l>=n.length)return new Array;this.barValues[i][a]===0?o[i].push($t.createEmptyElement()):o[i].push(n[l++])}}return o}}class XP extends GP{constructor(t){super(t)}moveToXValue(t){this.isInitialEntry&&this.handleInitialEntry();const n=this.points;if(!n||!n.length)return!1;const o=this.navigationService.moveToXValueInPoints(n,t,this.moveToIndex.bind(this));return o&&this.notifyStateUpdate(),o}audio(){const t=this.lineValues[this.row],n=this.col,o=s=>t[Math.max(0,Math.min(s,t.length-1))],a=n>0?o(n-1):o(n),l=o(n),i=n<t.length-1?o(n+1):o(n);return{min:this.min[this.row],max:this.max[this.row],size:t.length,index:n,value:[a,l,i],isContinuous:!0,...this.getAudioGroupIndex()}}}class tle extends XP{constructor(t){super(t)}mapToSvgElements(t){var a;if(!t||t.length!==this.lineValues.length)return null;const n=[];let o=!0;for(let l=0;l<t.length;l++){const i=$t.selectElement(t[l],!1);if(!i){n.push([]);continue}const s=(a=this.points)==null?void 0:a[l],c=[];for(const u of s)typeof u.svg_x=="number"&&typeof u.svg_y=="number"&&c.push($t.createCircleElement(u.svg_x,u.svg_y,i));c.length>0&&(o=!1),n.push(c)}return o?null:n}}function nle(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function rle(e){return Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&nle(e.data[0][0])?new tle(e):new XP(e)}class ile{static create(t){switch(t.type){case U2.BAR:return new $7e(t);case U2.BOX:return new U7e(t);case U2.CANDLESTICK:return new Z7e(t);case U2.HEATMAP:return new X7e(t);case U2.HISTOGRAM:return new W7e(t);case U2.LINE:return new GP(t);case U2.SCATTER:return new Y7e(t);case U2.SMOOTH:return rle(t);case U2.DODGED:case U2.NORMALIZED:case U2.STACKED:return new ele(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const ale="MAIDR Plot",ole="unavailable",lle="unavailable";class sle extends LH{constructor(n){super();ie(this,"id");ie(this,"title");ie(this,"subtitle");ie(this,"caption");ie(this,"subplots");ie(this,"size");this.id=n.id,this.title=n.title??ale,this.subtitle=n.subtitle??ole,this.caption=n.caption??lle;const o=n.subplots;this.subplots=o.map(a=>a.map(l=>new ule(l))),this.size=this.subplots.reduce((a,l)=>a+l.length,0)}dispose(){this.subplots.forEach(n=>n.forEach(o=>o.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((a,l)=>a+l.length,0),o=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:o.getStateWithFigurePosition(this.row,this.col),traceTypes:o.traceTypes,highlight:this.highlight()}}highlight(){var o;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}};try{const a=((o=this.subplots[0])==null?void 0:o.length)||1,l=this.row*a+this.col+1,i=`g[id="axes_${l}"]`,s=document.querySelector(i);if(s)return{empty:!1,elements:s};const c=document.querySelectorAll('g[id^="axes_"]');if(c.length>0&&l-1<c.length)return{empty:!1,elements:c[l-1]}}catch{return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}isMovable(n){switch(n){case"UPWARD":return this.row<this.subplots.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.subplots[this.row].length-1;case"BACKWARD":return this.col>0;default:return!1}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}}class ule extends LH{constructor(n){super();ie(this,"traces");ie(this,"traceTypes");ie(this,"size");this.isInitialEntry=!1;const o=n.layers;this.size=o.length,this.traces=o.map(a=>[ile.create(a)]),this.traceTypes=this.traces.flat().map(a=>{const l=a.state;return l.empty?ve.EMPTY:l.traceType})}getRow(){return this.row}getSize(){return this.size}dispose(){this.traces.forEach(n=>n.forEach(o=>o.dispose())),this.traces.length=0,super.dispose()}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}highlight(){return{empty:!0,type:"trace",audio:{size:this.values[this.row].length,index:this.col}}}moveOnce(n){if(this.isInitialEntry){this.handleInitialEntry(),this.notifyStateUpdate();return}if(!this.isMovable(n)){this.notifyOutOfBounds();return}switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}this.notifyStateUpdate()}get state(){return this.isOutOfBounds?{empty:!0,type:"subplot"}:{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight()}}getStateWithFigurePosition(n,o){return this.state}}const cn={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},ju=class ju{constructor(){ie(this,"basePalette");ie(this,"extendedPalette");this.basePalette=[{index:cn.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:cn.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:cn.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:cn.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:cn.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:cn.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:cn.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:cn.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:cn.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:cn.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:cn.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 o=this.generateExtendedEntry(t);return this.extendedPalette.set(t,o),o}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return cn.SINE_BASIC;case"Bear":return cn.SAWTOOTH_SOFT;case"Neutral":return cn.TRIANGLE_BASIC;default:return cn.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,o)=>{this.extendedPalette.set(this.basePalette.length+o,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,o=this.basePalette[n],a=Math.floor((t-this.basePalette.length)/this.basePalette.length),l=this.generateHarmonics(a),i=this.generateTimbreModulation(a,o.timbreModulation);return{index:t,waveType:o.waveType,harmonicMix:{fundamental:1,harmonics:l},timbreModulation:i}}generateHarmonics(t){const n=[],o=ju.MIN_HARMONICS+t%ju.HARMONIC_VARIATION;for(let a=0;a<o;a++){const l=1+(a+1)*(.5+t*.3%1),i=.4/(a+1)*(1-t*.1%.3);n.push({frequency:l,amplitude:i})}return n}generateTimbreModulation(t,n){const o=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*o)),decay:Math.max(.05,Math.min(.3,n.decay*o)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*o))}}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.`)})}};ie(ju,"MIN_HARMONICS",2),ie(ju,"HARMONIC_VARIATION",3);let EH=ju;const cle=100,Tle=440,Qle=880,SH=.3,MH=cn.SINE_BASIC;class fle{constructor(t,n,o){ie(this,"notification");ie(this,"audioPalette");ie(this,"settings");ie(this,"isCombinedAudio");ie(this,"mode");ie(this,"activeAudioIds");ie(this,"audioContext");ie(this,"compressor");ie(this,"currentVolume");ie(this,"currentMinFrequency");ie(this,"currentMaxFrequency");this.notification=t,this.audioPalette=new EH,this.settings=o,this.isCombinedAudio=!1,this.mode="on",this.updateMode(n),this.activeAudioIds=new Map,this.audioContext=new AudioContext,this.compressor=this.initCompressor();const a=this.settings.loadSettings();this.currentVolume=a.general.volume/100,this.currentMinFrequency=a.general.minFrequency,this.currentMaxFrequency=a.general.maxFrequency,this.settings.addObserver(this)}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close()),this.settings.removeObserver(this)}update(t){"general"in t?this.onSettingsChange(t):this.onStateChange(t)}onSettingsChange(t){this.currentVolume=t.general.volume/100,this.currentMinFrequency=t.general.minFrequency,this.currentMaxFrequency=t.general.maxFrequency}onStateChange(t){if(this.mode==="off")return;if(this.updateMode(t),t.type==="figure"){if(t.empty){this.playEmptyTone(1,0);return}return}let n;if(t.type==="subplot"){if(t.empty)return;n=t.trace}else n=t;this.handleTraceState(n)}handleTraceState(t){if(this.mode==="off"||t.type!=="trace")return;if(t.empty){this.stopAll(),this.playEmptyTone(t.audio.size,t.audio.index);return}if(t.traceType==="line"&&!t.empty&&Array.isArray(t.intersections)&&t.intersections.length>1){this.stopAll(),this.playSimultaneousTones(t.intersections);return}const n=t.audio;let o=n.groupIndex;n.trend&&o===void 0&&(o=this.audioPalette.getCandlestickGroupIndex(n.trend));const l=o!==void 0?this.audioPalette.getPaletteEntry(o):void 0;if(n.isContinuous)this.playSmooth(n.value,n.min,n.max,n.size,Array.isArray(n.index)?n.index[0]:n.index,l);else if(Array.isArray(n.value)){const i=n.value;if(i.length===0){this.playZeroTone();return}let s=0;const c=this.mode==="on"?50:0,u=new Array,Q=()=>{if(s<i.length){const f=Array.isArray(n.index)?n.index[s]:n.index;this.playTone(n.min,n.max,i[s++],n.size,f,l),u.push(setTimeout(Q,c))}else this.stop(u)};Q()}else{const i=n.value;if(i===0)this.playZeroTone();else{const s=Array.isArray(n.index)?n.index[0]:n.index;this.playTone(n.min,n.max,i,n.size,s,l)}}}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,o,a,l,i){const s={min:t,max:n},c=this.getFrequencyRange(),u=this.interpolate(o,s,c),Q={min:0,max:a},f={min:-1,max:1},h=this.clamp(this.interpolate(l,Q,f),-1,1);return this.playOscillator(u,h,i)}createOscillators(t,n){const o=[],a=this.audioContext.createOscillator();if(a.type=t.waveType,a.frequency.value=n,o.push(a),t.harmonicMix)for(const l of t.harmonicMix.harmonics){const i=this.audioContext.createOscillator();i.type=t.waveType,i.frequency.value=l.frequency*n,o.push(i)}return o}createGainNodes(t,n,o,a){const l=[],i=this.audioContext.currentTime,s=this.getVolume();for(let c=0;c<t.length;c++){const u=this.audioContext.createGain();let Q=s;if(c===0)n.harmonicMix&&(Q*=n.harmonicMix.fundamental);else{const h=n.harmonicMix.harmonics[c-1];Q*=h.amplitude}const f=this.createAdsrEnvelope(u,n,Q,i,a);f!==null&&u.gain.setValueCurveAtTime(f,i,a),l.push(u)}return l}playOscillator(t,n=0,o){const a=SH,l=this.getVolume();o||(o=this.audioPalette.getPaletteEntry(0));const i=this.createOscillators(o,t),s=this.createGainNodes(i,o,l,a),c=this.audioContext.createStereoPanner();c.pan.value=n;const u=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let h=0;h<i.length;h++)i[h].connect(s[h]),s[h].connect(c);c.connect(u),u.connect(this.compressor),i.forEach(h=>h.start());const Q=h=>{u.disconnect(this.compressor),c.disconnect(u);for(let p=0;p<i.length;p++)s[p].disconnect(c),i[p].stop(),i[p].disconnect(s[p]);this.activeAudioIds.delete(h)},f=setTimeout(()=>Q(f),a*1e3*2);return this.activeAudioIds.set(f,i),f}createAdsrEnvelope(t,n,o,a,l){if(n!=null&&n.timbreModulation){const{attack:i,decay:s,sustain:c,release:u}=n.timbreModulation,Q=l*i,f=l*s,h=l*u,p=l-Q-f-h;return t.gain.setValueAtTime(1e-4*o,a),t.gain.linearRampToValueAtTime(o,a+Q),t.gain.linearRampToValueAtTime(c*o,a+Q+f),p>0&&t.gain.setValueAtTime(c*o,a+Q+f+p),t.gain.linearRampToValueAtTime(1e-4*o,a+l),null}else return[.5*o,o,.5*o,.5*o,.5*o,.1*o,1e-4*o]}playSmooth(t,n,o,a,l,i){const s=this.audioContext,c=s.currentTime,u=SH,Q=this.getFrequencyRange(),f=this.getVolume(),h=(i==null?void 0:i.waveType)||"sine",p=t.map(O=>this.interpolate(O,{min:n,max:o},Q));p.length<2&&p.push(p[0]);const g=this.clamp(this.interpolate(l,{min:0,max:a-1},{min:-1,max:1}),-1,1),v=s.createOscillator();v.type=h,v.frequency.setValueCurveAtTime(p,c,u);const b=s.createGain(),x=this.createAdsrEnvelope(b,i,f,c,u);x!==null&&b.gain.setValueCurveAtTime(x,c,u);const E=s.createStereoPanner();E.pan.value=g,v.connect(b),b.connect(E),E.connect(this.compressor),v.start(c),v.stop(c+u);const _=setTimeout(()=>{v.disconnect(),b.disconnect(),E.disconnect(),this.activeAudioIds.delete(_)},u*1e3*2);this.activeAudioIds.set(_,[v])}playEmptyTone(t,n){const o=this.audioContext,a=o.currentTime,l=.2,i=this.getVolume(),s=[500,1e3,1500,2100,2700],c=[1,.6,.4,.2,.1],u=o.createGain();u.gain.setValueAtTime(.3*i,a),u.gain.exponentialRampToValueAtTime(.01*i,a+l),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 x=o.createOscillator(),E=o.createGain(),_=this.audioContext.createStereoPanner(),O=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});x.frequency.value=s[b],x.type="sine",E.gain.setValueAtTime(c[b]*i,a),E.gain.exponentialRampToValueAtTime(.001*i,a+l),_.pan.value=h,x.connect(E),E.connect(_),_.connect(O),O.connect(u),x.start(a),x.stop(a+l),p.push(x)}const g=b=>{u.disconnect(),p.forEach(x=>{x.disconnect()}),this.activeAudioIds.delete(b)},v=setTimeout(()=>g(v),l*1e3*2);return this.activeAudioIds.set(v,p),v}playZeroTone(){return this.playOscillator(cle,0,{index:MH,waveType:"triangle"})}playWaitingTone(){return setInterval(()=>this.playOscillator(Tle,0,{index:MH,waveType:"sine"}),1e3)}playCompleteTone(){return this.playOscillator(Qle,0,{index:MH,waveType:"sine"})}interpolate(t,n,o){return n.min===0&&n.max===0?0:(t-n.min)/(n.max-n.min)*(o.max-o.min)+o.min}clamp(t,n,o){return Math.max(n,Math.min(t,o))}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(o=>{const a=this.activeAudioIds.get(o);if(!a){clearInterval(o);return}a.forEach(l=>{l==null||l.disconnect(),l==null||l.stop()}),clearTimeout(o),this.activeAudioIds.delete(o)})}stopAll(){this.activeAudioIds.entries().forEach(([t,n])=>{clearTimeout(t),n.forEach(o=>{o.disconnect(),o.stop()})}),this.activeAudioIds.clear()}playSimultaneousTones(t){const n=this.getVolume(),o=SH,a=this.audioContext,l=a.currentTime,i=this.getFrequencyRange(),s=Array.isArray(t[0].value)?t[0].value[1]??t[0].value[0]:t[0].value,c=t[0].min,u=t[0].max,Q=this.interpolate(s,{min:c,max:u},i);t.forEach((f,h)=>{const p=Q,v=this.audioPalette.getPaletteEntry(h).waveType,b=a.createOscillator();b.type=v,b.frequency.value=p;const x=a.createGain();x.gain.setValueAtTime(n,l),x.gain.exponentialRampToValueAtTime(.01*n,l+o),b.connect(x),x.connect(this.compressor),b.start(l),b.stop(l+o);const E=setTimeout(()=>{b.disconnect(),x.disconnect()},o*1e3*2);this.activeAudioIds.set(E,[b])})}}const dle=250,hle=50,ple=500,mle=20;class yle{constructor(t,n,o){ie(this,"context");ie(this,"notification");ie(this,"settings");ie(this,"autoplayId");ie(this,"currentDirection");ie(this,"userSpeed");ie(this,"defaultSpeed");ie(this,"minSpeed");ie(this,"maxSpeed");ie(this,"autoplayRate");ie(this,"interval");ie(this,"currentDuration");ie(this,"onChangeEmitter");ie(this,"onChange");this.notification=n,this.context=t,this.settings=o,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=dle,this.minSpeed=hle,this.maxSpeed=ple,this.autoplayRate=this.defaultSpeed,this.interval=mle,this.currentDuration=this.settings.loadSettings().general.autoplayDuration,this.onChangeEmitter=new qs,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 o=Math.ceil(this.currentDuration/n.autoplay[t]);return this.defaultSpeed=o,this.minSpeed=Math.min(this.minSpeed,o),o}return this.defaultSpeed}}const WP=32;class Qd{encode(t){const n=new Array,o=new Array,a=new Array;for(let l=0;l<t.values.length;l++){o.push(new Array);const i=(t.max[l]-t.min[l])/4,s=t.min[l]+i,c=s+i,u=c+i;for(let Q=0;Q<t.values[l].length;Q++)t.values[l][Q]===0?n.push(" "):t.values[l][Q]<=s||t.values[l][Q]<=c?n.push("⠤"):t.values[l][Q]<=u?n.push("⠒"):n.push("⠉"),o[l].push(a.length),a.push({row:l,col:Q});n.push(ve.NEW_LINE),o[l].push(a.length),a.push({row:l,col:t.values[l].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}}class gle{constructor(){ie(this,"GLOBAL_MIN","globalMin");ie(this,"GLOBAL_MAX","globalMax");ie(this,"BLANK","blank");ie(this,"LOWER_OUTLIER","lowerOutlier");ie(this,"UPPER_OUTLIER","upperOutlier");ie(this,"MIN","min");ie(this,"MAX","max");ie(this,"Q1","q1");ie(this,"Q2","q2");ie(this,"Q3","q3")}encode(t,n=WP){const o=new Array,a=new Array,l=new Array;for(let i=0;i<t.values.length;i++){const s=t.values[i],c=[{type:this.GLOBAL_MIN,value:t.min},...s.lowerOutliers.map(V=>({type:this.LOWER_OUTLIER,value:V})),{type:this.MIN,value:s.min},{type:this.Q1,value:s.q1},{type:this.Q2,value:s.q2},{type:this.Q3,value:s.q3},{type:this.MAX,value:s.max},...s.upperOutliers.map(V=>({type:this.UPPER_OUTLIER,value:V})),{type:this.GLOBAL_MAX,value:t.max}],u=new Array;let Q=!0;for(let V=0;V<c.length-1;V++){const R=c[V],N=c[V+1],B=Math.abs(Q?N.value-R.value:R.value-c[V-1].value);R.type===this.LOWER_OUTLIER||R.type===this.UPPER_OUTLIER?(u.push({type:R.type,length:0,numChars:1}),u.push({type:this.BLANK,length:B,numChars:0})):R.type===this.Q2?(Q=!1,u.push({type:this.Q2,length:0,numChars:2})):R.type===this.GLOBAL_MIN||R.type===this.GLOBAL_MAX?u.push({type:this.BLANK,length:B,numChars:0}):u.push({type:R.type,length:B,numChars:1})}let f=u.reduce((V,R)=>V+(R.numChars>0?R.numChars:0),0),[h,p,g,v]=[-1,-1,-1,-1];for(let V=0;V<u.length;V++)u[V].type===this.MIN&&u[V].length>0&&(h=V),u[V].type===this.MAX&&u[V].length>0&&(p=V),u[V].type===this.Q1&&(g=V),u[V].type===this.Q3&&(v=V);h!==-1&&p!==-1&&u[h].length!==u[p].length&&(u[h].length>u[p].length?(u[h].numChars++,f++):(u[p].numChars++,f++)),g!==-1&&v!==-1&&u[g].length!==u[v].length&&(u[g].length>u[v].length?(u[g].numChars++,f++):(u[v].numChars++,f++));const b=Math.max(0,n-f),x=u.reduce((V,R)=>V+(R.type!==this.Q2&&R.length>0?R.length:0),0);for(const V of u)if(V.type!==this.Q2&&V.length>0){const R=Math.round(V.length/x*b);V.numChars+=R}const E=u.reduce((V,R)=>V+R.numChars,0);let _=n-E,O=0;for(;_!==0;){const V=u[O%u.length];V.type!==this.BLANK&&V.type!==this.Q2&&V.length>0&&(V.numChars+=_>0?1:-1,_+=_>0?-1:1),O++}let M=-1;const A=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];l.push(Array.from({length:A.length}).fill(-1));for(const V of u){V.type!==this.BLANK&&V.type!==this.GLOBAL_MIN&&V.type!==this.GLOBAL_MAX&&(M=A.indexOf(V.type),l[i][M]=o.length);for(let R=0;R<V.numChars;R++){let N="⠀";V.type===this.MIN||V.type===this.MAX?N="⠒":V.type===this.Q1||V.type===this.Q3?N="⠿":V.type===this.Q2?N=R===0?"⠸":"⠇":V.type===this.LOWER_OUTLIER||V.type===this.UPPER_OUTLIER?N="⠂":V.type===this.BLANK&&(N="⠀"),o.push(N),a.push({row:i,col:M})}}for(let V=0;V<3;V++)if(l[i][V]===-1){for(let R=V+1;R<=3;R++)if(l[i][R]!==-1){l[i][V]=l[i][R];break}}for(let V=6;V>3;V--)if(l[i][V]===-1){for(let R=V-1;R>=3;R--)if(l[i][R]!==-1){l[i][V]=l[i][R];break}}o.push(ve.NEW_LINE),a.push({row:i,col:M})}return{value:o.join(ve.EMPTY),cellToIndex:l,indexToCell:a}}}class vle{encode(t){const n=new Array,o=new Array,a=new Array,l=(t.max-t.min)/3,i=t.min+l,s=i+l;for(let c=0;c<t.values.length;c++){o.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("⠉"),o[c].push(a.length),a.push({row:c,col:u});n.push(ve.NEW_LINE),o[c].push(a.length),a.push({row:c,col:t.values[c].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}}class YP{encode(t){const n=new Array,o=new Array,a=new Array;for(let l=0;l<t.values.length;l++){o.push(new Array);const{low:i,medium:s,mediumHigh:c,high:u}=this.getThresholds(l,t);for(let Q=0;Q<t.values[l].length;Q++){const f=t.values[l][Q],h=Q>0?t.values[l][Q-1]:null,p=this.getBrailleChar(f,h,i,s,u,c);n.push(p),o[l].push(a.length),a.push({row:l,col:Q})}n.push(ve.NEW_LINE),o[l].push(a.length),a.push({row:l,col:t.values[l].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}getBrailleChar(t,n,o,a,l,i){return i===void 0&&(i=l),t<=o&&n!==null&&n>o?n<=a?"⢄":n<=i?"⢆":"⢇":t<=o?"⣀":n!==null&&n<=o?t<=a?"⡠":t<=i?"⡰":"⡸":t<=a&&n!==null&&n>a?n<=i?"⠢":"⠣":t<=a?"⠤":n!==null&&n<=a?t<=i?"⠔":"⠜":t<=i&&n!==null&&n>i?"⠑":t<=i?"⠒":n!==null&&n<=i?"⠊":t<=l?"⠉":""}getBraille6Char(t,n,o,a,l){const i=f=>f<=o?"low":f<=a?"medium":(f<=l,"high"),s=i(t),c=n!==null?i(n):null,u={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},Q=`${s},${c}`;return u[Q]||""}addDot8(t){if(!t||t.length===0)return"⢀";const a=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+a)}}class xle extends YP{getThresholds(t,n){const o=Array.isArray(n.min)?n.min[t]:n.min,a=Array.isArray(n.max)?n.max[t]:n.max,l=(a-o)/3,i=o+l,s=i+l;return{low:i,medium:s,high:a}}encode(t){var l;const n=new Array,o=new Array,a=new Array;for(let i=0;i<t.values.length;i++){o.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);((l=t.custom)==null?void 0:l[Q])==="Bear"&&(p=this.addDot8(p)),n.push(p),o[i].push(a.length),a.push({row:i,col:Q})}n.push(ve.NEW_LINE),o[i].push(a.length),a.push({row:i,col:t.values[i].length})}return{value:n.join(ve.EMPTY),cellToIndex:o,indexToCell:a}}}class Lle extends YP{getThresholds(t,n){const o=(n.max[t]-n.min[t])/4,a=n.min[t]+o,l=a+o,i=l+o,s=n.max[t];return{low:a,medium:l,mediumHigh:i,high:s}}}class ble{constructor(t,n,o){ie(this,"context");ie(this,"notification");ie(this,"display");ie(this,"enabled");ie(this,"cacheId");ie(this,"cache");ie(this,"encoders");ie(this,"onChangeEmitter");ie(this,"onChange");this.context=t,this.notification=n,this.display=o,this.enabled=!1,this.cacheId=ve.EMPTY,this.cache=null,this.encoders=new Map([[U2.BAR,new Qd],[U2.BOX,new gle],[U2.CANDLESTICK,new xle],[U2.DODGED,new Qd],[U2.HEATMAP,new vle],[U2.HISTOGRAM,new Qd],[U2.LINE,new Lle],[U2.NORMALIZED,new Qd],[U2.STACKED,new Qd]]),this.onChangeEmitter=new qs,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 o=n.braille;if(this.cacheId!==o.id||this.cache===null){const a=this.encoders.get(n.traceType);this.cache=a.encode(o,WP),this.cacheId=o.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[o.row][o.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:o}=this.cache.indexToCell[t];this.context.moveToIndex(n,o)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const o=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(o);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(Yt.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var KP=(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))(KP||{});class JP{constructor(){}static async post(t,n,o){const a={...this.DEFAULT_HEADERS,...o};return this.request(t,"POST",a,n)}static async request(t,n,o,a){try{const l=await fetch(t,{method:n,headers:o,body:a});return l.ok?{success:!0,data:await l.json()}:{success:!1,error:{statusCode:l.status,message:`API Error: ${l.status} - ${l.statusText}`}}}catch(l){return console.error(`Error in API ${n} request to ${t}:`,l),{success:!1,error:{statusCode:KP.SERVER_ERROR,message:l instanceof Error?l.message:"Unknown error occurred"}}}}}ie(JP,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const Hle=`You are an accessibility assistant specializing in describing statistical visualizations to blind users. Your role is to:
|
|
642
642
|
1. Provide simple, straightforward descriptions of charts and graphs
|
|
643
643
|
2. Focus on basic patterns and key points
|
|
644
644
|
3. Use simple, everyday language with minimal statistical terms
|