kline-orderbook-chart 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var L={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"],ct=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=ct.get(c);return e||(e=`rgba(${t},${s},${a},${(o/255).toFixed(3)})`,ct.size>=Se&&ct.clear(),ct.set(c,e),e)}var zt=new TextDecoder;function ht(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===L.END_FRAME)break;switch(f){case L.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 L.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 L.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 L.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 b=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,b]),t.moveTo(_,d),t.lineTo(h,p),t.stroke(),t.setLineDash([]);break}case L.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],b=p[(w+1)*2],Y=p[(w+1)*2+1];t.quadraticCurveTo(S,M,(S+b)*.5,(M+Y)*.5)}t.lineTo(p[(_-1)*2],p[(_-1)*2+1])}t.stroke()}break}case L.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 b=`${p}px "IBM Plex Mono",monospace`;b!==m&&(t.font=b,m=b),t.textAlign=ge[w]||"left",t.textBaseline="middle",t.fillText(M,_,d);break}case L.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 L.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 L.SAVE:{t.save();break}case L.RESTORE:{t.restore(),i="",u="",l=-1,m="";break}case L.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 L.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 b=`${p}px sans-serif`;b!==m&&(t.font=b,m=b),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 L.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 b=n[r],Y=n[r+1],F=n[r+2],U=n[r+3];r+=4;let G=n[r],et=n[r+1],rt=n[r+2],ft=n[r+3];r+=4;let vt=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(${b},${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},${et},${rt},${(ft/255*.5).toFixed(3)})`),q.addColorStop(1,`rgba(${G},${et},${rt},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(${b},${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 ot=P*.2,K=t.createRadialGradient(N,A,0,N,A,ot);K.addColorStop(0,"rgba(255,255,255,0.22)"),K.addColorStop(1,"rgba(255,255,255,0)"),t.beginPath(),t.arc(N,A,ot,0,Math.PI*2),t.fillStyle=K,t.fill(),i=""}break}case L.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 L.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 b=1;b<_;b++)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 at(t){return O[t]?.type==="2point"}function nt(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 pt(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 E(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}=E(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(pt(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(nt(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(at(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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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):pt(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):nt(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)):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._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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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}=E(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&&nt(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:_}=E(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:_}=E(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&&at(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:_}=E(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:_}=E(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 Ft(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 Pt(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(),b=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(b),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={free:{candlestick:!0,volume:!0,rsi:!1,drawingBasic:!1,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},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}},Ee={rsi:"RSI",drawingBasic:"Basic Drawing Tools",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"},be={rsi:"Standard",drawingBasic:"Standard",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 x(t){return Qt[t]||Qt.trial}function Rt(t){let s=x(t),a=new Set;return function(c){if(s[c])return!0;if(!a.has(c)){a.add(c);let e=Ee[c]||c,n=be[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 Fe=14,xt="trial",mt="free";var Lt=[95,95,109,114].map(t=>String.fromCharCode(t)).join(""),Pe=1297237059;function te(t){let s=`${t}:${Pe}:${(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 it(t){return`${t}.${te(t)}`}function lt(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=Lt+"e7x",re=Lt+"p3q",oe="mrd_engine_session_id",se="mrd_ce_db",k="meta",ae="trial_ts",ne=Lt+"ck";function Ct(){try{return lt(localStorage.getItem(ee))}catch{return null}}function yt(t){try{localStorage.setItem(ee,it(t))}catch{}}function At(){try{return lt(localStorage.getItem(re))}catch{return null}}function It(t){try{localStorage.setItem(re,it(t))}catch{}}function Yt(){try{return lt(sessionStorage.getItem(oe))}catch{return null}}function Xt(t){try{sessionStorage.setItem(oe,it(t))}catch{}}function Ot(){try{let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${ne}=([^;]+)`));return t?lt(decodeURIComponent(t[1])):null}catch{return null}}function Ht(t){try{let s=encodeURIComponent(it(t));document.cookie=`${ne}=${s};path=/;max-age=${86400*400};SameSite=Lax`}catch{}}var tt=null,kt=!1;function Re(){if(!(kt||typeof indexedDB>"u")){kt=!0;try{let t=indexedDB.open(se,1);t.onupgradeneeded=()=>{let s=t.result;s.objectStoreNames.contains(k)||s.createObjectStore(k)},t.onsuccess=()=>{let o=t.result.transaction(k,"readonly").objectStore(k).get(ae);o.onsuccess=()=>{let c=lt(o.result);c&&(!tt||c<tt)&&(tt=c,Le(c))}}}catch{}}}function ie(t){tt=t;try{let s=indexedDB.open(se,1);s.onsuccess=()=>{s.result.transaction(k,"readwrite").objectStore(k).put(it(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 Ce(){let t=Math.floor(Date.now()/1e3),s=[Ct(),At(),Yt(),Ot(),tt];return le(s,t)}function ye(t){yt(t),It(t),Xt(t),Ht(t),ie(t)}function Ae(t){Ct()||yt(t),At()||It(t),Yt()||Xt(t),Ot()||Ht(t),tt||ie(t)}Re();function gt(t){if(!t||t==="trial")return Ie();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:!0,plan:mt,watermark:!0,trialExpired:!0,originalPlan:a,error:`License expired on ${new Date(c*1e3).toLocaleDateString()}`,features:x(mt)};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=>Ye(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:x(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 Ie(){let t=Ce();t?Ae(t):(t=Math.floor(Date.now()/1e3),ye(t));let s=t+Fe*86400,a=Date.now()/1e3,o=Math.max(0,Math.ceil((s-a)/86400));return a>s?{valid:!0,plan:mt,watermark:!0,trialExpired:!0,daysLeft:0,features:x(mt)}:{valid:!0,plan:xt,watermark:!0,daysLeft:o,trialEnd:s,features:x(xt)}}function Ye(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 Xe({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 St=null,Nt=null,ut=null;async function fe(){return St||ut||(ut=(async()=>{let t=await import("./chart_engine.js");return await t.default(),Nt=t.wasm_memory(),St=t,t})(),ut)}function Oe(){!St&&!ut&&fe().catch(()=>{})}async function He(t,s={}){s.appId&&typeof window<"u"&&(window.__mrd_app_id=s.appId);let a=s.licenseKey||s.key||null,o=gt(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 R of T)if(R.contentRect.width>0&&R.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,b=("ontouchstart"in window||navigator.maxTouchPoints>0)&&window.innerWidth<=1399?33:0;function Y(){if(!(!_||d||f)){if(b>0){let g=performance.now()-S;if(g<b){w||(w=setTimeout(()=>{w=null,Y()},b-g));return}}f=requestAnimationFrame(ce)}}let F=()=>{m=!0,Y()},U=()=>h,G=null,et=null,rt=null,ft=null,vt=null,P=null,N=null,A=null,q=0,j=null,ot=null,K=0,Tt=0,J=-1,_t=!1,dt=!1,_e=Ft(t,l,{onDirty:F,onCrosshairMove:(g,v,T)=>{K=g,Tt=v,J=T,_t=!0,dt=!0},onCrosshairHide:()=>{dt&&(dt=!1,_t=!0,J=-1)},drawingApi:g=>{G=g},onDrawingComplete:()=>{et?.()},onDrawingCancel:()=>{rt?.()},onDrawingSelected:(g,v,T)=>{ft?.(g,v,T)},onMarkerSelected:g=>{vt?.(g)},onDrawingDblClick:(g,v,T,R,me)=>{P?.(g,v,T,R,me)},onVrvpHover:(g,v)=>{N?.(g,v)},onLiqAnnotationPin:(g,v)=>{ot?.(g,v)}});function de(){if(_t){if(_t=!1,!dt){p&&p(null,0,0),A&&A("");return}if(p)if(J===0||J===1){let g=l.get_tooltip_data();p(g,K,Tt)}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,Tt))}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(),R=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(),ht(u,Nt,T,R),g=!0}try{D.renderAll(u)}catch{}}catch{g||(m=!0)}de();try{j?.()}catch{}(m||l.is_dirty())&&Y()}}let st=Rt(o.plan),he=Gt(l,F,U,()=>st),pe=jt(l,F,U,()=>st),we=Jt(l,F,U,()=>st),D=Pt(l,Nt,ht);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){et=g},onDrawingCancel(g){rt=g},onDrawingSelected(g){ft=g},onMarkerSelected(g){vt=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){ot=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(!st("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=gt(g),!o.valid&&!o.expired&&console.error(`[MRD Chart Engine] ${o.error}`),st=Rt(o.plan);let v=o.expired?2:o.watermark?1:0,T=o.daysLeft||0,R=1297237059;return R=Math.imul(R,31)+v>>>0,R=Math.imul(R,31)+T>>>0,R=(R^R>>>16)>>>0,R=Math.imul(R,73244475)>>>0,R=(R^R>>>16)>>>0,l.set_license_state(v,T,R),F(),o.valid},...we,...he,...pe}}export{He as createChartBridge,Pt as createCustomIndicatorManager,ht as dispatchCommands,Xe as generateLicenseKey,Oe as prefetchWasm,Ft as setupEvents,gt as validateLicense};
1
+ var y={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},Ae=["left","center","right"],ht=new Map,ve=4096;function Te(t,s,a,o){return t<<24|s<<16|a<<8|o}function R(t,s,a,o){let c=Te(t,s,a,o),e=ht.get(c);return e||(e=`rgba(${t},${s},${a},${(o/255).toFixed(3)})`,ht.size>=ve&&ht.clear(),ht.set(c,e),e)}var Ht=new TextDecoder;function pt(t,s,a,o){let c=s.buffer;if(a+o>c.byteLength)return;let e=new DataView(c,a,o),i=new Uint8Array(c,a,o),r=0,n="",l="",u=-1,g="";for(;r<o;){let f=i[r];if(r+=1,f===y.END_FRAME)break;switch(f){case y.FILL_RECT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4,w!==n&&(t.fillStyle=w,n=w),t.fillRect(d,_,h,p);break}case y.STROKE_RECT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let M=e.getFloat32(r,!0);r+=4,w!==l&&(t.strokeStyle=w,l=w),M!==u&&(t.lineWidth=M,u=M),t.strokeRect(d,_,h,p);break}case y.LINE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let M=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==l&&(t.strokeStyle=w,l=w),M!==u&&(t.lineWidth=M,u=M),t.setLineDash([]),t.moveTo(d,_),t.lineTo(h,p),t.stroke();break}case y.DASHED_LINE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let M=e.getFloat32(r,!0);r+=4;let S=e.getFloat32(r,!0);r+=4;let I=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==l&&(t.strokeStyle=w,l=w),M!==u&&(t.lineWidth=M,u=M),t.setLineDash([S,I]),t.moveTo(d,_),t.lineTo(h,p),t.stroke(),t.setLineDash([]);break}case y.POLYLINE:{let d=e.getUint16(r,!0);r+=2;let _=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let h=e.getFloat32(r,!0);if(r+=4,d>0){let p=new Float32Array(d*2);for(let w=0;w<d;w++)p[w*2]=e.getFloat32(r,!0),r+=4,p[w*2+1]=e.getFloat32(r,!0),r+=4;if(t.beginPath(),_!==l&&(t.strokeStyle=_,l=_),h!==u&&(t.lineWidth=h,u=h),t.setLineDash([]),t.lineJoin="round",t.lineCap="round",d<=3){t.moveTo(p[0],p[1]);for(let w=1;w<d;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<d-1;w++){let M=p[w*2],S=p[w*2+1],I=p[(w+1)*2],j=p[(w+1)*2+1];t.quadraticCurveTo(M,S,(M+I)*.5,(S+j)*.5)}t.lineTo(p[(d-1)*2],p[(d-1)*2+1])}t.stroke()}break}case y.TEXT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=i[r];r+=1;let M=e.getUint16(r,!0);r+=2;let S=Ht.decode(new Uint8Array(s.buffer,a+r,M));r+=M,h!==n&&(t.fillStyle=h,n=h);let I=`${p}px "IBM Plex Mono",monospace`;I!==g&&(t.font=I,g=I),t.textAlign=Ae[w]||"left",t.textBaseline="middle",t.fillText(S,d,_);break}case y.CIRCLE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let w=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let M=e.getFloat32(r,!0);r+=4,t.beginPath(),t.arc(d,_,h,0,Math.PI*2),p!==n&&(t.fillStyle=p,n=p),t.fill(),M>0&&(w!==l&&(t.strokeStyle=w,l=w),M!==u&&(t.lineWidth=M,u=M),t.stroke());break}case y.TRIANGLE:{let d=e.getFloat32(r,!0);r+=4;let _=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 M=e.getFloat32(r,!0);r+=4;let S=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4,t.beginPath(),t.moveTo(d,_),t.lineTo(h,p),t.lineTo(w,M),t.closePath(),S!==n&&(t.fillStyle=S,n=S),t.fill();break}case y.SAVE:{t.save();break}case y.RESTORE:{t.restore(),n="",l="",u=-1,g="";break}case y.CLIP_RECT:{let d=e.getFloat32(r,!0);r+=4;let _=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 y.ROTATED_TEXT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=R(i[r],i[r+1],i[r+2],i[r+3]);r+=4;let p=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let M=e.getUint16(r,!0);r+=2;let S=Ht.decode(i.subarray(r,r+M));r+=M;let I=`${p}px sans-serif`;I!==g&&(t.font=I,g=I),h!==n&&(t.fillStyle=h,n=h),t.textAlign="center",t.textBaseline="middle",t.save(),t.translate(d,_),t.rotate(w),t.fillText(S,0,0),t.restore();break}case y.BUBBLE_3D:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let p=i[r],w=i[r+1],M=i[r+2],S=i[r+3];r+=4;let I=i[r],j=i[r+1],v=i[r+2],K=i[r+3];r+=4;let Q=i[r],et=i[r+1],rt=i[r+2],dt=i[r+3];r+=4;let It=e.getFloat32(r,!0);r+=4;let T=h;if(T<10){let z=`rgba(${p},${w},${M},${(S/255).toFixed(3)})`;t.beginPath(),t.arc(d,_,T,0,Math.PI*2),t.fillStyle=z,t.fill(),n=""}else if(T<18){let z=d-T*.25,P=_-T*.25,X=t.createRadialGradient(z,P,T*.08,d,_,T);X.addColorStop(0,`rgba(${I},${j},${v},${(K/255).toFixed(3)})`),X.addColorStop(1,`rgba(${p},${w},${M},${(S/255).toFixed(3)})`),t.beginPath(),t.arc(d,_,T,0,Math.PI*2),t.fillStyle=X,t.fill(),n=""}else{let z=d-T*.25,P=_-T*.25,X=t.createRadialGradient(d,_,T*.85,d,_,T*1.2);X.addColorStop(0,`rgba(${Q},${et},${rt},${(dt/255*.5).toFixed(3)})`),X.addColorStop(1,`rgba(${Q},${et},${rt},0)`),t.beginPath(),t.arc(d,_,T*1.2,0,Math.PI*2),t.fillStyle=X,t.fill();let U=t.createRadialGradient(z,P,T*.08,d,_,T);U.addColorStop(0,`rgba(${I},${j},${v},${(K/255).toFixed(3)})`),U.addColorStop(1,`rgba(${p},${w},${M},${(S/255).toFixed(3)})`),t.beginPath(),t.arc(d,_,T,0,Math.PI*2),t.fillStyle=U,t.fill();let ot=T*.2,G=t.createRadialGradient(z,P,0,z,P,ot);G.addColorStop(0,"rgba(255,255,255,0.22)"),G.addColorStop(1,"rgba(255,255,255,0)"),t.beginPath(),t.arc(z,P,ot,0,Math.PI*2),t.fillStyle=G,t.fill(),n=""}break}case y.FILL_POLYGON:{let d=e.getUint16(r,!0);r+=2;let _=R(i[r],i[r+1],i[r+2],i[r+3]);if(r+=4,d>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<d;w++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.closePath(),_!==n&&(t.fillStyle=_,n=_),t.fill()}else r+=d*8;break}case y.DASHED_POLYLINE:{let d=e.getUint16(r,!0);r+=2;let _=R(i[r],i[r+1],i[r+2],i[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,d>1){t.beginPath(),_!==l&&(t.strokeStyle=_,l=_),h!==u&&(t.lineWidth=h,u=h),t.setLineDash([p,w]),t.lineJoin="round";let M=e.getFloat32(r,!0);r+=4;let S=e.getFloat32(r,!0);r+=4,t.moveTo(M,S);for(let I=1;I<d;I++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.stroke(),t.setLineDash([])}else r+=d*8;break}default:return}}}var D={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 at(t){return D[t]?.type==="2point"}function it(t){return D[t]?.type==="3point"}function J(t){let s=D[t]?.type;return s==="1point"||s==="1point_x"||s==="1point_xy"||s==="1point_xp"}function wt(t){return D[t]?.type==="freehand"}function H(t){return D[t]?.type==="npoint"}function O(t){return D[t]?.type==="elliott_manual"}var Ot={r:.04,g:.49,b:1,lineWidth:2,dashed:!1,fontSize:12};function W(t,s,a,o,c,e){e=e||Ot;let i=D[s];if(!i)return 0;let r=0;return i.type==="3point"?r=t[i.addFn](a.x1,a.y1,a.x2,a.y2,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):i.type==="2point"?r=t[i.addFn](a.x1,a.y1,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):i.type==="1point_x"?r=t[i.addFn](o,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):i.type==="1point_xp"?r=t[i.addFn](o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane):i.type==="1point_xy"?r=t[i.addFn](o,c,e.r,e.g,e.b,e.fontSize||12,a.pane):r=t[i.addFn](c,e.r,e.g,e.b,e.lineWidth,e.dashed,a.pane),r||0}function Y(t,s,a,o,c,e,i){e=e||Ot;let r=D[s];if(r){if(r.previewFn==="elliott"){t.set_elliott_preview(o,c,e.r,e.g,e.b,e.lineWidth,i);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,i):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,i):t.set_channel_preview(a.x1,a.y1,a.x2,a.y2,o,c,e.r,e.g,e.b,e.lineWidth,e.dashed,i)):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,i):r.type==="1point_x"?t.set_drawing_preview(r.previewKind,o,0,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,i):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,i):t.set_drawing_preview(r.previewKind,0,c,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,i)}}function A(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 F(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 n=r.deltaY>0?1.1:.9,l=s.hit_zone(r.offsetX,r.offsetY);r.ctrlKey?s.zoom_y(r.offsetY,n):r.shiftKey||l===2?s.zoom_x(r.offsetX,n):l===3?s.zoom_y(r.offsetY,n):s.zoom(r.offsetX,r.offsetY,n),a.onDirty()},{passive:!1}),t.addEventListener("mousedown",r=>{if(o.disposed||r.button!==0)return;o.cancelMomentum(),e();let n=performance.now();if(n-o.lastClickTime<300){o.lastClickTime=n;return}o.lastClickTime=n;let l=o.drawingMode;if(l){let g=s.hit_zone(r.offsetX,r.offsetY);if(!F(g))return;let f=Z(g),{wx:d,wy:_}=A(s,r.offsetX,r.offsetY,f),h=l.style,p=l.tool;if(O(p)){if(!l.pathStarted)l.pane=f,s.start_elliott_manual(h.r,h.g,h.b,h.lineWidth,f),s.add_elliott_manual_point(d,_),l.pathStarted=!0,l.step=1;else if(s.add_elliott_manual_point(d,_)){o.finishDrawing(),a.onDirty();return}}else if(H(p))l.pathStarted?s.add_path_point(d,_):(l.pane=f,s.start_path(h.r,h.g,h.b,h.lineWidth,h.dashed,f),s.add_path_point(d,_),l.pathStarted=!0,l.step=1);else if(wt(p))l.pane=f,s.start_brush(h.r,h.g,h.b,h.lineWidth,f),s.add_brush_point(d,_),o.isBrushing=!0;else if(it(p))if(l.step===0)l.x1=d,l.y1=_,l.pane=f,l.step=1;else if(l.step===1)l.x2=d,l.y2=_,l.step=2,s.clear_drawing_preview();else{let w=D[p];w&&w.previewFn==="fib_ext"?s.clear_fib_ext_preview():s.clear_channel_preview(),W(s,p,l,d,_,h),o.finishDrawing()}else if(at(p))l.step===0?(l.x1=d,l.y1=_,l.pane=f,l.step=1):(W(s,p,l,d,_,h),o.finishDrawing());else{l.pane=f;let w=W(s,p,l,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 u=s.hit_zone(r.offsetX,r.offsetY);if(u===5){o.isResizingRsi=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_rsi_ratio(),t.style.cursor="ns-resize";return}if(u===7){o.isResizingOi=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_oi_ratio(),t.style.cursor="ns-resize";return}if(u===9){o.isResizingFr=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_fr_ratio(),t.style.cursor="ns-resize";return}if(u===11){o.isResizingCvd=!0,o.resizeStartY=r.offsetY,o.resizeStartRatio=s.get_cvd_ratio(),t.style.cursor="ns-resize";return}if(F(u)){let g=s.get_selected_drawing();if(g>0){let p=s.hit_test_drawing_anchor(r.offsetX,r.offsetY);if(p>=0){o.isDraggingAnchor=!0,o.dragAnchorIdx=p,o.dragAnchorPane=Z(u),t.style.cursor="grabbing";return}if(s.hit_test_drawing(r.offsetX,r.offsetY)===g){o.isDraggingDrawing=!0,o.dragDrawingPane=Z(u);let{wx:M,wy:S}=A(s,r.offsetX,r.offsetY,o.dragDrawingPane);o.dragDrawingLastWx=M,o.dragDrawingLastWy=S,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 d=s.hit_test_marker(r.offsetX,r.offsetY);if(d>0){s.deselect_drawing(),a.onDrawingSelected?.(0),s.select_marker(d),a.onMarkerSelected?.(d),a.onDirty();return}let _=s.get_selected_drawing(),h=s.get_selected_marker();_>0&&(s.deselect_drawing(),a.onDrawingSelected?.(0),a.onDirty()),h>0&&(s.deselect_marker(),a.onMarkerSelected?.(0),a.onDirty())}F(u)&&(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=u,o.lastX=r.offsetX,o.lastY=r.offsetY,u===2?t.style.cursor="ew-resize":u===3?t.style.cursor="ns-resize":t.style.cursor="grabbing"});let c=null;function e(){c&&(cancelAnimationFrame(c),c=null)}function i(r,n){let l=s.hover_hit_test(r,n),u=l[0],g=l[1],f=l[2],d=l[3],_=l[4],h=o.drawingMode;u===2?(t.style.cursor="ew-resize",s.hide_crosshair()):u===3?(t.style.cursor="ns-resize",s.hide_crosshair()):(s.set_crosshair(r,n),u===5||u===7||u===9||u===11?t.style.cursor="ns-resize":!h&&F(u)&&g>0&&f>=0?t.style.cursor="grab":!h&&F(u)&&g>0&&d===g?t.style.cursor="move":!h&&F(u)&&(d>0||_>0)?t.style.cursor="pointer":t.style.cursor="crosshair"),a.onDirty(),a.onCrosshairMove?.(r,n,u),a.onVrvpHover?.(r,n)}t.addEventListener("mousemove",r=>{if(o.disposed)return;if(o.liqPinTimer){let l=Math.abs(r.offsetX-o.liqPinSx),u=Math.abs(r.offsetY-o.liqPinSy);(l>6||u>6)&&(clearTimeout(o.liqPinTimer),o.liqPinTimer=null)}if(o.isResizingRsi){let u=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_rsi_ratio(d),a.onDirty();return}if(o.isResizingOi){let u=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_oi_ratio(d),a.onDirty();return}if(o.isResizingFr){let u=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_fr_ratio(d),a.onDirty();return}if(o.isResizingCvd){let u=t.getBoundingClientRect().height-28,f=(o.resizeStartY-r.offsetY)/u,d=Math.max(.05,Math.min(.5,o.resizeStartRatio+f));s.set_cvd_ratio(d),a.onDirty();return}if(o.isDraggingAnchor){let{wx:l,wy:u}=A(s,r.offsetX,r.offsetY,o.dragAnchorPane);s.update_drawing_anchor(o.dragAnchorIdx,l,u),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:l,wy:u}=A(s,r.offsetX,r.offsetY,o.dragDrawingPane),g=l-o.dragDrawingLastWx,f=u-o.dragDrawingLastWy;s.move_drawing(g,f),o.dragDrawingLastWx=l,o.dragDrawingLastWy=u,s.set_crosshair(r.offsetX,r.offsetY),a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,s.hit_zone(r.offsetX,r.offsetY));return}let n=o.drawingMode;if(o.isBrushing&&n){let l=n.pane||0,{wx:u,wy:g}=A(s,r.offsetX,r.offsetY,l);s.add_brush_point(u,g),s.set_crosshair(r.offsetX,r.offsetY),a.onDirty();return}if(n&&O(n.tool)&&n.pathStarted){let l=n.pane||0,{wx:u,wy:g}=A(s,r.offsetX,r.offsetY,l);s.set_elliott_manual_cursor(u,g),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(n&&H(n.tool)&&n.pathStarted){let l=n.pane||0,{wx:u,wy:g}=A(s,r.offsetX,r.offsetY,l);s.set_path_cursor(u,g),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(n&&n.step>0){let l=n.pane||0,{wx:u,wy:g}=A(s,r.offsetX,r.offsetY,l);Y(s,n.tool,n,u,g,n.style,l),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(n&&J(n.tool)){let l=s.hit_zone(r.offsetX,r.offsetY),u=Z(l),{wx:g,wy:f}=A(s,r.offsetX,r.offsetY,u);Y(s,n.tool,n,g,f,n.style,u),s.set_crosshair(r.offsetX,r.offsetY),a.onDirty(),a.onCrosshairMove?.(r.offsetX,r.offsetY,l);return}if(o.isDragging){let l=r.offsetX-o.lastX,u=r.offsetY-o.lastY;o.lastX=r.offsetX,o.lastY=r.offsetY,o.dragZone===2?s.pan_x(l):o.dragZone===3?s.pan_y(u):s.pan(l,u),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||i(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 n=o.drawingMode;if(n&&O(n.tool)&&n.pathStarted){s.finish_elliott_manual(),o.finishDrawing(),a.onDirty();return}if(n&&H(n.tool)&&n.pathStarted){s.finish_path(),o.finishDrawing(),a.onDirty();return}if(n)return;let l=s.hit_test_drawing(r.offsetX,r.offsetY);l>0&&(s.select_drawing(l),a.onDirty(),a.onDrawingDblClick?.(l,r.offsetX,r.offsetY,r.clientX,r.clientY))}),t.addEventListener("contextmenu",r=>{if(o.disposed)return;let n=o.drawingMode;if(n&&O(n.tool)&&n.pathStarted){r.preventDefault(),r.stopPropagation(),s.finish_elliott_manual(),o.finishDrawing(),a.onDirty();return}if(n&&H(n.tool)&&n.pathStarted){r.preventDefault(),r.stopPropagation(),s.finish_path(),o.finishDrawing(),a.onDirty();return}})}function Qt(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(),i=c.touches[1].clientX-c.touches[0].clientX,r=c.touches[1].clientY-c.touches[0].clientY;o.lastTouchDist=Math.sqrt(i*i+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(),i=c.touches[0].clientX-e.left,r=c.touches[0].clientY-e.top;o.touchStartX=i,o.touchStartY=r,o.touchMoved=!1;let n=o.drawingMode;if(n){let d=s.hit_zone(i,r);if(F(d)){let _=Z(d),{wx:h,wy:p}=A(s,i,r,_),w=n.tool;if(O(w)){if(!n.pathStarted)n.pane=_,s.start_elliott_manual(n.style.r,n.style.g,n.style.b,n.style.lineWidth,_),s.add_elliott_manual_point(h,p),n.pathStarted=!0,n.step=1;else if(s.add_elliott_manual_point(h,p)){o.finishDrawing(),a.onDirty();return}}else H(w)?n.pathStarted?s.add_path_point(h,p):(n.pane=_,s.start_path(n.style.r,n.style.g,n.style.b,n.style.lineWidth,n.style.dashed,_),s.add_path_point(h,p),n.pathStarted=!0,n.step=1):wt(w)?(n.pane=_,s.start_brush(n.style.r,n.style.g,n.style.b,n.style.lineWidth,_),s.add_brush_point(h,p),o.isBrushing=!0):it(w)?n.step===0?(n.x1=h,n.y1=p,n.pane=_,n.step=1,n._stepAtTouchStart=0,Y(s,w,n,h,p,n.style,_)):n.step===1?(n._stepAtTouchStart=1,Y(s,w,n,h,p,n.style,n.pane)):(n._stepAtTouchStart=2,Y(s,w,n,h,p,n.style,n.pane)):at(w)?n.step===0?(n.x1=h,n.y1=p,n.pane=_,n.step=1,n._stepAtTouchStart=0,Y(s,w,n,h,p,n.style,_)):(n._stepAtTouchStart=1,Y(s,w,n,h,p,n.style,n.pane)):J(w)?(n.pane=_,Y(s,w,n,h,p,n.style,_)):(n.pane=_,W(s,w,n,h,p,n.style),o.finishDrawing());s.set_crosshair(i,r),a.onDirty(),a.onCrosshairMove?.(i,r,d)}return}let l=s.hover_hit_test(i,r),u=l[0],g=l[1],f=l[2];if(F(u)&&!o.drawingMode&&g>0){if(f>=0){o.isDraggingAnchor=!0,o.dragAnchorIdx=f,o.dragAnchorPane=Z(u);return}if(l[3]===g){o.isDraggingDrawing=!0,o.dragDrawingPane=Z(u);let{wx:_,wy:h}=A(s,i,r,o.dragDrawingPane);o.dragDrawingLastWx=_,o.dragDrawingLastWy=h;return}}o.isDragging=!0,o.isCrosshairMode=!1,o.lastX=i,o.lastY=r,o.dragZone=u,clearTimeout(o.longPressTimer),o.longPressTimer=setTimeout(()=>{o.isDragging&&!o.touchMoved&&(o.isCrosshairMode=!0,s.set_crosshair(i,r),a.onDirty(),a.onCrosshairMove?.(i,r,o.dragZone),a.onVrvpHover?.(i,r))},300),F(o.dragZone)&&(o.liqPinSx=i,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,n=c.touches[0].clientY-e.top,{wx:l,wy:u}=A(s,r,n,o.dragAnchorPane);s.update_drawing_anchor(o.dragAnchorIdx,l,u),s.set_crosshair(r,n),a.onDirty();return}if(o.isDraggingDrawing&&c.touches.length===1){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top;o.touchMoved=!0;let{wx:l,wy:u}=A(s,r,n,o.dragDrawingPane),g=l-o.dragDrawingLastWx,f=u-o.dragDrawingLastWy;s.move_drawing(g,f),o.dragDrawingLastWx=l,o.dragDrawingLastWy=u,s.set_crosshair(r,n),a.onDirty();return}let i=o.drawingMode;if(o.isBrushing&&i&&c.touches.length===1){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top,l=i.pane||0,{wx:u,wy:g}=A(s,r,n,l);s.add_brush_point(u,g),s.set_crosshair(r,n),a.onDirty(),o.touchMoved=!0;return}if(i&&O(i.tool)&&i.pathStarted&&c.touches.length===1){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top,l=i.pane||0,{wx:u,wy:g}=A(s,r,n,l);s.set_elliott_manual_cursor(u,g),s.set_crosshair(r,n),a.onDirty(),o.touchMoved=!0;return}if(i&&H(i.tool)&&i.pathStarted&&c.touches.length===1){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top,l=i.pane||0,{wx:u,wy:g}=A(s,r,n,l);s.set_path_cursor(u,g),s.set_crosshair(r,n),a.onDirty(),o.touchMoved=!0;return}if(i&&i.step>0&&c.touches.length===1){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top;!o.touchMoved&&(Math.abs(r-o.touchStartX)>10||Math.abs(n-o.touchStartY)>10)&&(o.touchMoved=!0);let l=i.pane||0,{wx:u,wy:g}=A(s,r,n,l);Y(s,i.tool,i,u,g,i.style,l),s.set_crosshair(r,n);let f=s.hit_zone(r,n);a.onDirty(),a.onCrosshairMove?.(r,n,f);return}if(i&&J(i.tool)&&c.touches.length===1){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top,l=s.hit_zone(r,n),u=Z(l),{wx:g,wy:f}=A(s,r,n,u);Y(s,i.tool,i,g,f,i.style,u),s.set_crosshair(r,n),a.onDirty(),a.onCrosshairMove?.(r,n,l);return}if(c.touches.length===2){o.velSamples=[];let r=c.touches[1].clientX-c.touches[0].clientX,n=c.touches[1].clientY-c.touches[0].clientY,l=Math.sqrt(r*r+n*n),u=o.lastTouchDist/l,g=(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,u):o.dragZone===2?s.zoom_x(g,u):(s.zoom(g,f,u),s.pan(g-o.lastX,f-o.lastY)),o.lastTouchDist=l,o.lastX=g,o.lastY=f,a.onDirty()}else if(c.touches.length===1&&o.isDragging){let r=c.touches[0].clientX-e.left,n=c.touches[0].clientY-e.top,l=r-o.lastX,u=n-o.lastY;!o.touchMoved&&(Math.abs(r-o.touchStartX)>10||Math.abs(n-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,n),a.onDirty(),a.onCrosshairMove?.(r,n,o.dragZone),a.onVrvpHover?.(r,n)):(o.lastX=r,o.lastY=n,o.recordVelocity(l,u),o.dragZone===2?s.pan_x(l):o.dragZone===3?s.pan_y(u):s.pan(l,u),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 i=s.get_selected_drawing();if(i>0){let r=t.getBoundingClientRect();a.onDrawingDblClick?.(i,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&&O(e.tool)&&e.pathStarted){let i=Date.now(),r=o.touchStartX-(o._pathLastTapX||0),n=o.touchStartY-(o._pathLastTapY||0),l=Math.sqrt(r*r+n*n);i-(o._pathLastTapTime||0)<350&&l<30?(s.finish_elliott_manual(),o.finishDrawing(),o._pathLastTapTime=0):(o._pathLastTapTime=i,o._pathLastTapX=o.touchStartX,o._pathLastTapY=o.touchStartY),o.isDragging=!1,o.lastTouchDist=0,a.onDirty();return}if(e&&H(e.tool)&&e.pathStarted){let i=Date.now(),r=o.touchStartX-(o._pathLastTapX||0),n=o.touchStartY-(o._pathLastTapY||0),l=Math.sqrt(r*r+n*n);i-(o._pathLastTapTime||0)<350&&l<30?(s.finish_path(),o.finishDrawing(),o._pathLastTapTime=0):(o._pathLastTapTime=i,o._pathLastTapX=o.touchStartX,o._pathLastTapY=o.touchStartY),o.isDragging=!1,o.lastTouchDist=0,a.onDirty();return}if(e&&it(e.tool)){let i=e._stepAtTouchStart;if(e.step===1&&(i===1||o.touchMoved)){let r=t.getBoundingClientRect(),n=c.changedTouches?.[0];if(n){let l=n.clientX-r.left,u=n.clientY-r.top,g=e.pane||0,{wx:f,wy:d}=A(s,l,u,g);e.x2=f,e.y2=d,e.step=2,s.clear_drawing_preview()}}else if(e.step===2&&(i===2||o.touchMoved)){let r=t.getBoundingClientRect(),n=c.changedTouches?.[0];if(n){let l=n.clientX-r.left,u=n.clientY-r.top,g=e.pane||0,{wx:f,wy:d}=A(s,l,u,g),_=D[e.tool];_&&_.previewFn==="fib_ext"?s.clear_fib_ext_preview():s.clear_channel_preview(),W(s,e.tool,e,f,d,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&&at(e.tool)){if(e._stepAtTouchStart===1||o.touchMoved){let r=t.getBoundingClientRect(),n=c.changedTouches?.[0];if(n){let l=n.clientX-r.left,u=n.clientY-r.top,g=e.pane||0,{wx:f,wy:d}=A(s,l,u,g);W(s,e.tool,e,f,d,e.style),o.finishDrawing()}}o.isDragging=!1,o.lastTouchDist=0,o.drawingMode||(s.hide_crosshair(),a.onCrosshairHide?.()),a.onDirty();return}if(e&&J(e.tool)){let i=t.getBoundingClientRect(),r=c.changedTouches?.[0];if(r){let n=r.clientX-i.left,l=r.clientY-i.top,u=s.hit_zone(n,l),g=F(u)?Z(u):e.pane||0,{wx:f,wy:d}=A(s,n,l,g),_=e.tool;s.clear_drawing_preview();let h=W(s,_,e,f,d,e.style);o.finishDrawing(),_==="textnote"&&h>0&&(s.select_drawing(h),a.onDrawingSelected?.(h),a.onDrawingDblClick?.(h,n,l,n+i.left,l+i.top))}o.isDragging=!1,o.lastTouchDist=0,s.hide_crosshair(),a.onCrosshairHide?.(),a.onDirty();return}if(!o.touchMoved&&!o.drawingMode&&o.isDragging){let i=Date.now(),r=o.touchStartX-o.lastTapX,n=o.touchStartY-o.lastTapY,l=Math.sqrt(r*r+n*n),u=i-o.lastTapTime<350&&l<30,g=s.hover_hit_test(o.touchStartX,o.touchStartY),f=g[0],d=g[1],_=g[3],h=g[4];if(F(f))if(_>0){s.deselect_marker(),a.onMarkerSelected?.(0),s.select_drawing(_);let p=t.getBoundingClientRect(),w=o.touchStartX+p.left,M=o.touchStartY+p.top;a.onDrawingSelected?.(_,w,M),(d<=0||d===_)&&a.onDrawingDblClick?.(_,o.touchStartX,o.touchStartY,w,M),a.onDirty()}else h>0?(s.deselect_drawing(),a.onDrawingSelected?.(0),s.select_marker(h),a.onMarkerSelected?.(h),a.onDirty()):(d>0&&(s.deselect_drawing(),a.onDrawingSelected?.(0),a.onDirty()),s.get_selected_marker()>0&&(s.deselect_marker(),a.onMarkerSelected?.(0),a.onDirty()));o.lastTapTime=i,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 bt(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,i=80;o.recordVelocity=function(u,g){let f=performance.now();for(o.velSamples.push({dx:u,dy:g,t:f});o.velSamples.length>0&&f-o.velSamples[0].t>i;)o.velSamples.shift()};function r(){if(o.velSamples.length<2)return{vx:0,vy:0};let u=o.velSamples[0],f=o.velSamples[o.velSamples.length-1].t-u.t;if(f<5)return{vx:0,vy:0};let d=0,_=0;for(let p of o.velSamples)d+=p.dx,_+=p.dy;let h=16.67;return{vx:d/f*h,vy:_/f*h}}o.cancelMomentum=function(){o.momentumRaf&&(cancelAnimationFrame(o.momentumRaf),o.momentumRaf=null),o.velSamples=[]},o.startMomentum=function(u){let{vx:g,vy:f}=r();if(o.velSamples=[],Math.abs(g)<e&&Math.abs(f)<e)return;o.momentumVx=g,o.momentumVy=f,o.momentumZone=u;function d(){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(d)}o.momentumRaf=requestAnimationFrame(d)};let n={setMode(u,g){u?(o.drawingMode={tool:u,style:g,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?.(n),o.finishDrawing=function(){s.clear_drawing_preview(),a.onDrawingComplete?.(),o.drawingMode=null,t.style.cursor="crosshair"},Kt(t,s,a,o),Qt(t,s,a,o);let l=u=>{let g=document.activeElement?.tagName,f=g==="INPUT"||g==="TEXTAREA"||document.activeElement?.isContentEditable;if((u.key==="Delete"||u.key==="Backspace")&&!o.drawingMode&&!f){let _=s.get_selected_drawing();if(_>0){s.remove_drawing(_),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(u.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(u.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 d=20;switch(u.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(d);break;case"ArrowRight":s.pan_x(-d);break;case"ArrowUp":s.pan_y(-d);break;case"ArrowDown":s.pan_y(d);break;case"r":case"R":s.auto_scale_y();break;default:return}a.onDirty()};return window.addEventListener("keydown",l),()=>{o.disposed=!0,o.cancelMomentum(),window.removeEventListener("keydown",l)}}function $t(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,i){a()||(t.set_oi_data_ts(e,i),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,i){a()||(t.set_fr_binance_data(e,i),s())},setFrAggData(e,i){a()||(t.set_fr_agg_data(e,i),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,i){a()||(t.set_cvd_data(e,i),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,i,r,n){a()||(t.push_large_trade(e,i,r,n),s())},clearLargeTrades(){a()||(t.clear_large_trades(),s())},setLtVolumeFilter(e,i){a()||(t.set_lt_volume_filter(e,i),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,i){if(a())return"";try{return t.lt_hit_test(e,i)}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,i){if(a())return"";try{return t.vrvp_hit_test(e,i)}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,i){a()||(t.set_liq_heatmap_range(e,i),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,i){if(a())return"";try{return t.liq_heatmap_hit_test(e,i)}catch{return""}},liqZoneHitTest(e,i){if(a())return"";try{return t.liq_zone_hit_test(e,i)}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,i,r){t.add_marker(e,i,r),s()},clearMarkers(){t.clear_markers(),s()},hitTestMarker(e,i){return t.hit_test_marker(e,i)},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,i,r,n,l,u,g,f,d,_=0){let h=t.add_trendline(e,i,r,n,l,u,g,f,d,_);return s(),h},addHorizontalLine(e,i,r,n,l,u,g,f=0){let d=t.add_horizontal_line(e,i,r,n,l,u,g,f);return s(),d},addArrow(e,i,r,n,l,u,g,f,d,_=0){let h=t.add_arrow(e,i,r,n,l,u,g,f,d,_);return s(),h},addFibRetracement(e,i,r,n,l,u,g,f,d,_=0){if(!c("drawingFull"))return 0;let h=t.add_fib_retracement(e,i,r,n,l,u,g,f,d,_);return s(),h},addFibExtension(e,i,r,n,l,u,g,f,d,_,h,p=0){if(!c("drawingFull"))return 0;let w=t.add_fib_extension(e,i,r,n,l,u,g,f,d,_,h,p);return s(),w},addLongPosition(e,i,r,n,l,u,g,f,d,_=0){if(!c("drawingFull"))return 0;let h=t.add_long_position(e,i,r,n,l,u,g,f,d,_);return s(),h},addShortPosition(e,i,r,n,l,u,g,f,d,_=0){if(!c("drawingFull"))return 0;let h=t.add_short_position(e,i,r,n,l,u,g,f,d,_);return s(),h},addAnchoredVwap(e,i,r,n,l,u,g=0){if(!c("drawingFull"))return 0;let f=t.add_anchored_vwap(e,i,r,n,l,u,g);return s(),f},addPriceLabel(e,i,r,n,l,u,g=0){let f=t.add_price_label(e,i,r,n,l,u,g);return s(),f},addElliottImpulse(e,i,r,n,l,u,g=0){if(!c("drawingFull"))return 0;let f=t.add_elliott_impulse(e,i,r,n,l,u,g);return s(),f},setDrawingFontSize(e,i){t.set_drawing_font_size(e,i),s()},getDrawingFontSize(e){return t.get_drawing_font_size(e)},setDrawingText(e,i){t.set_drawing_text(e,i),s()},getDrawingText(e){return t.get_drawing_text(e)},setDrawingStyle(e,i,r,n,l){t.set_drawing_style(e,i,r,n,l),s()},getDrawingColor(e){let i=t.get_drawing_color(e);return i?{r:i>>>24&255,g:i>>>16&255,b:i>>>8&255,lineWidth:(i&255)/10}:null},getDrawingDashed(e){try{return t.get_drawing_dashed(e)}catch{return!1}},setDrawingDashed(e,i){t.set_drawing_dashed(e,i),s()},getDrawingHideLabel(e){try{return t.get_drawing_hide_label(e)}catch{return!1}},setDrawingHideLabel(e,i){t.set_drawing_hide_label(e,i),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,i,r,n,l,u,g,f,d,_,h=0){t.set_drawing_preview(e,i,r,n,l,u,g,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(i){console.warn("[bridge] importDrawingsJson failed",i)}},screenToWorld(e,i){return{x:t.screen_to_world_x(e),y:t.screen_to_world_y(i)}},worldToScreen(e,i){try{return{x:t.world_to_screen_x(e),y:t.world_to_screen_y(i)}}catch{return null}}}}function xt(t,s,a,o){let c=e=>o()(e);return{setKlines(e,i,r,n,l,u){t.set_klines(new Float64Array(e),new Float64Array(i),new Float64Array(r),new Float64Array(n),new Float64Array(l),new Float64Array(u)),s()},setRealTimestamps(e){t.set_real_timestamps(new Float64Array(e)),s()},appendRealTimestamp(e){t.append_real_timestamp(e)},prependKlines(e,i,r,n,l,u){t.prepend_klines(new Float64Array(e),new Float64Array(i),new Float64Array(r),new Float64Array(n),new Float64Array(l),new Float64Array(u)),s()},appendKline(e,i,r,n,l,u){t.append_kline(e,i,r,n,l,u),s()},updateLastKline(e,i,r,n,l,u){t.update_last_kline(e,i,r,n,l,u),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,i,r,n,l,u,g){c("heatmap")&&(t.set_heatmap(new Float64Array(e),i,r,n,l,u,g),s())},appendHeatmapColumn(e,i,r,n){c("heatmap")&&(t.append_heatmap_column(new Float64Array(e),i,r,n),s())},updateLastHeatmapColumn(e,i,r){t.update_last_heatmap_column(new Float64Array(e),i,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,i,r,n){t.update_heatmap_column_at(new Float64Array(e),i,r,n),s()},setHeatmapRange(e,i){t.set_heatmap_range(e,i),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,i,r,n){a()||t.footprint_add_trade(e,i,r,n)},footprintAddTradeBatch(e){a()||!e||e.length===0||t.footprint_add_trade_batch(e instanceof Float64Array?e:new Float64Array(e))},footprintSetBar(e,i,r,n,l){a()||(t.footprint_set_bar(e,i,r,n,l),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,i){if(a())return"";try{return t.footprint_profile_hit_test(e,i)}catch{return""}}}}var ye=1;function N(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 yt(t,s,a){let o=new Map,c=null,e=0,i=NaN;function r(){let f;try{f=t.kline_count()}catch{return c}if(f===0)return null;let d=t.kline_closes(),_=d?.[f-1]??NaN;if(c&&!(f!==e||_!==i))return c;try{let p=t.kline_timestamps(),w=t.kline_opens(),M=t.kline_highs(),S=t.kline_lows(),I=t.kline_volumes();if(!p||!d)return c;c={timestamps:Array.from(p),open:Array.from(w),high:Array.from(M),low:Array.from(S),close:Array.from(d),volume:Array.from(I),length:f},e=f,i=_;for(let j of o.values())j._needsCompute=!0}catch{}return c}function n(){return{seriesLine(f,d="#ffffff99",_=1.5){let h=N(d);t.custom_series_line(new Float64Array(f),h.r,h.g,h.b,h.a,_)},seriesDashedLine(f,d="#ffffff66",_=1,h=4,p=4){let w=N(d);t.custom_series_dashed_line(new Float64Array(f),w.r,w.g,w.b,w.a,_,h,p)},band(f,d,_="rgba(100,149,237,0.08)"){let h=N(_);t.custom_band(new Float64Array(f),new Float64Array(d),h.r,h.g,h.b,h.a)},hline(f,d="#ffffff66",_=1){let h=N(d);t.custom_hline(f,h.r,h.g,h.b,h.a,_)},dashedHline(f,d="#ffffff66",_=1,h=6,p=4){let w=N(d);t.custom_dashed_hline(f,w.r,w.g,w.b,w.a,_,h,p)},marker(f,d,_="#e8a04a",h=3){let p=N(_);t.custom_marker(f,d,p.r,p.g,p.b,p.a,h)},markerUp(f,d,_="#26a69a",h=5){let p=N(_);t.custom_marker_up(f,d,p.r,p.g,p.b,p.a,h)},markerDown(f,d,_="#ef5350",h=5){let p=N(_);t.custom_marker_down(f,d,p.r,p.g,p.b,p.a,h)},text(f,d,_,h="#ffffffaa",p=10,w="center"){let M=N(h),S=w==="center"?1:w==="right"?2:0;t.custom_text(f,d,_,M.r,M.g,M.b,M.a,p,S)},priceLabel(f,d,_="#ffffffaa",h=10){let p=N(_);t.custom_price_label(f,d,p.r,p.g,p.b,p.a,h)},linePx(f,d,_,h,p,w=1){let M=N(p);t.custom_line_px(f,d,_,h,M.r,M.g,M.b,M.a,w)},fillRectPx(f,d,_,h,p){let w=N(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 M=N(p);t.custom_stroke_rect_px(f,d,_,h,M.r,M.g,M.b,M.a,w)},textPx(f,d,_,h,p=10,w="left"){let M=N(h),S=w==="center"?1:w==="right"?2:0;t.custom_text_px(f,d,_,M.r,M.g,M.b,M.a,p,S)},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 l(f){if(!f.compute)return;let d=r();if(d)try{f._computed=f.compute(d,f.params)||{}}catch(_){console.warn(`[CustomIndicator "${f.name}"] compute error:`,_),f._computed={}}}function u(f){if(o.size===0)return;let d=r();if(!d)return;t.custom_begin();let _=n();for(let p of o.values())if(p.enabled){p._needsCompute&&(l(p),p._needsCompute=!1);try{p.render.call(p,_,p._computed||{},d)}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 g(){c=null,e=0,i=NaN;for(let f of o.values())f._needsCompute=!0}return{add(f){let d=ye++,_={id:d,name:f.name||`Custom ${d}`,params:{...f.params},compute:f.compute||null,render:f.render,enabled:!0,_computed:{},_needsCompute:!0};return o.set(d,_),d},remove(f){o.delete(f)},updateParams(f,d){let _=o.get(f);_&&(Object.assign(_.params,d),_._needsCompute=!0)},setEnabled(f,d){let _=o.get(f);_&&(_.enabled=d)},list(){return[...o.values()].map(f=>({id:f.id,name:f.name,params:{...f.params},enabled:f.enabled}))},invalidateCompute:g,renderAll:u}}var kt={free:{candlestick:!0,volume:!0,rsi:!1,drawingBasic:!1,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},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}},Ee={rsi:"RSI",drawingBasic:"Basic Drawing Tools",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"},Ne={rsi:"Standard",drawingBasic:"Standard",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 x(t){return kt[t]||kt.trial}function Et(t){let s=x(t),a=new Set;return function(c){if(s[c])return!0;if(!a.has(c)){a.add(c);let e=Ee[c]||c,i=Ne[c]||"a higher";console.warn(`[MRD Chart Engine] "${e}" requires ${i} plan. Current plan: ${t}. Upgrade at https://mrd-chart.dev/pricing`)}return!1}}var Pe=14,te="trial",nt="free";var Nt=[95,95,109,114].map(t=>String.fromCharCode(t)).join(""),Fe=1297237059;function se(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 lt(t){return`${t}.${se(t)}`}function ut(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)!==se(a)?null:a}var ae=Nt+"e7x",ie=Nt+"p3q",ne="mrd_engine_session_id",le="mrd_ce_db",k="meta",ue="trial_ts",fe=Nt+"ck";function Pt(){try{return ut(localStorage.getItem(ae))}catch{return null}}function Ft(t){try{localStorage.setItem(ae,lt(t))}catch{}}function jt(){try{return ut(localStorage.getItem(ie))}catch{return null}}function Rt(t){try{localStorage.setItem(ie,lt(t))}catch{}}function Dt(){try{return ut(sessionStorage.getItem(ne))}catch{return null}}function Yt(t){try{sessionStorage.setItem(ne,lt(t))}catch{}}function zt(){try{let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${fe}=([^;]+)`));return t?ut(decodeURIComponent(t[1])):null}catch{return null}}function Zt(t){try{let s=encodeURIComponent(lt(t));document.cookie=`${fe}=${s};path=/;max-age=${86400*400};SameSite=Lax`}catch{}}var tt=null,ee=!1;function je(){if(!(ee||typeof indexedDB>"u")){ee=!0;try{let t=indexedDB.open(le,1);t.onupgradeneeded=()=>{let s=t.result;s.objectStoreNames.contains(k)||s.createObjectStore(k)},t.onsuccess=()=>{let o=t.result.transaction(k,"readonly").objectStore(k).get(ue);o.onsuccess=()=>{let c=ut(o.result);c&&(!tt||c<tt)&&(tt=c,Re(c))}}}catch{}}}function de(t){tt=t;try{let s=indexedDB.open(le,1);s.onsuccess=()=>{s.result.transaction(k,"readwrite").objectStore(k).put(lt(t),ue)}}catch{}}function Re(t){let s=Math.floor(Date.now()/1e3),a=_e([Pt(),jt(),Dt(),zt(),t],s);a&&a!==t||a&&(Ft(a),Rt(a),Yt(a),Zt(a))}function _e(t,s){let a=null;for(let o of t)o&&(o>s+60||o<17e8||(!a||o<a)&&(a=o));return a}function De(){let t=Math.floor(Date.now()/1e3),s=[Pt(),jt(),Dt(),zt(),tt];return _e(s,t)}function Ye(t){Ft(t),Rt(t),Yt(t),Zt(t),de(t)}function ze(t){Pt()||Ft(t),jt()||Rt(t),Dt()||Yt(t),zt()||Zt(t),tt||de(t)}je();function Lt(t){if(!t||t==="trial")return Ze();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 i={...s};if(delete i.s,e!==ce(i))return{valid:!1,error:"Invalid license key signature"};if(c>0&&Date.now()/1e3>c)return{valid:!0,plan:nt,watermark:!0,trialExpired:!0,originalPlan:a,error:`License expired on ${new Date(c*1e3).toLocaleDateString()}`,features:x(nt)};let r=s.pl||"web";if((r==="web"||r==="any")&&o&&o!=="*"&&typeof window<"u"){let n=window.location.hostname;if(n&&n!=="localhost"&&n!=="127.0.0.1"&&n!=="0.0.0.0"&&n!==""&&!o.split(",").map(g=>g.trim()).some(g=>Xe(g,n)))return{valid:!1,error:`License not valid for domain: ${n}`}}if(r==="mobile"&&s.a&&typeof window<"u"){let n=window.__mrd_app_id;if(n&&n!==s.a)return{valid:!1,error:`License not valid for app: ${n}`}}return{valid:!0,plan:a,domain:o,platform:r,appId:s.a||null,expiry:c,watermark:!1,features:x(a)}}catch{return{valid:!1,error:"Invalid license key"}}}function ce(t){let s="mrd-ce-hmac-2024-x9k2m",a=JSON.stringify(t),o=s+":"+a,c=2166136261,e=1818371886,i=3735928559;for(let r=0;r<o.length;r++){let n=o.charCodeAt(r);c=Math.imul(c^n,16777619)>>>0,e=Math.imul(e^n,1540483477)>>>0,i=Math.imul(i^n,461845907)>>>0}return(c.toString(36)+e.toString(36)+i.toString(36)).slice(0,24)}function Ze(){let t=De();t?ze(t):(t=Math.floor(Date.now()/1e3),Ye(t));let s=t+Pe*86400,a=Date.now()/1e3,o=Math.max(0,Math.ceil((s-a)/86400));return a>s?{valid:!0,plan:nt,watermark:!0,trialExpired:!0,daysLeft:0,features:x(nt)}:{valid:!0,plan:te,watermark:!0,daysLeft:o,trialEnd:s,features:x(te)}}function Xe(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}var mt="MRD-Indicators",re="mrd-indicators.com",He="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iMzAiIHZpZXdCb3g9IjAgMCAzMCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtNCk7CiAgICAgIH0KCiAgICAgIC5jbHMtMiB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtMik7CiAgICAgIH0KCiAgICAgIC5jbHMtMiwgLmNscy0zLCAuY2xzLTQsIC5jbHMtNSwgLmNscy02IHsKICAgICAgICBtaXgtYmxlbmQtbW9kZTogbXVsdGlwbHk7CiAgICAgIH0KCiAgICAgIC5jbHMtMyB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtMyk7CiAgICAgIH0KCiAgICAgIC5jbHMtNCB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtNik7CiAgICAgIH0KCiAgICAgIC5jbHMtNSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtNSk7CiAgICAgIH0KCiAgICAgIC5jbHMtNiB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtNyk7CiAgICAgIH0KCiAgICAgIC5jbHMtNyB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQpOwogICAgICB9CgogICAgICAuY2xzLTggewogICAgICAgIGlzb2xhdGlvbjogaXNvbGF0ZTsKICAgICAgfQogICAgPC9zdHlsZT4KICAgIDxsaW5lYXJHcmFkaWVudCBpZD0ibGluZWFyLWdyYWRpZW50IiB4MT0iOS4xMiIgeTE9IjE1Ljg4IiB4Mj0iMTkuNjMiIHkyPSI1LjM3IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2IzNTA5ZSIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNmNWE0YzciLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVudC0yIiB4MT0iOS4wOCIgeTE9IjYuODEiIHgyPSI5LjA4IiB5Mj0iMTQuNzMiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjMjM0ZmIzIi8+CiAgICAgIDxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI2ZmZiIvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDxsaW5lYXJHcmFkaWVudCBpZD0ibGluZWFyLWdyYWRpZW50LTMiIHgxPSIxNy42NyIgeTE9IjYuMTEiIHgyPSI4LjQxIiB5Mj0iNi4xMSIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPgogICAgICA8c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiM1YTJhOGIiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmZmIi8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJsaW5lYXItZ3JhZGllbnQtNCIgeDE9IjIwLjAzIiB5MT0iMTUuODkiIHgyPSIxMC45OCIgeTI9IjE1Ljg5IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2Y2YWFjYiIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiM3NzJhOGQiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVudC01IiB4MT0iMTkuMDMiIHkxPSIxNi44MiIgeDI9IjE0Ljc5IiB5Mj0iMTIuNTgiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj4KICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZmZmIi8+CiAgICAgIDxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI2VkMzQ4ZCIvPgogICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDxsaW5lYXJHcmFkaWVudCBpZD0ibGluZWFyLWdyYWRpZW50LTYiIHgxPSIxNS4yNyIgeTE9IjE1LjA2IiB4Mj0iMTUuMjciIHkyPSIxOS4zNyIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPgogICAgICA8c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiNmZmYiLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZWU0YzliIi8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJsaW5lYXItZ3JhZGllbnQtNyIgeDE9IjUuNTEiIHkxPSItMTI4LjAyIiB4Mj0iLTMuNyIgeTI9Ii0xMjguMDIiIGdyYWRpZW50VHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTEwOS4xMiAxMC4wMSkgcm90YXRlKDg5LjYpIiB4bGluazpocmVmPSIjbGluZWFyLWdyYWRpZW50LTMiLz4KICA8L2RlZnM+CiAgPGcgY2xhc3M9ImNscy04IiBpZD0iTG9nbyI+CiAgICA8ZyBpZD0iT0JKRUNUUyIgPgogICAgICA8ZyBpZCA9IkxvZ28iPiAKICAgICAgICA8cGF0aCBjbGFzcz0iY2xzLTciIGQ9Ik00LjIzLDExYzAsNS4zNiw0LjM3LDkuNzEsOS43Niw5LjcxczkuNzYtNC4zNSw5Ljc2LTkuNzFTMTkuMzksMS4yOSwxNCwxLjI5LDQuMjMsNS42NCw0LjIzLDExWk0xMC4yNiwxMC4wN2MwLTEuNTQsMS4yNS0yLjc4LDIuOC0yLjc4aDEuODdjMS41NSwwLDIuOCwxLjI1LDIuOCwyLjc4djEuODZjMCwxLjU0LTEuMjUsMi43OC0yLjgsMi43OGgtMS4yMmMtLjQ1LDAtLjg4LjE1LTEuMjIuNDRsLTIuMjMsMS44NHYtNi45MloiLz4KICAgICAgICA8cGF0aCBjbGFzcz0iY2xzLTIiIGQ9Ik0xMC4yNiwxNi45OXYtNi45MnMwLS4wMiwwLS4wM2MuMDItMS41MiwxLjI2LTIuNzUsMi44LTIuNzVoLTUuMDljLTIuMDUsMC0zLjczLDEuNjQtMy43NCwzLjY4LDAsLjAxLDAsLjAzLDAsLjA0LDAsLjA4LDAsLjE2LDAsLjI0LDAsLjA0LDAsLjA4LDAsLjEyLDAsLjA0LDAsLjA4LDAsLjEyLDAsLjA2LDAsLjExLjAxLjE3LDAsLjAyLDAsLjA1LDAsLjA3LDAsLjA2LjAxLjEzLjAyLjE5LDAsLjAxLDAsLjAzLDAsLjA0LDAsLjA3LjAxLjE0LjAyLjIxLDAsMCwwLC4wMSwwLC4wMiwwLC4wNy4wMi4xNS4wMy4yMiwwLDAsMCwwLDAsMCwuNjgsNC42OCw0LjcxLDguMjcsOS42LDguMy0yLjA0LS4wMi0zLjY3LTEuNjktMy42Ny0zLjcyWiIvPgogICAgICAgIDxwYXRoIGNsYXNzPSJjbHMtMyIgZD0iTTE0LjA0LDEuMjlzLS4wMywwLS4wNCwwYy0uMDgsMC0uMTYsMC0uMjQsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDYsMC0uMTEsMC0uMTcsMC0uMDIsMC0uMDUsMC0uMDcsMC0uMDYsMC0uMTMuMDEtLjE5LjAyLS4wMSwwLS4wMywwLS4wNCwwLS4wNywwLS4xNC4wMS0uMjEuMDIsMCwwLS4wMSwwLS4wMiwwLS4wNywwLS4xNS4wMi0uMjIuMDMsMCwwLDAsMCwwLDAtNC43LjY4LTguMzIsNC42OS04LjM1LDkuNTQuMDItMi4wMiwxLjctMy42NSwzLjc0LTMuNjVoNi45NnMuMDIsMCwuMDMsMGMxLjUzLjAyLDIuNzcsMS4yNiwyLjc3LDIuNzh2LTUuMDZjMC0yLjA0LTEuNjUtMy43MS0zLjctMy43MloiLz4KICAgICAgICA8cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik0xNC45MywxNC43MWg1LjA5YzIuMDQsMCwzLjcyLTEuNjMsMy43NC0zLjY1LS4wMyw0Ljg2LTMuNjUsOC44Ny04LjM1LDkuNTQsMCwwLDAsMCwwLDAtLjA3LjAxLS4xNS4wMi0uMjIuMDMsMCwwLS4wMSwwLS4wMiwwLS4wNywwLS4xNC4wMi0uMjEuMDItLjAxLDAtLjAzLDAtLjA0LDAtLjA2LDAtLjEzLjAxLS4xOS4wMi0uMDIsMC0uMDUsMC0uMDcsMC0uMDYsMC0uMTEsMC0uMTcsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDgsMC0uMTYsMC0uMjQsMC0uMDEsMC0uMDMsMC0uMDQsMC0yLjA1LDAtMy43LTEuNjgtMy43LTMuNzJsMi4yMy0xLjg0Yy4zNC0uMjguNzgtLjQ0LDEuMjItLjQ0aDEuMjJaIi8+CiAgICAgICAgPHBhdGggY2xhc3M9ImNscy01IiBkPSJNMTQuOTMsMTQuNzFoNS4wOWMyLjA0LDAsMy43Mi0xLjYzLDMuNzQtMy42NS0uMDMsNC44Ni0zLjY1LDguODctOC4zNSw5LjU0LDAsMCwwLDAsMCwwLS4wNy4wMS0uMTUuMDItLjIyLjAzLDAsMC0uMDEsMC0uMDIsMC0uMDcsMC0uMTQuMDItLjIxLjAyLS4wMSwwLS4wMywwLS4wNCwwLS4wNiwwLS4xMy4wMS0uMTkuMDItLjAyLDAtLjA1LDAtLjA3LDAtLjA2LDAtLjExLDAtLjE3LDAtLjA0LDAtLjA4LDAtLjEyLDAtLjA0LDAtLjA4LDAtLjEyLDAtLjA4LDAtLjE2LDAtLjI0LDAtLjAxLDAtLjAzLDAtLjA0LDAtMi4wNSwwLTMuNy0xLjY4LTMuNy0zLjcybDIuMjMtMS44NGMuMzQtLjI4Ljc4LS40NCwxLjIyLS40NGgxLjIyWiIvPgogICAgICAgIDxwYXRoIGNsYXNzPSJjbHMtNCIgZD0iTTIwLjI4LDE0LjcxYy0uMDgsMC0uMTcsMC0uMjUsMGgtNi4zMWMtLjQ1LDAtLjg4LjE1LTEuMjIuNDRsLTIuMjMsMS44NGMwLC4wOCwwLC4xNywwLC4yNSwxLjA5LjY1LDIuMzcsMS4wMiwzLjczLDEuMDIsMi42NywwLDUuMDEtMS40Myw2LjI4LTMuNTVaIi8+CiAgICAgICAgPHBhdGggY2xhc3M9ImNscy02IiBkPSJNMjMuNzcsMTAuOTdzMC0uMDMsMC0uMDRjMC0uMDgsMC0uMTYsMC0uMjQsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDYsMC0uMTEtLjAxLS4xNywwLS4wMiwwLS4wNSwwLS4wNywwLS4wNi0uMDEtLjEzLS4wMi0uMTksMC0uMDEsMC0uMDMsMC0uMDQsMC0uMDctLjAyLS4xNC0uMDItLjIxLDAsMCwwLS4wMSwwLS4wMiwwLS4wNy0uMDItLjE1LS4wMy0uMjIsMCwwLDAsMCwwLDAtLjcxLTQuNjctNC43Ny04LjI0LTkuNjYtOC4yNCwyLjA0LDAsMy42OCwxLjY2LDMuNywzLjY5bC4wNCw1LjA2djEuODZzLjAxLjAyLjAxLjAzYzAsMS41Mi0xLjI1LDIuNzYtMi43OCwyLjc3bDUuMDktLjA0YzIuMDUtLjAxLDMuNzItMS42NiwzLjcxLTMuN1oiLz4KICAgICAgPC9nPgogICAgPC9nPgogIDwvZz4KPC9zdmc+",Mt=null,oe=!1;function he(){if(Mt||oe)return Mt;oe=!0;let t=new Image;return t.onload=()=>{Mt=t},t.src=He,null}function Oe(){return Math.floor(Date.now()/864e5)}function We(t){let s=(t^2654435769)>>>0;return function(){s=s+1831565813>>>0;let a=Math.imul(s^s>>>15,1|s);return a=a+Math.imul(a^a>>>7,61|a)^a,((a^a>>>14)>>>0)/4294967296}}function Be(t,s,a,o,c,e){let i=he();t.save(),t.setTransform(1,0,0,1,0,0),t.font="bold 12px Inter, system-ui, sans-serif";let r=t.measureText(o);t.font="10px Inter, system-ui, sans-serif";let n=t.measureText(c),l=i?28:0,u=i?22:0,g=10,f=8,d=i?8:0,h=l+d+Math.max(r.width,n.width)+g*2,p=Math.max(u,28)+f*2,w=Math.round(s-h/2),M=Math.round(a-p/2);t.globalAlpha=.92,t.fillStyle=e?"rgba(255,255,255,0.95)":"rgba(18,18,28,0.95)",t.shadowColor=e?"rgba(0,0,0,0.1)":"rgba(0,0,0,0.5)",t.shadowBlur=14,t.shadowOffsetY=2,t.beginPath(),t.roundRect(w,M,h,p,8),t.fill(),t.shadowColor="transparent",t.strokeStyle=e?"rgba(0,0,0,0.06)":"rgba(255,255,255,0.06)",t.lineWidth=1,t.stroke();let S=w+g,I=M+p/2;i&&(t.globalAlpha=1,t.drawImage(i,S,I-u/2,l,u),S+=l+d),t.globalAlpha=1,t.font="bold 12px Inter, system-ui, sans-serif",t.fillStyle=e?"#1a1a2e":"#ededf5",t.textAlign="left",t.textBaseline="alphabetic",t.fillText(o,S,I-1),t.font="10px Inter, system-ui, sans-serif",t.fillStyle=e?"#777790":"#8080a0",t.textBaseline="top",t.fillText(c,S,I+3),t.restore()}function pe(t,s,a,o){he();let c=s.width,e=s.height;if(c<100||e<80)return;t.save(),t.setTransform(1,0,0,1,0,0);let i=We(Oe());t.globalAlpha=o?.04:.06,t.font="bold 14px Inter, system-ui, sans-serif",t.fillStyle=o?"#000000":"#ffffff",t.textAlign="center";let r=i()*100;t.rotate(-.3);let n=240;for(let S=-e+r;S<e*2;S+=n)for(let I=-c+r;I<c*2;I+=n)t.fillText(mt,I,S);t.setTransform(1,0,0,1,0,0);let l=100,u=Math.max(c-l*2,60),g=Math.max(e-l*2,40),f=l+i()*u,d=l+i()*g,_=a.trialExpired||a.plan===nt,h=mt,p=_?`Free \u2014 ${re}/pricing`:`Trial: ${a.daysLeft||0}d left \u2014 ${re}`;Be(t,f,d,h,p,o);let w=Mt,M=e-14;t.globalAlpha=.65,w&&t.drawImage(w,c-82,M-7,16,12),t.font="10px Inter, system-ui, sans-serif",t.textAlign="right",t.textBaseline="bottom",t.fillStyle=o?"#555":"#888",t.fillText(_?`Free \u2022 ${mt}`:`Trial \u2022 ${mt}`,c-8,e-6),t.restore()}function Ve({plan:t,domain:s="*",expiryDays:a=365,name:o,email:c}){let e=a>0?Math.floor(Date.now()/1e3)+a*86400:0,i={p:t,d:s,e,...o?{n:o}:{},...c?{m:c}:{},i:Date.now()};return i.s=ce(i),btoa(JSON.stringify(i))}var St=null,Xt=null,ft=null;async function we(){return St||ft||(ft=(async()=>{let t=await import("./chart_engine.js");return await t.default(),Xt=t.wasm_memory(),St=t,t})(),ft)}function Ge(){!St&&!ft&&we().catch(()=>{})}async function qe(t,s={}){s.appId&&typeof window<"u"&&(window.__mrd_app_id=s.appId);let a=s.licenseKey||s.key||null,o=Lt(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 we(),e=window.devicePixelRatio||1,i=t.getBoundingClientRect();(i.width<1||i.height<1)&&(await new Promise(m=>{let L=new ResizeObserver(C=>{for(let b of C)if(b.contentRect.width>0&&b.contentRect.height>0){L.disconnect(),m();return}});L.observe(t.parentElement||t),setTimeout(()=>{L.disconnect(),m()},2e3)}),i=t.getBoundingClientRect());let r=Math.max(i.width,100),n=Math.max(i.height,100);t.width=r*e,t.height=n*e;let l=t.getContext("2d");l.scale(e,e);let u=new c.ChartEngine(r,n);{let m=o.expired?2:o.watermark?1:0,L=o.daysLeft||0,C=1297237059;C=Math.imul(C,31)+m>>>0,C=Math.imul(C,31)+L>>>0,C=(C^C>>>16)>>>0,C=Math.imul(C,73244475)>>>0,C=(C^C>>>16)>>>0,u.set_license_state(m,L,C)}let g=!0,f=null,d=!1,_=!1,h=!1,p=null,w=null,M=0,I=("ontouchstart"in window||navigator.maxTouchPoints>0)&&window.innerWidth<=1399?33:0;function j(){if(!(!d||_||f)){if(I>0){let m=performance.now()-M;if(m<I){w||(w=setTimeout(()=>{w=null,j()},I-m));return}}f=requestAnimationFrame(Me)}}let v=()=>{g=!0,j()},K=()=>h,Q=null,et=null,rt=null,dt=null,It=null,T=null,z=null,P=null,X=0,U=null,ot=null,G=0,Ct=0,$=-1,_t=!1,ct=!1,ge=bt(t,u,{onDirty:v,onCrosshairMove:(m,L,C)=>{G=m,Ct=L,$=C,_t=!0,ct=!0},onCrosshairHide:()=>{ct&&(ct=!1,_t=!0,$=-1)},drawingApi:m=>{Q=m},onDrawingComplete:()=>{et?.()},onDrawingCancel:()=>{rt?.()},onDrawingSelected:(m,L,C)=>{dt?.(m,L,C)},onMarkerSelected:m=>{It?.(m)},onDrawingDblClick:(m,L,C,b,Ce)=>{T?.(m,L,C,b,Ce)},onVrvpHover:(m,L)=>{z?.(m,L)},onLiqAnnotationPin:(m,L)=>{ot?.(m,L)}});function me(){if(_t){if(_t=!1,!ct){p&&p(null,0,0),P&&P("");return}if(p)if($===0||$===1){let m=u.get_tooltip_data();p(m,G,Ct)}else p(null,0,0);if(P){let m=performance.now();if($===0||$===1){if(m-X>=80){X=m;try{P(u.lt_hit_test(G,Ct))}catch{}}}else P("")}}}function Me(){if(f=null,!(!d||_)&&(g||u.is_dirty())){g=!1,M=performance.now();let m=!1;try{if(u.render()>0){let C=u.get_command_buffer_ptr(),b=u.get_command_buffer_len();l.save(),l.setTransform(1,0,0,1,0,0),l.clearRect(0,0,t.width,t.height),l.restore(),pt(l,Xt,C,b),m=!0}try{q.renderAll(l)}catch{}}catch{m||(g=!0)}me();try{U?.()}catch{}if(o.watermark)try{let L=u.get_theme()===1;pe(l,t,o,L)}catch{}(g||u.is_dirty())&&j()}}let st=Et(o.plan),Le=$t(u,v,K,()=>st),Se=Jt(u,v,K,()=>st),Ie=xt(u,v,K,()=>st),q=yt(u,Xt,pt);return{engine:u,start(){d=!0,_=!1,g=!0,j()},stop(){d=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null)},resize(m){if(i=t.getBoundingClientRect(),i.width<1||i.height<1){(m||0)<8&&setTimeout(()=>this.resize((m||0)+1),250);return}e=window.devicePixelRatio||1;let L=i.width*e,C=i.height*e;t.width=L,t.height=C,l.setTransform(1,0,0,1,0,0),l.scale(e,e),u.resize(i.width,i.height),v()},setHoverPrice(m){u.set_hover_price(m),v()},clearHoverPrice(){u.clear_hover_price(),v()},hitZone(m,L){return u.hit_zone(m,L)},startDrawing(m,L){Q?.setMode(m,L)},cancelDrawing(){Q?.setMode(null)},onDrawingComplete(m){et=m},onDrawingCancel(m){rt=m},onDrawingSelected(m){dt=m},onMarkerSelected(m){It=m},onDrawingDblClick(m){T=m},setReplayState(m,L,C){u.set_replay_state(m,L,C),v()},setReplayHovered(m){u.set_replay_hovered(m)},setReplayPreview(m){u.set_replay_preview(m),v()},setPrecision(m){u.set_price_precision(m),v()},setCandleInterval(m){u.set_candle_interval(m)},setTheme(m){let L=m==="light"?1:0;typeof u.set_theme=="function"?(u.set_theme(L),v()):console.warn("[ChartEngine] set_theme not available \u2014 reload page to load updated WASM")},getTheme(){return u.get_theme()===1?"light":"dark"},onTooltip(m){p=m},onVrvpHover(m){z=m},onLtHover(m){P=m},onPostRender(m){U=m},onLiqAnnotationPin(m){ot=m},pause(){_||(_=!0,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null))},resume(){_&&(_=!1,d&&(g=!0,j()))},get isPaused(){return _},destroy(){h=!0,d=!1,_=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null),ge();try{u.free()}catch{}},addIndicator(m){if(!st("customIndicators"))return null;let L=q.add(m);return v(),L},removeIndicator(m){q.remove(m),v()},updateIndicatorParams(m,L){q.updateParams(m,L),v()},setIndicatorEnabled(m,L){q.setEnabled(m,L),v()},listIndicators(){return q.list()},invalidateCustomIndicators(){q.invalidateCompute(),v()},get license(){return{plan:o.plan,valid:o.valid,expired:!!o.expired,watermark:!!o.watermark,daysLeft:o.daysLeft,features:o.features||{}}},setLicenseKey(m){o=Lt(m),!o.valid&&!o.expired&&console.error(`[MRD Chart Engine] ${o.error}`),st=Et(o.plan);let L=o.expired?2:o.watermark?1:0,C=o.daysLeft||0,b=1297237059;return b=Math.imul(b,31)+L>>>0,b=Math.imul(b,31)+C>>>0,b=(b^b>>>16)>>>0,b=Math.imul(b,73244475)>>>0,b=(b^b>>>16)>>>0,u.set_license_state(L,C,b),v(),o.valid},...Ie,...Le,...Se}}export{qe as createChartBridge,yt as createCustomIndicatorManager,pt as dispatchCommands,Ve as generateLicenseKey,Ge as prefetchWasm,bt as setupEvents,Lt as validateLicense};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kline-orderbook-chart",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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",