kline-orderbook-chart 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/mrd-chart-engine.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<h1 align="center">@mrd/chart-engine</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<strong>Candlestick chart with built-in orderbook heatmap, footprint chart, and liquidation heatmap.<br/>Native
|
|
4
|
+
<strong>Candlestick chart with built-in orderbook heatmap, footprint chart, and liquidation heatmap.<br/>Native high-performance engine. 60 fps. Zero dependencies.</strong>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
@@ -36,7 +36,7 @@ npm install @mrd/chart-engine
|
|
|
36
36
|
```javascript
|
|
37
37
|
import { createChartBridge, prefetchWasm } from '@mrd/chart-engine'
|
|
38
38
|
|
|
39
|
-
// Preload the
|
|
39
|
+
// Preload the engine binary in the background
|
|
40
40
|
prefetchWasm()
|
|
41
41
|
|
|
42
42
|
const chart = await createChartBridge(document.getElementById('chart'), {
|
|
@@ -81,7 +81,7 @@ document.addEventListener('visibilitychange', () =>
|
|
|
81
81
|
document.hidden ? chart.pause() : chart.resume()
|
|
82
82
|
)
|
|
83
83
|
|
|
84
|
-
// Free
|
|
84
|
+
// Free engine memory on component unmount
|
|
85
85
|
chart.destroy()
|
|
86
86
|
```
|
|
87
87
|
|
|
@@ -159,7 +159,7 @@ chart.onDrawingComplete = (id, type, points) => { /* persist to backend */ }
|
|
|
159
159
|
|
|
160
160
|
Chrome 80+ · Firefox 79+ · Safari 15.2+ · Edge 80+ · Mobile Chrome · Mobile Safari
|
|
161
161
|
|
|
162
|
-
Requires
|
|
162
|
+
Requires a modern browser (ES2020+).
|
|
163
163
|
|
|
164
164
|
---
|
|
165
165
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P={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},Te=["left","center","right"],pt=new Map,Ee=4096;function ye(t,o,i,s){return t<<24|o<<16|i<<8|s}function Y(t,o,i,s){let p=ye(t,o,i,s),e=pt.get(p);return e||(e=`rgba(${t},${o},${i},${(s/255).toFixed(3)})`,pt.size>=Ee&&pt.clear(),pt.set(p,e),e)}var Vt=new TextDecoder;function wt(t,o,i,s){let p=o.buffer;if(i+s>p.byteLength)return;let e=new DataView(p,i,s),n=new Uint8Array(p,i,s),r=0,a="",d="",l=-1,g="";for(;r<s;){let u=n[r];if(r+=1,u===P.END_FRAME)break;switch(u){case P.FILL_RECT:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4,w!==a&&(t.fillStyle=w,a=w),t.fillRect(f,_,c,h);break}case P.STROKE_RECT:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4,w!==d&&(t.strokeStyle=w,d=w),m!==l&&(t.lineWidth=m,l=m),t.strokeRect(f,_,c,h);break}case P.LINE:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==d&&(t.strokeStyle=w,d=w),m!==l&&(t.lineWidth=m,l=m),t.setLineDash([]),t.moveTo(f,_),t.lineTo(c,h),t.stroke();break}case P.DASHED_LINE:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4;let L=e.getFloat32(r,!0);r+=4;let S=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==d&&(t.strokeStyle=w,d=w),m!==l&&(t.lineWidth=m,l=m),t.setLineDash([L,S]),t.moveTo(f,_),t.lineTo(c,h),t.stroke(),t.setLineDash([]);break}case P.POLYLINE:{let f=e.getUint16(r,!0);r+=2;let _=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let c=e.getFloat32(r,!0);if(r+=4,f>0){let h=new Float32Array(f*2);for(let w=0;w<f;w++)h[w*2]=e.getFloat32(r,!0),r+=4,h[w*2+1]=e.getFloat32(r,!0),r+=4;if(t.beginPath(),_!==d&&(t.strokeStyle=_,d=_),c!==l&&(t.lineWidth=c,l=c),t.setLineDash([]),t.lineJoin="round",t.lineCap="round",f<=3){t.moveTo(h[0],h[1]);for(let w=1;w<f;w++)t.lineTo(h[w*2],h[w*2+1])}else{t.moveTo(h[0],h[1]),t.lineTo((h[0]+h[2])*.5,(h[1]+h[3])*.5);for(let w=1;w<f-1;w++){let m=h[w*2],L=h[w*2+1],S=h[(w+1)*2],C=h[(w+1)*2+1];t.quadraticCurveTo(m,L,(m+S)*.5,(L+C)*.5)}t.lineTo(h[(f-1)*2],h[(f-1)*2+1])}t.stroke()}break}case P.TEXT:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=n[r];r+=1;let m=e.getUint16(r,!0);r+=2;let L=Vt.decode(new Uint8Array(o.buffer,i+r,m));r+=m,c!==a&&(t.fillStyle=c,a=c);let S=`${h}px "IBM Plex Mono",monospace`;S!==g&&(t.font=S,g=S),t.textAlign=Te[w]||"left",t.textBaseline="middle",t.fillText(L,f,_);break}case P.CIRCLE:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4,t.beginPath(),t.arc(f,_,c,0,Math.PI*2),h!==a&&(t.fillStyle=h,a=h),t.fill(),m>0&&(w!==d&&(t.strokeStyle=w,d=w),m!==l&&(t.lineWidth=m,l=m),t.stroke());break}case P.TRIANGLE:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let m=e.getFloat32(r,!0);r+=4;let L=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4,t.beginPath(),t.moveTo(f,_),t.lineTo(c,h),t.lineTo(w,m),t.closePath(),L!==a&&(t.fillStyle=L,a=L),t.fill();break}case P.SAVE:{t.save();break}case P.RESTORE:{t.restore(),a="",d="",l=-1,g="";break}case P.CLIP_RECT:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4,t.beginPath(),t.rect(f,_,c,h),t.clip();break}case P.ROTATED_TEXT:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let m=e.getUint16(r,!0);r+=2;let L=Vt.decode(n.subarray(r,r+m));r+=m;let S=`${h}px sans-serif`;S!==g&&(t.font=S,g=S),c!==a&&(t.fillStyle=c,a=c),t.textAlign="center",t.textBaseline="middle",t.save(),t.translate(f,_),t.rotate(w),t.fillText(L,0,0),t.restore();break}case P.BUBBLE_3D:{let f=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=n[r],w=n[r+1],m=n[r+2],L=n[r+3];r+=4;let S=n[r],C=n[r+1],N=n[r+2],U=n[r+3];r+=4;let T=n[r],x=n[r+1],$=n[r+2],_t=n[r+3];r+=4;let St=e.getFloat32(r,!0);r+=4;let E=c;if(E<10){let Z=`rgba(${h},${w},${m},${(L/255).toFixed(3)})`;t.beginPath(),t.arc(f,_,E,0,Math.PI*2),t.fillStyle=Z,t.fill(),a=""}else if(E<18){let Z=f-E*.25,W=_-E*.25,H=t.createRadialGradient(Z,W,E*.08,f,_,E);H.addColorStop(0,`rgba(${S},${C},${N},${(U/255).toFixed(3)})`),H.addColorStop(1,`rgba(${h},${w},${m},${(L/255).toFixed(3)})`),t.beginPath(),t.arc(f,_,E,0,Math.PI*2),t.fillStyle=H,t.fill(),a=""}else{let Z=f-E*.25,W=_-E*.25,H=t.createRadialGradient(f,_,E*.85,f,_,E*1.2);H.addColorStop(0,`rgba(${T},${x},${$},${(_t/255*.5).toFixed(3)})`),H.addColorStop(1,`rgba(${T},${x},${$},0)`),t.beginPath(),t.arc(f,_,E*1.2,0,Math.PI*2),t.fillStyle=H,t.fill();let O=t.createRadialGradient(Z,W,E*.08,f,_,E);O.addColorStop(0,`rgba(${S},${C},${N},${(U/255).toFixed(3)})`),O.addColorStop(1,`rgba(${h},${w},${m},${(L/255).toFixed(3)})`),t.beginPath(),t.arc(f,_,E,0,Math.PI*2),t.fillStyle=O,t.fill();let st=E*.2,J=t.createRadialGradient(Z,W,0,Z,W,st);J.addColorStop(0,"rgba(255,255,255,0.22)"),J.addColorStop(1,"rgba(255,255,255,0)"),t.beginPath(),t.arc(Z,W,st,0,Math.PI*2),t.fillStyle=J,t.fill(),a=""}break}case P.FILL_POLYGON:{let f=e.getUint16(r,!0);r+=2;let _=Y(n[r],n[r+1],n[r+2],n[r+3]);if(r+=4,f>2){t.beginPath();let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4,t.moveTo(c,h);for(let w=1;w<f;w++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.closePath(),_!==a&&(t.fillStyle=_,a=_),t.fill()}else r+=f*8;break}case P.DASHED_POLYLINE:{let f=e.getUint16(r,!0);r+=2;let _=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);if(r+=4,f>1){t.beginPath(),_!==d&&(t.strokeStyle=_,d=_),c!==l&&(t.lineWidth=c,l=c),t.setLineDash([h,w]),t.lineJoin="round";let m=e.getFloat32(r,!0);r+=4;let L=e.getFloat32(r,!0);r+=4,t.moveTo(m,L);for(let S=1;S<f;S++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.stroke(),t.setLineDash([])}else r+=f*8;break}default:return}}}var z={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 nt(t){return z[t]?.type==="2point"}function at(t){return z[t]?.type==="3point"}function tt(t){let o=z[t]?.type;return o==="1point"||o==="1point_x"||o==="1point_xy"||o==="1point_xp"}function gt(t){return z[t]?.type==="freehand"}function V(t){return z[t]?.type==="npoint"}function B(t){return z[t]?.type==="elliott_manual"}var Bt={r:.04,g:.49,b:1,lineWidth:2,dashed:!1,fontSize:12};function G(t,o,i,s,p,e){e=e||Bt;let n=z[o];if(!n)return 0;let r=0;return n.type==="3point"?r=t[n.addFn](i.x1,i.y1,i.x2,i.y2,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="2point"?r=t[n.addFn](i.x1,i.y1,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="1point_x"?r=t[n.addFn](s,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="1point_xp"?r=t[n.addFn](s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="1point_xy"?r=t[n.addFn](s,p,e.r,e.g,e.b,e.fontSize||12,i.pane):r=t[n.addFn](p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane),r||0}function D(t,o,i,s,p,e,n){e=e||Bt;let r=z[o];if(r){if(r.previewFn==="elliott"){t.set_elliott_preview(s,p,e.r,e.g,e.b,e.lineWidth,n);return}r.type==="3point"?i.step===1?t.set_drawing_preview(r.previewKind,i.x1,i.y1,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n):i.step===2&&(r.previewFn==="fib_ext"?t.set_fib_ext_preview(i.x1,i.y1,i.x2,i.y2,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n):t.set_channel_preview(i.x1,i.y1,i.x2,i.y2,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n)):r.type==="2point"?t.set_drawing_preview(r.previewKind,i.x1,i.y1,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n):r.type==="1point_x"?t.set_drawing_preview(r.previewKind,s,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,s,p,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n):t.set_drawing_preview(r.previewKind,0,p,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n)}}function v(t,o,i,s){let p=t.screen_to_world_x(o),e;switch(s){case 1:e=t.screen_to_rsi_y(i);break;case 2:e=t.screen_to_oi_y(i);break;case 3:e=t.screen_to_fr_y(i);break;case 4:e=t.screen_to_cvd_y(i);break;case 5:e=t.screen_to_vpin_y(i);break;default:e=t.screen_to_world_y(i);break}return{wx:p,wy:e}}function X(t){return t===4?1:t===6?2:t===8?3:t===10?4:t===12?5:0}function F(t){return t===0||t===4||t===6||t===8||t===10||t===12}function $t(t,o,i,s){t.addEventListener("wheel",r=>{if(s.disposed)return;r.preventDefault(),s.cancelMomentum();let a=r.deltaY>0?1.1:.9,d=o.hit_zone(r.offsetX,r.offsetY);r.ctrlKey?o.zoom_y(r.offsetY,a):r.shiftKey||d===2?o.zoom_x(r.offsetX,a):d===3?o.zoom_y(r.offsetY,a):o.zoom(r.offsetX,r.offsetY,a),i.onDirty()},{passive:!1}),t.addEventListener("mousedown",r=>{if(s.disposed||r.button!==0)return;s.cancelMomentum(),e();let a=performance.now();if(a-s.lastClickTime<300){s.lastClickTime=a;return}s.lastClickTime=a;let d=s.drawingMode;if(d){let g=o.hit_zone(r.offsetX,r.offsetY);if(!F(g))return;let u=X(g),{wx:f,wy:_}=v(o,r.offsetX,r.offsetY,u),c=d.style,h=d.tool;if(B(h)){if(!d.pathStarted)d.pane=u,o.start_elliott_manual(c.r,c.g,c.b,c.lineWidth,u),o.add_elliott_manual_point(f,_),d.pathStarted=!0,d.step=1;else if(o.add_elliott_manual_point(f,_)){s.finishDrawing(),i.onDirty();return}}else if(V(h))d.pathStarted?o.add_path_point(f,_):(d.pane=u,o.start_path(c.r,c.g,c.b,c.lineWidth,c.dashed,u),o.add_path_point(f,_),d.pathStarted=!0,d.step=1);else if(gt(h))d.pane=u,o.start_brush(c.r,c.g,c.b,c.lineWidth,u),o.add_brush_point(f,_),s.isBrushing=!0;else if(at(h))if(d.step===0)d.x1=f,d.y1=_,d.pane=u,d.step=1;else if(d.step===1)d.x2=f,d.y2=_,d.step=2,o.clear_drawing_preview();else{let w=z[h];w&&w.previewFn==="fib_ext"?o.clear_fib_ext_preview():o.clear_channel_preview(),G(o,h,d,f,_,c),s.finishDrawing()}else if(nt(h))d.step===0?(d.x1=f,d.y1=_,d.pane=u,d.step=1):(G(o,h,d,f,_,c),s.finishDrawing());else{d.pane=u;let w=G(o,h,d,f,_,c);s.finishDrawing(),h==="textnote"&&w>0&&(o.select_drawing(w),i.onDrawingSelected?.(w),i.onDrawingDblClick?.(w,r.offsetX,r.offsetY,r.clientX,r.clientY))}i.onDirty();return}let l=o.hit_zone(r.offsetX,r.offsetY);if(l===5){s.isResizingRsi=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_rsi_ratio(),t.style.cursor="ns-resize";return}if(l===7){s.isResizingOi=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_oi_ratio(),t.style.cursor="ns-resize";return}if(l===9){s.isResizingFr=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_fr_ratio(),t.style.cursor="ns-resize";return}if(l===11){s.isResizingCvd=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_cvd_ratio(),t.style.cursor="ns-resize";return}if(l===13){s.isResizingVpin=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_vpin_ratio(),t.style.cursor="ns-resize";return}if(F(l)){let g=o.get_selected_drawing();if(g>0){let h=o.hit_test_drawing_anchor(r.offsetX,r.offsetY);if(h>=0){s.isDraggingAnchor=!0,s.dragAnchorIdx=h,s.dragAnchorPane=X(l),t.style.cursor="grabbing";return}if(o.hit_test_drawing(r.offsetX,r.offsetY)===g){s.isDraggingDrawing=!0,s.dragDrawingPane=X(l);let{wx:m,wy:L}=v(o,r.offsetX,r.offsetY,s.dragDrawingPane);s.dragDrawingLastWx=m,s.dragDrawingLastWy=L,t.style.cursor="move";return}}let u=o.hit_test_drawing(r.offsetX,r.offsetY);if(u>0){o.deselect_marker(),i.onMarkerSelected?.(0),o.select_drawing(u),i.onDrawingSelected?.(u),i.onDirty();return}let f=o.hit_test_marker(r.offsetX,r.offsetY);if(f>0){o.deselect_drawing(),i.onDrawingSelected?.(0),o.select_marker(f),i.onMarkerSelected?.(f),i.onDirty();return}let _=o.get_selected_drawing(),c=o.get_selected_marker();_>0&&(o.deselect_drawing(),i.onDrawingSelected?.(0),i.onDirty()),c>0&&(o.deselect_marker(),i.onMarkerSelected?.(0),i.onDirty())}F(l)&&(s.liqPinSx=r.offsetX,s.liqPinSy=r.offsetY,s.liqPinTimer&&clearTimeout(s.liqPinTimer),s.liqPinTimer=setTimeout(()=>{s.liqPinTimer=null,i.onLiqAnnotationPin?.(s.liqPinSx,s.liqPinSy)},700)),s.isDragging=!0,s.dragZone=l,s.lastX=r.offsetX,s.lastY=r.offsetY,l===2?t.style.cursor="ew-resize":l===3?t.style.cursor="ns-resize":t.style.cursor="grabbing"});let p=null;function e(){p&&(cancelAnimationFrame(p),p=null)}function n(r,a){let d=o.hover_hit_test(r,a),l=d[0],g=d[1],u=d[2],f=d[3],_=d[4],c=s.drawingMode;l===2?(t.style.cursor="ew-resize",o.hide_crosshair()):l===3?(t.style.cursor="ns-resize",o.hide_crosshair()):(o.set_crosshair(r,a),l===5||l===7||l===9||l===11||l===13?t.style.cursor="ns-resize":!c&&F(l)&&g>0&&u>=0?t.style.cursor="grab":!c&&F(l)&&g>0&&f===g?t.style.cursor="move":!c&&F(l)&&(f>0||_>0)?t.style.cursor="pointer":t.style.cursor="crosshair"),i.onDirty(),i.onCrosshairMove?.(r,a,l),i.onVrvpHover?.(r,a)}t.addEventListener("mousemove",r=>{if(s.disposed)return;if(s.liqPinTimer){let d=Math.abs(r.offsetX-s.liqPinSx),l=Math.abs(r.offsetY-s.liqPinSy);(d>6||l>6)&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null)}if(s.isResizingRsi){let l=t.getBoundingClientRect().height-28,u=(s.resizeStartY-r.offsetY)/l,f=Math.max(.05,Math.min(.5,s.resizeStartRatio+u));o.set_rsi_ratio(f),i.onDirty();return}if(s.isResizingOi){let l=t.getBoundingClientRect().height-28,u=(s.resizeStartY-r.offsetY)/l,f=Math.max(.05,Math.min(.5,s.resizeStartRatio+u));o.set_oi_ratio(f),i.onDirty();return}if(s.isResizingFr){let l=t.getBoundingClientRect().height-28,u=(s.resizeStartY-r.offsetY)/l,f=Math.max(.05,Math.min(.5,s.resizeStartRatio+u));o.set_fr_ratio(f),i.onDirty();return}if(s.isResizingCvd){let l=t.getBoundingClientRect().height-28,u=(s.resizeStartY-r.offsetY)/l,f=Math.max(.05,Math.min(.5,s.resizeStartRatio+u));o.set_cvd_ratio(f),i.onDirty();return}if(s.isResizingVpin){let l=t.getBoundingClientRect().height-28,u=(s.resizeStartY-r.offsetY)/l,f=Math.max(.05,Math.min(.5,s.resizeStartRatio+u));o.set_vpin_ratio(f),i.onDirty();return}if(s.isDraggingAnchor){let{wx:d,wy:l}=v(o,r.offsetX,r.offsetY,s.dragAnchorPane);o.update_drawing_anchor(s.dragAnchorIdx,d,l),o.set_crosshair(r.offsetX,r.offsetY),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,o.hit_zone(r.offsetX,r.offsetY));return}if(s.isDraggingDrawing){let{wx:d,wy:l}=v(o,r.offsetX,r.offsetY,s.dragDrawingPane),g=d-s.dragDrawingLastWx,u=l-s.dragDrawingLastWy;o.move_drawing(g,u),s.dragDrawingLastWx=d,s.dragDrawingLastWy=l,o.set_crosshair(r.offsetX,r.offsetY),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,o.hit_zone(r.offsetX,r.offsetY));return}let a=s.drawingMode;if(s.isBrushing&&a){let d=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,d);o.add_brush_point(l,g),o.set_crosshair(r.offsetX,r.offsetY),i.onDirty();return}if(a&&B(a.tool)&&a.pathStarted){let d=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,d);o.set_elliott_manual_cursor(l,g),o.set_crosshair(r.offsetX,r.offsetY);let u=o.hit_zone(r.offsetX,r.offsetY);i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,u);return}if(a&&V(a.tool)&&a.pathStarted){let d=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,d);o.set_path_cursor(l,g),o.set_crosshair(r.offsetX,r.offsetY);let u=o.hit_zone(r.offsetX,r.offsetY);i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,u);return}if(a&&a.step>0){let d=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,d);D(o,a.tool,a,l,g,a.style,d),o.set_crosshair(r.offsetX,r.offsetY);let u=o.hit_zone(r.offsetX,r.offsetY);i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,u);return}if(a&&tt(a.tool)){let d=o.hit_zone(r.offsetX,r.offsetY),l=X(d),{wx:g,wy:u}=v(o,r.offsetX,r.offsetY,l);D(o,a.tool,a,g,u,a.style,l),o.set_crosshair(r.offsetX,r.offsetY),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,d);return}if(s.isDragging){let d=r.offsetX-s.lastX,l=r.offsetY-s.lastY;s.lastX=r.offsetX,s.lastY=r.offsetY,s.dragZone===2?o.pan_x(d):s.dragZone===3?o.pan_y(l):o.pan(d,l),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,s.dragZone),i.onVrvpHover?.(r.offsetX,r.offsetY);return}s._pendingHoverX=r.offsetX,s._pendingHoverY=r.offsetY,p||(p=requestAnimationFrame(()=>{p=null,s.disposed||n(s._pendingHoverX,s._pendingHoverY)}))}),t.addEventListener("mouseup",()=>{s.disposed||(s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null),s.isBrushing&&(s.isBrushing=!1,o.finish_brush(),s.finishDrawing(),i.onDirty()),s.isDragging=!1,s.isResizingRsi=!1,s.isResizingOi=!1,s.isResizingFr=!1,s.isResizingCvd=!1,s.isResizingVpin=!1,s.isDraggingAnchor=!1,s.isDraggingDrawing=!1,s.dragAnchorIdx=-1,t.style.cursor="crosshair")}),t.addEventListener("mouseleave",()=>{s.disposed||(e(),s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null),s.isBrushing&&(s.isBrushing=!1,o.finish_brush(),s.finishDrawing()),s.isDragging=!1,s.isResizingRsi=!1,s.isResizingOi=!1,s.isResizingFr=!1,s.isResizingCvd=!1,s.isResizingVpin=!1,s.isDraggingAnchor=!1,s.isDraggingDrawing=!1,s.dragAnchorIdx=-1,o.hide_crosshair(),t.style.cursor="crosshair",i.onDirty(),i.onCrosshairHide?.(),i.onVrvpHover?.(null,null))}),t.addEventListener("dblclick",r=>{if(s.disposed)return;r.preventDefault(),r.stopPropagation();let a=s.drawingMode;if(a&&B(a.tool)&&a.pathStarted){o.finish_elliott_manual(),s.finishDrawing(),i.onDirty();return}if(a&&V(a.tool)&&a.pathStarted){o.finish_path(),s.finishDrawing(),i.onDirty();return}if(a)return;let d=o.hit_test_drawing(r.offsetX,r.offsetY);d>0&&(o.select_drawing(d),i.onDirty(),i.onDrawingDblClick?.(d,r.offsetX,r.offsetY,r.clientX,r.clientY))}),t.addEventListener("contextmenu",r=>{if(s.disposed)return;let a=s.drawingMode;if(a&&B(a.tool)&&a.pathStarted){r.preventDefault(),r.stopPropagation(),o.finish_elliott_manual(),s.finishDrawing(),i.onDirty();return}if(a&&V(a.tool)&&a.pathStarted){r.preventDefault(),r.stopPropagation(),o.finish_path(),s.finishDrawing(),i.onDirty();return}})}function Jt(t,o,i,s){t.addEventListener("touchstart",p=>{if(!s.disposed){if(p.preventDefault(),s.cancelMomentum(),p.touches.length===2){clearTimeout(s.longPressTimer),s.isCrosshairMode=!1;let e=t.getBoundingClientRect(),n=p.touches[1].clientX-p.touches[0].clientX,r=p.touches[1].clientY-p.touches[0].clientY;s.lastTouchDist=Math.sqrt(n*n+r*r),s.lastX=(p.touches[0].clientX+p.touches[1].clientX)/2-e.left,s.lastY=(p.touches[0].clientY+p.touches[1].clientY)/2-e.top,s.dragZone=o.hit_zone(s.lastX,s.lastY)}else if(p.touches.length===1){let e=t.getBoundingClientRect(),n=p.touches[0].clientX-e.left,r=p.touches[0].clientY-e.top;s.touchStartX=n,s.touchStartY=r,s.touchMoved=!1;let a=s.drawingMode;if(a){let f=o.hit_zone(n,r);if(F(f)){let _=X(f),{wx:c,wy:h}=v(o,n,r,_),w=a.tool;if(B(w)){if(!a.pathStarted)a.pane=_,o.start_elliott_manual(a.style.r,a.style.g,a.style.b,a.style.lineWidth,_),o.add_elliott_manual_point(c,h),a.pathStarted=!0,a.step=1;else if(o.add_elliott_manual_point(c,h)){s.finishDrawing(),i.onDirty();return}}else V(w)?a.pathStarted?o.add_path_point(c,h):(a.pane=_,o.start_path(a.style.r,a.style.g,a.style.b,a.style.lineWidth,a.style.dashed,_),o.add_path_point(c,h),a.pathStarted=!0,a.step=1):gt(w)?(a.pane=_,o.start_brush(a.style.r,a.style.g,a.style.b,a.style.lineWidth,_),o.add_brush_point(c,h),s.isBrushing=!0):at(w)?a.step===0?(a.x1=c,a.y1=h,a.pane=_,a.step=1,a._stepAtTouchStart=0,D(o,w,a,c,h,a.style,_)):a.step===1?(a._stepAtTouchStart=1,D(o,w,a,c,h,a.style,a.pane)):(a._stepAtTouchStart=2,D(o,w,a,c,h,a.style,a.pane)):nt(w)?a.step===0?(a.x1=c,a.y1=h,a.pane=_,a.step=1,a._stepAtTouchStart=0,D(o,w,a,c,h,a.style,_)):(a._stepAtTouchStart=1,D(o,w,a,c,h,a.style,a.pane)):tt(w)?(a.pane=_,D(o,w,a,c,h,a.style,_)):(a.pane=_,G(o,w,a,c,h,a.style),s.finishDrawing());o.set_crosshair(n,r),i.onDirty(),i.onCrosshairMove?.(n,r,f)}return}let d=o.hover_hit_test(n,r),l=d[0],g=d[1],u=d[2];if(F(l)&&!s.drawingMode&&g>0){if(u>=0){s.isDraggingAnchor=!0,s.dragAnchorIdx=u,s.dragAnchorPane=X(l);return}if(d[3]===g){s.isDraggingDrawing=!0,s.dragDrawingPane=X(l);let{wx:_,wy:c}=v(o,n,r,s.dragDrawingPane);s.dragDrawingLastWx=_,s.dragDrawingLastWy=c;return}}s.isDragging=!0,s.isCrosshairMode=!1,s.lastX=n,s.lastY=r,s.dragZone=l,clearTimeout(s.longPressTimer),s.longPressTimer=setTimeout(()=>{s.isDragging&&!s.touchMoved&&(s.isCrosshairMode=!0,o.set_crosshair(n,r),i.onDirty(),i.onCrosshairMove?.(n,r,s.dragZone),i.onVrvpHover?.(n,r))},300),F(s.dragZone)&&(s.liqPinSx=n,s.liqPinSy=r,s.liqPinTimer&&clearTimeout(s.liqPinTimer),s.liqPinTimer=setTimeout(()=>{s.liqPinTimer=null,s.touchMoved||i.onLiqAnnotationPin?.(s.liqPinSx,s.liqPinSy)},700))}}},{passive:!1}),t.addEventListener("touchmove",p=>{if(s.disposed)return;p.preventDefault();let e=t.getBoundingClientRect();if(s.isDraggingAnchor&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,{wx:d,wy:l}=v(o,r,a,s.dragAnchorPane);o.update_drawing_anchor(s.dragAnchorIdx,d,l),o.set_crosshair(r,a),i.onDirty();return}if(s.isDraggingDrawing&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top;s.touchMoved=!0;let{wx:d,wy:l}=v(o,r,a,s.dragDrawingPane),g=d-s.dragDrawingLastWx,u=l-s.dragDrawingLastWy;o.move_drawing(g,u),s.dragDrawingLastWx=d,s.dragDrawingLastWy=l,o.set_crosshair(r,a),i.onDirty();return}let n=s.drawingMode;if(s.isBrushing&&n&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,d=n.pane||0,{wx:l,wy:g}=v(o,r,a,d);o.add_brush_point(l,g),o.set_crosshair(r,a),i.onDirty(),s.touchMoved=!0;return}if(n&&B(n.tool)&&n.pathStarted&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,d=n.pane||0,{wx:l,wy:g}=v(o,r,a,d);o.set_elliott_manual_cursor(l,g),o.set_crosshair(r,a),i.onDirty(),s.touchMoved=!0;return}if(n&&V(n.tool)&&n.pathStarted&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,d=n.pane||0,{wx:l,wy:g}=v(o,r,a,d);o.set_path_cursor(l,g),o.set_crosshair(r,a),i.onDirty(),s.touchMoved=!0;return}if(n&&n.step>0&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top;!s.touchMoved&&(Math.abs(r-s.touchStartX)>10||Math.abs(a-s.touchStartY)>10)&&(s.touchMoved=!0);let d=n.pane||0,{wx:l,wy:g}=v(o,r,a,d);D(o,n.tool,n,l,g,n.style,d),o.set_crosshair(r,a);let u=o.hit_zone(r,a);i.onDirty(),i.onCrosshairMove?.(r,a,u);return}if(n&&tt(n.tool)&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,d=o.hit_zone(r,a),l=X(d),{wx:g,wy:u}=v(o,r,a,l);D(o,n.tool,n,g,u,n.style,l),o.set_crosshair(r,a),i.onDirty(),i.onCrosshairMove?.(r,a,d);return}if(p.touches.length===2){s.velSamples=[];let r=p.touches[1].clientX-p.touches[0].clientX,a=p.touches[1].clientY-p.touches[0].clientY,d=Math.sqrt(r*r+a*a),l=s.lastTouchDist/d,g=(p.touches[0].clientX+p.touches[1].clientX)/2-e.left,u=(p.touches[0].clientY+p.touches[1].clientY)/2-e.top;s.dragZone===3?o.zoom_y(u,l):s.dragZone===2?o.zoom_x(g,l):(o.zoom(g,u,l),o.pan(g-s.lastX,u-s.lastY)),s.lastTouchDist=d,s.lastX=g,s.lastY=u,i.onDirty()}else if(p.touches.length===1&&s.isDragging){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,d=r-s.lastX,l=a-s.lastY;!s.touchMoved&&(Math.abs(r-s.touchStartX)>10||Math.abs(a-s.touchStartY)>10)&&(s.touchMoved=!0,s.isCrosshairMode||clearTimeout(s.longPressTimer),s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null)),s.isCrosshairMode?(o.set_crosshair(r,a),i.onDirty(),i.onCrosshairMove?.(r,a,s.dragZone),i.onVrvpHover?.(r,a)):(s.lastX=r,s.lastY=a,s.recordVelocity(d,l),s.dragZone===2?o.pan_x(d):s.dragZone===3?o.pan_y(l):o.pan(d,l),i.onDirty())}},{passive:!1}),t.addEventListener("touchend",p=>{if(s.disposed)return;if(clearTimeout(s.longPressTimer),s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null),s.isDraggingAnchor){s.isDraggingAnchor=!1,s.dragAnchorIdx=-1,o.hide_crosshair(),i.onDirty(),i.onCrosshairHide?.();return}if(s.isDraggingDrawing){if(s.isDraggingDrawing=!1,o.hide_crosshair(),i.onDirty(),i.onCrosshairHide?.(),!s.touchMoved){let n=o.get_selected_drawing();if(n>0){let r=t.getBoundingClientRect();i.onDrawingDblClick?.(n,s.touchStartX,s.touchStartY,s.touchStartX+r.left,s.touchStartY+r.top)}}return}if(s.isBrushing){s.isBrushing=!1,o.finish_brush(),s.finishDrawing(),i.onDirty(),i.onCrosshairHide?.();return}let e=s.drawingMode;if(e&&B(e.tool)&&e.pathStarted){let n=Date.now(),r=s.touchStartX-(s._pathLastTapX||0),a=s.touchStartY-(s._pathLastTapY||0),d=Math.sqrt(r*r+a*a);n-(s._pathLastTapTime||0)<350&&d<30?(o.finish_elliott_manual(),s.finishDrawing(),s._pathLastTapTime=0):(s._pathLastTapTime=n,s._pathLastTapX=s.touchStartX,s._pathLastTapY=s.touchStartY),s.isDragging=!1,s.lastTouchDist=0,i.onDirty();return}if(e&&V(e.tool)&&e.pathStarted){let n=Date.now(),r=s.touchStartX-(s._pathLastTapX||0),a=s.touchStartY-(s._pathLastTapY||0),d=Math.sqrt(r*r+a*a);n-(s._pathLastTapTime||0)<350&&d<30?(o.finish_path(),s.finishDrawing(),s._pathLastTapTime=0):(s._pathLastTapTime=n,s._pathLastTapX=s.touchStartX,s._pathLastTapY=s.touchStartY),s.isDragging=!1,s.lastTouchDist=0,i.onDirty();return}if(e&&at(e.tool)){let n=e._stepAtTouchStart;if(e.step===1&&(n===1||s.touchMoved)){let r=t.getBoundingClientRect(),a=p.changedTouches?.[0];if(a){let d=a.clientX-r.left,l=a.clientY-r.top,g=e.pane||0,{wx:u,wy:f}=v(o,d,l,g);e.x2=u,e.y2=f,e.step=2,o.clear_drawing_preview()}}else if(e.step===2&&(n===2||s.touchMoved)){let r=t.getBoundingClientRect(),a=p.changedTouches?.[0];if(a){let d=a.clientX-r.left,l=a.clientY-r.top,g=e.pane||0,{wx:u,wy:f}=v(o,d,l,g),_=z[e.tool];_&&_.previewFn==="fib_ext"?o.clear_fib_ext_preview():o.clear_channel_preview(),G(o,e.tool,e,u,f,e.style),s.finishDrawing()}}s.isDragging=!1,s.lastTouchDist=0,s.drawingMode||(o.hide_crosshair(),i.onCrosshairHide?.()),i.onDirty();return}if(e&&e.step===1&&nt(e.tool)){if(e._stepAtTouchStart===1||s.touchMoved){let r=t.getBoundingClientRect(),a=p.changedTouches?.[0];if(a){let d=a.clientX-r.left,l=a.clientY-r.top,g=e.pane||0,{wx:u,wy:f}=v(o,d,l,g);G(o,e.tool,e,u,f,e.style),s.finishDrawing()}}s.isDragging=!1,s.lastTouchDist=0,s.drawingMode||(o.hide_crosshair(),i.onCrosshairHide?.()),i.onDirty();return}if(e&&tt(e.tool)){let n=t.getBoundingClientRect(),r=p.changedTouches?.[0];if(r){let a=r.clientX-n.left,d=r.clientY-n.top,l=o.hit_zone(a,d),g=F(l)?X(l):e.pane||0,{wx:u,wy:f}=v(o,a,d,g),_=e.tool;o.clear_drawing_preview();let c=G(o,_,e,u,f,e.style);s.finishDrawing(),_==="textnote"&&c>0&&(o.select_drawing(c),i.onDrawingSelected?.(c),i.onDrawingDblClick?.(c,a,d,a+n.left,d+n.top))}s.isDragging=!1,s.lastTouchDist=0,o.hide_crosshair(),i.onCrosshairHide?.(),i.onDirty();return}if(!s.touchMoved&&!s.drawingMode&&s.isDragging){let n=Date.now(),r=s.touchStartX-s.lastTapX,a=s.touchStartY-s.lastTapY,d=Math.sqrt(r*r+a*a),l=n-s.lastTapTime<350&&d<30,g=o.hover_hit_test(s.touchStartX,s.touchStartY),u=g[0],f=g[1],_=g[3],c=g[4];if(F(u))if(_>0){o.deselect_marker(),i.onMarkerSelected?.(0),o.select_drawing(_);let h=t.getBoundingClientRect(),w=s.touchStartX+h.left,m=s.touchStartY+h.top;i.onDrawingSelected?.(_,w,m),(f<=0||f===_)&&i.onDrawingDblClick?.(_,s.touchStartX,s.touchStartY,w,m),i.onDirty()}else c>0?(o.deselect_drawing(),i.onDrawingSelected?.(0),o.select_marker(c),i.onMarkerSelected?.(c),i.onDirty()):(f>0&&(o.deselect_drawing(),i.onDrawingSelected?.(0),i.onDirty()),o.get_selected_marker()>0&&(o.deselect_marker(),i.onMarkerSelected?.(0),i.onDirty()));s.lastTapTime=n,s.lastTapX=s.touchStartX,s.lastTapY=s.touchStartY}s.touchMoved&&!s.isCrosshairMode&&!s.drawingMode&&s.startMomentum(s.dragZone),s.isDragging=!1,s.isCrosshairMode=!1,s.lastTouchDist=0,(!s.drawingMode||s.drawingMode.step===0)&&(o.hide_crosshair(),i.onCrosshairHide?.()),i.onDirty(),i.onVrvpHover?.(null,null)})}function Et(t,o,i){let s={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},p=.92,e=.5,n=80;s.recordVelocity=function(l,g){let u=performance.now();for(s.velSamples.push({dx:l,dy:g,t:u});s.velSamples.length>0&&u-s.velSamples[0].t>n;)s.velSamples.shift()};function r(){if(s.velSamples.length<2)return{vx:0,vy:0};let l=s.velSamples[0],u=s.velSamples[s.velSamples.length-1].t-l.t;if(u<5)return{vx:0,vy:0};let f=0,_=0;for(let h of s.velSamples)f+=h.dx,_+=h.dy;let c=16.67;return{vx:f/u*c,vy:_/u*c}}s.cancelMomentum=function(){s.momentumRaf&&(cancelAnimationFrame(s.momentumRaf),s.momentumRaf=null),s.velSamples=[]},s.startMomentum=function(l){let{vx:g,vy:u}=r();if(s.velSamples=[],Math.abs(g)<e&&Math.abs(u)<e)return;s.momentumVx=g,s.momentumVy=u,s.momentumZone=l;function f(){if(s.momentumVx*=p,s.momentumVy*=p,Math.abs(s.momentumVx)<e&&Math.abs(s.momentumVy)<e){s.momentumRaf=null;return}s.momentumZone===2?o.pan_x(s.momentumVx):s.momentumZone===3?o.pan_y(s.momentumVy):o.pan(s.momentumVx,s.momentumVy),i.onDirty(),s.momentumRaf=requestAnimationFrame(f)}s.momentumRaf=requestAnimationFrame(f)};let a={setMode(l,g){l?(s.drawingMode={tool:l,style:g,step:0,x1:0,y1:0},t.style.cursor="crosshair"):(s.drawingMode?.pathStarted&&o.finish_path(),s.drawingMode=null,o.clear_drawing_preview(),t.style.cursor="crosshair"),i.onDirty()},getMode(){return s.drawingMode}};i.drawingApi?.(a),s.finishDrawing=function(){o.clear_drawing_preview(),i.onDrawingComplete?.(),s.drawingMode=null,t.style.cursor="crosshair"},$t(t,o,i,s),Jt(t,o,i,s);let d=l=>{let g=document.activeElement?.tagName,u=g==="INPUT"||g==="TEXTAREA"||document.activeElement?.isContentEditable;if((l.key==="Delete"||l.key==="Backspace")&&!s.drawingMode&&!u){let _=o.get_selected_drawing();if(_>0){o.remove_drawing(_),i.onDrawingSelected?.(0),i.onDirty();return}let c=o.get_selected_marker();if(c>0){o.remove_marker(c),i.onMarkerSelected?.(0),i.onDirty();return}}if(l.key==="Escape"&&!s.drawingMode){if(o.get_selected_drawing()>0){o.deselect_drawing(),i.onDrawingSelected?.(0),i.onDirty();return}if(o.get_selected_marker()>0){o.deselect_marker(),i.onMarkerSelected?.(0),i.onDirty();return}}if(l.key==="Escape"&&s.drawingMode){if(s.drawingMode.pathStarted){s.drawingMode.tool==="elliott"?o.finish_elliott_manual():o.finish_path(),s.finishDrawing(),i.onDirty();return}o.clear_drawing_preview(),s.drawingMode=null,t.style.cursor="crosshair",i.onDrawingCancel?.(),i.onDirty();return}let f=20;switch(l.key){case"+":case"=":o.zoom(t.width/2,t.height/2,.9);break;case"-":o.zoom(t.width/2,t.height/2,1.1);break;case"ArrowLeft":o.pan_x(f);break;case"ArrowRight":o.pan_x(-f);break;case"ArrowUp":o.pan_y(-f);break;case"ArrowDown":o.pan_y(f);break;case"r":case"R":o.auto_scale_y();break;default:return}i.onDirty()};return window.addEventListener("keydown",d),()=>{s.disposed=!0,s.cancelMomentum(),window.removeEventListener("keydown",d)}}function te(t,o,i,s){let p=e=>s()(e);return{enableRsi(){t.enable_rsi(),o()},disableRsi(){t.disable_rsi(),o()},setRsiPeriod(e){t.set_rsi_period(e),o()},isRsiEnabled(){return t.is_rsi_enabled()},setRsiShowEma(e){t.set_rsi_show_ema(e),o()},setRsiShowWma(e){t.set_rsi_show_wma(e),o()},setRsiShowSignals(e){t.set_rsi_show_signals(e),o()},setRsiShowDivergence(e){t.set_rsi_show_divergence(e),o()},setRsiShowTraps(e){t.set_rsi_show_traps(e),o()},setRsiSmoothing(e){t.set_rsi_smoothing(e),o()},setRsiRatio(e){t.set_rsi_ratio(e),o()},getRsiRatio(){return t.get_rsi_ratio()},enableForexSignals(){p("forexSignals")&&(t.enable_forex_signals(),o())},disableForexSignals(){t.disable_forex_signals(),o()},isForexSignalsEnabled(){return t.is_forex_signals_enabled()},setForexSignalsSetup(e){t.set_forex_signals_setup(e),o()},setForexSignalsMode(e){t.set_forex_signals_mode(e),o()},setForexSignalsShowStats(e){t.set_forex_signals_show_stats(e),o()},getForexSignalsCount(){return t.get_forex_signals_count()},enableOi(){i()||p("oi")&&(t.enable_oi(),o())},disableOi(){i()||(t.disable_oi(),o())},isOiEnabled(){if(i())return!1;try{return t.is_oi_enabled()}catch{return!1}},setOiData(e){i()||(t.set_oi_data(e),o())},setOiDataTs(e,n){i()||(t.set_oi_data_ts(e,n),o())},setOiShowOnChart(e){i()||(t.set_oi_show_on_chart(e),o())},setOiDisplayMode(e){i()||(t.set_oi_display_mode(e),o())},setOiRatio(e){i()||(t.set_oi_ratio(e),o())},getOiRatio(){if(i())return .2;try{return t.get_oi_ratio()}catch{return .2}},enableFundingRate(){i()||p("fundingRate")&&(t.enable_funding_rate(),o())},disableFundingRate(){i()||(t.disable_funding_rate(),o())},isFundingRateEnabled(){if(i())return!1;try{return t.is_funding_rate_enabled()}catch{return!1}},setFrBinanceData(e,n){i()||(t.set_fr_binance_data(e,n),o())},setFrAggData(e,n){i()||(t.set_fr_agg_data(e,n),o())},setFrShowAgg(e){i()||(t.set_fr_show_agg(e),o())},setFrShowSma(e){i()||(t.set_fr_show_sma(e),o())},enableCvd(){i()||p("cvd")&&(t.enable_cvd(),o())},disableCvd(){i()||(t.disable_cvd(),o())},isCvdEnabled(){if(i())return!1;try{return t.is_cvd_enabled()}catch{return!1}},setCvdData(e,n){i()||(t.set_cvd_data(e,n),o())},setCvdMode(e){i()||(t.set_cvd_mode(e),o())},getCvdMode(){if(i())return 0;try{return t.get_cvd_mode()}catch{return 0}},setCvdShowDelta(e){i()||(t.set_cvd_show_delta(e),o())},getCvdShowDelta(){if(i())return!0;try{return t.get_cvd_show_delta()}catch{return!0}},enableLargeTrades(){i()||p("largeTrades")&&(t.enable_large_trades(),o())},disableLargeTrades(){i()||(t.disable_large_trades(),o())},isLargeTradesEnabled(){if(i())return!1;try{return t.is_large_trades_enabled()}catch{return!1}},setLargeTradesData(e){i()||(t.set_large_trades_data(e),o())},pushLargeTrade(e,n,r,a){i()||(t.push_large_trade(e,n,r,a),o())},clearLargeTrades(){i()||(t.clear_large_trades(),o())},setLtVolumeFilter(e,n){i()||(t.set_lt_volume_filter(e,n),o())},setLtBubbleScale(e){i()||(t.set_lt_bubble_scale(e),o())},getLtDataMinVol(){return i()?0:t.get_lt_data_min_vol()},getLtDataMaxVol(){return i()?0:t.get_lt_data_max_vol()},ltHitTest(e,n){if(i())return"";try{return t.lt_hit_test(e,n)}catch{return""}},enableVrvp(){i()||p("vrvp")&&(t.enable_vrvp(),o())},disableVrvp(){i()||(t.disable_vrvp(),o())},isVrvpEnabled(){if(i())return!1;try{return t.is_vrvp_enabled()}catch{return!1}},setVrvpPocLine(e){i()||(t.set_vrvp_poc_line(e),o())},vrvpHitTest(e,n){if(i())return"";try{return t.vrvp_hit_test(e,n)}catch{return""}},enableTpo(){i()||p("tpo")&&(t.enable_tpo(),o())},disableTpo(){i()||(t.disable_tpo(),o())},isTpoEnabled(){if(i())return!1;try{return t.is_tpo_enabled()}catch{return!1}},setTpoPocLine(e){i()||(t.set_tpo_poc_line(e),o())},setTpoVaLines(e){i()||(t.set_tpo_va_lines(e),o())},setTpoIb(e){i()||(t.set_tpo_ib(e),o())},setTpoSinglePrints(e){i()||(t.set_tpo_single_prints(e),o())},setTpoPeriod(e){i()||(t.set_tpo_period(e),o())},getTpoPeriod(){if(i())return 1440;try{return t.get_tpo_period()}catch{return 1440}},setTpoNakedPoc(e){i()||(t.set_tpo_naked_poc(e),o())},setTpoProfileShape(e){i()||(t.set_tpo_profile_shape(e),o())},setTpoIbMinutes(e){i()||(t.set_tpo_ib_minutes(e),o())},setTpoLetterMinutes(e){i()||(t.set_tpo_letter_minutes(e),o())},setTpoSignals(e){i()||(t.set_tpo_signals(e),o())},isTpoSignals(){if(i())return!1;try{return t.is_tpo_signals()}catch{return!1}},enableLiqHeatmap(){i()||p("liqHeatmap")&&(t.enable_liq_heatmap(),o())},disableLiqHeatmap(){i()||(t.disable_liq_heatmap(),o())},isLiqHeatmapEnabled(){if(i())return!1;try{return t.is_liq_heatmap_enabled()}catch{return!1}},setLiqHeatmapRange(e,n){i()||(t.set_liq_heatmap_range(e,n),o())},getLiqHeatmapMin(){if(i())return 0;try{return t.get_liq_heatmap_min()}catch{return 0}},getLiqHeatmapMax(){if(i())return 1;try{return t.get_liq_heatmap_max()}catch{return 1}},getLiqHeatmapSegMax(){if(i())return 0;try{return t.get_liq_heatmap_seg_max()}catch{return 0}},setLiqHeatmapProfile(e){i()||(t.set_liq_heatmap_profile(e),o())},isLiqHeatmapProfile(){if(i())return!0;try{return t.is_liq_heatmap_profile()}catch{return!0}},setLiqHeatmapCellHeight(e){i()||(t.set_liq_heatmap_cell_height(e),o())},getLiqHeatmapCellHeight(){if(i())return 1;try{return t.get_liq_heatmap_cell_height()}catch{return 1}},setLiqHeatmapPredictions(e){i()||(t.set_liq_heatmap_predictions(e),o())},setLiqHeatmapFilledPct(e){i()||(t.set_liq_heatmap_filled_pct(e),o())},getLiqHeatmapFilledPct(){if(i())return .85;try{return t.get_liq_heatmap_filled_pct()}catch{return .85}},liqHeatmapHitTest(e,n){if(i())return"";try{return t.liq_heatmap_hit_test(e,n)}catch{return""}},liqZoneHitTest(e,n){if(i())return"";try{return t.liq_zone_hit_test(e,n)}catch{return""}},enableSmartRanges(){i()||p("smartRanges")&&(t.enable_smart_ranges(),o())},disableSmartRanges(){i()||(t.disable_smart_ranges(),o())},isSmartRangesEnabled(){if(i())return!1;try{return t.is_smart_ranges_enabled()}catch{return!1}},setSrTextSize(e){i()||(t.set_sr_text_size(e),o())},setSrShowOb(e){i()||(t.set_sr_show_ob(e),o())},setSrObLast(e){i()||(t.set_sr_ob_last(e),o())},setSrShowObActivity(e){i()||(t.set_sr_show_ob_activity(e),o())},setSrShowBreakers(e){i()||(t.set_sr_show_breakers(e),o())},setSrMitigation(e){i()||(t.set_sr_mitigation(e),o())},setSrShowMetrics(e){i()||(t.set_sr_show_metrics(e),o())},setSrShowHtfOb(e){i()||(t.set_sr_show_htf_ob(e),o())},setSrHtfMinutes(e){i()||(t.set_sr_htf_minutes(e),o())},setSrShowFvg(e){i()||(t.set_sr_show_fvg(e),o())},setSrFvgTheme(e){i()||(t.set_sr_fvg_theme(e),o())},setSrFvgMitigation(e){i()||(t.set_sr_fvg_mitigation(e),o())},setSrFvgHtf(e){i()||(t.set_sr_fvg_htf(e),o())},setSrFvgExtend(e){i()||(t.set_sr_fvg_extend(e),o())},setSrShowObSignals(e){i()||(t.set_sr_show_ob_signals(e),o())},setSrShowPredict(e){i()||(t.set_sr_show_predict(e),o())},setSrShowFvgSignals(e){i()||(t.set_sr_show_fvg_signals(e),o())},setSrShowSmartRev(e){i()||(t.set_sr_show_smart_rev(e),o())},setSrSmartRevHtf(e){i()||(t.set_sr_smart_rev_htf(e),o())},setSrStatsType(e){i()||(t.set_sr_stats_type(e),o())},setSrStatsPosition(e){i()||(t.set_sr_stats_position(e),o())},getSrSignalsCount(){if(i())return 0;try{return t.get_sr_signals_count()}catch{return 0}},enableEmaStructure(){i()||p("emaStructure")&&(t.enable_ema_structure(),o())},disableEmaStructure(){i()||(t.disable_ema_structure(),o())},isEmaStructureEnabled(){if(i())return!1;try{return t.is_ema_structure_enabled()}catch{return!1}},setEsEma1Len(e){i()||(t.set_es_ema1_len(e),o())},setEsEma2Len(e){i()||(t.set_es_ema2_len(e),o())},setEsWmaLen(e){i()||(t.set_es_wma_len(e),o())},setEsShowEma1(e){i()||(t.set_es_show_ema1(e),o())},setEsShowEma2(e){i()||(t.set_es_show_ema2(e),o())},setEsShowWma(e){i()||(t.set_es_show_wma(e),o())},setEsSwingLen(e){i()||(t.set_es_swing_len(e),o())},setEsShowBos(e){i()||(t.set_es_show_bos(e),o())},enableLiveSignals(){i()||(t.enable_live_signals(),o())},disableLiveSignals(){i()||(t.disable_live_signals(),o())},isLiveSignalsEnabled(){if(i())return!1;try{return t.is_live_signals_enabled()}catch{return!1}},setLiveSignalsData(e){i()||(t.set_live_signals_data(new Float64Array(e)),o())},clearLiveSignals(){i()||(t.clear_live_signals(),o())},setLiveSignalsLeverage(e){i()||(t.set_live_signals_leverage(e),o())},getLiveSignalsLeverage(){if(i())return 10;try{return t.get_live_signals_leverage()}catch{return 10}},setLiveSignalsTrial(e){i()||(t.set_live_signals_trial(e),o())},setLiveSignalsShowEntry(e){i()||(t.set_live_signals_show_entry(e),o())},setLiveSignalsShowTpSl(e){i()||(t.set_live_signals_show_tp_sl(e),o())},setLiveSignalsShowMaxProfit(e){i()||(t.set_live_signals_show_max_profit(e),o())},setLiveSignalsShowLabels(e){i()||(t.set_live_signals_show_labels(e),o())},setLiveSignalsShowZones(e){i()||(t.set_live_signals_show_zones(e),o())},setLiveSignalsTextSize(e){i()||(t.set_live_signals_text_size(e),o())},setLiveSignalsPipValue(e){i()||(t.set_live_signals_pip_value(e),o())},setLiveSignalsLoading(e){i()||(t.set_live_signals_loading(e),o())},getLiveSignalsCount(){if(i())return 0;try{return t.get_live_signals_count()}catch{return 0}},enableVpin(){i()||p("vpin")&&(t.enable_vpin(),o())},disableVpin(){i()||(t.disable_vpin(),o())},isVpinEnabled(){if(i())return!1;try{return t.is_vpin_enabled()}catch{return!1}},setVpinData(e,n){i()||(t.set_vpin_data(e,n),o())},setVpinBucketSize(e){i()||(t.set_vpin_bucket_size(e),o())},getVpinBucketSize(){if(i())return 50;try{return t.get_vpin_bucket_size()}catch{return 50}},setVpinNumBuckets(e){i()||(t.set_vpin_num_buckets(e),o())},getVpinNumBuckets(){if(i())return 50;try{return t.get_vpin_num_buckets()}catch{return 50}},setVpinThreshold(e){i()||(t.set_vpin_threshold(e),o())},getVpinThreshold(){if(i())return .7;try{return t.get_vpin_threshold()}catch{return .7}},setVpinShowSma(e){i()||(t.set_vpin_show_sma(e),o())},setVpinShowZones(e){i()||(t.set_vpin_show_zones(e),o())},enableStopIceberg(){i()||p("stopIceberg")&&(t.enable_stop_iceberg(),o())},disableStopIceberg(){i()||(t.disable_stop_iceberg(),o())},isStopIcebergEnabled(){if(i())return!1;try{return t.is_stop_iceberg_enabled()}catch{return!1}},setSiShowStops(e){i()||(t.set_si_show_stops(e),o())},setSiShowIcebergs(e){i()||(t.set_si_show_icebergs(e),o())},setSiShowZones(e){i()||(t.set_si_show_zones(e),o())},setIcebergEvents(e,n,r,a,d,l){i()||(t.set_iceberg_events(e,n,r,a,d,l),o())},getStopRunCount(){if(i())return 0;try{return t.get_stop_run_count()}catch{return 0}},getIcebergCount(){if(i())return 0;try{return t.get_iceberg_count()}catch{return 0}},enableVolume(){t.enable_volume(),o()},disableVolume(){t.disable_volume(),o()},isVolumeEnabled(){return t.is_volume_enabled()},setVolumeMaPeriod(e){t.set_volume_ma_period(e),o()},setVolumeShowMa(e){t.set_volume_show_ma(e),o()},setVolumeShowSignals(e){t.set_volume_show_signals(e),o()},setVolumeColorMode(e){t.set_volume_color_mode(e),o()},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 ee(t,o,i,s){let p=e=>s()(e);return{addMarker(e,n,r){t.add_marker(e,n,r),o()},clearMarkers(){t.clear_markers(),o()},hitTestMarker(e,n){return t.hit_test_marker(e,n)},selectMarker(e){t.select_marker(e),o()},deselectMarker(){t.deselect_marker(),o()},getSelectedMarker(){return t.get_selected_marker()},removeMarker(e){t.remove_marker(e),o()},deleteSelectedMarker(){let e=t.get_selected_marker();return e>0&&(t.remove_marker(e),o()),e},addTrendline(e,n,r,a,d,l,g,u,f,_=0){let c=t.add_trendline(e,n,r,a,d,l,g,u,f,_);return o(),c},addHorizontalLine(e,n,r,a,d,l,g,u=0){let f=t.add_horizontal_line(e,n,r,a,d,l,g,u);return o(),f},addArrow(e,n,r,a,d,l,g,u,f,_=0){let c=t.add_arrow(e,n,r,a,d,l,g,u,f,_);return o(),c},addFibRetracement(e,n,r,a,d,l,g,u,f,_=0){if(!p("drawingFull"))return 0;let c=t.add_fib_retracement(e,n,r,a,d,l,g,u,f,_);return o(),c},addFibExtension(e,n,r,a,d,l,g,u,f,_,c,h=0){if(!p("drawingFull"))return 0;let w=t.add_fib_extension(e,n,r,a,d,l,g,u,f,_,c,h);return o(),w},addLongPosition(e,n,r,a,d,l,g,u,f,_=0){if(!p("drawingFull"))return 0;let c=t.add_long_position(e,n,r,a,d,l,g,u,f,_);return o(),c},addShortPosition(e,n,r,a,d,l,g,u,f,_=0){if(!p("drawingFull"))return 0;let c=t.add_short_position(e,n,r,a,d,l,g,u,f,_);return o(),c},addAnchoredVwap(e,n,r,a,d,l,g=0){if(!p("drawingFull"))return 0;let u=t.add_anchored_vwap(e,n,r,a,d,l,g);return o(),u},addPriceLabel(e,n,r,a,d,l,g=0){let u=t.add_price_label(e,n,r,a,d,l,g);return o(),u},addElliottImpulse(e,n,r,a,d,l,g=0){if(!p("drawingFull"))return 0;let u=t.add_elliott_impulse(e,n,r,a,d,l,g);return o(),u},setDrawingFontSize(e,n){t.set_drawing_font_size(e,n),o()},getDrawingFontSize(e){return t.get_drawing_font_size(e)},setDrawingText(e,n){t.set_drawing_text(e,n),o()},getDrawingText(e){return t.get_drawing_text(e)},setDrawingStyle(e,n,r,a,d){t.set_drawing_style(e,n,r,a,d),o()},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),o()},getDrawingHideLabel(e){try{return t.get_drawing_hide_label(e)}catch{return!1}},setDrawingHideLabel(e,n){t.set_drawing_hide_label(e,n),o()},getDrawingKindId(e){try{return t.get_drawing_kind_id(e)}catch{return 255}},removeDrawing(e){t.remove_drawing(e),o()},clearDrawings(){t.clear_drawings(),o()},drawingCount(){return t.drawing_count()},setDrawingPreview(e,n,r,a,d,l,g,u,f,_,c=0){t.set_drawing_preview(e,n,r,a,d,l,g,u,f,_,c),o()},clearDrawingPreview(){t.clear_drawing_preview(),o()},cancelBrush(){t.cancel_brush(),o()},selectDrawing(e){t.select_drawing(e),o()},deselectDrawing(){t.deselect_drawing(),o()},getSelectedDrawing(){return t.get_selected_drawing()},deleteSelectedDrawing(){let e=t.get_selected_drawing();return e>0&&(t.remove_drawing(e),o()),e},exportDrawingsJson(){try{return t.export_drawings_json()}catch{return"[]"}},importDrawingsJson(e){try{t.import_drawings_json(e),o()}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}}}}var y=t=>t instanceof Float64Array?t:new Float64Array(t);function re(t,o,i,s){let p=e=>s()(e);return{setKlines(e,n,r,a,d,l){t.set_klines(y(e),y(n),y(r),y(a),y(d),y(l)),o()},setRealTimestamps(e){t.set_real_timestamps(y(e)),o()},appendRealTimestamp(e){t.append_real_timestamp(e)},prependKlines(e,n,r,a,d,l){t.prepend_klines(y(e),y(n),y(r),y(a),y(d),y(l)),o()},appendKline(e,n,r,a,d,l){t.append_kline(e,n,r,a,d,l),o()},updateLastKline(e,n,r,a,d,l){t.update_last_kline(e,n,r,a,d,l),o()},popLastKline(){let e=t.pop_last_kline();return e&&o(),e},getLastClose(){try{return t.get_last_close()}catch{return 0}},getKlineCount(){if(i())return 0;try{return t.kline_count()}catch{return 0}},getKlineTimestamps(){if(i())return null;try{return t.kline_timestamps()}catch{return null}},getKlineOpens(){if(i())return null;try{return t.kline_opens()}catch{return null}},getKlineHighs(){if(i())return null;try{return t.kline_highs()}catch{return null}},getKlineLows(){if(i())return null;try{return t.kline_lows()}catch{return null}},getKlineCloses(){if(i())return null;try{return t.kline_closes()}catch{return null}},getKlineVolumes(){if(i())return null;try{return t.kline_volumes()}catch{return null}},setHeatmap(e,n,r,a,d,l,g){p("heatmap")&&(t.set_heatmap(y(e),n,r,a,d,l,g),o())},appendHeatmapColumn(e,n,r,a){p("heatmap")&&(t.append_heatmap_column(y(e),n,r,a),o())},updateLastHeatmapColumn(e,n,r){t.update_last_heatmap_column(y(e),n,r),o()},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,a){t.update_heatmap_column_at(y(e),n,r,a),o()},setHeatmapRange(e,n){t.set_heatmap_range(e,n),o()},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){i()||e===2&&!p("footprint")||(t.set_chart_type(e),o())},getChartType(){if(i())return 0;try{return t.get_chart_type()}catch{return 0}},setFootprintTickSize(e){i()||p("footprint")&&(t.set_footprint_tick_size(e),o())},footprintEnsureLen(e){i()||t.footprint_ensure_len(e)},footprintAddTrade(e,n,r,a){i()||t.footprint_add_trade(e,n,r,a)},footprintAddTradeBatch(e){i()||!e||e.length===0||t.footprint_add_trade_batch(y(e))},footprintSetBar(e,n,r,a,d){i()||(t.footprint_set_bar(e,n,r,a,d),o())},footprintClear(){i()||(t.footprint_clear(),o())},footprintClearBar(e){i()||t.footprint_clear_bar(e)},footprintPrependEmpty(e){i()||t.footprint_prepend_empty(e)},footprintSetShowSignals(e){i()||(t.footprint_set_show_signals(e),o())},footprintGetShowSignals(){if(i())return!0;try{return t.footprint_get_show_signals()}catch{return!0}},footprintSignalCount(){if(i())return 0;try{return t.footprint_signal_count()}catch{return 0}},footprintSetShowProfile(e){i()||(t.footprint_set_show_profile(e),o())},footprintGetShowProfile(){if(i())return!1;try{return t.footprint_get_show_profile()}catch{return!1}},footprintProfileHitTest(e,n){if(i())return"";try{return t.footprint_profile_hit_test(e,n)}catch{return""}},footprintSetDisplayMode(e){i()||(t.footprint_set_display_mode(e),o())},footprintGetDisplayMode(){if(i())return 0;try{return t.footprint_get_display_mode()}catch{return 0}},enableDeltaHistogram(){i()||t.enable_delta_histogram()},disableDeltaHistogram(){i()||t.disable_delta_histogram()},deltaHistogramEnabled(){if(i())return!1;try{return t.delta_histogram_enabled()}catch{return!1}}}}var Pe=1;function j(t){if(typeof t!="string")return{r:255,g:255,b:255,a:153};if(t.startsWith("#")){let i=t.slice(1);if(i.length===8)return{r:parseInt(i.slice(0,2),16),g:parseInt(i.slice(2,4),16),b:parseInt(i.slice(4,6),16),a:parseInt(i.slice(6,8),16)};let s=parseInt(i.slice(0,2),16),p=parseInt(i.slice(2,4),16),e=parseInt(i.slice(4,6),16);return{r:s,g:p,b:e,a:255}}let o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\)/);return o?{r:+o[1],g:+o[2],b:+o[3],a:o[4]!==void 0?Math.round(+o[4]*255):255}:{r:255,g:255,b:255,a:153}}function yt(t,o,i){let s=new Map,p=null,e=0,n=NaN;function r(){let u;try{u=t.kline_count()}catch{return p}if(u===0)return null;let f=t.kline_closes(),_=f?.[u-1]??NaN;if(p&&!(u!==e||_!==n))return p;try{let h=t.kline_timestamps(),w=t.kline_opens(),m=t.kline_highs(),L=t.kline_lows(),S=t.kline_volumes();if(!h||!f)return p;p={timestamps:Array.from(h),open:Array.from(w),high:Array.from(m),low:Array.from(L),close:Array.from(f),volume:Array.from(S),length:u},e=u,n=_;for(let C of s.values())C._needsCompute=!0}catch{}return p}function a(){return{seriesLine(u,f="#ffffff99",_=1.5){let c=j(f);t.custom_series_line(new Float64Array(u),c.r,c.g,c.b,c.a,_)},seriesDashedLine(u,f="#ffffff66",_=1,c=4,h=4){let w=j(f);t.custom_series_dashed_line(new Float64Array(u),w.r,w.g,w.b,w.a,_,c,h)},band(u,f,_="rgba(100,149,237,0.08)"){let c=j(_);t.custom_band(new Float64Array(u),new Float64Array(f),c.r,c.g,c.b,c.a)},hline(u,f="#ffffff66",_=1){let c=j(f);t.custom_hline(u,c.r,c.g,c.b,c.a,_)},dashedHline(u,f="#ffffff66",_=1,c=6,h=4){let w=j(f);t.custom_dashed_hline(u,w.r,w.g,w.b,w.a,_,c,h)},marker(u,f,_="#e8a04a",c=3){let h=j(_);t.custom_marker(u,f,h.r,h.g,h.b,h.a,c)},markerUp(u,f,_="#26a69a",c=5){let h=j(_);t.custom_marker_up(u,f,h.r,h.g,h.b,h.a,c)},markerDown(u,f,_="#ef5350",c=5){let h=j(_);t.custom_marker_down(u,f,h.r,h.g,h.b,h.a,c)},text(u,f,_,c="#ffffffaa",h=10,w="center"){let m=j(c),L=w==="center"?1:w==="right"?2:0;t.custom_text(u,f,_,m.r,m.g,m.b,m.a,h,L)},priceLabel(u,f,_="#ffffffaa",c=10){let h=j(_);t.custom_price_label(u,f,h.r,h.g,h.b,h.a,c)},linePx(u,f,_,c,h,w=1){let m=j(h);t.custom_line_px(u,f,_,c,m.r,m.g,m.b,m.a,w)},fillRectPx(u,f,_,c,h){let w=j(h);t.custom_fill_rect_px(u,f,_,c,w.r,w.g,w.b,w.a)},strokeRectPx(u,f,_,c,h,w=1){let m=j(h);t.custom_stroke_rect_px(u,f,_,c,m.r,m.g,m.b,m.a,w)},textPx(u,f,_,c,h=10,w="left"){let m=j(c),L=w==="center"?1:w==="right"?2:0;t.custom_text_px(u,f,_,m.r,m.g,m.b,m.a,h,L)},worldToScreenX:u=>t.world_to_screen_x(u),worldToScreenY:u=>t.world_to_screen_y(u),screenToWorldX:u=>t.screen_to_world_x(u),screenToWorldY:u=>t.screen_to_world_y(u),chartArea:()=>({x:t.chart_area_x(),y:t.chart_area_y(),w:t.chart_area_w(),h:t.chart_area_h()})}}function d(u){if(!u.compute)return;let f=r();if(f)try{u._computed=u.compute(f,u.params)||{}}catch(_){console.warn(`[CustomIndicator "${u.name}"] compute error:`,_),u._computed={}}}function l(u){if(s.size===0)return;let f=r();if(!f)return;t.custom_begin();let _=a();for(let h of s.values())if(h.enabled){h._needsCompute&&(d(h),h._needsCompute=!1);try{h.render.call(h,_,h._computed||{},f)}catch(w){console.warn(`[CustomIndicator "${h.name}"] render error:`,w)}}if(t.custom_end(),t.custom_command_count()>0){let h=t.get_custom_buffer_ptr(),w=t.get_custom_buffer_len();i(u,o,h,w)}}function g(){p=null,e=0,n=NaN;for(let u of s.values())u._needsCompute=!0}return{add(u){let f=Pe++,_={id:f,name:u.name||`Custom ${f}`,params:{...u.params},compute:u.compute||null,render:u.render,enabled:!0,_computed:{},_needsCompute:!0};return s.set(f,_),f},remove(u){s.delete(u)},updateParams(u,f){let _=s.get(u);_&&(Object.assign(_.params,f),_._needsCompute=!0)},setEnabled(u,f){let _=s.get(u);_&&(_.enabled=f)},list(){return[...s.values()].map(u=>({id:u.id,name:u.name,params:{...u.params},enabled:u.enabled}))},invalidateCompute:g,renderAll:l}}var oe={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,vpin:!1,stopIceberg:!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,vpin:!1,stopIceberg:!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,vpin:!1,stopIceberg:!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,vpin:!1,stopIceberg:!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,vpin:!0,stopIceberg:!0}},Re={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",vpin:"VPIN",stopIceberg:"Stops & Icebergs"},je={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",vpin:"Enterprise",stopIceberg:"Enterprise"};function et(t){return oe[t]||oe.trial}function Nt(t){let o=et(t),i=new Set;return function(p){if(o[p])return!0;if(!i.has(p)){i.add(p);let e=Re[p]||p,n=je[p]||"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,se="trial",lt="free";var Rt=[95,95,109,114].map(t=>String.fromCharCode(t)).join(""),Ye=1297237059;function le(t){let o=`${t}:${Ye}:${(t^2043453)>>>0}`,i=2166136261;for(let s=0;s<o.length;s++)i^=o.charCodeAt(s),i=Math.imul(i,16777619);return(i>>>0).toString(36)}function ut(t){return`${t}.${le(t)}`}function ft(t){if(!t||typeof t!="string")return null;let o=t.lastIndexOf(".");if(o<1)return null;let i=parseInt(t.slice(0,o),10);return!i||i<1e9||i>2e9||t.slice(o+1)!==le(i)?null:i}var ue=Rt+"e7x",fe=Rt+"p3q",de="mrd_engine_session_id",_e="mrd_ce_db",rt="meta",ce="trial_ts",he=Rt+"ck";function jt(){try{return ft(localStorage.getItem(ue))}catch{return null}}function Ft(t){try{localStorage.setItem(ue,ut(t))}catch{}}function Yt(){try{return ft(localStorage.getItem(fe))}catch{return null}}function zt(t){try{localStorage.setItem(fe,ut(t))}catch{}}function Dt(){try{return ft(sessionStorage.getItem(de))}catch{return null}}function Zt(t){try{sessionStorage.setItem(de,ut(t))}catch{}}function Xt(){try{let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${he}=([^;]+)`));return t?ft(decodeURIComponent(t[1])):null}catch{return null}}function Ht(t){try{let o=encodeURIComponent(ut(t));document.cookie=`${he}=${o};path=/;max-age=${86400*400};SameSite=Lax`}catch{}}var ot=null,ie=!1;function ze(){if(!(ie||typeof indexedDB>"u")){ie=!0;try{let t=indexedDB.open(_e,1);t.onupgradeneeded=()=>{let o=t.result;o.objectStoreNames.contains(rt)||o.createObjectStore(rt)},t.onsuccess=()=>{let s=t.result.transaction(rt,"readonly").objectStore(rt).get(ce);s.onsuccess=()=>{let p=ft(s.result);p&&(!ot||p<ot)&&(ot=p,De(p))}}}catch{}}}function pe(t){ot=t;try{let o=indexedDB.open(_e,1);o.onsuccess=()=>{o.result.transaction(rt,"readwrite").objectStore(rt).put(ut(t),ce)}}catch{}}function De(t){let o=Math.floor(Date.now()/1e3),i=we([jt(),Yt(),Dt(),Xt(),t],o);i&&i!==t||i&&(Ft(i),zt(i),Zt(i),Ht(i))}function we(t,o){let i=null;for(let s of t)s&&(s>o+60||s<17e8||(!i||s<i)&&(i=s));return i}function Ze(){let t=Math.floor(Date.now()/1e3),o=[jt(),Yt(),Dt(),Xt(),ot];return we(o,t)}function Xe(t){Ft(t),zt(t),Zt(t),Ht(t),pe(t)}function He(t){jt()||Ft(t),Yt()||zt(t),Dt()||Zt(t),Xt()||Ht(t),ot||pe(t)}ze();function Mt(t){if(!t||t==="trial")return Oe();try{let o=JSON.parse(atob(t)),{p:i,d:s,e:p,s:e}=o;if(!i||!e)return{valid:!1,error:"Invalid license key format"};let n={...o};if(delete n.s,e!==ge(n))return{valid:!1,error:"Invalid license key signature"};if(p>0&&Date.now()/1e3>p)return{valid:!0,plan:lt,watermark:!0,trialExpired:!0,originalPlan:i,error:`License expired on ${new Date(p*1e3).toLocaleDateString()}`,features:et(lt)};let r=o.pl||"web";if((r==="web"||r==="any")&&s&&s!=="*"&&typeof window<"u"){let a=window.location.hostname;if(a&&a!=="localhost"&&a!=="127.0.0.1"&&a!=="0.0.0.0"&&a!==""&&!s.split(",").map(g=>g.trim()).some(g=>We(g,a)))return{valid:!1,error:`License not valid for domain: ${a}`}}if(r==="mobile"&&o.a&&typeof window<"u"){let a=window.__mrd_app_id;if(a&&a!==o.a)return{valid:!1,error:`License not valid for app: ${a}`}}return{valid:!0,plan:i,domain:s,platform:r,appId:o.a||null,expiry:p,watermark:!1,features:et(i)}}catch{return{valid:!1,error:"Invalid license key"}}}function ge(t){let o="mrd-ce-hmac-2024-x9k2m",i=JSON.stringify(t),s=o+":"+i,p=2166136261,e=1818371886,n=3735928559;for(let r=0;r<s.length;r++){let a=s.charCodeAt(r);p=Math.imul(p^a,16777619)>>>0,e=Math.imul(e^a,1540483477)>>>0,n=Math.imul(n^a,461845907)>>>0}return(p.toString(36)+e.toString(36)+n.toString(36)).slice(0,24)}function Oe(){let t=Ze();t?He(t):(t=Math.floor(Date.now()/1e3),Xe(t));let o=t+Fe*86400,i=Date.now()/1e3,s=Math.max(0,Math.ceil((o-i)/86400));return i>o?{valid:!0,plan:lt,watermark:!0,trialExpired:!0,daysLeft:0,features:et(lt)}:{valid:!0,plan:se,watermark:!0,daysLeft:s,trialEnd:o,features:et(se)}}function We(t,o){if(t==="*"||t===o)return!0;if(t.startsWith("*.")){let i=t.slice(1);return o.endsWith(i)||o===t.slice(2)}return!1}var Ve="MRD-Indicators",ne="mrd-indicators.com",Be="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iMzAiIHZpZXdCb3g9IjAgMCAzMCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtNCk7CiAgICAgIH0KCiAgICAgIC5jbHMtMiB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQtMik7CiAgICAgIH0KCiAgICAgIC5jbHMtMiwgLmNscy0z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DRsLTIuMjMsMS44NGMwLC4wOCwwLC4xNywwLC4yNSwxLjA5LjY1LDIuMzcsMS4wMiwzLjczLDEuMDIsMi42NywwLDUuMDEtMS40Myw2LjI4LTMuNTVaIi8+CiAgICAgICAgPHBhdGggY2xhc3M9ImNscy02IiBkPSJNMjMuNzcsMTAuOTdzMC0uMDMsMC0uMDRjMC0uMDgsMC0uMTYsMC0uMjQsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDYsMC0uMTEtLjAxLS4xNywwLS4wMiwwLS4wNSwwLS4wNywwLS4wNi0uMDEtLjEzLS4wMi0uMTksMC0uMDEsMC0uMDMsMC0uMDQsMC0uMDctLjAyLS4xNC0uMDItLjIxLDAsMCwwLS4wMSwwLS4wMiwwLS4wNy0uMDItLjE1LS4wMy0uMjIsMCwwLDAsMCwwLDAtLjcxLTQuNjctNC43Ny04LjI0LTkuNjYtOC4yNCwyLjA0LDAsMy42OCwxLjY2LDMuNywzLjY5bC4wNCw1LjA2djEuODZzLjAxLjAyLjAxLjAzYzAsMS41Mi0xLjI1LDIuNzYtMi43OCwyLjc3bDUuMDktLjA0YzIuMDUtLjAxLDMuNzItMS42NiwzLjcxLTMuN1oiLz4KICAgICAgPC9nPgogICAgPC9nPgogIDwvZz4KPC9zdmc+",Pt=null,ae=!1;function me(){if(Pt||ae)return Pt;ae=!0;let t=new Image;return t.onload=()=>{Pt=t},t.src=Be,null}function Ge(){return Math.floor(Date.now()/864e5)}function qe(t){let o=(t^2654435769)>>>0;return function(){o=o+1831565813>>>0;let i=Math.imul(o^o>>>15,1|o);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}function Ke(t,o,i,s,p,e){let n=me();t.save(),t.setTransform(1,0,0,1,0,0),t.font="bold 10px Inter, system-ui, sans-serif";let r=t.measureText(s);t.font="8px Inter, system-ui, sans-serif";let a=t.measureText(p),d=n?18:0,l=n?14:0,g=7,u=5,f=n?5:0,c=d+f+Math.max(r.width,a.width)+g*2,h=Math.max(l,20)+u*2,w=Math.round(o-c/2),m=Math.round(i-h/2);t.globalAlpha=.45,t.fillStyle=e?"rgba(255,255,255,0.8)":"rgba(18,18,28,0.8)",t.shadowColor=e?"rgba(0,0,0,0.06)":"rgba(0,0,0,0.25)",t.shadowBlur=8,t.shadowOffsetY=1,t.beginPath(),t.roundRect(w,m,c,h,6),t.fill(),t.shadowColor="transparent",t.strokeStyle=e?"rgba(0,0,0,0.04)":"rgba(255,255,255,0.04)",t.lineWidth=.5,t.stroke();let L=w+g,S=m+h/2;n&&(t.globalAlpha=.5,t.drawImage(n,L,S-l/2,d,l),L+=d+f),t.globalAlpha=.5,t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=e?"#1a1a2e":"#ededf5",t.textAlign="left",t.textBaseline="alphabetic",t.fillText(s,L,S-1),t.font="8px Inter, system-ui, sans-serif",t.fillStyle=e?"#777790":"#8080a0",t.textBaseline="top",t.fillText(p,L,S+2),t.restore()}function Me(t,o,i,s){me();let p=o.width,e=o.height;if(p<100||e<80)return;t.save(),t.setTransform(1,0,0,1,0,0);let n=qe(Ge()),r=100,a=Math.max(p-r*2,60),d=Math.max(e-r*2,40),l=r+n()*a,g=r+n()*d,u=i.trialExpired||i.plan===lt,f=Ve,_=u?`Free \u2014 ${ne}/pricing`:`Trial: ${i.daysLeft||0}d left \u2014 ${ne}`;Ke(t,l,g,f,_,s),t.restore()}function Ue({plan:t,domain:o="*",expiryDays:i=365,name:s,email:p}){let e=i>0?Math.floor(Date.now()/1e3)+i*86400:0,n={p:t,d:o,e,...s?{n:s}:{},...p?{m:p}:{},i:Date.now()};return n.s=ge(n),btoa(JSON.stringify(n))}var Lt=null,Ot=null,dt=null;async function Le(){return Lt||dt||(dt=(async()=>{let t=await import("./chart_engine.js");return await t.default(),Ot=t.wasm_memory(),Lt=t,t})(),dt)}function Qe(){!Lt&&!dt&&Le().catch(()=>{})}async function xe(t,o={}){o.appId&&typeof window<"u"&&(window.__mrd_app_id=o.appId);let i=o.licenseKey||o.key||null,s=Mt(i);if(!s.valid)if(s.expired)console.warn(`[MRD Chart Engine] ${s.error}. Get a license at https://mrd-chart.dev/pricing`);else throw new Error(`[MRD Chart Engine] ${s.error}`);s.plan==="trial"&&console.info(`[MRD Chart Engine] Trial mode \u2014 ${s.daysLeft} days remaining. Purchase: https://mrd-chart.dev/pricing`);let p=await Le(),e=window.devicePixelRatio||1,n=t.getBoundingClientRect();(n.width<1||n.height<1)&&(await new Promise(M=>{let I=new ResizeObserver(A=>{for(let b of A)if(b.contentRect.width>0&&b.contentRect.height>0){I.disconnect(),M();return}});I.observe(t.parentElement||t),setTimeout(()=>{I.disconnect(),M()},2e3)}),n=t.getBoundingClientRect());let r=Math.max(n.width,100),a=Math.max(n.height,100);t.width=r*e,t.height=a*e;let d=t.getContext("2d");d.scale(e,e);let l=new p.ChartEngine(r,a);try{let M=s.expired?2:s.watermark?1:0,I=s.daysLeft||0,A=1297237059;A=Math.imul(A,31)+M>>>0,A=Math.imul(A,31)+I>>>0,A=(A^A>>>16)>>>0,A=Math.imul(A,73244475)>>>0,A=(A^A>>>16)>>>0,l.set_license_state(M,I,A)}catch(M){console.warn("[MRD] set_license_state failed:",M.message)}let g=!0,u=null,f=!1,_=!1,c=!1,h=null,w=null,m=0,L=!1,S=!1,N=("ontouchstart"in window||navigator.maxTouchPoints>0)&&window.innerWidth<=1399?33:0;function U(){if(!(!f||_||u)){if(N>0){let M=performance.now()-m;if(M<N){w||(w=setTimeout(()=>{w=null,U()},N-M));return}}u=requestAnimationFrame(Ce)}}let T=()=>{g=!0,U()},x=()=>c,$=null,_t=null,St=null,E=null,Z=null,W=null,H=null,O=null,st=0,J=null,Wt=null,It=0,Ct=0,k=-1,ct=!1,ht=!1,Se=Et(t,l,{onDirty:T,onCrosshairMove:(M,I,A)=>{It=M,Ct=I,k=A,ct=!0,ht=!0},onCrosshairHide:()=>{ht&&(ht=!1,ct=!0,k=-1)},drawingApi:M=>{$=M},onDrawingComplete:()=>{_t?.()},onDrawingCancel:()=>{St?.()},onDrawingSelected:(M,I,A)=>{E?.(M,I,A)},onMarkerSelected:M=>{Z?.(M)},onDrawingDblClick:(M,I,A,b,At)=>{W?.(M,I,A,b,At)},onVrvpHover:(M,I)=>{H?.(M,I)},onLiqAnnotationPin:(M,I)=>{Wt?.(M,I)}});function Ie(){if(!(!ct||S)){if(ct=!1,!ht){h&&h(null,0,0),O&&O("");return}if(h)if(k===0||k===1)try{let M=l.get_tooltip_data();h(M,It,Ct)}catch{}else h(null,0,0);if(O){let M=performance.now();if(k===0||k===1){if(M-st>=80){st=M;try{O(l.lt_hit_test(It,Ct))}catch{}}}else O("")}}}function Ce(){if(u=null,!(!f||_||S)){L=!0;try{let M=!1;try{M=g||l.is_dirty()}catch{S=!0;return}if(M){g=!1,m=performance.now();let I=!1;try{if(l.render()>0){let b=l.get_command_buffer_ptr(),At=l.get_command_buffer_len();d.save(),d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,t.width,t.height),d.restore(),wt(d,Ot,b,At),I=!0}try{Q.renderAll(d)}catch{}}catch(A){if(I||(g=!0),A instanceof WebAssembly.RuntimeError){S=!0,console.error("[MRD] Engine crashed:",A.message);return}}Ie();try{J?.()}catch{}if(s.watermark)try{let A=l.get_theme()===1;Me(d,t,s,A)}catch{}try{(g||l.is_dirty())&&U()}catch{}}}finally{L=!1}}}let it=Nt(s.plan),Ae=te(l,T,x,()=>it),ve=ee(l,T,x,()=>it),be=re(l,T,x,()=>it),Q=yt(l,Ot,wt);return{engine:l,start(){f=!0,_=!1,g=!0,U()},stop(){f=!1,u&&(cancelAnimationFrame(u),u=null),w&&(clearTimeout(w),w=null)},resize(M){if(S||L)return;if(n=t.getBoundingClientRect(),n.width<1||n.height<1){(M||0)<8&&setTimeout(()=>this.resize((M||0)+1),250);return}e=window.devicePixelRatio||1;let I=n.width*e,A=n.height*e;t.width=I,t.height=A,d.setTransform(1,0,0,1,0,0),d.scale(e,e);try{l.resize(n.width,n.height)}catch(b){if(b instanceof WebAssembly.RuntimeError){S=!0;return}throw b}T()},setHoverPrice(M){l.set_hover_price(M),T()},clearHoverPrice(){l.clear_hover_price(),T()},hitZone(M,I){return l.hit_zone(M,I)},startDrawing(M,I){$?.setMode(M,I)},cancelDrawing(){$?.setMode(null)},onDrawingComplete(M){_t=M},onDrawingCancel(M){St=M},onDrawingSelected(M){E=M},onMarkerSelected(M){Z=M},onDrawingDblClick(M){W=M},setReplayState(M,I,A){l.set_replay_state(M,I,A),T()},setReplayHovered(M){l.set_replay_hovered(M)},setReplayPreview(M){l.set_replay_preview(M),T()},setPrecision(M){l.set_price_precision(M),T()},setCandleInterval(M){l.set_candle_interval(M)},setTheme(M){let I=M==="light"?1:0;typeof l.set_theme=="function"?(l.set_theme(I),T()):console.warn("[ChartEngine] set_theme not available \u2014 reload page to load updated WASM")},getTheme(){return l.get_theme()===1?"light":"dark"},onTooltip(M){h=M},onVrvpHover(M){H=M},onLtHover(M){O=M},onPostRender(M){J=M},onLiqAnnotationPin(M){Wt=M},pause(){_||(_=!0,u&&(cancelAnimationFrame(u),u=null),w&&(clearTimeout(w),w=null))},resume(){_&&(_=!1,f&&(g=!0,U()))},get isPaused(){return _},destroy(){c=!0,f=!1,_=!1,u&&(cancelAnimationFrame(u),u=null),w&&(clearTimeout(w),w=null),Se();try{l.free()}catch{}},addIndicator(M){if(!it("customIndicators"))return null;let I=Q.add(M);return T(),I},removeIndicator(M){Q.remove(M),T()},updateIndicatorParams(M,I){Q.updateParams(M,I),T()},setIndicatorEnabled(M,I){Q.setEnabled(M,I),T()},listIndicators(){return Q.list()},invalidateCustomIndicators(){Q.invalidateCompute(),T()},get license(){return{plan:s.plan,valid:s.valid,expired:!!s.expired,watermark:!!s.watermark,daysLeft:s.daysLeft,features:s.features||{}}},setLicenseKey(M){s=Mt(M),!s.valid&&!s.expired&&console.error(`[MRD Chart Engine] ${s.error}`),it=Nt(s.plan);try{let I=s.expired?2:s.watermark?1:0,A=s.daysLeft||0,b=1297237059;b=Math.imul(b,31)+I>>>0,b=Math.imul(b,31)+A>>>0,b=(b^b>>>16)>>>0,b=Math.imul(b,73244475)>>>0,b=(b^b>>>16)>>>0,l.set_license_state(I,A,b)}catch{}return T(),s.valid},...be,...Ae,...ve}}function $e(t,o){let{t:i,o:s,h:p,l:e,c:n,v:r}=t,a=n.length;if(a===0||o<=0)return{t:[],o:[],h:[],l:[],c:[],v:[]};let d=[],l=[],g=[],u=[],f=[],_=[],c=Math.round(n[0]/o)*o,h=0;for(let w=0;w<a;w++){h+=r[w];let L=n[w]-c;for(;L>=o;){let S=c,C=c+o;d.push(i[w]),l.push(S),g.push(C),u.push(S),f.push(C),_.push(h),h=0,c=C}for(;-L>=o;){let S=c,C=c-o;d.push(i[w]),l.push(S),g.push(S),u.push(C),f.push(C),_.push(h),h=0,c=C}}return{t:d,o:l,h:g,l:u,c:f,v:_}}function Je(t,o){let{t:i,o:s,h:p,l:e,c:n,v:r}=t,a=n.length;if(a===0||o<=0)return{t:[],o:[],h:[],l:[],c:[],v:[]};let d=[],l=[],g=[],u=[],f=[],_=[],c=s[0],h=p[0],w=e[0],m=0,L=i[0];for(let S=0;S<a;S++)for(h=Math.max(h,p[S]),w=Math.min(w,e[S]),m+=r[S];h-w>=o;){let C=n[S]>=c,N=C?w+o:h-o;if(d.push(L),l.push(c),g.push(h),u.push(w),f.push(N),_.push(m),c=N,h=C?Math.max(p[S],N):N,w=C?N:Math.min(e[S],N),m=0,L=i[S],h-w<o)break}return(m>0||d.length===0)&&(d.push(L),l.push(c),g.push(h),u.push(w),f.push(n[a-1]),_.push(m)),{t:d,o:l,h:g,l:u,c:f,v:_}}function ke(t,o){let{t:i,o:s,h:p,l:e,c:n,v:r}=t,a=n.length;if(a===0||o<=0)return{t:[],o:[],h:[],l:[],c:[],v:[]};let d=[],l=[],g=[],u=[],f=[],_=[],c=Math.max(1,Math.round(o));for(let h=0;h<a;h+=c){let w=Math.min(h+c,a),m=-1/0,L=1/0,S=0;for(let C=h;C<w;C++)p[C]>m&&(m=p[C]),e[C]<L&&(L=e[C]),S+=r[C];d.push(i[h]),l.push(s[h]),g.push(m),u.push(L),f.push(n[w-1]),_.push(S)}return{t:d,o:l,h:g,l:u,c:f,v:_}}function tr(t,o){let i=t>1e4?50:t>1e3?10:t>100?1:t>1?.1:.001,s=i*2,p=o<=60?10:o<=300?5:3;return{brickSize:i,rangeSize:s,tickCount:p}}var er={minRefills:3,hiddenRatio:2,refillWindowMs:1e4,maxTrackedLevels:200,maxEvents:500,decayMs:3e5};function rr(t={}){let o={...er,...t},i=new Map,s=new Map,p=[],e=0;function n(u){return Math.round(u*1e8)/1e8}function r(u,f,_,c){for(let[h,w]of u){let m=n(h),L=f.get(m);if(!L){f.set(m,{lastVol:w,refills:0,totalConsumed:0,lastRefillTs:c,peakVisible:w});continue}if(w<L.lastVol*.3&&L.lastVol>0){let S=L.lastVol-w;L.totalConsumed+=S,L.lastVol=w;continue}if(w>L.lastVol*1.5&&L.totalConsumed>0)if(c-L.lastRefillTs<o.refillWindowMs){if(L.refills++,L.lastRefillTs=c,L.peakVisible=Math.max(L.peakVisible,w),L.refills>=o.minRefills){let C=L.totalConsumed,N=L.peakVisible;C>=N*o.hiddenRatio&&(p.push({timestamp:c,price:h,visibleSize:N,hiddenSize:C,isBid:_,refillCount:L.refills}),p.length>o.maxEvents&&p.shift(),L.refills=0,L.totalConsumed=0)}}else L.refills=1,L.totalConsumed=0,L.lastRefillTs=c;L.lastVol=w}if(f.size>o.maxTrackedLevels){let h=[...f.entries()];h.sort((m,L)=>m[1].lastRefillTs-L[1].lastRefillTs);let w=h.length-o.maxTrackedLevels;for(let m=0;m<w;m++)f.delete(h[m][0])}}function a(u,f,_){let c=_||Date.now();e=c;let h=u instanceof Map?u:new Map(u.map(([L,S])=>[L,S])),w=f instanceof Map?f:new Map(f.map(([L,S])=>[L,S]));r(h,i,!0,c),r(w,s,!1,c);let m=c-o.decayMs;for(;p.length>0&&p[0].timestamp<m;)p.shift()}function d(){return p}function l(u){if(!u||p.length===0)return;let f=p.length,_=new Float64Array(f),c=new Float64Array(f),h=new Float64Array(f),w=new Float64Array(f),m=new Uint8Array(f),L=new Uint32Array(f);for(let S=0;S<f;S++){let C=p[S];_[S]=C.timestamp,c[S]=C.price,h[S]=C.visibleSize,w[S]=C.hiddenSize,m[S]=C.isBid?1:0,L[S]=C.refillCount}u.setIcebergEvents(_,c,h,w,m,L)}function g(){i.clear(),s.clear(),p.length=0}return{onOrderbookUpdate:a,getEvents:d,pushToEngine:l,reset:g}}export{Je as buildRange,$e as buildRenko,ke as buildTick,xe as createChartBridge,yt as createCustomIndicatorManager,rr as createIcebergDetector,wt as dispatchCommands,Ue as generateLicenseKey,Qe as prefetchWasm,Et as setupEvents,tr as suggestDefaults,Mt as validateLicense};
|
|
1
|
+
var P={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},Te=["left","center","right"],wt=new Map,Ee=4096;function ye(t,o,i,s){return t<<24|o<<16|i<<8|s}function Y(t,o,i,s){let p=ye(t,o,i,s),e=wt.get(p);return e||(e=`rgba(${t},${o},${i},${(s/255).toFixed(3)})`,wt.size>=Ee&&wt.clear(),wt.set(p,e),e)}var Vt=new TextDecoder;function nt(t,o,i,s){let p=o.buffer;if(i+s>p.byteLength)return;let e=new DataView(p,i,s),n=new Uint8Array(p,i,s),r=0,a="",u="",l=-1,g="";for(;r<s;){let f=n[r];if(r+=1,f===P.END_FRAME)break;switch(f){case P.FILL_RECT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4,w!==a&&(t.fillStyle=w,a=w),t.fillRect(d,_,c,h);break}case P.STROKE_RECT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4,w!==u&&(t.strokeStyle=w,u=w),m!==l&&(t.lineWidth=m,l=m),t.strokeRect(d,_,c,h);break}case P.LINE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==u&&(t.strokeStyle=w,u=w),m!==l&&(t.lineWidth=m,l=m),t.setLineDash([]),t.moveTo(d,_),t.lineTo(c,h),t.stroke();break}case P.DASHED_LINE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4;let L=e.getFloat32(r,!0);r+=4;let S=e.getFloat32(r,!0);r+=4,t.beginPath(),w!==u&&(t.strokeStyle=w,u=w),m!==l&&(t.lineWidth=m,l=m),t.setLineDash([L,S]),t.moveTo(d,_),t.lineTo(c,h),t.stroke(),t.setLineDash([]);break}case P.POLYLINE:{let d=e.getUint16(r,!0);r+=2;let _=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let c=e.getFloat32(r,!0);if(r+=4,d>0){let h=new Float32Array(d*2);for(let w=0;w<d;w++)h[w*2]=e.getFloat32(r,!0),r+=4,h[w*2+1]=e.getFloat32(r,!0),r+=4;if(t.beginPath(),_!==u&&(t.strokeStyle=_,u=_),c!==l&&(t.lineWidth=c,l=c),t.setLineDash([]),t.lineJoin="round",t.lineCap="round",d<=3){t.moveTo(h[0],h[1]);for(let w=1;w<d;w++)t.lineTo(h[w*2],h[w*2+1])}else{t.moveTo(h[0],h[1]),t.lineTo((h[0]+h[2])*.5,(h[1]+h[3])*.5);for(let w=1;w<d-1;w++){let m=h[w*2],L=h[w*2+1],S=h[(w+1)*2],C=h[(w+1)*2+1];t.quadraticCurveTo(m,L,(m+S)*.5,(L+C)*.5)}t.lineTo(h[(d-1)*2],h[(d-1)*2+1])}t.stroke()}break}case P.TEXT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=n[r];r+=1;let m=e.getUint16(r,!0);r+=2;let L=Vt.decode(new Uint8Array(o.buffer,i+r,m));r+=m,c!==a&&(t.fillStyle=c,a=c);let S=`${h}px "IBM Plex Mono",monospace`;S!==g&&(t.font=S,g=S),t.textAlign=Te[w]||"left",t.textBaseline="middle",t.fillText(L,d,_);break}case P.CIRCLE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let w=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let m=e.getFloat32(r,!0);r+=4,t.beginPath(),t.arc(d,_,c,0,Math.PI*2),h!==a&&(t.fillStyle=h,a=h),t.fill(),m>0&&(w!==u&&(t.strokeStyle=w,u=w),m!==l&&(t.lineWidth=m,l=m),t.stroke());break}case P.TRIANGLE:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let m=e.getFloat32(r,!0);r+=4;let L=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4,t.beginPath(),t.moveTo(d,_),t.lineTo(c,h),t.lineTo(w,m),t.closePath(),L!==a&&(t.fillStyle=L,a=L),t.fill();break}case P.SAVE:{t.save();break}case P.RESTORE:{t.restore(),a="",u="",l=-1,g="";break}case P.CLIP_RECT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4,t.beginPath(),t.rect(d,_,c,h),t.clip();break}case P.ROTATED_TEXT:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);r+=4;let m=e.getUint16(r,!0);r+=2;let L=Vt.decode(n.subarray(r,r+m));r+=m;let S=`${h}px sans-serif`;S!==g&&(t.font=S,g=S),c!==a&&(t.fillStyle=c,a=c),t.textAlign="center",t.textBaseline="middle",t.save(),t.translate(d,_),t.rotate(w),t.fillText(L,0,0),t.restore();break}case P.BUBBLE_3D:{let d=e.getFloat32(r,!0);r+=4;let _=e.getFloat32(r,!0);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=n[r],w=n[r+1],m=n[r+2],L=n[r+3];r+=4;let S=n[r],C=n[r+1],N=n[r+2],U=n[r+3];r+=4;let T=n[r],x=n[r+1],$=n[r+2],ct=n[r+3];r+=4;let It=e.getFloat32(r,!0);r+=4;let E=c;if(E<10){let Z=`rgba(${h},${w},${m},${(L/255).toFixed(3)})`;t.beginPath(),t.arc(d,_,E,0,Math.PI*2),t.fillStyle=Z,t.fill(),a=""}else if(E<18){let Z=d-E*.25,W=_-E*.25,H=t.createRadialGradient(Z,W,E*.08,d,_,E);H.addColorStop(0,`rgba(${S},${C},${N},${(U/255).toFixed(3)})`),H.addColorStop(1,`rgba(${h},${w},${m},${(L/255).toFixed(3)})`),t.beginPath(),t.arc(d,_,E,0,Math.PI*2),t.fillStyle=H,t.fill(),a=""}else{let Z=d-E*.25,W=_-E*.25,H=t.createRadialGradient(d,_,E*.85,d,_,E*1.2);H.addColorStop(0,`rgba(${T},${x},${$},${(ct/255*.5).toFixed(3)})`),H.addColorStop(1,`rgba(${T},${x},${$},0)`),t.beginPath(),t.arc(d,_,E*1.2,0,Math.PI*2),t.fillStyle=H,t.fill();let O=t.createRadialGradient(Z,W,E*.08,d,_,E);O.addColorStop(0,`rgba(${S},${C},${N},${(U/255).toFixed(3)})`),O.addColorStop(1,`rgba(${h},${w},${m},${(L/255).toFixed(3)})`),t.beginPath(),t.arc(d,_,E,0,Math.PI*2),t.fillStyle=O,t.fill();let st=E*.2,J=t.createRadialGradient(Z,W,0,Z,W,st);J.addColorStop(0,"rgba(255,255,255,0.22)"),J.addColorStop(1,"rgba(255,255,255,0)"),t.beginPath(),t.arc(Z,W,st,0,Math.PI*2),t.fillStyle=J,t.fill(),a=""}break}case P.FILL_POLYGON:{let d=e.getUint16(r,!0);r+=2;let _=Y(n[r],n[r+1],n[r+2],n[r+3]);if(r+=4,d>2){t.beginPath();let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4,t.moveTo(c,h);for(let w=1;w<d;w++)t.lineTo(e.getFloat32(r,!0),e.getFloat32(r+4,!0)),r+=8;t.closePath(),_!==a&&(t.fillStyle=_,a=_),t.fill()}else r+=d*8;break}case P.DASHED_POLYLINE:{let d=e.getUint16(r,!0);r+=2;let _=Y(n[r],n[r+1],n[r+2],n[r+3]);r+=4;let c=e.getFloat32(r,!0);r+=4;let h=e.getFloat32(r,!0);r+=4;let w=e.getFloat32(r,!0);if(r+=4,d>1){t.beginPath(),_!==u&&(t.strokeStyle=_,u=_),c!==l&&(t.lineWidth=c,l=c),t.setLineDash([h,w]),t.lineJoin="round";let m=e.getFloat32(r,!0);r+=4;let L=e.getFloat32(r,!0);r+=4,t.moveTo(m,L);for(let S=1;S<d;S++)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 z={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 z[t]?.type==="2point"}function lt(t){return z[t]?.type==="3point"}function tt(t){let o=z[t]?.type;return o==="1point"||o==="1point_x"||o==="1point_xy"||o==="1point_xp"}function gt(t){return z[t]?.type==="freehand"}function V(t){return z[t]?.type==="npoint"}function B(t){return z[t]?.type==="elliott_manual"}var Bt={r:.04,g:.49,b:1,lineWidth:2,dashed:!1,fontSize:12};function G(t,o,i,s,p,e){e=e||Bt;let n=z[o];if(!n)return 0;let r=0;return n.type==="3point"?r=t[n.addFn](i.x1,i.y1,i.x2,i.y2,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="2point"?r=t[n.addFn](i.x1,i.y1,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="1point_x"?r=t[n.addFn](s,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="1point_xp"?r=t[n.addFn](s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane):n.type==="1point_xy"?r=t[n.addFn](s,p,e.r,e.g,e.b,e.fontSize||12,i.pane):r=t[n.addFn](p,e.r,e.g,e.b,e.lineWidth,e.dashed,i.pane),r||0}function D(t,o,i,s,p,e,n){e=e||Bt;let r=z[o];if(r){if(r.previewFn==="elliott"){t.set_elliott_preview(s,p,e.r,e.g,e.b,e.lineWidth,n);return}r.type==="3point"?i.step===1?t.set_drawing_preview(r.previewKind,i.x1,i.y1,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n):i.step===2&&(r.previewFn==="fib_ext"?t.set_fib_ext_preview(i.x1,i.y1,i.x2,i.y2,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n):t.set_channel_preview(i.x1,i.y1,i.x2,i.y2,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n)):r.type==="2point"?t.set_drawing_preview(r.previewKind,i.x1,i.y1,s,p,e.r,e.g,e.b,e.lineWidth,e.dashed,n):r.type==="1point_x"?t.set_drawing_preview(r.previewKind,s,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,s,p,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n):t.set_drawing_preview(r.previewKind,0,p,0,0,e.r,e.g,e.b,e.lineWidth,e.dashed,n)}}function v(t,o,i,s){let p=t.screen_to_world_x(o),e;switch(s){case 1:e=t.screen_to_rsi_y(i);break;case 2:e=t.screen_to_oi_y(i);break;case 3:e=t.screen_to_fr_y(i);break;case 4:e=t.screen_to_cvd_y(i);break;case 5:e=t.screen_to_vpin_y(i);break;default:e=t.screen_to_world_y(i);break}return{wx:p,wy:e}}function X(t){return t===4?1:t===6?2:t===8?3:t===10?4:t===12?5:0}function F(t){return t===0||t===4||t===6||t===8||t===10||t===12}function $t(t,o,i,s){t.addEventListener("wheel",r=>{if(s.disposed)return;r.preventDefault(),s.cancelMomentum();let a=r.deltaY>0?1.1:.9,u=o.hit_zone(r.offsetX,r.offsetY);r.ctrlKey?o.zoom_y(r.offsetY,a):r.shiftKey||u===2?o.zoom_x(r.offsetX,a):u===3?o.zoom_y(r.offsetY,a):o.zoom(r.offsetX,r.offsetY,a),i.onDirty()},{passive:!1}),t.addEventListener("mousedown",r=>{if(s.disposed||r.button!==0)return;s.cancelMomentum(),e();let a=performance.now();if(a-s.lastClickTime<300){s.lastClickTime=a;return}s.lastClickTime=a;let u=s.drawingMode;if(u){let g=o.hit_zone(r.offsetX,r.offsetY);if(!F(g))return;let f=X(g),{wx:d,wy:_}=v(o,r.offsetX,r.offsetY,f),c=u.style,h=u.tool;if(B(h)){if(!u.pathStarted)u.pane=f,o.start_elliott_manual(c.r,c.g,c.b,c.lineWidth,f),o.add_elliott_manual_point(d,_),u.pathStarted=!0,u.step=1;else if(o.add_elliott_manual_point(d,_)){s.finishDrawing(),i.onDirty();return}}else if(V(h))u.pathStarted?o.add_path_point(d,_):(u.pane=f,o.start_path(c.r,c.g,c.b,c.lineWidth,c.dashed,f),o.add_path_point(d,_),u.pathStarted=!0,u.step=1);else if(gt(h))u.pane=f,o.start_brush(c.r,c.g,c.b,c.lineWidth,f),o.add_brush_point(d,_),s.isBrushing=!0;else if(lt(h))if(u.step===0)u.x1=d,u.y1=_,u.pane=f,u.step=1;else if(u.step===1)u.x2=d,u.y2=_,u.step=2,o.clear_drawing_preview();else{let w=z[h];w&&w.previewFn==="fib_ext"?o.clear_fib_ext_preview():o.clear_channel_preview(),G(o,h,u,d,_,c),s.finishDrawing()}else if(at(h))u.step===0?(u.x1=d,u.y1=_,u.pane=f,u.step=1):(G(o,h,u,d,_,c),s.finishDrawing());else{u.pane=f;let w=G(o,h,u,d,_,c);s.finishDrawing(),h==="textnote"&&w>0&&(o.select_drawing(w),i.onDrawingSelected?.(w),i.onDrawingDblClick?.(w,r.offsetX,r.offsetY,r.clientX,r.clientY))}i.onDirty();return}let l=o.hit_zone(r.offsetX,r.offsetY);if(l===5){s.isResizingRsi=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_rsi_ratio(),t.style.cursor="ns-resize";return}if(l===7){s.isResizingOi=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_oi_ratio(),t.style.cursor="ns-resize";return}if(l===9){s.isResizingFr=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_fr_ratio(),t.style.cursor="ns-resize";return}if(l===11){s.isResizingCvd=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_cvd_ratio(),t.style.cursor="ns-resize";return}if(l===13){s.isResizingVpin=!0,s.resizeStartY=r.offsetY,s.resizeStartRatio=o.get_vpin_ratio(),t.style.cursor="ns-resize";return}if(F(l)){let g=o.get_selected_drawing();if(g>0){let h=o.hit_test_drawing_anchor(r.offsetX,r.offsetY);if(h>=0){s.isDraggingAnchor=!0,s.dragAnchorIdx=h,s.dragAnchorPane=X(l),t.style.cursor="grabbing";return}if(o.hit_test_drawing(r.offsetX,r.offsetY)===g){s.isDraggingDrawing=!0,s.dragDrawingPane=X(l);let{wx:m,wy:L}=v(o,r.offsetX,r.offsetY,s.dragDrawingPane);s.dragDrawingLastWx=m,s.dragDrawingLastWy=L,t.style.cursor="move";return}}let f=o.hit_test_drawing(r.offsetX,r.offsetY);if(f>0){o.deselect_marker(),i.onMarkerSelected?.(0),o.select_drawing(f),i.onDrawingSelected?.(f),i.onDirty();return}let d=o.hit_test_marker(r.offsetX,r.offsetY);if(d>0){o.deselect_drawing(),i.onDrawingSelected?.(0),o.select_marker(d),i.onMarkerSelected?.(d),i.onDirty();return}let _=o.get_selected_drawing(),c=o.get_selected_marker();_>0&&(o.deselect_drawing(),i.onDrawingSelected?.(0),i.onDirty()),c>0&&(o.deselect_marker(),i.onMarkerSelected?.(0),i.onDirty())}F(l)&&(s.liqPinSx=r.offsetX,s.liqPinSy=r.offsetY,s.liqPinTimer&&clearTimeout(s.liqPinTimer),s.liqPinTimer=setTimeout(()=>{s.liqPinTimer=null,i.onLiqAnnotationPin?.(s.liqPinSx,s.liqPinSy)},700)),s.isDragging=!0,s.dragZone=l,s.lastX=r.offsetX,s.lastY=r.offsetY,l===2?t.style.cursor="ew-resize":l===3?t.style.cursor="ns-resize":t.style.cursor="grabbing"});let p=null;function e(){p&&(cancelAnimationFrame(p),p=null)}function n(r,a){let u=o.hover_hit_test(r,a),l=u[0],g=u[1],f=u[2],d=u[3],_=u[4],c=s.drawingMode;l===2?(t.style.cursor="ew-resize",o.hide_crosshair()):l===3?(t.style.cursor="ns-resize",o.hide_crosshair()):(o.set_crosshair(r,a),l===5||l===7||l===9||l===11||l===13?t.style.cursor="ns-resize":!c&&F(l)&&g>0&&f>=0?t.style.cursor="grab":!c&&F(l)&&g>0&&d===g?t.style.cursor="move":!c&&F(l)&&(d>0||_>0)?t.style.cursor="pointer":t.style.cursor="crosshair"),i.onDirty(),i.onCrosshairMove?.(r,a,l),i.onVrvpHover?.(r,a)}t.addEventListener("mousemove",r=>{if(s.disposed)return;if(s.liqPinTimer){let u=Math.abs(r.offsetX-s.liqPinSx),l=Math.abs(r.offsetY-s.liqPinSy);(u>6||l>6)&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null)}if(s.isResizingRsi){let l=t.getBoundingClientRect().height-28,f=(s.resizeStartY-r.offsetY)/l,d=Math.max(.05,Math.min(.5,s.resizeStartRatio+f));o.set_rsi_ratio(d),i.onDirty();return}if(s.isResizingOi){let l=t.getBoundingClientRect().height-28,f=(s.resizeStartY-r.offsetY)/l,d=Math.max(.05,Math.min(.5,s.resizeStartRatio+f));o.set_oi_ratio(d),i.onDirty();return}if(s.isResizingFr){let l=t.getBoundingClientRect().height-28,f=(s.resizeStartY-r.offsetY)/l,d=Math.max(.05,Math.min(.5,s.resizeStartRatio+f));o.set_fr_ratio(d),i.onDirty();return}if(s.isResizingCvd){let l=t.getBoundingClientRect().height-28,f=(s.resizeStartY-r.offsetY)/l,d=Math.max(.05,Math.min(.5,s.resizeStartRatio+f));o.set_cvd_ratio(d),i.onDirty();return}if(s.isResizingVpin){let l=t.getBoundingClientRect().height-28,f=(s.resizeStartY-r.offsetY)/l,d=Math.max(.05,Math.min(.5,s.resizeStartRatio+f));o.set_vpin_ratio(d),i.onDirty();return}if(s.isDraggingAnchor){let{wx:u,wy:l}=v(o,r.offsetX,r.offsetY,s.dragAnchorPane);o.update_drawing_anchor(s.dragAnchorIdx,u,l),o.set_crosshair(r.offsetX,r.offsetY),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,o.hit_zone(r.offsetX,r.offsetY));return}if(s.isDraggingDrawing){let{wx:u,wy:l}=v(o,r.offsetX,r.offsetY,s.dragDrawingPane),g=u-s.dragDrawingLastWx,f=l-s.dragDrawingLastWy;o.move_drawing(g,f),s.dragDrawingLastWx=u,s.dragDrawingLastWy=l,o.set_crosshair(r.offsetX,r.offsetY),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,o.hit_zone(r.offsetX,r.offsetY));return}let a=s.drawingMode;if(s.isBrushing&&a){let u=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,u);o.add_brush_point(l,g),o.set_crosshair(r.offsetX,r.offsetY),i.onDirty();return}if(a&&B(a.tool)&&a.pathStarted){let u=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,u);o.set_elliott_manual_cursor(l,g),o.set_crosshair(r.offsetX,r.offsetY);let f=o.hit_zone(r.offsetX,r.offsetY);i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(a&&V(a.tool)&&a.pathStarted){let u=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,u);o.set_path_cursor(l,g),o.set_crosshair(r.offsetX,r.offsetY);let f=o.hit_zone(r.offsetX,r.offsetY);i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(a&&a.step>0){let u=a.pane||0,{wx:l,wy:g}=v(o,r.offsetX,r.offsetY,u);D(o,a.tool,a,l,g,a.style,u),o.set_crosshair(r.offsetX,r.offsetY);let f=o.hit_zone(r.offsetX,r.offsetY);i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,f);return}if(a&&tt(a.tool)){let u=o.hit_zone(r.offsetX,r.offsetY),l=X(u),{wx:g,wy:f}=v(o,r.offsetX,r.offsetY,l);D(o,a.tool,a,g,f,a.style,l),o.set_crosshair(r.offsetX,r.offsetY),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,u);return}if(s.isDragging){let u=r.offsetX-s.lastX,l=r.offsetY-s.lastY;s.lastX=r.offsetX,s.lastY=r.offsetY,s.dragZone===2?o.pan_x(u):s.dragZone===3?o.pan_y(l):o.pan(u,l),i.onDirty(),i.onCrosshairMove?.(r.offsetX,r.offsetY,s.dragZone),i.onVrvpHover?.(r.offsetX,r.offsetY);return}s._pendingHoverX=r.offsetX,s._pendingHoverY=r.offsetY,p||(p=requestAnimationFrame(()=>{p=null,s.disposed||n(s._pendingHoverX,s._pendingHoverY)}))}),t.addEventListener("mouseup",()=>{s.disposed||(s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null),s.isBrushing&&(s.isBrushing=!1,o.finish_brush(),s.finishDrawing(),i.onDirty()),s.isDragging=!1,s.isResizingRsi=!1,s.isResizingOi=!1,s.isResizingFr=!1,s.isResizingCvd=!1,s.isResizingVpin=!1,s.isDraggingAnchor=!1,s.isDraggingDrawing=!1,s.dragAnchorIdx=-1,t.style.cursor="crosshair")}),t.addEventListener("mouseleave",()=>{s.disposed||(e(),s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null),s.isBrushing&&(s.isBrushing=!1,o.finish_brush(),s.finishDrawing()),s.isDragging=!1,s.isResizingRsi=!1,s.isResizingOi=!1,s.isResizingFr=!1,s.isResizingCvd=!1,s.isResizingVpin=!1,s.isDraggingAnchor=!1,s.isDraggingDrawing=!1,s.dragAnchorIdx=-1,o.hide_crosshair(),t.style.cursor="crosshair",i.onDirty(),i.onCrosshairHide?.(),i.onVrvpHover?.(null,null))}),t.addEventListener("dblclick",r=>{if(s.disposed)return;r.preventDefault(),r.stopPropagation();let a=s.drawingMode;if(a&&B(a.tool)&&a.pathStarted){o.finish_elliott_manual(),s.finishDrawing(),i.onDirty();return}if(a&&V(a.tool)&&a.pathStarted){o.finish_path(),s.finishDrawing(),i.onDirty();return}if(a)return;let u=o.hit_test_drawing(r.offsetX,r.offsetY);u>0&&(o.select_drawing(u),i.onDirty(),i.onDrawingDblClick?.(u,r.offsetX,r.offsetY,r.clientX,r.clientY))}),t.addEventListener("contextmenu",r=>{if(s.disposed)return;let a=s.drawingMode;if(a&&B(a.tool)&&a.pathStarted){r.preventDefault(),r.stopPropagation(),o.finish_elliott_manual(),s.finishDrawing(),i.onDirty();return}if(a&&V(a.tool)&&a.pathStarted){r.preventDefault(),r.stopPropagation(),o.finish_path(),s.finishDrawing(),i.onDirty();return}})}function Jt(t,o,i,s){t.addEventListener("touchstart",p=>{if(!s.disposed){if(p.preventDefault(),s.cancelMomentum(),p.touches.length===2){clearTimeout(s.longPressTimer),s.isCrosshairMode=!1;let e=t.getBoundingClientRect(),n=p.touches[1].clientX-p.touches[0].clientX,r=p.touches[1].clientY-p.touches[0].clientY;s.lastTouchDist=Math.sqrt(n*n+r*r),s.lastX=(p.touches[0].clientX+p.touches[1].clientX)/2-e.left,s.lastY=(p.touches[0].clientY+p.touches[1].clientY)/2-e.top,s.dragZone=o.hit_zone(s.lastX,s.lastY)}else if(p.touches.length===1){let e=t.getBoundingClientRect(),n=p.touches[0].clientX-e.left,r=p.touches[0].clientY-e.top;s.touchStartX=n,s.touchStartY=r,s.touchMoved=!1;let a=s.drawingMode;if(a){let d=o.hit_zone(n,r);if(F(d)){let _=X(d),{wx:c,wy:h}=v(o,n,r,_),w=a.tool;if(B(w)){if(!a.pathStarted)a.pane=_,o.start_elliott_manual(a.style.r,a.style.g,a.style.b,a.style.lineWidth,_),o.add_elliott_manual_point(c,h),a.pathStarted=!0,a.step=1;else if(o.add_elliott_manual_point(c,h)){s.finishDrawing(),i.onDirty();return}}else V(w)?a.pathStarted?o.add_path_point(c,h):(a.pane=_,o.start_path(a.style.r,a.style.g,a.style.b,a.style.lineWidth,a.style.dashed,_),o.add_path_point(c,h),a.pathStarted=!0,a.step=1):gt(w)?(a.pane=_,o.start_brush(a.style.r,a.style.g,a.style.b,a.style.lineWidth,_),o.add_brush_point(c,h),s.isBrushing=!0):lt(w)?a.step===0?(a.x1=c,a.y1=h,a.pane=_,a.step=1,a._stepAtTouchStart=0,D(o,w,a,c,h,a.style,_)):a.step===1?(a._stepAtTouchStart=1,D(o,w,a,c,h,a.style,a.pane)):(a._stepAtTouchStart=2,D(o,w,a,c,h,a.style,a.pane)):at(w)?a.step===0?(a.x1=c,a.y1=h,a.pane=_,a.step=1,a._stepAtTouchStart=0,D(o,w,a,c,h,a.style,_)):(a._stepAtTouchStart=1,D(o,w,a,c,h,a.style,a.pane)):tt(w)?(a.pane=_,D(o,w,a,c,h,a.style,_)):(a.pane=_,G(o,w,a,c,h,a.style),s.finishDrawing());o.set_crosshair(n,r),i.onDirty(),i.onCrosshairMove?.(n,r,d)}return}let u=o.hover_hit_test(n,r),l=u[0],g=u[1],f=u[2];if(F(l)&&!s.drawingMode&&g>0){if(f>=0){s.isDraggingAnchor=!0,s.dragAnchorIdx=f,s.dragAnchorPane=X(l);return}if(u[3]===g){s.isDraggingDrawing=!0,s.dragDrawingPane=X(l);let{wx:_,wy:c}=v(o,n,r,s.dragDrawingPane);s.dragDrawingLastWx=_,s.dragDrawingLastWy=c;return}}s.isDragging=!0,s.isCrosshairMode=!1,s.lastX=n,s.lastY=r,s.dragZone=l,clearTimeout(s.longPressTimer),s.longPressTimer=setTimeout(()=>{s.isDragging&&!s.touchMoved&&(s.isCrosshairMode=!0,o.set_crosshair(n,r),i.onDirty(),i.onCrosshairMove?.(n,r,s.dragZone),i.onVrvpHover?.(n,r))},300),F(s.dragZone)&&(s.liqPinSx=n,s.liqPinSy=r,s.liqPinTimer&&clearTimeout(s.liqPinTimer),s.liqPinTimer=setTimeout(()=>{s.liqPinTimer=null,s.touchMoved||i.onLiqAnnotationPin?.(s.liqPinSx,s.liqPinSy)},700))}}},{passive:!1}),t.addEventListener("touchmove",p=>{if(s.disposed)return;p.preventDefault();let e=t.getBoundingClientRect();if(s.isDraggingAnchor&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,{wx:u,wy:l}=v(o,r,a,s.dragAnchorPane);o.update_drawing_anchor(s.dragAnchorIdx,u,l),o.set_crosshair(r,a),i.onDirty();return}if(s.isDraggingDrawing&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top;s.touchMoved=!0;let{wx:u,wy:l}=v(o,r,a,s.dragDrawingPane),g=u-s.dragDrawingLastWx,f=l-s.dragDrawingLastWy;o.move_drawing(g,f),s.dragDrawingLastWx=u,s.dragDrawingLastWy=l,o.set_crosshair(r,a),i.onDirty();return}let n=s.drawingMode;if(s.isBrushing&&n&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,u=n.pane||0,{wx:l,wy:g}=v(o,r,a,u);o.add_brush_point(l,g),o.set_crosshair(r,a),i.onDirty(),s.touchMoved=!0;return}if(n&&B(n.tool)&&n.pathStarted&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,u=n.pane||0,{wx:l,wy:g}=v(o,r,a,u);o.set_elliott_manual_cursor(l,g),o.set_crosshair(r,a),i.onDirty(),s.touchMoved=!0;return}if(n&&V(n.tool)&&n.pathStarted&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,u=n.pane||0,{wx:l,wy:g}=v(o,r,a,u);o.set_path_cursor(l,g),o.set_crosshair(r,a),i.onDirty(),s.touchMoved=!0;return}if(n&&n.step>0&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top;!s.touchMoved&&(Math.abs(r-s.touchStartX)>10||Math.abs(a-s.touchStartY)>10)&&(s.touchMoved=!0);let u=n.pane||0,{wx:l,wy:g}=v(o,r,a,u);D(o,n.tool,n,l,g,n.style,u),o.set_crosshair(r,a);let f=o.hit_zone(r,a);i.onDirty(),i.onCrosshairMove?.(r,a,f);return}if(n&&tt(n.tool)&&p.touches.length===1){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,u=o.hit_zone(r,a),l=X(u),{wx:g,wy:f}=v(o,r,a,l);D(o,n.tool,n,g,f,n.style,l),o.set_crosshair(r,a),i.onDirty(),i.onCrosshairMove?.(r,a,u);return}if(p.touches.length===2){s.velSamples=[];let r=p.touches[1].clientX-p.touches[0].clientX,a=p.touches[1].clientY-p.touches[0].clientY,u=Math.sqrt(r*r+a*a),l=s.lastTouchDist/u,g=(p.touches[0].clientX+p.touches[1].clientX)/2-e.left,f=(p.touches[0].clientY+p.touches[1].clientY)/2-e.top;s.dragZone===3?o.zoom_y(f,l):s.dragZone===2?o.zoom_x(g,l):(o.zoom(g,f,l),o.pan(g-s.lastX,f-s.lastY)),s.lastTouchDist=u,s.lastX=g,s.lastY=f,i.onDirty()}else if(p.touches.length===1&&s.isDragging){let r=p.touches[0].clientX-e.left,a=p.touches[0].clientY-e.top,u=r-s.lastX,l=a-s.lastY;!s.touchMoved&&(Math.abs(r-s.touchStartX)>10||Math.abs(a-s.touchStartY)>10)&&(s.touchMoved=!0,s.isCrosshairMode||clearTimeout(s.longPressTimer),s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null)),s.isCrosshairMode?(o.set_crosshair(r,a),i.onDirty(),i.onCrosshairMove?.(r,a,s.dragZone),i.onVrvpHover?.(r,a)):(s.lastX=r,s.lastY=a,s.recordVelocity(u,l),s.dragZone===2?o.pan_x(u):s.dragZone===3?o.pan_y(l):o.pan(u,l),i.onDirty())}},{passive:!1}),t.addEventListener("touchend",p=>{if(s.disposed)return;if(clearTimeout(s.longPressTimer),s.liqPinTimer&&(clearTimeout(s.liqPinTimer),s.liqPinTimer=null),s.isDraggingAnchor){s.isDraggingAnchor=!1,s.dragAnchorIdx=-1,o.hide_crosshair(),i.onDirty(),i.onCrosshairHide?.();return}if(s.isDraggingDrawing){if(s.isDraggingDrawing=!1,o.hide_crosshair(),i.onDirty(),i.onCrosshairHide?.(),!s.touchMoved){let n=o.get_selected_drawing();if(n>0){let r=t.getBoundingClientRect();i.onDrawingDblClick?.(n,s.touchStartX,s.touchStartY,s.touchStartX+r.left,s.touchStartY+r.top)}}return}if(s.isBrushing){s.isBrushing=!1,o.finish_brush(),s.finishDrawing(),i.onDirty(),i.onCrosshairHide?.();return}let e=s.drawingMode;if(e&&B(e.tool)&&e.pathStarted){let n=Date.now(),r=s.touchStartX-(s._pathLastTapX||0),a=s.touchStartY-(s._pathLastTapY||0),u=Math.sqrt(r*r+a*a);n-(s._pathLastTapTime||0)<350&&u<30?(o.finish_elliott_manual(),s.finishDrawing(),s._pathLastTapTime=0):(s._pathLastTapTime=n,s._pathLastTapX=s.touchStartX,s._pathLastTapY=s.touchStartY),s.isDragging=!1,s.lastTouchDist=0,i.onDirty();return}if(e&&V(e.tool)&&e.pathStarted){let n=Date.now(),r=s.touchStartX-(s._pathLastTapX||0),a=s.touchStartY-(s._pathLastTapY||0),u=Math.sqrt(r*r+a*a);n-(s._pathLastTapTime||0)<350&&u<30?(o.finish_path(),s.finishDrawing(),s._pathLastTapTime=0):(s._pathLastTapTime=n,s._pathLastTapX=s.touchStartX,s._pathLastTapY=s.touchStartY),s.isDragging=!1,s.lastTouchDist=0,i.onDirty();return}if(e&<(e.tool)){let n=e._stepAtTouchStart;if(e.step===1&&(n===1||s.touchMoved)){let r=t.getBoundingClientRect(),a=p.changedTouches?.[0];if(a){let u=a.clientX-r.left,l=a.clientY-r.top,g=e.pane||0,{wx:f,wy:d}=v(o,u,l,g);e.x2=f,e.y2=d,e.step=2,o.clear_drawing_preview()}}else if(e.step===2&&(n===2||s.touchMoved)){let r=t.getBoundingClientRect(),a=p.changedTouches?.[0];if(a){let u=a.clientX-r.left,l=a.clientY-r.top,g=e.pane||0,{wx:f,wy:d}=v(o,u,l,g),_=z[e.tool];_&&_.previewFn==="fib_ext"?o.clear_fib_ext_preview():o.clear_channel_preview(),G(o,e.tool,e,f,d,e.style),s.finishDrawing()}}s.isDragging=!1,s.lastTouchDist=0,s.drawingMode||(o.hide_crosshair(),i.onCrosshairHide?.()),i.onDirty();return}if(e&&e.step===1&&at(e.tool)){if(e._stepAtTouchStart===1||s.touchMoved){let r=t.getBoundingClientRect(),a=p.changedTouches?.[0];if(a){let u=a.clientX-r.left,l=a.clientY-r.top,g=e.pane||0,{wx:f,wy:d}=v(o,u,l,g);G(o,e.tool,e,f,d,e.style),s.finishDrawing()}}s.isDragging=!1,s.lastTouchDist=0,s.drawingMode||(o.hide_crosshair(),i.onCrosshairHide?.()),i.onDirty();return}if(e&&tt(e.tool)){let n=t.getBoundingClientRect(),r=p.changedTouches?.[0];if(r){let a=r.clientX-n.left,u=r.clientY-n.top,l=o.hit_zone(a,u),g=F(l)?X(l):e.pane||0,{wx:f,wy:d}=v(o,a,u,g),_=e.tool;o.clear_drawing_preview();let c=G(o,_,e,f,d,e.style);s.finishDrawing(),_==="textnote"&&c>0&&(o.select_drawing(c),i.onDrawingSelected?.(c),i.onDrawingDblClick?.(c,a,u,a+n.left,u+n.top))}s.isDragging=!1,s.lastTouchDist=0,o.hide_crosshair(),i.onCrosshairHide?.(),i.onDirty();return}if(!s.touchMoved&&!s.drawingMode&&s.isDragging){let n=Date.now(),r=s.touchStartX-s.lastTapX,a=s.touchStartY-s.lastTapY,u=Math.sqrt(r*r+a*a),l=n-s.lastTapTime<350&&u<30,g=o.hover_hit_test(s.touchStartX,s.touchStartY),f=g[0],d=g[1],_=g[3],c=g[4];if(F(f))if(_>0){o.deselect_marker(),i.onMarkerSelected?.(0),o.select_drawing(_);let h=t.getBoundingClientRect(),w=s.touchStartX+h.left,m=s.touchStartY+h.top;i.onDrawingSelected?.(_,w,m),(d<=0||d===_)&&i.onDrawingDblClick?.(_,s.touchStartX,s.touchStartY,w,m),i.onDirty()}else c>0?(o.deselect_drawing(),i.onDrawingSelected?.(0),o.select_marker(c),i.onMarkerSelected?.(c),i.onDirty()):(d>0&&(o.deselect_drawing(),i.onDrawingSelected?.(0),i.onDirty()),o.get_selected_marker()>0&&(o.deselect_marker(),i.onMarkerSelected?.(0),i.onDirty()));s.lastTapTime=n,s.lastTapX=s.touchStartX,s.lastTapY=s.touchStartY}s.touchMoved&&!s.isCrosshairMode&&!s.drawingMode&&s.startMomentum(s.dragZone),s.isDragging=!1,s.isCrosshairMode=!1,s.lastTouchDist=0,(!s.drawingMode||s.drawingMode.step===0)&&(o.hide_crosshair(),i.onCrosshairHide?.()),i.onDirty(),i.onVrvpHover?.(null,null)})}function yt(t,o,i){let s={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},p=.92,e=.5,n=80;s.recordVelocity=function(l,g){let f=performance.now();for(s.velSamples.push({dx:l,dy:g,t:f});s.velSamples.length>0&&f-s.velSamples[0].t>n;)s.velSamples.shift()};function r(){if(s.velSamples.length<2)return{vx:0,vy:0};let l=s.velSamples[0],f=s.velSamples[s.velSamples.length-1].t-l.t;if(f<5)return{vx:0,vy:0};let d=0,_=0;for(let h of s.velSamples)d+=h.dx,_+=h.dy;let c=16.67;return{vx:d/f*c,vy:_/f*c}}s.cancelMomentum=function(){s.momentumRaf&&(cancelAnimationFrame(s.momentumRaf),s.momentumRaf=null),s.velSamples=[]},s.startMomentum=function(l){let{vx:g,vy:f}=r();if(s.velSamples=[],Math.abs(g)<e&&Math.abs(f)<e)return;s.momentumVx=g,s.momentumVy=f,s.momentumZone=l;function d(){if(s.momentumVx*=p,s.momentumVy*=p,Math.abs(s.momentumVx)<e&&Math.abs(s.momentumVy)<e){s.momentumRaf=null;return}s.momentumZone===2?o.pan_x(s.momentumVx):s.momentumZone===3?o.pan_y(s.momentumVy):o.pan(s.momentumVx,s.momentumVy),i.onDirty(),s.momentumRaf=requestAnimationFrame(d)}s.momentumRaf=requestAnimationFrame(d)};let a={setMode(l,g){l?(s.drawingMode={tool:l,style:g,step:0,x1:0,y1:0},t.style.cursor="crosshair"):(s.drawingMode?.pathStarted&&o.finish_path(),s.drawingMode=null,o.clear_drawing_preview(),t.style.cursor="crosshair"),i.onDirty()},getMode(){return s.drawingMode}};i.drawingApi?.(a),s.finishDrawing=function(){o.clear_drawing_preview(),i.onDrawingComplete?.(),s.drawingMode=null,t.style.cursor="crosshair"},$t(t,o,i,s),Jt(t,o,i,s);let u=l=>{let g=document.activeElement?.tagName,f=g==="INPUT"||g==="TEXTAREA"||document.activeElement?.isContentEditable;if((l.key==="Delete"||l.key==="Backspace")&&!s.drawingMode&&!f){let _=o.get_selected_drawing();if(_>0){o.remove_drawing(_),i.onDrawingSelected?.(0),i.onDirty();return}let c=o.get_selected_marker();if(c>0){o.remove_marker(c),i.onMarkerSelected?.(0),i.onDirty();return}}if(l.key==="Escape"&&!s.drawingMode){if(o.get_selected_drawing()>0){o.deselect_drawing(),i.onDrawingSelected?.(0),i.onDirty();return}if(o.get_selected_marker()>0){o.deselect_marker(),i.onMarkerSelected?.(0),i.onDirty();return}}if(l.key==="Escape"&&s.drawingMode){if(s.drawingMode.pathStarted){s.drawingMode.tool==="elliott"?o.finish_elliott_manual():o.finish_path(),s.finishDrawing(),i.onDirty();return}o.clear_drawing_preview(),s.drawingMode=null,t.style.cursor="crosshair",i.onDrawingCancel?.(),i.onDirty();return}let d=20;switch(l.key){case"+":case"=":o.zoom(t.width/2,t.height/2,.9);break;case"-":o.zoom(t.width/2,t.height/2,1.1);break;case"ArrowLeft":o.pan_x(d);break;case"ArrowRight":o.pan_x(-d);break;case"ArrowUp":o.pan_y(-d);break;case"ArrowDown":o.pan_y(d);break;case"r":case"R":o.auto_scale_y();break;default:return}i.onDirty()};return window.addEventListener("keydown",u),()=>{s.disposed=!0,s.cancelMomentum(),window.removeEventListener("keydown",u)}}function te(t,o,i,s){let p=e=>s()(e);return{enableRsi(){t.enable_rsi(),o()},disableRsi(){t.disable_rsi(),o()},setRsiPeriod(e){t.set_rsi_period(e),o()},isRsiEnabled(){return t.is_rsi_enabled()},setRsiShowEma(e){t.set_rsi_show_ema(e),o()},setRsiShowWma(e){t.set_rsi_show_wma(e),o()},setRsiShowSignals(e){t.set_rsi_show_signals(e),o()},setRsiShowDivergence(e){t.set_rsi_show_divergence(e),o()},setRsiShowTraps(e){t.set_rsi_show_traps(e),o()},setRsiSmoothing(e){t.set_rsi_smoothing(e),o()},setRsiRatio(e){t.set_rsi_ratio(e),o()},getRsiRatio(){return t.get_rsi_ratio()},enableForexSignals(){p("forexSignals")&&(t.enable_forex_signals(),o())},disableForexSignals(){t.disable_forex_signals(),o()},isForexSignalsEnabled(){return t.is_forex_signals_enabled()},setForexSignalsSetup(e){t.set_forex_signals_setup(e),o()},setForexSignalsMode(e){t.set_forex_signals_mode(e),o()},setForexSignalsShowStats(e){t.set_forex_signals_show_stats(e),o()},getForexSignalsCount(){return t.get_forex_signals_count()},enableOi(){i()||p("oi")&&(t.enable_oi(),o())},disableOi(){i()||(t.disable_oi(),o())},isOiEnabled(){if(i())return!1;try{return t.is_oi_enabled()}catch{return!1}},setOiData(e){i()||(t.set_oi_data(e),o())},setOiDataTs(e,n){i()||(t.set_oi_data_ts(e,n),o())},setOiShowOnChart(e){i()||(t.set_oi_show_on_chart(e),o())},setOiDisplayMode(e){i()||(t.set_oi_display_mode(e),o())},setOiRatio(e){i()||(t.set_oi_ratio(e),o())},getOiRatio(){if(i())return .2;try{return t.get_oi_ratio()}catch{return .2}},enableFundingRate(){i()||p("fundingRate")&&(t.enable_funding_rate(),o())},disableFundingRate(){i()||(t.disable_funding_rate(),o())},isFundingRateEnabled(){if(i())return!1;try{return t.is_funding_rate_enabled()}catch{return!1}},setFrBinanceData(e,n){i()||(t.set_fr_binance_data(e,n),o())},setFrAggData(e,n){i()||(t.set_fr_agg_data(e,n),o())},setFrShowAgg(e){i()||(t.set_fr_show_agg(e),o())},setFrShowSma(e){i()||(t.set_fr_show_sma(e),o())},enableCvd(){i()||p("cvd")&&(t.enable_cvd(),o())},disableCvd(){i()||(t.disable_cvd(),o())},isCvdEnabled(){if(i())return!1;try{return t.is_cvd_enabled()}catch{return!1}},setCvdData(e,n){i()||(t.set_cvd_data(e,n),o())},setCvdMode(e){i()||(t.set_cvd_mode(e),o())},getCvdMode(){if(i())return 0;try{return t.get_cvd_mode()}catch{return 0}},setCvdShowDelta(e){i()||(t.set_cvd_show_delta(e),o())},getCvdShowDelta(){if(i())return!0;try{return t.get_cvd_show_delta()}catch{return!0}},enableLargeTrades(){i()||p("largeTrades")&&(t.enable_large_trades(),o())},disableLargeTrades(){i()||(t.disable_large_trades(),o())},isLargeTradesEnabled(){if(i())return!1;try{return t.is_large_trades_enabled()}catch{return!1}},setLargeTradesData(e){i()||(t.set_large_trades_data(e),o())},pushLargeTrade(e,n,r,a){i()||(t.push_large_trade(e,n,r,a),o())},clearLargeTrades(){i()||(t.clear_large_trades(),o())},setLtVolumeFilter(e,n){i()||(t.set_lt_volume_filter(e,n),o())},setLtBubbleScale(e){i()||(t.set_lt_bubble_scale(e),o())},getLtDataMinVol(){return i()?0:t.get_lt_data_min_vol()},getLtDataMaxVol(){return i()?0:t.get_lt_data_max_vol()},ltHitTest(e,n){if(i())return"";try{return t.lt_hit_test(e,n)}catch{return""}},enableVrvp(){i()||p("vrvp")&&(t.enable_vrvp(),o())},disableVrvp(){i()||(t.disable_vrvp(),o())},isVrvpEnabled(){if(i())return!1;try{return t.is_vrvp_enabled()}catch{return!1}},setVrvpPocLine(e){i()||(t.set_vrvp_poc_line(e),o())},vrvpHitTest(e,n){if(i())return"";try{return t.vrvp_hit_test(e,n)}catch{return""}},enableTpo(){i()||p("tpo")&&(t.enable_tpo(),o())},disableTpo(){i()||(t.disable_tpo(),o())},isTpoEnabled(){if(i())return!1;try{return t.is_tpo_enabled()}catch{return!1}},setTpoPocLine(e){i()||(t.set_tpo_poc_line(e),o())},setTpoVaLines(e){i()||(t.set_tpo_va_lines(e),o())},setTpoIb(e){i()||(t.set_tpo_ib(e),o())},setTpoSinglePrints(e){i()||(t.set_tpo_single_prints(e),o())},setTpoPeriod(e){i()||(t.set_tpo_period(e),o())},getTpoPeriod(){if(i())return 1440;try{return t.get_tpo_period()}catch{return 1440}},setTpoNakedPoc(e){i()||(t.set_tpo_naked_poc(e),o())},setTpoProfileShape(e){i()||(t.set_tpo_profile_shape(e),o())},setTpoIbMinutes(e){i()||(t.set_tpo_ib_minutes(e),o())},setTpoLetterMinutes(e){i()||(t.set_tpo_letter_minutes(e),o())},setTpoSignals(e){i()||(t.set_tpo_signals(e),o())},isTpoSignals(){if(i())return!1;try{return t.is_tpo_signals()}catch{return!1}},enableLiqHeatmap(){i()||p("liqHeatmap")&&(t.enable_liq_heatmap(),o())},disableLiqHeatmap(){i()||(t.disable_liq_heatmap(),o())},isLiqHeatmapEnabled(){if(i())return!1;try{return t.is_liq_heatmap_enabled()}catch{return!1}},setLiqHeatmapRange(e,n){i()||(t.set_liq_heatmap_range(e,n),o())},getLiqHeatmapMin(){if(i())return 0;try{return t.get_liq_heatmap_min()}catch{return 0}},getLiqHeatmapMax(){if(i())return 1;try{return t.get_liq_heatmap_max()}catch{return 1}},getLiqHeatmapSegMax(){if(i())return 0;try{return t.get_liq_heatmap_seg_max()}catch{return 0}},setLiqHeatmapProfile(e){i()||(t.set_liq_heatmap_profile(e),o())},isLiqHeatmapProfile(){if(i())return!0;try{return t.is_liq_heatmap_profile()}catch{return!0}},setLiqHeatmapCellHeight(e){i()||(t.set_liq_heatmap_cell_height(e),o())},getLiqHeatmapCellHeight(){if(i())return 1;try{return t.get_liq_heatmap_cell_height()}catch{return 1}},setLiqHeatmapPredictions(e){i()||(t.set_liq_heatmap_predictions(e),o())},setLiqHeatmapFilledPct(e){i()||(t.set_liq_heatmap_filled_pct(e),o())},getLiqHeatmapFilledPct(){if(i())return .85;try{return t.get_liq_heatmap_filled_pct()}catch{return .85}},liqHeatmapHitTest(e,n){if(i())return"";try{return t.liq_heatmap_hit_test(e,n)}catch{return""}},liqZoneHitTest(e,n){if(i())return"";try{return t.liq_zone_hit_test(e,n)}catch{return""}},enableSmartRanges(){i()||p("smartRanges")&&(t.enable_smart_ranges(),o())},disableSmartRanges(){i()||(t.disable_smart_ranges(),o())},isSmartRangesEnabled(){if(i())return!1;try{return t.is_smart_ranges_enabled()}catch{return!1}},setSrTextSize(e){i()||(t.set_sr_text_size(e),o())},setSrShowOb(e){i()||(t.set_sr_show_ob(e),o())},setSrObLast(e){i()||(t.set_sr_ob_last(e),o())},setSrShowObActivity(e){i()||(t.set_sr_show_ob_activity(e),o())},setSrShowBreakers(e){i()||(t.set_sr_show_breakers(e),o())},setSrMitigation(e){i()||(t.set_sr_mitigation(e),o())},setSrShowMetrics(e){i()||(t.set_sr_show_metrics(e),o())},setSrShowHtfOb(e){i()||(t.set_sr_show_htf_ob(e),o())},setSrHtfMinutes(e){i()||(t.set_sr_htf_minutes(e),o())},setSrShowFvg(e){i()||(t.set_sr_show_fvg(e),o())},setSrFvgTheme(e){i()||(t.set_sr_fvg_theme(e),o())},setSrFvgMitigation(e){i()||(t.set_sr_fvg_mitigation(e),o())},setSrFvgHtf(e){i()||(t.set_sr_fvg_htf(e),o())},setSrFvgExtend(e){i()||(t.set_sr_fvg_extend(e),o())},setSrShowObSignals(e){i()||(t.set_sr_show_ob_signals(e),o())},setSrShowPredict(e){i()||(t.set_sr_show_predict(e),o())},setSrShowFvgSignals(e){i()||(t.set_sr_show_fvg_signals(e),o())},setSrShowSmartRev(e){i()||(t.set_sr_show_smart_rev(e),o())},setSrSmartRevHtf(e){i()||(t.set_sr_smart_rev_htf(e),o())},setSrStatsType(e){i()||(t.set_sr_stats_type(e),o())},setSrStatsPosition(e){i()||(t.set_sr_stats_position(e),o())},getSrSignalsCount(){if(i())return 0;try{return t.get_sr_signals_count()}catch{return 0}},enableEmaStructure(){i()||p("emaStructure")&&(t.enable_ema_structure(),o())},disableEmaStructure(){i()||(t.disable_ema_structure(),o())},isEmaStructureEnabled(){if(i())return!1;try{return t.is_ema_structure_enabled()}catch{return!1}},setEsEma1Len(e){i()||(t.set_es_ema1_len(e),o())},setEsEma2Len(e){i()||(t.set_es_ema2_len(e),o())},setEsWmaLen(e){i()||(t.set_es_wma_len(e),o())},setEsShowEma1(e){i()||(t.set_es_show_ema1(e),o())},setEsShowEma2(e){i()||(t.set_es_show_ema2(e),o())},setEsShowWma(e){i()||(t.set_es_show_wma(e),o())},setEsSwingLen(e){i()||(t.set_es_swing_len(e),o())},setEsShowBos(e){i()||(t.set_es_show_bos(e),o())},enableLiveSignals(){i()||(t.enable_live_signals(),o())},disableLiveSignals(){i()||(t.disable_live_signals(),o())},isLiveSignalsEnabled(){if(i())return!1;try{return t.is_live_signals_enabled()}catch{return!1}},setLiveSignalsData(e){i()||(t.set_live_signals_data(new Float64Array(e)),o())},clearLiveSignals(){i()||(t.clear_live_signals(),o())},setLiveSignalsLeverage(e){i()||(t.set_live_signals_leverage(e),o())},getLiveSignalsLeverage(){if(i())return 10;try{return t.get_live_signals_leverage()}catch{return 10}},setLiveSignalsTrial(e){i()||(t.set_live_signals_trial(e),o())},setLiveSignalsShowEntry(e){i()||(t.set_live_signals_show_entry(e),o())},setLiveSignalsShowTpSl(e){i()||(t.set_live_signals_show_tp_sl(e),o())},setLiveSignalsShowMaxProfit(e){i()||(t.set_live_signals_show_max_profit(e),o())},setLiveSignalsShowLabels(e){i()||(t.set_live_signals_show_labels(e),o())},setLiveSignalsShowZones(e){i()||(t.set_live_signals_show_zones(e),o())},setLiveSignalsTextSize(e){i()||(t.set_live_signals_text_size(e),o())},setLiveSignalsPipValue(e){i()||(t.set_live_signals_pip_value(e),o())},setLiveSignalsLoading(e){i()||(t.set_live_signals_loading(e),o())},getLiveSignalsCount(){if(i())return 0;try{return t.get_live_signals_count()}catch{return 0}},enableVpin(){i()||p("vpin")&&(t.enable_vpin(),o())},disableVpin(){i()||(t.disable_vpin(),o())},isVpinEnabled(){if(i())return!1;try{return t.is_vpin_enabled()}catch{return!1}},setVpinData(e,n){i()||(t.set_vpin_data(e,n),o())},setVpinBucketSize(e){i()||(t.set_vpin_bucket_size(e),o())},getVpinBucketSize(){if(i())return 50;try{return t.get_vpin_bucket_size()}catch{return 50}},setVpinNumBuckets(e){i()||(t.set_vpin_num_buckets(e),o())},getVpinNumBuckets(){if(i())return 50;try{return t.get_vpin_num_buckets()}catch{return 50}},setVpinThreshold(e){i()||(t.set_vpin_threshold(e),o())},getVpinThreshold(){if(i())return .7;try{return t.get_vpin_threshold()}catch{return .7}},setVpinShowSma(e){i()||(t.set_vpin_show_sma(e),o())},setVpinShowZones(e){i()||(t.set_vpin_show_zones(e),o())},enableStopIceberg(){i()||p("stopIceberg")&&(t.enable_stop_iceberg(),o())},disableStopIceberg(){i()||(t.disable_stop_iceberg(),o())},isStopIcebergEnabled(){if(i())return!1;try{return t.is_stop_iceberg_enabled()}catch{return!1}},setSiShowStops(e){i()||(t.set_si_show_stops(e),o())},setSiShowIcebergs(e){i()||(t.set_si_show_icebergs(e),o())},setSiShowZones(e){i()||(t.set_si_show_zones(e),o())},setIcebergEvents(e,n,r,a,u,l){i()||(t.set_iceberg_events(e,n,r,a,u,l),o())},getStopRunCount(){if(i())return 0;try{return t.get_stop_run_count()}catch{return 0}},getIcebergCount(){if(i())return 0;try{return t.get_iceberg_count()}catch{return 0}},enableVolume(){t.enable_volume(),o()},disableVolume(){t.disable_volume(),o()},isVolumeEnabled(){return t.is_volume_enabled()},setVolumeMaPeriod(e){t.set_volume_ma_period(e),o()},setVolumeShowMa(e){t.set_volume_show_ma(e),o()},setVolumeShowSignals(e){t.set_volume_show_signals(e),o()},setVolumeColorMode(e){t.set_volume_color_mode(e),o()},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 ee(t,o,i,s){let p=e=>s()(e);return{addMarker(e,n,r){t.add_marker(e,n,r),o()},clearMarkers(){t.clear_markers(),o()},hitTestMarker(e,n){return t.hit_test_marker(e,n)},selectMarker(e){t.select_marker(e),o()},deselectMarker(){t.deselect_marker(),o()},getSelectedMarker(){return t.get_selected_marker()},removeMarker(e){t.remove_marker(e),o()},deleteSelectedMarker(){let e=t.get_selected_marker();return e>0&&(t.remove_marker(e),o()),e},addTrendline(e,n,r,a,u,l,g,f,d,_=0){let c=t.add_trendline(e,n,r,a,u,l,g,f,d,_);return o(),c},addHorizontalLine(e,n,r,a,u,l,g,f=0){let d=t.add_horizontal_line(e,n,r,a,u,l,g,f);return o(),d},addArrow(e,n,r,a,u,l,g,f,d,_=0){let c=t.add_arrow(e,n,r,a,u,l,g,f,d,_);return o(),c},addFibRetracement(e,n,r,a,u,l,g,f,d,_=0){if(!p("drawingFull"))return 0;let c=t.add_fib_retracement(e,n,r,a,u,l,g,f,d,_);return o(),c},addFibExtension(e,n,r,a,u,l,g,f,d,_,c,h=0){if(!p("drawingFull"))return 0;let w=t.add_fib_extension(e,n,r,a,u,l,g,f,d,_,c,h);return o(),w},addLongPosition(e,n,r,a,u,l,g,f,d,_=0){if(!p("drawingFull"))return 0;let c=t.add_long_position(e,n,r,a,u,l,g,f,d,_);return o(),c},addShortPosition(e,n,r,a,u,l,g,f,d,_=0){if(!p("drawingFull"))return 0;let c=t.add_short_position(e,n,r,a,u,l,g,f,d,_);return o(),c},addAnchoredVwap(e,n,r,a,u,l,g=0){if(!p("drawingFull"))return 0;let f=t.add_anchored_vwap(e,n,r,a,u,l,g);return o(),f},addPriceLabel(e,n,r,a,u,l,g=0){let f=t.add_price_label(e,n,r,a,u,l,g);return o(),f},addElliottImpulse(e,n,r,a,u,l,g=0){if(!p("drawingFull"))return 0;let f=t.add_elliott_impulse(e,n,r,a,u,l,g);return o(),f},setDrawingFontSize(e,n){t.set_drawing_font_size(e,n),o()},getDrawingFontSize(e){return t.get_drawing_font_size(e)},setDrawingText(e,n){t.set_drawing_text(e,n),o()},getDrawingText(e){return t.get_drawing_text(e)},setDrawingStyle(e,n,r,a,u){t.set_drawing_style(e,n,r,a,u),o()},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),o()},getDrawingHideLabel(e){try{return t.get_drawing_hide_label(e)}catch{return!1}},setDrawingHideLabel(e,n){t.set_drawing_hide_label(e,n),o()},getDrawingKindId(e){try{return t.get_drawing_kind_id(e)}catch{return 255}},removeDrawing(e){t.remove_drawing(e),o()},clearDrawings(){t.clear_drawings(),o()},drawingCount(){return t.drawing_count()},setDrawingPreview(e,n,r,a,u,l,g,f,d,_,c=0){t.set_drawing_preview(e,n,r,a,u,l,g,f,d,_,c),o()},clearDrawingPreview(){t.clear_drawing_preview(),o()},cancelBrush(){t.cancel_brush(),o()},selectDrawing(e){t.select_drawing(e),o()},deselectDrawing(){t.deselect_drawing(),o()},getSelectedDrawing(){return t.get_selected_drawing()},deleteSelectedDrawing(){let e=t.get_selected_drawing();return e>0&&(t.remove_drawing(e),o()),e},exportDrawingsJson(){try{return t.export_drawings_json()}catch{return"[]"}},importDrawingsJson(e){try{t.import_drawings_json(e),o()}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}}}}var y=t=>t instanceof Float64Array?t:new Float64Array(t);function re(t,o,i,s){let p=e=>s()(e);return{setKlines(e,n,r,a,u,l){t.set_klines(y(e),y(n),y(r),y(a),y(u),y(l)),o()},setRealTimestamps(e){t.set_real_timestamps(y(e)),o()},appendRealTimestamp(e){t.append_real_timestamp(e)},prependKlines(e,n,r,a,u,l){t.prepend_klines(y(e),y(n),y(r),y(a),y(u),y(l)),o()},appendKline(e,n,r,a,u,l){t.append_kline(e,n,r,a,u,l),o()},updateLastKline(e,n,r,a,u,l){t.update_last_kline(e,n,r,a,u,l),o()},popLastKline(){let e=t.pop_last_kline();return e&&o(),e},getLastClose(){try{return t.get_last_close()}catch{return 0}},getKlineCount(){if(i())return 0;try{return t.kline_count()}catch{return 0}},getKlineTimestamps(){if(i())return null;try{return t.kline_timestamps()}catch{return null}},getKlineOpens(){if(i())return null;try{return t.kline_opens()}catch{return null}},getKlineHighs(){if(i())return null;try{return t.kline_highs()}catch{return null}},getKlineLows(){if(i())return null;try{return t.kline_lows()}catch{return null}},getKlineCloses(){if(i())return null;try{return t.kline_closes()}catch{return null}},getKlineVolumes(){if(i())return null;try{return t.kline_volumes()}catch{return null}},setHeatmap(e,n,r,a,u,l,g){p("heatmap")&&(t.set_heatmap(y(e),n,r,a,u,l,g),o())},appendHeatmapColumn(e,n,r,a){p("heatmap")&&(t.append_heatmap_column(y(e),n,r,a),o())},updateLastHeatmapColumn(e,n,r){t.update_last_heatmap_column(y(e),n,r),o()},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,a){t.update_heatmap_column_at(y(e),n,r,a),o()},setHeatmapRange(e,n){t.set_heatmap_range(e,n),o()},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){i()||e===2&&!p("footprint")||(t.set_chart_type(e),o())},getChartType(){if(i())return 0;try{return t.get_chart_type()}catch{return 0}},setFootprintTickSize(e){i()||p("footprint")&&(t.set_footprint_tick_size(e),o())},footprintEnsureLen(e){i()||t.footprint_ensure_len(e)},footprintAddTrade(e,n,r,a){i()||t.footprint_add_trade(e,n,r,a)},footprintAddTradeBatch(e){i()||!e||e.length===0||t.footprint_add_trade_batch(y(e))},footprintSetBar(e,n,r,a,u){i()||(t.footprint_set_bar(e,n,r,a,u),o())},footprintClear(){i()||(t.footprint_clear(),o())},footprintClearBar(e){i()||t.footprint_clear_bar(e)},footprintPrependEmpty(e){i()||t.footprint_prepend_empty(e)},footprintSetShowSignals(e){i()||(t.footprint_set_show_signals(e),o())},footprintGetShowSignals(){if(i())return!0;try{return t.footprint_get_show_signals()}catch{return!0}},footprintSignalCount(){if(i())return 0;try{return t.footprint_signal_count()}catch{return 0}},footprintSetShowProfile(e){i()||(t.footprint_set_show_profile(e),o())},footprintGetShowProfile(){if(i())return!1;try{return t.footprint_get_show_profile()}catch{return!1}},footprintProfileHitTest(e,n){if(i())return"";try{return t.footprint_profile_hit_test(e,n)}catch{return""}},footprintSetDisplayMode(e){i()||(t.footprint_set_display_mode(e),o())},footprintGetDisplayMode(){if(i())return 0;try{return t.footprint_get_display_mode()}catch{return 0}},enableDeltaHistogram(){i()||t.enable_delta_histogram()},disableDeltaHistogram(){i()||t.disable_delta_histogram()},deltaHistogramEnabled(){if(i())return!1;try{return t.delta_histogram_enabled()}catch{return!1}}}}var Pe=1;function j(t){if(typeof t!="string")return{r:255,g:255,b:255,a:153};if(t.startsWith("#")){let i=t.slice(1);if(i.length===8)return{r:parseInt(i.slice(0,2),16),g:parseInt(i.slice(2,4),16),b:parseInt(i.slice(4,6),16),a:parseInt(i.slice(6,8),16)};let s=parseInt(i.slice(0,2),16),p=parseInt(i.slice(2,4),16),e=parseInt(i.slice(4,6),16);return{r:s,g:p,b:e,a:255}}let o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\)/);return o?{r:+o[1],g:+o[2],b:+o[3],a:o[4]!==void 0?Math.round(+o[4]*255):255}:{r:255,g:255,b:255,a:153}}function Nt(t,o,i){let s=new Map,p=null,e=0,n=NaN;function r(){let f;try{f=t.kline_count()}catch{return p}if(f===0)return null;let d=t.kline_closes(),_=d?.[f-1]??NaN;if(p&&!(f!==e||_!==n))return p;try{let h=t.kline_timestamps(),w=t.kline_opens(),m=t.kline_highs(),L=t.kline_lows(),S=t.kline_volumes();if(!h||!d)return p;p={timestamps:Array.from(h),open:Array.from(w),high:Array.from(m),low:Array.from(L),close:Array.from(d),volume:Array.from(S),length:f},e=f,n=_;for(let C of s.values())C._needsCompute=!0}catch{}return p}function a(){return{seriesLine(f,d="#ffffff99",_=1.5){let c=j(d);t.custom_series_line(new Float64Array(f),c.r,c.g,c.b,c.a,_)},seriesDashedLine(f,d="#ffffff66",_=1,c=4,h=4){let w=j(d);t.custom_series_dashed_line(new Float64Array(f),w.r,w.g,w.b,w.a,_,c,h)},band(f,d,_="rgba(100,149,237,0.08)"){let c=j(_);t.custom_band(new Float64Array(f),new Float64Array(d),c.r,c.g,c.b,c.a)},hline(f,d="#ffffff66",_=1){let c=j(d);t.custom_hline(f,c.r,c.g,c.b,c.a,_)},dashedHline(f,d="#ffffff66",_=1,c=6,h=4){let w=j(d);t.custom_dashed_hline(f,w.r,w.g,w.b,w.a,_,c,h)},marker(f,d,_="#e8a04a",c=3){let h=j(_);t.custom_marker(f,d,h.r,h.g,h.b,h.a,c)},markerUp(f,d,_="#26a69a",c=5){let h=j(_);t.custom_marker_up(f,d,h.r,h.g,h.b,h.a,c)},markerDown(f,d,_="#ef5350",c=5){let h=j(_);t.custom_marker_down(f,d,h.r,h.g,h.b,h.a,c)},text(f,d,_,c="#ffffffaa",h=10,w="center"){let m=j(c),L=w==="center"?1:w==="right"?2:0;t.custom_text(f,d,_,m.r,m.g,m.b,m.a,h,L)},priceLabel(f,d,_="#ffffffaa",c=10){let h=j(_);t.custom_price_label(f,d,h.r,h.g,h.b,h.a,c)},linePx(f,d,_,c,h,w=1){let m=j(h);t.custom_line_px(f,d,_,c,m.r,m.g,m.b,m.a,w)},fillRectPx(f,d,_,c,h){let w=j(h);t.custom_fill_rect_px(f,d,_,c,w.r,w.g,w.b,w.a)},strokeRectPx(f,d,_,c,h,w=1){let m=j(h);t.custom_stroke_rect_px(f,d,_,c,m.r,m.g,m.b,m.a,w)},textPx(f,d,_,c,h=10,w="left"){let m=j(c),L=w==="center"?1:w==="right"?2:0;t.custom_text_px(f,d,_,m.r,m.g,m.b,m.a,h,L)},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 d=r();if(d)try{f._computed=f.compute(d,f.params)||{}}catch(_){console.warn(`[CustomIndicator "${f.name}"] compute error:`,_),f._computed={}}}function l(f){if(s.size===0)return;let d=r();if(!d)return;t.custom_begin();let _=a();for(let h of s.values())if(h.enabled){h._needsCompute&&(u(h),h._needsCompute=!1);try{h.render.call(h,_,h._computed||{},d)}catch(w){console.warn(`[CustomIndicator "${h.name}"] render error:`,w)}}if(t.custom_end(),t.custom_command_count()>0){let h=t.get_custom_buffer_ptr(),w=t.get_custom_buffer_len();i(f,o,h,w)}}function g(){p=null,e=0,n=NaN;for(let f of s.values())f._needsCompute=!0}return{add(f){let d=Pe++,_={id:d,name:f.name||`Custom ${d}`,params:{...f.params},compute:f.compute||null,render:f.render,enabled:!0,_computed:{},_needsCompute:!0};return s.set(d,_),d},remove(f){s.delete(f)},updateParams(f,d){let _=s.get(f);_&&(Object.assign(_.params,d),_._needsCompute=!0)},setEnabled(f,d){let _=s.get(f);_&&(_.enabled=d)},list(){return[...s.values()].map(f=>({id:f.id,name:f.name,params:{...f.params},enabled:f.enabled}))},invalidateCompute:g,renderAll:l}}var oe={trial:{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,vpin:!0,stopIceberg:!0},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,vpin:!1,stopIceberg:!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,vpin:!1,stopIceberg:!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,vpin:!0,stopIceberg:!0}},Re={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",vpin:"VPIN",stopIceberg:"Stops & Icebergs"},je={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",vpin:"Enterprise",stopIceberg:"Enterprise"};function et(t){return oe[t]||oe.trial}function Pt(t){let o=et(t),i=new Set;return function(p){if(o[p])return!0;if(!i.has(p)){i.add(p);let e=Re[p]||p,n=je[p]||"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,se="trial",ut="free";var jt=[95,95,109,114].map(t=>String.fromCharCode(t)).join(""),Ye=1297237059;function le(t){let o=`${t}:${Ye}:${(t^2043453)>>>0}`,i=2166136261;for(let s=0;s<o.length;s++)i^=o.charCodeAt(s),i=Math.imul(i,16777619);return(i>>>0).toString(36)}function ft(t){return`${t}.${le(t)}`}function dt(t){if(!t||typeof t!="string")return null;let o=t.lastIndexOf(".");if(o<1)return null;let i=parseInt(t.slice(0,o),10);return!i||i<1e9||i>2e9||t.slice(o+1)!==le(i)?null:i}var ue=jt+"e7x",fe=jt+"p3q",de="mrd_engine_session_id",_e="mrd_ce_db",rt="meta",ce="trial_ts",he=jt+"ck";function Ft(){try{return dt(localStorage.getItem(ue))}catch{return null}}function Yt(t){try{localStorage.setItem(ue,ft(t))}catch{}}function zt(){try{return dt(localStorage.getItem(fe))}catch{return null}}function Dt(t){try{localStorage.setItem(fe,ft(t))}catch{}}function Zt(){try{return dt(sessionStorage.getItem(de))}catch{return null}}function Xt(t){try{sessionStorage.setItem(de,ft(t))}catch{}}function Ht(){try{let t=document.cookie.match(new RegExp(`(?:^|;\\s*)${he}=([^;]+)`));return t?dt(decodeURIComponent(t[1])):null}catch{return null}}function Ot(t){try{let o=encodeURIComponent(ft(t));document.cookie=`${he}=${o};path=/;max-age=${86400*400};SameSite=Lax`}catch{}}var ot=null,ie=!1;function ze(){if(!(ie||typeof indexedDB>"u")){ie=!0;try{let t=indexedDB.open(_e,1);t.onupgradeneeded=()=>{let o=t.result;o.objectStoreNames.contains(rt)||o.createObjectStore(rt)},t.onsuccess=()=>{let s=t.result.transaction(rt,"readonly").objectStore(rt).get(ce);s.onsuccess=()=>{let p=dt(s.result);p&&(!ot||p<ot)&&(ot=p,De(p))}}}catch{}}}function pe(t){ot=t;try{let o=indexedDB.open(_e,1);o.onsuccess=()=>{o.result.transaction(rt,"readwrite").objectStore(rt).put(ft(t),ce)}}catch{}}function De(t){let o=Math.floor(Date.now()/1e3),i=we([Ft(),zt(),Zt(),Ht(),t],o);i&&i!==t||i&&(Yt(i),Dt(i),Xt(i),Ot(i))}function we(t,o){let i=null;for(let s of t)s&&(s>o+60||s<17e8||(!i||s<i)&&(i=s));return i}function Ze(){let t=Math.floor(Date.now()/1e3),o=[Ft(),zt(),Zt(),Ht(),ot];return we(o,t)}function Xe(t){Yt(t),Dt(t),Xt(t),Ot(t),pe(t)}function He(t){Ft()||Yt(t),zt()||Dt(t),Zt()||Xt(t),Ht()||Ot(t),ot||pe(t)}ze();function Mt(t){if(!t||t==="trial")return Oe();try{let o=JSON.parse(atob(t)),{p:i,d:s,e:p,s:e}=o;if(!i||!e)return{valid:!1,error:"Invalid license key format"};let n={...o};if(delete n.s,e!==ge(n))return{valid:!1,error:"Invalid license key signature"};if(p>0&&Date.now()/1e3>p)return{valid:!0,plan:ut,watermark:!0,trialExpired:!0,originalPlan:i,error:`License expired on ${new Date(p*1e3).toLocaleDateString()}`,features:et(ut)};let r=o.pl||"web";if((r==="web"||r==="any")&&s&&s!=="*"&&typeof window<"u"){let a=window.location.hostname;if(a&&a!=="localhost"&&a!=="127.0.0.1"&&a!=="0.0.0.0"&&a!==""&&!s.split(",").map(g=>g.trim()).some(g=>We(g,a)))return{valid:!1,error:`License not valid for domain: ${a}`}}if(r==="mobile"&&o.a&&typeof window<"u"){let a=window.__mrd_app_id;if(a&&a!==o.a)return{valid:!1,error:`License not valid for app: ${a}`}}return{valid:!0,plan:i,domain:s,platform:r,appId:o.a||null,expiry:p,watermark:!1,features:et(i)}}catch{return{valid:!1,error:"Invalid license key"}}}function ge(t){let o="mrd-ce-hmac-2024-x9k2m",i=JSON.stringify(t),s=o+":"+i,p=2166136261,e=1818371886,n=3735928559;for(let r=0;r<s.length;r++){let a=s.charCodeAt(r);p=Math.imul(p^a,16777619)>>>0,e=Math.imul(e^a,1540483477)>>>0,n=Math.imul(n^a,461845907)>>>0}return(p.toString(36)+e.toString(36)+n.toString(36)).slice(0,24)}function Oe(){let t=Ze();t?He(t):(t=Math.floor(Date.now()/1e3),Xe(t));let o=t+Fe*86400,i=Date.now()/1e3,s=Math.max(0,Math.ceil((o-i)/86400));return i>o?{valid:!0,plan:ut,watermark:!0,trialExpired:!0,daysLeft:0,features:et(ut)}:{valid:!0,plan:se,watermark:!1,daysLeft:s,trialEnd:o,features:et(se)}}function We(t,o){if(t==="*"||t===o)return!0;if(t.startsWith("*.")){let i=t.slice(1);return o.endsWith(i)||o===t.slice(2)}return!1}var Ve="MRD-Indicators",ne="mrd-indicators.com",Be="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iMzAiIHZpZXdCb3g9IjAgMCAzMCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnI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jEyLDAtLjA4LDAtLjE2LDAtLjI0LDAtLjAxLDAtLjAzLDAtLjA0LDAtMi4wNSwwLTMuNy0xLjY4LTMuNy0zLjcybDIuMjMtMS44NGMuMzQtLjI4Ljc4LS40NCwxLjIyLS40NGgxLjIyWiIvPgogICAgICAgIDxwYXRoIGNsYXNzPSJjbHMtNCIgZD0iTTIwLjI4LDE0LjcxYy0uMDgsMC0uMTcsMC0uMjUsMGgtNi4zMWMtLjQ1LDAtLjg4LjE1LTEuMjIuNDRsLTIuMjMsMS44NGMwLC4wOCwwLC4xNywwLC4yNSwxLjA5LjY1LDIuMzcsMS4wMiwzLjczLDEuMDIsMi42NywwLDUuMDEtMS40Myw2LjI4LTMuNTVaIi8+CiAgICAgICAgPHBhdGggY2xhc3M9ImNscy02IiBkPSJNMjMuNzcsMTAuOTdzMC0uMDMsMC0uMDRjMC0uMDgsMC0uMTYsMC0uMjQsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDQsMC0uMDgsMC0uMTIsMC0uMDYsMC0uMTEtLjAxLS4xNywwLS4wMiwwLS4wNSwwLS4wNywwLS4wNi0uMDEtLjEzLS4wMi0uMTksMC0uMDEsMC0uMDMsMC0uMDQsMC0uMDctLjAyLS4xNC0uMDItLjIxLDAsMCwwLS4wMSwwLS4wMiwwLS4wNy0uMDItLjE1LS4wMy0uMjIsMCwwLDAsMCwwLDAtLjcxLTQuNjctNC43Ny04LjI0LTkuNjYtOC4yNCwyLjA0LDAsMy42OCwxLjY2LDMuNywzLjY5bC4wNCw1LjA2djEuODZzLjAxLjAyLjAxLjAzYzAsMS41Mi0xLjI1LDIuNzYtMi43OCwyLjc3bDUuMDktLjA0YzIuMDUtLjAxLDMuNzItMS42NiwzLjcxLTMuN1oiLz4KICAgICAgPC9nPgogICAgPC9nPgogIDwvZz4KPC9zdmc+",Rt=null,ae=!1;function me(){if(Rt||ae)return Rt;ae=!0;let t=new Image;return t.onload=()=>{Rt=t},t.src=Be,null}function Ge(){return Math.floor(Date.now()/864e5)}function qe(t){let o=(t^2654435769)>>>0;return function(){o=o+1831565813>>>0;let i=Math.imul(o^o>>>15,1|o);return i=i+Math.imul(i^i>>>7,61|i)^i,((i^i>>>14)>>>0)/4294967296}}function Ke(t,o,i,s,p,e){let n=me();t.save(),t.setTransform(1,0,0,1,0,0),t.font="bold 10px Inter, system-ui, sans-serif";let r=t.measureText(s);t.font="8px Inter, system-ui, sans-serif";let a=t.measureText(p),u=n?18:0,l=n?14:0,g=7,f=5,d=n?5:0,c=u+d+Math.max(r.width,a.width)+g*2,h=Math.max(l,20)+f*2,w=Math.round(o-c/2),m=Math.round(i-h/2);t.globalAlpha=.45,t.fillStyle=e?"rgba(255,255,255,0.8)":"rgba(18,18,28,0.8)",t.shadowColor=e?"rgba(0,0,0,0.06)":"rgba(0,0,0,0.25)",t.shadowBlur=8,t.shadowOffsetY=1,t.beginPath(),t.roundRect(w,m,c,h,6),t.fill(),t.shadowColor="transparent",t.strokeStyle=e?"rgba(0,0,0,0.04)":"rgba(255,255,255,0.04)",t.lineWidth=.5,t.stroke();let L=w+g,S=m+h/2;n&&(t.globalAlpha=.5,t.drawImage(n,L,S-l/2,u,l),L+=u+d),t.globalAlpha=.5,t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=e?"#1a1a2e":"#ededf5",t.textAlign="left",t.textBaseline="alphabetic",t.fillText(s,L,S-1),t.font="8px Inter, system-ui, sans-serif",t.fillStyle=e?"#777790":"#8080a0",t.textBaseline="top",t.fillText(p,L,S+2),t.restore()}function Me(t,o,i,s){me();let p=o.width,e=o.height;if(p<100||e<80)return;t.save(),t.setTransform(1,0,0,1,0,0);let n=qe(Ge()),r=100,a=Math.max(p-r*2,60),u=Math.max(e-r*2,40),l=r+n()*a,g=r+n()*u,f=i.trialExpired||i.plan===ut,d=Ve,_=f?`Free \u2014 ${ne}/pricing`:`Trial: ${i.daysLeft||0}d left \u2014 ${ne}`;Ke(t,l,g,d,_,s),t.restore()}function Ue({plan:t,domain:o="*",expiryDays:i=365,name:s,email:p}){let e=i>0?Math.floor(Date.now()/1e3)+i*86400:0,n={p:t,d:o,e,...s?{n:s}:{},...p?{m:p}:{},i:Date.now()};return n.s=ge(n),btoa(JSON.stringify(n))}var Lt=null,St=null,_t=null;async function Le(){return Lt||_t||(_t=(async()=>{let t=await import("./chart_engine.js");return await t.default(),St=t.wasm_memory(),Lt=t,t})(),_t)}function Qe(){!Lt&&!_t&&Le().catch(()=>{})}async function xe(t,o={}){o.appId&&typeof window<"u"&&(window.__mrd_app_id=o.appId);let i=o.licenseKey||o.key||null,s=Mt(i);if(!s.valid)if(s.expired)console.warn(`[MRD Chart Engine] ${s.error}. Get a license at https://mrd-chart.dev/pricing`);else throw new Error(`[MRD Chart Engine] ${s.error}`);s.plan==="trial"&&console.info(`[MRD Chart Engine] Trial mode \u2014 ${s.daysLeft} days remaining. Purchase: https://mrd-chart.dev/pricing`);let p=await Le(),e=window.devicePixelRatio||1,n=t.getBoundingClientRect();(n.width<1||n.height<1)&&(await new Promise(M=>{let I=new ResizeObserver(A=>{for(let b of A)if(b.contentRect.width>0&&b.contentRect.height>0){I.disconnect(),M();return}});I.observe(t.parentElement||t),setTimeout(()=>{I.disconnect(),M()},2e3)}),n=t.getBoundingClientRect());let r=Math.max(n.width,100),a=Math.max(n.height,100);t.width=r*e,t.height=a*e;let u=t.getContext("2d");u.scale(e,e);let l=new p.ChartEngine(r,a);try{let M=s.expired?2:s.watermark?1:0,I=s.daysLeft||0,A=1297237059;A=Math.imul(A,31)+M>>>0,A=Math.imul(A,31)+I>>>0,A=(A^A>>>16)>>>0,A=Math.imul(A,73244475)>>>0,A=(A^A>>>16)>>>0,l.set_license_state(M,I,A)}catch(M){console.warn("[MRD] set_license_state failed:",M.message)}let g=!0,f=null,d=!1,_=!1,c=!1,h=null,w=null,m=0,L=!1,S=!1,N=("ontouchstart"in window||navigator.maxTouchPoints>0)&&window.innerWidth<=1399?33:0;function U(){if(!(!d||_||f)){if(N>0){let M=performance.now()-m;if(M<N){w||(w=setTimeout(()=>{w=null,U()},N-M));return}}f=requestAnimationFrame(Ce)}}let T=()=>{g=!0,U()},x=()=>c,$=null,ct=null,It=null,E=null,Z=null,W=null,H=null,O=null,st=0,J=null,Wt=null,Ct=0,At=0,k=-1,ht=!1,pt=!1,Se=yt(t,l,{onDirty:T,onCrosshairMove:(M,I,A)=>{Ct=M,At=I,k=A,ht=!0,pt=!0},onCrosshairHide:()=>{pt&&(pt=!1,ht=!0,k=-1)},drawingApi:M=>{$=M},onDrawingComplete:()=>{ct?.()},onDrawingCancel:()=>{It?.()},onDrawingSelected:(M,I,A)=>{E?.(M,I,A)},onMarkerSelected:M=>{Z?.(M)},onDrawingDblClick:(M,I,A,b,vt)=>{W?.(M,I,A,b,vt)},onVrvpHover:(M,I)=>{H?.(M,I)},onLiqAnnotationPin:(M,I)=>{Wt?.(M,I)}});function Ie(){if(!(!ht||S)){if(ht=!1,!pt){h&&h(null,0,0),O&&O("");return}if(h)if(k===0||k===1)try{let M=l.get_tooltip_data();h(M,Ct,At)}catch{}else h(null,0,0);if(O){let M=performance.now();if(k===0||k===1){if(M-st>=80){st=M;try{O(l.lt_hit_test(Ct,At))}catch{}}}else O("")}}}function Ce(){if(f=null,!(!d||_||S)){L=!0;try{let M=!1;try{M=g||l.is_dirty()}catch{S=!0;return}if(M){g=!1,m=performance.now();let I=!1;try{if(l.render()>0){let b=l.get_command_buffer_ptr(),vt=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(),nt(u,St,b,vt),I=!0}try{Q.renderAll(u)}catch{}}catch(A){if(I||(g=!0),A instanceof WebAssembly.RuntimeError){S=!0,console.error("[MRD] Engine crashed:",A.message);return}}Ie();try{J?.()}catch{}if(s.watermark)try{let A=l.get_theme()===1;Me(u,t,s,A)}catch{}try{(g||l.is_dirty())&&U()}catch{}}}finally{L=!1}}}let it=Pt(s.plan),Ae=te(l,T,x,()=>it),ve=ee(l,T,x,()=>it),be=re(l,T,x,()=>it),Q=Nt(l,St,nt);return{engine:l,start(){d=!0,_=!1,g=!0,U()},stop(){d=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null)},resize(M){if(S||L)return;if(n=t.getBoundingClientRect(),n.width<1||n.height<1){(M||0)<8&&setTimeout(()=>this.resize((M||0)+1),250);return}e=window.devicePixelRatio||1;let I=n.width*e,A=n.height*e;t.width=I,t.height=A,u.setTransform(1,0,0,1,0,0),u.scale(e,e);try{l.resize(n.width,n.height)}catch(b){if(b instanceof WebAssembly.RuntimeError){S=!0;return}throw b}T()},renderSync(){if(S)return 0;try{let M=l.render();if(M>0){let I=l.get_command_buffer_ptr(),A=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(),nt(u,St,I,A)}return M}catch(M){return M instanceof WebAssembly.RuntimeError&&(S=!0),0}},setHoverPrice(M){l.set_hover_price(M),T()},clearHoverPrice(){l.clear_hover_price(),T()},hitZone(M,I){return l.hit_zone(M,I)},startDrawing(M,I){$?.setMode(M,I)},cancelDrawing(){$?.setMode(null)},onDrawingComplete(M){ct=M},onDrawingCancel(M){It=M},onDrawingSelected(M){E=M},onMarkerSelected(M){Z=M},onDrawingDblClick(M){W=M},setReplayState(M,I,A){l.set_replay_state(M,I,A),T()},setReplayHovered(M){l.set_replay_hovered(M)},setReplayPreview(M){l.set_replay_preview(M),T()},setPrecision(M){l.set_price_precision(M),T()},setCandleInterval(M){l.set_candle_interval(M)},setTheme(M){let I=M==="light"?1:0;typeof l.set_theme=="function"?(l.set_theme(I),T()):console.warn("[ChartEngine] set_theme not available \u2014 reload page to load updated WASM")},getTheme(){return l.get_theme()===1?"light":"dark"},onTooltip(M){h=M},onVrvpHover(M){H=M},onLtHover(M){O=M},onPostRender(M){J=M},onLiqAnnotationPin(M){Wt=M},pause(){_||(_=!0,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null))},resume(){_&&(_=!1,d&&(g=!0,U()))},get isPaused(){return _},destroy(){c=!0,d=!1,_=!1,f&&(cancelAnimationFrame(f),f=null),w&&(clearTimeout(w),w=null),Se();try{l.free()}catch{}},addIndicator(M){if(!it("customIndicators"))return null;let I=Q.add(M);return T(),I},removeIndicator(M){Q.remove(M),T()},updateIndicatorParams(M,I){Q.updateParams(M,I),T()},setIndicatorEnabled(M,I){Q.setEnabled(M,I),T()},listIndicators(){return Q.list()},invalidateCustomIndicators(){Q.invalidateCompute(),T()},get license(){return{plan:s.plan,valid:s.valid,expired:!!s.expired,watermark:!!s.watermark,daysLeft:s.daysLeft,features:s.features||{}}},setLicenseKey(M){s=Mt(M),!s.valid&&!s.expired&&console.error(`[MRD Chart Engine] ${s.error}`),it=Pt(s.plan);try{let I=s.expired?2:s.watermark?1:0,A=s.daysLeft||0,b=1297237059;b=Math.imul(b,31)+I>>>0,b=Math.imul(b,31)+A>>>0,b=(b^b>>>16)>>>0,b=Math.imul(b,73244475)>>>0,b=(b^b>>>16)>>>0,l.set_license_state(I,A,b)}catch{}return T(),s.valid},...be,...Ae,...ve}}function $e(t,o){let{t:i,o:s,h:p,l:e,c:n,v:r}=t,a=n.length;if(a===0||o<=0)return{t:[],o:[],h:[],l:[],c:[],v:[]};let u=[],l=[],g=[],f=[],d=[],_=[],c=Math.round(n[0]/o)*o,h=0;for(let w=0;w<a;w++){h+=r[w];let L=n[w]-c;for(;L>=o;){let S=c,C=c+o;u.push(i[w]),l.push(S),g.push(C),f.push(S),d.push(C),_.push(h),h=0,c=C}for(;-L>=o;){let S=c,C=c-o;u.push(i[w]),l.push(S),g.push(S),f.push(C),d.push(C),_.push(h),h=0,c=C}}return{t:u,o:l,h:g,l:f,c:d,v:_}}function Je(t,o){let{t:i,o:s,h:p,l:e,c:n,v:r}=t,a=n.length;if(a===0||o<=0)return{t:[],o:[],h:[],l:[],c:[],v:[]};let u=[],l=[],g=[],f=[],d=[],_=[],c=s[0],h=p[0],w=e[0],m=0,L=i[0];for(let S=0;S<a;S++)for(h=Math.max(h,p[S]),w=Math.min(w,e[S]),m+=r[S];h-w>=o;){let C=n[S]>=c,N=C?w+o:h-o;if(u.push(L),l.push(c),g.push(h),f.push(w),d.push(N),_.push(m),c=N,h=C?Math.max(p[S],N):N,w=C?N:Math.min(e[S],N),m=0,L=i[S],h-w<o)break}return(m>0||u.length===0)&&(u.push(L),l.push(c),g.push(h),f.push(w),d.push(n[a-1]),_.push(m)),{t:u,o:l,h:g,l:f,c:d,v:_}}function ke(t,o){let{t:i,o:s,h:p,l:e,c:n,v:r}=t,a=n.length;if(a===0||o<=0)return{t:[],o:[],h:[],l:[],c:[],v:[]};let u=[],l=[],g=[],f=[],d=[],_=[],c=Math.max(1,Math.round(o));for(let h=0;h<a;h+=c){let w=Math.min(h+c,a),m=-1/0,L=1/0,S=0;for(let C=h;C<w;C++)p[C]>m&&(m=p[C]),e[C]<L&&(L=e[C]),S+=r[C];u.push(i[h]),l.push(s[h]),g.push(m),f.push(L),d.push(n[w-1]),_.push(S)}return{t:u,o:l,h:g,l:f,c:d,v:_}}function tr(t,o){let i=t>1e4?50:t>1e3?10:t>100?1:t>1?.1:.001,s=i*2,p=o<=60?10:o<=300?5:3;return{brickSize:i,rangeSize:s,tickCount:p}}var er={minRefills:3,hiddenRatio:2,refillWindowMs:1e4,maxTrackedLevels:200,maxEvents:500,decayMs:3e5};function rr(t={}){let o={...er,...t},i=new Map,s=new Map,p=[],e=0;function n(f){return Math.round(f*1e8)/1e8}function r(f,d,_,c){for(let[h,w]of f){let m=n(h),L=d.get(m);if(!L){d.set(m,{lastVol:w,refills:0,totalConsumed:0,lastRefillTs:c,peakVisible:w});continue}if(w<L.lastVol*.3&&L.lastVol>0){let S=L.lastVol-w;L.totalConsumed+=S,L.lastVol=w;continue}if(w>L.lastVol*1.5&&L.totalConsumed>0)if(c-L.lastRefillTs<o.refillWindowMs){if(L.refills++,L.lastRefillTs=c,L.peakVisible=Math.max(L.peakVisible,w),L.refills>=o.minRefills){let C=L.totalConsumed,N=L.peakVisible;C>=N*o.hiddenRatio&&(p.push({timestamp:c,price:h,visibleSize:N,hiddenSize:C,isBid:_,refillCount:L.refills}),p.length>o.maxEvents&&p.shift(),L.refills=0,L.totalConsumed=0)}}else L.refills=1,L.totalConsumed=0,L.lastRefillTs=c;L.lastVol=w}if(d.size>o.maxTrackedLevels){let h=[...d.entries()];h.sort((m,L)=>m[1].lastRefillTs-L[1].lastRefillTs);let w=h.length-o.maxTrackedLevels;for(let m=0;m<w;m++)d.delete(h[m][0])}}function a(f,d,_){let c=_||Date.now();e=c;let h=f instanceof Map?f:new Map(f.map(([L,S])=>[L,S])),w=d instanceof Map?d:new Map(d.map(([L,S])=>[L,S]));r(h,i,!0,c),r(w,s,!1,c);let m=c-o.decayMs;for(;p.length>0&&p[0].timestamp<m;)p.shift()}function u(){return p}function l(f){if(!f||p.length===0)return;let d=p.length,_=new Float64Array(d),c=new Float64Array(d),h=new Float64Array(d),w=new Float64Array(d),m=new Uint8Array(d),L=new Uint32Array(d);for(let S=0;S<d;S++){let C=p[S];_[S]=C.timestamp,c[S]=C.price,h[S]=C.visibleSize,w[S]=C.hiddenSize,m[S]=C.isBid?1:0,L[S]=C.refillCount}f.setIcebergEvents(_,c,h,w,m,L)}function g(){i.clear(),s.clear(),p.length=0}return{onOrderbookUpdate:a,getEvents:u,pushToEngine:l,reset:g}}export{Je as buildRange,$e as buildRenko,ke as buildTick,xe as createChartBridge,Nt as createCustomIndicatorManager,rr as createIcebergDetector,nt as dispatchCommands,Ue as generateLicenseKey,Qe as prefetchWasm,yt as setupEvents,tr as suggestDefaults,Mt as validateLicense};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kline-orderbook-chart",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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",
|