kline-orderbook-chart 1.6.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -1
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/chart-engine.mjs +416 -10
- package/dist/chart_engine.js +1 -1
- package/dist/chart_engine_bg.wasm +0 -0
- package/dist/index.d.ts +6 -0
- package/dist/ingestWorker.js +14 -0
- package/dist/panelWorker.js +56 -0
- package/dist/tickWorker.js +420 -0
- package/package.json +2 -2
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* chart-engine / kline-orderbook-chart
|
|
3
|
+
* Copyright (c) 2025-2026 Tape Delta. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Proprietary and confidential. Licensed, not sold. Unauthorized
|
|
6
|
+
* copying, redistribution, modification, reverse-engineering, or
|
|
7
|
+
* removal of this notice is strictly prohibited. See the LICENSE
|
|
8
|
+
* file shipped with this package for the full terms.
|
|
9
|
+
*
|
|
10
|
+
* Contact: support@tapedelta.com
|
|
11
|
+
* Web: https://tapedelta.com
|
|
12
|
+
* NPM: https://www.npmjs.com/package/kline-orderbook-chart
|
|
13
|
+
*/
|
|
14
|
+
var Ht=-Math.PI/2,Fn=new WeakMap;function fo(t,a){let i=Fn.get(t);i||(i=new Map,Fn.set(t,i));let c=i.get(a);if(c)return c;i.size>=128&&i.clear();let b=a*.259,n=a*.432,d=t.createRadialGradient(b,n,0,b,n,a*1.45);d.addColorStop(0,"rgba(0,0,0,0)"),d.addColorStop(1,"rgba(0,0,0,0.59)");let A=a*.135,E=a*.225,o=t.createRadialGradient(A,E,0,A,E,a*.38);return o.addColorStop(0,"rgba(255,255,255,0.35)"),o.addColorStop(1,"rgba(255,255,255,0)"),c={dark:d,spec:o},i.set(a,c),c}function Rn(t,a,i,c,b,n,d,A,E,o,r,e,M,O){if(!(c>0))return;let x=Math.min(1,Math.max(0,b)),z=x*Math.PI;if(t.save(),t.translate(a,i),t.globalAlpha*=.82,x>=.999||x<=.001){let g=x>=.999?[n,d,A,E]:[o,r,e,M];t.beginPath(),t.arc(0,0,c,0,Math.PI*2),t.fillStyle=`rgba(${g[0]},${g[1]},${g[2]},${(g[3]/255).toFixed(3)})`,t.fill()}else t.beginPath(),t.moveTo(0,0),t.arc(0,0,c,Ht-z,Ht+z),t.closePath(),t.fillStyle=`rgba(${n},${d},${A},${(E/255).toFixed(3)})`,t.fill(),t.beginPath(),t.moveTo(0,0),t.arc(0,0,c,Ht+z,Ht-z+Math.PI*2),t.closePath(),t.fillStyle=`rgba(${o},${r},${e},${(M/255).toFixed(3)})`,t.fill(),c>=4&&(t.strokeStyle="rgba(20,20,20,0.45)",t.lineWidth=Math.max(1,c*.08),t.beginPath(),t.moveTo(0,0),t.lineTo(c*Math.cos(Ht-z),c*Math.sin(Ht-z)),t.moveTo(0,0),t.lineTo(c*Math.cos(Ht+z),c*Math.sin(Ht+z)),t.stroke());if(O&&c>=4){let g=fo(t,Math.round(c));t.beginPath(),t.arc(0,0,c,0,Math.PI*2),t.fillStyle=g.dark,t.fill(),t.fillStyle=g.spec,t.fill()}t.restore()}var X={FILL_RECT:1,FILL_ROUND_RECT:27,FILL_ELLIPSE:38,FILL_RECT_SMOOTH_X:30,STROKE_RECT:2,LINE:3,CANDLE:34,CANDLE_BORDERED:36,OHLC_BAR:37,DASHED_LINE:4,POLYLINE:5,TEXT:6,STYLED_TEXT:33,CIRCLE:7,TRIANGLE:8,SAVE:9,RESTORE:10,CLIP_RECT:11,ROTATED_TEXT:12,BUBBLE_3D:13,BUBBLE_PIE:39,FILL_POLYGON:14,DASHED_POLYLINE:15,GRADIENT_RECT:16,GRADIENT_RECT_H:28,GRADIENT_RECT_H_MULTI:29,LINEAR_POLYLINE:17,SMOOTH_POLYLINE:24,BEGIN_HEATMAP_LAYER:18,END_HEATMAP_LAYER:19,HEATMAP_BITMAP:20,LINE_WITH_EXTEND:21,LABEL_CALLOUT:22,HEATMAP_WORLD:23,HEATMAP_BG:31,HEATMAP_WORLD_INTENSITY:32,OB_HEATMAP:35,DRAW_IMAGE:25,FILL_SMOOTH_BAND:26,END_FRAME:255},ho=(()=>{try{return typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches}catch{return!1}})(),mo=ho?1.5:1/0;function Me(){return typeof window<"u"&&window.devicePixelRatio||1}function bo(t,a){return typeof OffscreenCanvas<"u"?new OffscreenCanvas(t,a):Object.assign(document.createElement("canvas"),{width:t,height:a})}var Nt=null,Mn=null;function go(t,a){return Nt?(Nt.width!==t||Nt.height!==a)&&(Nt.width=t,Nt.height=a):(Nt=bo(t,a),Mn=Nt.getContext("2d")),Mn}var qe=new Float32Array(0);function yo(t){return qe.length<t&&(qe=new Float32Array(t)),qe}var he=new Float64Array(0),je=new Float64Array(0),Qe=new Float64Array(0),de=new Float64Array(0);function vo(t){return he.length<t&&(he=new Float64Array(t)),he}function po(t){return je.length<t&&(je=new Float64Array(t)),je}function To(t){return Qe.length<t&&(Qe=new Float64Array(t)),Qe}function Ao(t){return de.length<t&&(de=new Float64Array(t)),de}function Je(t,a){if(a<2)return;let i=a-1,c=vo(i),b=po(i),n=To(i);for(let A=0;A<i;A++){let E=t[A*2],o=t[A*2+1],r=t[(A+1)*2],e=t[(A+1)*2+1];c[A]=r-E,b[A]=e-o,n[A]=c[A]>0?b[A]/c[A]:0}let d=Ao(a);d[0]=n[0],d[a-1]=n[i-1];for(let A=1;A<i;A++){let E=n[A-1],o=n[A];d[A]=E*o<=0?0:(E+o)*.5}for(let A=0;A<i;A++){let E=n[A];if(E===0){d[A]=0,d[A+1]=0;continue}let o=d[A]/E,r=d[A+1]/E,e=o*o+r*r;if(e>9){let M=3/Math.sqrt(e);d[A]=M*o*E,d[A+1]=M*r*E}}}function Sn(t,a,i){let c=i-1,b=he,n=de;for(let d=0;d<c;d++){let A=a[d*2],E=a[d*2+1],o=a[(d+1)*2],r=a[(d+1)*2+1],e=b[d];if(e<=0){t.lineTo(o,r);continue}let M=e/3;t.bezierCurveTo(A+M,E+n[d]*M,o-M,r-n[d+1]*M,o,r)}}function _o(t,a,i){let c=i-1,b=he,n=de;for(let d=c-1;d>=0;d--){let A=a[d*2],E=a[d*2+1],o=a[(d+1)*2],r=a[(d+1)*2+1],e=b[d];if(e<=0){t.lineTo(A,E);continue}let M=e/3;t.bezierCurveTo(o-M,r-n[d+1]*M,A+M,E+n[d]*M,A,E)}}var Ln=["left","center","right"],Ee=new Map,Eo=4096;function wo(t,a,i,c){return t<<24|a<<16|i<<8|c}function q(t,a,i,c){let b=wo(t,a,i,c),n=Ee.get(b);return n||(n=`rgba(${t},${a},${i},${(c/255).toFixed(3)})`,Ee.size>=Eo&&Ee.clear(),Ee.set(b,n),n)}var we=new TextDecoder;function qt(t,a){return Math.round(t*a)/a}var Fe=new Map;function Re(t,a){let i=Fe.get(a);if(i!==void 0)return i;let c=t.font,b=t.textBaseline;t.font=a,t.textBaseline="alphabetic";let n=t.measureText("0"),d=n.actualBoundingBoxAscent||0,A=n.actualBoundingBoxDescent||0;return i=(d-A)/2,(!Number.isFinite(i)||i===0)&&(i=(parseFloat(a)||11)*.35),Fe.size>=256&&Fe.clear(),Fe.set(a,i),t.font=c,t.textBaseline=b,i}var xn=new WeakMap;function Fo(t,a,i,c,b){let n=xn.get(t);n||(n=new Map,xn.set(t,n));let d=Math.round(a),A=`${d}|${i}|${c}|${b}`,E=n.get(A);if(E)return E;let o=-d*.25,r=-d*.25,e=t.createRadialGradient(o,r,d*.08,0,0,d);e.addColorStop(0,c),e.addColorStop(1,i);let M=null;b&&(M=t.createRadialGradient(0,0,d*.85,0,0,d*1.2),M.addColorStop(0,b),M.addColorStop(1,b.replace(/[\d.]+\)$/,"0)")));let O=d*.2,x=t.createRadialGradient(o,r,0,o,r,O);return x.addColorStop(0,"rgba(255,255,255,0.22)"),x.addColorStop(1,"rgba(255,255,255,0)"),E={body:e,glow:M,spec:x,hlX:o,hlY:r,specR:O},n.set(A,E),E}function at(t,a,i){let c=Math.max(1,Math.round(a*i)),b=Math.round(t*i)/i;return c&1?b+.5/i:b}function xt(t,a,i,c,b){let n=Math.round(t*b),d=Math.round(a*b),A=Math.round((t+i)*b),E=Math.round((a+c)*b);return{x:n/b,y:d/b,w:(A-n)/b,h:(E-d)/b}}function Ro(t,a,i,c,b){return{x:Math.round(t*b)/b,y:Math.round(a*b)/b,w:Math.max(1,Math.round(i*b))/b,h:Math.max(1,Math.round(c*b))/b}}function Ze(t,a,i,c,b){let n=Math.round(a*b),d=Math.round((a+c)*b);return{x:t,y:n/b,w:i,h:(d-n)/b}}function Dn(t,a,i,c,b=null,n=null,d=null,A=null){let E=a.buffer;if(i+c>E.byteLength)return;let o=new DataView(E,i,c),r=new Uint8Array(E,i,c),e=0,M="",O="",x=-1,z="",g=Math.max(1,Math.abs(t.getTransform?.().a||Me())),tt=null,nt=[],B=A&&A.geom&&A.geom.available?A.geom:null,U=t,R=!1,$="";for(;e<c;){let j=r[e];if(e+=1,j===X.END_FRAME)break;switch(j){case X.FILL_RECT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];if(e+=4,B){B.rect(f,s,l,u,h,m,y,v,0,0,0,0,0,0,0);break}let p=q(h,m,y,v);p!==M&&(t.fillStyle=p,M=p);let F=xt(f,s,l,u,g);t.fillRect(F.x,F.y,F.w,F.h);break}case X.FILL_RECT_SMOOTH_X:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];if(e+=4,B){B.rect(f,s,l,u,h,m,y,v,0,0,0,0,0,0,1);break}let p=q(h,m,y,v);p!==M&&(t.fillStyle=p,M=p);let F=Ze(f,s,l,u,g);t.fillRect(F.x,F.y,F.w,F.h);break}case X.FILL_ELLIPSE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];if(e+=4,B){B.rect(f-l,s-u,l*2,u*2,h,m,y,v,-1,0,0,0,0,0,2);break}let p=q(h,m,y,v);p!==M&&(t.fillStyle=p,M=p),t.beginPath(),t.ellipse(f,s,Math.max(l,.1),Math.max(u,.1),0,0,Math.PI*2),t.fill();break}case X.FILL_ROUND_RECT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];e+=4;let p=o.getFloat32(e,!0);if(e+=4,B){B.rect(f,s,l,u,h,m,y,v,p,0,0,0,0,0,0);break}let F=q(h,m,y,v);F!==M&&(t.fillStyle=F,M=F);let T=xt(f,s,l,u,g),w=Math.min(p,T.w*.5,T.h*.5);w<=.5?t.fillRect(T.x,T.y,T.w,T.h):(t.beginPath(),t.moveTo(T.x+w,T.y),t.lineTo(T.x+T.w-w,T.y),t.arcTo(T.x+T.w,T.y,T.x+T.w,T.y+w,w),t.lineTo(T.x+T.w,T.y+T.h-w),t.arcTo(T.x+T.w,T.y+T.h,T.x+T.w-w,T.y+T.h,w),t.lineTo(T.x+w,T.y+T.h),t.arcTo(T.x,T.y+T.h,T.x,T.y+T.h-w,w),t.lineTo(T.x,T.y+w),t.arcTo(T.x,T.y,T.x+w,T.y,w),t.closePath(),t.fill());break}case X.STROKE_RECT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];e+=4;let p=o.getFloat32(e,!0);if(e+=4,B){let P=p*.5;B.rect(f-P,s-P,l+p,u+p,0,0,0,0,0,p,h,m,y,v,0);break}let F=q(h,m,y,v);F!==O&&(t.strokeStyle=F,O=F),p!==x&&(t.lineWidth=p,x=p);let T=at(f,p,g),w=at(s,p,g),L=Math.round(l*g)/g,S=Math.round(u*g)/g;t.strokeRect(T,w,L,S);break}case X.LINE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];e+=4;let p=o.getFloat32(e,!0);if(e+=4,B){B.seg(f,s,l,u,h,m,y,v,p,0,0);break}let F=q(h,m,y,v);t.beginPath(),F!==O&&(t.strokeStyle=F,O=F),p!==x&&(t.lineWidth=p,x=p),t.setLineDash([]),t.moveTo(at(f,p,g),at(s,p,g)),t.lineTo(at(l,p,g),at(u,p,g)),t.stroke();break}case X.CANDLE:case X.CANDLE_BORDERED:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getFloat32(e,!0);e+=4;let m=o.getFloat32(e,!0);e+=4;let y=o.getFloat32(e,!0);e+=4;let v=o.getFloat32(e,!0);e+=4;let p=r[e+3],F=q(r[e],r[e+1],r[e+2],p);e+=4;let T=r[e+3],w=q(r[e],r[e+1],r[e+2],T);e+=4;let L=null;j===X.CANDLE_BORDERED&&(L=q(r[e],r[e+1],r[e+2],r[e+3]),e+=4);let S=Math.max(1,Math.floor(y*g)),P=Math.max(1,Math.floor(v*g));S>P&&(S=P);let W=Math.min(Math.max(1,Math.floor(m*g)),P);W<S?W=S:(W^S)&1&&(W-=1);let I=f*g,N=S&1?Math.round(I-.5)+.5:Math.round(I),D=Math.max(1,Math.round(g)),H=Math.round(Math.min(u,h)*g),Y=Math.max(H+D,Math.round(Math.max(u,h)*g)),J=Math.round(Math.min(s,l)*g),C=Math.max(J+1,Math.round(Math.max(s,l)*g)),Z=Math.min(s,l),Gt=Math.max(s,l),ae=Math.min(u,h),ie=Math.max(u,h);if(Z<ae&&J>=H&&(J=H-1),Gt>ie&&C<=Y&&(C=Y+1),T>0&&(J<H||C>Y)){w!==M&&(t.fillStyle=w,M=w);let se=(N-S/2)/g,le=S/g;p===255?t.fillRect(se,J/g,le,(C-J)/g):(J<H&&t.fillRect(se,J/g,le,(H-J)/g),C>Y&&t.fillRect(se,Y/g,le,(C-Y)/g))}let rt=N-W/2,ft=Y-H;if(L===null){p>0&&(F!==M&&(t.fillStyle=F,M=F),t.fillRect(rt/g,H/g,W/g,ft/g));break}let it=Math.max(1,Math.floor(g));if(L!==M&&(t.fillStyle=L,M=L),W<=2*it||ft<=2*it){t.fillRect(rt/g,H/g,W/g,ft/g);break}p===255?t.fillRect(rt/g,H/g,W/g,ft/g):(t.fillRect(rt/g,H/g,W/g,it/g),t.fillRect(rt/g,(Y-it)/g,W/g,it/g),t.fillRect(rt/g,(H+it)/g,it/g,(ft-2*it)/g),t.fillRect((rt+W-it)/g,(H+it)/g,it/g,(ft-2*it)/g)),p>0&&(F!==M&&(t.fillStyle=F,M=F),t.fillRect((rt+it)/g,(H+it)/g,(W-2*it)/g,(ft-2*it)/g));break}case X.OHLC_BAR:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getFloat32(e,!0);e+=4;let m=o.getFloat32(e,!0);e+=4;let y=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let v=r[e];e+=1;let p=Math.max(1,Math.floor(m*g)),F=Math.max(1,Math.floor(g)),T=v&1?F:Math.max(F,Math.floor(p/6));T>p&&(T=p);let w=f*g,S=(T&1?Math.round(w-.5)+.5:Math.round(w))-T/2,P=Math.round(Math.min(l,u)*g),W=Math.max(P+1,Math.round(Math.max(l,u)*g));y!==M&&(t.fillStyle=y,M=y),t.fillRect(S/g,P/g,T/g,(W-P)/g);let I=Math.floor((Math.floor(p*.8)-T)/2);if(I>=1){if(!(v&2)){let D=Math.round(s*g-T/2);t.fillRect((S-I)/g,D/g,I/g,T/g)}let N=Math.round(h*g-T/2);t.fillRect((S+T)/g,N/g,I/g,T/g)}break}case X.DASHED_LINE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];e+=4;let p=o.getFloat32(e,!0);e+=4;let F=o.getFloat32(e,!0);e+=4;let T=o.getFloat32(e,!0);if(e+=4,B){B.seg(f,s,l,u,h,m,y,v,p,F,T);break}let w=q(h,m,y,v);t.beginPath(),w!==O&&(t.strokeStyle=w,O=w),p!==x&&(t.lineWidth=p,x=p),t.setLineDash([F,T]),t.moveTo(at(f,p,g),at(s,p,g)),t.lineTo(at(l,p,g),at(u,p,g)),t.stroke(),t.setLineDash([]);break}case X.LINEAR_POLYLINE:{let f=o.getUint16(e,!0);e+=2;let s=r[e],l=r[e+1],u=r[e+2],h=r[e+3];e+=4;let m=o.getFloat32(e,!0);if(e+=4,B){let v=0,p=0;for(let F=0;F<f;F++){let T=o.getFloat32(e,!0),w=o.getFloat32(e+4,!0);e+=8,F>0&&B.seg(v,p,T,w,s,l,u,h,m,0,0),v=T,p=w}break}let y=q(s,l,u,h);if(f>1){t.beginPath(),y!==O&&(t.strokeStyle=y,O=y),m!==x&&(t.lineWidth=m,x=m),t.setLineDash([]),t.lineJoin="miter",t.lineCap="butt",t.miterLimit=10;let v=o.getFloat32(e,!0);e+=4;let p=o.getFloat32(e,!0);e+=4,t.moveTo(v,p);for(let F=1;F<f;F++)t.lineTo(o.getFloat32(e,!0),o.getFloat32(e+4,!0)),e+=8;t.stroke()}else e+=f*8;break}case X.SMOOTH_POLYLINE:{let f=o.getUint16(e,!0);e+=2;let s=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let l=o.getFloat32(e,!0);if(e+=4,f>1){let u=new Float32Array(f*2);for(let h=0;h<f;h++)u[h*2]=o.getFloat32(e,!0),e+=4,u[h*2+1]=o.getFloat32(e,!0),e+=4;t.beginPath(),s!==O&&(t.strokeStyle=s,O=s),l!==x&&(t.lineWidth=l,x=l),t.setLineDash([]),t.lineJoin="round",t.lineCap="round",f===2?(t.moveTo(u[0],u[1]),t.lineTo(u[2],u[3])):(Je(u,f),t.moveTo(u[0],u[1]),Sn(t,u,f)),t.stroke()}else e+=f*8;break}case X.POLYLINE:{let f=o.getUint16(e,!0);e+=2;let s=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let l=o.getFloat32(e,!0);if(e+=4,f>0){let u=new Float32Array(f*2);for(let h=0;h<f;h++)u[h*2]=o.getFloat32(e,!0),e+=4,u[h*2+1]=o.getFloat32(e,!0),e+=4;if(t.beginPath(),s!==O&&(t.strokeStyle=s,O=s),l!==x&&(t.lineWidth=l,x=l),t.setLineDash([]),t.lineJoin="round",t.lineCap="round",f===2)t.moveTo(u[0],u[1]),t.lineTo(u[2],u[3]);else{t.moveTo(u[0],u[1]);for(let h=0;h<f-1;h++){let m=h>0?h-1:0,y=h,v=h+1,p=h<f-2?h+2:f-1,F=u[m*2],T=u[m*2+1],w=u[y*2],L=u[y*2+1],S=u[v*2],P=u[v*2+1],W=u[p*2],I=u[p*2+1],N=w+(S-F)/6,D=L+(P-T)/6,H=S-(W-w)/6,Y=P-(I-L)/6;t.bezierCurveTo(N,D,H,Y,S,P)}}t.stroke()}break}case X.TEXT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e];e+=1;let m=o.getUint16(e,!0);e+=2;let y=we.decode(new Uint8Array(a.buffer,i+e,m));e+=m,l!==M&&(t.fillStyle=l,M=l);let v=`${Math.round(u)}px "IBM Plex Mono",monospace`;v!==z&&(t.font=v,z=v),t.textAlign=Ln[h]||"left",t.textBaseline="alphabetic";let p=s+Re(t,v);t.fillText(y,qt(f,g),qt(p,g));break}case X.STYLED_TEXT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e];e+=1;let m=r[e];e+=1;let y=o.getUint16(e,!0);e+=2;let v=we.decode(new Uint8Array(a.buffer,i+e,y));e+=y,l!==M&&(t.fillStyle=l,M=l);let p=m&2?"italic ":"",F=m&1?"700 ":"",T=`${p}${F}${Math.round(u)}px "IBM Plex Mono",monospace`;T!==z&&(t.font=T,z=T),t.textAlign=Ln[h]||"left",t.textBaseline="alphabetic";let w=s+Re(t,T);t.fillText(v,qt(f,g),qt(w,g));break}case X.CIRCLE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=r[e],h=r[e+1],m=r[e+2],y=r[e+3],v=B?"":q(u,h,m,y);e+=4;let p=r[e],F=r[e+1],T=r[e+2],w=r[e+3],L=B?"":q(p,F,T,w);e+=4;let S=o.getFloat32(e,!0);if(e+=4,B){B.disc(f,s,l,u,h,m,y,p,F,T,w,0,0,0,0,S,0);break}t.beginPath(),t.arc(f,s,l,0,Math.PI*2),v!==M&&(t.fillStyle=v,M=v),t.fill(),S>0&&(L!==O&&(t.strokeStyle=L,O=L),S!==x&&(t.lineWidth=S,x=S),t.stroke());break}case X.TRIANGLE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getFloat32(e,!0);e+=4;let m=o.getFloat32(e,!0);e+=4;let y=r[e],v=r[e+1],p=r[e+2],F=r[e+3];if(e+=4,B){B.tri(f,s,l,u,h,m,y,v,p,F);break}let T=q(y,v,p,F);t.beginPath(),t.moveTo(f,s),t.lineTo(l,u),t.lineTo(h,m),t.closePath(),T!==M&&(t.fillStyle=T,M=T),t.fill();break}case X.SAVE:{t.save(),nt.push(tt);break}case X.RESTORE:{t.restore(),tt=nt.length?nt.pop():null,B&&B.setClip(tt),M="",O="",x=-1,z="";break}case X.CLIP_RECT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=xt(f,s,l,u,g);t.beginPath(),t.rect(h.x,h.y,h.w,h.h),t.clip(),tt=h,B&&B.setClip(h);break}case X.ROTATED_TEXT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getFloat32(e,!0);e+=4;let m=o.getUint16(e,!0);e+=2;let y=we.decode(r.subarray(e,e+m));e+=m;let v=`${u}px sans-serif`;v!==z&&(t.font=v,z=v),l!==M&&(t.fillStyle=l,M=l),t.textAlign="center",t.textBaseline="alphabetic";let p=Re(t,v);t.save(),t.translate(f,s),t.rotate(h),t.fillText(y,0,p),t.restore();break}case X.BUBBLE_PIE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e],m=r[e+1],y=r[e+2],v=r[e+3];e+=4;let p=r[e],F=r[e+1],T=r[e+2],w=r[e+3];e+=4;let L=r[e]!==0;if(e+=1,B){B.pie(f,s,l,u,h,m,y,v,p,F,T,w,L);break}Rn(t,f,s,l,u,h,m,y,v,p,F,T,w,L),M="";break}case X.BUBBLE_3D:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=r[e],h=r[e+1],m=r[e+2],y=r[e+3];e+=4;let v=r[e],p=r[e+1],F=r[e+2],T=r[e+3];e+=4;let w=r[e],L=r[e+1],S=r[e+2],P=r[e+3];e+=4;let W=o.getFloat32(e,!0);e+=4;let I=l;if(B){B.disc(f,s,I,u,h,m,y,w,L,S,P,v,p,F,T,W,I<4?0:1);break}if(I<4){let N=`rgba(${u},${h},${m},${(y/255).toFixed(3)})`;t.beginPath(),t.arc(f,s,I,0,Math.PI*2),t.fillStyle=N,t.fill(),M=""}else{let N=Math.round(I),D=I>=6,H=I>=16,Y=`rgba(${u},${h},${m},${(y/255).toFixed(3)})`,J=`rgba(${v},${p},${F},${(T/255).toFixed(3)})`,C=H?`rgba(${w},${L},${S},${(P/255*.5).toFixed(3)})`:null,Z=Fo(t,N,Y,J,C);t.save(),t.translate(f,s),H&&Z.glow&&(t.beginPath(),t.arc(0,0,N*1.2,0,Math.PI*2),t.fillStyle=Z.glow,t.fill()),t.beginPath(),t.arc(0,0,N,0,Math.PI*2),t.fillStyle=Z.body,t.fill(),D&&(t.beginPath(),t.arc(Z.hlX,Z.hlY,Z.specR,0,Math.PI*2),t.fillStyle=Z.spec,t.fill()),t.restore(),M=""}break}case X.FILL_POLYGON:{let f=o.getUint16(e,!0);e+=2;let s=r[e],l=r[e+1],u=r[e+2],h=r[e+3];if(e+=4,B){let y=yo(f*2);for(let v=0;v<f;v++)y[v*2]=o.getFloat32(e,!0),y[v*2+1]=o.getFloat32(e+4,!0),e+=8;B.poly(y,f,s,l,u,h);break}let m=q(s,l,u,h);if(f>2){t.beginPath();let y=o.getFloat32(e,!0);e+=4;let v=o.getFloat32(e,!0);e+=4,t.moveTo(y,v);for(let p=1;p<f;p++)t.lineTo(o.getFloat32(e,!0),o.getFloat32(e+4,!0)),e+=8;t.closePath(),m!==M&&(t.fillStyle=m,M=m),t.fill()}else e+=f*8;break}case X.FILL_SMOOTH_BAND:{let f=o.getUint16(e,!0);e+=2;let s=o.getUint16(e,!0);e+=2;let l=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let u=new Float32Array(f*2);for(let m=0;m<f;m++)u[m*2]=o.getFloat32(e,!0),e+=4,u[m*2+1]=o.getFloat32(e,!0),e+=4;let h=new Float32Array(s*2);for(let m=0;m<s;m++)h[m*2]=o.getFloat32(e,!0),e+=4,h[m*2+1]=o.getFloat32(e,!0),e+=4;f>=2&&s>=2&&(t.beginPath(),l!==M&&(t.fillStyle=l,M=l),f===2?(t.moveTo(u[0],u[1]),t.lineTo(u[2],u[3])):(Je(u,f),t.moveTo(u[0],u[1]),Sn(t,u,f)),t.lineTo(h[(s-1)*2],h[(s-1)*2+1]),s===2?t.lineTo(h[0],h[1]):(Je(h,s),_o(t,h,s)),t.closePath(),t.fill());break}case X.DASHED_POLYLINE:{let f=o.getUint16(e,!0);e+=2;let s=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getFloat32(e,!0);if(e+=4,f>1){t.beginPath(),s!==O&&(t.strokeStyle=s,O=s),l!==x&&(t.lineWidth=l,x=l),t.setLineDash([u,h]),t.lineJoin="round";let m=o.getFloat32(e,!0);e+=4;let y=o.getFloat32(e,!0);e+=4,t.moveTo(m,y);for(let v=1;v<f;v++)t.lineTo(o.getFloat32(e,!0),o.getFloat32(e+4,!0)),e+=8;t.stroke(),t.setLineDash([])}else e+=f*8;break}case X.GRADIENT_RECT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let m=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let y=xt(f,s,l,u,g),v=t.createLinearGradient(y.x,y.y,y.x,y.y+y.h);v.addColorStop(0,h),v.addColorStop(1,m),t.fillStyle=v,M="",t.fillRect(y.x,y.y,y.w,y.h);break}case X.GRADIENT_RECT_H:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let m=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let y=xt(f,s,l,u,g),v=t.createLinearGradient(y.x,y.y,y.x+y.w,y.y);v.addColorStop(0,h),v.addColorStop(1,m),t.fillStyle=v,M="",t.fillRect(y.x,y.y,y.w,y.h);break}case X.GRADIENT_RECT_H_MULTI:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=r[e];e+=1;let m=xt(f,s,l,u,g),y=t.createLinearGradient(m.x,m.y,m.x+m.w,m.y);for(let v=0;v<h;v++){let p=o.getFloat32(e,!0);e+=4;let F=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4,y.addColorStop(p<0?0:p>1?1:p,F)}t.fillStyle=y,M="",t.fillRect(m.x,m.y,m.w,m.h);break}case X.BEGIN_HEATMAP_LAYER:{let f=e-1,s=o.getUint32(e,!0);e+=4;let l=o.getUint32(e,!0);e+=4;let u=o.getUint32(e,!0);if(e+=4,!b||u===0)break;let h=U.canvas.width,m=U.canvas.height,y=`${s}|${l}|${h}|${m}|${g}`;if(b.getKey()===y&&b.getCanvas()){let v=h/g,p=m/g;U.drawImage(b.getCanvas(),0,0,v,p),e=f+u}else{let v=Math.min(g,mo),p=Math.max(1,Math.round(h/g*v)),F=Math.max(1,Math.round(m/g*v)),T=b.ensureSize(p,F,v);if(!T)break;T.save(),T.setTransform(1,0,0,1,0,0),T.clearRect(0,0,p,F),T.restore(),t=T,M="",O="",x=-1,z="",R=!0,$=y}break}case X.END_HEATMAP_LAYER:{if(!R)break;let f=U.canvas.width/g,s=U.canvas.height/g;U.drawImage(b.getCanvas(),0,0,f,s),b.setKey($),t=U,M="",O="",x=-1,z="",R=!1,$="";break}case X.HEATMAP_BITMAP:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getUint32(e,!0);e+=4;let u=o.getUint32(e,!0);e+=4;let h=l*u*4;if(e+h>r.byteLength){e=r.byteLength;break}let m=new Uint8ClampedArray(r.buffer,r.byteOffset+e,h);e+=h;let y=new ImageData(m,l,u),v=go(l,u);if(!v)break;v.putImageData(y,0,0),t.drawImage(Nt,f,s,l,u);break}case X.HEATMAP_WORLD:{let f=o.getUint32(e,!0);e+=4;let s=o.getUint32(e,!0);e+=4;let l=o.getUint32(e,!0);e+=4;let u=o.getUint32(e,!0);e+=4;let h=o.getUint32(e,!0);e+=4;let m=o.getUint32(e,!0);e+=4;let y=o.getFloat32(e,!0);e+=4;let v=o.getFloat32(e,!0);e+=4;let p=o.getFloat32(e,!0);e+=4;let F=o.getFloat32(e,!0);e+=4;let T=o.getFloat32(e,!0);e+=4;let w=o.getFloat32(e,!0);e+=4;let L=o.getFloat32(e,!0);e+=4;let S=o.getFloat32(e,!0);e+=4;let P=r[e];e+=1;let W=(P&1)!==0,I=h*m*4;if(e+I>r.byteLength){e=r.byteLength;break}if(!n||f===0||s===0){e+=I;break}let N=n.ensureSize(f,s);if(!N){e+=I;break}if(W&&N.clearRect(0,0,f,s),I>0){let D=new Uint8ClampedArray(r.buffer,r.byteOffset+e,I),H=new ImageData(D,h,m);N.putImageData(H,l,u)}if(e+=I,p>0&&F>0&&L>0&&S>0){let D=Ro(T,w,L,S,g);if(D.w>0&&D.h>0){let H=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(n.getCanvas(),y,v,p,F,D.x,D.y,D.w,D.h),t.imageSmoothingEnabled=H}}break}case X.LINE_WITH_EXTEND:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let m=o.getFloat32(e,!0);e+=4;let y=o.getFloat32(e,!0);e+=4;let v=o.getFloat32(e,!0);e+=4;let p=r[e];e+=1,h!==O&&(t.strokeStyle=h,O=h),m!==x&&(t.lineWidth=m,x=m),t.setLineDash(y>0?[y,v]:[]);let F=1e5,T=f,w=s,L=l,S=u,P=l-f,W=u-s,I=Math.hypot(P,W);if(I>0&&p!==0){let N=P/I,D=W/I;p&1&&(T=f-N*F,w=s-D*F),p&2&&(L=l+N*F,S=u+D*F),p&4&&D<0&&(T=f-N*F,w=s-D*F),p&8&&D>0&&(L=l+N*F,S=u+D*F)}t.beginPath(),t.moveTo(at(T,m,g),at(w,m,g)),t.lineTo(at(L,m,g),at(S,m,g)),t.stroke(),y>0&&t.setLineDash([]);break}case X.LABEL_CALLOUT:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let u=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let h=q(r[e],r[e+1],r[e+2],r[e+3]);e+=4;let m=o.getFloat32(e,!0);e+=4;let y=o.getFloat32(e,!0);e+=4;let v=r[e];e+=1;let p=r[e];e+=1;let F=o.getUint16(e,!0);e+=2;let T=we.decode(r.subarray(e,e+F));e+=F;let w=`${Math.round(m)}px "IBM Plex Mono",monospace`;w!==z&&(t.font=w,z=w);let L=4,S=6,P=T.indexOf(`
|
|
15
|
+
`)>=0?T.split(`
|
|
16
|
+
`):[T],W=Math.round(m),I=3,N=0;for(let rt=0;rt<P.length;rt++){let ft=t.measureText(P[rt]).width;ft>N&&(N=ft)}let D=P.length*W+(P.length-1)*I+L*2,H=Math.ceil(N)+L*2,Y,J;switch(p){case 1:J=s-S-D,Y=f-H/2;break;case 2:J=s+S,Y=f-H/2;break;case 3:J=s-D/2,Y=f+S;break;case 4:J=s-D/2,Y=f-S-H;break;default:J=s-D/2,v===1?Y=f-H/2:v===2?Y=f-H:Y=f;break}let C=xt(Y,J,H,D,g),Z=Math.min(3,C.w*.5,C.h*.5),Gt=()=>{t.beginPath(),Z<=.5?t.rect(C.x,C.y,C.w,C.h):(t.moveTo(C.x+Z,C.y),t.lineTo(C.x+C.w-Z,C.y),t.arcTo(C.x+C.w,C.y,C.x+C.w,C.y+Z,Z),t.lineTo(C.x+C.w,C.y+C.h-Z),t.arcTo(C.x+C.w,C.y+C.h,C.x+C.w-Z,C.y+C.h,Z),t.lineTo(C.x+Z,C.y+C.h),t.arcTo(C.x,C.y+C.h,C.x,C.y+C.h-Z,Z),t.lineTo(C.x,C.y+Z),t.arcTo(C.x,C.y,C.x+Z,C.y,Z)),t.closePath()};if(l!==M&&(t.fillStyle=l,M=l),Gt(),t.fill(),y>0&&(u!==O&&(t.strokeStyle=u,O=u),y!==x&&(t.lineWidth=y,x=y),t.setLineDash([]),Gt(),t.stroke()),p>=1&&p<=4){switch(l!==M&&(t.fillStyle=l,M=l),t.beginPath(),p){case 1:t.moveTo(f-S/2,J+D),t.lineTo(f+S/2,J+D),t.lineTo(f,s);break;case 2:t.moveTo(f-S/2,J),t.lineTo(f+S/2,J),t.lineTo(f,s);break;case 3:t.moveTo(Y,s-S/2),t.lineTo(Y,s+S/2),t.lineTo(f,s);break;case 4:t.moveTo(Y+H,s-S/2),t.lineTo(Y+H,s+S/2),t.lineTo(f,s);break}t.closePath(),t.fill()}h!==M&&(t.fillStyle=h,M=h),t.textAlign="center",t.textBaseline="alphabetic";let ae=Re(t,w),ie=Y+H/2;for(let rt=0;rt<P.length;rt++){let ft=J+L+W/2+rt*(W+I);t.fillText(P[rt],qt(ie,g),qt(ft+ae,g))}break}case X.DRAW_IMAGE:{let f=o.getFloat32(e,!0);e+=4;let s=o.getFloat32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getUint32(e,!0);if(e+=4,!d||h===0||l<=0||u<=0)break;let m=d.get(h);if(!m)break;try{t.drawImage(m,f,s,l,u)}catch(y){d.delete(h),console.warn("[canvasRenderer] drawImage failed for id="+h,y?.message||y)}break}case X.HEATMAP_BG:{let f=r[e],s=r[e+1],l=r[e+2],u=r[e+3],h=r[e+4],m=r[e+5],y=r[e+6],v=r[e+7],p=r[e+8]!==0;e+=9,A&&(t.save(),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.restore(),A.bg(f,s,l,u,h,m,y,v,p));break}case X.HEATMAP_WORLD_INTENSITY:{let f=o.getUint32(e,!0);e+=4;let s=o.getUint32(e,!0);e+=4;let l=o.getUint32(e,!0);e+=4;let u=o.getUint32(e,!0);e+=4;let h=o.getUint32(e,!0);e+=4;let m=o.getUint32(e,!0);e+=4;let y=o.getFloat32(e,!0);e+=4;let v=o.getFloat32(e,!0);e+=4;let p=o.getFloat32(e,!0);e+=4;let F=o.getFloat32(e,!0);e+=4;let T=o.getFloat32(e,!0);e+=4;let w=o.getFloat32(e,!0);e+=4;let L=o.getFloat32(e,!0);e+=4;let S=o.getFloat32(e,!0);e+=4;let P=o.getUint32(e,!0);e+=4;let W=r[e];e+=1;let I=o.getFloat32(e,!0);e+=4;let N=(W&2)!==0,D=(W&4)!==0,H=W&8?1:0,Y=h*m;if(e+Y>r.byteLength){e=r.byteLength;break}if(A){let J=Y>0?new Uint8Array(r.buffer,r.byteOffset+e,Y):null;A.heatmap({worldCols:f,worldRows:s,patchX:l,patchY:u,patchW:h,patchH:m,srcX:y,srcY:v,srcW:p,srcH:F,destX:T,destY:w,destW:L,destH:S,lutSeq:P,hd:N,subpx:D,subTexelX:I,fullRebuild:(W&1)!==0,layer:H,clip:tt},J)}e+=Y;break}case X.OB_HEATMAP:{let f=o.getUint32(e,!0);e+=4;let s=o.getUint32(e,!0);e+=4;let l=o.getFloat32(e,!0);e+=4;let u=o.getFloat32(e,!0);e+=4;let h=o.getFloat32(e,!0);e+=4;let m=o.getFloat32(e,!0);e+=4;let y=r[e],v=r[e+1],p=r[e+2],F=r[e+3];e+=4;let T=o.getFloat32(e,!0);e+=4;let w=o.getUint32(e,!0);e+=4,e+=1;let L=f*s*2;if(e+L>r.byteLength){e=r.byteLength;break}A&&typeof A.obHeatmap=="function"&&A.obHeatmap({cols:f,rows:s,destX:l,destY:u,destW:h,destH:m,bgR:y,bgG:v,bgB:p,bgA:F,alphaMul:T,lutSeq:w},L>0?new Uint8Array(r.buffer,r.byteOffset+e,L):null),e+=L;break}default:e=c;break}}if(R&&b){let j=U.canvas.width/g,f=U.canvas.height/g;U.drawImage(b.getCanvas(),0,0,j,f),b.invalidate()}B&&B.flush()}var tn=new Int32Array(0),en=new Uint8Array(0),nn=new Int32Array(0);function Mo(t){return tn.length<t&&(tn=new Int32Array(t)),tn}function So(t){return en.length<t&&(en=new Uint8Array(t)),en}function Lo(t){return nn.length<t&&(nn=new Int32Array(t)),nn}function Pn(t,a,i,c,b,n,d){let A=0,E=0;for(let R=1;R<a;R++){let $=t[R*2+1];$<t[A*2+1]&&(A=R),$>t[E*2+1]&&(E=R)}if(A===E)return!1;let o=(E-A+a)%a,r=a-o;if(o<1||r<1)return!1;let e=t[A*2+1];for(let R=1;R<=o;R++){let $=t[(A+R)%a*2+1];if($<e-1e-4)return!1;e=$}e=t[A*2+1];for(let R=1;R<=r;R++){let $=t[(A-R+a*2)%a*2+1];if($<e-1e-4)return!1;e=$}let M=0;for(let R=0,$=a-1;R<a;$=R++)M+=t[$*2]*t[R*2+1]-t[R*2]*t[$*2+1];if(M===0)return!1;let O=M>0?1:-1,x=Mo(a),z=So(a),g=0,tt=0,nt=1;for(;tt<=o||nt<=r-1;){let R=tt<=o,$=nt<=r-1,j=R?(A+tt)%a:-1,f=$?(A-nt+a*2)%a:-1,s=R&&(!$||t[j*2+1]<=t[f*2+1]);x[g]=s?j:f,z[g]=s?0:1,g++,s?tt++:nt++}let B=Lo(a),U=0;B[U++]=x[0],B[U++]=x[1];for(let R=2;R<g;R++){let $=x[R],j=t[$*2],f=t[$*2+1];if(z[R]!==z[R-1]){for(;U>1;){let s=B[--U],l=B[U-1];i(j,f,t[s*2],t[s*2+1],t[l*2],t[l*2+1],c,b,n,d)}U=0,B[U++]=x[R-1],B[U++]=$}else{let s=z[R]===0?O:-O;for(;U>1;){let l=B[U-1],u=B[U-2];if(((t[l*2]-t[u*2])*(f-t[l*2+1])-(t[l*2+1]-t[u*2+1])*(j-t[l*2]))*s<=0)break;U--,i(j,f,t[l*2],t[l*2+1],t[u*2],t[u*2+1],c,b,n,d)}B[U++]=$}}return!0}var In=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),zt=32,jt=32,Dt=32,Xt=12,xo=`#version 300 es
|
|
17
|
+
in vec2 aCorner;
|
|
18
|
+
in vec4 aRect; // x, y, w, h \u2014 CSS px
|
|
19
|
+
in vec4 aFill;
|
|
20
|
+
in vec4 aBorder;
|
|
21
|
+
in vec2 aShape; // corner radius, border width \u2014 CSS px
|
|
22
|
+
uniform vec2 uInvSize;
|
|
23
|
+
uniform float uPad;
|
|
24
|
+
out vec4 vFill;
|
|
25
|
+
out vec4 vBorder;
|
|
26
|
+
out vec2 vLocal;
|
|
27
|
+
out vec2 vHalf;
|
|
28
|
+
out float vRadius;
|
|
29
|
+
out float vBorderW;
|
|
30
|
+
void main() {
|
|
31
|
+
vec2 hf = abs(aRect.zw) * 0.5;
|
|
32
|
+
vec2 center = aRect.xy + aRect.zw * 0.5;
|
|
33
|
+
vec2 local = (aCorner - 0.5) * 2.0 * (hf + uPad);
|
|
34
|
+
gl_Position = vec4((center + local) * uInvSize + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
35
|
+
vLocal = local;
|
|
36
|
+
vHalf = hf;
|
|
37
|
+
// Negative radius is the ellipse sentinel \u2014 keep it through to the frag.
|
|
38
|
+
vRadius = aShape.x < 0.0 ? -1.0 : clamp(aShape.x, 0.0, min(hf.x, hf.y));
|
|
39
|
+
vBorderW = aShape.y;
|
|
40
|
+
vFill = aFill;
|
|
41
|
+
vBorder = aBorder;
|
|
42
|
+
}`,Do=`#version 300 es
|
|
43
|
+
precision highp float;
|
|
44
|
+
in vec4 vFill;
|
|
45
|
+
in vec4 vBorder;
|
|
46
|
+
in vec2 vLocal;
|
|
47
|
+
in vec2 vHalf;
|
|
48
|
+
in float vRadius;
|
|
49
|
+
in float vBorderW;
|
|
50
|
+
out vec4 outColor;
|
|
51
|
+
float sdRoundBox(vec2 p, vec2 b, float r) {
|
|
52
|
+
vec2 q = abs(p) - b + r;
|
|
53
|
+
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r;
|
|
54
|
+
}
|
|
55
|
+
// Cheap signed distance to an axis-aligned ellipse. The exact form needs a
|
|
56
|
+
// quartic solve; this gradient-normalised approximation is well inside the
|
|
57
|
+
// ~1 device-px feather the AA below applies, and costs two length() calls.
|
|
58
|
+
float sdEllipse(vec2 p, vec2 r) {
|
|
59
|
+
vec2 rr = max(r, vec2(1e-4));
|
|
60
|
+
float k1 = length(p / rr);
|
|
61
|
+
float k2 = length(p / (rr * rr));
|
|
62
|
+
return (k1 - 1.0) * k1 / max(k2, 1e-6);
|
|
63
|
+
}
|
|
64
|
+
void main() {
|
|
65
|
+
float d = vRadius < 0.0 ? sdEllipse(vLocal, vHalf) : sdRoundBox(vLocal, vHalf, vRadius);
|
|
66
|
+
// fwidth gives a ~1 device-px feather; callers snap rects to the device grid
|
|
67
|
+
// so axis-aligned edges still resolve crisp.
|
|
68
|
+
float aa = max(fwidth(d), 1e-5);
|
|
69
|
+
float inside = 1.0 - smoothstep(-aa, aa, d);
|
|
70
|
+
if (inside <= 0.0) discard;
|
|
71
|
+
vec4 col = vFill;
|
|
72
|
+
if (vBorderW > 0.0) {
|
|
73
|
+
float core = 1.0 - smoothstep(-aa, aa, d + vBorderW);
|
|
74
|
+
col = mix(vBorder, vFill, core);
|
|
75
|
+
}
|
|
76
|
+
outColor = vec4(col.rgb, col.a * inside);
|
|
77
|
+
}`,Po=`#version 300 es
|
|
78
|
+
in vec2 aCorner;
|
|
79
|
+
in vec4 aSeg; // x1, y1, x2, y2 \u2014 CSS px
|
|
80
|
+
in vec4 aColor;
|
|
81
|
+
in vec3 aStyle; // width, dash, gap \u2014 CSS px
|
|
82
|
+
uniform vec2 uInvSize;
|
|
83
|
+
uniform float uMinW;
|
|
84
|
+
uniform float uPad;
|
|
85
|
+
out vec4 vColor;
|
|
86
|
+
out float vAlong;
|
|
87
|
+
out float vOff;
|
|
88
|
+
out float vHalfW;
|
|
89
|
+
out vec2 vDash;
|
|
90
|
+
void main() {
|
|
91
|
+
vec2 d = aSeg.zw - aSeg.xy;
|
|
92
|
+
float len = length(d);
|
|
93
|
+
vec2 dir = len > 1e-6 ? d / len : vec2(1.0, 0.0);
|
|
94
|
+
vec2 nrm = vec2(-dir.y, dir.x);
|
|
95
|
+
float w = max(aStyle.x, uMinW);
|
|
96
|
+
// Feather headroom on the CROSS axis only. Along the length the cap is butt,
|
|
97
|
+
// exactly like Canvas2D \u2014 padding there would overhang the endpoint by a px.
|
|
98
|
+
float ext = w * 0.5 + uPad;
|
|
99
|
+
float off = (aCorner.y - 0.5) * 2.0 * ext;
|
|
100
|
+
float along = aCorner.x * len;
|
|
101
|
+
vec2 pos = aSeg.xy + dir * along + nrm * off;
|
|
102
|
+
gl_Position = vec4(pos * uInvSize + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
103
|
+
vColor = aColor;
|
|
104
|
+
vAlong = along;
|
|
105
|
+
vOff = off;
|
|
106
|
+
vHalfW = w * 0.5;
|
|
107
|
+
vDash = aStyle.yz;
|
|
108
|
+
}`,Bo=`#version 300 es
|
|
109
|
+
precision highp float;
|
|
110
|
+
in vec4 vColor;
|
|
111
|
+
in float vAlong;
|
|
112
|
+
in float vOff;
|
|
113
|
+
in float vHalfW;
|
|
114
|
+
in vec2 vDash;
|
|
115
|
+
out vec4 outColor;
|
|
116
|
+
void main() {
|
|
117
|
+
if (vDash.x > 0.0) {
|
|
118
|
+
float cycle = vDash.x + vDash.y;
|
|
119
|
+
if (cycle > 0.0 && mod(vAlong, cycle) > vDash.x) discard;
|
|
120
|
+
}
|
|
121
|
+
float aa = max(fwidth(vOff), 1e-5);
|
|
122
|
+
float a = 1.0 - smoothstep(vHalfW - aa, vHalfW + aa, abs(vOff));
|
|
123
|
+
if (a <= 0.0) discard;
|
|
124
|
+
outColor = vec4(vColor.rgb, vColor.a * a);
|
|
125
|
+
}`,Io=`#version 300 es
|
|
126
|
+
in vec2 aCorner;
|
|
127
|
+
in vec4 aGeom; // cx, cy, radius, lineWidth \u2014 CSS px
|
|
128
|
+
in vec4 aFill;
|
|
129
|
+
in vec4 aStroke;
|
|
130
|
+
in vec4 aHi;
|
|
131
|
+
in float aMode; // 0 = flat disc, 1 = shaded bubble
|
|
132
|
+
uniform vec2 uInvSize;
|
|
133
|
+
uniform float uPad;
|
|
134
|
+
out vec4 vFill;
|
|
135
|
+
out vec4 vStroke;
|
|
136
|
+
out vec4 vHi;
|
|
137
|
+
out vec2 vLocal;
|
|
138
|
+
out float vRadius;
|
|
139
|
+
out float vLineW;
|
|
140
|
+
out float vMode;
|
|
141
|
+
void main() {
|
|
142
|
+
float ext = aGeom.z + max(aGeom.w, 0.0) + uPad;
|
|
143
|
+
vec2 local = (aCorner - 0.5) * 2.0 * ext;
|
|
144
|
+
gl_Position = vec4((aGeom.xy + local) * uInvSize + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
145
|
+
vLocal = local;
|
|
146
|
+
vRadius = aGeom.z;
|
|
147
|
+
vLineW = aGeom.w;
|
|
148
|
+
vFill = aFill;
|
|
149
|
+
vStroke = aStroke;
|
|
150
|
+
vHi = aHi;
|
|
151
|
+
vMode = aMode;
|
|
152
|
+
}`,Co=`#version 300 es
|
|
153
|
+
precision highp float;
|
|
154
|
+
in vec4 vFill;
|
|
155
|
+
in vec4 vStroke;
|
|
156
|
+
in vec4 vHi;
|
|
157
|
+
in vec2 vLocal;
|
|
158
|
+
in float vRadius;
|
|
159
|
+
in float vLineW;
|
|
160
|
+
in float vMode;
|
|
161
|
+
out vec4 outColor;
|
|
162
|
+
void main() {
|
|
163
|
+
float d = length(vLocal) - vRadius;
|
|
164
|
+
float aa = max(fwidth(d), 1e-5);
|
|
165
|
+
float inside = 1.0 - smoothstep(-aa, aa, d);
|
|
166
|
+
if (inside <= 0.0) discard;
|
|
167
|
+
if (vMode > 1.5) {
|
|
168
|
+
// Pie bubble (2 lit, 3 flat): buy wedge centred at the top, ratio in vLineW,
|
|
169
|
+
// buy in vFill, sell in vHi \u2014 the reference bubble.frag.
|
|
170
|
+
vec2 uv = vLocal / max(vRadius, 1e-4);
|
|
171
|
+
float dist = length(uv);
|
|
172
|
+
float buy = clamp(vLineW, 0.0, 1.0);
|
|
173
|
+
float fromTop = abs((atan(uv.x, -uv.y) + 3.14159265) / 6.28318531 - 0.5);
|
|
174
|
+
float halfW = buy * 0.5;
|
|
175
|
+
bool isBuy = fromTop <= halfW;
|
|
176
|
+
vec4 side = isBuy ? vFill : vHi;
|
|
177
|
+
vec3 base = side.rgb;
|
|
178
|
+
if (buy > 0.001 && buy < 0.999) {
|
|
179
|
+
base = mix(base, vec3(0.08), smoothstep(0.025, 0.0, abs(fromTop - halfW)) * 0.5);
|
|
180
|
+
}
|
|
181
|
+
vec3 col3 = base;
|
|
182
|
+
if (vMode < 2.5) {
|
|
183
|
+
vec3 n = vec3(uv, sqrt(max(0.0, 1.0 - dist * dist)));
|
|
184
|
+
vec3 L = vec3(0.2591605, 0.4319342, 0.8638684);
|
|
185
|
+
float diff = max(dot(n, L), 0.0);
|
|
186
|
+
float spec = pow(max(dot(reflect(-L, n), vec3(0.0, 0.0, 1.0)), 0.0), 32.0);
|
|
187
|
+
col3 = base * (0.35 + 0.65 * diff) + vec3(spec * 0.35);
|
|
188
|
+
}
|
|
189
|
+
float a = 0.82 * side.a * (1.0 - smoothstep(0.96, 1.0, dist)) * inside;
|
|
190
|
+
outColor = vec4(col3, a);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
vec4 col = vFill;
|
|
194
|
+
if (vMode > 0.5) {
|
|
195
|
+
// Lambert-ish sheen from the upper-left, so a large print reads as a
|
|
196
|
+
// sphere rather than a flat dot (mirrors the Canvas2D Bubble3D gradient).
|
|
197
|
+
vec2 n = vLocal / max(vRadius, 1e-4);
|
|
198
|
+
float h = clamp(dot(normalize(vec2(-0.45, -0.55)), n) * 0.5 + 0.5, 0.0, 1.0);
|
|
199
|
+
col.rgb = mix(col.rgb, vHi.rgb, pow(h, 2.2) * vHi.a);
|
|
200
|
+
}
|
|
201
|
+
if (vLineW > 0.0) {
|
|
202
|
+
float core = 1.0 - smoothstep(-aa, aa, d + vLineW);
|
|
203
|
+
col = mix(vStroke, col, core);
|
|
204
|
+
}
|
|
205
|
+
outColor = vec4(col.rgb, col.a * inside);
|
|
206
|
+
}`,ko=`#version 300 es
|
|
207
|
+
in vec2 aPos;
|
|
208
|
+
in vec4 aColor;
|
|
209
|
+
uniform vec2 uInvSize;
|
|
210
|
+
out vec4 vColor;
|
|
211
|
+
void main() {
|
|
212
|
+
gl_Position = vec4(aPos * uInvSize + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
213
|
+
vColor = aColor;
|
|
214
|
+
}`,Uo=`#version 300 es
|
|
215
|
+
precision highp float;
|
|
216
|
+
in vec4 vColor;
|
|
217
|
+
out vec4 outColor;
|
|
218
|
+
void main() { outColor = vColor; }`;function Bn(t,a,i){let c=t.createShader(a);if(t.shaderSource(c,i),t.compileShader(c),!t.getShaderParameter(c,t.COMPILE_STATUS)){let b=t.getShaderInfoLog(c);throw t.deleteShader(c),new Error(`shader compile failed: ${b}`)}return c}function Se(t,a,i){let c=Bn(t,t.VERTEX_SHADER,a),b=Bn(t,t.FRAGMENT_SHADER,i),n=t.createProgram();if(t.attachShader(n,c),t.attachShader(n,b),t.linkProgram(n),t.deleteShader(c),t.deleteShader(b),!t.getProgramParameter(n,t.LINK_STATUS)){let d=t.getProgramInfoLog(n);throw t.deleteProgram(n),new Error(`program link failed: ${d}`)}return n}function Tt(t,a,i,c,b,n=t.FLOAT,d=!1){a<0||(t.enableVertexAttribArray(a),t.vertexAttribPointer(a,i,n,d,c,b),t.vertexAttribDivisor(a,1))}function Cn(t,a){let i=(()=>{let d=Se(t,xo,Do),A=t.createBuffer(),E=t.createVertexArray();t.bindVertexArray(E);let o=t.getAttribLocation(d,"aCorner");return t.bindBuffer(t.ARRAY_BUFFER,a),t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,8,0),t.bindBuffer(t.ARRAY_BUFFER,A),Tt(t,t.getAttribLocation(d,"aRect"),4,zt,0),Tt(t,t.getAttribLocation(d,"aFill"),4,zt,16,t.UNSIGNED_BYTE,!0),Tt(t,t.getAttribLocation(d,"aBorder"),4,zt,20,t.UNSIGNED_BYTE,!0),Tt(t,t.getAttribLocation(d,"aShape"),2,zt,24),t.bindVertexArray(null),{prog:d,vbo:A,vao:E,uInvSize:t.getUniformLocation(d,"uInvSize"),uPad:t.getUniformLocation(d,"uPad")}})(),c=(()=>{let d=Se(t,Po,Bo),A=t.createBuffer(),E=t.createVertexArray();t.bindVertexArray(E);let o=t.getAttribLocation(d,"aCorner");return t.bindBuffer(t.ARRAY_BUFFER,a),t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,8,0),t.bindBuffer(t.ARRAY_BUFFER,A),Tt(t,t.getAttribLocation(d,"aSeg"),4,jt,0),Tt(t,t.getAttribLocation(d,"aColor"),4,jt,16,t.UNSIGNED_BYTE,!0),Tt(t,t.getAttribLocation(d,"aStyle"),3,jt,20),t.bindVertexArray(null),{prog:d,vbo:A,vao:E,uInvSize:t.getUniformLocation(d,"uInvSize"),uMinW:t.getUniformLocation(d,"uMinW"),uPad:t.getUniformLocation(d,"uPad")}})(),b=(()=>{let d=Se(t,Io,Co),A=t.createBuffer(),E=t.createVertexArray();t.bindVertexArray(E);let o=t.getAttribLocation(d,"aCorner");return t.bindBuffer(t.ARRAY_BUFFER,a),t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,8,0),t.bindBuffer(t.ARRAY_BUFFER,A),Tt(t,t.getAttribLocation(d,"aGeom"),4,Dt,0),Tt(t,t.getAttribLocation(d,"aFill"),4,Dt,16,t.UNSIGNED_BYTE,!0),Tt(t,t.getAttribLocation(d,"aStroke"),4,Dt,20,t.UNSIGNED_BYTE,!0),Tt(t,t.getAttribLocation(d,"aHi"),4,Dt,24,t.UNSIGNED_BYTE,!0),Tt(t,t.getAttribLocation(d,"aMode"),1,Dt,28),t.bindVertexArray(null),{prog:d,vbo:A,vao:E,uInvSize:t.getUniformLocation(d,"uInvSize"),uPad:t.getUniformLocation(d,"uPad")}})(),n=(()=>{let d=Se(t,ko,Uo),A=t.createBuffer(),E=t.createVertexArray();t.bindVertexArray(E),t.bindBuffer(t.ARRAY_BUFFER,A);let o=t.getAttribLocation(d,"aPos");t.enableVertexAttribArray(o),t.vertexAttribPointer(o,2,t.FLOAT,!1,Xt,0);let r=t.getAttribLocation(d,"aColor");return t.enableVertexAttribArray(r),t.vertexAttribPointer(r,4,t.UNSIGNED_BYTE,!0,Xt,8),t.bindVertexArray(null),{prog:d,vbo:A,vao:E,uInvSize:t.getUniformLocation(d,"uInvSize")}})();return{rect:i,seg:c,disc:b,tri:n}}function kn(t,a){if(a){for(let i of[a.rect,a.seg,a.disc,a.tri])if(i){try{t.deleteBuffer(i.vbo)}catch{}try{t.deleteVertexArray(i.vao)}catch{}try{t.deleteProgram(i.prog)}catch{}}}}var Le=0,Un=1,Hn=2,on=3,Nn=4,Ho=1024,rn=65536;function xe(t){return{stride:t,cap:0,n:0,ab:null,f32:null,u8:null}}function On(t,a){let i=t.n+a;if(i<=t.cap)return!0;if(t.n>0&&i>rn)return!1;let c=t.cap||Ho;for(;c<i;)c*=2;if(c>rn&&(c=rn),i>c)return!1;let b=new ArrayBuffer(c*t.stride),n=new Uint8Array(b);return t.u8&&t.n>0&&n.set(t.u8.subarray(0,t.n*t.stride)),t.ab=b,t.u8=n,t.f32=new Float32Array(b),t.cap=c,!0}function Wn(t){let a=null,i=null;try{a=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,a),t.bufferData(t.ARRAY_BUFFER,In,t.STATIC_DRAW),i=Cn(t,a)}catch(s){console.warn("[glVector] program init failed, staying on Canvas2D:",s?.message||s);try{a&&t.deleteBuffer(a)}catch{}return null}let c=xe(zt),b=xe(jt),n=xe(Dt),d=xe(Xt),A=Le,E=null,o=1,r=1,e=1,M=!1,O=0,x=0,z=1;function g(s,l,u){o=s>0?s:1,r=l>0?l:1,e=u>0?u:1,z=1/e+.5}function tt(){let s=t.drawingBufferHeight;if(E&&E.w>0&&E.h>0){let l=Math.round(E.x*e),u=Math.round(E.y*e),h=Math.max(1,Math.round(E.w*e)),m=Math.max(1,Math.round(E.h*e));t.enable(t.SCISSOR_TEST),t.scissor(l,s-(u+m),h,m)}else t.disable(t.SCISSOR_TEST)}function nt(){t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight),t.disable(t.DEPTH_TEST),t.enable(t.BLEND),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),tt()}function B(s,l){t.bindVertexArray(s.vao),t.bindBuffer(t.ARRAY_BUFFER,s.vbo),t.bufferData(t.ARRAY_BUFFER,l.u8.subarray(0,l.n*l.stride),t.DYNAMIC_DRAW),O++,x+=l.n}function U(){if(M||A===Le)return;let s=2/o,l=-2/r;A===Un&&c.n>0?(nt(),t.useProgram(i.rect.prog),t.uniform2f(i.rect.uInvSize,s,l),t.uniform1f(i.rect.uPad,z),B(i.rect,c),t.drawArraysInstanced(t.TRIANGLES,0,6,c.n),c.n=0):A===Hn&&b.n>0?(nt(),t.useProgram(i.seg.prog),t.uniform2f(i.seg.uInvSize,s,l),t.uniform1f(i.seg.uPad,z),t.uniform1f(i.seg.uMinW,1/e),B(i.seg,b),t.drawArraysInstanced(t.TRIANGLES,0,6,b.n),b.n=0):A===on&&n.n>0?(nt(),t.useProgram(i.disc.prog),t.uniform2f(i.disc.uInvSize,s,l),t.uniform1f(i.disc.uPad,z),B(i.disc,n),t.drawArraysInstanced(t.TRIANGLES,0,6,n.n),n.n=0):A===Nn&&d.n>0&&(nt(),t.useProgram(i.tri.prog),t.uniform2f(i.tri.uInvSize,s,l),B(i.tri,d),t.drawArrays(t.TRIANGLES,0,d.n),d.n=0),A=Le,t.bindVertexArray(null),t.disable(t.SCISSOR_TEST)}function R(s,l,u){return!(M||(A!==s&&(U(),A=s),!On(l,u)&&(U(),A=s,!On(l,u))))}function $(s){let l=E;!l&&!s||l&&s&&l.x===s.x&&l.y===s.y&&l.w===s.w&&l.h===s.h||(U(),E=s||null)}function j(s,l,u,h,m,y){return Pn(s,l,f,u,h,m,y)}function f(s,l,u,h,m,y,v,p,F,T){if(!R(Nn,d,3))return;let w=d,L=w.n*3,S=w.n*Xt;w.f32[L]=s,w.f32[L+1]=l,w.u8[S+8]=v,w.u8[S+9]=p,w.u8[S+10]=F,w.u8[S+11]=T,L+=3,S+=Xt,w.f32[L]=u,w.f32[L+1]=h,w.u8[S+8]=v,w.u8[S+9]=p,w.u8[S+10]=F,w.u8[S+11]=T,L+=3,S+=Xt,w.f32[L]=m,w.f32[L+1]=y,w.u8[S+8]=v,w.u8[S+9]=p,w.u8[S+10]=F,w.u8[S+11]=T,w.n+=3}return{available:!0,setSize:g,setClip:$,flush:U,beginFrame(){O=0,x=0},get drawCalls(){return O},get instances(){return x},rect(s,l,u,h,m,y,v,p,F,T,w,L,S,P,W){if(!R(Un,c,1))return;let I=W===1?Ze(s,l,u,h,e):W===2?{x:s,y:l,w:u,h}:xt(s,l,u,h,e),N=c,D=N.n*8,H=N.n*zt;N.f32[D]=I.x,N.f32[D+1]=I.y,N.f32[D+2]=I.w,N.f32[D+3]=I.h,N.u8[H+16]=m,N.u8[H+17]=y,N.u8[H+18]=v,N.u8[H+19]=p,N.u8[H+20]=w,N.u8[H+21]=L,N.u8[H+22]=S,N.u8[H+23]=P,N.f32[D+6]=F<0?-1:F>0?F:0,N.f32[D+7]=T>0?T:0,N.n++},seg(s,l,u,h,m,y,v,p,F,T,w){if(!R(Hn,b,1))return;let L=b,S=L.n*8,P=L.n*jt,W=s===u,I=l===h;L.f32[S]=W?at(s,F,e):s,L.f32[S+1]=I?at(l,F,e):l,L.f32[S+2]=W?at(u,F,e):u,L.f32[S+3]=I?at(h,F,e):h,L.u8[P+16]=m,L.u8[P+17]=y,L.u8[P+18]=v,L.u8[P+19]=p,L.f32[S+5]=F>0?F:1,L.f32[S+6]=T>0?T:0,L.f32[S+7]=w>0?w:0,L.n++},disc(s,l,u,h,m,y,v,p,F,T,w,L,S,P,W,I,N){if(!(u>0)||!R(on,n,1))return;let D=n,H=D.n*8,Y=D.n*Dt;D.f32[H]=s,D.f32[H+1]=l,D.f32[H+2]=u,D.f32[H+3]=I>0?I:0,D.u8[Y+16]=h,D.u8[Y+17]=m,D.u8[Y+18]=y,D.u8[Y+19]=v,D.u8[Y+20]=p,D.u8[Y+21]=F,D.u8[Y+22]=T,D.u8[Y+23]=w,D.u8[Y+24]=L,D.u8[Y+25]=S,D.u8[Y+26]=P,D.u8[Y+27]=W,D.f32[H+7]=N===1?1:0,D.n++},pie(s,l,u,h,m,y,v,p,F,T,w,L,S){if(!(u>0)||!R(on,n,1))return;let P=n,W=P.n*8,I=P.n*Dt;P.f32[W]=s,P.f32[W+1]=l,P.f32[W+2]=u,P.f32[W+3]=h,P.u8[I+16]=m,P.u8[I+17]=y,P.u8[I+18]=v,P.u8[I+19]=p,P.u8[I+20]=0,P.u8[I+21]=0,P.u8[I+22]=0,P.u8[I+23]=0,P.u8[I+24]=F,P.u8[I+25]=T,P.u8[I+26]=w,P.u8[I+27]=L,P.f32[W+7]=S?2:3,P.n++},tri:f,poly(s,l,u,h,m,y){if(!(l<3)){if(l===3){f(s[0],s[1],s[2],s[3],s[4],s[5],u,h,m,y);return}if(!j(s,l,u,h,m,y))for(let v=1;v+1<l;v++)f(s[0],s[1],s[v*2],s[v*2+1],s[(v+1)*2],s[(v+1)*2+1],u,h,m,y)}},destroy(){if(!M){M=!0,A=Le;try{kn(t,i)}catch{}try{a&&t.deleteBuffer(a)}catch{}i=null,a=null;for(let s of[c,b,n,d])s.ab=null,s.f32=null,s.u8=null,s.cap=0,s.n=0}}}}var No=`#version 300 es
|
|
219
|
+
in vec2 aPos;
|
|
220
|
+
void main() { gl_Position = vec4(aPos, 0.0, 1.0); }`,Oo=`#version 300 es
|
|
221
|
+
precision highp float;
|
|
222
|
+
uniform vec4 uTop; // colour at the top of the canvas (0..1, straight alpha)
|
|
223
|
+
uniform vec4 uBot; // colour at the bottom of the canvas
|
|
224
|
+
uniform float uH; // canvas height in device px
|
|
225
|
+
uniform float uDither;
|
|
226
|
+
out vec4 frag;
|
|
227
|
+
// Break 8-bit vertical-gradient banding ("s\u1ECDc ngang" on Windows). Two culprits:
|
|
228
|
+
// 1. ANGLE/D3D interpolates a vertex-colour "varying" at REDUCED precision,
|
|
229
|
+
// so the ramp is already stepped BEFORE any dither \u2014 a \xB11 LSB jitter then
|
|
230
|
+
// only wiggles the existing steps. So we compute the ramp HERE at highp
|
|
231
|
+
// from gl_FragCoord.y (1 = top of canvas, 0 = bottom), giving a full-
|
|
232
|
+
// precision gradient the driver can't pre-quantise.
|
|
233
|
+
// 2. The 8-bit backbuffer write itself bands; macOS/Metal dithers natively,
|
|
234
|
+
// D3D does not. We add per-pixel triangular-PDF noise of \xB11 LSB (1/255)
|
|
235
|
+
// to randomise the rounding. Gated by uDither (0 for a solid bg \u2192 no
|
|
236
|
+
// grain on flat fills). gl_FragCoord.xy makes it screen-stable (no shimmer).
|
|
237
|
+
float _h(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }
|
|
238
|
+
void main() {
|
|
239
|
+
float f = clamp(gl_FragCoord.y / uH, 0.0, 1.0);
|
|
240
|
+
vec3 c = mix(uBot.rgb, uTop.rgb, f);
|
|
241
|
+
float a = mix(uBot.a, uTop.a, f);
|
|
242
|
+
float d = (_h(gl_FragCoord.xy) + _h(gl_FragCoord.xy + 0.5) - 1.0) / 255.0;
|
|
243
|
+
frag = vec4(c + d * uDither, a);
|
|
244
|
+
}`,Wo=`#version 300 es
|
|
245
|
+
in vec2 aPos;
|
|
246
|
+
in vec2 aTex;
|
|
247
|
+
out vec2 vTex;
|
|
248
|
+
void main() { vTex = aTex; gl_Position = vec4(aPos, 0.0, 1.0); }`,Yo=`#version 300 es
|
|
249
|
+
precision highp float;
|
|
250
|
+
in vec2 vTex;
|
|
251
|
+
uniform sampler2D uIntensity;
|
|
252
|
+
uniform sampler2D uLut;
|
|
253
|
+
out vec4 frag;
|
|
254
|
+
void main() {
|
|
255
|
+
// R8 intensity \u2192 0..1 (= baked byte / 255). LUT is 256 wide; pick the exact
|
|
256
|
+
// texel the Canvas2D path used: idx = (byte + 0.5) / 256 with NEAREST. Empty
|
|
257
|
+
// cells bake to 0 and LUT[0].a == 0 (every scheme), so they read transparent
|
|
258
|
+
// \u2014 identical to the Canvas2D (0,0,0,0) path.
|
|
259
|
+
float i = texture(uIntensity, vTex).r;
|
|
260
|
+
float idx = (i * 255.0 + 0.5) / 256.0;
|
|
261
|
+
frag = texture(uLut, vec2(idx, 0.5)); // straight (non-premultiplied) alpha
|
|
262
|
+
}`,Go=`#version 300 es
|
|
263
|
+
precision highp float;
|
|
264
|
+
in vec2 vTex;
|
|
265
|
+
uniform sampler2D uIntensity;
|
|
266
|
+
uniform sampler2D uLut;
|
|
267
|
+
uniform float uShiftX;
|
|
268
|
+
out vec4 frag;
|
|
269
|
+
// texelFetch ignores the sampler filter, so the texture stays NEAREST.
|
|
270
|
+
vec4 _col(int x, int y, ivec2 sz) {
|
|
271
|
+
float i = texelFetch(uIntensity, ivec2(clamp(x, 0, sz.x - 1), y), 0).r;
|
|
272
|
+
vec4 c = texture(uLut, vec2((i * 255.0 + 0.5) / 256.0, 0.5));
|
|
273
|
+
return vec4(c.rgb * c.a, c.a);
|
|
274
|
+
}
|
|
275
|
+
void main() {
|
|
276
|
+
ivec2 sz = textureSize(uIntensity, 0);
|
|
277
|
+
int x = int(floor(vTex.x * float(sz.x)));
|
|
278
|
+
int y = clamp(int(floor(vTex.y * float(sz.y))), 0, sz.y - 1);
|
|
279
|
+
vec4 m = _col(x, y, sz);
|
|
280
|
+
// Uniform branch \u2014 free, and it keeps the zoomed-in path at one fetch.
|
|
281
|
+
if (uShiftX > 0.0) {
|
|
282
|
+
m = mix(m, _col(x + 1, y, sz), uShiftX);
|
|
283
|
+
}
|
|
284
|
+
frag = m.a > 0.002 ? vec4(m.rgb / m.a, m.a) : vec4(0.0);
|
|
285
|
+
}`,zo=`#version 300 es
|
|
286
|
+
in vec3 aPos; // cell-local: x,z \u2208 [0,1]; y = 0 base / 1 top
|
|
287
|
+
in vec3 aNormal; // object-space face normal
|
|
288
|
+
uniform sampler2D uIntensity;
|
|
289
|
+
uniform mat4 uMvp;
|
|
290
|
+
uniform vec4 uSrc; // sx, sy, sw, sh (texels)
|
|
291
|
+
uniform vec2 uTexSize;
|
|
292
|
+
uniform vec2 uGrid; // cells across, cells deep
|
|
293
|
+
uniform vec2 uExtent; // half-size in x (time) and z (price) \u2014 pane aspect
|
|
294
|
+
uniform float uDepth; // world height at full intensity
|
|
295
|
+
uniform vec3 uEye; // camera position, world space
|
|
296
|
+
out float vI;
|
|
297
|
+
out vec3 vN;
|
|
298
|
+
out vec3 vView; // surface \u2192 eye
|
|
299
|
+
void main() {
|
|
300
|
+
float nx = uGrid.x;
|
|
301
|
+
float ny = uGrid.y;
|
|
302
|
+
float cx = mod(float(gl_InstanceID), nx);
|
|
303
|
+
float cy = floor(float(gl_InstanceID) / nx);
|
|
304
|
+
// One sample per CELL (its centre) so the whole box is one flat colour \u2014
|
|
305
|
+
// that is what keeps the edges hard.
|
|
306
|
+
vec2 texel = uSrc.xy + (vec2(cx, cy) + 0.5) / vec2(nx, ny) * uSrc.zw;
|
|
307
|
+
ivec2 ip = ivec2(clamp(texel, vec2(0.0), uTexSize - 1.0));
|
|
308
|
+
float i = texelFetch(uIntensity, ip, 0).r;
|
|
309
|
+
if (i <= 0.0) {
|
|
310
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // off-clip \u21D2 culled, no fragments
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
vI = i;
|
|
314
|
+
// Same layout as 2-D: x = time across the pane, z = price down the pane.
|
|
315
|
+
// Extent matches the pane's aspect so the field IS the chart, not a square
|
|
316
|
+
// floating in it (that square is what got cropped on the sides).
|
|
317
|
+
float h = max(i * uDepth, uDepth * 0.02);
|
|
318
|
+
vec3 w = vec3(
|
|
319
|
+
((cx + aPos.x) / nx * 2.0 - 1.0) * uExtent.x,
|
|
320
|
+
aPos.y * h,
|
|
321
|
+
((cy + aPos.z) / ny * 2.0 - 1.0) * uExtent.y
|
|
322
|
+
);
|
|
323
|
+
vN = aNormal;
|
|
324
|
+
vView = uEye - w;
|
|
325
|
+
gl_Position = uMvp * vec4(w, 1.0);
|
|
326
|
+
}`,Xo=`#version 300 es
|
|
327
|
+
precision highp float;
|
|
328
|
+
in float vI;
|
|
329
|
+
in vec3 vN;
|
|
330
|
+
in vec3 vView;
|
|
331
|
+
uniform sampler2D uLut;
|
|
332
|
+
uniform vec3 uLightDir; // TOWARD the light, world space, normalised
|
|
333
|
+
uniform float uRough; // 0 = mirror, 1 = fully diffuse
|
|
334
|
+
uniform float uMetal; // 0 = dielectric, 1 = metal
|
|
335
|
+
uniform float uAmbient;
|
|
336
|
+
out vec4 frag;
|
|
337
|
+
void main() {
|
|
338
|
+
vec4 c = texture(uLut, vec2((vI * 255.0 + 0.5) / 256.0, 0.5));
|
|
339
|
+
if (c.a <= 0.002) discard; // empty cells stay empty
|
|
340
|
+
vec3 albedo = c.rgb;
|
|
341
|
+
vec3 N = normalize(vN);
|
|
342
|
+
vec3 V = normalize(vView);
|
|
343
|
+
vec3 L = normalize(uLightDir);
|
|
344
|
+
vec3 H = normalize(L + V);
|
|
345
|
+
float ndl = max(dot(N, L), 0.0);
|
|
346
|
+
// Blinn-Phong standing in for a GGX lobe: roughness \u2192 exponent. Cheap, and
|
|
347
|
+
// at this geometry density the difference is not visible.
|
|
348
|
+
float shine = mix(180.0, 4.0, clamp(uRough, 0.0, 1.0));
|
|
349
|
+
float spec = pow(max(dot(N, H), 0.0), shine) * (1.0 - clamp(uRough, 0.0, 1.0));
|
|
350
|
+
// A metal tints its highlight with its own colour and kills the diffuse; a
|
|
351
|
+
// dielectric keeps a white highlight over full diffuse.
|
|
352
|
+
vec3 specTint = mix(vec3(1.0), albedo, clamp(uMetal, 0.0, 1.0));
|
|
353
|
+
vec3 diffuse = albedo * (uAmbient + ndl * (1.0 - 0.65 * clamp(uMetal, 0.0, 1.0)));
|
|
354
|
+
// Rim: a Fresnel-ish edge light so a box reads against the box behind it
|
|
355
|
+
// even when both faces point away from the lamp.
|
|
356
|
+
float rim = pow(1.0 - max(dot(N, V), 0.0), 3.0) * 0.35;
|
|
357
|
+
vec3 col = diffuse + specTint * spec + albedo * rim;
|
|
358
|
+
frag = vec4(clamp(col, 0.0, 1.0), 1.0);
|
|
359
|
+
}`,Vo=224,$o=168,Ko=.14,qo=`#version 300 es
|
|
360
|
+
in vec2 aQuad; // unit quad, \u22121..1
|
|
361
|
+
in vec4 aPrint; // world x, world y, world z, radius (world)
|
|
362
|
+
in float aSide; // +1 buy, \u22121 sell
|
|
363
|
+
uniform mat4 uView;
|
|
364
|
+
uniform mat4 uProj;
|
|
365
|
+
out vec2 vUv;
|
|
366
|
+
out float vSide;
|
|
367
|
+
void main() {
|
|
368
|
+
vec4 eye = uView * vec4(aPrint.xyz, 1.0);
|
|
369
|
+
eye.xy += aQuad * aPrint.w;
|
|
370
|
+
vUv = aQuad;
|
|
371
|
+
vSide = aSide;
|
|
372
|
+
gl_Position = uProj * eye;
|
|
373
|
+
}`,jo=`#version 300 es
|
|
374
|
+
precision highp float;
|
|
375
|
+
in vec2 vUv;
|
|
376
|
+
in float vSide;
|
|
377
|
+
uniform vec3 uBuy;
|
|
378
|
+
uniform vec3 uSell;
|
|
379
|
+
out vec4 frag;
|
|
380
|
+
void main() {
|
|
381
|
+
float r2 = dot(vUv, vUv);
|
|
382
|
+
if (r2 > 1.0) discard; // round, not a square
|
|
383
|
+
// Shade the disc like a sphere: the normal falls out of the quad coords, so
|
|
384
|
+
// a print reads as a bead sitting in the scene rather than a flat dot.
|
|
385
|
+
vec3 n = vec3(vUv, sqrt(max(1.0 - r2, 0.0)));
|
|
386
|
+
vec3 base = vSide >= 0.0 ? uBuy : uSell;
|
|
387
|
+
float ndl = clamp(dot(n, normalize(vec3(-0.4, 0.5, 0.75))), 0.0, 1.0);
|
|
388
|
+
float spec = pow(ndl, 24.0) * 0.5;
|
|
389
|
+
frag = vec4(clamp(base * (0.45 + 0.75 * ndl) + spec, 0.0, 1.0), 1.0);
|
|
390
|
+
}`,Qo=`#version 300 es
|
|
391
|
+
in vec3 aPos;
|
|
392
|
+
uniform mat4 uMvp;
|
|
393
|
+
void main() { gl_Position = uMvp * vec4(aPos, 1.0); }`,Jo=`#version 300 es
|
|
394
|
+
precision highp float;
|
|
395
|
+
uniform vec4 uColor;
|
|
396
|
+
out vec4 frag;
|
|
397
|
+
void main() { frag = uColor; }`,an=8,Zo=`#version 300 es
|
|
398
|
+
precision highp float;
|
|
399
|
+
in vec2 vTex;
|
|
400
|
+
uniform sampler2D uIntensity;
|
|
401
|
+
uniform sampler2D uLut;
|
|
402
|
+
uniform vec2 uTexel; // 1 / texture size
|
|
403
|
+
uniform ivec2 uTaps; // texels collapsing into one pixel, per axis (>= 1)
|
|
404
|
+
out vec4 frag;
|
|
405
|
+
const int MAX_TAPS = ${an};
|
|
406
|
+
void main() {
|
|
407
|
+
vec2 half0 = 0.5 * (vec2(uTaps) - 1.0);
|
|
408
|
+
float m = 0.0;
|
|
409
|
+
// Constant loop bounds + break: a uniform-bounded loop is legal in GLSL ES
|
|
410
|
+
// 3.0 but some drivers handle it badly.
|
|
411
|
+
for (int j = 0; j < MAX_TAPS; ++j) {
|
|
412
|
+
if (j >= uTaps.y) break;
|
|
413
|
+
for (int i = 0; i < MAX_TAPS; ++i) {
|
|
414
|
+
if (i >= uTaps.x) break;
|
|
415
|
+
vec2 o = (vec2(float(i), float(j)) - half0) * uTexel;
|
|
416
|
+
m = max(m, texture(uIntensity, vTex + o).r);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
frag = texture(uLut, vec2((m * 255.0 + 0.5) / 256.0, 0.5));
|
|
420
|
+
}`;function Yn(t,a,i){let c=t.createShader(a);if(t.shaderSource(c,i),t.compileShader(c),!t.getShaderParameter(c,t.COMPILE_STATUS)){let b=t.getShaderInfoLog(c);throw t.deleteShader(c),new Error("shader compile failed: "+b)}return c}function me(t,a,i){let c=Yn(t,t.VERTEX_SHADER,a),b=Yn(t,t.FRAGMENT_SHADER,i),n=t.createProgram();if(t.attachShader(n,c),t.attachShader(n,b),t.linkProgram(n),t.deleteShader(c),t.deleteShader(b),!t.getProgramParameter(n,t.LINK_STATUS)){let d=t.getProgramInfoLog(n);throw t.deleteProgram(n),new Error("program link failed: "+d)}return n}function tr(t,a){let i=new Float32Array(16);for(let c=0;c<4;c++)for(let b=0;b<4;b++)i[c*4+b]=t[b]*a[c*4]+t[4+b]*a[c*4+1]+t[8+b]*a[c*4+2]+t[12+b]*a[c*4+3];return i}function er(t,a,i,c){let b=1/Math.tan(t/2),n=1/(i-c),d=new Float32Array(16);return d[0]=b/a,d[5]=b,d[10]=(c+i)*n,d[11]=-1,d[14]=2*c*i*n,d}function nr(t,a,i){let c=t[0]-a[0],b=t[1]-a[1],n=t[2]-a[2],d=Math.hypot(c,b,n)||1;c/=d,b/=d,n/=d;let A=i[1]*n-i[2]*b,E=i[2]*c-i[0]*n,o=i[0]*b-i[1]*c,r=Math.hypot(A,E,o)||1;A/=r,E/=r,o/=r;let e=b*o-n*E,M=n*A-c*o,O=c*E-b*A,x=new Float32Array(16);return x[0]=A,x[1]=e,x[2]=c,x[3]=0,x[4]=E,x[5]=M,x[6]=b,x[7]=0,x[8]=o,x[9]=O,x[10]=n,x[11]=0,x[12]=-(A*t[0]+E*t[1]+o*t[2]),x[13]=-(e*t[0]+M*t[1]+O*t[2]),x[14]=-(c*t[0]+b*t[1]+n*t[2]),x[15]=1,x}function or(t,a,i,c,b,n,d,A){let E=Math.cos(a),o=Math.sin(a),r=Math.sin(t),e=Math.cos(t),M=r*E,O=o,x=e*E,z=x,g=-M,tt=Math.hypot(z,g)||1;z/=tt,g/=tt;let nt=O*g,B=x*z-M*g,U=-O*z,R=1/Math.tan(Math.max(.05,i)/2),$=R/Math.max(c,1e-6),j=Math.max(.5,Math.min(.92,A)),f=.05,s=1/0,l=-1/0;for(let u=0;u<8;u++){let h=(u&1?1:-1)*b,m=(u&2?1:-1)*n,y=(u&4?1:-1)*d,v=h*M+m*O+y*x,p=h*z+y*g,F=h*nt+m*B+y*U;v<s&&(s=v),v>l&&(l=v),f=Math.max(f,v+Math.abs($*p)/j,v+Math.abs(R*F)/j)}return{d:f,alongMin:s,alongMax:l}}function Gn(t,a={}){let i=typeof a.fetchLut=="function"?a.fetchLut:()=>new Uint8Array(1024),c=typeof a.onContextLost=="function"?a.onContextLost:null,b=a.desynchronized===!0,n=null;try{n=t.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,antialias:!1,depth:!0,stencil:!1,preserveDrawingBuffer:!1,desynchronized:b})}catch{n=null}if(!n)return{available:!1,dispatch(){},resize(){},destroy(){},ensureHd:()=>!1};let d=!0,A=null,E=Math.max(1,Me()),o=(()=>{try{return n.getParameter(n.MAX_TEXTURE_SIZE)||4096}catch{return 4096}})(),r=null,e=-1,M=null,O=null,x=null,z=null,g=null,tt=null,nt=!1,B=null,U=!1,R=null,$=!1,j=null,f=null,s=0,l=null,u=null,h=null,m=null,y=null,v=!1,p=null,F=1,T=1,w={on:!1,depth:.5,yaw:-.18,pitch:1.22,zoom:1,fov:42,rough:.55,metal:.15,ambient:.28,lightYaw:-.9,lightPitch:.85};function L(_){let k=me(n,Wo,_);return{prog:k,aPos:n.getAttribLocation(k,"aPos"),aTex:n.getAttribLocation(k,"aTex"),uInt:n.getUniformLocation(k,"uIntensity"),uLut:n.getUniformLocation(k,"uLut"),uTexel:n.getUniformLocation(k,"uTexel"),uTaps:n.getUniformLocation(k,"uTaps"),uShiftX:n.getUniformLocation(k,"uShiftX")}}try{r=me(n,No,Oo),g=L(Yo),e=n.getAttribLocation(r,"aPos"),M=n.getUniformLocation(r,"uTop"),O=n.getUniformLocation(r,"uBot"),x=n.getUniformLocation(r,"uH"),z=n.getUniformLocation(r,"uDither")}catch(_){return console.warn("[webglHeatmap] program init failed, falling back:",_?.message||_),{available:!1,dispatch(){},resize(){},destroy(){},ensureHd:()=>!1}}function S(){if(!d||$)return!1;if(R)return!0;try{let _=me(n,zo,Xo);return R={prog:_,aPos:n.getAttribLocation(_,"aPos"),aNormal:n.getAttribLocation(_,"aNormal"),uInt:n.getUniformLocation(_,"uIntensity"),uLut:n.getUniformLocation(_,"uLut"),uMvp:n.getUniformLocation(_,"uMvp"),uSrc:n.getUniformLocation(_,"uSrc"),uTexSize:n.getUniformLocation(_,"uTexSize"),uGrid:n.getUniformLocation(_,"uGrid"),uExtent:n.getUniformLocation(_,"uExtent"),uDepth:n.getUniformLocation(_,"uDepth"),uEye:n.getUniformLocation(_,"uEye"),uLightDir:n.getUniformLocation(_,"uLightDir"),uRough:n.getUniformLocation(_,"uRough"),uMetal:n.getUniformLocation(_,"uMetal"),uAmbient:n.getUniformLocation(_,"uAmbient")},!0}catch(_){return $=!0,console.warn("[webglHeatmap] 3D program unavailable, staying 2D:",_?.message||_),!1}}function P(){if(j)return!0;let _=[[[0,1,0],[0,1,1],[1,1,1],[1,1,0]],[0,1,0],[[0,0,0],[1,0,0],[1,0,1],[0,0,1]],[0,-1,0],[[1,0,0],[1,1,0],[1,1,1],[1,0,1]],[1,0,0],[[0,0,0],[0,0,1],[0,1,1],[0,1,0]],[-1,0,0],[[0,0,1],[1,0,1],[1,1,1],[0,1,1]],[0,0,1],[[0,0,0],[0,1,0],[1,1,0],[1,0,0]],[0,0,-1]],k=new Float32Array(6*4*6),K=new Uint16Array(6*6),V=0,lt=0;for(let ht=0;ht<6;ht++){let Ft=_[ht*2],ct=_[ht*2+1],Q=ht*4;for(let ot of Ft)k[V++]=ot[0],k[V++]=ot[1],k[V++]=ot[2],k[V++]=ct[0],k[V++]=ct[1],k[V++]=ct[2];K[lt++]=Q,K[lt++]=Q+1,K[lt++]=Q+2,K[lt++]=Q,K[lt++]=Q+2,K[lt++]=Q+3}return j=n.createBuffer(),f=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,j),n.bufferData(n.ARRAY_BUFFER,k,n.STATIC_DRAW),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,f),n.bufferData(n.ELEMENT_ARRAY_BUFFER,K,n.STATIC_DRAW),s=K.length,!0}function W(){if(!d||nt)return!1;if(tt)return!0;try{return tt=L(Zo),!0}catch(_){return nt=!0,console.warn("[webglHeatmap] HD program unavailable, staying on SD:",_?.message||_),!1}}function I(){if(U)return!1;if(B)return!0;try{return B=L(Go),!0}catch(_){return U=!0,console.warn("[webglHeatmap] sub-pixel program unavailable, staying on SD:",_?.message||_),!1}}let N=n.createBuffer(),D=n.createBuffer(),H=new Float32Array(6*4);n.bindBuffer(n.ARRAY_BUFFER,N),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,1,-1,-1,1,1,1,1,-1,-1,1,-1]),n.STATIC_DRAW);let Y=[];function J(_){let k=Y[_];return k||(k={tex:n.createTexture(),cols:0,rows:0},n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,k.tex),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),Y[_]=k,k)}let C=n.createTexture(),Z=-1;n.bindTexture(n.TEXTURE_2D,C),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.pixelStorei(n.UNPACK_ALIGNMENT,1),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),n.disable(n.DEPTH_TEST),n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA);function Gt(_){if(_.preventDefault(),d=!1,A=null,c)try{c()}catch{}}t.addEventListener("webglcontextlost",Gt,!1);function ae(_){let k;try{k=i(_)}catch{k=null}!k||k.length<256*4||(n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,C),n.texImage2D(n.TEXTURE_2D,0,n.RGBA8,256,1,0,n.RGBA,n.UNSIGNED_BYTE,k.length===256*4?k:k.subarray(0,256*4)),n.activeTexture(n.TEXTURE0))}function ie(_,k,K){d&&(E=K>0?K:Math.max(1,Me()),n.drawingBufferWidth>0&&n.viewport(0,0,_,k),A&&A.setSize(_/E,k/E,E))}function rt(_,k,K,V,lt,ht,Ft,ct,Q){if(!d)return;A&&(A.flush(),A.beginFrame());let ot=t.width,Rt=t.height;n.viewport(0,0,ot,Rt),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);let st=_/255,bt=k/255,dt=K/255,gt=V/255,vt=Q?lt/255:st,pt=Q?ht/255:bt,yt=Q?Ft/255:dt,St=Q?ct/255:gt;n.useProgram(r),n.uniform4f(M,st,bt,dt,gt),n.uniform4f(O,vt,pt,yt,St),n.uniform1f(x,Rt),n.uniform1f(z,Q?1:0),n.bindBuffer(n.ARRAY_BUFFER,N),n.enableVertexAttribArray(e),n.vertexAttribPointer(e,2,n.FLOAT,!1,8,0),n.drawArrays(n.TRIANGLES,0,6)}function ft(_,k){if(!d)return;A&&A.flush();let K=_.worldCols,V=_.worldRows;if(K===0||V===0||K>o||V>o)return;let lt=1,ht=1;_.hd&&_.destW>0&&_.destH>0&&_.srcW>0&&_.srcH>0&&(lt=Math.min(an,Math.max(1,Math.ceil(_.srcW/(_.destW*E)))),ht=Math.min(an,Math.max(1,Math.ceil(_.srcH/(_.destH*E)))));let Ft=lt>1||ht>1;if(Ft&&!W())return;let ct=!Ft&&_.subpx===!0&&I(),Q=Ft?tt:ct?B:g;_.lutSeq!==Z&&(ae(_.lutSeq),Z=_.lutSeq);let ot=J(_.layer===1?1:0);if(n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,C),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,ot.tex),(_.fullRebuild||K!==ot.cols||V!==ot.rows)&&(n.texImage2D(n.TEXTURE_2D,0,n.R8,K,V,0,n.RED,n.UNSIGNED_BYTE,null),ot.cols=K,ot.rows=V),_.patchW>0&&_.patchH>0&&k&&k.length>=_.patchW*_.patchH&&n.texSubImage2D(n.TEXTURE_2D,0,_.patchX,_.patchY,_.patchW,_.patchH,n.RED,n.UNSIGNED_BYTE,k),!(_.srcW>0&&_.srcH>0&&_.destW>0&&_.destH>0))return;let Rt=t.width,st=t.height,bt=_.destX*E,dt=_.destY*E,gt=bt+Math.max(1,_.destW*E),vt=dt+Math.max(1,_.destH*E),pt=bt/Rt*2-1,yt=gt/Rt*2-1,St=1-dt/st*2,Ct=1-vt/st*2,Kt=_.srcX/K,We=(_.srcX+_.srcW)/K,Ye=_.srcY/V,Ge=(_.srcY+_.srcH)/V,kt=_.clip;if(w.on&&S()&&P()){let Ut=Math.max(2,Math.min(Vo,Math.round(_.srcW))),ve=Math.max(2,Math.min($o,Math.round(_.srcH))),pe=Math.round((kt?kt.x:_.destX)*E),ce=Math.round((kt?kt.y:_.destY)*E),ze=Math.max(1,Math.round((kt?kt.w:_.destW)*E)),ue=Math.max(1,Math.round((kt?kt.h:_.destH)*E));n.viewport(pe,st-(ce+ue),ze,ue),n.enable(n.SCISSOR_TEST),n.scissor(pe,st-(ce+ue),ze,ue);let Te=Math.max(.08,Math.min(1.5,w.pitch)),pn=Math.max(.02,w.depth)+Ko,Ae=[0,pn*.5,0],Tn=w.fov*Math.PI/180,Xe=ze/ue;F=Math.max(.2,Xe),T=1;let Ve=or(w.yaw,Te,Tn,Xe,F,pn*.5,T,.92),fe=Ve.d*Math.max(.35,Math.min(3,w.zoom)),_e=[Ae[0]+Math.sin(w.yaw)*Math.cos(Te)*fe,Ae[1]+Math.sin(Te)*fe,Ae[2]+Math.cos(w.yaw)*Math.cos(Te)*fe],An=Math.max(.02,(fe-Ve.alongMax)*.45),uo=Math.max(An+1,(fe-Ve.alongMin)*1.8),_n=er(Tn,Xe,An,uo),En=nr(_e,Ae,[0,1,0]),wn=tr(_n,En),$e=w.lightPitch,Ke=[Math.sin(w.lightYaw)*Math.cos($e),Math.sin($e),Math.cos(w.lightYaw)*Math.cos($e)];n.enable(n.DEPTH_TEST),n.depthFunc(n.LEQUAL),n.depthMask(!0),n.clear(n.DEPTH_BUFFER_BIT),n.enable(n.CULL_FACE),n.cullFace(n.BACK),n.frontFace(n.CCW),n.useProgram(R.prog),n.uniform1i(R.uInt,0),n.uniform1i(R.uLut,1),n.uniformMatrix4fv(R.uMvp,!1,wn),n.uniform4f(R.uSrc,_.srcX,_.srcY,_.srcW,_.srcH),n.uniform2f(R.uTexSize,K,V),n.uniform2f(R.uGrid,Ut,ve),n.uniform2f(R.uExtent,F,T),n.uniform1f(R.uDepth,Math.max(.02,w.depth)),n.uniform3f(R.uEye,_e[0],_e[1],_e[2]),n.uniform3f(R.uLightDir,Ke[0],Ke[1],Ke[2]),n.uniform1f(R.uRough,w.rough),n.uniform1f(R.uMetal,w.metal),n.uniform1f(R.uAmbient,w.ambient),n.bindBuffer(n.ARRAY_BUFFER,j),n.enableVertexAttribArray(R.aPos),n.vertexAttribPointer(R.aPos,3,n.FLOAT,!1,24,0),n.enableVertexAttribArray(R.aNormal),n.vertexAttribPointer(R.aNormal,3,n.FLOAT,!1,24,12),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,f),n.drawElementsInstanced(n.TRIANGLES,s,n.UNSIGNED_SHORT,0,Ut*ve),n.disable(n.CULL_FACE),lo(En,_n,wn),n.disable(n.CULL_FACE),n.disable(n.DEPTH_TEST),n.disable(n.SCISSOR_TEST),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,null),n.viewport(0,0,Rt,st);return}let et=H;if(et[0]=pt,et[1]=St,et[2]=Kt,et[3]=Ye,et[4]=pt,et[5]=Ct,et[6]=Kt,et[7]=Ge,et[8]=yt,et[9]=St,et[10]=We,et[11]=Ye,et[12]=yt,et[13]=St,et[14]=We,et[15]=Ye,et[16]=pt,et[17]=Ct,et[18]=Kt,et[19]=Ge,et[20]=yt,et[21]=Ct,et[22]=We,et[23]=Ge,n.useProgram(Q.prog),n.uniform1i(Q.uInt,0),n.uniform1i(Q.uLut,1),Ft&&(n.uniform2f(Q.uTexel,1/K,1/V),n.uniform2i(Q.uTaps,lt,ht)),Q.uShiftX){let Ut=_.subTexelX;n.uniform1f(Q.uShiftX,Ut>0&&Ut<1?Ut:0)}n.bindBuffer(n.ARRAY_BUFFER,D),n.bufferData(n.ARRAY_BUFFER,et,n.DYNAMIC_DRAW),n.enableVertexAttribArray(Q.aPos),n.vertexAttribPointer(Q.aPos,2,n.FLOAT,!1,16,0),n.enableVertexAttribArray(Q.aTex),n.vertexAttribPointer(Q.aTex,2,n.FLOAT,!1,16,8);let Lt=_.clip;if(Lt&&Lt.w>0&&Lt.h>0){let Ut=Math.round(Lt.x*E),ve=Math.round(Lt.y*E),pe=Math.max(1,Math.round(Lt.w*E)),ce=Math.max(1,Math.round(Lt.h*E));n.enable(n.SCISSOR_TEST),n.scissor(Ut,st-(ve+ce),pe,ce)}n.drawArrays(n.TRIANGLES,0,6),Lt&&Lt.w>0&&Lt.h>0&&n.disable(n.SCISSOR_TEST)}function it(){d=!1;try{t.removeEventListener("webglcontextlost",Gt,!1)}catch{}try{A?.destroy()}catch{}A=null;try{n.deleteBuffer(N),n.deleteBuffer(D),j&&n.deleteBuffer(j),f&&n.deleteBuffer(f);for(let k of Y)k&&n.deleteTexture(k.tex);Y.length=0,n.deleteTexture(C),n.deleteProgram(r),g&&n.deleteProgram(g.prog),tt&&n.deleteProgram(tt.prog),B&&n.deleteProgram(B.prog),R&&n.deleteProgram(R.prog);let _=n.getExtension("WEBGL_lose_context");_&&_.loseContext()}catch{}g=null,tt=null,B=null,R=null,j=null,f=null,s=0,n=null}function se(_){if(!_)return;let k=(V,lt)=>Number.isFinite(+V)?+V:lt,K={...w,..._};w={on:K.on===!0,depth:Math.max(.02,Math.min(4,k(K.depth,.5))),yaw:k(K.yaw,-.18),pitch:Math.max(.08,Math.min(1.5,k(K.pitch,1.22))),zoom:Math.max(.35,Math.min(3,k(K.zoom,1))),fov:Math.max(15,Math.min(80,k(K.fov,42))),rough:Math.max(0,Math.min(1,k(K.rough,.55))),metal:Math.max(0,Math.min(1,k(K.metal,.15))),ambient:Math.max(0,Math.min(1,k(K.ambient,.28))),lightYaw:k(K.lightYaw,-.9),lightPitch:Math.max(-1.4,Math.min(1.4,k(K.lightPitch,.85)))}}function le(){return{...w}}function io(_){p=_||null}function so(){if(v)return!1;if(l&&m)return!0;try{if(!l){let _=me(n,qo,jo);l={prog:_,aQuad:n.getAttribLocation(_,"aQuad"),aPrint:n.getAttribLocation(_,"aPrint"),aSide:n.getAttribLocation(_,"aSide"),uView:n.getUniformLocation(_,"uView"),uProj:n.getUniformLocation(_,"uProj"),uBuy:n.getUniformLocation(_,"uBuy"),uSell:n.getUniformLocation(_,"uSell")},u=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,u),n.bufferData(n.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,1,1,-1,-1,1,1,-1,1]),n.STATIC_DRAW),h=n.createBuffer()}if(!m){let _=me(n,Qo,Jo);m={prog:_,aPos:n.getAttribLocation(_,"aPos"),uMvp:n.getUniformLocation(_,"uMvp"),uColor:n.getUniformLocation(_,"uColor")},y=n.createBuffer()}return!0}catch(_){return v=!0,console.warn("[webglHeatmap] 3D overlay programs unavailable:",_?.message||_),!1}}function lo(_,k,K){let V=p;if(!V||!so())return;let lt=Math.max(.02,w.depth);n.disable(n.DEPTH_TEST);let ht=ot=>(ot*2-1)*F,Ft=ot=>(ot*2-1)*T,ct=V.bubbles;if(ct&&ct.length>5){let ot=ct[0]>0?ct[0]:1,Rt=Math.floor((ct.length-1)/4),st=new Float32Array(Rt*5),bt=0,dt=0;for(let gt=0;gt<Rt;gt++){let vt=1+gt*4,pt=ct[vt],yt=ct[vt+1],St=ct[vt+2],Ct=ct[vt+3];if(!(St>0)||yt<0)continue;let Kt=Math.sqrt(Math.min(1,St/ot));st[bt++]=ht(pt),st[bt++]=lt+V.bubLift*(1+Kt),st[bt++]=Ft(yt),st[bt++]=V.bubMin+Kt*(V.bubMax-V.bubMin),st[bt++]=Ct,dt++}dt>0&&(n.useProgram(l.prog),n.uniformMatrix4fv(l.uView,!1,_),n.uniformMatrix4fv(l.uProj,!1,k),n.uniform3f(l.uBuy,V.buy[0],V.buy[1],V.buy[2]),n.uniform3f(l.uSell,V.sell[0],V.sell[1],V.sell[2]),n.bindBuffer(n.ARRAY_BUFFER,u),n.enableVertexAttribArray(l.aQuad),n.vertexAttribPointer(l.aQuad,2,n.FLOAT,!1,8,0),n.vertexAttribDivisor(l.aQuad,0),n.bindBuffer(n.ARRAY_BUFFER,h),n.bufferData(n.ARRAY_BUFFER,st.subarray(0,dt*5),n.DYNAMIC_DRAW),n.enableVertexAttribArray(l.aPrint),n.vertexAttribPointer(l.aPrint,4,n.FLOAT,!1,20,0),n.vertexAttribDivisor(l.aPrint,1),n.enableVertexAttribArray(l.aSide),n.vertexAttribPointer(l.aSide,1,n.FLOAT,!1,20,16),n.vertexAttribDivisor(l.aSide,1),n.drawArraysInstanced(n.TRIANGLES,0,6,dt),n.vertexAttribDivisor(l.aPrint,0),n.vertexAttribDivisor(l.aSide,0))}let Q=V.bbo;if(Q&&Q.length>=6){let ot=Math.floor(Q.length/3);n.useProgram(m.prog),n.uniformMatrix4fv(m.uMvp,!1,K),n.bindBuffer(n.ARRAY_BUFFER,y),n.enableVertexAttribArray(m.aPos),n.vertexAttribPointer(m.aPos,3,n.FLOAT,!1,12,0),n.vertexAttribDivisor(m.aPos,0);let Rt=V.bboBid||V.buy,st=V.bboAsk||V.sell;for(let[bt,dt]of[[1,Rt],[2,st]]){let gt=new Float32Array(ot*3),vt=0,pt=0;for(let yt=0;yt<ot;yt++){let St=Q[yt*3],Ct=Q[yt*3+bt];Ct<0||(gt[vt++]=ht(St),gt[vt++]=lt+V.bubLift*.6,gt[vt++]=Ft(Ct),pt++)}pt<2||(n.uniform4f(m.uColor,dt[0],dt[1],dt[2],1),n.bufferData(n.ARRAY_BUFFER,gt.subarray(0,pt*3),n.DYNAMIC_DRAW),n.drawArrays(n.LINE_STRIP,0,pt))}}}function co(){return d?A?!0:(A=Wn(n),A?(A.setSize(t.width/E,t.height/E,E),!0):!1):!1}return{get available(){return d},get geom(){return A},enableVectorLayer:co,bg:rt,heatmap:ft,ensureHd:W,set3d:se,get3d:le,setScene3d:io,resize:ie,destroy:it}}var sn=null,ln=null,Qt=null;async function rr(){let t=typeof globalThis>"u"?null:globalThis,a=t&&t.__mrdWasmResp;if(!a)return null;t.__mrdWasmResp=null;try{let i=await a;return i&&i.ok?i:null}catch{return null}}function ar(){if(typeof WorkerGlobalScope>"u"||!self.location?.search)return null;let t=a=>new URL(a+self.location.search,self.location.href).href;return{glue:t("./chart_engine.js"),wasm:t("./chart_engine_bg.wasm")}}async function zn(){return sn?{module:sn,memory:ln}:Qt||(Qt=(async()=>{let t=ar(),a=t?await import(t.glue):await import("./chart_engine.js"),i=t?null:await rr(),c=t?t.wasm:i;try{await(c?a.default({module_or_path:c}):a.default())}catch(b){console.warn("[mrd-chart] WebAssembly streaming init failed, retrying with arrayBuffer fallback:",b);let n=t?t.wasm:new URL("../wasm/chart_engine_bg.wasm",import.meta.url),d=await fetch(n);if(!d.ok)throw new Error(`WASM fetch failed (${d.status} ${d.statusText}) at ${n}`);let A=await d.arrayBuffer();await a.default(A)}return ln=a.wasm_memory(),sn=a,{module:a,memory:ln}})(),Qt.catch(()=>{Qt=null}),Qt)}var Jt=Object.freeze({BOOK_KEY:1,BOOK_DELTA:2,TRADES:3,TICK:4});var Ur=4*8192;var De=12;function sr(t){let a=[];if(!t||!t.byteLength)return a;let i=new DataView(t.buffer,t.byteOffset,t.byteLength),c=0;for(;c+40<=t.byteLength&&i.getUint32(c,!0)===827475028;){let b=i.getUint32(c+4,!0),n=c+40;if(n+b>t.byteLength)break;a.push({flags:i.getUint8(c+12),t0:i.getFloat64(c+16,!0),t1:i.getFloat64(c+24,!0),session:i.getUint32(c+32,!0),seq:i.getUint32(c+36,!0),off:n,len:b}),c=n+b}return a}function Vn(){return{a:new Float64Array(4096),b:new Float64Array(4096),n:0}}function qn(t,a){if(t.a.length>=a*2&&t.b.length>=a*2)return;let i=Math.max(a*2,t.a.length*2),c=new Float64Array(i);c.set(t.a.subarray(0,t.n*2)),t.a=c,t.b=new Float64Array(i)}function $n(t,a,i,c){qn(c,i);let b=c.a;for(let n=0;n<i;n++,a+=De)b[2*n]=t.getFloat64(a,!0),b[2*n+1]=t.getFloat32(a+8,!0);return c.n=i,a}function Kn(t,a,i,c,b){qn(c,c.n+i);let n=c.a,d=c.b,A=c.n,E=0,o=0;for(let r=0;r<i;r++,a+=De){let e=t.getFloat64(a,!0),M=t.getFloat32(a+8,!0);for(;E<A&&b*n[2*E]<b*e;)d[2*o]=n[2*E],d[2*o+1]=n[2*E+1],o++,E++;E<A&&n[2*E]===e&&E++,M>0&&(d[2*o]=e,d[2*o+1]=M,o++)}for(;E<A;)d[2*o]=n[2*E],d[2*o+1]=n[2*E+1],o++,E++;return c.a=d,c.b=n,c.n=o,a}var lr=()=>new Promise(t=>setTimeout(t,0));async function jn(t,a,i={}){let c=+i.fromMs||0,b=Math.max(0,Number.isFinite(+i.stepMs)?+i.stepMs:250),n=Math.max(2,+i.sliceMs||8),d=typeof i.isAlive=="function"?i.isAlive:()=>!0,A=typeof i.yieldFn=="function"?i.yieldFn:lr,E={frames:0,trades:0,lastT:0,aborted:!1},o=sr(a).filter(U=>U.session!==i.excludeSession);if(!o.length)return E;let r=new Map;for(let U of o){let R=r.get(U.session);(R===void 0||U.t0<R)&&r.set(U.session,U.t0)}o.sort((U,R)=>r.get(U.session)-r.get(R.session)||U.session-R.session||U.seq-R.seq);let e=new DataView(a.buffer,a.byteOffset,a.byteLength),M=Vn(),O=Vn(),x=!1,z=-1,g=-1,tt=-1/0,nt=!i.applyTick,B=performance.now();for(let U of o){(U.session!==z||U.seq!==g+1)&&(x=!1),z=U.session,g=U.seq;let R=U.off,$=U.off+U.len;for(;R<$;){let j=e.getUint8(R);if(R+=1,j===Jt.TICK){let f=e.getFloat64(R,!0);R+=8,!nt&&f>0&&(t.set_tick_size(f),nt=!0)}else if(j===Jt.BOOK_KEY||j===Jt.BOOK_DELTA){let f=e.getFloat64(R,!0),s=e.getFloat64(R+8,!0),l=e.getUint32(R+16,!0),u=e.getUint32(R+20,!0);if(R+=24,R+(l+u)*De>$){R=$;break}if(j===Jt.BOOK_KEY)R=$n(e,R,l,M),R=$n(e,R,u,O),x=!0;else if(x)R=Kn(e,R,l,M,-1),R=Kn(e,R,u,O,1);else{R+=(l+u)*De;continue}f>=c&&f-tt>=b&&s>0&&(t.push_book(f,M.a.subarray(0,M.n*2),O.a.subarray(0,O.n*2),s),tt=f,E.frames++,f>E.lastT&&(E.lastT=f))}else if(j===Jt.TRADES){let f=e.getUint32(R,!0);if(R+=4,R+f*21>$){R=$;break}for(let s=0;s<f;s++,R+=21){let l=e.getFloat64(R,!0);l<c||(t.push_trade(l,e.getFloat64(R+8,!0),e.getFloat32(R+16,!0),e.getUint8(R+20)),E.trades++,l>E.lastT&&(E.lastT=l))}}else{x=!1;break}if(performance.now()-B>n){if(await A(),!d())return E.aborted=!0,E;B=performance.now()}}}return E}var G=null,gn=null,_t=null,wt=null,Et=null,mt=null,yn=1,te=!1,Pt=!1,It=!1,ut=!1,fn=!1,Ot=!0,Wt=null,hn=!1,ke=0,ee=0,ge=0,Bt=0,dn=0,Ue=16,cr=66,Qn=3e4,cn=0,mn=15,Pe=0,Zt=0,oo=0,ne=null,He=null,Be=0,oe=[],bn=!1,Ne=!1,Ie=0,ur=250,re=null;function Jn(){re!==null||It||ut||(re=self.setTimeout(()=>{re=null,!(It||ut||Pt||!G)&&(!ne&&!oe.length||(ro(),ao()))},ur))}var At={on:!1,depth:.5,yaw:-.18,pitch:1.22,zoom:1,fov:42,rough:.55,metal:.15,ambient:.28,lightYaw:-.9,lightPitch:.85},ye=!1,un=0,Zn=1;function Yt(t,a,i){try{self.postMessage({t,...a},i||[])}catch{}}function Mt(t){ut||(ut=!0,Ce(),Yt("dead",{err:String(t&&t.message?t.message:t)}))}var fr=typeof self.requestAnimationFrame=="function";function Vt(){It||!te||Pt||ut||Wt!==null||(fr?(hn=!0,Wt=self.requestAnimationFrame(to)):(hn=!1,Wt=self.setTimeout(()=>to(performance.now()),Ue)))}function Ce(){Wt!==null&&(hn?self.cancelAnimationFrame(Wt):self.clearTimeout(Wt),Wt=null)}function hr(){if(Pt||!te)return Number.POSITIVE_INFINITY;let t=performance.now();return(t-ee>Qn&&t-ge>Qn?cr:Ue)+Zt}function to(t){if(Wt=null,It||!te||Pt||ut)return;let a=hr();if(!Number.isFinite(a))return;if(t-ke<a){Vt();return}ke=t,ro();try{G.set_wall_now(Date.now())}catch(c){Mt(c);return}ao();let i=Ot;if(!i){try{i=G.is_dirty()}catch(c){Mt(c);return}i&&Bt===0&&(Bt=t)}if(i&&fn)Ot=!0;else if(i){Ot=!1;let c=performance.now();if(vn()){let n=performance.now();dn=n;let d=Bt>0?Math.min(200,Math.max(0,n-Bt)):0;Bt=0,yr(d,Math.min(200,Math.max(0,n-c)))}else{if(ut)return;Ot=!0}let b=performance.now()-c;cn=cn*.85+b*.15,b>mn?(Pe+=1,Pe>=8&&(Zt=Math.min(100,Zt+16),Pe=0)):(Pe=0,Zt>0&&cn<mn*.5&&(Zt=Math.max(0,Zt-8)))}Vt()}function ro(){if(!Ne){if(ne&&Be>0){try{G.push_book(oo,ne,He,Be)}catch(t){if(t instanceof WebAssembly.RuntimeError){Mt(t);return}}ne=null,He=null,Be=0}if(oe.length){let t=new Float64Array(oe);oe.length=0;try{G.push_trades_batch(t),bn=!0}catch(a){if(a instanceof WebAssembly.RuntimeError){Mt(a);return}}}}}function ao(){if(!bn)return;bn=!1;let t;try{t=G.drain_orderflow_events()}catch(i){i instanceof WebAssembly.RuntimeError&&Mt(i);return}if(!t||t.length<5)return;let a=t instanceof Float64Array?t:new Float64Array(t);Yt("of",{flat:a},[a.buffer])}function dr(){if(!(!At.on||!mt?.setScene3d))try{mt.setScene3d({view:G.tick_view_window?.()||null,bubbles:G.tick_bubbles_3d?.()||null,bbo:G.tick_bbo_3d?.()||null,buy:ye?[.149,.651,.604]:[.055,.796,.506],sell:ye?[.937,.325,.314]:[.965,.275,.365],bboBid:[8/255,153/255,129/255],bboAsk:[242/255,56/255,90/255],bubLift:.02,bubMin:.006,bubMax:.055})}catch{}}function vn(){if(ut||!_t)return!1;try{if(dr(),G.render()>0){let a=G.get_command_buffer_ptr(),i=G.get_command_buffer_len();_t.save(),_t.setTransform(1,0,0,1,0,0),_t.clearRect(0,0,wt.width,wt.height),_t.restore(),Dn(_t,gn,a,i,null,null,null,mt)}return!0}catch(t){return t instanceof WebAssembly.RuntimeError&&Mt(t),!1}}var eo=null;function mr(){let t="";try{t=G.pane_layout_sig?.()||""}catch{return null}if(t===eo)return null;eo=t,Oe=!0;let a="";try{a=G.pane_rects_json?.()||""}catch{a=""}let i={};try{for(let c of Object.keys(a?JSON.parse(a):{}))c.startsWith("__")||(i[c]=G.pane_height_frac?.(c)||0)}catch{}return{sig:t,rects:a,fracs:i}}var no=0,be=null,br=2e3;function gr(t){if(t-no<br)return null;no=t;let a=gn?.buffer?.byteLength||0,i=0;try{i=performance.memory?.usedJSHeapSize||0}catch{}return be&&be.wasm===a&&be.js===i?null:(be={wasm:a,js:i},be)}var Oe=!0;function yr(t,a){let i=mr(),c=gr(performance.now()),b=null;if(Oe){let d=null;try{d=G.tick_input_map?.()}catch{}d&&d.length&&(Oe=!1,b=d instanceof Float64Array?d:new Float64Array(d),un=b[3],Zn=b[5])}let n=null;try{n=[G.price_at_y(un),G.price_at_y(un+Zn),G.is_follow_live?.()?1:0,G.is_auto_scale_y?.()?1:0,G.get_last_mid(),G.cvd_height_frac?.()||0]}catch{}b?Yt("frame",{geom:b,st:n,panes:i,mem:c,latMs:t,paintMs:a},[b.buffer]):Yt("frame",{geom:null,st:n,panes:i,mem:c,latMs:t,paintMs:a})}var $t=()=>{!Ot&&Bt===0&&(Bt=performance.now()),Ot=!0,Vt()};function vr(t){let a=At.on;At={...At,...t};try{mt?.set3d?.(At)}catch{}if(At.on!==a){try{G.set_heatmap_3d?.(At.on)}catch{}if(At.on){At={...At,yaw:-.18,pitch:1.22,zoom:1};try{mt?.set3d?.(At)}catch{}}}$t()}function pr(){if(!Et)return!1;if(mt=Gn(Et,{fetchLut:()=>G.heatmap_lut_rgba(),onContextLost:()=>{try{G.set_render_backend(0)}catch{}mt=null,$t()}}),!mt.available){mt=null;try{G.set_render_backend(0)}catch{}return!1}try{mt.resize(Et.width,Et.height,Et.width/Math.max(1,yn))}catch{}try{mt.set3d?.(At)}catch{}try{G.set_render_backend(1)}catch{}return!0}function Tr(t){if(It||ut||!(t.cssW>=1)||!(t.cssH>=1))return;yn=t.cssW;try{G.resize(t.cssW,t.cssH)}catch(i){Mt(i);return}let a=t.bufW/Math.max(1,t.cssW);try{G.set_dpr?.(a)}catch{}if((wt.width!==t.bufW||wt.height!==t.bufH)&&(wt.width=t.bufW,wt.height=t.bufH,_t.setTransform(1,0,0,1,0,0),_t.scale(a,t.bufH/Math.max(1,t.cssH)),Et)){Et.width=t.bufW,Et.height=t.bufH;try{mt?.resize(t.bufW,t.bufH,a)}catch{}}Oe=!0,vn(),$t()}async function Ar(t){wt=t.canvas2d,Et=t.glCanvas||null,yn=t.cssW,Ue=t.options?.frameMs||16,mn=Math.max(4,Ue-1),ye=t.options?.theme==="light";let{module:a,memory:i}=await zn();gn=i,G=new a.TickEngine(t.cssW,t.cssH),_t=wt.getContext("2d");let c=t.bufW/Math.max(1,t.cssW);_t.setTransform(1,0,0,1,0,0),_t.scale(c,t.bufH/Math.max(1,t.cssH));try{G.set_license_token(t.options?.licenseToken||"",Date.now(),t.options?.host||"")}catch{}try{G.set_dpr?.(c)}catch{}if(ye)try{G.set_theme(1)}catch{}let b=t.options?.renderer==="canvas2d"?!1:pr();ee=performance.now(),ge=ee,Yt("ready",{gl:b})}async function _r(t){let a=null;if(!ut&&G&&t.buf){let i=++Ie;Ne=!0;try{a=await jn(G,t.buf,{...t.opts||{},isAlive:()=>i===Ie&&!It&&!ut})}catch(c){c instanceof WebAssembly.RuntimeError&&Mt(c),a=null}finally{i===Ie&&(Ne=!1)}$t()}Yt("reply",{id:t.id,v:a})}self.onmessage=t=>{let a=t.data;if(!(!a||It))switch(a.t){case"init":Ar(a).catch(i=>Mt(i));return;case"call":if(ut||!G)return;try{G[a.m]?.(...a.a||[])}catch(i){if(i instanceof WebAssembly.RuntimeError){Mt(i);return}}$t();return;case"calls":{if(ut||!G)return;let i=a.batch||[];for(let c=0;c<i.length;c++)try{G[i[c][0]]?.(...i[c][1]||[])}catch(b){if(b instanceof WebAssembly.RuntimeError){Mt(b);return}}$t();return}case"query":{let i=null;if(!ut&&G)try{i=G[a.m]?.(...a.a||[])}catch{i=null}i&&typeof i=="object"&&"length"in i&&!Array.isArray(i)&&(i=Array.from(i)),Yt("reply",{id:a.id,v:i});return}case"book":if(ut||Pt)return;ge=performance.now(),oo=a.tMs,ne=a.bids,He=a.asks,Be=a.mid,Vt(),Jn();return;case"trades":{if(ut||Pt)return;ge=performance.now();let i=a.flat;for(let c=0;c<i.length;c++)oe.push(i[c]);Vt(),Jn();return}case"history":_r(a);return;case"history-cancel":Ie++,Ne=!1;return;case"resize":Tr(a);return;case"busy":fn=!!a.v,fn||$t();return;case"cfg3d":vr(a.patch||{});return;case"input":ee=performance.now();return;case"theme":ye=!!a.light;return;case"capture":{let i=null;try{vn();let c=new OffscreenCanvas(wt.width,wt.height),b=c.getContext("2d");Et&&b.drawImage(Et,0,0),b.drawImage(wt,0,0),i=c.transferToImageBitmap()}catch{i=null}Yt("reply",{id:a.id,v:i},i?[i]:[]);return}case"life":switch(a.v){case"start":te=!0,Pt=!1,Ot=!0,ke=0,ee=performance.now(),ge=ee,Vt();return;case"pause":Pt=!0,Ce(),dn=0,Bt=0;return;case"resume":if(It||ut)return;Pt=!1,te=!0,Ot=!0,ke=0,dn=0,Bt=0,Vt();return;case"stop":te=!1,Ce();return;case"destroy":It=!0,Ce(),re!==null&&(self.clearTimeout(re),re=null);try{mt?.destroy?.()}catch{}try{G?.free?.()}catch{}mt=null,G=null,_t=null,wt=null,Et=null,oe=[],ne=null,He=null;return;default:return}default:return}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kline-orderbook-chart",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Candlestick chart with built-in GPU-accelerated (WebGL2) orderbook heatmap, footprint chart, volume profile, and liquidation heatmap. Native WebAssembly engine — 60 fps, zero dependencies. Same engine also ships as a native Rust crate (GPUI / wgpu / skia) for desktop apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/chart-engine.mjs",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"homepage": "https://github.com/tapedelta/kline-orderbook-chart",
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
|
62
|
-
"url": "https://github.com/tapedelta/kline-orderbook-chart.git"
|
|
62
|
+
"url": "git+https://github.com/tapedelta/kline-orderbook-chart.git"
|
|
63
63
|
},
|
|
64
64
|
"bugs": {
|
|
65
65
|
"url": "https://github.com/tapedelta/kline-orderbook-chart/issues"
|