kline-orderbook-chart 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var C={FILL_RECT:1,STROKE_RECT:2,LINE:3,DASHED_LINE:4,POLYLINE:5,TEXT:6,CIRCLE:7,TRIANGLE:8,SAVE:9,RESTORE:10,CLIP_RECT:11,ROTATED_TEXT:12,BUBBLE_3D:13,FILL_POLYGON:14,DASHED_POLYLINE:15,END_FRAME:255},he=["left","center","right"],_t=new Map,ce=4096;function pe(e,o,s,t){return e<<24|o<<16|s<<8|t}function X(e,o,s,t){let l=pe(e,o,s,t),a=_t.get(l);return a||(a=`rgba(${e},${o},${s},${(t/255).toFixed(3)})`,_t.size>=ce&&_t.clear(),_t.set(l,a),a)}var Xt=new TextDecoder;function dt(e,o,s,t){let l=o.buffer;if(s+t>l.byteLength)return;let a=new DataView(l,s,t),i=new Uint8Array(l,s,t),r=0,n="",_="",u=-1,m="";for(;r<t;){let f=i[r];if(r+=1,f===C.END_FRAME)break;switch(f){case C.FILL_RECT:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4,w!==n&&(e.fillStyle=w,n=w),e.fillRect(d,h,p,c);break}case C.STROKE_RECT:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let S=a.getFloat32(r,!0);r+=4,w!==_&&(e.strokeStyle=w,_=w),S!==u&&(e.lineWidth=S,u=S),e.strokeRect(d,h,p,c);break}case C.LINE:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let S=a.getFloat32(r,!0);r+=4,e.beginPath(),w!==_&&(e.strokeStyle=w,_=w),S!==u&&(e.lineWidth=S,u=S),e.setLineDash([]),e.moveTo(d,h),e.lineTo(p,c),e.stroke();break}case C.DASHED_LINE:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let S=a.getFloat32(r,!0);r+=4;let M=a.getFloat32(r,!0);r+=4;let E=a.getFloat32(r,!0);r+=4,e.beginPath(),w!==_&&(e.strokeStyle=w,_=w),S!==u&&(e.lineWidth=S,u=S),e.setLineDash([M,E]),e.moveTo(d,h),e.lineTo(p,c),e.stroke(),e.setLineDash([]);break}case C.POLYLINE:{let d=a.getUint16(r,!0);r+=2;let h=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let p=a.getFloat32(r,!0);if(r+=4,d>0){let c=new Float32Array(d*2);for(let w=0;w<d;w++)c[w*2]=a.getFloat32(r,!0),r+=4,c[w*2+1]=a.getFloat32(r,!0),r+=4;if(e.beginPath(),h!==_&&(e.strokeStyle=h,_=h),p!==u&&(e.lineWidth=p,u=p),e.setLineDash([]),e.lineJoin="round",e.lineCap="round",d<=3){e.moveTo(c[0],c[1]);for(let w=1;w<d;w++)e.lineTo(c[w*2],c[w*2+1])}else{e.moveTo(c[0],c[1]),e.lineTo((c[0]+c[2])*.5,(c[1]+c[3])*.5);for(let w=1;w<d-1;w++){let S=c[w*2],M=c[w*2+1],E=c[(w+1)*2],I=c[(w+1)*2+1];e.quadraticCurveTo(S,M,(S+E)*.5,(M+I)*.5)}e.lineTo(c[(d-1)*2],c[(d-1)*2+1])}e.stroke()}break}case C.TEXT:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=i[r];r+=1;let S=a.getUint16(r,!0);r+=2;let M=Xt.decode(new Uint8Array(o.buffer,s+r,S));r+=S,p!==n&&(e.fillStyle=p,n=p);let E=`${c}px "IBM Plex Mono",monospace`;E!==m&&(e.font=E,m=E),e.textAlign=he[w]||"left",e.textBaseline="middle",e.fillText(M,d,h);break}case C.CIRCLE:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let w=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let S=a.getFloat32(r,!0);r+=4,e.beginPath(),e.arc(d,h,p,0,Math.PI*2),c!==n&&(e.fillStyle=c,n=c),e.fill(),S>0&&(w!==_&&(e.strokeStyle=w,_=w),S!==u&&(e.lineWidth=S,u=S),e.stroke());break}case C.TRIANGLE:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=a.getFloat32(r,!0);r+=4;let S=a.getFloat32(r,!0);r+=4;let M=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4,e.beginPath(),e.moveTo(d,h),e.lineTo(p,c),e.lineTo(w,S),e.closePath(),M!==n&&(e.fillStyle=M,n=M),e.fill();break}case C.SAVE:{e.save();break}case C.RESTORE:{e.restore(),n="",_="",u=-1,m="";break}case C.CLIP_RECT:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4,e.beginPath(),e.rect(d,h,p,c),e.clip();break}case C.ROTATED_TEXT:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=a.getFloat32(r,!0);r+=4;let S=a.getUint16(r,!0);r+=2;let M=Xt.decode(i.subarray(r,r+S));r+=S;let E=`${c}px sans-serif`;E!==m&&(e.font=E,m=E),p!==n&&(e.fillStyle=p,n=p),e.textAlign="center",e.textBaseline="middle",e.save(),e.translate(d,h),e.rotate(w),e.fillText(M,0,0),e.restore();break}case C.BUBBLE_3D:{let d=a.getFloat32(r,!0);r+=4;let h=a.getFloat32(r,!0);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=i[r],w=i[r+1],S=i[r+2],M=i[r+3];r+=4;let E=i[r],I=i[r+1],P=i[r+2],U=i[r+3];r+=4;let G=i[r],tt=i[r+1],et=i[r+2],lt=i[r+3];r+=4;let mt=a.getFloat32(r,!0);r+=4;let L=p;if(L<10){let N=`rgba(${c},${w},${S},${(M/255).toFixed(3)})`;e.beginPath(),e.arc(d,h,L,0,Math.PI*2),e.fillStyle=N,e.fill(),n=""}else if(L<18){let N=d-L*.25,A=h-L*.25,q=e.createRadialGradient(N,A,L*.08,d,h,L);q.addColorStop(0,`rgba(${E},${I},${P},${(U/255).toFixed(3)})`),q.addColorStop(1,`rgba(${c},${w},${S},${(M/255).toFixed(3)})`),e.beginPath(),e.arc(d,h,L,0,Math.PI*2),e.fillStyle=q,e.fill(),n=""}else{let N=d-L*.25,A=h-L*.25,q=e.createRadialGradient(d,h,L*.85,d,h,L*1.2);q.addColorStop(0,`rgba(${G},${tt},${et},${(lt/255*.5).toFixed(3)})`),q.addColorStop(1,`rgba(${G},${tt},${et},0)`),e.beginPath(),e.arc(d,h,L*1.2,0,Math.PI*2),e.fillStyle=q,e.fill();let j=e.createRadialGradient(N,A,L*.08,d,h,L);j.addColorStop(0,`rgba(${E},${I},${P},${(U/255).toFixed(3)})`),j.addColorStop(1,`rgba(${c},${w},${S},${(M/255).toFixed(3)})`),e.beginPath(),e.arc(d,h,L,0,Math.PI*2),e.fillStyle=j,e.fill();let rt=L*.2,K=e.createRadialGradient(N,A,0,N,A,rt);K.addColorStop(0,"rgba(255,255,255,0.22)"),K.addColorStop(1,"rgba(255,255,255,0)"),e.beginPath(),e.arc(N,A,rt,0,Math.PI*2),e.fillStyle=K,e.fill(),n=""}break}case C.FILL_POLYGON:{let d=a.getUint16(r,!0);r+=2;let h=X(i[r],i[r+1],i[r+2],i[r+3]);if(r+=4,d>2){e.beginPath();let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4,e.moveTo(p,c);for(let w=1;w<d;w++)e.lineTo(a.getFloat32(r,!0),a.getFloat32(r+4,!0)),r+=8;e.closePath(),h!==n&&(e.fillStyle=h,n=h),e.fill()}else r+=d*8;break}case C.DASHED_POLYLINE:{let d=a.getUint16(r,!0);r+=2;let h=X(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let p=a.getFloat32(r,!0);r+=4;let c=a.getFloat32(r,!0);r+=4;let w=a.getFloat32(r,!0);if(r+=4,d>1){e.beginPath(),h!==_&&(e.strokeStyle=h,_=h),p!==u&&(e.lineWidth=p,u=p),e.setLineDash([c,w]),e.lineJoin="round";let S=a.getFloat32(r,!0);r+=4;let M=a.getFloat32(r,!0);r+=4,e.moveTo(S,M);for(let E=1;E<d;E++)e.lineTo(a.getFloat32(r,!0),a.getFloat32(r+4,!0)),r+=8;e.stroke(),e.setLineDash([])}else r+=d*8;break}default:return}}}var O={trendline:{type:"2point",previewKind:0,addFn:"add_trendline"},arrow:{type:"2point",previewKind:4,addFn:"add_arrow"},measure:{type:"2point",previewKind:2,addFn:"add_price_range"},fib:{type:"2point",previewKind:3,addFn:"add_fib_retracement"},long:{type:"2point",previewKind:5,addFn:"add_long_position"},short:{type:"2point",previewKind:5,addFn:"add_short_position"},hline:{type:"1point_xp",previewKind:1,addFn:"add_horizontal_line"},vwap:{type:"1point_x",previewKind:6,addFn:"add_anchored_vwap"},pricelabel:{type:"1point_xy",previewKind:7,addFn:"add_price_label"},circle:{type:"2point",previewKind:8,addFn:"add_circle"},arrowup:{type:"1point_xy",previewKind:9,addFn:"add_arrow_marker_up"},arrowdown:{type:"1point_xy",previewKind:10,addFn:"add_arrow_marker_down"},textnote:{type:"1point_xy",previewKind:11,addFn:"add_text_note"},channel:{type:"3point",previewKind:0,addFn:"add_parallel_channel"},fibext:{type:"3point",previewKind:0,addFn:"add_fib_extension",previewFn:"fib_ext"},brush:{type:"freehand"},path:{type:"npoint"},elliott:{type:"elliott_manual"},elliottauto:{type:"1point_xy",previewKind:12,addFn:"add_elliott_impulse",previewFn:"elliott"}};function ot(e){return O[e]?.type==="2point"}function st(e){return O[e]?.type==="3point"}function Q(e){let o=O[e]?.type;return o==="1point"||o==="1point_x"||o==="1point_xy"||o==="1point_xp"}function ht(e){return O[e]?.type==="freehand"}function V(e){return O[e]?.type==="npoint"}function W(e){return O[e]?.type==="elliott_manual"}var Ot={r:.04,g:.49,b:1,lineWidth:2,dashed:!1,fontSize:12};function Z(e,o,s,t,l,a){a=a||Ot;let i=O[o];if(!i)return 0;let r=0;return i.type==="3point"?r=e[i.addFn](s.x1,s.y1,s.x2,s.y2,t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,s.pane):i.type==="2point"?r=e[i.addFn](s.x1,s.y1,t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,s.pane):i.type==="1point_x"?r=e[i.addFn](t,a.r,a.g,a.b,a.lineWidth,a.dashed,s.pane):i.type==="1point_xp"?r=e[i.addFn](t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,s.pane):i.type==="1point_xy"?r=e[i.addFn](t,l,a.r,a.g,a.b,a.fontSize||12,s.pane):r=e[i.addFn](l,a.r,a.g,a.b,a.lineWidth,a.dashed,s.pane),r||0}function z(e,o,s,t,l,a,i){a=a||Ot;let r=O[o];if(r){if(r.previewFn==="elliott"){e.set_elliott_preview(t,l,a.r,a.g,a.b,a.lineWidth,i);return}r.type==="3point"?s.step===1?e.set_drawing_preview(r.previewKind,s.x1,s.y1,t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,i):s.step===2&&(r.previewFn==="fib_ext"?e.set_fib_ext_preview(s.x1,s.y1,s.x2,s.y2,t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,i):e.set_channel_preview(s.x1,s.y1,s.x2,s.y2,t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,i)):r.type==="2point"?e.set_drawing_preview(r.previewKind,s.x1,s.y1,t,l,a.r,a.g,a.b,a.lineWidth,a.dashed,i):r.type==="1point_x"?e.set_drawing_preview(r.previewKind,t,0,0,0,a.r,a.g,a.b,a.lineWidth,a.dashed,i):r.type==="1point_xp"||r.type==="1point_xy"?e.set_drawing_preview(r.previewKind,t,l,0,0,a.r,a.g,a.b,a.lineWidth,a.dashed,i):e.set_drawing_preview(r.previewKind,0,l,0,0,a.r,a.g,a.b,a.lineWidth,a.dashed,i)}}function b(e,o,s,t){let l=e.screen_to_world_x(o),a;switch(t){case 1:a=e.screen_to_rsi_y(s);break;case 2:a=e.screen_to_oi_y(s);break;case 3:a=e.screen_to_fr_y(s);break;case 4:a=e.screen_to_cvd_y(s);break;default:a=e.screen_to_world_y(s);break}return{wx:l,wy:a}}function H(e){return e===4?1:e===6?2:e===8?3:e===10?4:0}function Y(e){return e===0||e===4||e===6||e===8||e===10}function Wt(e,o,s,t){e.addEventListener("wheel",r=>{if(t.disposed)return;r.preventDefault(),t.cancelMomentum();let n=r.deltaY>0?1.1:.9,_=o.hit_zone(r.offsetX,r.offsetY);r.ctrlKey?o.zoom_y(r.offsetY,n):r.shiftKey||_===2?o.zoom_x(r.offsetX,n):_===3?o.zoom_y(r.offsetY,n):o.zoom(r.offsetX,r.offsetY,n),s.onDirty()},{passive:!1}),e.addEventListener("mousedown",r=>{if(t.disposed||r.button!==0)return;t.cancelMomentum(),a();let n=performance.now();if(n-t.lastClickTime<300){t.lastClickTime=n;return}t.lastClickTime=n;let _=t.drawingMode;if(_){let m=o.hit_zone(r.offsetX,r.offsetY);if(!Y(m))return;let f=H(m),{wx:d,wy:h}=b(o,r.offsetX,r.offsetY,f),p=_.style,c=_.tool;if(W(c)){if(!_.pathStarted)_.pane=f,o.start_elliott_manual(p.r,p.g,p.b,p.lineWidth,f),o.add_elliott_manual_point(d,h),_.pathStarted=!0,_.step=1;else if(o.add_elliott_manual_point(d,h)){t.finishDrawing(),s.onDirty();return}}else if(V(c))_.pathStarted?o.add_path_point(d,h):(_.pane=f,o.start_path(p.r,p.g,p.b,p.lineWidth,p.dashed,f),o.add_path_point(d,h),_.pathStarted=!0,_.step=1);else if(ht(c))_.pane=f,o.start_brush(p.r,p.g,p.b,p.lineWidth,f),o.add_brush_point(d,h),t.isBrushing=!0;else if(st(c))if(_.step===0)_.x1=d,_.y1=h,_.pane=f,_.step=1;else if(_.step===1)_.x2=d,_.y2=h,_.step=2,o.clear_drawing_preview();else{let w=O[c];w&&w.previewFn==="fib_ext"?o.clear_fib_ext_preview():o.clear_channel_preview(),Z(o,c,_,d,h,p),t.finishDrawing()}else if(ot(c))_.step===0?(_.x1=d,_.y1=h,_.pane=f,_.step=1):(Z(o,c,_,d,h,p),t.finishDrawing());else{_.pane=f;let w=Z(o,c,_,d,h,p);t.finishDrawing(),c==="textnote"&&w>0&&(o.select_drawing(w),s.onDrawingSelected?.(w),s.onDrawingDblClick?.(w,r.offsetX,r.offsetY,r.clientX,r.clientY))}s.onDirty();return}let u=o.hit_zone(r.offsetX,r.offsetY);if(u===5){t.isResizingRsi=!0,t.resizeStartY=r.offsetY,t.resizeStartRatio=o.get_rsi_ratio(),e.style.cursor="ns-resize";return}if(u===7){t.isResizingOi=!0,t.resizeStartY=r.offsetY,t.resizeStartRatio=o.get_oi_ratio(),e.style.cursor="ns-resize";return}if(u===9){t.isResizingFr=!0,t.resizeStartY=r.offsetY,t.resizeStartRatio=o.get_fr_ratio(),e.style.cursor="ns-resize";return}if(u===11){t.isResizingCvd=!0,t.resizeStartY=r.offsetY,t.resizeStartRatio=o.get_cvd_ratio(),e.style.cursor="ns-resize";return}if(Y(u)){let m=o.get_selected_drawing();if(m>0){let c=o.hit_test_drawing_anchor(r.offsetX,r.offsetY);if(c>=0){t.isDraggingAnchor=!0,t.dragAnchorIdx=c,t.dragAnchorPane=H(u),e.style.cursor="grabbing";return}if(o.hit_test_drawing(r.offsetX,r.offsetY)===m){t.isDraggingDrawing=!0,t.dragDrawingPane=H(u);let{wx:S,wy:M}=b(o,r.offsetX,r.offsetY,t.dragDrawingPane);t.dragDrawingLastWx=S,t.dragDrawingLastWy=M,e.style.cursor="move";return}}let f=o.hit_test_drawing(r.offsetX,r.offsetY);if(f>0){o.deselect_marker(),s.onMarkerSelected?.(0),o.select_drawing(f),s.onDrawingSelected?.(f),s.onDirty();return}let d=o.hit_test_marker(r.offsetX,r.offsetY);if(d>0){o.deselect_drawing(),s.onDrawingSelected?.(0),o.select_marker(d),s.onMarkerSelected?.(d),s.onDirty();return}let h=o.get_selected_drawing(),p=o.get_selected_marker();h>0&&(o.deselect_drawing(),s.onDrawingSelected?.(0),s.onDirty()),p>0&&(o.deselect_marker(),s.onMarkerSelected?.(0),s.onDirty())}Y(u)&&(t.liqPinSx=r.offsetX,t.liqPinSy=r.offsetY,t.liqPinTimer&&clearTimeout(t.liqPinTimer),t.liqPinTimer=setTimeout(()=>{t.liqPinTimer=null,s.onLiqAnnotationPin?.(t.liqPinSx,t.liqPinSy)},700)),t.isDragging=!0,t.dragZone=u,t.lastX=r.offsetX,t.lastY=r.offsetY,u===2?e.style.cursor="ew-resize":u===3?e.style.cursor="ns-resize":e.style.cursor="grabbing"});let l=null;function a(){l&&(cancelAnimationFrame(l),l=null)}function i(r,n){let _=o.hover_hit_test(r,n),u=_[0],m=_[1],f=_[2],d=_[3],h=_[4],p=t.drawingMode;u===2?(e.style.cursor="ew-resize",o.hide_crosshair()):u===3?(e.style.cursor="ns-resize",o.hide_crosshair()):(o.set_crosshair(r,n),u===5||u===7||u===9||u===11?e.style.cursor="ns-resize":!p&&Y(u)&&m>0&&f>=0?e.style.cursor="grab":!p&&Y(u)&&m>0&&d===m?e.style.cursor="move":!p&&Y(u)&&(d>0||h>0)?e.style.cursor="pointer":e.style.cursor="crosshair"),s.onDirty(),s.onCrosshairMove?.(r,n,u),s.onVrvpHover?.(r,n)}e.addEventListener("mousemove",r=>{if(t.disposed)return;if(t.liqPinTimer){let _=Math.abs(r.offsetX-t.liqPinSx),u=Math.abs(r.offsetY-t.liqPinSy);(_>6||u>6)&&(clearTimeout(t.liqPinTimer),t.liqPinTimer=null)}if(t.isResizingRsi){let u=e.getBoundingClientRect().height-28,f=(t.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,t.resizeStartRatio+f));o.set_rsi_ratio(d),s.onDirty();return}if(t.isResizingOi){let u=e.getBoundingClientRect().height-28,f=(t.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,t.resizeStartRatio+f));o.set_oi_ratio(d),s.onDirty();return}if(t.isResizingFr){let u=e.getBoundingClientRect().height-28,f=(t.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,t.resizeStartRatio+f));o.set_fr_ratio(d),s.onDirty();return}if(t.isResizingCvd){let u=e.getBoundingClientRect().height-28,f=(t.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,t.resizeStartRatio+f));o.set_cvd_ratio(d),s.onDirty();return}if(t.isDraggingAnchor){let{wx:_,wy:u}=b(o,r.offsetX,r.offsetY,t.dragAnchorPane);o.update_drawing_anchor(t.dragAnchorIdx,_,u),o.set_crosshair(r.offsetX,r.offsetY),s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,o.hit_zone(r.offsetX,r.offsetY));return}if(t.isDraggingDrawing){let{wx:_,wy:u}=b(o,r.offsetX,r.offsetY,t.dragDrawingPane),m=_-t.dragDrawingLastWx,f=u-t.dragDrawingLastWy;o.move_drawing(m,f),t.dragDrawingLastWx=_,t.dragDrawingLastWy=u,o.set_crosshair(r.offsetX,r.offsetY),s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,o.hit_zone(r.offsetX,r.offsetY));return}let n=t.drawingMode;if(t.isBrushing&&n){let _=n.pane||0,{wx:u,wy:m}=b(o,r.offsetX,r.offsetY,_);o.add_brush_point(u,m),o.set_crosshair(r.offsetX,r.offsetY),s.onDirty();return}if(n&&W(n.tool)&&n.pathStarted){let _=n.pane||0,{wx:u,wy:m}=b(o,r.offsetX,r.offsetY,_);o.set_elliott_manual_cursor(u,m),o.set_crosshair(r.offsetX,r.offsetY);let f=o.hit_zone(r.offsetX,r.offsetY);s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(n&&V(n.tool)&&n.pathStarted){let _=n.pane||0,{wx:u,wy:m}=b(o,r.offsetX,r.offsetY,_);o.set_path_cursor(u,m),o.set_crosshair(r.offsetX,r.offsetY);let f=o.hit_zone(r.offsetX,r.offsetY);s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(n&&n.step>0){let _=n.pane||0,{wx:u,wy:m}=b(o,r.offsetX,r.offsetY,_);z(o,n.tool,n,u,m,n.style,_),o.set_crosshair(r.offsetX,r.offsetY);let f=o.hit_zone(r.offsetX,r.offsetY);s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(n&&Q(n.tool)){let _=o.hit_zone(r.offsetX,r.offsetY),u=H(_),{wx:m,wy:f}=b(o,r.offsetX,r.offsetY,u);z(o,n.tool,n,m,f,n.style,u),o.set_crosshair(r.offsetX,r.offsetY),s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,_);return}if(t.isDragging){let _=r.offsetX-t.lastX,u=r.offsetY-t.lastY;t.lastX=r.offsetX,t.lastY=r.offsetY,t.dragZone===2?o.pan_x(_):t.dragZone===3?o.pan_y(u):o.pan(_,u),s.onDirty(),s.onCrosshairMove?.(r.offsetX,r.offsetY,t.dragZone),s.onVrvpHover?.(r.offsetX,r.offsetY);return}t._pendingHoverX=r.offsetX,t._pendingHoverY=r.offsetY,l||(l=requestAnimationFrame(()=>{l=null,t.disposed||i(t._pendingHoverX,t._pendingHoverY)}))}),e.addEventListener("mouseup",()=>{t.disposed||(t.liqPinTimer&&(clearTimeout(t.liqPinTimer),t.liqPinTimer=null),t.isBrushing&&(t.isBrushing=!1,o.finish_brush(),t.finishDrawing(),s.onDirty()),t.isDragging=!1,t.isResizingRsi=!1,t.isResizingOi=!1,t.isResizingFr=!1,t.isResizingCvd=!1,t.isDraggingAnchor=!1,t.isDraggingDrawing=!1,t.dragAnchorIdx=-1,e.style.cursor="crosshair")}),e.addEventListener("mouseleave",()=>{t.disposed||(a(),t.liqPinTimer&&(clearTimeout(t.liqPinTimer),t.liqPinTimer=null),t.isBrushing&&(t.isBrushing=!1,o.finish_brush(),t.finishDrawing()),t.isDragging=!1,t.isResizingRsi=!1,t.isResizingOi=!1,t.isResizingFr=!1,t.isResizingCvd=!1,t.isDraggingAnchor=!1,t.isDraggingDrawing=!1,t.dragAnchorIdx=-1,o.hide_crosshair(),e.style.cursor="crosshair",s.onDirty(),s.onCrosshairHide?.(),s.onVrvpHover?.(null,null))}),e.addEventListener("dblclick",r=>{if(t.disposed)return;r.preventDefault(),r.stopPropagation();let n=t.drawingMode;if(n&&W(n.tool)&&n.pathStarted){o.finish_elliott_manual(),t.finishDrawing(),s.onDirty();return}if(n&&V(n.tool)&&n.pathStarted){o.finish_path(),t.finishDrawing(),s.onDirty();return}if(n)return;let _=o.hit_test_drawing(r.offsetX,r.offsetY);_>0&&(o.select_drawing(_),s.onDirty(),s.onDrawingDblClick?.(_,r.offsetX,r.offsetY,r.clientX,r.clientY))}),e.addEventListener("contextmenu",r=>{if(t.disposed)return;let n=t.drawingMode;if(n&&W(n.tool)&&n.pathStarted){r.preventDefault(),r.stopPropagation(),o.finish_elliott_manual(),t.finishDrawing(),s.onDirty();return}if(n&&V(n.tool)&&n.pathStarted){r.preventDefault(),r.stopPropagation(),o.finish_path(),t.finishDrawing(),s.onDirty();return}})}function Zt(e,o,s,t){e.addEventListener("touchstart",l=>{if(!t.disposed){if(l.preventDefault(),t.cancelMomentum(),l.touches.length===2){clearTimeout(t.longPressTimer),t.isCrosshairMode=!1;let a=e.getBoundingClientRect(),i=l.touches[1].clientX-l.touches[0].clientX,r=l.touches[1].clientY-l.touches[0].clientY;t.lastTouchDist=Math.sqrt(i*i+r*r),t.lastX=(l.touches[0].clientX+l.touches[1].clientX)/2-a.left,t.lastY=(l.touches[0].clientY+l.touches[1].clientY)/2-a.top,t.dragZone=o.hit_zone(t.lastX,t.lastY)}else if(l.touches.length===1){let a=e.getBoundingClientRect(),i=l.touches[0].clientX-a.left,r=l.touches[0].clientY-a.top;t.touchStartX=i,t.touchStartY=r,t.touchMoved=!1;let n=t.drawingMode;if(n){let d=o.hit_zone(i,r);if(Y(d)){let h=H(d),{wx:p,wy:c}=b(o,i,r,h),w=n.tool;if(W(w)){if(!n.pathStarted)n.pane=h,o.start_elliott_manual(n.style.r,n.style.g,n.style.b,n.style.lineWidth,h),o.add_elliott_manual_point(p,c),n.pathStarted=!0,n.step=1;else if(o.add_elliott_manual_point(p,c)){t.finishDrawing(),s.onDirty();return}}else V(w)?n.pathStarted?o.add_path_point(p,c):(n.pane=h,o.start_path(n.style.r,n.style.g,n.style.b,n.style.lineWidth,n.style.dashed,h),o.add_path_point(p,c),n.pathStarted=!0,n.step=1):ht(w)?(n.pane=h,o.start_brush(n.style.r,n.style.g,n.style.b,n.style.lineWidth,h),o.add_brush_point(p,c),t.isBrushing=!0):st(w)?n.step===0?(n.x1=p,n.y1=c,n.pane=h,n.step=1,n._stepAtTouchStart=0,z(o,w,n,p,c,n.style,h)):n.step===1?(n._stepAtTouchStart=1,z(o,w,n,p,c,n.style,n.pane)):(n._stepAtTouchStart=2,z(o,w,n,p,c,n.style,n.pane)):ot(w)?n.step===0?(n.x1=p,n.y1=c,n.pane=h,n.step=1,n._stepAtTouchStart=0,z(o,w,n,p,c,n.style,h)):(n._stepAtTouchStart=1,z(o,w,n,p,c,n.style,n.pane)):Q(w)?(n.pane=h,z(o,w,n,p,c,n.style,h)):(n.pane=h,Z(o,w,n,p,c,n.style),t.finishDrawing());o.set_crosshair(i,r),s.onDirty(),s.onCrosshairMove?.(i,r,d)}return}let _=o.hover_hit_test(i,r),u=_[0],m=_[1],f=_[2];if(Y(u)&&!t.drawingMode&&m>0){if(f>=0){t.isDraggingAnchor=!0,t.dragAnchorIdx=f,t.dragAnchorPane=H(u);return}if(_[3]===m){t.isDraggingDrawing=!0,t.dragDrawingPane=H(u);let{wx:h,wy:p}=b(o,i,r,t.dragDrawingPane);t.dragDrawingLastWx=h,t.dragDrawingLastWy=p;return}}t.isDragging=!0,t.isCrosshairMode=!1,t.lastX=i,t.lastY=r,t.dragZone=u,clearTimeout(t.longPressTimer),t.longPressTimer=setTimeout(()=>{t.isDragging&&!t.touchMoved&&(t.isCrosshairMode=!0,o.set_crosshair(i,r),s.onDirty(),s.onCrosshairMove?.(i,r,t.dragZone),s.onVrvpHover?.(i,r))},300),Y(t.dragZone)&&(t.liqPinSx=i,t.liqPinSy=r,t.liqPinTimer&&clearTimeout(t.liqPinTimer),t.liqPinTimer=setTimeout(()=>{t.liqPinTimer=null,t.touchMoved||s.onLiqAnnotationPin?.(t.liqPinSx,t.liqPinSy)},700))}}},{passive:!1}),e.addEventListener("touchmove",l=>{if(t.disposed)return;l.preventDefault();let a=e.getBoundingClientRect();if(t.isDraggingAnchor&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top,{wx:_,wy:u}=b(o,r,n,t.dragAnchorPane);o.update_drawing_anchor(t.dragAnchorIdx,_,u),o.set_crosshair(r,n),s.onDirty();return}if(t.isDraggingDrawing&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top;t.touchMoved=!0;let{wx:_,wy:u}=b(o,r,n,t.dragDrawingPane),m=_-t.dragDrawingLastWx,f=u-t.dragDrawingLastWy;o.move_drawing(m,f),t.dragDrawingLastWx=_,t.dragDrawingLastWy=u,o.set_crosshair(r,n),s.onDirty();return}let i=t.drawingMode;if(t.isBrushing&&i&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top,_=i.pane||0,{wx:u,wy:m}=b(o,r,n,_);o.add_brush_point(u,m),o.set_crosshair(r,n),s.onDirty(),t.touchMoved=!0;return}if(i&&W(i.tool)&&i.pathStarted&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top,_=i.pane||0,{wx:u,wy:m}=b(o,r,n,_);o.set_elliott_manual_cursor(u,m),o.set_crosshair(r,n),s.onDirty(),t.touchMoved=!0;return}if(i&&V(i.tool)&&i.pathStarted&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top,_=i.pane||0,{wx:u,wy:m}=b(o,r,n,_);o.set_path_cursor(u,m),o.set_crosshair(r,n),s.onDirty(),t.touchMoved=!0;return}if(i&&i.step>0&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top;!t.touchMoved&&(Math.abs(r-t.touchStartX)>10||Math.abs(n-t.touchStartY)>10)&&(t.touchMoved=!0);let _=i.pane||0,{wx:u,wy:m}=b(o,r,n,_);z(o,i.tool,i,u,m,i.style,_),o.set_crosshair(r,n);let f=o.hit_zone(r,n);s.onDirty(),s.onCrosshairMove?.(r,n,f);return}if(i&&Q(i.tool)&&l.touches.length===1){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top,_=o.hit_zone(r,n),u=H(_),{wx:m,wy:f}=b(o,r,n,u);z(o,i.tool,i,m,f,i.style,u),o.set_crosshair(r,n),s.onDirty(),s.onCrosshairMove?.(r,n,_);return}if(l.touches.length===2){t.velSamples=[];let r=l.touches[1].clientX-l.touches[0].clientX,n=l.touches[1].clientY-l.touches[0].clientY,_=Math.sqrt(r*r+n*n),u=t.lastTouchDist/_,m=(l.touches[0].clientX+l.touches[1].clientX)/2-a.left,f=(l.touches[0].clientY+l.touches[1].clientY)/2-a.top;t.dragZone===3?o.zoom_y(f,u):t.dragZone===2?o.zoom_x(m,u):(o.zoom(m,f,u),o.pan(m-t.lastX,f-t.lastY)),t.lastTouchDist=_,t.lastX=m,t.lastY=f,s.onDirty()}else if(l.touches.length===1&&t.isDragging){let r=l.touches[0].clientX-a.left,n=l.touches[0].clientY-a.top,_=r-t.lastX,u=n-t.lastY;!t.touchMoved&&(Math.abs(r-t.touchStartX)>10||Math.abs(n-t.touchStartY)>10)&&(t.touchMoved=!0,t.isCrosshairMode||clearTimeout(t.longPressTimer),t.liqPinTimer&&(clearTimeout(t.liqPinTimer),t.liqPinTimer=null)),t.isCrosshairMode?(o.set_crosshair(r,n),s.onDirty(),s.onCrosshairMove?.(r,n,t.dragZone),s.onVrvpHover?.(r,n)):(t.lastX=r,t.lastY=n,t.recordVelocity(_,u),t.dragZone===2?o.pan_x(_):t.dragZone===3?o.pan_y(u):o.pan(_,u),s.onDirty())}},{passive:!1}),e.addEventListener("touchend",l=>{if(t.disposed)return;if(clearTimeout(t.longPressTimer),t.liqPinTimer&&(clearTimeout(t.liqPinTimer),t.liqPinTimer=null),t.isDraggingAnchor){t.isDraggingAnchor=!1,t.dragAnchorIdx=-1,o.hide_crosshair(),s.onDirty(),s.onCrosshairHide?.();return}if(t.isDraggingDrawing){if(t.isDraggingDrawing=!1,o.hide_crosshair(),s.onDirty(),s.onCrosshairHide?.(),!t.touchMoved){let i=o.get_selected_drawing();if(i>0){let r=e.getBoundingClientRect();s.onDrawingDblClick?.(i,t.touchStartX,t.touchStartY,t.touchStartX+r.left,t.touchStartY+r.top)}}return}if(t.isBrushing){t.isBrushing=!1,o.finish_brush(),t.finishDrawing(),s.onDirty(),s.onCrosshairHide?.();return}let a=t.drawingMode;if(a&&W(a.tool)&&a.pathStarted){let i=Date.now(),r=t.touchStartX-(t._pathLastTapX||0),n=t.touchStartY-(t._pathLastTapY||0),_=Math.sqrt(r*r+n*n);i-(t._pathLastTapTime||0)<350&&_<30?(o.finish_elliott_manual(),t.finishDrawing(),t._pathLastTapTime=0):(t._pathLastTapTime=i,t._pathLastTapX=t.touchStartX,t._pathLastTapY=t.touchStartY),t.isDragging=!1,t.lastTouchDist=0,s.onDirty();return}if(a&&V(a.tool)&&a.pathStarted){let i=Date.now(),r=t.touchStartX-(t._pathLastTapX||0),n=t.touchStartY-(t._pathLastTapY||0),_=Math.sqrt(r*r+n*n);i-(t._pathLastTapTime||0)<350&&_<30?(o.finish_path(),t.finishDrawing(),t._pathLastTapTime=0):(t._pathLastTapTime=i,t._pathLastTapX=t.touchStartX,t._pathLastTapY=t.touchStartY),t.isDragging=!1,t.lastTouchDist=0,s.onDirty();return}if(a&&st(a.tool)){let i=a._stepAtTouchStart;if(a.step===1&&(i===1||t.touchMoved)){let r=e.getBoundingClientRect(),n=l.changedTouches?.[0];if(n){let _=n.clientX-r.left,u=n.clientY-r.top,m=a.pane||0,{wx:f,wy:d}=b(o,_,u,m);a.x2=f,a.y2=d,a.step=2,o.clear_drawing_preview()}}else if(a.step===2&&(i===2||t.touchMoved)){let r=e.getBoundingClientRect(),n=l.changedTouches?.[0];if(n){let _=n.clientX-r.left,u=n.clientY-r.top,m=a.pane||0,{wx:f,wy:d}=b(o,_,u,m),h=O[a.tool];h&&h.previewFn==="fib_ext"?o.clear_fib_ext_preview():o.clear_channel_preview(),Z(o,a.tool,a,f,d,a.style),t.finishDrawing()}}t.isDragging=!1,t.lastTouchDist=0,t.drawingMode||(o.hide_crosshair(),s.onCrosshairHide?.()),s.onDirty();return}if(a&&a.step===1&&ot(a.tool)){if(a._stepAtTouchStart===1||t.touchMoved){let r=e.getBoundingClientRect(),n=l.changedTouches?.[0];if(n){let _=n.clientX-r.left,u=n.clientY-r.top,m=a.pane||0,{wx:f,wy:d}=b(o,_,u,m);Z(o,a.tool,a,f,d,a.style),t.finishDrawing()}}t.isDragging=!1,t.lastTouchDist=0,t.drawingMode||(o.hide_crosshair(),s.onCrosshairHide?.()),s.onDirty();return}if(a&&Q(a.tool)){let i=e.getBoundingClientRect(),r=l.changedTouches?.[0];if(r){let n=r.clientX-i.left,_=r.clientY-i.top,u=o.hit_zone(n,_),m=Y(u)?H(u):a.pane||0,{wx:f,wy:d}=b(o,n,_,m),h=a.tool;o.clear_drawing_preview();let p=Z(o,h,a,f,d,a.style);t.finishDrawing(),h==="textnote"&&p>0&&(o.select_drawing(p),s.onDrawingSelected?.(p),s.onDrawingDblClick?.(p,n,_,n+i.left,_+i.top))}t.isDragging=!1,t.lastTouchDist=0,o.hide_crosshair(),s.onCrosshairHide?.(),s.onDirty();return}if(!t.touchMoved&&!t.drawingMode&&t.isDragging){let i=Date.now(),r=t.touchStartX-t.lastTapX,n=t.touchStartY-t.lastTapY,_=Math.sqrt(r*r+n*n),u=i-t.lastTapTime<350&&_<30,m=o.hover_hit_test(t.touchStartX,t.touchStartY),f=m[0],d=m[1],h=m[3],p=m[4];if(Y(f))if(h>0){o.deselect_marker(),s.onMarkerSelected?.(0),o.select_drawing(h);let c=e.getBoundingClientRect(),w=t.touchStartX+c.left,S=t.touchStartY+c.top;s.onDrawingSelected?.(h,w,S),(d<=0||d===h)&&s.onDrawingDblClick?.(h,t.touchStartX,t.touchStartY,w,S),s.onDirty()}else p>0?(o.deselect_drawing(),s.onDrawingSelected?.(0),o.select_marker(p),s.onMarkerSelected?.(p),s.onDirty()):(d>0&&(o.deselect_drawing(),s.onDrawingSelected?.(0),s.onDirty()),o.get_selected_marker()>0&&(o.deselect_marker(),s.onMarkerSelected?.(0),s.onDirty()));t.lastTapTime=i,t.lastTapX=t.touchStartX,t.lastTapY=t.touchStartY}t.touchMoved&&!t.isCrosshairMode&&!t.drawingMode&&t.startMomentum(t.dragZone),t.isDragging=!1,t.isCrosshairMode=!1,t.lastTouchDist=0,(!t.drawingMode||t.drawingMode.step===0)&&(o.hide_crosshair(),s.onCrosshairHide?.()),s.onDirty(),s.onVrvpHover?.(null,null)})}function Mt(e,o,s){let t={disposed:!1,isDragging:!1,dragZone:0,lastX:0,lastY:0,lastTouchDist:0,isResizingRsi:!1,isResizingOi:!1,isResizingFr:!1,isResizingCvd:!1,resizeStartY:0,resizeStartRatio:0,lastClickTime:0,isDraggingAnchor:!1,dragAnchorIdx:-1,dragAnchorPane:0,isBrushing:!1,isDraggingDrawing:!1,dragDrawingPane:0,dragDrawingLastWx:0,dragDrawingLastWy:0,touchStartX:0,touchStartY:0,touchMoved:!1,longPressTimer:null,isCrosshairMode:!1,liqPinTimer:null,liqPinSx:0,liqPinSy:0,velSamples:[],momentumRaf:null,momentumVx:0,momentumVy:0,momentumZone:0,lastTapTime:0,lastTapX:0,lastTapY:0,drawingMode:null},l=.92,a=.5,i=80;t.recordVelocity=function(u,m){let f=performance.now();for(t.velSamples.push({dx:u,dy:m,t:f});t.velSamples.length>0&&f-t.velSamples[0].t>i;)t.velSamples.shift()};function r(){if(t.velSamples.length<2)return{vx:0,vy:0};let u=t.velSamples[0],f=t.velSamples[t.velSamples.length-1].t-u.t;if(f<5)return{vx:0,vy:0};let d=0,h=0;for(let c of t.velSamples)d+=c.dx,h+=c.dy;let p=16.67;return{vx:d/f*p,vy:h/f*p}}t.cancelMomentum=function(){t.momentumRaf&&(cancelAnimationFrame(t.momentumRaf),t.momentumRaf=null),t.velSamples=[]},t.startMomentum=function(u){let{vx:m,vy:f}=r();if(t.velSamples=[],Math.abs(m)<a&&Math.abs(f)<a)return;t.momentumVx=m,t.momentumVy=f,t.momentumZone=u;function d(){if(t.momentumVx*=l,t.momentumVy*=l,Math.abs(t.momentumVx)<a&&Math.abs(t.momentumVy)<a){t.momentumRaf=null;return}t.momentumZone===2?o.pan_x(t.momentumVx):t.momentumZone===3?o.pan_y(t.momentumVy):o.pan(t.momentumVx,t.momentumVy),s.onDirty(),t.momentumRaf=requestAnimationFrame(d)}t.momentumRaf=requestAnimationFrame(d)};let n={setMode(u,m){u?(t.drawingMode={tool:u,style:m,step:0,x1:0,y1:0},e.style.cursor="crosshair"):(t.drawingMode?.pathStarted&&o.finish_path(),t.drawingMode=null,o.clear_drawing_preview(),e.style.cursor="crosshair"),s.onDirty()},getMode(){return t.drawingMode}};s.drawingApi?.(n),t.finishDrawing=function(){o.clear_drawing_preview(),s.onDrawingComplete?.(),t.drawingMode=null,e.style.cursor="crosshair"},Wt(e,o,s,t),Zt(e,o,s,t);let _=u=>{let m=document.activeElement?.tagName,f=m==="INPUT"||m==="TEXTAREA"||document.activeElement?.isContentEditable;if((u.key==="Delete"||u.key==="Backspace")&&!t.drawingMode&&!f){let h=o.get_selected_drawing();if(h>0){o.remove_drawing(h),s.onDrawingSelected?.(0),s.onDirty();return}let p=o.get_selected_marker();if(p>0){o.remove_marker(p),s.onMarkerSelected?.(0),s.onDirty();return}}if(u.key==="Escape"&&!t.drawingMode){if(o.get_selected_drawing()>0){o.deselect_drawing(),s.onDrawingSelected?.(0),s.onDirty();return}if(o.get_selected_marker()>0){o.deselect_marker(),s.onMarkerSelected?.(0),s.onDirty();return}}if(u.key==="Escape"&&t.drawingMode){if(t.drawingMode.pathStarted){t.drawingMode.tool==="elliott"?o.finish_elliott_manual():o.finish_path(),t.finishDrawing(),s.onDirty();return}o.clear_drawing_preview(),t.drawingMode=null,e.style.cursor="crosshair",s.onDrawingCancel?.(),s.onDirty();return}let d=20;switch(u.key){case"+":case"=":o.zoom(e.width/2,e.height/2,.9);break;case"-":o.zoom(e.width/2,e.height/2,1.1);break;case"ArrowLeft":o.pan_x(d);break;case"ArrowRight":o.pan_x(-d);break;case"ArrowUp":o.pan_y(-d);break;case"ArrowDown":o.pan_y(d);break;case"r":case"R":o.auto_scale_y();break;default:return}s.onDirty()};return window.addEventListener("keydown",_),()=>{t.disposed=!0,t.cancelMomentum(),window.removeEventListener("keydown",_)}}function $t(e,o,s){return{enableRsi(){e.enable_rsi(),o()},disableRsi(){e.disable_rsi(),o()},setRsiPeriod(t){e.set_rsi_period(t),o()},isRsiEnabled(){return e.is_rsi_enabled()},setRsiShowEma(t){e.set_rsi_show_ema(t),o()},setRsiShowWma(t){e.set_rsi_show_wma(t),o()},setRsiShowSignals(t){e.set_rsi_show_signals(t),o()},setRsiShowDivergence(t){e.set_rsi_show_divergence(t),o()},setRsiShowTraps(t){e.set_rsi_show_traps(t),o()},setRsiSmoothing(t){e.set_rsi_smoothing(t),o()},setRsiRatio(t){e.set_rsi_ratio(t),o()},getRsiRatio(){return e.get_rsi_ratio()},enableForexSignals(){e.enable_forex_signals(),o()},disableForexSignals(){e.disable_forex_signals(),o()},isForexSignalsEnabled(){return e.is_forex_signals_enabled()},setForexSignalsSetup(t){e.set_forex_signals_setup(t),o()},setForexSignalsMode(t){e.set_forex_signals_mode(t),o()},setForexSignalsShowStats(t){e.set_forex_signals_show_stats(t),o()},getForexSignalsCount(){return e.get_forex_signals_count()},enableOi(){s()||(e.enable_oi(),o())},disableOi(){s()||(e.disable_oi(),o())},isOiEnabled(){if(s())return!1;try{return e.is_oi_enabled()}catch{return!1}},setOiData(t){s()||(e.set_oi_data(t),o())},setOiDataTs(t,l){s()||(e.set_oi_data_ts(t,l),o())},setOiShowOnChart(t){s()||(e.set_oi_show_on_chart(t),o())},setOiDisplayMode(t){s()||(e.set_oi_display_mode(t),o())},setOiRatio(t){s()||(e.set_oi_ratio(t),o())},getOiRatio(){if(s())return .2;try{return e.get_oi_ratio()}catch{return .2}},enableFundingRate(){s()||(e.enable_funding_rate(),o())},disableFundingRate(){s()||(e.disable_funding_rate(),o())},isFundingRateEnabled(){if(s())return!1;try{return e.is_funding_rate_enabled()}catch{return!1}},setFrBinanceData(t,l){s()||(e.set_fr_binance_data(t,l),o())},setFrAggData(t,l){s()||(e.set_fr_agg_data(t,l),o())},setFrShowAgg(t){s()||(e.set_fr_show_agg(t),o())},setFrShowSma(t){s()||(e.set_fr_show_sma(t),o())},enableCvd(){s()||(e.enable_cvd(),o())},disableCvd(){s()||(e.disable_cvd(),o())},isCvdEnabled(){if(s())return!1;try{return e.is_cvd_enabled()}catch{return!1}},setCvdData(t,l){s()||(e.set_cvd_data(t,l),o())},setCvdMode(t){s()||(e.set_cvd_mode(t),o())},getCvdMode(){if(s())return 0;try{return e.get_cvd_mode()}catch{return 0}},setCvdShowDelta(t){s()||(e.set_cvd_show_delta(t),o())},getCvdShowDelta(){if(s())return!0;try{return e.get_cvd_show_delta()}catch{return!0}},enableLargeTrades(){s()||(e.enable_large_trades(),o())},disableLargeTrades(){s()||(e.disable_large_trades(),o())},isLargeTradesEnabled(){if(s())return!1;try{return e.is_large_trades_enabled()}catch{return!1}},setLargeTradesData(t){s()||(e.set_large_trades_data(t),o())},pushLargeTrade(t,l,a,i){s()||(e.push_large_trade(t,l,a,i),o())},clearLargeTrades(){s()||(e.clear_large_trades(),o())},setLtVolumeFilter(t,l){s()||(e.set_lt_volume_filter(t,l),o())},setLtBubbleScale(t){s()||(e.set_lt_bubble_scale(t),o())},getLtDataMinVol(){return s()?0:e.get_lt_data_min_vol()},getLtDataMaxVol(){return s()?0:e.get_lt_data_max_vol()},ltHitTest(t,l){if(s())return"";try{return e.lt_hit_test(t,l)}catch{return""}},enableVrvp(){s()||(e.enable_vrvp(),o())},disableVrvp(){s()||(e.disable_vrvp(),o())},isVrvpEnabled(){if(s())return!1;try{return e.is_vrvp_enabled()}catch{return!1}},setVrvpPocLine(t){s()||(e.set_vrvp_poc_line(t),o())},vrvpHitTest(t,l){if(s())return"";try{return e.vrvp_hit_test(t,l)}catch{return""}},enableTpo(){s()||(e.enable_tpo(),o())},disableTpo(){s()||(e.disable_tpo(),o())},isTpoEnabled(){if(s())return!1;try{return e.is_tpo_enabled()}catch{return!1}},setTpoPocLine(t){s()||(e.set_tpo_poc_line(t),o())},setTpoVaLines(t){s()||(e.set_tpo_va_lines(t),o())},setTpoIb(t){s()||(e.set_tpo_ib(t),o())},setTpoSinglePrints(t){s()||(e.set_tpo_single_prints(t),o())},setTpoPeriod(t){s()||(e.set_tpo_period(t),o())},getTpoPeriod(){if(s())return 1440;try{return e.get_tpo_period()}catch{return 1440}},setTpoNakedPoc(t){s()||(e.set_tpo_naked_poc(t),o())},setTpoProfileShape(t){s()||(e.set_tpo_profile_shape(t),o())},setTpoIbMinutes(t){s()||(e.set_tpo_ib_minutes(t),o())},setTpoLetterMinutes(t){s()||(e.set_tpo_letter_minutes(t),o())},setTpoSignals(t){s()||(e.set_tpo_signals(t),o())},isTpoSignals(){if(s())return!1;try{return e.is_tpo_signals()}catch{return!1}},enableLiqHeatmap(){s()||(e.enable_liq_heatmap(),o())},disableLiqHeatmap(){s()||(e.disable_liq_heatmap(),o())},isLiqHeatmapEnabled(){if(s())return!1;try{return e.is_liq_heatmap_enabled()}catch{return!1}},setLiqHeatmapRange(t,l){s()||(e.set_liq_heatmap_range(t,l),o())},getLiqHeatmapMin(){if(s())return 0;try{return e.get_liq_heatmap_min()}catch{return 0}},getLiqHeatmapMax(){if(s())return 1;try{return e.get_liq_heatmap_max()}catch{return 1}},getLiqHeatmapSegMax(){if(s())return 0;try{return e.get_liq_heatmap_seg_max()}catch{return 0}},setLiqHeatmapProfile(t){s()||(e.set_liq_heatmap_profile(t),o())},isLiqHeatmapProfile(){if(s())return!0;try{return e.is_liq_heatmap_profile()}catch{return!0}},setLiqHeatmapCellHeight(t){s()||(e.set_liq_heatmap_cell_height(t),o())},getLiqHeatmapCellHeight(){if(s())return 1;try{return e.get_liq_heatmap_cell_height()}catch{return 1}},setLiqHeatmapPredictions(t){s()||(e.set_liq_heatmap_predictions(t),o())},setLiqHeatmapFilledPct(t){s()||(e.set_liq_heatmap_filled_pct(t),o())},getLiqHeatmapFilledPct(){if(s())return .85;try{return e.get_liq_heatmap_filled_pct()}catch{return .85}},liqHeatmapHitTest(t,l){if(s())return"";try{return e.liq_heatmap_hit_test(t,l)}catch{return""}},liqZoneHitTest(t,l){if(s())return"";try{return e.liq_zone_hit_test(t,l)}catch{return""}},enableSmartRanges(){s()||(e.enable_smart_ranges(),o())},disableSmartRanges(){s()||(e.disable_smart_ranges(),o())},isSmartRangesEnabled(){if(s())return!1;try{return e.is_smart_ranges_enabled()}catch{return!1}},setSrTextSize(t){s()||(e.set_sr_text_size(t),o())},setSrShowOb(t){s()||(e.set_sr_show_ob(t),o())},setSrObLast(t){s()||(e.set_sr_ob_last(t),o())},setSrShowObActivity(t){s()||(e.set_sr_show_ob_activity(t),o())},setSrShowBreakers(t){s()||(e.set_sr_show_breakers(t),o())},setSrMitigation(t){s()||(e.set_sr_mitigation(t),o())},setSrShowMetrics(t){s()||(e.set_sr_show_metrics(t),o())},setSrShowHtfOb(t){s()||(e.set_sr_show_htf_ob(t),o())},setSrHtfMinutes(t){s()||(e.set_sr_htf_minutes(t),o())},setSrShowFvg(t){s()||(e.set_sr_show_fvg(t),o())},setSrFvgTheme(t){s()||(e.set_sr_fvg_theme(t),o())},setSrFvgMitigation(t){s()||(e.set_sr_fvg_mitigation(t),o())},setSrFvgHtf(t){s()||(e.set_sr_fvg_htf(t),o())},setSrFvgExtend(t){s()||(e.set_sr_fvg_extend(t),o())},setSrShowObSignals(t){s()||(e.set_sr_show_ob_signals(t),o())},setSrShowPredict(t){s()||(e.set_sr_show_predict(t),o())},setSrShowFvgSignals(t){s()||(e.set_sr_show_fvg_signals(t),o())},setSrShowSmartRev(t){s()||(e.set_sr_show_smart_rev(t),o())},setSrSmartRevHtf(t){s()||(e.set_sr_smart_rev_htf(t),o())},setSrStatsType(t){s()||(e.set_sr_stats_type(t),o())},setSrStatsPosition(t){s()||(e.set_sr_stats_position(t),o())},getSrSignalsCount(){if(s())return 0;try{return e.get_sr_signals_count()}catch{return 0}},enableEmaStructure(){s()||(e.enable_ema_structure(),o())},disableEmaStructure(){s()||(e.disable_ema_structure(),o())},isEmaStructureEnabled(){if(s())return!1;try{return e.is_ema_structure_enabled()}catch{return!1}},setEsEma1Len(t){s()||(e.set_es_ema1_len(t),o())},setEsEma2Len(t){s()||(e.set_es_ema2_len(t),o())},setEsWmaLen(t){s()||(e.set_es_wma_len(t),o())},setEsShowEma1(t){s()||(e.set_es_show_ema1(t),o())},setEsShowEma2(t){s()||(e.set_es_show_ema2(t),o())},setEsShowWma(t){s()||(e.set_es_show_wma(t),o())},setEsSwingLen(t){s()||(e.set_es_swing_len(t),o())},setEsShowBos(t){s()||(e.set_es_show_bos(t),o())},enableLiveSignals(){s()||(e.enable_live_signals(),o())},disableLiveSignals(){s()||(e.disable_live_signals(),o())},isLiveSignalsEnabled(){if(s())return!1;try{return e.is_live_signals_enabled()}catch{return!1}},setLiveSignalsData(t){s()||(e.set_live_signals_data(new Float64Array(t)),o())},clearLiveSignals(){s()||(e.clear_live_signals(),o())},setLiveSignalsLeverage(t){s()||(e.set_live_signals_leverage(t),o())},getLiveSignalsLeverage(){if(s())return 10;try{return e.get_live_signals_leverage()}catch{return 10}},setLiveSignalsTrial(t){s()||(e.set_live_signals_trial(t),o())},setLiveSignalsShowEntry(t){s()||(e.set_live_signals_show_entry(t),o())},setLiveSignalsShowTpSl(t){s()||(e.set_live_signals_show_tp_sl(t),o())},setLiveSignalsShowMaxProfit(t){s()||(e.set_live_signals_show_max_profit(t),o())},setLiveSignalsShowLabels(t){s()||(e.set_live_signals_show_labels(t),o())},setLiveSignalsShowZones(t){s()||(e.set_live_signals_show_zones(t),o())},setLiveSignalsTextSize(t){s()||(e.set_live_signals_text_size(t),o())},setLiveSignalsPipValue(t){s()||(e.set_live_signals_pip_value(t),o())},setLiveSignalsLoading(t){s()||(e.set_live_signals_loading(t),o())},getLiveSignalsCount(){if(s())return 0;try{return e.get_live_signals_count()}catch{return 0}},enableVolume(){e.enable_volume(),o()},disableVolume(){e.disable_volume(),o()},isVolumeEnabled(){return e.is_volume_enabled()},setVolumeMaPeriod(t){e.set_volume_ma_period(t),o()},setVolumeShowMa(t){e.set_volume_show_ma(t),o()},setVolumeShowSignals(t){e.set_volume_show_signals(t),o()},setVolumeColorMode(t){e.set_volume_color_mode(t),o()},getVolumeMaPeriod(){return e.get_volume_ma_period()},getVolumeShowMa(){return e.get_volume_show_ma()},getVolumeShowSignals(){return e.get_volume_show_signals()},getVolumeColorMode(){return e.get_volume_color_mode()}}}function Kt(e,o,s){return{addMarker(t,l,a){e.add_marker(t,l,a),o()},clearMarkers(){e.clear_markers(),o()},hitTestMarker(t,l){return e.hit_test_marker(t,l)},selectMarker(t){e.select_marker(t),o()},deselectMarker(){e.deselect_marker(),o()},getSelectedMarker(){return e.get_selected_marker()},removeMarker(t){e.remove_marker(t),o()},deleteSelectedMarker(){let t=e.get_selected_marker();return t>0&&(e.remove_marker(t),o()),t},addTrendline(t,l,a,i,r,n,_,u,m,f=0){let d=e.add_trendline(t,l,a,i,r,n,_,u,m,f);return o(),d},addHorizontalLine(t,l,a,i,r,n,_,u=0){let m=e.add_horizontal_line(t,l,a,i,r,n,_,u);return o(),m},addArrow(t,l,a,i,r,n,_,u,m,f=0){let d=e.add_arrow(t,l,a,i,r,n,_,u,m,f);return o(),d},addFibRetracement(t,l,a,i,r,n,_,u,m,f=0){let d=e.add_fib_retracement(t,l,a,i,r,n,_,u,m,f);return o(),d},addFibExtension(t,l,a,i,r,n,_,u,m,f,d,h=0){let p=e.add_fib_extension(t,l,a,i,r,n,_,u,m,f,d,h);return o(),p},addLongPosition(t,l,a,i,r,n,_,u,m,f=0){let d=e.add_long_position(t,l,a,i,r,n,_,u,m,f);return o(),d},addShortPosition(t,l,a,i,r,n,_,u,m,f=0){let d=e.add_short_position(t,l,a,i,r,n,_,u,m,f);return o(),d},addAnchoredVwap(t,l,a,i,r,n,_=0){let u=e.add_anchored_vwap(t,l,a,i,r,n,_);return o(),u},addPriceLabel(t,l,a,i,r,n,_=0){let u=e.add_price_label(t,l,a,i,r,n,_);return o(),u},addElliottImpulse(t,l,a,i,r,n,_=0){let u=e.add_elliott_impulse(t,l,a,i,r,n,_);return o(),u},setDrawingFontSize(t,l){e.set_drawing_font_size(t,l),o()},getDrawingFontSize(t){return e.get_drawing_font_size(t)},setDrawingText(t,l){e.set_drawing_text(t,l),o()},getDrawingText(t){return e.get_drawing_text(t)},setDrawingStyle(t,l,a,i,r){e.set_drawing_style(t,l,a,i,r),o()},getDrawingColor(t){let l=e.get_drawing_color(t);return l?{r:l>>>24&255,g:l>>>16&255,b:l>>>8&255,lineWidth:(l&255)/10}:null},getDrawingDashed(t){try{return e.get_drawing_dashed(t)}catch{return!1}},setDrawingDashed(t,l){e.set_drawing_dashed(t,l),o()},getDrawingHideLabel(t){try{return e.get_drawing_hide_label(t)}catch{return!1}},setDrawingHideLabel(t,l){e.set_drawing_hide_label(t,l),o()},getDrawingKindId(t){try{return e.get_drawing_kind_id(t)}catch{return 255}},removeDrawing(t){e.remove_drawing(t),o()},clearDrawings(){e.clear_drawings(),o()},drawingCount(){return e.drawing_count()},setDrawingPreview(t,l,a,i,r,n,_,u,m,f,d=0){e.set_drawing_preview(t,l,a,i,r,n,_,u,m,f,d),o()},clearDrawingPreview(){e.clear_drawing_preview(),o()},cancelBrush(){e.cancel_brush(),o()},selectDrawing(t){e.select_drawing(t),o()},deselectDrawing(){e.deselect_drawing(),o()},getSelectedDrawing(){return e.get_selected_drawing()},deleteSelectedDrawing(){let t=e.get_selected_drawing();return t>0&&(e.remove_drawing(t),o()),t},exportDrawingsJson(){try{return e.export_drawings_json()}catch{return"[]"}},importDrawingsJson(t){try{e.import_drawings_json(t),o()}catch(l){console.warn("[bridge] importDrawingsJson failed",l)}},screenToWorld(t,l){return{x:e.screen_to_world_x(t),y:e.screen_to_world_y(l)}},worldToScreen(t,l){try{return{x:e.world_to_screen_x(t),y:e.world_to_screen_y(l)}}catch{return null}}}}function Dt(e,o,s){return{setKlines(t,l,a,i,r,n){e.set_klines(new Float64Array(t),new Float64Array(l),new Float64Array(a),new Float64Array(i),new Float64Array(r),new Float64Array(n)),o()},setRealTimestamps(t){e.set_real_timestamps(new Float64Array(t)),o()},appendRealTimestamp(t){e.append_real_timestamp(t)},prependKlines(t,l,a,i,r,n){e.prepend_klines(new Float64Array(t),new Float64Array(l),new Float64Array(a),new Float64Array(i),new Float64Array(r),new Float64Array(n)),o()},appendKline(t,l,a,i,r,n){e.append_kline(t,l,a,i,r,n),o()},updateLastKline(t,l,a,i,r,n){e.update_last_kline(t,l,a,i,r,n),o()},popLastKline(){let t=e.pop_last_kline();return t&&o(),t},getLastClose(){try{return e.get_last_close()}catch{return 0}},getKlineCount(){if(s())return 0;try{return e.kline_count()}catch{return 0}},getKlineTimestamps(){if(s())return null;try{return e.kline_timestamps()}catch{return null}},getKlineOpens(){if(s())return null;try{return e.kline_opens()}catch{return null}},getKlineHighs(){if(s())return null;try{return e.kline_highs()}catch{return null}},getKlineLows(){if(s())return null;try{return e.kline_lows()}catch{return null}},getKlineCloses(){if(s())return null;try{return e.kline_closes()}catch{return null}},getKlineVolumes(){if(s())return null;try{return e.kline_volumes()}catch{return null}},setHeatmap(t,l,a,i,r,n,_){e.set_heatmap(new Float64Array(t),l,a,i,r,n,_),o()},appendHeatmapColumn(t,l,a,i){e.append_heatmap_column(new Float64Array(t),l,a,i),o()},updateLastHeatmapColumn(t,l,a){e.update_last_heatmap_column(new Float64Array(t),l,a),o()},getHeatmapLastTimestamp(){try{return e.get_heatmap_last_timestamp()}catch{return 0}},getHeatmapXStep(){try{return e.get_heatmap_x_step()}catch{return 0}},updateHeatmapColumnAt(t,l,a,i){e.update_heatmap_column_at(new Float64Array(t),l,a,i),o()},setHeatmapRange(t,l){e.set_heatmap_range(t,l),o()},getHeatmapDataRange(){try{return{min:e.get_heatmap_data_min(),max:e.get_heatmap_data_max()}}catch{return{min:0,max:0}}},setHeatmapPrefetchRange(t){try{e.set_heatmap_prefetch_range(t)}catch{}},clearHeatmapPrefetchRange(){try{e.clear_heatmap_prefetch_range()}catch{}},getHeatmapPrefetchMax(){try{return e.get_heatmap_prefetch_max()}catch{return 0}},setChartType(t){s()||(e.set_chart_type(t),o())},getChartType(){if(s())return 0;try{return e.get_chart_type()}catch{return 0}},setFootprintTickSize(t){s()||(e.set_footprint_tick_size(t),o())},footprintEnsureLen(t){s()||e.footprint_ensure_len(t)},footprintAddTrade(t,l,a,i){s()||e.footprint_add_trade(t,l,a,i)},footprintAddTradeBatch(t){s()||!t||t.length===0||e.footprint_add_trade_batch(t instanceof Float64Array?t:new Float64Array(t))},footprintSetBar(t,l,a,i,r){s()||(e.footprint_set_bar(t,l,a,i,r),o())},footprintClear(){s()||(e.footprint_clear(),o())},footprintClearBar(t){s()||e.footprint_clear_bar(t)},footprintPrependEmpty(t){s()||e.footprint_prepend_empty(t)},footprintSetShowSignals(t){s()||(e.footprint_set_show_signals(t),o())},footprintGetShowSignals(){if(s())return!0;try{return e.footprint_get_show_signals()}catch{return!0}},footprintSignalCount(){if(s())return 0;try{return e.footprint_signal_count()}catch{return 0}},footprintSetShowProfile(t){s()||(e.footprint_set_show_profile(t),o())},footprintGetShowProfile(){if(s())return!1;try{return e.footprint_get_show_profile()}catch{return!1}},footprintProfileHitTest(t,l){if(s())return"";try{return e.footprint_profile_hit_test(t,l)}catch{return""}}}}var me=1;function R(e){if(typeof e!="string")return{r:255,g:255,b:255,a:153};if(e.startsWith("#")){let s=e.slice(1);if(s.length===8)return{r:parseInt(s.slice(0,2),16),g:parseInt(s.slice(2,4),16),b:parseInt(s.slice(4,6),16),a:parseInt(s.slice(6,8),16)};let t=parseInt(s.slice(0,2),16),l=parseInt(s.slice(2,4),16),a=parseInt(s.slice(4,6),16);return{r:t,g:l,b:a,a:255}}let o=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\)/);return o?{r:+o[1],g:+o[2],b:+o[3],a:o[4]!==void 0?Math.round(+o[4]*255):255}:{r:255,g:255,b:255,a:153}}function bt(e,o,s){let t=new Map,l=null,a=0,i=NaN;function r(){let f;try{f=e.kline_count()}catch{return l}if(f===0)return null;let d=e.kline_closes(),h=d?.[f-1]??NaN;if(l&&!(f!==a||h!==i))return l;try{let c=e.kline_timestamps(),w=e.kline_opens(),S=e.kline_highs(),M=e.kline_lows(),E=e.kline_volumes();if(!c||!d)return l;l={timestamps:Array.from(c),open:Array.from(w),high:Array.from(S),low:Array.from(M),close:Array.from(d),volume:Array.from(E),length:f},a=f,i=h;for(let I of t.values())I._needsCompute=!0}catch{}return l}function n(){return{seriesLine(f,d="#ffffff99",h=1.5){let p=R(d);e.custom_series_line(new Float64Array(f),p.r,p.g,p.b,p.a,h)},seriesDashedLine(f,d="#ffffff66",h=1,p=4,c=4){let w=R(d);e.custom_series_dashed_line(new Float64Array(f),w.r,w.g,w.b,w.a,h,p,c)},band(f,d,h="rgba(100,149,237,0.08)"){let p=R(h);e.custom_band(new Float64Array(f),new Float64Array(d),p.r,p.g,p.b,p.a)},hline(f,d="#ffffff66",h=1){let p=R(d);e.custom_hline(f,p.r,p.g,p.b,p.a,h)},dashedHline(f,d="#ffffff66",h=1,p=6,c=4){let w=R(d);e.custom_dashed_hline(f,w.r,w.g,w.b,w.a,h,p,c)},marker(f,d,h="#e8a04a",p=3){let c=R(h);e.custom_marker(f,d,c.r,c.g,c.b,c.a,p)},markerUp(f,d,h="#26a69a",p=5){let c=R(h);e.custom_marker_up(f,d,c.r,c.g,c.b,c.a,p)},markerDown(f,d,h="#ef5350",p=5){let c=R(h);e.custom_marker_down(f,d,c.r,c.g,c.b,c.a,p)},text(f,d,h,p="#ffffffaa",c=10,w="center"){let S=R(p),M=w==="center"?1:w==="right"?2:0;e.custom_text(f,d,h,S.r,S.g,S.b,S.a,c,M)},priceLabel(f,d,h="#ffffffaa",p=10){let c=R(h);e.custom_price_label(f,d,c.r,c.g,c.b,c.a,p)},linePx(f,d,h,p,c,w=1){let S=R(c);e.custom_line_px(f,d,h,p,S.r,S.g,S.b,S.a,w)},fillRectPx(f,d,h,p,c){let w=R(c);e.custom_fill_rect_px(f,d,h,p,w.r,w.g,w.b,w.a)},strokeRectPx(f,d,h,p,c,w=1){let S=R(c);e.custom_stroke_rect_px(f,d,h,p,S.r,S.g,S.b,S.a,w)},textPx(f,d,h,p,c=10,w="left"){let S=R(p),M=w==="center"?1:w==="right"?2:0;e.custom_text_px(f,d,h,S.r,S.g,S.b,S.a,c,M)},worldToScreenX:f=>e.world_to_screen_x(f),worldToScreenY:f=>e.world_to_screen_y(f),screenToWorldX:f=>e.screen_to_world_x(f),screenToWorldY:f=>e.screen_to_world_y(f),chartArea:()=>({x:e.chart_area_x(),y:e.chart_area_y(),w:e.chart_area_w(),h:e.chart_area_h()})}}function _(f){if(!f.compute)return;let d=r();if(d)try{f._computed=f.compute(d,f.params)||{}}catch(h){console.warn(`[CustomIndicator "${f.name}"] compute error:`,h),f._computed={}}}function u(f){if(t.size===0)return;let d=r();if(!d)return;e.custom_begin();let h=n();for(let c of t.values())if(c.enabled){c._needsCompute&&(_(c),c._needsCompute=!1);try{c.render.call(c,h,c._computed||{},d)}catch(w){console.warn(`[CustomIndicator "${c.name}"] render error:`,w)}}if(e.custom_end(),e.custom_command_count()>0){let c=e.get_custom_buffer_ptr(),w=e.get_custom_buffer_len();s(f,o,c,w)}}function m(){l=null,a=0,i=NaN;for(let f of t.values())f._needsCompute=!0}return{add(f){let d=me++,h={id:d,name:f.name||`Custom ${d}`,params:{...f.params},compute:f.compute||null,render:f.render,enabled:!0,_computed:{},_needsCompute:!0};return t.set(d,h),d},remove(f){t.delete(f)},updateParams(f,d){let h=t.get(f);h&&(Object.assign(h.params,d),h._needsCompute=!0)},setEnabled(f,d){let h=t.get(f);h&&(h.enabled=d)},list(){return[...t.values()].map(f=>({id:f.id,name:f.name,params:{...f.params},enabled:f.enabled}))},invalidateCompute:m,renderAll:u}}var Ut="trial";var Et=[95,95,109,114].map(e=>String.fromCharCode(e)).join(""),ge=1297237059;function jt(e){let o=`${e}:${ge}:${(e^2043453)>>>0}`,s=2166136261;for(let t=0;t<o.length;t++)s^=o.charCodeAt(t),s=Math.imul(s,16777619);return(s>>>0).toString(36)}function at(e){return`${e}.${jt(e)}`}function nt(e){if(!e||typeof e!="string")return null;let o=e.lastIndexOf(".");if(o<1)return null;let s=parseInt(e.slice(0,o),10);return!s||s<1e9||s>2e9||e.slice(o+1)!==jt(s)?null:s}var Jt=Et+"e7x",Qt=Et+"p3q",xt="mrd_engine_session_id",kt="mrd_ce_db",x="meta",te="trial_ts",ee=Et+"ck";function Pt(){try{return nt(localStorage.getItem(Jt))}catch{return null}}function Lt(e){try{localStorage.setItem(Jt,at(e))}catch{}}function Ft(){try{return nt(localStorage.getItem(Qt))}catch{return null}}function Ct(e){try{localStorage.setItem(Qt,at(e))}catch{}}function yt(){try{return nt(sessionStorage.getItem(xt))}catch{return null}}function Rt(e){try{sessionStorage.setItem(xt,at(e))}catch{}}function At(){try{let e=document.cookie.match(new RegExp(`(?:^|;\\s*)${ee}=([^;]+)`));return e?nt(decodeURIComponent(e[1])):null}catch{return null}}function Yt(e){try{let o=encodeURIComponent(at(e));document.cookie=`${ee}=${o};path=/;max-age=${86400*400};SameSite=Lax`}catch{}}var k=null,Gt=!1;function Se(){if(!(Gt||typeof indexedDB>"u")){Gt=!0;try{let e=indexedDB.open(kt,1);e.onupgradeneeded=()=>{let o=e.result;o.objectStoreNames.contains(x)||o.createObjectStore(x)},e.onsuccess=()=>{let t=e.result.transaction(x,"readonly").objectStore(x).get(te);t.onsuccess=()=>{let l=nt(t.result);l&&(!k||l<k)&&(k=l,ve(l))}}}catch{}}}function re(e){k=e;try{let o=indexedDB.open(kt,1);o.onsuccess=()=>{o.result.transaction(x,"readwrite").objectStore(x).put(at(e),te)}}catch{}}function ve(e){let o=Math.floor(Date.now()/1e3),s=oe([Pt(),Ft(),yt(),At(),e],o);s&&s!==e||s&&(Lt(s),Ct(s),Rt(s),Yt(s))}function oe(e,o){let s=null;for(let t of e)t&&(t>o+60||t<17e8||(!s||t<s)&&(s=t));return s}function Te(){let e=Math.floor(Date.now()/1e3),o=[Pt(),Ft(),yt(),At(),k];return oe(o,e)}function Me(e){Lt(e),Ct(e),Rt(e),Yt(e),re(e)}function be(e){Pt()||Lt(e),Ft()||Ct(e),yt()||Rt(e),At()||Yt(e),k||re(e)}Se();function pt(e){if(!e||e==="trial")return Ee();try{let o=JSON.parse(atob(e)),{p:s,d:t,e:l,s:a}=o;if(!s||!a)return{valid:!1,error:"Invalid license key format"};let i={...o};if(delete i.s,a!==se(i))return{valid:!1,error:"Invalid license key signature"};if(l>0&&Date.now()/1e3>l)return{valid:!1,expired:!0,plan:s,error:`License expired on ${new Date(l*1e3).toLocaleDateString()}`};if(t&&t!=="*"&&typeof window<"u"){let r=window.location.hostname;if(!t.split(",").map(u=>u.trim()).some(u=>Pe(u,r)))return{valid:!1,error:`License not valid for domain: ${r}`}}return{valid:!0,plan:s,domain:t,expiry:l,watermark:!1}}catch{return{valid:!1,error:"Invalid license key"}}}function se(e){let o="mrd-ce-hmac-2024-x9k2m",s=JSON.stringify(e),t=o+":"+s,l=2166136261,a=1818371886,i=3735928559;for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);l=Math.imul(l^n,16777619)>>>0,a=Math.imul(a^n,1540483477)>>>0,i=Math.imul(i^n,461845907)>>>0}return(l.toString(36)+a.toString(36)+i.toString(36)).slice(0,24)}function Ee(){let e=Te();e?be(e):(e=Math.floor(Date.now()/1e3),Me(e));let o=e+14*86400,s=Date.now()/1e3,t=Math.max(0,Math.ceil((o-s)/86400));return s>o?{valid:!1,expired:!0,plan:Ut,error:"14-day trial has expired",daysLeft:0}:{valid:!0,plan:Ut,watermark:!0,daysLeft:t,trialEnd:o}}function Pe(e,o){if(e==="*"||e===o)return!0;if(e.startsWith("*.")){let s=e.slice(1);return o.endsWith(s)||o===e.slice(2)}return!1}function Le({plan:e,domain:o="*",expiryDays:s=365,name:t,email:l}){let a=s>0?Math.floor(Date.now()/1e3)+s*86400:0,i={p:e,d:o,e:a,...t?{n:t}:{},...l?{m:l}:{},i:Date.now()};return i.s=se(i),btoa(JSON.stringify(i))}var wt=null,It=null,it=null;async function ae(){return wt||it||(it=(async()=>{let e=await import("./chart_engine.js");return await e.default(),It=e.wasm_memory(),wt=e,e})(),it)}function Fe(){!wt&&!it&&ae().catch(()=>{})}async function Ce(e,o={}){let s=o.licenseKey||o.key||null,t=pt(s);if(!t.valid)if(t.expired)console.warn(`[MRD Chart Engine] ${t.error}. Get a license at https://mrd-chart.dev/pricing`);else throw new Error(`[MRD Chart Engine] ${t.error}`);t.plan==="trial"&&console.info(`[MRD Chart Engine] Trial mode \u2014 ${t.daysLeft} days remaining. Purchase: https://mrd-chart.dev/pricing`);let l=await ae(),a=window.devicePixelRatio||1,i=e.getBoundingClientRect();(i.width<1||i.height<1)&&(await new Promise(g=>{let v=new ResizeObserver(T=>{for(let F of T)if(F.contentRect.width>0&&F.contentRect.height>0){v.disconnect(),g();return}});v.observe(e.parentElement||e),setTimeout(()=>{v.disconnect(),g()},2e3)}),i=e.getBoundingClientRect());let r=Math.max(i.width,100),n=Math.max(i.height,100);e.width=r*a,e.height=n*a;let _=e.getContext("2d");_.scale(a,a);let u=new l.ChartEngine(r,n);{let g=t.expired?2:t.watermark?1:0,v=t.daysLeft||0,T=1297237059;T=Math.imul(T,31)+g>>>0,T=Math.imul(T,31)+v>>>0,T=(T^T>>>16)>>>0,T=Math.imul(T,73244475)>>>0,T=(T^T>>>16)>>>0,u.set_license_state(g,v,T)}let m=!0,f=null,d=!1,h=!1,p=!1,c=null,w=null,S=0,E=("ontouchstart"in window||navigator.maxTouchPoints>0)&&window.innerWidth<=1399?33:0;function I(){if(!(!d||h||f)){if(E>0){let g=performance.now()-S;if(g<E){w||(w=setTimeout(()=>{w=null,I()},E-g));return}}f=requestAnimationFrame(le)}}let P=()=>{m=!0,I()},U=()=>p,G=null,tt=null,et=null,lt=null,mt=null,L=null,N=null,A=null,q=0,j=null,rt=null,K=0,gt=0,J=-1,ut=!1,ft=!1,ne=Mt(e,u,{onDirty:P,onCrosshairMove:(g,v,T)=>{K=g,gt=v,J=T,ut=!0,ft=!0},onCrosshairHide:()=>{ft&&(ft=!1,ut=!0,J=-1)},drawingApi:g=>{G=g},onDrawingComplete:()=>{tt?.()},onDrawingCancel:()=>{et?.()},onDrawingSelected:(g,v,T)=>{lt?.(g,v,T)},onMarkerSelected:g=>{mt?.(g)},onDrawingDblClick:(g,v,T,F,de)=>{L?.(g,v,T,F,de)},onVrvpHover:(g,v)=>{N?.(g,v)},onLiqAnnotationPin:(g,v)=>{rt?.(g,v)}});function ie(){if(ut){if(ut=!1,!ft){c&&c(null,0,0),A&&A("");return}if(c)if(J===0||J===1){let g=u.get_tooltip_data();c(g,K,gt)}else c(null,0,0);if(A){let g=performance.now();if(J===0||J===1){if(g-q>=80){q=g;try{A(u.lt_hit_test(K,gt))}catch{}}}else A("")}}}function le(){if(f=null,!(!d||h)&&(m||u.is_dirty())){m=!1,S=performance.now();let g=!1;try{if(u.render()>0){let T=u.get_command_buffer_ptr(),F=u.get_command_buffer_len();_.save(),_.setTransform(1,0,0,1,0,0),_.clearRect(0,0,e.width,e.height),_.restore(),dt(_,It,T,F),g=!0}try{D.renderAll(_)}catch{}}catch{g||(m=!0)}ie();try{j?.()}catch{}(m||u.is_dirty())&&I()}}let ue=$t(u,P,U),fe=Kt(u,P,U),_e=Dt(u,P,U),D=bt(u,It,dt);return{engine:u,start(){d=!0,h=!1,m=!0,I()},stop(){d=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null)},resize(g){if(i=e.getBoundingClientRect(),i.width<1||i.height<1){(g||0)<8&&setTimeout(()=>this.resize((g||0)+1),250);return}a=window.devicePixelRatio||1;let v=i.width*a,T=i.height*a;e.width=v,e.height=T,_.setTransform(1,0,0,1,0,0),_.scale(a,a),u.resize(i.width,i.height),P()},setHoverPrice(g){u.set_hover_price(g),P()},clearHoverPrice(){u.clear_hover_price(),P()},hitZone(g,v){return u.hit_zone(g,v)},startDrawing(g,v){G?.setMode(g,v)},cancelDrawing(){G?.setMode(null)},onDrawingComplete(g){tt=g},onDrawingCancel(g){et=g},onDrawingSelected(g){lt=g},onMarkerSelected(g){mt=g},onDrawingDblClick(g){L=g},setReplayState(g,v,T){u.set_replay_state(g,v,T),P()},setReplayHovered(g){u.set_replay_hovered(g)},setReplayPreview(g){u.set_replay_preview(g),P()},setPrecision(g){u.set_price_precision(g),P()},setCandleInterval(g){u.set_candle_interval(g)},setTheme(g){let v=g==="light"?1:0;typeof u.set_theme=="function"?(u.set_theme(v),P()):console.warn("[ChartEngine] set_theme not available \u2014 reload page to load updated WASM")},getTheme(){return u.get_theme()===1?"light":"dark"},onTooltip(g){c=g},onVrvpHover(g){N=g},onLtHover(g){A=g},onPostRender(g){j=g},onLiqAnnotationPin(g){rt=g},pause(){h||(h=!0,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null))},resume(){h&&(h=!1,d&&(m=!0,I()))},get isPaused(){return h},destroy(){p=!0,d=!1,h=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null),ne();try{u.free()}catch{}},addIndicator(g){let v=D.add(g);return P(),v},removeIndicator(g){D.remove(g),P()},updateIndicatorParams(g,v){D.updateParams(g,v),P()},setIndicatorEnabled(g,v){D.setEnabled(g,v),P()},listIndicators(){return D.list()},invalidateCustomIndicators(){D.invalidateCompute(),P()},get license(){return{plan:t.plan,valid:t.valid,expired:!!t.expired,watermark:!!t.watermark,daysLeft:t.daysLeft}},setLicenseKey(g){t=pt(g),!t.valid&&!t.expired&&console.error(`[MRD Chart Engine] ${t.error}`);let v=t.expired?2:t.watermark?1:0,T=t.daysLeft||0,F=1297237059;return F=Math.imul(F,31)+v>>>0,F=Math.imul(F,31)+T>>>0,F=(F^F>>>16)>>>0,F=Math.imul(F,73244475)>>>0,F=(F^F>>>16)>>>0,u.set_license_state(v,T,F),P(),t.valid},..._e,...ue,...fe}}export{Ce as createChartBridge,bt as createCustomIndicatorManager,dt as dispatchCommands,Le as generateLicenseKey,Fe as prefetchWasm,Mt as setupEvents,pt as validateLicense};
1
+ var R={FILL_RECT:1,STROKE_RECT:2,LINE:3,DASHED_LINE:4,POLYLINE:5,TEXT:6,CIRCLE:7,TRIANGLE:8,SAVE:9,RESTORE:10,CLIP_RECT:11,ROTATED_TEXT:12,BUBBLE_3D:13,FILL_POLYGON:14,DASHED_POLYLINE:15,END_FRAME:255},ge=["left","center","right"],dt=new Map,Se=4096;function ve(t,s,a,o){return t<<24|s<<16|a<<8|o}function X(t,s,a,o){let c=ve(t,s,a,o),e=dt.get(c);return e||(e=`rgba(${t},${s},${a},${(o/255).toFixed(3)})`,dt.size>=Se&&dt.clear(),dt.set(c,e),e)}var zt=new TextDecoder;function ct(t,s,a,o){let c=s.buffer;if(a+o>c.byteLength)return;let e=new DataView(c,a,o),n=new Uint8Array(c,a,o),r=0,i="",u="",l=-1,m="";for(;r<o;){let f=n[r];if(r+=1,f===R.END_FRAME)break;switch(f){case R.FILL_RECT:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4,w!==i&&(t.fillStyle=w,i=w),t.fillRect(_,d,h,p);break}case R.STROKE_RECT:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let S=e.getFloat32(r,!0);r+=4,w!==u&&(t.strokeStyle=w,u=w),S!==l&&(t.lineWidth=S,l=S),t.strokeRect(_,d,h,p);break}case R.LINE:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let S=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==u&&(t.strokeStyle=w,u=w),S!==l&&(t.lineWidth=S,l=S),t.setLineDash([]),t.moveTo(_,d),t.lineTo(h,p),t.stroke();break}case R.DASHED_LINE:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let S=e.getFloat32(r,!0);r+=4;let M=e.getFloat32(r,!0);r+=4;let E=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==u&&(t.strokeStyle=w,u=w),S!==l&&(t.lineWidth=S,l=S),t.setLineDash([M,E]),t.moveTo(_,d),t.lineTo(h,p),t.stroke(),t.setLineDash([]);break}case R.POLYLINE:{let _=e.getUint16(r,!0);r+=2;let d=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let h=e.getFloat32(r,!0);if(r+=4,_>0){let p=new Float32Array(_*2);for(let w=0;w<_;w++)p[w*2]=e.getFloat32(r,!0),r+=4,p[w*2+1]=e.getFloat32(r,!0),r+=4;if(t.beginPath(),d!==u&&(t.strokeStyle=d,u=d),h!==l&&(t.lineWidth=h,l=h),t.setLineDash([]),t.lineJoin="round",t.lineCap="round",_<=3){t.moveTo(p[0],p[1]);for(let w=1;w<_;w++)t.lineTo(p[w*2],p[w*2+1])}else{t.moveTo(p[0],p[1]),t.lineTo((p[0]+p[2])*.5,(p[1]+p[3])*.5);for(let w=1;w<_-1;w++){let S=p[w*2],M=p[w*2+1],E=p[(w+1)*2],Y=p[(w+1)*2+1];t.quadraticCurveTo(S,M,(S+E)*.5,(M+Y)*.5)}t.lineTo(p[(_-1)*2],p[(_-1)*2+1])}t.stroke()}break}case R.TEXT:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=n[r];r+=1;let S=e.getUint16(r,!0);r+=2;let M=zt.decode(new Uint8Array(s.buffer,a+r,S));r+=S,h!==i&&(t.fillStyle=h,i=h);let E=`${p}px "IBM Plex Mono",monospace`;E!==m&&(t.font=E,m=E),t.textAlign=ge[w]||"left",t.textBaseline="middle",t.fillText(M,_,d);break}case R.CIRCLE:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let w=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let S=e.getFloat32(r,!0);r+=4,t.beginPath(),t.arc(_,d,h,0,Math.PI*2),p!==i&&(t.fillStyle=p,i=p),t.fill(),S>0&&(w!==u&&(t.strokeStyle=w,u=w),S!==l&&(t.lineWidth=S,l=S),t.stroke());break}case R.TRIANGLE:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let S=e.getFloat32(r,!0);r+=4;let M=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4,t.beginPath(),t.moveTo(_,d),t.lineTo(h,p),t.lineTo(w,S),t.closePath(),M!==i&&(t.fillStyle=M,i=M),t.fill();break}case R.SAVE:{t.save();break}case R.RESTORE:{t.restore(),i="",u="",l=-1,m="";break}case R.CLIP_RECT:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4,t.beginPath(),t.rect(_,d,h,p),t.clip();break}case R.ROTATED_TEXT:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let S=e.getUint16(r,!0);r+=2;let M=zt.decode(n.subarray(r,r+S));r+=S;let E=`${p}px sans-serif`;E!==m&&(t.font=E,m=E),h!==i&&(t.fillStyle=h,i=h),t.textAlign="center",t.textBaseline="middle",t.save(),t.translate(_,d),t.rotate(w),t.fillText(M,0,0),t.restore();break}case R.BUBBLE_3D:{let _=e.getFloat32(r,!0);r+=4;let d=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=n[r],w=n[r+1],S=n[r+2],M=n[r+3];r+=4;let E=n[r],Y=n[r+1],F=n[r+2],U=n[r+3];r+=4;let G=n[r],tt=n[r+1],et=n[r+2],ut=n[r+3];r+=4;let St=e.getFloat32(r,!0);r+=4;let P=h;if(P<10){let N=`rgba(${p},${w},${S},${(M/255).toFixed(3)})`;t.beginPath(),t.arc(_,d,P,0,Math.PI*2),t.fillStyle=N,t.fill(),i=""}else if(P<18){let N=_-P*.25,A=d-P*.25,q=t.createRadialGradient(N,A,P*.08,_,d,P);q.addColorStop(0,`rgba(${E},${Y},${F},${(U/255).toFixed(3)})`),q.addColorStop(1,`rgba(${p},${w},${S},${(M/255).toFixed(3)})`),t.beginPath(),t.arc(_,d,P,0,Math.PI*2),t.fillStyle=q,t.fill(),i=""}else{let N=_-P*.25,A=d-P*.25,q=t.createRadialGradient(_,d,P*.85,_,d,P*1.2);q.addColorStop(0,`rgba(${G},${tt},${et},${(ut/255*.5).toFixed(3)})`),q.addColorStop(1,`rgba(${G},${tt},${et},0)`),t.beginPath(),t.arc(_,d,P*1.2,0,Math.PI*2),t.fillStyle=q,t.fill();let j=t.createRadialGradient(N,A,P*.08,_,d,P);j.addColorStop(0,`rgba(${E},${Y},${F},${(U/255).toFixed(3)})`),j.addColorStop(1,`rgba(${p},${w},${S},${(M/255).toFixed(3)})`),t.beginPath(),t.arc(_,d,P,0,Math.PI*2),t.fillStyle=j,t.fill();let rt=P*.2,K=t.createRadialGradient(N,A,0,N,A,rt);K.addColorStop(0,"rgba(255,255,255,0.22)"),K.addColorStop(1,"rgba(255,255,255,0)"),t.beginPath(),t.arc(N,A,rt,0,Math.PI*2),t.fillStyle=K,t.fill(),i=""}break}case R.FILL_POLYGON:{let _=e.getUint16(r,!0);r+=2;let d=X(n[r],n[r+1],n[r+2],n[r+3]);if(r+=4,_>2){t.beginPath();let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4,t.moveTo(h,p);for(let w=1;w<_;w++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.closePath(),d!==i&&(t.fillStyle=d,i=d),t.fill()}else r+=_*8;break}case R.DASHED_POLYLINE:{let _=e.getUint16(r,!0);r+=2;let d=X(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);if(r+=4,_>1){t.beginPath(),d!==u&&(t.strokeStyle=d,u=d),h!==l&&(t.lineWidth=h,l=h),t.setLineDash([p,w]),t.lineJoin="round";let S=e.getFloat32(r,!0);r+=4;let M=e.getFloat32(r,!0);r+=4,t.moveTo(S,M);for(let E=1;E<_;E++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.stroke(),t.setLineDash([])}else r+=_*8;break}default:return}}}var O={trendline:{type:"2point",previewKind:0,addFn:"add_trendline"},arrow:{type:"2point",previewKind:4,addFn:"add_arrow"},measure:{type:"2point",previewKind:2,addFn:"add_price_range"},fib:{type:"2point",previewKind:3,addFn:"add_fib_retracement"},long:{type:"2point",previewKind:5,addFn:"add_long_position"},short:{type:"2point",previewKind:5,addFn:"add_short_position"},hline:{type:"1point_xp",previewKind:1,addFn:"add_horizontal_line"},vwap:{type:"1point_x",previewKind:6,addFn:"add_anchored_vwap"},pricelabel:{type:"1point_xy",previewKind:7,addFn:"add_price_label"},circle:{type:"2point",previewKind:8,addFn:"add_circle"},arrowup:{type:"1point_xy",previewKind:9,addFn:"add_arrow_marker_up"},arrowdown:{type:"1point_xy",previewKind:10,addFn:"add_arrow_marker_down"},textnote:{type:"1point_xy",previewKind:11,addFn:"add_text_note"},channel:{type:"3point",previewKind:0,addFn:"add_parallel_channel"},fibext:{type:"3point",previewKind:0,addFn:"add_fib_extension",previewFn:"fib_ext"},brush:{type:"freehand"},path:{type:"npoint"},elliott:{type:"elliott_manual"},elliottauto:{type:"1point_xy",previewKind:12,addFn:"add_elliott_impulse",previewFn:"elliott"}};function st(t){return O[t]?.type==="2point"}function at(t){return O[t]?.type==="3point"}function Q(t){let s=O[t]?.type;return s==="1point"||s==="1point_x"||s==="1point_xy"||s==="1point_xp"}function ht(t){return O[t]?.type==="freehand"}function B(t){return O[t]?.type==="npoint"}function V(t){return O[t]?.type==="elliott_manual"}var qt={r:.04,g:.49,b:1,lineWidth:2,dashed:!1,fontSize:12};function W(t,s,a,o,c,e){e=e||qt;let n=O[s];if(!n)return 0;let r=0;return n.type==="3point"?r=t[n.addFn](a.x1,a.y1,a.x2,a.y2,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):n.type==="2point"?r=t[n.addFn](a.x1,a.y1,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):n.type==="1point_x"?r=t[n.addFn](o,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):n.type==="1point_xp"?r=t[n.addFn](o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):n.type==="1point_xy"?r=t[n.addFn](o,c,e.r,e.g,e.b,e.fontSize||12,a.pane):r=t[n.addFn](c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane),r||0}function H(t,s,a,o,c,e,n){e=e||qt;let r=O[s];if(r){if(r.previewFn==="elliott"){t.set_elliott_preview(o,c,e.r,e.g,e.b,e.lineWidth,n);return}r.type==="3point"?a.step===1?t.set_drawing_preview(r.previewKind,a.x1,a.y1,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,n):a.step===2&&(r.previewFn==="fib_ext"?t.set_fib_ext_preview(a.x1,a.y1,a.x2,a.y2,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,n):t.set_channel_preview(a.x1,a.y1,a.x2,a.y2,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,n)):r.type==="2point"?t.set_drawing_preview(r.previewKind,a.x1,a.y1,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,n):r.type==="1point_x"?t.set_drawing_preview(r.previewKind,o,0,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n):r.type==="1point_xp"||r.type==="1point_xy"?t.set_drawing_preview(r.previewKind,o,c,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n):t.set_drawing_preview(r.previewKind,0,c,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n)}}function b(t,s,a,o){let c=t.screen_to_world_x(s),e;switch(o){case 1:e=t.screen_to_rsi_y(a);break;case 2:e=t.screen_to_oi_y(a);break;case 3:e=t.screen_to_fr_y(a);break;case 4:e=t.screen_to_cvd_y(a);break;default:e=t.screen_to_world_y(a);break}return{wx:c,wy:e}}function z(t){return t===4?1:t===6?2:t===8?3:t===10?4:0}function I(t){return t===0||t===4||t===6||t===8||t===10}function Kt(t,s,a,o){t.addEventListener("wheel",r=>{if(o.disposed)return;r.preventDefault(),o.cancelMomentum();let i=r.deltaY>0?1.1:.9,u=s.hit_zone(r.offsetX,r.offsetY);r.ctrlKey?s.zoom_y(r.offsetY,i):r.shiftKey||u===2?s.zoom_x(r.offsetX,i):u===3?s.zoom_y(r.offsetY,i):s.zoom(r.offsetX,r.offsetY,i),a.onDirty()},{passive:!1}),t.addEventListener("mousedown",r=>{if(o.disposed||r.button!==0)return;o.cancelMomentum(),e();let i=performance.now();if(i-o.lastClickTime<300){o.lastClickTime=i;return}o.lastClickTime=i;let u=o.drawingMode;if(u){let m=s.hit_zone(r.offsetX,r.offsetY);if(!I(m))return;let f=z(m),{wx:_,wy:d}=b(s,r.offsetX,r.offsetY,f),h=u.style,p=u.tool;if(V(p)){if(!u.pathStarted)u.pane=f,s.start_elliott_manual(h.r,h.g,h.b,h.lineWidth,f),s.add_elliott_manual_point(_,d),u.pathStarted=!0,u.step=1;else if(s.add_elliott_manual_point(_,d)){o.finishDrawing(),a.onDirty();return}}else if(B(p))u.pathStarted?s.add_path_point(_,d):(u.pane=f,s.start_path(h.r,h.g,h.b,h.lineWidth,h.dashed,f),s.add_path_point(_,d),u.pathStarted=!0,u.step=1);else if(ht(p))u.pane=f,s.start_brush(h.r,h.g,h.b,h.lineWidth,f),s.add_brush_point(_,d),o.isBrushing=!0;else if(at(p))if(u.step===0)u.x1=_,u.y1=d,u.pane=f,u.step=1;else if(u.step===1)u.x2=_,u.y2=d,u.step=2,s.clear_drawing_preview();else{let w=O[p];w&&w.previewFn==="fib_ext"?s.clear_fib_ext_preview():s.clear_channel_preview(),W(s,p,u,_,d,h),o.finishDrawing()}else if(st(p))u.step===0?(u.x1=_,u.y1=d,u.pane=f,u.step=1):(W(s,p,u,_,d,h),o.finishDrawing());else{u.pane=f;let w=W(s,p,u,_,d,h);o.finishDrawing(),p==="textnote"&&w>0&&(s.select_drawing(w),a.onDrawingSelected?.(w),a.onDrawingDblClick?.(w,r.offsetX,r.offsetY,r.clientX,r.clientY))}a.onDirty();return}let l=s.hit_zone(r.offsetX,r.offsetY);if(l===5){o.isResizingRsi=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_rsi_ratio(),t.style.cursor="ns-resize";return}if(l===7){o.isResizingOi=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_oi_ratio(),t.style.cursor="ns-resize";return}if(l===9){o.isResizingFr=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_fr_ratio(),t.style.cursor="ns-resize";return}if(l===11){o.isResizingCvd=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_cvd_ratio(),t.style.cursor="ns-resize";return}if(I(l)){let m=s.get_selected_drawing();if(m>0){let p=s.hit_test_drawing_anchor(r.offsetX,r.offsetY);if(p>=0){o.isDraggingAnchor=!0,o.dragAnchorIdx=p,o.dragAnchorPane=z(l),t.style.cursor="grabbing";return}if(s.hit_test_drawing(r.offsetX,r.offsetY)===m){o.isDraggingDrawing=!0,o.dragDrawingPane=z(l);let{wx:S,wy:M}=b(s,r.offsetX,r.offsetY,o.dragDrawingPane);o.dragDrawingLastWx=S,o.dragDrawingLastWy=M,t.style.cursor="move";return}}let f=s.hit_test_drawing(r.offsetX,r.offsetY);if(f>0){s.deselect_marker(),a.onMarkerSelected?.(0),s.select_drawing(f),a.onDrawingSelected?.(f),a.onDirty();return}let _=s.hit_test_marker(r.offsetX,r.offsetY);if(_>0){s.deselect_drawing(),a.onDrawingSelected?.(0),s.select_marker(_),a.onMarkerSelected?.(_),a.onDirty();return}let d=s.get_selected_drawing(),h=s.get_selected_marker();d>0&&(s.deselect_drawing(),a.onDrawingSelected?.(0),a.onDirty()),h>0&&(s.deselect_marker(),a.onMarkerSelected?.(0),a.onDirty())}I(l)&&(o.liqPinSx=r.offsetX,o.liqPinSy=r.offsetY,o.liqPinTimer&&clearTimeout(o.liqPinTimer),o.liqPinTimer=setTimeout(()=>{o.liqPinTimer=null,a.onLiqAnnotationPin?.(o.liqPinSx,o.liqPinSy)},700)),o.isDragging=!0,o.dragZone=l,o.lastX=r.offsetX,o.lastY=r.offsetY,l===2?t.style.cursor="ew-resize":l===3?t.style.cursor="ns-resize":t.style.cursor="grabbing"});let c=null;function e(){c&&(cancelAnimationFrame(c),c=null)}function n(r,i){let u=s.hover_hit_test(r,i),l=u[0],m=u[1],f=u[2],_=u[3],d=u[4],h=o.drawingMode;l===2?(t.style.cursor="ew-resize",s.hide_crosshair()):l===3?(t.style.cursor="ns-resize",s.hide_crosshair()):(s.set_crosshair(r,i),l===5||l===7||l===9||l===11?t.style.cursor="ns-resize":!h&&I(l)&&m>0&&f>=0?t.style.cursor="grab":!h&&I(l)&&m>0&&_===m?t.style.cursor="move":!h&&I(l)&&(_>0||d>0)?t.style.cursor="pointer":t.style.cursor="crosshair"),a.onDirty(),a.onCrosshairMove?.(r,i,l),a.onVrvpHover?.(r,i)}t.addEventListener("mousemove",r=>{if(o.disposed)return;if(o.liqPinTimer){let u=Math.abs(r.offsetX-o.liqPinSx),l=Math.abs(r.offsetY-o.liqPinSy);(u>6||l>6)&&(clearTimeout(o.liqPinTimer),o.liqPinTimer=null)}if(o.isResizingRsi){let l=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/l,_=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_rsi_ratio(_),a.onDirty();return}if(o.isResizingOi){let l=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/l,_=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_oi_ratio(_),a.onDirty();return}if(o.isResizingFr){let l=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/l,_=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_fr_ratio(_),a.onDirty();return}if(o.isResizingCvd){let l=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/l,_=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_cvd_ratio(_),a.onDirty();return}if(o.isDraggingAnchor){let{wx:u,wy:l}=b(s,r.offsetX,r.offsetY,o.dragAnchorPane);s.update_drawing_anchor(o.dragAnchorIdx,u,l),s.set_crosshair(r.offsetX,r.offsetY),a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,s.hit_zone(r.offsetX,r.offsetY));return}if(o.isDraggingDrawing){let{wx:u,wy:l}=b(s,r.offsetX,r.offsetY,o.dragDrawingPane),m=u-o.dragDrawingLastWx,f=l-o.dragDrawingLastWy;s.move_drawing(m,f),o.dragDrawingLastWx=u,o.dragDrawingLastWy=l,s.set_crosshair(r.offsetX,r.offsetY),a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,s.hit_zone(r.offsetX,r.offsetY));return}let i=o.drawingMode;if(o.isBrushing&&i){let u=i.pane||0,{wx:l,wy:m}=b(s,r.offsetX,r.offsetY,u);s.add_brush_point(l,m),s.set_crosshair(r.offsetX,r.offsetY),a.onDirty();return}if(i&&V(i.tool)&&i.pathStarted){let u=i.pane||0,{wx:l,wy:m}=b(s,r.offsetX,r.offsetY,u);s.set_elliott_manual_cursor(l,m),s.set_crosshair(r.offsetX,r.offsetY);let f=s.hit_zone(r.offsetX,r.offsetY);a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(i&&B(i.tool)&&i.pathStarted){let u=i.pane||0,{wx:l,wy:m}=b(s,r.offsetX,r.offsetY,u);s.set_path_cursor(l,m),s.set_crosshair(r.offsetX,r.offsetY);let f=s.hit_zone(r.offsetX,r.offsetY);a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(i&&i.step>0){let u=i.pane||0,{wx:l,wy:m}=b(s,r.offsetX,r.offsetY,u);H(s,i.tool,i,l,m,i.style,u),s.set_crosshair(r.offsetX,r.offsetY);let f=s.hit_zone(r.offsetX,r.offsetY);a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(i&&Q(i.tool)){let u=s.hit_zone(r.offsetX,r.offsetY),l=z(u),{wx:m,wy:f}=b(s,r.offsetX,r.offsetY,l);H(s,i.tool,i,m,f,i.style,l),s.set_crosshair(r.offsetX,r.offsetY),a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,u);return}if(o.isDragging){let u=r.offsetX-o.lastX,l=r.offsetY-o.lastY;o.lastX=r.offsetX,o.lastY=r.offsetY,o.dragZone===2?s.pan_x(u):o.dragZone===3?s.pan_y(l):s.pan(u,l),a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,o.dragZone),a.onVrvpHover?.(r.offsetX,r.offsetY);return}o._pendingHoverX=r.offsetX,o._pendingHoverY=r.offsetY,c||(c=requestAnimationFrame(()=>{c=null,o.disposed||n(o._pendingHoverX,o._pendingHoverY)}))}),t.addEventListener("mouseup",()=>{o.disposed||(o.liqPinTimer&&(clearTimeout(o.liqPinTimer),o.liqPinTimer=null),o.isBrushing&&(o.isBrushing=!1,s.finish_brush(),o.finishDrawing(),a.onDirty()),o.isDragging=!1,o.isResizingRsi=!1,o.isResizingOi=!1,o.isResizingFr=!1,o.isResizingCvd=!1,o.isDraggingAnchor=!1,o.isDraggingDrawing=!1,o.dragAnchorIdx=-1,t.style.cursor="crosshair")}),t.addEventListener("mouseleave",()=>{o.disposed||(e(),o.liqPinTimer&&(clearTimeout(o.liqPinTimer),o.liqPinTimer=null),o.isBrushing&&(o.isBrushing=!1,s.finish_brush(),o.finishDrawing()),o.isDragging=!1,o.isResizingRsi=!1,o.isResizingOi=!1,o.isResizingFr=!1,o.isResizingCvd=!1,o.isDraggingAnchor=!1,o.isDraggingDrawing=!1,o.dragAnchorIdx=-1,s.hide_crosshair(),t.style.cursor="crosshair",a.onDirty(),a.onCrosshairHide?.(),a.onVrvpHover?.(null,null))}),t.addEventListener("dblclick",r=>{if(o.disposed)return;r.preventDefault(),r.stopPropagation();let i=o.drawingMode;if(i&&V(i.tool)&&i.pathStarted){s.finish_elliott_manual(),o.finishDrawing(),a.onDirty();return}if(i&&B(i.tool)&&i.pathStarted){s.finish_path(),o.finishDrawing(),a.onDirty();return}if(i)return;let u=s.hit_test_drawing(r.offsetX,r.offsetY);u>0&&(s.select_drawing(u),a.onDirty(),a.onDrawingDblClick?.(u,r.offsetX,r.offsetY,r.clientX,r.clientY))}),t.addEventListener("contextmenu",r=>{if(o.disposed)return;let i=o.drawingMode;if(i&&V(i.tool)&&i.pathStarted){r.preventDefault(),r.stopPropagation(),s.finish_elliott_manual(),o.finishDrawing(),a.onDirty();return}if(i&&B(i.tool)&&i.pathStarted){r.preventDefault(),r.stopPropagation(),s.finish_path(),o.finishDrawing(),a.onDirty();return}})}function Dt(t,s,a,o){t.addEventListener("touchstart",c=>{if(!o.disposed){if(c.preventDefault(),o.cancelMomentum(),c.touches.length===2){clearTimeout(o.longPressTimer),o.isCrosshairMode=!1;let e=t.getBoundingClientRect(),n=c.touches[1].clientX-c.touches[0].clientX,r=c.touches[1].clientY-c.touches[0].clientY;o.lastTouchDist=Math.sqrt(n*n+r*r),o.lastX=(c.touches[0].clientX+c.touches[1].clientX)/2-e.left,o.lastY=(c.touches[0].clientY+c.touches[1].clientY)/2-e.top,o.dragZone=s.hit_zone(o.lastX,o.lastY)}else if(c.touches.length===1){let e=t.getBoundingClientRect(),n=c.touches[0].clientX-e.left,r=c.touches[0].clientY-e.top;o.touchStartX=n,o.touchStartY=r,o.touchMoved=!1;let i=o.drawingMode;if(i){let _=s.hit_zone(n,r);if(I(_)){let d=z(_),{wx:h,wy:p}=b(s,n,r,d),w=i.tool;if(V(w)){if(!i.pathStarted)i.pane=d,s.start_elliott_manual(i.style.r,i.style.g,i.style.b,i.style.lineWidth,d),s.add_elliott_manual_point(h,p),i.pathStarted=!0,i.step=1;else if(s.add_elliott_manual_point(h,p)){o.finishDrawing(),a.onDirty();return}}else B(w)?i.pathStarted?s.add_path_point(h,p):(i.pane=d,s.start_path(i.style.r,i.style.g,i.style.b,i.style.lineWidth,i.style.dashed,d),s.add_path_point(h,p),i.pathStarted=!0,i.step=1):ht(w)?(i.pane=d,s.start_brush(i.style.r,i.style.g,i.style.b,i.style.lineWidth,d),s.add_brush_point(h,p),o.isBrushing=!0):at(w)?i.step===0?(i.x1=h,i.y1=p,i.pane=d,i.step=1,i._stepAtTouchStart=0,H(s,w,i,h,p,i.style,d)):i.step===1?(i._stepAtTouchStart=1,H(s,w,i,h,p,i.style,i.pane)):(i._stepAtTouchStart=2,H(s,w,i,h,p,i.style,i.pane)):st(w)?i.step===0?(i.x1=h,i.y1=p,i.pane=d,i.step=1,i._stepAtTouchStart=0,H(s,w,i,h,p,i.style,d)):(i._stepAtTouchStart=1,H(s,w,i,h,p,i.style,i.pane)):Q(w)?(i.pane=d,H(s,w,i,h,p,i.style,d)):(i.pane=d,W(s,w,i,h,p,i.style),o.finishDrawing());s.set_crosshair(n,r),a.onDirty(),a.onCrosshairMove?.(n,r,_)}return}let u=s.hover_hit_test(n,r),l=u[0],m=u[1],f=u[2];if(I(l)&&!o.drawingMode&&m>0){if(f>=0){o.isDraggingAnchor=!0,o.dragAnchorIdx=f,o.dragAnchorPane=z(l);return}if(u[3]===m){o.isDraggingDrawing=!0,o.dragDrawingPane=z(l);let{wx:d,wy:h}=b(s,n,r,o.dragDrawingPane);o.dragDrawingLastWx=d,o.dragDrawingLastWy=h;return}}o.isDragging=!0,o.isCrosshairMode=!1,o.lastX=n,o.lastY=r,o.dragZone=l,clearTimeout(o.longPressTimer),o.longPressTimer=setTimeout(()=>{o.isDragging&&!o.touchMoved&&(o.isCrosshairMode=!0,s.set_crosshair(n,r),a.onDirty(),a.onCrosshairMove?.(n,r,o.dragZone),a.onVrvpHover?.(n,r))},300),I(o.dragZone)&&(o.liqPinSx=n,o.liqPinSy=r,o.liqPinTimer&&clearTimeout(o.liqPinTimer),o.liqPinTimer=setTimeout(()=>{o.liqPinTimer=null,o.touchMoved||a.onLiqAnnotationPin?.(o.liqPinSx,o.liqPinSy)},700))}}},{passive:!1}),t.addEventListener("touchmove",c=>{if(o.disposed)return;c.preventDefault();let e=t.getBoundingClientRect();if(o.isDraggingAnchor&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top,{wx:u,wy:l}=b(s,r,i,o.dragAnchorPane);s.update_drawing_anchor(o.dragAnchorIdx,u,l),s.set_crosshair(r,i),a.onDirty();return}if(o.isDraggingDrawing&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top;o.touchMoved=!0;let{wx:u,wy:l}=b(s,r,i,o.dragDrawingPane),m=u-o.dragDrawingLastWx,f=l-o.dragDrawingLastWy;s.move_drawing(m,f),o.dragDrawingLastWx=u,o.dragDrawingLastWy=l,s.set_crosshair(r,i),a.onDirty();return}let n=o.drawingMode;if(o.isBrushing&&n&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top,u=n.pane||0,{wx:l,wy:m}=b(s,r,i,u);s.add_brush_point(l,m),s.set_crosshair(r,i),a.onDirty(),o.touchMoved=!0;return}if(n&&V(n.tool)&&n.pathStarted&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top,u=n.pane||0,{wx:l,wy:m}=b(s,r,i,u);s.set_elliott_manual_cursor(l,m),s.set_crosshair(r,i),a.onDirty(),o.touchMoved=!0;return}if(n&&B(n.tool)&&n.pathStarted&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top,u=n.pane||0,{wx:l,wy:m}=b(s,r,i,u);s.set_path_cursor(l,m),s.set_crosshair(r,i),a.onDirty(),o.touchMoved=!0;return}if(n&&n.step>0&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top;!o.touchMoved&&(Math.abs(r-o.touchStartX)>10||Math.abs(i-o.touchStartY)>10)&&(o.touchMoved=!0);let u=n.pane||0,{wx:l,wy:m}=b(s,r,i,u);H(s,n.tool,n,l,m,n.style,u),s.set_crosshair(r,i);let f=s.hit_zone(r,i);a.onDirty(),a.onCrosshairMove?.(r,i,f);return}if(n&&Q(n.tool)&&c.touches.length===1){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top,u=s.hit_zone(r,i),l=z(u),{wx:m,wy:f}=b(s,r,i,l);H(s,n.tool,n,m,f,n.style,l),s.set_crosshair(r,i),a.onDirty(),a.onCrosshairMove?.(r,i,u);return}if(c.touches.length===2){o.velSamples=[];let r=c.touches[1].clientX-c.touches[0].clientX,i=c.touches[1].clientY-c.touches[0].clientY,u=Math.sqrt(r*r+i*i),l=o.lastTouchDist/u,m=(c.touches[0].clientX+c.touches[1].clientX)/2-e.left,f=(c.touches[0].clientY+c.touches[1].clientY)/2-e.top;o.dragZone===3?s.zoom_y(f,l):o.dragZone===2?s.zoom_x(m,l):(s.zoom(m,f,l),s.pan(m-o.lastX,f-o.lastY)),o.lastTouchDist=u,o.lastX=m,o.lastY=f,a.onDirty()}else if(c.touches.length===1&&o.isDragging){let r=c.touches[0].clientX-e.left,i=c.touches[0].clientY-e.top,u=r-o.lastX,l=i-o.lastY;!o.touchMoved&&(Math.abs(r-o.touchStartX)>10||Math.abs(i-o.touchStartY)>10)&&(o.touchMoved=!0,o.isCrosshairMode||clearTimeout(o.longPressTimer),o.liqPinTimer&&(clearTimeout(o.liqPinTimer),o.liqPinTimer=null)),o.isCrosshairMode?(s.set_crosshair(r,i),a.onDirty(),a.onCrosshairMove?.(r,i,o.dragZone),a.onVrvpHover?.(r,i)):(o.lastX=r,o.lastY=i,o.recordVelocity(u,l),o.dragZone===2?s.pan_x(u):o.dragZone===3?s.pan_y(l):s.pan(u,l),a.onDirty())}},{passive:!1}),t.addEventListener("touchend",c=>{if(o.disposed)return;if(clearTimeout(o.longPressTimer),o.liqPinTimer&&(clearTimeout(o.liqPinTimer),o.liqPinTimer=null),o.isDraggingAnchor){o.isDraggingAnchor=!1,o.dragAnchorIdx=-1,s.hide_crosshair(),a.onDirty(),a.onCrosshairHide?.();return}if(o.isDraggingDrawing){if(o.isDraggingDrawing=!1,s.hide_crosshair(),a.onDirty(),a.onCrosshairHide?.(),!o.touchMoved){let n=s.get_selected_drawing();if(n>0){let r=t.getBoundingClientRect();a.onDrawingDblClick?.(n,o.touchStartX,o.touchStartY,o.touchStartX+r.left,o.touchStartY+r.top)}}return}if(o.isBrushing){o.isBrushing=!1,s.finish_brush(),o.finishDrawing(),a.onDirty(),a.onCrosshairHide?.();return}let e=o.drawingMode;if(e&&V(e.tool)&&e.pathStarted){let n=Date.now(),r=o.touchStartX-(o._pathLastTapX||0),i=o.touchStartY-(o._pathLastTapY||0),u=Math.sqrt(r*r+i*i);n-(o._pathLastTapTime||0)<350&&u<30?(s.finish_elliott_manual(),o.finishDrawing(),o._pathLastTapTime=0):(o._pathLastTapTime=n,o._pathLastTapX=o.touchStartX,o._pathLastTapY=o.touchStartY),o.isDragging=!1,o.lastTouchDist=0,a.onDirty();return}if(e&&B(e.tool)&&e.pathStarted){let n=Date.now(),r=o.touchStartX-(o._pathLastTapX||0),i=o.touchStartY-(o._pathLastTapY||0),u=Math.sqrt(r*r+i*i);n-(o._pathLastTapTime||0)<350&&u<30?(s.finish_path(),o.finishDrawing(),o._pathLastTapTime=0):(o._pathLastTapTime=n,o._pathLastTapX=o.touchStartX,o._pathLastTapY=o.touchStartY),o.isDragging=!1,o.lastTouchDist=0,a.onDirty();return}if(e&&at(e.tool)){let n=e._stepAtTouchStart;if(e.step===1&&(n===1||o.touchMoved)){let r=t.getBoundingClientRect(),i=c.changedTouches?.[0];if(i){let u=i.clientX-r.left,l=i.clientY-r.top,m=e.pane||0,{wx:f,wy:_}=b(s,u,l,m);e.x2=f,e.y2=_,e.step=2,s.clear_drawing_preview()}}else if(e.step===2&&(n===2||o.touchMoved)){let r=t.getBoundingClientRect(),i=c.changedTouches?.[0];if(i){let u=i.clientX-r.left,l=i.clientY-r.top,m=e.pane||0,{wx:f,wy:_}=b(s,u,l,m),d=O[e.tool];d&&d.previewFn==="fib_ext"?s.clear_fib_ext_preview():s.clear_channel_preview(),W(s,e.tool,e,f,_,e.style),o.finishDrawing()}}o.isDragging=!1,o.lastTouchDist=0,o.drawingMode||(s.hide_crosshair(),a.onCrosshairHide?.()),a.onDirty();return}if(e&&e.step===1&&st(e.tool)){if(e._stepAtTouchStart===1||o.touchMoved){let r=t.getBoundingClientRect(),i=c.changedTouches?.[0];if(i){let u=i.clientX-r.left,l=i.clientY-r.top,m=e.pane||0,{wx:f,wy:_}=b(s,u,l,m);W(s,e.tool,e,f,_,e.style),o.finishDrawing()}}o.isDragging=!1,o.lastTouchDist=0,o.drawingMode||(s.hide_crosshair(),a.onCrosshairHide?.()),a.onDirty();return}if(e&&Q(e.tool)){let n=t.getBoundingClientRect(),r=c.changedTouches?.[0];if(r){let i=r.clientX-n.left,u=r.clientY-n.top,l=s.hit_zone(i,u),m=I(l)?z(l):e.pane||0,{wx:f,wy:_}=b(s,i,u,m),d=e.tool;s.clear_drawing_preview();let h=W(s,d,e,f,_,e.style);o.finishDrawing(),d==="textnote"&&h>0&&(s.select_drawing(h),a.onDrawingSelected?.(h),a.onDrawingDblClick?.(h,i,u,i+n.left,u+n.top))}o.isDragging=!1,o.lastTouchDist=0,s.hide_crosshair(),a.onCrosshairHide?.(),a.onDirty();return}if(!o.touchMoved&&!o.drawingMode&&o.isDragging){let n=Date.now(),r=o.touchStartX-o.lastTapX,i=o.touchStartY-o.lastTapY,u=Math.sqrt(r*r+i*i),l=n-o.lastTapTime<350&&u<30,m=s.hover_hit_test(o.touchStartX,o.touchStartY),f=m[0],_=m[1],d=m[3],h=m[4];if(I(f))if(d>0){s.deselect_marker(),a.onMarkerSelected?.(0),s.select_drawing(d);let p=t.getBoundingClientRect(),w=o.touchStartX+p.left,S=o.touchStartY+p.top;a.onDrawingSelected?.(d,w,S),(_<=0||_===d)&&a.onDrawingDblClick?.(d,o.touchStartX,o.touchStartY,w,S),a.onDirty()}else h>0?(s.deselect_drawing(),a.onDrawingSelected?.(0),s.select_marker(h),a.onMarkerSelected?.(h),a.onDirty()):(_>0&&(s.deselect_drawing(),a.onDrawingSelected?.(0),a.onDirty()),s.get_selected_marker()>0&&(s.deselect_marker(),a.onMarkerSelected?.(0),a.onDirty()));o.lastTapTime=n,o.lastTapX=o.touchStartX,o.lastTapY=o.touchStartY}o.touchMoved&&!o.isCrosshairMode&&!o.drawingMode&&o.startMomentum(o.dragZone),o.isDragging=!1,o.isCrosshairMode=!1,o.lastTouchDist=0,(!o.drawingMode||o.drawingMode.step===0)&&(s.hide_crosshair(),a.onCrosshairHide?.()),a.onDirty(),a.onVrvpHover?.(null,null)})}function Et(t,s,a){let o={disposed:!1,isDragging:!1,dragZone:0,lastX:0,lastY:0,lastTouchDist:0,isResizingRsi:!1,isResizingOi:!1,isResizingFr:!1,isResizingCvd:!1,resizeStartY:0,resizeStartRatio:0,lastClickTime:0,isDraggingAnchor:!1,dragAnchorIdx:-1,dragAnchorPane:0,isBrushing:!1,isDraggingDrawing:!1,dragDrawingPane:0,dragDrawingLastWx:0,dragDrawingLastWy:0,touchStartX:0,touchStartY:0,touchMoved:!1,longPressTimer:null,isCrosshairMode:!1,liqPinTimer:null,liqPinSx:0,liqPinSy:0,velSamples:[],momentumRaf:null,momentumVx:0,momentumVy:0,momentumZone:0,lastTapTime:0,lastTapX:0,lastTapY:0,drawingMode:null},c=.92,e=.5,n=80;o.recordVelocity=function(l,m){let f=performance.now();for(o.velSamples.push({dx:l,dy:m,t:f});o.velSamples.length>0&&f-o.velSamples[0].t>n;)o.velSamples.shift()};function r(){if(o.velSamples.length<2)return{vx:0,vy:0};let l=o.velSamples[0],f=o.velSamples[o.velSamples.length-1].t-l.t;if(f<5)return{vx:0,vy:0};let _=0,d=0;for(let p of o.velSamples)_+=p.dx,d+=p.dy;let h=16.67;return{vx:_/f*h,vy:d/f*h}}o.cancelMomentum=function(){o.momentumRaf&&(cancelAnimationFrame(o.momentumRaf),o.momentumRaf=null),o.velSamples=[]},o.startMomentum=function(l){let{vx:m,vy:f}=r();if(o.velSamples=[],Math.abs(m)<e&&Math.abs(f)<e)return;o.momentumVx=m,o.momentumVy=f,o.momentumZone=l;function _(){if(o.momentumVx*=c,o.momentumVy*=c,Math.abs(o.momentumVx)<e&&Math.abs(o.momentumVy)<e){o.momentumRaf=null;return}o.momentumZone===2?s.pan_x(o.momentumVx):o.momentumZone===3?s.pan_y(o.momentumVy):s.pan(o.momentumVx,o.momentumVy),a.onDirty(),o.momentumRaf=requestAnimationFrame(_)}o.momentumRaf=requestAnimationFrame(_)};let i={setMode(l,m){l?(o.drawingMode={tool:l,style:m,step:0,x1:0,y1:0},t.style.cursor="crosshair"):(o.drawingMode?.pathStarted&&s.finish_path(),o.drawingMode=null,s.clear_drawing_preview(),t.style.cursor="crosshair"),a.onDirty()},getMode(){return o.drawingMode}};a.drawingApi?.(i),o.finishDrawing=function(){s.clear_drawing_preview(),a.onDrawingComplete?.(),o.drawingMode=null,t.style.cursor="crosshair"},Kt(t,s,a,o),Dt(t,s,a,o);let u=l=>{let m=document.activeElement?.tagName,f=m==="INPUT"||m==="TEXTAREA"||document.activeElement?.isContentEditable;if((l.key==="Delete"||l.key==="Backspace")&&!o.drawingMode&&!f){let d=s.get_selected_drawing();if(d>0){s.remove_drawing(d),a.onDrawingSelected?.(0),a.onDirty();return}let h=s.get_selected_marker();if(h>0){s.remove_marker(h),a.onMarkerSelected?.(0),a.onDirty();return}}if(l.key==="Escape"&&!o.drawingMode){if(s.get_selected_drawing()>0){s.deselect_drawing(),a.onDrawingSelected?.(0),a.onDirty();return}if(s.get_selected_marker()>0){s.deselect_marker(),a.onMarkerSelected?.(0),a.onDirty();return}}if(l.key==="Escape"&&o.drawingMode){if(o.drawingMode.pathStarted){o.drawingMode.tool==="elliott"?s.finish_elliott_manual():s.finish_path(),o.finishDrawing(),a.onDirty();return}s.clear_drawing_preview(),o.drawingMode=null,t.style.cursor="crosshair",a.onDrawingCancel?.(),a.onDirty();return}let _=20;switch(l.key){case"+":case"=":s.zoom(t.width/2,t.height/2,.9);break;case"-":s.zoom(t.width/2,t.height/2,1.1);break;case"ArrowLeft":s.pan_x(_);break;case"ArrowRight":s.pan_x(-_);break;case"ArrowUp":s.pan_y(-_);break;case"ArrowDown":s.pan_y(_);break;case"r":case"R":s.auto_scale_y();break;default:return}a.onDirty()};return window.addEventListener("keydown",u),()=>{o.disposed=!0,o.cancelMomentum(),window.removeEventListener("keydown",u)}}function Gt(t,s,a,o){let c=e=>o()(e);return{enableRsi(){t.enable_rsi(),s()},disableRsi(){t.disable_rsi(),s()},setRsiPeriod(e){t.set_rsi_period(e),s()},isRsiEnabled(){return t.is_rsi_enabled()},setRsiShowEma(e){t.set_rsi_show_ema(e),s()},setRsiShowWma(e){t.set_rsi_show_wma(e),s()},setRsiShowSignals(e){t.set_rsi_show_signals(e),s()},setRsiShowDivergence(e){t.set_rsi_show_divergence(e),s()},setRsiShowTraps(e){t.set_rsi_show_traps(e),s()},setRsiSmoothing(e){t.set_rsi_smoothing(e),s()},setRsiRatio(e){t.set_rsi_ratio(e),s()},getRsiRatio(){return t.get_rsi_ratio()},enableForexSignals(){c("forexSignals")&&(t.enable_forex_signals(),s())},disableForexSignals(){t.disable_forex_signals(),s()},isForexSignalsEnabled(){return t.is_forex_signals_enabled()},setForexSignalsSetup(e){t.set_forex_signals_setup(e),s()},setForexSignalsMode(e){t.set_forex_signals_mode(e),s()},setForexSignalsShowStats(e){t.set_forex_signals_show_stats(e),s()},getForexSignalsCount(){return t.get_forex_signals_count()},enableOi(){a()||c("oi")&&(t.enable_oi(),s())},disableOi(){a()||(t.disable_oi(),s())},isOiEnabled(){if(a())return!1;try{return t.is_oi_enabled()}catch{return!1}},setOiData(e){a()||(t.set_oi_data(e),s())},setOiDataTs(e,n){a()||(t.set_oi_data_ts(e,n),s())},setOiShowOnChart(e){a()||(t.set_oi_show_on_chart(e),s())},setOiDisplayMode(e){a()||(t.set_oi_display_mode(e),s())},setOiRatio(e){a()||(t.set_oi_ratio(e),s())},getOiRatio(){if(a())return .2;try{return t.get_oi_ratio()}catch{return .2}},enableFundingRate(){a()||c("fundingRate")&&(t.enable_funding_rate(),s())},disableFundingRate(){a()||(t.disable_funding_rate(),s())},isFundingRateEnabled(){if(a())return!1;try{return t.is_funding_rate_enabled()}catch{return!1}},setFrBinanceData(e,n){a()||(t.set_fr_binance_data(e,n),s())},setFrAggData(e,n){a()||(t.set_fr_agg_data(e,n),s())},setFrShowAgg(e){a()||(t.set_fr_show_agg(e),s())},setFrShowSma(e){a()||(t.set_fr_show_sma(e),s())},enableCvd(){a()||c("cvd")&&(t.enable_cvd(),s())},disableCvd(){a()||(t.disable_cvd(),s())},isCvdEnabled(){if(a())return!1;try{return t.is_cvd_enabled()}catch{return!1}},setCvdData(e,n){a()||(t.set_cvd_data(e,n),s())},setCvdMode(e){a()||(t.set_cvd_mode(e),s())},getCvdMode(){if(a())return 0;try{return t.get_cvd_mode()}catch{return 0}},setCvdShowDelta(e){a()||(t.set_cvd_show_delta(e),s())},getCvdShowDelta(){if(a())return!0;try{return t.get_cvd_show_delta()}catch{return!0}},enableLargeTrades(){a()||c("largeTrades")&&(t.enable_large_trades(),s())},disableLargeTrades(){a()||(t.disable_large_trades(),s())},isLargeTradesEnabled(){if(a())return!1;try{return t.is_large_trades_enabled()}catch{return!1}},setLargeTradesData(e){a()||(t.set_large_trades_data(e),s())},pushLargeTrade(e,n,r,i){a()||(t.push_large_trade(e,n,r,i),s())},clearLargeTrades(){a()||(t.clear_large_trades(),s())},setLtVolumeFilter(e,n){a()||(t.set_lt_volume_filter(e,n),s())},setLtBubbleScale(e){a()||(t.set_lt_bubble_scale(e),s())},getLtDataMinVol(){return a()?0:t.get_lt_data_min_vol()},getLtDataMaxVol(){return a()?0:t.get_lt_data_max_vol()},ltHitTest(e,n){if(a())return"";try{return t.lt_hit_test(e,n)}catch{return""}},enableVrvp(){a()||c("vrvp")&&(t.enable_vrvp(),s())},disableVrvp(){a()||(t.disable_vrvp(),s())},isVrvpEnabled(){if(a())return!1;try{return t.is_vrvp_enabled()}catch{return!1}},setVrvpPocLine(e){a()||(t.set_vrvp_poc_line(e),s())},vrvpHitTest(e,n){if(a())return"";try{return t.vrvp_hit_test(e,n)}catch{return""}},enableTpo(){a()||c("tpo")&&(t.enable_tpo(),s())},disableTpo(){a()||(t.disable_tpo(),s())},isTpoEnabled(){if(a())return!1;try{return t.is_tpo_enabled()}catch{return!1}},setTpoPocLine(e){a()||(t.set_tpo_poc_line(e),s())},setTpoVaLines(e){a()||(t.set_tpo_va_lines(e),s())},setTpoIb(e){a()||(t.set_tpo_ib(e),s())},setTpoSinglePrints(e){a()||(t.set_tpo_single_prints(e),s())},setTpoPeriod(e){a()||(t.set_tpo_period(e),s())},getTpoPeriod(){if(a())return 1440;try{return t.get_tpo_period()}catch{return 1440}},setTpoNakedPoc(e){a()||(t.set_tpo_naked_poc(e),s())},setTpoProfileShape(e){a()||(t.set_tpo_profile_shape(e),s())},setTpoIbMinutes(e){a()||(t.set_tpo_ib_minutes(e),s())},setTpoLetterMinutes(e){a()||(t.set_tpo_letter_minutes(e),s())},setTpoSignals(e){a()||(t.set_tpo_signals(e),s())},isTpoSignals(){if(a())return!1;try{return t.is_tpo_signals()}catch{return!1}},enableLiqHeatmap(){a()||c("liqHeatmap")&&(t.enable_liq_heatmap(),s())},disableLiqHeatmap(){a()||(t.disable_liq_heatmap(),s())},isLiqHeatmapEnabled(){if(a())return!1;try{return t.is_liq_heatmap_enabled()}catch{return!1}},setLiqHeatmapRange(e,n){a()||(t.set_liq_heatmap_range(e,n),s())},getLiqHeatmapMin(){if(a())return 0;try{return t.get_liq_heatmap_min()}catch{return 0}},getLiqHeatmapMax(){if(a())return 1;try{return t.get_liq_heatmap_max()}catch{return 1}},getLiqHeatmapSegMax(){if(a())return 0;try{return t.get_liq_heatmap_seg_max()}catch{return 0}},setLiqHeatmapProfile(e){a()||(t.set_liq_heatmap_profile(e),s())},isLiqHeatmapProfile(){if(a())return!0;try{return t.is_liq_heatmap_profile()}catch{return!0}},setLiqHeatmapCellHeight(e){a()||(t.set_liq_heatmap_cell_height(e),s())},getLiqHeatmapCellHeight(){if(a())return 1;try{return t.get_liq_heatmap_cell_height()}catch{return 1}},setLiqHeatmapPredictions(e){a()||(t.set_liq_heatmap_predictions(e),s())},setLiqHeatmapFilledPct(e){a()||(t.set_liq_heatmap_filled_pct(e),s())},getLiqHeatmapFilledPct(){if(a())return .85;try{return t.get_liq_heatmap_filled_pct()}catch{return .85}},liqHeatmapHitTest(e,n){if(a())return"";try{return t.liq_heatmap_hit_test(e,n)}catch{return""}},liqZoneHitTest(e,n){if(a())return"";try{return t.liq_zone_hit_test(e,n)}catch{return""}},enableSmartRanges(){a()||c("smartRanges")&&(t.enable_smart_ranges(),s())},disableSmartRanges(){a()||(t.disable_smart_ranges(),s())},isSmartRangesEnabled(){if(a())return!1;try{return t.is_smart_ranges_enabled()}catch{return!1}},setSrTextSize(e){a()||(t.set_sr_text_size(e),s())},setSrShowOb(e){a()||(t.set_sr_show_ob(e),s())},setSrObLast(e){a()||(t.set_sr_ob_last(e),s())},setSrShowObActivity(e){a()||(t.set_sr_show_ob_activity(e),s())},setSrShowBreakers(e){a()||(t.set_sr_show_breakers(e),s())},setSrMitigation(e){a()||(t.set_sr_mitigation(e),s())},setSrShowMetrics(e){a()||(t.set_sr_show_metrics(e),s())},setSrShowHtfOb(e){a()||(t.set_sr_show_htf_ob(e),s())},setSrHtfMinutes(e){a()||(t.set_sr_htf_minutes(e),s())},setSrShowFvg(e){a()||(t.set_sr_show_fvg(e),s())},setSrFvgTheme(e){a()||(t.set_sr_fvg_theme(e),s())},setSrFvgMitigation(e){a()||(t.set_sr_fvg_mitigation(e),s())},setSrFvgHtf(e){a()||(t.set_sr_fvg_htf(e),s())},setSrFvgExtend(e){a()||(t.set_sr_fvg_extend(e),s())},setSrShowObSignals(e){a()||(t.set_sr_show_ob_signals(e),s())},setSrShowPredict(e){a()||(t.set_sr_show_predict(e),s())},setSrShowFvgSignals(e){a()||(t.set_sr_show_fvg_signals(e),s())},setSrShowSmartRev(e){a()||(t.set_sr_show_smart_rev(e),s())},setSrSmartRevHtf(e){a()||(t.set_sr_smart_rev_htf(e),s())},setSrStatsType(e){a()||(t.set_sr_stats_type(e),s())},setSrStatsPosition(e){a()||(t.set_sr_stats_position(e),s())},getSrSignalsCount(){if(a())return 0;try{return t.get_sr_signals_count()}catch{return 0}},enableEmaStructure(){a()||c("emaStructure")&&(t.enable_ema_structure(),s())},disableEmaStructure(){a()||(t.disable_ema_structure(),s())},isEmaStructureEnabled(){if(a())return!1;try{return t.is_ema_structure_enabled()}catch{return!1}},setEsEma1Len(e){a()||(t.set_es_ema1_len(e),s())},setEsEma2Len(e){a()||(t.set_es_ema2_len(e),s())},setEsWmaLen(e){a()||(t.set_es_wma_len(e),s())},setEsShowEma1(e){a()||(t.set_es_show_ema1(e),s())},setEsShowEma2(e){a()||(t.set_es_show_ema2(e),s())},setEsShowWma(e){a()||(t.set_es_show_wma(e),s())},setEsSwingLen(e){a()||(t.set_es_swing_len(e),s())},setEsShowBos(e){a()||(t.set_es_show_bos(e),s())},enableLiveSignals(){a()||(t.enable_live_signals(),s())},disableLiveSignals(){a()||(t.disable_live_signals(),s())},isLiveSignalsEnabled(){if(a())return!1;try{return t.is_live_signals_enabled()}catch{return!1}},setLiveSignalsData(e){a()||(t.set_live_signals_data(new Float64Array(e)),s())},clearLiveSignals(){a()||(t.clear_live_signals(),s())},setLiveSignalsLeverage(e){a()||(t.set_live_signals_leverage(e),s())},getLiveSignalsLeverage(){if(a())return 10;try{return t.get_live_signals_leverage()}catch{return 10}},setLiveSignalsTrial(e){a()||(t.set_live_signals_trial(e),s())},setLiveSignalsShowEntry(e){a()||(t.set_live_signals_show_entry(e),s())},setLiveSignalsShowTpSl(e){a()||(t.set_live_signals_show_tp_sl(e),s())},setLiveSignalsShowMaxProfit(e){a()||(t.set_live_signals_show_max_profit(e),s())},setLiveSignalsShowLabels(e){a()||(t.set_live_signals_show_labels(e),s())},setLiveSignalsShowZones(e){a()||(t.set_live_signals_show_zones(e),s())},setLiveSignalsTextSize(e){a()||(t.set_live_signals_text_size(e),s())},setLiveSignalsPipValue(e){a()||(t.set_live_signals_pip_value(e),s())},setLiveSignalsLoading(e){a()||(t.set_live_signals_loading(e),s())},getLiveSignalsCount(){if(a())return 0;try{return t.get_live_signals_count()}catch{return 0}},enableVolume(){t.enable_volume(),s()},disableVolume(){t.disable_volume(),s()},isVolumeEnabled(){return t.is_volume_enabled()},setVolumeMaPeriod(e){t.set_volume_ma_period(e),s()},setVolumeShowMa(e){t.set_volume_show_ma(e),s()},setVolumeShowSignals(e){t.set_volume_show_signals(e),s()},setVolumeColorMode(e){t.set_volume_color_mode(e),s()},getVolumeMaPeriod(){return t.get_volume_ma_period()},getVolumeShowMa(){return t.get_volume_show_ma()},getVolumeShowSignals(){return t.get_volume_show_signals()},getVolumeColorMode(){return t.get_volume_color_mode()}}}function jt(t,s,a,o){let c=e=>o()(e);return{addMarker(e,n,r){t.add_marker(e,n,r),s()},clearMarkers(){t.clear_markers(),s()},hitTestMarker(e,n){return t.hit_test_marker(e,n)},selectMarker(e){t.select_marker(e),s()},deselectMarker(){t.deselect_marker(),s()},getSelectedMarker(){return t.get_selected_marker()},removeMarker(e){t.remove_marker(e),s()},deleteSelectedMarker(){let e=t.get_selected_marker();return e>0&&(t.remove_marker(e),s()),e},addTrendline(e,n,r,i,u,l,m,f,_,d=0){let h=t.add_trendline(e,n,r,i,u,l,m,f,_,d);return s(),h},addHorizontalLine(e,n,r,i,u,l,m,f=0){let _=t.add_horizontal_line(e,n,r,i,u,l,m,f);return s(),_},addArrow(e,n,r,i,u,l,m,f,_,d=0){let h=t.add_arrow(e,n,r,i,u,l,m,f,_,d);return s(),h},addFibRetracement(e,n,r,i,u,l,m,f,_,d=0){if(!c("drawingFull"))return 0;let h=t.add_fib_retracement(e,n,r,i,u,l,m,f,_,d);return s(),h},addFibExtension(e,n,r,i,u,l,m,f,_,d,h,p=0){if(!c("drawingFull"))return 0;let w=t.add_fib_extension(e,n,r,i,u,l,m,f,_,d,h,p);return s(),w},addLongPosition(e,n,r,i,u,l,m,f,_,d=0){if(!c("drawingFull"))return 0;let h=t.add_long_position(e,n,r,i,u,l,m,f,_,d);return s(),h},addShortPosition(e,n,r,i,u,l,m,f,_,d=0){if(!c("drawingFull"))return 0;let h=t.add_short_position(e,n,r,i,u,l,m,f,_,d);return s(),h},addAnchoredVwap(e,n,r,i,u,l,m=0){if(!c("drawingFull"))return 0;let f=t.add_anchored_vwap(e,n,r,i,u,l,m);return s(),f},addPriceLabel(e,n,r,i,u,l,m=0){let f=t.add_price_label(e,n,r,i,u,l,m);return s(),f},addElliottImpulse(e,n,r,i,u,l,m=0){if(!c("drawingFull"))return 0;let f=t.add_elliott_impulse(e,n,r,i,u,l,m);return s(),f},setDrawingFontSize(e,n){t.set_drawing_font_size(e,n),s()},getDrawingFontSize(e){return t.get_drawing_font_size(e)},setDrawingText(e,n){t.set_drawing_text(e,n),s()},getDrawingText(e){return t.get_drawing_text(e)},setDrawingStyle(e,n,r,i,u){t.set_drawing_style(e,n,r,i,u),s()},getDrawingColor(e){let n=t.get_drawing_color(e);return n?{r:n>>>24&255,g:n>>>16&255,b:n>>>8&255,lineWidth:(n&255)/10}:null},getDrawingDashed(e){try{return t.get_drawing_dashed(e)}catch{return!1}},setDrawingDashed(e,n){t.set_drawing_dashed(e,n),s()},getDrawingHideLabel(e){try{return t.get_drawing_hide_label(e)}catch{return!1}},setDrawingHideLabel(e,n){t.set_drawing_hide_label(e,n),s()},getDrawingKindId(e){try{return t.get_drawing_kind_id(e)}catch{return 255}},removeDrawing(e){t.remove_drawing(e),s()},clearDrawings(){t.clear_drawings(),s()},drawingCount(){return t.drawing_count()},setDrawingPreview(e,n,r,i,u,l,m,f,_,d,h=0){t.set_drawing_preview(e,n,r,i,u,l,m,f,_,d,h),s()},clearDrawingPreview(){t.clear_drawing_preview(),s()},cancelBrush(){t.cancel_brush(),s()},selectDrawing(e){t.select_drawing(e),s()},deselectDrawing(){t.deselect_drawing(),s()},getSelectedDrawing(){return t.get_selected_drawing()},deleteSelectedDrawing(){let e=t.get_selected_drawing();return e>0&&(t.remove_drawing(e),s()),e},exportDrawingsJson(){try{return t.export_drawings_json()}catch{return"[]"}},importDrawingsJson(e){try{t.import_drawings_json(e),s()}catch(n){console.warn("[bridge] importDrawingsJson failed",n)}},screenToWorld(e,n){return{x:t.screen_to_world_x(e),y:t.screen_to_world_y(n)}},worldToScreen(e,n){try{return{x:t.world_to_screen_x(e),y:t.world_to_screen_y(n)}}catch{return null}}}}function Jt(t,s,a,o){let c=e=>o()(e);return{setKlines(e,n,r,i,u,l){t.set_klines(new Float64Array(e),new Float64Array(n),new Float64Array(r),new Float64Array(i),new Float64Array(u),new Float64Array(l)),s()},setRealTimestamps(e){t.set_real_timestamps(new Float64Array(e)),s()},appendRealTimestamp(e){t.append_real_timestamp(e)},prependKlines(e,n,r,i,u,l){t.prepend_klines(new Float64Array(e),new Float64Array(n),new Float64Array(r),new Float64Array(i),new Float64Array(u),new Float64Array(l)),s()},appendKline(e,n,r,i,u,l){t.append_kline(e,n,r,i,u,l),s()},updateLastKline(e,n,r,i,u,l){t.update_last_kline(e,n,r,i,u,l),s()},popLastKline(){let e=t.pop_last_kline();return e&&s(),e},getLastClose(){try{return t.get_last_close()}catch{return 0}},getKlineCount(){if(a())return 0;try{return t.kline_count()}catch{return 0}},getKlineTimestamps(){if(a())return null;try{return t.kline_timestamps()}catch{return null}},getKlineOpens(){if(a())return null;try{return t.kline_opens()}catch{return null}},getKlineHighs(){if(a())return null;try{return t.kline_highs()}catch{return null}},getKlineLows(){if(a())return null;try{return t.kline_lows()}catch{return null}},getKlineCloses(){if(a())return null;try{return t.kline_closes()}catch{return null}},getKlineVolumes(){if(a())return null;try{return t.kline_volumes()}catch{return null}},setHeatmap(e,n,r,i,u,l,m){c("heatmap")&&(t.set_heatmap(new Float64Array(e),n,r,i,u,l,m),s())},appendHeatmapColumn(e,n,r,i){c("heatmap")&&(t.append_heatmap_column(new Float64Array(e),n,r,i),s())},updateLastHeatmapColumn(e,n,r){t.update_last_heatmap_column(new Float64Array(e),n,r),s()},getHeatmapLastTimestamp(){try{return t.get_heatmap_last_timestamp()}catch{return 0}},getHeatmapXStep(){try{return t.get_heatmap_x_step()}catch{return 0}},updateHeatmapColumnAt(e,n,r,i){t.update_heatmap_column_at(new Float64Array(e),n,r,i),s()},setHeatmapRange(e,n){t.set_heatmap_range(e,n),s()},getHeatmapDataRange(){try{return{min:t.get_heatmap_data_min(),max:t.get_heatmap_data_max()}}catch{return{min:0,max:0}}},setHeatmapPrefetchRange(e){try{t.set_heatmap_prefetch_range(e)}catch{}},clearHeatmapPrefetchRange(){try{t.clear_heatmap_prefetch_range()}catch{}},getHeatmapPrefetchMax(){try{return t.get_heatmap_prefetch_max()}catch{return 0}},setChartType(e){a()||e===2&&!c("footprint")||(t.set_chart_type(e),s())},getChartType(){if(a())return 0;try{return t.get_chart_type()}catch{return 0}},setFootprintTickSize(e){a()||c("footprint")&&(t.set_footprint_tick_size(e),s())},footprintEnsureLen(e){a()||t.footprint_ensure_len(e)},footprintAddTrade(e,n,r,i){a()||t.footprint_add_trade(e,n,r,i)},footprintAddTradeBatch(e){a()||!e||e.length===0||t.footprint_add_trade_batch(e instanceof Float64Array?e:new Float64Array(e))},footprintSetBar(e,n,r,i,u){a()||(t.footprint_set_bar(e,n,r,i,u),s())},footprintClear(){a()||(t.footprint_clear(),s())},footprintClearBar(e){a()||t.footprint_clear_bar(e)},footprintPrependEmpty(e){a()||t.footprint_prepend_empty(e)},footprintSetShowSignals(e){a()||(t.footprint_set_show_signals(e),s())},footprintGetShowSignals(){if(a())return!0;try{return t.footprint_get_show_signals()}catch{return!0}},footprintSignalCount(){if(a())return 0;try{return t.footprint_signal_count()}catch{return 0}},footprintSetShowProfile(e){a()||(t.footprint_set_show_profile(e),s())},footprintGetShowProfile(){if(a())return!1;try{return t.footprint_get_show_profile()}catch{return!1}},footprintProfileHitTest(e,n){if(a())return"";try{return t.footprint_profile_hit_test(e,n)}catch{return""}}}}var Me=1;function y(t){if(typeof t!="string")return{r:255,g:255,b:255,a:153};if(t.startsWith("#")){let a=t.slice(1);if(a.length===8)return{r:parseInt(a.slice(0,2),16),g:parseInt(a.slice(2,4),16),b:parseInt(a.slice(4,6),16),a:parseInt(a.slice(6,8),16)};let o=parseInt(a.slice(0,2),16),c=parseInt(a.slice(2,4),16),e=parseInt(a.slice(4,6),16);return{r:o,g:c,b:e,a:255}}let s=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\)/);return s?{r:+s[1],g:+s[2],b:+s[3],a:s[4]!==void 0?Math.round(+s[4]*255):255}:{r:255,g:255,b:255,a:153}}function Ft(t,s,a){let o=new Map,c=null,e=0,n=NaN;function r(){let f;try{f=t.kline_count()}catch{return c}if(f===0)return null;let _=t.kline_closes(),d=_?.[f-1]??NaN;if(c&&!(f!==e||d!==n))return c;try{let p=t.kline_timestamps(),w=t.kline_opens(),S=t.kline_highs(),M=t.kline_lows(),E=t.kline_volumes();if(!p||!_)return c;c={timestamps:Array.from(p),open:Array.from(w),high:Array.from(S),low:Array.from(M),close:Array.from(_),volume:Array.from(E),length:f},e=f,n=d;for(let Y of o.values())Y._needsCompute=!0}catch{}return c}function i(){return{seriesLine(f,_="#ffffff99",d=1.5){let h=y(_);t.custom_series_line(new Float64Array(f),h.r,h.g,h.b,h.a,d)},seriesDashedLine(f,_="#ffffff66",d=1,h=4,p=4){let w=y(_);t.custom_series_dashed_line(new Float64Array(f),w.r,w.g,w.b,w.a,d,h,p)},band(f,_,d="rgba(100,149,237,0.08)"){let h=y(d);t.custom_band(new Float64Array(f),new Float64Array(_),h.r,h.g,h.b,h.a)},hline(f,_="#ffffff66",d=1){let h=y(_);t.custom_hline(f,h.r,h.g,h.b,h.a,d)},dashedHline(f,_="#ffffff66",d=1,h=6,p=4){let w=y(_);t.custom_dashed_hline(f,w.r,w.g,w.b,w.a,d,h,p)},marker(f,_,d="#e8a04a",h=3){let p=y(d);t.custom_marker(f,_,p.r,p.g,p.b,p.a,h)},markerUp(f,_,d="#26a69a",h=5){let p=y(d);t.custom_marker_up(f,_,p.r,p.g,p.b,p.a,h)},markerDown(f,_,d="#ef5350",h=5){let p=y(d);t.custom_marker_down(f,_,p.r,p.g,p.b,p.a,h)},text(f,_,d,h="#ffffffaa",p=10,w="center"){let S=y(h),M=w==="center"?1:w==="right"?2:0;t.custom_text(f,_,d,S.r,S.g,S.b,S.a,p,M)},priceLabel(f,_,d="#ffffffaa",h=10){let p=y(d);t.custom_price_label(f,_,p.r,p.g,p.b,p.a,h)},linePx(f,_,d,h,p,w=1){let S=y(p);t.custom_line_px(f,_,d,h,S.r,S.g,S.b,S.a,w)},fillRectPx(f,_,d,h,p){let w=y(p);t.custom_fill_rect_px(f,_,d,h,w.r,w.g,w.b,w.a)},strokeRectPx(f,_,d,h,p,w=1){let S=y(p);t.custom_stroke_rect_px(f,_,d,h,S.r,S.g,S.b,S.a,w)},textPx(f,_,d,h,p=10,w="left"){let S=y(h),M=w==="center"?1:w==="right"?2:0;t.custom_text_px(f,_,d,S.r,S.g,S.b,S.a,p,M)},worldToScreenX:f=>t.world_to_screen_x(f),worldToScreenY:f=>t.world_to_screen_y(f),screenToWorldX:f=>t.screen_to_world_x(f),screenToWorldY:f=>t.screen_to_world_y(f),chartArea:()=>({x:t.chart_area_x(),y:t.chart_area_y(),w:t.chart_area_w(),h:t.chart_area_h()})}}function u(f){if(!f.compute)return;let _=r();if(_)try{f._computed=f.compute(_,f.params)||{}}catch(d){console.warn(`[CustomIndicator "${f.name}"] compute error:`,d),f._computed={}}}function l(f){if(o.size===0)return;let _=r();if(!_)return;t.custom_begin();let d=i();for(let p of o.values())if(p.enabled){p._needsCompute&&(u(p),p._needsCompute=!1);try{p.render.call(p,d,p._computed||{},_)}catch(w){console.warn(`[CustomIndicator "${p.name}"] render error:`,w)}}if(t.custom_end(),t.custom_command_count()>0){let p=t.get_custom_buffer_ptr(),w=t.get_custom_buffer_len();a(f,s,p,w)}}function m(){c=null,e=0,n=NaN;for(let f of o.values())f._needsCompute=!0}return{add(f){let _=Me++,d={id:_,name:f.name||`Custom ${_}`,params:{...f.params},compute:f.compute||null,render:f.render,enabled:!0,_computed:{},_needsCompute:!0};return o.set(_,d),_},remove(f){o.delete(f)},updateParams(f,_){let d=o.get(f);d&&(Object.assign(d.params,_),d._needsCompute=!0)},setEnabled(f,_){let d=o.get(f);d&&(d.enabled=_)},list(){return[...o.values()].map(f=>({id:f.id,name:f.name,params:{...f.params},enabled:f.enabled}))},invalidateCompute:m,renderAll:l}}var Qt={trial:{candlestick:!0,volume:!0,rsi:!0,drawingBasic:!0,drawingFull:!1,heatmap:!1,footprint:!1,liqHeatmap:!1,oi:!1,fundingRate:!1,cvd:!1,largeTrades:!1,vrvp:!1,tpo:!1,smartRanges:!1,emaStructure:!1,customIndicators:!1,forexSignals:!1},standard:{candlestick:!0,volume:!0,rsi:!0,drawingBasic:!0,drawingFull:!1,heatmap:!1,footprint:!1,liqHeatmap:!1,oi:!1,fundingRate:!1,cvd:!1,largeTrades:!1,vrvp:!1,tpo:!1,smartRanges:!1,emaStructure:!1,customIndicators:!1,forexSignals:!1},professional:{candlestick:!0,volume:!0,rsi:!0,drawingBasic:!0,drawingFull:!0,heatmap:!0,footprint:!0,liqHeatmap:!0,oi:!0,fundingRate:!0,cvd:!0,largeTrades:!0,vrvp:!1,tpo:!1,smartRanges:!1,emaStructure:!1,customIndicators:!1,forexSignals:!1},enterprise:{candlestick:!0,volume:!0,rsi:!0,drawingBasic:!0,drawingFull:!0,heatmap:!0,footprint:!0,liqHeatmap:!0,oi:!0,fundingRate:!0,cvd:!0,largeTrades:!0,vrvp:!0,tpo:!0,smartRanges:!0,emaStructure:!0,customIndicators:!0,forexSignals:!0}},be={heatmap:"Orderbook Heatmap",footprint:"Footprint Chart",liqHeatmap:"Liquidation Heatmap",oi:"Open Interest",fundingRate:"Funding Rate",cvd:"CVD",largeTrades:"Large Trades",vrvp:"VRVP",tpo:"TPO / Market Profile",smartRanges:"Smart Ranges",emaStructure:"EMA Structure",drawingFull:"All Drawing Tools",customIndicators:"Custom Indicators",forexSignals:"Forex Signals"},Ee={heatmap:"Professional",footprint:"Professional",liqHeatmap:"Professional",oi:"Professional",fundingRate:"Professional",cvd:"Professional",largeTrades:"Professional",drawingFull:"Professional",vrvp:"Enterprise",tpo:"Enterprise",smartRanges:"Enterprise",emaStructure:"Enterprise",customIndicators:"Enterprise",forexSignals:"Enterprise"};function wt(t){return Qt[t]||Qt.trial}function Pt(t){let s=wt(t),a=new Set;return function(c){if(s[c])return!0;if(!a.has(c)){a.add(c);let e=be[c]||c,n=Ee[c]||"a higher";console.warn(`[MRD Chart Engine] "${e}" requires ${n} plan. Current plan: ${t}. Upgrade at https://mrd-chart.dev/pricing`)}return!1}}var xt=14,Lt="trial";var Rt=[95,95,109,114].map(t=>String.fromCharCode(t)).join(""),Fe=1297237059;function te(t){let s=`${t}:${Fe}:${(t^2043453)>>>0}`,a=2166136261;for(let o=0;o<s.length;o++)a^=s.charCodeAt(o),a=Math.imul(a,16777619);return(a>>>0).toString(36)}function nt(t){return`${t}.${te(t)}`}function it(t){if(!t||typeof t!="string")return null;let s=t.lastIndexOf(".");if(s<1)return null;let a=parseInt(t.slice(0,s),10);return!a||a<1e9||a>2e9||t.slice(s+1)!==te(a)?null:a}var ee=Rt+"e7x",re=Rt+"p3q",oe="mrd_engine_session_id",se="mrd_ce_db",x="meta",ae="trial_ts",ne=Rt+"ck";function Ct(){try{return it(localStorage.getItem(ee))}catch{return null}}function yt(t){try{localStorage.setItem(ee,nt(t))}catch{}}function At(){try{return it(localStorage.getItem(re))}catch{return null}}function It(t){try{localStorage.setItem(re,nt(t))}catch{}}function Yt(){try{return it(sessionStorage.getItem(oe))}catch{return null}}function Xt(t){try{sessionStorage.setItem(oe,nt(t))}catch{}}function Ot(){try{let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${ne}=([^;]+)`));return t?it(decodeURIComponent(t[1])):null}catch{return null}}function Ht(t){try{let s=encodeURIComponent(nt(t));document.cookie=`${ne}=${s};path=/;max-age=${86400*400};SameSite=Lax`}catch{}}var k=null,kt=!1;function Pe(){if(!(kt||typeof indexedDB>"u")){kt=!0;try{let t=indexedDB.open(se,1);t.onupgradeneeded=()=>{let s=t.result;s.objectStoreNames.contains(x)||s.createObjectStore(x)},t.onsuccess=()=>{let o=t.result.transaction(x,"readonly").objectStore(x).get(ae);o.onsuccess=()=>{let c=it(o.result);c&&(!k||c<k)&&(k=c,Le(c))}}}catch{}}}function ie(t){k=t;try{let s=indexedDB.open(se,1);s.onsuccess=()=>{s.result.transaction(x,"readwrite").objectStore(x).put(nt(t),ae)}}catch{}}function Le(t){let s=Math.floor(Date.now()/1e3),a=le([Ct(),At(),Yt(),Ot(),t],s);a&&a!==t||a&&(yt(a),It(a),Xt(a),Ht(a))}function le(t,s){let a=null;for(let o of t)o&&(o>s+60||o<17e8||(!a||o<a)&&(a=o));return a}function Re(){let t=Math.floor(Date.now()/1e3),s=[Ct(),At(),Yt(),Ot(),k];return le(s,t)}function Ce(t){yt(t),It(t),Xt(t),Ht(t),ie(t)}function ye(t){Ct()||yt(t),At()||It(t),Yt()||Xt(t),Ot()||Ht(t),k||ie(t)}Pe();function mt(t){if(!t||t==="trial")return Ae();try{let s=JSON.parse(atob(t)),{p:a,d:o,e:c,s:e}=s;if(!a||!e)return{valid:!1,error:"Invalid license key format"};let n={...s};if(delete n.s,e!==ue(n))return{valid:!1,error:"Invalid license key signature"};if(c>0&&Date.now()/1e3>c)return{valid:!1,expired:!0,plan:a,error:`License expired on ${new Date(c*1e3).toLocaleDateString()}`};let r=s.pl||"web";if((r==="web"||r==="any")&&o&&o!=="*"&&typeof window<"u"){let i=window.location.hostname;if(i&&i!=="localhost"&&i!=="127.0.0.1"&&i!=="0.0.0.0"&&i!==""&&!o.split(",").map(m=>m.trim()).some(m=>Ie(m,i)))return{valid:!1,error:`License not valid for domain: ${i}`}}if(r==="mobile"&&s.a&&typeof window<"u"){let i=window.__mrd_app_id;if(i&&i!==s.a)return{valid:!1,error:`License not valid for app: ${i}`}}return{valid:!0,plan:a,domain:o,platform:r,appId:s.a||null,expiry:c,watermark:!1,features:wt(a)}}catch{return{valid:!1,error:"Invalid license key"}}}function ue(t){let s="mrd-ce-hmac-2024-x9k2m",a=JSON.stringify(t),o=s+":"+a,c=2166136261,e=1818371886,n=3735928559;for(let r=0;r<o.length;r++){let i=o.charCodeAt(r);c=Math.imul(c^i,16777619)>>>0,e=Math.imul(e^i,1540483477)>>>0,n=Math.imul(n^i,461845907)>>>0}return(c.toString(36)+e.toString(36)+n.toString(36)).slice(0,24)}function Ae(){let t=Re();t?ye(t):(t=Math.floor(Date.now()/1e3),Ce(t));let s=t+xt*86400,a=Date.now()/1e3,o=Math.max(0,Math.ceil((s-a)/86400));return a>s?{valid:!1,expired:!0,plan:Lt,error:`${xt}-day trial has expired`,daysLeft:0}:{valid:!0,plan:Lt,watermark:!0,daysLeft:o,trialEnd:s,features:wt(Lt)}}function Ie(t,s){if(t==="*"||t===s)return!0;if(t.startsWith("*.")){let a=t.slice(1);return s.endsWith(a)||s===t.slice(2)}return!1}function Ye({plan:t,domain:s="*",expiryDays:a=365,name:o,email:c}){let e=a>0?Math.floor(Date.now()/1e3)+a*86400:0,n={p:t,d:s,e,...o?{n:o}:{},...c?{m:c}:{},i:Date.now()};return n.s=ue(n),btoa(JSON.stringify(n))}var gt=null,Nt=null,lt=null;async function fe(){return gt||lt||(lt=(async()=>{let t=await import("./chart_engine.js");return await t.default(),Nt=t.wasm_memory(),gt=t,t})(),lt)}function Xe(){!gt&&!lt&&fe().catch(()=>{})}async function Oe(t,s={}){s.appId&&typeof window<"u"&&(window.__mrd_app_id=s.appId);let a=s.licenseKey||s.key||null,o=mt(a);if(!o.valid)if(o.expired)console.warn(`[MRD Chart Engine] ${o.error}. Get a license at https://mrd-chart.dev/pricing`);else throw new Error(`[MRD Chart Engine] ${o.error}`);o.plan==="trial"&&console.info(`[MRD Chart Engine] Trial mode \u2014 ${o.daysLeft} days remaining. Purchase: https://mrd-chart.dev/pricing`);let c=await fe(),e=window.devicePixelRatio||1,n=t.getBoundingClientRect();(n.width<1||n.height<1)&&(await new Promise(g=>{let v=new ResizeObserver(T=>{for(let L of T)if(L.contentRect.width>0&&L.contentRect.height>0){v.disconnect(),g();return}});v.observe(t.parentElement||t),setTimeout(()=>{v.disconnect(),g()},2e3)}),n=t.getBoundingClientRect());let r=Math.max(n.width,100),i=Math.max(n.height,100);t.width=r*e,t.height=i*e;let u=t.getContext("2d");u.scale(e,e);let l=new c.ChartEngine(r,i);{let g=o.expired?2:o.watermark?1:0,v=o.daysLeft||0,T=1297237059;T=Math.imul(T,31)+g>>>0,T=Math.imul(T,31)+v>>>0,T=(T^T>>>16)>>>0,T=Math.imul(T,73244475)>>>0,T=(T^T>>>16)>>>0,l.set_license_state(g,v,T)}let m=!0,f=null,_=!1,d=!1,h=!1,p=null,w=null,S=0,E=("ontouchstart"in window||navigator.maxTouchPoints>0)&&window.innerWidth<=1399?33:0;function Y(){if(!(!_||d||f)){if(E>0){let g=performance.now()-S;if(g<E){w||(w=setTimeout(()=>{w=null,Y()},E-g));return}}f=requestAnimationFrame(ce)}}let F=()=>{m=!0,Y()},U=()=>h,G=null,tt=null,et=null,ut=null,St=null,P=null,N=null,A=null,q=0,j=null,rt=null,K=0,vt=0,J=-1,ft=!1,_t=!1,_e=Et(t,l,{onDirty:F,onCrosshairMove:(g,v,T)=>{K=g,vt=v,J=T,ft=!0,_t=!0},onCrosshairHide:()=>{_t&&(_t=!1,ft=!0,J=-1)},drawingApi:g=>{G=g},onDrawingComplete:()=>{tt?.()},onDrawingCancel:()=>{et?.()},onDrawingSelected:(g,v,T)=>{ut?.(g,v,T)},onMarkerSelected:g=>{St?.(g)},onDrawingDblClick:(g,v,T,L,me)=>{P?.(g,v,T,L,me)},onVrvpHover:(g,v)=>{N?.(g,v)},onLiqAnnotationPin:(g,v)=>{rt?.(g,v)}});function de(){if(ft){if(ft=!1,!_t){p&&p(null,0,0),A&&A("");return}if(p)if(J===0||J===1){let g=l.get_tooltip_data();p(g,K,vt)}else p(null,0,0);if(A){let g=performance.now();if(J===0||J===1){if(g-q>=80){q=g;try{A(l.lt_hit_test(K,vt))}catch{}}}else A("")}}}function ce(){if(f=null,!(!_||d)&&(m||l.is_dirty())){m=!1,S=performance.now();let g=!1;try{if(l.render()>0){let T=l.get_command_buffer_ptr(),L=l.get_command_buffer_len();u.save(),u.setTransform(1,0,0,1,0,0),u.clearRect(0,0,t.width,t.height),u.restore(),ct(u,Nt,T,L),g=!0}try{D.renderAll(u)}catch{}}catch{g||(m=!0)}de();try{j?.()}catch{}(m||l.is_dirty())&&Y()}}let ot=Pt(o.plan),he=Gt(l,F,U,()=>ot),pe=jt(l,F,U,()=>ot),we=Jt(l,F,U,()=>ot),D=Ft(l,Nt,ct);return{engine:l,start(){_=!0,d=!1,m=!0,Y()},stop(){_=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null)},resize(g){if(n=t.getBoundingClientRect(),n.width<1||n.height<1){(g||0)<8&&setTimeout(()=>this.resize((g||0)+1),250);return}e=window.devicePixelRatio||1;let v=n.width*e,T=n.height*e;t.width=v,t.height=T,u.setTransform(1,0,0,1,0,0),u.scale(e,e),l.resize(n.width,n.height),F()},setHoverPrice(g){l.set_hover_price(g),F()},clearHoverPrice(){l.clear_hover_price(),F()},hitZone(g,v){return l.hit_zone(g,v)},startDrawing(g,v){G?.setMode(g,v)},cancelDrawing(){G?.setMode(null)},onDrawingComplete(g){tt=g},onDrawingCancel(g){et=g},onDrawingSelected(g){ut=g},onMarkerSelected(g){St=g},onDrawingDblClick(g){P=g},setReplayState(g,v,T){l.set_replay_state(g,v,T),F()},setReplayHovered(g){l.set_replay_hovered(g)},setReplayPreview(g){l.set_replay_preview(g),F()},setPrecision(g){l.set_price_precision(g),F()},setCandleInterval(g){l.set_candle_interval(g)},setTheme(g){let v=g==="light"?1:0;typeof l.set_theme=="function"?(l.set_theme(v),F()):console.warn("[ChartEngine] set_theme not available \u2014 reload page to load updated WASM")},getTheme(){return l.get_theme()===1?"light":"dark"},onTooltip(g){p=g},onVrvpHover(g){N=g},onLtHover(g){A=g},onPostRender(g){j=g},onLiqAnnotationPin(g){rt=g},pause(){d||(d=!0,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null))},resume(){d&&(d=!1,_&&(m=!0,Y()))},get isPaused(){return d},destroy(){h=!0,_=!1,d=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null),_e();try{l.free()}catch{}},addIndicator(g){if(!ot("customIndicators"))return null;let v=D.add(g);return F(),v},removeIndicator(g){D.remove(g),F()},updateIndicatorParams(g,v){D.updateParams(g,v),F()},setIndicatorEnabled(g,v){D.setEnabled(g,v),F()},listIndicators(){return D.list()},invalidateCustomIndicators(){D.invalidateCompute(),F()},get license(){return{plan:o.plan,valid:o.valid,expired:!!o.expired,watermark:!!o.watermark,daysLeft:o.daysLeft,features:o.features||{}}},setLicenseKey(g){o=mt(g),!o.valid&&!o.expired&&console.error(`[MRD Chart Engine] ${o.error}`),ot=Pt(o.plan);let v=o.expired?2:o.watermark?1:0,T=o.daysLeft||0,L=1297237059;return L=Math.imul(L,31)+v>>>0,L=Math.imul(L,31)+T>>>0,L=(L^L>>>16)>>>0,L=Math.imul(L,73244475)>>>0,L=(L^L>>>16)>>>0,l.set_license_state(v,T,L),F(),o.valid},...we,...he,...pe}}export{Oe as createChartBridge,Ft as createCustomIndicatorManager,ct as dispatchCommands,Ye as generateLicenseKey,Xe as prefetchWasm,Et as setupEvents,mt as validateLicense};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kline-orderbook-chart",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Candlestick chart with built-in orderbook heatmap, footprint chart, and liquidation heatmap. Native high-performance engine. 60 fps, zero dependencies.",
5
5
  "type": "module",
6
6
  "main": "dist/mrd-chart-engine.mjs",