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
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ export interface ChartEngine {
|
|
|
66
66
|
pause(): void;
|
|
67
67
|
resume(): void;
|
|
68
68
|
readonly isPaused: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Show / hide the engine-drawn load spinner (pulsing bars centred in the
|
|
71
|
+
* chart area). Rendered on the canvas, so toggling it never mounts or
|
|
72
|
+
* unmounts a DOM layer over the chart.
|
|
73
|
+
*/
|
|
74
|
+
setLoading(on: boolean): void;
|
|
69
75
|
|
|
70
76
|
// Data
|
|
71
77
|
setKlines(klines: any[]): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 _=null,b=null,h=null;async function B(){let t=typeof globalThis>"u"?null:globalThis,e=t&&t.__mrdWasmResp;if(!e)return null;t.__mrdWasmResp=null;try{let s=await e;return s&&s.ok?s:null}catch{return null}}function R(){if(typeof WorkerGlobalScope>"u"||!self.location?.search)return null;let t=e=>new URL(e+self.location.search,self.location.href).href;return{glue:t("./chart_engine.js"),wasm:t("./chart_engine_bg.wasm")}}async function y(){return _?{module:_,memory:b}:h||(h=(async()=>{let t=R(),e=t?await import(t.glue):await import("./chart_engine.js"),s=t?null:await B(),i=t?t.wasm:s;try{await(i?e.default({module_or_path:i}):e.default())}catch(n){console.warn("[mrd-chart] WebAssembly streaming init failed, retrying with arrayBuffer fallback:",n);let r=t?t.wasm:new URL("../wasm/chart_engine_bg.wasm",import.meta.url),o=await fetch(r);if(!o.ok)throw new Error(`WASM fetch failed (${o.status} ${o.statusText}) at ${r}`);let E=await o.arrayBuffer();await e.default(E)}return b=e.wasm_memory(),_=e,{module:e,memory:b}})(),h.catch(()=>{h=null}),h)}var l=class{constructor(e){this.url=e.url,this.role=e.role||"",this.binary=!!e.binary,this.viaGateway=!!e.viaGateway,this.h=e,this.ws=null,this.timer=null,this.backoffMs=1e3,this.lastMsgAt=0,this.stopped=!0}isOpen(){return!!this.ws&&this.ws.readyState===WebSocket.OPEN}open(){if(this.stopped=!1,this.ws)return;let e;try{e=new WebSocket(this.url),this.binary&&(e.binaryType="arraybuffer")}catch(i){console.warn(`[ingest] ws construct failed (${this.role}):`,i?.message||i),this.scheduleReconnect();return}this.ws=e;let s=!1;e.onopen=()=>{s=!0,this.backoffMs=1e3,this.lastMsgAt=Date.now(),this.h.onHandshake?.(!0),this.h.onOpen?.()},e.onmessage=i=>{this.ws===e&&(this.lastMsgAt=Date.now(),this.h.onMessage(i.data))},e.onclose=i=>{this.ws===e&&(this.ws=null,s||this.h.onHandshake?.(!1),!this.stopped&&(console.warn(`[ingest] ws closed (${this.role}, code ${i?.code}); reconnecting in ${this.backoffMs}ms`),this.scheduleReconnect()))},e.onerror=()=>{}}send(e){this.isOpen()&&this.ws.send(JSON.stringify(e))}scheduleReconnect(){this.timer||this.stopped||(this.timer=setTimeout(()=>{this.timer=null,this.backoffMs=Math.min(this.backoffMs*2,3e4),this.open()},this.backoffMs))}bounce(e){if(this.stopped)return;let s=this.isOpen();s&&Date.now()-this.lastMsgAt<e||(this.timer&&(clearTimeout(this.timer),this.timer=null),this.backoffMs=1e3,(s||this.ws)&&this.drop(),this.open())}kick(){if(this.ws)try{this.ws.close()}catch{}}drop(){let e=this.ws;if(this.ws=null,e)try{e.close()}catch{}}close(){this.stopped=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.drop()}};function a(t,e){self.postMessage(t,e||[])}var c=class{constructor(e,s){this.id=s,this.feed=new e.BookFeed,this.gen=0,this.lastBookAt=0,this.pendingTrades=0,this.closed=!1}resetFeed(e,s,i,n){this.gen=e,this.feed.reset(s,i,n,Date.now()),this.lastBookAt=0,this.pendingTrades=0}noteTrade(){++this.pendingTrades>=2048&&this.drain(Date.now(),!1)}drain(e,s){let i=s&&e-this.lastBookAt>=100,n=this.feed.drain(e,i);if(this.pendingTrades=0,!(n&3))return;let r={t:"frame",id:this.id,gen:this.gen,tMs:e,bits:n,mid:0,tick:0},o=[];n&1&&(this.lastBookAt=e,r.bids=this.feed.bids(),r.asks=this.feed.asks(),r.mid=this.feed.mid(),o.push(r.bids.buffer,r.asks.buffer)),n&16&&(r.tick=this.feed.rowTick()),n&2&&(r.trades=this.feed.trades(),o.push(r.trades.buffer)),a(r,o)}health(){}park(){}unpark(){}free(){this.closed=!0,this.feed.free()}};var C=12e3,u=class extends c{constructor(e,s){super(e,s.id),this.legs=[],this.restart(s)}restart({gen:e,symbol:s,legs:i}){this.closeLegs(),this.resetFeed(e,s,1,""),this.legs=(i||[]).map(n=>{let r=new l({url:n.url,role:n.role,viaGateway:n.viaGateway,onOpen:()=>{n.carriesDepth&&this.needSnapshot()},onHandshake:o=>a({t:"ws",id:this.id,role:n.role,ok:o,viaGateway:r.viaGateway,reportable:!!n.reportable}),onMessage:o=>this.onMessage(o)});return r});for(let n of this.legs)n.open()}onMessage(e){typeof e=="string"&&(this.feed.binance(e)&1&&this.needSnapshot(),e.includes('"aggTrade"')&&this.noteTrade())}needSnapshot(){a({t:"need-snapshot",id:this.id,gen:this.gen})}snapshot(e,s){e!==this.gen||typeof s!="string"||this.feed.snapshot(s)&1&&this.needSnapshot()}setUrl(e,s,i){let n=this.legs.find(r=>r.role===e);n&&s&&(n.url=s,n.viaGateway=!!i)}resume(){for(let e of this.legs)e.bounce(C)}closeLegs(){for(let e of this.legs)e.close();this.legs=[]}close(){this.closeLegs(),this.free()}};var x=12e3,F=9e4,d=class extends c{constructor(e,s){super(e,s.id),this.parked=!1,this.leg=new l({url:s.url,role:"obag",binary:!0,onOpen:()=>{this.resetFeed(this.gen,this.symbol,2,this.venues.join(",")),this.subscribe(!0)},onMessage:i=>this.onMessage(i)}),this.restart(s)}restart({gen:e,symbol:s,venues:i}){this.symbol=s||"",this.venues=Array.isArray(i)?i:[],this.resetFeed(e,this.symbol,2,this.venues.join(",")),this.leg.isOpen()?this.subscribe(!1):this.parked||this.leg.open()}subscribe(e){let s=this.leg;s.send({type:"change_symbol",symbol:this.symbol}),s.send({type:"get_server_info"}),e&&(s.send({type:"subscribe_orderbook_raw",exchanges:this.venues}),s.send({type:"subscribe_trades"}))}onMessage(e){let s=Date.now(),i;typeof e=="string"?(i=this.feed.obag(e,s),e.includes('"type":"trade"')&&this.noteTrade()):i=this.feed.obagBinary(new Uint8Array(e),s),i&2&&this.leg.send({type:"get_orderbook_raw_snapshot",exchanges:this.venues})}health(e){this.leg.isOpen()&&e-this.leg.lastMsgAt>F&&(console.warn(`[ingest] obAG silent ${Math.round((e-this.leg.lastMsgAt)/1e3)}s \u2014 reconnecting`),this.leg.kick())}resume(){this.parked||this.leg.bounce(x)}park(){this.parked||(this.parked=!0,this.leg.close())}unpark(){this.parked&&(this.parked=!1,this.leg.open())}close(){this.leg.close(),this.free()}};var K=33,v=1e3,N=250,U={binance:u,obag:d},A=null,g=!1,w=!1,p=null,S=0,f=new Map;function O(){let t=Date.now();for(let e of f.values())e.health(t),e.drain(t,!g||w)}function L(){let t=w?N:v,e=f.size===0?0:g?t:K;e!==S&&(p&&(clearInterval(p),p=null),S=e,e&&(p=setInterval(O,e)))}var m=0;function T(){if(m)for(let t of f.values())try{t.feed?.setRowBudget?.(m)}catch{}}function G(t){let e=t.id!=null?f.get(t.id):null;switch(t.t){case"open":{let s=U[t.kind||"binance"];!e&&s&&(f.set(t.id,new s(A,t)),T());break}case"symbol":e?.restart(t);break;case"urls":e?.setUrl?.(t.role,t.url,t.viaGateway);break;case"snapshot":e?.snapshot?.(t.gen,t.text);break;case"resume":e?.resume();break;case"park":e?.park();break;case"unpark":e?.unpark();break;case"close":e&&(e.close(),f.delete(t.id));break;case"budget":m=t.rows|0,T();break;case"vis":g=!!t.hidden,w=!!t.keepBook,g||O();break;default:return}L()}y().then(({module:t})=>{if(typeof t.BookFeed!="function")throw new Error("engine glue has no BookFeed (stale build)");A=t,self.onmessage=e=>{try{G(e.data||{})}catch(s){console.error("[ingest] message failed:",s)}},a({t:"ready"})}).catch(t=>a({t:"fatal",error:String(t?.message||t)}));
|
|
@@ -0,0 +1,56 @@
|
|
|
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 rt=-Math.PI/2,zt=new WeakMap;function ce(e,r){let o=zt.get(e);o||(o=new Map,zt.set(e,o));let f=o.get(r);if(f)return f;o.size>=128&&o.clear();let _=r*.259,E=r*.432,T=e.createRadialGradient(_,E,0,_,E,r*1.45);T.addColorStop(0,"rgba(0,0,0,0)"),T.addColorStop(1,"rgba(0,0,0,0.59)");let F=r*.135,P=r*.225,n=e.createRadialGradient(F,P,0,F,P,r*.38);return n.addColorStop(0,"rgba(255,255,255,0.35)"),n.addColorStop(1,"rgba(255,255,255,0)"),f={dark:T,spec:n},o.set(r,f),f}function Vt(e,r,o,f,_,E,T,F,P,n,a,t,w,D){if(!(f>0))return;let S=Math.min(1,Math.max(0,_)),W=S*Math.PI;if(e.save(),e.translate(r,o),e.globalAlpha*=.82,S>=.999||S<=.001){let i=S>=.999?[E,T,F,P]:[n,a,t,w];e.beginPath(),e.arc(0,0,f,0,Math.PI*2),e.fillStyle=`rgba(${i[0]},${i[1]},${i[2]},${(i[3]/255).toFixed(3)})`,e.fill()}else e.beginPath(),e.moveTo(0,0),e.arc(0,0,f,rt-W,rt+W),e.closePath(),e.fillStyle=`rgba(${E},${T},${F},${(P/255).toFixed(3)})`,e.fill(),e.beginPath(),e.moveTo(0,0),e.arc(0,0,f,rt+W,rt-W+Math.PI*2),e.closePath(),e.fillStyle=`rgba(${n},${a},${t},${(w/255).toFixed(3)})`,e.fill(),f>=4&&(e.strokeStyle="rgba(20,20,20,0.45)",e.lineWidth=Math.max(1,f*.08),e.beginPath(),e.moveTo(0,0),e.lineTo(f*Math.cos(rt-W),f*Math.sin(rt-W)),e.moveTo(0,0),e.lineTo(f*Math.cos(rt+W),f*Math.sin(rt+W)),e.stroke());if(D&&f>=4){let i=ce(e,Math.round(f));e.beginPath(),e.arc(0,0,f,0,Math.PI*2),e.fillStyle=i.dark,e.fill(),e.fillStyle=i.spec,e.fill()}e.restore()}var k={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},ue=(()=>{try{return typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches}catch{return!1}})(),fe=ue?1.5:1/0;function he(){return typeof window<"u"&&window.devicePixelRatio||1}function ge(e,r){return typeof OffscreenCanvas<"u"?new OffscreenCanvas(e,r):Object.assign(document.createElement("canvas"),{width:e,height:r})}var lt=null,Kt=null;function de(e,r){return lt?(lt.width!==e||lt.height!==r)&&(lt.width=e,lt.height=r):(lt=ge(e,r),Kt=lt.getContext("2d")),Kt}var Bt=new Float32Array(0);function ye(e){return Bt.length<e&&(Bt=new Float32Array(e)),Bt}var mt=new Float64Array(0),Ut=new Float64Array(0),Ot=new Float64Array(0),_t=new Float64Array(0);function be(e){return mt.length<e&&(mt=new Float64Array(e)),mt}function me(e){return Ut.length<e&&(Ut=new Float64Array(e)),Ut}function _e(e){return Ot.length<e&&(Ot=new Float64Array(e)),Ot}function pe(e){return _t.length<e&&(_t=new Float64Array(e)),_t}function $t(e,r){if(r<2)return;let o=r-1,f=be(o),_=me(o),E=_e(o);for(let F=0;F<o;F++){let P=e[F*2],n=e[F*2+1],a=e[(F+1)*2],t=e[(F+1)*2+1];f[F]=a-P,_[F]=t-n,E[F]=f[F]>0?_[F]/f[F]:0}let T=pe(r);T[0]=E[0],T[r-1]=E[o-1];for(let F=1;F<o;F++){let P=E[F-1],n=E[F];T[F]=P*n<=0?0:(P+n)*.5}for(let F=0;F<o;F++){let P=E[F];if(P===0){T[F]=0,T[F+1]=0;continue}let n=T[F]/P,a=T[F+1]/P,t=n*n+a*a;if(t>9){let w=3/Math.sqrt(t);T[F]=w*n*P,T[F+1]=w*a*P}}}function qt(e,r,o){let f=o-1,_=mt,E=_t;for(let T=0;T<f;T++){let F=r[T*2],P=r[T*2+1],n=r[(T+1)*2],a=r[(T+1)*2+1],t=_[T];if(t<=0){e.lineTo(n,a);continue}let w=t/3;e.bezierCurveTo(F+w,P+E[T]*w,n-w,a-E[T+1]*w,n,a)}}function Te(e,r,o){let f=o-1,_=mt,E=_t;for(let T=f-1;T>=0;T--){let F=r[T*2],P=r[T*2+1],n=r[(T+1)*2],a=r[(T+1)*2+1],t=_[T];if(t<=0){e.lineTo(F,P);continue}let w=t/3;e.bezierCurveTo(n-w,a-E[T+1]*w,F+w,P+E[T]*w,F,P)}}var Jt=["left","center","right"],At=new Map,we=4096;function Fe(e,r,o,f){return e<<24|r<<16|o<<8|f}function $(e,r,o,f){let _=Fe(e,r,o,f),E=At.get(_);return E||(E=`rgba(${e},${r},${o},${(f/255).toFixed(3)})`,At.size>=we&&At.clear(),At.set(_,E),E)}var Rt=new TextDecoder;function dt(e,r){return Math.round(e*r)/r}var Lt=new Map;function vt(e,r){let o=Lt.get(r);if(o!==void 0)return o;let f=e.font,_=e.textBaseline;e.font=r,e.textBaseline="alphabetic";let E=e.measureText("0"),T=E.actualBoundingBoxAscent||0,F=E.actualBoundingBoxDescent||0;return o=(T-F)/2,(!Number.isFinite(o)||o===0)&&(o=(parseFloat(r)||11)*.35),Lt.size>=256&&Lt.clear(),Lt.set(r,o),e.font=f,e.textBaseline=_,o}var Qt=new WeakMap;function Ee(e,r,o,f,_){let E=Qt.get(e);E||(E=new Map,Qt.set(e,E));let T=Math.round(r),F=`${T}|${o}|${f}|${_}`,P=E.get(F);if(P)return P;let n=-T*.25,a=-T*.25,t=e.createRadialGradient(n,a,T*.08,0,0,T);t.addColorStop(0,f),t.addColorStop(1,o);let w=null;_&&(w=e.createRadialGradient(0,0,T*.85,0,0,T*1.2),w.addColorStop(0,_),w.addColorStop(1,_.replace(/[\d.]+\)$/,"0)")));let D=T*.2,S=e.createRadialGradient(n,a,0,n,a,D);return S.addColorStop(0,"rgba(255,255,255,0.22)"),S.addColorStop(1,"rgba(255,255,255,0)"),P={body:t,glow:w,spec:S,hlX:n,hlY:a,specR:D},E.set(F,P),P}function Q(e,r,o){let f=Math.max(1,Math.round(r*o)),_=Math.round(e*o)/o;return f&1?_+.5/o:_}function ut(e,r,o,f,_){let E=Math.round(e*_),T=Math.round(r*_),F=Math.round((e+o)*_),P=Math.round((r+f)*_);return{x:E/_,y:T/_,w:(F-E)/_,h:(P-T)/_}}function Me(e,r,o,f,_){return{x:Math.round(e*_)/_,y:Math.round(r*_)/_,w:Math.max(1,Math.round(o*_))/_,h:Math.max(1,Math.round(f*_))/_}}function Ae(e,r,o,f,_){let E=Math.round(r*_),T=Math.round((r+f)*_);return{x:e,y:E/_,w:o,h:(T-E)/_}}function jt(e,r,o,f,_=null,E=null,T=null,F=null){let P=r.buffer;if(o+f>P.byteLength)return;let n=new DataView(P,o,f),a=new Uint8Array(P,o,f),t=0,w="",D="",S=-1,W="",i=Math.max(1,Math.abs(e.getTransform?.().a||he())),it=null,v=[],L=F&&F.geom&&F.geom.available?F.geom:null,z=e,tt=!1,ot="";for(;t<f;){let ct=a[t];if(t+=1,ct===k.END_FRAME)break;switch(ct){case k.FILL_RECT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];if(t+=4,L){L.rect(l,u,g,s,c,h,y,m,0,0,0,0,0,0,0);break}let d=$(c,h,y,m);d!==w&&(e.fillStyle=d,w=d);let p=ut(l,u,g,s,i);e.fillRect(p.x,p.y,p.w,p.h);break}case k.FILL_RECT_SMOOTH_X:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];if(t+=4,L){L.rect(l,u,g,s,c,h,y,m,0,0,0,0,0,0,1);break}let d=$(c,h,y,m);d!==w&&(e.fillStyle=d,w=d);let p=Ae(l,u,g,s,i);e.fillRect(p.x,p.y,p.w,p.h);break}case k.FILL_ELLIPSE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];if(t+=4,L){L.rect(l-g,u-s,g*2,s*2,c,h,y,m,-1,0,0,0,0,0,2);break}let d=$(c,h,y,m);d!==w&&(e.fillStyle=d,w=d),e.beginPath(),e.ellipse(l,u,Math.max(g,.1),Math.max(s,.1),0,0,Math.PI*2),e.fill();break}case k.FILL_ROUND_RECT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];t+=4;let d=n.getFloat32(t,!0);if(t+=4,L){L.rect(l,u,g,s,c,h,y,m,d,0,0,0,0,0,0);break}let p=$(c,h,y,m);p!==w&&(e.fillStyle=p,w=p);let b=ut(l,u,g,s,i),M=Math.min(d,b.w*.5,b.h*.5);M<=.5?e.fillRect(b.x,b.y,b.w,b.h):(e.beginPath(),e.moveTo(b.x+M,b.y),e.lineTo(b.x+b.w-M,b.y),e.arcTo(b.x+b.w,b.y,b.x+b.w,b.y+M,M),e.lineTo(b.x+b.w,b.y+b.h-M),e.arcTo(b.x+b.w,b.y+b.h,b.x+b.w-M,b.y+b.h,M),e.lineTo(b.x+M,b.y+b.h),e.arcTo(b.x,b.y+b.h,b.x,b.y+b.h-M,M),e.lineTo(b.x,b.y+M),e.arcTo(b.x,b.y,b.x+M,b.y,M),e.closePath(),e.fill());break}case k.STROKE_RECT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];t+=4;let d=n.getFloat32(t,!0);if(t+=4,L){let H=d*.5;L.rect(l-H,u-H,g+d,s+d,0,0,0,0,0,d,c,h,y,m,0);break}let p=$(c,h,y,m);p!==D&&(e.strokeStyle=p,D=p),d!==S&&(e.lineWidth=d,S=d);let b=Q(l,d,i),M=Q(u,d,i),C=Math.round(g*i)/i,R=Math.round(s*i)/i;e.strokeRect(b,M,C,R);break}case k.LINE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];t+=4;let d=n.getFloat32(t,!0);if(t+=4,L){L.seg(l,u,g,s,c,h,y,m,d,0,0);break}let p=$(c,h,y,m);e.beginPath(),p!==D&&(e.strokeStyle=p,D=p),d!==S&&(e.lineWidth=d,S=d),e.setLineDash([]),e.moveTo(Q(l,d,i),Q(u,d,i)),e.lineTo(Q(g,d,i),Q(s,d,i)),e.stroke();break}case k.CANDLE:case k.CANDLE_BORDERED:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getFloat32(t,!0);t+=4;let h=n.getFloat32(t,!0);t+=4;let y=n.getFloat32(t,!0);t+=4;let m=n.getFloat32(t,!0);t+=4;let d=a[t+3],p=$(a[t],a[t+1],a[t+2],d);t+=4;let b=a[t+3],M=$(a[t],a[t+1],a[t+2],b);t+=4;let C=null;ct===k.CANDLE_BORDERED&&(C=$(a[t],a[t+1],a[t+2],a[t+3]),t+=4);let R=Math.max(1,Math.floor(y*i)),H=Math.max(1,Math.floor(m*i));R>H&&(R=H);let B=Math.min(Math.max(1,Math.floor(h*i)),H);B<R?B=R:(B^R)&1&&(B-=1);let U=l*i,G=R&1?Math.round(U-.5)+.5:Math.round(U),O=Math.max(1,Math.round(i)),I=Math.round(Math.min(s,c)*i),N=Math.max(I+O,Math.round(Math.max(s,c)*i)),Y=Math.round(Math.min(u,g)*i),A=Math.max(Y+1,Math.round(Math.max(u,g)*i)),x=Math.min(u,g),Mt=Math.max(u,g),Ct=Math.min(s,c),Pt=Math.max(s,c);if(x<Ct&&Y>=I&&(Y=I-1),Mt>Pt&&A<=N&&(A=N+1),b>0&&(Y<I||A>N)){M!==w&&(e.fillStyle=M,w=M);let Dt=(G-R/2)/i,It=R/i;d===255?e.fillRect(Dt,Y/i,It,(A-Y)/i):(Y<I&&e.fillRect(Dt,Y/i,It,(I-Y)/i),A>N&&e.fillRect(Dt,N/i,It,(A-N)/i))}let K=G-B/2,j=N-I;if(C===null){d>0&&(p!==w&&(e.fillStyle=p,w=p),e.fillRect(K/i,I/i,B/i,j/i));break}let J=Math.max(1,Math.floor(i));if(C!==w&&(e.fillStyle=C,w=C),B<=2*J||j<=2*J){e.fillRect(K/i,I/i,B/i,j/i);break}d===255?e.fillRect(K/i,I/i,B/i,j/i):(e.fillRect(K/i,I/i,B/i,J/i),e.fillRect(K/i,(N-J)/i,B/i,J/i),e.fillRect(K/i,(I+J)/i,J/i,(j-2*J)/i),e.fillRect((K+B-J)/i,(I+J)/i,J/i,(j-2*J)/i)),d>0&&(p!==w&&(e.fillStyle=p,w=p),e.fillRect((K+J)/i,(I+J)/i,(B-2*J)/i,(j-2*J)/i));break}case k.OHLC_BAR:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getFloat32(t,!0);t+=4;let h=n.getFloat32(t,!0);t+=4;let y=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let m=a[t];t+=1;let d=Math.max(1,Math.floor(h*i)),p=Math.max(1,Math.floor(i)),b=m&1?p:Math.max(p,Math.floor(d/6));b>d&&(b=d);let M=l*i,R=(b&1?Math.round(M-.5)+.5:Math.round(M))-b/2,H=Math.round(Math.min(g,s)*i),B=Math.max(H+1,Math.round(Math.max(g,s)*i));y!==w&&(e.fillStyle=y,w=y),e.fillRect(R/i,H/i,b/i,(B-H)/i);let U=Math.floor((Math.floor(d*.8)-b)/2);if(U>=1){if(!(m&2)){let O=Math.round(u*i-b/2);e.fillRect((R-U)/i,O/i,U/i,b/i)}let G=Math.round(c*i-b/2);e.fillRect((R+b)/i,G/i,U/i,b/i)}break}case k.DASHED_LINE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];t+=4;let d=n.getFloat32(t,!0);t+=4;let p=n.getFloat32(t,!0);t+=4;let b=n.getFloat32(t,!0);if(t+=4,L){L.seg(l,u,g,s,c,h,y,m,d,p,b);break}let M=$(c,h,y,m);e.beginPath(),M!==D&&(e.strokeStyle=M,D=M),d!==S&&(e.lineWidth=d,S=d),e.setLineDash([p,b]),e.moveTo(Q(l,d,i),Q(u,d,i)),e.lineTo(Q(g,d,i),Q(s,d,i)),e.stroke(),e.setLineDash([]);break}case k.LINEAR_POLYLINE:{let l=n.getUint16(t,!0);t+=2;let u=a[t],g=a[t+1],s=a[t+2],c=a[t+3];t+=4;let h=n.getFloat32(t,!0);if(t+=4,L){let m=0,d=0;for(let p=0;p<l;p++){let b=n.getFloat32(t,!0),M=n.getFloat32(t+4,!0);t+=8,p>0&&L.seg(m,d,b,M,u,g,s,c,h,0,0),m=b,d=M}break}let y=$(u,g,s,c);if(l>1){e.beginPath(),y!==D&&(e.strokeStyle=y,D=y),h!==S&&(e.lineWidth=h,S=h),e.setLineDash([]),e.lineJoin="miter",e.lineCap="butt",e.miterLimit=10;let m=n.getFloat32(t,!0);t+=4;let d=n.getFloat32(t,!0);t+=4,e.moveTo(m,d);for(let p=1;p<l;p++)e.lineTo(n.getFloat32(t,!0),n.getFloat32(t+4,!0)),t+=8;e.stroke()}else t+=l*8;break}case k.SMOOTH_POLYLINE:{let l=n.getUint16(t,!0);t+=2;let u=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let g=n.getFloat32(t,!0);if(t+=4,l>1){let s=new Float32Array(l*2);for(let c=0;c<l;c++)s[c*2]=n.getFloat32(t,!0),t+=4,s[c*2+1]=n.getFloat32(t,!0),t+=4;e.beginPath(),u!==D&&(e.strokeStyle=u,D=u),g!==S&&(e.lineWidth=g,S=g),e.setLineDash([]),e.lineJoin="round",e.lineCap="round",l===2?(e.moveTo(s[0],s[1]),e.lineTo(s[2],s[3])):($t(s,l),e.moveTo(s[0],s[1]),qt(e,s,l)),e.stroke()}else t+=l*8;break}case k.POLYLINE:{let l=n.getUint16(t,!0);t+=2;let u=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let g=n.getFloat32(t,!0);if(t+=4,l>0){let s=new Float32Array(l*2);for(let c=0;c<l;c++)s[c*2]=n.getFloat32(t,!0),t+=4,s[c*2+1]=n.getFloat32(t,!0),t+=4;if(e.beginPath(),u!==D&&(e.strokeStyle=u,D=u),g!==S&&(e.lineWidth=g,S=g),e.setLineDash([]),e.lineJoin="round",e.lineCap="round",l===2)e.moveTo(s[0],s[1]),e.lineTo(s[2],s[3]);else{e.moveTo(s[0],s[1]);for(let c=0;c<l-1;c++){let h=c>0?c-1:0,y=c,m=c+1,d=c<l-2?c+2:l-1,p=s[h*2],b=s[h*2+1],M=s[y*2],C=s[y*2+1],R=s[m*2],H=s[m*2+1],B=s[d*2],U=s[d*2+1],G=M+(R-p)/6,O=C+(H-b)/6,I=R-(B-M)/6,N=H-(U-C)/6;e.bezierCurveTo(G,O,I,N,R,H)}}e.stroke()}break}case k.TEXT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t];t+=1;let h=n.getUint16(t,!0);t+=2;let y=Rt.decode(new Uint8Array(r.buffer,o+t,h));t+=h,g!==w&&(e.fillStyle=g,w=g);let m=`${Math.round(s)}px "IBM Plex Mono",monospace`;m!==W&&(e.font=m,W=m),e.textAlign=Jt[c]||"left",e.textBaseline="alphabetic";let d=u+vt(e,m);e.fillText(y,dt(l,i),dt(d,i));break}case k.STYLED_TEXT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t];t+=1;let h=a[t];t+=1;let y=n.getUint16(t,!0);t+=2;let m=Rt.decode(new Uint8Array(r.buffer,o+t,y));t+=y,g!==w&&(e.fillStyle=g,w=g);let d=h&2?"italic ":"",p=h&1?"700 ":"",b=`${d}${p}${Math.round(s)}px "IBM Plex Mono",monospace`;b!==W&&(e.font=b,W=b),e.textAlign=Jt[c]||"left",e.textBaseline="alphabetic";let M=u+vt(e,b);e.fillText(m,dt(l,i),dt(M,i));break}case k.CIRCLE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=a[t],c=a[t+1],h=a[t+2],y=a[t+3],m=L?"":$(s,c,h,y);t+=4;let d=a[t],p=a[t+1],b=a[t+2],M=a[t+3],C=L?"":$(d,p,b,M);t+=4;let R=n.getFloat32(t,!0);if(t+=4,L){L.disc(l,u,g,s,c,h,y,d,p,b,M,0,0,0,0,R,0);break}e.beginPath(),e.arc(l,u,g,0,Math.PI*2),m!==w&&(e.fillStyle=m,w=m),e.fill(),R>0&&(C!==D&&(e.strokeStyle=C,D=C),R!==S&&(e.lineWidth=R,S=R),e.stroke());break}case k.TRIANGLE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getFloat32(t,!0);t+=4;let h=n.getFloat32(t,!0);t+=4;let y=a[t],m=a[t+1],d=a[t+2],p=a[t+3];if(t+=4,L){L.tri(l,u,g,s,c,h,y,m,d,p);break}let b=$(y,m,d,p);e.beginPath(),e.moveTo(l,u),e.lineTo(g,s),e.lineTo(c,h),e.closePath(),b!==w&&(e.fillStyle=b,w=b),e.fill();break}case k.SAVE:{e.save(),v.push(it);break}case k.RESTORE:{e.restore(),it=v.length?v.pop():null,L&&L.setClip(it),w="",D="",S=-1,W="";break}case k.CLIP_RECT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=ut(l,u,g,s,i);e.beginPath(),e.rect(c.x,c.y,c.w,c.h),e.clip(),it=c,L&&L.setClip(c);break}case k.ROTATED_TEXT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getFloat32(t,!0);t+=4;let h=n.getUint16(t,!0);t+=2;let y=Rt.decode(a.subarray(t,t+h));t+=h;let m=`${s}px sans-serif`;m!==W&&(e.font=m,W=m),g!==w&&(e.fillStyle=g,w=g),e.textAlign="center",e.textBaseline="alphabetic";let d=vt(e,m);e.save(),e.translate(l,u),e.rotate(c),e.fillText(y,0,d),e.restore();break}case k.BUBBLE_PIE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t],h=a[t+1],y=a[t+2],m=a[t+3];t+=4;let d=a[t],p=a[t+1],b=a[t+2],M=a[t+3];t+=4;let C=a[t]!==0;if(t+=1,L){L.pie(l,u,g,s,c,h,y,m,d,p,b,M,C);break}Vt(e,l,u,g,s,c,h,y,m,d,p,b,M,C),w="";break}case k.BUBBLE_3D:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=a[t],c=a[t+1],h=a[t+2],y=a[t+3];t+=4;let m=a[t],d=a[t+1],p=a[t+2],b=a[t+3];t+=4;let M=a[t],C=a[t+1],R=a[t+2],H=a[t+3];t+=4;let B=n.getFloat32(t,!0);t+=4;let U=g;if(L){L.disc(l,u,U,s,c,h,y,M,C,R,H,m,d,p,b,B,U<4?0:1);break}if(U<4){let G=`rgba(${s},${c},${h},${(y/255).toFixed(3)})`;e.beginPath(),e.arc(l,u,U,0,Math.PI*2),e.fillStyle=G,e.fill(),w=""}else{let G=Math.round(U),O=U>=6,I=U>=16,N=`rgba(${s},${c},${h},${(y/255).toFixed(3)})`,Y=`rgba(${m},${d},${p},${(b/255).toFixed(3)})`,A=I?`rgba(${M},${C},${R},${(H/255*.5).toFixed(3)})`:null,x=Ee(e,G,N,Y,A);e.save(),e.translate(l,u),I&&x.glow&&(e.beginPath(),e.arc(0,0,G*1.2,0,Math.PI*2),e.fillStyle=x.glow,e.fill()),e.beginPath(),e.arc(0,0,G,0,Math.PI*2),e.fillStyle=x.body,e.fill(),O&&(e.beginPath(),e.arc(x.hlX,x.hlY,x.specR,0,Math.PI*2),e.fillStyle=x.spec,e.fill()),e.restore(),w=""}break}case k.FILL_POLYGON:{let l=n.getUint16(t,!0);t+=2;let u=a[t],g=a[t+1],s=a[t+2],c=a[t+3];if(t+=4,L){let y=ye(l*2);for(let m=0;m<l;m++)y[m*2]=n.getFloat32(t,!0),y[m*2+1]=n.getFloat32(t+4,!0),t+=8;L.poly(y,l,u,g,s,c);break}let h=$(u,g,s,c);if(l>2){e.beginPath();let y=n.getFloat32(t,!0);t+=4;let m=n.getFloat32(t,!0);t+=4,e.moveTo(y,m);for(let d=1;d<l;d++)e.lineTo(n.getFloat32(t,!0),n.getFloat32(t+4,!0)),t+=8;e.closePath(),h!==w&&(e.fillStyle=h,w=h),e.fill()}else t+=l*8;break}case k.FILL_SMOOTH_BAND:{let l=n.getUint16(t,!0);t+=2;let u=n.getUint16(t,!0);t+=2;let g=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let s=new Float32Array(l*2);for(let h=0;h<l;h++)s[h*2]=n.getFloat32(t,!0),t+=4,s[h*2+1]=n.getFloat32(t,!0),t+=4;let c=new Float32Array(u*2);for(let h=0;h<u;h++)c[h*2]=n.getFloat32(t,!0),t+=4,c[h*2+1]=n.getFloat32(t,!0),t+=4;l>=2&&u>=2&&(e.beginPath(),g!==w&&(e.fillStyle=g,w=g),l===2?(e.moveTo(s[0],s[1]),e.lineTo(s[2],s[3])):($t(s,l),e.moveTo(s[0],s[1]),qt(e,s,l)),e.lineTo(c[(u-1)*2],c[(u-1)*2+1]),u===2?e.lineTo(c[0],c[1]):($t(c,u),Te(e,c,u)),e.closePath(),e.fill());break}case k.DASHED_POLYLINE:{let l=n.getUint16(t,!0);t+=2;let u=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getFloat32(t,!0);if(t+=4,l>1){e.beginPath(),u!==D&&(e.strokeStyle=u,D=u),g!==S&&(e.lineWidth=g,S=g),e.setLineDash([s,c]),e.lineJoin="round";let h=n.getFloat32(t,!0);t+=4;let y=n.getFloat32(t,!0);t+=4,e.moveTo(h,y);for(let m=1;m<l;m++)e.lineTo(n.getFloat32(t,!0),n.getFloat32(t+4,!0)),t+=8;e.stroke(),e.setLineDash([])}else t+=l*8;break}case k.GRADIENT_RECT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let h=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let y=ut(l,u,g,s,i),m=e.createLinearGradient(y.x,y.y,y.x,y.y+y.h);m.addColorStop(0,c),m.addColorStop(1,h),e.fillStyle=m,w="",e.fillRect(y.x,y.y,y.w,y.h);break}case k.GRADIENT_RECT_H:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let h=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let y=ut(l,u,g,s,i),m=e.createLinearGradient(y.x,y.y,y.x+y.w,y.y);m.addColorStop(0,c),m.addColorStop(1,h),e.fillStyle=m,w="",e.fillRect(y.x,y.y,y.w,y.h);break}case k.GRADIENT_RECT_H_MULTI:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=a[t];t+=1;let h=ut(l,u,g,s,i),y=e.createLinearGradient(h.x,h.y,h.x+h.w,h.y);for(let m=0;m<c;m++){let d=n.getFloat32(t,!0);t+=4;let p=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4,y.addColorStop(d<0?0:d>1?1:d,p)}e.fillStyle=y,w="",e.fillRect(h.x,h.y,h.w,h.h);break}case k.BEGIN_HEATMAP_LAYER:{let l=t-1,u=n.getUint32(t,!0);t+=4;let g=n.getUint32(t,!0);t+=4;let s=n.getUint32(t,!0);if(t+=4,!_||s===0)break;let c=z.canvas.width,h=z.canvas.height,y=`${u}|${g}|${c}|${h}|${i}`;if(_.getKey()===y&&_.getCanvas()){let m=c/i,d=h/i;z.drawImage(_.getCanvas(),0,0,m,d),t=l+s}else{let m=Math.min(i,fe),d=Math.max(1,Math.round(c/i*m)),p=Math.max(1,Math.round(h/i*m)),b=_.ensureSize(d,p,m);if(!b)break;b.save(),b.setTransform(1,0,0,1,0,0),b.clearRect(0,0,d,p),b.restore(),e=b,w="",D="",S=-1,W="",tt=!0,ot=y}break}case k.END_HEATMAP_LAYER:{if(!tt)break;let l=z.canvas.width/i,u=z.canvas.height/i;z.drawImage(_.getCanvas(),0,0,l,u),_.setKey(ot),e=z,w="",D="",S=-1,W="",tt=!1,ot="";break}case k.HEATMAP_BITMAP:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getUint32(t,!0);t+=4;let s=n.getUint32(t,!0);t+=4;let c=g*s*4;if(t+c>a.byteLength){t=a.byteLength;break}let h=new Uint8ClampedArray(a.buffer,a.byteOffset+t,c);t+=c;let y=new ImageData(h,g,s),m=de(g,s);if(!m)break;m.putImageData(y,0,0),e.drawImage(lt,l,u,g,s);break}case k.HEATMAP_WORLD:{let l=n.getUint32(t,!0);t+=4;let u=n.getUint32(t,!0);t+=4;let g=n.getUint32(t,!0);t+=4;let s=n.getUint32(t,!0);t+=4;let c=n.getUint32(t,!0);t+=4;let h=n.getUint32(t,!0);t+=4;let y=n.getFloat32(t,!0);t+=4;let m=n.getFloat32(t,!0);t+=4;let d=n.getFloat32(t,!0);t+=4;let p=n.getFloat32(t,!0);t+=4;let b=n.getFloat32(t,!0);t+=4;let M=n.getFloat32(t,!0);t+=4;let C=n.getFloat32(t,!0);t+=4;let R=n.getFloat32(t,!0);t+=4;let H=a[t];t+=1;let B=(H&1)!==0,U=c*h*4;if(t+U>a.byteLength){t=a.byteLength;break}if(!E||l===0||u===0){t+=U;break}let G=E.ensureSize(l,u);if(!G){t+=U;break}if(B&&G.clearRect(0,0,l,u),U>0){let O=new Uint8ClampedArray(a.buffer,a.byteOffset+t,U),I=new ImageData(O,c,h);G.putImageData(I,g,s)}if(t+=U,d>0&&p>0&&C>0&&R>0){let O=Me(b,M,C,R,i);if(O.w>0&&O.h>0){let I=e.imageSmoothingEnabled;e.imageSmoothingEnabled=!1,e.drawImage(E.getCanvas(),y,m,d,p,O.x,O.y,O.w,O.h),e.imageSmoothingEnabled=I}}break}case k.LINE_WITH_EXTEND:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let h=n.getFloat32(t,!0);t+=4;let y=n.getFloat32(t,!0);t+=4;let m=n.getFloat32(t,!0);t+=4;let d=a[t];t+=1,c!==D&&(e.strokeStyle=c,D=c),h!==S&&(e.lineWidth=h,S=h),e.setLineDash(y>0?[y,m]:[]);let p=1e5,b=l,M=u,C=g,R=s,H=g-l,B=s-u,U=Math.hypot(H,B);if(U>0&&d!==0){let G=H/U,O=B/U;d&1&&(b=l-G*p,M=u-O*p),d&2&&(C=g+G*p,R=s+O*p),d&4&&O<0&&(b=l-G*p,M=u-O*p),d&8&&O>0&&(C=g+G*p,R=s+O*p)}e.beginPath(),e.moveTo(Q(b,h,i),Q(M,h,i)),e.lineTo(Q(C,h,i),Q(R,h,i)),e.stroke(),y>0&&e.setLineDash([]);break}case k.LABEL_CALLOUT:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let s=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let c=$(a[t],a[t+1],a[t+2],a[t+3]);t+=4;let h=n.getFloat32(t,!0);t+=4;let y=n.getFloat32(t,!0);t+=4;let m=a[t];t+=1;let d=a[t];t+=1;let p=n.getUint16(t,!0);t+=2;let b=Rt.decode(a.subarray(t,t+p));t+=p;let M=`${Math.round(h)}px "IBM Plex Mono",monospace`;M!==W&&(e.font=M,W=M);let C=4,R=6,H=b.indexOf(`
|
|
15
|
+
`)>=0?b.split(`
|
|
16
|
+
`):[b],B=Math.round(h),U=3,G=0;for(let K=0;K<H.length;K++){let j=e.measureText(H[K]).width;j>G&&(G=j)}let O=H.length*B+(H.length-1)*U+C*2,I=Math.ceil(G)+C*2,N,Y;switch(d){case 1:Y=u-R-O,N=l-I/2;break;case 2:Y=u+R,N=l-I/2;break;case 3:Y=u-O/2,N=l+R;break;case 4:Y=u-O/2,N=l-R-I;break;default:Y=u-O/2,m===1?N=l-I/2:m===2?N=l-I:N=l;break}let A=ut(N,Y,I,O,i),x=Math.min(3,A.w*.5,A.h*.5),Mt=()=>{e.beginPath(),x<=.5?e.rect(A.x,A.y,A.w,A.h):(e.moveTo(A.x+x,A.y),e.lineTo(A.x+A.w-x,A.y),e.arcTo(A.x+A.w,A.y,A.x+A.w,A.y+x,x),e.lineTo(A.x+A.w,A.y+A.h-x),e.arcTo(A.x+A.w,A.y+A.h,A.x+A.w-x,A.y+A.h,x),e.lineTo(A.x+x,A.y+A.h),e.arcTo(A.x,A.y+A.h,A.x,A.y+A.h-x,x),e.lineTo(A.x,A.y+x),e.arcTo(A.x,A.y,A.x+x,A.y,x)),e.closePath()};if(g!==w&&(e.fillStyle=g,w=g),Mt(),e.fill(),y>0&&(s!==D&&(e.strokeStyle=s,D=s),y!==S&&(e.lineWidth=y,S=y),e.setLineDash([]),Mt(),e.stroke()),d>=1&&d<=4){switch(g!==w&&(e.fillStyle=g,w=g),e.beginPath(),d){case 1:e.moveTo(l-R/2,Y+O),e.lineTo(l+R/2,Y+O),e.lineTo(l,u);break;case 2:e.moveTo(l-R/2,Y),e.lineTo(l+R/2,Y),e.lineTo(l,u);break;case 3:e.moveTo(N,u-R/2),e.lineTo(N,u+R/2),e.lineTo(l,u);break;case 4:e.moveTo(N+I,u-R/2),e.lineTo(N+I,u+R/2),e.lineTo(l,u);break}e.closePath(),e.fill()}c!==w&&(e.fillStyle=c,w=c),e.textAlign="center",e.textBaseline="alphabetic";let Ct=vt(e,M),Pt=N+I/2;for(let K=0;K<H.length;K++){let j=Y+C+B/2+K*(B+U);e.fillText(H[K],dt(Pt,i),dt(j+Ct,i))}break}case k.DRAW_IMAGE:{let l=n.getFloat32(t,!0);t+=4;let u=n.getFloat32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getUint32(t,!0);if(t+=4,!T||c===0||g<=0||s<=0)break;let h=T.get(c);if(!h)break;try{e.drawImage(h,l,u,g,s)}catch(y){T.delete(c),console.warn("[canvasRenderer] drawImage failed for id="+c,y?.message||y)}break}case k.HEATMAP_BG:{let l=a[t],u=a[t+1],g=a[t+2],s=a[t+3],c=a[t+4],h=a[t+5],y=a[t+6],m=a[t+7],d=a[t+8]!==0;t+=9,F&&(e.save(),e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,e.canvas.width,e.canvas.height),e.restore(),F.bg(l,u,g,s,c,h,y,m,d));break}case k.HEATMAP_WORLD_INTENSITY:{let l=n.getUint32(t,!0);t+=4;let u=n.getUint32(t,!0);t+=4;let g=n.getUint32(t,!0);t+=4;let s=n.getUint32(t,!0);t+=4;let c=n.getUint32(t,!0);t+=4;let h=n.getUint32(t,!0);t+=4;let y=n.getFloat32(t,!0);t+=4;let m=n.getFloat32(t,!0);t+=4;let d=n.getFloat32(t,!0);t+=4;let p=n.getFloat32(t,!0);t+=4;let b=n.getFloat32(t,!0);t+=4;let M=n.getFloat32(t,!0);t+=4;let C=n.getFloat32(t,!0);t+=4;let R=n.getFloat32(t,!0);t+=4;let H=n.getUint32(t,!0);t+=4;let B=a[t];t+=1;let U=n.getFloat32(t,!0);t+=4;let G=(B&2)!==0,O=(B&4)!==0,I=B&8?1:0,N=c*h;if(t+N>a.byteLength){t=a.byteLength;break}if(F){let Y=N>0?new Uint8Array(a.buffer,a.byteOffset+t,N):null;F.heatmap({worldCols:l,worldRows:u,patchX:g,patchY:s,patchW:c,patchH:h,srcX:y,srcY:m,srcW:d,srcH:p,destX:b,destY:M,destW:C,destH:R,lutSeq:H,hd:G,subpx:O,subTexelX:U,fullRebuild:(B&1)!==0,layer:I,clip:it},Y)}t+=N;break}case k.OB_HEATMAP:{let l=n.getUint32(t,!0);t+=4;let u=n.getUint32(t,!0);t+=4;let g=n.getFloat32(t,!0);t+=4;let s=n.getFloat32(t,!0);t+=4;let c=n.getFloat32(t,!0);t+=4;let h=n.getFloat32(t,!0);t+=4;let y=a[t],m=a[t+1],d=a[t+2],p=a[t+3];t+=4;let b=n.getFloat32(t,!0);t+=4;let M=n.getUint32(t,!0);t+=4,t+=1;let C=l*u*2;if(t+C>a.byteLength){t=a.byteLength;break}F&&typeof F.obHeatmap=="function"&&F.obHeatmap({cols:l,rows:u,destX:g,destY:s,destW:c,destH:h,bgR:y,bgG:m,bgB:d,bgA:p,alphaMul:b,lutSeq:M},C>0?new Uint8Array(a.buffer,a.byteOffset+t,C):null),t+=C;break}default:t=f;break}}if(tt&&_){let ct=z.canvas.width/i,l=z.canvas.height/i;z.drawImage(_.getCanvas(),0,0,ct,l),_.invalidate()}L&&L.flush()}var Re=`#version 300 es
|
|
17
|
+
in vec2 aPos;
|
|
18
|
+
uniform vec4 uRect; // clip-space x0,y0 (bottom-left) .. x1,y1 (top-right)
|
|
19
|
+
out vec2 vUv;
|
|
20
|
+
void main() {
|
|
21
|
+
vUv = aPos;
|
|
22
|
+
gl_Position = vec4(mix(uRect.xy, uRect.zw, aPos), 0.0, 1.0);
|
|
23
|
+
}`,Le=`#version 300 es
|
|
24
|
+
precision highp float;
|
|
25
|
+
in vec2 vUv;
|
|
26
|
+
uniform sampler2D uCells; // RG8: R = intensity (0 = empty), G = 0 bid / 1 ask
|
|
27
|
+
uniform sampler2D uLut; // 256x2 RGBA: row0 bid ramp, row1 ask ramp
|
|
28
|
+
uniform vec2 uGrid; // cols, rows
|
|
29
|
+
uniform float uAlpha;
|
|
30
|
+
uniform float uPool;
|
|
31
|
+
out vec4 outColor;
|
|
32
|
+
|
|
33
|
+
const int MAX_POOL = 32;
|
|
34
|
+
|
|
35
|
+
void main() {
|
|
36
|
+
float col = clamp(floor(vUv.x * uGrid.x), 0.0, uGrid.x - 1.0);
|
|
37
|
+
float row0 = floor(vUv.y * uGrid.y);
|
|
38
|
+
int pool = int(clamp(uPool, 1.0, float(MAX_POOL)));
|
|
39
|
+
// Not "half" \u2014 that is a GLSL ES reserved word and fails to compile.
|
|
40
|
+
float halfPool = floor(float(pool) * 0.5);
|
|
41
|
+
|
|
42
|
+
float best = 0.0;
|
|
43
|
+
float side = 0.0;
|
|
44
|
+
for (int k = 0; k < MAX_POOL; k++) {
|
|
45
|
+
if (k >= pool) break;
|
|
46
|
+
float r = row0 + float(k) - halfPool;
|
|
47
|
+
if (r < 0.0 || r >= uGrid.y) continue;
|
|
48
|
+
vec2 c = texture(uCells, (vec2(col, r) + 0.5) / uGrid).rg;
|
|
49
|
+
if (c.r > best) { best = c.r; side = c.g; }
|
|
50
|
+
}
|
|
51
|
+
if (best <= 0.0) discard;
|
|
52
|
+
|
|
53
|
+
// best is the normalised byte; land on the matching LUT texel centre.
|
|
54
|
+
vec4 lut = texture(uLut, vec2((best * 255.0 + 0.5) / 256.0, side > 0.5 ? 0.75 : 0.25));
|
|
55
|
+
outColor = vec4(lut.rgb, lut.a * uAlpha);
|
|
56
|
+
}`;function Zt(e,r,o){let f=e.createShader(r);if(e.shaderSource(f,o),e.compileShader(f),!e.getShaderParameter(f,e.COMPILE_STATUS)){let _=e.getShaderInfoLog(f);throw e.deleteShader(f),new Error(`ob shader compile failed: ${_}`)}return f}function te(e,r={}){let o=null,f=null,_=null,E=null,T=null,F=null,P=null,n=null,a=null,t=null,w=-1,D=1,S=1,W=1,i=!1;try{o=e.getContext("webgl2",{alpha:!0,depth:!1,stencil:!1,antialias:!1,preserveDrawingBuffer:!1,desynchronized:!1,premultipliedAlpha:!1})}catch{o=null}if(o)try{let v=Zt(o,o.VERTEX_SHADER,Re),L=Zt(o,o.FRAGMENT_SHADER,Le);if(f=o.createProgram(),o.attachShader(f,v),o.attachShader(f,L),o.linkProgram(f),o.deleteShader(v),o.deleteShader(L),!o.getProgramParameter(f,o.LINK_STATUS))throw new Error(`ob program link failed: ${o.getProgramInfoLog(f)}`);_=o.createVertexArray(),o.bindVertexArray(_),E=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,E),o.bufferData(o.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),o.STATIC_DRAW);let z=o.getAttribLocation(f,"aPos");o.enableVertexAttribArray(z),o.vertexAttribPointer(z,2,o.FLOAT,!1,0,0),o.bindVertexArray(null),T=o.createTexture(),o.bindTexture(o.TEXTURE_2D,T);for(let[tt,ot]of[[o.TEXTURE_MIN_FILTER,o.NEAREST],[o.TEXTURE_MAG_FILTER,o.NEAREST],[o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE],[o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE]])o.texParameteri(o.TEXTURE_2D,tt,ot);F=o.createTexture(),o.bindTexture(o.TEXTURE_2D,F);for(let[tt,ot]of[[o.TEXTURE_MIN_FILTER,o.NEAREST],[o.TEXTURE_MAG_FILTER,o.NEAREST],[o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE],[o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE]])o.texParameteri(o.TEXTURE_2D,tt,ot);P=o.getUniformLocation(f,"uRect"),n=o.getUniformLocation(f,"uGrid"),a=o.getUniformLocation(f,"uAlpha"),t=o.getUniformLocation(f,"uPool"),o.useProgram(f),o.uniform1i(o.getUniformLocation(f,"uCells"),0),o.uniform1i(o.getUniformLocation(f,"uLut"),1),o.disable(o.DEPTH_TEST),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA),o.pixelStorei(o.UNPACK_ALIGNMENT,1),S=e.width,W=e.height,o.viewport(0,0,S,W),i=!0}catch(v){console.warn("[ObWebgl] init failed:",v?.message||v),i=!1}o&&typeof e.addEventListener=="function"&&e.addEventListener("webglcontextlost",v=>{v.preventDefault(),i=!1;try{r.onContextLost?.()}catch{}});function it(v){if(v===w)return;let L=r.fetchLut?.();!L||L.length<512*4||(o.activeTexture(o.TEXTURE1),o.bindTexture(o.TEXTURE_2D,F),o.texImage2D(o.TEXTURE_2D,0,o.RGBA8,256,2,0,o.RGBA,o.UNSIGNED_BYTE,L),w=v)}return{get available(){return i},obHeatmap(v,L){if(!i||(o.viewport(0,0,S,W),o.clearColor(v.bgR/255,v.bgG/255,v.bgB/255,v.bgA/255),o.clear(o.COLOR_BUFFER_BIT),!v.cols||!v.rows||!L||v.destW<=0||v.destH<=0)||L.length<v.cols*v.rows*2)return;o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,T),o.texImage2D(o.TEXTURE_2D,0,o.RG8,v.cols,v.rows,0,o.RG,o.UNSIGNED_BYTE,L),it(v.lutSeq);let z=v.destX*D/S*2-1,tt=(v.destX+v.destW)*D/S*2-1,ot=1-v.destY*D/W*2,ct=1-(v.destY+v.destH)*D/W*2;o.useProgram(f),o.bindVertexArray(_),o.uniform4f(P,z,ct,tt,ot),o.uniform2f(n,v.cols,v.rows),o.uniform1f(a,v.alphaMul),o.uniform1f(t,Math.min(32,Math.max(1,Math.ceil(v.rows/Math.max(v.destH*D,1))))),o.drawArrays(o.TRIANGLE_STRIP,0,4),o.bindVertexArray(null)},resize(v,L,z){S=Math.max(1,v),W=Math.max(1,L),D=z>0?z:1,i&&o.viewport(0,0,S,W)},destroy(){if(i=!1,!!o){try{o.deleteTexture(T),o.deleteTexture(F),o.deleteBuffer(E),o.deleteVertexArray(_),o.deleteProgram(f),o.getExtension("WEBGL_lose_context")?.loseContext()}catch{}o=null}}}}function ee(e,r,o){let f=e&&e[r];typeof f=="function"&&f.apply(e,o||[])}var Ht=null,Nt=null,yt=null;async function ve(){let e=typeof globalThis>"u"?null:globalThis,r=e&&e.__mrdWasmResp;if(!r)return null;e.__mrdWasmResp=null;try{let o=await r;return o&&o.ok?o:null}catch{return null}}function ke(){if(typeof WorkerGlobalScope>"u"||!self.location?.search)return null;let e=r=>new URL(r+self.location.search,self.location.href).href;return{glue:e("./chart_engine.js"),wasm:e("./chart_engine_bg.wasm")}}async function oe(){return Ht?{module:Ht,memory:Nt}:yt||(yt=(async()=>{let e=ke(),r=e?await import(e.glue):await import("./chart_engine.js"),o=e?null:await ve(),f=e?e.wasm:o;try{await(f?r.default({module_or_path:f}):r.default())}catch(_){console.warn("[mrd-chart] WebAssembly streaming init failed, retrying with arrayBuffer fallback:",_);let E=e?e.wasm:new URL("../wasm/chart_engine_bg.wasm",import.meta.url),T=await fetch(E);if(!T.ok)throw new Error(`WASM fetch failed (${T.status} ${T.statusText}) at ${E}`);let F=await T.arrayBuffer();await r.default(F)}return Nt=r.wasm_memory(),Ht=r,{module:r,memory:Nt}})(),yt.catch(()=>{yt=null}),yt)}async function ne(e){if(!Array.isArray(e)||!e.length||typeof FontFace!="function"||!self.fonts)return;let r=!1,o=new Promise(_=>setTimeout(()=>{r=!0,_()},1500)),f=e.map(async _=>{try{let E={weight:_.weight,style:_.style};_.unicodeRange&&(E.unicodeRange=_.unicodeRange);let T=new FontFace(_.family,`url(${_.src})`,E);await T.load(),r||self.fonts.add(T)}catch{}});await Promise.race([Promise.all(f),o])}function ae(e){let r=e.get_hover_price();return r>0?{price:r,qty:e.get_hover_qty(),side:e.get_hover_side()===2?"ask":"bid"}:null}var Se={OrderbookEngine:{gl:!0,readState(e){let r=ae(e),o=null;if(e.is_range_active()){let f=e.get_range_low_price(),_=e.get_range_high_price();_>f&&(o={low:f,high:_,delta:_-f,deltaPct:f>0?(_-f)/f*100:0,bidQty:e.get_range_bid_qty(),askQty:e.get_range_ask_qty(),ticks:e.get_range_tick_count(),mode:e.get_range_mode()===2?"hover":"measure"})}return{hover:r,range:o}},sig:e=>`${e.hover?`${e.hover.price}|${e.hover.qty}|${e.hover.side}`:""}#${e.range?`${e.range.low}|${e.range.high}|${e.range.bidQty}|${e.range.askQty}|${e.range.mode}`:""}`,clickHover:ae},DomLadderEngine:{gl:!0,lut:"dom",readState(e){let r=e.get_hover_price();return{hover:r>0?{price:r,side:e.get_hover_side()===1?"ask":"bid"}:null,viewLocked:e.is_view_locked(),m1:e.momentum_1m(),buy1m:e.buy_volume_1m(),sell1m:e.sell_volume_1m(),map:typeof e.ladder_view_map=="function"?e.ladder_view_map():null,lanes:typeof e.ladder_lane_map=="function"?e.ladder_lane_map():null,colScroll:typeof e.column_scroll_state=="function"?e.column_scroll_state():null}},sig:e=>{let r=e.map,o=r&&r.length?`${r.length}|${r[0]}|${r[1]}|${r[2]}|${r[3]}|${r[r.length-1]}`:"",f=e.lanes,_=f&&f.length?f.join("|"):"",E=e.colScroll,T=E&&E.length>=2?`${E[0]}|${E[1]}`:"";return`${e.hover?`${e.hover.price}|${e.hover.side}`:""}#${e.viewLocked}#${e.m1}|${e.buy1m}|${e.sell1m}#${o}#${_}#${T}`},clickHover(e){let r=e.get_hover_price();return r>0?{price:r,side:e.get_hover_side()===1?"ask":"bid"}:null}}},X=null,st=null,Xt=null,V=null,q=null,Z=null,at=null,nt=1,Tt=!1,Yt=!1,et=!1,wt=!1,Ft=!1,ft=!0,ht=null,re="",se=typeof self.requestAnimationFrame=="function",Wt=!0,Gt=0,Ce=1500;function gt(e,r,o){try{self.postMessage({t:e,...r},o||[])}catch{}}function Et(e){et||(et=!0,kt(),gt("dead",{err:String(e&&e.message?e.message:e)}))}function bt(){Yt||!Tt||et||Ft||ht!==null||Wt&&(ht=se?self.requestAnimationFrame(le):setTimeout(le,16))}function kt(){ht!==null&&(se?self.cancelAnimationFrame(ht):clearTimeout(ht),ht=null)}function pt(){ft=!0,bt()}function ie(){try{q.save(),q.setTransform(1,0,0,1,0,0),q.clearRect(0,0,V.width,V.height),q.fillStyle="#787b86",q.font=`600 ${Math.round(12*nt)}px ui-monospace, 'SF Mono', Menlo, Consolas, monospace`,q.textAlign="center",q.textBaseline="middle",q.fillText("Enterprise license required",V.width/2,V.height/2),q.restore()}catch{}}function xt(){if(et)return!1;if(Ft)return ie(),!0;try{if(X.render()>0){let r=X.get_command_buffer_ptr(),o=X.get_command_buffer_len();q.save(),q.setTransform(1,0,0,1,0,0),q.clearRect(0,0,V.width,V.height),q.restore(),jt(q,Xt,r,o,null,null,null,at)}return!0}catch(e){return e instanceof WebAssembly.RuntimeError&&Et(e),!1}}function le(){if(ht=null,Yt||!Tt||et||Ft)return;let e=!1;try{X.set_now_ms?.(Date.now()),e=ft||X.is_dirty()}catch(f){Et(f);return}let r=wt&&Gt>0&&Date.now()-Gt>Ce;e&&wt&&!r?ft=!0:e&&(ft=!xt(),De());let o=ft;if(!o)try{o=X.is_dirty()}catch{o=!1}o&&bt()}function Pe(){if(et||!V)return null;let e=V.width,r=V.height;if(!(e>0)||!(r>0)||!xt())return null;try{let o=new OffscreenCanvas(e,r),f=o.getContext("2d");return f?(at&&Z&&f.drawImage(Z,0,0),f.drawImage(V,0,0),o.transferToImageBitmap()):null}catch{return null}}function De(){if(et||!st)return;let e=null;try{e=st.readState(X)}catch{return}let r=st.sig(e);r!==re&&(re=r,gt("state",e,e.map&&e.map.buffer?[e.map.buffer]:[]))}function Ie(){try{X?.set_render_backend(0)}catch{}try{at?.destroy()}catch{}at=null,pt()}function Be(){if(!(!Z||!st.gl||typeof X.set_render_backend!="function"))try{let e=st.lut==="dom"?()=>X.dom_lut_rgba():()=>X.ob_lut_rgba(),r=te(Z,{fetchLut:e,onContextLost:Ie});if(!r.available){r.destroy();return}r.resize(Z.width,Z.height,nt),at=r,X.set_render_backend(1)}catch(e){console.warn("[PanelEngine/worker] GL band unavailable, using Canvas2D:",e?.message||e),at=null}}function St(e,r){if(!(et||!X))try{ee(X,e,r),ft=!0}catch(o){o instanceof WebAssembly.RuntimeError&&Et(o)}}async function Ue(e){if(st=Se[e.engine],!st)throw new Error(`unknown panel engine: ${e.engine}`);V=e.canvas,Z=e.gl||null,nt=e.dpr||1,Ft=!!e.blocked;let[{module:r,memory:o}]=await Promise.all([oe(),ne(e.opts.fonts)]);Xt=o,q=V.getContext("2d"),q.setTransform(nt,0,0,nt,0,0);let f=r[e.engine];if(typeof f!="function")throw new Error(`engine missing in wasm: ${e.engine}`);X=new f(e.cssW,e.cssH);try{X.set_license_token?.(e.opts.licenseToken||"",Date.now(),e.opts.host||"")}catch(_){console.warn("[PanelEngine/worker] set_license_token failed:",_.message)}for(let[_,E]of e.opts.boot||[])St(_,E);Be(),Ft&&ie(),gt("ready",{})}self.onmessage=e=>{let r=e.data;if(r)switch(r.t){case"init":Ue(r).catch(o=>Et(o));return;case"call":St(r.m,r.a),bt();return;case"calls":for(let[o,f]of r.batch)St(o,f);bt();return;case"query":{let o=null;try{let f=X&&X[r.m];typeof f=="function"&&(o=f.apply(X,r.a||[]))}catch{o=null}gt("reply",{id:r.id,v:o});return}case"capture":{let o=Pe();gt("reply",{id:r.id,v:o},o?[o]:[]);return}case"domVol":{let o=r.flat;if(!o)return;for(let f=0;f+2<o.length;f+=3)St("push_dom_vol",[o[f],o[f+1],o[f+2]]);bt();return}case"click":{if(et||!X)return;let o=null;try{X.set_hover(r.x,r.y),o=st.clickHover(X)}catch{return}ft=!0,bt(),o&>("click",{hover:o});return}case"resize":{if(et||!X)return;nt=r.dpr||1;let o=V.width!==r.bufW||V.height!==r.bufH;V.width!==r.bufW&&(V.width=r.bufW),V.height!==r.bufH&&(V.height=r.bufH),q.setTransform(nt,0,0,nt,0,0),Z&&(Z.width!==r.bufW&&(Z.width=r.bufW),Z.height!==r.bufH&&(Z.height=r.bufH),at?.resize(r.bufW,r.bufH,nt));try{X.resize(r.cssW,r.cssH)}catch(f){Et(f);return}o&&xt(),pt();return}case"life":if(r.v==="start")Tt=!0,pt();else if(r.v==="stop")Tt=!1,kt();else if(r.v==="destroy"){Yt=!0,Tt=!1,kt();try{at?.destroy()}catch{}at=null;try{X?.free()}catch{}X=null}return;case"vis":Wt=!!r.v,Wt?pt():kt();return;case"busy":wt=!!r.v,Gt=wt?Date.now():0,wt||pt();return;case"heap":gt("heap",{bytes:Xt?.buffer?.byteLength||0});return;default:}};
|