maidr 3.48.0 → 3.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maidr.js +2 -2
- package/dist/maidr.js.map +1 -1
- package/package.json +1 -1
package/dist/maidr.js
CHANGED
|
@@ -299,12 +299,12 @@ Learn more: https://react.dev/warnings/version-mismatch`))})(),typeof Map=="func
|
|
|
299
299
|
You might need to use a local HTTP server (instead of file://): https://react.dev/link/react-devtools-faq`:""),"font-weight:bold")}uv.createRoot=function(r,a){if(!N(r))throw Error("Target container is not a DOM element.");_5(r);var u=!1,g="",S=w1,E=T4,M=A4;return a!=null&&(a.hydrate?console.warn("hydrate through createRoot is deprecated. Use ReactDOMClient.hydrateRoot(container, <App />) instead."):typeof a=="object"&&a!==null&&a.$$typeof===ol&&console.error(`You passed a JSX element to createRoot. You probably meant to call root.render instead. Example usage:
|
|
300
300
|
|
|
301
301
|
let root = createRoot(domContainer);
|
|
302
|
-
root.render(<App />);`),a.unstable_strictMode===!0&&(u=!0),a.identifierPrefix!==void 0&&(g=a.identifierPrefix),a.onUncaughtError!==void 0&&(S=a.onUncaughtError),a.onCaughtError!==void 0&&(E=a.onCaughtError),a.onRecoverableError!==void 0&&(M=a.onRecoverableError)),a=vE(r,1,!1,null,null,u,g,null,S,E,M,wE),r[cl]=a.current,Fp(r),new js(a)},uv.hydrateRoot=function(r,a,u){if(!N(r))throw Error("Target container is not a DOM element.");_5(r),a===void 0&&console.error("Must provide initial children as second argument to hydrateRoot. Example usage: hydrateRoot(domContainer, <App />)");var g=!1,S="",E=w1,M=T4,D=A4,$=null;return u!=null&&(u.unstable_strictMode===!0&&(g=!0),u.identifierPrefix!==void 0&&(S=u.identifierPrefix),u.onUncaughtError!==void 0&&(E=u.onUncaughtError),u.onCaughtError!==void 0&&(M=u.onCaughtError),u.onRecoverableError!==void 0&&(D=u.onRecoverableError),u.formState!==void 0&&($=u.formState)),a=vE(r,1,!0,a,u??null,g,S,$,E,M,D,wE),a.context=T5(null),u=a.current,g=Qi(u),g=Vt(g),S=xs(g),S.callback=null,Aa(u,S,g),Cl(g,"hydrateRoot()",null),u=g,a.current.lanes=u,mt(a,u),_a(a),r[cl]=a.current,Fp(r),new om(a)},uv.version="19.2.4",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})(),uv}var gC;function hB(){if(gC)return Qc.exports;gC=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(),Qc.exports=fB()):Qc.exports=dB(),Qc.exports}var pB=hB(),Rn=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(Rn||{}),or=(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))(or||{});function mB(e){return e!==null&&typeof e=="object"&&"x"in e}function gB(e){return typeof e=="string"||typeof e=="number"}function yB(e){return e!==null&&typeof e=="object"&&"x"in e}class D7{stepTraceInSubplot(t,n){const i=t.activeTrace;if(!i)return null;const o=i.getCurrentXValue();t.moveOnce(n);const s=t.activeTrace;return s
|
|
302
|
+
root.render(<App />);`),a.unstable_strictMode===!0&&(u=!0),a.identifierPrefix!==void 0&&(g=a.identifierPrefix),a.onUncaughtError!==void 0&&(S=a.onUncaughtError),a.onCaughtError!==void 0&&(E=a.onCaughtError),a.onRecoverableError!==void 0&&(M=a.onRecoverableError)),a=vE(r,1,!1,null,null,u,g,null,S,E,M,wE),r[cl]=a.current,Fp(r),new js(a)},uv.hydrateRoot=function(r,a,u){if(!N(r))throw Error("Target container is not a DOM element.");_5(r),a===void 0&&console.error("Must provide initial children as second argument to hydrateRoot. Example usage: hydrateRoot(domContainer, <App />)");var g=!1,S="",E=w1,M=T4,D=A4,$=null;return u!=null&&(u.unstable_strictMode===!0&&(g=!0),u.identifierPrefix!==void 0&&(S=u.identifierPrefix),u.onUncaughtError!==void 0&&(E=u.onUncaughtError),u.onCaughtError!==void 0&&(M=u.onCaughtError),u.onRecoverableError!==void 0&&(D=u.onRecoverableError),u.formState!==void 0&&($=u.formState)),a=vE(r,1,!0,a,u??null,g,S,$,E,M,D,wE),a.context=T5(null),u=a.current,g=Qi(u),g=Vt(g),S=xs(g),S.callback=null,Aa(u,S,g),Cl(g,"hydrateRoot()",null),u=g,a.current.lanes=u,mt(a,u),_a(a),r[cl]=a.current,Fp(r),new om(a)},uv.version="19.2.4",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})(),uv}var gC;function hB(){if(gC)return Qc.exports;gC=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(),Qc.exports=fB()):Qc.exports=dB(),Qc.exports}var pB=hB(),Rn=(e=>(e.VERTICAL="vert",e.HORIZONTAL="horz",e))(Rn||{}),or=(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))(or||{});function mB(e){return e!==null&&typeof e=="object"&&"x"in e}function gB(e){return typeof e=="string"||typeof e=="number"}function yB(e){return e!==null&&typeof e=="object"&&"x"in e}class D7{stepTraceInSubplot(t,n){const i=t.activeTrace;if(!i)return null;const o=i.getCurrentXValue();t.moveOnce(n);const s=t.activeTrace;if(!s)return null;if(s.getId()===i.getId())return s.notifyOutOfBounds(),t.notifyOutOfBounds(),s;let f=!1;return typeof s.onSwitchFrom=="function"&&(f=s.onSwitchFrom(i)),f||s.moveToXValue(o),this.notifyLayerSwitch(t,s),s}computeIndexAndSegment(t,n,i,o){return i===Rn.HORIZONTAL?{pointIndex:t,segmentType:o[n]}:{pointIndex:n,segmentType:o[t]}}computeVisualCoordinates(t,n,i){return i===Rn.HORIZONTAL?{row:t,col:n}:{row:n,col:t}}extractXValueFromPoints(t,n,i){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const o=t[0][i];return this.extractXFromPoint(o)}if(Array.isArray(t)&&Array.isArray(t[n])&&t[n][i]){const o=t[n][i];return this.extractXFromPoint(o)}return null}extractXValueFromValues(t,n,i){if(this.isValidPosition(t,n,i)){const o=t[n][i];return this.extractXFromValue(o)}return null}moveToXValueInPoints(t,n,i){if(Array.isArray(t)&&t.length===1&&Array.isArray(t[0])){const h=this.findPointIndexByX(t[0],n);if(h!==-1)return i(0,h),!0;{const y=this.findNearestPointIndexByX(t[0],n);if(y!==-1){const b=Gu(t[0][y]);if(typeof n=="number"&&typeof b=="number")return i(0,y),!0;if(typeof n=="string"&&typeof b=="string")return i(0,y),!0}}}let o=-1,s=-1,f=Number.POSITIVE_INFINITY,d=null;if(Array.isArray(t))for(let h=0;h<t.length;h++){const y=t[h];if(Array.isArray(y)){const b=this.findPointIndexByX(y,n);if(b!==-1)return i(h,b),!0;const x=this.findNearestPointIndexByX(y,n);if(x!==-1){const T=Gu(y[x]);let w=Number.POSITIVE_INFINITY;typeof n=="number"&&typeof T=="number"?(w=Math.abs(T-n),w<f&&(f=w,o=h,s=x,d="numeric")):typeof n=="string"&&typeof T=="string"?o===-1&&(o=h,s=x,d="categorical"):o===-1&&(o=h,s=x,d="generic")}}}if(o!==-1&&s!==-1){const h=t[o];if(Array.isArray(h)&&Gu(h[s]),d!==null)return i(o,s),!0}return!1}moveToXValueInValues(t,n,i){let o=-1,s=-1,f=Number.POSITIVE_INFINITY,d=null;for(let h=0;h<t.length;h++)for(let y=0;y<t[h].length;y++){const b=t[h][y],x=this.extractXFromValue(b);if(x===n)return i(h,y),!0;if(typeof n=="number"&&typeof x=="number"){const T=Math.abs(x-n);T<f&&(f=T,o=h,s=y,d="numeric")}else typeof n=="string"&&typeof x=="string"?o===-1&&(o=h,s=y,d="categorical"):o===-1&&(o=h,s=y,d="generic")}return o!==-1&&s!==-1?(this.extractXFromValue(t[o][s]),i(o,s),!0):!1}extractXFromPoint(t){return yB(t)?t.x:null}extractXFromValue(t){return mB(t)?t.x:gB(t)?t:null}findPointIndexByX(t,n){return t.findIndex(i=>i.x===n)}isValidPosition(t,n,i){return n>=0&&n<t.length&&i>=0&&i<t[n].length}findNearestPointIndexByX(t,n){if(typeof n=="number"){let i=-1,o=Number.POSITIVE_INFINITY;for(let s=0;s<t.length;s++){const f=Gu(t[s]);if(typeof f=="number"){const d=Math.abs(f-n);d<o&&(o=d,i=s)}else if(typeof f=="string"){const d=Number(f);if(!Number.isNaN(d)){const h=Math.abs(d-n);h<o&&(o=h,i=s)}}}if(i!==-1)return Gu(t[i]),i}else if(typeof n=="string"){for(let o=0;o<t.length;o++)if(Gu(t[o])===n)return o;const i=Number(n);if(!Number.isNaN(i)){let o=-1,s=Number.POSITIVE_INFINITY;for(let f=0;f<t.length;f++){const d=Gu(t[f]);if(typeof d=="number"){const h=Math.abs(d-i);h<s&&(s=h,o=f)}else if(typeof d=="string"){const h=Number(d);if(!Number.isNaN(h)){const y=Math.abs(h-i);y<s&&(s=y,o=f)}}}if(o!==-1)return Gu(t[o]),o}for(let o=0;o<t.length;o++)if(typeof Gu(t[o])=="string")return o}return t.length>0?(Gu(t[0]),0):-1}dispose(){}notifyLayerSwitch(t,n){if(n.state.empty)n.notifyStateUpdate();else{const i=t.getRow()+1,o=t.getSize(),s={...n.state,isLayerSwitch:!0,index:i,size:o};n.notifyObserversWithState(s)}}}function vB(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function bB(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function SB(e){return e&&typeof e=="object"&&"xMin"in e&&"xMax"in e}function xB(e){return e&&typeof e=="object"&&"x"in e&&"y"in e}function EB(e){return e&&typeof e=="object"&&typeof e.x=="number"&&typeof e.y=="number"}function wB(e){return e&&typeof e=="object"&&"value"in e}function Gu(e){return e?vB(e)||bB(e)||xB(e)||EB(e)||SB(e)?e.x:wB(e)?e.value:null:null}var Bo=(e=>(e.CLICK="click",e.DOM_LOADED="DOMContentLoaded",e.FOCUS_IN="focusin",e.FOCUS_OUT="focusout",e.MOUSE_ENTER="mouseenter",e.MOUSE_LEAVE="mouseleave",e.MOUSE_MOVE="mousemove",e.SELECTION_CHANGE="selectionchange",e.VISIBILITY_CHANGE="visibilitychange",e))(Bo||{}),fn=(e=>(e.BRAILLE="BRAILLE",e.CHAT="CHAT",e.COMMAND_PALETTE="COMMAND_PALETTE",e.GO_TO_EXTREMA="GO_TO_EXTREMA",e.HELP="HELP",e.FIGURE_LABEL="FIGURE_LABEL",e.SUBPLOT="SUBPLOT",e.TRACE="TRACE",e.TRACE_LABEL="TRACE_LABEL",e.REVIEW="REVIEW",e.SETTINGS="SETTINGS",e))(fn||{});class Md{constructor(){H(this,"listeners");H(this,"event",t=>(this.listeners.add(t),{dispose:()=>this.listeners.delete(t)}));this.listeners=new Set}dispose(){this.listeners.clear()}fire(t){for(const n of this.listeners)n(t)}}class ge{constructor(){}}H(ge,"ARTICLE","article"),H(ge,"DIV","div"),H(ge,"FIGURE","figure"),H(ge,"IMAGE","img"),H(ge,"INPUT","input"),H(ge,"STYLE","style"),H(ge,"TEXT_AREA","textarea"),H(ge,"BRAILLE_TEXT_AREA","maidr-braille-textarea"),H(ge,"MAIDR_ARTICLE","maidr-article"),H(ge,"MAIDR_FIGURE","maidr-figure"),H(ge,"MAIDR_HIGHLIGHT","maidr-highlight"),H(ge,"REACT_CONTAINER","maidr-react-container"),H(ge,"REVIEW_INPUT","maidr-review-input"),H(ge,"TEXT_CONTAINER","maidr-text-container"),H(ge,"MAIDR_INSTRUCTION","maidr-instruction"),H(ge,"ROTOR_AREA","maidr-rotor-area"),H(ge,"SR_ONLY_CLASS","maidr-sr-only"),H(ge,"ARIA_LABEL","aria-label"),H(ge,"CIRCLE_X","cx"),H(ge,"CIRCLE_Y","cy"),H(ge,"D","d"),H(ge,"FILL","fill"),H(ge,"MARGIN","margin"),H(ge,"POINTS","points"),H(ge,"RADIUS","r"),H(ge,"ROLE","role"),H(ge,"STROKE","stroke"),H(ge,"STROKE_WIDTH","stroke-width"),H(ge,"TITLE","title"),H(ge,"VISIBILITY","visibility"),H(ge,"X1","x1"),H(ge,"X2","x2"),H(ge,"Y1","y1"),H(ge,"Y2","y2"),H(ge,"MAIDR_SUBPLOT","subplot"),H(ge,"MAIDR","maidr"),H(ge,"MAIDR_JSON_SELECTOR",'[maidr^="{"]'),H(ge,"AFTER_END","afterend"),H(ge,"APPLICATION","application"),H(ge,"ARE"," are "),H(ge,"CIRCLE","circle"),H(ge,"CLOSE_BRACKET","]"),H(ge,"COMMA",","),H(ge,"COMMA_SPACE",", "),H(ge,"EMPTY",""),H(ge,"HIDDEN","hidden"),H(ge,"IS"," is "),H(ge,"LINE","line"),H(ge,"MAIDR_DATA","maidr-data"),H(ge,"MAIDR_HIGHLIGHT_COLOR","#BADA55"),H(ge,"NEW_LINE",`
|
|
303
303
|
`),H(ge,"OPEN_BRACKET","["),H(ge,"POLYLINE","polyline"),H(ge,"SPACE"," "),H(ge,"THROUGH"," through "),H(ge,"TRANSPARENT","transparent"),H(ge,"VISIBLE","visible"),H(ge,"X","x"),H(ge,"Y","y"),H(ge,"HIGHLIGHT_BASE_COLOR",{r:255,g:255,b:255}),H(ge,"HIGHLIGHT_CONTRAST_RATIO",3),H(ge,"HIGHLIGHT_COLOR_RATIO",.6),H(ge,"HIGHLIGHT_MAX_COLOR",255),H(ge,"HIGHER_VALUE_MODE","HIGHER VALUE NAVIGATION"),H(ge,"LOWER_VALUE_MODE","LOWER VALUE NAVIGATION"),H(ge,"DATA_MODE","DATA POINT NAVIGATION"),H(ge,"NO_OF_ROTOR_NAV_MODES",3);class k7{constructor(){H(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 i=this.items.lastIndexOf(t);return i!==-1?(this.items.splice(i,n),!0):!1}isEmpty(){return this.items.length===0}size(){return this.items.length}clear(){this.items.length=0}}const N7=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function z7(e,t,n,i){e.addEventListener?e.addEventListener(t,n,i):e.attachEvent&&e.attachEvent("on".concat(t),n)}function cv(e,t,n,i){e.removeEventListener?e.removeEventListener(t,n,i):e.detachEvent&&e.detachEvent("on".concat(t),n)}function yC(e,t){const n=t.slice(0,t.length-1);for(let i=0;i<n.length;i++)n[i]=e[n[i].toLowerCase()];return n}function vC(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function TB(e,t){const n=e.length>=t.length?e:t,i=e.length>=t.length?t:e;let o=!0;for(let s=0;s<n.length;s++)i.indexOf(n[s])===-1&&(o=!1);return o}const fv={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":N7?173:189,"=":N7?61:187,";":N7?59:186,"'":222,"[":219,"]":221,"\\":220},ru={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},dv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},ga={16:!1,18:!1,17:!1,91:!1},ri={};for(let e=1;e<20;e++)fv["f".concat(e)]=111+e;let $r=[],hv=null,bC="all";const Kc=new Map,pv=e=>fv[e.toLowerCase()]||ru[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),AB=e=>Object.keys(fv).find(t=>fv[t]===e),CB=e=>Object.keys(ru).find(t=>ru[t]===e);function SC(e){bC=e||"all"}function mv(){return bC||"all"}function OB(){return $r.slice(0)}function MB(){return $r.map(e=>AB(e)||CB(e)||String.fromCharCode(e))}function RB(){const e=[];return Object.keys(ri).forEach(t=>{ri[t].forEach(n=>{let{key:i,scope:o,mods:s,shortcut:f}=n;e.push({scope:o,shortcut:f,mods:s,keys:i.split("+").map(d=>pv(d))})})}),e}function _B(e){const t=e.target||e.srcElement,{tagName:n}=t;let i=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(i=!1),i}function DB(e){return typeof e=="string"&&(e=pv(e)),$r.indexOf(e)!==-1}function kB(e,t){let n,i;e||(e=mv());for(const o in ri)if(Object.prototype.hasOwnProperty.call(ri,o))for(n=ri[o],i=0;i<n.length;)n[i].scope===e?n.splice(i,1).forEach(f=>{let{element:d}=f;return I7(d)}):i++;mv()===e&&SC(t||"all")}function NB(e){let t=e.keyCode||e.which||e.charCode;const n=$r.indexOf(t);if(n>=0&&$r.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&$r.splice(0,$r.length),(t===93||t===224)&&(t=91),t in ga){ga[t]=!1;for(const i in ru)ru[i]===t&&(La[i]=!1)}}function xC(e){if(typeof e>"u")Object.keys(ri).forEach(o=>{Array.isArray(ri[o])&&ri[o].forEach(s=>BS(s)),delete ri[o]}),I7(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&BS(o)});else if(typeof e=="object")e.key&&BS(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];let[o,s]=n;typeof o=="function"&&(s=o,o=""),BS({key:e,scope:o,method:s,splitKey:"+"})}}const BS=e=>{let{key:t,scope:n,method:i,splitKey:o="+"}=e;vC(t).forEach(f=>{const d=f.split(o),h=d.length,y=d[h-1],b=y==="*"?"*":pv(y);if(!ri[b])return;n||(n=mv());const x=h>1?yC(ru,d):[],T=[];ri[b]=ri[b].filter(w=>{const R=(i?w.method===i:!0)&&w.scope===n&&TB(w.mods,x);return R&&T.push(w.element),!R}),T.forEach(w=>I7(w))})};function EC(e,t,n,i){if(t.element!==i)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const s in ga)Object.prototype.hasOwnProperty.call(ga,s)&&(!ga[s]&&t.mods.indexOf(+s)>-1||ga[s]&&t.mods.indexOf(+s)===-1)&&(o=!1);(t.mods.length===0&&!ga[16]&&!ga[18]&&!ga[17]&&!ga[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat($r),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function wC(e,t){const n=ri["*"];let i=e.keyCode||e.which||e.charCode;if(!La.filter.call(this,e))return;if((i===93||i===224)&&(i=91),$r.indexOf(i)===-1&&i!==229&&$r.push(i),["metaKey","ctrlKey","altKey","shiftKey"].forEach(d=>{const h=dv[d];e[d]&&$r.indexOf(h)===-1?$r.push(h):!e[d]&&$r.indexOf(h)>-1?$r.splice($r.indexOf(h),1):d==="metaKey"&&e[d]&&($r=$r.filter(y=>y in dv||y===i))}),i in ga){ga[i]=!0;for(const d in ru)if(Object.prototype.hasOwnProperty.call(ru,d)){const h=dv[ru[d]];La[d]=e[h]}if(!n)return}for(const d in ga)Object.prototype.hasOwnProperty.call(ga,d)&&(ga[d]=e[dv[d]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&($r.indexOf(17)===-1&&$r.push(17),$r.indexOf(18)===-1&&$r.push(18),ga[17]=!0,ga[18]=!0);const o=mv();if(n)for(let d=0;d<n.length;d++)n[d].scope===o&&(e.type==="keydown"&&n[d].keydown||e.type==="keyup"&&n[d].keyup)&&EC(e,n[d],o,t);if(!(i in ri))return;const s=ri[i],f=s.length;for(let d=0;d<f;d++)if((e.type==="keydown"&&s[d].keydown||e.type==="keyup"&&s[d].keyup)&&s[d].key){const h=s[d],{splitKey:y}=h,b=h.key.split(y),x=[];for(let T=0;T<b.length;T++)x.push(pv(b[T]));x.sort().join("")===$r.sort().join("")&&EC(e,h,o,t)}}function La(e,t,n){$r=[];const i=vC(e);let o=[],s="all",f=document,d=0,h=!1,y=!0,b="+",x=!1,T=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(s=t.scope),t.element&&(f=t.element),t.keyup&&(h=t.keyup),t.keydown!==void 0&&(y=t.keydown),t.capture!==void 0&&(x=t.capture),typeof t.splitKey=="string"&&(b=t.splitKey),t.single===!0&&(T=!0)),typeof t=="string"&&(s=t),T&&xC(e,s);d<i.length;d++)e=i[d].split(b),o=[],e.length>1&&(o=yC(ru,e)),e=e[e.length-1],e=e==="*"?"*":pv(e),e in ri||(ri[e]=[]),ri[e].push({keyup:h,keydown:y,scope:s,mods:o,shortcut:i[d],method:n,key:i[d],splitKey:b,element:f});if(typeof f<"u"&&window){if(!Kc.has(f)){const w=function(){let R=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return wC(R,f)},C=function(){let R=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;wC(R,f),NB(R)};Kc.set(f,{keydownListener:w,keyupListenr:C,capture:x}),z7(f,"keydown",w,x),z7(f,"keyup",C,x)}if(!hv){const w=()=>{$r=[]};hv={listener:w,capture:x},z7(window,"focus",w,x)}}}function zB(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ri).forEach(n=>{ri[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function I7(e){const t=Object.values(ri).flat();if(t.findIndex(i=>{let{element:o}=i;return o===e})<0){const{keydownListener:i,keyupListenr:o,capture:s}=Kc.get(e)||{};i&&o&&(cv(e,"keyup",o,s),cv(e,"keydown",i,s),Kc.delete(e))}if((t.length<=0||Kc.size<=0)&&(Object.keys(Kc).forEach(o=>{const{keydownListener:s,keyupListenr:f,capture:d}=Kc.get(o)||{};s&&f&&(cv(o,"keyup",f,d),cv(o,"keydown",s,d),Kc.delete(o))}),Kc.clear(),Object.keys(ri).forEach(o=>delete ri[o]),hv)){const{listener:o,capture:s}=hv;cv(window,"focus",o,s),hv=null}}const L7={getPressedKeyString:MB,setScope:SC,getScope:mv,deleteScope:kB,getPressedKeyCodes:OB,getAllKeyCodes:RB,isPressed:DB,filter:_B,trigger:zB,unbind:xC,keyMap:fv,modifier:ru,modifierMap:dv};for(const e in L7)Object.prototype.hasOwnProperty.call(L7,e)&&(La[e]=L7[e]);if(typeof window<"u"){const e=window.hotkeys;La.noConflict=t=>(t&&window.hotkeys===La&&(window.hotkeys=e),La),window.hotkeys=La}class IB{constructor(t){H(this,"id");H(this,"instructionContext");H(this,"selectorList",[]);H(this,"plotContext");H(this,"scopeContext");H(this,"navigationService");H(this,"figure");H(this,"isRotorActive");this.figure=t,this.id=t.id,this.plotContext=new k7,this.scopeContext=new k7,this.navigationService=new D7,this.isRotorActive=!1;const n=t.state;if(n.empty||n.size!==1){this.instructionContext=t,this.plotContext.push(t),this.scopeContext.push(fn.SUBPLOT);return}this.scopeContext.push(fn.TRACE);const i=t.activeSubplot.state;if(i.empty||i.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}setRotorEnabled(t){this.isRotorActive=t}isRotorEnabled(){return this.isRotorActive}toggleScope(t){this.scopeContext.clear(),this.scopeContext.push(t),La.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)}moveToPoint(t,n){this.active.moveToPoint(t,n)}stepTrace(t){if(this.plotContext.size()>1){const n=this.active;this.plotContext.pop();const i=this.active,o=this.navigationService.stepTraceInSubplot(i,t);o?this.plotContext.push(o):n&&this.plotContext.push(n)}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 i=n.activeSubplot.activeTrace;i.resetToInitialEntry(),this.plotContext.push(i),this.toggleScope(fn.TRACE)}}exitSubplot(){this.plotContext.size()>2&&(this.plotContext.pop(),this.plotContext.pop(),this.active.notifyStateUpdate(),this.toggleScope(fn.SUBPLOT))}getInstruction(t){const n=this.instructionContext.state;if(n.empty)return`No ${n.type} info available`;const i=t?"Click to activate.":ge.EMPTY;switch(n.type){case"figure":return`This is a maidr figure containing ${n.size} subplots. ${i}
|
|
304
304
|
Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a maidr plot containing ${n.size} layers, and
|
|
305
305
|
this is layer 1 of ${n.size}: ${n.trace.traceType} plot. ${i}
|
|
306
306
|
Use Arrows to navigate data points. Toggle B for Braille, T for Text,
|
|
307
|
-
S for Sonification, and R for Review mode.`;case"trace":{let o=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(o="single line");const s=o==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${o}${s}. ${i} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}class VS{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[5],16)}}const i=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return i?{r:Number.parseInt(i[1],10),g:Number.parseInt(i[2],10),b:Number.parseInt(i[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const i=this.calculateLuminance(t),o=this.calculateLuminance(n);return(Math.max(i,o)+.05)/(Math.min(i,o)+.05)}static calculateLuminance(t){const[n,i,o]=[t.r,t.g,t.b].map(s=>{const f=s/255;return f<=.03928?f/12.92:((f+.055)/1.055)**2.4});return .2126*n+.7152*i+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}static isEqual(t,n){const i=this.parse(t),o=this.parse(n);return!i||!o?!1:i.r===o.r&&i.g===o.g&&i.b===o.b}}class Ht{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,s=await new Promise((h,y)=>{const b=new Image;b.onload=()=>h(b),b.onerror=()=>y(new Error("Failed to load SVG image")),b.src=o}),f=document.createElement("canvas");[f.width,f.height]=[s.naturalWidth,s.naturalHeight];const d=f.getContext("2d");return d?(d.drawImage(s,0,0),f.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(i=>{if(!n)return i;const o=i.cloneNode(!0);return o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i.insertAdjacentElement(ge.AFTER_END,o),o})}static selectElement(t,n=!0){const i=document.querySelector(t);if(!n)return i;const o=i==null?void 0:i.cloneNode(!0);return o==null||o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i==null||i.insertAdjacentElement(ge.AFTER_END,o),o}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(ge.FILL,ge.TRANSPARENT),n.setAttribute(ge.STROKE,ge.TRANSPARENT),n.setAttribute(ge.VISIBILITY,ge.HIDDEN),n}static createCircleElement(t,n,i){var y;const o=window.getComputedStyle(i),s=o.stroke||o.fill,f=o.strokeWidth||"2",d=Number.parseFloat(f)*2,h=document.createElementNS(this.SVG_NAMESPACE,ge.CIRCLE);return h.setAttribute(ge.CIRCLE_X,String(t)),h.setAttribute(ge.CIRCLE_Y,String(n)),h.setAttribute(ge.RADIUS,String(d)),h.setAttribute(ge.FILL,s),h.setAttribute(ge.STROKE,s),h.setAttribute(ge.STROKE_WIDTH,f),h.setAttribute(ge.VISIBILITY,ge.HIDDEN),(y=i.parentElement)==null||y.insertAdjacentElement(ge.AFTER_END,h),h}static createLineElement(t,n){const o=t.getBBox();let s,f,d,h;switch(n){case"top":[s,f,d,h]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[s,f,d,h]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[s,f,d,h]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[s,f,d,h]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const y=window.getComputedStyle(t),b=document.createElementNS(this.SVG_NAMESPACE,ge.LINE);return b.setAttribute(ge.X1,String(s)),b.setAttribute(ge.Y1,String(f)),b.setAttribute(ge.X2,String(d)),b.setAttribute(ge.Y2,String(h)),b.setAttribute(ge.STROKE,y.stroke),b.setAttribute(ge.STROKE_WIDTH,y.strokeWidth||"2"),b.setAttribute(ge.VISIBILITY,ge.HIDDEN),t.insertAdjacentElement(ge.AFTER_END,b),b}static getAdjustedOpacity(t,n){const i=t?Number.parseFloat(t):Number.NaN;return!Number.isNaN(i)&&i>n?i.toString():"1"}static createHighlightElement(t,n){const i=t.cloneNode(!0),o=t.tagName.toLowerCase(),s=o===ge.POLYLINE||o===ge.LINE,f=window.getComputedStyle(t),d=s?f.getPropertyValue(ge.STROKE):f.getPropertyValue(ge.FILL),h=this.getHighlightColor(d,n),y=f.getPropertyValue("fill-opacity"),b=f.getPropertyValue("stroke-opacity");if(i.style.fillOpacity=this.getAdjustedOpacity(y,this.MIN_VISIBLE_FILL_OPACITY),i.style.strokeOpacity=this.getAdjustedOpacity(b,this.MIN_VISIBLE_STROKE_OPACITY),i.setAttribute(ge.VISIBILITY,ge.VISIBLE),i.setAttribute(ge.STROKE,h),i.setAttribute(ge.FILL,h),i.style.fill=h,i.style.stroke=h,s){const x=window.getComputedStyle(i).getPropertyValue(ge.STROKE_WIDTH),T=x.match(/^([0-9.]+)([a-z%]*)$/i);if(T){const w=Number.parseFloat(T[1]),C=T[2]||"";i.setAttribute(ge.STROKE_WIDTH,`${w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE}${C}`)}else{const w=Number.parseFloat(x),C=Number.isNaN(w)?this.STROKE_WIDTH_HIGHLIGHT_INCREASE:w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE;i.setAttribute(ge.STROKE_WIDTH,`${C}`)}}return t.insertAdjacentElement(ge.AFTER_END,i),i}static getHighlightColor(t,n){const i=VS.parse(t);if(!i||!(VS.getContrastRatio(i,ge.HIGHLIGHT_BASE_COLOR)<ge.HIGHLIGHT_CONTRAST_RATIO))return n;const f={...i};return i.r===i.g&&i.g===i.b?(f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)),f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)),f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO))):i.r>=i.g&&i.r>=i.b?f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)):i.g>=i.r&&i.g>=i.b?f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)):f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO)),VS.rgbToString(f)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",i=VS.parse(n);return i?(.2126*i.r+.7152*i.g+.0722*i.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,i){const o=t.querySelector("rect, path");let s="";if(o){s=window.getComputedStyle(o).getPropertyValue("fill"),(!s||s==="none"||s==="transparent"||s==="rgba(0, 0, 0, 0)")&&(i?s=window.getComputedStyle(i).getPropertyValue("fill"):s=n);const f=this.getHighlightColor(s,n);o.setAttribute("stroke",f),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}H(Ht,"SVG_NAMESPACE","http://www.w3.org/2000/svg"),H(Ht,"MIN_VISIBLE_FILL_OPACITY",.01),H(Ht,"MIN_VISIBLE_STROKE_OPACITY",.01),H(Ht,"STROKE_WIDTH_HIGHLIGHT_INCREASE",2);const LB="unavailable",BB="X",VB="Y",UB="unavailable";class B7{constructor(){H(this,"observers");H(this,"isWarning");this.observers=new Array,this.isWarning=!1}dispose(){this.observers.length=0}notifyRotorBounds(){this.isWarning=!0,this.notifyStateUpdate(),this.isWarning=!1}get isInitialEntry(){return this.movable.isInitialEntry}set isInitialEntry(t){this.movable.isInitialEntry=t}get isOutOfBounds(){return this.movable.isOutOfBounds}set isOutOfBounds(t){this.movable.isOutOfBounds=t}get row(){return this.movable.row}get col(){return this.movable.col}set row(t){this.movable.row=t}set col(t){this.movable.col=t}getSafeIndices(){const t=this.row>=0&&this.row<this.dimension.rows?this.row:0,n=this.col>=0&&this.col<this.dimension.cols?this.col:0;return{row:t,col:n}}addObserver(t){this.observers.push(t)}removeObserver(t){const n=this.observers.indexOf(t);n!==-1&&this.observers.splice(n,1)}notifyStateUpdate(){const t=this.state;this.observers.forEach(n=>n.update(t))}notifyOutOfBounds(){const t=this.outOfBoundsState;this.observers.forEach(n=>n.update(t))}moveOnce(t){const n=this.movable.moveOnce(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToExtreme(t){const n=this.movable.moveToExtreme(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToIndex(t,n){const i=this.movable.moveToIndex(t,n);return i?this.notifyStateUpdate():this.notifyOutOfBounds(),i}isMovable(t){return this.movable.isMovable(t)}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}moveToNextCompareValue(t,n){return this.notifyRotorBounds(),!1}compare(t,n,i){return i==="lower"?t<n:i==="higher"?t>n:!1}moveUpRotor(t){throw new Error("Move up function is not defined for this trace")}moveDownRotor(t){throw new Error("Move down function is not defined for this trace")}moveLeftRotor(t){throw new Error("Move left function is not defined for this trace")}moveRightRotor(t){throw new Error("Move right function is not defined for this trace")}moveToPoint(t,n){}}class Fl extends B7{constructor(n){var i,o,s;super();H(this,"id");H(this,"type");H(this,"title");H(this,"xAxis");H(this,"yAxis");H(this,"fill");H(this,"navigationService");H(this,"layer");this.layer=n,this.navigationService=new D7,this.id=n.id,this.type=n.type,this.title=n.title??LB,this.xAxis=((i=n.axes)==null?void 0:i.x)??BB,this.yAxis=((o=n.axes)==null?void 0:o.y)??VB,this.fill=((s=n.axes)==null?void 0:s.fill)??UB}dispose(){this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(i=>{(Array.isArray(i)?i:[i]).forEach(s=>s.remove())})),this.highlightValues.length=0),super.dispose()}get state(){return this.isWarning?{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols},warning:!0}:{empty:!1,type:"trace",layerId:this.id,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}}get outOfBoundsState(){return{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols}}}get highlight(){return this.highlightValues===null||this.isInitialEntry?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAllHighlightElements(){if(this.highlightValues===null)return[];const n=[];for(const i of this.highlightValues)for(const o of i)Array.isArray(o)?n.push(...o):o&&n.push(o);return n}getAllOriginalElements(){if(this.highlightValues===null)return[];const n=[];for(const i of this.highlightValues)for(const o of i){const s=Array.isArray(o)?o:o?[o]:[];for(const f of s){const d=f.previousElementSibling;d&&d.tagName===f.tagName&&d.getAttribute("visibility")!=="hidden"&&n.push(d)}}return n}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){return{UPWARD:this.dimension.rows,DOWNWARD:this.dimension.rows,FORWARD:this.dimension.cols,BACKWARD:this.dimension.cols}}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}get 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 i=this.getPointsArray();if(this.isValidPointsArray(i))return this.navigationService.moveToXValueInPoints(i,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const i=this.values;if(this.isValidValuesArray(i))return this.navigationService.moveToXValueInValues(i,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}moveToPoint(n,i){const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}isPointInBounds(n,i,{element:o,row:s,col:f}){const d=o.getBoundingClientRect();let h=12;return(this.type===or.HEATMAP||this.type===or.BAR||this.type===or.STACKED||this.type===or.HISTOGRAM)&&(h=0),n>=d.x-h&&n<=d.x+d.width+h&&i>=d.y-h&&i<=d.y+d.height+h}}class Ba{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],i=t[0];for(let o=1;o<t.length;o++){const s=t[o];s<n&&(n=s),s>i&&(i=s)}return{min:n,max:i}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class V7{constructor(t){H(this,"isInitialEntry");H(this,"isOutOfBounds");H(this,"row");H(this,"col");this.isInitialEntry=(t==null?void 0:t.isInitialEntry)??!0,this.isOutOfBounds=!1,this.row=(t==null?void 0:t.row)??0,this.col=(t==null?void 0:t.col)??0}moveToIndex(t,n){return this.isMovable([t,n])?(this.row=t,this.col=n,this.isInitialEntry=!1,!0):!1}}class Pm extends V7{constructor(n,i){super(i);H(this,"elements");this.elements=n}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;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}return!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":this.row=this.elements.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.col=this.elements[this.row].length-1;break;case"BACKWARD":this.col=0;break}return!0}moveToIndex(n,i){return this.isMovable([n,i])?(this.row=n,this.col=i,this.isInitialEntry=!1,!0):!1}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.elements.length&&o>=0&&o<this.elements[this.row].length}switch(n){case"UPWARD":return this.row<this.elements.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.elements[this.row].length-1;case"BACKWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.elements.length-1)),this.col=Math.max(0,Math.min(this.col,this.elements[this.row].length-1))}}class PB extends V7{constructor(n,i){super(i);H(this,"graph");this.graph=n}moveOnce(n){var s;if(this.isInitialEntry)return this.handleInitialEntry(),!0;const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.up;break;case"DOWNWARD":o=i.down;break;case"FORWARD":o=i.right;break;case"BACKWARD":o=i.left;break}return o?(this.row=o.row,this.col=o.col,!0):!1}moveToExtreme(n){var s;this.isInitialEntry&&this.handleInitialEntry();const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.top;break;case"DOWNWARD":o=i.bottom;break;case"FORWARD":o=i.end;break;case"BACKWARD":o=i.start;break}return o?(this.row=o.row,this.col=o.col,!0):!1}isMovable(n){var o,s,f;if(Array.isArray(n)){const[d,h]=n;return((o=this.graph[d])==null?void 0:o[h])!==null&&((s=this.graph[d])==null?void 0:s[h])!==void 0}const i=(f=this.graph[this.row])==null?void 0:f[this.col];if(!i)return!1;switch(n){case"UPWARD":return i.up!==null;case"DOWNWARD":return i.down!==null;case"FORWARD":return i.right!==null;case"BACKWARD":return i.left!==null}}handleInitialEntry(){this.isInitialEntry=!1,this.isMovable([0,0])?(this.row=0,this.col=0):(this.row=-1,this.col=-1)}}class jB extends V7{constructor(n,i){super();H(this,"mode");H(this,"xPoints");H(this,"yPoints");H(this,"xValues");H(this,"yValues");this.mode="col",this.xPoints=n,this.yPoints=i,this.xValues=n.map(o=>o.x),this.yValues=i.map(o=>o.y)}dispose(){this.xValues.length=0,this.yValues.length=0}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;if(this.mode==="col")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}}return!0}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="col")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}return!0}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="col")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}}toggleNavigation(){if(this.mode==="col"){const n=this.xPoints[this.col],i=n.y[Math.floor(n.y.length/2)];this.row=this.yValues.indexOf(i),this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)];this.col=this.xValues.indexOf(i),this.mode="col"}}handleInitialEntry(){this.isInitialEntry=!1,this.mode==="col"?(this.col=Math.max(0,Math.min(this.col,this.xPoints.length-1)),this.row=Math.max(0,Math.min(this.row,this.xPoints[this.col].y.length-1))):(this.row=Math.max(0,Math.min(this.row,this.yPoints.length-1)),this.col=Math.max(0,Math.min(this.col,this.yPoints[this.row].x.length-1)))}}class U7 extends Fl{constructor(n,i){super(n);H(this,"movable");H(this,"points");H(this,"barValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"orientation");H(this,"min");H(this,"max");H(this,"supportsExtrema",!0);this.points=i,this.orientation=n.orientation??Rn.VERTICAL,this.barValues=i.map(o=>o.map(s=>this.orientation===Rn.VERTICAL?Number(s.y):Number(s.x))),this.min=this.barValues.map(o=>Ba.safeMin(o)),this.max=this.barValues.map(o=>Ba.safeMax(o)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Pm(this.points)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get audio(){const n=this.orientation===Rn.VERTICAL,i=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{freq:{min:Ba.safeMin(this.min),max:Ba.safeMax(this.max),raw:i},panning:{x:n?this.col:this.row,y:n?this.row:this.col,rows:n?this.barValues.length:this.barValues[this.col].length,cols:n?this.barValues[this.row].length:this.barValues.length},group:n?this.row:this.col}}get braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){const n=this.orientation===Rn.VERTICAL,i=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,s=n?i.x:i.y,f=n?this.yAxis:this.xAxis,d=n?i.y:i.x;return{main:{label:o,value:s},cross:{label:f,value:d},mainAxis:n?"x":"y",crossAxis:n?"y":"x"}}get dimension(){return{rows:this.barValues.length,cols:this.barValues[this.row].length}}get values(){return this.barValues}mapToSvgElements(n){if(!n)return null;const i=[Ht.selectAllElements(n)];if(i.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(i[o].length!==this.points[o].length)return null;return i}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();d&&i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}return i}findNearestPoint(n,i){if(!this.highlightValues)return null;for(let o=0;o<this.highlightValues.length;o++)for(let s=0;s<this.highlightValues[o].length;s++){const f=this.highlightValues[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();if(n>=h.x&&n<=h.x+h.width&&i>=h.y&&i<=h.y+h.height)return{element:d,row:o,col:s}}return null}}class $B extends U7{isPointInBounds(t,n,{element:i,row:o,col:s}){const f=i.getBoundingClientRect();return t>=f.x&&t<=f.x+f.width&&n>=f.y&&n<=f.y+f.height}constructor(t){super(t,[t.data])}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.barValues[n];if(!i||i.length===0)return t;const o=this.min[n],s=this.max[n],f=i.indexOf(s),d=i.indexOf(o);return t.push({label:`Max Bar at ${this.getPointLabel(f)}`,value:s,pointIndex:f,segment:"bar",type:"max",navigationType:"point"}),t.push({label:`Min Bar at ${this.getPointLabel(d)}`,value:o,pointIndex:d,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===Rn.VERTICAL?`${n.x}`:`${n.y}`}return`Point ${t}`}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const iu={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class HB extends Fl{constructor(n,i=!1){var f;super(n);H(this,"supportsExtrema",!1);H(this,"movable");H(this,"points");H(this,"boxValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"orientation");H(this,"sections");H(this,"min");H(this,"max");H(this,"isViolinBoxPlot");this.isViolinBoxPlot=i&&n.type===or.BOX,this.points=n.data,this.orientation=n.orientation??Rn.VERTICAL,this.orientation===Rn.HORIZONTAL?this.points=[...n.data].reverse():this.points=n.data,this.sections=[iu.LOWER_OUTLIER,iu.MIN,iu.Q1,iu.Q2,iu.Q3,iu.MAX,iu.UPPER_OUTLIER];const o=[d=>d.lowerOutliers,d=>d.min,d=>d.q1,d=>d.q2,d=>d.q3,d=>d.max,d=>d.upperOutliers];this.orientation===Rn.HORIZONTAL?this.boxValues=this.points.map(d=>o.map(h=>h(d))):this.boxValues=o.map(d=>this.points.map(h=>d(h)));const s=this.boxValues.map(d=>d.flatMap(h=>Array.isArray(h)?h:[h]));this.min=Ba.minFrom2D(s),this.max=Ba.maxFrom2D(s),this.highlightValues=this.mapToSvgElements(n.selectors),this.orientation===Rn.HORIZONTAL&&((f=this.highlightValues)==null||f.reverse()),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Pm(this.boxValues,{row:0})}isViolin(){return this.isViolinBoxPlot}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,i){return super.moveToIndex(n,i)}handleInitialEntry(){var n;this.isInitialEntry=!1,this.orientation===Rn.VERTICAL?(this.row=Math.min(1,this.boxValues.length-1),this.col=0):(this.row=0,this.col=Math.min(1,((n=this.boxValues[0])==null?void 0:n.length)??1))}moveOnce(n){if(!this.isViolin())return super.moveOnce(n);if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.orientation===Rn.VERTICAL)if(n==="FORWARD")this.col+=1,this.row=1;else if(n==="BACKWARD")this.col-=1,this.row=1;else return super.moveOnce(n);else if(n==="UPWARD")this.row+=1,this.col=1;else if(n==="DOWNWARD")this.row-=1,this.col=1;else return super.moveOnce(n);return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}get values(){return this.boxValues}get audio(){const n=this.orientation===Rn.HORIZONTAL,i=this.boxValues[this.row][this.col],o=n?this.col:this.row,s=Array.isArray(i)?i.length===0?o:i[i.length-1]-this.min:Number.isNaN(i)?o:i-this.min;return{freq:{min:this.min,max:this.max,raw:this.boxValues[this.row][this.col]},panning:{x:n?s:this.row,y:n?this.row:s,rows:n?this.boxValues.length:this.max-this.min,cols:n?this.max-this.min:this.boxValues.length}}}get braille(){const n=this.orientation===Rn.HORIZONTAL,i=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:i,col:o}}get text(){const n=this.orientation===Rn.HORIZONTAL,i=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,s=n?this.sections[this.col]:this.sections[this.row],f=n?this.xAxis:this.yAxis,d=this.boxValues[this.row][this.col];return{main:{label:o,value:i.fill},cross:{label:f,value:d},section:s,mainAxis:n?"y":"x",crossAxis:n?"x":"y"}}get dimension(){const n=this.orientation===Rn.HORIZONTAL;return{rows:n?this.boxValues.length:this.boxValues[this.row].length,cols:n?this.boxValues[this.row].length:this.boxValues.length}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const i=this.orientation===Rn.VERTICAL,o=new Array;if(i)for(let f=0;f<this.sections.length;f++)o.push(Array.from({length:n.length}));const s=[];return n.forEach(f=>{var w,C;const d=((w=f.lowerOutliers)==null?void 0:w.flatMap(R=>Ht.selectAllElements(R,!1)))??[],h=((C=f.upperOutliers)==null?void 0:C.flatMap(R=>Ht.selectAllElements(R,!1)))??[],y=Ht.selectElement(f.min,!1),b=Ht.selectElement(f.max,!1),x=Ht.selectElement(f.iq,!1),T=Ht.selectElement(f.q2,!1);s.push({lowerOutliers:d,upperOutliers:h,min:y,max:b,iq:x,q2:T})}),s.forEach((f,d)=>{var N;const h=f.lowerOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),y=f.upperOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),b=this.cloneElementOrEmpty(f.min),x=this.cloneElementOrEmpty(f.max),T=this.cloneElementOrEmpty(f.q2),w=((N=this.layer.domMapping)==null?void 0:N.iqrDirection)==="reverse",[C,R]=f.iq?i?w?[Ht.createLineElement(f.iq,"top"),Ht.createLineElement(f.iq,"bottom")]:[Ht.createLineElement(f.iq,"bottom"),Ht.createLineElement(f.iq,"top")]:[Ht.createLineElement(f.iq,"left"),Ht.createLineElement(f.iq,"right")]:[Ht.createEmptyElement("line"),Ht.createEmptyElement("line")],_=[h,b,C,T,R,x,y];i?_.forEach((z,B)=>{o[B][d]=z}):o.push(_)}),o}cloneElementOrEmpty(n){if(!n)return Ht.createEmptyElement();const i=n.cloneNode(!0);return i.setAttribute(ge.VISIBILITY,ge.HIDDEN),n.insertAdjacentElement(ge.AFTER_END,i),i}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.boxValues.length)return!1;let s=[],f=0;if(n==="left"||n==="right"?(s=this.boxValues[this.row],f=this.col):(s=this.boxValues.map(y=>y[this.col]),f=this.row),s.length<=0)return!1;const d=n==="right"||n==="up"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){const y=s[f],b=s[h];if(Array.isArray(b)||Array.isArray(y))return!0;if(this.compare(b,y,i))return this.set_point(n,h),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}set_point(n,i){n==="left"||n==="right"?this.col=i:this.row=i}moveUpRotor(n){return this.orientation===Rn.VERTICAL?(this.moveOnce("UPWARD"),!0):this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.orientation===Rn.VERTICAL?(this.moveOnce("DOWNWARD"),!0):this.moveToNextCompareValue("down",n)}moveLeftRotor(n){return this.orientation===Rn.HORIZONTAL?(this.moveOnce("BACKWARD"),!0):this.moveToNextCompareValue("left",n)}moveRightRotor(n){return this.orientation===Rn.HORIZONTAL?(this.moveOnce("FORWARD"),!0):this.moveToNextCompareValue("right",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){}getCurrentXValue(){return this.isViolin()?this.orientation===Rn.VERTICAL?this.col>=0?this.col:null:this.row>=0?this.row:null:super.getCurrentXValue()}moveToXValue(n){if(!this.isViolin())return super.moveToXValue(n);if(this.isInitialEntry&&this.handleInitialEntry(),typeof n!="number")return!1;const i=Math.floor(n),o=this.values;if(this.orientation===Rn.VERTICAL){const s=o.length>0?o[0].length:0;if(i<0||i>=s)return!1;const f=this.col;return this.col=i,i!==f&&(this.row=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(i<0||i>=o.length)return!1;const s=this.row;return this.row=i,i!==s&&(this.col=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}getCurrentYValue(){if(!this.isViolin())return null;const n=this.values;if(this.orientation===Rn.VERTICAL){if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}}else if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}return null}moveToXAndYValue(n,i){if(!this.isViolin()||typeof n!="number")return!1;const o=Math.floor(n),s=this.values;if(this.orientation===Rn.VERTICAL){const f=s.length>0?s[0].length:0;if(o<0||o>=f)return!1;this.col=o;let d=1,h=1/0;for(let y=0;y<s.length;y++){const b=s[y];if(Array.isArray(b)&&o<b.length){const x=b[o];if(Array.isArray(x)){for(const T of x)if(typeof T=="number"){const w=Math.abs(T-i);w<h&&(h=w,d=y)}}else if(typeof x=="number"){const T=Math.abs(x-i);T<h&&(h=T,d=y)}}}return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(o<0||o>=s.length)return!1;this.row=o;let f=1,d=1/0;const h=s[o];if(Array.isArray(h))for(let y=0;y<h.length;y++){const b=h[y];if(Array.isArray(b)){for(const x of b)if(typeof x=="number"){const T=Math.abs(x-i);T<d&&(d=T,f=y)}}else if(typeof b=="number"){const x=Math.abs(b-i);x<d&&(d=x,f=y)}}return this.col=f,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}onSwitchFrom(n){var d;if(!this.isViolin())return!1;const i=n;if(!((i.type||((d=i.state)==null?void 0:d.traceType))==="smooth"))return!1;const f=n.getCurrentXValue();if(n.getCurrentYValue){const h=n.getCurrentYValue();if(h!==null&&f!==null&&this.moveToXAndYValue){const y=this.moveToXAndYValue(f,h);return y&&(this.isInitialEntry=!1),y}}if(f!==null){const h=this.moveToXValue(f);return h&&(this.isInitialEntry=!1),h}return!1}}const qB="trend",TC=100,FB=["volatility","open","high","low","close"];class GB extends Fl{constructor(n){super(n);H(this,"supportsExtrema",!0);H(this,"movable");H(this,"candles");H(this,"candleValues");H(this,"orientation");H(this,"currentSegmentType","open");H(this,"currentPointIndex",0);H(this,"sortedSegmentsByPoint");H(this,"segmentPositionMaps");H(this,"sections");H(this,"min");H(this,"max");H(this,"highlightValues");H(this,"highlightCenters");H(this,"navigationService");this.navigationService=new D7;const i=n.data;this.candles=i.map(s=>({...s,volatility:Math.round((s.high-s.low)*TC)/TC,trend:s.close>s.open?"Bull":s.close<s.open?"Bear":"Neutral"})),this.orientation=n.orientation??Rn.VERTICAL,this.sections=FB,this.candleValues=this.sections.map(s=>this.candles.map(f=>f[s]));const o=this.orientation===Rn.HORIZONTAL?{col:this.sections.length-1}:{row:this.sections.length-1};this.movable=new Pm(this.candleValues,o),this.min=Ba.minFrom2D(this.candleValues),this.max=Ba.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===Rn.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters()}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(s=>[s,n[s]]).sort((s,f)=>s[1]-f[1]).map(s=>s[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const i=new Map;return n.forEach((o,s)=>{i.set(o,s)}),i})}getSegmentPositionInSortedOrder(n,i){return this.segmentPositionMaps[n].get(i)??0}getSegmentTypeAtSortedPosition(n,i){return this.sortedSegmentsByPoint[n][i]??"open"}updateVisualSegmentPosition(){const i=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===Rn.HORIZONTAL?this.col=i:this.row=i}updateVisualPointPosition(){this.orientation===Rn.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)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open");if(o===-1)return this.notifyOutOfBounds(),!1;const s=n==="UPWARD"?o+1:o-1;if(s>=0&&s<i.length)this.currentSegmentType=i[s],this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(i>=0&&i<this.candles.length)this.currentPointIndex=i,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}}return this.notifyStateUpdate(),!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[i.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[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}}return this.notifyStateUpdate(),!0}moveToIndex(n,i){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:o,segmentType:s}=this.navigationService.computeIndexAndSegment(n,i,this.orientation,this.sections);return this.currentPointIndex=o,this.currentSegmentType=s,this.row=n,this.col=i,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open"),s=n==="UPWARD"?o+1:o-1;return s>=0&&s<i.length}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return i>=0&&i<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}get audio(){let n;const i=this.orientation===Rn.HORIZONTAL;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,{freq:{min:this.min,max:this.max,raw:n},panning:{x:i?this.row:this.col,y:i?this.col:this.row,rows:i?this.candleValues.length:this.candleValues[this.row].length,cols:i?this.candleValues[this.row].length:this.candleValues.length},trend:this.candles[this.currentPointIndex].trend}}get braille(){const n=this.candles.map(f=>f.trend),i=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=i;const o=this.candleValues.map(f=>Math.min(...f)),s=this.candleValues.map(f=>Math.max(...f));return{empty:!1,id:this.id,values:this.candleValues,min:o,max:s,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const i=Array.isArray(n)?n:[n],o=[];for(const s of i)o.push(...Ht.selectAllElements(s));return o}getElementAt(n,i){return i<n.length?n[i]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const C=Array.isArray(n)?n[0]||"":n,R=Ht.selectAllElements(C),_=[];for(let N=0;N<this.sections.length;N++){_[N]=[];for(let z=0;z<this.candles.length;z++){const B=z<R.length?z:0;_[N][z]=R[B]}}return _}const i=n,o=this.candles.length,s=this.collectElements(i.body);let f=this.collectElements(i.wickHigh),d=this.collectElements(i.wickLow);if(f.length===0||d.length===0){const C=this.collectElements(i.wick);C.length>0&&(f.length===0&&(f=C),d.length===0&&(d=C))}const h=this.collectElements(i.open),y=this.collectElements(i.close),b=Array.from({length:o},()=>Ht.createEmptyElement()),x=Array.from({length:o},()=>Ht.createEmptyElement()),T=Array.from({length:o},()=>Ht.createEmptyElement());for(let C=0;C<o;C++){let R=this.getElementAt(h,C);if(!R){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"bottom":B<z?"top":"bottom";R=Ht.createLineElement(N,V)}else R=Ht.createEmptyElement()}b[C]=R;let _=this.getElementAt(y,C);if(!_){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"top":B<z?"bottom":"top";_=Ht.createLineElement(N,V)}else _=Ht.createEmptyElement()}x[C]=_,T[C]=Ht.createEmptyElement()}const w=Array.from({length:this.sections.length},()=>Array.from({length:o},()=>Ht.createEmptyElement()));for(let C=0;C<o;C++){const R=this.sortedSegmentsByPoint[C];for(let _=0;_<R.length;_++){const N=R[_];let z;switch(N){case"volatility":{const B=[],V=this.getElementAt(s,C),I=this.getElementAt(f,C)??V,P=this.getElementAt(d,C)??V;I&&B.push(I),V&&B.push(V),P&&B.push(P);const Y=Array.from(new Set(B));z=Y.length>0?Y:[Ht.createEmptyElement()]}break;case"open":z=b[C];break;case"close":z=x[C];break;case"high":z=this.getElementAt(f,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;case"low":z=this.getElementAt(d,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;default:z=Ht.createEmptyElement()}w[_][C]=z}}return w}get text(){const n=this.candles[this.currentPointIndex],i=this.orientation===Rn.HORIZONTAL;let o;return this.currentSegmentType==="volatility"?o=n.volatility:this.currentSegmentType?o=n[this.currentSegmentType]:o=n.open,{main:{label:i?this.yAxis:this.xAxis,value:n.value},cross:{label:i?this.xAxis:this.yAxis,value:o},section:this.currentSegmentType??"open",fill:{label:qB,value:n.trend},mainAxis:i?"y":"x",crossAxis:i?"x":"y"}}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 i=this.candles.findIndex(o=>o.value===n);return i!==-1?(this.currentPointIndex=i,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getAvailableXValues(){return this.candles.map(n=>n.value)}getExtremaTargets(){const n=[],i=this.currentSegmentType??"open";if(i==="volatility"){const o=this.candles.map((y,b)=>({value:y.volatility,index:b})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,b)=>{const x=this.candles[y];n.push({label:`Max Volatility at ${x.value}`,value:x.volatility,pointIndex:y,segment:"volatility",type:"max",navigationType:"point"})}),h.forEach((y,b)=>{const x=this.candles[y];n.push({label:`Min Volatility at ${x.value}`,value:x.volatility,pointIndex:y,segment:"volatility",type:"min",navigationType:"point"})})}else{const o=this.candles.map((y,b)=>({value:y[i],index:b,xValue:y.value})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,b)=>{const x=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Max ${T} at ${x.value}`,value:x[i],pointIndex:y,segment:i,type:"max",navigationType:"point"})}),h.forEach((y,b)=>{const x=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Min ${T} at ${x.value}`,value:x[i],pointIndex:y,segment:i,type:"min",navigationType:"point"})})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.finalizeExtremaNavigation()}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.candles.length)return!1;const s=this.currentSegmentType??"open",f=this.candles.map((b,x)=>({value:b[s],index:x,xValue:b.value})),d=this.col,h=n==="right"?1:-1;let y=d+h;for(;y>=0&&y<f.length;){if(this.compare(f[y].value,f[d].value,i))return this.col=y,this.currentPointIndex=y,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;y+=h}return this.notifyRotorBounds(),!1}moveUpRotor(){return this.moveOnce("UPWARD"),!0}moveDownRotor(){return this.moveOnce("DOWNWARD"),!0}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}get dimension(){const n=this.orientation===Rn.HORIZONTAL;return{rows:n?this.candleValues.length:this.candleValues[this.row].length,cols:n?this.candleValues[this.row].length:this.candleValues.length}}}class YB extends Fl{constructor(n){super(n);H(this,"supportsExtrema",!1);H(this,"movable");H(this,"heatmapValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"x");H(this,"y");H(this,"min");H(this,"max");const i=n.data;this.x=i.x,this.y=[...i.y].reverse(),this.heatmapValues=[...i.points].reverse();const{min:o,max:s}=Ba.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=s,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Pm(this.heatmapValues)}get values(){return this.heatmapValues}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get audio(){return{freq:{min:this.min,max:this.max,raw:this.heatmapValues[this.row][this.col]},panning:{x:this.col,y:this.row,rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}}get braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}get 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:this.heatmapValues[this.row][this.col]}}}get dimension(){return{rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}mapToSvgElements(n){var d;if(!n)return null;const i=this.heatmapValues.length,o=this.heatmapValues[0].length,s=Ht.selectAllElements(n);if(s.length===0||s.length!==i*o)return null;const f=new Array;if(s[0]instanceof SVGPathElement)for(let h=0;h<i;h++){const y=i-1-h,b=new Array;for(let x=0;x<o;x++){const T=y*o+x;b.push(s[T])}f.push(b)}else if(s[0]instanceof SVGRectElement)if(((d=this.layer.domMapping)==null?void 0:d.order)==="row")for(let h=0;h<i;h++){const y=new Array;for(let b=0;b<o;b++){const x=h*o+b;y.push(s[x])}f.push(y)}else for(let h=0;h<i;h++){const y=new Array;for(let b=0;b<o;b++){const x=b*i+h;y.push(s[x])}f.push(y)}return f}updateVisualPointPosition(){const{row:n,col:i}=this.getSafeIndices();this.row=n,this.col=i}moveToNextCompareValue(n,i){switch(n){case"left":case"right":return this.search_in_row(n,i);case"up":case"down":return this.search_in_col(n,i);default:return this.notifyRotorBounds(),!1}}search_in_row(n,i){const o=this.y.length,s=this.col,f=n==="left"?-1:1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[this.row][d],this.heatmapValues[this.row][s],i))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}search_in_col(n,i){const o=this.x.length,s=this.row,f=n==="up"?1:-1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[d][this.col],this.heatmapValues[s][this.col],i))return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return!1}moveUpRotor(n){return this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.moveToNextCompareValue("down",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}}class XB extends U7{constructor(t){super(t,[t.data])}get text(){const t=this.orientation===Rn.VERTICAL,n=this.points[this.row][this.col],i=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text,range:{min:i,max:o}}}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const AC="Group",P7=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class CC extends Fl{constructor(n){super(n);H(this,"supportsExtrema",!0);H(this,"rotorSupport",!0);H(this,"movable");H(this,"points");H(this,"lineValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"min");H(this,"max");H(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(i=>i.map(o=>Number(o.y))),this.min=this.lineValues.map(i=>Ba.safeMin(i)),this.max=this.lineValues.map(i=>Ba.safeMax(i)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new PB(this.buildGraph())}get values(){return this.lineValues}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}buildGraph(){const n=this.points.length;if(n===0)return new Array;const i=Math.max(0,...this.points.map(s=>s.length)),o=this.points.map(s=>s.map(()=>({up:null,down:null,left:null,right:null,top:null,bottom:null,start:null,end:null})));for(let s=0;s<i;s++){const f=this.points.map((b,x)=>{var T;return{y:(T=b[s])==null?void 0:T.y,row:x}}).filter(b=>b.y!==void 0);if(f.length===0)continue;const d=[...f].sort((b,x)=>b.y-x.y),h={row:d[0].row,col:s},y={row:d[d.length-1].row,col:s};for(let b=0;b<d.length;b++){const{row:x}=d[b],T=o[x][s];T&&(b>0&&(T.down={row:d[b-1].row,col:s}),b<d.length-1&&(T.up={row:d[b+1].row,col:s}),T.bottom=h,T.top=y)}}for(let s=0;s<n;s++){const f=this.points[s].length>0?{row:s,col:0}:null,d=this.points[s].length>0?{row:s,col:this.points[s].length-1}:null;for(let h=0;h<this.points[s].length;h++){const y=o[s][h];y&&(h>0&&(y.left={row:s,col:h-1}),h<this.points[s].length-1&&(y.right={row:s,col:h+1}),y.start=f,y.end=d)}}return o}get audio(){return{freq:{min:this.min[this.row],max:this.max[this.row],raw:this.lineValues[this.row][this.col]},panning:{x:this.col,y:this.row,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:this.row}}get braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){var s;const n=this.points[this.row][this.col],i=this.findIntersections();let o={};if(i.length>1){let f=i.map(d=>{var y;const h=d.group;return((y=this.points[h][0])==null?void 0:y.fill)||`l${h+1}`});if(this.previousRow!==null){const d=((s=this.points[this.previousRow][0])==null?void 0:s.fill)||`l${this.previousRow+1}`;f.includes(d)&&(f=[d,...f.filter(h=>h!==d)])}o={fill:{label:AC,value:`intersection at (${f.join(", ")})`}}}else o=n.fill?{fill:{label:AC,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...o}}get dimension(){return{rows:this.lineValues.length,cols:this.lineValues[this.row].length}}moveOnce(n){if(this.isInitialEntry)return this.movable.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const o=this.findLineByXAndYDirection(n),s=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const f=this.findColumnByXValue(o,s);if(f!==-1){this.row=o,this.col=f;const d=this.findIntersections();if(d.length>1){const y={...super.state,intersections:d};for(const b of this.observers)b.update(y)}else this.notifyStateUpdate();return!0}else return this.notifyOutOfBounds(),!1}else return this.notifyOutOfBounds(),!1}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const i=this.findIntersections();if(i.length>1){const s={...super.state,intersections:i};for(const f of this.observers)f.update(s)}else this.notifyStateUpdate();return!0}findIntersections(){const n=this.points[this.row][this.col].x,i=this.points[this.row][this.col].y,o=[];for(let s=0;s<this.points.length;s++)this.points[s].findIndex(d=>d.x===n&&d.y===i)!==-1&&o.push({freq:{min:this.min[s],max:this.max[s],raw:i},panning:{x:this.col,y:this.row,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:s});return o}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.values.length&&o>=0&&o<this.values[i].length}switch(n){case"UPWARD":case"DOWNWARD":{const i=this.findLineByXAndYDirection(n);if(i===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(i,o)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const i=this.points[this.row][this.col].x;let o=null,s=Number.POSITIVE_INFINITY;for(let f=0;f<this.points.length;f++){if(f===this.row)continue;const d=this.points[f].findIndex(x=>x.x===i);if(d===-1)continue;const h=this.points[f][d].y,y=n==="UPWARD"?h>this.points[this.row][this.col].y:h<this.points[this.row][this.col].y,b=Math.abs(h-this.points[this.row][this.col].y);y&&b<s&&(s=b,o=f)}return o}findColumnByXValue(n,i){return this.points[n].findIndex(o=>o.x===i)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const i=[];let o=!0;for(let s=0;s<n.length;s++){const f=Ht.selectElement(n[s],!1);if(!f){i.push([]);continue}const d=[];if(f instanceof SVGPathElement){const b=f.getAttribute(ge.D)||ge.EMPTY;P7.lastIndex=0;let x=P7.exec(b);for(;x!==null;)d.push({x:Number.parseFloat(x[1]),y:Number.parseFloat(x[2])}),x=P7.exec(b)}else if(f instanceof SVGPolylineElement){const x=(f.getAttribute(ge.POINTS)||ge.EMPTY).split(/\s+/).filter(Boolean);for(const T of x){const[w,C]=T.split(ge.COMMA);d.push({x:Number.parseFloat(w),y:Number.parseFloat(C)})}}if(d.length!==this.lineValues[s].length)if(d.length<this.lineValues[s].length)for(;d.length<this.lineValues[s].length;)d.push({x:Number.NaN,y:Number.NaN});else d.length>this.lineValues[s].length&&(d.length=this.lineValues[s].length);const h=[];let y=!1;for(const b of d){if(Number.isNaN(b.x)||Number.isNaN(b.y)){y=!0;break}h.push(Ht.createCircleElement(b.x,b.y,f))}if(y){i.push([]);continue}h.length>0&&(o=!1),i.push(h)}return o?null:i}get state(){const n=super.state;if(n.empty)return n;const i=this.points.length>1,o={...n,plotType:i?"multiline":"single line",...i&&{groupCount:this.points.length}},s=this.findIntersections();return s.length>1?{...o,intersections:s}:o}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}getExtremaTargets(){const n=[],i=this.row;if(i<0||i>=this.lineValues.length)return n;const o=this.lineValues[i];if(!o||o.length===0)return n;const s=this.min[i],f=this.max[i],d=[],h=[];for(let y=0;y<o.length;y++){const b=o[y];b===f&&d.push(y),b===s&&h.push(y)}for(const y of d)n.push({label:`Max point at ${this.getPointLabel(y)}`,value:f,pointIndex:y,segment:"line",type:"max",navigationType:"point"});for(const y of h)n.push({label:`Min point at ${this.getPointLabel(y)}`,value:s,pointIndex:y,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:i}=this.getSafeIndices();this.row=n,this.col=i}getAvailableXValues(){return this.points[this.row].map(n=>n.x)}moveToXValue(n){return this.isInitialEntry&&this.movable.handleInitialEntry(),super.moveToXValue(n)}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.lineValues.length)return!1;const s=this.lineValues[o];if(!s||s.length===0)return!1;const f=this.col,d=n==="right"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){if(this.compare(s[h],s[f],i))return this.col=h,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}compare(n,i,o){return o==="lower"?n<i:o==="higher"?n>i:!1}moveUpRotor(n){return this.moveOnce("UPWARD"),!0}moveDownRotor(n){return this.moveOnce("DOWNWARD"),!0}}class WB extends Fl{constructor(n){super(n);H(this,"mode");H(this,"movable");H(this,"supportsExtrema",!1);H(this,"xPoints");H(this,"yPoints");H(this,"xValues");H(this,"yValues");H(this,"highlightXValues");H(this,"highlightYValues");H(this,"highlightCenters");H(this,"minX");H(this,"maxX");H(this,"minY");H(this,"maxY");this.mode="column";const i=n.data,o=[...i].sort((h,y)=>h.x-y.x||h.y-y.y);this.xPoints=new Array;let s=null;for(const h of o)(!s||s.x!==h.x)&&(s={x:h.x,y:[]},this.xPoints.push(s)),s.y.push(h.y);const f=[...i].sort((h,y)=>h.y-y.y||h.x-y.x);this.yPoints=new Array;let d=null;for(const h of f)(!d||d.y!==h.y)&&(d={y:h.y,x:[]},this.yPoints.push(d)),d.x.push(h.x);this.xValues=this.xPoints.map(h=>h.x),this.yValues=this.yPoints.map(h=>h.y),this.minX=Ba.safeMin(this.xValues),this.maxX=Ba.safeMax(this.xValues),this.minY=Ba.safeMin(this.yValues),this.maxY=Ba.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new jB(this.xPoints,this.yPoints)}dispose(){this.movable.dispose(),this.xPoints.length=0,this.yPoints.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightYValues.length=0),super.dispose()}get highlightValues(){return this.movable.mode==="col"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}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 braille(){return{empty:!1,id:this.id,values:this.values,min:0,max:0,row:this.row,col:this.col}}get audio(){if(this.movable.mode==="col"){const n=this.xPoints[this.col];return{freq:{raw:n.y,min:this.minY,max:this.maxY},panning:{y:this.row,x:this.col,rows:n.y.length,cols:this.xPoints.length}}}else{const n=this.yPoints[this.row];return{freq:{raw:n.x,min:this.minX,max:this.maxX},panning:{y:this.row,x:this.col,rows:this.yPoints.length,cols:n.x.length}}}}get text(){if(this.movable.mode==="col"){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 dimension(){return{rows:this.yPoints.length,cols:this.xPoints.length}}get highlight(){if(this.highlightValues===null)return this.outOfBoundsState;const n=this.movable.mode==="col"?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}:this.outOfBoundsState}get 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],i=n.y[Math.floor(n.y.length/2)],o=this.yValues.indexOf(i);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(i);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;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}}return this.notifyStateUpdate(),!0}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}return this.notifyStateUpdate(),!0}moveToIndex(n,i){return this.mode==="column"?n>=0&&n<this.xPoints.length?(this.col=n,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):i>=0&&i<this.yPoints.length?(this.col=i,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}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 i=Ht.selectAllElements(n);if(i.length===0)return[null,null];const o=new Map,s=new Map;i.forEach(h=>{const y=Number.parseFloat(h.getAttribute("x")||""),b=Number.parseFloat(h.getAttribute("y")||"");Number.isNaN(y)||(o.has(y)||o.set(y,[]),o.get(y).push(h)),Number.isNaN(b)||(s.has(b)||s.set(b,[]),s.get(b).push(h))});const f=Array.from(o.entries()).sort(([h],[y])=>h-y).map(([h,y])=>y),d=Array.from(s.entries()).sort(([h],[y])=>y-h).map(([h,y])=>y);return[f,d]}mapSvgElementsToCenters(){const n=this.highlightXValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){this.mode="column";const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}}const OC="Sum",QB="Level",KB="undefined";class ZB extends U7{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let s=0;s<this.barValues[0].length;s++){const f=this.barValues.reduce((h,y)=>h+y[s],0);t.push(f);const d=this.orientation===Rn.VERTICAL?{x:this.points[0][s].x,y:f,fill:OC}:{x:f,y:this.points[0][s].y,fill:OC};n.push(d)}this.points.push(n),this.barValues.push(t);const{min:i,max:o}=Ba.minMax(t);this.min.push(i),this.max.push(o)}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.min[n],o=this.max[n],s=this.barValues[n];if(!s||s.length===0)return t;const f=s.indexOf(o),d=s.indexOf(i),h=this.getGroupLabel(n),y=this.getCategoryLabel(f),b=this.getCategoryLabel(d);return t.push({label:`Max ${h} at ${y}`,value:o,pointIndex:f,segment:h,type:"max",groupIndex:n,categoryIndex:f,navigationType:"group"}),t.push({label:`Min ${h} at ${b}`,value:i,pointIndex:d,segment:h,type:"min",groupIndex:n,categoryIndex:d,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===Rn.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}get text(){return{...super.text,fill:{label:QB,value:this.points[this.row][this.col].fill??KB}}}get highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}mapToSvgElements(t){var o;if(!t)return new Array;const n=Ht.selectAllElements(t);if(n.length===0)return new Array;const i=new Array;if(n[0]instanceof SVGPathElement)for(let s=0,f=0;s<this.barValues.length;s++){const d=new Array;for(let h=0;h<this.barValues[s].length;h++){if(f>=n.length)return new Array;this.barValues[s][h]===0?d.push(Ht.createEmptyElement()):d.push(n[f++])}i.push(d)}else if(n[0]instanceof SVGRectElement){for(let f=0;f<this.barValues.length;f++)i.push(new Array);const s=((o=this.layer.domMapping)==null?void 0:o.groupDirection)==="forward";for(let f=0,d=0;f<this.barValues[0].length;f++)if(s)for(let h=0;h<this.barValues.length;h++){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}else for(let h=this.barValues.length-1;h>=0;h--){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}}return i}}class j7 extends CC{constructor(t){super(t)}get state(){const t=super.state;return t.empty?t:{...t,plotType:"smooth"}}get audio(){const t=this.lineValues[this.row],n=f=>t[Math.max(0,Math.min(f,t.length-1))],i=n(this.col-1),o=n(this.col),s=n(this.col+1);return{freq:{min:this.min[this.row],max:this.max[this.row],raw:[i,o,s]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0}}}class JB extends j7{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let i=!0;for(let s=0;s<t.length;s++){const f=Ht.selectElement(t[s],!1);if(!f){n.push([]);continue}const d=(o=this.points)==null?void 0:o[s],h=[];for(const y of d)typeof y.svg_x=="number"&&typeof y.svg_y=="number"&&h.push(Ht.createCircleElement(y.svg_x,y.svg_y,f));h.length>0&&(i=!1),n.push(h)}return i?null:n}}const $7=.001;class eV extends j7{constructor(t){super(t)}isMovable(t){var n;if(Array.isArray(t)){const[i,o]=t;return i>=0&&i<this.points.length&&o>=0&&o<(((n=this.points[i])==null?void 0:n.length)||0)}switch(t){case"FORWARD":return this.row<this.points.length-1;case"BACKWARD":return this.row>0;case"UPWARD":return this.col<this.points[this.row].length-1;case"DOWNWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0}moveOnce(t){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(t))return this.notifyOutOfBounds(),!1;switch(t){case"FORWARD":if(this.row<this.points.length-1){const n=this.row+1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"BACKWARD":if(this.row>0){const n=this.row-1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"UPWARD":case"DOWNWARD":return t==="UPWARD"?this.col<this.points[this.row].length-1?(this.col+=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):this.col>0?(this.col-=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}}mapToSvgElements(t){if(!t||t.length===0)return null;const n=[];let i=!0;const o=t.length===this.points.length;for(let s=0;s<this.points.length;s++){const f=[],d=this.points[s];let h;if(o?h=t[s]:h=t[0],!h){n.push([]);continue}const y=Ht.selectAllElements(h,!1);let b=null;if(y.length>0){const x=y.filter(C=>C instanceof SVGUseElement),T=y.filter(C=>C instanceof SVGPathElement),w=x.length>0?x:T;w.length>0&&(b=w[o?0:s<w.length?s:0])}if(b&&d){for(const x of d){let T,w;const C=x;if(typeof C.svg_x=="number"&&typeof C.svg_y=="number")T=C.svg_x,w=C.svg_y;else if(typeof x.x=="number"&&typeof x.y=="number")T=x.x,w=x.y;else continue;!Number.isNaN(T)&&!Number.isNaN(w)&&f.push(Ht.createCircleElement(T,w,b))}f.length>0&&(i=!1)}n.push(f)}return i?null:n}get text(){const t=this.points[this.row][this.col],n=t.x,i=Number(t.y),o=this.points[this.row],s=t;let f;if(typeof s.width=="number"&&!Number.isNaN(s.width))f=s.width;else{const w=typeof s.svg_y=="number"?s.svg_y:null,C=[];for(const R of o){const _=R,N=Number(R.y),z=typeof _.svg_y=="number"?_.svg_y:null;let B=!1;w!==null&&z!==null?B=Math.abs(z-w)<=1:B=Math.abs(N-i)<=.01,B&&typeof _.svg_x=="number"&&!Number.isNaN(_.svg_x)&&C.push(_.svg_x)}if(C.length>=2){const R=Math.min(...C),_=Math.max(...C);f=Math.abs(_-R)}}const d=T=>Math.round(T*1e4)/1e4,h=d(i),y=f!==void 0&&f>0?d(f):void 0;let b;if(typeof n=="string")b=n;else{const T=o[0];T&&typeof T.x=="string"?b=T.x:b=`Category ${this.row}`}const x={main:{label:this.xAxis,value:b},cross:{label:this.yAxis,value:h}};return y!==void 0&&(x.fill={label:"volume",value:String(y)}),x}get audio(){const n=this.points[0];if(!n||n.length===0)return super.audio;const i=n.map(z=>z.density??z.width??0),o=i.filter(z=>z>0);if(o.length===0)return super.audio;const s=Math.min(...o),f=i.length>0?Math.max(...i):0,d=s===f?Math.max(0,s-$7):s,h=s===f?f+$7:f,y=Math.min(this.col,i.length-1),b=z=>i[Math.max(0,Math.min(z,i.length-1))],x=y>0?b(y-1):b(y),T=b(y),w=y<i.length-1?b(y+1):b(y),C=this.points[this.row],R=C?Math.min(this.col,C.length-1):0,_=C==null?void 0:C[R];let N=1;if(_){const z=_.density??_.width??0,B=C.map(Y=>Y.density??Y.width??0),V=B.filter(Y=>Y>0),I=V.length>0?Math.min(...V):0,P=B.length>0?Math.max(...B):0;if(P>0&&typeof z=="number"&&z>0){const Y=I===P?P+$7:P;N=z/Y}}return{freq:{min:d,max:h,raw:[x,T,w]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0,volumeScale:N}}getCurrentXValue(){return this.row>=0&&this.row<this.points.length?this.row:null}moveToXValue(t){var s;this.isInitialEntry&&this.handleInitialEntry();const n=this.points;if(!n||!n.length)return!1;const i=Math.floor(t);if(i<0||i>=n.length)return!1;const o=this.row;if(this.row=i,i!==o)this.col=0;else{const f=(s=n[i])!=null&&s.length?n[i].length-1:0;this.col=Math.min(this.col,f)}return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}getCurrentYValue(){const t=this.lineValues[this.row];if(!t||t.length===0)return null;if(this.col>=0&&this.col<t.length){const n=t[this.col];return typeof n=="number"?n:null}return null}moveToXAndYValue(t,n){if(typeof t!="number")return!1;const i=Math.floor(t);if(i<0||i>=this.lineValues.length)return!1;this.row=i;const o=this.lineValues[this.row];if(!o||o.length===0)return this.col=0,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;let s=0,f=Math.abs(o[0]-n);for(let d=1;d<o.length;d++){const h=Math.abs(o[d]-n);h<f&&(f=h,s=d)}return this.col=s,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}onSwitchFrom(t){var f;const n=t;if(!((n.type||((f=n.state)==null?void 0:f.traceType))==="box"))return!1;const s=t.getCurrentXValue();if(t.getCurrentYValue){const d=t.getCurrentYValue();if(d!==null&&s!==null&&this.moveToXAndYValue){const h=this.moveToXAndYValue(s,d);return h&&(this.isInitialEntry=!1),h}}if(s!==null){const d=this.moveToXValue(s);return d&&(this.isInitialEntry=!1),d}return!1}}function tV(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function nV(e,t=!1){return t&&e.type===or.SMOOTH?new eV(e):Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&tV(e.data[0][0])?new JB(e):new j7(e)}class rV{static create(t,n){const i=(n==null?void 0:n.isViolinPlot)===!0;switch(t.type){case or.BAR:return new $B(t);case or.BOX:return new HB(t,i);case or.CANDLESTICK:return new GB(t);case or.HEATMAP:return new YB(t);case or.HISTOGRAM:return new XB(t);case or.LINE:return new CC(t);case or.SCATTER:return new WB(t);case or.SMOOTH:return nV(t,i);case or.DODGED:case or.NORMALIZED:case or.STACKED:return new ZB(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const iV="MAIDR Plot",aV="unavailable",oV="unavailable";class lV extends B7{constructor(n){super();H(this,"id");H(this,"movable");H(this,"title");H(this,"subtitle");H(this,"caption");H(this,"subplots");H(this,"size");this.id=n.id,this.title=n.title??iV,this.subtitle=n.subtitle??aV,this.caption=n.caption??oV;const i=n.subplots;this.subplots=i.map(o=>o.map(s=>new sV(s))),this.size=this.subplots.reduce((o,s)=>o+s.length,0),this.movable=new Pm(this.subplots,{row:this.subplots.length-1})}get dimension(){return{rows:this.subplots.length,cols:this.subplots[this.row].length}}dispose(){this.subplots.forEach(n=>n.forEach(i=>i.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((o,s)=>o+s.length,0),i=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:i.getStateWithFigurePosition(this.row,this.col),traceTypes:i.traceTypes,highlight:this.highlight}}get highlight(){var i;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}};try{const o=((i=this.subplots[0])==null?void 0:i.length)||1,s=this.row*o+this.col+1,f=`g[id="axes_${s}"]`,d=document.querySelector(f);if(d)return{empty:!1,elements:d};const h=document.querySelectorAll('g[id^="axes_"]');if(h.length>0&&s-1<h.length)return{empty:!1,elements:h[s-1]}}catch{return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}moveToPoint(n,i){this.notifyStateUpdate()}get outOfBoundsState(){return{empty:!0,type:"figure"}}}class sV extends B7{constructor(n){super();H(this,"movable");H(this,"traces");H(this,"traceTypes");H(this,"size");H(this,"highlightValue");H(this,"isViolinPlot");const i=n.layers;this.size=i.length;const o=i.map(h=>h.type),s=o.includes(or.BOX),f=o.includes(or.SMOOTH),d=s&&f;this.isViolinPlot=d,this.traces=i.map(h=>[rV.create(h,{isViolinPlot:d})]),this.traceTypes=this.traces.flat().map(h=>{const y=h.state;return y.empty?ge.EMPTY:y.traceType}),this.highlightValue=this.mapToSvgElement(n.selector),this.movable=new Pm(this.traces)}get dimension(){return{rows:this.values.length,cols:this.values[this.row].length}}dispose(){this.traces.forEach(n=>n.forEach(i=>i.dispose())),this.traces.length=0,super.dispose()}getRow(){return this.row}getSize(){return this.size}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}moveOnce(n){return this.isViolinPlot?(this.isInitialEntry&&(this.isInitialEntry=!1),super.moveOnce(n)):super.moveOnce(n)}get state(){return{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight}}get outOfBoundsState(){return{empty:!0,type:"subplot"}}get highlight(){return this.highlightValue===null?{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.values.length,cols:this.values[this.row].length}}:{empty:!1,elements:this.highlightValue}}moveToPoint(n,i){this.notifyStateUpdate()}getStateWithFigurePosition(n,i){return this.state}mapToSvgElement(n){return n?Ht.selectElement(n)??null:null}}const Va={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},Vg=class Vg{constructor(){H(this,"basePalette");H(this,"extendedPalette");this.basePalette=[{index:Va.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:Va.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:Va.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:Va.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:Va.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:Va.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:Va.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:Va.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:Va.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:Va.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:Va.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 i=this.generateExtendedEntry(t);return this.extendedPalette.set(t,i),i}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return Va.SINE_BASIC;case"Bear":return Va.SAWTOOTH_SOFT;case"Neutral":return Va.TRIANGLE_BASIC;default:return Va.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,i)=>{this.extendedPalette.set(this.basePalette.length+i,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,i=this.basePalette[n],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),s=this.generateHarmonics(o),f=this.generateTimbreModulation(o,i.timbreModulation);return{index:t,waveType:i.waveType,harmonicMix:{fundamental:1,harmonics:s},timbreModulation:f}}generateHarmonics(t){const n=[],i=Vg.MIN_HARMONICS+t%Vg.HARMONIC_VARIATION;for(let o=0;o<i;o++){const s=1+(o+1)*(.5+t*.3%1),f=.4/(o+1)*(1-t*.1%.3);n.push({frequency:s,amplitude:f})}return n}generateTimbreModulation(t,n){const i=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*i)),decay:Math.max(.05,Math.min(.3,n.decay*i)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*i))}}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.`)})}};H(Vg,"MIN_HARMONICS",2),H(Vg,"HARMONIC_VARIATION",3);let H7=Vg;const uV=100,cV=440,fV=880,MC=180,RC=.2,dV=.1,q7=.3,US=Va.SINE_BASIC;class hV{constructor(t,n,i){H(this,"notification");H(this,"audioPalette");H(this,"isCombinedAudio");H(this,"mode");H(this,"activeAudioIds");H(this,"volume");H(this,"minFrequency");H(this,"maxFrequency");H(this,"audioContext");H(this,"compressor");this.notification=t,this.audioPalette=new H7,this.isCombinedAudio=!1,this.mode="on",this.updateMode(i),this.activeAudioIds=new Map,this.volume=this.normalizeVolume(n.get("general.volume")),this.minFrequency=n.get("general.minFrequency"),this.maxFrequency=n.get("general.maxFrequency"),n.onChange(o=>{o.affectsSetting("general.volume")&&(this.volume=this.normalizeVolume(o.get("general.volume"))),o.affectsSetting("general.minFrequency")&&(this.minFrequency=o.get("general.minFrequency")),o.affectsSetting("general.maxFrequency")&&(this.maxFrequency=o.get("general.maxFrequency"))}),this.audioContext=new AudioContext,this.compressor=this.initCompressor()}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close())}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const 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"))}update(t){if(this.updateMode(t),this.mode==="off")return;if(t.empty){t.warning?this.playWarningTone():this.playEmptyTone({x:t.audio.x,y:t.audio.y,rows:t.audio.rows,cols:t.audio.cols});return}if(t.type!=="trace")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 i=n.group;n.trend&&i===void 0&&(i=this.audioPalette.getCandlestickGroupIndex(n.trend));const o=i!==void 0?this.audioPalette.getPaletteEntry(i):void 0;if(n.isContinuous)this.playSmooth(n.freq,n.panning,o,n.volumeMultiplier,n.volumeScale);else if(Array.isArray(n.freq.raw)){const s=n.freq.raw;if(s.length===0){this.playZeroTone(n.panning);return}let f=0;const d=this.mode==="on"?50:0,h=new Array,y=()=>{f<s.length?(this.playTone({min:n.freq.min,max:n.freq.max,raw:s[f++]},{x:n.panning.x,y:n.panning.y,rows:n.panning.rows,cols:n.panning.cols},o),h.push(setTimeout(y,d))):this.stop(h)};y()}else n.freq.raw===0?this.playZeroTone(n.panning):this.playTone(n.freq,n.panning,o)}playTone(t,n,i){const o={min:t.min,max:t.max},s={min:this.minFrequency,max:this.maxFrequency},f=this.interpolate(t.raw,o,s),d=this.clamp(this.interpolate(n.x,{min:0,max:n.cols},{min:-1,max:1}),-1,1),h=this.clamp(this.interpolate(n.y,{min:0,max:n.rows},{min:-1,max:1}),-1,1);return this.playOscillator(f,{x:d,y:h},i)}createAdsrEnvelope(t,n,i,o,s){if(n!=null&&n.timbreModulation){const{attack:f,decay:d,sustain:h,release:y}=n.timbreModulation,b=s*f,x=s*d,T=s*y,w=s-b-x-T;return t.gain.setValueAtTime(1e-4*i,o),t.gain.linearRampToValueAtTime(i,o+b),t.gain.linearRampToValueAtTime(h*i,o+b+x),w>0&&t.gain.setValueAtTime(h*i,o+b+x+w),t.gain.linearRampToValueAtTime(1e-4*i,o+s),null}else return[.5*i,i,.5*i,.5*i,.5*i,.1*i,1e-4*i]}playOscillator(t,n={x:0,y:0},i){const o=q7,s=this.audioContext.currentTime;i||(i=this.audioPalette.getPaletteEntry(US));const f=[],d=[],h=this.audioContext.createOscillator();if(h.type=i.waveType,h.frequency.value=t,f.push(h),i.harmonicMix)for(const T of i.harmonicMix.harmonics){const w=this.audioContext.createOscillator();w.type=i.waveType,w.frequency.value=T.frequency*t,f.push(w)}for(let T=0;T<f.length;T++){const w=this.audioContext.createGain();let C=this.volume;if(T===0)i.harmonicMix&&(C*=i.harmonicMix.fundamental);else{const _=i.harmonicMix.harmonics[T-1];C*=_.amplitude}const R=this.createAdsrEnvelope(w,i,C,s,o);R!==null&&w.gain.setValueCurveAtTime(R,s,o),d.push(w)}const y=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"linear",positionX:n.x,positionY:n.y,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});for(let T=0;T<f.length;T++)f[T].connect(d[T]),d[T].connect(y);y.connect(this.compressor),f.forEach(T=>T.start(s));const b=T=>{y.disconnect();for(let w=0;w<f.length;w++)f[w].stop(),f[w].disconnect(),d[w].disconnect();this.activeAudioIds.delete(T)},x=setTimeout(()=>b(x),o*1e3*2);return this.activeAudioIds.set(x,f),x}playSmooth(t,n,i,o,s){const f=this.audioContext,d=f.currentTime,h=q7,y=t.raw.map(V=>this.interpolate(V,{min:t.min,max:t.max},{min:this.minFrequency,max:this.maxFrequency})),b=this.volume;let x;s!==void 0?x=b*Math.max(0,s):x=b*(o??1),y.length<2&&y.push(y[0]);const T=this.clamp(this.interpolate(n.x,{min:0,max:n.cols-1},{min:-1,max:1}),-1,1),w=this.clamp(this.interpolate(n.y,{min:0,max:n.rows-1},{min:-1,max:1}),-1,1),C=(i==null?void 0:i.waveType)||"sine",R=f.createOscillator();R.type=C,R.frequency.setValueCurveAtTime(y,d,h);const _=f.createGain(),N=this.createAdsrEnvelope(_,i,x,d,h);N!==null&&_.gain.setValueCurveAtTime(N,d,h);const z=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"linear",positionX:T,positionY:w,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1});R.connect(_),_.connect(z),z.connect(this.compressor),R.start(d),R.stop(d+h);const B=setTimeout(()=>{R.disconnect(),_.disconnect(),z.disconnect(),this.activeAudioIds.delete(B)},h*1e3*2);this.activeAudioIds.set(B,R)}playEmptyTone(t){const n=this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),i=this.interpolate(t.y,{min:0,max:t.rows-1},{min:-1,max:1}),o=this.audioContext,s=o.currentTime,f=.2,d=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"inverse",positionX:n,positionY:i,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1}),h=[500,1e3,1500,2100,2700],y=[1,.6,.4,.2,.1],b=o.createGain();b.gain.setValueAtTime(.3*this.volume,s),b.gain.exponentialRampToValueAtTime(.01*this.volume,s+f),b.connect(d),d.connect(this.compressor);const x=[];for(let C=0;C<h.length;C++){const R=o.createOscillator(),_=o.createGain(),N=this.audioContext.createStereoPanner(),z=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});R.frequency.value=h[C],R.type="sine",_.gain.setValueAtTime(y[C]*this.volume,s),_.gain.exponentialRampToValueAtTime(.001*this.volume,s+f),R.connect(_),_.connect(N),N.connect(z),z.connect(b),R.start(s),R.stop(s+f),x.push(R)}const T=C=>{d.disconnect(),b.disconnect(),x.forEach(R=>{R.disconnect()}),this.activeAudioIds.delete(C)},w=setTimeout(()=>T(w),f*1e3*2);return this.activeAudioIds.set(w,x),w}playOneWarningBeep(t,n){const i=this.audioContext.createOscillator(),o=this.audioContext.createGain();i.type="sine",i.frequency.value=t;let s=1;i.type!=="sine"&&(s=.5),o.gain.setValueAtTime(s,n),o.gain.exponentialRampToValueAtTime(.001,n+RC),i.connect(o),o.connect(this.audioContext.destination),i.start(n),i.stop(n+RC)}playWarningTone(){const t=this.audioContext.currentTime;this.playOneWarningBeep(MC,t),this.playOneWarningBeep(MC/2**(1/12),t+dV)}playWarningToneIfEnabled(){this.mode!=="off"&&this.playWarningTone()}playZeroTone(t){const n=this.clamp(this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),-1,1),i=this.clamp(this.interpolate(t.y,{min:0,max:t.rows-1},{min:-1,max:1}),-1,1);return this.playOscillator(uV,{x:n,y:i},{index:US,waveType:"triangle"})}playWaitingTone(){const t=this.audioPalette.getPaletteEntry(US);return setInterval(()=>this.playOscillator(cV,{x:0,y:0},t),1e3)}playCompleteTone(){const t=this.audioPalette.getPaletteEntry(US);return this.playOscillator(fV,{x:0,y:0},t)}playSimultaneousTones(t){const n=q7,i=this.audioContext,o=i.currentTime,s=Array.isArray(t[0].freq.raw)?t[0].freq.raw[1]??t[0].freq.raw[0]:t[0].freq.raw,f=this.interpolate(s,{min:t[0].freq.min,max:t[0].freq.max},{min:this.minFrequency,max:this.maxFrequency});t.forEach((d,h)=>{const b=this.audioPalette.getPaletteEntry(d.group??h).waveType,x=i.createOscillator();x.type=b,x.frequency.value=f;const T=i.createGain();T.gain.setValueAtTime(this.volume,o),T.gain.exponentialRampToValueAtTime(.01*this.volume,o+n),x.connect(T),T.connect(this.compressor),x.start(o),x.stop(o+n);const w=setTimeout(()=>{x.disconnect(),T.disconnect(),this.activeAudioIds.delete(w)},n*1e3*2);this.activeAudioIds.set(w,[x])})}interpolate(t,n,i){return n.min===n.max?i.min:(t-n.min)/(n.max-n.min)*(i.max-i.min)+i.min}clamp(t,n,i){return Math.max(n,Math.min(t,i))}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(i=>{const o=this.activeAudioIds.get(i);if(!o){clearInterval(i);return}(Array.isArray(o)?o:[o]).forEach(f=>{f==null||f.disconnect(),f==null||f.stop()}),clearTimeout(i),this.activeAudioIds.delete(i)})}stopAll(){this.activeAudioIds.forEach((t,n)=>{clearTimeout(n),(Array.isArray(t)?t:[t]).forEach(o=>{o.disconnect(),o.stop()})}),this.activeAudioIds.clear()}normalizeVolume(t){return t/100*(t/100)}}const pV=250,mV=50,gV=500,_C=20;class yV{constructor(t,n,i){H(this,"context");H(this,"notification");H(this,"settings");H(this,"autoplayId");H(this,"currentDirection");H(this,"userSpeed");H(this,"defaultSpeed");H(this,"minSpeed");H(this,"maxSpeed");H(this,"autoplayRate");H(this,"interval");H(this,"totalDuration");H(this,"onChangeEmitter");H(this,"onChange");this.notification=n,this.context=t,this.settings=i,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=pV,this.minSpeed=mV,this.maxSpeed=gV,this.interval=_C,this.autoplayRate=this.defaultSpeed,this.interval=_C,this.totalDuration=i.get("general.autoplayDuration"),i.onChange(o=>{o.affectsSetting("general.autoplayDuration")&&(this.totalDuration=o.get("general.autoplayDuration"),this.restart())}),this.onChangeEmitter=new Md,this.onChange=this.onChangeEmitter.event}dispose(){this.stop(),this.onChangeEmitter.dispose()}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 i=Math.ceil(this.totalDuration/n.autoplay[t]);return this.defaultSpeed=i,this.minSpeed=Math.min(this.minSpeed,i),i}return this.defaultSpeed}}const DC=32;class gv{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const f=(t.max[s]-t.min[s])/4,d=t.min[s]+f,h=d+f,y=h+f;for(let b=0;b<t.values[s].length;b++)t.values[s][b]===0?n.push(" "):t.values[s][b]<=d||t.values[s][b]<=h?n.push("⠤"):t.values[s][b]<=y?n.push("⠒"):n.push("⠉"),i[s].push(o.length),o.push({row:s,col:b});n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class vV{constructor(){H(this,"GLOBAL_MIN","globalMin");H(this,"GLOBAL_MAX","globalMax");H(this,"BLANK","blank");H(this,"LOWER_OUTLIER","lowerOutlier");H(this,"UPPER_OUTLIER","upperOutlier");H(this,"MIN","min");H(this,"MAX","max");H(this,"Q1","q1");H(this,"Q2","q2");H(this,"Q3","q3")}encode(t,n=DC){const i=new Array,o=new Array,s=new Array;for(let f=0;f<t.values.length;f++){const d=t.values[f],h=[{type:this.GLOBAL_MIN,value:t.min},...d.lowerOutliers.map(Y=>({type:this.LOWER_OUTLIER,value:Y})),{type:this.MIN,value:d.min},{type:this.Q1,value:d.q1},{type:this.Q2,value:d.q2},{type:this.Q3,value:d.q3},{type:this.MAX,value:d.max},...d.upperOutliers.map(Y=>({type:this.UPPER_OUTLIER,value:Y})),{type:this.GLOBAL_MAX,value:t.max}],y=new Array;let b=!0;for(let Y=0;Y<h.length-1;Y++){const se=h[Y],ue=h[Y+1],re=Math.abs(b?ue.value-se.value:se.value-h[Y-1].value);se.type===this.LOWER_OUTLIER||se.type===this.UPPER_OUTLIER?(y.push({type:se.type,length:0,numChars:1}),y.push({type:this.BLANK,length:re,numChars:0})):se.type===this.Q2?(b=!1,y.push({type:this.Q2,length:0,numChars:2})):se.type===this.GLOBAL_MIN||se.type===this.GLOBAL_MAX?y.push({type:this.BLANK,length:re,numChars:0}):y.push({type:se.type,length:re,numChars:1})}let x=y.reduce((Y,se)=>Y+(se.numChars>0?se.numChars:0),0),[T,w,C,R]=[-1,-1,-1,-1];for(let Y=0;Y<y.length;Y++)y[Y].type===this.MIN&&y[Y].length>0&&(T=Y),y[Y].type===this.MAX&&y[Y].length>0&&(w=Y),y[Y].type===this.Q1&&(C=Y),y[Y].type===this.Q3&&(R=Y);T!==-1&&w!==-1&&y[T].length!==y[w].length&&(y[T].length>y[w].length?(y[T].numChars++,x++):(y[w].numChars++,x++)),C!==-1&&R!==-1&&y[C].length!==y[R].length&&(y[C].length>y[R].length?(y[C].numChars++,x++):(y[R].numChars++,x++));const _=Math.max(0,n-x),N=y.reduce((Y,se)=>Y+(se.type!==this.Q2&&se.length>0?se.length:0),0);for(const Y of y)if(Y.type!==this.Q2&&Y.length>0){const se=Math.round(Y.length/N*_);Y.numChars+=se}const z=y.reduce((Y,se)=>Y+se.numChars,0);let B=n-z,V=0;for(;B!==0;){const Y=y[V%y.length];Y.type!==this.BLANK&&Y.type!==this.Q2&&Y.length>0&&(Y.numChars+=B>0?1:-1,B+=B>0?-1:1),V++}let I=-1;const P=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];s.push(Array.from({length:P.length}).fill(-1));for(const Y of y){Y.type!==this.BLANK&&Y.type!==this.GLOBAL_MIN&&Y.type!==this.GLOBAL_MAX&&(I=P.indexOf(Y.type),s[f][I]=i.length);for(let se=0;se<Y.numChars;se++){let ue="⠀";Y.type===this.MIN||Y.type===this.MAX?ue="⠒":Y.type===this.Q1||Y.type===this.Q3?ue="⠿":Y.type===this.Q2?ue=se===0?"⠸":"⠇":Y.type===this.LOWER_OUTLIER||Y.type===this.UPPER_OUTLIER?ue="⠂":Y.type===this.BLANK&&(ue="⠀"),i.push(ue),o.push({row:f,col:I})}}for(let Y=0;Y<3;Y++)if(s[f][Y]===-1){for(let se=Y+1;se<=3;se++)if(s[f][se]!==-1){s[f][Y]=s[f][se];break}}for(let Y=6;Y>3;Y--)if(s[f][Y]===-1){for(let se=Y-1;se>=3;se--)if(s[f][se]!==-1){s[f][Y]=s[f][se];break}}i.push(ge.NEW_LINE),o.push({row:f,col:I})}return{value:i.join(ge.EMPTY),cellToIndex:s,indexToCell:o}}}class bV{encode(t){const n=new Array,i=new Array,o=new Array,s=(t.max-t.min)/3,f=t.min+s,d=f+s;for(let h=0;h<t.values.length;h++){i.push(new Array);for(let y=0;y<t.values[h].length;y++)t.values[h][y]===0?n.push(" "):t.values[h][y]<=f?n.push("⠤"):t.values[h][y]<=d?n.push("⠒"):n.push("⠉"),i[h].push(o.length),o.push({row:h,col:y});n.push(ge.NEW_LINE),i[h].push(o.length),o.push({row:h,col:t.values[h].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class kC{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const{low:f,medium:d,mediumHigh:h,high:y}=this.getThresholds(s,t);for(let b=0;b<t.values[s].length;b++){const x=t.values[s][b],T=b>0?t.values[s][b-1]:null,w=this.getBrailleChar(x,T,f,d,y,h);n.push(w),i[s].push(o.length),o.push({row:s,col:b})}n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}getBrailleChar(t,n,i,o,s,f){return f===void 0&&(f=s),t<=i&&n!==null&&n>i?n<=o?"⢄":n<=f?"⢆":"⢇":t<=i?"⣀":n!==null&&n<=i?t<=o?"⡠":t<=f?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=f?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=f?"⠔":"⠜":t<=f&&n!==null&&n>f?"⠑":t<=f?"⠒":n!==null&&n<=f?"⠊":t<=s?"⠉":""}getBraille6Char(t,n,i,o,s){const f=x=>x<=i?"low":x<=o?"medium":(x<=s,"high"),d=f(t),h=n!==null?f(n):null,y={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},b=`${d},${h}`;return y[b]||""}addDot8(t){if(!t||t.length===0)return"⢀";const o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class SV extends kC{getThresholds(t,n){const i=Array.isArray(n.min)?n.min[t]:n.min,o=Array.isArray(n.max)?n.max[t]:n.max,s=(o-i)/3,f=i+s,d=f+s;return{low:f,medium:d,high:o}}encode(t){var s;const n=new Array,i=new Array,o=new Array;for(let f=0;f<t.values.length;f++){i.push(new Array);const{low:d,medium:h,high:y}=this.getThresholds(f,t);for(let b=0;b<t.values[f].length;b++){const x=t.values[f][b],T=b>0?t.values[f][b-1]:null;let w=this.getBraille6Char(x,T,d,h,y);((s=t.custom)==null?void 0:s[b])==="Bear"&&(w=this.addDot8(w)),n.push(w),i[f].push(o.length),o.push({row:f,col:b})}n.push(ge.NEW_LINE),i[f].push(o.length),o.push({row:f,col:t.values[f].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class NC extends kC{getThresholds(t,n){const i=(n.max[t]-n.min[t])/4,o=n.min[t]+i,s=o+i,f=s+i,d=n.max[t];return{low:o,medium:s,mediumHigh:f,high:d}}}class xV{constructor(t,n,i){H(this,"context");H(this,"notification");H(this,"display");H(this,"enabled");H(this,"cacheId");H(this,"cache");H(this,"encoders");H(this,"onChangeEmitter");H(this,"onChange");this.context=t,this.notification=n,this.display=i,this.enabled=!1,this.cacheId=ge.EMPTY,this.cache=null,this.encoders=new Map([[or.BAR,new gv],[or.BOX,new vV],[or.CANDLESTICK,new SV],[or.DODGED,new gv],[or.HEATMAP,new bV],[or.HISTOGRAM,new gv],[or.LINE,new NC],[or.NORMALIZED,new gv],[or.SMOOTH,new NC],[or.STACKED,new gv]]),this.onChangeEmitter=new Md,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 i=n.braille;if(this.cache===null||this.cacheId!==i.id){const o=this.encoders.get(n.traceType);this.cache=o.encode(i,DC),this.cacheId=i.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[i.row][i.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:i}=this.cache.indexToCell[t];this.context.moveToIndex(n,i)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const i=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(i);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(fn.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var zC=(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))(zC||{});class IC{constructor(){}static async post(t,n,i){const o={...this.DEFAULT_HEADERS,...i};return this.request(t,"POST",o,n)}static async request(t,n,i,o){try{const s=await fetch(t,{method:n,headers:i,body:o});return s.ok?{success:!0,data:await s.json()}:{success:!1,error:{statusCode:s.status,message:`API Error: ${s.status} - ${s.statusText}`}}}catch(s){return console.error(`Error in API ${n} request to ${t}:`,s),{success:!1,error:{statusCode:zC.SERVER_ERROR,message:s instanceof Error?s.message:"Unknown error occurred"}}}}}H(IC,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const EV=`You are a helpful assistant that answers questions about statistical visualizations. Your role is to:
|
|
307
|
+
S for Sonification, and R for Review mode.`;case"trace":{let o=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(o="single line");const s=o==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${o}${s}. ${i} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}class VS{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[5],16)}}const i=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return i?{r:Number.parseInt(i[1],10),g:Number.parseInt(i[2],10),b:Number.parseInt(i[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const i=this.calculateLuminance(t),o=this.calculateLuminance(n);return(Math.max(i,o)+.05)/(Math.min(i,o)+.05)}static calculateLuminance(t){const[n,i,o]=[t.r,t.g,t.b].map(s=>{const f=s/255;return f<=.03928?f/12.92:((f+.055)/1.055)**2.4});return .2126*n+.7152*i+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}static isEqual(t,n){const i=this.parse(t),o=this.parse(n);return!i||!o?!1:i.r===o.r&&i.g===o.g&&i.b===o.b}}class Ht{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,s=await new Promise((h,y)=>{const b=new Image;b.onload=()=>h(b),b.onerror=()=>y(new Error("Failed to load SVG image")),b.src=o}),f=document.createElement("canvas");[f.width,f.height]=[s.naturalWidth,s.naturalHeight];const d=f.getContext("2d");return d?(d.drawImage(s,0,0),f.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(i=>{if(!n)return i;const o=i.cloneNode(!0);return o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i.insertAdjacentElement(ge.AFTER_END,o),o})}static selectElement(t,n=!0){const i=document.querySelector(t);if(!n)return i;const o=i==null?void 0:i.cloneNode(!0);return o==null||o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i==null||i.insertAdjacentElement(ge.AFTER_END,o),o}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(ge.FILL,ge.TRANSPARENT),n.setAttribute(ge.STROKE,ge.TRANSPARENT),n.setAttribute(ge.VISIBILITY,ge.HIDDEN),n}static createCircleElement(t,n,i){var y;const o=window.getComputedStyle(i),s=o.stroke||o.fill,f=o.strokeWidth||"2",d=Number.parseFloat(f)*2,h=document.createElementNS(this.SVG_NAMESPACE,ge.CIRCLE);return h.setAttribute(ge.CIRCLE_X,String(t)),h.setAttribute(ge.CIRCLE_Y,String(n)),h.setAttribute(ge.RADIUS,String(d)),h.setAttribute(ge.FILL,s),h.setAttribute(ge.STROKE,s),h.setAttribute(ge.STROKE_WIDTH,f),h.setAttribute(ge.VISIBILITY,ge.HIDDEN),(y=i.parentElement)==null||y.insertAdjacentElement(ge.AFTER_END,h),h}static createLineElement(t,n){const o=t.getBBox();let s,f,d,h;switch(n){case"top":[s,f,d,h]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[s,f,d,h]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[s,f,d,h]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[s,f,d,h]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const y=window.getComputedStyle(t),b=document.createElementNS(this.SVG_NAMESPACE,ge.LINE);return b.setAttribute(ge.X1,String(s)),b.setAttribute(ge.Y1,String(f)),b.setAttribute(ge.X2,String(d)),b.setAttribute(ge.Y2,String(h)),b.setAttribute(ge.STROKE,y.stroke),b.setAttribute(ge.STROKE_WIDTH,y.strokeWidth||"2"),b.setAttribute(ge.VISIBILITY,ge.HIDDEN),t.insertAdjacentElement(ge.AFTER_END,b),b}static getAdjustedOpacity(t,n){const i=t?Number.parseFloat(t):Number.NaN;return!Number.isNaN(i)&&i>n?i.toString():"1"}static createHighlightElement(t,n){const i=t.cloneNode(!0),o=t.tagName.toLowerCase(),s=o===ge.POLYLINE||o===ge.LINE,f=window.getComputedStyle(t),d=s?f.getPropertyValue(ge.STROKE):f.getPropertyValue(ge.FILL),h=this.getHighlightColor(d,n),y=f.getPropertyValue("fill-opacity"),b=f.getPropertyValue("stroke-opacity");if(i.style.fillOpacity=this.getAdjustedOpacity(y,this.MIN_VISIBLE_FILL_OPACITY),i.style.strokeOpacity=this.getAdjustedOpacity(b,this.MIN_VISIBLE_STROKE_OPACITY),i.setAttribute(ge.VISIBILITY,ge.VISIBLE),i.setAttribute(ge.STROKE,h),i.setAttribute(ge.FILL,h),i.style.fill=h,i.style.stroke=h,s){const x=window.getComputedStyle(i).getPropertyValue(ge.STROKE_WIDTH),T=x.match(/^([0-9.]+)([a-z%]*)$/i);if(T){const w=Number.parseFloat(T[1]),C=T[2]||"";i.setAttribute(ge.STROKE_WIDTH,`${w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE}${C}`)}else{const w=Number.parseFloat(x),C=Number.isNaN(w)?this.STROKE_WIDTH_HIGHLIGHT_INCREASE:w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE;i.setAttribute(ge.STROKE_WIDTH,`${C}`)}}return t.insertAdjacentElement(ge.AFTER_END,i),i}static getHighlightColor(t,n){const i=VS.parse(t);if(!i||!(VS.getContrastRatio(i,ge.HIGHLIGHT_BASE_COLOR)<ge.HIGHLIGHT_CONTRAST_RATIO))return n;const f={...i};return i.r===i.g&&i.g===i.b?(f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)),f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)),f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO))):i.r>=i.g&&i.r>=i.b?f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)):i.g>=i.r&&i.g>=i.b?f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)):f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO)),VS.rgbToString(f)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",i=VS.parse(n);return i?(.2126*i.r+.7152*i.g+.0722*i.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,i){const o=t.querySelector("rect, path");let s="";if(o){s=window.getComputedStyle(o).getPropertyValue("fill"),(!s||s==="none"||s==="transparent"||s==="rgba(0, 0, 0, 0)")&&(i?s=window.getComputedStyle(i).getPropertyValue("fill"):s=n);const f=this.getHighlightColor(s,n);o.setAttribute("stroke",f),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}H(Ht,"SVG_NAMESPACE","http://www.w3.org/2000/svg"),H(Ht,"MIN_VISIBLE_FILL_OPACITY",.01),H(Ht,"MIN_VISIBLE_STROKE_OPACITY",.01),H(Ht,"STROKE_WIDTH_HIGHLIGHT_INCREASE",2);const LB="unavailable",BB="X",VB="Y",UB="unavailable";class B7{constructor(){H(this,"observers");H(this,"isWarning");this.observers=new Array,this.isWarning=!1}dispose(){this.observers.length=0}notifyRotorBounds(){this.isWarning=!0,this.notifyStateUpdate(),this.isWarning=!1}get isInitialEntry(){return this.movable.isInitialEntry}set isInitialEntry(t){this.movable.isInitialEntry=t}get isOutOfBounds(){return this.movable.isOutOfBounds}set isOutOfBounds(t){this.movable.isOutOfBounds=t}get row(){return this.movable.row}get col(){return this.movable.col}set row(t){this.movable.row=t}set col(t){this.movable.col=t}getSafeIndices(){const t=this.row>=0&&this.row<this.dimension.rows?this.row:0,n=this.col>=0&&this.col<this.dimension.cols?this.col:0;return{row:t,col:n}}addObserver(t){this.observers.push(t)}removeObserver(t){const n=this.observers.indexOf(t);n!==-1&&this.observers.splice(n,1)}notifyStateUpdate(){const t=this.state;this.observers.forEach(n=>n.update(t))}notifyOutOfBounds(){const t=this.outOfBoundsState;this.observers.forEach(n=>n.update(t))}moveOnce(t){const n=this.movable.moveOnce(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToExtreme(t){const n=this.movable.moveToExtreme(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToIndex(t,n){const i=this.movable.moveToIndex(t,n);return i?this.notifyStateUpdate():this.notifyOutOfBounds(),i}isMovable(t){return this.movable.isMovable(t)}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}moveToNextCompareValue(t,n){return this.notifyRotorBounds(),!1}compare(t,n,i){return i==="lower"?t<n:i==="higher"?t>n:!1}moveUpRotor(t){throw new Error("Move up function is not defined for this trace")}moveDownRotor(t){throw new Error("Move down function is not defined for this trace")}moveLeftRotor(t){throw new Error("Move left function is not defined for this trace")}moveRightRotor(t){throw new Error("Move right function is not defined for this trace")}moveToPoint(t,n){}}class Fl extends B7{constructor(n){var i,o,s;super();H(this,"id");H(this,"type");H(this,"title");H(this,"xAxis");H(this,"yAxis");H(this,"fill");H(this,"navigationService");H(this,"layer");this.layer=n,this.navigationService=new D7,this.id=n.id,this.type=n.type,this.title=n.title??LB,this.xAxis=((i=n.axes)==null?void 0:i.x)??BB,this.yAxis=((o=n.axes)==null?void 0:o.y)??VB,this.fill=((s=n.axes)==null?void 0:s.fill)??UB}dispose(){this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(i=>{(Array.isArray(i)?i:[i]).forEach(s=>s.remove())})),this.highlightValues.length=0),super.dispose()}get state(){return this.isWarning?{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols},warning:!0}:{empty:!1,type:"trace",layerId:this.id,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}}get outOfBoundsState(){return{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols}}}get highlight(){return this.highlightValues===null||this.isInitialEntry?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}getAllHighlightElements(){if(this.highlightValues===null)return[];const n=[];for(const i of this.highlightValues)for(const o of i)Array.isArray(o)?n.push(...o):o&&n.push(o);return n}getAllOriginalElements(){if(this.highlightValues===null)return[];const n=[];for(const i of this.highlightValues)for(const o of i){const s=Array.isArray(o)?o:o?[o]:[];for(const f of s){const d=f.previousElementSibling;d&&d.tagName===f.tagName&&d.getAttribute("visibility")!=="hidden"&&n.push(d)}}return n}getAudioGroupIndex(){return this.values&&this.values.length>1?{groupIndex:this.row}:{}}get autoplay(){return{UPWARD:this.dimension.rows,DOWNWARD:this.dimension.rows,FORWARD:this.dimension.cols,BACKWARD:this.dimension.cols}}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}get 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 i=this.getPointsArray();if(this.isValidPointsArray(i))return this.navigationService.moveToXValueInPoints(i,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const i=this.values;if(this.isValidValuesArray(i))return this.navigationService.moveToXValueInValues(i,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}moveToPoint(n,i){const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}isPointInBounds(n,i,{element:o,row:s,col:f}){const d=o.getBoundingClientRect();let h=12;return(this.type===or.HEATMAP||this.type===or.BAR||this.type===or.STACKED||this.type===or.HISTOGRAM)&&(h=0),n>=d.x-h&&n<=d.x+d.width+h&&i>=d.y-h&&i<=d.y+d.height+h}}class Ba{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],i=t[0];for(let o=1;o<t.length;o++){const s=t[o];s<n&&(n=s),s>i&&(i=s)}return{min:n,max:i}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class V7{constructor(t){H(this,"isInitialEntry");H(this,"isOutOfBounds");H(this,"row");H(this,"col");this.isInitialEntry=(t==null?void 0:t.isInitialEntry)??!0,this.isOutOfBounds=!1,this.row=(t==null?void 0:t.row)??0,this.col=(t==null?void 0:t.col)??0}moveToIndex(t,n){return this.isMovable([t,n])?(this.row=t,this.col=n,this.isInitialEntry=!1,!0):!1}}class Pm extends V7{constructor(n,i){super(i);H(this,"elements");this.elements=n}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;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}return!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":this.row=this.elements.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.col=this.elements[this.row].length-1;break;case"BACKWARD":this.col=0;break}return!0}moveToIndex(n,i){return this.isMovable([n,i])?(this.row=n,this.col=i,this.isInitialEntry=!1,!0):!1}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.elements.length&&o>=0&&o<this.elements[this.row].length}switch(n){case"UPWARD":return this.row<this.elements.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.elements[this.row].length-1;case"BACKWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.elements.length-1)),this.col=Math.max(0,Math.min(this.col,this.elements[this.row].length-1))}}class PB extends V7{constructor(n,i){super(i);H(this,"graph");this.graph=n}moveOnce(n){var s;if(this.isInitialEntry)return this.handleInitialEntry(),!0;const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.up;break;case"DOWNWARD":o=i.down;break;case"FORWARD":o=i.right;break;case"BACKWARD":o=i.left;break}return o?(this.row=o.row,this.col=o.col,!0):!1}moveToExtreme(n){var s;this.isInitialEntry&&this.handleInitialEntry();const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.top;break;case"DOWNWARD":o=i.bottom;break;case"FORWARD":o=i.end;break;case"BACKWARD":o=i.start;break}return o?(this.row=o.row,this.col=o.col,!0):!1}isMovable(n){var o,s,f;if(Array.isArray(n)){const[d,h]=n;return((o=this.graph[d])==null?void 0:o[h])!==null&&((s=this.graph[d])==null?void 0:s[h])!==void 0}const i=(f=this.graph[this.row])==null?void 0:f[this.col];if(!i)return!1;switch(n){case"UPWARD":return i.up!==null;case"DOWNWARD":return i.down!==null;case"FORWARD":return i.right!==null;case"BACKWARD":return i.left!==null}}handleInitialEntry(){this.isInitialEntry=!1,this.isMovable([0,0])?(this.row=0,this.col=0):(this.row=-1,this.col=-1)}}class jB extends V7{constructor(n,i){super();H(this,"mode");H(this,"xPoints");H(this,"yPoints");H(this,"xValues");H(this,"yValues");this.mode="col",this.xPoints=n,this.yPoints=i,this.xValues=n.map(o=>o.x),this.yValues=i.map(o=>o.y)}dispose(){this.xValues.length=0,this.yValues.length=0}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;if(this.mode==="col")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}}return!0}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="col")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}return!0}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="col")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}}toggleNavigation(){if(this.mode==="col"){const n=this.xPoints[this.col],i=n.y[Math.floor(n.y.length/2)];this.row=this.yValues.indexOf(i),this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)];this.col=this.xValues.indexOf(i),this.mode="col"}}handleInitialEntry(){this.isInitialEntry=!1,this.mode==="col"?(this.col=Math.max(0,Math.min(this.col,this.xPoints.length-1)),this.row=Math.max(0,Math.min(this.row,this.xPoints[this.col].y.length-1))):(this.row=Math.max(0,Math.min(this.row,this.yPoints.length-1)),this.col=Math.max(0,Math.min(this.col,this.yPoints[this.row].x.length-1)))}}class U7 extends Fl{constructor(n,i){super(n);H(this,"movable");H(this,"points");H(this,"barValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"orientation");H(this,"min");H(this,"max");H(this,"supportsExtrema",!0);this.points=i,this.orientation=n.orientation??Rn.VERTICAL,this.barValues=i.map(o=>o.map(s=>this.orientation===Rn.VERTICAL?Number(s.y):Number(s.x))),this.min=this.barValues.map(o=>Ba.safeMin(o)),this.max=this.barValues.map(o=>Ba.safeMax(o)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Pm(this.points)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get audio(){const n=this.orientation===Rn.VERTICAL,i=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{freq:{min:Ba.safeMin(this.min),max:Ba.safeMax(this.max),raw:i},panning:{x:n?this.col:this.row,y:n?this.row:this.col,rows:n?this.barValues.length:this.barValues[this.col].length,cols:n?this.barValues[this.row].length:this.barValues.length},group:n?this.row:this.col}}get braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){const n=this.orientation===Rn.VERTICAL,i=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,s=n?i.x:i.y,f=n?this.yAxis:this.xAxis,d=n?i.y:i.x;return{main:{label:o,value:s},cross:{label:f,value:d},mainAxis:n?"x":"y",crossAxis:n?"y":"x"}}get dimension(){return{rows:this.barValues.length,cols:this.barValues[this.row].length}}get values(){return this.barValues}mapToSvgElements(n){if(!n)return null;const i=[Ht.selectAllElements(n)];if(i.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(i[o].length!==this.points[o].length)return null;return i}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();d&&i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}return i}findNearestPoint(n,i){if(!this.highlightValues)return null;for(let o=0;o<this.highlightValues.length;o++)for(let s=0;s<this.highlightValues[o].length;s++){const f=this.highlightValues[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();if(n>=h.x&&n<=h.x+h.width&&i>=h.y&&i<=h.y+h.height)return{element:d,row:o,col:s}}return null}}class $B extends U7{isPointInBounds(t,n,{element:i,row:o,col:s}){const f=i.getBoundingClientRect();return t>=f.x&&t<=f.x+f.width&&n>=f.y&&n<=f.y+f.height}constructor(t){super(t,[t.data])}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.barValues[n];if(!i||i.length===0)return t;const o=this.min[n],s=this.max[n],f=i.indexOf(s),d=i.indexOf(o);return t.push({label:`Max Bar at ${this.getPointLabel(f)}`,value:s,pointIndex:f,segment:"bar",type:"max",navigationType:"point"}),t.push({label:`Min Bar at ${this.getPointLabel(d)}`,value:o,pointIndex:d,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===Rn.VERTICAL?`${n.x}`:`${n.y}`}return`Point ${t}`}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const iu={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class HB extends Fl{constructor(n,i=!1){var f;super(n);H(this,"supportsExtrema",!1);H(this,"movable");H(this,"points");H(this,"boxValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"orientation");H(this,"sections");H(this,"min");H(this,"max");H(this,"isViolinBoxPlot");this.isViolinBoxPlot=i&&n.type===or.BOX,this.points=n.data,this.orientation=n.orientation??Rn.VERTICAL,this.orientation===Rn.HORIZONTAL?this.points=[...n.data].reverse():this.points=n.data,this.sections=[iu.LOWER_OUTLIER,iu.MIN,iu.Q1,iu.Q2,iu.Q3,iu.MAX,iu.UPPER_OUTLIER];const o=[d=>d.lowerOutliers,d=>d.min,d=>d.q1,d=>d.q2,d=>d.q3,d=>d.max,d=>d.upperOutliers];this.orientation===Rn.HORIZONTAL?this.boxValues=this.points.map(d=>o.map(h=>h(d))):this.boxValues=o.map(d=>this.points.map(h=>d(h)));const s=this.boxValues.map(d=>d.flatMap(h=>Array.isArray(h)?h:[h]));this.min=Ba.minFrom2D(s),this.max=Ba.maxFrom2D(s),this.highlightValues=this.mapToSvgElements(n.selectors),this.orientation===Rn.HORIZONTAL&&((f=this.highlightValues)==null||f.reverse()),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Pm(this.boxValues,{row:0})}isViolin(){return this.isViolinBoxPlot}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,i){return super.moveToIndex(n,i)}handleInitialEntry(){var n;this.isInitialEntry=!1,this.orientation===Rn.VERTICAL?(this.row=Math.min(1,this.boxValues.length-1),this.col=0):(this.row=0,this.col=Math.min(1,((n=this.boxValues[0])==null?void 0:n.length)??1))}moveOnce(n){if(!this.isViolin())return super.moveOnce(n);if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.orientation===Rn.VERTICAL)if(n==="FORWARD")this.col+=1,this.row=1;else if(n==="BACKWARD")this.col-=1,this.row=1;else return super.moveOnce(n);else if(n==="UPWARD")this.row+=1,this.col=1;else if(n==="DOWNWARD")this.row-=1,this.col=1;else return super.moveOnce(n);return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}get values(){return this.boxValues}get audio(){const n=this.orientation===Rn.HORIZONTAL,i=this.boxValues[this.row][this.col],o=n?this.col:this.row,s=Array.isArray(i)?i.length===0?o:i[i.length-1]-this.min:Number.isNaN(i)?o:i-this.min;return{freq:{min:this.min,max:this.max,raw:this.boxValues[this.row][this.col]},panning:{x:n?s:this.row,y:n?this.row:s,rows:n?this.boxValues.length:this.max-this.min,cols:n?this.max-this.min:this.boxValues.length}}}get braille(){const n=this.orientation===Rn.HORIZONTAL,i=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:i,col:o}}get text(){const n=this.orientation===Rn.HORIZONTAL,i=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,s=n?this.sections[this.col]:this.sections[this.row],f=n?this.xAxis:this.yAxis,d=this.boxValues[this.row][this.col];return{main:{label:o,value:i.fill},cross:{label:f,value:d},section:s,mainAxis:n?"y":"x",crossAxis:n?"x":"y"}}get dimension(){const n=this.orientation===Rn.HORIZONTAL;return{rows:n?this.boxValues.length:this.boxValues[this.row].length,cols:n?this.boxValues[this.row].length:this.boxValues.length}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const i=this.orientation===Rn.VERTICAL,o=new Array;if(i)for(let f=0;f<this.sections.length;f++)o.push(Array.from({length:n.length}));const s=[];return n.forEach(f=>{var w,C;const d=((w=f.lowerOutliers)==null?void 0:w.flatMap(R=>Ht.selectAllElements(R,!1)))??[],h=((C=f.upperOutliers)==null?void 0:C.flatMap(R=>Ht.selectAllElements(R,!1)))??[],y=Ht.selectElement(f.min,!1),b=Ht.selectElement(f.max,!1),x=Ht.selectElement(f.iq,!1),T=Ht.selectElement(f.q2,!1);s.push({lowerOutliers:d,upperOutliers:h,min:y,max:b,iq:x,q2:T})}),s.forEach((f,d)=>{var N;const h=f.lowerOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),y=f.upperOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),b=this.cloneElementOrEmpty(f.min),x=this.cloneElementOrEmpty(f.max),T=this.cloneElementOrEmpty(f.q2),w=((N=this.layer.domMapping)==null?void 0:N.iqrDirection)==="reverse",[C,R]=f.iq?i?w?[Ht.createLineElement(f.iq,"top"),Ht.createLineElement(f.iq,"bottom")]:[Ht.createLineElement(f.iq,"bottom"),Ht.createLineElement(f.iq,"top")]:[Ht.createLineElement(f.iq,"left"),Ht.createLineElement(f.iq,"right")]:[Ht.createEmptyElement("line"),Ht.createEmptyElement("line")],_=[h,b,C,T,R,x,y];i?_.forEach((z,B)=>{o[B][d]=z}):o.push(_)}),o}cloneElementOrEmpty(n){if(!n)return Ht.createEmptyElement();const i=n.cloneNode(!0);return i.setAttribute(ge.VISIBILITY,ge.HIDDEN),n.insertAdjacentElement(ge.AFTER_END,i),i}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.boxValues.length)return!1;let s=[],f=0;if(n==="left"||n==="right"?(s=this.boxValues[this.row],f=this.col):(s=this.boxValues.map(y=>y[this.col]),f=this.row),s.length<=0)return!1;const d=n==="right"||n==="up"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){const y=s[f],b=s[h];if(Array.isArray(b)||Array.isArray(y))return!0;if(this.compare(b,y,i))return this.set_point(n,h),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}set_point(n,i){n==="left"||n==="right"?this.col=i:this.row=i}moveUpRotor(n){return this.orientation===Rn.VERTICAL?(this.moveOnce("UPWARD"),!0):this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.orientation===Rn.VERTICAL?(this.moveOnce("DOWNWARD"),!0):this.moveToNextCompareValue("down",n)}moveLeftRotor(n){return this.orientation===Rn.HORIZONTAL?(this.moveOnce("BACKWARD"),!0):this.moveToNextCompareValue("left",n)}moveRightRotor(n){return this.orientation===Rn.HORIZONTAL?(this.moveOnce("FORWARD"),!0):this.moveToNextCompareValue("right",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){}getCurrentXValue(){return this.isViolin()?this.orientation===Rn.VERTICAL?this.col>=0?this.col:null:this.row>=0?this.row:null:super.getCurrentXValue()}moveToXValue(n){if(!this.isViolin())return super.moveToXValue(n);if(this.isInitialEntry&&this.handleInitialEntry(),typeof n!="number")return!1;const i=Math.floor(n),o=this.values;if(this.orientation===Rn.VERTICAL){const s=o.length>0?o[0].length:0;if(i<0||i>=s)return!1;const f=this.col;return this.col=i,i!==f&&(this.row=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(i<0||i>=o.length)return!1;const s=this.row;return this.row=i,i!==s&&(this.col=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}getCurrentYValue(){if(!this.isViolin())return null;const n=this.values;if(this.orientation===Rn.VERTICAL){if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}}else if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}return null}moveToXAndYValue(n,i){if(!this.isViolin()||typeof n!="number")return!1;const o=Math.floor(n),s=this.values;if(this.orientation===Rn.VERTICAL){const f=s.length>0?s[0].length:0;if(o<0||o>=f)return!1;this.col=o;let d=1,h=1/0;for(let y=0;y<s.length;y++){const b=s[y];if(Array.isArray(b)&&o<b.length){const x=b[o];if(Array.isArray(x)){for(const T of x)if(typeof T=="number"){const w=Math.abs(T-i);w<h&&(h=w,d=y)}}else if(typeof x=="number"){const T=Math.abs(x-i);T<h&&(h=T,d=y)}}}return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(o<0||o>=s.length)return!1;this.row=o;let f=1,d=1/0;const h=s[o];if(Array.isArray(h))for(let y=0;y<h.length;y++){const b=h[y];if(Array.isArray(b)){for(const x of b)if(typeof x=="number"){const T=Math.abs(x-i);T<d&&(d=T,f=y)}}else if(typeof b=="number"){const x=Math.abs(b-i);x<d&&(d=x,f=y)}}return this.col=f,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}onSwitchFrom(n){var d;if(!this.isViolin())return!1;const i=n;if(!((i.type||((d=i.state)==null?void 0:d.traceType))==="smooth"))return!1;const f=n.getCurrentXValue();if(n.getCurrentYValue){const h=n.getCurrentYValue();if(h!==null&&f!==null&&this.moveToXAndYValue){const y=this.moveToXAndYValue(f,h);return y&&(this.isInitialEntry=!1),y}}if(f!==null){const h=this.moveToXValue(f);return h&&(this.isInitialEntry=!1),h}return!1}}const qB="trend",TC=100,FB=["volatility","open","high","low","close"];class GB extends Fl{constructor(n){super(n);H(this,"supportsExtrema",!0);H(this,"movable");H(this,"candles");H(this,"candleValues");H(this,"orientation");H(this,"currentSegmentType","open");H(this,"currentPointIndex",0);H(this,"sortedSegmentsByPoint");H(this,"segmentPositionMaps");H(this,"sections");H(this,"min");H(this,"max");H(this,"highlightValues");H(this,"highlightCenters");H(this,"navigationService");this.navigationService=new D7;const i=n.data;this.candles=i.map(s=>({...s,volatility:Math.round((s.high-s.low)*TC)/TC,trend:s.close>s.open?"Bull":s.close<s.open?"Bear":"Neutral"})),this.orientation=n.orientation??Rn.VERTICAL,this.sections=FB,this.candleValues=this.sections.map(s=>this.candles.map(f=>f[s]));const o=this.orientation===Rn.HORIZONTAL?{col:this.sections.length-1}:{row:this.sections.length-1};this.movable=new Pm(this.candleValues,o),this.min=Ba.minFrom2D(this.candleValues),this.max=Ba.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===Rn.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters()}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(s=>[s,n[s]]).sort((s,f)=>s[1]-f[1]).map(s=>s[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const i=new Map;return n.forEach((o,s)=>{i.set(o,s)}),i})}getSegmentPositionInSortedOrder(n,i){return this.segmentPositionMaps[n].get(i)??0}getSegmentTypeAtSortedPosition(n,i){return this.sortedSegmentsByPoint[n][i]??"open"}updateVisualSegmentPosition(){const i=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===Rn.HORIZONTAL?this.col=i:this.row=i}updateVisualPointPosition(){this.orientation===Rn.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)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open");if(o===-1)return this.notifyOutOfBounds(),!1;const s=n==="UPWARD"?o+1:o-1;if(s>=0&&s<i.length)this.currentSegmentType=i[s],this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(i>=0&&i<this.candles.length)this.currentPointIndex=i,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}}return this.notifyStateUpdate(),!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[i.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[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}}return this.notifyStateUpdate(),!0}moveToIndex(n,i){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:o,segmentType:s}=this.navigationService.computeIndexAndSegment(n,i,this.orientation,this.sections);return this.currentPointIndex=o,this.currentSegmentType=s,this.row=n,this.col=i,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open"),s=n==="UPWARD"?o+1:o-1;return s>=0&&s<i.length}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return i>=0&&i<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}get audio(){let n;const i=this.orientation===Rn.HORIZONTAL;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,{freq:{min:this.min,max:this.max,raw:n},panning:{x:i?this.row:this.col,y:i?this.col:this.row,rows:i?this.candleValues.length:this.candleValues[this.row].length,cols:i?this.candleValues[this.row].length:this.candleValues.length},trend:this.candles[this.currentPointIndex].trend}}get braille(){const n=this.candles.map(f=>f.trend),i=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=i;const o=this.candleValues.map(f=>Math.min(...f)),s=this.candleValues.map(f=>Math.max(...f));return{empty:!1,id:this.id,values:this.candleValues,min:o,max:s,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const i=Array.isArray(n)?n:[n],o=[];for(const s of i)o.push(...Ht.selectAllElements(s));return o}getElementAt(n,i){return i<n.length?n[i]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const C=Array.isArray(n)?n[0]||"":n,R=Ht.selectAllElements(C),_=[];for(let N=0;N<this.sections.length;N++){_[N]=[];for(let z=0;z<this.candles.length;z++){const B=z<R.length?z:0;_[N][z]=R[B]}}return _}const i=n,o=this.candles.length,s=this.collectElements(i.body);let f=this.collectElements(i.wickHigh),d=this.collectElements(i.wickLow);if(f.length===0||d.length===0){const C=this.collectElements(i.wick);C.length>0&&(f.length===0&&(f=C),d.length===0&&(d=C))}const h=this.collectElements(i.open),y=this.collectElements(i.close),b=Array.from({length:o},()=>Ht.createEmptyElement()),x=Array.from({length:o},()=>Ht.createEmptyElement()),T=Array.from({length:o},()=>Ht.createEmptyElement());for(let C=0;C<o;C++){let R=this.getElementAt(h,C);if(!R){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"bottom":B<z?"top":"bottom";R=Ht.createLineElement(N,V)}else R=Ht.createEmptyElement()}b[C]=R;let _=this.getElementAt(y,C);if(!_){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"top":B<z?"bottom":"top";_=Ht.createLineElement(N,V)}else _=Ht.createEmptyElement()}x[C]=_,T[C]=Ht.createEmptyElement()}const w=Array.from({length:this.sections.length},()=>Array.from({length:o},()=>Ht.createEmptyElement()));for(let C=0;C<o;C++){const R=this.sortedSegmentsByPoint[C];for(let _=0;_<R.length;_++){const N=R[_];let z;switch(N){case"volatility":{const B=[],V=this.getElementAt(s,C),I=this.getElementAt(f,C)??V,P=this.getElementAt(d,C)??V;I&&B.push(I),V&&B.push(V),P&&B.push(P);const Y=Array.from(new Set(B));z=Y.length>0?Y:[Ht.createEmptyElement()]}break;case"open":z=b[C];break;case"close":z=x[C];break;case"high":z=this.getElementAt(f,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;case"low":z=this.getElementAt(d,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;default:z=Ht.createEmptyElement()}w[_][C]=z}}return w}get text(){const n=this.candles[this.currentPointIndex],i=this.orientation===Rn.HORIZONTAL;let o;return this.currentSegmentType==="volatility"?o=n.volatility:this.currentSegmentType?o=n[this.currentSegmentType]:o=n.open,{main:{label:i?this.yAxis:this.xAxis,value:n.value},cross:{label:i?this.xAxis:this.yAxis,value:o},section:this.currentSegmentType??"open",fill:{label:qB,value:n.trend},mainAxis:i?"y":"x",crossAxis:i?"x":"y"}}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 i=this.candles.findIndex(o=>o.value===n);return i!==-1?(this.currentPointIndex=i,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getAvailableXValues(){return this.candles.map(n=>n.value)}getExtremaTargets(){const n=[],i=this.currentSegmentType??"open";if(i==="volatility"){const o=this.candles.map((y,b)=>({value:y.volatility,index:b})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,b)=>{const x=this.candles[y];n.push({label:`Max Volatility at ${x.value}`,value:x.volatility,pointIndex:y,segment:"volatility",type:"max",navigationType:"point"})}),h.forEach((y,b)=>{const x=this.candles[y];n.push({label:`Min Volatility at ${x.value}`,value:x.volatility,pointIndex:y,segment:"volatility",type:"min",navigationType:"point"})})}else{const o=this.candles.map((y,b)=>({value:y[i],index:b,xValue:y.value})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,b)=>{const x=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Max ${T} at ${x.value}`,value:x[i],pointIndex:y,segment:i,type:"max",navigationType:"point"})}),h.forEach((y,b)=>{const x=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Min ${T} at ${x.value}`,value:x[i],pointIndex:y,segment:i,type:"min",navigationType:"point"})})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.finalizeExtremaNavigation()}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.candles.length)return!1;const s=this.currentSegmentType??"open",f=this.candles.map((b,x)=>({value:b[s],index:x,xValue:b.value})),d=this.col,h=n==="right"?1:-1;let y=d+h;for(;y>=0&&y<f.length;){if(this.compare(f[y].value,f[d].value,i))return this.col=y,this.currentPointIndex=y,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;y+=h}return this.notifyRotorBounds(),!1}moveUpRotor(){return this.moveOnce("UPWARD"),!0}moveDownRotor(){return this.moveOnce("DOWNWARD"),!0}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}get dimension(){const n=this.orientation===Rn.HORIZONTAL;return{rows:n?this.candleValues.length:this.candleValues[this.row].length,cols:n?this.candleValues[this.row].length:this.candleValues.length}}}class YB extends Fl{constructor(n){super(n);H(this,"supportsExtrema",!1);H(this,"movable");H(this,"heatmapValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"x");H(this,"y");H(this,"min");H(this,"max");const i=n.data;this.x=i.x,this.y=[...i.y].reverse(),this.heatmapValues=[...i.points].reverse();const{min:o,max:s}=Ba.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=s,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Pm(this.heatmapValues)}get values(){return this.heatmapValues}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get audio(){return{freq:{min:this.min,max:this.max,raw:this.heatmapValues[this.row][this.col]},panning:{x:this.col,y:this.row,rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}}get braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}get 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:this.heatmapValues[this.row][this.col]}}}get dimension(){return{rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}mapToSvgElements(n){var d;if(!n)return null;const i=this.heatmapValues.length,o=this.heatmapValues[0].length,s=Ht.selectAllElements(n);if(s.length===0||s.length!==i*o)return null;const f=new Array;if(s[0]instanceof SVGPathElement)for(let h=0;h<i;h++){const y=i-1-h,b=new Array;for(let x=0;x<o;x++){const T=y*o+x;b.push(s[T])}f.push(b)}else if(s[0]instanceof SVGRectElement)if(((d=this.layer.domMapping)==null?void 0:d.order)==="row")for(let h=0;h<i;h++){const y=new Array;for(let b=0;b<o;b++){const x=h*o+b;y.push(s[x])}f.push(y)}else for(let h=0;h<i;h++){const y=new Array;for(let b=0;b<o;b++){const x=b*i+h;y.push(s[x])}f.push(y)}return f}updateVisualPointPosition(){const{row:n,col:i}=this.getSafeIndices();this.row=n,this.col=i}moveToNextCompareValue(n,i){switch(n){case"left":case"right":return this.search_in_row(n,i);case"up":case"down":return this.search_in_col(n,i);default:return this.notifyRotorBounds(),!1}}search_in_row(n,i){const o=this.y.length,s=this.col,f=n==="left"?-1:1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[this.row][d],this.heatmapValues[this.row][s],i))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}search_in_col(n,i){const o=this.x.length,s=this.row,f=n==="up"?1:-1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[d][this.col],this.heatmapValues[s][this.col],i))return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return!1}moveUpRotor(n){return this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.moveToNextCompareValue("down",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}}class XB extends U7{constructor(t){super(t,[t.data])}get text(){const t=this.orientation===Rn.VERTICAL,n=this.points[this.row][this.col],i=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text,range:{min:i,max:o}}}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const AC="Group",P7=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class CC extends Fl{constructor(n){super(n);H(this,"supportsExtrema",!0);H(this,"rotorSupport",!0);H(this,"movable");H(this,"points");H(this,"lineValues");H(this,"highlightValues");H(this,"highlightCenters");H(this,"min");H(this,"max");H(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(i=>i.map(o=>Number(o.y))),this.min=this.lineValues.map(i=>Ba.safeMin(i)),this.max=this.lineValues.map(i=>Ba.safeMax(i)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new PB(this.buildGraph())}get values(){return this.lineValues}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}buildGraph(){const n=this.points.length;if(n===0)return new Array;const i=Math.max(0,...this.points.map(s=>s.length)),o=this.points.map(s=>s.map(()=>({up:null,down:null,left:null,right:null,top:null,bottom:null,start:null,end:null})));for(let s=0;s<i;s++){const f=this.points.map((b,x)=>{var T;return{y:(T=b[s])==null?void 0:T.y,row:x}}).filter(b=>b.y!==void 0);if(f.length===0)continue;const d=[...f].sort((b,x)=>b.y-x.y),h={row:d[0].row,col:s},y={row:d[d.length-1].row,col:s};for(let b=0;b<d.length;b++){const{row:x}=d[b],T=o[x][s];T&&(b>0&&(T.down={row:d[b-1].row,col:s}),b<d.length-1&&(T.up={row:d[b+1].row,col:s}),T.bottom=h,T.top=y)}}for(let s=0;s<n;s++){const f=this.points[s].length>0?{row:s,col:0}:null,d=this.points[s].length>0?{row:s,col:this.points[s].length-1}:null;for(let h=0;h<this.points[s].length;h++){const y=o[s][h];y&&(h>0&&(y.left={row:s,col:h-1}),h<this.points[s].length-1&&(y.right={row:s,col:h+1}),y.start=f,y.end=d)}}return o}get audio(){return{freq:{min:this.min[this.row],max:this.max[this.row],raw:this.lineValues[this.row][this.col]},panning:{x:this.col,y:this.row,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:this.row}}get braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){var s;const n=this.points[this.row][this.col],i=this.findIntersections();let o={};if(i.length>1){let f=i.map(d=>{var y;const h=d.group;return((y=this.points[h][0])==null?void 0:y.fill)||`l${h+1}`});if(this.previousRow!==null){const d=((s=this.points[this.previousRow][0])==null?void 0:s.fill)||`l${this.previousRow+1}`;f.includes(d)&&(f=[d,...f.filter(h=>h!==d)])}o={fill:{label:AC,value:`intersection at (${f.join(", ")})`}}}else o=n.fill?{fill:{label:AC,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...o}}get dimension(){return{rows:this.lineValues.length,cols:this.lineValues[this.row].length}}moveOnce(n){if(this.isInitialEntry)return this.movable.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const o=this.findLineByXAndYDirection(n),s=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const f=this.findColumnByXValue(o,s);if(f!==-1){this.row=o,this.col=f;const d=this.findIntersections();if(d.length>1){const y={...super.state,intersections:d};for(const b of this.observers)b.update(y)}else this.notifyStateUpdate();return!0}else return this.notifyOutOfBounds(),!1}else return this.notifyOutOfBounds(),!1}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const i=this.findIntersections();if(i.length>1){const s={...super.state,intersections:i};for(const f of this.observers)f.update(s)}else this.notifyStateUpdate();return!0}findIntersections(){const n=this.points[this.row][this.col].x,i=this.points[this.row][this.col].y,o=[];for(let s=0;s<this.points.length;s++)this.points[s].findIndex(d=>d.x===n&&d.y===i)!==-1&&o.push({freq:{min:this.min[s],max:this.max[s],raw:i},panning:{x:this.col,y:this.row,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:s});return o}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.values.length&&o>=0&&o<this.values[i].length}switch(n){case"UPWARD":case"DOWNWARD":{const i=this.findLineByXAndYDirection(n);if(i===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(i,o)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const i=this.points[this.row][this.col].x;let o=null,s=Number.POSITIVE_INFINITY;for(let f=0;f<this.points.length;f++){if(f===this.row)continue;const d=this.points[f].findIndex(x=>x.x===i);if(d===-1)continue;const h=this.points[f][d].y,y=n==="UPWARD"?h>this.points[this.row][this.col].y:h<this.points[this.row][this.col].y,b=Math.abs(h-this.points[this.row][this.col].y);y&&b<s&&(s=b,o=f)}return o}findColumnByXValue(n,i){return this.points[n].findIndex(o=>o.x===i)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const i=[];let o=!0;for(let s=0;s<n.length;s++){const f=Ht.selectElement(n[s],!1);if(!f){i.push([]);continue}const d=[];if(f instanceof SVGPathElement){const b=f.getAttribute(ge.D)||ge.EMPTY;P7.lastIndex=0;let x=P7.exec(b);for(;x!==null;)d.push({x:Number.parseFloat(x[1]),y:Number.parseFloat(x[2])}),x=P7.exec(b)}else if(f instanceof SVGPolylineElement){const x=(f.getAttribute(ge.POINTS)||ge.EMPTY).split(/\s+/).filter(Boolean);for(const T of x){const[w,C]=T.split(ge.COMMA);d.push({x:Number.parseFloat(w),y:Number.parseFloat(C)})}}if(d.length!==this.lineValues[s].length)if(d.length<this.lineValues[s].length)for(;d.length<this.lineValues[s].length;)d.push({x:Number.NaN,y:Number.NaN});else d.length>this.lineValues[s].length&&(d.length=this.lineValues[s].length);const h=[];let y=!1;for(const b of d){if(Number.isNaN(b.x)||Number.isNaN(b.y)){y=!0;break}h.push(Ht.createCircleElement(b.x,b.y,f))}if(y){i.push([]);continue}h.length>0&&(o=!1),i.push(h)}return o?null:i}get state(){const n=super.state;if(n.empty)return n;const i=this.points.length>1,o={...n,plotType:i?"multiline":"single line",...i&&{groupCount:this.points.length}},s=this.findIntersections();return s.length>1?{...o,intersections:s}:o}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}getExtremaTargets(){const n=[],i=this.row;if(i<0||i>=this.lineValues.length)return n;const o=this.lineValues[i];if(!o||o.length===0)return n;const s=this.min[i],f=this.max[i],d=[],h=[];for(let y=0;y<o.length;y++){const b=o[y];b===f&&d.push(y),b===s&&h.push(y)}for(const y of d)n.push({label:`Max point at ${this.getPointLabel(y)}`,value:f,pointIndex:y,segment:"line",type:"max",navigationType:"point"});for(const y of h)n.push({label:`Min point at ${this.getPointLabel(y)}`,value:s,pointIndex:y,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:i}=this.getSafeIndices();this.row=n,this.col=i}getAvailableXValues(){return this.points[this.row].map(n=>n.x)}moveToXValue(n){return this.isInitialEntry&&this.movable.handleInitialEntry(),super.moveToXValue(n)}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.lineValues.length)return!1;const s=this.lineValues[o];if(!s||s.length===0)return!1;const f=this.col,d=n==="right"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){if(this.compare(s[h],s[f],i))return this.col=h,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}compare(n,i,o){return o==="lower"?n<i:o==="higher"?n>i:!1}moveUpRotor(n){return this.moveOnce("UPWARD"),!0}moveDownRotor(n){return this.moveOnce("DOWNWARD"),!0}}class WB extends Fl{constructor(n){super(n);H(this,"mode");H(this,"movable");H(this,"supportsExtrema",!1);H(this,"xPoints");H(this,"yPoints");H(this,"xValues");H(this,"yValues");H(this,"highlightXValues");H(this,"highlightYValues");H(this,"highlightCenters");H(this,"minX");H(this,"maxX");H(this,"minY");H(this,"maxY");this.mode="column";const i=n.data,o=[...i].sort((h,y)=>h.x-y.x||h.y-y.y);this.xPoints=new Array;let s=null;for(const h of o)(!s||s.x!==h.x)&&(s={x:h.x,y:[]},this.xPoints.push(s)),s.y.push(h.y);const f=[...i].sort((h,y)=>h.y-y.y||h.x-y.x);this.yPoints=new Array;let d=null;for(const h of f)(!d||d.y!==h.y)&&(d={y:h.y,x:[]},this.yPoints.push(d)),d.x.push(h.x);this.xValues=this.xPoints.map(h=>h.x),this.yValues=this.yPoints.map(h=>h.y),this.minX=Ba.safeMin(this.xValues),this.maxX=Ba.safeMax(this.xValues),this.minY=Ba.safeMin(this.yValues),this.maxY=Ba.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new jB(this.xPoints,this.yPoints)}dispose(){this.movable.dispose(),this.xPoints.length=0,this.yPoints.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightYValues.length=0),super.dispose()}get highlightValues(){return this.movable.mode==="col"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}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 braille(){return{empty:!1,id:this.id,values:this.values,min:0,max:0,row:this.row,col:this.col}}get audio(){if(this.movable.mode==="col"){const n=this.xPoints[this.col];return{freq:{raw:n.y,min:this.minY,max:this.maxY},panning:{y:this.row,x:this.col,rows:n.y.length,cols:this.xPoints.length}}}else{const n=this.yPoints[this.row];return{freq:{raw:n.x,min:this.minX,max:this.maxX},panning:{y:this.row,x:this.col,rows:this.yPoints.length,cols:n.x.length}}}}get text(){if(this.movable.mode==="col"){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 dimension(){return{rows:this.yPoints.length,cols:this.xPoints.length}}get highlight(){if(this.highlightValues===null)return this.outOfBoundsState;const n=this.movable.mode==="col"?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}:this.outOfBoundsState}get 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],i=n.y[Math.floor(n.y.length/2)],o=this.yValues.indexOf(i);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(i);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;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}}return this.notifyStateUpdate(),!0}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}return this.notifyStateUpdate(),!0}moveToIndex(n,i){return this.mode==="column"?n>=0&&n<this.xPoints.length?(this.col=n,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):i>=0&&i<this.yPoints.length?(this.col=i,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}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 i=Ht.selectAllElements(n);if(i.length===0)return[null,null];const o=new Map,s=new Map;i.forEach(h=>{const y=Number.parseFloat(h.getAttribute("x")||""),b=Number.parseFloat(h.getAttribute("y")||"");Number.isNaN(y)||(o.has(y)||o.set(y,[]),o.get(y).push(h)),Number.isNaN(b)||(s.has(b)||s.set(b,[]),s.get(b).push(h))});const f=Array.from(o.entries()).sort(([h],[y])=>h-y).map(([h,y])=>y),d=Array.from(s.entries()).sort(([h],[y])=>y-h).map(([h,y])=>y);return[f,d]}mapSvgElementsToCenters(){const n=this.highlightXValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){this.mode="column";const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}}const OC="Sum",QB="Level",KB="undefined";class ZB extends U7{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let s=0;s<this.barValues[0].length;s++){const f=this.barValues.reduce((h,y)=>h+y[s],0);t.push(f);const d=this.orientation===Rn.VERTICAL?{x:this.points[0][s].x,y:f,fill:OC}:{x:f,y:this.points[0][s].y,fill:OC};n.push(d)}this.points.push(n),this.barValues.push(t);const{min:i,max:o}=Ba.minMax(t);this.min.push(i),this.max.push(o)}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.min[n],o=this.max[n],s=this.barValues[n];if(!s||s.length===0)return t;const f=s.indexOf(o),d=s.indexOf(i),h=this.getGroupLabel(n),y=this.getCategoryLabel(f),b=this.getCategoryLabel(d);return t.push({label:`Max ${h} at ${y}`,value:o,pointIndex:f,segment:h,type:"max",groupIndex:n,categoryIndex:f,navigationType:"group"}),t.push({label:`Min ${h} at ${b}`,value:i,pointIndex:d,segment:h,type:"min",groupIndex:n,categoryIndex:d,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===Rn.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}get text(){return{...super.text,fill:{label:QB,value:this.points[this.row][this.col].fill??KB}}}get highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}mapToSvgElements(t){var o;if(!t)return new Array;const n=Ht.selectAllElements(t);if(n.length===0)return new Array;const i=new Array;if(n[0]instanceof SVGPathElement)for(let s=0,f=0;s<this.barValues.length;s++){const d=new Array;for(let h=0;h<this.barValues[s].length;h++){if(f>=n.length)return new Array;this.barValues[s][h]===0?d.push(Ht.createEmptyElement()):d.push(n[f++])}i.push(d)}else if(n[0]instanceof SVGRectElement){for(let f=0;f<this.barValues.length;f++)i.push(new Array);const s=((o=this.layer.domMapping)==null?void 0:o.groupDirection)==="forward";for(let f=0,d=0;f<this.barValues[0].length;f++)if(s)for(let h=0;h<this.barValues.length;h++){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}else for(let h=this.barValues.length-1;h>=0;h--){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}}return i}}class j7 extends CC{constructor(t){super(t)}get state(){const t=super.state;return t.empty?t:{...t,plotType:"smooth"}}get audio(){const t=this.lineValues[this.row],n=f=>t[Math.max(0,Math.min(f,t.length-1))],i=n(this.col-1),o=n(this.col),s=n(this.col+1);return{freq:{min:this.min[this.row],max:this.max[this.row],raw:[i,o,s]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0}}}class JB extends j7{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let i=!0;for(let s=0;s<t.length;s++){const f=Ht.selectElement(t[s],!1);if(!f){n.push([]);continue}const d=(o=this.points)==null?void 0:o[s],h=[];for(const y of d)typeof y.svg_x=="number"&&typeof y.svg_y=="number"&&h.push(Ht.createCircleElement(y.svg_x,y.svg_y,f));h.length>0&&(i=!1),n.push(h)}return i?null:n}}const $7=.001;class eV extends j7{constructor(t){super(t)}isMovable(t){var n;if(Array.isArray(t)){const[i,o]=t;return i>=0&&i<this.points.length&&o>=0&&o<(((n=this.points[i])==null?void 0:n.length)||0)}switch(t){case"FORWARD":return this.row<this.points.length-1;case"BACKWARD":return this.row>0;case"UPWARD":return this.col<this.points[this.row].length-1;case"DOWNWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0}moveOnce(t){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(t))return this.notifyOutOfBounds(),!1;switch(t){case"FORWARD":if(this.row<this.points.length-1){const n=this.row+1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"BACKWARD":if(this.row>0){const n=this.row-1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"UPWARD":case"DOWNWARD":return t==="UPWARD"?this.col<this.points[this.row].length-1?(this.col+=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):this.col>0?(this.col-=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}}mapToSvgElements(t){if(!t||t.length===0)return null;const n=[];let i=!0;const o=t.length===this.points.length;for(let s=0;s<this.points.length;s++){const f=[],d=this.points[s];let h;if(o?h=t[s]:h=t[0],!h){n.push([]);continue}const y=Ht.selectAllElements(h,!1);let b=null;if(y.length>0){const x=y.filter(C=>C instanceof SVGUseElement),T=y.filter(C=>C instanceof SVGPathElement),w=x.length>0?x:T;w.length>0&&(b=w[o?0:s<w.length?s:0])}if(b&&d){for(const x of d){let T,w;const C=x;if(typeof C.svg_x=="number"&&typeof C.svg_y=="number")T=C.svg_x,w=C.svg_y;else if(typeof x.x=="number"&&typeof x.y=="number")T=x.x,w=x.y;else continue;!Number.isNaN(T)&&!Number.isNaN(w)&&f.push(Ht.createCircleElement(T,w,b))}f.length>0&&(i=!1)}n.push(f)}return i?null:n}get text(){const t=this.points[this.row][this.col],n=t.x,i=Number(t.y),o=this.points[this.row],s=t;let f;if(typeof s.width=="number"&&!Number.isNaN(s.width))f=s.width;else{const w=typeof s.svg_y=="number"?s.svg_y:null,C=[];for(const R of o){const _=R,N=Number(R.y),z=typeof _.svg_y=="number"?_.svg_y:null;let B=!1;w!==null&&z!==null?B=Math.abs(z-w)<=1:B=Math.abs(N-i)<=.01,B&&typeof _.svg_x=="number"&&!Number.isNaN(_.svg_x)&&C.push(_.svg_x)}if(C.length>=2){const R=Math.min(...C),_=Math.max(...C);f=Math.abs(_-R)}}const d=T=>Math.round(T*1e4)/1e4,h=d(i),y=f!==void 0&&f>0?d(f):void 0;let b;if(typeof n=="string")b=n;else{const T=o[0];T&&typeof T.x=="string"?b=T.x:b=`Category ${this.row}`}const x={main:{label:this.xAxis,value:b},cross:{label:this.yAxis,value:h}};return y!==void 0&&(x.fill={label:"volume",value:String(y)}),x}get audio(){const n=this.points[0];if(!n||n.length===0)return super.audio;const i=n.map(z=>z.density??z.width??0),o=i.filter(z=>z>0);if(o.length===0)return super.audio;const s=Math.min(...o),f=i.length>0?Math.max(...i):0,d=s===f?Math.max(0,s-$7):s,h=s===f?f+$7:f,y=Math.min(this.col,i.length-1),b=z=>i[Math.max(0,Math.min(z,i.length-1))],x=y>0?b(y-1):b(y),T=b(y),w=y<i.length-1?b(y+1):b(y),C=this.points[this.row],R=C?Math.min(this.col,C.length-1):0,_=C==null?void 0:C[R];let N=1;if(_){const z=_.density??_.width??0,B=C.map(Y=>Y.density??Y.width??0),V=B.filter(Y=>Y>0),I=V.length>0?Math.min(...V):0,P=B.length>0?Math.max(...B):0;if(P>0&&typeof z=="number"&&z>0){const Y=I===P?P+$7:P;N=z/Y}}return{freq:{min:d,max:h,raw:[x,T,w]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0,volumeScale:N}}getCurrentXValue(){return this.row>=0&&this.row<this.points.length?this.row:null}moveToXValue(t){var s;this.isInitialEntry&&this.handleInitialEntry();const n=this.points;if(!n||!n.length)return!1;const i=Math.floor(t);if(i<0||i>=n.length)return!1;const o=this.row;if(this.row=i,i!==o)this.col=0;else{const f=(s=n[i])!=null&&s.length?n[i].length-1:0;this.col=Math.min(this.col,f)}return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}getCurrentYValue(){const t=this.lineValues[this.row];if(!t||t.length===0)return null;if(this.col>=0&&this.col<t.length){const n=t[this.col];return typeof n=="number"?n:null}return null}moveToXAndYValue(t,n){if(typeof t!="number")return!1;const i=Math.floor(t);if(i<0||i>=this.lineValues.length)return!1;this.row=i;const o=this.lineValues[this.row];if(!o||o.length===0)return this.col=0,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;let s=0,f=Math.abs(o[0]-n);for(let d=1;d<o.length;d++){const h=Math.abs(o[d]-n);h<f&&(f=h,s=d)}return this.col=s,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}onSwitchFrom(t){var f;const n=t;if(!((n.type||((f=n.state)==null?void 0:f.traceType))==="box"))return!1;const s=t.getCurrentXValue();if(t.getCurrentYValue){const d=t.getCurrentYValue();if(d!==null&&s!==null&&this.moveToXAndYValue){const h=this.moveToXAndYValue(s,d);return h&&(this.isInitialEntry=!1),h}}if(s!==null){const d=this.moveToXValue(s);return d&&(this.isInitialEntry=!1),d}return!1}}function tV(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function nV(e,t=!1){return t&&e.type===or.SMOOTH?new eV(e):Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&tV(e.data[0][0])?new JB(e):new j7(e)}class rV{static create(t,n){const i=(n==null?void 0:n.isViolinPlot)===!0;switch(t.type){case or.BAR:return new $B(t);case or.BOX:return new HB(t,i);case or.CANDLESTICK:return new GB(t);case or.HEATMAP:return new YB(t);case or.HISTOGRAM:return new XB(t);case or.LINE:return new CC(t);case or.SCATTER:return new WB(t);case or.SMOOTH:return nV(t,i);case or.DODGED:case or.NORMALIZED:case or.STACKED:return new ZB(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const iV="MAIDR Plot",aV="unavailable",oV="unavailable";class lV extends B7{constructor(n){super();H(this,"id");H(this,"movable");H(this,"title");H(this,"subtitle");H(this,"caption");H(this,"subplots");H(this,"size");this.id=n.id,this.title=n.title??iV,this.subtitle=n.subtitle??aV,this.caption=n.caption??oV;const i=n.subplots;this.subplots=i.map(o=>o.map(s=>new sV(s))),this.size=this.subplots.reduce((o,s)=>o+s.length,0),this.movable=new Pm(this.subplots,{row:this.subplots.length-1})}get dimension(){return{rows:this.subplots.length,cols:this.subplots[this.row].length}}dispose(){this.subplots.forEach(n=>n.forEach(i=>i.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((o,s)=>o+s.length,0),i=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:i.getStateWithFigurePosition(this.row,this.col),traceTypes:i.traceTypes,highlight:this.highlight}}get highlight(){var i;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}};try{const o=((i=this.subplots[0])==null?void 0:i.length)||1,s=this.row*o+this.col+1,f=`g[id="axes_${s}"]`,d=document.querySelector(f);if(d)return{empty:!1,elements:d};const h=document.querySelectorAll('g[id^="axes_"]');if(h.length>0&&s-1<h.length)return{empty:!1,elements:h[s-1]}}catch{return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}moveToPoint(n,i){this.notifyStateUpdate()}get outOfBoundsState(){return{empty:!0,type:"figure"}}}class sV extends B7{constructor(n){super();H(this,"movable");H(this,"traces");H(this,"traceTypes");H(this,"size");H(this,"highlightValue");H(this,"isViolinPlot");const i=n.layers;this.size=i.length;const o=i.map(h=>h.type),s=o.includes(or.BOX),f=o.includes(or.SMOOTH),d=s&&f;this.isViolinPlot=d,this.traces=i.map(h=>[rV.create(h,{isViolinPlot:d})]),this.traceTypes=this.traces.flat().map(h=>{const y=h.state;return y.empty?ge.EMPTY:y.traceType}),this.highlightValue=this.mapToSvgElement(n.selector),this.movable=new Pm(this.traces)}get dimension(){return{rows:this.values.length,cols:this.values[this.row].length}}dispose(){this.traces.forEach(n=>n.forEach(i=>i.dispose())),this.traces.length=0,super.dispose()}getRow(){return this.row}getSize(){return this.size}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}moveOnce(n){return this.size>1&&this.isInitialEntry&&(this.isInitialEntry=!1),super.moveOnce(n)}get state(){return{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight}}get outOfBoundsState(){return{empty:!0,type:"subplot"}}get highlight(){return this.highlightValue===null?{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.values.length,cols:this.values[this.row].length}}:{empty:!1,elements:this.highlightValue}}moveToPoint(n,i){this.notifyStateUpdate()}getStateWithFigurePosition(n,i){return this.state}mapToSvgElement(n){return n?Ht.selectElement(n)??null:null}}const Va={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},Vg=class Vg{constructor(){H(this,"basePalette");H(this,"extendedPalette");this.basePalette=[{index:Va.SINE_BASIC,waveType:"sine",timbreModulation:{attack:.01,decay:.1,sustain:.8,release:.2}},{index:Va.SQUARE_BASIC,waveType:"square",timbreModulation:{attack:.005,decay:.05,sustain:.7,release:.15}},{index:Va.SAWTOOTH_BASIC,waveType:"sawtooth",timbreModulation:{attack:.02,decay:.08,sustain:.6,release:.25}},{index:Va.TRIANGLE_BASIC,waveType:"triangle",timbreModulation:{attack:.015,decay:.12,sustain:.9,release:.18}},{index:Va.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:Va.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:Va.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:Va.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:Va.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:Va.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:Va.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 i=this.generateExtendedEntry(t);return this.extendedPalette.set(t,i),i}get basePaletteSize(){return this.basePalette.length}getCandlestickGroupIndex(t){switch(t){case"Bull":return Va.SINE_BASIC;case"Bear":return Va.SAWTOOTH_SOFT;case"Neutral":return Va.TRIANGLE_BASIC;default:return Va.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,i)=>{this.extendedPalette.set(this.basePalette.length+i,n)})}generateExtendedEntry(t){const n=t%this.basePalette.length,i=this.basePalette[n],o=Math.floor((t-this.basePalette.length)/this.basePalette.length),s=this.generateHarmonics(o),f=this.generateTimbreModulation(o,i.timbreModulation);return{index:t,waveType:i.waveType,harmonicMix:{fundamental:1,harmonics:s},timbreModulation:f}}generateHarmonics(t){const n=[],i=Vg.MIN_HARMONICS+t%Vg.HARMONIC_VARIATION;for(let o=0;o<i;o++){const s=1+(o+1)*(.5+t*.3%1),f=.4/(o+1)*(1-t*.1%.3);n.push({frequency:s,amplitude:f})}return n}generateTimbreModulation(t,n){const i=1+t*.2%.5;return{attack:Math.max(.005,Math.min(.05,n.attack*i)),decay:Math.max(.05,Math.min(.3,n.decay*i)),sustain:Math.max(.4,Math.min(.9,n.sustain+t*.1%.2)),release:Math.max(.1,Math.min(.5,n.release*i))}}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.`)})}};H(Vg,"MIN_HARMONICS",2),H(Vg,"HARMONIC_VARIATION",3);let H7=Vg;const uV=100,cV=440,fV=880,MC=180,RC=.2,dV=.1,q7=.3,US=Va.SINE_BASIC;class hV{constructor(t,n,i){H(this,"notification");H(this,"audioPalette");H(this,"isCombinedAudio");H(this,"mode");H(this,"activeAudioIds");H(this,"volume");H(this,"minFrequency");H(this,"maxFrequency");H(this,"audioContext");H(this,"compressor");this.notification=t,this.audioPalette=new H7,this.isCombinedAudio=!1,this.mode="on",this.updateMode(i),this.activeAudioIds=new Map,this.volume=this.normalizeVolume(n.get("general.volume")),this.minFrequency=n.get("general.minFrequency"),this.maxFrequency=n.get("general.maxFrequency"),n.onChange(o=>{o.affectsSetting("general.volume")&&(this.volume=this.normalizeVolume(o.get("general.volume"))),o.affectsSetting("general.minFrequency")&&(this.minFrequency=o.get("general.minFrequency")),o.affectsSetting("general.maxFrequency")&&(this.maxFrequency=o.get("general.maxFrequency"))}),this.audioContext=new AudioContext,this.compressor=this.initCompressor()}dispose(){this.stopAll(),this.audioPalette.dispose(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close())}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const 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"))}update(t){if(this.updateMode(t),this.mode==="off")return;if(t.empty){t.warning?this.playWarningTone():t.type==="trace"&&t.audio?this.playEmptyTone({x:t.audio.x,y:t.audio.y,rows:t.audio.rows,cols:t.audio.cols}):this.playEmptyTone({x:0,y:0,rows:1,cols:1});return}if(t.type!=="trace")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 i=n.group;n.trend&&i===void 0&&(i=this.audioPalette.getCandlestickGroupIndex(n.trend));const o=i!==void 0?this.audioPalette.getPaletteEntry(i):void 0;if(n.isContinuous)this.playSmooth(n.freq,n.panning,o,n.volumeMultiplier,n.volumeScale);else if(Array.isArray(n.freq.raw)){const s=n.freq.raw;if(s.length===0){this.playZeroTone(n.panning);return}let f=0;const d=this.mode==="on"?50:0,h=new Array,y=()=>{f<s.length?(this.playTone({min:n.freq.min,max:n.freq.max,raw:s[f++]},{x:n.panning.x,y:n.panning.y,rows:n.panning.rows,cols:n.panning.cols},o),h.push(setTimeout(y,d))):this.stop(h)};y()}else n.freq.raw===0?this.playZeroTone(n.panning):this.playTone(n.freq,n.panning,o)}playTone(t,n,i){const o={min:t.min,max:t.max},s={min:this.minFrequency,max:this.maxFrequency},f=this.interpolate(t.raw,o,s),d=this.clamp(this.interpolate(n.x,{min:0,max:n.cols-1},{min:-1,max:1}),-1,1);return this.playOscillator(f,{x:d,y:0},i)}createAdsrEnvelope(t,n,i,o,s){if(n!=null&&n.timbreModulation){const{attack:f,decay:d,sustain:h,release:y}=n.timbreModulation,b=s*f,x=s*d,T=s*y,w=s-b-x-T;return t.gain.setValueAtTime(1e-4*i,o),t.gain.linearRampToValueAtTime(i,o+b),t.gain.linearRampToValueAtTime(h*i,o+b+x),w>0&&t.gain.setValueAtTime(h*i,o+b+x+w),t.gain.linearRampToValueAtTime(1e-4*i,o+s),null}else return[.5*i,i,.5*i,.5*i,.5*i,.1*i,1e-4*i]}playOscillator(t,n={x:0,y:0},i){const o=q7,s=this.audioContext.currentTime;i||(i=this.audioPalette.getPaletteEntry(US));const f=[],d=[],h=this.audioContext.createOscillator();if(h.type=i.waveType,h.frequency.value=t,f.push(h),i.harmonicMix)for(const T of i.harmonicMix.harmonics){const w=this.audioContext.createOscillator();w.type=i.waveType,w.frequency.value=T.frequency*t,f.push(w)}for(let T=0;T<f.length;T++){const w=this.audioContext.createGain();let C=this.volume;if(T===0)i.harmonicMix&&(C*=i.harmonicMix.fundamental);else{const _=i.harmonicMix.harmonics[T-1];C*=_.amplitude}const R=this.createAdsrEnvelope(w,i,C,s,o);R!==null&&w.gain.setValueCurveAtTime(R,s,o),d.push(w)}const y=this.audioContext.createStereoPanner();y.pan.value=n.x;for(let T=0;T<f.length;T++)f[T].connect(d[T]),d[T].connect(y);y.connect(this.compressor),f.forEach(T=>T.start(s));const b=T=>{y.disconnect();for(let w=0;w<f.length;w++)f[w].stop(),f[w].disconnect(),d[w].disconnect();this.activeAudioIds.delete(T)},x=setTimeout(()=>b(x),o*1e3*2);return this.activeAudioIds.set(x,f),x}playSmooth(t,n,i,o,s){const f=this.audioContext,d=f.currentTime,h=q7,y=t.raw.map(B=>this.interpolate(B,{min:t.min,max:t.max},{min:this.minFrequency,max:this.maxFrequency})),b=this.volume;let x;s!==void 0?x=b*Math.max(0,s):x=b*(o??1),y.length<2&&y.push(y[0]);const T=this.clamp(this.interpolate(n.x,{min:0,max:n.cols-1},{min:-1,max:1}),-1,1),w=(i==null?void 0:i.waveType)||"sine",C=f.createOscillator();C.type=w,C.frequency.setValueCurveAtTime(y,d,h);const R=f.createGain(),_=this.createAdsrEnvelope(R,i,x,d,h);_!==null&&R.gain.setValueCurveAtTime(_,d,h);const N=f.createStereoPanner();N.pan.value=T,C.connect(R),R.connect(N),N.connect(this.compressor),C.start(d),C.stop(d+h);const z=setTimeout(()=>{C.disconnect(),R.disconnect(),N.disconnect(),this.activeAudioIds.delete(z)},h*1e3*2);this.activeAudioIds.set(z,C)}playEmptyTone(t){const n=this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),i=this.audioContext,o=i.currentTime,s=.2,f=i.createStereoPanner();f.pan.value=n;const d=[500,1e3,1500,2100,2700],h=[1,.6,.4,.2,.1],y=i.createGain();y.gain.setValueAtTime(.3*this.volume,o),y.gain.exponentialRampToValueAtTime(.01*this.volume,o+s),y.connect(f),f.connect(this.compressor);const b=[];for(let w=0;w<d.length;w++){const C=i.createOscillator(),R=i.createGain();C.frequency.value=d[w],C.type="sine",R.gain.setValueAtTime(h[w]*this.volume,o),R.gain.exponentialRampToValueAtTime(.001*this.volume,o+s),C.connect(R),R.connect(y),C.start(o),C.stop(o+s),b.push(C)}const x=w=>{f.disconnect(),y.disconnect(),b.forEach(C=>{C.disconnect()}),this.activeAudioIds.delete(w)},T=setTimeout(()=>x(T),s*1e3*2);return this.activeAudioIds.set(T,b),T}playOneWarningBeep(t,n){const i=this.audioContext.createOscillator(),o=this.audioContext.createGain();i.type="sine",i.frequency.value=t;let s=1;i.type!=="sine"&&(s=.5),o.gain.setValueAtTime(s,n),o.gain.exponentialRampToValueAtTime(.001,n+RC),i.connect(o),o.connect(this.audioContext.destination),i.start(n),i.stop(n+RC)}playWarningTone(){const t=this.audioContext.currentTime;this.playOneWarningBeep(MC,t),this.playOneWarningBeep(MC/2**(1/12),t+dV)}playWarningToneIfEnabled(){this.mode!=="off"&&this.playWarningTone()}playZeroTone(t){const n=this.clamp(this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),-1,1);return this.playOscillator(uV,{x:n,y:0},{index:US,waveType:"triangle"})}playWaitingTone(){const t=this.audioPalette.getPaletteEntry(US);return setInterval(()=>this.playOscillator(cV,{x:0,y:0},t),1e3)}playCompleteTone(){const t=this.audioPalette.getPaletteEntry(US);return this.playOscillator(fV,{x:0,y:0},t)}playSimultaneousTones(t){const n=q7,i=this.audioContext,o=i.currentTime,s=Array.isArray(t[0].freq.raw)?t[0].freq.raw[1]??t[0].freq.raw[0]:t[0].freq.raw,f=this.interpolate(s,{min:t[0].freq.min,max:t[0].freq.max},{min:this.minFrequency,max:this.maxFrequency});t.forEach((d,h)=>{const b=this.audioPalette.getPaletteEntry(d.group??h).waveType,x=i.createOscillator();x.type=b,x.frequency.value=f;const T=i.createGain();T.gain.setValueAtTime(this.volume,o),T.gain.exponentialRampToValueAtTime(.01*this.volume,o+n),x.connect(T),T.connect(this.compressor),x.start(o),x.stop(o+n);const w=setTimeout(()=>{x.disconnect(),T.disconnect(),this.activeAudioIds.delete(w)},n*1e3*2);this.activeAudioIds.set(w,[x])})}interpolate(t,n,i){return n.min===n.max?i.min:(t-n.min)/(n.max-n.min)*(i.max-i.min)+i.min}clamp(t,n,i){return Math.max(n,Math.min(t,i))}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(i=>{const o=this.activeAudioIds.get(i);if(!o){clearInterval(i);return}(Array.isArray(o)?o:[o]).forEach(f=>{f==null||f.disconnect(),f==null||f.stop()}),clearTimeout(i),this.activeAudioIds.delete(i)})}stopAll(){this.activeAudioIds.forEach((t,n)=>{clearTimeout(n),(Array.isArray(t)?t:[t]).forEach(o=>{o.disconnect(),o.stop()})}),this.activeAudioIds.clear()}normalizeVolume(t){return t/100*(t/100)}}const pV=250,mV=50,gV=500,_C=20;class yV{constructor(t,n,i){H(this,"context");H(this,"notification");H(this,"settings");H(this,"autoplayId");H(this,"currentDirection");H(this,"userSpeed");H(this,"defaultSpeed");H(this,"minSpeed");H(this,"maxSpeed");H(this,"autoplayRate");H(this,"interval");H(this,"totalDuration");H(this,"onChangeEmitter");H(this,"onChange");this.notification=n,this.context=t,this.settings=i,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=pV,this.minSpeed=mV,this.maxSpeed=gV,this.interval=_C,this.autoplayRate=this.defaultSpeed,this.interval=_C,this.totalDuration=i.get("general.autoplayDuration"),i.onChange(o=>{o.affectsSetting("general.autoplayDuration")&&(this.totalDuration=o.get("general.autoplayDuration"),this.restart())}),this.onChangeEmitter=new Md,this.onChange=this.onChangeEmitter.event}dispose(){this.stop(),this.onChangeEmitter.dispose()}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 i=Math.ceil(this.totalDuration/n.autoplay[t]);return this.defaultSpeed=i,this.minSpeed=Math.min(this.minSpeed,i),i}return this.defaultSpeed}}const DC=32;class gv{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const f=(t.max[s]-t.min[s])/4,d=t.min[s]+f,h=d+f,y=h+f;for(let b=0;b<t.values[s].length;b++)t.values[s][b]===0?n.push(" "):t.values[s][b]<=d||t.values[s][b]<=h?n.push("⠤"):t.values[s][b]<=y?n.push("⠒"):n.push("⠉"),i[s].push(o.length),o.push({row:s,col:b});n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class vV{constructor(){H(this,"GLOBAL_MIN","globalMin");H(this,"GLOBAL_MAX","globalMax");H(this,"BLANK","blank");H(this,"LOWER_OUTLIER","lowerOutlier");H(this,"UPPER_OUTLIER","upperOutlier");H(this,"MIN","min");H(this,"MAX","max");H(this,"Q1","q1");H(this,"Q2","q2");H(this,"Q3","q3")}encode(t,n=DC){const i=new Array,o=new Array,s=new Array;for(let f=0;f<t.values.length;f++){const d=t.values[f],h=[{type:this.GLOBAL_MIN,value:t.min},...d.lowerOutliers.map(Y=>({type:this.LOWER_OUTLIER,value:Y})),{type:this.MIN,value:d.min},{type:this.Q1,value:d.q1},{type:this.Q2,value:d.q2},{type:this.Q3,value:d.q3},{type:this.MAX,value:d.max},...d.upperOutliers.map(Y=>({type:this.UPPER_OUTLIER,value:Y})),{type:this.GLOBAL_MAX,value:t.max}],y=new Array;let b=!0;for(let Y=0;Y<h.length-1;Y++){const se=h[Y],ue=h[Y+1],re=Math.abs(b?ue.value-se.value:se.value-h[Y-1].value);se.type===this.LOWER_OUTLIER||se.type===this.UPPER_OUTLIER?(y.push({type:se.type,length:0,numChars:1}),y.push({type:this.BLANK,length:re,numChars:0})):se.type===this.Q2?(b=!1,y.push({type:this.Q2,length:0,numChars:2})):se.type===this.GLOBAL_MIN||se.type===this.GLOBAL_MAX?y.push({type:this.BLANK,length:re,numChars:0}):y.push({type:se.type,length:re,numChars:1})}let x=y.reduce((Y,se)=>Y+(se.numChars>0?se.numChars:0),0),[T,w,C,R]=[-1,-1,-1,-1];for(let Y=0;Y<y.length;Y++)y[Y].type===this.MIN&&y[Y].length>0&&(T=Y),y[Y].type===this.MAX&&y[Y].length>0&&(w=Y),y[Y].type===this.Q1&&(C=Y),y[Y].type===this.Q3&&(R=Y);T!==-1&&w!==-1&&y[T].length!==y[w].length&&(y[T].length>y[w].length?(y[T].numChars++,x++):(y[w].numChars++,x++)),C!==-1&&R!==-1&&y[C].length!==y[R].length&&(y[C].length>y[R].length?(y[C].numChars++,x++):(y[R].numChars++,x++));const _=Math.max(0,n-x),N=y.reduce((Y,se)=>Y+(se.type!==this.Q2&&se.length>0?se.length:0),0);for(const Y of y)if(Y.type!==this.Q2&&Y.length>0){const se=Math.round(Y.length/N*_);Y.numChars+=se}const z=y.reduce((Y,se)=>Y+se.numChars,0);let B=n-z,V=0;for(;B!==0;){const Y=y[V%y.length];Y.type!==this.BLANK&&Y.type!==this.Q2&&Y.length>0&&(Y.numChars+=B>0?1:-1,B+=B>0?-1:1),V++}let I=-1;const P=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];s.push(Array.from({length:P.length}).fill(-1));for(const Y of y){Y.type!==this.BLANK&&Y.type!==this.GLOBAL_MIN&&Y.type!==this.GLOBAL_MAX&&(I=P.indexOf(Y.type),s[f][I]=i.length);for(let se=0;se<Y.numChars;se++){let ue="⠀";Y.type===this.MIN||Y.type===this.MAX?ue="⠒":Y.type===this.Q1||Y.type===this.Q3?ue="⠿":Y.type===this.Q2?ue=se===0?"⠸":"⠇":Y.type===this.LOWER_OUTLIER||Y.type===this.UPPER_OUTLIER?ue="⠂":Y.type===this.BLANK&&(ue="⠀"),i.push(ue),o.push({row:f,col:I})}}for(let Y=0;Y<3;Y++)if(s[f][Y]===-1){for(let se=Y+1;se<=3;se++)if(s[f][se]!==-1){s[f][Y]=s[f][se];break}}for(let Y=6;Y>3;Y--)if(s[f][Y]===-1){for(let se=Y-1;se>=3;se--)if(s[f][se]!==-1){s[f][Y]=s[f][se];break}}i.push(ge.NEW_LINE),o.push({row:f,col:I})}return{value:i.join(ge.EMPTY),cellToIndex:s,indexToCell:o}}}class bV{encode(t){const n=new Array,i=new Array,o=new Array,s=(t.max-t.min)/3,f=t.min+s,d=f+s;for(let h=0;h<t.values.length;h++){i.push(new Array);for(let y=0;y<t.values[h].length;y++)t.values[h][y]===0?n.push(" "):t.values[h][y]<=f?n.push("⠤"):t.values[h][y]<=d?n.push("⠒"):n.push("⠉"),i[h].push(o.length),o.push({row:h,col:y});n.push(ge.NEW_LINE),i[h].push(o.length),o.push({row:h,col:t.values[h].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class kC{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const{low:f,medium:d,mediumHigh:h,high:y}=this.getThresholds(s,t);for(let b=0;b<t.values[s].length;b++){const x=t.values[s][b],T=b>0?t.values[s][b-1]:null,w=this.getBrailleChar(x,T,f,d,y,h);n.push(w),i[s].push(o.length),o.push({row:s,col:b})}n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}getBrailleChar(t,n,i,o,s,f){return f===void 0&&(f=s),t<=i&&n!==null&&n>i?n<=o?"⢄":n<=f?"⢆":"⢇":t<=i?"⣀":n!==null&&n<=i?t<=o?"⡠":t<=f?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=f?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=f?"⠔":"⠜":t<=f&&n!==null&&n>f?"⠑":t<=f?"⠒":n!==null&&n<=f?"⠊":t<=s?"⠉":""}getBraille6Char(t,n,i,o,s){const f=x=>x<=i?"low":x<=o?"medium":(x<=s,"high"),d=f(t),h=n!==null?f(n):null,y={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},b=`${d},${h}`;return y[b]||""}addDot8(t){if(!t||t.length===0)return"⢀";const o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class SV extends kC{getThresholds(t,n){const i=Array.isArray(n.min)?n.min[t]:n.min,o=Array.isArray(n.max)?n.max[t]:n.max,s=(o-i)/3,f=i+s,d=f+s;return{low:f,medium:d,high:o}}encode(t){var s;const n=new Array,i=new Array,o=new Array;for(let f=0;f<t.values.length;f++){i.push(new Array);const{low:d,medium:h,high:y}=this.getThresholds(f,t);for(let b=0;b<t.values[f].length;b++){const x=t.values[f][b],T=b>0?t.values[f][b-1]:null;let w=this.getBraille6Char(x,T,d,h,y);((s=t.custom)==null?void 0:s[b])==="Bear"&&(w=this.addDot8(w)),n.push(w),i[f].push(o.length),o.push({row:f,col:b})}n.push(ge.NEW_LINE),i[f].push(o.length),o.push({row:f,col:t.values[f].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class NC extends kC{getThresholds(t,n){const i=(n.max[t]-n.min[t])/4,o=n.min[t]+i,s=o+i,f=s+i,d=n.max[t];return{low:o,medium:s,mediumHigh:f,high:d}}}class xV{constructor(t,n,i){H(this,"context");H(this,"notification");H(this,"display");H(this,"enabled");H(this,"cacheId");H(this,"cache");H(this,"encoders");H(this,"onChangeEmitter");H(this,"onChange");this.context=t,this.notification=n,this.display=i,this.enabled=!1,this.cacheId=ge.EMPTY,this.cache=null,this.encoders=new Map([[or.BAR,new gv],[or.BOX,new vV],[or.CANDLESTICK,new SV],[or.DODGED,new gv],[or.HEATMAP,new bV],[or.HISTOGRAM,new gv],[or.LINE,new NC],[or.NORMALIZED,new gv],[or.SMOOTH,new NC],[or.STACKED,new gv]]),this.onChangeEmitter=new Md,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 i=n.braille;if(this.cache===null||this.cacheId!==i.id){const o=this.encoders.get(n.traceType);this.cache=o.encode(i,DC),this.cacheId=i.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[i.row][i.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:i}=this.cache.indexToCell[t];this.context.moveToIndex(n,i)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const i=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(i);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(fn.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var zC=(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))(zC||{});class IC{constructor(){}static async post(t,n,i){const o={...this.DEFAULT_HEADERS,...i};return this.request(t,"POST",o,n)}static async request(t,n,i,o){try{const s=await fetch(t,{method:n,headers:i,body:o});return s.ok?{success:!0,data:await s.json()}:{success:!1,error:{statusCode:s.status,message:`API Error: ${s.status} - ${s.statusText}`}}}catch(s){return console.error(`Error in API ${n} request to ${t}:`,s),{success:!1,error:{statusCode:zC.SERVER_ERROR,message:s instanceof Error?s.message:"Unknown error occurred"}}}}}H(IC,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const EV=`You are a helpful assistant that answers questions about statistical visualizations. Your role is to:
|
|
308
308
|
1. Answer the user's specific question directly and clearly
|
|
309
309
|
2. Use simple, everyday language with minimal statistical terms
|
|
310
310
|
3. Provide relevant information from the data when needed
|