@supersolutions/super-chart-web 0.0.0-stage → 0.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/LICENSE +674 -0
- package/README.md +8 -2
- package/dist/annotations.d.ts +124 -0
- package/dist/annotations.js +315 -0
- package/dist/chunk-PTYNDDEE.js +3082 -0
- package/dist/engine.d.ts +147 -0
- package/dist/engine.js +6 -0
- package/dist/index.d.ts +413 -0
- package/dist/index.js +1807 -0
- package/dist/overlays.d.ts +24 -0
- package/dist/overlays.js +109 -0
- package/dist/super-chart.engine.global.js +7 -0
- package/dist/super-chart.global.js +75 -0
- package/package.json +65 -4
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EngineFrame, MarketBar, MarketOverlayFrame, MarketOverlayOptions } from '@supersolutions/super-chart-core';
|
|
2
|
+
|
|
3
|
+
/** Optional paint layer. Callbacks read borrowed data; they must not mutate chart state. */
|
|
4
|
+
export interface EngineLayer {
|
|
5
|
+
update: (frame: EngineFrame, revealedRawBars: readonly MarketBar[]) => void;
|
|
6
|
+
paint: (context: CanvasRenderingContext2D) => void;
|
|
7
|
+
dispose?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export interface MarketOverlayRenderOptions {
|
|
10
|
+
up?: string;
|
|
11
|
+
down?: string;
|
|
12
|
+
profile?: string;
|
|
13
|
+
/** Show value-area boundaries in addition to the point of control. */
|
|
14
|
+
showValueArea?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Canvas-only paint; projection and raw-data calculations stay platform neutral. */
|
|
17
|
+
export declare function paintMarketOverlays(ctx: CanvasRenderingContext2D, frame: MarketOverlayFrame, options?: MarketOverlayRenderOptions): void;
|
|
18
|
+
/** Import on demand; the base engine does not import the market detectors. */
|
|
19
|
+
export declare function createMarketOverlayLayer(options: MarketOverlayOptions, render?: MarketOverlayRenderOptions): EngineLayer & {
|
|
20
|
+
getSnapshot: () => MarketOverlayFrame | null;
|
|
21
|
+
};
|
|
22
|
+
export * from "@supersolutions/super-chart-core";
|
|
23
|
+
|
|
24
|
+
export {};
|
package/dist/overlays.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// packages/bindings/web/src/overlayEntry.ts
|
|
2
|
+
export * from "@supersolutions/super-chart-core";
|
|
3
|
+
|
|
4
|
+
// packages/bindings/web/src/marketOverlayLayer.ts
|
|
5
|
+
import { projectMarketOverlays } from "@supersolutions/super-chart-core";
|
|
6
|
+
|
|
7
|
+
// packages/bindings/web/src/marketOverlayRenderer.ts
|
|
8
|
+
function paintMarketOverlays(ctx, frame, options = {}) {
|
|
9
|
+
const { bounds, profile, zones } = frame;
|
|
10
|
+
if (profile === null && zones.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
const up = options.up ?? "#26a69a", down = options.down ?? "#ef5350";
|
|
13
|
+
const profileColor = options.profile ?? "#7e57c2";
|
|
14
|
+
ctx.save();
|
|
15
|
+
try {
|
|
16
|
+
ctx.beginPath();
|
|
17
|
+
ctx.rect(bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top);
|
|
18
|
+
ctx.clip();
|
|
19
|
+
const alpha = ctx.globalAlpha;
|
|
20
|
+
ctx.lineWidth = 1;
|
|
21
|
+
for (const zone of zones) {
|
|
22
|
+
const color = zone.direction === "bullish" ? up : down;
|
|
23
|
+
const { x, y, width, height } = zone.rect;
|
|
24
|
+
ctx.fillStyle = color;
|
|
25
|
+
if (zone.kind === "fair-value-gap") {
|
|
26
|
+
ctx.globalAlpha = alpha * (zone.status === "filled" ? 0.08 : 0.22);
|
|
27
|
+
ctx.fillRect(x, y, width, height);
|
|
28
|
+
} else {
|
|
29
|
+
const mitigated = zone.status === "mitigated";
|
|
30
|
+
ctx.globalAlpha = alpha * (mitigated ? 0.06 : 0.16);
|
|
31
|
+
ctx.fillRect(x, y, width, height);
|
|
32
|
+
ctx.setLineDash(mitigated ? [3, 3] : []);
|
|
33
|
+
ctx.globalAlpha = alpha * (mitigated ? 0.35 : 0.9);
|
|
34
|
+
ctx.strokeStyle = color;
|
|
35
|
+
ctx.strokeRect(x, y, width, height);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (profile !== null) {
|
|
39
|
+
ctx.fillStyle = profileColor;
|
|
40
|
+
for (const row of profile.rows) {
|
|
41
|
+
if (row.rect === null)
|
|
42
|
+
continue;
|
|
43
|
+
ctx.globalAlpha = alpha * (row.pointOfControl ? 0.65 : 0.32);
|
|
44
|
+
ctx.fillRect(row.rect.x, row.rect.y, row.rect.width, row.rect.height);
|
|
45
|
+
}
|
|
46
|
+
ctx.strokeStyle = profileColor;
|
|
47
|
+
const line = (y, opacity, dash) => {
|
|
48
|
+
if (y === null)
|
|
49
|
+
return;
|
|
50
|
+
ctx.globalAlpha = alpha * opacity;
|
|
51
|
+
ctx.setLineDash(dash);
|
|
52
|
+
ctx.beginPath();
|
|
53
|
+
ctx.moveTo(bounds.left, y);
|
|
54
|
+
ctx.lineTo(bounds.right, y);
|
|
55
|
+
ctx.stroke();
|
|
56
|
+
};
|
|
57
|
+
line(profile.pocY, 0.9, [4, 4]);
|
|
58
|
+
if (options.showValueArea) {
|
|
59
|
+
line(profile.vahY, 0.5, [2, 4]);
|
|
60
|
+
line(profile.valY, 0.5, [2, 4]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} finally {
|
|
64
|
+
ctx.restore();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// packages/bindings/web/src/marketOverlayLayer.ts
|
|
69
|
+
function createMarketOverlayLayer(options, render = {}) {
|
|
70
|
+
const settings = {
|
|
71
|
+
...options,
|
|
72
|
+
volumeProfile: typeof options.volumeProfile === "object" ? { ...options.volumeProfile } : options.volumeProfile,
|
|
73
|
+
orderBlocks: typeof options.orderBlocks === "object" ? { ...options.orderBlocks } : options.orderBlocks
|
|
74
|
+
};
|
|
75
|
+
const style = { ...render };
|
|
76
|
+
let projected = null;
|
|
77
|
+
return {
|
|
78
|
+
update: (frame, bars) => {
|
|
79
|
+
projected = projectMarketOverlays(frame, bars, settings);
|
|
80
|
+
},
|
|
81
|
+
paint: (context) => {
|
|
82
|
+
if (projected === null)
|
|
83
|
+
return;
|
|
84
|
+
paintMarketOverlays(context, projected, style);
|
|
85
|
+
const statuses = Object.values(projected.status);
|
|
86
|
+
const message = statuses.includes("invalid-data") ? "Overlay data unavailable" : statuses.includes("too-wide") ? "Zoom in to display imbalance zones" : statuses.includes("missing-volume") ? "Volume profile needs reported volume" : "";
|
|
87
|
+
if (message !== "") {
|
|
88
|
+
context.save();
|
|
89
|
+
try {
|
|
90
|
+
context.font = "12px system-ui";
|
|
91
|
+
context.textAlign = "left";
|
|
92
|
+
context.textBaseline = "bottom";
|
|
93
|
+
context.fillStyle = "#d6deea";
|
|
94
|
+
context.fillText(message, projected.bounds.left + 6, projected.bounds.bottom - 6, Math.max(1, projected.bounds.right - projected.bounds.left - 12));
|
|
95
|
+
} finally {
|
|
96
|
+
context.restore();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
getSnapshot: () => projected,
|
|
101
|
+
dispose: () => {
|
|
102
|
+
projected = null;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
createMarketOverlayLayer,
|
|
108
|
+
paintMarketOverlays
|
|
109
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var SuperChartEngine=(()=>{var mt=Object.defineProperty;var Un=Object.getOwnPropertyDescriptor;var Vn=Object.getOwnPropertyNames;var qn=Object.prototype.hasOwnProperty;var Kn=(e,t)=>{for(var i in t)mt(e,i,{get:t[i],enumerable:!0})},Xn=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Vn(t))!qn.call(e,r)&&r!==i&&mt(e,r,{get:()=>t[r],enumerable:!(n=Un(t,r))||n.enumerable});return e};var Jn=e=>Xn(mt({},"__esModule",{value:!0}),e);var Jr={};Kn(Jr,{EngineChart:()=>ft});function U(e){return new Array(e).fill(null)}function ie(e){return Number.isInteger(e)&&e>=1}function Zn(e,t,i){let n=0;for(let r=t;r<=i;r++)n+=e[r];return n}function pe(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=0,o=-1,s=!1,a=0,l=0,u=0;for(let h=0;h<i;h++){let c=e[h];if(c==null){r=0,s=!1;continue}if(r++,Number.isFinite(c)||(o=h),!(r<t)){if(o>h-t){n[h]=Zn(e,h-t+1,h),s=!1;continue}if(!s||++u>=t){a=0,l=0;for(let d=h-t+1;d<=h;d++){let f=e[d],m=a+f;l+=Math.abs(a)>=Math.abs(f)?a-m+f:f-m+a,a=m}u=0,s=!0}else{let d=-e[h-t],f=a+d;l+=Math.abs(a)>=Math.abs(d)?a-f+d:d-f+a,a=f,f=a+c,l+=Math.abs(a)>=Math.abs(c)?a-f+c:c-f+a,a=f}n[h]=a+l}}return n}function ge(e,t){let i=pe(e,t);for(let n=0;n<i.length;n++){let r=i[n];r!=null&&(i[n]=r/t)}return i}function Ae(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=t*(t+1)/2,o=0,s=-1,a=!1,l=0,u=0,h=0;for(let c=0;c<i;c++){let d=e[c];if(d==null){o=0,a=!1;continue}if(o++,Number.isFinite(d)||(s=c),!(o<t)){if(s>c-t){let f=0;for(let m=0;m<t;m++)f+=e[c-t+1+m]*(m+1);n[c]=f/r,a=!1;continue}if(!a||++h>=t){l=0,u=0;for(let f=0;f<t;f++){let m=e[c-t+1+f];l+=m,u+=m*(f+1)}h=0,a=!0}else u=u-l+t*d,l=l-e[c-t]+d;n[c]=u/r}}return n}function Xt(e,t){if(!ie(t)||t<2)return U(e.length);let i=Ae(e,Math.floor(t/2)),n=Ae(e,t),r=i.map((o,s)=>{let a=n[s];return o==null||a==null?null:2*o-a});return Ae(r,Math.round(Math.sqrt(t)))}function Jt(e,t,i){let n=e.map((a,l)=>{let u=t[l];return a==null||u==null?null:a*u}),r=t.map((a,l)=>e[l]==null?null:a),o=pe(n,i),s=pe(r,i);return o.map((a,l)=>{let u=s[l];return a==null||u==null||u===0?null:a/u})}function me(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=null,o=0,s=0;for(let a=0;a<i;a++){let l=e[a];l!=null&&(r==null?(o+=l,s++,s===t&&(r=o/t,n[a]=r)):(r=(2*l+(t-1)*r)/(t+1),n[a]=r))}return n}function pt(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=null,o=0,s=0;for(let a=0;a<i;a++){let l=e[a];l!=null&&(r==null?(o+=l,s++,s===t&&(r=o/t,n[a]=r)):(r=(r*(t-1)+l)/t,n[a]=r))}return n}function Kt(e,t){return t===0?100:e===0?0:100-100/(1+e/t)}function Ve(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=0,o=0,s=null,a=0;for(let l=0;l<i;l++){let u=e[l];if(u==null){s=null;continue}if(s!=null){let h=u-s,c=Math.max(h,0),d=Math.max(-h,0);a<t?(r+=c,o+=d,a++,a===t&&(r/=t,o/=t,n[l]=Kt(r,o))):(r=(r*(t-1)+c)/t,o=(o*(t-1)+d)/t,n[l]=Kt(r,o))}s=u}return n}function gt(e,t=12,i=26,n=9,r={}){let o=r.histMultiplier??1,s=me(e,t),a=me(e,i),l=s.map((c,d)=>{let f=a[d];return c==null||f==null?null:c-f}),u=me(l,n),h=l.map((c,d)=>{let f=u[d];return c==null||f==null?null:(c-f)*o});return{dif:l,dea:u,hist:h}}function yt(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=0,o=-1,s=!1,a=0,l=0,u=0;for(let h=0;h<i;h++){let c=e[h];if(c==null){r=0,s=!1;continue}if(r++,Number.isFinite(c)||(o=h),r<t)continue;if(o>h-t||!s||++u>=t){let m=0;for(let w=h-t+1;w<=h;w++)m+=e[w];let v=m/t,g=0;for(let w=h-t+1;w<=h;w++)g+=(e[w]-v)**2;n[h]=Math.sqrt(g/t),s=!(o>h-t),s&&(a=v,l=g,u=0);continue}let d=e[h-t],f=a+(c-d)/t;l+=(c-d)*(c-f+d-a),a=f,n[h]=Math.sqrt(Math.max(l,0)/t)}return n}function vt(e,t){let i=e.length,n=U(i);if(!ie(t))return n;let r=0;for(let o=0;o<i;o++){if(e[o]==null){r=0;continue}if(r++,r<t)continue;let s=0;for(let u=o-t+1;u<=o;u++)s+=e[u];let a=s/t,l=0;for(let u=o-t+1;u<=o;u++)l+=Math.abs(e[u]-a);n[o]=l/t}return n}function qe(e,t,i=2){let n=ge(e,t),r=yt(e,t),o=n.map((a,l)=>{let u=r[l];return a==null||u==null?null:a+i*u}),s=n.map((a,l)=>{let u=r[l];return a==null||u==null?null:a-i*u});return{basis:n,upper:o,lower:s}}function Zt(e,t,i){let n=e.length,r=U(n);if(!ie(t)||t>n)return r;let o=new Int32Array(t),s=0,a=0,l=0,u=-1;for(let h=0;h<n;h++){let c=e[h];if(c==null){l=0,s=0,a=0;continue}if(l++,a>0&&o[s]<=h-t&&(s=s+1===t?0:s+1,a--),Number.isNaN(c))u=h;else{for(;a>0;){let f=s+a-1,m=e[o[f>=t?f-t:f]];if(i?m<=c:m>=c)a--;else break}let d=s+a;o[d>=t?d-t:d]=h,a++}l<t||(r[h]=u>h-t?NaN:a>0?e[o[s]]:i?-1/0:1/0)}return r}function Ke(e,t){return Zt(e,t,!0)}function Xe(e,t){return Zt(e,t,!1)}function Qn(e,t,i,n){let r=0,o=0,s=0,a=0;for(let c=0;c<i;c++){let d=e[t-i+1+c];r+=c,o+=d,s+=c*c,a+=c*d}let l=i*s-r*r;if(l===0)return o/i;let u=(i*a-r*o)/l;return(o-u*r)/i+u*(i-1-n)}function Qt(e,t,i=0){let n=e.length,r=U(n);if(!ie(t))return r;let o=t*(t-1)/2,s=(t-1)*t*(2*t-1)/6,a=t*s-o*o,l=0,u=-1,h=0,c=0,d=0,f=t;for(let m=0;m<n;m++){let v=e[m];if(v==null){l=0,f=t;continue}if(l++,Number.isFinite(v)||(u=m),l<t)continue;if(u>m-t){r[m]=Qn(e,m,t,i),f=t;continue}if(f>=t){h=e[m-t+1],c=0,d=0;for(let b=0;b<t;b++){let p=e[m-t+1+b]-h;c+=p,d+=b*p}f=0}else{let b=e[m-t]-h,p=v-h;d=d-(c-b)+(t-1)*p,c=c-b+p,f++}if(a===0){r[m]=c/t+h;continue}let g=(t*d-o*c)/a,w=(c-g*o)/t;r[m]=w+g*(t-1-i)+h}return r}var er=32,tr=64;function ei(e,t,i){let n=e.length,r=U(n);if(!ie(i))return r;let o=0,s=-1,a=!1,l=0,u=0,h=0,c=0,d=0,f=0,m=0,v=0,g=Math.min(i,tr),w=b=>{u=e[b-i+1],h=t[b-i+1],c=0,d=0;for(let p=b-i+1;p<=b;p++)c+=e[p]-u,d+=t[p]-h;c/=i,d/=i,f=0,m=0,v=0;for(let p=b-i+1;p<=b;p++){let y=e[p]-u-c,_=t[p]-h-d;f+=y*y,m+=_*_,v+=y*_}};for(let b=0;b<n;b++){let p=e[b],y=t[b];if(p==null||y==null){o=0,a=!1;continue}if(o++,(!Number.isFinite(p)||!Number.isFinite(y))&&(s=b),o<i)continue;if(s>b-i){let F=0,D=0,k=0,S=0,T=0;for(let A=b-i+1;A<=b;A++){let O=e[A],E=t[A];F+=O,D+=E,k+=O*O,S+=E*E,T+=O*E}let P=F/i,z=D/i,Y=Math.sqrt((k/i-P*P)*(S/i-z*z));r[b]=Y===0?null:(T/i-P*z)/Y,a=!1;continue}if(i<=er||!a||++l>=g)w(b),l=0,a=!0;else{let F=e[b-i]-u,D=t[b-i]-h,k=p-u,S=y-h,T=k-F,P=S-D,z=c+T/i,Y=d+P/i;f+=T*(k-z+F-c),m+=P*(S-Y+D-d),v+=T*(S-Y)+P*(F-c),c=z,d=Y}let _=f<=i*(16*Number.EPSILON*Math.max(Math.abs(u+c),1e-300))**2,N=m<=i*(16*Number.EPSILON*Math.max(Math.abs(h+d),1e-300))**2;r[b]=_||N?null:Math.max(-1,Math.min(1,v/Math.sqrt(f*m)))}return r}function wt(e,t=1){return e.map((i,n)=>{let r=n-t>=0?e[n-t]:null;return i==null||r==null?null:i-r})}function ti(e,t){return wt(e,t)}function ii(e,t){return e.map((i,n)=>{let r=n-t>=0?e[n-t]:null;return i==null||r==null||r===0?null:100*(i-r)/r})}function ni(e,t){return e.map((i,n)=>{let r=e[n-1],o=t[n-1],s=t[n];return i==null||s==null||r==null||o==null?null:r<=o&&i>s?1:0})}function ri(e,t){return e.map((i,n)=>{let r=e[n-1],o=t[n-1],s=t[n];return i==null||s==null||r==null||o==null?null:r>=o&&i<s?1:0})}function si(e,t){return e.map((i,n)=>{let r=e[n-1],o=t[n-1],s=t[n];return i==null||s==null||r==null||o==null?null:r<=o&&i>s||r>=o&&i<s?1:0})}function oi(e){let t=U(e.length),i=0;for(let n=0;n<e.length;n++){let r=e[n];r!=null&&(i+=r,t[n]=i)}return t}function ai(e){let t=U(e.length),i=null;for(let n=0;n<e.length;n++){let r=e[n];r!=null&&r!==0?i=0:i!=null&&i++,t[n]=i}return t}function li(e,t,i=0){let n=U(e.length);if(i===0){let a;for(let l=0;l<e.length;l++){let u=e[l];u!=null&&u!==0&&(a=l),n[l]=a===void 0?null:t[a]}return n}if(!Number.isInteger(i)||i<0||i>=e.length)return n;let r=[],o=i+1,s=0;for(let a=0;a<e.length;a++){let l=e[a];l!=null&&l!==0&&(r[s]=a,s=(s+1)%o);let u=r.length===o?r[s]:void 0;n[a]=u==null?null:t[u]}return n}function ci(e,t,i,n){let r=t+i+1;return r>=64&&r<=e.length&&Number.isSafeInteger(t)&&Number.isSafeInteger(i)&&t>=0&&i>=0&&e.every(o=>o==null||Number.isFinite(o))?ir(e,r,i,n):nr(e,t,i,n)}function ir(e,t,i,n){let r=U(e.length),o=new Int32Array(t),s=0,a=0,l=0;for(let u=0;u<e.length;u++){let h=e[u];if(h==null){s=0,a=0,l=0;continue}for(l++,a>0&&o[s]<=u-t&&(s=s+1===t?0:s+1,a--);a>0;){let f=s+a-1,m=e[o[f>=t?f-t:f]];if(n==="high"?m<h:m>h)a--;else break}let c=s+a;o[c>=t?c-t:c]=u,a++;let d=u-i;l>=t&&o[s]===d&&(r[u]=e[d])}return r}function nr(e,t,i,n){let r=U(e.length);for(let o=t;o<e.length-i;o++){let s=e[o];if(s==null)continue;let a=!0;for(let l=o-t;l<=o+i;l++){if(l===o)continue;let u=e[l];if(u==null){a=!1;break}if(n==="high"?u>s:u<s){a=!1;break}if(u===s&&l<o){a=!1;break}}a&&(r[o+i]=s)}return r}function bt(e,t,i){return e.map((n,r)=>{let o=t[r],s=r>0?i[r-1]:null;return n==null||o==null?null:s==null?n-o:Math.max(n-o,Math.abs(n-s),Math.abs(o-s))})}function Le(e,t,i,n){return pt(bt(e,t,i),n)}function ui(e,t){let i=U(e.length),n=0,r=null;for(let o=0;o<e.length;o++){let s=e[o],a=t[o]??0;s!=null&&(r!=null&&(n+=s>r?a:s<r?-a:0),i[o]=n,r=s)}return i}function hi(e,t,i,n){let r=U(i.length),o=0,s=0;for(let a=0;a<i.length;a++){let l=e[a],u=t[a],h=i[a],c=n[a]??0;l==null||u==null||h==null||(o+=(l+u+h)/3*c,s+=c,r[a]=s===0?null:o/s)}return r}function di(e,t,i){return e.map((n,r)=>{let o=t[r],s=i[r];return n==null||o==null||s==null?null:(n+o+s)/3})}function fi(e,t,i,n){let r=di(e,t,i),o=ge(r,n),s=vt(r,n);return r.map((a,l)=>{let u=o[l],h=s[l];return a==null||u==null||h==null||h===0?null:(a-u)/(.015*h)})}function mi(e,t,i,n,r){let o=i.length,s=di(e,t,i),a=new Array(o).fill(0),l=new Array(o).fill(0);for(let c=1;c<o;c++){let d=s[c],f=s[c-1],m=n[c]??0;d==null||f==null||(d>f?a[c]=d*m:d<f&&(l[c]=d*m))}let u=pe(a,r),h=pe(l,r);return u.map((c,d)=>{let f=h[d];return c==null||f==null?null:f===0?100:100-100/(1+c/f)})}function Je(e,t,i,n){let r=Ke(e,n),o=Xe(t,n);return i.map((s,a)=>{let l=r[a],u=o[a];if(s==null||l==null||u==null)return null;let h=l-u;return h===0?0:100*(s-u)/h})}function pi(e,t,i=.02,n=.02,r=.2){let o=e.length,s=U(o);if(o<2)return s;let a=e[0],l=t[0],u=e[1],h=t[1];if(a==null||l==null||u==null||h==null)return s;let c=u>=a,d=i,f=c?u:h,m=c?l:a;for(let v=1;v<o;v++){let g=e[v],w=t[v];g==null||w==null||(m=m+d*(f-m),c?w<m?(c=!1,m=f,f=w,d=i):g>f&&(f=g,d=Math.min(d+n,r)):g>m?(c=!0,m=f,f=g,d=i):w<f&&(f=w,d=Math.min(d+n,r)),s[v]=m)}return s}function gi(e,t){return e.map((i,n)=>{let r=t[n];return i==null||r==null?null:(i+r)/2})}function xt(e,t){return Je(e,e,e,t)}function yi(e,t,i,n,r){let o=ge(xt(Ve(e,t),i),n);return{k:o,d:ge(o,r)}}function vi(e,t,i=2){let{upper:n,lower:r}=qe(e,t,i);return e.map((o,s)=>{let a=n[s],l=r[s];return o==null||a==null||l==null||a===l?null:(o-l)/(a-l)})}function wi(e,t,i,n=20,r=2,o=10){let s=me(i,n),a=Le(e,t,i,o),l=u=>s.map((h,c)=>{let d=a[c];return h==null||d==null?null:h+u*r*d});return{basis:s,upper:l(1),lower:l(-1)}}function Re(e,t,i=20){let n=Ke(e,i),r=Xe(t,i);return{basis:gi(n,r),upper:n,lower:r}}function bi(e,t,i,n=14,r=2){let o=Le(e,t,i,n),s=a=>i.map((l,u)=>{let h=o[u];return l==null||h==null?null:l+a*r*h});return{basis:i.slice(),upper:s(1),lower:s(-1)}}function xi(e,t,i,n=10,r=3){let o=i.length,s=U(o),a=U(o),l=Le(e,t,i,n),u=0,h=0,c=null,d=null;for(let f=0;f<o;f++){let m=e[f],v=t[f],g=i[f],w=l[f];if(m==null||v==null||g==null||w==null){d=w??null;continue}let b=(m+v)/2,p=f>0?i[f-1]:null,y=b+r*w,_=b-r*w;_=_>h||p!=null&&p<h?_:h,y=y<u||p!=null&&p>u?y:u;let N;d==null?N=!1:c===u?N=g>y:N=!(g<_);let F=N?_:y;s[f]=F,a[f]=N?1:-1,u=y,h=_,c=F,d=w}return{line:s,trend:a}}function _i(e,t,i,n=9,r=26,o=52,s=26){let a=i.length,l=Re(e,t,n).basis,u=Re(e,t,r).basis,h=gi(l,u),c=Re(e,t,o).basis,d=Math.max(0,Math.floor(s)-1),f=U(a),m=U(a),v=U(a);for(let b=0;b<a;b++)b-d>=0&&(f[b]=h[b-d],m[b]=c[b-d]),b+d<a&&(v[b]=i[b+d]);let g=U(d),w=U(d);for(let b=0;b<d;b++){let p=a-d+b;p>=0&&(g[b]=h[p],w[b]=c[p])}return{conversion:l,base:u,spanA:f,spanB:m,lagging:v,futureA:g,futureB:w}}function Mi(e,t,i,n,r,o=!1){let s=i.length,a=U(s),l=U(s),u=null,h=-1,c=0,d=0,f=0,m=0;for(let v=0;v<s;v++){let g=r[v],w=e[v],b=t[v],p=i[v];if(g==null||w==null||b==null||p==null)continue;let y=(w+b+p)/3;g!==u&&(u=g,h++,c=y,d=0,f=0,m=0);let _=n[v]??0,N=y-c;if(d+=_,f+=_*N,m+=_*N*N,!(o&&h===0)&&d>0){let F=f/d;a[v]=c+F,l[v]=Math.sqrt(Math.max(0,m/d-F*F))}}return{vwap:a,stdev:l}}var rr=new WeakMap;function _t(e){return rr.get(e)}var sr=new WeakMap;function Ii(e){return sr.get(e)}var Pe;function Ei(e,t){let i=Pe;Pe={bars:e,fields:new Map};try{return t()}finally{Pe=i}}function ki(e,t,i="raw"){let n=Pe?.bars===e?Pe.fields:void 0,r=i+":"+t,o=n?.get(r);if(o!==void 0)return o;let s=new Array(e.length);for(let a=0;a<e.length;a++){let l=e[a][t];s[a]=typeof l!="number"||i!=="raw"&&!Number.isFinite(l)||i==="volume"&&l<0?null:l}return n?.set(r,s),s}function We(e,t){if(e.length===0||!Number.isFinite(t))return null;let i=0,n=e.length;for(;i<n;){let r=i+Math.floor((n-i)/2);e[r].timestamp<t?i=r+1:n=r}return i===0?0:i===e.length||t-e[i-1].timestamp<=e[i].timestamp-t?i-1:i}var or=1e11;function Ji(){return{notArray:!1,dropped:0,duplicates:0,unsorted:!1,seconds:!1,coerced:!1}}function ye(e){return typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):NaN}function Rt(e){return typeof e=="object"&&e!==null}function Zi(e){if(!Array.isArray(e))return;let t=-1/0;for(let i of e)if(Rt(i)){let n=ye(i.timestamp);Number.isFinite(n)&&n>t&&(t=n)}if(t!==-1/0)return t<or?1e3:1}function Di(e){return e==null||typeof e=="number"&&Number.isFinite(e)}function ar(e,t){if(t!==1)return!1;let i=-1/0;for(let n of e){if(!Rt(n))return!1;let{timestamp:r,open:o,high:s,low:a,close:l}=n;if(typeof r!="number"||typeof o!="number"||typeof s!="number"||typeof a!="number"||typeof l!="number"||!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(l)||r<=i||!Di(n.volume)||!Di(n.turnover))return!1;i=r}return!0}function tt(e,t,i=Ji()){if(!Rt(e))return i.dropped++,null;let n=ye(e.timestamp)*t,r=ye(e.open),o=ye(e.high),s=ye(e.low),a=ye(e.close);if(!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(s)||!Number.isFinite(a))return i.dropped++,null;(typeof e.timestamp!="number"||typeof e.open!="number"||typeof e.high!="number"||typeof e.low!="number"||typeof e.close!="number")&&(i.coerced=!0);let l={...e,timestamp:n,open:r,high:o,low:s,close:a};for(let u of["volume","turnover"]){let h=e[u];if(h==null)continue;let c=ye(h);typeof h!="number"&&(i.coerced=!0),l[u]=Number.isFinite(c)?c:void 0}return l}function Ne(e,t){let i=Ji();if(!Array.isArray(e))return i.notArray=!0,{bars:[],unit:t??1,issues:i};let n=t??Zi(e)??1;if(ar(e,n))return{bars:e,unit:n,issues:i};i.seconds=n===1e3;let r=[],o=!0;for(let a of e){let l=tt(a,n,i);l!==null&&(r.length>0&&l.timestamp<r[r.length-1].timestamp&&(o=!1),r.push(l))}o||(i.unsorted=!0,r.sort((a,l)=>a.timestamp-l.timestamp));let s=0;for(let a of r){let l=s>0?r[s-1]:void 0;l!==void 0&&l.timestamp===a.timestamp?(r[s-1]=a,i.duplicates++):r[s++]=a}return r.length=s,{bars:r,unit:n,issues:i}}function lr(e,t,i){return Math.min(i,Math.max(t,e))}function He(e){let t=1/0,i=1/0,n=-1/0;for(let s of e)for(let a of[s.open,s.high,s.low,s.close])typeof a!="number"||!Number.isFinite(a)||(a>0&&a<t&&(t=a),a<i&&(i=a),a>n&&(n=a));if(!Number.isFinite(t))return 2;let r=lr(Math.ceil(-Math.log10(t))+3,2,10),o=n-i;if(Number.isFinite(o)&&o>0)for(;r<10&&o<10**-r;)r++;return r}function Ye(e,t,i=52,n=12){let r=Math.max(1,e),o=Math.max(1,t),s=Math.max(52,Math.min(i,r*.34)),a=Math.max(s+1,r-Math.max(12,Math.min(n,r*.34))),l=12,u=Math.max(l+1,o-34);return{width:r,height:o,left:s,right:a,top:l,bottom:u,plotWidth:a-s,plotHeight:u-l}}function Ct(e){if(typeof e=="number")return e;let t=Number(e);return Number.isFinite(t)?t:Date.parse(e)}function Ni(e,t){return String(t==="category"?e:Ct(e))}function Qi(e){return Number.isFinite(e.o)&&Number.isFinite(e.h)&&Number.isFinite(e.l)&&Number.isFinite(e.c)&&e.h>=Math.max(e.o,e.c)&&e.l<=Math.min(e.o,e.c)}function en(e){let t=new Map,i=l=>{if(typeof l=="number")return l;let u=Number(l);if(Number.isFinite(u))return u;let h=t.get(l);return h===void 0&&(h=Date.parse(l),t.set(l,h)),h},n=e.series??[],r=n.reduce((l,u)=>l==null||u.points.length>l.points.length?u:l,null),o=new Set,s=[],a=l=>{if(e.xType!=="category"&&!Number.isFinite(i(l)))return;let u=e.xType==="category"?String(l):String(i(l));o.has(u)||(o.add(u),s.push(l))};for(let l of e.candles??[])Qi(l)&&a(l.t);if(r!=null)for(let l of r.points)Number.isFinite(l[1])&&a(l[0]);for(let l of n)for(let u of l.points)Number.isFinite(u[1])&&a(u[0]);return e.xType==="category"?s:s.sort((l,u)=>i(l)-i(u))}function Ti(e,t,i=3){if(e===t)return[e];let n=(t-e)/i,r=10**Math.floor(Math.log10(n)),o=[1,2,5,10].map(a=>a*r).find(a=>a>=n)??10*r,s=[];for(let a=Math.ceil(e/o)*o;a<=t+o*.001;a+=o)s.push(Number(a.toFixed(10)));return s.length>0?s:[e,t]}function Si(e,t){if(e.length===0)return[0,1];let i=1/0,n=-1/0;for(let o of e)i=Math.min(i,o),n=Math.max(n,o);let r=n>i?(n-i)*.12:Math.max(Math.abs(n)*.05,.01);return[t?Math.min(0,i):i-r,t?Math.max(.01,n+r):n+r]}function tn(e,t,i,n=52,r,o=52){let s=new Map,a=x=>{if(typeof x=="number"||e.xType==="category")return Ni(x,e.xType);let C=s.get(x);return C===void 0&&(C=Ni(x,e.xType),s.set(x,C)),C},l=en(e),u=Math.max(0,Math.min(r?.start??0,Math.max(0,l.length-1))),h=Math.max(u+1,Math.min(r?.end??l.length,l.length)),c=l.slice(u,h),d=new Set(c.map(x=>a(x))),f=e.series??[],m=(e.candles??[]).filter(x=>Qi(x)&&d.has(a(x.t))),v=f.some(x=>x.axis==="right"),g=Ye(t,i,n,v?o:12),w=new Map(c.map((x,C)=>[a(x),C])),b=f.map(x=>({source:x,points:x.points.filter(C=>d.has(a(C[0]))&&Number.isFinite(C[1]))})),p=m.flatMap(x=>[x.h,x.l]).filter(Number.isFinite),y=[];for(let{source:x,points:C}of b){let j=x.axis==="right"?y:p;for(let L of C)j.push(L[1])}if(e.stacked)for(let x of["left","right"]){let C=new Map;for(let{source:L,points:W}of b)if(!(L.type!=="bar"||(L.axis??"left")!==x))for(let H of W){let $=a(H[0]),R=C.get($);R==null&&(R=[0,0],C.set($,R)),R[H[1]>=0?0:1]+=H[1]}let j=x==="right"?y:p;for(let L of c){let W=C.get(a(L));j.push(W?.[0]??0,W?.[1]??0)}}let _=e.scale==="zero"||e.scale!=="tight"&&f.length>0&&f.every(x=>x.type==="bar"),[N,F]=Si(p,_||f.some(x=>x.type==="bar"&&(x.axis??"left")==="left")),[D,k]=Si(y,_||f.some(x=>x.type==="bar"&&x.axis==="right")),S=e.xType==="category"?[]:c.map(Ct),T=S[0]??0,P=S[S.length-1]??1,z=(x,C)=>e.xType==="category"?g.left+(c.length<2?g.plotWidth/2:C/(c.length-1)*g.plotWidth):g.left+(P===T?g.plotWidth/2:(Ct(x)-T)/(P-T)*g.plotWidth),Y=(x,C="left")=>{let j=C==="right"?D:N,L=C==="right"?k:F;return g.bottom-(x-j)/(L-j)*g.plotHeight},A=c.map((x,C)=>z(x,C)),O=c.length<3?c.map((x,C)=>C):[...new Set([0,Math.floor((c.length-1)/2),c.length-1])],E=b.map(({source:x,points:C})=>({source:x,points:C.map(([j,L])=>{let W=w.get(a(j))??0;return{x:z(j,W),y:Y(L,x.axis),value:L,key:j,index:W}}).filter(j=>Number.isFinite(j.x)&&Number.isFinite(j.y))})),M=m.map(x=>{let C=w.get(a(x.t))??0;return{...x,x:z(x.t,C),bodyTop:Y(Math.max(x.o,x.c)),bodyBottom:Y(Math.min(x.o,x.c)),wickTop:Y(x.h),wickBottom:Y(x.l),index:C}});return s.clear(),{geometry:g,min:N,max:F,yTicks:Ti(N,F),rightMin:D,rightMax:k,rightTicks:v?Ti(D,k):[],hasRightAxis:v,xKeys:c,allKeys:l,start:u,end:h,xPositions:A,xTickIndices:O,plottedSeries:E,plottedCandles:M,x:z,y:Y}}function it(e,t){if(e.xPositions.length===0)return null;let i=e.xPositions;if(!Number.isFinite(t))return 0;if(!Number.isFinite(i[0])||!Number.isFinite(i[i.length-1])){let a=0;for(let l=1;l<i.length;l++)Math.abs(i[l]-t)<Math.abs(i[a]-t)&&(a=l);return a}let n=a=>{let l=0,u=i.length;for(;l<u;){let h=l+u>>>1;i[h]<a?l=h+1:u=h}return l},r=n(t),o=Math.max(0,r-1),s=r<i.length&&Math.abs(i[r]-t)<Math.abs(i[o]-t)?r:o;return n(i[s])}var nn=12;function ue(e={}){let t=e.minBars??nn,i=e.maxBars??Number.MAX_SAFE_INTEGER,n=e.rightPaddingBars??0;if(!Number.isSafeInteger(t)||t<1||!Number.isSafeInteger(i)||i<t||!Number.isSafeInteger(n)||n<0)throw new RangeError("Viewport bounds must be safe integers: 1 <= minBars <= maxBars, rightPaddingBars >= 0");return{minBars:t,maxBars:i,rightPaddingBars:n}}var Pt=90;function Lt(e,t=Pt,i){if(!Number.isFinite(e)||e<=0)return{i0:0,i1:0};let n=ue(i),r=Math.min(Number.MAX_SAFE_INTEGER,e+n.rightPaddingBars),o=Math.max(1,Math.min(t,r,n.maxBars));return ve({i0:r-o,i1:r-1},e,n)}function ve(e,t,i){if(!Number.isFinite(t)||t<=0)return{i0:0,i1:0};let n=ue(i);if(!Number.isFinite(e.i0)||!Number.isFinite(e.i1))return Lt(t,Pt,n);let r=Math.min(Number.MAX_SAFE_INTEGER,t+n.rightPaddingBars),o=Math.min(n.minBars,r),s=Math.round(e.i0),a=Math.round(e.i1);a<s&&([s,a]=[a,s]);let l=Math.max(o,Math.min(a-s+1,r,n.maxBars));return s=Math.max(0,Math.min(s,r-l,t-1)),a=s+l-1,a>r-1&&(a=r-1,l=a-s+1),{i0:s,i1:a}}function re(e){return e.i1-e.i0+1}function rn(e,t,i,n,r){if(t<=0||!Number.isFinite(i)||i<=0||!Number.isFinite(n))return ve(e,t,r);let o=re(e),s=ue(r),a=Math.min(Number.MAX_SAFE_INTEGER,t+s.rightPaddingBars),l=Math.min(s.minBars,a),u=Math.max(l,Math.min(a,s.maxBars,Math.round(o/i))),h=Math.max(0,Math.min(1,n)),c=e.i0+h*(o-1),d=Math.round(c-h*(u-1));return ve({i0:d,i1:d+u-1},t,r)}function sn(e,t,i,n){if(t<=0||!Number.isFinite(i))return ve(e,t,n);let r=Math.round(i);return ve({i0:e.i0+r,i1:e.i1+r},t,n)}function nt(e,t={}){let i=ue(t),n=t.minCandleSpacing??1.5,r=t.maxCandleSpacing??40;if(!Number.isFinite(e)||!Number.isFinite(n)||n<=0||!Number.isFinite(r)||r<n)throw new RangeError("Viewport density requires a finite width and positive ordered candle spacing");if(e<=0)return i;let o=Math.min(i.maxBars,Math.max(i.minBars,Math.floor(e/n)+1)),s=Math.min(o,Math.max(i.minBars,Math.ceil(e/r)+1));return{...i,minBars:s,maxBars:o}}function on(e){let t=null,i=null;return e.map(n=>{let{open:r,high:o,low:s,close:a}=n;if(!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(s)||!Number.isFinite(a))return t=null,i=null,n;let l=(r+o+s+a)/4,u=t===null||i===null?(r+a)/2:(t+i)/2,h=Math.max(o,u,l),c=Math.min(s,u,l);return t=u,i=l,{...n,open:u,high:h,low:c,close:l}})}var Bt=class{_bars=[];_ha=null;_ma=[];_ema=[];_sum=0;_previous=null;_sumBeforeLast=0;_emaBeforeLast=null;_version=0;_more=!1;_loadMore=null;_listeners=new Set;_referenceIndicators;constructor(e={}){this._referenceIndicators=e.referenceIndicators!==!1}get version(){return this._version}get hasMore(){return this._more}getDataList(){return this._bars}getLastTimestamp(){return this._bars[this._bars.length-1]?.timestamp}snapshot(e=0,t=this._bars.length,i="raw"){let n=this._bars;return i==="heikin-ashi"&&(this._ha===null&&(this._ha=on(this._bars)),n=this._ha),{version:this._version,bars:n.slice(e,t).map(r=>({...r})),ma20:this._ma.slice(e,t),ema21:this._ema.slice(e,t)}}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}loadMore(e){this._loadMore=e}requestMore(){this._more&&this._loadMore?.(this._bars[0]?.timestamp??null)}applyNewData(e,t=!1){this._bars=this._copyValidated(e),this._more=t,this._rebuild(),this._emit("reset",0)}truncateData(e,t,i){return!Number.isSafeInteger(e)||e<1||e>this._bars.length||this._bars.length!==t||this.getLastTimestamp()!==i?!1:(e===this._bars.length||(this._bars.length=e,this._referenceIndicators?this._rebuild():this._ha!==null&&(this._ha.length=e),this._emit("truncate",e)),!0)}applyMoreData(e,t=!1){this._validate(e);let i=this._bars[0]?.timestamp??1/0,n=e.filter(o=>o.timestamp<i).map(o=>({...o})),r=this._more!==t;if(this._more=t,n.length===0){r&&this._emit("availability",this._bars.length);return}this._bars=n.concat(this._bars),this._rebuild(),this._emit("prepend",0)}updateData(e){this.updateDataBatch([e])}updateDataBatch(e,t){this._validate(e,!0);let i=t!==void 0&&this._more!==t;t!==void 0&&(this._more=t);let n=this._bars.length,r=!1;for(let o of e){let s=this._bars.length-1,a=this._bars[s];a!==void 0&&o.timestamp<a.timestamp||(a!==void 0&&o.timestamp===a.timestamp?(this._bars[s]={...o},this._sum=this._sumBeforeLast,this._previous=this._emaBeforeLast,this._calculate(s),n=Math.min(n,s)):(this._bars.push({...o}),this._calculate(s+1)),r=!0)}r?this._emit("tail",n):i&&this._emit("availability",this._bars.length)}_rebuild(){if(this._ha!==null&&(this._ha=[]),this._ma=[],this._ema=[],this._sum=0,this._previous=null,this._sumBeforeLast=0,this._emaBeforeLast=null,this._referenceIndicators||this._ha!==null)for(let e=0;e<this._bars.length;e++)this._calculate(e)}_calculate(e){if(this._referenceIndicators){this._sumBeforeLast=this._sum,this._emaBeforeLast=this._previous;let t=this._bars[e].close;this._sum+=t,e>=20&&(this._sum-=this._bars[e-20].close),this._ma[e]=e>=19?this._sum/20:null,this._previous=this._previous===null?t:t*(2/22)+this._previous*(1-2/22),this._ema[e]=e>=20?this._previous:null}if(this._ha!==null){let t=this._bars[e],i=this._ha[e-1],n=(t.open+t.high+t.low+t.close)/4,r=i===void 0?(t.open+t.close)/2:(i.open+i.close)/2;this._ha[e]={...t,open:r,close:n,high:Math.max(t.high,r,n),low:Math.min(t.low,r,n)}}}_copyValidated(e){let t=[],i=-1/0;for(let n of e){let r={...n};this._validateBar(r,i,!1),t.push(r),i=r.timestamp}return t}_validateBar(e,t,i){if(!Number.isFinite(e.timestamp)||!Number.isFinite(e.open)||!Number.isFinite(e.high)||!Number.isFinite(e.low)||!Number.isFinite(e.close)||(i?e.timestamp<t:e.timestamp<=t))throw new RangeError("RealtimeSeries requires finite OHLC and ascending normalized timestamps")}_validate(e,t=!1){let i=-1/0;for(let n of e)this._validateBar(n,i,t),i=n.timestamp}_emit(e,t){let i={kind:e,from:t,length:this._bars.length,version:++this._version};for(let n of[...this._listeners])n(i)}};function we(e,t,i){if(t<=0)return{i0:0,i1:0};if(!Number.isFinite(e.i0)||!Number.isFinite(e.i1))throw new RangeError("Viewport must be finite");let n=Math.min(e.i0,e.i1),r=Math.max(e.i0,e.i1),o=ue(i),s=Math.min(Number.MAX_SAFE_INTEGER,t+o.rightPaddingBars),a=Math.max(Math.min(o.minBars,s),Math.min(s,o.maxBars,r-n+1)),l=Math.max(0,Math.min(n,s-a,t-1));return{i0:l,i1:Math.min(s-1,l+a-1)}}function be(e,t,i,n,r){if(!Number.isFinite(i)||i<=0||!Number.isFinite(n))return we(e,t,r);let o=Math.max(0,Math.min(1,n)),s=re(e),a=ue(r),l=Math.min(Number.MAX_SAFE_INTEGER,t+a.rightPaddingBars),u=Math.max(Math.min(a.minBars,l),Math.min(l,a.maxBars,s/i)),h=e.i0+o*(s-u);return we({i0:h,i1:h+u-1},t,r)}var Ot=class{constructor(e,t={}){this._series=e;let i=t.navigationHistory??32;if(!Number.isSafeInteger(i)||i<0||i>100)throw new RangeError("Navigation history must be an integer from 0 to 100");this._historyLimit=i,this._continuous=t.continuous===!0,this._limits=Object.freeze(ue(t.limits)),this._count=this._validCount(t.count??160),this._openingCount=this._count,this._mode=t.mode??"raw",this._length=e.getDataList().length,this._viewport=this._default(this._count),this._snapshot=this._read(),this._unsubscribe=e.subscribe(n=>{this._changed(n)})}_viewport;_length;_following=!0;_count;_mode;_snapshot;_disposed=!1;_unsubscribe;_listeners=new Set;_continuous;_limits;_openingCount;_historyLimit;_past=[];_future=[];_navigationStart=null;getSnapshot=()=>this._snapshot;subscribe=e=>this._disposed?()=>{}:(this._listeners.add(e),()=>{this._listeners.delete(e)});getLimits(){return this._limits}setLimits(e){if(this._disposed)return;let t=ue(e);t.minBars===this._limits.minBars&&t.maxBars===this._limits.maxBars&&t.rightPaddingBars===this._limits.rightPaddingBars||(this._limits=Object.freeze(t),this._count=this._validCount(this._count),this._viewport=this._following?this._default(this._count):this._clamp(this._viewport),this._navigationStart!==null&&(this._navigationStart=this._navigationState()),this._publish())}setViewport(e){if(this._disposed||this._length===0||!Number.isFinite(e.i0)||!Number.isFinite(e.i1))return;let t=this._clamp(e);if(!this._following&&t.i0===this._viewport.i0&&t.i1===this._viewport.i1)return;let i=this._navigationStart===null?this._navigationState():null;this._following=!1,this._viewport=t,this._count=re(t),i!==null&&this._recordNavigation(i),this._publish()}pan(e){!Number.isFinite(e)||e===0||this.setViewport(this._continuous?{i0:this._viewport.i0+e,i1:this._viewport.i1+e}:sn(this._viewport,this._length,e,this._limits))}zoom(e,t=.5){!Number.isFinite(e)||e<=0||!Number.isFinite(t)||this.setViewport((this._continuous?be:rn)(this._viewport,this._length,e,t,this._limits))}followLatest(e=this._count){if(this._disposed)return;let t=this._validCount(e),i=this._default(t);if(this._following&&t===this._count&&i.i0===this._viewport.i0&&i.i1===this._viewport.i1)return;let n=this._navigationStart===null?this._navigationState():null;this._count=t,this._following=!0,this._viewport=i,n!==null&&this._recordNavigation(n),this._publish()}resetViewport(){this.followLatest(this._openingCount)}beginNavigation(){!this._disposed&&this._navigationStart===null&&(this._navigationStart=this._navigationState())}endNavigation(){let e=this._navigationStart;this._navigationStart=null,!this._disposed&&e!==null&&this._recordNavigation(e)&&this._publish(!1,!0)}getNavigationHistory(){return{canUndo:this._past.length>0,canRedo:this._future.length>0,limit:this._historyLimit}}clearNavigationHistory(){if(this._disposed)return;let e=this._past.length>0||this._future.length>0;this._past.length=0,this._future.length=0,this._navigationStart=null,e&&this._publish(!1,!0)}undoNavigation(){if(this._disposed)return!1;this.endNavigation();let e=this._past.pop();return e===void 0?!1:(this._future.push(this._navigationState()),this._restoreNavigation(e),!0)}redoNavigation(){if(this._disposed)return!1;this.endNavigation();let e=this._future.pop();return e===void 0?!1:(this._past.push(this._navigationState()),this._restoreNavigation(e),!0)}setMode(e){this._disposed||e===this._mode||(this._mode=e,this._publish())}seek(e,t=.5){if(this._disposed||!Number.isFinite(t))return!1;let i=We(this._series.getDataList(),e);if(i===null)return!1;let n=re(this._viewport),r=Math.max(0,Math.min(1,t))*(n-1),o=i-(this._continuous?r:Math.round(r));return this.setViewport({i0:o,i1:o+n-1}),!0}requestMore(){this._disposed||this._series.requestMore()}dispose(){this._disposed||(this._disposed=!0,this._unsubscribe(),this._listeners.clear(),this._past.length=0,this._future.length=0,this._navigationStart=null)}_navigationState(){return{viewport:{...this._viewport},count:this._count,following:this._following}}_recordNavigation(e){return this._historyLimit===0||e.following===this._following&&(this._following?e.count===this._count:e.viewport.i0===this._viewport.i0&&e.viewport.i1===this._viewport.i1)?!1:(this._past.push(e),this._past.length>this._historyLimit&&this._past.shift(),this._future.length=0,!0)}_restoreNavigation(e){this._following=e.following,this._count=this._validCount(e.count),this._viewport=this._following?this._default(this._count):this._clamp(e.viewport),this._following||(this._count=re(this._viewport)),this._publish()}_validCount(e){if(!Number.isFinite(e)||e<1)throw new RangeError("View count must be a positive finite number");return Math.max(this._limits.minBars,Math.min(this._limits.maxBars,this._continuous?e:Math.floor(e)))}_clamp(e){return(this._continuous?we:ve)(e,this._length,this._limits)}_default(e){let t=Math.min(Number.MAX_SAFE_INTEGER,this._length+this._limits.rightPaddingBars);return this._continuous?this._clamp({i0:Math.max(0,t-e),i1:Math.max(0,t-1)}):Lt(this._length,e,this._limits)}_changed(e){let t=this._length;if(this._length=e.length,e.kind==="reset"||e.kind==="truncate")this._past.length=0,this._future.length=0,this._navigationStart=null,e.kind==="reset"&&(this._following=!0);else if(e.kind==="prepend"){let r=this._length-t;for(let o of[...this._past,...this._future,...this._navigationStart===null?[]:[this._navigationStart]])o.viewport={i0:o.viewport.i0+r,i1:o.viewport.i1+r}}if(this._following)this._viewport=this._default(this._count);else if(e.kind==="prepend"){let r=this._length-t;this._viewport=this._clamp({i0:this._viewport.i0+r,i1:this._viewport.i1+r})}else this._viewport=this._clamp(this._viewport);let i=this._continuous?Math.ceil(this._viewport.i1):this._viewport.i1;if(e.kind==="tail"&&t===this._length&&e.from>i&&this._snapshot.hasMore===this._series.hasMore)return;let n=(e.kind==="availability"||e.kind==="tail"&&e.from>i)&&this._snapshot.viewport.i0===this._viewport.i0&&this._snapshot.viewport.i1===this._viewport.i1;this._publish(n,e.kind==="availability"||e.kind==="tail"&&t===this._length&&e.from===t-1)}_read(e){let t=this._continuous?Math.floor(this._viewport.i0):this._viewport.i0,i=Math.min(this._length-1,this._continuous?Math.ceil(this._viewport.i1):this._viewport.i1),n=this._snapshot,r=this._continuous&&n!==void 0&&n.version===this._series.version&&n.mode===this._mode&&n.dataStart===t&&Math.min(n.length-1,Math.ceil(n.viewport.i1))===i,o=r?n:this._series.snapshot(t,i+1,this._mode);return Object.freeze({...o,...this._continuous?{dataStart:t}:{},bars:r?n.bars:Object.freeze(o.bars.map(s=>Object.freeze(s))),ma20:Object.freeze(o.ma20),ema21:Object.freeze(o.ema21),viewport:e!==void 0&&e.i0===this._viewport.i0&&e.i1===this._viewport.i1?e:Object.freeze({...this._viewport}),length:this._length,hasMore:this._series.hasMore,following:this._following,mode:this._mode})}_publish(e=!1,t=!1){this._snapshot=e?Object.freeze({...this._snapshot,version:this._series.version,length:this._length,hasMore:this._series.hasMore}):this._read(t&&this._continuous?this._snapshot.viewport:void 0);for(let i of[...this._listeners])i()}};function an(e,t,i){if(t.dataStart===void 0||t.viewport.i1<=t.viewport.i0||t.bars.length===0)return;let n=t.dataStart,r=e.geometry,o=i==="category"||t.bars.length===1,s=c=>{if(t.bars.length===1)return t.bars[0].timestamp;let d=c-n,f=Math.max(0,Math.min(t.bars.length-2,Math.floor(d))),m=t.bars[f].timestamp,v=t.bars[f+1].timestamp;return m+(v-m)*(d-f)},a=s(t.viewport.i0),l=s(t.viewport.i1);e.x=(c,d)=>r.left+(o?(n+d-t.viewport.i0)/(t.viewport.i1-t.viewport.i0):(Number(c)-a)/(l-a))*r.plotWidth,e.xPositions=e.xKeys.map((c,d)=>e.x(c,d));for(let c of e.plottedCandles)c.x=e.x(c.t,c.index);for(let c of e.plottedSeries)for(let d of c.points)d.x=e.x(d.key,d.index);let u=Math.max(0,Math.ceil(t.viewport.i0)-n),h=Math.min(e.xKeys.length-1,Math.floor(t.viewport.i1)-n);e.xTickIndices=h<u?[]:[...new Set([u,Math.floor((u+h)/2),h])]}function Te(e){if(e.mode!==void 0&&!["linear","log","percentage"].includes(e.mode))throw new RangeError("Unknown price scale");if(e.range!==void 0){let[t,i]=e.range;if(!Number.isFinite(t)||!Number.isFinite(i)||t>=i||e.mode==="log"&&t<=0)throw new RangeError("Invalid price scale range")}}function zt(e,t,i,n={},r=1){Te(n);let o=n.mode??"linear";if(o==="percentage"&&(!Number.isFinite(r)||r===0))throw new RangeError("Percentage scale requires a finite nonzero reference price");let s=Math.abs(r),a=o==="log"?p=>Math.log(p):o==="percentage"?p=>(p-r)/s*100:p=>p,l=o==="log"?p=>Math.exp(p):o==="percentage"?p=>r+p/100*s:p=>p,u=1/0,h=-1/0;for(let p of e){if(!Number.isFinite(p)||o==="log"&&p<=0)continue;let y=a(p);u=Math.min(u,y),h=Math.max(h,y)}if(n.range!==void 0)u=a(n.range[0]),h=a(n.range[1]);else{Number.isFinite(u)||(u=0,h=1);let p=h>u?(h-u)*.08:o==="log"?Math.log(1.05):u===0?.01:Math.max(Number.MIN_VALUE,Math.abs(u)*.05);u-=p,h+=p}let c=h-u,d=Math.max(1,i-t),f=p=>{let y=(a(p)-u)/c;return n.reversed===!0?t+y*d:i-y*d},m=p=>l(u+(n.reversed===!0?p-t:i-p)/d*c),v=c/4,g=10**Math.floor(Math.log10(v)),w=([1,2,5,10].find(p=>p*g>=v)??10)*g,b=[];if(Number.isFinite(w)&&w>0){let p=Math.ceil(u/w)*w;for(let y=0;y<12&&p+y*w<=h;y++)b.push(l(p+y*w))}return{min:l(u),max:l(h),ticks:b,y:f,value:m,label:(p,y)=>o==="percentage"?`${a(p).toFixed(2)}%`:p.toFixed(y)}}function Se(e){if(e.axisGutter!==void 0&&(!Number.isFinite(e.axisGutter)||e.axisGutter<0))throw new RangeError("Axis gutter must be finite and nonnegative");if(e.priceRatio!==void 0&&(!Number.isFinite(e.priceRatio)||e.priceRatio<.3||e.priceRatio>.85))throw new RangeError("Price ratio must be from 0.3 to 0.85");if(e.paneWeights!==void 0&&(e.paneWeights===null||typeof e.paneWeights!="object"||Array.isArray(e.paneWeights)||Object.values(e.paneWeights).some(t=>!Number.isFinite(t)||t<=0)))throw new RangeError("Pane weights must be positive finite numbers")}function cr(e,t,i,n){let r=zt(t,e.geometry.top,e.geometry.bottom,i,n);e.min=r.min,e.max=r.max,e.yTicks=r.ticks,e.y=r.y;for(let o of e.plottedCandles){let s=r.y(o.o),a=r.y(o.c),l=r.y(o.h),u=r.y(o.l);o.bodyTop=Math.min(s,a),o.bodyBottom=Math.max(s,a),o.wickTop=Math.min(l,u),o.wickBottom=Math.max(l,u)}e.plottedCandles=e.plottedCandles.filter(o=>Number.isFinite(o.wickTop)&&Number.isFinite(o.wickBottom));for(let o of e.plottedSeries)o.points=o.points.map(s=>({...s,y:r.y(s.value)})).filter(s=>Number.isFinite(s.y));return r}function ur(e,t,i,n,r,o,s,a,l,u){let h=Ye(n,r,o,12),c=e.bars.length,d=zt(a,h.top,h.bottom,s,l),f=e.viewport.i1-e.viewport.i0,m=e.dataStart!==void 0&&f>0&&c>0,v=(y,_)=>h.left+(m?(e.dataStart+_-e.viewport.i0)/f*h.plotWidth:c<2?h.plotWidth/2:_/(c-1)*h.plotWidth),g=e.bars.map(y=>y.timestamp),w=g.map(v),b=c<3?g.map((y,_)=>_):[0,Math.floor((c-1)/2),c-1];if(m){let y=Math.max(0,Math.ceil(e.viewport.i0)-e.dataStart),_=Math.min(c-1,Math.floor(e.viewport.i1)-e.dataStart);b=_<y?[]:[...new Set([y,Math.floor((y+_)/2),_])]}let p={geometry:h,min:d.min,max:d.max,yTicks:d.ticks,rightMin:0,rightMax:1,rightTicks:[],hasRightAxis:!1,xKeys:g,allKeys:[...g],start:0,end:Math.max(1,c),xPositions:w,xTickIndices:b,plottedCandles:[],plottedSeries:[],x:v,y:d.y};if(u)for(let y=0;y<c;y++){let _=e.bars[y],N=d.y(_.open),F=d.y(_.close),D=d.y(_.high),k=d.y(_.low);!Number.isFinite(D)||!Number.isFinite(k)||p.plottedCandles.push({t:_.timestamp,o:_.open,h:_.high,l:_.low,c:_.close,v:_.volume,x:w[y],index:y,bodyTop:Math.min(N,F),bodyBottom:Math.max(N,F),wickTop:Math.min(D,k),wickBottom:Math.max(D,k)})}for(let y of t){let _=[];for(let[N,F]of y.points){let D=i.get(N),k=d.y(F);D===void 0||!Number.isFinite(w[D])||!Number.isFinite(k)||_.push({x:w[D],y:k,value:F,key:N,index:D})}p.plottedSeries.push({source:y,points:_})}return{model:p,scale:d}}function jt(e,t,i,n,r,o={},s,a){Se(o);let l=[...new Set(i.filter(A=>A.pane!=="price").map(A=>A.pane))],u=Math.max(.3,Math.min(.85,o.priceRatio??.62)),h=["price",...l],c=h.map(A=>o.paneWeights?.[A]??(A==="price"?u:(1-u)/l.length)),d=Math.max(...c),f=c.map(A=>A/d),m=f.reduce((A,O)=>A+O,0),v=r,g=Math.min(48,r/h.length),w=new Array(h.length),b=new Set(h.map((A,O)=>O));for(;b.size>0;){let A=[...b].filter(O=>v*f[O]/m<g);if(A.length===0){for(let O of b)w[O]=v*f[O]/m;break}for(let O of A)w[O]=g,v-=g,m-=f[O],b.delete(O)}let p=[],y=e.bars.every((A,O,E)=>Number.isFinite(A.timestamp)&&(O===0||A.timestamp>E[O-1].timestamp)&&Number.isFinite(A.open)&&Number.isFinite(A.high)&&Number.isFinite(A.low)&&Number.isFinite(A.close)&&A.high>=Math.max(A.open,A.close)&&A.low<=Math.min(A.open,A.close)),_=new Map;if(y)for(let A=0;A<e.bars.length;A++)_.set(e.bars[A].timestamp,A);let N=y?[]:e.bars.map(A=>({t:A.timestamp,o:A.open,h:A.high,l:A.low,c:A.close,v:A.volume})),F=He(e.bars),D=e.dataStart??e.viewport.i0,k=(A,O)=>{if(!Number.isFinite(O))return null;let E=e.viewport.i1-e.viewport.i0;if(e.dataStart!==void 0&&E>0&&A.xPositions.length>0){let L=A.geometry.plotWidth/E/2;if(O>A.xPositions[A.xPositions.length-1]+L||O<A.xPositions[0]-L)return null}let M=it(A,O),x=M===null?void 0:A.xKeys[M],C=y?M:typeof x=="number"?We(e.bars,x):null,j=C===null?void 0:e.bars[C];return C===null||j===void 0||j.timestamp!==x?null:{index:D+C,timestamp:j.timestamp,mode:e.mode,displayBar:j}},S=(A,O)=>{let E=k(A,O);if(E===null)return null;let M=Object.create(null);for(let x of i)M[x.id]={...x.rows[E.index]};return{...E,indicatorBasis:"raw",indicators:M}},T=0;for(let[A,O]of h.entries()){let E=A===0,M=w[A],x=T;T+=M;let C=[],j=new Map;for(let I of i)if(I.pane===O)for(let B of I.figures){let V=[];for(let G=0;G<e.bars.length;G++){let Z=I.rows[D+G]?.[B.key];Z!=null&&Number.isFinite(Z)&&V.push([e.bars[G].timestamp,Z])}let X=JSON.stringify([I.id,B.key]);j.set(X,B),C.push({id:X,name:B.title,type:B.type==="circle"?"scatter":B.type,color:B.color,points:V})}let L=[];if(E)for(let I of e.bars)L.push(I.high,I.low);for(let I of C){for(let B of I.points)L.push(B[1]);I.type==="bar"&&L.push(j.get(I.id)?.base??0)}let W=E?o.priceScale??{}:{},H=t[0]?.close??1,$,R;y?{model:$,scale:R}=ur(e,C,_,n,M,o.axisGutter,W,L,H,E):($=tn({xType:"category",series:C,candles:N},n,M,o.axisGutter),an($,e,"category"),E||($.plottedCandles=[]),R=cr($,L,W,H)),p.push({id:O,top:x,height:M,frame:{snapshot:e,model:$,figureStyles:j,pricePrecision:F,previousClose:E?s:void 0,indicatorPane:!E,title:E?void 0:i.filter(I=>I.pane===O).map(I=>I.name).join(" \xB7 "),inspectBar:I=>k($,I),inspect:I=>S($,I)},scale:R})}let P=p[0],z=P.frame.model,Y=A=>{if(!Number.isFinite(A)||t.length===0)return null;let O=0,E=t.length;for(;O<E;){let C=O+E>>>1;t[C].timestamp<A?O=C+1:E=C}if(t.length===1)return 0;if(O===0)return(A-t[0].timestamp)/(t[1].timestamp-t[0].timestamp);if(O===t.length)return t.length-1+(A-t[O-1].timestamp)/(t[O-1].timestamp-t[O-2].timestamp);let M=t[O-1].timestamp,x=t[O].timestamp;return O-1+(A-M)/(x-M)};return{...P.frame,drawingContext:{bars:t,revision:a,visibleRange:[e.viewport.i0,e.viewport.i1]},panes:p,project:(A,O)=>{let E=Y(A);if(E===null||!Number.isFinite(O))return null;let M=e.viewport.i1-e.viewport.i0,x=z.geometry,C=M<=0?x.left+x.plotWidth/2:x.left+(E-e.viewport.i0)/M*x.plotWidth,j=P.scale.y(O);return Number.isFinite(j)?{x:C,y:j}:null},unproject:(A,O)=>{if(!Number.isFinite(A)||!Number.isFinite(O)||e.bars.length===0)return null;let E=z.geometry,M=(A-E.left)/E.plotWidth*Math.max(0,e.viewport.i1-e.viewport.i0),x=e.viewport.i0+M,C=Math.max(0,Math.min(t.length-2,Math.floor(x))),j=t[C],L=t[Math.min(t.length-1,C+1)],W=j.timestamp+(L.timestamp-j.timestamp)*(x-C),H=P.scale.value(O);return Number.isFinite(H)?{timestamp:W,price:H}:null}}}var Mt=Object.freeze({basis:null,upper:null,lower:null}),Ze=e=>Number.isFinite(e)?e:null;function Fi(){return{run:0,valid:!1,sinceSeed:0,sum:0,compensation:0,mean:0,m2:0}}function Ci(e){return{...e}}function It(e,t){let i=e.sum+t;e.compensation+=Math.abs(e.sum)>=Math.abs(t)?e.sum-i+t:t-i+e.sum,e.sum=i}function hr(e,t,i,n,r){if(!Number.isInteger(i)||i<1)return Mt;let o=Ze(e[t].close);if(o===null)return r.run=0,r.valid=!1,Mt;if(r.run++,r.run<i)return Mt;let s;if(!r.valid||++r.sinceSeed>=i){r.sum=0,r.compensation=0;let l=0;for(let u=t-i+1;u<=t;u++){let h=e[u].close;It(r,h),l+=h}r.mean=l/i,r.m2=0;for(let u=t-i+1;u<=t;u++)r.m2+=(e[u].close-r.mean)**2;r.valid=!0,r.sinceSeed=0,s=Math.sqrt(r.m2/i)}else{let l=e[t-i].close;It(r,-l),It(r,o);let u=r.mean+(o-l)/i;r.m2+=(o-l)*(o-u+l-r.mean),r.mean=u,s=Math.sqrt(Math.max(r.m2,0)/i)}let a=(r.sum+r.compensation)/i;return{basis:Ze(a),upper:Ze(a+n*s),lower:Ze(a-n*s)}}function K(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function de(e,t){return ki(e,t,"finite")}function Be(e,t){let i=new Array(t[0]?.length??0);for(let n=0;n<i.length;n++){let r=Object.create(null);for(let o=0;o<e.length;o++)r[e[o]]=K(t[o][n]);i[n]=r}return i}function ln(e){let t=K(e.volume);return{volume:t!==null&&t>=0?t:null}}function ze(){return{sum:0,count:0,previous:null,gain:0,loss:0}}function Ai(){return{fast:ze(),slow:ze(),signal:ze()}}function Ri(e){return{fast:{...e.fast},slow:{...e.slow},signal:{...e.signal}}}function Pi(){return{run:0,valid:!1,sum:0,compensation:0,sinceSeed:0}}function Et(e,t){let i=e.sum+t;e.compensation+=Math.abs(e.sum)>=Math.abs(t)?e.sum-i+t:t-i+e.sum,e.sum=i}function dr(e,t,i,n){let r=K(e[t].close);if(r===null)return n.run=0,n.valid=!1,null;if(n.run++,n.run<i)return null;if(!n.valid||++n.sinceSeed>=i){n.sum=0,n.compensation=0;for(let o=t-i+1;o<=t;o++)Et(n,e[o].close);n.sinceSeed=0,n.valid=!0}else Et(n,-e[t-i].close),Et(n,r);return K((n.sum+n.compensation)/i)}function Qe(e,t,i,n){if(e==="EMA")return t===null?null:(n.previous===null?(n.sum+=t,n.count++,n.count===i&&(n.previous=n.sum/i)):n.previous=(2*t+(i-1)*n.previous)/(i+1),K(n.previous));if(t===null)return n.previous=null,null;if(n.previous===null)return n.previous=t,null;let r=t-n.previous;n.previous=t;let o=Math.max(r,0),s=Math.max(-r,0);if(n.count<i){if(n.gain+=o,n.loss+=s,n.count++,n.count<i)return null;n.gain/=i,n.loss/=i}else n.gain=(n.gain*(i-1)+o)/i,n.loss=(n.loss*(i-1)+s)/i;return K(n.loss===0?100:n.gain===0?0:100-100/(1+n.gain/n.loss))}function fr(e,t){let i=Je(de(e,"high"),de(e,"low"),de(e,"close"),t[0]),n=new Array(e.length),r=50,o=50;for(let s=0;s<i.length;s++){let a=K(i[s]);if(a===null){n[s]={k:null,d:null,j:null},r=50,o=50;continue}r=((t[1]-1)*r+a)/t[1],o=((t[2]-1)*o+r)/t[2],n[s]={k:K(r),d:K(o),j:K(3*r-2*o)}}return n}var mr=[{name:"MA",params:[20],pane:"price",figures:[{key:"ma",title:"MA",type:"line"}],calculate:(e,t)=>Be(["ma"],[ge(de(e,"close"),t[0])])},{name:"EMA",params:[20],pane:"price",figures:[{key:"ema",title:"EMA",type:"line"}],calculate:(e,t)=>Be(["ema"],[me(de(e,"close"),t[0])])},{name:"BOLL",params:[20,2],pane:"price",figures:[{key:"basis",title:"Basis",type:"line"},{key:"upper",title:"Upper",type:"line"},{key:"lower",title:"Lower",type:"line"}],calculate:(e,t)=>{let i=qe(de(e,"close"),t[0],t[1]);return Be(["basis","upper","lower"],[i.basis,i.upper,i.lower])}},{name:"VOL",params:[],pane:"separate",figures:[{key:"volume",title:"Volume",type:"bar"}],calculate:e=>e.map(ln)},{name:"MACD",params:[12,26,9],pane:"separate",figures:[{key:"dif",title:"DIF",type:"line"},{key:"dea",title:"DEA",type:"line"},{key:"hist",title:"MACD",type:"bar"}],calculate:(e,t)=>{let i=gt(de(e,"close"),t[0],t[1],t[2]);return Be(["dif","dea","hist"],[i.dif,i.dea,i.hist])}},{name:"RSI",params:[14],pane:"separate",figures:[{key:"rsi",title:"RSI",type:"line"}],calculate:(e,t)=>Be(["rsi"],[Ve(de(e,"close"),t[0])])},{name:"KDJ",params:[9,3,3],pane:"separate",figures:[{key:"k",title:"K",type:"line"},{key:"d",title:"D",type:"line"},{key:"j",title:"J",type:"line"}],calculate:fr}];function kt(e,t){for(let i of e)if(typeof i!="number"||!Number.isFinite(i))throw new RangeError("Indicator parameters must be finite numbers");if(t!==void 0){let i=t==="VOL"?0:t==="BOLL"?2:t==="MACD"||t==="KDJ"?3:1;if(e.length!==i)throw new RangeError(`${t} requires ${i} parameters`);for(let n=0;n<e.length;n++)if(t==="BOLL"&&n===1){if(e[n]<0)throw new RangeError("BOLL deviation multiplier must not be negative")}else if(!Number.isSafeInteger(e[n])||e[n]<1)throw new RangeError("Indicator periods must be positive safe integers")}return Object.freeze([...e])}var rt=class{definitions=new Map;builtinNames=new Set;entries=new Map;result=[];bars=null;length=0;dataDirty=!1;structureDirty=!1;fullReset=!1;from=1/0;nextId=1;disposed=!1;constructor(){for(let e of mr)this.register(e),this.builtinNames.add(e.name)}register(e){if(this.assertLive(),typeof e.name!="string"||e.name.trim()==="")throw new TypeError("Indicator name must not be empty");if(this.definitions.has(e.name))throw new Error(`Indicator already registered: ${e.name}`);if(e.pane!=="price"&&e.pane!=="separate")throw new TypeError("Invalid indicator pane");if(typeof e.calculate!="function"||e.figures.length===0)throw new TypeError("Indicator needs figures and a calculation");let t=new Set,i=e.figures.map(n=>{if(typeof n.key!="string"||n.key===""||t.has(n.key)||!["line","bar","circle"].includes(n.type))throw new TypeError("Indicator figure keys must be unique and types must be line, bar or circle");if(n.lineWidth!==void 0&&(!Number.isFinite(n.lineWidth)||n.lineWidth<=0||n.lineWidth>32))throw new RangeError("Figure width must be greater than zero and at most 32");if(n.base!==void 0&&!Number.isFinite(n.base))throw new RangeError("Figure base must be finite");if(n.dash!==void 0&&(!Array.isArray(n.dash)||n.dash.length>16||n.dash.some(r=>!Number.isFinite(r)||r<0)))throw new RangeError("Invalid figure dash pattern");return t.add(n.key),Object.freeze({...n,...n.dash===void 0?{}:{dash:Object.freeze([...n.dash])}})});this.definitions.set(e.name,Object.freeze({...e,params:kt(e.params??[]),figures:Object.freeze(i)}))}unregister(e,t){this.assertLive();let i=this.definitions.get(e);return i===void 0||this.builtinNames.has(e)||t!==void 0&&i.calculate!==t||[...this.entries.values()].some(n=>n.instance.name===e)?!1:this.definitions.delete(e)}add(e){this.assertLive();let t=this.definitions.get(e.name);if(t===void 0)throw new Error(`Unknown indicator: ${e.name}`);let i=this.builtinNames.has(e.name)?e.name:void 0,n=kt(e.params??t.params??[],i);t.validateParams?.(n);let r=e.pane??t.pane;if(r!=="price"&&r!=="separate")throw new TypeError("Invalid indicator pane");let o=e.id;if(o===void 0)do o=`indicator-${this.nextId++}`;while(this.entries.has(o));if(typeof o!="string"||o.trim()===""||this.entries.has(o))throw new Error("Indicator id must be nonempty and unique");this.validatePlacement(e);let s=Object.freeze({id:o,name:e.name,params:n,pane:r,paneId:e.paneId,visible:e.visible??!0});return this.entries.set(o,{instance:s,definition:t,builtin:i??_t(t.calculate)?.name,result:null}),this.structureDirty=!0,o}update(e,t){this.assertLive();let i=this.entries.get(e);if(i===void 0)return!1;this.validatePlacement(t);let n=t.pane??i.instance.pane;if(n!=="price"&&n!=="separate")throw new TypeError("Invalid indicator pane");let r=t.params===void 0?i.instance.params:kt(t.params,this.builtinNames.has(i.instance.name)?i.builtin:void 0);i.definition.validateParams?.(r);let o=Object.freeze({...i.instance,...t,pane:n,params:r,visible:t.visible??i.instance.visible});return r.length!==i.instance.params.length||r.some((a,l)=>a!==i.instance.params[l])||o.visible!==i.instance.visible?i.result=null:i.result!==null&&(i.result={...i.result,pane:n,paneId:o.paneId}),i.instance=o,this.structureDirty=!0,!0}validatePlacement(e){if(e.paneId!==void 0&&(typeof e.paneId!="string"||e.paneId.trim()===""||e.paneId.length>128))throw new TypeError("Indicator pane id must be nonempty and at most 128 characters");if(e.visible!==void 0&&typeof e.visible!="boolean")throw new TypeError("Indicator visibility must be boolean")}remove(e){this.assertLive();let t=this.entries.delete(e);return t&&(this.structureDirty=!0),t}hasCustom(){return[...this.entries.values()].some(e=>e.instance.visible&&e.builtin===void 0)}list(){return this.assertLive(),Array.from(this.entries.values(),e=>e.instance)}registeredNames(){return this.assertLive(),[...this.definitions.keys()]}validateReplacement(e){this.prepareReplacement(e).dispose()}replace(e){let t=this.prepareReplacement(e);this.entries.clear();for(let[i,n]of t.entries)this.entries.set(i,n);this.nextId=t.nextId,this.result=[],this.structureDirty=!0,this.fullReset=!0,t.dispose()}prepareReplacement(e){if(this.assertLive(),!Array.isArray(e)||e.length>64)throw new RangeError("At most 64 indicator instances can be restored");let t=new rt;t.nextId=this.nextId;try{for(let i of this.definitions.values())this.builtinNames.has(i.name)||t.register(i);for(let i of e)t.add(i);return t}catch(i){throw t.dispose(),i}}dispose(){this.disposed||(this.disposed=!0,this.entries.clear(),this.definitions.clear(),this.builtinNames.clear(),this.result=[],this.bars=null,this.length=0,this.dataDirty=!1,this.structureDirty=!1,this.fullReset=!1,this.from=1/0)}invalidate(e){this.assertLive(),e.kind!=="availability"&&(this.dataDirty=!0,e.kind!=="tail"||!Number.isSafeInteger(e.from)||e.from<0?this.fullReset=!0:this.from=Math.min(this.from,e.from))}compute(e){this.assertLive();let t=this.dataDirty||this.bars!==e||this.length!==e.length;if(!t&&!this.structureDirty)return this.result;let i=this.dataDirty&&!this.fullReset&&this.bars===e&&e.length>=this.length&&this.from<=this.length,n=i?this.from:0,r=[];try{Ei(e,()=>{let o=new Map;for(let s of this.entries.values()){if(!s.instance.visible){s.result=null;continue}let a=_t(s.definition.calculate),l=a?.parameters(s.instance.params)??s.instance.params,u=s.builtin===void 0?void 0:JSON.stringify([s.builtin,l,a?.maKey??"ma"]),h=u===void 0?void 0:o.get(u);h!==void 0?(s.result={...h.result,id:s.instance.id,name:s.instance.name,pane:s.instance.pane,paneId:s.instance.paneId,figures:s.definition.figures},s.recursive=h.recursive,s.macd=h.macd,s.bollinger=h.bollinger,s.movingAverage=h.movingAverage):((t||s.result===null)&&this.calculate(s,e,n,i&&s.result!==null,l,a?.maKey),u!==void 0&&o.set(u,s)),r.push(s.result)}})}catch(o){throw this.dataDirty=!0,this.fullReset=!0,o}return this.result=r,this.bars=e,this.length=e.length,this.dataDirty=!1,this.structureDirty=!1,this.fullReset=!1,this.from=1/0,this.result}calculate(e,t,i,n,r,o="ma"){let s,a=e.builtin;if(a==="MA"){let l=e.movingAverage,u=n&&l!==void 0&&this.length>0&&i>=this.length-1,h=u?i:0,c=u?{...i===this.length?l.afterLast:l.beforeLast}:Pi();s=u?e.result.rows:new Array(t.length);let d=Pi();for(let f=h;f<t.length;f++){f===t.length-1&&(d={...c});let m=dr(t,f,r[0],c);s[f]=o==="ma"?{ma:m}:{[o]:m}}h===t.length&&l!==void 0&&(d=l.beforeLast),e.movingAverage={beforeLast:d,afterLast:c}}else if(a==="EMA"||a==="RSI"){let l=e.recursive,u=n&&l!==void 0&&this.length>0&&i>=this.length-1,h=u?i:0,c=u?{...i===this.length?l.afterLast:l.beforeLast}:ze();s=u?e.result.rows:new Array(t.length);let d=ze();for(let f=h;f<t.length;f++){f===t.length-1&&(d={...c});let m=Qe(a,K(t[f].close),r[0],c);s[f]=a==="EMA"?{ema:m}:{rsi:m}}h===t.length&&l!==void 0&&(d=l.beforeLast),e.recursive={beforeLast:d,afterLast:c}}else if(a==="BOLL"){let l=e.bollinger,u=n&&l!==void 0&&this.length>0&&i>=this.length-1,h=u?i:0,c=u?Ci(i===this.length?l.afterLast:l.beforeLast):Fi();s=u?e.result.rows:new Array(t.length);let d=Fi();for(let f=h;f<t.length;f++)f===t.length-1&&(d=Ci(c)),s[f]=hr(t,f,r[0],r[1],c);h===t.length&&l!==void 0&&(d=l.beforeLast),e.bollinger={beforeLast:d,afterLast:c}}else if(a==="MACD"){let l=e.macd,u=n&&l!==void 0&&this.length>0&&i>=this.length-1,h=u?i:0,c=u?Ri(i===this.length?l.afterLast:l.beforeLast):Ai();s=u?e.result.rows:new Array(t.length);let d=Ai(),[f,m,v]=r;for(let g=h;g<t.length;g++){g===t.length-1&&(d=Ri(c));let w=K(t[g].close),b=Qe("EMA",w,f,c.fast),p=Qe("EMA",w,m,c.slow),y=b===null||p===null?null:b-p,_=Qe("EMA",y,v,c.signal);s[g]={dif:K(y),dea:K(_),hist:y===null||_===null?null:K(y-_)}}h===t.length&&l!==void 0&&(d=l.beforeLast),e.macd={beforeLast:d,afterLast:c}}else if(a==="KDJ"&&n&&this.length>0&&i>=this.length-1&&i>0&&e.result.rows[i-1]?.k!=null&&e.result.rows[i-1]?.d!=null){s=e.result.rows;let[l,u,h]=r,c=s[i-1].k,d=s[i-1].d;for(let f=i;f<t.length;f++){let m=-1/0,v=1/0;for(let b=Math.max(0,f-l+1);b<=f;b++){let p=K(t[b].high),y=K(t[b].low);if(p===null||y===null){m=NaN;break}m=Math.max(m,p),v=Math.min(v,y)}let g=K(t[f].close),w=g===null||f<l-1?null:K(m===v?0:100*(g-v)/(m-v));if(w===null){s[f]={k:null,d:null,j:null},c=50,d=50;continue}c=((u-1)*c+w)/u,d=((h-1)*d+c)/h,s[f]={k:K(c),d:K(d),j:K(3*c-2*d)}}}else if(a==="VOL"){s=n?e.result.rows:new Array(t.length);for(let l=n?i:0;l<t.length;l++)s[l]=ln(t[l])}else{let l=n&&i>=this.length-1?Ii(e.definition.calculate):void 0,u=l?.inputStart(r,i,t.length)??0,h=e.definition.calculate(u>0?t.slice(u):t,r);if(!Array.isArray(h)||h.length!==t.length-u)throw new RangeError(`${e.instance.name} must return one row per bar`);if(a!==void 0)s=h;else{let c=u>0?l.outputStart(r,i,t.length):0;s=u>0?e.result.rows:new Array(t.length);for(let d=c;d<t.length;d++){let f=Object.create(null);for(let m of e.definition.figures)f[m.key]=K(h[d-u]?.[m.key]);s[d]=f}s.length=t.length}}e.result={id:e.instance.id,name:e.instance.name,pane:e.instance.pane,paneId:e.instance.paneId,figures:e.definition.figures,rows:s}}assertLive(){if(this.disposed)throw new Error("EngineIndicators has been disposed")}},Li=[0,.236,.382,.5,.618,.786,1],pr=[1,.75,.618,.5,.382,.25,0],gr=[.382,.5,.618,1],yr=[0,1,2,3,5,8,13,21,34],vr=[1/8,1/4,1/3,1/2,1,2,3,4,8],Bi=Math.PI*2,Ie=Math.PI/2,wr=e=>e!==null&&Number.isFinite(e.x)&&Number.isFinite(e.y),Wt=(e,t)=>({x:e.x/2+t.x/2,y:e.y/2+t.y/2}),je=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),br=(e,t,i)=>({x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i});function xr(e,t){for(let i=1;i<t.length;i++)e.line(t[i-1],t[i])}function _r(e){let t=e.length-1,i=0;for(let n=2;n<e.length;n++){let r=e[n-2],o=e[n-1],s=e[n];i=Math.max(i,t*(t-1)*Math.hypot(r.x-2*o.x+s.x,r.y-2*o.y+s.y))}return Math.max(1,Math.min(1024,Math.ceil(Math.sqrt(i/(8*.35)))))}function Dt(e,t){let i=_r(t),n=t[0];for(let r=1;r<=i;r++){let o=r/i,s=t;for(;s.length>1;)s=s.slice(1).map((a,l)=>br(s[l],a,o));e.line(n,s[0]),n=s[0]}}function ke(e,t,i,n,r){if(![t.x,t.y,i,n,r].every(Number.isFinite)||i<=0)return;let o=Math.max(16,Math.min(512,Math.ceil(Math.abs(r-n)*Math.sqrt(i/.5)))),s=l=>({x:t.x+i*Math.cos(l),y:t.y+i*Math.sin(l)}),a=s(n);for(let l=1;l<=o;l++){let u=s(n+(r-n)*l/o);e.line(a,u),a=u}}function Mr(e,t,i){let n=je(t,i);if(!(n>0)||!Number.isFinite(n))return;let r=(i.x-t.x)/n,o=(i.y-t.y)/n,s=Math.min(10,n/3);e.line(t,i);for(let a of[1,-1])e.line(i,{x:i.x-r*s+a*o*s/2,y:i.y-o*s-a*r*s/2})}function Oi(e,t){let i=t?.bars;if(i===void 0||i.length<2)return null;let n=0,r=i.length-1;for(;n+1<r;){let s=n+r>>>1;i[s].timestamp<=e?n=s:r=s}e>=i[i.length-1].timestamp&&(n=i.length-2,r=i.length-1);let o=i[r].timestamp-i[n].timestamp;return o>0?n+(e-i[n].timestamp)/o:null}function cn({drawing:e,context:t}){let i=Oi(e.anchors[0].timestamp,t),n=Oi(e.anchors[1].timestamp,t);return i===null||n===null?null:Math.abs(Math.round(n-i))}function zi(e){return({points:[t],sink:i})=>{let n=(r,o)=>({x:t.x+r,y:t.y+e*o});i.polygon([n(0,0),n(-7,9),n(-3,9),n(-3,20),n(3,20),n(3,9),n(7,9)])}}function Me(e,t){return({points:i,sink:n})=>{if(xr(n,i),i.forEach((r,o)=>n.text(r,`(${e?.[o]??o})`)),e!==null)for(let r=2;r<i.length;r++)n.line(i[r-2],i[r]);t&&(n.polygon([i[0],i[1],i[2]]),n.polygon([i[2],i[3],i[4]]))}}function ji(e){return({points:[t,i],sink:n})=>{if(n.polygon([t,{x:i.x,y:t.y},i,{x:t.x,y:i.y}]),n.line(t,i),n.line({x:t.x,y:i.y},{x:i.x,y:t.y}),e){let r=Wt(t,i);n.line({x:r.x,y:t.y},{x:r.x,y:i.y}),n.line({x:t.x,y:r.y},{x:i.x,y:r.y});return}for(let r of[.25,.5])n.line(t,{x:i.x,y:i.y-(i.y-t.y)*r}),n.line({x:t.x,y:i.y},{x:i.x,y:t.y+(i.y-t.y)*r});for(let r of[.236,.5])n.line(t,{x:t.x+(i.x-t.x)*r,y:i.y}),n.line({x:t.x,y:i.y},{x:t.x+(i.x-t.x)*r,y:t.y})}}function Ir({points:[e,t],sink:i}){let n=je(e,t)/Math.sqrt(24),r=Math.atan2(t.y-e.y,t.x-e.x);if(!(n>0)||!Number.isFinite(n))return;let o=(h,c)=>({x:e.x+h*Math.cos(r)-c*Math.sin(r),y:e.y+h*Math.sin(r)+c*Math.cos(r)}),s=[n,n*2],a=-n,l=-n;ke(i,o(-n,0),n,r,r+Ie),ke(i,o(a,l),s[1],r+Ie,r+Math.PI);let u=[[-1,0],[0,-1],[1,0],[0,1]];for(let h=2;h<9;h++){s.push(s[h-2]+s[h-1]);let[c,d]=u[h%4];a+=c*s[h-2],l+=d*s[h-2];let f=r+h%4*Ie;ke(i,o(a,l),s[h],f,f+Ie)}i.line(e,t,!0)}var Er={"arrow-up":zi(1),"arrow-down":zi(-1),"price-line":({drawing:e,points:[t],bounds:i,sink:n})=>{n.line(t,{x:i.right,y:t.y}),n.text({x:i.right-3,y:t.y},"",e.anchors[0].price,"right")},flag:({points:[e],sink:t})=>{t.line(e,{x:e.x,y:e.y-22}),t.polygon([{x:e.x,y:e.y-22},{x:e.x+15,y:e.y-18},{x:e.x,y:e.y-14}])},pin:({points:[e],sink:t})=>{t.polygon([e,{x:e.x-7,y:e.y-15},{x:e.x+7,y:e.y-15}]),ke(t,{x:e.x,y:e.y-18},8,0,Bi)},curve:({points:[e,t,i],sink:n})=>Dt(n,[e,t,i]),arc:({points:[e,t,i],sink:n})=>Dt(n,[e,{x:2*t.x-(e.x+i.x)/2,y:2*t.y-(e.y+i.y)/2},i]),"double-curve":({points:[e,t,i,n],sink:r})=>Dt(r,[e,t,i,n]),"disjoint-channel":({points:[e,t,i],sink:n})=>n.polygon([e,t,{x:i.x+t.x-e.x,y:i.y+t.y-e.y},i]),"rotated-rectangle":({points:[e,t,i],sink:n})=>{let r=je(e,t);if(!(r>0)){n.line(e,i);return}let o=-(t.y-e.y)/r,s=(t.x-e.x)/r,a=(i.x-t.x)*o+(i.y-t.y)*s;n.polygon([e,t,{x:t.x+o*a,y:t.y+s*a},{x:e.x+o*a,y:e.y+s*a}])},"fibonacci-line":({drawing:{anchors:[e,t]},project:i,bounds:n,sink:r})=>{for(let o of Li){let s=t.price*(1-o)+e.price*o,a=i(e.timestamp,s);!wr(a)||!Number.isFinite(s)||(r.line({x:n.left,y:a.y},{x:n.right,y:a.y}),r.text({x:n.right-3,y:a.y},`${Math.round(o*1e3)/10}%`,s,"right"))}},"fibonacci-circle":({points:[e,t],sink:i})=>{let n=je(e,t);for(let r of Li.slice(1))ke(i,e,n*r,0,Bi),i.text({x:e.x,y:e.y+n*r},`${r*100}%`)},"fibonacci-spiral":Ir,"fibonacci-fan":({points:[e,t],sink:i})=>{for(let n of pr){let r=t.x-(t.x-e.x)*n,o=t.y-(t.y-e.y)*n;i.line({x:r,y:e.y},{x:r,y:t.y}),i.line({x:e.x,y:o},{x:t.x,y:o}),i.line(e,{x:r,y:t.y},!0),i.line(e,{x:t.x,y:o},!0),i.text({x:r,y:e.y},String(n)),i.text({x:e.x,y:o},String(n),void 0,"left")}},"fibonacci-time-zone":({points:[e,t],bounds:i,sink:n})=>{for(let r of yr){let o=e.x+(t.x-e.x)*r;n.line({x:o,y:i.top},{x:o,y:i.bottom}),n.text({x:o,y:i.top+16},String(r))}},"fibonacci-arcs":({points:[e,t],sink:i})=>{let n=je(e,t),r=t.x>=e.x,o=t.y>=e.y;i.line(e,t);let s=r?0:Math.PI,a=o?Ie:r?-Ie:Math.PI*1.5;for(let l of gr)ke(i,e,n*l,s,a)},"gann-fan":({points:[e,t],sink:i})=>{for(let n of vr)i.line(e,{x:t.x,y:e.y+(t.y-e.y)*n},!0)},"gann-square":ji(!0),"gann-box":ji(!1),xabcd:Me(["X","A","B","C","D"],!0),abcd:Me(["A","B","C","D"],!1),"three-waves":Me(null,!1),"five-waves":Me(null,!1),"eight-waves":Me(null,!1),"any-waves":Me(null,!1),"time-range":e=>{let t=cn(e);t!==null&&e.sink.text(Wt(e.points[0],e.points[1]),`${t} bars`)},"price-time-range":e=>Wi(e,!0),forecast:e=>Wi(e,!1),note:({drawing:e,points:[t],sink:i})=>i.label(t,e.text??""),callout:({drawing:e,points:[t,i],sink:n})=>{n.line(t,i),n.label(i,e.text??"")},signpost:({drawing:e,points:[t],sink:i})=>{let n={x:t.x,y:t.y-26};i.line(t,n),i.label(n,e.text??"")}};function Wi(e,t){let{drawing:{anchors:[i,n]},points:[r,o],sink:s}=e;t?s.polygon([r,{x:o.x,y:r.y},o,{x:r.x,y:o.y}]):Mr(s,r,o);let a=n.price-i.price,l=a/Math.abs(i.price)*100;if(!Number.isFinite(a))return;let u=Number.isFinite(l)?`${l>=0?"+":""}${l.toFixed(2)}%`:"Percentage unavailable";if(t){let h=cn(e);h!==null&&(u+=` \xB7 ${h} bars`),u+=" \xB7 \u0394"}t?s.text(Wt(r,o),u,a):s.text(o,u)}function un(e,t,i,n,r,o){Er[e.type]?.({drawing:e,points:t,project:i,bounds:n,context:r,sink:o})}var Hi=1e4,Nt=e=>Number.isFinite(e.high)&&Number.isFinite(e.low),Yi=e=>Number.isFinite(e.volume)&&e.volume>0?e.volume:0;function Tt(e,t){return Math.max(0,Math.min(t-1,e))}function hn(e,t={}){let i=t.rows??24,n=t.valueArea??.7;if(!Number.isInteger(i)||i<1||i>Hi)throw new RangeError(`Volume profile rows must be an integer from 1 to ${Hi}`);if(!(n>0&&n<=1))throw new RangeError("Volume profile value area must be above 0 and at most 1");let r=1/0,o=-1/0;for(let m of e)Nt(m)&&(m.low<r&&(r=m.low),m.high>o&&(o=m.high));if(!Number.isFinite(r)||!Number.isFinite(o))return{rows:[],poc:NaN,vah:NaN,val:NaN,pmin:r,pmax:o};if(!(o>r)){let m=e.reduce((v,g)=>v+(Nt(g)?Yi(g):0),0);return{rows:[{priceLow:r,priceHigh:r,volume:m}],poc:r,vah:r,val:r,pmin:r,pmax:r}}let s=new Array(i).fill(0),a=(o-r)/i;for(let m of e){let v=Nt(m)?Yi(m):0;if(v<=0)continue;if(!(m.high>m.low)){s[Tt(Math.floor((m.low-r)/a),i)]+=v;continue}let g=Tt(Math.floor((m.low-r)/a),i),w=Tt(Math.floor((m.high-r)/a),i),b=m.high-m.low;for(let p=g;p<=w;p++){let y=r+p*a,_=y+a,N=Math.min(m.high,_)-Math.max(m.low,y);N>0&&(s[p]+=v*(N/b))}}let l=s.reduce((m,v)=>m+v,0),u=0;for(let m=1;m<i;m++)s[m]>s[u]&&(u=m);let h=u,c=u,d=s[u];for(;d<l*n&&(h>0||c<i-1);){let m=h>0?s[h-1]:-1;(c<i-1?s[c+1]:-1)>=m?(c++,d+=s[c]):(h--,d+=s[h])}return{rows:s.map((m,v)=>({priceLow:r+v*a,priceHigh:r+(v+1)*a,volume:m})),poc:r+(u+.5)*a,vah:r+(c+1)*a,val:r+h*a,pmin:r,pmax:o}}var Ht=Object.freeze(["regression-trend","position-long","position-short","anchored-vwap","fixed-range-volume-profile","anchored-volume-profile"]),De=Object.freeze({rangeBars:1e5,visibleVwapBars:8192,cachedCells:1e6,cacheEntries:64}),Gi=new WeakMap,Ee=new Set,St=0;function kr(e){let t={value:e,cells:e.vwap?.length??(e.profile?.rows.length??1)*3};for(Ee.add(t),St+=t.cells;St>De.cachedCells||Ee.size>De.cacheEntries;){let i=Ee.values().next().value;Ee.delete(i),St-=i.cells,i.value=null}return t}function q(e,t,i={}){return Object.freeze({...i,type:e,status:t,...i.statistics===void 0?{}:{statistics:Object.freeze(i.statistics)}})}function he(e){return e!==null&&Number.isFinite(e.x)&&Number.isFinite(e.y)}function Dr(e,t){return e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom}function Nr(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);e[r].timestamp<=t?i=r+1:n=r}return i-1}function Tr(e,t){return Number.isFinite(e.timestamp)&&Math.abs(e.timestamp)<=864e13&&e.timestamp>t&&[e.open,e.high,e.low,e.close].every(Number.isFinite)&&e.high>=Math.max(e.open,e.close,e.low)&&e.low<=Math.min(e.open,e.close)}function $i(e){let t=0,i=0;for(let n of e){let r=n-i,o=t+r;i=o-t-r,t=o}return t}function Sr(e,t,i,n){let r={fromIndex:i,toIndex:n},o=n-i+1;if(o>De.rangeBars)return{result:q(e,"too-wide",r)};if(o<(e==="anchored-vwap"?1:2))return{result:q(e,"empty",r)};let s=0;for(let h=i;h<=n;h++){let c=t[h];if(!Tr(c,h===0?-1/0:t[h-1].timestamp))return{result:q(e,"invalid-data",r)};e!=="regression-trend"&&(typeof c.volume!="number"||!Number.isFinite(c.volume)||c.volume<0)&&s++}if(s>0)return{result:q(e,"missing-volume",{...r,missingVolumeBars:s})};if(e==="regression-trend"){let h=(o-1)/2,c=0;for(let w=i;w<=n;w++)c+=(t[w].close-c)/(w-i+1);function*d(){for(let w=i;w<=n;w++)yield(w-i-h)*(t[w].close-c)}let f=$i(d())/(o*(o*o-1)/12),m=c-f*h,v=0;for(let w=i;w<=n;w++)v=Math.hypot(v,t[w].close-(m+f*(w-i)));let g=v/Math.sqrt(o);return[f,m,g].every(Number.isFinite)?{result:q(e,"ready",{...r,statistics:{slope:f,intercept:m,standardDeviation:g}})}:{result:q(e,"invalid-data",r)}}if(e==="anchored-vwap"){let h=new Float64Array(o),c=0,d=0,f=0;for(let m=i;m<=n;m++){let v=t[m],g=v.volume,w=g-d,b=c+w;if(d=b-c-w,!Number.isFinite(b))return{result:q(e,"invalid-data",r)};if(g>0){let p=v.high/3+v.low/3+v.close/3;f=c===0?p:f*(c/b)+p*(g/b)}if(c=b,h[m-i]=c>0?f:NaN,c>0&&!Number.isFinite(f))return{result:q(e,"invalid-data",r)}}return{result:q(e,c>0?"ready":"empty",{...r,statistics:{totalVolume:c}}),vwap:h}}let a=t.slice(i,n+1).map(h=>({low:h.low,high:h.high,volume:h.volume})),l=hn(a,{rows:24,valueArea:.7}),u=$i(a.map(h=>h.volume));return!Number.isFinite(u)||![l.poc,l.vah,l.val,l.pmin,l.pmax].every(Number.isFinite)||l.rows.some(h=>![h.priceLow,h.priceHigh,h.volume].every(Number.isFinite))?{result:q(e,"invalid-data",r)}:{result:q(e,u>0?"ready":"empty",{...r,statistics:{totalVolume:u,poc:l.poc,valueAreaHigh:l.vah,valueAreaLow:l.val}}),profile:l}}function Fr(e,t,i,n){let r=t.bars,o=Gi.get(r),s=`${e}:${i}:${n}`,a=t.revision!==void 0&&o!==void 0&&Object.is(o.revision,t.revision)&&o.length===r.length&&o.firstTimestamp===r[0].timestamp&&o.lastTimestamp===r[r.length-1].timestamp,l=a?o.values.get(s):void 0;if(l!==void 0&&l.value!==null)return Ee.delete(l),Ee.add(l),l.value;let u=Sr(e,r,i,n);if(t.revision!==void 0){let h=a?o:{revision:t.revision,length:r.length,firstTimestamp:r[0].timestamp,lastTimestamp:r[r.length-1].timestamp,values:new Map};h.values.set(s,kr(u)),h.values.size>De.cacheEntries&&h.values.delete(h.values.keys().next().value),Gi.set(r,h)}return u}function Cr(e,t,i,n,r){if(e.anchors.length!==3)return q(t,"invalid-position");let[o,s,a]=e.anchors.map(p=>p.price),l=t==="position-long";if(![o,s,a].every(Number.isFinite)||(l?!(s>o&&a<o):!(s<o&&a>o)))return q(t,"invalid-position");let u=Math.abs(s-o)/Math.abs(o-a);if(!Number.isFinite(u))return q(t,"invalid-position");let h=p=>{let y=(p-o)/Math.abs(o)*100;return o!==0&&Number.isFinite(y)?y:void 0},c=h(s),d=h(a),f={rewardRiskRatio:u,...c===void 0?{}:{targetChangePercent:c},...d===void 0?{}:{stopChangePercent:d}},m=e.anchors.map(p=>i(p.timestamp,p.price));if(!m.every(he))return q(t,"unprojectable",{statistics:f});let v=Math.min(...m.map(p=>p.x)),g=Math.max(...m.map(p=>p.x));for(let p of[m[1],m[2]])r.polygon([{x:v,y:m[0].y},{x:g,y:m[0].y},{x:g,y:p.y},{x:v,y:p.y}]);for(let p of m)r.line({x:v,y:p.y},{x:g,y:p.y});let w=(p,y,_)=>{let N={x:Math.max(n.left+4,Math.min(n.right-4,v/2+g/2)),y:p.y};Dr(N,n)&&r.text(N,y,_,"center")},b=p=>p===void 0?"":` ${p>=0?"+":""}${p.toFixed(2)}%`;return w(m[0],`${l?"Long":"Short"} R/R ${u.toFixed(2)}`),w(m[1],`Target${b(c)}`,s),w(m[2],`Stop${b(d)}`,a),q(t,"ready",{statistics:f})}function dn(e,t,i,n,r){let o=e.type;if(!Ht.includes(o))return null;if(o==="position-long"||o==="position-short")return Cr(e,o,t,i,r);let s=n?.bars;if(n===void 0||s===void 0||s.length===0)return q(o,"unavailable-history");let a=o==="regression-trend"||o==="fixed-range-volume-profile"?2:1;if(e.anchors.length!==a||e.anchors.some(g=>!Number.isFinite(g.timestamp)))return q(o,"invalid-data");let l=e.anchors.map(g=>g.timestamp);if(l.some(g=>g<s[0].timestamp||g>s[s.length-1].timestamp))return q(o,"unavailable-history");let u=l.map(g=>Nr(s,g)),h=Math.min(...u),c=a===2?Math.max(...u):s.length-1;if(h<0||c<h)return q(o,"unavailable-history");let d=Fr(o,n,h,c),f=d.result;if(f.status!=="ready")return f;let m=!1,v=(g,w)=>{he(g)&&he(w)&&(r.line(g,w),m=!0)};if(d.vwap!==void 0){let g=n.visibleRange??[h,c];if(g.length!==2||!g.every(Number.isFinite))return q(o,"invalid-data");let w=Math.max(h,Math.floor(Math.min(...g))-1),b=Math.min(c,Math.ceil(Math.max(...g))+1);if(b-w+1>De.visibleVwapBars)return q(o,"too-wide",f);for(let p=w+1;p<=b;p++){let y=d.vwap[p-h-1],_=d.vwap[p-h];Number.isFinite(y)&&Number.isFinite(_)&&v(t(s[p-1].timestamp,y),t(s[p].timestamp,_))}}else if(o==="regression-trend"){let g=f.statistics,w=g.intercept,b=w+g.slope*(c-h);for(let p of[0,2*g.standardDeviation,-2*g.standardDeviation])Number.isFinite(w+p)&&Number.isFinite(b+p)&&v(t(s[h].timestamp,w+p),t(s[c].timestamp,b+p))}else if(d.profile!==void 0){let g=d.profile,w=t(e.anchors[0].timestamp,g.poc),b=a===2?t(e.anchors[1].timestamp,g.poc):null;if(!he(w)||a===2&&!he(b))return q(o,"unprojectable",f);let p=b===null?w.x:Math.min(w.x,b.x),y=b===null?120:Math.abs(b.x-w.x),_=g.rows.reduce((F,D)=>Math.max(F,D.volume),0);if(!(_>0))return q(o,"invalid-data",f);for(let F of g.rows){if(F.volume<=0)continue;let D=t(s[h].timestamp,F.priceLow),k=t(s[h].timestamp,F.priceHigh);if(!he(D)||!he(k))continue;let S=D.y/2+k.y/2,T=Math.max(.5,Math.abs(k.y/2-D.y/2)*.84),P=p+F.volume/_*y*(a===2?.95:1);[S,T,P].every(Number.isFinite)&&(r.polygon([{x:p,y:S-T},{x:P,y:S-T},{x:P,y:S+T},{x:p,y:S+T}]),m=!0)}let N=t(s[h].timestamp,g.poc);he(N)&&v({x:p,y:N.y},{x:p+y,y:N.y})}return m?f:q(o,"unprojectable",f)}var ae=Object.freeze({encodedCharacters:512*1024,dimension:4096,pixels:4*1024*1024,cachedImages:32,cachedPixels:16*1024*1024}),J=()=>{throw new TypeError("Drawing images must be bounded static PNG, JPEG or WebP rasters")};function fe(e,t){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<=0||t<=0||e>ae.dimension||t>ae.dimension||e*t>ae.pixels)throw new RangeError("Drawing image exceeds its decoded dimension or pixel limit")}function st(e,t){let i=new DataView(e.buffer,e.byteOffset,e.byteLength),n=(s,a)=>String.fromCharCode(...e.subarray(s,s+a)),r=0,o=0;if(t==="image/png"){(e.length<33||e[0]!==137||n(1,7)!==`PNG\r
|
|
2
|
+
|
|
3
|
+
`||i.getUint32(8)!==13||n(12,4)!=="IHDR")&&J(),r=i.getUint32(16),o=i.getUint32(20);let s=8,a=!1,l=0;for(;s+12<=e.length;){let u=i.getUint32(s),h=n(s+4,4);if((u>e.length-s-12||h==="acTL")&&J(),h==="IHDR"&&++l!==1&&J(),s+=u+12,h==="IEND"){a=u===0&&s===e.length;break}}a||J()}else if(t==="image/jpeg"){(e.length<4||e[0]!==255||e[1]!==216)&&J();let s=2,a=0;for(;s<e.length;){for(e[s++]!==255&&J();e[s]===255;)s++;let l=e[s++];if(l===218||l===217)break;if(l===1||l>=208&&l<=215)continue;s+2>e.length&&J();let u=i.getUint16(s);(u<2||u>e.length-s)&&J(),[192,193,194,195,197,198,199,201,202,203,205,206,207].includes(l)&&((![192,193,194].includes(l)||++a!==1)&&J(),u<8&&J(),o=i.getUint16(s+3),r=i.getUint16(s+5),fe(r,o)),s+=u}}else if(t==="image/webp"){(e.length<20||n(0,4)!=="RIFF"||n(8,4)!=="WEBP"||i.getUint32(4,!0)!==e.length-8)&&J();let s=12,a=0,l=0,u=0;for(;s+8<=e.length;){let h=n(s,4),c=i.getUint32(s+4,!0),d=s+8;if((c>e.length-d||h==="ANIM"||h==="ANMF")&&J(),h==="VP8X")(c!==10||a!==0||e[d]&2)&&J(),a=1+e[d+4]+(e[d+5]<<8)+(e[d+6]<<16),l=1+e[d+7]+(e[d+8]<<8)+(e[d+9]<<16),fe(a,l);else if(h==="VP8 ")(++u!==1||c<10||e[d]&1||n(d+3,3)!=="\x9D*")&&J(),r=i.getUint16(d+6,!0)&16383,o=i.getUint16(d+8,!0)&16383,fe(r,o);else if(h==="VP8L"){(++u!==1||c<5||e[d]!==47)&&J();let f=i.getUint32(d+1,!0);r=1+(f&16383),o=1+(f>>>14&16383),fe(r,o)}s=d+c+c%2}(s!==e.length||u!==1||a!==0&&(a!==r||l!==o))&&J()}else J();return fe(r,o),{width:r,height:o}}function ot(e){if(typeof e!="string"||e.length>ae.encodedCharacters)throw new RangeError("Drawing image exceeds its encoded size limit");let t=/^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/]+={0,2})$/.exec(e);if(t===null||t[2].length%4!==0)return J();let i;try{i=atob(t[2])}catch{return J()}let n=Uint8Array.from(i,r=>r.charCodeAt(0));return{mime:t[1],bytes:n,...st(n,t[1])}}function Ge(e){return ot(e),e}var at=2048;function fn(e,t,i){if(e.type!=="brush"&&e.type!=="highlighter"||e.hidden||e.anchors.length<2||e.anchors.length>at)return null;let n=[];for(let r of e.anchors){let o=t(r.timestamp,r.price);if(o===null||!Number.isFinite(o.x)||!Number.isFinite(o.y))return null;n.push(Object.freeze({...o}))}return Object.freeze({kind:"stroke",points:Object.freeze(n),width:e.strokeWidth??(e.type==="highlighter"?16:2),opacity:e.type==="highlighter"?.24:1,clip:Object.freeze({...i})})}var lt=Object.freeze(["horizontal","vertical","horizontal-ray","segment","ray","trend-line","arrow","rectangle","ellipse","circle","price-range","time-range","fibonacci","horizontal-segment","vertical-segment","vertical-ray","parallel-channel","price-channel","pitchfork","schiff-pitchfork","modified-schiff-pitchfork","fibonacci-extension","triangle","parallelogram","text","price-label","arrow-up","arrow-down","price-line","curve","arc","double-curve","flag","regression-trend","disjoint-channel","rotated-rectangle","fibonacci-line","fibonacci-circle","fibonacci-spiral","fibonacci-fan","fibonacci-time-zone","gann-box","gann-fan","gann-square","fibonacci-arcs","xabcd","abcd","three-waves","five-waves","eight-waves","any-waves","position-long","position-short","price-time-range","forecast","note","callout","signpost","pin","image","anchored-vwap","fixed-range-volume-profile","anchored-volume-profile","brush","highlighter"]),mn=[0,.236,.382,.5,.618,.786,1],Ar=[...mn,1.618,2.618,3.618,4.236],Ui=1e3,Vi=8*1024*1024,Rr=864e13;function et(e,t,i){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`Invalid ${i}`);let n=e;if(Object.keys(n).some(r=>!t.includes(r)))throw new TypeError(`Unknown ${i} property`);return n}function qi(e,t){if(e===void 0)return!1;if(typeof e!="boolean")throw new TypeError(`Invalid drawing ${t}`);return e}function $e(e){return e==="text"||e==="note"||e==="callout"||e==="signpost"}function xe(e){switch(e){case"horizontal":case"vertical":case"horizontal-ray":case"text":case"price-label":case"arrow-up":case"arrow-down":case"price-line":case"flag":case"note":case"signpost":case"pin":case"anchored-vwap":case"anchored-volume-profile":return 1;case"parallel-channel":case"price-channel":case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":case"fibonacci-extension":case"triangle":case"parallelogram":case"curve":case"arc":case"disjoint-channel":case"rotated-rectangle":case"position-long":case"position-short":return 3;case"double-curve":case"abcd":case"three-waves":return 4;case"xabcd":return 5;case"five-waves":return 6;case"eight-waves":return 9;default:return 2}}function Pr(e,t){let i=xe(t),n=t==="brush"||t==="highlighter"||t==="any-waves";if(!Array.isArray(e)||(n?e.length<2||e.length>(t==="any-waves"?256:2048):e.length!==i))throw new TypeError(`${t} requires ${n?"a bounded path of at least 2":i} anchors`);let r=e.map(o=>{let s=et(o,["timestamp","price"],"drawing anchor");if(typeof s.timestamp!="number"||!Number.isFinite(s.timestamp)||Math.abs(s.timestamp)>Rr||typeof s.price!="number"||!Number.isFinite(s.price))throw new TypeError("Invalid drawing anchor coordinates");return{timestamp:s.timestamp,price:s.price}});return t==="horizontal-segment"&&(r[1].price=r[0].price),(t==="vertical-segment"||t==="vertical-ray")&&(r[1].timestamp=r[0].timestamp),Object.freeze(r.map(o=>Object.freeze(o)))}function Ft(e){let t=et(e,["id","type","anchors","locked","hidden","text","image","strokeWidth"],"drawing");if(typeof t.id!="string"||t.id.trim()===""||t.id.length>128)throw new TypeError("Invalid drawing id");if(!lt.includes(t.type))throw new TypeError("Invalid drawing type");let i=t.type,n={};if($e(i)){if(typeof t.text!="string"||t.text.trim()===""||t.text.length>512||t.text.split(`
|
|
4
|
+
`).length>8||Array.from(t.text).some(r=>{let o=r.charCodeAt(0);return o<32&&o!==9&&o!==10||o===127}))throw new TypeError("Drawing text must contain 1\u2013512 plain characters in at most 8 lines");n.text=t.text}else if(t.text!==void 0)throw new TypeError("Only text drawings accept text");if(i==="image")n.image=Ge(t.image);else if(t.image!==void 0)throw new TypeError("Only image drawings accept image data");if(t.strokeWidth!==void 0){if(i!=="brush"&&i!=="highlighter"||typeof t.strokeWidth!="number"||!Number.isFinite(t.strokeWidth)||t.strokeWidth<1||t.strokeWidth>64)throw new TypeError("Invalid freehand stroke width");n.strokeWidth=t.strokeWidth}return Object.freeze({id:t.id,type:i,anchors:Pr(t.anchors,i),locked:qi(t.locked,"locked"),hidden:qi(t.hidden,"hidden"),...n})}function Ki(e,t){return e.id===t.id&&e.type===t.type&&e.locked===t.locked&&e.hidden===t.hidden&&e.text===t.text&&e.image===t.image&&e.strokeWidth===t.strokeWidth&&e.anchors.length===t.anchors.length&&e.anchors.every((i,n)=>i.timestamp===t.anchors[n].timestamp&&i.price===t.anchors[n].price)}function oe(e){return e!==null&&Number.isFinite(e.x)&&Number.isFinite(e.y)}function ce(e,t){return e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom}function pn(e){if(![e.left,e.top,e.right,e.bottom].every(Number.isFinite)||e.left>=e.right||e.top>=e.bottom)throw new RangeError("Drawing bounds must be finite and have positive size")}function Xi(e,t,i,n=!1,r=!1){let o=t.x-e.x,s=t.y-e.y;if(!Number.isFinite(o)||!Number.isFinite(s))return null;if(o===0&&s===0)return ce(e,i)?{kind:"line",from:e,to:t}:null;let a=r?-1/0:0,l=n||r?1/0:1,u=[[-o,e.x-i.left],[o,i.right-e.x],[-s,e.y-i.top],[s,i.bottom-e.y]];for(let[d,f]of u){if(d===0){if(f<0)return null;continue}let m=f/d;if(d<0?a=Math.max(a,m):l=Math.min(l,m),a>l)return null}let h={x:e.x+a*o,y:e.y+a*s},c={x:e.x+l*o,y:e.y+l*s};return oe(h)&&oe(c)?{kind:"line",from:h,to:c}:null}function Lr(e,t){let i=[...e];for(let[n,r,o]of[["x",t.left,!0],["x",t.right,!1],["y",t.top,!0],["y",t.bottom,!1]]){let s=i;if(i=[],s.length===0)break;let a=s[s.length-1],l=o?a[n]>=r:a[n]<=r;for(let u of s){let h=o?u[n]>=r:u[n]<=r;if(h!==l){let c=(r-a[n])/(u[n]-a[n]),d={x:a.x*(1-c)+u.x*c,y:a.y*(1-c)+u.y*c};oe(d)&&i.push(d)}h&&i.push(u),a=u,l=h}}return i}function ct(e,t,i,n){if(pn(i),e.hidden)return null;let r=e.anchors.map(p=>t(p.timestamp,p.price));if(!r.every(oe)&&!Ht.includes(e.type))return null;let o=r.map(p=>oe(p)?p:{x:NaN,y:NaN}),s=o[0];e.type==="horizontal-segment"&&(o[1]={x:o[1].x,y:s.y}),(e.type==="vertical-segment"||e.type==="vertical-ray")&&(o[1]={x:s.x,y:o[1].y});let a=o[1],l=o[2],u=[],h=(p,y,_=!1,N=!1)=>{let F=Xi(p,y,i,_,N);F!==null&&u.push(F)},c=(p,y)=>{let _=y.x-p.x,N=y.y-p.y,F=Math.hypot(_,N);if(!ce(y,i)||!Number.isFinite(F)||F===0)return;let D=Math.min(10,F*.35),k=_/F,S=N/F;h({x:y.x-k*D+S*D*.5,y:y.y-S*D-k*D*.5},y),h({x:y.x-k*D-S*D*.5,y:y.y-S*D+k*D*.5},y)},d=()=>{let p=Math.min(s.x,a.x),y=Math.max(s.x,a.x),_=Math.min(s.y,a.y),N=Math.max(s.y,a.y),F={left:Math.max(p,i.left),right:Math.min(y,i.right),top:Math.max(_,i.top),bottom:Math.min(N,i.bottom)};F.left<F.right&&F.top<F.bottom&&u.push({kind:"rect",from:{x:F.left,y:F.top},to:{x:F.right,y:F.bottom}}),h({x:p,y:_},{x:y,y:_}),h({x:y,y:_},{x:y,y:N}),h({x:y,y:N},{x:p,y:N}),h({x:p,y:N},{x:p,y:_})},f=p=>{if(!p.every(oe))return;let y=Lr(p,i);y.length>2&&u.push({kind:"polygon",points:y});for(let _=0;_<p.length;_++)h(p[_],p[(_+1)%p.length])},m=(p,y,_,N=!0)=>{if(!ce(p,i))return;let F=[];for(let T of y.split(`
|
|
5
|
+
`)){let P=Array.from(T);P.length===0&&F.push("");for(let z=0;z<P.length;z+=32)F.push(P.slice(z,z+32).join(""))}let D=F.slice(0,24),k=_===void 0?Math.max(32,Math.min(260,Math.max(...D.map(T=>Array.from(T).length))*8+12)):150,S={left:p.x,top:p.y,right:p.x+k,bottom:p.y+D.length*16+8};u.push({kind:"label",bounds:S,clip:{...i},lines:D,price:_,boxed:N})},v=(p,y)=>{if(u.length===0)return;let _={x:Math.min(i.right-4,Math.max(s.x,a.x)),y:Math.max(i.top+16,Math.min(s.y,a.y))};ce(_,i)&&u.push({kind:"text",position:_,text:p,price:y,align:"right"})};switch(e.type){case"horizontal":h({x:i.left,y:s.y},{x:i.right,y:s.y});break;case"vertical":h({x:s.x,y:i.top},{x:s.x,y:i.bottom});break;case"horizontal-ray":s.x<=i.right&&h(s,{x:i.right,y:s.y});break;case"segment":case"horizontal-segment":case"vertical-segment":h(s,a);break;case"vertical-ray":h(s,a,!0);break;case"ray":h(s,a,!0);break;case"trend-line":h(s,a,!1,!0);break;case"arrow":h(s,a),c(s,a);break;case"rectangle":d();break;case"triangle":f([s,a,l]);break;case"parallelogram":f([s,a,l,{x:s.x+l.x-a.x,y:s.y+l.y-a.y}]);break;case"parallel-channel":case"price-channel":{let p={x:a.x-s.x,y:a.y-s.y};if(!oe(p)||p.x===0&&p.y===0)break;let y=_=>({x:_.x+p.x,y:_.y+p.y});if(h(s,a,!1,!0),h(l,y(l),!1,!0),e.type==="price-channel"){let _={x:2*s.x-l.x,y:2*s.y-l.y};h(_,y(_),!1,!0)}else{let _={x:s.x/2+l.x/2,y:s.y/2+l.y/2};h(_,y(_),!1,!0)}break}case"pitchfork":case"schiff-pitchfork":case"modified-schiff-pitchfork":{let p=e.type==="pitchfork"?s:{x:e.type==="schiff-pitchfork"?s.x:s.x/2+a.x/2,y:s.y/2+a.y/2},y={x:a.x/2+l.x/2,y:a.y/2+l.y/2},_=y.x-p.x,N=y.y-p.y;if(h(a,l),!Number.isFinite(_)||!Number.isFinite(N)||_===0&&N===0)break;for(let F of[p,a,l])h(F,{x:F.x+_,y:F.y+N},!0);break}case"text":m(s,e.text??"",void 0,!1);break;case"price-label":m(s,"",e.anchors[0].price);break;case"ellipse":case"circle":{let p=e.type==="circle"?s:{x:s.x/2+a.x/2,y:s.y/2+a.y/2},y=e.type==="circle"?Math.hypot(a.x-s.x,a.y-s.y):Math.abs(a.x/2-s.x/2),_=e.type==="circle"?y:Math.abs(a.y/2-s.y/2);if(![y,_].every(Number.isFinite))break;if(y===0||_===0){h(s,a);break}if(p.x+y<i.left||p.x-y>i.right||p.y+_<i.top||p.y-_>i.bottom)break;u.push({kind:"ellipse",center:p,radiusX:y,radiusY:_,clip:{...i}});break}case"price-range":{d();let p={x:s.x/2+a.x/2,y:s.y},y={x:p.x,y:a.y};h(p,y),c(p,y),c(y,p);let _=e.anchors[1].price-e.anchors[0].price;if(!Number.isFinite(_))break;let N=_/Math.abs(e.anchors[0].price)*100;v(Number.isFinite(N)?`${N>=0?"+":""}${N.toFixed(2)}% \xB7 \u0394`:"\u0394",_);break}case"time-range":{d();let p={x:s.x,y:s.y/2+a.y/2},y={x:a.x,y:p.y};h(p,y),c(p,y),c(y,p);let _=Math.abs(e.anchors[1].timestamp-e.anchors[0].timestamp),[N,F]=_>=864e5?["d",864e5]:_>=36e5?["h",36e5]:_>=6e4?["m",6e4]:_>=1e3?["s",1e3]:["ms",1];v(`${Number((_/F).toFixed(2))} ${N}`);break}case"fibonacci":case"fibonacci-extension":{let p=e.anchors[0],y=e.anchors[1],_=e.type==="fibonacci-extension",N=e.anchors[2];_&&(h(s,a),h(a,l));for(let F of _?Ar:mn){let D=_?N.price+(y.price-p.price)*F:y.price*(1-F)+p.price*F,k=t(_?y.timestamp:p.timestamp,D),S=t(_?N.timestamp:y.timestamp,D);if(!Number.isFinite(D)||!oe(k)||!oe(S))continue;let T=Xi(k,S,i);if(T===null||T.kind!=="line")continue;u.push(T);let P=T.from.x>T.to.x?T.from:T.to;u.push({kind:"text",position:P,text:`${Math.round(F*1e3)/10}%`,price:D,align:"right"})}break}}let g={line:h,polygon:f,label:m,text:(p,y,_,N="center")=>{oe(p)&&ce(p,i)&&u.push({kind:"text",position:p,text:y,price:_,align:N})}};un(e,o,t,i,n,g);let w=dn(e,t,i,n,g)??void 0;if(e.type==="brush"||e.type==="highlighter"){let p=fn(e,t,i);p!==null&&u.push(p)}if(e.type==="image"&&e.image!==void 0){let p={left:Math.min(s.x,a.x),top:Math.min(s.y,a.y),right:Math.max(s.x,a.x),bottom:Math.max(s.y,a.y)};p.left<i.right&&p.right>i.left&&p.top<i.bottom&&p.bottom>i.top&&p.left<p.right&&p.top<p.bottom&&u.push({kind:"image",source:e.image,bounds:p,clip:{...i}})}let b=e.locked?[]:o.flatMap((p,y)=>ce(p,i)?[{point:p,anchorIndex:y}]:[]);return{id:e.id,type:e.type,locked:e.locked,primitives:u,handles:b,...w===void 0?{}:{analysis:w}}}function At(e,t,i){let n=i.x-t.x,r=i.y-t.y,o=n*n+r*r,s=o===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*r)/o));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*r))}function Br(e,t){if(!ce(e,t.clip))return 1/0;let i=Math.abs(e.x-t.center.x),n=Math.abs(e.y-t.center.y),r=Math.max(t.radiusX,t.radiusY,i,n,1),o=t.radiusX/r,s=t.radiusY/r,a=i/r,l=n/r;if(Math.hypot(a/o,l/s)<=1)return 0;let u=o*o,h=s*s;if(u===0||h===0)return 1/0;let c=0,d=Math.hypot(o*a,s*l);for(let m=0;m<48;m++){let v=(c+d)/2;Math.hypot(o*a/(v+u),s*l/(v+h))>1?c=v:d=v}let f=(c+d)/2;return Math.hypot(a-u*a/(f+u),l-h*l/(f+h))*r}function Or(e,t){let i=!1,n=1/0;for(let r=0,o=t.length-1;r<t.length;o=r++){let s=t[r],a=t[o];n=Math.min(n,At(e,s,a)),s.y>e.y!=a.y>e.y&&e.x<(a.x-s.x)*(e.y-s.y)/(a.y-s.y)+s.x&&(i=!i)}return i?0:n}function gn(e,t,i,n=6){if(!oe(i)||!Number.isFinite(n)||n<0)return null;let r=e.find(o=>o.id===t);if(r!==void 0)for(let o of r.handles){let s=Math.hypot(i.x-o.point.x,i.y-o.point.y);if(s<=n)return{id:r.id,anchorIndex:o.anchorIndex,distance:s}}for(let o=e.length-1;o>=0;o--){let s=e[o];for(let a of s.primitives){if(a.kind==="text")continue;let l=a.kind==="stroke"?ce(i,a.clip)?Math.max(0,a.points.reduce((u,h,c)=>c===0?u:Math.min(u,At(i,a.points[c-1],h)),1/0)-a.width/2):1/0:a.kind==="polygon"?Or(i,a.points):a.kind==="label"||a.kind==="image"?ce(i,a.clip)?Math.hypot(Math.max(a.bounds.left-i.x,0,i.x-a.bounds.right),Math.max(a.bounds.top-i.y,0,i.y-a.bounds.bottom)):1/0:a.kind==="ellipse"?Br(i,a):a.kind==="line"?At(i,a.from,a.to):Math.hypot(Math.max(a.from.x-i.x,0,i.x-a.to.x),Math.max(a.from.y-i.y,0,i.y-a.to.y));if(l<=n)return{id:s.id,anchorIndex:null,distance:l}}}return null}var ut=class{drawings=Object.freeze([]);selectedId=null;past=[];future=[];listeners=new Set;historyLimit;snapshot=Object.freeze({drawings:this.drawings,selectedId:null,canUndo:!1,canRedo:!1});constructor(e={}){let t=e.historyLimit??50;if(!Number.isInteger(t)||t<0||t>200)throw new RangeError("Drawing history limit must be between 0 and 200");this.historyLimit=t}getSnapshot=()=>this.snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});add(e){let t=Ft(e);if(this.drawings.length>=Ui)throw new RangeError("Drawing limit reached");if(this.drawings.some(i=>i.id===t.id))throw new TypeError("Duplicate drawing id");return this.commit([...this.drawings,t]),t}update(e,t){let i=et(t,["anchors","locked","hidden","text","image","strokeWidth"],"drawing patch"),n=this.drawings.findIndex(a=>a.id===e);if(n<0)return!1;let r=this.drawings[n],o=Ft({...r,...i});if(r.locked&&(i.anchors!==void 0||i.text!==void 0||i.image!==void 0||i.strokeWidth!==void 0)||Ki(r,o))return!1;let s=this.drawings.slice();return s[n]=o,this.commit(s),!0}remove(e){let t=this.drawings.find(i=>i.id===e);return t===void 0||t.locked?!1:(this.commit(this.drawings.filter(i=>i.id!==e)),!0)}clear(){let e=this.drawings.filter(t=>t.locked);return e.length===this.drawings.length?!1:(this.commit(e),!0)}select(e){return e!==null&&!this.drawings.some(t=>t.id===e&&!t.hidden)||e===this.selectedId?!1:(this.selectedId=e,this.publish(),!0)}undo(){let e=this.past.pop();return e===void 0?!1:(this.future.push(this.drawings),this.drawings=e,this.publish(),!0)}redo(){let e=this.future.pop();return e===void 0?!1:(this.past.push(this.drawings),this.drawings=e,this.publish(),!0)}exportJson(){return JSON.stringify({version:1,drawings:this.drawings})}importJson(e,t={}){if(typeof e!="string"||e.length>Vi)throw new TypeError("Invalid drawing document size");let i=et(JSON.parse(e),["version","drawings"],"drawing document");if(i.version!==1||!Array.isArray(i.drawings)||i.drawings.length>Ui)throw new TypeError("Invalid drawing document");let n=i.drawings.map(Ft);if(new Set(n.map(s=>s.id)).size!==n.length)throw new TypeError("Duplicate drawing id");let o=n.length!==this.drawings.length||n.some((s,a)=>!Ki(s,this.drawings[a]));t.recordHistory===!0?o&&this.commit(n):(this.past=[],this.future=[],this.drawings=Object.freeze(n),this.publish())}geometry(e,t,i){pn(t);let n=[];for(let r of this.drawings){let o=ct(r,e,t,i);o!==null&&n.push(o)}return n}hitTest(e,t,i,n=6,r){return gn(this.geometry(t,i,r),this.selectedId,e,n)}commit(e){if(JSON.stringify({version:1,drawings:e}).length>Vi)throw new RangeError("Drawing document size limit reached");this.historyLimit>0&&(this.past.push(this.drawings),this.past.length>this.historyLimit&&this.past.shift()),this.future=[],this.drawings=Object.freeze(e),this.publish()}publish(){this.drawings.some(e=>e.id===this.selectedId&&!e.hidden)||(this.selectedId=null),this.snapshot=Object.freeze({drawings:this.drawings,selectedId:this.selectedId,canUndo:this.past.length>0,canRedo:this.future.length>0});for(let e of[...this.listeners])try{e()}catch(t){console.warn("[super-chart] Drawing observer failed",t)}}},Yt=["candles","hollow-candles","outline-candles","hollow-down-candles","ohlc","volume-bars","columns","high-low","line","line-markers","step-line","area","hlc-area","baseline"];var zr=Object.freeze({characters:8*1024*1024,nodes:11e5,depth:24,indicators:64,params:64,drawings:1e3});var yn={hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"};function ne(e,t,i){let n={};for(let{type:r,value:o}of e.formatToParts(new Date(t)))switch(r){case"year":n.YYYY=o;break;case"month":n.MM=o;break;case"day":n.DD=o;break;case"hour":n.HH=o==="24"?"00":o;break;case"minute":n.mm=o;break;case"second":n.ss=o;break}return i.replace(/YYYY|MM|DD|HH|mm|ss/g,r=>n[r]??r)}var jr=new Intl.DateTimeFormat("en",{...yn,timeZone:"UTC"}),Oe=new Map;function Wr(e){let t=Oe.get(e);if(t!==void 0)return t;let i;try{i=new Intl.DateTimeFormat("en",{...yn,timeZone:e})}catch{i=jr}return Oe.size>=8&&Oe.delete(Oe.keys().next().value),Oe.set(e,i),i}function Hr(e){return e==="day"||e==="week"||e==="month"||e==="year"}function Gt(e){let t=Hr(e.timespan)?Wr(e.symbolTimezone??"UTC"):e.displayDtf;switch(e.timespan){case"second":return e.type==="xAxis"?ne(t,e.timestamp,e.format==="YYYY"||e.format==="YYYY-MM"||e.format==="MM-DD"?e.format:"HH:mm:ss"):ne(t,e.timestamp,"YYYY-MM-DD HH:mm:ss");case"minute":return e.type==="xAxis"?e.format==="YYYY"||e.format==="YYYY-MM"||e.format==="MM-DD"?ne(t,e.timestamp,e.format):ne(t,e.timestamp,"HH:mm"):ne(t,e.timestamp,"YYYY-MM-DD HH:mm");case"hour":return e.type==="xAxis"?ne(t,e.timestamp,"MM-DD HH:mm"):ne(t,e.timestamp,"YYYY-MM-DD HH:mm");case"day":case"week":return ne(t,e.timestamp,"YYYY-MM-DD");case"month":return e.type==="xAxis"?ne(t,e.timestamp,"YYYY-MM"):ne(t,e.timestamp,"YYYY-MM-DD");case"year":return e.type==="xAxis"?ne(t,e.timestamp,"YYYY"):ne(t,e.timestamp,"YYYY-MM-DD");default:return ne(t,e.timestamp,"YYYY-MM-DD HH:mm")}}var Yr=Object.freeze({isLength:ie,sum:pe,sma:ge,wma:Ae,hma:Xt,vwma:Jt,ema:me,rma:pt,rsi:Ve,macd:gt,stdev:yt,dev:vt,bollinger:qe,highest:Ke,lowest:Xe,linreg:Qt,correlation:ei,change:wt,mom:ti,roc:ii,crossover:ni,crossunder:ri,cross:si,cum:oi,barssince:ai,valuewhen:li,pivot:ci,trueRange:bt,atr:Le,obv:ui,vwap:hi,cci:fi,mfi:mi,stochK:Je,sar:pi,stoch:xt,stochRsi:yi,bbPercent:vi,keltner:wi,donchian:Re,atrBands:bi,supertrend:xi,ichimoku:_i,anchoredVwap:Mi});function vn(e){return e.map((t,i)=>{let n=i>0?e[i-1].close:t.open;return{index:i,from:n,to:t.close,up:t.close>=n}})}function wn(e){let t=[];return e.forEach((i,n)=>{n>0&&t.push({index:n,value:e[n-1].close}),t.push({index:n,value:i.close})}),t}function $t(e){return(e.high+e.low+e.close)/3}function bn(e){return e.map((t,i)=>({index:i,value:$t(t)}))}function xn(e,t){if(e.length===0)return[];let i=[],n=0,r=e[0].close>=t;for(let o=1;o<e.length;o++){let s=e[o].close>=t;s!==r&&(i.push({from:n,to:o-1,above:r}),n=o-1,r=s)}return i.push({from:n,to:e.length-1,above:r}),i}function ht(e,t){let i=t!==void 0&&Number.isFinite(t)&&t>0?t:e.geometry.plotWidth;for(let n=1;n<e.xPositions.length;n++){let r=e.xPositions[n]-e.xPositions[n-1];r>0&&(i=Math.min(i,r))}return Math.max(.25,i*.34)}function _n(e){return e.map(t=>({open:t.o,high:t.h,low:t.l,close:t.c,volume:t.v}))}function Mn(e,t){for(let i=0;i<t.length;i++){let n=t[i];i===0?e.moveTo(n.x,n.y):e.lineTo(n.x,n.y)}}function In(e,t,i){let n=[],r=-2,o=[];for(let s of e){if(!Number.isFinite(s.x)||!Number.isFinite(t(i(s)))){r=-2;continue}s.index!==r+1&&(o=[],n.push(o)),o.push(s),r=s.index}return n}function Gr(e,t,i,n,r,o){let s=t.y(i);if(!Number.isFinite(s))return;let a=(l,u)=>{let h=t.y(l.c),c=t.y(u.c),d=c===h?0:Math.max(0,Math.min(1,(s-h)/(c-h)));return{x:l.x+(u.x-l.x)*d,y:s}};for(let l of In(t.plottedCandles,t.y,u=>u.c)){let u=_n(l);for(let h of xn(u,i)){let c=[];for(let v=h.from;v<=h.to;v++){let g=l[v];v===h.from&&g.c>=i!==h.above&&v+1<l.length?c.push(a(g,l[v+1])):c.push({x:g.x,y:t.y(g.c)})}h.to+1<l.length&&l[h.to+1].c>=i!==h.above&&c.push(a(l[h.to],l[h.to+1]));let d=c[0],f=c[c.length-1];if(d===void 0)continue;let m=h.above?n:r;e.fillStyle=e.strokeStyle=m,e.beginPath(),e.moveTo(d.x,s);for(let v of c)e.lineTo(v.x,v.y);e.lineTo(f.x,s),e.closePath(),e.globalAlpha=.22,e.fill(),e.globalAlpha=1,e.beginPath(),Mn(e,c),e.stroke()}}e.strokeStyle=o,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(t.geometry.left,s),e.lineTo(t.geometry.right,s),e.stroke()}function En(e,t,i={},n){let r=i.chartType??"candles";if(r==="candles"||r==="ohlc"||r==="line"||r==="area")return!1;let o=t.model,s=o.plottedCandles,a=n??ht(o),l=i.up??"#58c9ac",u=i.down??"#f28b82",h=i.line??"#8bafff",c=d=>d?l:u;e.save();try{switch(e.globalAlpha=1,e.globalCompositeOperation="source-over",e.setLineDash([]),e.lineWidth=1.5,e.strokeStyle=e.fillStyle=h,r){case"hollow-candles":case"outline-candles":case"hollow-down-candles":{for(let d=0;d<2;d++){let f=d===0,m=r==="outline-candles"||(r==="hollow-candles"?f:!f);e.strokeStyle=e.fillStyle=c(f),e.lineWidth=1,e.beginPath();for(let v of s){if(v.c>=v.o!==f)continue;let{bodyTop:g,bodyBottom:w,wickTop:b,wickBottom:p}=v;if(!Number.isFinite(g)||!Number.isFinite(w)||!Number.isFinite(b)||!Number.isFinite(p))continue;let y=Math.max(1,w-g),_=(g+w-y)/2;e.moveTo(v.x,v.wickTop),e.lineTo(v.x,_),e.moveTo(v.x,_+y),e.lineTo(v.x,v.wickBottom)}e.stroke(),e.beginPath();for(let v of s){if(v.c>=v.o!==f)continue;let{bodyTop:g,bodyBottom:w}=v;if(!Number.isFinite(g)||!Number.isFinite(w))continue;let b=Math.max(1,w-g);e.rect(v.x-a,(g+w-b)/2,a*2,b)}m?e.stroke():e.fill()}break}case"columns":{let d=vn(t.snapshot.bars),f=t.previousClose;d.length>0&&f!==void 0&&Number.isFinite(f)&&(d[0]={...d[0],from:f,up:d[0].to>=f});for(let m=0;m<2;m++){let v=m===0;e.fillStyle=c(v),e.beginPath();for(let g of s){let w=t.snapshot.bars[g.index]?.timestamp===g.t?g.index:typeof g.t=="number"?We(t.snapshot.bars,g.t):null;if(w===null||t.snapshot.bars[w].timestamp!==g.t)continue;let b=d[w];if(b.up!==v)continue;let p=o.y(b.from),y=o.y(b.to);!Number.isFinite(p)||!Number.isFinite(y)||e.rect(g.x-a,Math.min(p,y),a*2,Math.max(1,Math.abs(y-p)))}e.fill()}break}case"high-low":{e.lineWidth=2;for(let d=0;d<2;d++){let f=d===0;e.strokeStyle=c(f),e.beginPath();for(let m of s){if(m.c>=m.o!==f)continue;let v=m.x,g=o.y(m.h),w=o.y(m.l);!Number.isFinite(g)||!Number.isFinite(w)||(e.moveTo(v,g),e.lineTo(v,w))}e.stroke()}break}case"volume-bars":{let d=0;for(let f of s)d=Math.max(d,f.v??0);e.lineWidth=2;for(let f=0;f<s.length;f++){let m=s[f],v=o.y(m.o),g=o.y(m.c);!Number.isFinite(v)||!Number.isFinite(g)||(e.strokeStyle=c(m.c>=m.o),e.globalAlpha=.25+.65*(d<=0?0:Math.max(0,Math.min(1,(m.v??0)/d))),e.beginPath(),e.moveTo(m.x,m.wickTop),e.lineTo(m.x,m.wickBottom),e.moveTo(m.x-a,v),e.lineTo(m.x,v),e.moveTo(m.x,g),e.lineTo(m.x+a,g),e.stroke())}break}case"step-line":case"hlc-area":case"line-markers":{let d=r==="hlc-area";for(let f of In(s,o.y,m=>d?m.h/3+m.l/3+m.c/3:m.c)){let m=_n(f),v=r==="step-line"?wn(m):d?bn(m):m.map((w,b)=>({index:b,value:w.close}));if(d){for(let w of v)if(!Number.isFinite(w.value)){let b=m[w.index];w.value=b.high/3+b.low/3+b.close/3}}let g=v.map(w=>({x:f[w.index].x,y:o.y(w.value)})).filter(w=>Number.isFinite(w.y));if(g.length!==0){if(d){e.beginPath(),e.moveTo(g[0].x,o.geometry.bottom);for(let w of g)e.lineTo(w.x,w.y);e.lineTo(g[g.length-1].x,o.geometry.bottom),e.closePath(),e.globalAlpha=.18,e.fill(),e.globalAlpha=1}if(e.lineWidth=1.75,e.beginPath(),Mn(e,g),e.stroke(),r==="line-markers"){e.beginPath();for(let w of g)e.moveTo(w.x+2.5,w.y),e.arc(w.x,w.y,2.5,0,Math.PI*2);e.fill()}}}break}case"baseline":{let d=i.baseline??t.snapshot.bars[0]?.close;d!==void 0&&Number.isFinite(d)&&Gr(e,o,d,l,u,i.text??"#aebcca");break}default:return!1}return!0}finally{e.restore()}}var se={background:"#10151d",grid:"#283444",text:"#aebcca",up:"#58c9ac",down:"#f28b82",line:"#8bafff",font:"12px system-ui"},Ue=new Map;function Cn(e){let t=Ue.get(e);return t!==void 0||(t=new Intl.DateTimeFormat("en",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}),Ue.size===8&&Ue.delete(Ue.keys().next().value),Ue.set(e,t)),t}function An(e){return e!==void 0&&Number.isFinite(e)?Math.max(0,Math.min(20,Math.trunc(e))):2}var kn=new Map,Dn=new Map;function Rn(e,t,i){return e.size>=512&&e.delete(e.keys().next().value),e.set(t,i),i}function Pn(e,t,i,n,r="HH:mm"){if(!Number.isFinite(t)||Math.abs(t)>864e13)return String(t);let o=JSON.stringify([i.timeZone??"UTC",t,i.timespan??"",i.symbolTimezone,n,r]);return kn.get(o)??Rn(kn,o,Gt({displayDtf:e,timestamp:t,timespan:i.timespan??"",symbolTimezone:i.symbolTimezone,type:n,format:r}))}function $r(e,t,i){let n=JSON.stringify([i,t]),r=Dn.get(n);if(r!==void 0)return r;let o={};for(let s of e.formatToParts(t))(s.type==="year"||s.type==="month"||s.type==="day")&&(o[s.type]=s.value);return Rn(Dn,n,o)}function Ur(e,t){return t===null?"MM-DD":e.year!==t.year?"YYYY":e.month!==t.month?"YYYY-MM":e.day!==t.day?"MM-DD":"HH:mm"}function Ln(e){let t=e.geometry;return Number.isFinite(t.width)&&Number.isFinite(t.height)&&t.width>0&&t.height>0&&Number.isFinite(t.left)&&Number.isFinite(t.top)&&Number.isFinite(t.plotWidth)&&Number.isFinite(t.plotHeight)&&t.plotWidth>0&&t.plotHeight>0}function Bn(e,t){let i=t.geometry;e.beginPath(),e.rect(i.left,i.top,i.plotWidth,i.plotHeight),e.clip()}var Nn=new WeakMap;function On(e){let t=Nn.get(e);if(t!==void 0)return t;t={points:[]};for(let i of e.plottedCandles){let n=e.y(i.c);Number.isFinite(i.x)&&Number.isFinite(n)&&t.points.push({x:i.x,y:n,index:i.index})}return Nn.set(e,t),t}function Tn(e,t,i){let n=-2,r=0,o=0,s=!1;for(let a of On(t).points)a.index!==n+1?(i&&s&&(e.lineTo(o,t.geometry.bottom),e.lineTo(r,t.geometry.bottom),e.closePath()),e.moveTo(a.x,a.y),r=a.x,s=!0):e.lineTo(a.x,a.y),n=a.index,o=a.x;i&&s&&(e.lineTo(o,t.geometry.bottom),e.lineTo(r,t.geometry.bottom),e.closePath())}function Sn(e,t,i){if(typeof Path2D<"u"){let n=On(t),r=i?"area":"stroke",o=n[r];o===void 0&&(o=new Path2D,Tn(o,t,i),n[r]=o),i?e.fill(o):e.stroke(o)}else e.beginPath(),Tn(e,t,i),i?e.fill():e.stroke()}var Fn=new WeakMap;function Vr(e){if(e.plottedCandles.length<=e.geometry.plotWidth)return e.plottedCandles;let t=Fn.get(e);if(t!==void 0)return t;let i=[],n=NaN;for(let r of e.plottedCandles){let o=Math.floor(r.x);if(!Number.isFinite(o))continue;let s=i[i.length-1];if(o!==n||s===void 0){i.push({...r}),n=o;continue}s.c=r.c,s.h=Math.max(s.h,r.h),s.l=Math.min(s.l,r.l),s.wickTop=Math.min(s.wickTop,r.wickTop),s.wickBottom=Math.max(s.wickBottom,r.wickBottom);let a=e.y(s.o),l=e.y(s.c);s.bodyTop=Math.min(a,l),s.bodyBottom=Math.max(a,l)}return Fn.set(e,i),i}function zn(e,t,i={}){let n=t.model,r=n.geometry;if(!Ln(n))return;let o=An(i.pricePrecision??t.pricePrecision??He(t.snapshot.bars)),s=Cn(i.timeZone??"UTC");e.save();try{e.globalAlpha=1,e.globalCompositeOperation="source-over",e.setLineDash([]),e.lineWidth=1,e.fillStyle=i.background??se.background,e.fillRect(0,0,r.width,r.height),e.font=i.font??se.font,e.textBaseline="middle",e.save();try{Bn(e,n),e.strokeStyle=i.grid??se.grid,e.beginPath();for(let d of n.yTicks){let f=n.y(d);e.moveTo(r.left,f),e.lineTo(r.right,f)}for(let d of n.xTickIndices){let f=n.xPositions[d];e.moveTo(f,r.top),e.lineTo(f,r.bottom)}e.stroke();let u=i.chartType??"candles",h=t.snapshot.viewport.i1-t.snapshot.viewport.i0,c=u!=="line"&&u!=="area"||n.plottedSeries.some(d=>d.source.type==="bar")?ht(n,t.snapshot.dataStart!==void 0&&h>0?r.plotWidth/h:void 0):0;if(!En(e,t,i,c))if(u==="line"||u==="area"){let d=i.line??se.line;u==="area"&&(e.fillStyle=d,e.globalAlpha=.14,Sn(e,n,!0),e.globalAlpha=1),e.strokeStyle=d,e.lineWidth=1.5,Sn(e,n,!1)}else{let d=i.candleDensity==="pixel-envelope"?Vr(n):n.plottedCandles;for(let f=0;f<2;f++){let m=f===0,v=m?i.up??se.up:i.down??se.down;e.fillStyle=e.strokeStyle=v,e.beginPath();for(let g of d)if(g.c>=g.o===m&&(e.moveTo(g.x,g.wickTop),e.lineTo(g.x,g.wickBottom),u==="ohlc")){let w=n.y(g.o),b=n.y(g.c);e.moveTo(g.x-c,w),e.lineTo(g.x,w),e.moveTo(g.x,b),e.lineTo(g.x+c,b)}if(e.stroke(),u==="candles"){e.beginPath();for(let g of d){if(g.c>=g.o!==m)continue;let w=Math.max(1,g.bodyBottom-g.bodyTop);e.rect(g.x-c,g.bodyTop,2*c,w)}e.fill()}}}e.lineWidth=1.5;for(let d of n.plottedSeries){let f=t.figureStyles?.get(d.source.id);if(e.lineWidth=f?.lineWidth??1.5,e.setLineDash(f?.dash===void 0?[]:[...f.dash]),e.strokeStyle=d.source.color??i.line??se.line,d.source.type==="bar"){e.fillStyle=e.strokeStyle;let v=Math.max(n.min,Math.min(n.max,f?.base??0)),g=Math.max(r.top,Math.min(r.bottom,n.y(v)));e.beginPath();for(let w of d.points)e.rect(w.x-c,Math.min(g,w.y),c*2,Math.max(1,Math.abs(w.y-g)));e.fill();continue}if(d.source.type==="scatter"){e.fillStyle=e.strokeStyle,e.beginPath();for(let v of d.points)e.moveTo(v.x+e.lineWidth,v.y),e.arc(v.x,v.y,e.lineWidth,0,2*Math.PI);e.fill();continue}e.beginPath();let m=-2;for(let v of d.points)v.index!==m+1?e.moveTo(v.x,v.y):e.lineTo(v.x,v.y),m=v.index;e.stroke()}}finally{e.restore()}e.fillStyle=i.text??se.text,t.indicatorPane===!0&&t.title!==void 0&&(e.textAlign="left",e.fillText(t.title,r.left+4,Math.max(8,r.top-7),Math.max(1,r.plotWidth-8))),e.textAlign="right";for(let u of n.yTicks)e.fillText(i.formatPrice?.(u,o)??u.toFixed(o),r.left-6,n.y(u),Math.max(1,r.left-10));if(n.hasRightAxis){e.textAlign="left";for(let u of n.rightTicks)e.fillText(u.toFixed(o),r.right+6,n.y(u,"right"),Math.max(1,r.width-r.right-10))}let a=-1/0,l=null;e.textAlign="center";for(let u of i.showTimeAxis===!1?[]:n.xTickIndices){let h=n.xKeys[u],c=(i.timespan==="minute"||i.timespan==="second")&&typeof h=="number"&&Number.isFinite(h)&&Math.abs(h)<=864e13?$r(s,h,i.timeZone??"UTC"):null,d=typeof h=="number"?Pn(s,h,i,"xAxis",c===null?"HH:mm":Ur(c,l)):String(h),f=Math.min(e.measureText(d).width,Math.max(1,r.width-8)),m=Math.max(4+f/2,Math.min(r.width-4-f/2,n.xPositions[u]));m-f/2<a+8||(e.fillText(d,m,Math.min(r.height-8,r.bottom+18),f),a=m+f/2,l=c)}}finally{e.restore()}}function jn(e,t,i,n={}){let r=t.model,o=r.geometry;if(!Ln(r)||!Number.isFinite(i)||i<o.left||i>o.right)return;let s=it(r,i),a=t.inspectBar!==void 0?t.inspectBar(i):t.inspect(i);if(s===null||a===null)return;let l=a.displayBar,u=$t(l),h=n.chartType==="hlc-area"?Number.isFinite(u)?u:l.high/3+l.low/3+l.close/3:l.close,c=r.xPositions[s],d=r.y(h),f=t.indicatorPane===!0;if(!Number.isFinite(c)||!f&&!Number.isFinite(d))return;let m=An(n.pricePrecision??t.pricePrecision??He(t.snapshot.bars));e.save();try{e.globalAlpha=1,e.globalCompositeOperation="source-over",e.strokeStyle=e.fillStyle=n.text??se.text,e.lineWidth=1,e.setLineDash([3,3]),e.save();try{Bn(e,r),e.beginPath(),e.moveTo(c,o.top),e.lineTo(c,o.bottom),f||(e.moveTo(o.left,d),e.lineTo(o.right,d)),e.stroke()}finally{e.restore()}e.setLineDash([]),e.font=n.font??se.font,e.textAlign="left",e.textBaseline="top";let v=f?r.plottedSeries.map(y=>{let _=0,N=y.points.length;for(;_<N;){let D=_+N>>>1;y.points[D].index<s?_=D+1:N=D}let F=y.points[_]?.index===s?y.points[_]:void 0;return`${y.source.name??y.source.id} ${F===void 0?"\u2014":Number(F.value.toPrecision(6))}`}).join(" "):`${a.mode==="heikin-ashi"?"HA ":""}O ${l.open.toFixed(m)} H ${l.high.toFixed(m)} L ${l.low.toFixed(m)} C ${l.close.toFixed(m)}`,g=Math.min(o.plotWidth,e.measureText(v).width+8);e.fillStyle=n.background??se.background,e.fillRect(o.left,o.top,g,20),e.fillStyle=n.text??se.text,e.fillText(v,o.left+4,o.top+3,Math.max(1,g-8)),e.textAlign="right",e.textBaseline="middle",f||e.fillText(n.formatPrice?.(h,m)??h.toFixed(m),o.left-6,d,Math.max(1,o.left-10));let w=Pn(Cn(n.timeZone??"UTC"),a.timestamp,n,"crosshair"),b=Math.min(o.width-8,e.measureText(w).width),p=Math.max(4+b/2,Math.min(o.width-4-b/2,c));e.textAlign="center",n.showTimeAxis!==!1&&e.fillText(w,p,Math.min(o.height-8,o.bottom+18),b)}finally{e.restore()}}function Wn(e,t,i,n,r={}){let o=e.ownerDocument,s=o.defaultView;if(s===null)return Object.assign(()=>{},{cancelInput:()=>{}});let a=r.frameScheduler??{request:R=>s.requestAnimationFrame(R),cancel:R=>s.cancelAnimationFrame(R)},l=new s.AbortController,u=new Map,h=s.matchMedia?.("(prefers-reduced-motion: reduce)"),c=e.style.touchAction;e.style.touchAction="none";let d=!1,f=!1,m=null,v=null,g=null,w=null,b=null,p=null,y=0,_={x:0,time:0},N=null,F=null,D=R=>R instanceof s.Element&&R.closest('input,textarea,select,button,a,[contenteditable]:not([contenteditable="false"])')!==null,k=()=>{p=null},S=()=>(p===null&&(p=e.getBoundingClientRect()),b===null&&(b=a.request(()=>{b=null,p=null})),p),T=R=>{let I=s.performance.now();return Number.isFinite(R.timeStamp)&&Math.abs(R.timeStamp-I)<6e4?R.timeStamp:I},P=()=>{F!==null&&s.clearTimeout(F.timer),F=null},z=()=>{let R=i(),I=t.getSnapshot();return R!==null&&Number.isFinite(R.left)&&Number.isFinite(R.plotWidth)&&R.plotWidth>0&&I.length>0?{length:I.length,left:R.left,width:R.plotWidth,observed:I.viewport}:null},Y=R=>{let I=z();return I!==null&&I.length===R.length&&I.left===R.left&&I.width===R.width&&I.observed===R.observed},A=()=>{let R=v;if(v=null,R===null||!Y(R.frame))return;t.setViewport(R.next);let I=t.getSnapshot();m!==null&&(m.observed=I.viewport),N!==null&&(N.frame.observed=I.viewport),g!==null&&(g.frame.observed=I.viewport),I.viewport.i0===0&&I.hasMore&&t.requestMore()},O=()=>{d||w!==null||(w=a.request(R=>{if(w=null,!d){if(N!==null)if(!Y(N.frame)||h?.matches===!0||r.reducedMotion===!0)N=null;else{let I=Math.max(0,R-N.started),B=Math.exp(-I/220),X=-(N.velocity*220*(1-B))/N.frame.width*Math.max(0,re(N.start)-1),G={i0:N.start.i0+X,i1:N.start.i1+X},Z=we(G,N.frame.length,t.getLimits());v={next:Z,frame:N.frame};let Q=X<0&&Z.i0>G.i0+1e-9||X>0&&Z.i1<G.i1-1e-9;(Math.abs(N.velocity*B)<.01||I>=1400||Q)&&(N=null)}if(g!==null)if(!Y(g.frame))g=null;else{let I=t.getSnapshot().viewport,B=g.target,V=Math.max(0,R-g.time);g.time=R;let X=r.reducedMotion===!0||h?.matches===!0?1:1-Math.exp(-V/40),G=re(I),Z=re(B),Q=G*Math.exp(Math.log(Z/G)*X),le=Math.abs(Z-G)>1e-9?(Q-G)/(Z-G):X,ee={i0:I.i0+(B.i0-I.i0)*le,i1:I.i1+(B.i1-I.i1)*le},_e=Math.max(Math.abs(ee.i0-B.i0),Math.abs(ee.i1-B.i1))*g.frame.width/Math.max(1,Z-1),te=X===1||_e<.15||R-g.lastInput>=280;v={next:te?B:ee,frame:g.frame},te&&(g=null)}(N!==null||g!==null)&&O(),A(),u.size===0&&N===null&&g===null&&t.endNavigation()}}))},E=()=>{w!==null&&a.cancel(w),w=null},M=()=>{E(),g=null,N=null,A()},x=()=>{E(),v=null,g=null,N=null,y=0},C=()=>{let R=u.values(),I=R.next().value,B=R.next().value;return B===void 0?{x:I.x,distance:0}:{x:(I.x+B.x)/2,distance:Math.hypot(B.x-I.x,B.y-I.y)}},j=()=>{let R=z();if(u.size===0||R===null){m=null;return}let I=C();t.beginNavigation(),m={...R,start:{...R.observed},x:I.x,distance:I.distance},_={x:I.x,time:s.performance.now()},y=0},L=()=>{x(),P(),m=null,f=!1;let R=[...u.keys()];u.clear();for(let I of R)e.hasPointerCapture(I)&&e.releasePointerCapture(I);t.endNavigation(),n(null)},W=(R,I,B=!0)=>{e.addEventListener(R,I,{signal:l.signal,passive:B})};W("pointerdown",R=>{let I=R;if(I.button!==0||u.size>=2||D(I.target)||z()===null)return;M(),x(),P(),u.size===0&&t.endNavigation(),f=!1,t.beginNavigation();let B=S(),V={x:I.clientX-B.left,y:I.clientY-B.top};if(u.set(I.pointerId,V),e.setPointerCapture(I.pointerId),e.focus({preventScroll:!0}),j(),I.pointerType==="touch"&&u.size===1){let X=I.pointerId;F={id:X,point:V,timer:s.setTimeout(()=>{let G=u.get(X);if(F?.id!==X||G===void 0||u.size!==1||m===null||!Y(m)){P();return}F=null,f=!0,v=null,y=0,t.endNavigation(),n(G.x)},450)}}else n(null)});let H=(R,I=R.target)=>{let B=S(),V=R.clientX-B.left,X=R.clientY-B.top;if(!u.has(R.pointerId)){u.size===0&&!f&&!D(I)&&n(V);return}if(u.set(R.pointerId,{x:V,y:X}),F!==null){if(Math.hypot(V-F.point.x,X-F.point.y)<=8)return;P()}if(f&&u.size===1){n(V);return}if(m===null||!Y(m)){v=null,j();return}let G=C(),Z=T(R),Q=u.size===2&&m.distance>1?Math.max(1,G.distance)/m.distance:1,le=Math.max(0,Math.min(1,(m.x-m.left)/m.width)),ee=be(m.start,m.length,Q,le,t.getLimits()),_e=(m.x-G.x)/m.width*Math.max(0,re(ee)-1);v={next:{i0:ee.i0+_e,i1:ee.i1+_e},frame:m};let te=Z-_.time;if(u.size===1&&te>0){let Ce=Math.max(-3,Math.min(3,(G.x-_.x)/te));(te>80||Ce*y<0)&&(y=0),y+=(Ce-y)*(1-Math.exp(-te/30))}else u.size!==1&&(y=0);_={x:G.x,time:Z},O(),n(G.x)};return W("pointermove",R=>{let I=R,B=I.getCoalescedEvents?.(),V=B===void 0||B.length===0?I:B[B.length-1];H(V,I.target)}),W("pointerup",R=>{let I=R;if(!u.has(I.pointerId))return;let B=u.get(I.pointerId),V=S();(B.x!==I.clientX-V.left||B.y!==I.clientY-V.top)&&H(I);let X=u.size===1,G=s.performance.now()-_.time<80,Z=m!==null&&Y(m);if(M(),P(),u.delete(I.pointerId),e.hasPointerCapture(I.pointerId)&&e.releasePointerCapture(I.pointerId),u.size>0){j();return}let Q=z(),le=y;m=null,!f&&X&&Z&&G&&Q!==null&&r.inertia===!0&&r.reducedMotion!==!0&&h?.matches!==!0&&Math.abs(le)>.05?(N={frame:Q,start:{...Q.observed},velocity:le,started:s.performance.now()},O()):t.endNavigation(),I.pointerType!=="mouse"&&!f&&n(null)}),W("pointercancel",L),W("lostpointercapture",R=>{u.has(R.pointerId)&&L()}),W("pointerleave",()=>{u.size===0&&!f&&n(null)}),W("blur",L),W("focusin",R=>{D(R.target)&&L()}),s.addEventListener("blur",L,{signal:l.signal}),s.addEventListener("resize",k,{signal:l.signal}),o.addEventListener("scroll",k,{signal:l.signal,capture:!0,passive:!0}),o.addEventListener("visibilitychange",()=>{o.hidden&&L()},{signal:l.signal}),W("wheel",R=>{let I=R,B=z();if(B===null||D(I.target)||u.size>0)return;let V=I.deltaMode===1?16:I.deltaMode===2?B.width:1,X=I.deltaMode===1?16:I.deltaMode===2?e.clientHeight:1,G=I.deltaX*V,Z=I.deltaY*X,Q=s.performance.now(),le=g!==null&&Q-g.lastInput<160?g.mode:null,ee=I.ctrlKey?"zoom":I.shiftKey?"pan":le??(Math.abs(G)>Math.abs(Z)*1.2?"pan":"zoom"),_e=ee==="pan"?I.shiftKey&&G===0?Z:G:Z,te=Math.max(-400,Math.min(400,_e));if(!Number.isFinite(te)||te===0)return;I.preventDefault(),N!==null&&(M(),t.endNavigation()),N=null,P(),f=!1;let Ce=Math.sign(te);(g===null||!Y(g.frame)||g.direction!==Ce||g.mode!==ee)&&(g!==null&&g.mode!==ee&&t.endNavigation(),t.beginNavigation(),g={mode:ee,target:{...B.observed},direction:Ce,frame:B,time:Q,lastInput:Q});let Vt=I.clientX-S().left;if(ee==="zoom")g.target=be(g.target,B.length,Math.exp(-te*.002),(Vt-B.left)/B.width,t.getLimits());else{let qt=te/B.width*Math.max(0,re(g.target)-1);g.target=we({i0:g.target.i0+qt,i1:g.target.i1+qt},B.length,t.getLimits())}g.lastInput=Q,O(),n(Vt)},!1),W("keydown",R=>{let I=R;if(D(I.target)||I.ctrlKey||I.metaKey||I.isComposing)return;if(I.altKey){(I.key==="ArrowLeft"||I.key==="ArrowRight")&&(M(),L(),I.key==="ArrowLeft"?t.undoNavigation():t.redoNavigation(),I.preventDefault());return}if(I.key==="Escape"){L(),I.preventDefault();return}if(!["ArrowLeft","ArrowRight","PageUp","PageDown","+","=","-","Home"].includes(I.key))return;M(),L();let B=re(t.getSnapshot().viewport);switch(I.key){case"ArrowLeft":t.pan(-10);break;case"ArrowRight":t.pan(10);break;case"PageUp":t.pan(-Math.round(B*.8));break;case"PageDown":t.pan(Math.round(B*.8));break;case"+":case"=":t.zoom(1.5);break;case"-":t.zoom(1/1.5);break;case"Home":t.followLatest();break}let V=t.getSnapshot();I.key!=="Home"&&V.viewport.i0===0&&V.hasMore&&t.requestMore(),I.preventDefault()},!1),Object.assign(()=>{d||(d=!0,l.abort(),L(),b!==null&&a.cancel(b),b=null,p=null,e.style.touchAction=c)},{cancelInput:L})}var qr=0,Kr=e=>e!==null&&Number.isFinite(e.timestamp)&&Math.abs(e.timestamp)<=864e13&&Number.isFinite(e.price);function Hn(e,t,i,n,r,o){let s=e.ownerDocument,a=s.defaultView;if(a===null)return{setTool:()=>{},dispose:()=>{}};let l=new a.AbortController,u=null,h=!1,c=0,d=0,f=null,m=k=>{k.preventDefault(),k.stopImmediatePropagation()},v=k=>k instanceof a.Element&&k.closest('input,textarea,select,button,a,[contenteditable]:not([contenteditable="false"])')!==null,g=()=>{let k=i(),S=e.getBoundingClientRect(),T=k?.model.geometry;return k!==null&&k.snapshot.length>0&&S.width>0&&S.height>0&&T!==void 0&&[T.left,T.right,T.top,T.bottom].every(Number.isFinite)&&T.right>T.left&&T.bottom>T.top?k:null},w=k=>{e.hasPointerCapture(k)&&e.releasePointerCapture(k)},b=()=>{d++,c!==0&&a.cancelAnimationFrame(c),c=0;let k=f;f=null,k!==null&&w(k.pointerId),n(null)},p=()=>{let k=g(),S=f;if(S===null||k===null||S.points.length<2)return null;let T=[];for(let P of S.points){let z=k.unproject(P.x,P.y);if(!Kr(z))return null;let Y=k.project(z.timestamp,z.price);if(Y===null||Math.abs(Y.x-P.x)>.5||Math.abs(Y.y-P.y)>.5)return null;T.push(Object.freeze({...z}))}return Object.freeze({id:S.id,type:S.type,anchors:Object.freeze(T),locked:!1,hidden:!1,strokeWidth:S.type==="highlighter"?16:2})},y=()=>{c=0,!h&&f!==null&&n(p())},_=k=>{let S=g();if(S===null)return null;let T=e.getBoundingClientRect(),P=S.model.geometry,z=k.clientX-T.left,Y=k.clientY-T.top;return!Number.isFinite(z)||!Number.isFinite(Y)?null:{x:Math.max(P.left,Math.min(P.right,z)),y:Math.max(P.top,Math.min(P.bottom,Y))}},N=(k,S=!1)=>{let T=f,P=_(k);if(T===null||P===null)return;let z=T.points[T.points.length-1];Math.hypot(P.x-z.x,P.y-z.y)<(S?.01:T.spacing)||(T.points.length>=at&&(T.points=T.points.filter((A,O)=>O%2===0||O===T.points.length-1),T.spacing*=2),T.points.push(P))},F=(k,S)=>{e.addEventListener(k,S,{capture:!0,passive:!1,signal:l.signal})};F("pointerdown",k=>{let S=k;if(u===null||v(S.target)||S.button!==0)return;if(f!==null){m(S);return}let T=g(),P=e.getBoundingClientRect(),z=T?.model.geometry;if(T===null||z===void 0||S.clientX-P.left<z.left||S.clientX-P.left>z.right||S.clientY-P.top<z.top||S.clientY-P.top>z.bottom)return;let Y=d,A=u;if(m(S),o?.(),h||Y!==d||u!==A)return;let O=_(S);if(O===null)return;let E;do E=`stroke-${Date.now().toString(36)}-${(++qr).toString(36)}`;while(t.getSnapshot().drawings.some(M=>M.id===E));f={id:E,type:A,pointerId:S.pointerId,points:[O],spacing:2,original:t.getSnapshot().drawings};try{e.setPointerCapture(S.pointerId)}catch{b();return}e.focus({preventScroll:!0})}),F("pointermove",k=>{let S=k;if(f===null||(m(S),S.pointerId!==f.pointerId))return;let T=typeof S.getCoalescedEvents=="function"?S.getCoalescedEvents():[],P=Math.max(1,Math.ceil(T.length/64));for(let z=0;z<T.length;z+=P)N(T[z]);N(S),c===0&&(c=a.requestAnimationFrame(y))}),F("pointerup",k=>{let S=k;if(f===null||(m(S),S.pointerId!==f.pointerId))return;N(S,!0);let T=p(),P=f,z=d+1;b(),!(h||z!==d||T===null||P===null||u!==P.type||t.getSnapshot().drawings!==P.original||P.points.every(Y=>Math.hypot(Y.x-P.points[0].x,Y.y-P.points[0].y)<2))&&(t.add(T),t.select(T.id),u=null,r?.())}),F("pointercancel",k=>{f?.pointerId===k.pointerId&&(m(k),b())}),F("lostpointercapture",k=>{f?.pointerId===k.pointerId&&b()}),F("keydown",k=>{let S=k;S.key==="Escape"&&!S.isComposing&&!v(S.target)&&(f!==null||u!==null)&&(m(S),b(),u=null,r?.())}),F("blur",k=>{let S=k.relatedTarget;(!(S instanceof a.Node)||!e.contains(S))&&b()}),a.addEventListener("blur",b,{signal:l.signal}),s.addEventListener("visibilitychange",()=>{s.hidden&&b()},{signal:l.signal});let D=t.subscribe?.(()=>{f!==null&&t.getSnapshot().drawings!==f.original&&b()});return{setTool:k=>{if(!h){if(k!==null&&k!=="brush"&&k!=="highlighter")throw new TypeError("Unknown freehand tool");b(),u=k}},dispose:()=>{h||(h=!0,l.abort(),D?.(),b(),u=null)}}}async function Yn(e,t){(!["image/png","image/jpeg","image/webp"].includes(e.type)||e.size<=0||e.size>Math.floor((ae.encodedCharacters-32)*3/4))&&J(),t?.throwIfAborted();let i=new Uint8Array(await e.arrayBuffer());t?.throwIfAborted(),st(i,e.type);let n="";for(let r=0;r<i.length;r+=8192)n+=String.fromCharCode(...i.subarray(r,r+8192));return Ge(`data:${e.type};base64,${btoa(n)}`)}var Fe=class{constructor(t=async i=>await createImageBitmap(i)){this.decode=t}entries=new Map;held=new Map;pixels=0;disposed=!1;prepare(t){if(this.disposed)return Promise.reject(new Error("Drawing image renderer is disposed"));let i=this.entries.get(t);if(i!==void 0)return i.promise;let n;try{n=ot(t)}catch(s){return Promise.reject(s)}let r=n.width*n.height;if(this.entries.size>=ae.cachedImages||this.pixels+r>ae.cachedPixels)return Promise.reject(new RangeError("Drawing image cache is full; release unused images before adding another"));let o={promise:Promise.resolve(),bitmap:null,error:null,pixels:r,invalidations:new Set};return this.entries.set(t,o),this.pixels+=r,o.promise=Promise.resolve().then(async()=>{if(this.disposed||this.entries.get(t)!==o)throw new Error("Drawing image decode was cancelled");let s=await this.decode(new Blob([n.bytes],{type:n.mime}));if(this.disposed||this.entries.get(t)!==o)throw s.close(),new Error("Drawing image decode was cancelled");try{if(fe(s.width,s.height),s.width*s.height!==r)throw new RangeError("Decoded image dimensions disagree with the raster header");o.bitmap=s}catch(a){throw s.close(),a}}).catch(s=>{throw o.error=s instanceof Error?s:new Error(String(s)),o.error}).finally(()=>{let s=[...o.invalidations];if(o.invalidations.clear(),!this.disposed&&this.entries.get(t)===o)for(let a of s)try{a()}catch{}}),o.promise.catch(()=>{}),o.promise}getError(t){return this.entries.get(t)?.error??null}paint(t,i,n,r,o){if(this.disposed||![n.left,n.top,n.right,n.bottom,r.left,r.top,r.right,r.bottom].every(Number.isFinite)||n.right<=n.left||n.bottom<=n.top||r.right<=r.left||r.bottom<=r.top)return"unavailable";this.entries.has(i)||this.prepare(i).catch(()=>{});let s=this.entries.get(i);if(s===void 0||s.error!==null)return"unavailable";if(s.bitmap===null)return o!==void 0&&s.invalidations.add(o),"loading";t.save();try{t.beginPath(),t.rect(r.left,r.top,r.right-r.left,r.bottom-r.top),t.clip(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.drawImage(s.bitmap,n.left,n.top,n.right-n.left,n.bottom-n.top)}finally{t.restore()}return"ready"}retain(t){for(let[i,n]of this.entries){let r=n.bitmap===null&&n.error===null;!t.has(i)&&!this.held.has(i)&&!r&&this.release(i)}}hold(t){if(this.disposed)throw new Error("Drawing image renderer is disposed");if(t.size>ae.cachedImages)throw new RangeError("Too many held drawing images");let i=[...t];for(let r of i)Ge(r);if(new Set([...this.held.keys(),...i]).size>ae.cachedImages)throw new RangeError("Too many held drawing images");for(let r of i)this.held.set(r,(this.held.get(r)??0)+1);let n=!1;return()=>{if(!n){n=!0;for(let r of i){let o=this.held.get(r)??0;o<=1?this.held.delete(r):this.held.set(r,o-1)}}}}has(t){return this.entries.has(t)}release(t){if(this.held.has(t))return;let i=this.entries.get(t);i!==void 0&&(this.entries.delete(t),this.pixels-=i.pixels,i.invalidations.clear(),i.bitmap?.close())}dispose(){if(!this.disposed){this.disposed=!0,this.held.clear();for(let t of this.entries.keys())this.release(t)}}};var Xr=0;function Gn(e,t,i,n,r,o,s){let a=e.ownerDocument,l=a.defaultView;if(l===null)return{setTool:()=>{},dispose:()=>{}};let u=new l.AbortController,h=null,c=null,d=null,f=null,m=null,v=!1,g=E=>E instanceof l.Element&&E.closest('input,textarea,select,button,a,[contenteditable]:not([contenteditable="false"])')!==null,w=E=>{E.preventDefault(),E.stopImmediatePropagation()},b=E=>{let M=e.getBoundingClientRect();return{x:E.clientX-M.left,y:E.clientY-M.top}},p=()=>{let E=i(),M=E?.model.geometry,x=e.getBoundingClientRect();return x.width>0&&x.height>0&&E!==null&&E.snapshot.length>0&&M!==void 0&&[M.left,M.right,M.top,M.bottom].every(Number.isFinite)&&M.left<M.right&&M.top<M.bottom?E:null},y=E=>E!==null&&Number.isFinite(E.timestamp)&&Math.abs(E.timestamp)<=864e13&&Number.isFinite(E.price),_=E=>{e.hasPointerCapture(E)&&e.releasePointerCapture(E)},N=()=>{let E=c;c=null,d=null,E!==null&&_(E.pointerId),f?.close(),m!==null&&(m.abort.abort(),m.input.remove(),m=null),n(null)},F=()=>{h!==null&&(h=null,r?.())},D=Hn(e,t,i,n,r,o),k=E=>E.original===null||t.getSnapshot().drawings.find(M=>M.id===E.original?.id)===E.original,S=(E,M,x)=>({...E,anchors:E.anchors.map((C,j)=>j>=M?x:C)}),T=(E,M)=>{f?.close();let x=p(),C=E.anchors[E.type==="callout"?1:0],j=x?.project(C.timestamp,C.price);if(j==null){n(null),F();return}let L=a.createElement("textarea");L.setAttribute("aria-label","Drawing text"),L.placeholder="Text \xB7 Enter to save \xB7 Shift+Enter for a new line",L.maxLength=512,L.rows=3,L.value=E.text??"";let W=Math.min(260,e.clientWidth),H=Math.min(100,e.clientHeight);L.style.cssText=`position:absolute;z-index:4;box-sizing:border-box;resize:none;width:${W}px;height:${H}px;left:${Math.max(0,Math.min(j.x,e.clientWidth-W))}px;top:${Math.max(0,Math.min(j.y,e.clientHeight-H))}px;padding:6px;background:#10151d;color:#eee;border:1px solid #8bafff;font:12px system-ui;`;let $=!1,R=()=>{$||($=!0,f?.input===L&&(f=null),L.remove(),n(null))},I=()=>{if(!$){if(M!==null&&t.getSnapshot().drawings.find(B=>B.id===M.id)!==M){R();return}try{let B=L.value;M===null?(t.add({...E,text:B}),t.select(E.id)):t.update(M.id,{text:B})}catch(B){L.setCustomValidity(B instanceof Error?B.message:"Invalid drawing text"),L.reportValidity();return}R(),F(),e.focus({preventScroll:!0})}};f={input:L,original:M,close:R},e.append(L),L.addEventListener("input",()=>{L.setCustomValidity(""),n({...E,text:L.value})}),L.addEventListener("keydown",B=>{B.stopPropagation(),B.key==="Escape"?(B.preventDefault(),R(),F(),e.focus({preventScroll:!0})):B.key==="Enter"&&!B.shiftKey&&!B.isComposing&&(B.preventDefault(),I())}),L.addEventListener("blur",()=>{R(),F()}),n(E),L.focus(),L.select()},P=E=>{let M=a.createElement("input"),x=new l.AbortController;M.type="file",M.accept="image/png,image/jpeg,image/webp",M.hidden=!0,m={abort:x,input:M},e.append(M);let C=()=>{M.remove(),m?.abort===x&&(m=null,n(null),F())};M.addEventListener("cancel",C,{once:!0}),M.addEventListener("change",()=>{let j=M.files?.[0];if(j===void 0){C();return}let L=s??new Fe(async H=>await l.createImageBitmap(H)),W;(async()=>{try{let H=await Yn(j,x.signal);if(W=H,await L.prepare(H),v||x.signal.aborted||m?.abort!==x)return;t.add({...E,image:H}),t.select(E.id)}catch(H){x.signal.aborted||(console.warn("[super-chart] Image drawing was not saved",H),e.dispatchEvent(new l.CustomEvent("drawingerror",{bubbles:!0,detail:H})))}finally{s===void 0?L.dispose():W!==void 0&&!t.getSnapshot().drawings.some(H=>H.image===W)&&L.release(W),C()}})()},{once:!0}),M.click()},z=()=>{if(d?.preview.type!=="any-waves")return;let E=d.preview,M=E.anchors.slice(0,d.nextAnchor).filter((x,C,j)=>C===0||x.timestamp!==j[C-1].timestamp||x.price!==j[C-1].price);M.length<2||(d=null,t.add({...E,anchors:M}),t.select(E.id),n(null),F())},Y=E=>{let M=c,x=p();if(M===null)return!1;if(M.preview.locked)return!0;if(x===null||!k(M))return N(),!1;let C=b(E),j=C.x-M.start.x,L=C.y-M.start.y;if(!Number.isFinite(j)||!Number.isFinite(L))return!1;if(Math.hypot(j,L)>2&&(M.moved=!0),M.original!==null&&!M.moved)return!0;let W;if(M.original===null){let H=x.unproject(C.x,C.y);if(!y(H))return!1;W=xe(M.preview.type)===1?[H]:S(M.preview,M.anchorIndex??1,H).anchors}else if(M.anchorIndex!==null){let H=x.unproject(C.x,C.y);if(!y(H))return!1;W=M.original.anchors.map(($,R)=>R===M.anchorIndex?H:$)}else{let H=[];for(let $ of M.projected){let R=$.x+j,I=$.y+L,B=x.unproject(R,I);if(!y(B))return!1;let V=x.project(B.timestamp,B.price);if(V===null||Math.abs(V.x-R)>.5||Math.abs(V.y-I)>.5)return!1;H.push(B)}W=H}return M.preview={...M.preview,anchors:W},n(M.preview),!0},A=(E,M)=>{e.addEventListener(E,M,{capture:!0,passive:!1,signal:u.signal})};A("pointerdown",E=>{let M=E;if(f!==null&&g(M.target))return;if(m!==null){w(M);return}if(c!==null){w(M);return}if(M.button!==0||g(M.target))return;h!==null&&(w(M),o?.());let x=p();if(x===null)return;let C=b(M),j=x.model.geometry,L=C.x>=j.left&&C.x<=j.right&&C.y>=j.top&&C.y<=j.bottom;if(h!==null){if(!L)return;let W=x.unproject(C.x,C.y);if(!y(W))return;let H,$=null;if(d!==null)$=d.nextAnchor,H=S(d.preview,$,W),d=null;else{let R;do R=`drawing-${Date.now().toString(36)}-${(++Xr).toString(36)}`;while(t.getSnapshot().drawings.some(I=>I.id===R));H={id:R,type:h,anchors:Array.from({length:xe(h)},()=>W),locked:!1,hidden:!1}}c={pointerId:M.pointerId,start:C,original:null,preview:H,projected:[],anchorIndex:$,moved:!1},n(H)}else{let W=L?t.hitTest(C,x.project,j,M.pointerType==="touch"?10:6,x.drawingContext):null;if(W===null){t.select(null);return}let H=t.getSnapshot().drawings.find(R=>R.id===W.id);if(H===void 0||(t.select(W.id),H.locked))return;w(M),o?.();let $=[];for(let R of H.anchors){let I=x.project(R.timestamp,R.price);if(I===null||!Number.isFinite(I.x)||!Number.isFinite(I.y))return;$.push({...I})}c={pointerId:M.pointerId,start:C,original:H,preview:H,projected:$,anchorIndex:W.anchorIndex,moved:!1}}try{e.setPointerCapture(M.pointerId)}catch{N();return}e.focus({preventScroll:!0})}),A("pointermove",E=>{let M=E;if(c===null){if(d===null||g(M.target))return;let x=b(M),C=p()?.unproject(x.x,x.y);C!==void 0&&y(C)&&(d.preview=S(d.preview,d.nextAnchor,C),n(d.preview)),w(M);return}w(M),M.pointerId===c.pointerId&&Y(M)}),A("pointerup",E=>{if(c===null)return;let M=E;if(w(M),M.pointerId!==c.pointerId)return;if(!Y(M)){N();return}let x=c;if(x===null)return;if(c=null,_(x.pointerId),x.original===null&&x.preview.type==="any-waves"){let j=x.anchorIndex===null?x.moved?2:1:x.anchorIndex+1;if(j>=256){t.add(x.preview),t.select(x.preview.id),n(null),F();return}let L=x.preview.anchors.slice(0,j);L.push(L[L.length-1]),d={preview:{...x.preview,anchors:L},nextAnchor:j},n(d.preview);return}let C=xe(x.preview.type);if(x.original===null&&C>2&&x.anchorIndex!==C-1){d={preview:x.preview,nextAnchor:x.anchorIndex===null?x.moved?2:1:x.anchorIndex+1},n(x.preview);return}if(x.original===null&&$e(x.preview.type)){T(x.preview,null);return}if(x.original===null&&x.preview.type==="image"){x.moved?P(x.preview):n(null);return}try{if(x.original===null){if(!x.moved&&xe(x.preview.type)===2)return;t.add(x.preview),t.select(x.preview.id),F()}else x.moved&&!x.original.locked&&k(x)&&t.update(x.original.id,{anchors:x.preview.anchors})}finally{n(null)}}),A("dblclick",E=>{if(d?.preview.type==="any-waves"){w(E),z();return}if(h!==null||c!==null||d!==null||g(E.target))return;let M=p();if(M===null)return;let x=b(E),C=t.hitTest(x,M.project,M.model.geometry,6,M.drawingContext),j=t.getSnapshot().drawings.find(L=>L.id===C?.id);j===void 0||!$e(j.type)||j.locked||(w(E),t.select(j.id),o?.(),T(j,j))}),A("pointercancel",E=>{c!==null&&E.pointerId===c.pointerId&&(w(E),N())}),A("lostpointercapture",E=>{c!==null&&E.pointerId===c.pointerId&&N()}),A("blur",E=>{if(m!==null)return;let M=E.relatedTarget;(!(M instanceof l.Node)||!e.contains(M))&&N()}),l.addEventListener("blur",()=>{m===null&&N()},{signal:u.signal}),a.addEventListener("visibilitychange",()=>{a.hidden&&m===null&&N()},{signal:u.signal}),A("keydown",E=>{let M=E,x=a.activeElement;if(g(M.target)||M.isComposing||x===null||!e.contains(x))return;if(M.key==="Enter"&&d?.preview.type==="any-waves"){w(M),z();return}if(M.key==="Escape"&&(c!==null||d!==null||h!==null)){w(M),N(),F();return}let C=t.getSnapshot();if((M.ctrlKey||M.metaKey)&&!M.altKey){let L=M.key.toLowerCase(),W=L==="z"&&M.shiftKey||L==="y"&&!M.shiftKey,H=L==="z"&&!M.shiftKey;(W&&C.canRedo||H&&C.canUndo)&&(w(M),N(),D.setTool(null),W?t.redo():t.undo())}else if(!M.altKey&&!M.shiftKey&&(M.key==="Delete"||M.key==="Backspace")){let L=C.drawings.find(W=>W.id===C.selectedId);L!==void 0&&!L.locked&&(w(M),N(),t.remove(L.id))}});let O=t.subscribe(()=>{c!==null&&!k(c)&&N(),f?.original!==null&&f?.original!==void 0&&t.getSnapshot().drawings.find(E=>E.id===f?.original?.id)!==f.original&&f.close()});return{setTool:E=>{v||(N(),D.setTool(E==="brush"||E==="highlighter"?E:null),h=E==="brush"||E==="highlighter"?null:E)},dispose:()=>{v||(v=!0,u.abort(),O(),N(),D.dispose(),h=null)}}}function Ut(e,t,i,n={}){let r=n.lineWidth!==void 0&&Number.isFinite(n.lineWidth)&&n.lineWidth>0?n.lineWidth:1.5,o=n.handleRadius!==void 0&&Number.isFinite(n.handleRadius)&&n.handleRadius>0?n.handleRadius:4,s=n.fillOpacity!==void 0&&Number.isFinite(n.fillOpacity)?Math.max(0,Math.min(1,n.fillOpacity)):.1;e.save();try{e.globalAlpha=1,e.globalCompositeOperation="source-over";let a=n.bounds;if(a!==void 0){if(![a.left,a.right,a.top,a.bottom].every(Number.isFinite)||a.left>=a.right||a.top>=a.bottom)return;e.beginPath(),e.rect(a.left,a.top,a.right-a.left,a.bottom-a.top),e.clip()}e.lineWidth=r,e.lineCap="round",e.lineJoin="round",e.setLineDash([]),e.font=n.font??"11px system-ui",e.textBaseline="bottom";for(let l of t){let u=l.id===i,h=u?n.selectedColor??"#c3d5ff":n.color??"#8bafff";e.strokeStyle=h;for(let c of l.primitives)if(c.kind==="image"){let d=n.imageRenderer?.paint(e,c.source,c.bounds,c.clip,n.onInvalidate);if(n.imageRenderer===void 0||d==="unavailable"){e.save();try{let f=c.bounds,m=c.clip;e.beginPath(),e.rect(m.left,m.top,m.right-m.left,m.bottom-m.top),e.clip(),e.strokeRect(f.left,f.top,f.right-f.left,f.bottom-f.top),e.fillStyle=h,e.font="12px system-ui",e.textAlign="left",e.textBaseline="top",e.fillText("Image unavailable",f.left+4,f.top+4,Math.max(1,f.right-f.left-8))}finally{e.restore()}}}else if(c.kind==="stroke"){e.save();try{let d=c.clip;e.beginPath(),e.rect(d.left,d.top,d.right-d.left,d.bottom-d.top),e.clip(),e.lineWidth=c.width,e.globalAlpha=c.opacity,e.beginPath(),c.points.forEach((f,m)=>{m===0?e.moveTo(f.x,f.y):e.lineTo(f.x,f.y)}),e.stroke()}finally{e.restore()}}for(let c of l.primitives)c.kind!=="rect"&&c.kind!=="polygon"||(e.fillStyle=n.fillColor??h,e.globalAlpha=s,c.kind==="rect"?e.fillRect(c.from.x,c.from.y,c.to.x-c.from.x,c.to.y-c.from.y):(e.beginPath(),c.points.forEach((d,f)=>{f===0?e.moveTo(d.x,d.y):e.lineTo(d.x,d.y)}),e.closePath(),e.fill()));for(let c of l.primitives)if(c.kind==="ellipse"){e.save();try{let d=c.clip;e.beginPath(),e.rect(d.left,d.top,d.right-d.left,d.bottom-d.top),e.clip(),e.beginPath(),e.ellipse(c.center.x,c.center.y,c.radiusX,c.radiusY,0,0,Math.PI*2),e.fillStyle=n.fillColor??h,e.globalAlpha=s,e.fill(),e.globalAlpha=1,e.stroke()}finally{e.restore()}}e.globalAlpha=1,e.beginPath();for(let c of l.primitives)c.kind==="line"&&(e.moveTo(c.from.x,c.from.y),e.lineTo(c.to.x,c.to.y));e.stroke(),e.fillStyle=h;for(let c of l.primitives){if(c.kind==="label"){e.save();try{let f=c.bounds,m=c.clip;e.beginPath(),e.rect(m.left,m.top,m.right-m.left,m.bottom-m.top),e.clip(),c.boxed!==!1&&(e.fillStyle=n.handleFill??"#10151d",e.globalAlpha=.92,e.fillRect(f.left,f.top,f.right-f.left,f.bottom-f.top),e.globalAlpha=1,e.strokeRect(f.left,f.top,f.right-f.left,f.bottom-f.top)),e.beginPath(),e.rect(f.left,f.top,f.right-f.left,f.bottom-f.top),e.clip(),e.fillStyle=h,e.font="12px system-ui",e.textAlign="left",e.textBaseline="top",(c.price===void 0?c.lines:[n.formatPrice?.(c.price)??String(c.price)]).forEach((g,w)=>e.fillText(g,f.left+6,f.top+4+w*16,f.right-f.left-12))}finally{e.restore()}continue}if(c.kind!=="text")continue;e.textAlign=c.align;let d=c.price===void 0?c.text:`${c.text} ${n.formatPrice?.(c.price)??String(c.price)}`;e.fillText(d,c.position.x,c.position.y-3)}if(!(!u||l.locked)){e.fillStyle=n.handleFill??"#10151d",e.beginPath();for(let c of l.handles)e.moveTo(c.point.x+o,c.point.y),e.arc(c.point.x,c.point.y,o,0,Math.PI*2);e.fill(),e.stroke()}}}finally{e.restore()}}function $n(e,t,i,n,r,o,s){let a=e.ownerDocument.defaultView;if(a===null)return()=>{};let l=s??{request:D=>a.requestAnimationFrame(D),cancel:D=>a.cancelAnimationFrame(D)},u=new a.AbortController,h=e.style.cursor,c=null,d=null,f=null,m=null,v=null,g=()=>{v=null},w=()=>(v===null&&(v=e.getBoundingClientRect()),m===null&&(m=l.request(()=>{m=null,v=null})),v),b=D=>{let k=w();return{x:D.clientX-k.left,y:D.clientY-k.top}},p=(D,k,S)=>{for(let z=1;z<D.panes.length;z++)if(Math.abs(S-D.panes[z].top)<=5)return z;let T=D.model.geometry;if(k>=0&&k<T.left&&S>=T.top&&S<=T.bottom)return null;let P=D.panes[D.panes.length-1];if(o!==void 0&&P!==void 0&&k>=T.left&&k<=T.right&&S>=P.top+P.frame.model.geometry.bottom&&S<=P.top+P.height)return"time"},y=()=>{f!==null&&l.cancel(f),f=null,d=null;let D=c;c=null,e.style.cursor=h,D?.area==="time"&&o?.endNavigation(),D!==null&&e.hasPointerCapture(D.pointer)&&e.releasePointerCapture(D.pointer)},_=()=>{let D=d;if(d=null,D===null||c===null)return;let k=t(),S=w(),T=c.initial;if(k===null||S.width!==c.width||S.height!==c.height||k.panes.map(P=>P.id).join(`
|
|
6
|
+
`)!==T.panes.map(P=>P.id).join(`
|
|
7
|
+
`)){y();return}if(c.area==="time"){if(o===void 0||o.getSnapshot().viewport!==c.observed||o.getSnapshot().length!==T.snapshot.length){y();return}let P=T.model.geometry,z=Math.max(0,Math.min(1,(c.x-P.left)/P.plotWidth)),Y=Math.exp(Math.max(-4,Math.min(4,(D.x-c.x)/P.plotWidth*3)));o.setViewport(be(T.snapshot.viewport,T.snapshot.length,Y,z,o.getLimits())),c.observed=o.getSnapshot().viewport;return}if(k.snapshot.viewport!==T.snapshot.viewport){y();return}if(typeof c.area=="number"){let P=T.panes[c.area-1],z=T.panes[c.area],Y=Math.min(48,c.height/T.panes.length),A=Math.max(Y-P.height,Math.min(z.height-Y,D.y-c.y)),O=Object.create(null);for(let E of T.panes)O[E.id]=Math.max(1e-9,E.height+(E===P?A:E===z?-A:0));n({paneWeights:O})}else{let P=T.panes[0].scale,z=T.model.geometry,Y=Math.exp(Math.max(-4,Math.min(4,(D.y-c.y)/z.plotHeight*2))),A=P.value(c.y+(z.top-c.y)*Y),O=P.value(c.y+(z.bottom-c.y)*Y);Number.isFinite(A)&&Number.isFinite(O)&&A!==O&&(i().priceScale?.mode!=="log"||Math.min(A,O)>0)&&n({priceScale:{...i().priceScale,range:[Math.min(A,O),Math.max(A,O)]}})}},N=()=>{f===null&&(f=l.request(()=>{f=null,_()}))},F=D=>{D.preventDefault(),D.stopImmediatePropagation()};return e.addEventListener("pointerdown",D=>{if(D.button!==0||!D.isPrimary||c!==null)return;let k=t(),S=b(D);if(k===null||k.snapshot.length===0)return;let T=p(k,S.x,S.y);if(T===void 0)return;F(D),r(),T==="time"&&o?.beginNavigation();let P=w();c={pointer:D.pointerId,x:S.x,y:S.y,initial:k,width:P.width,height:P.height,area:T,observed:k.snapshot.viewport},e.setPointerCapture(D.pointerId),e.focus({preventScroll:!0})},{signal:u.signal,passive:!1}),e.addEventListener("pointermove",D=>{let k=D.getCoalescedEvents?.(),S=k===void 0||k.length===0?D:k[k.length-1],T=b(S);if(c===null){let P=t(),z=P===null?void 0:p(P,T.x,T.y);e.style.cursor=z===void 0?h:z==="time"?"ew-resize":"ns-resize";return}D.pointerId===c.pointer&&(F(D),d=T,N())},{signal:u.signal,passive:!1}),e.addEventListener("pointerup",D=>{D.pointerId===c?.pointer&&(F(D),d=b(D),_(),y())},{signal:u.signal}),e.addEventListener("pointercancel",y,{signal:u.signal}),e.addEventListener("lostpointercapture",D=>{D.pointerId===c?.pointer&&y()},{signal:u.signal}),e.addEventListener("dblclick",D=>{let k=t(),S=b(D);if(k===null)return;let T=p(k,S.x,S.y);T!==void 0&&(F(D),y(),r(),T==="time"?o?.resetViewport():n(T===null?{priceScale:{...i().priceScale,range:void 0}}:{paneWeights:void 0}))},{signal:u.signal}),e.addEventListener("keydown",D=>{D.key==="Escape"&&c!==null&&(F(D),y())},{signal:u.signal}),e.addEventListener("blur",y,{signal:u.signal}),a.addEventListener("blur",y,{signal:u.signal}),a.addEventListener("resize",g,{signal:u.signal}),e.ownerDocument.addEventListener("scroll",g,{signal:u.signal,capture:!0,passive:!0}),e.ownerDocument.addEventListener("visibilitychange",()=>{e.ownerDocument.hidden&&y()},{signal:u.signal}),()=>{u.abort(),y(),m!==null&&l.cancel(m),m=null,v=null}}function dt(e){return{...e,...e.priceScale===void 0?{}:{priceScale:{...e.priceScale,...e.priceScale.range===void 0?{}:{range:[...e.priceScale.range]}}},...e.paneWeights===void 0?{}:{paneWeights:{...e.paneWeights}}}}var ft=class{series=new Bt({referenceIndicators:!1});dataPort=Object.freeze({applyNewData:(t,i)=>{this.setData(t,i)},applyNormalizedData:(t,i)=>{this.assertLive(),this.validateBars(t,this.layout,t[0]?.close,!0),this.series.applyNewData(t,i)},truncateData:(t,i,n)=>(this.assertLive(),this.series.truncateData(t,i,n)),applyMoreData:(t,i)=>{this.prependData(t,i)},updateData:t=>{this.update(t)},updateDataBatch:(t,i)=>{this.updateBatch(t,i)},getDataList:()=>this.getBars(),getLastTimestamp:()=>(this.assertLive(),this.series.getLastTimestamp()),loadMore:t=>{this.assertLive(),this.series.loadMore(t)}});view;drawings=new ut;indicators=new rt;doc;win;root;canvas;cursorCanvas;drawingCanvas;drawingContext;drawingImages;context;cursorContext;resizeObserver;abort;unsubscribers=[];stopGestures;drawingInput;onInspect;inputs=new Map;layers=new Set;indicatorListeners=new Set;indicatorNoticeQueued=!1;inputId=0;draining=!1;preview=null;frame=null;frameId=0;cursorX=null;width=0;height=0;ratio=0;geometryDirty=!0;paintDirty=!0;drawingDirty=!0;cursorDirty=!0;disposed=!1;invalidateDrawings=()=>{this.disposed||(this.drawingDirty=!0,this.schedule())};viewportOptions;resolution;densityWidth=-1;layout;renderOptions;dprQuery=null;counters={frames:0,geometryBuilds:0,plotPaints:0,drawingPaints:0,cursorPaints:0,lastFrameMs:0,firstDataFrameMs:0,maxFrameMs:0};constructor(t,i={}){if(this.doc=t.ownerDocument,this.doc.defaultView===null)throw new Error("Chart host needs an active document");if(this.win=this.doc.defaultView,this.drawingImages=new Fe(async a=>await this.win.createImageBitmap(a)),this.abort=new this.win.AbortController,this.layout=dt(i.layout??{}),Se(this.layout),Te(this.layout.priceScale??{}),this.viewportOptions={minBars:20,maxBars:1200,rightPaddingBars:12,...i.viewport},nt(0,this.viewportOptions),this.resolution={...i.resolution},this.resolution.maxPixelRatio!==void 0&&(!Number.isFinite(this.resolution.maxPixelRatio)||this.resolution.maxPixelRatio<=0))throw new RangeError("Pixel ratio cap must be positive and finite");if(this.resolution.maxCanvasPixels!==void 0&&(!Number.isSafeInteger(this.resolution.maxCanvasPixels)||this.resolution.maxCanvasPixels<1))throw new RangeError("Canvas pixel budget must be a positive safe integer");this.renderOptions={...i.render},this.validateRender(this.renderOptions);for(let a of i.indicators??[{name:"MA",params:[20]},{name:"EMA",params:[21]}])this.indicators.add(a);this.view=new Ot(this.series,{count:i.count,mode:i.mode,continuous:!0,limits:this.viewportOptions}),this.onInspect=i.onInspect,this.root=this.doc.createElement("div"),this.root.style.cssText="position:relative;width:100%;height:100%;min-height:0;overflow:hidden;touch-action:none;",this.root.tabIndex=0,this.root.setAttribute("role","group"),this.root.setAttribute("aria-label","Chart. Drag to pan, pinch or wheel to zoom; Home follows the latest candle."),this.canvas=this.doc.createElement("canvas"),this.drawingCanvas=this.doc.createElement("canvas"),this.drawingCanvas.width=this.drawingCanvas.height=1,this.cursorCanvas=this.doc.createElement("canvas");for(let a of[this.canvas,this.drawingCanvas,this.cursorCanvas])a.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;",a.setAttribute("aria-hidden","true"),this.root.append(a);let n=this.canvas.getContext("2d"),r=this.drawingCanvas.getContext("2d"),o=this.cursorCanvas.getContext("2d");if(n===null||r===null||o===null)throw this.view.dispose(),new Error("Canvas 2D is unavailable");this.context=n,this.drawingContext=r,this.cursorContext=o,t.append(this.root),this.unsubscribers.push(this.series.subscribe(a=>{this.indicators.invalidate(a),a.kind!=="availability"&&((this.indicators.hasCustom()||this.layers.size>0)&&(this.geometryDirty=!0),this.drawings.getSnapshot().drawings.length>0&&(this.drawingDirty=!0),(this.geometryDirty||this.drawingDirty)&&this.schedule())})),this.unsubscribers.push(this.view.subscribe(()=>{let a=this.view.getSnapshot(),l=this.frame?.snapshot;(l===void 0||a.viewport!==l.viewport||a.bars!==l.bars||a.ma20!==l.ma20||a.ema21!==l.ema21)&&(this.geometryDirty=!0),this.cursorDirty=!0,this.schedule()})),this.unsubscribers.push(this.drawings.subscribe(()=>{this.retainDrawingImages(),this.drawingDirty=!0,this.schedule()}));let s={request:a=>{let l=++this.inputId;return this.inputs.set(l,a),this.schedule(),l},cancel:a=>{this.inputs.delete(a)}};this.unsubscribers.push($n(this.root,()=>this.frame,()=>this.layout,a=>this.setLayout(a),()=>this.stopGestures.cancelInput(),this.view,s)),this.drawingInput=Gn(this.root,this.drawings,()=>this.frame,a=>{this.preview=a,this.drawingDirty=!0,this.schedule()},i.onToolComplete,()=>this.stopGestures.cancelInput(),this.drawingImages),this.stopGestures=Wn(this.root,this.view,()=>this.frame?.model.geometry??null,a=>{this.cursorX!==a&&(this.cursorX=a,this.cursorDirty=!0,this.schedule())},{inertia:i.inertia!==!1,frameScheduler:s}),this.resizeObserver=new this.win.ResizeObserver(()=>this.schedule()),this.resizeObserver.observe(this.root),this.doc.addEventListener("visibilitychange",()=>{this.doc.hidden&&this.frameId!==0?(this.win.cancelAnimationFrame(this.frameId),this.frameId=0):this.schedule()},{signal:this.abort.signal}),this.watchPixelRatio(),this.schedule()}setData(t,i=!1){this.assertLive();let n=Ne(t,1).bars;this.validateBars(n,this.layout,n[0]?.close),this.series.applyNewData(n,i)}update(t){this.assertLive();let i=tt(t,1);if(i===null)throw new TypeError("Invalid OHLC candle");this.validateBars([i],this.layout,this.updateReference([i])),this.series.updateData(i)}prependData(t,i=!1){this.assertLive();let n=Ne(t,1).bars,r=this.series.getDataList()[0],o=r===void 0||n[0]!==void 0&&n[0].timestamp<r.timestamp?n[0]?.close:r.close;this.validateBars(n,this.layout,o),this.series.applyMoreData(n,i)}updateBatch(t,i){this.assertLive();let n=Ne(t,1).bars;this.validateBars(n,this.layout,this.updateReference(n)),this.series.updateDataBatch(n,i)}registerIndicator(t){this.assertLive(),this.indicators.register(t),this.notifyIndicators()}unregisterIndicator(t,i){this.assertLive();let n=this.indicators.unregister(t,i);return n&&this.notifyIndicators(),n}addIndicator(t){this.assertLive();let i=this.indicators.add(t);return this.geometryDirty=!0,this.schedule(),this.notifyIndicators(),i}removeIndicator(t){this.assertLive();let i=this.indicators.remove(t);return i&&(this.geometryDirty=!0,this.schedule(),this.notifyIndicators()),i}updateIndicator(t,i){this.assertLive();let n=this.indicators.update(t,i);return n&&(this.geometryDirty=!0,this.schedule(),this.notifyIndicators()),n}listIndicators(){return this.indicators.list()}getRegisteredIndicatorNames(){return this.indicators.registeredNames()}validateIndicatorReplacement(t){this.indicators.validateReplacement(t)}replaceIndicators(t){this.assertLive(),this.indicators.replace(t),this.geometryDirty=!0,this.schedule(),this.notifyIndicators()}onIndicatorsChanged(t){return this.assertLive(),this.indicatorListeners.add(t),()=>{this.indicatorListeners.delete(t)}}notifyIndicators(){this.indicatorNoticeQueued||this.disposed||(this.indicatorNoticeQueued=!0,this.win.queueMicrotask(()=>{if(this.indicatorNoticeQueued=!1,!this.disposed){for(let t of[...this.indicatorListeners])if(this.indicatorListeners.has(t))try{t()}catch(i){this.win.console.warn("Indicator change listener failed",i)}}}))}setDrawingTool(t){if(this.assertLive(),t!==null&&!lt.includes(t))throw new RangeError(`Unknown drawing tool ${JSON.stringify(t)}`);this.drawingInput.setTool(t)}addLayer(t){if(this.assertLive(),this.layers.has(t))throw new Error("Layer is already attached");return this.layers.add(t),this.geometryDirty=!0,this.schedule(),()=>{this.layers.delete(t)&&(this.paintDirty=!0,this.schedule(),t.dispose?.())}}setRenderOptions(t){this.assertLive();let i={...this.renderOptions,...t};this.validateRender(i),this.renderOptions=i,this.paintDirty=!0,this.drawingDirty=!0,this.cursorDirty=!0,this.schedule()}setLayout(t){this.assertLive();let i=dt({...this.layout,...t});Se(i),Te(i.priceScale??{}),(i.priceScale?.mode??"linear")!==(this.layout.priceScale?.mode??"linear")&&this.validateBars(this.series.getDataList(),i),this.layout=i,this.geometryDirty=!0,this.schedule()}getMetrics(){return{...this.counters}}getBars(t={}){if(this.assertLive(),Object.keys(t).some(s=>s!=="limit"))throw new TypeError("Only the bars limit option is supported");let i=t.limit;if(i!==void 0&&(!Number.isSafeInteger(i)||i<0))throw new RangeError("Bars limit must be a nonnegative safe integer");let n=this.series.getDataList(),r=i===void 0?0:Math.max(0,n.length-i),o=[];for(let s=r;s<n.length;s++)o.push({...n[s]});return o}getLastBar(){this.assertLive();let t=this.series.getDataList(),i=t[t.length-1];return i===void 0?null:{...i}}getLayoutOptions(){return this.assertLive(),dt(this.layout)}getRenderOptions(){return this.assertLive(),{...this.renderOptions}}restoreConfiguration(t,i){if(this.assertLive(),t.mode!=="raw"&&t.mode!=="heikin-ashi")throw new TypeError("Invalid candle mode");let n={...t.render},r=dt(t.layout);this.validateRender(n),Se(r),Te(r.priceScale??{});let o=i===void 0?this.series.getDataList():Ne(i.bars,1).bars;this.validateBars(o,r,o[0]?.close);let s=new ut({historyLimit:0});s.importJson(t.drawingsJson);let a=s.exportJson();this.indicators.replace(t.indicators),this.renderOptions=n,this.layout=r,this.drawings.importJson(a,{recordHistory:!1});try{this.view.setMode(t.mode),i!==void 0&&this.series.applyNewData(o,i.more)}finally{this.geometryDirty=!0,this.drawingDirty=!0,this.cursorDirty=!0,this.schedule(),this.notifyIndicators()}}requestPaint(){this.assertLive(),this.paintDirty=!0,this.schedule()}async prepareDrawingImages(t){this.assertLive();let i=this.holdDrawingImages(t),n=new Set(t.flatMap(r=>r.image===void 0?[]:[r.image]));try{let o=(await Promise.allSettled([...n].map(async s=>await this.drawingImages.prepare(s)))).find(s=>s.status==="rejected");if(o!==void 0)throw o.reason;this.assertLive()}finally{i()}}holdDrawingImages(t){this.assertLive();let i=this.drawingImages.hold(new Set(t.flatMap(n=>n.image===void 0?[]:[n.image])));return()=>{i(),this.retainDrawingImages(),this.invalidateDrawings()}}retainDrawingImages(){let t=new Set(this.drawings.getSnapshot().drawings.flatMap(i=>i.image===void 0?[]:[i.image]));this.preview?.image!==void 0&&t.add(this.preview.image),this.drawingImages.retain(t)}async snapshot(){this.assertLive();let t=this.drawings.getSnapshot().drawings,i=this.holdDrawingImages(t);try{if(await this.prepareDrawingImages(t),this.drawings.getSnapshot().drawings!==t)throw new Error("Drawings changed while preparing the image; capture again");if(this.frameId!==0&&(this.win.cancelAnimationFrame(this.frameId),this.frameId=0),this.renderTick(this.win.performance.now()),this.assertLive(),this.width<=0||this.height<=0)throw new Error("Cannot capture a zero-sized chart");if(this.frame===null||this.drawings.getSnapshot().drawings!==t)throw new Error("Chart changed while preparing the image; capture again");let n=this.doc.createElement("canvas");n.width=this.canvas.width,n.height=this.canvas.height;let r=n.getContext("2d");if(r===null)throw new Error("Canvas 2D is unavailable");r.drawImage(this.canvas,0,0),r.setTransform(this.canvas.width/this.width,0,0,this.canvas.height/this.height,0,0);let o=this.frame.model.geometry;return Ut(r,this.drawings.geometry(this.frame.project,o,this.frame.drawingContext),null,{bounds:o,imageRenderer:this.drawingImages}),await new Promise((s,a)=>n.toBlob(l=>{l===null?a(new Error("PNG encoding failed")):s(l)},"image/png"))}finally{i()}}dispose(){if(this.disposed)return;this.disposed=!0,this.abort.abort(),this.resizeObserver.disconnect(),this.unsubscribers.forEach(n=>n()),this.drawingInput.dispose(),this.drawingImages.dispose(),this.stopGestures(),this.view.dispose(),this.dprQuery?.removeEventListener("change",this.pixelRatioChanged),this.frameId!==0&&this.win.cancelAnimationFrame(this.frameId),this.frameId=0,this.inputs.clear(),this.frame=null,this.preview=null,this.series.loadMore(()=>{}),this.series.applyNewData([]),this.indicators.dispose(),this.indicatorListeners.clear(),this.root.remove(),this.canvas.width=this.canvas.height=this.drawingCanvas.width=this.drawingCanvas.height=this.cursorCanvas.width=this.cursorCanvas.height=0;let t=[...this.layers];this.layers.clear();let i=[];for(let n of t)try{n.dispose?.()}catch(r){i.push(r)}if(i.length>0)throw i[0]}assertLive(){if(this.disposed)throw new Error("Chart is disposed")}updateReference(t){let i=this.series.getDataList();return i.length===0?t[0]?.close:i.length===1?t.find(n=>n.timestamp===i[0].timestamp)?.close??i[0].close:i[0].close}validateBars(t,i=this.layout,n=this.series.getDataList()[0]?.close??t[0]?.close,r=!1){if(i.priceScale?.mode==="percentage"&&n===0)throw new RangeError("Percentage scale needs a nonzero reference price");for(let o of t){let{timestamp:s,open:a,high:l,low:u,close:h,volume:c,turnover:d}=o;if(r&&(c!=null&&!Number.isFinite(c)||d!=null&&!Number.isFinite(d)))throw new TypeError("Normalized candle has invalid volume or turnover");if(!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(l)||!Number.isFinite(u)||!Number.isFinite(h)||l<Math.max(a,h)||u>Math.min(a,h))throw new RangeError("Candle has invalid OHLC bounds");if(Math.abs(s)>864e13)throw new RangeError("Candle timestamp is outside the supported Date range");if(i.priceScale?.mode==="log"&&Math.min(a,l,u,h)<=0)throw new RangeError("Log scale requires positive prices")}}validateRender(t){if(t.timeZone!==void 0&&new Intl.DateTimeFormat("en",{timeZone:t.timeZone}).format(0),t.candleDensity!==void 0&&t.candleDensity!=="raw"&&t.candleDensity!=="pixel-envelope")throw new RangeError("Unknown candle density mode");if(t.chartType!==void 0&&!Yt.includes(t.chartType))throw new RangeError("Unknown chart type");if(t.baseline!==void 0&&!Number.isFinite(t.baseline))throw new RangeError("Baseline must be a finite price")}pixelRatioChanged=()=>{this.watchPixelRatio(),this.schedule()};watchPixelRatio(){this.dprQuery?.removeEventListener("change",this.pixelRatioChanged),this.dprQuery=this.win.matchMedia(`(resolution: ${this.win.devicePixelRatio||1}dppx)`),this.dprQuery.addEventListener("change",this.pixelRatioChanged)}schedule(){this.disposed||this.doc.hidden||this.frameId!==0||this.draining||(this.frameId=this.win.requestAnimationFrame(t=>{this.frameId=0,this.renderTick(t)}))}renderTick(t){this.draining=!0;let i=!1;try{let n=[...this.inputs.entries()];for(let[r,o]of n)this.inputs.delete(r)&&o(t);this.flush(),i=!0}finally{this.draining=!1,i&&(this.inputs.size>0||this.width>0&&this.height>0&&(this.geometryDirty||this.paintDirty||this.drawingDirty||this.cursorDirty))&&this.schedule()}}sizeDrawingCanvas(t){let i=t?this.canvas.width:1,n=t?this.canvas.height:1;this.drawingCanvas.width!==i&&(this.drawingCanvas.width=i),this.drawingCanvas.height!==n&&(this.drawingCanvas.height=n)}flush(){if(this.disposed)return;let t=this.win.performance.now(),i=this.root.getBoundingClientRect(),n=this.resolution.maxCanvasPixels,r=Math.min(this.win.devicePixelRatio||1,this.resolution.maxPixelRatio??1/0,n===void 0||i.width<=0||i.height<=0?1/0:Math.sqrt(n/(i.width*i.height))),o=i.width>0?Ye(i.width,i.height,this.layout.axisGutter,12).plotWidth:0;o>0&&o!==this.densityWidth&&(this.densityWidth=o,this.view.setLimits(nt(o,this.viewportOptions)));let s=i.width!==this.width||i.height!==this.height;if(s||r!==this.ratio){this.width=i.width,this.height=i.height,this.ratio=r;for(let a of[this.canvas,this.cursorCanvas])a.width=Math.min(n??1/0,Math.max(this.width>0?1:0,Math.floor(this.width*r))),a.height=Math.min(n===void 0||a.width===0?1/0:Math.floor(n/a.width),Math.max(this.height>0?1:0,Math.floor(this.height*r)));this.geometryDirty=this.geometryDirty||s,this.paintDirty=!0,this.drawingDirty=!0,this.cursorDirty=!0}if(this.width<=0||this.height<=0){this.preview===null&&this.drawings.getSnapshot().drawings.length===0&&this.sizeDrawingCanvas(!1);return}if(this.geometryDirty||this.frame===null){let a=this.series.getDataList(),l=this.indicators.compute(a).map(d=>({...d,pane:d.pane==="price"?"price":`indicator:${d.paneId??d.id}`})),u=this.view.getSnapshot(),h=u.dataStart??u.viewport.i0,c=h>0?this.series.snapshot(h-1,h,u.mode).bars[0]?.close:void 0;this.frame=jt(u,a,l,this.width,this.height,this.layout,c,this.series.version);for(let d of this.layers)d.update(this.frame,a);if(this.disposed)return;this.geometryDirty=!1,this.paintDirty=!0,this.drawingDirty=!0,this.cursorDirty=!0,this.counters.geometryBuilds++}if(this.paintDirty){this.context.setTransform(this.canvas.width/this.width,0,0,this.canvas.height/this.height,0,0),this.context.clearRect(0,0,this.width,this.height);for(let[a,l]of this.frame.panes.entries())this.context.save(),this.context.translate(0,l.top),zn(this.context,l.frame,{...this.renderOptions,formatPrice:a===0?l.scale.label:u=>String(Number(u.toPrecision(6))),showTimeAxis:a===this.frame.panes.length-1}),this.context.restore();for(let a of this.layers){this.context.save();try{a.paint(this.context)}finally{this.context.restore()}if(this.disposed)return}this.paintDirty=!1,this.counters.plotPaints++}if(this.drawingDirty){let a=this.drawings.getSnapshot();this.sizeDrawingCanvas(this.preview!==null||a.drawings.length>0),this.drawingContext.setTransform(this.canvas.width/this.width,0,0,this.canvas.height/this.height,0,0),this.drawingContext.clearRect(0,0,this.width,this.height);let l=this.frame.model.geometry;this.retainDrawingImages(),this.frame.drawingContext={bars:this.series.getDataList(),revision:this.series.version,visibleRange:[this.frame.snapshot.viewport.i0,this.frame.snapshot.viewport.i1]};let u=this.drawings.geometry(this.frame.project,l,this.frame.drawingContext).filter(h=>h.id!==this.preview?.id);if(this.preview!==null){let h=ct(this.preview,this.frame.project,l,this.frame.drawingContext);h!==null&&u.push(h)}Ut(this.drawingContext,u,this.preview?.id??a.selectedId,{bounds:l,imageRenderer:this.drawingImages,onInvalidate:this.invalidateDrawings}),this.drawingDirty=!1,this.counters.drawingPaints++}if(this.cursorDirty){if(this.cursorContext.setTransform(this.canvas.width/this.width,0,0,this.canvas.height/this.height,0,0),this.cursorContext.clearRect(0,0,this.width,this.height),this.cursorX!==null)for(let[a,l]of this.frame.panes.entries())this.cursorContext.save(),this.cursorContext.translate(0,l.top),jn(this.cursorContext,l.frame,this.cursorX,{...this.renderOptions,formatPrice:l.scale.label,showTimeAxis:a===this.frame.panes.length-1}),this.cursorContext.restore();this.cursorDirty=!1,this.counters.cursorPaints++,this.onInspect?.(this.cursorX===null?null:this.frame.inspect(this.cursorX))}this.disposed||this.frame===null||(this.counters.frames++,this.counters.lastFrameMs=this.win.performance.now()-t,this.counters.firstDataFrameMs===0&&this.frame.snapshot.bars.length>0&&(this.counters.firstDataFrameMs=this.counters.lastFrameMs),this.counters.maxFrameMs=Math.max(this.counters.maxFrameMs,this.counters.lastFrameMs))}};return Jn(Jr);})();
|