@363045841yyt/klinechart 0.6.9 → 0.6.10

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.
Files changed (48) hide show
  1. package/README.md +1 -0
  2. package/dist/index.cjs +5 -5
  3. package/dist/index.js +3824 -2564
  4. package/dist/klinechart.css +1 -1
  5. package/dist/src/api/data/baostock.d.ts +4 -0
  6. package/dist/src/components/IndicatorSelector.vue.d.ts +0 -9
  7. package/dist/src/core/chart.d.ts +38 -5
  8. package/dist/src/core/controller/interaction.d.ts +2 -30
  9. package/dist/src/core/controller/markerInteraction.d.ts +28 -0
  10. package/dist/src/core/controller/pinchTracker.d.ts +18 -0
  11. package/dist/src/core/controller/tooltipPosition.d.ts +21 -0
  12. package/dist/src/core/indicators/atrState.d.ts +16 -0
  13. package/dist/src/core/indicators/calculators.d.ts +67 -0
  14. package/dist/src/core/indicators/demaState.d.ts +16 -0
  15. package/dist/src/core/indicators/donchianState.d.ts +23 -0
  16. package/dist/src/core/indicators/hmaState.d.ts +16 -0
  17. package/dist/src/core/indicators/indicatorRuntime.d.ts +20 -0
  18. package/dist/src/core/indicators/kamaState.d.ts +20 -0
  19. package/dist/src/core/indicators/keltnerState.d.ts +27 -0
  20. package/dist/src/core/indicators/sarState.d.ts +26 -0
  21. package/dist/src/core/indicators/scheduler.d.ts +46 -2
  22. package/dist/src/core/indicators/stateComposer.d.ts +30 -0
  23. package/dist/src/core/indicators/supertrendState.d.ts +22 -0
  24. package/dist/src/core/indicators/temaState.d.ts +16 -0
  25. package/dist/src/core/indicators/wmaState.d.ts +16 -0
  26. package/dist/src/core/indicators/workerProtocol.d.ts +111 -1
  27. package/dist/src/core/paneRenderer.d.ts +3 -1
  28. package/dist/src/core/renderers/Indicator/atr.d.ts +17 -0
  29. package/dist/src/core/renderers/Indicator/dema.d.ts +5 -0
  30. package/dist/src/core/renderers/Indicator/donchian.d.ts +5 -0
  31. package/dist/src/core/renderers/Indicator/hma.d.ts +5 -0
  32. package/dist/src/core/renderers/Indicator/index.d.ts +2 -1
  33. package/dist/src/core/renderers/Indicator/indicatorData.d.ts +13 -0
  34. package/dist/src/core/renderers/Indicator/kama.d.ts +5 -0
  35. package/dist/src/core/renderers/Indicator/keltner.d.ts +5 -0
  36. package/dist/src/core/renderers/Indicator/sar.d.ts +5 -0
  37. package/dist/src/core/renderers/Indicator/scale/atr_scale.d.ts +11 -0
  38. package/dist/src/core/renderers/Indicator/subPaneConfig.d.ts +9 -0
  39. package/dist/src/core/renderers/Indicator/supertrend.d.ts +5 -0
  40. package/dist/src/core/renderers/Indicator/tema.d.ts +5 -0
  41. package/dist/src/core/renderers/Indicator/wma.d.ts +5 -0
  42. package/dist/src/core/renderers/webgl/candleSurface.d.ts +16 -5
  43. package/dist/src/core/renderers/webgl/sharedWebGLSurface.d.ts +33 -0
  44. package/dist/src/core/subPaneManager.d.ts +22 -0
  45. package/dist/src/semantic/types.d.ts +36 -0
  46. package/dist/src/test-setup.d.ts +6 -0
  47. package/package.json +1 -1
  48. /package/dist/src/api/data/{baostock.test.d.ts → baostock.integration.test.d.ts} +0 -0
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);var t=class{listeners=new Map;on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){let n=this.listeners.get(e);n&&n.delete(t)}emit(e,t){let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[EventBus] Error in handler for "${e}":`,t)}})}once(e,t){let n=r=>{this.off(e,n),t(r)};this.on(e,n)}clear(){this.listeners.clear()}listenerCount(e){return this.listeners.get(e)?.size??0}},n=class e extends Error{constructor(e){super(e),this.name=`HttpError`}static isHttpError(t){return t instanceof e}};async function r(e,t){let r=new URLSearchParams;if(t?.params)for(let[e,n]of Object.entries(t.params))n!==void 0&&n!==``&&r.set(e,String(n));let i=r.toString(),a=i?`${e}?${i}`:e,o=new AbortController,s=t?.timeout?setTimeout(()=>o.abort(),t.timeout):void 0;try{let e=await fetch(a,{signal:o.signal});if(!e.ok)throw new n(`HTTP ${e.status}: ${e.statusText}`);return{data:await e.json()}}catch(e){throw e instanceof n?e:e?.name===`AbortError`?new n(`请求超时`):new n(e?.message||`网络请求失败`)}finally{clearTimeout(s)}}function i(e){if(/^\d{8}$/.test(e))return`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`;if(/^\d{4}-\d{2}-\d{2}T/.test(e))return e.slice(0,10);if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString().slice(0,10)}function a(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)throw Error(`无法解析日期: ${e}`);let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return Date.UTC(n,r-1,i,-8,0,0,0)}function o(e){return e&&{daily:`d`,weekly:`w`,monthly:`m`,5:`5`,15:`15`,30:`30`,60:`60`}[e]||`d`}function s(e){return e&&{qfq:`2`,hfq:`1`,none:`3`}[e]||`3`}function c(e){let t=i(e.date),n=e=>{let t=parseFloat(e);return Number.isNaN(t)?0:t};return{timestamp:a(t),stockCode:e.code,open:n(e.open),high:n(e.high),low:n(e.low),close:n(e.close),volume:n(e.volume),turnover:n(e.amount),changePercent:n(e.pctChg),turnoverRate:n(e.turn)}}var l=``,u=`/api/stock/kdata`;async function d(e){if(typeof window<`u`&&window.location.hostname.includes(`github.io`)){let e=await(await fetch(`mock-stock-data.json`)).json();if(e.success&&e.data)return e.data.map(c).sort((e,t)=>e.timestamp-t.timestamp);throw Error(`Mock data failed`)}let{timeout:t,...n}=e,i=`${l}${u}`,a={stock_code:n.symbol,start_date:n.start_date,end_date:n.end_date,frequency:o(n.period),adjustflag:s(n.adjust),timeout:t};try{let e=(await r(i,{params:a,timeout:t?t*1e3:void 0})).data;if(!e.success)throw Error(`获取K线数据失败: ${e.error_msg||`未知错误`} (code: ${e.error_code})`);return!e.data||e.data.length===0?[]:e.data.map(c).sort((e,t)=>e.timestamp-t.timestamp)}catch(e){try{console.log(`fetch mock-stock-data.json`);let e=await fetch(`mock-stock-data.json`);if(e.ok){let t=await e.json();if(t.success&&t.data)return t.data.map(c).sort((e,t)=>e.timestamp-t.timestamp)}}catch{}throw Error(`获取K线数据失败: ${e instanceof Error?e.message:String(e)}`)}}function f(e){return e.map(e=>({timestamp:e.timestamp,open:e.open,high:e.high,low:e.low,close:e.close,stockCode:e.stockCode,volume:e.volume,turnover:e.turnover,amplitude:e.amplitude,changePercent:e.changePercent,changeAmount:e.changeAmount,turnoverRate:e.turnoverRate})).sort((e,t)=>e.timestamp-t.timestamp)}var p=`/api/public/stock_zh_a_hist`;function m(e){if(/^\d{8}$/.test(e))return`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`;if(/^\d{4}-\d{2}-\d{2}T/.test(e))return e.slice(0,10);if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString().slice(0,10)}function h(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)throw Error(`无法解析日期: ${e}`);let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return Date.UTC(n,r-1,i,-8,0,0,0)}function g(e){return{timestamp:h(m(e.日期)),stockCode:e.股票代码,open:e.开盘,close:e.收盘,high:e.最高,low:e.最低,volume:e.成交量,turnover:e.成交额,amplitude:e.振幅,changePercent:e.涨跌幅,changeAmount:e.涨跌额,turnoverRate:e.换手率}}async function _(e){try{let{timeout:t,...n}=e;return(await r(p,{params:n,timeout:t?t*1e3:void 0})).data.map(g)}catch(e){throw Error(`获取K线数据失败: ${e instanceof Error?e.message:String(e)}`)}}var v=new class{set(e,t){let n={data:t,timestamp:Date.now()};localStorage.setItem(e,JSON.stringify(n))}get(e,t=3600*1e3){let n=localStorage.getItem(e);if(!n)return null;try{let r=JSON.parse(n);return Date.now()-r.timestamp>t?(localStorage.removeItem(e),null):r.data}catch{return localStorage.removeItem(e),null}}remove(e){localStorage.removeItem(e)}clear(){localStorage.clear()}generateKey(e,t){return`${e}:${Object.keys(t).sort().map(e=>`${e}:${t[e]}`).join(`|`)}`}},y=class{name=`baostock`;async fetchKLineData(e){return d({symbol:this.addMarketPrefix(e.symbol),start_date:e.startDate,end_date:e.endDate,period:{daily:`daily`,weekly:`weekly`,monthly:`monthly`,"5min":`5`,"15min":`15`,"30min":`30`,"60min":`60`}[e.period]||`daily`,adjust:e.adjust,timeout:e.timeout})}addMarketPrefix(e){return/^(6|68)\d{5}$/.test(e)?`sh.${e}`:/^(0|3)\d{5}$/.test(e)?`sz.${e}`:e}},b=class{name=`dongcai`;async fetchKLineData(e){let t=e.startDate.replace(/-/g,``),n=e.endDate.replace(/-/g,``),r={daily:`daily`,weekly:`weekly`,monthly:`monthly`}[e.period];if(!r)throw Error(`东财数据源不支持周期: ${e.period}`);return f(await _({symbol:e.symbol,start_date:t,end_date:n,period:r,adjust:e.adjust===`none`?void 0:e.adjust,timeout:e.timeout}))}},x=class{static instances=new Map;static create(e){if(!this.instances.has(e))switch(e){case`baostock`:this.instances.set(e,new y);break;case`dongcai`:this.instances.set(e,new b);break;default:throw Error(`未知的数据源类型: ${e}`)}return this.instances.get(e)}},S=3600*1e3;function C(e,t){return v.generateKey(`kline:${e}`,{symbol:t.symbol,startDate:t.startDate,endDate:t.endDate,period:t.period,adjust:t.adjust})}async function w(e,t,n=!0){let r=C(e,t);if(n){let e=v.get(r,S);if(e)return console.log(`[KLineCache] 命中缓存: ${r}`),e}let i=await x.create(e).fetchKLineData(t);return n&&i.length>0&&(v.set(r,i),console.log(`[KLineCache] 写入缓存: ${r}, ${i.length} 条数据`)),i}var T=[`__proto__`,`constructor`,`prototype`],E=/^(#[0-9a-fA-F]{3,8}|rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)|rgba\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*[\d.]+\s*\))$/,D={SH:/^(600|601|603|605|688)\d{3}$/,SZ:/^(000|001|002|003|300|301)\d{3}$/,BJ:/^(83|87|43|82)\d{4}$/};function O(e){return{"5min":30,"15min":60,"30min":90,"60min":180,daily:365*3,weekly:365*5,monthly:365*10}[e]??365}var k=(typeof document<`u`?document.createElement(`canvas`):null)?.getContext(`2d`)??null,A=class e{limits;_ajv=null;constructor(){this.limits={maxJsonSize:64*1024,maxIndicators:10,maxCustomMarkers:100}}async getAjv(){return this._ajv||=(async()=>{let e=(await import(`ajv`)).default,t=new e({allErrors:!0,allowUnionTypes:!0});t.addFormat(`date`,{type:`string`,validate:e=>/^\d{4}-\d{2}-\d{2}$/.test(e)});let n=await Promise.resolve().then(()=>require(`./schema-CzmPW09E.cjs`));return t.addSchema(n.default||n),t})(),this._ajv}validateRawInput(e){return(typeof TextEncoder<`u`?new TextEncoder().encode(e).byteLength:e.length*3)>this.limits.maxJsonSize?{valid:!1,errors:[`JSON payload too large (max 64KB)`]}:{valid:!0}}async validate(e){if(!e||typeof e!=`object`)return{valid:!1,errors:[`Config must be an object`]};let t=this.checkPrototypePollution(e);if(!t.valid)return t;try{let t=await this.getAjv();if(!t.validate(`https://kmap.dev/schemas/semantic-chart-config/1.0.0`,e))return{valid:!1,errors:t.errors?.map(e=>`${e.instancePath} ${e.message}`)||[`Schema validation failed`]}}catch{return{valid:!1,errors:[`Schema validation unavailable (ajv not loaded)`]}}return{valid:!0}}securityCheck(e){let t=[],n=this.checkDateRange(e.data);n.valid||t.push(...n.errors||[]);let r=this.checkSymbol(e.data);if(r.valid||t.push(...r.errors||[]),e.indicators&&(e.indicators.main?.length||0)+(e.indicators.sub?.length||0)>this.limits.maxIndicators&&t.push(`Too many indicators (max ${this.limits.maxIndicators})`),(e.markers?.customMarkers?.length||0)>this.limits.maxCustomMarkers&&t.push(`Too many custom markers (max ${this.limits.maxCustomMarkers})`),e.markers?.customMarkers)for(let n of e.markers.customMarkers){if(n.style){let e=this.checkMarkerStyle(n.style,n.id);t.push(...e)}let e=this.checkMarkerDate(n.date,n.id);t.push(...e)}return{passed:t.length===0,violations:t.length>0?t:void 0}}checkPrototypePollution(e,t=``){if(!e||typeof e!=`object`)return{valid:!0};let n=[];for(let r of Object.keys(e))T.includes(r)&&n.push(`Forbidden key "${r}" found at ${t}`);return n.length>0?{valid:!1,errors:n}:{valid:!0}}checkDateRange(e){let t=[],n=new Date(e.startDate),r=new Date(e.endDate);if(isNaN(n.getTime())&&t.push(`Invalid startDate: ${e.startDate}`),isNaN(r.getTime())&&t.push(`Invalid endDate: ${e.endDate}`),t.length>0)return{valid:!1,errors:t};let i=O(e.period),a=Math.ceil((r.getTime()-n.getTime())/(1e3*60*60*24));return a>i&&t.push(`Date range exceeds maximum for period "${e.period}" (max ${i} days, got ${a})`),a<0&&t.push(`endDate must be after startDate`),t.length>0?{valid:!1,errors:t}:{valid:!0}}checkSymbol(e){let{symbol:t,exchange:n}=e;if(n){if(!D[n].test(t))return{valid:!1,errors:[`Invalid symbol "${t}" for exchange "${n}"`]}}else if(!Object.values(D).some(e=>e.test(t)))return{valid:!1,errors:[`Invalid symbol format: "${t}"`]};return{valid:!0}}checkMarkerStyle(e,t){let n=[],r=[`fillColor`,`strokeColor`,`textColor`];for(let i of r){let r=e[i];typeof r==`string`&&!E.test(r)&&n.push(`Invalid ${i} in marker "${t}": ${r}`)}if(k)for(let i of r){let r=e[i];typeof r==`string`&&(k.fillStyle=`#000000`,k.fillStyle=r,k.fillStyle===`#000000`&&r!==`#000000`&&!r.startsWith(`#000`)&&n.push(`Potentially unsafe ${i} in marker "${t}": ${r}`))}return n}static DATE_PATTERN=/^\d{4}-\d{2}-\d{2}( \d{2}:\d{2})?$/;checkMarkerDate(t,n){let r=[];if(!e.DATE_PATTERN.test(t))return r.push(`Invalid date format in marker "${n}": ${t} (expected YYYY-MM-DD or YYYY-MM-DD HH:mm)`),r;let i=t.includes(` `),a;if(i)a=new Date(t);else{let[e,n,r]=t.split(`-`).map(Number);a=new Date(Date.UTC(e,n-1,r))}return isNaN(a.getTime())&&r.push(`Invalid date value in marker "${n}": ${t}`),r}},j=class{chart;validator;events;constructor(e){this.chart=e,this.validator=new A,this.events=new t}async applyConfig(e){let t=await this.validator.validate(e);if(!t.valid)return{success:!1,errors:t.errors};let n=this.validator.securityCheck(e);if(!n.passed)return{success:!1,errors:n.violations};this.events.emit(`config:loading`,void 0);try{return await this.doApplyConfig(e),this.events.emit(`config:ready`,void 0),{success:!0}}catch(e){return this.events.emit(`config:error`,e),{success:!1,errors:[e instanceof Error?e.message:String(e)]}}}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}async doApplyConfig(e){console.log(`[Semantic] doApplyConfig start, data config:`,e.data);let t=await w(e.data.source,{symbol:e.data.symbol,startDate:e.data.startDate,endDate:e.data.endDate,period:e.data.period,adjust:e.data.adjust});console.log(`[Semantic] fetched data:`,t.length,`items`),this.chart.updateData(t),e.indicators&&(console.log(`[Semantic] applying indicators:`,e.indicators),this.applyIndicators(e.indicators.main,e.indicators.sub)),e.markers&&(console.log(`[Semantic] applying markers:`,e.markers.customMarkers?.length,`markers`),this.applyMarkers(e.markers.customMarkers,e.data.period)),e.chart&&this.applyChartOptions(e.chart),console.log(`[Semantic] doApplyConfig done`)}applyIndicators(e,t){if(e){for(let t of e)if(t.enabled)switch(t.type){case`MA`:this.applyMAIndicator(t);break;case`BOLL`:this.applyBOLLIndicator(t);break;case`EXPMA`:this.applyEXPMAIndicator(t);break;case`ENE`:this.applyENEIndicator(t);break}}if(this.chart.clearSubPanes(),t)for(let e of t)this.applySubIndicator(e)}applyMAIndicator(e){let t=e.params?.periods||[5,10,20,30,60],n={};for(let e of t)e===5?n.ma5=!0:e===10?n.ma10=!0:e===20?n.ma20=!0:e===30?n.ma30=!0:e===60&&(n.ma60=!0);console.log(`[Semantic] applyMAIndicator, periods:`,t,`maFlags:`,n),this.chart.updateRendererConfig(`ma`,n)}applyBOLLIndicator(e){let t={period:e.params?.period||20,multiplier:e.params?.multiplier||2};this.chart.updateRendererConfig(`boll`,t)}applyEXPMAIndicator(e){let t={fastPeriod:e.params?.fastPeriod||12,slowPeriod:e.params?.slowPeriod||50};this.chart.updateRendererConfig(`expma`,t)}applyENEIndicator(e){let t={period:e.params?.period||10,deviation:e.params?.deviation||11};this.chart.updateRendererConfig(`ene`,t)}applySubIndicator(e){if(!e.enabled)return;let{type:t,params:n}=e;this.chart.createSubPane(t,n)||console.warn(`[Semantic] Failed to create sub pane for ${t}`)}applyMarkers(e,t){if(!e||e.length===0){this.chart.clearCustomMarkers();return}let n=e.map(e=>({id:e.id,date:e.date,timestamp:M(e.date,t||`daily`),shape:e.shape,groupKey:e.groupKey,offset:e.offset,style:e.style,label:e.label,metadata:e.metadata}));this.chart.updateCustomMarkers(n)}applyChartOptions(e){e.autoScrollToRight}};function M(e,t){if(e.includes(` `)){let[t,n]=e.split(` `),r=t.split(`-`).map(Number),i=r[0],a=r[1],o=r[2],s=n.split(`:`).map(Number),c=s[0],l=s[1];return Date.UTC(i,a-1,o,c-8,l,0,0)}else{let t=e.split(`-`).map(Number),n=t[0],r=t[1],i=t[2];return Date.UTC(n,r-1,i,-8,0,0,0)}}var N={arrow_up:16,arrow_down:16,flag:14,circle:12,rectangle:14,diamond:12};function P(e,t,n,r,i,a){let o=a.fillColor||`#000000`,s=a.strokeColor||o,c=i||N[t];switch(e.fillStyle=o,e.strokeStyle=s,e.lineWidth=a.lineWidth||1,a.opacity!==void 0&&(e.globalAlpha=a.opacity),t){case`arrow_up`:ne(e,n,r,c);break;case`arrow_down`:re(e,n,r,c);break;case`circle`:ie(e,n,r,c);break;case`rectangle`:ae(e,n,r,c);break;case`diamond`:oe(e,n,r,c);break;case`flag`:se(e,n,r,c);break}e.globalAlpha=1}var F=2.5,I=4;function ee(e,t,n,r,i,a,o=!1){let s=t.fontSize||12,c=a.textColor||`#333333`,l=i/2;e.font=`${s}px sans-serif`,e.fillStyle=c,e.textBaseline=`middle`;let u=i*F,d=te(e,t.text,u),f=e.measureText(d).width,p=n,m=r;switch(t.position){case`left`:p=n-l-f/2-I;break;case`right`:p=n+l+f/2+I;break;case`top`:m=r-l-s/2-I;break;case`bottom`:m=r+l+s/2+I;break;default:m=o?r-l-s/2-I:r+l+s/2+I;break}t.offset&&(p+=t.offset.x||0,m+=t.offset.y||0),e.textAlign=t.align||`center`,e.fillText(d,p,m)}function te(e,t,n){if(e.measureText(t).width<=n)return t;let r=e.measureText(`…`).width,i=0,a=t.length;for(;i<a;){let o=Math.ceil((i+a)/2),s=t.slice(0,o);e.measureText(s).width+r<=n?i=o:a=o-1}return t.slice(0,i)+`…`}function ne(e,t,n,r){e.beginPath(),e.moveTo(t,n-r/2),e.lineTo(t-r/2,n+r/2),e.lineTo(t+r/2,n+r/2),e.closePath(),e.fill()}function re(e,t,n,r){e.beginPath(),e.moveTo(t,n+r/2),e.lineTo(t-r/2,n-r/2),e.lineTo(t+r/2,n-r/2),e.closePath(),e.fill()}function ie(e,t,n,r){e.beginPath(),e.arc(t,n,r/2,0,Math.PI*2),e.fill()}function ae(e,t,n,r){e.fillRect(t-r/2,n-r/2,r,r)}function oe(e,t,n,r){e.beginPath(),e.moveTo(t,n-r/2),e.lineTo(t+r/2,n),e.lineTo(t,n+r/2),e.lineTo(t-r/2,n),e.closePath(),e.fill()}function se(e,t,n,r){e.beginPath(),e.moveTo(t-r/4,n+r/2),e.lineTo(t-r/4,n-r/2),e.stroke(),e.beginPath(),e.moveTo(t-r/4,n-r/2),e.lineTo(t+r/2,n-r/4),e.lineTo(t-r/4,n),e.closePath(),e.fill()}function ce(e,t,n,r,i,a){let o=a/2;switch(n){case`circle`:let n=e-r,a=t-i;return n*n+a*a<=o*o;default:return e>=r-o&&e<=r+o&&t>=i-o&&t<=i+o}}var le=function(e){return e.Registered=`registered`,e.Installed=`installed`,e.Error=`error`,e}({});function ue(e){return{id:e.id,role:e.role,capabilities:{...e.capabilities},top:e.top,height:e.height,yAxis:{priceToY:t=>e.yAxis.priceToY(t),yToPrice:t=>e.yAxis.yToPrice(t),getPaddingTop:()=>e.yAxis.getPaddingTop(),getPaddingBottom:()=>e.yAxis.getPaddingBottom(),getPriceOffset:()=>e.yAxis.getPriceOffset(),getDisplayRange:t=>e.yAxis.getDisplayRange(t),getScaleType:()=>e.yAxis.getScaleType()},priceRange:e.priceRange}}var de=Symbol(`global-pane`),L={LAST_PRICE_LABEL:-25,SYSTEM_YAXIS:-20,SYSTEM_XAXIS:-20,BACKGROUND:0,GRID:10,INDICATOR:30,MAIN:50,INDICATOR_SCALE:55,OVERLAY:80,FOREGROUND:100,SYSTEM_BORDER:120,SYSTEM_CROSSHAIR:150},fe=class{plugins=new Map;register(e,t){if(this.plugins.has(e.name))throw Error(`Plugin "${e.name}" is already registered`);let n={plugin:e,config:{enabled:!0,priority:0,...t},state:`registered`};return this.plugins.set(e.name,n),n}unregister(e){return this.plugins.delete(e)}get(e){return this.plugins.get(e)}getPlugin(e){return this.plugins.get(e)?.plugin}getAll(){return Array.from(this.plugins.values())}getEnabled(){return this.getAll().filter(e=>e.config?.enabled!==!1)}updateState(e,t,n){let r=this.plugins.get(e);r&&(r.state=t,n&&(r.error=n))}has(e){return this.plugins.has(e)}clear(){this.plugins.clear()}},pe=class{hooks=new Map;tap(e,t,n=0){this.hooks.has(e)||this.hooks.set(e,[]);let r=this.hooks.get(e);r.push({name:e,fn:t,priority:n}),r.sort((e,t)=>e.priority-t.priority)}untap(e,t){let n=this.hooks.get(e);if(n){let e=n.findIndex(e=>e.fn===t);e!==-1&&n.splice(e,1)}}async call(e,t,n){let r=this.hooks.get(e);if(!r||r.length===0)return[];let i=[];for(let{fn:a}of r)try{let e=await a(t);i.push(e)}catch(t){if(console.error(`[HookSystem] Error in hook "${e}":`,t),n?.throwOnError)throw t}return i}callSync(e,t,n){let r=this.hooks.get(e);if(!r||r.length===0)return[];let i=[];for(let{fn:a}of r)try{let e=a(t);i.push(e)}catch(t){if(console.error(`[HookSystem] Error in hook "${e}":`,t),n?.throwOnError)throw t}return i}clear(){this.hooks.clear()}hookCount(e){return this.hooks.get(e)?.length??0}},me=class{configs=new Map;defaults=new Map;registerDefaults(e,t){this.defaults.set(e,{...t}),this.configs.has(e)||this.configs.set(e,new Map);let n=this.configs.get(e);for(let[e,r]of Object.entries(t))n.has(e)||n.set(e,r)}get(e,t,n){let r=this.configs.get(e);if(r?.has(t))return r.get(t);let i=this.defaults.get(e);return i&&t in i?i[t]:n}set(e,t,n){this.configs.has(e)||this.configs.set(e,new Map),this.configs.get(e).set(t,n)}setAll(e,t){for(let[n,r]of Object.entries(t))this.set(e,n,r)}getAll(e){let t=this.configs.get(e);return{...this.defaults.get(e)||{},...t?Object.fromEntries(t):{}}}clear(e){e?(this.configs.delete(e),this.defaults.delete(e)):(this.configs.clear(),this.defaults.clear())}},he=class{states=new Map;ownerNamespaces=new Map;setState(e,t,n){this.states.set(e,t)}getState(e){return this.states.get(e)}clearState(e){this.states.delete(e)}registerStateOwner(e,t){this.ownerNamespaces.set(e,new Set(t))}clearByOwner(e){let t=this.ownerNamespaces.get(e);t&&(t.forEach(e=>{this.states.delete(e)}),this.ownerNamespaces.delete(e))}clear(){this.states.clear(),this.ownerNamespaces.clear()}},ge=class{registry;eventBus;hookSystem;configManager;stateStore;isDestroyed=!1;logger;constructor(e){this.registry=new fe,this.eventBus=new t,this.hookSystem=new pe,this.configManager=new me,this.stateStore=new he,this.logger=e??console}events={on:(e,t)=>{this.eventBus.on(e,t)},off:(e,t)=>{this.eventBus.off(e,t)},emit:(e,t)=>{this.eventBus.emit(e,t)},once:(e,t)=>{this.eventBus.once(e,t)}};hooks={tap:(e,t,n=0)=>{this.hookSystem.tap(e,t,n)},untap:(e,t)=>{this.hookSystem.untap(e,t)},call:async(e,t,n)=>this.hookSystem.call(e,t,n),callSync:(e,t,n)=>this.hookSystem.callSync(e,t,n)};getConfig(e,t,n){return this.configManager.get(e,t,n)}setConfig(e,t,n){this.configManager.set(e,t,n)}getPlugin(e){return this.registry.getPlugin(e)}log(e,t,...n){let r=`[${new Date().toISOString()}] [${e.toUpperCase()}]`;this.logger[e](`${r} ${t}`,...n)}setSharedState(e,t,n){this.stateStore.setState(e,t,n)}getSharedState(e){return this.stateStore.getState(e)}clearSharedState(e){this.stateStore.clearState(e)}registerStateOwner(e,t){this.stateStore.registerStateOwner(e,t)}clearByOwner(e){this.stateStore.clearByOwner(e)}async use(e,t){if(this.ensureNotDestroyed(),this.registry.has(e.name))throw Error(`Plugin "${e.name}" is already installed`);try{let n=this.registry.register(e,t);t&&this.configManager.setAll(e.name,t),await this.hooks.call(`plugin:beforeInstall`,{plugin:e,config:t},{throwOnError:!0}),await e.install(this,n.config),this.registry.updateState(e.name,`installed`),await this.hooks.call(`plugin:afterInstall`,{plugin:e,config:t},{throwOnError:!0}),this.log(`info`,`Plugin "${e.name}" installed successfully`)}catch(t){throw this.registry.updateState(e.name,`error`,t instanceof Error?t:Error(String(t))),this.log(`error`,`Failed to install plugin "${e.name}":`,t),t}}async remove(e){this.ensureNotDestroyed();let t=this.registry.get(e);if(!t)throw Error(`Plugin "${e}" is not installed`);try{await this.hooks.call(`plugin:beforeUninstall`,{name:e},{throwOnError:!0}),t.plugin.uninstall&&await t.plugin.uninstall(),this.registry.unregister(e),this.configManager.clear(e),await this.hooks.call(`plugin:afterUninstall`,{name:e},{throwOnError:!0}),this.log(`info`,`Plugin "${e}" removed successfully`)}catch(t){throw this.log(`error`,`Failed to remove plugin "${e}":`,t),t}}getPlugins(){return this.registry.getAll()}getState(e){return this.registry.get(e)?.state}async destroy(){if(!this.isDestroyed){for(let e of this.registry.getAll())try{e.plugin.uninstall&&await e.plugin.uninstall()}catch(t){this.log(`error`,`Error uninstalling "${e.plugin.name}":`,t)}this.registry.clear(),this.eventBus.clear(),this.hookSystem.clear(),this.configManager.clear(),this.stateStore.clear(),this.isDestroyed=!0,this.log(`info`,`PluginHost destroyed`)}}ensureNotDestroyed(){if(this.isDestroyed)throw Error(`PluginHost has been destroyed`)}};function _e(e){return new ge(e)}function ve(e,t){let n=Math.round(e*t);return n%2==0&&(n+=1),Math.max(1,n)}function R(e,t,n){let r=ve(e,n),i=Math.round(t*n),a=r+i,o=i;return{kWidthPx:r,kGapPx:i,unitPx:a,startXPx:o,kWidthLogical:r/n,kGapLogical:i/n,unitLogical:a/n,startXLogical:o/n}}function ye(e,t,n,r,i,a=1){let{unitPx:o,startXPx:s}=R(n,r,a),c=e*a,l=t*a;return{start:Math.max(0,Math.floor((c-s)/o)-1),end:Math.min(i,Math.ceil((c+l-s)/o)+1)}}function be(e,t,n){let r=-1/0,i=1/0;for(let a=t;a<n&&a<e.length;a++){let t=e[a];t&&(t.high>r&&(r=t.high),t.low<i&&(i=t.low))}return!Number.isFinite(r)||!Number.isFinite(i)?{maxPrice:100,minPrice:0}:{maxPrice:r,minPrice:i}}var xe={logicalOffset:4,coordOffset:1e-4};function Se(e){return Math.abs(e)<1e-15}function z(e,t){let n=Math.abs(e);if(Se(n))return 0;let r=Math.log10(n+t.coordOffset)+t.logicalOffset;return e<0?-r:r}function Ce(e,t){let n=Math.abs(e);if(Se(n))return 0;let r=10**(n-t.logicalOffset)-t.coordOffset;return e<0?-r:r}function we(e){if(e===null)return{...xe};let t=Math.abs(e.maxPrice-e.minPrice);if(t>=1||t<1e-15)return{...xe};let n=Math.ceil(Math.abs(Math.log10(t))),r=xe.logicalOffset+n;return{logicalOffset:r,coordOffset:1/10**r}}function Te(e,t){return e.logicalOffset===t.logicalOffset&&e.coordOffset===t.coordOffset}var Ee=class{range={maxPrice:100,minPrice:0};height=1;paddingTop=0;paddingBottom=0;priceOffset=0;verticalScale=1;scaleType=`linear`;logFormula=we(null);setRange(e){if(this.range=e,this.scaleType===`log`&&e.minPrice>0){let t=we(e);if(!Te(t,this.logFormula)){let n=z(e.minPrice,this.logFormula),r=(z(e.maxPrice,this.logFormula)+n)/2+this.priceOffset;this.logFormula=t;let i=z(e.minPrice,this.logFormula),a=(z(e.maxPrice,this.logFormula)+i)/2;this.priceOffset=this.clampOffset(r-a)}}}setHeight(e){this.height=Math.max(1,e)}setPadding(e,t){this.paddingTop=Math.max(0,e),this.paddingBottom=Math.max(0,t)}getRange(){return this.range}getPaddingTop(){return this.paddingTop}getPaddingBottom(){return this.paddingBottom}setPriceOffset(e){this.priceOffset=this.clampOffset(e)}getPriceOffset(){return this.priceOffset}resetPriceOffset(){this.priceOffset=0}clampOffset(e){if(this.scaleType===`log`&&this.range.minPrice>0){let t=z(this.range.minPrice,this.logFormula),n=z(this.range.maxPrice,this.logFormula)-t;if(n<=0)return 0;let r=n*(1+1/this.verticalScale)/2;return Math.max(-r,Math.min(r,e))}let t=this.range.maxPrice-this.range.minPrice;if(t<=0)return 0;let n=t*(1+1/this.verticalScale)/2;return Math.max(-n,Math.min(n,e))}scaleByDelta(e){if(!Number.isFinite(e)||e===0)return;let t=Math.exp(-e*.01),n=this.verticalScale*t;this.verticalScale=Math.min(8,Math.max(.2,n)),this.priceOffset=this.clampOffset(this.priceOffset)}getVerticalScale(){return this.verticalScale}setScaleType(e){if(e!==this.scaleType){if(e===`log`&&this.range.minPrice>0){this.logFormula=we(this.range);let e=(this.range.maxPrice+this.range.minPrice)/2,t=e+this.priceOffset;this.priceOffset=z(t,this.logFormula)-z(e,this.logFormula),this.priceOffset=this.clampOffset(this.priceOffset)}else if(e===`linear`&&this.scaleType===`log`){let e=z(this.range.minPrice,this.logFormula),t=Ce((z(this.range.maxPrice,this.logFormula)+e)/2+this.priceOffset,this.logFormula),n=(this.range.maxPrice+this.range.minPrice)/2;this.priceOffset=t-n,this.priceOffset=this.clampOffset(this.priceOffset)}this.scaleType=e}}getScaleType(){return this.scaleType}getDisplayRange(e){let{minPrice:t,maxPrice:n}=e??this.range;if(this.scaleType===`log`&&t>0){let e=z(t,this.logFormula),r=z(n,this.logFormula),i=r-e||1,a=(r+e)/2+this.priceOffset,o=i/(2*this.verticalScale);return{maxPrice:Ce(a+o,this.logFormula),minPrice:Ce(a-o,this.logFormula)}}let r=n-t||1,i=(n+t)/2+this.priceOffset,a=r/(2*this.verticalScale);return{maxPrice:i+a,minPrice:i-a}}priceToY(e){let{maxPrice:t,minPrice:n}=this.getDisplayRange(),r=Math.max(1,this.height-this.paddingTop-this.paddingBottom),i;if(this.scaleType===`log`&&n>0){let r=z(n,this.logFormula),a=z(t,this.logFormula);i=(z(e,this.logFormula)-r)/(a-r||1)}else i=(e-n)/(t-n||1);return this.paddingTop+r*(1-i)}yToPrice(e){let{maxPrice:t,minPrice:n}=this.getDisplayRange(),r=Math.max(1,this.height-this.paddingTop-this.paddingBottom),i=1-(e-this.paddingTop)/r;if(this.scaleType===`log`&&n>0){let e=z(n,this.logFormula);return Ce(e+i*(z(t,this.logFormula)-e),this.logFormula)}return n+i*(t-n)}deltaYToPriceOffset(e){let t=Math.max(1,this.height-this.paddingTop-this.paddingBottom);if(this.scaleType===`log`&&this.range.minPrice>0){let n=z(this.range.minPrice,this.logFormula);return e*((z(this.range.maxPrice,this.logFormula)-n)/t)}return e*((this.range.maxPrice-this.range.minPrice||1)/t)}},B=function(e){return e.Main=`main`,e.Overlay=`overlay`,e.All=`all`,e}({});function De(e){return e===`price`?{showPriceAxisTicks:!0,showCrosshairPriceLabel:!0,candleHitTest:!0,supportsPriceTranslate:!0}:e===`indicator`?{showPriceAxisTicks:!1,showCrosshairPriceLabel:!0,candleHitTest:!1,supportsPriceTranslate:!0}:{showPriceAxisTicks:!1,showCrosshairPriceLabel:!1,candleHitTest:!1,supportsPriceTranslate:!1}}var Oe=class{id;role;capabilities;top=0;height=0;priceRange={maxPrice:100,minPrice:0};yAxis=new Ee;renderers=[];constructor(e,t={}){this.id=e,this.role=t.role??(e===`main`?`price`:`indicator`),this.capabilities={...De(this.role),...t.capabilities??{}}}setLayout(e,t){this.top=e,this.height=Math.max(1,t),this.yAxis.setHeight(this.height)}setPadding(e,t){this.yAxis.setPadding(e,t)}addRenderer(e){this.renderers.push(e)}updateRange(e,t,n){this.priceRange=be(e,t.start,t.end),n&&Number.isFinite(n.min)&&Number.isFinite(n.max)&&(this.priceRange.minPrice=Math.min(this.priceRange.minPrice,n.min),this.priceRange.maxPrice=Math.max(this.priceRange.maxPrice,n.max)),this.yAxis.setRange(this.priceRange)}},ke=Symbol(`renderer:global-cache`),Ae=class{plugins=new Map;pluginHost=null;enabledState=new Map;groupCache=new Map;mergedCache=new Map;knownPaneIds=new Set;cacheInvalid=!0;onInvalidate=null;setInvalidateCallback(e){this.onInvalidate=e}setPluginHost(e){this.pluginHost=e}addKnownPaneId(e){this.knownPaneIds.add(e),this.cacheInvalid=!0}removeKnownPaneId(e){this.knownPaneIds.delete(e),this.cacheInvalid=!0}setKnownPaneIds(e){this.knownPaneIds=new Set(e),this.cacheInvalid=!0}register(e){if(this.plugins.has(e.name)){console.warn(`Renderer plugin "${e.name}" already registered`);return}this.plugins.set(e.name,e),e.enabled!==void 0&&this.enabledState.set(e.name,e.enabled),this.cacheInvalid=!0;let t=e;if(t.onInstall&&this.pluginHost)try{t.onInstall(this.pluginHost)}catch(t){console.error(`[RendererPlugin] ${e.name} onInstall error:`,t)}let n=t.getDeclaredNamespaces?.();n&&this.pluginHost&&this.pluginHost.registerStateOwner(e.name,n),this.onInvalidate?.()}unregister(e){let t=this.plugins.get(e);if(t){if(this.pluginHost?.clearByOwner(e),t.onUninstall)try{t.onUninstall()}catch(e){console.error(`[RendererPlugin] ${t.name} onUninstall error:`,e)}this.plugins.delete(e),this.enabledState.delete(e),this.cacheInvalid=!0,this.onInvalidate?.()}}clear(){for(let e of this.plugins.values())if(e.onUninstall)try{e.onUninstall()}catch(t){console.error(`[RendererPlugin] ${e.name} onUninstall error:`,t)}this.plugins.clear(),this.enabledState.clear(),this.groupCache.clear(),this.mergedCache.clear(),this.cacheInvalid=!1}mergeSorted(e,t){let n=[],r=0,i=0;for(;r<e.length&&i<t.length;)e[r].priority<=t[i].priority?n.push(e[r++]):n.push(t[i++]);return[...n,...e.slice(r),...t.slice(i)]}rebuildCache(){if(!this.cacheInvalid)return;this.groupCache.clear(),this.mergedCache.clear();for(let e of this.plugins.values()){let t=typeof e.paneId==`symbol`?ke:e.paneId;this.groupCache.has(t)||this.groupCache.set(t,[]),this.groupCache.get(t).push(e)}for(let[,e]of this.groupCache)e.sort((e,t)=>e.priority-t.priority);let e=this.groupCache.get(ke)??[];for(let t of this.knownPaneIds){let n=this.groupCache.get(t)??[],r=this.mergeSorted(n,e);this.mergedCache.set(t,r)}this.mergedCache.set(ke,[...e]),this.cacheInvalid=!1}isRendererEnabled(e){let t=this.enabledState.get(e.name);return t===void 0?e.enabled!==!1:t}getMergedRenderers(e){this.rebuildCache();let t=this.mergedCache.get(e);if(!t){let n=this.groupCache.get(e)??[],r=this.groupCache.get(ke)??[];t=this.mergeSorted(n,r),this.mergedCache.set(e,t)}return t}getRenderers(e){return this.getMergedRenderers(e).filter(e=>e.isSystem?!1:this.isRendererEnabled(e))}render(e,t,n){let r=this.getRenderers(e),i=[];for(let e of r){if(n){let t=e.layer??`main`;if(n===B.Overlay&&t!==`overlay`||n===B.Main&&t===`overlay`)continue}try{e.draw(t)}catch(n){let r=n instanceof Error?n:Error(String(n));console.error(`[RendererPlugin] ${e.name} draw error:`,r),i.push({name:e.name,error:{message:r.message,stack:r.stack},paneId:t.pane.id,timestamp:Date.now()})}}return i}renderPlugin(e,t){let n=this.plugins.get(e);if(!n||!this.isRendererEnabled(n))return[];let r=[];try{n.draw(t)}catch(n){let i=n instanceof Error?n:Error(String(n));console.error(`[RendererPlugin] ${e} draw error:`,i),r.push({name:e,error:{message:i.message,stack:i.stack},paneId:t.pane.id,timestamp:Date.now()})}return r}setEnabled(e,t){this.plugins.has(e)&&(this.enabledState.set(e,t),this.onInvalidate?.())}updateConfig(e,t){let n=this.plugins.get(e);return n?.setConfig?(n.setConfig(t),this.onInvalidate?.(),!0):!1}getAllPlugins(){return Array.from(this.plugins.values())}getPlugin(e){return this.plugins.get(e)}notifyDataUpdate(e,t){for(let n of this.plugins.values())if(n.onDataUpdate&&this.isRendererEnabled(n))try{n.onDataUpdate(e,t)}catch(e){console.error(`[RendererPlugin] ${n.name} onDataUpdate error:`,e)}}notifyResize(e,t){let n=this.getMergedRenderers(e).filter(e=>this.isRendererEnabled(e));for(let e of n)if(e.onResize)try{e.onResize(t)}catch(t){console.error(`[RendererPlugin] ${e.name} onResize error:`,t)}}},je={PRIMARY:`hsl(210, 9%, 31%)`,SECONDARY:`hsl(210, 9%, 35%)`,TERTIARY:`hsl(210, 8%, 50%)`,WEAK:`hsl(210, 7%, 65%)`,WHITE:`rgba(255, 255, 255, 0.92)`},V={UP:`rgba(214, 10, 34, 1)`,UP_LIGHT:`rgba(214, 10, 34, 0.92)`,UP_TICK:`hsl(0, 60%, 50%)`,DOWN:`rgba(3, 123, 102, 1)`,DOWN_LIGHT:`rgba(3, 123, 102, 0.92)`,DOWN_TICK:`hsl(150, 30%, 60%)`,NEUTRAL:`rgba(0, 0, 0, 0.78)`,LAST_PRICE:`rgba(196, 74, 86, 0.95)`},Me={WHITE:`rgb(255, 255, 255)`,LIGHT_GRAY:`rgba(255, 255, 255, 0.92)`,PURE_WHITE:`#ffffff`,TRANSPARENT:`transparent`,ACTIVE:`#1890ff`,ACTIVE_HOVER:`#40a9ff`,HOVER:`#f0f0f0`},H={DARK:`rgba(0, 0, 0, 0.12)`,MEDIUM:`rgba(0, 0, 0, 0.10)`,LIGHT:`rgba(0, 0, 0, 0.08)`,SEPARATOR:`rgba(0, 0, 0, 0.10)`,BUTTON:`#d0d0d0`},Ne={HORIZONTAL:`rgba(0, 0, 0, 0.06)`,VERTICAL:`rgba(0, 0, 0, 0.12)`},U={MA5:`rgba(255, 193, 37, 1)`,MA10:`rgba(190, 131, 12, 1)`,MA20:`rgba(69, 112, 249, 1)`,MA30:`rgba(76, 175, 80, 1)`,MA60:`rgba(156, 39, 176, 1)`},W={UPPER:`rgba(178, 34, 34, 1)`,MIDDLE:`rgba(69, 112, 249, 1)`,LOWER:`rgba(34, 139, 34, 1)`,BAND_FILL:`rgba(100, 149, 237, 0.1)`},G={DIF:`rgba(69, 112, 249, 1)`,DEA:`rgba(255, 152, 0, 1)`,BAR_UP:`#ff5252`,BAR_UP_LIGHT:`#fccbcd`,BAR_DOWN:`#22ab94`,BAR_DOWN_LIGHT:`#ace5dc`},K={UP:`#ff5252`,DOWN:`#22ab94`,NEUTRAL:`rgba(0, 0, 0, 0.78)`},q={RSI1:`rgba(69, 112, 249, 1)`,RSI2:`rgba(255, 152, 0, 1)`,RSI3:`rgba(156, 39, 176, 1)`},Pe={CCI:`rgba(69, 112, 249, 1)`,OVERBOUGHT:`rgba(214, 10, 34, 0.5)`,OVERSOLD:`rgba(3, 123, 102, 0.5)`},J={K:`rgba(69, 112, 249, 1)`,D:`rgba(255, 152, 0, 1)`,J:`rgba(156, 39, 176, 1)`},Fe={MOM:`rgba(69, 112, 249, 1)`,ZERO:`rgba(0, 0, 0, 0.2)`},Ie={WMSR:`rgba(69, 112, 249, 1)`,OVERBOUGHT:`rgba(214, 10, 34, 0.5)`,OVERSOLD:`rgba(3, 123, 102, 0.5)`},Le={KST:`rgba(69, 112, 249, 1)`,SIGNAL:`rgba(255, 152, 0, 1)`},Re={FAST:`rgba(255, 152, 0, 1)`,SLOW:`rgba(69, 112, 249, 1)`},Y={UPPER:`rgba(214, 10, 34, 1)`,MIDDLE:`rgba(69, 112, 249, 1)`,LOWER:`rgba(3, 123, 102, 1)`,BAND_FILL:`rgba(69, 112, 249, 0.08)`},ze={LINE:`rgba(0, 0, 0, 0.28)`,LABEL_BG:`rgb(0, 0, 0)`,LABEL_TEXT:`rgba(255, 255, 255, 0.92)`};function X(e,t){return Math.round(e*t)/t}function Z(e,t){return(Math.floor(e*t)+.5)/t}function Be(e,t,n,r){if(t===n)return null;let i=Math.min(t,n),a=Math.max(t,n),o=Math.round(e*r),s=Math.round(i*r),c=Math.round(a*r);return{x:o/r,y:s/r,width:1/r,height:Math.max(1,c-s)/r}}function Ve(e,t,n,r){if(e===t)return null;let i=Math.min(e,t),a=Math.max(e,t),o=Math.round(i*r),s=Math.round(a*r),c=Math.round(n*r);return{x:o/r,y:c/r,width:Math.max(1,s-o)/r,height:1/r}}function He(e,t,n,r,i){let a=e+n,o=n,s=Math.round(t*i),c=Math.round((t+r)*i),l=Math.max(1,c-s),u=e+(n-1)/2,d=u,f=o%2==1;return{bodyRect:{x:e/i,y:s/i,width:n/i,height:l/i},physBodyLeft:e,physBodyRight:a,physBodyWidth:o,physBodyCenter:d,physWickX:u,wickRect:{x:u/i,width:1/i},isPerfectlyAligned:f}}var Ue=1.2,We=24,Ge=6;function Ke(e){switch(e){case`arrow_up`:case`flag`:return!0;default:return!1}}function qe(){return{name:`customMarkers`,version:`1.0.0`,description:`自定义标记渲染器`,debugName:`自定义标记`,paneId:de,priority:L.OVERLAY,draw(e){let{ctx:t,pane:n,data:r,range:i,scrollLeft:a,kWidth:o,kLineCenters:s,dpr:c,markerManager:l}=e;if(!l)return;let u=l.getCustomMarkers();if(!u||u.length===0)return;let d=r;if(d.length&&n.role===`price`){t.save(),t.translate(-a,0);for(let e of u){let r=Ye(d,e.timestamp);if(r===-1||r<i.start||r>=i.end)continue;let u=r-i.start;if(u<0||u>=s.length)continue;let f=s[u],p=d[r],m=e.style?.size,h=Je(o,m),g=(e.offset?.y??0)<0?!0:(e.offset?.y??0)>0?!1:Ke(e.shape),_;_=g?n.yAxis.priceToY(p.high)-h/2-4+(e.offset?.y??0):n.yAxis.priceToY(p.low)+h/2+4+(e.offset?.y??0);let v=f+(e.offset?.x??0),y=_,b=v,x=y,S=Math.round(h*c/2)*2/c;P(t,e.shape,b,x,S,e.style||{}),e.label&&ee(t,e.label,b,x,S,e.style||{},g),l.setCustomMarkerPosition(e.id,b-a,x,S,e.shape)}t.restore()}}}}function Je(e,t){let n=e*Ue;return Math.max(Ge,Math.min(n,t??We))}function Ye(e,t){let n=0,r=e.length-1;for(;n<=r;){let i=Math.floor((n+r)/2),a=e[i]?.timestamp;if(a===void 0)break;if(a===t)return i;a<t?n=i+1:r=i-1}return-1}var Xe=new Intl.DateTimeFormat(`zh-CN`,{timeZone:`Asia/Shanghai`,year:`numeric`,month:`2-digit`,day:`2-digit`}),Ze=1024,Qe=new Map;function $e(e){let t=Qe.get(e);if(t!==void 0)return t;let n=Xe.formatToParts(new Date(e)),r=``,i=``,a=``;for(let e=0;e<n.length;e++){let t=n[e];t.type===`year`?r=t.value:t.type===`month`?i=t.value:t.type===`day`&&(a=t.value)}let o=`${r}-${i}-${a}`;return Qe.size>=Ze&&Qe.clear(),Qe.set(e,o),o}var et=512,tt=new Map;function nt(e){let t=tt.get(e);if(t!==void 0)return t;let n=new Date(e),r=n.getFullYear(),i=n.getMonth()+1,a=i===1?{text:String(r),isYear:!0}:{text:`${i}月`,isYear:!1};return tt.size>=et&&tt.clear(),tt.set(e,a),a}function rt(e){let t=new Date(e);return t.getFullYear()*12+t.getMonth()}var it=$e,at=$e,ot=null,st=0,ct=0,lt=0,ut=[];function dt(e){if(e.length===0)return[];if(ot===e&&st===e.length){let t=e[0]?.timestamp,n=e[e.length-1]?.timestamp;if(t===ct&&n===lt)return ut}let t=[0],n=rt(e[0].timestamp);for(let r=1;r<e.length;r++){let i=e[r];if(!i)continue;let a=rt(i.timestamp);a!==n&&(t.push(r),n=a)}return ot=e,st=e.length,ct=e[0]?.timestamp??0,lt=e[e.length-1]?.timestamp??0,ut=t,t}var ft=V.UP,pt=V.DOWN,mt=V.NEUTRAL;function ht(e){return e>0?ft:e<0?pt:mt}function gt(e,t=2){let n=Math.abs(e);return n>=1e8?`${(e/1e8).toFixed(t)}亿`:n>=1e4?`${(e/1e4).toFixed(t)}万`:`${Math.round(e)}`}function _t(e,t=2){return`${e>0?`+`:``}${e.toFixed(t)}`}function vt(e,t=2){return`${e.toFixed(t)}%`}function yt(e,t=2){return`${e>0?`+`:``}${e.toFixed(t)}%`}function bt(e,t){let n=t?.close??e.open;return ht(e.open-n)}function xt(e){return ht(e.close-e.open)}function St(e){return typeof e.changePercent==`number`?ht(e.changePercent):typeof e.changeAmount==`number`?ht(e.changeAmount):mt}var Ct={class:`kline-tooltip__title`},wt={key:0},Tt={class:`kline-tooltip__grid`},Et={class:`row`},Dt={class:`row`},Ot={class:`row`},kt={class:`row`},At={key:0,class:`row`},jt={key:1,class:`row`},Mt={key:2,class:`row`},Nt={key:3,class:`row`},Pt={key:4,class:`row`},Ft={key:5,class:`row`},It=(0,e.defineComponent)({__name:`KLineTooltip`,props:{k:{},index:{},data:{},pos:{},useAnchor:{type:Boolean},anchorPlacement:{},setEl:{type:Function}},setup(t){let n=t,r=(0,e.computed)(()=>n.useAnchor===!0),i=(0,e.computed)(()=>n.anchorPlacement===`left-bottom`?`anchor-left-bottom`:`anchor-right-bottom`);function a(e){n.setEl?.(e)}let o=(0,e.computed)(()=>{let e=n.k;if(!e)return mt;let t=n.index;return bt(e,typeof t==`number`&&t>0?n.data[t-1]:void 0)}),s=(0,e.computed)(()=>{let e=n.k;return e?xt(e):mt}),c=(0,e.computed)(()=>{let e=n.k;return e?St(e):mt});return(n,l)=>t.k?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,ref:a,class:(0,e.normalizeClass)([`kline-tooltip`,[{"use-anchor":r.value},i.value]]),style:(0,e.normalizeStyle)(r.value?void 0:{left:`${t.pos.x}px`,top:`${t.pos.y}px`})},[(0,e.createElementVNode)(`div`,Ct,[t.k.stockCode?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,wt,(0,e.toDisplayString)(t.k.stockCode),1)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(it)(t.k.timestamp)),1)]),(0,e.createElementVNode)(`div`,Tt,[(0,e.createElementVNode)(`div`,Et,[l[0]||=(0,e.createElementVNode)(`span`,null,`开`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:o.value})},(0,e.toDisplayString)(t.k.open.toFixed(2)),5)]),(0,e.createElementVNode)(`div`,Dt,[l[1]||=(0,e.createElementVNode)(`span`,null,`高`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.k.high.toFixed(2)),1)]),(0,e.createElementVNode)(`div`,Ot,[l[2]||=(0,e.createElementVNode)(`span`,null,`低`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.k.low.toFixed(2)),1)]),(0,e.createElementVNode)(`div`,kt,[l[3]||=(0,e.createElementVNode)(`span`,null,`收`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:s.value})},(0,e.toDisplayString)(t.k.close.toFixed(2)),5)]),typeof t.k.volume==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,At,[l[4]||=(0,e.createElementVNode)(`span`,null,`成交量`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(gt)(t.k.volume)),1)])):(0,e.createCommentVNode)(``,!0),typeof t.k.turnover==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,jt,[l[5]||=(0,e.createElementVNode)(`span`,null,`成交额`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(gt)(t.k.turnover)),1)])):(0,e.createCommentVNode)(``,!0),typeof t.k.amplitude==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Mt,[l[6]||=(0,e.createElementVNode)(`span`,null,`振幅`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.k.amplitude)+`%`,1)])):(0,e.createCommentVNode)(``,!0),typeof t.k.changePercent==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Nt,[l[7]||=(0,e.createElementVNode)(`span`,null,`涨跌幅`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:c.value})},(0,e.toDisplayString)((0,e.unref)(yt)(t.k.changePercent)),5)])):(0,e.createCommentVNode)(``,!0),typeof t.k.changeAmount==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Pt,[l[8]||=(0,e.createElementVNode)(`span`,null,`涨跌额`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:c.value})},(0,e.toDisplayString)((0,e.unref)(_t)(t.k.changeAmount)),5)])):(0,e.createCommentVNode)(``,!0),typeof t.k.turnoverRate==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ft,[l[9]||=(0,e.createElementVNode)(`span`,null,`换手率`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(vt)(t.k.turnoverRate)),1)])):(0,e.createCommentVNode)(``,!0)])],6)):(0,e.createCommentVNode)(``,!0)}}),Lt=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},Rt=Lt(It,[[`__scopeId`,`data-v-d0fe85e6`]]),zt={RISE_WITH_VOLUME:`量价齐升`,RISE_WITHOUT_VOLUME:`量缩价升`,FALL_WITH_VOLUME:`量价齐缩`,FALL_WITHOUT_VOLUME:`量升价缩`},Bt=class{markers=new Map;hoveredMarkerId=null;lastHoveredId=null;customMarkers=new Map;customMarkerPositions=new Map;clear(){this.markers.clear()}register(e){this.markers.set(e.id,e)}getState(e){return this.hoveredMarkerId===e?`hovered`:`normal`}hitTest(e,t,n=3){for(let r of this.markers.values())if(e>=r.x-n&&e<=r.x+r.width+n&&t>=r.y-n&&t<=r.y+r.height+n)return r;return null}setHover(e){this.hoveredMarkerId=e,this.lastHoveredId=e}validateHoverState(){this.hoveredMarkerId!==null&&!this.markers.has(this.hoveredMarkerId)&&(this.hoveredMarkerId=null)}getHoveredMarker(){return this.hoveredMarkerId===null?null:this.markers.get(this.hoveredMarkerId)||null}getLastHoverId(){return this.lastHoveredId}getAllMarkers(){return Array.from(this.markers.values())}registerCustomMarker(e){this.customMarkers.set(e.id,e)}setCustomMarkers(e){this.clearCustomMarkers();for(let t of e)this.customMarkers.set(t.id,t)}clearCustomMarkers(){this.customMarkers.clear(),this.customMarkerPositions.clear()}getCustomMarkers(){return Array.from(this.customMarkers.values())}setCustomMarkerPosition(e,t,n,r,i){this.customMarkerPositions.set(e,{x:t,y:n,size:r,shape:i})}hitTestCustomMarker(e,t){for(let n of this.customMarkers.values()){let r=this.customMarkerPositions.get(n.id);if(r&&ce(e,t,r.shape,r.x,r.y,r.size))return n}return null}},Vt={class:`marker-tooltip__title`},Ht={key:0,class:`marker-tooltip__content`},Ut=Lt((0,e.defineComponent)({__name:`MarkerTooltip`,props:{marker:{},pos:{},useAnchor:{type:Boolean},anchorPlacement:{},setEl:{type:Function}},setup(t){let n=t,r=(0,e.computed)(()=>n.useAnchor===!0),i=(0,e.computed)(()=>n.anchorPlacement===`left-bottom`?`anchor-left-bottom`:`anchor-right-bottom`);function a(e){n.setEl?.(e)}let o=(0,e.computed)(()=>n.marker&&`date`in n.marker),s=(0,e.computed)(()=>{if(!n.marker)return``;if(o.value){let e=n.marker;return e.label?.text||e.shape}let e=n.marker;return zt[e.markerType]||e.markerType}),c=(0,e.computed)(()=>{if(!n.marker)return{};if(o.value){let e=n.marker;return{日期:e.date,...e.metadata}}return n.marker.metadata}),l=(0,e.computed)(()=>Object.keys(c.value).length>0);function u(e){return typeof e==`number`?e.toFixed(2):String(e)}return(n,o)=>t.marker?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,ref:a,class:(0,e.normalizeClass)([`marker-tooltip`,[{"use-anchor":r.value},i.value]]),style:(0,e.normalizeStyle)(r.value?void 0:{left:`${t.pos.x+12}px`,top:`${t.pos.y+12}px`})},[(0,e.createElementVNode)(`div`,Vt,(0,e.toDisplayString)(s.value),1),l.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ht,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(c.value,(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:n,class:`row`},[(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(n),1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(u(t)),1)]))),128))])):(0,e.createCommentVNode)(``,!0)],6)):(0,e.createCommentVNode)(``,!0)}}),[[`__scopeId`,`data-v-5574cc25`]]),Wt=Symbol(`fullscreen-teleport-target`);function Gt(){let t=(0,e.inject)(Wt,null);return(0,e.computed)(()=>t?.value??`body`)}var Kt={class:`params-header`},qt={class:`header-left`},Jt={class:`params-title`},Yt={class:`header-right`},Xt={key:0,class:`indicator-description`},Zt={class:`params-body`},Qt={class:`param-header`},$t={class:`param-label`},en={class:`param-label-text`},tn={key:0,class:`param-range`},nn={class:`input-wrapper`},rn=[`disabled`,`onClick`],an=[`value`,`min`,`max`,`step`,`onInput`],on=[`disabled`,`onClick`],sn={key:0,class:`param-description`},cn={class:`params-footer`},ln={class:`footer-right`},un=Lt((0,e.defineComponent)({__name:`IndicatorParams`,props:{visible:{type:Boolean},indicatorId:{},indicatorName:{},indicatorDescription:{},params:{},values:{}},emits:[`close`,`confirm`],setup(t,{emit:n}){let r=t,i=n,a=(0,e.ref)({...r.values}),o=(0,e.ref)(!0),s=Gt();(0,e.watch)(()=>r.values,e=>{a.value={...e}},{deep:!0,immediate:!0}),(0,e.watch)(()=>r.visible,e=>{e&&(a.value={...r.values})});function c(e,t){let n=t.target,r=parseFloat(n.value);isNaN(r)||(a.value[e]=r)}function l(e,t){let n=e.step||1,r=(a.value[e.key]||0)+t*n;e.min!==void 0&&(r=Math.max(e.min,r)),e.max!==void 0&&(r=Math.min(e.max,r)),a.value[e.key]=parseFloat(r.toFixed(10))}function u(){let e={};r.params.forEach(t=>{e[t.key]=t.default??r.values[t.key]??0}),a.value=e}function d(){i(`confirm`,{...a.value})}return(n,r)=>((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{to:(0,e.unref)(s)},[(0,e.createVNode)(e.Transition,{name:`overlay`},{default:(0,e.withCtx)(()=>[t.visible?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`params-overlay`,onClick:r[4]||=e=>n.$emit(`close`)},[(0,e.createVNode)(e.Transition,{name:`modal`},{default:(0,e.withCtx)(()=>[(0,e.createElementVNode)(`div`,{class:`indicator-params`,onClick:r[3]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`div`,Kt,[(0,e.createElementVNode)(`div`,qt,[(0,e.createElementVNode)(`span`,Jt,(0,e.toDisplayString)(t.indicatorName),1),r[5]||=(0,e.createElementVNode)(`span`,{class:`params-subtitle`},`参数设置`,-1)]),(0,e.createElementVNode)(`div`,Yt,[(0,e.createElementVNode)(`button`,{class:(0,e.normalizeClass)([`toggle-desc-btn`,{active:o.value}]),onClick:r[0]||=e=>o.value=!o.value,title:`显示/隐藏说明`},[...r[6]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 1024 1024`},[(0,e.createElementVNode)(`path`,{d:`M512 97.52381c228.912762 0 414.47619 185.563429 414.47619 414.47619s-185.563429 414.47619-414.47619 414.47619S97.52381 740.912762 97.52381 512 283.087238 97.52381 512 97.52381z m0 73.142857C323.486476 170.666667 170.666667 323.486476 170.666667 512s152.81981 341.333333 341.333333 341.333333 341.333333-152.81981 341.333333-341.333333S700.513524 170.666667 512 170.666667z m36.571429 268.190476v292.571428h-73.142858V438.857143h73.142858z m0-121.904762v73.142857h-73.142858v-73.142857h73.142858z`,fill:`currentColor`})],-1)]],2),(0,e.createElementVNode)(`button`,{class:`params-close`,onClick:r[1]||=e=>n.$emit(`close`)},[...r[7]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M18 6L6 18M6 6l12 12`})],-1)]])])]),(0,e.createVNode)(e.Transition,{name:`slide`},{default:(0,e.withCtx)(()=>[o.value&&t.indicatorDescription?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Xt,[(0,e.createElementVNode)(`p`,null,(0,e.toDisplayString)(t.indicatorDescription),1)])):(0,e.createCommentVNode)(``,!0)]),_:1}),(0,e.createElementVNode)(`div`,Zt,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.params,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.key,class:(0,e.normalizeClass)([`param-item`,{"has-desc":o.value&&t.description}])},[(0,e.createElementVNode)(`div`,Qt,[(0,e.createElementVNode)(`label`,$t,[(0,e.createElementVNode)(`span`,en,(0,e.toDisplayString)(t.label),1),t.min!==void 0||t.max!==void 0?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,tn,(0,e.toDisplayString)(t.min??`-∞`)+` ~ `+(0,e.toDisplayString)(t.max??`+∞`),1)):(0,e.createCommentVNode)(``,!0)]),(0,e.createElementVNode)(`div`,nn,[(0,e.createElementVNode)(`button`,{class:`stepper-btn`,disabled:t.min!==void 0&&(a.value[t.key]??0)<=t.min,onClick:e=>l(t,-1)},` − `,8,rn),t.type===`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`input`,{key:0,type:`number`,class:`param-input`,value:a.value[t.key],min:t.min,max:t.max,step:t.step||1,onInput:e=>c(t.key,e)},null,40,an)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`button`,{class:`stepper-btn`,disabled:t.max!==void 0&&(a.value[t.key]??0)>=t.max,onClick:e=>l(t,1)},` + `,8,on)])]),(0,e.createVNode)(e.Transition,{name:`slide`},{default:(0,e.withCtx)(()=>[o.value&&t.description?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,sn,(0,e.toDisplayString)(t.description),1)):(0,e.createCommentVNode)(``,!0)]),_:2},1024)],2))),128))]),(0,e.createElementVNode)(`div`,cn,[(0,e.createElementVNode)(`button`,{class:`params-btn reset`,onClick:u},[...r[8]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}),(0,e.createElementVNode)(`path`,{d:`M3 3v5h5`})],-1),(0,e.createTextVNode)(` 重置 `,-1)]]),(0,e.createElementVNode)(`div`,ln,[(0,e.createElementVNode)(`button`,{class:`params-btn cancel`,onClick:r[2]||=e=>n.$emit(`close`)},`取消`),(0,e.createElementVNode)(`button`,{class:`params-btn confirm`,onClick:d},[...r[9]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`},[(0,e.createElementVNode)(`path`,{d:`M20 6L9 17l-5-5`})],-1),(0,e.createTextVNode)(` 确定 `,-1)]])])])])]),_:1})])):(0,e.createCommentVNode)(``,!0)]),_:1})],8,[`to`]))}}),[[`__scopeId`,`data-v-bb1d1eb3`]]),dn={class:`indicator-selector`},fn={class:`indicator-scroll-container`},pn={class:`indicator-list`},mn={key:0,class:`indicator-divider`,"aria-hidden":`true`},hn=[`draggable`,`onDragstart`,`onDragover`,`onDrop`],gn=[`onMouseenter`],_n={class:`btn-content`},vn={key:0,class:`param-hint`},yn={key:0,class:`hover-overlay`},bn=[`onClick`],xn={key:1,class:`divider`},Sn=[`onClick`],Cn={class:`indicator-item`},wn={class:`menu-section`},Tn={class:`menu-items`},En=[`disabled`,`onClick`],Dn={class:`param-hint`},On={key:0,class:`active-tag`},kn={class:`menu-section`},An={class:`menu-items`},jn=[`disabled`,`onClick`],Mn={class:`param-hint`},Nn={key:0,class:`active-tag`},Pn=Lt((0,e.defineComponent)({__name:`IndicatorSelector`,props:{activeIndicators:{},indicatorParams:{}},emits:[`toggle`,`updateParams`,`reorderSubIndicators`],setup(t,{emit:n}){let r=[{id:`MA`,label:`MA`,name:`均线`,pane:`main`},{id:`VOLUME`,label:`VOL`,name:`成交量`,pane:`sub`,description:`成交量反映市场活跃度,柱状图显示每根K线的交易量。上涨时柱子为红色,下跌时为绿色。`},{id:`BOLL`,label:`BOLL`,name:`布林带`,pane:`main`,description:`布林带由三条轨道线组成,用于判断价格的波动范围和趋势强度。价格触及上轨可能超买,触及下轨可能超卖。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:20,description:`计算移动平均线的周期数,周期越长轨道越平滑`},{key:`multiplier`,label:`倍数`,type:`number`,min:.1,max:5,step:.1,default:2,description:`标准差倍数,决定轨道宽度,通常为 2`}]},{id:`EXPMA`,label:`EXPMA`,name:`指数平滑移动平均线`,pane:`main`,description:`EXPMA 对近期价格给予更高权重,比普通 MA 更敏感。快线上穿慢线为金叉看涨,下穿为死叉看跌。`,params:[{key:`fastPeriod`,label:`快线`,type:`number`,min:2,max:100,step:1,default:12,description:`快线周期,对价格变化更敏感`},{key:`slowPeriod`,label:`慢线`,type:`number`,min:2,max:200,step:1,default:50,description:`慢线周期,用于判断趋势方向`}]},{id:`ENE`,label:`ENE`,name:`轨道线`,pane:`main`,description:`ENE 轨道线由三条轨道组成,价格突破上轨可能超买,突破下轨可能超卖,适合判断震荡行情的买卖点。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:10,description:`计算中轨的周期数`},{key:`deviation`,label:`偏离率`,type:`number`,min:1,max:30,step:.5,default:11,description:`轨道偏离率百分比,决定轨道宽度`}]},{id:`MACD`,label:`MACD`,name:`指数平滑异同移动平均线`,pane:`sub`,description:`MACD 通过快慢均线的交叉判断趋势方向和动量。DIF 上穿 DEA 为金叉看涨,下穿为死叉看跌。`,params:[{key:`fastPeriod`,label:`快线`,type:`number`,min:2,max:50,step:1,default:12,description:`快线 EMA 周期,对价格变化更敏感`},{key:`slowPeriod`,label:`慢线`,type:`number`,min:2,max:100,step:1,default:26,description:`慢线 EMA 周期,用于计算 DIF`},{key:`signalPeriod`,label:`信号`,type:`number`,min:2,max:50,step:1,default:9,description:`DEA 的 EMA 周期,用于生成买卖信号`}]},{id:`RSI`,label:`RSI`,name:`相对强弱指标`,pane:`sub`,description:`RSI 衡量价格变动的速度和幅度,判断超买超卖状态。RSI > 70 超买,RSI < 30 超卖。`,params:[{key:`period1`,label:`周期 1`,type:`number`,min:2,max:100,step:1,default:6,description:`第一条 RSI 周期,通常为 6(快线)`},{key:`period2`,label:`周期 2`,type:`number`,min:2,max:100,step:1,default:12,description:`第二条 RSI 周期,通常为 12(中线)`},{key:`period3`,label:`周期 3`,type:`number`,min:2,max:100,step:1,default:24,description:`第三条 RSI 周期,通常为 24(慢线)`}]},{id:`CCI`,label:`CCI`,name:`顺势指标`,pane:`sub`,description:`CCI 衡量价格与统计平均值的偏离程度。CCI > 100 超买,CCI < -100 超卖,适合捕捉趋势反转。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:14,description:`计算周期,周期越短信号越灵敏`}]},{id:`STOCH`,label:`STOCH`,name:`随机指标`,pane:`sub`,description:`KDJ 随机指标通过比较收盘价与价格区间判断超买超卖。K > 80 超买,K < 20 超卖,K 上穿 D 金叉。`,params:[{key:`n`,label:`K 周期`,type:`number`,min:2,max:100,step:1,default:9,description:`计算 K 值的周期,统计 N 日内价格区间`},{key:`m`,label:`D 周期`,type:`number`,min:1,max:50,step:1,default:3,description:`D 值是 K 的 M 日移动平均,使信号更平滑`}]},{id:`MOM`,label:`MOM`,name:`动量指标`,pane:`sub`,description:`动量指标衡量价格变化的速度,MOM > 0 表示上涨动能,MOM < 0 表示下跌动能。适合判断趋势强度。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:10,description:`与多少日前价格比较,周期越短越灵敏`}]},{id:`WMSR`,label:`WMSR`,name:`威廉指标`,pane:`sub`,description:`威廉指标衡量超买超卖程度,范围为 -100 到 0。WMSR > -20 超买,WMSR < -80 超卖。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:14,description:`回溯周期,统计周期内最高最低价`}]},{id:`KST`,label:`KST`,name:`确然指标`,pane:`sub`,description:`KST 综合多个 ROC 判断长期趋势,KST 上穿信号线看涨,下穿看跌。适合捕捉主要趋势转换。`,params:[{key:`roc1`,label:`ROC1`,type:`number`,min:2,max:100,step:1,default:10,description:`短期变化率周期`},{key:`roc2`,label:`ROC2`,type:`number`,min:2,max:100,step:1,default:15,description:`中短期变化率周期`},{key:`roc3`,label:`ROC3`,type:`number`,min:2,max:100,step:1,default:20,description:`中长期变化率周期`},{key:`roc4`,label:`ROC4`,type:`number`,min:2,max:100,step:1,default:30,description:`长期变化率周期`},{key:`signalPeriod`,label:`信号`,type:`number`,min:2,max:50,step:1,default:9,description:`信号线的 SMA 周期`}]},{id:`FASTK`,label:`FASTK`,name:`快速随机指标`,pane:`sub`,description:`FASTK 是未经过平滑处理的随机指标,比普通 KDJ 更敏感,能更快捕捉价格转折点,但假信号也更多。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:9,description:`计算周期,周期越短越敏感`}]}],i=r.filter(e=>e.pane===`main`),a=r.filter(e=>e.pane===`sub`),o=t,s=n,c=(0,e.ref)(null),l=(0,e.ref)(null),u=(0,e.ref)(!1),d=(0,e.ref)(null),f=(0,e.ref)(null),p=(0,e.ref)(!1),m=(0,e.ref)({left:`0`,bottom:`0`}),h=(0,e.ref)(!1),g=(0,e.ref)(null),_=(0,e.ref)(null),v=Gt(),y=(0,e.computed)(()=>o.activeIndicators?.length?o.activeIndicators.map(e=>r.find(t=>t.id===e)).filter(e=>e!==void 0).sort((e,t)=>e.pane===t.pane?0:e.pane===`main`?-1:1):[]),b=(0,e.computed)(()=>y.value.some(e=>e.pane===`main`)?y.value.find(e=>e.pane===`sub`)?.id??null:null),x=(0,e.computed)(()=>d.value&&r.find(e=>e.id===d.value)||null);function S(e){return o.activeIndicators?.includes(e)??!1}function C(e){if(S(e))return;let t=r.find(t=>t.id===e);t&&(t.pane===`main`&&r.filter(t=>t.pane===`main`&&t.id!==e&&S(t.id)).forEach(e=>s(`toggle`,e.id,!1)),s(`toggle`,e,!0),p.value=!1)}function w(e){s(`toggle`,e,!1)}function T(e){d.value=e,u.value=!0}function E(e){let t=r.find(t=>t.id===e);if(!t?.params)return{};let n={};for(let e of t.params)n[e.key]=e.default??e.min??1;let i=o.indicatorParams?.[e]||{},a={...n};for(let[e,t]of Object.entries(i))typeof t==`number`&&(a[e]=t);return a}function D(e){let t=E(e.id);return e.params?e.params.map(e=>t[e.key]??``).join(`,`):``}function O(e){d.value&&s(`updateParams`,d.value,e),u.value=!1}function k(e){return r.find(t=>t.id===e)?.pane===`sub`}function A(e,t){if(!k(t)){e.preventDefault();return}_.value=t,g.value=null,e.dataTransfer?.setData(`text/plain`,t),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`)}function j(e,t){!_.value||!k(t)||_.value===t||(g.value=t,e.dataTransfer&&(e.dataTransfer.dropEffect=`move`))}function M(e,t){let n=_.value||e.dataTransfer?.getData(`text/plain`)||``;if(!n||n===t){N();return}if(!k(n)||!k(t)){N();return}let r=y.value.findIndex(e=>e.id===n),i=y.value.findIndex(e=>e.id===t);if(r<0||i<0){N();return}let a=[...y.value.map(e=>e.id)],[o]=a.splice(r,1);if(!o){N();return}a.splice(i,0,o),s(`reorderSubIndicators`,a.filter(e=>k(e))),N()}function N(){g.value=null,_.value=null}function P(){if(!p.value&&c.value&&!h.value){let e=c.value.getBoundingClientRect(),t=window.innerWidth,n=e.left+e.width/2;n+160>t-8&&(n=t-160-8),n-160<8&&(n=168),m.value={left:`${n}px`,bottom:`${window.innerHeight-e.top+8}px`}}p.value=!p.value}function F(e){let t=l.value&&!l.value.contains(e.target),n=c.value&&!c.value.contains(e.target);t&&n&&(p.value=!1)}function I(){p.value&&=!1}return(0,e.onMounted)(()=>{h.value=typeof CSS<`u`&&CSS.supports(`anchor-name: --kmap-anchor`)&&CSS.supports(`position-anchor: --kmap-anchor`),document.addEventListener(`click`,F),window.addEventListener(`resize`,I)}),(0,e.onUnmounted)(()=>{document.removeEventListener(`click`,F),window.removeEventListener(`resize`,I)}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,dn,[(0,e.createElementVNode)(`div`,fn,[(0,e.createElementVNode)(`div`,pn,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(y.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:t.id},[t.id===b.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,mn)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`indicator-item`,{draggable:k(t.id),"drag-over":g.value===t.id,"is-dragging":_.value===t.id}]),draggable:k(t.id),onDragstart:e=>A(e,t.id),onDragover:(0,e.withModifiers)(e=>j(e,t.id),[`prevent`]),onDrop:(0,e.withModifiers)(e=>M(e,t.id),[`prevent`]),onDragend:N},[(0,e.createElementVNode)(`div`,{class:`indicator-btn-wrapper`,onMouseenter:e=>f.value=t.id,onMouseleave:n[0]||=e=>f.value=null},[(0,e.createElementVNode)(`button`,{class:(0,e.normalizeClass)([`indicator-btn`,{active:!0,hovering:f.value===t.id}])},[(0,e.createElementVNode)(`span`,_n,[(0,e.createTextVNode)((0,e.toDisplayString)(t.label)+` `,1),t.params?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,vn,` (`+(0,e.toDisplayString)(D(t))+`) `,1)):(0,e.createCommentVNode)(``,!0)]),(0,e.createVNode)(e.Transition,{name:`fade`},{default:(0,e.withCtx)(()=>[f.value===t.id?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,yn,[t.params?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:0,class:`action-btn settings-btn`,onClick:(0,e.withModifiers)(e=>T(t.id),[`stop`]),title:`编辑参数`},[...n[2]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z`})],-1)]],8,bn)):(0,e.createCommentVNode)(``,!0),t.params?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,xn)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`button`,{class:`action-btn remove-btn`,onClick:(0,e.withModifiers)(e=>w(t.id),[`stop`]),title:`移除指标`},[...n[3]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})],-1)]],8,Sn)])):(0,e.createCommentVNode)(``,!0)]),_:2},1024)],2)],40,gn)],42,hn)],64))),128)),(0,e.createElementVNode)(`div`,Cn,[(0,e.createElementVNode)(`button`,{ref_key:`addBtnRef`,ref:c,class:`add-btn`,onClick:P,title:`添加指标`},[...n[4]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`})],-1)]],512)])])]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{to:(0,e.unref)(v)},[(0,e.createVNode)(e.Transition,{name:`slide`},{default:(0,e.withCtx)(()=>[p.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`add-menu`,{"use-anchor":h.value}]),ref_key:`addMenuRef`,ref:l,style:(0,e.normalizeStyle)(h.value?void 0:m.value)},[(0,e.createElementVNode)(`div`,wn,[n[6]||=(0,e.createElementVNode)(`div`,{class:`menu-title`},`主图指标`,-1),(0,e.createElementVNode)(`div`,Tn,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)((0,e.unref)(i),t=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:t.id,class:(0,e.normalizeClass)([`menu-item`,{disabled:S(t.id)}]),disabled:S(t.id),onClick:e=>C(t.id)},[(0,e.createTextVNode)((0,e.toDisplayString)(t.label)+` `,1),(0,e.createElementVNode)(`span`,Dn,` (`+(0,e.toDisplayString)(t.name)+`) `,1),S(t.id)?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,On,[...n[5]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})],-1)]])):(0,e.createCommentVNode)(``,!0)],10,En))),128))])]),(0,e.createElementVNode)(`div`,kn,[n[8]||=(0,e.createElementVNode)(`div`,{class:`menu-title`},`副图指标`,-1),(0,e.createElementVNode)(`div`,An,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)((0,e.unref)(a),t=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:t.id,class:(0,e.normalizeClass)([`menu-item`,{disabled:S(t.id)}]),disabled:S(t.id),onClick:e=>C(t.id)},[(0,e.createTextVNode)((0,e.toDisplayString)(t.label)+` `,1),(0,e.createElementVNode)(`span`,Mn,` (`+(0,e.toDisplayString)(t.name)+`) `,1),S(t.id)?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,Nn,[...n[7]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})],-1)]])):(0,e.createCommentVNode)(``,!0)],10,jn))),128))])])],6)):(0,e.createCommentVNode)(``,!0)]),_:1})],8,[`to`])),x.value?((0,e.openBlock)(),(0,e.createBlock)(un,{key:0,visible:u.value,"indicator-id":x.value.id,"indicator-name":x.value.name,"indicator-description":x.value.description,params:x.value.params||[],values:E(x.value.id),onClose:n[1]||=e=>u.value=!1,onConfirm:O},null,8,[`visible`,`indicator-id`,`indicator-name`,`indicator-description`,`params`,`values`])):(0,e.createCommentVNode)(``,!0)]))}}),[[`__scopeId`,`data-v-f3fbebbd`]]),Fn={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function In(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Fn,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 7h16m-10 4v6m4-6v6M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3`},null,-1)]])}var Ln=(0,e.markRaw)({name:`tabler-trash`,render:In}),Rn={class:`toolbar-item color-item`,title:`颜色`},zn=[`value`],Bn=[`value`],Vn=[`value`],Hn=Lt((0,e.defineComponent)({__name:`DrawingStyleToolbar`,props:{drawing:{}},emits:[`updateStyle`,`delete`],setup(t,{emit:n}){let r=n;function i(e){e.key===`Delete`&&(e.preventDefault(),r(`delete`))}(0,e.onMounted)(()=>document.addEventListener(`keydown`,i)),(0,e.onUnmounted)(()=>document.removeEventListener(`keydown`,i));function a(e){r(`updateStyle`,{stroke:e})}function o(e){r(`updateStyle`,{strokeWidth:e})}function s(e){r(`updateStyle`,{strokeStyle:e})}return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`drawing-style-toolbar`,onPointerdown:r[4]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[5]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[6]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`div`,Rn,[(0,e.createElementVNode)(`span`,{class:`color-swatch`,style:(0,e.normalizeStyle)({background:t.drawing.style.stroke??`#2962ff`})},null,4),(0,e.createElementVNode)(`input`,{type:`color`,class:`color-input`,value:t.drawing.style.stroke??`#2962ff`,onInput:r[0]||=e=>a(e.target.value)},null,40,zn)]),(0,e.createElementVNode)(`select`,{class:`toolbar-select`,value:t.drawing.style.strokeWidth??1,onChange:r[1]||=e=>o(Number(e.target.value)),title:`线宽`},[...r[7]||=[(0,e.createElementVNode)(`option`,{value:1},`1px`,-1),(0,e.createElementVNode)(`option`,{value:2},`2px`,-1),(0,e.createElementVNode)(`option`,{value:3},`3px`,-1),(0,e.createElementVNode)(`option`,{value:4},`4px`,-1)]],40,Bn),(0,e.createElementVNode)(`select`,{class:`toolbar-select`,value:t.drawing.style.strokeStyle??`solid`,onChange:r[2]||=e=>s(e.target.value),title:`线型`},[...r[8]||=[(0,e.createElementVNode)(`option`,{value:`solid`},`实线`,-1),(0,e.createElementVNode)(`option`,{value:`dashed`},`虚线`,-1),(0,e.createElementVNode)(`option`,{value:`dotted`},`点线`,-1)]],40,Vn),(0,e.createElementVNode)(`button`,{type:`button`,class:`toolbar-btn delete-btn`,title:`删除`,onClick:r[3]||=e=>n.$emit(`delete`)},[(0,e.createVNode)((0,e.unref)(Ln),{class:`delete-icon`,"aria-hidden":`true`})])],32))}}),[[`__scopeId`,`data-v-92699cb2`]]),Un=class{chart;isDragging=!1;dragMode=`none`;dragStartX=0;scrollStartX=0;applyPanScroll(e,t){let n=Math.max(0,e.scrollWidth-e.clientWidth),r=Math.min(Math.max(0,t),n),i=this.chart.getCurrentDpr();e.scrollLeft=Math.round(r*i)/i}dragStartY=0;activePaneIdOnDrag=null;activeSeparatorUpperPaneId=null;hoveredSeparatorUpperPaneId=null;hoveredRightAxisPaneId=null;isTouchSession=!1;activePointers=new Map;lastPinchDistance=0;pinchCenter={x:0,y:0};isPinching=!1;onPinchZoomCallback;crosshairPos=null;crosshairIndex=null;crosshairPrice=null;hoveredIndex=null;activePaneId=null;tooltipPos={x:0,y:0};tooltipSize={width:220,height:180};tooltipAnchorPlacement=`right-bottom`;useTooltipAnchorPositioning=!1;onInteractionChangeCallback;settings={};hoveredMarkerId=null;clickedMarkerId=null;hoveredMarkerData=null;clickedMarkerData=null;onMarkerHoverCallback;onMarkerClickCallback;hoveredCustomMarker=null;onCustomMarkerHoverCallback;onCustomMarkerClickCallback;kLinePositions=null;visibleRange=null;lastHoverRenderKey=``;kWidthPx=null;constructor(e){this.chart=e}setOnPinchZoom(e){this.onPinchZoomCallback=e}updateSettings(e){let t=this.settings.disableMainPaneVerticalScroll;this.settings={...e},!t&&this.settings.disableMainPaneVerticalScroll&&this.chart.resetPriceOffset(`main`)}getInteractionSnapshot(){return{crosshairPos:this.crosshairPos?{...this.crosshairPos}:null,crosshairIndex:this.crosshairIndex,crosshairPrice:this.crosshairPrice,hoveredIndex:this.hoveredIndex,activePaneId:this.activePaneId,tooltipPos:{...this.tooltipPos},tooltipAnchorPlacement:this.tooltipAnchorPlacement,hoveredMarkerData:this.hoveredMarkerData,hoveredCustomMarker:this.hoveredCustomMarker,isDragging:this.isDragging,isResizingPaneBoundary:this.dragMode===`resize-separator`,isHoveringPaneBoundary:this.hoveredSeparatorUpperPaneId!==null,hoveredPaneBoundaryId:this.hoveredSeparatorUpperPaneId,isHoveringRightAxis:this.hoveredRightAxisPaneId!==null}}setOnInteractionChange(e){this.onInteractionChangeCallback=e}notifyInteractionChange(){this.onInteractionChangeCallback?.(this.getInteractionSnapshot())}getHoverRenderKey(){let e=this.crosshairPos?Math.round(this.crosshairPos.x*this.chart.getCurrentDpr()):`n`,t=this.crosshairPos?Math.round(this.crosshairPos.y*this.chart.getCurrentDpr()):`n`;return[this.crosshairIndex??`n`,this.hoveredIndex??`n`,this.activePaneId??`n`,this.hoveredRightAxisPaneId??`n`,this.hoveredSeparatorUpperPaneId??`n`,this.hoveredMarkerId??`n`,this.hoveredCustomMarker?.id??`n`,e,t].join(`|`)}onPointerDown(e){if(this.isTouchSession=e.pointerType===`touch`,this.activePointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.activePointers.size===2&&this.isTouchSession){this.isPinching=!0,this.isDragging=!1,this.dragMode=`none`;let e=Array.from(this.activePointers.values()),t=e[0],n=e[1];this.lastPinchDistance=Math.hypot(n.x-t.x,n.y-t.y),this.pinchCenter={x:(t.x+n.x)/2,y:(t.y+n.y)/2};return}if(e.isPrimary===!1||this.isPinching||this.activePointers.size>1)return;let t=this.getPlotPointerLocation(e.clientX,e.clientY);if(!t)return;let{mouseX:n,mouseY:r}=t,i=this.chart.getCachedScrollLeft(),a=this.chart.getMarkerManager(),o=i+n,s=a.hitTest(o,r,3);if(s){this.clickedMarkerId=s.id,this.clickedMarkerData=s,this.onMarkerClickCallback&&this.onMarkerClickCallback(s);return}let c=this.hitTestPaneSeparator(r);if(c){this.isDragging=!0,this.dragMode=`resize-separator`,this.dragStartY=e.clientY,this.activeSeparatorUpperPaneId=c,this.hoveredSeparatorUpperPaneId=c,this.clearHover(),this.chart.scheduleDraw();return}let l=this.getPaneByY(r);this.isDragging=!0,this.dragMode=`pan`,this.updatePlotHoverFromPoint(e.clientX,e.clientY),this.dragStartX=e.clientX,this.dragStartY=e.clientY,this.scrollStartX=this.chart.getCachedScrollLeft(),this.activePaneIdOnDrag=l?.id||null,this.chart.scheduleDraw()}setTooltipSize(e){this.tooltipSize=e}setTooltipAnchorPositioning(e){this.useTooltipAnchorPositioning=e}onPointerUp(e){this.activePointers.delete(e.pointerId),this.isPinching&&this.activePointers.size<2&&(this.isPinching=!1,this.lastPinchDistance=0),e.isPrimary!==!1&&(this.isDragging=!1,this.dragMode=`none`,this.activePaneIdOnDrag=null,this.activeSeparatorUpperPaneId=null,this.notifyInteractionChange())}onPointerLeave(e){this.activePointers.delete(e.pointerId),this.activePointers.size<2&&(this.isPinching=!1,this.lastPinchDistance=0),e.isPrimary!==!1&&(this.isDragging=!1,this.dragMode=`none`,this.activePaneIdOnDrag=null,this.clearSeparatorState(),this.isTouchSession=!1,this.clearHover(),this.chart.scheduleDraw(),this.notifyInteractionChange())}onScroll(){this.kLinePositions=null,this.visibleRange=null,this.clearHover(),this.chart.scheduleDraw(),this.notifyInteractionChange()}onPointerMove(e){if(this.activePointers.has(e.pointerId)&&this.activePointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.isPinching&&this.activePointers.size===2){let e=Array.from(this.activePointers.values()),t=e[0],n=e[1],r=Math.hypot(n.x-t.x,n.y-t.y),i=r-this.lastPinchDistance;if(Math.abs(i)>10){let e=i>0?1:-1,a=(t.x+n.x)/2;this.onPinchZoomCallback?.(e,a),this.lastPinchDistance=r}return}if(!e.isPrimary)return;e.pointerType===`touch`&&(this.isTouchSession=!0);let t=this.chart.getDom().container;if(this.isDragging){if(this.dragMode===`resize-separator`){let t=e.clientY-this.dragStartY;t!==0&&this.activeSeparatorUpperPaneId&&this.chart.resizePaneBoundary(this.activeSeparatorUpperPaneId,t)&&(this.dragStartY=e.clientY);return}if(this.dragMode===`scale-price`){let t=e.clientY-this.dragStartY;t!==0&&this.activePaneIdOnDrag&&(this.chart.scalePrice(this.activePaneIdOnDrag,t),this.dragStartY=e.clientY);return}if(this.dragMode===`pan`){let n=this.dragStartX-e.clientX;this.applyPanScroll(t,this.scrollStartX+n);let r=e.clientY-this.dragStartY;this.dragStartY=e.clientY,r!==0&&this.activePaneIdOnDrag===`main`&&(this.settings.disableMainPaneVerticalScroll||this.chart.translatePrice(this.activePaneIdOnDrag,r))}return}let n=this.getPlotPointerLocation(e.clientX,e.clientY);if(!n)return;this.hoveredSeparatorUpperPaneId=this.hitTestPaneSeparator(n.mouseY),this.updatePlotHoverFromPoint(e.clientX,e.clientY);let r=this.getHoverRenderKey();r!==this.lastHoverRenderKey&&(this.lastHoverRenderKey=r,this.chart.scheduleDraw(B.Overlay)),this.notifyInteractionChange()}setKLinePositions(e,t,n){this.kLinePositions=e,this.visibleRange=t,n!==void 0&&(this.kWidthPx=n)}onRightAxisPointerDown(e){if(e.isPrimary===!1)return;this.isTouchSession=e.pointerType===`touch`;let t=this.getRightAxisPointerLocation(e.clientX,e.clientY);t&&this.beginScalePriceDrag(e.clientY,t.mouseY)&&(this.chart.scheduleDraw(),this.notifyInteractionChange())}onRightAxisPointerMove(e){if(!e.isPrimary)return;if(e.pointerType===`touch`&&(this.isTouchSession=!0),this.isDragging&&this.dragMode===`scale-price`){let t=e.clientY-this.dragStartY;t!==0&&this.activePaneIdOnDrag&&(this.chart.scalePrice(this.activePaneIdOnDrag,t),this.dragStartY=e.clientY);return}this.updateRightAxisHoverFromPoint(e.clientX,e.clientY);let t=this.getHoverRenderKey();t!==this.lastHoverRenderKey&&(this.lastHoverRenderKey=t,this.chart.scheduleDraw(B.Overlay)),this.notifyInteractionChange()}onRightAxisPointerUp(e){this.onPointerUp(e)}onRightAxisPointerLeave(e){e.isPrimary!==!1&&(this.isDragging&&this.dragMode===`scale-price`||(this.hoveredRightAxisPaneId=null,this.notifyInteractionChange()))}isDraggingState(){return this.isDragging}setOnMarkerHover(e){this.onMarkerHoverCallback=e}setOnMarkerClick(e){this.onMarkerClickCallback=e}setOnCustomMarkerHover(e){this.onCustomMarkerHoverCallback=e}setOnCustomMarkerClick(e){this.onCustomMarkerClickCallback=e}hitTestPaneSeparator(e){let t=this.chart.getPaneRenderers();if(t.length<2)return null;for(let n=0;n<t.length-1;n++){let r=t[n]?.getPane(),i=t[n+1]?.getPane();if(!r||!i)continue;let a=r.top+r.height;if(Math.abs(e-a)<=5)return r.id}return null}getPaneByY(e){return this.chart.getPaneRenderers().find(t=>{let n=t.getPane();return e>=n.top&&e<=n.top+n.height})?.getPane()||null}getPlotPointerLocation(e,t){let n=this.chart.getDom().container.getBoundingClientRect();return{mouseX:e-n.left,mouseY:t-n.top}}getRightAxisPointerLocation(e,t){let n=this.chart.getDom().rightAxisLayer.getBoundingClientRect();return{mouseX:e-n.left,mouseY:t-n.top}}beginScalePriceDrag(e,t){let n=this.getPaneByY(t);return!n||n.id===`main`&&this.settings.disableMainPaneVerticalScroll?!1:(this.isDragging=!0,this.dragMode=`scale-price`,this.dragStartY=e,this.activePaneIdOnDrag=n.id,this.hoveredRightAxisPaneId=n.id,this.hoveredSeparatorUpperPaneId=null,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=n.id,!0)}clearHover(){this.lastHoverRenderKey=``,this.hoveredRightAxisPaneId=null,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=null,this.hoveredMarkerId===null?this.hoveredMarkerData=null:(this.hoveredMarkerId=null,this.hoveredMarkerData=null,this.chart.getMarkerManager().setHover(null),this.onMarkerHoverCallback&&this.onMarkerHoverCallback(null)),this.hoveredCustomMarker!==null&&(this.hoveredCustomMarker=null,this.onCustomMarkerHoverCallback&&this.onCustomMarkerHoverCallback(null))}clearSeparatorState(){this.activeSeparatorUpperPaneId=null,this.hoveredSeparatorUpperPaneId=null,this.hoveredRightAxisPaneId=null}updateRightAxisHoverFromPoint(e,t){let n=this.getRightAxisPointerLocation(e,t);if(!n)return;let{mouseY:r}=n,i=this.chart.getViewport()?.plotHeight??Math.max(1,Math.round(this.chart.getDom().container.clientHeight));if(r<0||r>i){this.hoveredRightAxisPaneId=null;return}let a=this.getPaneByY(r);this.hoveredRightAxisPaneId=a?.id||null,this.hoveredSeparatorUpperPaneId=null,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=a?.id||null}updatePlotHoverFromPoint(e,t){let n=this.getPlotPointerLocation(e,t);if(!n)return;let{mouseX:r,mouseY:i}=n,a=this.chart.getDom().container,o=this.chart.getViewport(),s=o?.viewWidth??Math.max(1,Math.round(a.clientWidth)),c=o?.viewHeight??Math.max(1,Math.round(a.clientHeight)),l=o?.plotWidth??s,u=o?.plotHeight??c;if(r<0||i<0||r>l||i>u){this.clearHover();return}this.hoveredRightAxisPaneId=null;let d=this.chart.getCachedScrollLeft(),f=this.chart.getCurrentDpr(),p=this.hitTestPaneSeparator(i);if(this.hoveredSeparatorUpperPaneId=p,p){this.clearHover();return}let m=this.chart.getMarkerManager(),h=d+r,g=m.hitTest(h,i,3);if(g){this.hoveredMarkerId!==g.id&&(this.hoveredMarkerId=g.id,this.hoveredMarkerData=g,m.setHover(g.id),this.onMarkerHoverCallback&&this.onMarkerHoverCallback(g)),this.hoveredCustomMarker!==null&&(this.hoveredCustomMarker=null,this.onCustomMarkerHoverCallback&&this.onCustomMarkerHoverCallback(null)),this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null;return}else this.hoveredMarkerId!==null&&(this.hoveredMarkerId=null,this.hoveredMarkerData=null,m.setHover(null),this.onMarkerHoverCallback&&this.onMarkerHoverCallback(null));let _=m.hitTestCustomMarker(r,i);if(_){this.hoveredCustomMarker?.id!==_.id&&(this.hoveredCustomMarker=_,this.onCustomMarkerHoverCallback&&this.onCustomMarkerHoverCallback(_)),this.hoveredMarkerId!==null&&(this.hoveredMarkerId=null,this.hoveredMarkerData=null,m.setHover(null),this.onMarkerHoverCallback&&this.onMarkerHoverCallback(null)),this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null;return}else this.hoveredCustomMarker!==null&&(this.hoveredCustomMarker=null,this.onCustomMarkerHoverCallback&&this.onCustomMarkerHoverCallback(null));if(!this.kLinePositions||!this.visibleRange||!this.kWidthPx){this.clearHover();return}let v=this.kWidthPx/f,y=0,b=this.kLinePositions.length;for(;y<b;){let e=y+b>>1;this.kLinePositions[e]<h?y=e+1:b=e}let x=y;if(y>0&&y<this.kLinePositions.length){let e=this.kLinePositions[y-1]+v/2,t=this.kLinePositions[y]+v/2;Math.abs(h-e)<Math.abs(h-t)&&(x=y-1)}else y===this.kLinePositions.length&&this.kLinePositions.length>0&&(x=this.kLinePositions.length-1);let S=x+this.visibleRange.start,C=this.chart.getData(),w=this.getPaneByY(i);if(this.activePaneId=w?.id||null,S>=0&&S<(C?.length??0)){this.crosshairIndex=S;let e=this.kLinePositions[x],t=(Math.round(e*f)+(this.kWidthPx-1)/2)/f-d;if(this.crosshairPos={x:Math.min(Math.max(t,0),l),y:Math.min(Math.max(i,0),u)},w){let e=i-w.top;this.crosshairPrice=w.yAxis.yToPrice(e)}else this.crosshairPrice=null}else this.crosshairIndex=null,this.crosshairPos=null,this.crosshairPrice=null;let T=typeof this.crosshairIndex==`number`?C[this.crosshairIndex]:void 0;if(!T||!w||!w.capabilities.candleHitTest){this.hoveredIndex=null;return}let E=i-w.top,D=w.yAxis.priceToY(T.open),O=w.yAxis.priceToY(T.close),k=w.yAxis.priceToY(T.high),A=w.yAxis.priceToY(T.low),j=Math.min(D,O),M=Math.max(D,O),N=h-this.kLinePositions[x],P=v/2,F=Math.abs(M-j),I=F<8?(j+M)/2-8/2:j,ee=F<8?(j+M)/2+8/2:M,te=E>=I&&E<=ee&&N>=0&&N<=v,ne=Math.abs(N-P)<=3&&E>=Math.min(k,A)&&E<=Math.max(k,A);if(!te&&!ne){this.hoveredIndex=null;return}if(this.hoveredIndex=this.crosshairIndex,this.useTooltipAnchorPositioning){let e=this.tooltipSize.width,t=r+14+e+12>l;this.tooltipAnchorPlacement=t?`left-bottom`:`right-bottom`,this.tooltipPos={x:Math.min(Math.max(r,12),Math.max(12,l-12)),y:Math.min(Math.max(i,12),Math.max(12,u-12))};return}let re=this.tooltipSize.width,ie=this.tooltipSize.height,ae=r+14,oe=r-14-re,se=ae+re+12<=s?ae:oe,ce=i+14,le=Math.max(12,s-re-12),ue=Math.max(12,c-ie-12);this.tooltipPos={x:Math.min(Math.max(se,12),le),y:Math.min(Math.max(ce,12),ue)}}reset(){this.isDragging=!1,this.dragMode=`none`,this.dragStartX=0,this.dragStartY=0,this.scrollStartX=0,this.activePaneIdOnDrag=null,this.clearSeparatorState(),this.isTouchSession=!1,this.activePointers.clear(),this.isPinching=!1,this.lastPinchDistance=0,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=null,this.hoveredMarkerId=null,this.clickedMarkerId=null,this.hoveredMarkerData=null,this.clickedMarkerData=null,this.hoveredCustomMarker=null,this.kLinePositions=null,this.visibleRange=null,this.lastHoverRenderKey=``,this.kWidthPx=null}getCrosshairIndex(){return this.crosshairIndex}},Wn=`#version 300 es
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);var t=class{listeners=new Map;on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){let n=this.listeners.get(e);n&&n.delete(t)}emit(e,t){let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[EventBus] Error in handler for "${e}":`,t)}})}once(e,t){let n=r=>{this.off(e,n),t(r)};this.on(e,n)}clear(){this.listeners.clear()}listenerCount(e){return this.listeners.get(e)?.size??0}},n=class e extends Error{constructor(e){super(e),this.name=`HttpError`}static isHttpError(t){return t instanceof e}};async function r(e,t){let r=new URLSearchParams;if(t?.params)for(let[e,n]of Object.entries(t.params))n!==void 0&&n!==``&&r.set(e,String(n));let i=r.toString(),a=i?`${e}?${i}`:e,o=new AbortController,s=t?.timeout?setTimeout(()=>o.abort(),t.timeout):void 0;try{let e=await fetch(a,{signal:o.signal});if(!e.ok)throw new n(`HTTP ${e.status}: ${e.statusText}`);return{data:await e.json()}}catch(e){throw e instanceof n?e:e?.name===`AbortError`?new n(`请求超时`):new n(e?.message||`网络请求失败`)}finally{clearTimeout(s)}}function i(e){if(/^\d{8}$/.test(e))return`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`;if(/^\d{4}-\d{2}-\d{2}T/.test(e))return e.slice(0,10);if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString().slice(0,10)}function a(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)throw Error(`无法解析日期: ${e}`);let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return Date.UTC(n,r-1,i,-8,0,0,0)}function o(e){return e&&{daily:`d`,weekly:`w`,monthly:`m`,5:`5`,15:`15`,30:`30`,60:`60`}[e]||`d`}function s(e){return e&&{qfq:`2`,hfq:`1`,none:`3`}[e]||`3`}function c(e){let t=i(e.date),n=e=>{let t=parseFloat(e);return Number.isNaN(t)?0:t};return{timestamp:a(t),stockCode:e.code,open:n(e.open),high:n(e.high),low:n(e.low),close:n(e.close),volume:n(e.volume),turnover:n(e.amount),changePercent:n(e.pctChg),turnoverRate:n(e.turn)}}var l=``,u=`/api/stock/kdata`;async function d(){let e=await(await fetch(`mock-stock-data.json`)).json();if(e.success&&e.data)return e.data.map(c).sort((e,t)=>e.timestamp-t.timestamp);throw Error(`Mock data failed`)}async function f(e){if(typeof window<`u`&&window.location.hostname.includes(`github.io`))return d();let{timeout:t,...n}=e,i=`${l}${u}`,a={stock_code:n.symbol,start_date:n.start_date,end_date:n.end_date,frequency:o(n.period),adjustflag:s(n.adjust),timeout:t};try{let e=(await r(i,{params:a,timeout:t?t*1e3:void 0})).data;if(!e.success)throw Error(`获取K线数据失败: ${e.error_msg||`未知错误`} (code: ${e.error_code})`);return!e.data||e.data.length===0?[]:e.data.map(c).sort((e,t)=>e.timestamp-t.timestamp)}catch(e){try{return await d()}catch{}throw Error(`获取K线数据失败: ${e instanceof Error?e.message:String(e)}`)}}function p(e){return e.map(e=>({timestamp:e.timestamp,open:e.open,high:e.high,low:e.low,close:e.close,stockCode:e.stockCode,volume:e.volume,turnover:e.turnover,amplitude:e.amplitude,changePercent:e.changePercent,changeAmount:e.changeAmount,turnoverRate:e.turnoverRate})).sort((e,t)=>e.timestamp-t.timestamp)}var m=`/api/public/stock_zh_a_hist`;function h(e){if(/^\d{8}$/.test(e))return`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`;if(/^\d{4}-\d{2}-\d{2}T/.test(e))return e.slice(0,10);if(/^\d{4}-\d{2}-\d{2}$/.test(e))return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString().slice(0,10)}function g(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)throw Error(`无法解析日期: ${e}`);let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return Date.UTC(n,r-1,i,-8,0,0,0)}function _(e){return{timestamp:g(h(e.日期)),stockCode:e.股票代码,open:e.开盘,close:e.收盘,high:e.最高,low:e.最低,volume:e.成交量,turnover:e.成交额,amplitude:e.振幅,changePercent:e.涨跌幅,changeAmount:e.涨跌额,turnoverRate:e.换手率}}async function v(e){try{let{timeout:t,...n}=e;return(await r(m,{params:n,timeout:t?t*1e3:void 0})).data.map(_)}catch(e){throw Error(`获取K线数据失败: ${e instanceof Error?e.message:String(e)}`)}}var y=new class{set(e,t){let n={data:t,timestamp:Date.now()};localStorage.setItem(e,JSON.stringify(n))}get(e,t=3600*1e3){let n=localStorage.getItem(e);if(!n)return null;try{let r=JSON.parse(n);return Date.now()-r.timestamp>t?(localStorage.removeItem(e),null):r.data}catch{return localStorage.removeItem(e),null}}remove(e){localStorage.removeItem(e)}clear(){localStorage.clear()}generateKey(e,t){return`${e}:${Object.keys(t).sort().map(e=>`${e}:${t[e]}`).join(`|`)}`}},b=class{name=`baostock`;async fetchKLineData(e){return f({symbol:this.addMarketPrefix(e.symbol),start_date:e.startDate,end_date:e.endDate,period:{daily:`daily`,weekly:`weekly`,monthly:`monthly`,"5min":`5`,"15min":`15`,"30min":`30`,"60min":`60`}[e.period]||`daily`,adjust:e.adjust,timeout:e.timeout})}addMarketPrefix(e){return/^(6|68)\d{5}$/.test(e)?`sh.${e}`:/^(0|3)\d{5}$/.test(e)?`sz.${e}`:e}},x=class{name=`dongcai`;async fetchKLineData(e){let t=e.startDate.replace(/-/g,``),n=e.endDate.replace(/-/g,``),r={daily:`daily`,weekly:`weekly`,monthly:`monthly`}[e.period];if(!r)throw Error(`东财数据源不支持周期: ${e.period}`);return p(await v({symbol:e.symbol,start_date:t,end_date:n,period:r,adjust:e.adjust===`none`?void 0:e.adjust,timeout:e.timeout}))}},S=class{static instances=new Map;static create(e){if(!this.instances.has(e))switch(e){case`baostock`:this.instances.set(e,new b);break;case`dongcai`:this.instances.set(e,new x);break;default:throw Error(`未知的数据源类型: ${e}`)}return this.instances.get(e)}},C=3600*1e3;function w(e,t){return y.generateKey(`kline:${e}`,{symbol:t.symbol,startDate:t.startDate,endDate:t.endDate,period:t.period,adjust:t.adjust})}async function T(e,t,n=!0){if(typeof window<`u`&&window.location.hostname.includes(`github.io`))return console.log(`[KLine] GitHub Pages 模式,加载 mock 数据`),d();let r=w(e,t);if(n){let e=y.get(r,C);if(e)return console.log(`[KLineCache] 命中缓存: ${r}`),e}try{let i=await S.create(e).fetchKLineData(t);return n&&i.length>0&&(y.set(r,i),console.log(`[KLineCache] 写入缓存: ${r}, ${i.length} 条数据`)),i}catch(e){let t=y.get(r,2**53-1);if(t)return console.warn(`[KLineCache] 网络请求失败,使用缓存回退: ${r}`,e),t;throw e}}var E=[`__proto__`,`constructor`,`prototype`],D=/^(#[0-9a-fA-F]{3,8}|rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)|rgba\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*[\d.]+\s*\))$/,O={SH:/^(600|601|603|605|688)\d{3}$/,SZ:/^(000|001|002|003|300|301)\d{3}$/,BJ:/^(83|87|43|82)\d{4}$/};function k(e){return{"5min":30,"15min":60,"30min":90,"60min":180,daily:365*3,weekly:365*5,monthly:365*10}[e]??365}var A=(typeof document<`u`?document.createElement(`canvas`):null)?.getContext(`2d`)??null,j=class e{limits;_ajv=null;constructor(){this.limits={maxJsonSize:64*1024,maxIndicators:10,maxCustomMarkers:100}}async getAjv(){return this._ajv||=(async()=>{let e=(await import(`ajv`)).default,t=new e({allErrors:!0,allowUnionTypes:!0});t.addFormat(`date`,{type:`string`,validate:e=>/^\d{4}-\d{2}-\d{2}$/.test(e)});let n=await Promise.resolve().then(()=>require(`./schema-CzmPW09E.cjs`));return t.addSchema(n.default||n),t})(),this._ajv}validateRawInput(e){return(typeof TextEncoder<`u`?new TextEncoder().encode(e).byteLength:e.length*3)>this.limits.maxJsonSize?{valid:!1,errors:[`JSON payload too large (max 64KB)`]}:{valid:!0}}async validate(e){if(!e||typeof e!=`object`)return{valid:!1,errors:[`Config must be an object`]};let t=this.checkPrototypePollution(e);if(!t.valid)return t;try{let t=await this.getAjv();if(!t.validate(`https://kmap.dev/schemas/semantic-chart-config/1.0.0`,e))return{valid:!1,errors:t.errors?.map(e=>`${e.instancePath} ${e.message}`)||[`Schema validation failed`]}}catch{return{valid:!1,errors:[`Schema validation unavailable (ajv not loaded)`]}}return{valid:!0}}securityCheck(e){let t=[],n=this.checkDateRange(e.data);n.valid||t.push(...n.errors||[]);let r=this.checkSymbol(e.data);if(r.valid||t.push(...r.errors||[]),e.indicators&&(e.indicators.main?.length||0)+(e.indicators.sub?.length||0)>this.limits.maxIndicators&&t.push(`Too many indicators (max ${this.limits.maxIndicators})`),(e.markers?.customMarkers?.length||0)>this.limits.maxCustomMarkers&&t.push(`Too many custom markers (max ${this.limits.maxCustomMarkers})`),e.markers?.customMarkers)for(let n of e.markers.customMarkers){if(n.style){let e=this.checkMarkerStyle(n.style,n.id);t.push(...e)}let e=this.checkMarkerDate(n.date,n.id);t.push(...e)}return{passed:t.length===0,violations:t.length>0?t:void 0}}checkPrototypePollution(e,t=``){if(!e||typeof e!=`object`)return{valid:!0};let n=[];for(let r of Object.keys(e))E.includes(r)&&n.push(`Forbidden key "${r}" found at ${t}`);return n.length>0?{valid:!1,errors:n}:{valid:!0}}checkDateRange(e){let t=[],n=new Date(e.startDate),r=new Date(e.endDate);if(isNaN(n.getTime())&&t.push(`Invalid startDate: ${e.startDate}`),isNaN(r.getTime())&&t.push(`Invalid endDate: ${e.endDate}`),t.length>0)return{valid:!1,errors:t};let i=k(e.period),a=Math.ceil((r.getTime()-n.getTime())/(1e3*60*60*24));return a>i&&t.push(`Date range exceeds maximum for period "${e.period}" (max ${i} days, got ${a})`),a<0&&t.push(`endDate must be after startDate`),t.length>0?{valid:!1,errors:t}:{valid:!0}}checkSymbol(e){let{symbol:t,exchange:n}=e;if(n){if(!O[n].test(t))return{valid:!1,errors:[`Invalid symbol "${t}" for exchange "${n}"`]}}else if(!Object.values(O).some(e=>e.test(t)))return{valid:!1,errors:[`Invalid symbol format: "${t}"`]};return{valid:!0}}checkMarkerStyle(e,t){let n=[],r=[`fillColor`,`strokeColor`,`textColor`];for(let i of r){let r=e[i];typeof r==`string`&&!D.test(r)&&n.push(`Invalid ${i} in marker "${t}": ${r}`)}if(A)for(let i of r){let r=e[i];typeof r==`string`&&(A.fillStyle=`#000000`,A.fillStyle=r,A.fillStyle===`#000000`&&r!==`#000000`&&!r.startsWith(`#000`)&&n.push(`Potentially unsafe ${i} in marker "${t}": ${r}`))}return n}static DATE_PATTERN=/^\d{4}-\d{2}-\d{2}( \d{2}:\d{2})?$/;checkMarkerDate(t,n){let r=[];if(!e.DATE_PATTERN.test(t))return r.push(`Invalid date format in marker "${n}": ${t} (expected YYYY-MM-DD or YYYY-MM-DD HH:mm)`),r;let i=t.includes(` `),a;if(i)a=new Date(t);else{let[e,n,r]=t.split(`-`).map(Number);a=new Date(Date.UTC(e,n-1,r))}return isNaN(a.getTime())&&r.push(`Invalid date value in marker "${n}": ${t}`),r}},M=class{chart;validator;events;constructor(e){this.chart=e,this.validator=new j,this.events=new t}async applyConfig(e){let t=await this.validator.validate(e);if(!t.valid)return{success:!1,errors:t.errors};let n=this.validator.securityCheck(e);if(!n.passed)return{success:!1,errors:n.violations};this.events.emit(`config:loading`,void 0);try{return await this.doApplyConfig(e),this.events.emit(`config:ready`,void 0),{success:!0}}catch(e){return this.events.emit(`config:error`,e),{success:!1,errors:[e instanceof Error?e.message:String(e)]}}}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}async doApplyConfig(e){console.log(`[Semantic] doApplyConfig start, data config:`,e.data);let t=await T(e.data.source,{symbol:e.data.symbol,startDate:e.data.startDate,endDate:e.data.endDate,period:e.data.period,adjust:e.data.adjust});console.log(`[Semantic] fetched data:`,t.length,`items`),this.chart.updateData(t),e.indicators&&(console.log(`[Semantic] applying indicators:`,e.indicators),this.applyIndicators(e.indicators.main,e.indicators.sub)),e.markers&&(console.log(`[Semantic] applying markers:`,e.markers.customMarkers?.length,`markers`),this.applyMarkers(e.markers.customMarkers,e.data.period)),e.chart&&this.applyChartOptions(e.chart),console.log(`[Semantic] doApplyConfig done`)}applyIndicators(e,t){if(e){for(let t of e)if(t.enabled)switch(t.type){case`MA`:this.applyMAIndicator(t);break;case`BOLL`:this.applyBOLLIndicator(t);break;case`EXPMA`:this.applyEXPMAIndicator(t);break;case`ENE`:this.applyENEIndicator(t);break}}if(this.chart.clearSubPanes(),t)for(let e of t)this.applySubIndicator(e)}applyMAIndicator(e){let t=e.params?.periods||[5,10,20,30,60],n={};for(let e of t)e===5?n.ma5=!0:e===10?n.ma10=!0:e===20?n.ma20=!0:e===30?n.ma30=!0:e===60&&(n.ma60=!0);console.log(`[Semantic] applyMAIndicator, periods:`,t,`maFlags:`,n),this.chart.updateRendererConfig(`ma`,n)}applyBOLLIndicator(e){let t={period:e.params?.period||20,multiplier:e.params?.multiplier||2};this.chart.updateRendererConfig(`boll`,t)}applyEXPMAIndicator(e){let t={fastPeriod:e.params?.fastPeriod||12,slowPeriod:e.params?.slowPeriod||50};this.chart.updateRendererConfig(`expma`,t)}applyENEIndicator(e){let t={period:e.params?.period||10,deviation:e.params?.deviation||11};this.chart.updateRendererConfig(`ene`,t)}applySubIndicator(e){if(!e.enabled)return;let{type:t,params:n}=e,r=`${t}_0`;this.chart.createSubPane(r,t,n)||console.warn(`[Semantic] Failed to create sub pane for ${t}`)}applyMarkers(e,t){if(!e||e.length===0){this.chart.clearCustomMarkers();return}let n=e.map(e=>({id:e.id,date:e.date,timestamp:N(e.date,t||`daily`),shape:e.shape,groupKey:e.groupKey,offset:e.offset,style:e.style,label:e.label,metadata:e.metadata}));this.chart.updateCustomMarkers(n)}applyChartOptions(e){e.autoScrollToRight}};function N(e,t){if(e.includes(` `)){let[t,n]=e.split(` `),r=t.split(`-`).map(Number),i=r[0],a=r[1],o=r[2],s=n.split(`:`).map(Number),c=s[0],l=s[1];return Date.UTC(i,a-1,o,c-8,l,0,0)}else{let t=e.split(`-`).map(Number),n=t[0],r=t[1],i=t[2];return Date.UTC(n,r-1,i,-8,0,0,0)}}var P={arrow_up:16,arrow_down:16,flag:14,circle:12,rectangle:14,diamond:12};function F(e,t,n,r,i,a){let o=a.fillColor||`#000000`,s=a.strokeColor||o,c=i||P[t];switch(e.fillStyle=o,e.strokeStyle=s,e.lineWidth=a.lineWidth||1,a.opacity!==void 0&&(e.globalAlpha=a.opacity),t){case`arrow_up`:ne(e,n,r,c);break;case`arrow_down`:re(e,n,r,c);break;case`circle`:ie(e,n,r,c);break;case`rectangle`:ae(e,n,r,c);break;case`diamond`:oe(e,n,r,c);break;case`flag`:se(e,n,r,c);break}e.globalAlpha=1}var I=2.5,L=4;function ee(e,t,n,r,i,a,o=!1){let s=t.fontSize||12,c=a.textColor||`#333333`,l=i/2;e.font=`${s}px sans-serif`,e.fillStyle=c,e.textBaseline=`middle`;let u=i*I,d=te(e,t.text,u),f=e.measureText(d).width,p=n,m=r;switch(t.position){case`left`:p=n-l-f/2-L;break;case`right`:p=n+l+f/2+L;break;case`top`:m=r-l-s/2-L;break;case`bottom`:m=r+l+s/2+L;break;default:m=o?r-l-s/2-L:r+l+s/2+L;break}t.offset&&(p+=t.offset.x||0,m+=t.offset.y||0),e.textAlign=t.align||`center`,e.fillText(d,p,m)}function te(e,t,n){if(e.measureText(t).width<=n)return t;let r=e.measureText(`…`).width,i=0,a=t.length;for(;i<a;){let o=Math.ceil((i+a)/2),s=t.slice(0,o);e.measureText(s).width+r<=n?i=o:a=o-1}return t.slice(0,i)+`…`}function ne(e,t,n,r){e.beginPath(),e.moveTo(t,n-r/2),e.lineTo(t-r/2,n+r/2),e.lineTo(t+r/2,n+r/2),e.closePath(),e.fill()}function re(e,t,n,r){e.beginPath(),e.moveTo(t,n+r/2),e.lineTo(t-r/2,n-r/2),e.lineTo(t+r/2,n-r/2),e.closePath(),e.fill()}function ie(e,t,n,r){e.beginPath(),e.arc(t,n,r/2,0,Math.PI*2),e.fill()}function ae(e,t,n,r){e.fillRect(t-r/2,n-r/2,r,r)}function oe(e,t,n,r){e.beginPath(),e.moveTo(t,n-r/2),e.lineTo(t+r/2,n),e.lineTo(t,n+r/2),e.lineTo(t-r/2,n),e.closePath(),e.fill()}function se(e,t,n,r){e.beginPath(),e.moveTo(t-r/4,n+r/2),e.lineTo(t-r/4,n-r/2),e.stroke(),e.beginPath(),e.moveTo(t-r/4,n-r/2),e.lineTo(t+r/2,n-r/4),e.lineTo(t-r/4,n),e.closePath(),e.fill()}function ce(e,t,n,r,i,a){let o=a/2;switch(n){case`circle`:let n=e-r,a=t-i;return n*n+a*a<=o*o;default:return e>=r-o&&e<=r+o&&t>=i-o&&t<=i+o}}var le=function(e){return e.Registered=`registered`,e.Installed=`installed`,e.Error=`error`,e}({});function ue(e){return{id:e.id,role:e.role,capabilities:{...e.capabilities},top:e.top,height:e.height,yAxis:{priceToY:t=>e.yAxis.priceToY(t),yToPrice:t=>e.yAxis.yToPrice(t),getPaddingTop:()=>e.yAxis.getPaddingTop(),getPaddingBottom:()=>e.yAxis.getPaddingBottom(),getPriceOffset:()=>e.yAxis.getPriceOffset(),getDisplayRange:t=>e.yAxis.getDisplayRange(t),getScaleType:()=>e.yAxis.getScaleType()},priceRange:e.priceRange}}var de=Symbol(`global-pane`),R={LAST_PRICE_LABEL:-25,SYSTEM_YAXIS:-20,SYSTEM_XAXIS:-20,BACKGROUND:0,GRID:10,INDICATOR:30,MAIN:50,INDICATOR_SCALE:55,OVERLAY:80,FOREGROUND:100,SYSTEM_BORDER:120,SYSTEM_CROSSHAIR:150},fe=class{plugins=new Map;register(e,t){if(this.plugins.has(e.name))throw Error(`Plugin "${e.name}" is already registered`);let n={plugin:e,config:{enabled:!0,priority:0,...t},state:`registered`};return this.plugins.set(e.name,n),n}unregister(e){return this.plugins.delete(e)}get(e){return this.plugins.get(e)}getPlugin(e){return this.plugins.get(e)?.plugin}getAll(){return Array.from(this.plugins.values())}getEnabled(){return this.getAll().filter(e=>e.config?.enabled!==!1)}updateState(e,t,n){let r=this.plugins.get(e);r&&(r.state=t,n&&(r.error=n))}has(e){return this.plugins.has(e)}clear(){this.plugins.clear()}},pe=class{hooks=new Map;tap(e,t,n=0){this.hooks.has(e)||this.hooks.set(e,[]);let r=this.hooks.get(e);r.push({name:e,fn:t,priority:n}),r.sort((e,t)=>e.priority-t.priority)}untap(e,t){let n=this.hooks.get(e);if(n){let e=n.findIndex(e=>e.fn===t);e!==-1&&n.splice(e,1)}}async call(e,t,n){let r=this.hooks.get(e);if(!r||r.length===0)return[];let i=[];for(let{fn:a}of r)try{let e=await a(t);i.push(e)}catch(t){if(console.error(`[HookSystem] Error in hook "${e}":`,t),n?.throwOnError)throw t}return i}callSync(e,t,n){let r=this.hooks.get(e);if(!r||r.length===0)return[];let i=[];for(let{fn:a}of r)try{let e=a(t);i.push(e)}catch(t){if(console.error(`[HookSystem] Error in hook "${e}":`,t),n?.throwOnError)throw t}return i}clear(){this.hooks.clear()}hookCount(e){return this.hooks.get(e)?.length??0}},z=class{configs=new Map;defaults=new Map;registerDefaults(e,t){this.defaults.set(e,{...t}),this.configs.has(e)||this.configs.set(e,new Map);let n=this.configs.get(e);for(let[e,r]of Object.entries(t))n.has(e)||n.set(e,r)}get(e,t,n){let r=this.configs.get(e);if(r?.has(t))return r.get(t);let i=this.defaults.get(e);return i&&t in i?i[t]:n}set(e,t,n){this.configs.has(e)||this.configs.set(e,new Map),this.configs.get(e).set(t,n)}setAll(e,t){for(let[n,r]of Object.entries(t))this.set(e,n,r)}getAll(e){let t=this.configs.get(e);return{...this.defaults.get(e)||{},...t?Object.fromEntries(t):{}}}clear(e){e?(this.configs.delete(e),this.defaults.delete(e)):(this.configs.clear(),this.defaults.clear())}},me=class{states=new Map;ownerNamespaces=new Map;setState(e,t,n){this.states.set(e,t)}getState(e){return this.states.get(e)}clearState(e){this.states.delete(e)}registerStateOwner(e,t){this.ownerNamespaces.set(e,new Set(t))}clearByOwner(e){let t=this.ownerNamespaces.get(e);t&&(t.forEach(e=>{this.states.delete(e)}),this.ownerNamespaces.delete(e))}clear(){this.states.clear(),this.ownerNamespaces.clear()}},he=class{registry;eventBus;hookSystem;configManager;stateStore;isDestroyed=!1;logger;constructor(e){this.registry=new fe,this.eventBus=new t,this.hookSystem=new pe,this.configManager=new z,this.stateStore=new me,this.logger=e??console}events={on:(e,t)=>{this.eventBus.on(e,t)},off:(e,t)=>{this.eventBus.off(e,t)},emit:(e,t)=>{this.eventBus.emit(e,t)},once:(e,t)=>{this.eventBus.once(e,t)}};hooks={tap:(e,t,n=0)=>{this.hookSystem.tap(e,t,n)},untap:(e,t)=>{this.hookSystem.untap(e,t)},call:async(e,t,n)=>this.hookSystem.call(e,t,n),callSync:(e,t,n)=>this.hookSystem.callSync(e,t,n)};getConfig(e,t,n){return this.configManager.get(e,t,n)}setConfig(e,t,n){this.configManager.set(e,t,n)}getPlugin(e){return this.registry.getPlugin(e)}log(e,t,...n){let r=`[${new Date().toISOString()}] [${e.toUpperCase()}]`;this.logger[e](`${r} ${t}`,...n)}setSharedState(e,t,n){this.stateStore.setState(e,t,n)}getSharedState(e){return this.stateStore.getState(e)}clearSharedState(e){this.stateStore.clearState(e)}registerStateOwner(e,t){this.stateStore.registerStateOwner(e,t)}clearByOwner(e){this.stateStore.clearByOwner(e)}async use(e,t){if(this.ensureNotDestroyed(),this.registry.has(e.name))throw Error(`Plugin "${e.name}" is already installed`);try{let n=this.registry.register(e,t);t&&this.configManager.setAll(e.name,t),await this.hooks.call(`plugin:beforeInstall`,{plugin:e,config:t},{throwOnError:!0}),await e.install(this,n.config),this.registry.updateState(e.name,`installed`),await this.hooks.call(`plugin:afterInstall`,{plugin:e,config:t},{throwOnError:!0}),this.log(`info`,`Plugin "${e.name}" installed successfully`)}catch(t){throw this.registry.updateState(e.name,`error`,t instanceof Error?t:Error(String(t))),this.log(`error`,`Failed to install plugin "${e.name}":`,t),t}}async remove(e){this.ensureNotDestroyed();let t=this.registry.get(e);if(!t)throw Error(`Plugin "${e}" is not installed`);try{await this.hooks.call(`plugin:beforeUninstall`,{name:e},{throwOnError:!0}),t.plugin.uninstall&&await t.plugin.uninstall(),this.registry.unregister(e),this.configManager.clear(e),await this.hooks.call(`plugin:afterUninstall`,{name:e},{throwOnError:!0}),this.log(`info`,`Plugin "${e}" removed successfully`)}catch(t){throw this.log(`error`,`Failed to remove plugin "${e}":`,t),t}}getPlugins(){return this.registry.getAll()}getState(e){return this.registry.get(e)?.state}async destroy(){if(!this.isDestroyed){for(let e of this.registry.getAll())try{e.plugin.uninstall&&await e.plugin.uninstall()}catch(t){this.log(`error`,`Error uninstalling "${e.plugin.name}":`,t)}this.registry.clear(),this.eventBus.clear(),this.hookSystem.clear(),this.configManager.clear(),this.stateStore.clear(),this.isDestroyed=!0,this.log(`info`,`PluginHost destroyed`)}}ensureNotDestroyed(){if(this.isDestroyed)throw Error(`PluginHost has been destroyed`)}};function ge(e){return new he(e)}function _e(e,t){let n=Math.round(e*t);return n%2==0&&(n+=1),Math.max(1,n)}function B(e,t,n){let r=_e(e,n),i=Math.round(t*n),a=r+i,o=i;return{kWidthPx:r,kGapPx:i,unitPx:a,startXPx:o,kWidthLogical:r/n,kGapLogical:i/n,unitLogical:a/n,startXLogical:o/n}}function ve(e,t,n,r,i,a=1){let{unitPx:o,startXPx:s}=B(n,r,a),c=e*a,l=t*a;return{start:Math.max(0,Math.floor((c-s)/o)-1),end:Math.min(i,Math.ceil((c+l-s)/o)+1)}}function ye(e,t,n){let r=-1/0,i=1/0;for(let a=t;a<n&&a<e.length;a++){let t=e[a];t&&(t.high>r&&(r=t.high),t.low<i&&(i=t.low))}return!Number.isFinite(r)||!Number.isFinite(i)?{maxPrice:100,minPrice:0}:{maxPrice:r,minPrice:i}}var be={logicalOffset:4,coordOffset:1e-4};function xe(e){return Math.abs(e)<1e-15}function V(e,t){let n=Math.abs(e);if(xe(n))return 0;let r=Math.log10(n+t.coordOffset)+t.logicalOffset;return e<0?-r:r}function Se(e,t){let n=Math.abs(e);if(xe(n))return 0;let r=10**(n-t.logicalOffset)-t.coordOffset;return e<0?-r:r}function Ce(e){if(e===null)return{...be};let t=Math.abs(e.maxPrice-e.minPrice);if(t>=1||t<1e-15)return{...be};let n=Math.ceil(Math.abs(Math.log10(t))),r=be.logicalOffset+n;return{logicalOffset:r,coordOffset:1/10**r}}function we(e,t){return e.logicalOffset===t.logicalOffset&&e.coordOffset===t.coordOffset}var Te=class{range={maxPrice:100,minPrice:0};height=1;paddingTop=0;paddingBottom=0;priceOffset=0;verticalScale=1;scaleType=`linear`;logFormula=Ce(null);setRange(e){if(this.range=e,this.scaleType===`log`&&e.minPrice>0){let t=Ce(e);if(!we(t,this.logFormula)){let n=V(e.minPrice,this.logFormula),r=(V(e.maxPrice,this.logFormula)+n)/2+this.priceOffset;this.logFormula=t;let i=V(e.minPrice,this.logFormula),a=(V(e.maxPrice,this.logFormula)+i)/2;this.priceOffset=this.clampOffset(r-a)}}}setHeight(e){this.height=Math.max(1,e)}setPadding(e,t){this.paddingTop=Math.max(0,e),this.paddingBottom=Math.max(0,t)}getRange(){return this.range}getPaddingTop(){return this.paddingTop}getPaddingBottom(){return this.paddingBottom}setPriceOffset(e){this.priceOffset=this.clampOffset(e)}getPriceOffset(){return this.priceOffset}resetPriceOffset(){this.priceOffset=0}clampOffset(e){if(this.scaleType===`log`&&this.range.minPrice>0){let t=V(this.range.minPrice,this.logFormula),n=V(this.range.maxPrice,this.logFormula)-t;if(n<=0)return 0;let r=n*(1+1/this.verticalScale)/2;return Math.max(-r,Math.min(r,e))}let t=this.range.maxPrice-this.range.minPrice;if(t<=0)return 0;let n=t*(1+1/this.verticalScale)/2;return Math.max(-n,Math.min(n,e))}scaleByDelta(e){if(!Number.isFinite(e)||e===0)return;let t=Math.exp(-e*.01),n=this.verticalScale*t;this.verticalScale=Math.min(8,Math.max(.2,n)),this.priceOffset=this.clampOffset(this.priceOffset)}getVerticalScale(){return this.verticalScale}setScaleType(e){if(e!==this.scaleType){if(e===`log`&&this.range.minPrice>0){this.logFormula=Ce(this.range);let e=(this.range.maxPrice+this.range.minPrice)/2,t=e+this.priceOffset;this.priceOffset=V(t,this.logFormula)-V(e,this.logFormula),this.priceOffset=this.clampOffset(this.priceOffset)}else if(e===`linear`&&this.scaleType===`log`){let e=V(this.range.minPrice,this.logFormula),t=Se((V(this.range.maxPrice,this.logFormula)+e)/2+this.priceOffset,this.logFormula),n=(this.range.maxPrice+this.range.minPrice)/2;this.priceOffset=t-n,this.priceOffset=this.clampOffset(this.priceOffset)}this.scaleType=e}}getScaleType(){return this.scaleType}getDisplayRange(e){let{minPrice:t,maxPrice:n}=e??this.range;if(this.scaleType===`log`&&t>0){let e=V(t,this.logFormula),r=V(n,this.logFormula),i=r-e||1,a=(r+e)/2+this.priceOffset,o=i/(2*this.verticalScale);return{maxPrice:Se(a+o,this.logFormula),minPrice:Se(a-o,this.logFormula)}}let r=n-t||1,i=(n+t)/2+this.priceOffset,a=r/(2*this.verticalScale);return{maxPrice:i+a,minPrice:i-a}}priceToY(e){let{maxPrice:t,minPrice:n}=this.getDisplayRange(),r=Math.max(1,this.height-this.paddingTop-this.paddingBottom),i;if(this.scaleType===`log`&&n>0){let r=V(n,this.logFormula),a=V(t,this.logFormula);i=(V(e,this.logFormula)-r)/(a-r||1)}else i=(e-n)/(t-n||1);return this.paddingTop+r*(1-i)}yToPrice(e){let{maxPrice:t,minPrice:n}=this.getDisplayRange(),r=Math.max(1,this.height-this.paddingTop-this.paddingBottom),i=1-(e-this.paddingTop)/r;if(this.scaleType===`log`&&n>0){let e=V(n,this.logFormula);return Se(e+i*(V(t,this.logFormula)-e),this.logFormula)}return n+i*(t-n)}deltaYToPriceOffset(e){let t=Math.max(1,this.height-this.paddingTop-this.paddingBottom);if(this.scaleType===`log`&&this.range.minPrice>0){let n=V(this.range.minPrice,this.logFormula);return e*((V(this.range.maxPrice,this.logFormula)-n)/t)}return e*((this.range.maxPrice-this.range.minPrice||1)/t)}},H=function(e){return e.Main=`main`,e.Overlay=`overlay`,e.All=`all`,e}({});function Ee(e){return e===`price`?{showPriceAxisTicks:!0,showCrosshairPriceLabel:!0,candleHitTest:!0,supportsPriceTranslate:!0}:e===`indicator`?{showPriceAxisTicks:!1,showCrosshairPriceLabel:!0,candleHitTest:!1,supportsPriceTranslate:!0}:{showPriceAxisTicks:!1,showCrosshairPriceLabel:!1,candleHitTest:!1,supportsPriceTranslate:!1}}var De=class{id;role;capabilities;top=0;height=0;priceRange={maxPrice:100,minPrice:0};yAxis=new Te;renderers=[];constructor(e,t={}){this.id=e,this.role=t.role??(e===`main`?`price`:`indicator`),this.capabilities={...Ee(this.role),...t.capabilities??{}}}setLayout(e,t){this.top=e,this.height=Math.max(1,t),this.yAxis.setHeight(this.height)}setPadding(e,t){this.yAxis.setPadding(e,t)}addRenderer(e){this.renderers.push(e)}updateRange(e,t,n){this.priceRange=ye(e,t.start,t.end),n&&Number.isFinite(n.min)&&Number.isFinite(n.max)&&(this.priceRange.minPrice=Math.min(this.priceRange.minPrice,n.min),this.priceRange.maxPrice=Math.max(this.priceRange.maxPrice,n.max)),this.yAxis.setRange(this.priceRange)}},Oe=Symbol(`renderer:global-cache`),ke=class{plugins=new Map;pluginHost=null;enabledState=new Map;groupCache=new Map;mergedCache=new Map;knownPaneIds=new Set;cacheInvalid=!0;onInvalidate=null;setInvalidateCallback(e){this.onInvalidate=e}setPluginHost(e){this.pluginHost=e}addKnownPaneId(e){this.knownPaneIds.add(e),this.cacheInvalid=!0}removeKnownPaneId(e){this.knownPaneIds.delete(e),this.cacheInvalid=!0}setKnownPaneIds(e){this.knownPaneIds=new Set(e),this.cacheInvalid=!0}register(e){if(this.plugins.has(e.name)){console.warn(`Renderer plugin "${e.name}" already registered`);return}this.plugins.set(e.name,e),e.enabled!==void 0&&this.enabledState.set(e.name,e.enabled),this.cacheInvalid=!0;let t=e;if(t.onInstall&&this.pluginHost)try{t.onInstall(this.pluginHost)}catch(t){console.error(`[RendererPlugin] ${e.name} onInstall error:`,t)}let n=t.getDeclaredNamespaces?.();n&&this.pluginHost&&this.pluginHost.registerStateOwner(e.name,n),this.onInvalidate?.()}unregister(e){let t=this.plugins.get(e);if(t){if(t.getDeclaredNamespaces&&this.pluginHost?.clearByOwner(e),t.onUninstall)try{t.onUninstall()}catch(e){console.error(`[RendererPlugin] ${t.name} onUninstall error:`,e)}this.plugins.delete(e),this.enabledState.delete(e),this.cacheInvalid=!0,this.onInvalidate?.()}}clear(){for(let e of this.plugins.values())if(e.onUninstall)try{e.onUninstall()}catch(t){console.error(`[RendererPlugin] ${e.name} onUninstall error:`,t)}this.plugins.clear(),this.enabledState.clear(),this.groupCache.clear(),this.mergedCache.clear(),this.cacheInvalid=!1}mergeSorted(e,t){let n=[],r=0,i=0;for(;r<e.length&&i<t.length;)e[r].priority<=t[i].priority?n.push(e[r++]):n.push(t[i++]);return[...n,...e.slice(r),...t.slice(i)]}rebuildCache(){if(!this.cacheInvalid)return;this.groupCache.clear(),this.mergedCache.clear();for(let e of this.plugins.values()){let t=typeof e.paneId==`symbol`?Oe:e.paneId;this.groupCache.has(t)||this.groupCache.set(t,[]),this.groupCache.get(t).push(e)}for(let[,e]of this.groupCache)e.sort((e,t)=>e.priority-t.priority);let e=this.groupCache.get(Oe)??[];for(let t of this.knownPaneIds){let n=this.groupCache.get(t)??[],r=this.mergeSorted(n,e);this.mergedCache.set(t,r)}this.mergedCache.set(Oe,[...e]),this.cacheInvalid=!1}isRendererEnabled(e){let t=this.enabledState.get(e.name);return t===void 0?e.enabled!==!1:t}getMergedRenderers(e){this.rebuildCache();let t=this.mergedCache.get(e);if(!t){let n=this.groupCache.get(e)??[],r=this.groupCache.get(Oe)??[];t=this.mergeSorted(n,r),this.mergedCache.set(e,t)}return t}getRenderers(e){return this.getMergedRenderers(e).filter(e=>e.isSystem?!1:this.isRendererEnabled(e))}render(e,t,n){let r=this.getRenderers(e),i=[];for(let e of r){if(n){let t=e.layer??`main`;if(n===H.Overlay&&t!==`overlay`||n===H.Main&&t===`overlay`)continue}try{e.draw(t)}catch(n){let r=n instanceof Error?n:Error(String(n));console.error(`[RendererPlugin] ${e.name} draw error:`,r),i.push({name:e.name,error:{message:r.message,stack:r.stack},paneId:t.pane.id,timestamp:Date.now()})}}return i}renderPlugin(e,t){let n=this.plugins.get(e);if(!n||!this.isRendererEnabled(n))return[];let r=[];try{n.draw(t)}catch(n){let i=n instanceof Error?n:Error(String(n));console.error(`[RendererPlugin] ${e} draw error:`,i),r.push({name:e,error:{message:i.message,stack:i.stack},paneId:t.pane.id,timestamp:Date.now()})}return r}setEnabled(e,t){this.plugins.has(e)&&(this.enabledState.set(e,t),this.onInvalidate?.())}updateConfig(e,t){let n=this.plugins.get(e);return n?.setConfig?(n.setConfig(t),this.onInvalidate?.(),!0):!1}getAllPlugins(){return Array.from(this.plugins.values())}getPlugin(e){return this.plugins.get(e)}notifyDataUpdate(e,t){for(let n of this.plugins.values())if(n.onDataUpdate&&this.isRendererEnabled(n))try{n.onDataUpdate(e,t)}catch(e){console.error(`[RendererPlugin] ${n.name} onDataUpdate error:`,e)}}notifyResize(e,t){let n=this.getMergedRenderers(e).filter(e=>this.isRendererEnabled(e));for(let e of n)if(e.onResize)try{e.onResize(t)}catch(t){console.error(`[RendererPlugin] ${e.name} onResize error:`,t)}}},Ae={PRIMARY:`hsl(210, 9%, 31%)`,SECONDARY:`hsl(210, 9%, 35%)`,TERTIARY:`hsl(210, 8%, 50%)`,WEAK:`hsl(210, 7%, 65%)`,WHITE:`rgba(255, 255, 255, 0.92)`},U={UP:`rgba(214, 10, 34, 1)`,UP_LIGHT:`rgba(214, 10, 34, 0.92)`,UP_TICK:`hsl(0, 60%, 50%)`,DOWN:`rgba(3, 123, 102, 1)`,DOWN_LIGHT:`rgba(3, 123, 102, 0.92)`,DOWN_TICK:`hsl(150, 30%, 60%)`,NEUTRAL:`rgba(0, 0, 0, 0.78)`,LAST_PRICE:`rgba(196, 74, 86, 0.95)`},je={WHITE:`rgb(255, 255, 255)`,LIGHT_GRAY:`rgba(255, 255, 255, 0.92)`,PURE_WHITE:`#ffffff`,TRANSPARENT:`transparent`,ACTIVE:`#1890ff`,ACTIVE_HOVER:`#40a9ff`,HOVER:`#f0f0f0`},Me={DARK:`rgba(0, 0, 0, 0.12)`,MEDIUM:`rgba(0, 0, 0, 0.10)`,LIGHT:`rgba(0, 0, 0, 0.08)`,SEPARATOR:`rgba(0, 0, 0, 0.10)`,BUTTON:`#d0d0d0`},W={HORIZONTAL:`rgba(0, 0, 0, 0.06)`,VERTICAL:`rgba(0, 0, 0, 0.12)`},Ne={MA5:`rgba(255, 193, 37, 1)`,MA10:`rgba(190, 131, 12, 1)`,MA20:`rgba(69, 112, 249, 1)`,MA30:`rgba(76, 175, 80, 1)`,MA60:`rgba(156, 39, 176, 1)`},G={UPPER:`rgba(178, 34, 34, 1)`,MIDDLE:`rgba(69, 112, 249, 1)`,LOWER:`rgba(34, 139, 34, 1)`,BAND_FILL:`rgba(100, 149, 237, 0.1)`},K={DIF:`rgba(69, 112, 249, 1)`,DEA:`rgba(255, 152, 0, 1)`,BAR_UP:`#ff5252`,BAR_UP_LIGHT:`#fccbcd`,BAR_DOWN:`#22ab94`,BAR_DOWN_LIGHT:`#ace5dc`},Pe={UP:`#ff5252`,DOWN:`#22ab94`,NEUTRAL:`rgba(0, 0, 0, 0.78)`},q={RSI1:`rgba(69, 112, 249, 1)`,RSI2:`rgba(255, 152, 0, 1)`,RSI3:`rgba(156, 39, 176, 1)`},Fe={CCI:`rgba(69, 112, 249, 1)`,OVERBOUGHT:`rgba(214, 10, 34, 0.5)`,OVERSOLD:`rgba(3, 123, 102, 0.5)`},Ie={K:`rgba(69, 112, 249, 1)`,D:`rgba(255, 152, 0, 1)`,J:`rgba(156, 39, 176, 1)`},Le={MOM:`rgba(69, 112, 249, 1)`,ZERO:`rgba(0, 0, 0, 0.2)`},Re={WMSR:`rgba(69, 112, 249, 1)`,OVERBOUGHT:`rgba(214, 10, 34, 0.5)`,OVERSOLD:`rgba(3, 123, 102, 0.5)`},ze={KST:`rgba(69, 112, 249, 1)`,SIGNAL:`rgba(255, 152, 0, 1)`},Be={FAST:`rgba(255, 152, 0, 1)`,SLOW:`rgba(69, 112, 249, 1)`},J={UPPER:`rgba(214, 10, 34, 1)`,MIDDLE:`rgba(69, 112, 249, 1)`,LOWER:`rgba(3, 123, 102, 1)`,BAND_FILL:`rgba(69, 112, 249, 0.08)`},Ve={LINE:`rgba(0, 0, 0, 0.28)`,LABEL_BG:`rgb(0, 0, 0)`,LABEL_TEXT:`rgba(255, 255, 255, 0.92)`};function Y(e,t){return Math.round(e*t)/t}function X(e,t){return(Math.floor(e*t)+.5)/t}function He(e,t,n,r){if(t===n)return null;let i=Math.min(t,n),a=Math.max(t,n),o=Math.round(e*r),s=Math.round(i*r),c=Math.round(a*r);return{x:o/r,y:s/r,width:1/r,height:Math.max(1,c-s)/r}}function Ue(e,t,n,r){if(e===t)return null;let i=Math.min(e,t),a=Math.max(e,t),o=Math.round(i*r),s=Math.round(a*r),c=Math.round(n*r);return{x:o/r,y:c/r,width:Math.max(1,s-o)/r,height:1/r}}function We(e,t,n,r,i){let a=e+n,o=n,s=Math.round(t*i),c=Math.round((t+r)*i),l=Math.max(1,c-s),u=e+(n-1)/2,d=u,f=o%2==1;return{bodyRect:{x:e/i,y:s/i,width:n/i,height:l/i},physBodyLeft:e,physBodyRight:a,physBodyWidth:o,physBodyCenter:d,physWickX:u,wickRect:{x:u/i,width:1/i},isPerfectlyAligned:f}}var Ge=1.2,Ke=24,qe=6;function Je(e){switch(e){case`arrow_up`:case`flag`:return!0;default:return!1}}function Ye(){return{name:`customMarkers`,version:`1.0.0`,description:`自定义标记渲染器`,debugName:`自定义标记`,paneId:de,priority:R.OVERLAY,draw(e){let{ctx:t,pane:n,data:r,range:i,scrollLeft:a,kWidth:o,kLineCenters:s,dpr:c,markerManager:l,zoomLevel:u}=e;if(!l||(u??1)<2)return;let d=l.getCustomMarkers();if(!d||d.length===0)return;let f=r;if(f.length&&n.role===`price`){t.save(),t.translate(-a,0);for(let e of d){let r=Ze(f,e.timestamp);if(r===-1||r<i.start||r>=i.end)continue;let u=r-i.start;if(u<0||u>=s.length)continue;let d=s[u],p=f[r],m=e.style?.size,h=Xe(o,m),g=(e.offset?.y??0)<0?!0:(e.offset?.y??0)>0?!1:Je(e.shape),_;_=g?n.yAxis.priceToY(p.high)-h/2-4+(e.offset?.y??0):n.yAxis.priceToY(p.low)+h/2+4+(e.offset?.y??0);let v=d+(e.offset?.x??0),y=_,b=v,x=y,S=Math.round(h*c/2)*2/c;F(t,e.shape,b,x,S,e.style||{}),e.label&&ee(t,e.label,b,x,S,e.style||{},g),l.setCustomMarkerPosition(e.id,b-a,x,S,e.shape)}t.restore()}}}}function Xe(e,t){let n=e*Ge;return Math.max(qe,Math.min(n,t??Ke))}function Ze(e,t){let n=0,r=e.length-1;for(;n<=r;){let i=Math.floor((n+r)/2),a=e[i]?.timestamp;if(a===void 0)break;if(a===t)return i;a<t?n=i+1:r=i-1}return-1}var Qe=new Intl.DateTimeFormat(`zh-CN`,{timeZone:`Asia/Shanghai`,year:`numeric`,month:`2-digit`,day:`2-digit`}),$e=1024,et=new Map;function tt(e){let t=et.get(e);if(t!==void 0)return t;let n=Qe.formatToParts(new Date(e)),r=``,i=``,a=``;for(let e=0;e<n.length;e++){let t=n[e];t.type===`year`?r=t.value:t.type===`month`?i=t.value:t.type===`day`&&(a=t.value)}let o=`${r}-${i}-${a}`;return et.size>=$e&&et.clear(),et.set(e,o),o}var nt=512,rt=new Map;function it(e){let t=rt.get(e);if(t!==void 0)return t;let n=new Date(e),r=n.getFullYear(),i=n.getMonth()+1,a=i===1?{text:String(r),isYear:!0}:{text:`${i}月`,isYear:!1};return rt.size>=nt&&rt.clear(),rt.set(e,a),a}function at(e){let t=new Date(e);return t.getFullYear()*12+t.getMonth()}var ot=tt,st=tt,ct=null,lt=0,ut=0,dt=0,ft=[];function pt(e){if(e.length===0)return[];if(ct===e&&lt===e.length){let t=e[0]?.timestamp,n=e[e.length-1]?.timestamp;if(t===ut&&n===dt)return ft}let t=[0],n=at(e[0].timestamp);for(let r=1;r<e.length;r++){let i=e[r];if(!i)continue;let a=at(i.timestamp);a!==n&&(t.push(r),n=a)}return ct=e,lt=e.length,ut=e[0]?.timestamp??0,dt=e[e.length-1]?.timestamp??0,ft=t,t}var mt=U.UP,ht=U.DOWN,gt=U.NEUTRAL;function _t(e){return e>0?mt:e<0?ht:gt}function vt(e,t=2){let n=Math.abs(e);return n>=1e8?`${(e/1e8).toFixed(t)}亿`:n>=1e4?`${(e/1e4).toFixed(t)}万`:`${Math.round(e)}`}function yt(e,t=2){return`${e>0?`+`:``}${e.toFixed(t)}`}function bt(e,t=2){return`${e.toFixed(t)}%`}function xt(e,t=2){return`${e>0?`+`:``}${e.toFixed(t)}%`}function St(e,t){let n=t?.close??e.open;return _t(e.open-n)}function Ct(e){return _t(e.close-e.open)}function wt(e){return typeof e.changePercent==`number`?_t(e.changePercent):typeof e.changeAmount==`number`?_t(e.changeAmount):gt}var Tt={class:`kline-tooltip__title`},Et={key:0},Dt={class:`kline-tooltip__grid`},Ot={class:`row`},kt={class:`row`},At={class:`row`},jt={class:`row`},Mt={key:0,class:`row`},Nt={key:1,class:`row`},Pt={key:2,class:`row`},Ft={key:3,class:`row`},It={key:4,class:`row`},Lt={key:5,class:`row`},Rt=(0,e.defineComponent)({__name:`KLineTooltip`,props:{k:{},index:{},data:{},pos:{},useAnchor:{type:Boolean},anchorPlacement:{},setEl:{type:Function}},setup(t){let n=t,r=(0,e.computed)(()=>n.useAnchor===!0),i=(0,e.computed)(()=>n.anchorPlacement===`left-bottom`?`anchor-left-bottom`:`anchor-right-bottom`);function a(e){n.setEl?.(e)}let o=(0,e.computed)(()=>{let e=n.k;if(!e)return gt;let t=n.index;return St(e,typeof t==`number`&&t>0?n.data[t-1]:void 0)}),s=(0,e.computed)(()=>{let e=n.k;return e?Ct(e):gt}),c=(0,e.computed)(()=>{let e=n.k;return e?wt(e):gt});return(n,l)=>t.k?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,ref:a,class:(0,e.normalizeClass)([`kline-tooltip`,[{"use-anchor":r.value},i.value]]),style:(0,e.normalizeStyle)(r.value?void 0:{left:`${t.pos.x}px`,top:`${t.pos.y}px`})},[(0,e.createElementVNode)(`div`,Tt,[t.k.stockCode?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,Et,(0,e.toDisplayString)(t.k.stockCode),1)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(ot)(t.k.timestamp)),1)]),(0,e.createElementVNode)(`div`,Dt,[(0,e.createElementVNode)(`div`,Ot,[l[0]||=(0,e.createElementVNode)(`span`,null,`开`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:o.value})},(0,e.toDisplayString)(t.k.open.toFixed(2)),5)]),(0,e.createElementVNode)(`div`,kt,[l[1]||=(0,e.createElementVNode)(`span`,null,`高`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.k.high.toFixed(2)),1)]),(0,e.createElementVNode)(`div`,At,[l[2]||=(0,e.createElementVNode)(`span`,null,`低`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.k.low.toFixed(2)),1)]),(0,e.createElementVNode)(`div`,jt,[l[3]||=(0,e.createElementVNode)(`span`,null,`收`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:s.value})},(0,e.toDisplayString)(t.k.close.toFixed(2)),5)]),typeof t.k.volume==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Mt,[l[4]||=(0,e.createElementVNode)(`span`,null,`成交量`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(vt)(t.k.volume)),1)])):(0,e.createCommentVNode)(``,!0),typeof t.k.turnover==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Nt,[l[5]||=(0,e.createElementVNode)(`span`,null,`成交额`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(vt)(t.k.turnover)),1)])):(0,e.createCommentVNode)(``,!0),typeof t.k.amplitude==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Pt,[l[6]||=(0,e.createElementVNode)(`span`,null,`振幅`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.k.amplitude)+`%`,1)])):(0,e.createCommentVNode)(``,!0),typeof t.k.changePercent==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ft,[l[7]||=(0,e.createElementVNode)(`span`,null,`涨跌幅`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:c.value})},(0,e.toDisplayString)((0,e.unref)(xt)(t.k.changePercent)),5)])):(0,e.createCommentVNode)(``,!0),typeof t.k.changeAmount==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,It,[l[8]||=(0,e.createElementVNode)(`span`,null,`涨跌额`,-1),(0,e.createElementVNode)(`span`,{style:(0,e.normalizeStyle)({color:c.value})},(0,e.toDisplayString)((0,e.unref)(yt)(t.k.changeAmount)),5)])):(0,e.createCommentVNode)(``,!0),typeof t.k.turnoverRate==`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Lt,[l[9]||=(0,e.createElementVNode)(`span`,null,`换手率`,-1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(bt)(t.k.turnoverRate)),1)])):(0,e.createCommentVNode)(``,!0)])],6)):(0,e.createCommentVNode)(``,!0)}}),zt=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},Bt=zt(Rt,[[`__scopeId`,`data-v-d0fe85e6`]]),Vt={RISE_WITH_VOLUME:`量价齐升`,RISE_WITHOUT_VOLUME:`量缩价升`,FALL_WITH_VOLUME:`量价齐缩`,FALL_WITHOUT_VOLUME:`量升价缩`},Ht=class{markers=new Map;hoveredMarkerId=null;lastHoveredId=null;customMarkers=new Map;customMarkerPositions=new Map;clear(){this.markers.clear()}register(e){this.markers.set(e.id,e)}getState(e){return this.hoveredMarkerId===e?`hovered`:`normal`}hitTest(e,t,n=3){for(let r of this.markers.values())if(e>=r.x-n&&e<=r.x+r.width+n&&t>=r.y-n&&t<=r.y+r.height+n)return r;return null}setHover(e){this.hoveredMarkerId=e,this.lastHoveredId=e}validateHoverState(){this.hoveredMarkerId!==null&&!this.markers.has(this.hoveredMarkerId)&&(this.hoveredMarkerId=null)}getHoveredMarker(){return this.hoveredMarkerId===null?null:this.markers.get(this.hoveredMarkerId)||null}getLastHoverId(){return this.lastHoveredId}getAllMarkers(){return Array.from(this.markers.values())}registerCustomMarker(e){this.customMarkers.set(e.id,e)}setCustomMarkers(e){this.clearCustomMarkers();for(let t of e)this.customMarkers.set(t.id,t)}clearCustomMarkers(){this.customMarkers.clear(),this.customMarkerPositions.clear()}getCustomMarkers(){return Array.from(this.customMarkers.values())}setCustomMarkerPosition(e,t,n,r,i){this.customMarkerPositions.set(e,{x:t,y:n,size:r,shape:i})}hitTestCustomMarker(e,t){for(let n of this.customMarkers.values()){let r=this.customMarkerPositions.get(n.id);if(r&&ce(e,t,r.shape,r.x,r.y,r.size))return n}return null}},Ut={class:`marker-tooltip__title`},Wt={key:0,class:`marker-tooltip__content`},Gt=zt((0,e.defineComponent)({__name:`MarkerTooltip`,props:{marker:{},pos:{},useAnchor:{type:Boolean},anchorPlacement:{},setEl:{type:Function}},setup(t){let n=t,r=(0,e.computed)(()=>n.useAnchor===!0),i=(0,e.computed)(()=>n.anchorPlacement===`left-bottom`?`anchor-left-bottom`:`anchor-right-bottom`);function a(e){n.setEl?.(e)}let o=(0,e.computed)(()=>n.marker&&`date`in n.marker),s=(0,e.computed)(()=>{if(!n.marker)return``;if(o.value){let e=n.marker;return e.label?.text||e.shape}let e=n.marker;return Vt[e.markerType]||e.markerType}),c=(0,e.computed)(()=>{if(!n.marker)return{};if(o.value){let e=n.marker;return{日期:e.date,...e.metadata}}return n.marker.metadata}),l=(0,e.computed)(()=>Object.keys(c.value).length>0);function u(e){return typeof e==`number`?e.toFixed(2):String(e)}return(n,o)=>t.marker?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,ref:a,class:(0,e.normalizeClass)([`marker-tooltip`,[{"use-anchor":r.value},i.value]]),style:(0,e.normalizeStyle)(r.value?void 0:{left:`${t.pos.x+12}px`,top:`${t.pos.y+12}px`})},[(0,e.createElementVNode)(`div`,Ut,(0,e.toDisplayString)(s.value),1),l.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Wt,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(c.value,(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:n,class:`row`},[(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(n),1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(u(t)),1)]))),128))])):(0,e.createCommentVNode)(``,!0)],6)):(0,e.createCommentVNode)(``,!0)}}),[[`__scopeId`,`data-v-5574cc25`]]),Kt=Symbol(`fullscreen-teleport-target`);function qt(){let t=(0,e.inject)(Kt,null);return(0,e.computed)(()=>t?.value??`body`)}var Jt={class:`params-header`},Yt={class:`header-left`},Xt={class:`params-title`},Zt={class:`header-right`},Qt={key:0,class:`indicator-description`},$t={class:`params-body`},en={class:`param-header`},tn={class:`param-label`},nn={class:`param-label-text`},rn={key:0,class:`param-range`},an={class:`input-wrapper`},on=[`disabled`,`onClick`],sn=[`value`,`min`,`max`,`step`,`onInput`],cn=[`disabled`,`onClick`],ln={key:0,class:`param-description`},un={class:`params-footer`},dn={class:`footer-right`},fn=zt((0,e.defineComponent)({__name:`IndicatorParams`,props:{visible:{type:Boolean},indicatorId:{},indicatorName:{},indicatorDescription:{},params:{},values:{}},emits:[`close`,`confirm`],setup(t,{emit:n}){let r=t,i=n,a=(0,e.ref)({...r.values}),o=(0,e.ref)(!0),s=qt();(0,e.watch)(()=>r.values,e=>{a.value={...e}},{deep:!0,immediate:!0}),(0,e.watch)(()=>r.visible,e=>{e&&(a.value={...r.values})});function c(e,t){let n=t.target,r=parseFloat(n.value);isNaN(r)||(a.value[e]=r)}function l(e,t){let n=e.step||1,r=(a.value[e.key]||0)+t*n;e.min!==void 0&&(r=Math.max(e.min,r)),e.max!==void 0&&(r=Math.min(e.max,r)),a.value[e.key]=parseFloat(r.toFixed(10))}function u(){let e={};r.params.forEach(t=>{e[t.key]=t.default??r.values[t.key]??0}),a.value=e}function d(){i(`confirm`,{...a.value})}return(n,r)=>((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{to:(0,e.unref)(s)},[(0,e.createVNode)(e.Transition,{name:`overlay`},{default:(0,e.withCtx)(()=>[t.visible?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`params-overlay`,onClick:r[4]||=e=>n.$emit(`close`)},[(0,e.createVNode)(e.Transition,{name:`modal`},{default:(0,e.withCtx)(()=>[(0,e.createElementVNode)(`div`,{class:`indicator-params`,onClick:r[3]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`div`,Jt,[(0,e.createElementVNode)(`div`,Yt,[(0,e.createElementVNode)(`span`,Xt,(0,e.toDisplayString)(t.indicatorName),1),r[5]||=(0,e.createElementVNode)(`span`,{class:`params-subtitle`},`参数设置`,-1)]),(0,e.createElementVNode)(`div`,Zt,[(0,e.createElementVNode)(`button`,{class:(0,e.normalizeClass)([`toggle-desc-btn`,{active:o.value}]),onClick:r[0]||=e=>o.value=!o.value,title:`显示/隐藏说明`},[...r[6]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 1024 1024`},[(0,e.createElementVNode)(`path`,{d:`M512 97.52381c228.912762 0 414.47619 185.563429 414.47619 414.47619s-185.563429 414.47619-414.47619 414.47619S97.52381 740.912762 97.52381 512 283.087238 97.52381 512 97.52381z m0 73.142857C323.486476 170.666667 170.666667 323.486476 170.666667 512s152.81981 341.333333 341.333333 341.333333 341.333333-152.81981 341.333333-341.333333S700.513524 170.666667 512 170.666667z m36.571429 268.190476v292.571428h-73.142858V438.857143h73.142858z m0-121.904762v73.142857h-73.142858v-73.142857h73.142858z`,fill:`currentColor`})],-1)]],2),(0,e.createElementVNode)(`button`,{class:`params-close`,onClick:r[1]||=e=>n.$emit(`close`)},[...r[7]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M18 6L6 18M6 6l12 12`})],-1)]])])]),(0,e.createVNode)(e.Transition,{name:`slide`},{default:(0,e.withCtx)(()=>[o.value&&t.indicatorDescription?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Qt,[(0,e.createElementVNode)(`p`,null,(0,e.toDisplayString)(t.indicatorDescription),1)])):(0,e.createCommentVNode)(``,!0)]),_:1}),(0,e.createElementVNode)(`div`,$t,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.params,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.key,class:(0,e.normalizeClass)([`param-item`,{"has-desc":o.value&&t.description}])},[(0,e.createElementVNode)(`div`,en,[(0,e.createElementVNode)(`label`,tn,[(0,e.createElementVNode)(`span`,nn,(0,e.toDisplayString)(t.label),1),t.min!==void 0||t.max!==void 0?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,rn,(0,e.toDisplayString)(t.min??`-∞`)+` ~ `+(0,e.toDisplayString)(t.max??`+∞`),1)):(0,e.createCommentVNode)(``,!0)]),(0,e.createElementVNode)(`div`,an,[(0,e.createElementVNode)(`button`,{class:`stepper-btn`,disabled:t.min!==void 0&&(a.value[t.key]??0)<=t.min,onClick:e=>l(t,-1)},` − `,8,on),t.type===`number`?((0,e.openBlock)(),(0,e.createElementBlock)(`input`,{key:0,type:`number`,class:`param-input`,value:a.value[t.key],min:t.min,max:t.max,step:t.step||1,onInput:e=>c(t.key,e)},null,40,sn)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`button`,{class:`stepper-btn`,disabled:t.max!==void 0&&(a.value[t.key]??0)>=t.max,onClick:e=>l(t,1)},` + `,8,cn)])]),(0,e.createVNode)(e.Transition,{name:`slide`},{default:(0,e.withCtx)(()=>[o.value&&t.description?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,ln,(0,e.toDisplayString)(t.description),1)):(0,e.createCommentVNode)(``,!0)]),_:2},1024)],2))),128))]),(0,e.createElementVNode)(`div`,un,[(0,e.createElementVNode)(`button`,{class:`params-btn reset`,onClick:u},[...r[8]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}),(0,e.createElementVNode)(`path`,{d:`M3 3v5h5`})],-1),(0,e.createTextVNode)(` 重置 `,-1)]]),(0,e.createElementVNode)(`div`,dn,[(0,e.createElementVNode)(`button`,{class:`params-btn cancel`,onClick:r[2]||=e=>n.$emit(`close`)},`取消`),(0,e.createElementVNode)(`button`,{class:`params-btn confirm`,onClick:d},[...r[9]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`},[(0,e.createElementVNode)(`path`,{d:`M20 6L9 17l-5-5`})],-1),(0,e.createTextVNode)(` 确定 `,-1)]])])])])]),_:1})])):(0,e.createCommentVNode)(``,!0)]),_:1})],8,[`to`]))}}),[[`__scopeId`,`data-v-bb1d1eb3`]]),pn=[{id:`MA`,label:`MA`,name:`均线`,pane:`main`},{id:`VOLUME`,label:`VOL`,name:`成交量`,pane:`sub`,description:`成交量反映市场活跃度,柱状图显示每根K线的交易量。上涨时柱子为红色,下跌时为绿色。`},{id:`BOLL`,label:`BOLL`,name:`布林带`,pane:`main`,description:`布林带由三条轨道线组成,用于判断价格的波动范围和趋势强度。价格触及上轨可能超买,触及下轨可能超卖。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:20,description:`计算移动平均线的周期数,周期越长轨道越平滑`},{key:`multiplier`,label:`倍数`,type:`number`,min:.1,max:5,step:.1,default:2,description:`标准差倍数,决定轨道宽度,通常为 2`}]},{id:`EXPMA`,label:`EXPMA`,name:`指数平滑移动平均线`,pane:`main`,description:`EXPMA 对近期价格给予更高权重,比普通 MA 更敏感。快线上穿慢线为金叉看涨,下穿为死叉看跌。`,params:[{key:`fastPeriod`,label:`快线`,type:`number`,min:2,max:100,step:1,default:12,description:`快线周期,对价格变化更敏感`},{key:`slowPeriod`,label:`慢线`,type:`number`,min:2,max:200,step:1,default:50,description:`慢线周期,用于判断趋势方向`}]},{id:`ENE`,label:`ENE`,name:`轨道线`,pane:`main`,description:`ENE 轨道线由三条轨道组成,价格突破上轨可能超买,突破下轨可能超卖,适合判断震荡行情的买卖点。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:10,description:`计算中轨的周期数`},{key:`deviation`,label:`偏离率`,type:`number`,min:1,max:30,step:.5,default:11,description:`轨道偏离率百分比,决定轨道宽度`}]},{id:`MACD`,label:`MACD`,name:`指数平滑异同移动平均线`,pane:`sub`,description:`MACD 通过快慢均线的交叉判断趋势方向和动量。DIF 上穿 DEA 为金叉看涨,下穿为死叉看跌。`,params:[{key:`fastPeriod`,label:`快线`,type:`number`,min:2,max:50,step:1,default:12,description:`快线 EMA 周期,对价格变化更敏感`},{key:`slowPeriod`,label:`慢线`,type:`number`,min:2,max:100,step:1,default:26,description:`慢线 EMA 周期,用于计算 DIF`},{key:`signalPeriod`,label:`信号`,type:`number`,min:2,max:50,step:1,default:9,description:`DEA 的 EMA 周期,用于生成买卖信号`}]},{id:`RSI`,label:`RSI`,name:`相对强弱指标`,pane:`sub`,description:`RSI 衡量价格变动的速度和幅度,判断超买超卖状态。RSI > 70 超买,RSI < 30 超卖。`,params:[{key:`period1`,label:`周期 1`,type:`number`,min:2,max:100,step:1,default:6,description:`第一条 RSI 周期,通常为 6(快线)`},{key:`period2`,label:`周期 2`,type:`number`,min:2,max:100,step:1,default:12,description:`第二条 RSI 周期,通常为 12(中线)`},{key:`period3`,label:`周期 3`,type:`number`,min:2,max:100,step:1,default:24,description:`第三条 RSI 周期,通常为 24(慢线)`}]},{id:`CCI`,label:`CCI`,name:`顺势指标`,pane:`sub`,description:`CCI 衡量价格与统计平均值的偏离程度。CCI > 100 超买,CCI < -100 超卖,适合捕捉趋势反转。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:14,description:`计算周期,周期越短信号越灵敏`}]},{id:`STOCH`,label:`STOCH`,name:`随机指标`,pane:`sub`,description:`KDJ 随机指标通过比较收盘价与价格区间判断超买超卖。K > 80 超买,K < 20 超卖,K 上穿 D 金叉。`,params:[{key:`n`,label:`K 周期`,type:`number`,min:2,max:100,step:1,default:9,description:`计算 K 值的周期,统计 N 日内价格区间`},{key:`m`,label:`D 周期`,type:`number`,min:1,max:50,step:1,default:3,description:`D 值是 K 的 M 日移动平均,使信号更平滑`}]},{id:`MOM`,label:`MOM`,name:`动量指标`,pane:`sub`,description:`动量指标衡量价格变化的速度,MOM > 0 表示上涨动能,MOM < 0 表示下跌动能。适合判断趋势强度。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:10,description:`与多少日前价格比较,周期越短越灵敏`}]},{id:`WMSR`,label:`WMSR`,name:`威廉指标`,pane:`sub`,description:`威廉指标衡量超买超卖程度,范围为 -100 到 0。WMSR > -20 超买,WMSR < -80 超卖。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:14,description:`回溯周期,统计周期内最高最低价`}]},{id:`KST`,label:`KST`,name:`确然指标`,pane:`sub`,description:`KST 综合多个 ROC 判断长期趋势,KST 上穿信号线看涨,下穿看跌。适合捕捉主要趋势转换。`,params:[{key:`roc1`,label:`ROC1`,type:`number`,min:2,max:100,step:1,default:10,description:`短期变化率周期`},{key:`roc2`,label:`ROC2`,type:`number`,min:2,max:100,step:1,default:15,description:`中短期变化率周期`},{key:`roc3`,label:`ROC3`,type:`number`,min:2,max:100,step:1,default:20,description:`中长期变化率周期`},{key:`roc4`,label:`ROC4`,type:`number`,min:2,max:100,step:1,default:30,description:`长期变化率周期`},{key:`signalPeriod`,label:`信号`,type:`number`,min:2,max:50,step:1,default:9,description:`信号线的 SMA 周期`}]},{id:`FASTK`,label:`FASTK`,name:`快速随机指标`,pane:`sub`,description:`FASTK 是未经过平滑处理的随机指标,比普通 KDJ 更敏感,能更快捕捉价格转折点,但假信号也更多。`,params:[{key:`period`,label:`周期`,type:`number`,min:2,max:100,step:1,default:9,description:`计算周期,周期越短越敏感`}]},{id:`ATR`,label:`ATR`,name:`平均真实波幅`,pane:`sub`,description:`ATR(Average True Range)衡量市场波动性,值越大表示波动越剧烈。Wilder 平滑算法,常用于设置止损位和判断趋势强度。`,params:[{key:`period`,label:`周期`,type:`number`,min:1,max:100,step:1,default:14,description:`ATR 计算周期,周期越长曲线越平滑`}]}],mn=pn.filter(e=>e.pane===`main`),hn=pn.filter(e=>e.pane===`sub`);function gn(e){return pn.find(t=>t.id===e)}function _n(e){return pn.find(t=>t.id===e)?.pane===`sub`}var vn={class:`indicator-selector`},yn={class:`indicator-scroll-container`},bn={class:`indicator-list`},xn={key:0,class:`indicator-divider`,"aria-hidden":`true`},Sn=[`draggable`,`onDragstart`,`onDragover`,`onDrop`],Cn=[`onMouseenter`],wn={class:`btn-content`},Tn={key:0,class:`param-hint`},En={key:0,class:`hover-overlay`},Dn=[`onClick`],On={key:1,class:`divider`},kn=[`onClick`],An={class:`indicator-item`},jn={class:`menu-section`},Mn={class:`menu-items`},Nn=[`disabled`,`onClick`],Pn={class:`param-hint`},Fn={key:0,class:`active-tag`},In={class:`menu-section`},Ln={class:`menu-items`},Rn=[`disabled`,`onClick`],zn={class:`param-hint`},Bn={key:0,class:`active-tag`},Vn=zt((0,e.defineComponent)({__name:`IndicatorSelector`,props:{activeIndicators:{},indicatorParams:{}},emits:[`toggle`,`updateParams`,`reorderSubIndicators`],setup(t,{emit:n}){let r=t,i=n,a=(0,e.ref)(null),o=(0,e.ref)(null),s=(0,e.ref)(!1),c=(0,e.ref)(null),l=(0,e.ref)(null),u=(0,e.ref)(!1),d=(0,e.ref)({left:`0`,bottom:`0`}),f=(0,e.ref)(!1),p=(0,e.ref)(null),m=(0,e.ref)(null),h=qt(),g=(0,e.computed)(()=>r.activeIndicators?.length?r.activeIndicators.map(e=>gn(e)).filter(e=>e!==void 0).sort((e,t)=>e.pane===t.pane?0:e.pane===`main`?-1:1):[]),_=(0,e.computed)(()=>g.value.some(e=>e.pane===`main`)?g.value.find(e=>e.pane===`sub`)?.id??null:null),v=(0,e.computed)(()=>c.value?gn(c.value):null);function y(e){return r.activeIndicators?.includes(e)??!1}function b(e){if(y(e))return;let t=gn(e);t&&(t.pane===`main`&&mn.filter(t=>t.id!==e&&y(t.id)).forEach(e=>i(`toggle`,e.id,!1)),i(`toggle`,e,!0),u.value=!1)}function x(e){i(`toggle`,e,!1)}function S(e){c.value=e,s.value=!0}function C(e){let t=gn(e);if(!t?.params)return{};let n={};for(let e of t.params)n[e.key]=e.default??e.min??1;let i=r.indicatorParams?.[e]||{},a={...n};for(let[e,t]of Object.entries(i))typeof t==`number`&&(a[e]=t);return a}function w(e){let t=C(e.id);return e.params?e.params.map(e=>t[e.key]??``).join(`,`):``}function T(e){c.value&&i(`updateParams`,c.value,e),s.value=!1}function E(e,t){if(!_n(t)){e.preventDefault();return}m.value=t,p.value=null,e.dataTransfer?.setData(`text/plain`,t),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`)}function D(e,t){!m.value||!_n(t)||m.value===t||(p.value=t,e.dataTransfer&&(e.dataTransfer.dropEffect=`move`))}function O(e,t){let n=m.value||e.dataTransfer?.getData(`text/plain`)||``;if(!n||n===t){k();return}if(!_n(n)||!_n(t)){k();return}let r=g.value.findIndex(e=>e.id===n),a=g.value.findIndex(e=>e.id===t);if(r<0||a<0){k();return}let o=[...g.value.map(e=>e.id)],[s]=o.splice(r,1);if(!s){k();return}o.splice(a,0,s),i(`reorderSubIndicators`,o.filter(e=>_n(e))),k()}function k(){p.value=null,m.value=null}function A(){if(!u.value&&a.value&&!f.value){let e=a.value.getBoundingClientRect(),t=window.innerWidth,n=e.left+e.width/2;n+160>t-8&&(n=t-160-8),n-160<8&&(n=168),d.value={left:`${n}px`,bottom:`${window.innerHeight-e.top+8}px`}}u.value=!u.value}function j(e){let t=o.value&&!o.value.contains(e.target),n=a.value&&!a.value.contains(e.target);t&&n&&(u.value=!1)}function M(){u.value&&=!1}return(0,e.onMounted)(()=>{f.value=typeof CSS<`u`&&CSS.supports(`anchor-name: --kmap-anchor`)&&CSS.supports(`position-anchor: --kmap-anchor`),document.addEventListener(`click`,j),window.addEventListener(`resize`,M)}),(0,e.onUnmounted)(()=>{document.removeEventListener(`click`,j),window.removeEventListener(`resize`,M)}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,vn,[(0,e.createElementVNode)(`div`,yn,[(0,e.createElementVNode)(`div`,bn,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(g.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:t.id},[t.id===_.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,xn)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`indicator-item`,{draggable:(0,e.unref)(_n)(t.id),"drag-over":p.value===t.id,"is-dragging":m.value===t.id}]),draggable:(0,e.unref)(_n)(t.id),onDragstart:e=>E(e,t.id),onDragover:(0,e.withModifiers)(e=>D(e,t.id),[`prevent`]),onDrop:(0,e.withModifiers)(e=>O(e,t.id),[`prevent`]),onDragend:k},[(0,e.createElementVNode)(`div`,{class:`indicator-btn-wrapper`,onMouseenter:e=>l.value=t.id,onMouseleave:n[0]||=e=>l.value=null},[(0,e.createElementVNode)(`button`,{class:(0,e.normalizeClass)([`indicator-btn`,{active:!0,hovering:l.value===t.id}])},[(0,e.createElementVNode)(`span`,wn,[(0,e.createTextVNode)((0,e.toDisplayString)(t.label)+` `,1),t.params?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,Tn,` (`+(0,e.toDisplayString)(w(t))+`) `,1)):(0,e.createCommentVNode)(``,!0)]),(0,e.createVNode)(e.Transition,{name:`fade`},{default:(0,e.withCtx)(()=>[l.value===t.id?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,En,[t.params?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:0,class:`action-btn settings-btn`,onClick:(0,e.withModifiers)(e=>S(t.id),[`stop`]),title:`编辑参数`},[...n[2]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z`})],-1)]],8,Dn)):(0,e.createCommentVNode)(``,!0),t.params?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,On)):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`button`,{class:`action-btn remove-btn`,onClick:(0,e.withModifiers)(e=>x(t.id),[`stop`]),title:`移除指标`},[...n[3]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z`})],-1)]],8,kn)])):(0,e.createCommentVNode)(``,!0)]),_:2},1024)],2)],40,Cn)],42,Sn)],64))),128)),(0,e.createElementVNode)(`div`,An,[(0,e.createElementVNode)(`button`,{ref_key:`addBtnRef`,ref:a,class:`add-btn`,onClick:A,title:`添加指标`},[...n[4]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z`})],-1)]],512)])])]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{to:(0,e.unref)(h)},[(0,e.createVNode)(e.Transition,{name:`slide`},{default:(0,e.withCtx)(()=>[u.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`add-menu`,{"use-anchor":f.value}]),ref_key:`addMenuRef`,ref:o,style:(0,e.normalizeStyle)(f.value?void 0:d.value)},[(0,e.createElementVNode)(`div`,jn,[n[6]||=(0,e.createElementVNode)(`div`,{class:`menu-title`},`主图指标`,-1),(0,e.createElementVNode)(`div`,Mn,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)((0,e.unref)(mn),t=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:t.id,class:(0,e.normalizeClass)([`menu-item`,{disabled:y(t.id)}]),disabled:y(t.id),onClick:e=>b(t.id)},[(0,e.createTextVNode)((0,e.toDisplayString)(t.label)+` `,1),(0,e.createElementVNode)(`span`,Pn,` (`+(0,e.toDisplayString)(t.name)+`) `,1),y(t.id)?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,Fn,[...n[5]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})],-1)]])):(0,e.createCommentVNode)(``,!0)],10,Nn))),128))])]),(0,e.createElementVNode)(`div`,In,[n[8]||=(0,e.createElementVNode)(`div`,{class:`menu-title`},`副图指标`,-1),(0,e.createElementVNode)(`div`,Ln,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)((0,e.unref)(hn),t=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:t.id,class:(0,e.normalizeClass)([`menu-item`,{disabled:y(t.id)}]),disabled:y(t.id),onClick:e=>b(t.id)},[(0,e.createTextVNode)((0,e.toDisplayString)(t.label)+` `,1),(0,e.createElementVNode)(`span`,zn,` (`+(0,e.toDisplayString)(t.name)+`) `,1),y(t.id)?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,Bn,[...n[7]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`currentColor`},[(0,e.createElementVNode)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})],-1)]])):(0,e.createCommentVNode)(``,!0)],10,Rn))),128))])])],6)):(0,e.createCommentVNode)(``,!0)]),_:1})],8,[`to`])),v.value?((0,e.openBlock)(),(0,e.createBlock)(fn,{key:0,visible:s.value,"indicator-id":v.value.id,"indicator-name":v.value.name,"indicator-description":v.value.description,params:v.value.params||[],values:C(v.value.id),onClose:n[1]||=e=>s.value=!1,onConfirm:T},null,8,[`visible`,`indicator-id`,`indicator-name`,`indicator-description`,`params`,`values`])):(0,e.createCommentVNode)(``,!0)]))}}),[[`__scopeId`,`data-v-b8333f39`]]),Hn={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Un(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Hn,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 7h16m-10 4v6m4-6v6M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3`},null,-1)]])}var Wn=(0,e.markRaw)({name:`tabler-trash`,render:Un}),Gn={class:`toolbar-item color-item`,title:`颜色`},Kn=[`value`],qn=[`value`],Jn=[`value`],Yn=zt((0,e.defineComponent)({__name:`DrawingStyleToolbar`,props:{drawing:{}},emits:[`updateStyle`,`delete`],setup(t,{emit:n}){let r=n;function i(e){e.key===`Delete`&&(e.preventDefault(),r(`delete`))}(0,e.onMounted)(()=>document.addEventListener(`keydown`,i)),(0,e.onUnmounted)(()=>document.removeEventListener(`keydown`,i));function a(e){r(`updateStyle`,{stroke:e})}function o(e){r(`updateStyle`,{strokeWidth:e})}function s(e){r(`updateStyle`,{strokeStyle:e})}return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`drawing-style-toolbar`,onPointerdown:r[4]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[5]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[6]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`div`,Gn,[(0,e.createElementVNode)(`span`,{class:`color-swatch`,style:(0,e.normalizeStyle)({background:t.drawing.style.stroke??`#2962ff`})},null,4),(0,e.createElementVNode)(`input`,{type:`color`,class:`color-input`,value:t.drawing.style.stroke??`#2962ff`,onInput:r[0]||=e=>a(e.target.value)},null,40,Kn)]),(0,e.createElementVNode)(`select`,{class:`toolbar-select`,value:t.drawing.style.strokeWidth??1,onChange:r[1]||=e=>o(Number(e.target.value)),title:`线宽`},[...r[7]||=[(0,e.createElementVNode)(`option`,{value:1},`1px`,-1),(0,e.createElementVNode)(`option`,{value:2},`2px`,-1),(0,e.createElementVNode)(`option`,{value:3},`3px`,-1),(0,e.createElementVNode)(`option`,{value:4},`4px`,-1)]],40,qn),(0,e.createElementVNode)(`select`,{class:`toolbar-select`,value:t.drawing.style.strokeStyle??`solid`,onChange:r[2]||=e=>s(e.target.value),title:`线型`},[...r[8]||=[(0,e.createElementVNode)(`option`,{value:`solid`},`实线`,-1),(0,e.createElementVNode)(`option`,{value:`dashed`},`虚线`,-1),(0,e.createElementVNode)(`option`,{value:`dotted`},`点线`,-1)]],40,Jn),(0,e.createElementVNode)(`button`,{type:`button`,class:`toolbar-btn delete-btn`,title:`删除`,onClick:r[3]||=e=>n.$emit(`delete`)},[(0,e.createVNode)((0,e.unref)(Wn),{class:`delete-icon`,"aria-hidden":`true`})])],32))}}),[[`__scopeId`,`data-v-92699cb2`]]),Xn=class{hoveredMarkerId=null;clickedMarkerId=null;hoveredMarkerData=null;clickedMarkerData=null;hoveredCustomMarker=null;onMarkerHoverCallback;onMarkerClickCallback;onCustomMarkerHoverCallback;onCustomMarkerClickCallback;setOnMarkerHover(e){this.onMarkerHoverCallback=e}setOnMarkerClick(e){this.onMarkerClickCallback=e}setOnCustomMarkerHover(e){this.onCustomMarkerHoverCallback=e}setOnCustomMarkerClick(e){this.onCustomMarkerClickCallback=e}handleClick(e){this.clickedMarkerId=e.id,this.clickedMarkerData=e,this.onMarkerClickCallback?.(e)}updateHoverFromPoint(e,t,n,r){let i=r.hitTest(e,n,3);if(i)return this.enterMarkerHover(i,r);this.leaveMarkerHover(r);let a=r.hitTestCustomMarker(t,n);return a?this.enterCustomMarkerHover(a,r):(this.leaveCustomMarkerHover(),!1)}enterMarkerHover(e,t){return this.hoveredMarkerId!==e.id&&(this.hoveredMarkerId=e.id,this.hoveredMarkerData=e,t.setHover(e.id),this.onMarkerHoverCallback?.(e)),this.hoveredCustomMarker!==null&&(this.hoveredCustomMarker=null,this.onCustomMarkerHoverCallback?.(null)),!0}leaveMarkerHover(e){this.hoveredMarkerId===null?this.hoveredMarkerData=null:(this.hoveredMarkerId=null,this.hoveredMarkerData=null,e.setHover(null),this.onMarkerHoverCallback?.(null))}enterCustomMarkerHover(e,t){return this.hoveredCustomMarker?.id!==e.id&&(this.hoveredCustomMarker=e,this.onCustomMarkerHoverCallback?.(e)),this.hoveredMarkerId!==null&&(this.hoveredMarkerId=null,this.hoveredMarkerData=null,t.setHover(null),this.onMarkerHoverCallback?.(null)),!0}leaveCustomMarkerHover(){this.hoveredCustomMarker!==null&&(this.hoveredCustomMarker=null,this.onCustomMarkerHoverCallback?.(null))}clearAll(e){this.hoveredMarkerId===null?this.hoveredMarkerData=null:(this.hoveredMarkerId=null,this.hoveredMarkerData=null,e.setHover(null),this.onMarkerHoverCallback?.(null)),this.hoveredCustomMarker!==null&&(this.hoveredCustomMarker=null,this.onCustomMarkerHoverCallback?.(null))}reset(){this.hoveredMarkerId=null,this.clickedMarkerId=null,this.hoveredMarkerData=null,this.clickedMarkerData=null,this.hoveredCustomMarker=null}},Zn=class{activePointers=new Map;lastPinchDistance=0;pinchCenter={x:0,y:0};isPinching=!1;onPinchZoomCallback;setOnPinchZoom(e){this.onPinchZoomCallback=e}getIsPinching(){return this.isPinching}getPointerCount(){return this.activePointers.size}handlePointerDown(e,t){if(this.activePointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.activePointers.size===2&&t){this.isPinching=!0;let e=Array.from(this.activePointers.values()),t=e[0],n=e[1];return this.lastPinchDistance=Math.hypot(n.x-t.x,n.y-t.y),this.pinchCenter={x:(t.x+n.x)/2,y:(t.y+n.y)/2},!0}return!1}handlePointerUp(e){this.activePointers.delete(e.pointerId),this.isPinching&&this.activePointers.size<2&&(this.isPinching=!1,this.lastPinchDistance=0)}handlePointerLeave(e){this.activePointers.delete(e.pointerId),this.activePointers.size<2&&(this.isPinching=!1,this.lastPinchDistance=0)}handlePointerMove(e){if(this.activePointers.has(e.pointerId)&&this.activePointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.isPinching&&this.activePointers.size===2){let e=Array.from(this.activePointers.values()),t=e[0],n=e[1],r=Math.hypot(n.x-t.x,n.y-t.y),i=r-this.lastPinchDistance;if(Math.abs(i)>10){let e=i>0?1:-1,a=(t.x+n.x)/2;this.onPinchZoomCallback?.(e,a),this.lastPinchDistance=r}return!0}return!1}reset(){this.activePointers.clear(),this.isPinching=!1,this.lastPinchDistance=0}};function Qn(e){if(e.useAnchorPositioning){let t=e.tooltipSize.width;return{anchorPlacement:e.mouseX+14+t+12>e.plotWidth?`left-bottom`:`right-bottom`,pos:{x:Math.min(Math.max(e.mouseX,12),Math.max(12,e.plotWidth-12)),y:Math.min(Math.max(e.mouseY,12),Math.max(12,e.plotHeight-12))}}}let t=e.tooltipSize.width,n=e.tooltipSize.height,r=e.mouseX+14,i=e.mouseX-14-t,a=r+t+12<=e.viewWidth?r:i,o=e.mouseY+14,s=Math.max(12,e.viewWidth-t-12),c=Math.max(12,e.viewHeight-n-12);return{pos:{x:Math.min(Math.max(a,12),s),y:Math.min(Math.max(o,12),c)}}}var $n=class{chart;isDragging=!1;dragMode=`none`;dragStartX=0;scrollStartX=0;applyPanScroll(e,t){let n=Math.max(0,e.scrollWidth-e.clientWidth),r=Math.min(Math.max(0,t),n),i=this.chart.getCurrentDpr();e.scrollLeft=Math.round(r*i)/i}dragStartY=0;activePaneIdOnDrag=null;activeSeparatorUpperPaneId=null;hoveredSeparatorUpperPaneId=null;hoveredRightAxisPaneId=null;isTouchSession=!1;pinchTracker=new Zn;crosshairPos=null;crosshairIndex=null;crosshairPrice=null;hoveredIndex=null;activePaneId=null;tooltipPos={x:0,y:0};tooltipSize={width:220,height:180};tooltipAnchorPlacement=`right-bottom`;useTooltipAnchorPositioning=!1;onInteractionChangeCallback;settings={};markerState=new Xn;kLinePositions=null;visibleRange=null;lastHoverRenderKey=``;kWidthPx=null;constructor(e){this.chart=e}setOnPinchZoom(e){this.pinchTracker.setOnPinchZoom(e)}updateSettings(e){let t=this.settings.disableMainPaneVerticalScroll;this.settings={...e},!t&&this.settings.disableMainPaneVerticalScroll&&this.chart.resetPriceOffset(`main`)}getInteractionSnapshot(){return{crosshairPos:this.crosshairPos?{...this.crosshairPos}:null,crosshairIndex:this.crosshairIndex,crosshairPrice:this.crosshairPrice,hoveredIndex:this.hoveredIndex,activePaneId:this.activePaneId,tooltipPos:{...this.tooltipPos},tooltipAnchorPlacement:this.tooltipAnchorPlacement,hoveredMarkerData:this.markerState.hoveredMarkerData,hoveredCustomMarker:this.markerState.hoveredCustomMarker,isDragging:this.isDragging,isResizingPaneBoundary:this.dragMode===`resize-separator`,isHoveringPaneBoundary:this.hoveredSeparatorUpperPaneId!==null,hoveredPaneBoundaryId:this.hoveredSeparatorUpperPaneId,isHoveringRightAxis:this.hoveredRightAxisPaneId!==null}}setOnInteractionChange(e){this.onInteractionChangeCallback=e}notifyInteractionChange(){this.onInteractionChangeCallback?.(this.getInteractionSnapshot())}getHoverRenderKey(){let e=this.crosshairPos?Math.round(this.crosshairPos.x*this.chart.getCurrentDpr()):`n`,t=this.crosshairPos?Math.round(this.crosshairPos.y*this.chart.getCurrentDpr()):`n`;return[this.crosshairIndex??`n`,this.hoveredIndex??`n`,this.activePaneId??`n`,this.hoveredRightAxisPaneId??`n`,this.hoveredSeparatorUpperPaneId??`n`,this.markerState.hoveredMarkerId??`n`,this.markerState.hoveredCustomMarker?.id??`n`,e,t].join(`|`)}onPointerDown(e){if(this.isTouchSession=e.pointerType===`touch`,this.pinchTracker.handlePointerDown(e,this.isTouchSession)){this.isDragging=!1,this.dragMode=`none`;return}if(e.isPrimary===!1||this.pinchTracker.getIsPinching()||this.pinchTracker.getPointerCount()>1)return;let t=this.getPlotPointerLocation(e.clientX,e.clientY);if(!t)return;let{mouseX:n,mouseY:r}=t,i=this.chart.getCachedScrollLeft(),a=this.chart.getMarkerManager(),o=i+n,s=a.hitTest(o,r,3);if(s){this.markerState.handleClick(s);return}let c=this.hitTestPaneSeparator(r);if(c){this.isDragging=!0,this.dragMode=`resize-separator`,this.dragStartY=e.clientY,this.activeSeparatorUpperPaneId=c,this.hoveredSeparatorUpperPaneId=c,this.clearHover(),this.chart.scheduleDraw();return}let l=this.getPaneByY(r);this.isDragging=!0,this.dragMode=`pan`,this.updatePlotHoverFromPoint(e.clientX,e.clientY),this.dragStartX=e.clientX,this.dragStartY=e.clientY,this.scrollStartX=this.chart.getCachedScrollLeft(),this.activePaneIdOnDrag=l?.id||null,this.chart.scheduleDraw()}setTooltipSize(e){this.tooltipSize=e}setTooltipAnchorPositioning(e){this.useTooltipAnchorPositioning=e}onPointerUp(e){this.pinchTracker.handlePointerUp(e),e.isPrimary!==!1&&(this.isDragging=!1,this.dragMode=`none`,this.activePaneIdOnDrag=null,this.activeSeparatorUpperPaneId=null,this.notifyInteractionChange())}onPointerLeave(e){this.pinchTracker.handlePointerLeave(e),e.isPrimary!==!1&&(this.isDragging=!1,this.dragMode=`none`,this.activePaneIdOnDrag=null,this.clearSeparatorState(),this.isTouchSession=!1,this.clearHover(),this.chart.scheduleDraw(),this.notifyInteractionChange())}onScroll(){this.kLinePositions=null,this.visibleRange=null,this.clearHover(),this.chart.scheduleDraw(),this.notifyInteractionChange()}onPointerMove(e){if(this.pinchTracker.handlePointerMove(e)||!e.isPrimary)return;e.pointerType===`touch`&&(this.isTouchSession=!0);let t=this.chart.getDom().container;if(this.isDragging){if(this.dragMode===`resize-separator`){let t=e.clientY-this.dragStartY;t!==0&&this.activeSeparatorUpperPaneId&&this.chart.resizePaneBoundary(this.activeSeparatorUpperPaneId,t)&&(this.dragStartY=e.clientY);return}if(this.dragMode===`scale-price`){let t=e.clientY-this.dragStartY;t!==0&&this.activePaneIdOnDrag&&(this.chart.scalePrice(this.activePaneIdOnDrag,t),this.dragStartY=e.clientY);return}if(this.dragMode===`pan`){let n=this.dragStartX-e.clientX;this.applyPanScroll(t,this.scrollStartX+n);let r=e.clientY-this.dragStartY;this.dragStartY=e.clientY,r!==0&&this.activePaneIdOnDrag===`main`&&(this.settings.disableMainPaneVerticalScroll||this.chart.translatePrice(this.activePaneIdOnDrag,r))}return}let n=this.getPlotPointerLocation(e.clientX,e.clientY);if(!n)return;this.hoveredSeparatorUpperPaneId=this.hitTestPaneSeparator(n.mouseY),this.updatePlotHoverFromPoint(e.clientX,e.clientY);let r=this.getHoverRenderKey();r!==this.lastHoverRenderKey&&(this.lastHoverRenderKey=r,this.chart.scheduleDraw(H.Overlay)),this.notifyInteractionChange()}setKLinePositions(e,t,n){this.kLinePositions=e,this.visibleRange=t,n!==void 0&&(this.kWidthPx=n)}onRightAxisPointerDown(e){if(e.isPrimary===!1)return;this.isTouchSession=e.pointerType===`touch`;let t=this.getRightAxisPointerLocation(e.clientX,e.clientY);t&&this.beginScalePriceDrag(e.clientY,t.mouseY)&&(this.chart.scheduleDraw(),this.notifyInteractionChange())}onRightAxisPointerMove(e){if(!e.isPrimary)return;if(e.pointerType===`touch`&&(this.isTouchSession=!0),this.isDragging&&this.dragMode===`scale-price`){let t=e.clientY-this.dragStartY;t!==0&&this.activePaneIdOnDrag&&(this.chart.scalePrice(this.activePaneIdOnDrag,t),this.dragStartY=e.clientY);return}this.updateRightAxisHoverFromPoint(e.clientX,e.clientY);let t=this.getHoverRenderKey();t!==this.lastHoverRenderKey&&(this.lastHoverRenderKey=t,this.chart.scheduleDraw(H.Overlay)),this.notifyInteractionChange()}onRightAxisPointerUp(e){this.onPointerUp(e)}onRightAxisPointerLeave(e){e.isPrimary!==!1&&(this.isDragging&&this.dragMode===`scale-price`||(this.hoveredRightAxisPaneId=null,this.notifyInteractionChange()))}isDraggingState(){return this.isDragging}setOnMarkerHover(e){this.markerState.setOnMarkerHover(e)}setOnMarkerClick(e){this.markerState.setOnMarkerClick(e)}setOnCustomMarkerHover(e){this.markerState.setOnCustomMarkerHover(e)}setOnCustomMarkerClick(e){this.markerState.setOnCustomMarkerClick(e)}hitTestPaneSeparator(e){let t=this.chart.getPaneRenderers();if(t.length<2)return null;for(let n=0;n<t.length-1;n++){let r=t[n]?.getPane(),i=t[n+1]?.getPane();if(!r||!i)continue;let a=r.top+r.height;if(Math.abs(e-a)<=5)return r.id}return null}getPaneByY(e){return this.chart.getPaneRenderers().find(t=>{let n=t.getPane();return e>=n.top&&e<=n.top+n.height})?.getPane()||null}getPlotPointerLocation(e,t){let n=this.chart.getDom().container.getBoundingClientRect();return{mouseX:e-n.left,mouseY:t-n.top}}getRightAxisPointerLocation(e,t){let n=this.chart.getDom().rightAxisLayer.getBoundingClientRect();return{mouseX:e-n.left,mouseY:t-n.top}}beginScalePriceDrag(e,t){let n=this.getPaneByY(t);return!n||n.id===`main`&&this.settings.disableMainPaneVerticalScroll?!1:(this.isDragging=!0,this.dragMode=`scale-price`,this.dragStartY=e,this.activePaneIdOnDrag=n.id,this.hoveredRightAxisPaneId=n.id,this.hoveredSeparatorUpperPaneId=null,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=n.id,!0)}clearHover(){this.lastHoverRenderKey=``,this.hoveredRightAxisPaneId=null,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=null,this.markerState.clearAll(this.chart.getMarkerManager())}clearSeparatorState(){this.activeSeparatorUpperPaneId=null,this.hoveredSeparatorUpperPaneId=null,this.hoveredRightAxisPaneId=null}updateRightAxisHoverFromPoint(e,t){let n=this.getRightAxisPointerLocation(e,t);if(!n)return;let{mouseY:r}=n,i=this.chart.getViewport()?.plotHeight??Math.max(1,Math.round(this.chart.getDom().container.clientHeight));if(r<0||r>i){this.hoveredRightAxisPaneId=null;return}let a=this.getPaneByY(r);this.hoveredRightAxisPaneId=a?.id||null,this.hoveredSeparatorUpperPaneId=null,this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=a?.id||null}updatePlotHoverFromPoint(e,t){let n=this.getPlotPointerLocation(e,t);if(!n)return;let{mouseX:r,mouseY:i}=n,a=this.chart.getDom().container,o=this.chart.getViewport(),s=o?.viewWidth??Math.max(1,Math.round(a.clientWidth)),c=o?.viewHeight??Math.max(1,Math.round(a.clientHeight)),l=o?.plotWidth??s,u=o?.plotHeight??c;if(r<0||i<0||r>l||i>u){this.clearHover();return}this.hoveredRightAxisPaneId=null;let d=this.chart.getCachedScrollLeft(),f=this.chart.getCurrentDpr(),p=this.hitTestPaneSeparator(i);if(this.hoveredSeparatorUpperPaneId=p,p){this.clearHover();return}let m=this.chart.getMarkerManager(),h=d+r;if(this.markerState.updateHoverFromPoint(h,r,i,m)){this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null;return}if(!this.kLinePositions||!this.visibleRange||!this.kWidthPx){this.clearHover();return}let g=this.kWidthPx/f,_=0,v=this.kLinePositions.length;for(;_<v;){let e=_+v>>1;this.kLinePositions[e]<h?_=e+1:v=e}let y=_;if(_>0&&_<this.kLinePositions.length){let e=this.kLinePositions[_-1]+g/2,t=this.kLinePositions[_]+g/2;Math.abs(h-e)<Math.abs(h-t)&&(y=_-1)}else _===this.kLinePositions.length&&this.kLinePositions.length>0&&(y=this.kLinePositions.length-1);let b=y+this.visibleRange.start,x=this.chart.getData(),S=this.getPaneByY(i);if(this.activePaneId=S?.id||null,b>=0&&b<(x?.length??0)){this.crosshairIndex=b;let e=this.kLinePositions[y],t=(Math.round(e*f)+(this.kWidthPx-1)/2)/f-d;if(this.crosshairPos={x:Math.min(Math.max(t,0),l),y:Math.min(Math.max(i,0),u)},S){let e=i-S.top;this.crosshairPrice=S.yAxis.yToPrice(e)}else this.crosshairPrice=null}else this.crosshairIndex=null,this.crosshairPos=null,this.crosshairPrice=null;let C=typeof this.crosshairIndex==`number`?x[this.crosshairIndex]:void 0;if(!C||!S||!S.capabilities.candleHitTest){this.hoveredIndex=null;return}let w=i-S.top,T=S.yAxis.priceToY(C.open),E=S.yAxis.priceToY(C.close),D=S.yAxis.priceToY(C.high),O=S.yAxis.priceToY(C.low),k=Math.min(T,E),A=Math.max(T,E),j=h-this.kLinePositions[y],M=g/2,N=Math.abs(A-k),P=N<8?(k+A)/2-8/2:k,F=N<8?(k+A)/2+8/2:A,I=w>=P&&w<=F&&j>=0&&j<=g,L=Math.abs(j-M)<=3&&w>=Math.min(D,O)&&w<=Math.max(D,O);if(!I&&!L){this.hoveredIndex=null;return}this.hoveredIndex=this.crosshairIndex;let ee=Qn({mouseX:r,mouseY:i,viewWidth:s,viewHeight:c,plotWidth:l,plotHeight:u,tooltipSize:this.tooltipSize,useAnchorPositioning:this.useTooltipAnchorPositioning});ee.anchorPlacement&&(this.tooltipAnchorPlacement=ee.anchorPlacement),this.tooltipPos=ee.pos}reset(){this.isDragging=!1,this.dragMode=`none`,this.dragStartX=0,this.dragStartY=0,this.scrollStartX=0,this.activePaneIdOnDrag=null,this.clearSeparatorState(),this.isTouchSession=!1,this.pinchTracker.reset(),this.crosshairPos=null,this.crosshairIndex=null,this.crosshairPrice=null,this.hoveredIndex=null,this.activePaneId=null,this.markerState.reset(),this.kLinePositions=null,this.visibleRange=null,this.lastHoverRenderKey=``,this.kWidthPx=null}getCrosshairIndex(){return this.crosshairIndex}},er=class{canvas;gl=null;constructor(e){this.canvas=e??document.createElement(`canvas`),this.gl=this.initContext()}isAvailable(){return this.gl!==null}getGL(){return this.gl}getCanvas(){return this.canvas}resize(e,t,n){let r=Math.max(1,Math.round(e*n)),i=Math.max(1,Math.round(t*n));this.canvas.width!==r&&(this.canvas.width=r),this.canvas.height!==i&&(this.canvas.height=i)}getPhysicalRegion(e){return this.toPhysicalRegion(e)}bindRegion(e){let t=this.gl,n=this.toPhysicalRegion(e);if(!t||!n)return!1;let r=this.canvas.height-n.sourceY-n.heightPx;return t.enable(t.SCISSOR_TEST),t.viewport(n.sourceX,r,n.widthPx,n.heightPx),t.scissor(n.sourceX,r,n.widthPx,n.heightPx),!0}clearRegion(e){let t=this.gl;!t||!this.bindRegion(e)||(t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT))}compositeRegionTo(e,t,n={}){let r=this.toPhysicalRegion(t);if(!r||r.widthPx<=0||r.heightPx<=0)return;let i=e.imageSmoothingEnabled,a=e.globalAlpha,o=e.getTransform();n.imageSmoothingEnabled!==void 0&&(e.imageSmoothingEnabled=n.imageSmoothingEnabled),n.alpha!==void 0&&(e.globalAlpha=a*n.alpha),e.setTransform(1,0,0,1,0,0),e.drawImage(this.canvas,r.sourceX,r.sourceY,r.widthPx,r.heightPx,0,0,r.widthPx,r.heightPx),e.setTransform(o),e.globalAlpha=a,e.imageSmoothingEnabled=i}destroy(){this.canvas.width=1,this.canvas.height=1,this.gl=null}toPhysicalRegion(e){let t=Math.max(0,Math.round(e.width*e.dpr)),n=Math.max(0,Math.round(e.height*e.dpr));return t<=0||n<=0?null:{sourceX:Math.max(0,Math.round(e.x*e.dpr)),sourceY:Math.max(0,Math.round(e.y*e.dpr)),widthPx:t,heightPx:n}}initContext(){try{return this.canvas.getContext(`webgl2`,{alpha:!0,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1})}catch{return null}}},tr=`#version 300 es
2
2
  precision mediump float;
3
3
 
4
4
  in vec2 a_unit;
@@ -20,7 +20,7 @@ void main() {
20
20
  );
21
21
 
22
22
  gl_Position = vec4(clip, 0.0, 1.0);
23
- }`,Gn=`#version 300 es
23
+ }`,nr=`#version 300 es
24
24
  precision mediump float;
25
25
 
26
26
  in vec2 a_position;
@@ -37,7 +37,7 @@ void main() {
37
37
  );
38
38
 
39
39
  gl_Position = vec4(clip, 0.0, 1.0);
40
- }`,Kn=`#version 300 es
40
+ }`,rr=`#version 300 es
41
41
  precision mediump float;
42
42
 
43
43
  uniform vec4 u_color;
@@ -45,5 +45,5 @@ out vec4 outColor;
45
45
 
46
46
  void main() {
47
47
  outColor = u_color;
48
- }`,qn=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),Jn=class{canvas;handles=null;logicalWidth=0;logicalHeight=0;available=!1;rectCapacity=0;rectScratch=new Float32Array;constructor(e){this.canvas=e??document.createElement(`canvas`),this.handles=this.initRectHandles(),this.available=this.handles!==null}isAvailable(){return this.available}getCanvas(){return this.canvas}resize(e,t,n){this.logicalWidth=e,this.logicalHeight=t;let r=Math.max(1,Math.round(e*n)),i=Math.max(1,Math.round(t*n));this.canvas.width!==r&&(this.canvas.width=r),this.canvas.height!==i&&(this.canvas.height=i)}clear(){let e=this.handles?.gl;!e||this.logicalWidth<=0||this.logicalHeight<=0||(e.viewport(0,0,this.canvas.width,this.canvas.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT))}drawRectBuffer(e,t,n,r){let i=this.handles;if(!i||t===0||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let a=tr(n);if(!a)return!1;let o=t*4,{gl:s}=i;return s.useProgram(i.program),s.bindVertexArray(i.vao),s.bindBuffer(s.ARRAY_BUFFER,i.rectBuffer),this.rectCapacity<o&&(this.rectCapacity=Xn(o),s.bufferData(s.ARRAY_BUFFER,this.rectCapacity*Float32Array.BYTES_PER_ELEMENT,s.DYNAMIC_DRAW)),s.bufferSubData(s.ARRAY_BUFFER,0,e),a[3]===1?s.disable(s.BLEND):s.enable(s.BLEND),s.uniform2f(i.resolutionLocation,this.logicalWidth,this.logicalHeight),s.uniform1f(i.scrollXLocation,r),s.uniform4f(i.colorLocation,a[0],a[1],a[2],a[3]),s.drawArraysInstanced(s.TRIANGLES,0,6,t),s.bindVertexArray(null),!0}drawRects(e,t,n){if(!this.handles||!e.length||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let r=e.length*4;this.rectScratch.length<r&&(this.rectScratch=new Float32Array(Xn(r)));for(let t=0;t<e.length;t++){let n=e[t],r=t*4;this.rectScratch[r]=n.x,this.rectScratch[r+1]=n.y,this.rectScratch[r+2]=n.width,this.rectScratch[r+3]=n.height}return this.drawRectBuffer(this.rectScratch.subarray(0,r),e.length,t,n)}destroy(){let e=this.handles;if(!e)return;let{gl:t,program:n,vao:r,unitBuffer:i,rectBuffer:a}=e;t.deleteBuffer(i),t.deleteBuffer(a),t.deleteVertexArray(r),t.deleteProgram(n),this.handles=null,this.available=!1}initRectHandles(){let e=null;try{e=this.canvas.getContext(`webgl2`,{alpha:!0,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1})}catch{e=null}if(!e)return null;console.log(`[CandleWebGLSurface] 抗锯齿已禁用 (antialias: false, 无AA着色器)`);let t=Qn(e,e.VERTEX_SHADER,Wn),n=Qn(e,e.FRAGMENT_SHADER,Kn);if(!t||!n)return t&&e.deleteShader(t),n&&e.deleteShader(n),null;let r=$n(e,t,n);if(e.deleteShader(t),e.deleteShader(n),!r)return null;let i=e.createVertexArray(),a=e.createBuffer(),o=e.createBuffer();if(!i||!a||!o)return i&&e.deleteVertexArray(i),a&&e.deleteBuffer(a),o&&e.deleteBuffer(o),e.deleteProgram(r),null;let s=e.getUniformLocation(r,`u_resolution`),c=e.getUniformLocation(r,`u_scrollX`),l=e.getUniformLocation(r,`u_color`);if(!s||!c||!l)return e.deleteBuffer(a),e.deleteBuffer(o),e.deleteVertexArray(i),e.deleteProgram(r),null;let u=e.getAttribLocation(r,`a_unit`),d=e.getAttribLocation(r,`a_rect`);return u<0||d<0?(e.deleteBuffer(a),e.deleteBuffer(o),e.deleteVertexArray(i),e.deleteProgram(r),null):(e.bindVertexArray(i),e.bindBuffer(e.ARRAY_BUFFER,a),e.bufferData(e.ARRAY_BUFFER,qn,e.STATIC_DRAW),e.enableVertexAttribArray(u),e.vertexAttribPointer(u,2,e.FLOAT,!1,0,0),e.vertexAttribDivisor(u,0),e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(d),e.vertexAttribPointer(d,4,e.FLOAT,!1,16,0),e.vertexAttribDivisor(d,1),e.bindVertexArray(null),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),{gl:e,program:r,vao:i,unitBuffer:a,rectBuffer:o,resolutionLocation:s,scrollXLocation:c,colorLocation:l})}},Yn=class{canvas;handles=null;logicalWidth=0;logicalHeight=0;dpr=1;available=!1;vertexCapacity=0;fillScratch=new Float32Array;lineScratch=new Float32Array;geoCache=new WeakMap;constructor(e){this.canvas=e??document.createElement(`canvas`),this.handles=this.initLineHandles(),this.available=this.handles!==null}isAvailable(){return this.available}getCanvas(){return this.canvas}resize(e,t,n){this.logicalWidth=e,this.logicalHeight=t,this.dpr=n;let r=Math.max(1,Math.round(e*n)),i=Math.max(1,Math.round(t*n));this.canvas.width!==r&&(this.canvas.width=r),this.canvas.height!==i&&(this.canvas.height=i)}clear(){let e=this.handles?.gl;!e||this.logicalWidth<=0||this.logicalHeight<=0||(e.viewport(0,0,this.canvas.width,this.canvas.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT))}drawLineStrips(e,t){let n=this.handles;if(!n||e.length===0||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let r=[],i=0;for(let t of e){if(t.points.length<2)return!1;let e=tr(t.color);if(!e)return!1;if(t.width===1){let{vertexCount:a,vertices:o}=this.getThinLineVertices(t.points);r.push({colorValue:e,mode:n.gl.LINE_STRIP,firstVertex:i/2,pointCount:a}),i+=o.length}else{let a=this.getLineGeometry(t);if(!a)return!1;r.push({colorValue:e,mode:n.gl.TRIANGLES,firstVertex:i/2,pointCount:a.vertexCount}),i+=a.vertices.length}}this.lineScratch.length<i&&(this.lineScratch=new Float32Array(Xn(i)));let a=0;for(let t of e){let e=t.width===1?this.getThinLineVertices(t.points).vertices:this.getLineGeometry(t).vertices;this.lineScratch.set(e,a),a+=e.length}let{gl:o}=n;o.useProgram(n.basic.program),o.bindVertexArray(n.basic.vao),o.bindBuffer(o.ARRAY_BUFFER,n.basic.vertexBuffer),this.vertexCapacity<i&&(this.vertexCapacity=Xn(i),o.bufferData(o.ARRAY_BUFFER,this.vertexCapacity*Float32Array.BYTES_PER_ELEMENT,o.DYNAMIC_DRAW)),o.bufferSubData(o.ARRAY_BUFFER,0,this.lineScratch.subarray(0,i)),o.uniform2f(n.basic.resolutionLocation,this.logicalWidth,this.logicalHeight),o.uniform1f(n.basic.scrollXLocation,t);for(let e of r)o.uniform4f(n.basic.colorLocation,e.colorValue[0],e.colorValue[1],e.colorValue[2],e.colorValue[3]),o.drawArrays(e.mode,e.firstVertex,e.pointCount);return o.bindVertexArray(null),!0}getThinLineVertices(e){let t=this.geoCache.get(e);if(t){let e=t.get(0);if(e)return e}else t=new Map,this.geoCache.set(e,t);let n=e.length,r=new Float32Array(n*2),i=0;for(let t of e)r[i++]=t.x,r[i++]=t.y;let a={vertices:r,vertexCount:n};return t.set(0,a),a}getLineGeometry(e){let t=e.width/2,n=this.geoCache.get(e.points);if(n){let e=n.get(t);if(e)return e}else n=new Map,this.geoCache.set(e.points,n);let r=Zn(e.points,t);return r&&n.set(t,r),r}drawFilledBand(e,t,n){let r=this.handles,i=Math.min(e.upperPoints.length,e.lowerPoints.length);if(!r||i<2||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let a=tr(t);if(!a)return!1;let o=i*2,s=o*2;this.fillScratch.length<s&&(this.fillScratch=new Float32Array(Xn(s)));let c=0;for(let t=0;t<i;t++){let n=e.upperPoints[t],r=e.lowerPoints[t];this.fillScratch[c++]=n.x,this.fillScratch[c++]=n.y,this.fillScratch[c++]=r.x,this.fillScratch[c++]=r.y}let{gl:l}=r;return l.useProgram(r.basic.program),l.bindVertexArray(r.basic.vao),l.bindBuffer(l.ARRAY_BUFFER,r.basic.vertexBuffer),this.vertexCapacity<s&&(this.vertexCapacity=Xn(s),l.bufferData(l.ARRAY_BUFFER,this.vertexCapacity*Float32Array.BYTES_PER_ELEMENT,l.DYNAMIC_DRAW)),l.bufferSubData(l.ARRAY_BUFFER,0,this.fillScratch.subarray(0,s)),l.uniform2f(r.basic.resolutionLocation,this.logicalWidth,this.logicalHeight),l.uniform1f(r.basic.scrollXLocation,n),l.uniform4f(r.basic.colorLocation,a[0],a[1],a[2],a[3]),l.drawArrays(l.TRIANGLE_STRIP,0,o),l.bindVertexArray(null),!0}destroy(){let e=this.handles;if(!e){this.vertexCapacity=0;return}let{gl:t,basic:n}=e;t.deleteBuffer(n.vertexBuffer),t.deleteVertexArray(n.vao),t.deleteProgram(n.program),this.handles=null,this.available=!1,this.vertexCapacity=0}initLineHandles(){let e=null;try{e=this.canvas.getContext(`webgl2`,{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1})}catch{e=null}if(!e)return null;let t=Qn(e,e.VERTEX_SHADER,Gn),n=Qn(e,e.FRAGMENT_SHADER,Kn);if(!t||!n)return t&&e.deleteShader(t),n&&e.deleteShader(n),null;let r=$n(e,t,n);if(e.deleteShader(t),e.deleteShader(n),!r)return null;let i=e.createVertexArray(),a=e.createBuffer();if(!i||!a)return i&&e.deleteVertexArray(i),a&&e.deleteBuffer(a),e.deleteProgram(r),null;let o=e.getUniformLocation(r,`u_resolution`),s=e.getUniformLocation(r,`u_scrollX`),c=e.getUniformLocation(r,`u_color`);if(!o||!s||!c)return e.deleteBuffer(a),e.deleteVertexArray(i),e.deleteProgram(r),null;let l=e.getAttribLocation(r,`a_position`);return l<0?(e.deleteBuffer(a),e.deleteVertexArray(i),e.deleteProgram(r),null):(e.bindVertexArray(i),e.bindBuffer(e.ARRAY_BUFFER,a),e.enableVertexAttribArray(l),e.vertexAttribPointer(l,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),{gl:e,basic:{program:r,vao:i,vertexBuffer:a,resolutionLocation:o,scrollXLocation:s,colorLocation:c}})}};function Xn(e){let t=1;for(;t<e;)t<<=1;return t}function Zn(e,t){if(e.length<2)return null;let n=Array(e.length-1),r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1],o=a.x-i.x,s=a.y-i.y,c=o*o+s*s;if(c<=0){n[t]={nx:0,ny:0,valid:!1};continue}let l=1/Math.sqrt(c);n[t]={nx:-s*l,ny:o*l,valid:!0},r++}if(r===0)return null;let i=(e.length-1)*12,a=new Float32Array(i),o=0;for(let r=0;r<e.length-1;r++){let i=e[r],s=e[r+1],c=r>0?n[r-1]:null,l=n[r];if(!l.valid||!c&&!l.valid)continue;let u=0,d=0;if(c?.valid&&l.valid){u=c.nx+l.nx,d=c.ny+l.ny;let e=u*u+d*d;if(e>1e-12){let t=1/Math.sqrt(e);u*=t,d*=t;let n=u*l.nx+d*l.ny,r=1/Math.max(.2,Math.abs(n));u*=r,d*=r}else u=l.nx,d=l.ny}else if(l.valid)u=l.nx,d=l.ny;else if(c?.valid)u=c.nx,d=c.ny;else continue;let f=l.nx,p=l.ny,m=r<e.length-2?n[r+1]:null;if(m?.valid&&l.valid){f=l.nx+m.nx,p=l.ny+m.ny;let e=f*f+p*p;if(e>1e-12){let t=1/Math.sqrt(e);f*=t,p*=t;let n=f*m.nx+p*m.ny,r=1/Math.max(.2,Math.abs(n));f*=r,p*=r}else f=l.nx,p=l.ny}let h=i.x+u*t,g=i.y+d*t,_=i.x-u*t,v=i.y-d*t,y=s.x+f*t,b=s.y+p*t,x=s.x-f*t,S=s.y-p*t;a[o++]=h,a[o++]=g,a[o++]=_,a[o++]=v,a[o++]=y,a[o++]=b,a[o++]=y,a[o++]=b,a[o++]=_,a[o++]=v,a[o++]=x,a[o++]=S}return o===0?null:{vertices:o===i?a:a.subarray(0,o),vertexCount:o/2}}function Qn(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null}function $n(e,t,n){let r=e.createProgram();return r?(e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(e.deleteProgram(r),null)):null}var er=new Map;function tr(e){let t=er.get(e);if(t)return t;let n=e.trim().toLowerCase(),r=null;if(n.startsWith(`rgba(`)){let e=n.slice(5,-1).split(`,`).map(e=>Number(e.trim()));e.length===4&&e.every(e=>Number.isFinite(e))&&(r=[e[0]/255,e[1]/255,e[2]/255,e[3]])}else if(n.startsWith(`rgb(`)){let e=n.slice(4,-1).split(`,`).map(e=>Number(e.trim()));e.length===3&&e.every(e=>Number.isFinite(e))&&(r=[e[0]/255,e[1]/255,e[2]/255,1])}else if(n.startsWith(`#`)){let e=n.slice(1);e.length===6?r=[Number.parseInt(e.slice(0,2),16)/255,Number.parseInt(e.slice(2,4),16)/255,Number.parseInt(e.slice(4,6),16)/255,1]:e.length===3&&(r=[Number.parseInt(e[0]+e[0],16)/255,Number.parseInt(e[1]+e[1],16)/255,Number.parseInt(e[2]+e[2],16)/255,1])}return r&&er.set(e,r),r}var nr=class{dom;pane;opt;contexts=null;webgl;constructor(e,t,n){this.dom=e,this.pane=t,this.opt={...n,priceLabelWidth:n.priceLabelWidth||60},this.webgl={candleSurface:new Jn,lineSurface:new Yn}}getPane(){return this.pane}getDom(){return this.dom}getContexts(){return this.contexts||={mainCtx:this.dom.mainCanvas.getContext(`2d`),overlayCtx:this.dom.overlayCanvas.getContext(`2d`,{desynchronized:!0}),yAxisCtx:this.dom.yAxisCanvas.getContext(`2d`)},this.contexts}getWebGL(){return this.webgl}resize(e,t,n){let r=this.dom.mainCanvas,i=this.dom.overlayCanvas,a=this.dom.yAxisCanvas,o=this.opt.rightAxisWidth+(this.opt.priceLabelWidth||60),s=a.parentElement?.clientWidth??0,c=s>0?s:o,l=Math.round(e*n);r.width!==l&&(r.width=l);let u=Math.round(t*n);r.height!==u&&(r.height=u);let d=`${l/n}px`;r.style.width!==d&&(r.style.width=d);let f=`${u/n}px`;r.style.height!==f&&(r.style.height=f),i.width!==l&&(i.width=l),i.height!==u&&(i.height=u),i.style.width!==d&&(i.style.width=d),i.style.height!==f&&(i.style.height=f);let p=Math.round(c*n);a.width!==p&&(a.width=p);let m=Math.round(t*n);a.height!==m&&(a.height=m);let h=`${p/n}px`;a.style.width!==h&&(a.style.width=h);let g=`${m/n}px`;a.style.height!==g&&(a.style.height=g),this.webgl.candleSurface?.resize(e,t,n),this.webgl.lineSurface?.resize(e,t,n)}destroy(){this.contexts=null,this.webgl.candleSurface?.destroy(),this.webgl.lineSurface?.destroy()}};function rr(e){let{dataLength:t,kWidth:n,kGap:r,viewWidth:i,viewportDpr:a}=e;if(t===0)return 0;let{startXPx:o,unitPx:s}=R(n,r,a),c=(o+(t+24)*s)/a;return Math.max(c,i)}function ir(t){let n=(0,e.reactive)({zoomLevel:t.initialZoomLevel,kWidth:0,kGap:1,viewportDpr:1,dataLength:0,dataVersion:0,paneRatios:{},drawings:[],selectedDrawingId:null,drawingVersion:0,viewWidth:0}),r=(0,e.computed)(()=>t.rightAxisWidth+t.priceLabelWidth),i=(0,e.computed)(()=>rr({dataLength:n.dataLength,kWidth:n.kWidth,kGap:n.kGap,viewWidth:n.viewWidth,viewportDpr:n.viewportDpr}));function a(){n.dataVersion++}function o(){n.drawingVersion++}function s(e){n.dataLength=e}function c(e){n.viewportDpr=e}function l(e){n.viewWidth=e}function u(e,t,r){n.zoomLevel=e,n.kWidth=t,n.kGap=r}function d(e){n.paneRatios=e}function f(e){n.drawings=e,n.selectedDrawingId&&!e.some(e=>e.id===n.selectedDrawingId)&&(n.selectedDrawingId=null),n.drawingVersion++}function p(e){n.selectedDrawingId=e}return{state:n,computed:{axisHostWidth:r,totalWidth:i},actions:{bumpDataVersion:a,bumpDrawingVersion:o,setDataLength:s,setViewportDpr:c,setViewWidth:l,setZoomState:u,setPaneRatios:d,setDrawings:f,setSelectedDrawingId:p}}}var ar=[5,10,20,30,60];function or(e,t,n){let r=Array(e.length);if(e.length<t)return r;let i=0,a=[];for(let n=0;n<t;n++){let t=e[n];if(!t)return r;let o=t.close;a.push(o),i+=o}for(let o=t-1;o<e.length;o++){let s=e[o];if(!s)continue;if(o>=t){let e=a.shift();e!==void 0&&(i-=e);let t=s.close;a.push(t),i+=t}let c=i/t,l=0;for(let e=0;e<t;e++){let t=a[e];t!==void 0&&(l+=(t-c)**2)}let u=Math.sqrt(l/t);r[o]={upper:c+n*u,middle:c,lower:c-n*u}}return r}function sr(e,t,n){let r=Array(e.length);if(e.length===0)return r;let i=2/(t+1),a=2/(n+1),o=e[0].close,s=o,c=o;r[0]={fast:s,slow:c};for(let t=1;t<e.length;t++){let n=e[t].close;s=n*i+s*(1-i),c=n*a+c*(1-a),r[t]={fast:s,slow:c}}return r}function cr(e,t,n){let r=Array(e.length);if(e.length<t)return r;let i=0;for(let n=0;n<t;n++){let t=e[n];if(!t)return r;i+=t.close}let a=i/t,o=n/100;r[t-1]={upper:a*(1+o),middle:a,lower:a*(1-o)};for(let a=t;a<e.length;a++){let o=e[a-t],s=e[a];if(!o||!s)continue;i=i-o.close+s.close;let c=i/t,l=n/100;r[a]={upper:c*(1+l),middle:c,lower:c*(1-l)}}return r}function lr(e,t){let n=Array(e.length);if(e.length<t)return n;let r=0;for(let i=0;i<t;i++){let t=e[i];if(!t)return n;r+=t.close}n[t-1]=r/t;for(let i=t;i<e.length;i++){let a=e[i-t],o=e[i];!a||!o||(r=r-a.close+o.close,n[i]=r/t)}return n}function ur(e,t){let n=Array(e.length);if(e.length<t+1)return n;let r=[];for(let t=1;t<e.length;t++)r.push(e[t].close-e[t-1].close);let i=0,a=0;for(let e=0;e<t;e++){let t=r[e];t!==void 0&&(t>0?i+=t:a+=Math.abs(t))}let o=i/t,s=a/t;s===0?n[t]=100:n[t]=100-100/(1+o/s);for(let e=t;e<r.length;e++){let i=r[e];if(i!==void 0)if(i>0?(o=(o*(t-1)+i)/t,s=s*(t-1)/t):(o=o*(t-1)/t,s=(s*(t-1)+Math.abs(i))/t),s===0)n[e+1]=100;else{let t=o/s;n[e+1]=100-100/(1+t)}}return n}function dr(e,t){let n=Array(e.length);if(e.length<t)return n;let r=[];for(let t of e)r.push((t.high+t.low+t.close)/3);let i=0;for(let e=0;e<t;e++)i+=r[e];for(let a=t-1;a<e.length;a++){a>=t&&(i=i-r[a-t]+r[a]);let e=i/t,o=0;for(let n=0;n<t;n++)o+=Math.abs(r[a-n]-e);o/=t,o===0?n[a]=0:n[a]=(r[a]-e)/(.015*o)}return n}function fr(e,t,n){let r=Array(e.length);if(e.length<t)return r;let i=Array(e.length);for(let n=t-1;n<e.length;n++){let r=-1/0,a=1/0;for(let i=0;i<t;i++){let t=e[n-i];t&&(r=Math.max(r,t.high),a=Math.min(a,t.low))}let o=e[n].close;r===a?i[n]=50:i[n]=(o-a)/(r-a)*100}for(let a=t-1+n-1;a<e.length;a++){let e=i[a];if(e===void 0)continue;let t=0,o=0;for(let e=0;e<n;e++){let n=i[a-e];n!==void 0&&(t+=n,o++)}o===n&&(r[a]={k:e,d:t/n})}return r}function pr(e,t){let n=Array(e.length);if(e.length<t+1)return n;for(let r=t;r<e.length;r++){let i=e[r]?.close,a=e[r-t]?.close;i!==void 0&&a!==void 0&&(n[r]=i-a)}return n}function mr(e,t){let n=Array(e.length);if(e.length<t)return n;for(let r=t-1;r<e.length;r++){let i=-1/0,a=1/0;for(let n=0;n<t;n++){let t=e[r-n];t&&(i=Math.max(i,t.high),a=Math.min(a,t.low))}let o=e[r].close;i===a?n[r]=-50:n[r]=(i-o)/(i-a)*-100}return n}function hr(e,t){let n=Array(e.length);if(e.length<t+1)return n;for(let r=t;r<e.length;r++){let i=e[r]?.close,a=e[r-t]?.close;i!==void 0&&a!==void 0&&a!==0&&(n[r]=(i-a)/a*100)}return n}function gr(e,t){let n=Array(e.length),r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o!==void 0){if(r+=o,i++,i>t){let n=e[a-t];n!==void 0&&(r-=n,i--)}i===t&&(n[a]=r/t)}}return n}function _r(e,t,n,r,i,a){let o=Array(e.length),s=hr(e,t),c=hr(e,n),l=hr(e,r),u=hr(e,i),d=gr(s,10),f=gr(c,10),p=gr(l,10),m=gr(u,15),h=Array(e.length);for(let t=0;t<e.length;t++){let e=d[t],n=f[t],r=p[t],i=m[t];e!==void 0&&n!==void 0&&r!==void 0&&i!==void 0&&(h[t]=e*1+n*2+r*3+i*4)}let g=gr(h,a);for(let t=0;t<e.length;t++){let e=h[t],n=g[t];e!==void 0&&n!==void 0&&(o[t]={kst:e,signal:n})}return o}function vr(e,t){let n=Array(e.length);if(e.length<t)return n;for(let r=t-1;r<e.length;r++){let i=-1/0,a=1/0;for(let n=0;n<t;n++){let t=e[r-n];t&&(i=Math.max(i,t.high),a=Math.min(a,t.low))}let o=e[r].close;i===a?n[r]=50:n[r]=(o-a)/(i-a)*100}return n}function yr(e,t){let n=Array(e.length),r=2/(t+1);if(e.length===0)return n;n[0]=e[0].close;for(let t=1;t<e.length;t++){let i=e[t];i&&(n[t]=i.close*r+n[t-1]*(1-r))}return n}function br(e,t){let n=Array(e.length),r=2/(t+1),i=e.findIndex(e=>e!==void 0);if(i===-1)return n;n[i]=e[i];for(let t=i+1;t<e.length;t++){let i=e[t],a=n[t-1];i===void 0||a===void 0||(n[t]=i*r+a*(1-r))}return n}function xr(e,t,n,r){let i=Array(e.length);if(e.length<n)return i;let a=yr(e,t),o=yr(e,n),s=Array(e.length);for(let t=0;t<e.length;t++){let e=a[t],n=o[t];e!==void 0&&n!==void 0&&(s[t]=e-n)}let c=br(s,r);for(let t=0;t<e.length;t++){let e=s[t],n=c[t];e!==void 0&&n!==void 0&&(i[t]={dif:e,dea:n,macd:(e-n)*2})}return i}var Sr=class{currentData=[];dataVersion=0;config=this.getDefaultConfig();configVersion=0;cachedSeries={};cachedBollSeries=[];cachedExpmaSeries=[];cachedEneSeries=[];cachedRsiSeries={};cachedCciSeries=[];cachedStochSeries=[];cachedMomSeries=[];cachedWmsrSeries=[];cachedKstSeries=[];cachedFastkSeries=[];cachedMacdSeries=[];dirtyData=!0;dirtyMAConfig=!0;dirtyBollConfig=!0;dirtyExpmaConfig=!0;dirtyEneConfig=!0;dirtyRsiConfig=!0;dirtyCciConfig=!0;dirtyStochConfig=!0;dirtyMomConfig=!0;dirtyWmsrConfig=!0;dirtyKstConfig=!0;dirtyFastkConfig=!0;dirtyMacdConfig=!0;getDefaultConfig(){return{ma:{ma5:!0,ma10:!0,ma20:!0,ma30:!0,ma60:!0},boll:{period:20,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0,showBand:!0},expma:{fastPeriod:12,slowPeriod:50},ene:{period:10,deviation:11},rsi:{period1:6,period2:12,period3:24,showRSI1:!0,showRSI2:!0,showRSI3:!0},cci:{period:14,showCCI:!0},stoch:{n:9,m:3,showK:!0,showD:!0},mom:{period:10,showMOM:!0},wmsr:{period:14,showWMSR:!0},kst:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},fastk:{period:9,showFASTK:!0},macd:{fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0},rsiPaneId:`sub_RSI`,cciPaneId:`sub_CCI`,stochPaneId:`sub_STOCH`,momPaneId:`sub_MOM`,wmsrPaneId:`sub_WMSR`,kstPaneId:`sub_KST`,fastkPaneId:`sub_FASTK`,macdPaneId:`sub_MACD`}}setData(e,t){this.dataVersion===t&&!this.dirtyData||(this.currentData=e,this.dataVersion=t,this.dirtyData=!0)}shallowEqual(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}setConfig(e,t){e.ma!==void 0&&!this.shallowEqual(e.ma,this.config.ma)&&(this.config.ma={...this.config.ma,...e.ma},this.dirtyMAConfig=!0),e.boll!==void 0&&!this.shallowEqual(e.boll,this.config.boll)&&(this.config.boll={...this.config.boll,...e.boll},this.dirtyBollConfig=!0),e.expma!==void 0&&!this.shallowEqual(e.expma,this.config.expma)&&(this.config.expma={...this.config.expma,...e.expma},this.dirtyExpmaConfig=!0),e.ene!==void 0&&!this.shallowEqual(e.ene,this.config.ene)&&(this.config.ene={...this.config.ene,...e.ene},this.dirtyEneConfig=!0),e.rsi!==void 0&&!this.shallowEqual(e.rsi,this.config.rsi)&&(this.config.rsi={...this.config.rsi,...e.rsi},this.dirtyRsiConfig=!0),e.cci!==void 0&&!this.shallowEqual(e.cci,this.config.cci)&&(this.config.cci={...this.config.cci,...e.cci},this.dirtyCciConfig=!0),e.stoch!==void 0&&!this.shallowEqual(e.stoch,this.config.stoch)&&(this.config.stoch={...this.config.stoch,...e.stoch},this.dirtyStochConfig=!0),e.mom!==void 0&&!this.shallowEqual(e.mom,this.config.mom)&&(this.config.mom={...this.config.mom,...e.mom},this.dirtyMomConfig=!0),e.wmsr!==void 0&&!this.shallowEqual(e.wmsr,this.config.wmsr)&&(this.config.wmsr={...this.config.wmsr,...e.wmsr},this.dirtyWmsrConfig=!0),e.kst!==void 0&&!this.shallowEqual(e.kst,this.config.kst)&&(this.config.kst={...this.config.kst,...e.kst},this.dirtyKstConfig=!0),e.fastk!==void 0&&!this.shallowEqual(e.fastk,this.config.fastk)&&(this.config.fastk={...this.config.fastk,...e.fastk},this.dirtyFastkConfig=!0),e.macd!==void 0&&!this.shallowEqual(e.macd,this.config.macd)&&(this.config.macd={...this.config.macd,...e.macd},this.dirtyMacdConfig=!0),e.rsiPaneId!==void 0&&(this.config.rsiPaneId=e.rsiPaneId),e.cciPaneId!==void 0&&(this.config.cciPaneId=e.cciPaneId),e.stochPaneId!==void 0&&(this.config.stochPaneId=e.stochPaneId),e.momPaneId!==void 0&&(this.config.momPaneId=e.momPaneId),e.wmsrPaneId!==void 0&&(this.config.wmsrPaneId=e.wmsrPaneId),e.kstPaneId!==void 0&&(this.config.kstPaneId=e.kstPaneId),e.fastkPaneId!==void 0&&(this.config.fastkPaneId=e.fastkPaneId),e.macdPaneId!==void 0&&(this.config.macdPaneId=e.macdPaneId),this.configVersion=t}forceDirty(){this.dirtyData=!0,this.dirtyMAConfig=!0,this.dirtyBollConfig=!0,this.dirtyExpmaConfig=!0,this.dirtyEneConfig=!0,this.dirtyRsiConfig=!0,this.dirtyCciConfig=!0,this.dirtyStochConfig=!0,this.dirtyMomConfig=!0,this.dirtyWmsrConfig=!0,this.dirtyKstConfig=!0,this.dirtyFastkConfig=!0,this.dirtyMacdConfig=!0}getDataVersion(){return this.dataVersion}getConfigVersion(){return this.configVersion}computeSeries(){let e=this.currentData,t=[];if(this.dirtyData||this.dirtyMAConfig){this.cachedSeries={};for(let t of ar){let n=`ma${t}`;this.config.ma[n]&&(this.cachedSeries[t]=lr(e,t))}t.push(`ma`)}if((this.dirtyData||this.dirtyBollConfig)&&(this.cachedBollSeries=or(e,this.config.boll.period,this.config.boll.multiplier),t.push(`boll`)),(this.dirtyData||this.dirtyExpmaConfig)&&(this.cachedExpmaSeries=sr(e,this.config.expma.fastPeriod,this.config.expma.slowPeriod),t.push(`expma`)),(this.dirtyData||this.dirtyEneConfig)&&(this.cachedEneSeries=cr(e,this.config.ene.period,this.config.ene.deviation),t.push(`ene`)),this.dirtyData||this.dirtyRsiConfig){this.cachedRsiSeries={};let n=[this.config.rsi.period1,this.config.rsi.period2,this.config.rsi.period3],r=[this.config.rsi.showRSI1,this.config.rsi.showRSI2,this.config.rsi.showRSI3];for(let t=0;t<n.length;t++)r[t]&&(this.cachedRsiSeries[n[t]]=ur(e,n[t]));t.push(`rsi`)}return(this.dirtyData||this.dirtyCciConfig)&&(this.config.cci.showCCI?this.cachedCciSeries=dr(e,this.config.cci.period):this.cachedCciSeries=[],t.push(`cci`)),(this.dirtyData||this.dirtyStochConfig)&&(this.config.stoch.showK||this.config.stoch.showD?this.cachedStochSeries=fr(e,this.config.stoch.n,this.config.stoch.m):this.cachedStochSeries=[],t.push(`stoch`)),(this.dirtyData||this.dirtyMomConfig)&&(this.config.mom.showMOM?this.cachedMomSeries=pr(e,this.config.mom.period):this.cachedMomSeries=[],t.push(`mom`)),(this.dirtyData||this.dirtyWmsrConfig)&&(this.config.wmsr.showWMSR?this.cachedWmsrSeries=mr(e,this.config.wmsr.period):this.cachedWmsrSeries=[],t.push(`wmsr`)),(this.dirtyData||this.dirtyKstConfig)&&(this.config.kst.showKST||this.config.kst.showSignal?this.cachedKstSeries=_r(e,this.config.kst.roc1,this.config.kst.roc2,this.config.kst.roc3,this.config.kst.roc4,this.config.kst.signalPeriod):this.cachedKstSeries=[],t.push(`kst`)),(this.dirtyData||this.dirtyFastkConfig)&&(this.config.fastk.showFASTK?this.cachedFastkSeries=vr(e,this.config.fastk.period):this.cachedFastkSeries=[],t.push(`fastk`)),(this.dirtyData||this.dirtyMacdConfig)&&(this.config.macd.showDIF||this.config.macd.showDEA||this.config.macd.showBAR?this.cachedMacdSeries=xr(e,this.config.macd.fastPeriod,this.config.macd.slowPeriod,this.config.macd.signalPeriod):this.cachedMacdSeries=[],t.push(`macd`)),this.dirtyData=!1,this.dirtyMAConfig=!1,this.dirtyBollConfig=!1,this.dirtyExpmaConfig=!1,this.dirtyEneConfig=!1,this.dirtyRsiConfig=!1,this.dirtyCciConfig=!1,this.dirtyStochConfig=!1,this.dirtyMomConfig=!1,this.dirtyWmsrConfig=!1,this.dirtyKstConfig=!1,this.dirtyFastkConfig=!1,this.dirtyMacdConfig=!1,{ma:{series:this.cachedSeries,enabledPeriods:Object.keys(this.cachedSeries).map(Number)},boll:{series:this.cachedBollSeries,params:{...this.config.boll}},expma:{series:this.cachedExpmaSeries,params:{...this.config.expma}},ene:{series:this.cachedEneSeries,params:{...this.config.ene}},rsi:{series:this.cachedRsiSeries,enabledPeriods:Object.keys(this.cachedRsiSeries).map(Number),params:{...this.config.rsi}},cci:{series:this.cachedCciSeries,params:{...this.config.cci}},stoch:{series:this.cachedStochSeries,params:{...this.config.stoch}},mom:{series:this.cachedMomSeries,params:{...this.config.mom}},wmsr:{series:this.cachedWmsrSeries,params:{...this.config.wmsr}},kst:{series:this.cachedKstSeries,params:{...this.config.kst}},fastk:{series:this.cachedFastkSeries,params:{...this.config.fastk}},macd:{series:this.cachedMacdSeries,params:{...this.config.macd}},_changed:t}}getCachedSeries(){return{_changed:[],ma:{series:this.cachedSeries,enabledPeriods:Object.keys(this.cachedSeries).map(Number)},boll:{series:this.cachedBollSeries,params:{...this.config.boll}},expma:{series:this.cachedExpmaSeries,params:{...this.config.expma}},ene:{series:this.cachedEneSeries,params:{...this.config.ene}},rsi:{series:this.cachedRsiSeries,enabledPeriods:Object.keys(this.cachedRsiSeries).map(Number),params:{...this.config.rsi}},cci:{series:this.cachedCciSeries,params:{...this.config.cci}},stoch:{series:this.cachedStochSeries,params:{...this.config.stoch}},mom:{series:this.cachedMomSeries,params:{...this.config.mom}},wmsr:{series:this.cachedWmsrSeries,params:{...this.config.wmsr}},kst:{series:this.cachedKstSeries,params:{...this.config.kst}},fastk:{series:this.cachedFastkSeries,params:{...this.config.fastk}},macd:{series:this.cachedMacdSeries,params:{...this.config.macd}}}}};function Cr(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.type==`string`?[`ready`,`seriesResult`,`error`].includes(t.type):!1}var Q=(e,t)=>`indicator:${e}:${t}`,wr=e=>Q(`rsi`,e),Tr={timestamp:0,series:{},enabledPeriods:[],params:{period1:6,period2:12,period3:24,showRSI1:!0,showRSI2:!0,showRSI3:!0},valueMin:0,valueMax:100,visibleMin:1/0,visibleMax:-1/0},Er=e=>Q(`cci`,e),Dr={timestamp:0,series:[],params:{period:14,showCCI:!0},valueMin:-150,valueMax:150,visibleMin:1/0,visibleMax:-1/0},Or=e=>Q(`stoch`,e),kr={timestamp:0,series:[],params:{n:9,m:3,showK:!0,showD:!0},valueMin:0,valueMax:100,visibleMin:1/0,visibleMax:-1/0},Ar=e=>Q(`mom`,e),jr={timestamp:0,series:[],params:{period:10,showMOM:!0},valueMin:0,valueMax:0,visibleMin:1/0,visibleMax:-1/0},Mr=e=>Q(`wmsr`,e),Nr={timestamp:0,series:[],params:{period:14,showWMSR:!0},valueMin:-100,valueMax:0,visibleMin:1/0,visibleMax:-1/0},Pr=e=>Q(`kst`,e),Fr={timestamp:0,series:[],params:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},valueMin:0,valueMax:0,visibleMin:1/0,visibleMax:-1/0},Ir=e=>Q(`fastk`,e),Lr={timestamp:0,series:[],params:{period:9,showFASTK:!0},valueMin:0,valueMax:100,visibleMin:1/0,visibleMax:-1/0},Rr=`indicator:macd`;function zr(e){return`${Rr}:${e}`}var Br={timestamp:0,series:[],params:{fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0},visibleMin:1/0,visibleMax:-1/0,valueMin:-1/0,valueMax:1/0};function Vr(e,t){let n=t.end-1;return n>=0&&n<e.macd.series.length?e.macd.series[n]:null}function Hr(e,t,n){return{...e,...n,timestamp:t}}function Ur(e,t,n,r={}){let i=r.rsi??!0,a=r.cci??!0,o=r.stoch??!0,s=r.mom??!0,c=r.wmsr??!0,l=r.kst??!0,u=r.fastk??!0,d=r.macd??!0,f=i?Yr(e.rsi.series,t):null,p=a?Xr(e.cci.series,t):null,m=o?Zr(e.stoch.series,t):null,h=s?Qr(e.mom.series,t):null,g=c?$r(e.wmsr.series,t):null,_=l?ei(e.kst.series,t):null,v=u?ti(e.fastk.series,t):null,y=d?ni(e.macd.series,t):null,b=d?Vr(e,t):null,x=y?Math.max(Math.abs(y.max),Math.abs(y.min))*.1:0,S=y&&Number.isFinite(y.min)?y.min-x:Br.valueMin,C=y&&Number.isFinite(y.max)?y.max+x:Br.valueMax,w=p?Math.min(p.min,-150):Dr.valueMin,T=p?Math.max(p.max,150):Dr.valueMax,E=h?Math.max(Math.abs(h.max),Math.abs(h.min))*.1:0,D=h?h.min-E:jr.valueMin,O=h?h.max+E:jr.valueMax,k=(_?_.max-_.min:0)*.1,A=_?_.min-k:Fr.valueMin,j=_?_.max+k:Fr.valueMax;return{rsi:i?{timestamp:n,series:e.rsi.series,enabledPeriods:e.rsi.enabledPeriods,params:e.rsi.params,valueMin:0,valueMax:100,visibleMin:f.min,visibleMax:f.max}:Hr(Tr,n,{series:e.rsi.series,enabledPeriods:e.rsi.enabledPeriods,params:e.rsi.params}),cci:a?{timestamp:n,series:e.cci.series,params:e.cci.params,valueMin:w,valueMax:T,visibleMin:p.min,visibleMax:p.max}:Hr(Dr,n,{series:e.cci.series,params:e.cci.params}),stoch:o?{timestamp:n,series:e.stoch.series,params:e.stoch.params,valueMin:0,valueMax:100,visibleMin:m.min,visibleMax:m.max}:Hr(kr,n,{series:e.stoch.series,params:e.stoch.params}),mom:s?{timestamp:n,series:e.mom.series,params:e.mom.params,valueMin:D,valueMax:O,visibleMin:h.min,visibleMax:h.max}:Hr(jr,n,{series:e.mom.series,params:e.mom.params}),wmsr:c?{timestamp:n,series:e.wmsr.series,params:e.wmsr.params,valueMin:-100,valueMax:0,visibleMin:g.min,visibleMax:g.max}:Hr(Nr,n,{series:e.wmsr.series,params:e.wmsr.params}),kst:l?{timestamp:n,series:e.kst.series,params:e.kst.params,valueMin:A,valueMax:j,visibleMin:_.min,visibleMax:_.max}:Hr(Fr,n,{series:e.kst.series,params:e.kst.params}),fastk:u?{timestamp:n,series:e.fastk.series,params:e.fastk.params,valueMin:0,valueMax:100,visibleMin:v.min,visibleMax:v.max}:Hr(Lr,n,{series:e.fastk.series,params:e.fastk.params}),macd:d?{timestamp:n,series:e.macd.series,params:e.macd.params,valueMin:S,valueMax:C,visibleMin:y.min,visibleMax:y.max,latestValues:b?{dif:b.dif,dea:b.dea,macd:b.macd}:void 0}:Hr(Br,n,{series:e.macd.series,params:e.macd.params})}}function Wr(e,t,n){let r=Gr(e.ma.series,t),i=Kr(e.boll.series,t),a=qr(e.expma.series,t),o=Jr(e.ene.series,t),s=Ur(e,t,n);return{ma:{timestamp:n,series:e.ma.series,enabledPeriods:e.ma.enabledPeriods,visibleMin:r.min,visibleMax:r.max},boll:{timestamp:n,series:e.boll.series,params:e.boll.params,visibleMin:i.min,visibleMax:i.max},expma:{timestamp:n,series:e.expma.series,params:e.expma.params,visibleMin:a.min,visibleMax:a.max},ene:{timestamp:n,series:e.ene.series,params:e.ene.params,visibleMin:o.min,visibleMax:o.max},...s}}function Gr(e,t){let n=Object.values(e);if(n.length===0||t.start>=n[0].length)return{min:1/0,max:-1/0};let r=1/0,i=-1/0;for(let e of n){let n=Math.min(t.end,e.length);for(let a=t.start;a<n;a++){let t=e[a];t!==void 0&&(r=Math.min(r,t),i=Math.max(i,t))}}return{min:r,max:i}}function Kr(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.upper,t.middle,t.lower),r=Math.max(r,t.upper,t.middle,t.lower))}return{min:n,max:r}}function qr(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.fast,t.slow),r=Math.max(r,t.fast,t.slow))}return{min:n,max:r}}function Jr(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.upper,t.middle,t.lower),r=Math.max(r,t.upper,t.middle,t.lower))}return{min:n,max:r}}function Yr(e,t){let n=Object.values(e);if(n.length===0||t.start>=n[0].length)return{min:1/0,max:-1/0};let r=1/0,i=-1/0;for(let e of n){let n=Math.min(t.end,e.length);for(let a=t.start;a<n;a++){let t=e[a];t!==void 0&&(r=Math.min(r,t),i=Math.max(i,t))}}return{min:r,max:i}}function Xr(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function Zr(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.k,t.d),r=Math.max(r,t.k,t.d))}return{min:n,max:r}}function Qr(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function $r(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function ei(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.kst,t.signal),r=Math.max(r,t.kst,t.signal))}return{min:n,max:r}}function ti(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function ni(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.dif,t.dea,t.macd),r=Math.max(r,t.dif,t.dea,t.macd))}return{min:n,max:r}}function ri(e,t,n){let r=1/0,i=-1/0,{start:a,end:o}=t;if(n.has(`ma`)&&Object.keys(e.ma.series).length>0)for(let t of Object.values(e.ma.series))for(let e=a;e<o&&e<t.length;e++){let n=t[e];n!==void 0&&(r=Math.min(r,n),i=Math.max(i,n))}if(n.has(`boll`)&&e.boll.series.length>0)for(let t=a;t<o&&t<e.boll.series.length;t++){let n=e.boll.series[t];n&&(r=Math.min(r,n.upper,n.middle,n.lower),i=Math.max(i,n.upper,n.middle,n.lower))}if(n.has(`expma`)&&e.expma.series.length>0)for(let t=a;t<o&&t<e.expma.series.length;t++){let n=e.expma.series[t];n&&(r=Math.min(r,n.fast,n.slow),i=Math.max(i,n.fast,n.slow))}if(n.has(`ene`)&&e.ene.series.length>0)for(let t=a;t<o&&t<e.ene.series.length;t++){let n=e.ene.series[t];n&&(r=Math.min(r,n.upper,n.middle,n.lower),i=Math.max(i,n.upper,n.middle,n.lower))}return!Number.isFinite(r)||!Number.isFinite(i)?null:{min:r,max:i}}var ii=Q(`ma`,`main`),ai=Q(`boll`,`main`),oi=Q(`expma`,`main`),si=Q(`ene`,`main`),ci=class{pluginHost=null;visibleRange={start:0,end:0};activeMainIndicators=new Set;dataVersion=0;configVersion=0;requestId=0;lastAppliedRequestId=0;currentData=[];configSnapshot=this.getDefaultConfig();worker=null;workerReady=!1;useWorker=!1;pendingRequest=null;inlineRuntime=null;latestResult=null;invalidateCallback=null;getActiveSubPaneIds=null;constructor(){this.initBackend()}setPluginHost(e){this.pluginHost=e}setInvalidateCallback(e){this.invalidateCallback=e}setActiveSubPaneProvider(e){this.getActiveSubPaneIds=e}destroy(){this.terminateWorker(),this.inlineRuntime=null,this.latestResult=null,this.invalidateCallback=null}getDefaultConfig(){return{ma:{ma5:!0,ma10:!0,ma20:!0,ma30:!0,ma60:!0},boll:{period:20,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0,showBand:!0},expma:{fastPeriod:12,slowPeriod:50},ene:{period:10,deviation:11},rsi:{period1:6,period2:12,period3:24,showRSI1:!0,showRSI2:!0,showRSI3:!0},cci:{period:14,showCCI:!0},stoch:{n:9,m:3,showK:!0,showD:!0},mom:{period:10,showMOM:!0},wmsr:{period:14,showWMSR:!0},kst:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},fastk:{period:9,showFASTK:!0},macd:{fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0},rsiPaneId:`sub_RSI`,cciPaneId:`sub_CCI`,stochPaneId:`sub_STOCH`,momPaneId:`sub_MOM`,wmsrPaneId:`sub_WMSR`,kstPaneId:`sub_KST`,fastkPaneId:`sub_FASTK`,macdPaneId:`sub_MACD`}}initBackend(){this.tryInitWorker()||this.initInlineRuntime()}tryInitWorker(){if(console.log(`[IndicatorScheduler] tryInitWorker: Worker available?`,typeof Worker<`u`),typeof Worker>`u`)return!1;try{let e=new URL(`data:video/mp2t;base64,LyoqCiAqIEluZGljYXRvciBXb3JrZXIg5YWl5Y+jCiAqIOi/kOihjOWcqOeLrOeri+e6v+eoi++8jOi0n+i0o+aMh+agh+iuoeeulwogKi8KCmltcG9ydCB0eXBlIHsKICAgIEluZGljYXRvcldvcmtlclJlcXVlc3QsCiAgICBJbmRpY2F0b3JXb3JrZXJSZXNwb25zZSwKICAgIEluZGljYXRvckNvbmZpZ1NuYXBzaG90LAp9IGZyb20gJy4vd29ya2VyUHJvdG9jb2wnCmltcG9ydCB7IFBST1RPQ09MX1ZFUlNJT04gfSBmcm9tICcuL3dvcmtlclByb3RvY29sJwppbXBvcnQgdHlwZSB7IEtMaW5lRGF0YSB9IGZyb20gJ0AvdHlwZXMvcHJpY2UnCmltcG9ydCB7IEluZGljYXRvclJ1bnRpbWUgfSBmcm9tICcuL2luZGljYXRvclJ1bnRpbWUnCgovLyBXb3JrZXIg5YWo5bGA5L2c55So5Z+fCmNvbnN0IGN0eCA9IHNlbGYgYXMgdW5rbm93biBhcyBXb3JrZXIKCi8vIOi/kOihjOaXtuWunuS+iwpsZXQgcnVudGltZTogSW5kaWNhdG9yUnVudGltZSB8IG51bGwgPSBudWxsCgovKioKICog5Y+R6YCB5ZON5bqU5Yiw5Li757q/56iLCiAqLwpmdW5jdGlvbiBwb3N0UmVzcG9uc2UocmVzcG9uc2U6IEluZGljYXRvcldvcmtlclJlc3BvbnNlKTogdm9pZCB7CiAgICBjdHgucG9zdE1lc3NhZ2UocmVzcG9uc2UpCn0KCi8qKgogKiDlpITnkIbliJ3lp4vljJYKICovCmZ1bmN0aW9uIGhhbmRsZUluaXQoKTogdm9pZCB7CiAgICBydW50aW1lID0gbmV3IEluZGljYXRvclJ1bnRpbWUoKQogICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICB0eXBlOiAncmVhZHknLAogICAgICAgIHByb3RvY29sVmVyc2lvbjogUFJPVE9DT0xfVkVSU0lPTiwKICAgIH0pCn0KCi8qKgogKiDlpITnkIborr7nva7mlbDmja4KICovCmZ1bmN0aW9uIGhhbmRsZVNldERhdGEoZGF0YTogS0xpbmVEYXRhW10sIHZlcnNpb246IG51bWJlcik6IHZvaWQgewogICAgaWYgKCFydW50aW1lKSB7CiAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgdHlwZTogJ2Vycm9yJywKICAgICAgICAgICAgc3RhZ2U6ICdzZXREYXRhJywKICAgICAgICAgICAgbWVzc2FnZTogJ1J1bnRpbWUgbm90IGluaXRpYWxpemVkJywKICAgICAgICB9KQogICAgICAgIHJldHVybgogICAgfQogICAgcnVudGltZS5zZXREYXRhKGRhdGEsIHZlcnNpb24pCn0KCi8qKgogKiDlpITnkIborr7nva7phY3nva4KICovCmZ1bmN0aW9uIGhhbmRsZVNldENvbmZpZyhjb25maWc6IFBhcnRpYWw8SW5kaWNhdG9yQ29uZmlnU25hcHNob3Q+LCB2ZXJzaW9uOiBudW1iZXIpOiB2b2lkIHsKICAgIGlmICghcnVudGltZSkgewogICAgICAgIHBvc3RSZXNwb25zZSh7CiAgICAgICAgICAgIHR5cGU6ICdlcnJvcicsCiAgICAgICAgICAgIHN0YWdlOiAnc2V0Q29uZmlnJywKICAgICAgICAgICAgbWVzc2FnZTogJ1J1bnRpbWUgbm90IGluaXRpYWxpemVkJywKICAgICAgICB9KQogICAgICAgIHJldHVybgogICAgfQogICAgcnVudGltZS5zZXRDb25maWcoY29uZmlnLCB2ZXJzaW9uKQp9CgovKioKICog5aSE55CG6K6h566XIHNlcmllcwogKi8KZnVuY3Rpb24gaGFuZGxlQ29tcHV0ZVNlcmllcyhyZXF1ZXN0SWQ6IG51bWJlciwgZGF0YVZlcnNpb246IG51bWJlciwgY29uZmlnVmVyc2lvbjogbnVtYmVyKTogdm9pZCB7CiAgICBpZiAoIXJ1bnRpbWUpIHsKICAgICAgICBwb3N0UmVzcG9uc2UoewogICAgICAgICAgICB0eXBlOiAnZXJyb3InLAogICAgICAgICAgICByZXF1ZXN0SWQsCiAgICAgICAgICAgIHN0YWdlOiAnY29tcHV0ZVNlcmllcycsCiAgICAgICAgICAgIG1lc3NhZ2U6ICdSdW50aW1lIG5vdCBpbml0aWFsaXplZCcsCiAgICAgICAgfSkKICAgICAgICByZXR1cm4KICAgIH0KCiAgICBjb25zdCBzdGFydFRpbWUgPSBwZXJmb3JtYW5jZS5ub3coKQoKICAgIHRyeSB7CiAgICAgICAgY29uc29sZS5sb2coYFtJbmRpY2F0b3JXb3JrZXJdIGNvbXB1dGVTZXJpZXMgU1RBUlQgcmVxSWQ9JHtyZXF1ZXN0SWR9YCkKICAgICAgICBjb25zdCByZXN1bHRzID0gcnVudGltZS5jb21wdXRlU2VyaWVzKCkKICAgICAgICBjb25zdCBjb21wdXRlTXMgPSBwZXJmb3JtYW5jZS5ub3coKSAtIHN0YXJ0VGltZQogICAgICAgIGNvbnNvbGUubG9nKGBbSW5kaWNhdG9yV29ya2VyXSBjb21wdXRlU2VyaWVzIERPTkUgaW4gJHtjb21wdXRlTXMudG9GaXhlZCgxKX1tcywgY2hhbmdlZD1bJHtyZXN1bHRzLl9jaGFuZ2VkLmpvaW4oJywnKX1dYCkKCiAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgdHlwZTogJ3Nlcmllc1Jlc3VsdCcsCiAgICAgICAgICAgIHJlcXVlc3RJZCwKICAgICAgICAgICAgZGF0YVZlcnNpb24sCiAgICAgICAgICAgIGNvbmZpZ1ZlcnNpb24sCiAgICAgICAgICAgIHJlc3VsdHMsCiAgICAgICAgICAgIG1ldHJpY3M6IHsKICAgICAgICAgICAgICAgIGNvbXB1dGVNcywKICAgICAgICAgICAgICAgIGRhdGFMZW5ndGg6IDAsIC8vIOeUseiwg+eUqOaWueWhq+WFhQogICAgICAgICAgICB9LAogICAgICAgIH0pCiAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICBjb25zdCBtZXNzYWdlID0gZXJyIGluc3RhbmNlb2YgRXJyb3IgPyBlcnIubWVzc2FnZSA6IFN0cmluZyhlcnIpCiAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgdHlwZTogJ2Vycm9yJywKICAgICAgICAgICAgcmVxdWVzdElkLAogICAgICAgICAgICBzdGFnZTogJ2NvbXB1dGVTZXJpZXMnLAogICAgICAgICAgICBtZXNzYWdlLAogICAgICAgIH0pCiAgICB9Cn0KCi8qKgogKiDlpITnkIbplIDmr4EKICovCmZ1bmN0aW9uIGhhbmRsZURpc3Bvc2UoKTogdm9pZCB7CiAgICBydW50aW1lID0gbnVsbAogICAgLy8gV29ya2VyIOS8muiiq+S4u+e6v+eoiyB0ZXJtaW5hdGXvvIzov5nph4zlgZrmuIXnkIbljbPlj68KfQoKLyoqCiAqIOa2iOaBr+WkhOeQhuWZqAogKi8KY3R4Lm9ubWVzc2FnZSA9IChldmVudDogTWVzc2FnZUV2ZW50PEluZGljYXRvcldvcmtlclJlcXVlc3Q+KSA9PiB7CiAgICBjb25zdCBtc2cgPSBldmVudC5kYXRhCgogICAgaWYgKCFtc2cgfHwgdHlwZW9mIG1zZyAhPT0gJ29iamVjdCcpIHsKICAgICAgICBwb3N0UmVzcG9uc2UoewogICAgICAgICAgICB0eXBlOiAnZXJyb3InLAogICAgICAgICAgICBzdGFnZTogJ2luaXQnLAogICAgICAgICAgICBtZXNzYWdlOiAnSW52YWxpZCBtZXNzYWdlIGZvcm1hdCcsCiAgICAgICAgfSkKICAgICAgICByZXR1cm4KICAgIH0KCiAgICBzd2l0Y2ggKG1zZy50eXBlKSB7CiAgICAgICAgY2FzZSAnaW5pdCc6CiAgICAgICAgICAgIGhhbmRsZUluaXQoKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdzZXREYXRhJzoKICAgICAgICAgICAgaGFuZGxlU2V0RGF0YShtc2cuZGF0YSwgbXNnLmRhdGFWZXJzaW9uKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdzZXRDb25maWcnOgogICAgICAgICAgICBoYW5kbGVTZXRDb25maWcobXNnLmNvbmZpZ3MsIG1zZy5jb25maWdWZXJzaW9uKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdjb21wdXRlU2VyaWVzJzoKICAgICAgICAgICAgaGFuZGxlQ29tcHV0ZVNlcmllcyhtc2cucmVxdWVzdElkLCBtc2cuZGF0YVZlcnNpb24sIG1zZy5jb25maWdWZXJzaW9uKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdkaXNwb3NlJzoKICAgICAgICAgICAgaGFuZGxlRGlzcG9zZSgpCiAgICAgICAgICAgIGJyZWFrCgogICAgICAgIGRlZmF1bHQ6IHsKICAgICAgICAgICAgY29uc3QgX2V4aGF1c3RpdmVDaGVjazogbmV2ZXIgPSBtc2cKICAgICAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgICAgIHR5cGU6ICdlcnJvcicsCiAgICAgICAgICAgICAgICBzdGFnZTogJ2luaXQnLAogICAgICAgICAgICAgICAgbWVzc2FnZTogYFVua25vd24gbWVzc2FnZSB0eXBlOiAkeyhfZXhoYXVzdGl2ZUNoZWNrIGFzIHVua25vd24gYXMgeyB0eXBlOiBzdHJpbmcgfSkudHlwZX1gLAogICAgICAgICAgICB9KQogICAgICAgIH0KICAgIH0KfQoKLy8g6YCa55+l5Li757q/56iLIHdvcmtlciDlt7LliqDovb3vvIjlj6/pgInvvIzkuLvopoHnlKjkuo7osIPor5XvvIkKLy8gY29uc29sZS5sb2coJ1tJbmRpY2F0b3JXb3JrZXJdIExvYWRlZCcpCg==`,``+{}.url);return console.log(`[IndicatorScheduler] Creating worker from:`,e.href),this.worker=new Worker(e,{type:`module`}),console.log(`[IndicatorScheduler] Worker created, waiting for ready...`),this.worker.onmessage=e=>this.handleWorkerMessage(e.data),this.worker.onerror=e=>{console.error(`[IndicatorScheduler] Worker error:`,e),this.fallbackToInline()},this.worker.postMessage({type:`init`,protocolVersion:1}),!0}catch(e){return console.warn(`[IndicatorScheduler] Failed to init worker:`,e),!1}}initInlineRuntime(){console.log(`[IndicatorScheduler] Using INLINE runtime (fallback)`),this.inlineRuntime=new Sr,this.useWorker=!1,this.workerReady=!0}fallbackToInline(){console.warn(`[IndicatorScheduler] Falling back to inline runtime`),this.terminateWorker(),this.initInlineRuntime(),this.pendingRequest&&this.computeWithInline()}terminateWorker(){this.worker&&=(this.worker.terminate(),null),this.workerReady=!1,this.useWorker=!1}handleWorkerMessage(e){if(!Cr(e)){console.warn(`[IndicatorScheduler] Invalid worker response:`,e);return}switch(e.type){case`ready`:this.workerReady=!0,this.useWorker=!0,console.log(`[IndicatorScheduler] Worker READY - using Worker backend`),this.triggerRecompute();break;case`seriesResult`:this.handleSeriesResult(e);break;case`error`:console.error(`[IndicatorScheduler] Worker error:`,e.stage,e.message),this.pendingRequest&&e.requestId===this.pendingRequest.requestId&&this.fallbackToInline();break;default:console.warn(`[IndicatorScheduler] Unknown response type:`,e.type)}}handleSeriesResult(e){e.requestId<this.lastAppliedRequestId||e.dataVersion!==this.dataVersion||e.configVersion!==this.configVersion||(console.log(`[IndicatorScheduler] << Worker result: requestId=${e.requestId} metrics=`,e.metrics),this.lastAppliedRequestId=e.requestId,this.pendingRequest=null,this.latestResult=e.results,this.applyResults(e.results),this.invalidateCallback?.())}applyResults(e){if(!this.pluginHost)return;let t=new Set(e._changed),n=Date.now(),r=Wr(e,this.visibleRange,n);if(t.has(`ma`)&&this.pluginHost.setSharedState(ii,r.ma,`ma_scheduler`),t.has(`boll`)&&this.pluginHost.setSharedState(ai,r.boll,`indicator_scheduler`),t.has(`expma`)&&this.pluginHost.setSharedState(oi,r.expma,`indicator_scheduler`),t.has(`ene`)&&this.pluginHost.setSharedState(si,r.ene,`indicator_scheduler`),t.has(`rsi`)){let e=wr(this.configSnapshot.rsiPaneId);this.pluginHost.setSharedState(e,r.rsi,`indicator_scheduler`)}if(t.has(`cci`)){let e=Er(this.configSnapshot.cciPaneId);this.pluginHost.setSharedState(e,r.cci,`indicator_scheduler`)}if(t.has(`stoch`)){let e=Or(this.configSnapshot.stochPaneId);this.pluginHost.setSharedState(e,r.stoch,`indicator_scheduler`)}if(t.has(`mom`)){let e=Ar(this.configSnapshot.momPaneId);this.pluginHost.setSharedState(e,r.mom,`indicator_scheduler`)}if(t.has(`wmsr`)){let e=Mr(this.configSnapshot.wmsrPaneId);this.pluginHost.setSharedState(e,r.wmsr,`indicator_scheduler`)}if(t.has(`kst`)){let e=Pr(this.configSnapshot.kstPaneId);this.pluginHost.setSharedState(e,r.kst,`indicator_scheduler`)}if(t.has(`fastk`)){let e=Ir(this.configSnapshot.fastkPaneId);this.pluginHost.setSharedState(e,r.fastk,`indicator_scheduler`)}if(t.has(`macd`)){let e=zr(this.configSnapshot.macdPaneId);this.pluginHost.setSharedState(e,r.macd,`indicator_scheduler`)}}updateVisibleStatesOnly(){if(!this.pluginHost||!this.latestResult)return;let e=Date.now(),t=this.buildActiveSubIndicatorMask(),n=Ur(this.latestResult,this.visibleRange,e,t),r=wr(this.configSnapshot.rsiPaneId);this.pluginHost.setSharedState(r,n.rsi,`indicator_scheduler`);let i=Er(this.configSnapshot.cciPaneId);this.pluginHost.setSharedState(i,n.cci,`indicator_scheduler`);let a=Or(this.configSnapshot.stochPaneId);this.pluginHost.setSharedState(a,n.stoch,`indicator_scheduler`);let o=Ar(this.configSnapshot.momPaneId);this.pluginHost.setSharedState(o,n.mom,`indicator_scheduler`);let s=Mr(this.configSnapshot.wmsrPaneId);this.pluginHost.setSharedState(s,n.wmsr,`indicator_scheduler`);let c=Pr(this.configSnapshot.kstPaneId);this.pluginHost.setSharedState(c,n.kst,`indicator_scheduler`);let l=Ir(this.configSnapshot.fastkPaneId);this.pluginHost.setSharedState(l,n.fastk,`indicator_scheduler`);let u=zr(this.configSnapshot.macdPaneId);this.pluginHost.setSharedState(u,n.macd,`indicator_scheduler`)}buildActiveSubIndicatorMask(){let e=this.getActiveSubPaneIds?.()??[];return{rsi:e.includes(this.configSnapshot.rsiPaneId),cci:e.includes(this.configSnapshot.cciPaneId),stoch:e.includes(this.configSnapshot.stochPaneId),mom:e.includes(this.configSnapshot.momPaneId),wmsr:e.includes(this.configSnapshot.wmsrPaneId),kst:e.includes(this.configSnapshot.kstPaneId),fastk:e.includes(this.configSnapshot.fastkPaneId),macd:e.includes(this.configSnapshot.macdPaneId)}}buildActiveConfig(){let e=this.getActiveSubPaneIds?.()??[];if(e.length===0)return{...this.configSnapshot};let t={...this.configSnapshot};for(let n of[`rsi`,`cci`,`stoch`,`mom`,`wmsr`,`kst`,`fastk`,`macd`]){let r=t[`${n}PaneId`];if(!e.includes(r)){let e={...t[n]};for(let t of Object.keys(e))t.startsWith(`show`)&&(e[t]=!1);t[n]=e}}return t}update(e,t){this.currentData=e,this.visibleRange=t,this.dataVersion++,this.useWorker&&this.worker&&this.workerReady?this.computeWithWorker():this.computeWithInline()}updateVisibleRange(e){this.visibleRange=e,this.latestResult&&this.updateVisibleStatesOnly()}updateMAConfig(e){this.configSnapshot.ma={...e},this.configVersion++,this.triggerRecompute()}updateBOLLConfig(e){this.configSnapshot.boll={...this.configSnapshot.boll,...e},this.configVersion++,this.triggerRecompute()}updateEXPMAConfig(e){this.configSnapshot.expma={...this.configSnapshot.expma,...e},this.configVersion++,this.triggerRecompute()}updateENEConfig(e){this.configSnapshot.ene={...this.configSnapshot.ene,...e},this.configVersion++,this.triggerRecompute()}updateRSIConfig(e,t){t!==void 0&&(this.configSnapshot.rsiPaneId=t),this.configSnapshot.rsi={...this.configSnapshot.rsi,...e},this.configVersion++,this.triggerRecompute()}updateCCIConfig(e,t){t!==void 0&&(this.configSnapshot.cciPaneId=t),this.configSnapshot.cci={...this.configSnapshot.cci,...e},this.configVersion++,this.triggerRecompute()}updateSTOCHConfig(e,t){t!==void 0&&(this.configSnapshot.stochPaneId=t),this.configSnapshot.stoch={...this.configSnapshot.stoch,...e},this.configVersion++,this.triggerRecompute()}updateMOMConfig(e,t){t!==void 0&&(this.configSnapshot.momPaneId=t),this.configSnapshot.mom={...this.configSnapshot.mom,...e},this.configVersion++,this.triggerRecompute()}updateWMSRConfig(e,t){t!==void 0&&(this.configSnapshot.wmsrPaneId=t),this.configSnapshot.wmsr={...this.configSnapshot.wmsr,...e},this.configVersion++,this.triggerRecompute()}updateKSTConfig(e,t){t!==void 0&&(this.configSnapshot.kstPaneId=t),this.configSnapshot.kst={...this.configSnapshot.kst,...e},this.configVersion++,this.triggerRecompute()}updateFASTKConfig(e,t){t!==void 0&&(this.configSnapshot.fastkPaneId=t),this.configSnapshot.fastk={...this.configSnapshot.fastk,...e},this.configVersion++,this.triggerRecompute()}updateMACDConfig(e,t){t!==void 0&&(this.configSnapshot.macdPaneId=t),this.configSnapshot.macd={...this.configSnapshot.macd,...e},this.configVersion++,this.triggerRecompute()}setActiveMainIndicators(e){this.activeMainIndicators=new Set(e.map(e=>e.toLowerCase()))}getMainIndicatorPriceRange(){return this.latestResult?ri(this.latestResult,this.visibleRange,this.activeMainIndicators):null}recompute(){this.inlineRuntime&&this.inlineRuntime.forceDirty(),this.dataVersion++,this.triggerRecompute()}triggerRecompute(){this.useWorker&&this.worker&&this.workerReady?this.computeWithWorker():this.computeWithInline()}computeWithWorker(){!this.worker||!this.workerReady||(console.log(`[IndicatorScheduler] >> Worker compute: requestId=${this.requestId+1} dataV=${this.dataVersion} configV=${this.configVersion}`),this.requestId++,this.pendingRequest={requestId:this.requestId,dataVersion:this.dataVersion,configVersion:this.configVersion},this.worker.postMessage({type:`setData`,dataVersion:this.dataVersion,format:`aos`,data:this.currentData}),this.worker.postMessage({type:`setConfig`,configVersion:this.configVersion,configs:this.buildActiveConfig()}),this.worker.postMessage({type:`computeSeries`,requestId:this.requestId,dataVersion:this.dataVersion,configVersion:this.configVersion}))}computeWithInline(){this.inlineRuntime||=new Sr,console.log(`[IndicatorScheduler] >> INLINE compute: dataV=${this.dataVersion} configV=${this.configVersion}`),this.inlineRuntime.setData(this.currentData,this.dataVersion),this.inlineRuntime.setConfig(this.buildActiveConfig(),this.configVersion);let e=this.inlineRuntime.computeSeries();this.latestResult=e,this.applyResults(e),this.invalidateCallback?.()}};function li(e={}){let{paneId:t=`sub`}=e,n=Q(`volume`,t),r=null;return{name:`volume_${t}`,version:`1.0.0`,description:`成交量渲染器`,debugName:`成交量`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:i,pane:a,data:o,range:s,dpr:c}=e,l=o;if(!l.length)return;let{start:u,end:d}=s,f=0,p=1/0;for(let e=u;e<d&&e<l.length;e++){let t=l[e];if(!t)continue;let n=t.volume;n!=null&&(f=Math.max(f,n),p=Math.min(p,n))}if(f===0||!Number.isFinite(p))return;let m=Math.max(.05,(f-p)*.1),h=Math.max(0,p-m),g=f+m,_=a.yAxis.getDisplayRange({minPrice:h,maxPrice:g}),v=_.minPrice,y=_.maxPrice-v||1,b=a.height-(0-v)/y*a.height,x=Math.round(b*c)/c;r?.setSharedState(n,{valueMin:h,valueMax:g,timestamp:Date.now()},`volume_${t}`);let S=Math.max(1,d-u),C=new Float32Array(S*4),w=new Float32Array(S*4),T=new Float32Array(S*4),E=0,D=0,O=0;for(let t=u;t<d;t++){let n=l[t];if(!n)continue;let r=n.volume;if(!r)continue;let i=e.kBarRects[t-u];if(!i)continue;let o=a.height-(r-v)/y*a.height,s=Math.round(o*c)/c,d=1/c,f=x-s,p=f<=0?d:Math.max(f,d),m=f<=0?x-d:x-p,h=pi(n),g,_;h===K.UP?(g=C,_=E++):h===K.DOWN?(g=w,_=D++):(g=T,_=O++);let b=_*4;g[b]=i.x,g[b+1]=m,g[b+2]=i.width,g[b+3]=p}ui(e,C,E,w,D,T,O)?fi(i,e):di(i,e.scrollLeft,C,E,w,D,T,O)}}}function ui(e,t,n,r,i,a,o){if(e.settings?.enableWebGLRendering===!1)return!1;let s=e.candleWebGLSurface;if(!s||!s.isAvailable())return!1;s.clear();let c=n===0||s.drawRectBuffer(t.subarray(0,n*4),n,K.UP,e.scrollLeft),l=i===0||s.drawRectBuffer(r.subarray(0,i*4),i,K.DOWN,e.scrollLeft),u=o===0||s.drawRectBuffer(a.subarray(0,o*4),o,K.NEUTRAL,e.scrollLeft);return c&&l&&u}function di(e,t,n,r,i,a,o,s){e.save(),e.translate(-t,0),e.fillStyle=K.UP;for(let t=0;t<r;t++){let r=t*4;e.fillRect(n[r],n[r+1],n[r+2],n[r+3])}e.fillStyle=K.DOWN;for(let t=0;t<a;t++){let n=t*4;e.fillRect(i[n],i[n+1],i[n+2],i[n+3])}e.fillStyle=K.NEUTRAL;for(let t=0;t<s;t++){let n=t*4;e.fillRect(o[n],o[n+1],o[n+2],o[n+3])}e.restore()}function fi(e,t){let n=t.candleWebGLSurface;if(!n)return;let r=n.getCanvas();r.width<=0||r.height<=0||e.drawImage(r,0,0,r.width,r.height,0,0,r.width/t.dpr,r.height/t.dpr)}function pi(e){return e.close>e.open?K.UP:e.close<e.open?K.DOWN:K.NEUTRAL}var mi={5:U.MA5,10:U.MA10,20:U.MA20,30:U.MA30,60:U.MA60};function hi(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),r.join(`,`),n.height.toFixed(2)].join(`|`)}function gi(){let e=null,t=``,n=new Map;function r(){t=``,n=new Map}return{name:`ma`,version:`2.0.0`,description:`MA均线渲染器(带绘制缓存)`,debugName:`MA均线`,paneId:`main`,priority:L.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[ii]},draw(i){let{ctx:a,pane:o,range:s,scrollLeft:c,dpr:l,kLineCenters:u,lineWebGLSurface:d}=i,f=e?.getSharedState(ii);if(!f||f.visibleMin>f.visibleMax){r();return}if(f.enabledPeriods.length===0){r();return}let p=hi(s,u,o,f.enabledPeriods);if(t!==p){t=p,n=new Map;for(let[e,t]of Object.entries(f.series)){let r=Number(e),i=[];for(let e=s.start;e<s.end&&e<t.length;e++){let n=t[e];if(n===void 0)continue;let r=u[e-s.start];r!==void 0&&i.push({x:r,y:o.yAxis.priceToY(n)})}i.length>=2&&n.set(r,i)}}let m=i.settings?.enableWebGLRendering!==!1,h=!1;if(m&&d?.isAvailable()){let e=[];for(let t of f.enabledPeriods){let r=n.get(t);r&&e.push({points:r,width:1,color:mi[t]??U.MA5})}if(e.length>0&&d.drawLineStrips(e,c)){h=!0;let e=d.getCanvas();if(e.width>0&&e.height>0){let t=a.imageSmoothingEnabled;a.imageSmoothingEnabled=!1,a.drawImage(e,0,0,e.width,e.height,0,0,e.width/l,e.height/l),a.imageSmoothingEnabled=t}}}if(!h){a.save(),a.translate(-c,0),a.lineWidth=1,a.lineJoin=`round`,a.lineCap=`round`;for(let e of f.enabledPeriods){let t=n.get(e);if(!(!t||t.length<2)){a.strokeStyle=mi[e]??U.MA5,a.beginPath(),a.moveTo(t[0].x,t[0].y);for(let e=1;e<t.length;e++){let n=t[e];a.lineTo(n.x,n.y)}a.stroke()}}a.restore()}},getConfig(){let t=e?.getSharedState(ii),n={};return t?.enabledPeriods.forEach(e=>{n[`ma${e}`]=!0}),n},setConfig(e){}}}var _i=1;function vi(e){let t=e.match(/^rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)$/i);if(!t)return 1;let n=Number(t[1]);return Number.isFinite(n)?n:1}function yi(e){return e.replace(/,\s*[\d.]+\s*\)$/i,`, 1)`)}function bi(e,t,n=1){let r=t.getCanvas();if(r.width<=0||r.height<=0)return;let i=e.ctx.imageSmoothingEnabled,a=e.ctx.globalAlpha;e.ctx.imageSmoothingEnabled=!1,e.ctx.globalAlpha=a*n,e.ctx.drawImage(r,0,0,r.width,r.height,0,0,r.width/e.dpr,r.height/e.dpr),e.ctx.globalAlpha=a,e.ctx.imageSmoothingEnabled=i}function xi(e,t){if(e.settings?.enableWebGLRendering===!1)return!1;let n=e.lineWebGLSurface;if(!n||!n.isAvailable())return!1;n.clear();let r=!0;t.showBand&&t.bandUpperPoints.length>=2&&t.bandLowerPoints.length>=2&&(n.clear(),r=n.drawFilledBand({upperPoints:t.bandUpperPoints,lowerPoints:t.bandLowerPoints},yi(W.BAND_FILL),e.scrollLeft),r&&bi(e,n,vi(W.BAND_FILL))),n.clear();let i=[];if(t.showUpper&&t.upperPoints.length>=2&&i.push({points:t.upperPoints,width:_i,color:W.UPPER}),t.showMiddle&&t.middlePoints.length>=2&&i.push({points:t.middlePoints,width:_i,color:W.MIDDLE}),t.showLower&&t.lowerPoints.length>=2&&i.push({points:t.lowerPoints,width:_i,color:W.LOWER}),i.length>0&&(r=n.drawLineStrips(i,e.scrollLeft)),!r)return n.clear(),!1;let a=n.getCanvas();return a.width<=0||a.height<=0?(n.clear(),!0):(bi(e,n),n.clear(),!0)}function Si(){let e=null,t=[],n=[],r=[],i=[],a=[],o=0;function s(e){if(!(e<=o)){for(let s=o;s<e;s++)t[s]={x:0,y:0},n[s]={x:0,y:0},r[s]={x:0,y:0},i[s]={x:0,y:0},a[s]={x:0,y:0};o=e}}return{name:`boll`,version:`2.2.0`,description:`布林带渲染器(无缓存优化)`,debugName:`BOLL布林带`,paneId:`main`,priority:L.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[ai]},draw(o){let{ctx:c,pane:l,data:u,range:d,scrollLeft:f,dpr:p,kLineCenters:m}=o,h=u,g=e?.getSharedState(ai);if(!g||g.visibleMin>g.visibleMax||g.series.length===0)return;let{period:_,showUpper:v,showMiddle:y,showLower:b,showBand:x}=g.params,S=g.series;if(h.length<_)return;let C=Math.max(d.start,_-1),w=Math.min(d.end,h.length);if(w<=C)return;let T=d.start,E=l.yAxis.priceToY.bind(l.yAxis),D=w-C;s(D);let O=Array(D),k=Array(D),A=Array(D),j=x?Array(D):[],M=x?Array(D):[],N=0,P=0,F=0,I=0;for(let e=C;e<w;e++){let o=S[e];if(!o)continue;let s=m[e-T];if(s===void 0)continue;let c=Z(E(o.upper),p),l=Z(E(o.middle),p),u=Z(E(o.lower),p),d=t[N];d.x=s,d.y=c,O[N++]=d,d=n[P],d.x=s,d.y=l,k[P++]=d,d=r[F],d.x=s,d.y=u,A[F++]=d,x&&(d=i[I],d.x=s,d.y=c,j[I]=d,d=a[I],d.x=s,d.y=u,M[I]=d,I++)}if(O.length=N,k.length=P,A.length=F,x&&(j.length=I,M.length=I),xi(o,{showUpper:v,showMiddle:y,showLower:b,showBand:x,upperPoints:O,middlePoints:k,lowerPoints:A,bandUpperPoints:j,bandLowerPoints:M}))return;if(c.save(),c.translate(-f,0),c.lineWidth=_i,c.lineJoin=`round`,c.lineCap=`round`,x&&j.length>=2){let e=new Path2D;e.moveTo(j[0].x,j[0].y);for(let t=1;t<j.length;t++)e.lineTo(j[t].x,j[t].y);for(let t=M.length-1;t>=0;t--)e.lineTo(M[t].x,M[t].y);e.closePath(),c.fillStyle=W.BAND_FILL,c.fill(e)}let ee=(e,t)=>{if(!(e.length<2)){c.beginPath(),c.strokeStyle=t,c.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)c.lineTo(e[t].x,e[t].y);c.stroke()}};v&&ee(O,W.UPPER),y&&ee(k,W.MIDDLE),b&&ee(A,W.LOWER),c.restore()},getConfig(){let t=e?.getSharedState(ai);return t?{...t.params}:{}},setConfig(e){}}}function Ci(e,t,n){let r=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,r.maxPrice.toFixed(6),r.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2)].join(`|`)}function wi(){let e=null,t=``,n=[],r=[];function i(){t=``,n=[],r=[]}return{name:`expma`,version:`2.0.0`,description:`EXPMA 指数平滑移动平均线渲染器(带绘制缓存)`,debugName:`EXPMA`,paneId:`main`,priority:L.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[oi]},draw(a){let{ctx:o,pane:s,data:c,range:l,scrollLeft:u,dpr:d,kLineCenters:f,lineWebGLSurface:p}=a,m=c,h=e?.getSharedState(oi);if(!h||h.visibleMin>h.visibleMax){i();return}if(h.series.length===0||m.length<2){i();return}let g=h.series,_=l.start,v=Math.min(l.end,m.length),y=Ci(l,f,s);if(t!==y){t=y,n=[],r=[];for(let e=_;e<v;e++){let t=g[e];if(!t)continue;let i=f[e-l.start];i!==void 0&&(n.push({x:i,y:s.yAxis.priceToY(t.fast)}),r.push({x:i,y:s.yAxis.priceToY(t.slow)}))}}let b=a.settings?.enableWebGLRendering!==!1,x=!1;if(b&&p?.isAvailable()){let e=[];if(n.length>=2&&e.push({points:n,width:1,color:Re.FAST}),r.length>=2&&e.push({points:r,width:1,color:Re.SLOW}),e.length>0&&p.drawLineStrips(e,u)){x=!0;let e=p.getCanvas();if(e.width>0&&e.height>0){let t=o.imageSmoothingEnabled;o.imageSmoothingEnabled=!1,o.drawImage(e,0,0,e.width,e.height,0,0,e.width/d,e.height/d),o.imageSmoothingEnabled=t}}}if(!x){if(o.save(),o.translate(-u,0),o.lineWidth=1,o.lineJoin=`round`,o.lineCap=`round`,n.length>=2){o.strokeStyle=Re.FAST,o.beginPath(),o.moveTo(n[0].x,n[0].y);for(let e=1;e<n.length;e++){let t=n[e];o.lineTo(t.x,t.y)}o.stroke()}if(r.length>=2){o.strokeStyle=Re.SLOW,o.beginPath(),o.moveTo(r[0].x,r[0].y);for(let e=1;e<r.length;e++){let t=r[e];o.lineTo(t.x,t.y)}o.stroke()}o.restore()}},getConfig(){let t=e?.getSharedState(oi);return t?{...t.params}:{}},setConfig(e){}}}function Ti(e){let t=e.match(/^rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)$/i);if(!t)return 1;let n=Number(t[1]);return Number.isFinite(n)?n:1}function Ei(e){return e.replace(/,\s*[\d.]+\s*\)$/i,`, 1)`)}function Di(e,t,n=1){let r=t.getCanvas();if(r.width<=0||r.height<=0)return;let i=e.ctx.imageSmoothingEnabled,a=e.ctx.globalAlpha;e.ctx.imageSmoothingEnabled=!1,e.ctx.globalAlpha=a*n,e.ctx.drawImage(r,0,0,r.width,r.height,0,0,r.width/e.dpr,r.height/e.dpr),e.ctx.globalAlpha=a,e.ctx.imageSmoothingEnabled=i}function Oi(e,t){if(e.settings?.enableWebGLRendering===!1)return!1;let n=e.lineWebGLSurface;if(!n||!n.isAvailable())return!1;n.clear();let r=!0;t.upperPoints.length>=2&&t.lowerPoints.length>=2&&(n.clear(),r=n.drawFilledBand({upperPoints:t.upperPoints,lowerPoints:t.lowerPoints},Ei(Y.BAND_FILL),e.scrollLeft),r&&Di(e,n,Ti(Y.BAND_FILL))),n.clear();let i=[];if(t.upperPoints.length>=2&&i.push({points:t.upperPoints,width:1,color:Y.UPPER}),t.middlePoints.length>=2&&i.push({points:t.middlePoints,width:1,color:Y.MIDDLE}),t.lowerPoints.length>=2&&i.push({points:t.lowerPoints,width:1,color:Y.LOWER}),i.length>0&&(r=n.drawLineStrips(i,e.scrollLeft)),!r)return n.clear(),!1;let a=n.getCanvas();return a.width>0&&a.height>0&&Di(e,n),n.clear(),!0}function ki(){let e=null;return{name:`ene`,version:`2.0.0`,description:`ENE 轨道线渲染器(无状态)`,debugName:`ENE轨道线`,paneId:`main`,priority:L.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[si]},draw(t){let{ctx:n,pane:r,data:i,range:a,scrollLeft:o,dpr:s,kLineCenters:c}=t,l=i,u=e?.getSharedState(si);if(!u||u.visibleMin>u.visibleMax||u.series.length===0)return;let{period:d}=u.params,f=u.series;if(l.length<d)return;let p=Math.max(a.start,d-1),m=Math.min(a.end,l.length),h=[],g=[],_=[];for(let e=p;e<m;e++){let t=f[e];if(!t)continue;let n=c[e-a.start];n!==void 0&&(h.push({x:n,y:Z(r.yAxis.priceToY(t.upper),s)}),g.push({x:n,y:Z(r.yAxis.priceToY(t.middle),s)}),_.push({x:n,y:Z(r.yAxis.priceToY(t.lower),s)}))}if(Oi(t,{upperPoints:h,middlePoints:g,lowerPoints:_}))return;if(n.save(),n.translate(-o,0),n.fillStyle=Y.BAND_FILL,n.beginPath(),h.length>0){n.moveTo(h[0].x,h[0].y);for(let e=1;e<h.length;e++){let t=h[e];n.lineTo(t.x,t.y)}for(let e=_.length-1;e>=0;e--){let t=_[e];n.lineTo(t.x,t.y)}}n.closePath(),n.fill(),n.lineWidth=1,n.lineJoin=`round`,n.lineCap=`round`;let v=(e,t)=>{if(e.length!==0){n.strokeStyle=t,n.beginPath(),n.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++){let r=e[t];n.lineTo(r.x,r.y)}n.stroke()}};v(h,Y.UPPER),v(g,Y.MIDDLE),v(_,Y.LOWER),n.restore()},getConfig(){let t=e?.getSharedState(si);return t?{...t.params}:{}},setConfig(e){}}}var Ai=`"Trebuchet MS", Roboto, Ubuntu, sans-serif`;function ji(e,t){return`${t?.bold?`bold `:``}${e}px ${Ai}`}function Mi(e,t){e.font!==t&&(e.font=t)}var Ni=new Map,Pi=512;function Fi(e,t){let n=`${e.font}\n${t}`,r=Ni.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return Ni.size>=Pi&&Ni.clear(),Ni.set(n,i),i}function Ii(e){let t={yPaddingPx:e.yPaddingPx,indicators:{MA:{enabled:!0,params:{}},BOLL:{enabled:!1,params:{period:20,multiplier:2}},EXPMA:{enabled:!1,params:{fastPeriod:12,slowPeriod:50}},ENE:{enabled:!1,params:{period:10,deviation:11}}}},n=null;return{name:`mainIndicatorLegend`,version:`2.0.0`,description:`主图指标图例渲染器(MA 数据来自 StateStore)`,debugName:`主图指标图例`,paneId:`main`,priority:L.FOREGROUND,enabled:!0,onInstall(e){n=e},getDeclaredNamespaces(){return[ii,ai,oi,si]},draw(e){let{ctx:r,data:i,range:a,crosshairIndex:o}=e,s=i;if(!s.length)return;r.save(),Mi(r,ji(12)),r.textAlign=`left`;let c=o??Math.min(a.end-1,s.length-1),l=[];t.indicators.MA?.enabled&&l.push({draw:e=>{let i=[],a=n?.getSharedState(ii);if(a&&a.visibleMin<=a.visibleMax)for(let e of a.enabledPeriods){let t=`MA${e}`,n=a.series[e]?.[c];i.push({label:`MA${e}`,color:U[t]||U.MA5,value:n})}if(i.length>0){let n=12,a=t.yPaddingPx/2+12+e*18;r.fillStyle=V.NEUTRAL,r.fillText(`MA`,n,a),n+=Fi(r,`MA`)+10;for(let e of i){let t=typeof e.value==`number`?` ${e.value.toFixed(2)}`:``,i=`${e.label}${t}`;r.fillStyle=e.color,r.fillText(i,n,a),n+=Fi(r,i)+10}}}}),t.indicators.BOLL?.enabled&&l.push({draw:e=>{let i=n?.getSharedState(ai),a=i?.series[c],o=i?.params.period??20,s=i?.params.multiplier??2,l=12,u=t.yPaddingPx/2+12+e*18,d=`BOLL(${o},${s})`;if(r.fillStyle=V.NEUTRAL,r.fillText(d,l,u),l+=Fi(r,d)+10,a){let e=`上轨:${a.upper.toFixed(2)}`;r.fillStyle=W.UPPER,r.fillText(e,l,u),l+=Fi(r,e)+10;let t=`中轨:${a.middle.toFixed(2)}`;r.fillStyle=W.MIDDLE,r.fillText(t,l,u),l+=Fi(r,t)+10;let n=`下轨:${a.lower.toFixed(2)}`;r.fillStyle=W.LOWER,r.fillText(n,l,u)}}}),t.indicators.EXPMA?.enabled&&l.push({draw:e=>{let i=n?.getSharedState(oi),a=i?.series[c],o=i?.params.fastPeriod??12,s=i?.params.slowPeriod??50,l=12,u=t.yPaddingPx/2+12+e*18,d=`EXPMA(${o},${s})`;if(r.fillStyle=V.NEUTRAL,r.fillText(d,l,u),l+=Fi(r,d)+10,a){let e=`快:${a.fast.toFixed(2)}`;r.fillStyle=Re.FAST,r.fillText(e,l,u),l+=Fi(r,e)+10;let t=`慢:${a.slow.toFixed(2)}`;r.fillStyle=Re.SLOW,r.fillText(t,l,u)}}}),t.indicators.ENE?.enabled&&l.push({draw:e=>{let i=n?.getSharedState(si),a=i?.series[c],o=i?.params.period??10,s=i?.params.deviation??11,l=12,u=t.yPaddingPx/2+12+e*18,d=`ENE(${o},${s})`;if(r.fillStyle=V.NEUTRAL,r.fillText(d,l,u),l+=Fi(r,d)+10,a){let e=`上轨:${a.upper.toFixed(2)}`;r.fillStyle=Y.UPPER,r.fillText(e,l,u),l+=Fi(r,e)+10;let t=`中轨:${a.middle.toFixed(2)}`;r.fillStyle=Y.MIDDLE,r.fillText(t,l,u),l+=Fi(r,t)+10;let n=`下轨:${a.lower.toFixed(2)}`;r.fillStyle=Y.LOWER,r.fillText(n,l,u)}}}),l.forEach((e,t)=>e.draw(t)),r.restore()},getConfig(){return{yPaddingPx:t.yPaddingPx,indicators:{...t.indicators}}},setConfig(e){if(typeof e.yPaddingPx==`number`&&(t.yPaddingPx=e.yPaddingPx),e.indicators&&typeof e.indicators==`object`)for(let[n,r]of Object.entries(e.indicators))t.indicators[n]||(t.indicators[n]={enabled:!1,params:{}}),r.enabled!==void 0&&(t.indicators[n].enabled=r.enabled),r.params&&(t.indicators[n].params=r.params)}}}function Li(e={}){let{paneId:t=`sub`,config:n={}}=e,r=zr(t),i=null,a={fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0,...n},o=``,s=[],c=[];function l(){o=``,s=[],c=[]}function u(e,t,n,r,i){return n.yAxis.getDisplayRange(),[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.toFixed(6),r.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),a.showDIF,a.showDEA].join(`|`)}return{name:`macd_${t}`,version:`1.0.0`,description:`MACD 指标渲染器`,debugName:`MACD`,paneId:t,priority:L.INDICATOR,onInstall(e){i=e},getDeclaredNamespaces(){return[r]},draw(e){let{ctx:t,pane:n,data:l,range:d,scrollLeft:f,dpr:p,kLineCenters:m,lineWebGLSurface:h}=e,g=l,_=i?.getSharedState(r);if(!_||_.visibleMin>_.visibleMax||g.length<a.slowPeriod)return;let v=_.series;if(!v||v.length===0)return;let y=_.visibleMin,b=_.visibleMax,x=Math.max(.05,(b-y)*.1);y-=x,b+=x,b-y;let S=n.yAxis.getDisplayRange({minPrice:y,maxPrice:b}),C=S.minPrice,w=S.maxPrice,T=w-C||1,E=n.height-(0-C)/T*n.height,D=Math.max(d.start,a.slowPeriod-1),O=Math.min(d.end,g.length);if(a.showBAR){let r=Math.round(E*p)/p,i=Math.max(1,O-D),a=new Float32Array(i*4),o=new Float32Array(i*4),s=new Float32Array(i*4),c=new Float32Array(i*4),l=0,u=0,m=0,h=0;for(let t=D;t<O;t++){let i=v[t];if(!i)continue;let f=e.kBarRects[t-d.start];if(!f)continue;let g=n.height-(i.macd-C)/T*n.height,_=i.macd>=0,y=t>0?v[t-1]:null,b=y?i.macd>=y.macd:!0,x=Math.round(g*p)/p,S=1/p,w,E;if(_){let e=r-x,t=e<=0?S:Math.max(e,S),n=e<=0?r-S:r-t;b?(w=a,E=l++):(w=o,E=u++);let i=E*4;w[i]=f.x,w[i+1]=n,w[i+2]=f.width,w[i+3]=t}else{let e=x-r,t=e<=0?S:Math.max(e,S);b?(w=c,E=h++):(w=s,E=m++);let n=E*4;w[n]=f.x,w[n+1]=r,w[n+2]=f.width,w[n+3]=t}}Ri(e,a,l,o,u,s,m,c,h)?Vi(t,e):zi(t,f,a,l,o,u,s,m,c,h)}let k=u(d,m,n,C,w);if(o!==k){if(o=k,s=[],c=[],a.showDIF)for(let e=D;e<O;e++){let t=v[e];if(!t)continue;let r=m[e-d.start];if(r===void 0)continue;let i=n.height-(t.dif-C)/T*n.height;s.push({x:r,y:i})}if(a.showDEA)for(let e=D;e<O;e++){let t=v[e];if(!t)continue;let r=m[e-d.start];if(r===void 0)continue;let i=n.height-(t.dea-C)/T*n.height;c.push({x:r,y:i})}}let A=e.settings?.enableWebGLRendering!==!1,j=!1;if(A&&h?.isAvailable()){let e=[];if(a.showDIF&&s.length>=2&&e.push({points:s,width:1,color:G.DIF}),a.showDEA&&c.length>=2&&e.push({points:c,width:1,color:G.DEA}),e.length>0&&h.drawLineStrips(e,f)){j=!0;let e=h.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/p,e.height/p),t.imageSmoothingEnabled=n}}}j||Bi(t,f,s,c,a)},onDataUpdate(){l()},getConfig(){return{...a}},setConfig(e){let t=!1;`fastPeriod`in e&&e.fastPeriod!==a.fastPeriod&&l(),`slowPeriod`in e&&e.slowPeriod!==a.slowPeriod&&l(),`signalPeriod`in e&&e.signalPeriod!==a.signalPeriod&&l(),`showDIF`in e&&e.showDIF!==a.showDIF&&(t=!0),`showDEA`in e&&e.showDEA!==a.showDEA&&(t=!0),Object.assign(a,e),t&&l()}}}function Ri(e,t,n,r,i,a,o,s,c){if(e.settings?.enableWebGLRendering===!1)return!1;let l=e.candleWebGLSurface;if(!l||!l.isAvailable())return!1;l.clear();let u=n===0||l.drawRectBuffer(t.subarray(0,n*4),n,G.BAR_UP,e.scrollLeft),d=i===0||l.drawRectBuffer(r.subarray(0,i*4),i,G.BAR_UP_LIGHT,e.scrollLeft),f=o===0||l.drawRectBuffer(a.subarray(0,o*4),o,G.BAR_DOWN,e.scrollLeft),p=c===0||l.drawRectBuffer(s.subarray(0,c*4),c,G.BAR_DOWN_LIGHT,e.scrollLeft);return u&&d&&f&&p}function zi(e,t,n,r,i,a,o,s,c,l){e.save(),e.translate(-t,0),e.fillStyle=G.BAR_UP;for(let t=0;t<r;t++){let r=t*4;e.fillRect(n[r],n[r+1],n[r+2],n[r+3])}e.fillStyle=G.BAR_UP_LIGHT;for(let t=0;t<a;t++){let n=t*4;e.fillRect(i[n],i[n+1],i[n+2],i[n+3])}e.fillStyle=G.BAR_DOWN;for(let t=0;t<s;t++){let n=t*4;e.fillRect(o[n],o[n+1],o[n+2],o[n+3])}e.fillStyle=G.BAR_DOWN_LIGHT;for(let t=0;t<l;t++){let n=t*4;e.fillRect(c[n],c[n+1],c[n+2],c[n+3])}e.restore()}function Bi(e,t,n,r,i){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,i.showDIF&&n.length>=2){e.strokeStyle=G.DIF,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(i.showDEA&&r.length>=2){e.strokeStyle=G.DEA,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function Vi(e,t){let n=t.candleWebGLSurface;if(!n)return;let r=n.getCanvas();r.width<=0||r.height<=0||e.drawImage(r,0,0,r.width,r.height,0,0,r.width/t.dpr,r.height/t.dpr)}function Hi(e,t,n,r,i,a=`sub_MACD`){let o=i.getSharedState(zr(a));if(!o)return null;let s=o.series[e];return s?{name:`MACD`,params:[t,n,r],values:[{label:`DIF`,value:s.dif,color:G.DIF},{label:`DEA`,value:s.dea,color:G.DEA},{label:`MACD`,value:s.macd,color:s.macd>=0?G.BAR_UP:G.BAR_DOWN}]}:null}function Ui(e={}){let{paneId:t=`sub`}=e,n=null,r=``,i=[],a=[],o=[],s=null,c=null,l=``;function u(){r=``,i=[],a=[],o=[]}function d(e,t){return(!s||s.width!==e||s.height!==t)&&(s=document.createElement(`canvas`),s.width=e,s.height=t,c=s.getContext(`2d`),l=``),{canvas:s,ctx:c}}function f(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function p(e,t,n,r,i,a){let o=i-r||1,s=Z(n-(80-r)/o*n,a),c=Z(n-(50-r)/o*n,a),l=Z(n-(20-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.lineWidth=1.1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.moveTo(0,c),e.lineTo(t,c),e.moveTo(0,l),e.lineTo(t,l),e.stroke(),e.restore()}function m(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showRSI1,r.showRSI2,r.showRSI3].join(`|`)}return{name:`rsi_${t}`,version:`2.0.0`,description:`RSI 相对强弱指标渲染器(WebGL + Canvas2D 回退)`,debugName:`RSI`,paneId:t,priority:L.MAIN,onInstall(e){n=e},getDeclaredNamespaces(){return[wr(t)]},draw(e){let{ctx:c,pane:h,range:g,scrollLeft:_,dpr:v,kLineCenters:y,lineWebGLSurface:b}=e,x=wr(t),S=n?.getSharedState(x);if(!S||S.visibleMin>S.visibleMax){u();return}let{valueMin:C,valueMax:w,params:T,series:E}=S,D=h.yAxis.getDisplayRange({minPrice:C,maxPrice:w}),O=D.minPrice,k=D.maxPrice,A=k-O||1,j=e.paneWidth,M=h.height,N=f(j,M,O,k,v);if(l!==N){l=N;let{ctx:e}=d(Math.ceil(j*v),Math.ceil(M*v));p(e,j,M,O,k,v)}s&&c.drawImage(s,0,0,j,M);let P=Math.max(g.start,T.period1),F=Math.min(g.end,y.length+g.start),I=m(g,y,h,T);if(r!==I){r=I;let e=M,t=e/A,n=g.start,s=r=>{let i=[];for(let a=P;a<F;a++){let o=r[a];if(o===void 0)continue;let s=y[a-n];s!==void 0&&i.push({x:s,y:e-(o-O)*t})}return i};i=T.showRSI1&&E[T.period1]?s(E[T.period1]):[],a=T.showRSI2&&E[T.period2]?s(E[T.period2]):[],o=T.showRSI3&&E[T.period3]?s(E[T.period3]):[]}let ee=e.settings?.enableWebGLRendering!==!1,te=!1;if(ee&&b?.isAvailable()){let e=[];if(T.showRSI1&&i.length>=2&&e.push({points:i,width:1,color:q.RSI1}),T.showRSI2&&a.length>=2&&e.push({points:a,width:1,color:q.RSI2}),T.showRSI3&&o.length>=2&&e.push({points:o,width:1,color:q.RSI3}),e.length>0&&b.drawLineStrips(e,_)){te=!0;let e=b.getCanvas();if(e.width>0&&e.height>0){let t=c.imageSmoothingEnabled;c.imageSmoothingEnabled=!1,c.drawImage(e,0,0,e.width,e.height,0,0,e.width/v,e.height/v),c.imageSmoothingEnabled=t}}}te||Wi(c,_,i,a,o,T)},getConfig(){let e=wr(t),r=n?.getSharedState(e);return r?{...r.params}:{}},setConfig(e){}}}function Wi(e,t,n,r,i,a){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,a.showRSI1&&n.length>=2){e.strokeStyle=q.RSI1,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(a.showRSI2&&r.length>=2){e.strokeStyle=q.RSI2,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}if(a.showRSI3&&i.length>=2){e.strokeStyle=q.RSI3,e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++){let n=i[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function Gi(e,t,n,r,i,a=`sub_RSI`){let o=wr(a),s=i.getSharedState(o);if(!s)return null;let c=s.series[t]?.[e],l=s.series[n]?.[e],u=s.series[r]?.[e],d=[];return c!==void 0&&d.push({label:`RSI${t}`,value:c,color:q.RSI1}),l!==void 0&&d.push({label:`RSI${n}`,value:l,color:q.RSI2}),u!==void 0&&d.push({label:`RSI${r}`,value:u,color:q.RSI3}),d.length===0?null:{name:`RSI`,params:[t,n,r],values:d}}function Ki(e={}){let{paneId:t=`sub`}=e,n=Er(t),r=null,i=``,a=[];function o(){i=``,a=[]}function s(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showCCI,r.period].join(`|`)}return{name:`cci_${t}`,version:`2.0.0`,description:`CCI 顺势指标渲染器(WebGL + Canvas2D 回退)`,debugName:`CCI`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:c,range:l,scrollLeft:u,dpr:d,kLineCenters:f,lineWebGLSurface:p}=e,m=r?.getSharedState(n);if(!m||m.visibleMin>m.visibleMax){o();return}let{valueMin:h,valueMax:g,params:_,series:v}=m;g-h;let y=c.yAxis.getDisplayRange({minPrice:h,maxPrice:g}),b=y.minPrice,x=y.maxPrice-b||1,S=c.height-(0-b)/x*c.height;t.save(),t.translate(-u,0);let C=c.height-(100-b)/x*c.height,w=c.height-(-100-b)/x*c.height,T=u,E=u+e.paneWidth;t.strokeStyle=Pe.OVERBOUGHT,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(T,C),t.lineTo(E,C),t.stroke(),t.strokeStyle=Pe.OVERSOLD,t.beginPath(),t.moveTo(T,w),t.lineTo(E,w),t.stroke(),t.strokeStyle=`rgba(0, 0, 0, 0.1)`,t.beginPath(),t.moveTo(T,S),t.lineTo(E,S),t.stroke(),t.setLineDash([]),t.restore();let D=Math.max(l.start,_.period-1),O=Math.min(l.end,v.length),k=s(l,f,c,_);if(i!==k&&(i=k,a=[],_.showCCI))for(let e=D;e<O;e++){let t=v[e];if(t===void 0)continue;let n=f[e-l.start];if(n===void 0)continue;let r=c.height-(t-b)/x*c.height;a.push({x:n,y:r})}let A=e.settings?.enableWebGLRendering!==!1,j=!1;if(A&&p?.isAvailable()&&_.showCCI&&a.length>=2&&p.drawLineStrips([{points:a,width:1,color:Pe.CCI}],u)){j=!0;let e=p.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/d,e.height/d),t.imageSmoothingEnabled=n}}j||qi(t,u,a,_)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function qi(e,t,n,r){if(!(!r.showCCI||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Pe.CCI,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function Ji(e,t,n,r=`sub_CCI`){let i=n.getSharedState(Er(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`CCI`,params:[t],values:[{label:`CCI`,value:a,color:Pe.CCI}]}}function Yi(e={}){let{paneId:t=`sub`}=e,n=Or(t),r=null,i=``,a=[],o=[],s=null,c=null,l=``;function u(){i=``,a=[],o=[]}function d(e,t){return(!s||s.width!==e||s.height!==t)&&(s=document.createElement(`canvas`),s.width=e,s.height=t,c=s.getContext(`2d`),l=``),{canvas:s,ctx:c}}function f(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function p(e,t,n,r,i,a){let o=i-r||1,s=Z(n-(80-r)/o*n,a),c=Z(n-(20-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.moveTo(0,c),e.lineTo(t,c),e.stroke(),e.restore()}function m(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showK,r.showD,r.n,r.m].join(`|`)}return{name:`stoch_${t}`,version:`2.0.0`,description:`STOCH 随机指标渲染器(WebGL + Canvas2D 回退)`,debugName:`STOCH`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:c,range:h,scrollLeft:g,dpr:_,kLineCenters:v,lineWebGLSurface:y}=e,b=r?.getSharedState(n);if(!b||b.visibleMin>b.visibleMax){u();return}let{valueMin:x,valueMax:S,params:C,series:w}=b,T=c.yAxis.getDisplayRange({minPrice:x,maxPrice:S}),E=T.minPrice,D=T.maxPrice,O=D-E||1,k=e.paneWidth,A=c.height,j=f(k,A,E,D,_);if(l!==j){l=j;let{ctx:e}=d(Math.ceil(k*_),Math.ceil(A*_));p(e,k,A,E,D,_)}s&&t.drawImage(s,0,0,k,A);let M=Math.max(h.start,C.n+C.m-2),N=Math.min(h.end,w.length),P=m(h,v,c,C);if(i!==P){i=P;let e=A,t=e/O,n=h.start;if(C.showK){let r=[];for(let i=M;i<N;i++){let a=w[i];if(!a)continue;let o=v[i-n];o!==void 0&&r.push({x:o,y:e-(a.k-E)*t})}a=r}else a=[];if(C.showD){let r=[];for(let i=M;i<N;i++){let a=w[i];if(!a)continue;let o=v[i-n];o!==void 0&&r.push({x:o,y:e-(a.d-E)*t})}o=r}else o=[]}let F=e.settings?.enableWebGLRendering!==!1,I=!1;if(F&&y?.isAvailable()){let e=[];if(C.showK&&a.length>=2&&e.push({points:a,width:1,color:J.K}),C.showD&&o.length>=2&&e.push({points:o,width:1,color:J.D}),e.length>0&&y.drawLineStrips(e,g)){I=!0;let e=y.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/_,e.height/_),t.imageSmoothingEnabled=n}}}I||Xi(t,g,a,o,C)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function Xi(e,t,n,r,i){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,i.showK&&n.length>=2){e.strokeStyle=J.K,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(i.showD&&r.length>=2){e.strokeStyle=J.D,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function Zi(e,t,n,r,i=`sub_STOCH`){let a=r.getSharedState(Or(i));if(!a)return null;let o=a.series[e];if(!o||o.k===void 0)return null;let s=[];return a.params.showK&&s.push({label:`K`,value:o.k,color:J.K}),a.params.showD&&s.push({label:`D`,value:o.d,color:J.D}),s.length===0?null:{name:`STOCH`,params:[t,n],values:s}}function Qi(e={}){let{paneId:t=`sub`}=e,n=Ar(t),r=null,i=``,a=[],o=null,s=null,c=``;function l(){i=``,a=[]}function u(e,t){return(!o||o.width!==e||o.height!==t)&&(o=document.createElement(`canvas`),o.width=e,o.height=t,s=o.getContext(`2d`),c=``),{canvas:o,ctx:s}}function d(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function f(e,t,n,r,i,a){let o=i-r||1,s=Z(n-(0-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=Fe.ZERO,e.lineWidth=1,e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.stroke(),e.restore()}function p(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showMOM,r.period].join(`|`)}return{name:`mom_${t}`,version:`2.0.0`,description:`MOM 动量指标渲染器(WebGL + Canvas2D 回退)`,debugName:`MOM`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:s,range:m,scrollLeft:h,dpr:g,kLineCenters:_,lineWebGLSurface:v}=e,y=r?.getSharedState(n);if(!y||y.visibleMin>y.visibleMax){l();return}let{valueMin:b,valueMax:x,params:S,series:C}=y,w=s.yAxis.getDisplayRange({minPrice:b,maxPrice:x}),T=w.minPrice,E=w.maxPrice,D=E-T||1,O=e.paneWidth,k=s.height,A=d(O,k,T,E,g);if(c!==A){c=A;let{ctx:e}=u(Math.ceil(O*g),Math.ceil(k*g));f(e,O,k,T,E,g)}o&&t.drawImage(o,0,0,O,k);let j=Math.max(m.start,S.period),M=Math.min(m.end,C.length),N=p(m,_,s,S);if(i!==N){i=N;let e=k,t=e/D,n=m.start;if(S.showMOM){let r=[];for(let i=j;i<M;i++){let a=C[i];if(a===void 0)continue;let o=_[i-n];o!==void 0&&r.push({x:o,y:e-(a-T)*t})}a=r}else a=[]}let P=e.settings?.enableWebGLRendering!==!1,F=!1;if(P&&v?.isAvailable()&&S.showMOM&&a.length>=2&&v.drawLineStrips([{points:a,width:1,color:Fe.MOM}],h)){F=!0;let e=v.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/g,e.height/g),t.imageSmoothingEnabled=n}}F||$i(t,h,a,S)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function $i(e,t,n,r){if(!(!r.showMOM||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Fe.MOM,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function ea(e,t,n,r=`sub_MOM`){let i=n.getSharedState(Ar(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`MOM`,params:[t],values:[{label:`MOM`,value:a,color:Fe.MOM}]}}function ta(e={}){let{paneId:t=`sub`}=e,n=Mr(t),r=null,i=``,a=[],o=null,s=null,c=``;function l(){i=``,a=[]}function u(e,t){return(!o||o.width!==e||o.height!==t)&&(o=document.createElement(`canvas`),o.width=e,o.height=t,s=o.getContext(`2d`),c=``),{canvas:o,ctx:s}}function d(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function f(e,t,n,r,i,a){let o=i-r||1,s=Z(n-(-20-r)/o*n,a),c=Z(n-(-80-r)/o*n,a),l=Z(n-(-50-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.lineWidth=1,e.setLineDash([4,4]),e.strokeStyle=Ie.OVERBOUGHT,e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.stroke(),e.strokeStyle=Ie.OVERSOLD,e.beginPath(),e.moveTo(0,c),e.lineTo(t,c),e.stroke(),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.beginPath(),e.moveTo(0,l),e.lineTo(t,l),e.stroke(),e.restore()}function p(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showWMSR,r.period].join(`|`)}return{name:`wmsr_${t}`,version:`2.0.0`,description:`WMSR 威廉指标渲染器(WebGL + Canvas2D 回退)`,debugName:`WMSR`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:s,range:m,scrollLeft:h,dpr:g,kLineCenters:_,lineWebGLSurface:v}=e,y=r?.getSharedState(n);if(!y||y.visibleMin>y.visibleMax){l();return}let{valueMin:b,valueMax:x,params:S,series:C}=y,w=s.yAxis.getDisplayRange({minPrice:b,maxPrice:x}),T=w.minPrice,E=w.maxPrice,D=E-T||1,O=e.paneWidth,k=s.height,A=d(O,k,T,E,g);if(c!==A){c=A;let{ctx:e}=u(Math.ceil(O*g),Math.ceil(k*g));f(e,O,k,T,E,g)}o&&t.drawImage(o,0,0,O,k);let j=Math.max(m.start,S.period-1),M=Math.min(m.end,C.length),N=p(m,_,s,S);if(i!==N){i=N;let e=k,t=e/D,n=m.start;if(S.showWMSR){let r=[];for(let i=j;i<M;i++){let a=C[i];if(a===void 0)continue;let o=_[i-n];o!==void 0&&r.push({x:o,y:e-(a-T)*t})}a=r}else a=[]}let P=e.settings?.enableWebGLRendering!==!1,F=!1;if(P&&v?.isAvailable()&&S.showWMSR&&a.length>=2&&v.drawLineStrips([{points:a,width:1,color:Ie.WMSR}],h)){F=!0;let e=v.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/g,e.height/g),t.imageSmoothingEnabled=n}}F||na(t,h,a,S)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function na(e,t,n,r){if(!(!r.showWMSR||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Ie.WMSR,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function ra(e,t,n,r=`sub_WMSR`){let i=n.getSharedState(Mr(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`WMSR`,params:[t],values:[{label:`WMSR`,value:a,color:Ie.WMSR}]}}function ia(e={}){let{paneId:t=`sub`}=e,n=Pr(t),r=null,i=``,a=[],o=[];function s(){i=``,a=[],o=[]}function c(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showKST,r.showSignal,r.roc1,r.roc2,r.roc3,r.roc4,r.signalPeriod].join(`|`)}return{name:`kst_${t}`,version:`2.0.0`,description:`KST 确知指标渲染器(WebGL + Canvas2D 回退)`,debugName:`KST`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:l,range:u,scrollLeft:d,dpr:f,kLineCenters:p,lineWebGLSurface:m}=e,h=r?.getSharedState(n);if(!h||h.visibleMin>h.visibleMax){s();return}let{valueMin:g,valueMax:_,params:v,series:y}=h;_-g;let b=l.yAxis.getDisplayRange({minPrice:g,maxPrice:_}),x=b.minPrice,S=b.maxPrice-x||1,C=l.height-(0-x)/S*l.height;t.save(),t.translate(-d,0);let w=d,T=d+e.paneWidth;t.strokeStyle=`rgba(0, 0, 0, 0.1)`,t.lineWidth=1,t.beginPath(),t.moveTo(w,C),t.lineTo(T,C),t.stroke(),t.restore();let E=Math.max(u.start,v.roc4+15+v.signalPeriod-1),D=Math.min(u.end,y.length),O=c(u,p,l,v);if(i!==O){if(i=O,a=[],o=[],v.showKST)for(let e=E;e<D;e++){let t=y[e];if(!t)continue;let n=p[e-u.start];if(n===void 0)continue;let r=l.height-(t.kst-x)/S*l.height;a.push({x:n,y:r})}if(v.showSignal)for(let e=E;e<D;e++){let t=y[e];if(!t)continue;let n=p[e-u.start];if(n===void 0)continue;let r=l.height-(t.signal-x)/S*l.height;o.push({x:n,y:r})}}let k=e.settings?.enableWebGLRendering!==!1,A=!1;if(k&&m?.isAvailable()){let e=[];if(v.showKST&&a.length>=2&&e.push({points:a,width:1,color:Le.KST}),v.showSignal&&o.length>=2&&e.push({points:o,width:1,color:Le.SIGNAL}),e.length>0&&m.drawLineStrips(e,d)){A=!0;let e=m.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/f,e.height/f),t.imageSmoothingEnabled=n}}}A||aa(t,d,a,o,v)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function aa(e,t,n,r,i){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,i.showKST&&n.length>=2){e.strokeStyle=Le.KST,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(i.showSignal&&r.length>=2){e.strokeStyle=Le.SIGNAL,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function oa(e,t,n,r,i,a,o,s=`sub_KST`){let c=o.getSharedState(Pr(s));if(!c)return null;let l=c.series[e];if(!l)return null;let u=[];return c.params.showKST&&u.push({label:`KST`,value:l.kst,color:Le.KST}),c.params.showSignal&&u.push({label:`Signal`,value:l.signal,color:Le.SIGNAL}),u.length===0?null:{name:`KST`,params:[t,n,r,i,a],values:u}}function sa(e={}){let{paneId:t=`sub`}=e,n=Ir(t),r=null,i=``,a=[],o=null,s=null,c=``;function l(){i=``,a=[]}function u(e,t){return(!o||o.width!==e||o.height!==t)&&(o=document.createElement(`canvas`),o.width=e,o.height=t,s=o.getContext(`2d`),c=``),{canvas:o,ctx:s}}function d(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function f(e,t,n,r,i,a){let o=i-r||1,s=Z(n-(80-r)/o*n,a),c=Z(n-(20-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.moveTo(0,c),e.lineTo(t,c),e.stroke(),e.restore()}function p(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showFASTK,r.period].join(`|`)}return{name:`fastk_${t}`,version:`2.0.0`,description:`FASTK 快速随机指标渲染器(WebGL + Canvas2D 回退)`,debugName:`FASTK`,paneId:t,priority:L.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:s,range:m,scrollLeft:h,dpr:g,kLineCenters:_,lineWebGLSurface:v}=e,y=r?.getSharedState(n);if(!y||y.visibleMin>y.visibleMax){l();return}let{valueMin:b,valueMax:x,params:S,series:C}=y,w=s.yAxis.getDisplayRange({minPrice:b,maxPrice:x}),T=w.minPrice,E=w.maxPrice,D=E-T||1,O=e.paneWidth,k=s.height,A=d(O,k,T,E,g);if(c!==A){c=A;let{ctx:e}=u(Math.ceil(O*g),Math.ceil(k*g));f(e,O,k,T,E,g)}o&&t.drawImage(o,0,0,O,k);let j=Math.max(m.start,S.period-1),M=Math.min(m.end,C.length),N=p(m,_,s,S);if(i!==N){i=N;let e=k,t=e/D,n=m.start;if(S.showFASTK){let r=[];for(let i=j;i<M;i++){let a=C[i];if(a===void 0)continue;let o=_[i-n];o!==void 0&&r.push({x:o,y:e-(a-T)*t})}a=r}else a=[]}let P=e.settings?.enableWebGLRendering!==!1,F=!1;if(P&&v?.isAvailable()&&S.showFASTK&&a.length>=2&&v.drawLineStrips([{points:a,width:1,color:J.K}],h)){F=!0;let e=v.getCanvas();if(e.width>0&&e.height>0){let n=t.imageSmoothingEnabled;t.imageSmoothingEnabled=!1,t.drawImage(e,0,0,e.width,e.height,0,0,e.width/g,e.height/g),t.imageSmoothingEnabled=n}}F||ca(t,h,a,S)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function ca(e,t,n,r){if(!(!r.showFASTK||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=J.K,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function la(e,t,n,r=`sub_FASTK`){let i=n.getSharedState(Ir(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`FASTK`,params:[t],values:[{label:`FASTK`,value:a,color:J.K}]}}function ua(e){let{indicatorId:t,paneId:n}=e;switch(t){case`VOLUME`:return li({paneId:n});case`MACD`:return Li({paneId:n});case`RSI`:return Ui({paneId:n});case`CCI`:return Ki({paneId:n});case`STOCH`:return Yi({paneId:n});case`MOM`:return Qi({paneId:n});case`WMSR`:return ta({paneId:n});case`KST`:return ia({paneId:n});case`FASTK`:return sa({paneId:n});default:throw Error(`Unknown indicator: ${t}`)}}var da=8,fa=6,pa=class e{chart;activeTool=`cursor`;pendingAnchors=[];drawings=[];callbacks={};previewDrawingId=`__preview__`;dragState=null;selectedDrawingId=null;static SINGLE_ANCHOR_TOOLS=[`h-line`,`h-ray`,`v-line`,`crosshair-line`];static DOUBLE_ANCHOR_TOOLS=[`trend-line`,`ray`,`info-line`,`regression-channel`];static TRIPLE_ANCHOR_TOOLS=[`parallel-channel`,`flat-line`,`disjoint-channel`];constructor(e){this.chart=e}setCallbacks(e){this.callbacks=e}getActiveTool(){return this.activeTool}setTool(e){this.activeTool=e,this.pendingAnchors=[],this.removePreview(),this.dragState=null,this.setSelected(null),this.callbacks.onToolChange?.(e)}getDrawings(){return this.drawings}setDrawings(e){this.drawings=e,this.chart.setDrawings(e)}clear(){this.pendingAnchors=[],this.removePreview(),this.dragState=null,this.setSelected(null)}getSelectedDrawing(){return this.selectedDrawingId?this.drawings.find(e=>e.id===this.selectedDrawingId)??null:null}updateDrawingStyle(e,t){this.drawings=this.drawings.map(n=>n.id===e?{...n,style:{...n.style,...t}}:n),this.chart.setDrawings(this.drawings)}removeDrawing(e){this.drawings=this.drawings.filter(t=>t.id!==e),this.selectedDrawingId===e&&this.setSelected(null),this.chart.setDrawings(this.drawings)}onPointerMove(e,t){return this.dragState?this.handleDragMove(e,t):this.activeTool===`cursor`?!1:this.handlePreviewMove(e,t)}onPointerDown(t,n){if(this.activeTool===`cursor`)return this.handleCursorDown(t,n);let r=this.resolveAnchorFromPointer(t,n);if(!r)return!1;if(e.SINGLE_ANCHOR_TOOLS.includes(this.activeTool))return this.createSingleAnchorDrawing(r),!0;let i=e.DOUBLE_ANCHOR_TOOLS.includes(this.activeTool),a=e.TRIPLE_ANCHOR_TOOLS.includes(this.activeTool);if(!i&&!a)return!1;this.pendingAnchors.push(r);let o=i?2:3;return this.pendingAnchors.length>=o&&(this.createMultiAnchorDrawing(this.pendingAnchors),this.pendingAnchors=[]),!0}onPointerUp(e,t){return this.dragState?(this.dragState=null,!0):!1}handleCursorDown(e,t){let n=t.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top,a=this.hitTest(r,i);return a?(this.setSelected(a.drawing),this.dragState={drawingId:a.drawing.id,anchorIndex:`anchorIndex`in a?a.anchorIndex:void 0,snapshot:a.drawing.anchors.map(e=>({...e})),startMouse:{x:r,y:i}},!0):(this.setSelected(null),!1)}handleDragMove(e,t){if(!this.dragState)return!1;let n=this.drawings.find(e=>e.id===this.dragState.drawingId);if(!n)return this.dragState=null,!1;let r=this.resolveAnchorFromPointer(e,t);if(this.dragState.anchorIndex!==void 0){if(r){let e=this.dragState.anchorIndex;n.anchors[e]={...n.anchors[e],index:r.index,time:r.time,price:r.price},n.kind===`flat-line`&&e===1&&n.anchors.length>=3&&(n.anchors[2]={...n.anchors[2],index:r.index,time:r.time})}}else{let r=t.getBoundingClientRect(),i=e.clientX-r.left,a=e.clientY-r.top,o=i-this.dragState.startMouse.x,s=a-this.dragState.startMouse.y;for(let e=0;e<n.anchors.length;e++){let t=this.dragState.snapshot[e],r=this.anchorToScreen(t);if(!r)continue;let i=r.x+o,a=r.y+s,c=this.screenToAnchor(i,a);c&&(n.anchors[e]={...n.anchors[e],index:c.index,time:c.time,price:c.price})}}return this.chart.setDrawings([...this.drawings]),!0}handlePreviewMove(t,n){let r=this.resolveAnchorFromPointer(t,n);if(!r)return this.removePreview(),!1;let i=e.SINGLE_ANCHOR_TOOLS.includes(this.activeTool),a=e.DOUBLE_ANCHOR_TOOLS.includes(this.activeTool),o=e.TRIPLE_ANCHOR_TOOLS.includes(this.activeTool);if(!i&&!a&&!o)return!1;let s;if(i)s={id:this.previewDrawingId,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:r.index,time:r.time,price:r.price}],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`}};else if(a&&this.pendingAnchors.length>=1)s={id:this.previewDrawingId,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:this.pendingAnchors[0].index,time:this.pendingAnchors[0].time,price:this.pendingAnchors[0].price},{id:`${this.previewDrawingId}-b`,index:r.index,time:r.time,price:r.price}],params:this.activeTool===`regression-channel`?{sigma:2}:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`,...this.activeTool===`regression-channel`?{fillOpacity:.1}:{}}};else if(o){if(this.pendingAnchors.length===0)return!1;if(this.pendingAnchors.length===1)s={id:this.previewDrawingId,kind:`trend-line`,paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:this.pendingAnchors[0].index,time:this.pendingAnchors[0].time,price:this.pendingAnchors[0].price},{id:`${this.previewDrawingId}-b`,index:r.index,time:r.time,price:r.price}],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`}};else{let e=this.activeTool===`flat-line`?{id:`${this.previewDrawingId}-c`,index:this.pendingAnchors[1].index,time:this.pendingAnchors[1].time,price:r.price}:{id:`${this.previewDrawingId}-c`,index:r.index,time:r.time,price:r.price};s={id:this.previewDrawingId,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:this.pendingAnchors[0].index,time:this.pendingAnchors[0].time,price:this.pendingAnchors[0].price},{id:`${this.previewDrawingId}-b`,index:this.pendingAnchors[1].index,time:this.pendingAnchors[1].time,price:this.pendingAnchors[1].price},e],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`,fillOpacity:.1}}}}else return!1;return this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId),this.drawings=[...this.drawings,s],this.chart.setDrawings(this.drawings),!0}hitTest(e,t){let n=this.drawings.filter(e=>e.id!==this.previewDrawingId&&e.visible),r=new Map;for(let i of n){if(i.kind===`regression-channel`&&i.anchors.length>=2){let n=this.hitTestRegressionEndpoints(i,e,t,r);if(n)return n}for(let n=0;n<i.anchors.length;n++){let r=this.anchorToScreen(i.anchors[n]);if(r&&Math.hypot(e-r.x,t-r.y)<=da)return{drawing:i,anchorIndex:n}}}for(let i of n){let n=this.getDrawingLineSegments(i,r);for(let r of n)if(ma(e,t,r.a,r.b)<=fa)return{drawing:i}}return null}getDrawingLineSegments(e,t){let n=this.chart.getViewport();if(!n)return[];if(e.kind===`regression-channel`)return this.getRegressionChannelGeometry(e,t)?.segments??[];if(e.anchors.length===1){let t=this.anchorToScreen(e.anchors[0]);if(!t)return[];let r=this.chart.getPaneRenderers().find(e=>e.getPane().id===`main`)?.getPane();if(!r)return[];let i=n.plotWidth,a=r.height;switch(e.kind){case`horizontal-line`:return[{a:{x:0,y:t.y},b:{x:i,y:t.y}}];case`horizontal-ray`:return[{a:t,b:{x:i,y:t.y}}];case`vertical-line`:return[{a:{x:t.x,y:0},b:{x:t.x,y:a}}];case`cross-line`:return[{a:{x:0,y:t.y},b:{x:i,y:t.y}},{a:{x:t.x,y:0},b:{x:t.x,y:a}}];default:return[]}}let r=e.anchors.map(e=>this.anchorToScreen(e)).filter(Boolean);if(r.length<2)return[];let i=[];if(r.length===2){let t=r[0],a=r[1],o=a.x-t.x,s=a.y-t.y,c=t,l=a,u=this.getExtendMode(e),d=Math.max(n.plotWidth,n.plotHeight)*4;(u===`right`||u===`both`)&&(l={x:a.x+o*d,y:a.y+s*d}),(u===`left`||u===`both`)&&(c={x:t.x-o*d,y:t.y-s*d}),i.push({a:c,b:l})}else if(r.length>=3)switch(e.kind){case`parallel-channel`:{let[e,t,n]=r,a=t.x-e.x,o=t.y-e.y,s={x:n.x+a,y:n.y+o};i.push({a:e,b:t},{a:n,b:s});break}case`flat-line`:{let[e,t,n]=r,a={x:e.x,y:n.y},o={x:t.x,y:n.y};i.push({a:e,b:t}),i.push({a,b:o});break}case`disjoint-channel`:{let[e,t,n]=r,a=t.x-e.x,o=t.y-e.y,s={x:n.x+a,y:n.y-o};i.push({a:e,b:t}),i.push({a:n,b:s});break}default:for(let e=0;e<r.length-1;e++)i.push({a:r[e],b:r[e+1]})}return i}hitTestRegressionEndpoints(e,t,n,r){let i=this.getRegressionChannelGeometry(e,r);if(!i)return null;for(let r of i.endpoints)if(Math.hypot(t-r.point.x,n-r.point.y)<=da)return{drawing:e,anchorIndex:r.anchorIndex};return null}getRegressionChannelGeometry(e,t){let n=t?.get(e.id);if(n!==void 0)return n;let r=this.chart.getData();if(r.length===0||e.anchors.length<2)return t?.set(e.id,null),null;let i=Math.round(e.anchors[0].index),a=Math.round(e.anchors[1].index),o=Math.min(Math.max(i,0),r.length-1),s=Math.min(Math.max(a,0),r.length-1),c=Math.min(o,s),l=Math.max(o,s),u=r.slice(c,l+1),d=Ca(u.map(e=>e.close));if(!d)return t?.set(e.id,null),null;let f=e.params?.sigma??2,p=d.stdDev*f,m=d.intercept,h=d.intercept+d.slope*(u.length-1),g=this.anchorToScreen({id:``,index:i,price:m}),_=this.anchorToScreen({id:``,index:a,price:h}),v=this.anchorToScreen({id:``,index:i,price:m+p}),y=this.anchorToScreen({id:``,index:a,price:h+p}),b=this.anchorToScreen({id:``,index:i,price:m-p}),x=this.anchorToScreen({id:``,index:a,price:h-p}),S=[];g&&_&&S.push({a:g,b:_}),v&&y&&S.push({a:v,b:y}),b&&x&&S.push({a:b,b:x});let C=[];g&&C.push({point:g,anchorIndex:0}),_&&C.push({point:_,anchorIndex:1}),v&&C.push({point:v,anchorIndex:0}),y&&C.push({point:y,anchorIndex:1}),b&&C.push({point:b,anchorIndex:0}),x&&C.push({point:x,anchorIndex:1});let w={segments:S,endpoints:C};return t?.set(e.id,w),w}getExtendMode(e){switch(e.kind){case`ray`:return`right`;case`extended-line`:return`both`;default:return`none`}}anchorToScreen(e){let t=this.chart.getViewport();if(!t)return null;let n=this.chart.getOption(),r=this.chart.getCurrentDpr(),{startXPx:i,unitPx:a}=R(n.kWidth,n.kGap,r);if(!Number.isFinite(e.index))return null;let o=(i+e.index*a+(a-1)/2)/r-t.scrollLeft,s=this.chart.getPaneRenderers().find(e=>e.getPane().id===`main`)?.getPane();return s?{x:o,y:s.yAxis.priceToY(e.price)}:null}screenToAnchor(e,t){let n=this.chart.getData();if(!this.chart.getViewport()||n.length===0)return null;let r=this.chart.getLogicalIndexAtX(e);if(r===null)return null;let i=this.chart.getPaneRenderers().find(e=>e.getPane().id===`main`)?.getPane();return i?{index:r,time:this.chart.getTimestampAtLogicalIndex(r)??void 0??void 0,price:i.yAxis.yToPrice(t-i.top)}:null}setSelected(e){let t=e?.id??null;this.selectedDrawingId!==t&&(this.selectedDrawingId=t,this.chart.setSelectedDrawingId(t),this.callbacks.onDrawingSelected?.(e))}removePreview(){this.drawings.some(e=>e.id===this.previewDrawingId)&&(this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId),this.chart.setDrawings(this.drawings))}resolveAnchorFromPointer(e,t){let n=this.chart.getData(),r=this.chart.getViewport();if(!r||n.length===0)return null;let i=t.getBoundingClientRect(),a=e.clientX-i.left,o=e.clientY-i.top;if(a<0||o<0||a>r.plotWidth||o>r.plotHeight)return null;let s=this.chart.getPaneRenderers().find(e=>{let t=e.getPane();return t.id===`main`&&o>=t.top&&o<=t.top+t.height})?.getPane();if(!s)return null;let c=this.chart.getLogicalIndexAtX(a);return c===null?null:{index:c,time:this.chart.getTimestampAtLogicalIndex(c)??void 0??void 0,price:s.yAxis.yToPrice(o-s.top)}}createSingleAnchorDrawing(e){this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId);let t={id:`drawing-${Date.now()}`,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${Date.now()}-a`,index:e.index,time:e.time,price:e.price}],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`solid`}};this.drawings=[...this.drawings,t],this.chart.setDrawings(this.drawings),this.callbacks.onDrawingCreated?.(t),this.activeTool=`cursor`,this.callbacks.onToolChange?.(`cursor`)}createMultiAnchorDrawing(e){this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId);let t=this.getDrawingKind(this.activeTool),n=t===`regression-channel`?{sigma:2}:{},r=t===`flat-line`&&e.length>=3?[e[0],e[1],{index:e[1].index,time:e[1].time,price:e[2].price}]:e,i=[`parallel-channel`,`regression-channel`,`flat-line`,`disjoint-channel`].includes(t),a={id:`drawing-${Date.now()}`,kind:t,paneId:`main`,visible:!0,anchors:r.map((e,t)=>({id:`${Date.now()}-${String.fromCharCode(97+t)}`,index:e.index,time:e.time,price:e.price})),params:n,style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`solid`,...i?{fillOpacity:.1}:{}}};this.drawings=[...this.drawings,a],this.chart.setDrawings(this.drawings),this.callbacks.onDrawingCreated?.(a),this.activeTool=`cursor`,this.callbacks.onToolChange?.(`cursor`)}getDrawingKind(e){switch(e){case`cursor`:throw Error(`cursor is not a drawing kind`);case`h-line`:return`horizontal-line`;case`h-ray`:return`horizontal-ray`;case`v-line`:return`vertical-line`;case`crosshair-line`:return`cross-line`;default:return e}}};function ma(e,t,n,r){let i=r.x-n.x,a=r.y-n.y,o=i*i+a*a;if(o===0)return Math.hypot(e-n.x,t-n.y);let s=((e-n.x)*i+(t-n.y)*a)/o;return s=Math.max(0,Math.min(1,s)),Math.hypot(e-(n.x+s*i),t-(n.y+s*a))}var ha=class{drawings=[];selectedId=null;getSelectedId(){return this.selectedId}setSelectedId(e){this.selectedId=e}getAll(){return this.drawings}getVisibleByPane(e){return this.drawings.filter(t=>t.visible&&t.paneId===e).sort((e,t)=>(e.zIndex??0)-(t.zIndex??0))}setAll(e){this.drawings=[...e],this.selectedId&&!this.drawings.some(e=>e.id===this.selectedId)&&(this.selectedId=null)}upsert(e){let t=this.drawings.findIndex(t=>t.id===e.id);if(t>=0){this.drawings[t]=e;return}this.drawings.push(e)}remove(e){this.drawings=this.drawings.filter(t=>t.id!==e)}clear(){this.drawings=[],this.selectedId=null}},ga=class{definitions=new Map;register(e){this.definitions.set(e.kind,e)}get(e){return this.definitions.get(e)}compute(e,t){let n=this.get(e.kind);return n?n.compute(e,t):null}};function _a(e,t){if(e.strokeStyle=t?.stroke??`#2962ff`,e.lineWidth=t?.strokeWidth??1,t?.strokeStyle===`dashed`){e.setLineDash([6,4]);return}if(t?.strokeStyle===`dotted`){e.setLineDash([2,3]);return}e.setLineDash([])}function va(e,t){e.fillStyle=t?.fill??t?.stroke??`#2962ff`,e.globalAlpha=t?.fillOpacity??1}function ya(e,t,n,r,i){let a=(e,t)=>{let n=0;return e<i.left?n|=1:e>i.right&&(n|=2),t<i.top?n|=8:t>i.bottom&&(n|=4),n},o=e,s=t,c=n,l=r;for(;;){let e=a(o,s),t=a(c,l);if(!(e|t))return{a:{x:o,y:s},b:{x:c,y:l}};if(e&t)return null;let n=e||t,r=0,u=0;n&8?(r=o+(c-o)*(i.top-s)/(l-s),u=i.top):n&4?(r=o+(c-o)*(i.bottom-s)/(l-s),u=i.bottom):n&2?(u=s+(l-s)*(i.right-o)/(c-o),r=i.right):(u=s+(l-s)*(i.left-o)/(c-o),r=i.left),n===e?(o=r,s=u):(c=r,l=u)}}function ba(e,t){let{a:n,b:r,extend:i=`none`}=e;if(i===`none`)return ya(n.x,n.y,r.x,r.y,t);let a=r.x-n.x,o=r.y-n.y;if(a===0&&o===0)return null;let s=Math.max(t.right-t.left,t.bottom-t.top)*4,c=n,l=r;return(i===`left`||i===`both`)&&(c={x:n.x-a*s,y:n.y-o*s}),(i===`right`||i===`both`)&&(l={x:r.x+a*s,y:r.y+o*s}),ya(c.x,c.y,l.x,l.y,t)}function xa(e,t){if(!Number.isFinite(e.index))return-1;let n=Math.round(e.index);return n<0||n>=t.length?-1:n}function Sa(e,t=2){if(!Number.isFinite(e))return`0`;let n=e.toFixed(t);return e>0?`+${n}`:n}function Ca(e){let t=e.length;if(t<2)return null;let n=0,r=0,i=0,a=0;for(let o=0;o<t;o++){let t=o,s=e[o];n+=t,r+=s,i+=t*s,a+=t*t}let o=t*a-n*n;if(o===0)return null;let s=(t*i-n*r)/o,c=(r-s*n)/t,l=0;for(let n=0;n<t;n++){let t=c+s*n,r=e[n]-t;l+=r*r}return{slope:s,intercept:c,stdDev:Math.sqrt(l/t)}}function wa(){return{point(e,t,n){let r=t.style?.pointRadius??4;e.save(),e.fillStyle=t.style?.fill??t.style?.stroke??`#2962ff`,e.beginPath(),e.arc(t.point.x,t.point.y,Math.max(r,1/n),0,Math.PI*2),e.fill(),e.restore()},line(e,t,n,r){let i=ba(t,n);if(!i)return;e.save(),_a(e,t.style);let a=(t.style?.strokeWidth??1)<=1?.5/r:0;if(e.beginPath(),e.moveTo(i.a.x+a,i.a.y+a),e.lineTo(i.b.x+a,i.b.y+a),e.stroke(),t.showEndpoints!==!1){let n=t.style?.pointRadius??4;e.fillStyle=t.style?.stroke??`#2962ff`,e.beginPath(),e.arc(t.a.x,t.a.y,Math.max(n,1/r),0,Math.PI*2),e.fill(),e.beginPath(),e.arc(t.b.x,t.b.y,Math.max(n,1/r),0,Math.PI*2),e.fill()}e.restore()},area(e,t){if(t.points.length!==0){e.save(),va(e,t.style),e.beginPath(),e.moveTo(t.points[0].x,t.points[0].y);for(let n=1;n<t.points.length;n++){let r=t.points[n];e.lineTo(r.x,r.y)}t.closed&&e.closePath(),e.fill(),e.restore()}},text(e,t){e.save(),e.fillStyle=t.style?.textColor??t.style?.stroke??`#2962ff`,e.font=`${t.style?.fontSize??12}px sans-serif`,e.textAlign=t.align??`left`,e.textBaseline=t.baseline??`bottom`,e.fillText(t.text,t.point.x,t.point.y),e.restore()}}}function Ta(e,t){return{kind:e,minAnchors:2,maxAnchors:2,compute(e,n){let[r,i]=e.anchors;return!r||!i?{primitives:[]}:{primitives:[{kind:`line`,a:n.toScreen(r),b:n.toScreen(i),extend:t,style:e.style}]}}}}function Ea(e){return{kind:e,minAnchors:1,maxAnchors:1,compute(t,n){let[r]=t.anchors;if(!r)return{primitives:[]};let i=n.toScreen(r),a=n.pane.height,o=n.viewport.plotWidth;return e===`horizontal-line`?{primitives:[{kind:`line`,a:{x:0,y:i.y},b:{x:o,y:i.y},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}:e===`horizontal-ray`?{primitives:[{kind:`line`,a:i,b:{x:o,y:i.y},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}:e===`vertical-line`?{primitives:[{kind:`line`,a:{x:i.x,y:0},b:{x:i.x,y:a},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}:{primitives:[{kind:`line`,a:{x:0,y:i.y},b:{x:o,y:i.y},showEndpoints:!1,style:t.style},{kind:`line`,a:{x:i.x,y:0},b:{x:i.x,y:a},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}}}}function Da(){return{kind:`info-line`,minAnchors:2,maxAnchors:2,compute(e,t){let[n,r]=e.anchors;if(!n||!r)return{primitives:[]};let i=t.toScreen(n),a=t.toScreen(r),o=Math.round(n.index),s=Math.round(r.index)-o,c=r.price-n.price,l=n.price===0?0:c/n.price*100,u=Math.atan2(a.y-i.y,a.x-i.x)*(180/Math.PI),d=`${Sa(c)} (${Sa(l)}%) ${s} bars ${Sa(u)}°`;return{primitives:[{kind:`line`,a:i,b:a,style:e.style},{kind:`text`,point:{x:(i.x+a.x)/2+8,y:Math.min(i.y,a.y)-8},text:d,align:`left`,baseline:`bottom`,style:e.style}],meta:{delta:c,percent:l,bars:s,angle:u}}}}}function Oa(){return{kind:`parallel-channel`,minAnchors:3,maxAnchors:3,compute(e,t){let[n,r,i]=e.anchors;if(!n||!r||!i)return{primitives:[]};let a=t.toScreen(n),o=t.toScreen(r),s=t.toScreen(i),c=o.x-a.x,l=o.y-a.y,u={x:s.x+c,y:s.y+l},d=e.params?.extend??`none`,f=i.index+(r.index-n.index),p=i.time?(typeof i.time==`string`?new Date(i.time).getTime():i.time)+((typeof r.time==`string`?new Date(r.time).getTime():r.time??0)-(typeof n.time==`string`?new Date(n.time).getTime():n.time??0)):void 0;return{primitives:[{kind:`area`,points:[a,o,u,s],closed:!0,style:e.style},{kind:`line`,a,b:o,extend:d,style:e.style},{kind:`line`,a:s,b:u,extend:d,style:e.style}],computedAnchors:[{id:`${e.id}-p4`,index:f,time:p,price:i.price+(r.price-n.price)}]}}}}function ka(){return{kind:`flat-line`,minAnchors:3,maxAnchors:3,compute(e,t){let[n,r,i]=e.anchors;if(!n||!r||!i)return{primitives:[]};let a=t.toScreen(n),o=t.toScreen(r),s=t.toScreen(i),c={x:a.x,y:s.y},l={x:o.x,y:s.y};return{primitives:[{kind:`area`,points:[a,o,l,c],closed:!0,style:e.style},{kind:`line`,a,b:o,style:e.style},{kind:`line`,a:c,b:l,style:e.style},{kind:`point`,point:c,style:e.style},{kind:`point`,point:l,style:e.style}],computedAnchors:[{id:`${e.id}-h1`,index:n.index,time:n.time,price:i.price},{id:`${e.id}-h2`,index:r.index,time:r.time,price:i.price}]}}}}function Aa(){return{kind:`disjoint-channel`,minAnchors:3,maxAnchors:3,compute(e,t){let[n,r,i]=e.anchors;if(!n||!r||!i)return{primitives:[]};let a=t.toScreen(n),o=t.toScreen(r),s=t.toScreen(i),c=o.x-a.x,l=o.y-a.y,u={x:s.x+c,y:s.y-l},d=i.index+(r.index-n.index),f=i.price-(r.price-n.price),p=i.time?(typeof i.time==`string`?new Date(i.time).getTime():i.time)-((typeof r.time==`string`?new Date(r.time).getTime():r.time??0)-(typeof n.time==`string`?new Date(n.time).getTime():n.time??0)):void 0;return{primitives:[{kind:`area`,points:[a,o,u,s],closed:!0,style:e.style},{kind:`line`,a,b:o,style:e.style},{kind:`line`,a:s,b:u,style:e.style}],computedAnchors:[{id:`${e.id}-p4`,index:d,time:p,price:f}]}}}}function ja(){return{kind:`regression-channel`,minAnchors:2,maxAnchors:2,compute(e,t){let[n,r]=e.anchors;if(!n||!r)return{primitives:[]};let i=xa(n,t.seriesData),a=xa(r,t.seriesData);if(i<0&&a<0)return{primitives:[]};let o=Math.min(Math.max(Math.round(n.index),0),t.seriesData.length-1),s=Math.min(Math.max(Math.round(r.index),0),t.seriesData.length-1),c=Math.min(o,s),l=Math.max(o,s),u=t.seriesData.slice(c,l+1),d=Ca(u.map(e=>e.close));if(!d)return{primitives:[]};let f=e.params?.sigma??2,p=d.stdDev*f,m=d.intercept,h=d.intercept+d.slope*(u.length-1),g={id:`${e.id}-reg-start`,index:Math.round(n.index),time:t.seriesData[c].timestamp,price:m},_={id:`${e.id}-reg-end`,index:Math.round(r.index),time:t.seriesData[l].timestamp,price:h},v={...g,id:`${e.id}-reg-upper-start`,price:m+p},y={..._,id:`${e.id}-reg-upper-end`,price:h+p},b={...g,id:`${e.id}-reg-lower-start`,price:m-p},x={..._,id:`${e.id}-reg-lower-end`,price:h-p},S=t.toScreen(g),C=t.toScreen(_),w=t.toScreen(v),T=t.toScreen(y),E=t.toScreen(b),D=t.toScreen(x);return{primitives:[{kind:`area`,points:[w,T,D,E],closed:!0,style:e.style},{kind:`line`,a:S,b:C,style:{...e.style,strokeStyle:`dashed`}},{kind:`line`,a:w,b:T,style:e.style},{kind:`line`,a:E,b:D,style:e.style}],computedAnchors:[g,_],meta:{sigma:f,stdDev:d.stdDev,slope:d.slope}}}}}function Ma(e){e.register(Ta(`trend-line`,`none`)),e.register(Ta(`ray`,`right`)),e.register(Ta(`extended-line`,`both`)),e.register(Ea(`horizontal-line`)),e.register(Ea(`horizontal-ray`)),e.register(Ea(`vertical-line`)),e.register(Ea(`cross-line`)),e.register(Da()),e.register(Oa()),e.register(ja()),e.register(ka()),e.register(Aa())}function Na(e){let t=e.store,n=e.definitions??new ga,r=e.renderers??wa();return Ma(n),{name:`drawingRenderer`,version:`0.1.0`,description:`绘图渲染器`,debugName:`绘图层`,paneId:e.paneId??`main`,priority:-25,draw(e){let{ctx:i,pane:a,data:o,range:s,dpr:c,paneWidth:l,kLinePositions:u,kLineCenters:d,kBarRects:f,kWidth:p,kGap:m}=e,h=e.viewport??{scrollLeft:e.scrollLeft,plotWidth:l,plotHeight:a.height},{startXPx:g,unitPx:_}=R(p,m,c),v=o,y=v.slice(s.start,s.end),b=t.getVisibleByPane(a.id);if(b.length===0)return;let x={left:0,top:0,right:h.plotWidth,bottom:a.height};i.save(),i.beginPath(),i.rect(0,0,h.plotWidth,a.height),i.clip();for(let o of b){let b=n.compute(o,{pane:a,visibleData:y,seriesData:v,range:s,kLinePositions:u,kLineCenters:d,kBarRects:f,kWidth:p,kGap:m,dpr:c,paneWidth:l,viewport:h,toScreen(e){return!Number.isFinite(e.index)||e.index<0?{x:-p,y:a.yAxis.priceToY(e.price)}:{x:(g+e.index*_+(_-1)/2)/c-h.scrollLeft,y:a.yAxis.priceToY(e.price)}}});if(!b)continue;let S=t.getSelectedId()===o.id,C=S?b.primitives.map(e=>Pa(e,o.style)):b.primitives;if(S&&o.visible&&a.role===`price`){let t=[...o.anchors,...b.computedAnchors??[]];if(t.length===0)continue;if(t.length>=2){let n=1/0,r=-1/0;for(let e of t)Number.isFinite(e.price)&&(e.price<n&&(n=e.price),e.price>r&&(r=e.price));Number.isFinite(n)&&Number.isFinite(r)&&n!==r&&(e.yAxisRanges||=[],e.yAxisRanges.push({topY:a.yAxis.priceToY(r),bottomY:a.yAxis.priceToY(n),color:o.style?.stroke??`#2962ff`,opacity:.15}))}if(t.length>=2){let n=1/0,r=-1/0;for(let e of t)!Number.isFinite(e.index)||e.index<0||(e.index<n&&(n=e.index),e.index>r&&(r=e.index));if(Number.isFinite(n)&&Number.isFinite(r)&&n!==r){e.xAxisRanges||=[];let t=(g+n*_+(_-1)/2)/c,i=(g+r*_+(_-1)/2)/c;e.xAxisRanges.push({leftX:t,rightX:i,color:o.style?.stroke??`#2962ff`,opacity:.15})}}let n=e=>{if(e>=0&&e<v.length)return v[e]?.timestamp??null;if(v.length>=2&&e>=v.length){let t=v.length-1,n=v.length-2,r=v[t].timestamp,i=r-v[n].timestamp;return r+(e-t)*i}return null};for(let r of t){if(!Number.isFinite(r.index)||!Number.isFinite(r.price))continue;let t=r.index<0?{x:-p,y:a.yAxis.priceToY(r.price)}:{x:(g+r.index*_+(_-1)/2)/c-h.scrollLeft,y:a.yAxis.priceToY(r.price)};if(t.y>=0&&t.y<=a.height&&(e.yAxisLabels||=[],e.yAxisLabels.push({dataIndex:Math.round(r.index),price:r.price,y:t.y,style:{bgColor:o.style?.stroke??`#2962ff`,borderColor:o.style?.stroke??`#2962ff`,textColor:`#ffffff`}})),t.x>=-p&&t.x<=h.plotWidth+p){let i=r.time?typeof r.time==`string`?new Date(r.time).getTime():r.time:n(Math.round(r.index));if(!i)continue;e.xAxisLabels||=[],e.xAxisLabels.push({dataIndex:Math.round(r.index),timestamp:i,x:t.x+h.scrollLeft,style:{bgColor:o.style?.stroke??`#2962ff`,textColor:`#ffffff`}})}}}for(let e of C){if(e.kind===`point`){r.point(i,e,c);continue}if(e.kind===`line`){r.line(i,e,x,c);continue}if(e.kind===`area`){r.area(i,e,c);continue}r.text(i,e,c)}}i.restore()}}}function Pa(e,t){let n=t.stroke??`#2962ff`,r=(t.strokeWidth??1)+1,i=(t.pointRadius??4)+2;return e.kind===`point`?{...e,style:{...e.style,stroke:n,pointRadius:i}}:e.kind===`line`?{...e,style:{...e.style,stroke:n,strokeWidth:r}}:e.kind===`area`?{...e,style:{...e.style,stroke:n}}:{...e,style:{...e.style,textColor:n,fontSize:(e.style?.fontSize??12)+1}}}var Fa=class e{dom;opt;data=[];raf=null;pendingUpdateLevel=B.All;viewport=null;paneRenderers=[];markerManager;drawingStore=new ha;interaction;pluginHost;rendererPluginManager;preciseDpr=0;resizeObserver;onScroll;observedSize={width:0,height:0};cachedScrollLeft=0;overlayHadCrosshair=!1;settings={};paneRatios=new Map;onViewportChange;xAxisCtx=null;onPaneLayoutChange;onDataChange;currentZoomLevel=1;zoomLevelCount;indicatorScheduler;lastVisibleRange={start:0,end:0};cachedDrawFrame=null;activeMainIndicators=new Set;mainIndicatorParams={MA:{ma5:!0,ma10:!0,ma20:!0,ma30:!0,ma60:!0},BOLL:{period:20,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0,showBand:!0},EXPMA:{fastPeriod:12,slowPeriod:50},ENE:{period:10,deviation:11}};enableMainIndicator(e,t){let n=e.toUpperCase();return[`MA`,`BOLL`,`EXPMA`,`ENE`].includes(n)?this.activeMainIndicators.has(n)?(t&&(this.mainIndicatorParams[n]={...this.mainIndicatorParams[n],...t},this.updateIndicatorSchedulerConfig(n)),!0):(this.activeMainIndicators.add(n),t&&(this.mainIndicatorParams[n]={...this.mainIndicatorParams[n],...t}),this.enableMainIndicatorRenderer(n),this.updateIndicatorSchedulerConfig(n),this.scheduleDraw(),!0):(console.warn(`[Chart] 未知的主图指标: ${e}`),!1)}disableMainIndicator(e){let t=e.toUpperCase();return this.activeMainIndicators.has(t)?(this.activeMainIndicators.delete(t),this.disableMainIndicatorRenderer(t),this.updateIndicatorSchedulerConfig(t),this.scheduleDraw(),!0):!1}toggleMainIndicator(e,t){t?this.enableMainIndicator(e):this.disableMainIndicator(e)}getActiveMainIndicators(){return Array.from(this.activeMainIndicators)}isMainIndicatorActive(e){return this.activeMainIndicators.has(e.toUpperCase())}updateMainIndicatorParams(e,t){let n=e.toUpperCase();this.mainIndicatorParams[n]||(this.mainIndicatorParams[n]={}),this.mainIndicatorParams[n]={...this.mainIndicatorParams[n],...t};let r=n.toLowerCase(),i=this.getRenderer(r);i&&i.setConfig&&i.setConfig(this.mainIndicatorParams[n]),this.updateIndicatorSchedulerConfig(n),this.scheduleDraw()}getMainIndicatorParams(e){return this.mainIndicatorParams[e.toUpperCase()]??null}clearMainIndicators(){for(let e of this.activeMainIndicators)this.disableMainIndicatorRenderer(e);this.activeMainIndicators.clear(),this.scheduleDraw()}enableMainIndicatorRenderer(e){let t={MA:()=>{this.getRenderer(`ma`)||this.useRenderer(gi()),this.setRendererEnabled(`ma`,!0)},BOLL:()=>{this.getRenderer(`boll`)||this.useRenderer(Si()),this.setRendererEnabled(`boll`,!0)},EXPMA:()=>{this.getRenderer(`expma`)||this.useRenderer(wi()),this.setRendererEnabled(`expma`,!0)},ENE:()=>{this.getRenderer(`ene`)||this.useRenderer(ki()),this.setRendererEnabled(`ene`,!0)}}[e];t&&t(),this.getRenderer(`mainIndicatorLegend`)||this.useRenderer(Ii({yPaddingPx:this.opt.yPaddingPx}))}disableMainIndicatorRenderer(e){let t={MA:`ma`,BOLL:`boll`,EXPMA:`expma`,ENE:`ene`}[e];t&&this.setRendererEnabled(t,!1)}updateIndicatorSchedulerConfig(e){let t=this.activeMainIndicators.has(e),n=this.mainIndicatorParams[e];switch(e){case`MA`:this.indicatorScheduler.updateMAConfig({ma5:t,ma10:t,ma20:t,ma30:t,ma60:t});break;case`BOLL`:t?this.indicatorScheduler.updateBOLLConfig(n):this.indicatorScheduler.updateBOLLConfig({...n,showUpper:!1,showMiddle:!1,showLower:!1,showBand:!1});break;case`EXPMA`:t&&this.indicatorScheduler.updateEXPMAConfig(n);break;case`ENE`:t&&this.indicatorScheduler.updateENEConfig(n);break}}setActiveMainIndicators(e){let t=new Set(e.map(e=>e.toUpperCase())),n=new Set(this.activeMainIndicators);for(let e of n)t.has(e)||this.disableMainIndicator(e);for(let e of t)n.has(e)||this.enableMainIndicator(e)}constructor(e,t){this.dom=e;let{kWidth:n,kGap:r,...i}=t;this.opt={...i,kWidth:n??0,kGap:r??0},this.interaction=new Un(this),this.markerManager=new Bt,this.pluginHost=_e(),this.rendererPluginManager=new Ae,this.rendererPluginManager.setPluginHost(this.pluginHost),this.rendererPluginManager.setInvalidateCallback(()=>this.scheduleDraw()),this.syncPaneRatiosFromSpecs(this.opt.panes),this.zoomLevelCount=Math.max(2,Math.round(this.opt.zoomLevels??20)),this.currentZoomLevel=this.opt.initialZoomLevel??1,this.currentZoomLevel=Math.max(1,Math.min(this.zoomLevelCount,this.currentZoomLevel)),this.indicatorScheduler=new ci,this.indicatorScheduler.setPluginHost(this.pluginHost),this.indicatorScheduler.setInvalidateCallback(()=>this.scheduleDraw()),this.indicatorScheduler.setActiveSubPaneProvider(()=>this.getSubPaneIndicators().map(e=>`sub_${e}`)),this.initPanes(),this.useRenderer(Na({store:this.drawingStore})),this.initResizeObserver()}initResizeObserver(){if(typeof ResizeObserver>`u`)return;let e=this.dom.container;if(e){this.cachedScrollLeft=e.scrollLeft,this.onScroll=()=>{this.cachedScrollLeft=e.scrollLeft},e.addEventListener(`scroll`,this.onScroll,{passive:!0}),this.resizeObserver=new ResizeObserver(e=>{let t=e[0];if(!t)return;let n=this.observedSize.width,r=this.observedSize.height,i=this.preciseDpr;this.updateObservedMetrics(t);let a=this.observedSize.width!==n,o=this.observedSize.height!==r,s=this.preciseDpr!==i;(a||o||s)&&this.resize()});try{this.resizeObserver.observe(e,{box:`device-pixel-content-box`})}catch{this.resizeObserver.observe(e)}}}updateObservedMetrics(e){let t=Math.max(1,Math.round(e.contentRect.width)),n=Math.max(1,Math.round(e.contentRect.height));this.observedSize.width=t,this.observedSize.height=n;let r=e.devicePixelContentBoxSize?.[0],i=e.contentBoxSize?.[0];if(!r||!i||i.inlineSize<=0){this.preciseDpr=0;return}let a=r.inlineSize/i.inlineSize;this.preciseDpr=Math.round(a*64)/64}getEffectiveDpr(){let e=this.preciseDpr>0?this.preciseDpr:Math.round((window.devicePixelRatio||1)*64)/64;return e<1&&(e=1),e}getViewport(){return this.viewport}getCurrentDpr(){return this.getEffectiveDpr()}getCachedScrollLeft(){return this.cachedScrollLeft}get plugin(){return this.pluginHost}useRenderer(e,t){this.rendererPluginManager.register(e),t&&e.setConfig&&e.setConfig(t)}removeRenderer(e){this.rendererPluginManager.unregister(e)}getRenderer(e){return this.rendererPluginManager.getPlugin(e)}updateRendererConfig(e,t){this.rendererPluginManager.updateConfig(e,t)}setRendererEnabled(e,t){this.rendererPluginManager.setEnabled(e,t)}getAllRenderers(){return this.rendererPluginManager.getAllPlugins()}updateSettings(e){this.settings={...e},this.interaction.updateSettings(e);let t=e.logarithmicScale?`log`:`linear`;for(let e of this.paneRenderers)e.getPane().yAxis.setScaleType(t);this.scheduleDraw()}draw(e=B.All){this.markerManager.clear();let t=e===B.Overlay&&this.cachedDrawFrame!==null,n=t?this.cachedDrawFrame.viewport:this.computeViewport();if(!n||this.data.length===0)return;let r=t?this.cachedDrawFrame.range:(()=>{let{start:e,end:t}=ye(n.scrollLeft,n.plotWidth,this.opt.kWidth,this.opt.kGap,this.data.length,n.dpr);return{start:e,end:t}})();!t&&(r.start!==this.lastVisibleRange.start||r.end!==this.lastVisibleRange.end)&&(this.indicatorScheduler.updateVisibleRange(r),this.lastVisibleRange=r);let i=t?this.cachedDrawFrame.kLinePositions:this.calcKLinePositions(r),a,o,s;if(t)a=this.cachedDrawFrame.kLineCenters,o=this.cachedDrawFrame.kBarRects,s=this.cachedDrawFrame.kWidthPx;else{let e=R(this.opt.kWidth,this.opt.kGap,n.dpr),t=Math.max(1,e.unitPx-1);t%2==0&&--t,a=Array(i.length),o=Array(i.length);for(let r=0;r<i.length;r++){let s=i[r],c=Math.round(s*n.dpr)+(e.kWidthPx-1)/2;a[r]=c/n.dpr;let l=c-(t-1)/2;o[r]={x:l/n.dpr,width:t/n.dpr}}s=R(this.opt.kWidth,this.opt.kGap,n.dpr).kWidthPx,this.cachedDrawFrame={viewport:{...n},range:{...r},kLinePositions:i,kLineCenters:a,kBarRects:o,kWidthPx:s}}this.interaction.setKLinePositions(i,r,s);let c=[],l=[],u=[],d=[];this.indicatorScheduler.setActiveMainIndicators(Array.from(this.activeMainIndicators));let f=t?null:this.indicatorScheduler.getMainIndicatorPriceRange(),p=this.interaction.getCrosshairIndex()!==null;for(let s of this.paneRenderers){let m=s.getPane(),{mainCtx:h,overlayCtx:g,yAxisCtx:_}=s.getContexts(),{candleSurface:v,lineSurface:y}=s.getWebGL();if(!t){let e=m.role===`price`?f:null;m.updateRange(this.data,r,e)}let b=e===B.Main||e===B.All,x=(e===B.Overlay||e===B.All)&&(p||this.overlayHadCrosshair);if(b&&h&&(h.setTransform(1,0,0,1,0,0),h.scale(n.dpr,n.dpr),h.clearRect(0,0,n.plotWidth+1,m.height+2/n.dpr),v?.clear(),y?.clear()),x&&g){let e=g.canvas.width/n.dpr;g.setTransform(1,0,0,1,0,0),g.scale(n.dpr,n.dpr),g.clearRect(0,0,e+1,m.height+2/n.dpr)}if(_&&!t){let e=_.canvas.width/n.dpr;_.setTransform(1,0,0,1,0,0),_.scale(n.dpr,n.dpr),_.clearRect(0,0,e,m.height+2/n.dpr)}let S={ctx:h,overlayCtx:g??void 0,pane:ue(m),data:this.data,range:r,scrollLeft:n.scrollLeft,kWidth:this.opt.kWidth,kGap:this.opt.kGap,dpr:n.dpr,paneWidth:n.plotWidth,kLinePositions:i,kLineCenters:a,kBarRects:o,markerManager:this.markerManager,crosshairIndex:this.interaction.getCrosshairIndex(),yAxisCtx:_??void 0,candleWebGLSurface:v??void 0,lineWebGLSurface:y??void 0,zoomLevel:this.currentZoomLevel,zoomLevelCount:this.zoomLevelCount,viewport:{scrollLeft:n.scrollLeft,plotWidth:n.plotWidth,plotHeight:n.plotHeight},settings:this.settings,yAxisLabels:c,xAxisLabels:l,yAxisRanges:u,xAxisRanges:d},C=this.rendererPluginManager.render(m.id,S,e);C.length>0&&this.pluginHost.events.emit(`renderer:error`,{paneId:m.id,errors:C});let w=this.rendererPluginManager.renderPlugin(`yAxis`,S);w.length>0&&this.pluginHost.events.emit(`renderer:error`,{paneId:m.id,errors:w})}this.overlayHadCrosshair=p;let m=this.xAxisCtx??this.dom.xAxisCanvas.getContext(`2d`);if(this.xAxisCtx||=m,m){let e={ctx:m,pane:{id:`xAxis`,role:`auxiliary`,capabilities:{showPriceAxisTicks:!1,showCrosshairPriceLabel:!1,candleHitTest:!1,supportsPriceTranslate:!1},top:0,height:this.opt.bottomAxisHeight,yAxis:{priceToY:()=>0,yToPrice:()=>0,getPaddingTop:()=>0,getPaddingBottom:()=>0,getPriceOffset:()=>0,getDisplayRange:e=>e??{maxPrice:0,minPrice:0},getScaleType:()=>`linear`},priceRange:{maxPrice:0,minPrice:0}},data:this.data,range:r,scrollLeft:n.scrollLeft,kWidth:this.opt.kWidth,kGap:this.opt.kGap,dpr:n.dpr,paneWidth:n.plotWidth,kLinePositions:i,kLineCenters:a,kBarRects:o,xAxisCtx:m,viewport:{scrollLeft:n.scrollLeft,plotWidth:n.plotWidth,plotHeight:n.plotHeight},yAxisLabels:[],xAxisLabels:l,xAxisRanges:d},t=this.rendererPluginManager.renderPlugin(`timeAxis`,e);t.length>0&&this.pluginHost.events.emit(`renderer:error`,{paneId:`timeAxis`,errors:t})}}applyRenderState(e,t,n){let r=n===void 0?this.currentZoomLevel:Math.max(1,Math.min(this.zoomLevelCount,n));(this.opt.kWidth!==e||this.opt.kGap!==t||this.currentZoomLevel!==r)&&(this.opt={...this.opt,kWidth:e,kGap:t},n!==void 0&&(this.currentZoomLevel=r),this.scheduleDraw())}getZoomLevelCount(){return this.zoomLevelCount}setOnViewportChange(e){this.onViewportChange=e}setOnPaneLayoutChange(e){this.onPaneLayoutChange=e}setOnDataChange(e){this.onDataChange=e}getPaneRenderers(){return this.paneRenderers}getMarkerManager(){return this.markerManager}updateCustomMarkers(e){this.markerManager.setCustomMarkers(e),this.scheduleDraw()}clearCustomMarkers(){this.markerManager.clearCustomMarkers(),this.scheduleDraw()}getDom(){return this.dom}getOption(){return this.opt}calcKLinePositions(e){let{start:t,end:n}=e,r=n-t;if(r<=0)return[];let i=this.getEffectiveDpr(),{unitPx:a,startXPx:o}=R(this.opt.kWidth,this.opt.kGap,i),s=Array(r);for(let e=0;e<r;e++)s[e]=(o+(t+e)*a)/i;return s}updateOptions(e){if(e.kWidth!==void 0&&(console.warn(`[Chart] kWidth cannot be set directly. Use applyRenderState() instead.`),delete e.kWidth),e.kGap!==void 0&&delete e.kGap,e.panes){let t=e.panes.map(e=>({...e}));this.opt={...this.opt,...e,panes:t},this.applyPaneLayoutSpecs(t);return}this.opt={...this.opt,...e},this.resize()}updatePaneLayout(e){this.applyPaneLayoutSpecs(e)}setPaneDefinitions(e){this.applyPaneLayoutSpecs(e)}upsertPane(e){let t=this.opt.panes.findIndex(t=>t.id===e.id);if(t===-1){this.applyPaneLayoutSpecs([...this.opt.panes,{...e}]);return}let n=[...this.opt.panes];n[t]={...n[t],...e},this.applyPaneLayoutSpecs(n)}removePaneDefinition(e){this.opt.panes.some(t=>t.id===e)&&(this.paneRatios.delete(e),this.applyPaneLayoutSpecs(this.opt.panes.filter(t=>t.id!==e)))}bindIndicatorToPane(e,t,n){this.opt.panes.some(t=>t.id===e)||this.upsertPane({id:e,ratio:1,visible:!0,role:`indicator`});let r=`${t.toLowerCase()}_${e}`;if(this.getRenderer(r)){n&&this.updateRendererConfig(r,n);return}let i=ua({indicatorId:t,paneId:e});this.useRenderer(i,n)}setDrawings(e){this.drawingStore.setAll(e),this.scheduleDraw()}setSelectedDrawingId(e){this.drawingStore.getSelectedId()!==e&&(this.drawingStore.setSelectedId(e),this.scheduleDraw())}getPaneLayoutSpecs(){let e=this.opt.panes.filter(e=>e.visible!==!1).reduce((e,t)=>e+(this.paneRatios.get(t.id)??t.ratio??0),0),t=e>0?e:1;return this.opt.panes.map(e=>{let n=this.paneRatios.get(e.id)??e.ratio??0,r=e.visible===!1?n:n/t,i=this.paneRenderers.find(t=>t.getPane().id===e.id)?.getPane();return{...e,ratio:r,role:i?.role??e.role,capabilities:i?{...i.capabilities}:e.capabilities}})}emitPaneLayoutChange(){this.onPaneLayoutChange?.(this.getPaneLayoutSpecs())}applyPaneLayoutSpecs(e){this.opt.panes=e.map(e=>({...e})),this.syncPaneRatiosFromSpecs(this.opt.panes),this.initPanes(),this.layoutPanes(),this.emitPaneLayoutChange(),this.scheduleDraw()}resizePaneBoundary(e,t){if(!Number.isFinite(t)||t===0)return!1;let n=this.viewport;if(!n)return!1;let r=this.opt.panes.filter(e=>e.visible!==!1),i=r.findIndex(t=>t.id===e);if(i<0||i>=r.length-1)return!1;let a=r[i],o=r[i+1];if(!a||!o)return!1;let s=new Map;for(let e of r){let t=this.paneRenderers.find(t=>t.getPane().id===e.id);t&&s.set(e.id,t.getPane().height)}let c=t>0?i:i+1,l=t>0?i+1:i,u=t>0?1:-1,d=Math.abs(t),f=l;for(;d>0&&f>=0&&f<r.length;){let e=r[f];if(!e)break;let t=s.get(e.id)??0,i=this.getPaneMinHeight(e,n.plotHeight),a=Math.max(0,t-i);if(a>0){let n=Math.min(a,d);s.set(e.id,t-n),d-=n}d>0&&(f+=u)}if(d>0)return!1;let p=r[c];if(!p)return!1;let m=s.get(p.id)??0;s.set(p.id,m+Math.abs(t));let h=Math.max(0,this.opt.paneGap??0)*Math.max(0,r.length-1),g=Math.max(1,n.plotHeight-h);for(let e of r){let t=s.get(e.id)??0;this.paneRatios.set(e.id,t/g)}return this.normalizeVisiblePaneRatios(r),this.syncPaneRatiosToSpecs(),this.layoutPanes(),this.emitPaneLayoutChange(),this.scheduleDraw(),!0}resolvePaneRole(e,t){return e.role?e.role:t===0?`price`:`indicator`}addPane(e){if(this.opt.panes.some(t=>t.id===e)){console.warn(`Pane "${e}" already exists`);return}let t=this.opt.panes.some((e,t)=>this.resolvePaneRole(e,t)===`price`)?`indicator`:`price`;this.applyPaneLayoutSpecs([...this.opt.panes,{id:e,ratio:1,visible:!0,role:t}])}removePane(e){if(!this.opt.panes.some(t=>t.id===e))return;let t=this.opt.panes.filter(t=>t.id!==e);this.paneRatios.delete(e),this.applyPaneLayoutSpecs(t)}hasPane(e){return this.opt.panes.some(t=>t.id===e)}static SUB_PANE_PREFIX=`sub_`;createSubPane(t,n){let r=`${e.SUB_PANE_PREFIX}${t}`,i=`${t.toLowerCase()}_${r}`;if(this.getRenderer(i))return n&&this.updateRendererConfig(i,n),!0;let a=this.opt.panes.filter(e=>e.visible!==!1),o=a.filter((e,t)=>this.resolvePaneRole(e,t)===`price`),s=a.filter((e,t)=>this.resolvePaneRole(e,t)===`indicator`);if(o.length===1){let e=o[0];e&&this.paneRatios.set(e.id,3);for(let e of s)this.paneRatios.set(e.id,1);this.paneRatios.set(r,1)}else this.paneRatios.set(r,1);return this.upsertPane({id:r,ratio:this.paneRatios.get(r)??1,visible:!0,role:`indicator`}),this.bindIndicatorToPane(r,t,n),!0}removeSubPane(t){let n=`${e.SUB_PANE_PREFIX}${t}`;if(!this.hasPane(n))return;let r=`${t.toLowerCase()}_${n}`;this.removeRenderer(r),this.paneRatios.delete(n),this.applyPaneLayoutSpecs(this.opt.panes.filter(e=>e.id!==n))}clearSubPanes(){let t=this.opt.panes.map(e=>e.id).filter(t=>t.startsWith(e.SUB_PANE_PREFIX));if(t.length!==0){for(let n of t){let t=`${n.slice(e.SUB_PANE_PREFIX.length).toLowerCase()}_${n}`;this.removeRenderer(t),this.paneRatios.delete(n)}this.applyPaneLayoutSpecs(this.opt.panes.filter(t=>!t.id.startsWith(e.SUB_PANE_PREFIX)))}}getSubPaneIndicators(){return this.opt.panes.map(e=>e.id).filter(t=>t.startsWith(e.SUB_PANE_PREFIX)).map(t=>t.slice(e.SUB_PANE_PREFIX.length))}translatePrice(e,t){let n=this.paneRenderers.find(t=>t.getPane().id===e);if(!n)return;let r=n.getPane();if(!r.capabilities.supportsPriceTranslate)return;let i=r.yAxis.deltaYToPriceOffset(t),a=r.yAxis.getPriceOffset();r.yAxis.setPriceOffset(a+i),this.scheduleDraw()}resetPriceOffset(e){let t=this.paneRenderers.find(t=>t.getPane().id===e);t&&(t.getPane().yAxis.resetPriceOffset(),this.scheduleDraw())}scalePrice(e,t){let n=this.paneRenderers.find(t=>t.getPane().id===e);if(!n)return;let r=n.getPane();r.capabilities.supportsPriceTranslate&&(r.yAxis.scaleByDelta(t),this.scheduleDraw())}updateData(e){this.data=e??[],this.onDataChange?.(this.data);let t=this.dom.container;if(t){let e=this.getContentWidth(),n=Math.max(0,e-t.clientWidth);this.cachedScrollLeft>n&&(t.scrollLeft=n,this.cachedScrollLeft=n)}this.interaction.reset(),this.indicatorScheduler.update(this.data,this.lastVisibleRange),this.scheduleDraw()}getData(){return this.data}getIndicatorScheduler(){return this.indicatorScheduler}getTrailingSlotCount(){return 24}getLogicalSlotCount(){return this.data.length+this.getTrailingSlotCount()}getTimestampAtLogicalIndex(e){return!Number.isInteger(e)||e<0||e>=this.data.length?null:this.data[e]?.timestamp??null}getLogicalIndexAtX(e){let t=this.viewport;if(!t||this.data.length===0)return null;let n=this.getEffectiveDpr(),{startXPx:r,unitPx:i}=R(this.opt.kWidth,this.opt.kGap,n),a=Math.round((t.scrollLeft+e)*n),o=Math.floor((a-r)/i);return o<0?null:o}getDataIndexAtX(e){let t=this.getLogicalIndexAtX(e);return t===null||t>=this.data.length?null:t}getContentWidth(){return rr({dataLength:this.data.length,kWidth:this.opt.kWidth,kGap:this.opt.kGap,viewWidth:this.viewport?.plotWidth??0,viewportDpr:this.getEffectiveDpr()})}resize(){let e=this.computeViewport();!e||e.viewWidth<10||e.viewHeight<10||(this.layoutPanes(),this.emitPaneLayoutChange(),this.scheduleDraw())}scheduleDraw(e=B.All){if(this.raf!==null){if(this.pendingUpdateLevel===B.All)return;if(e===B.All){this.pendingUpdateLevel=B.All;return}if(this.pendingUpdateLevel===B.Main&&e===B.Overlay||this.pendingUpdateLevel===B.Overlay&&e===B.Main){this.pendingUpdateLevel=B.All;return}return}this.pendingUpdateLevel=e,this.raf=requestAnimationFrame(()=>{this.raf=null;let e=this.pendingUpdateLevel;this.pendingUpdateLevel=B.All,this.draw(e)})}async destroy(){this.raf!==null&&(cancelAnimationFrame(this.raf),this.raf=null),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.preciseDpr=0,this.observedSize={width:0,height:0},this.onScroll&&=(this.dom.container?.removeEventListener(`scroll`,this.onScroll),void 0),this.viewport=null,this.cachedDrawFrame=null,this.xAxisCtx=null,this.paneRenderers.forEach(e=>e.destroy()),this.paneRenderers=[],this.rendererPluginManager.clear(),this.onViewportChange=void 0,this.onPaneLayoutChange=void 0,this.indicatorScheduler.destroy(),await this.pluginHost.destroy()}initPanes(){this.paneRenderers=this.opt.panes.map((e,t)=>{let n=new Oe(e.id,{role:this.resolvePaneRole(e,t),capabilities:e.capabilities}),r=document.createElement(`canvas`),i=document.createElement(`canvas`),a=document.createElement(`canvas`),o=n.role===`price`;return r.id=`${e.id}-main`,r.className=o?`main-canvas main`:`main-canvas sub`,r.style.position=`absolute`,r.style.left=`0`,r.style.top=`0`,i.id=`${e.id}-overlay`,i.className=`overlay-canvas`,i.style.position=`absolute`,i.style.left=`0`,i.style.top=`0`,i.style.pointerEvents=`none`,i.style.backgroundColor=`transparent`,a.id=`${e.id}-yAxis`,a.className=`right-axis`,a.style.position=`absolute`,a.style.left=`0`,new nr({mainCanvas:r,overlayCanvas:i,yAxisCanvas:a},n,{rightAxisWidth:this.opt.rightAxisWidth,yPaddingPx:this.opt.yPaddingPx,priceLabelWidth:this.opt.priceLabelWidth})});let e=this.dom.canvasLayer,t=this.dom.rightAxisLayer;e&&e.querySelectorAll(`canvas:not(.x-axis-canvas)`).forEach(e=>e.remove()),t&&t.querySelectorAll(`canvas.right-axis`).forEach(e=>e.remove()),this.paneRenderers.forEach(n=>{let r=n.getDom();e.appendChild(r.mainCanvas),e.appendChild(r.overlayCanvas),t.appendChild(r.yAxisCanvas)}),this.rendererPluginManager.setKnownPaneIds(this.paneRenderers.map(e=>e.getPane().id))}syncPaneRatiosFromSpecs(e){let t=new Map;for(let n of e){let e=this.paneRatios.get(n.id),r=Number.isFinite(n.ratio)?n.ratio:0,i=e===void 0?r>0?r:1:e;t.set(n.id,i)}this.paneRatios=t,this.normalizeVisiblePaneRatios(e),this.syncPaneRatiosToSpecs()}syncPaneRatiosToSpecs(){let e=this.opt.panes.filter(e=>e.visible!==!1).reduce((e,t)=>e+(this.paneRatios.get(t.id)??t.ratio??0),0),t=e>0?e:1;this.opt.panes=this.opt.panes.map(e=>{let n=this.paneRatios.get(e.id)??e.ratio??0;return e.visible===!1?{...e,ratio:n}:{...e,ratio:n/t}})}normalizeVisiblePaneRatios(e){let t=e.filter(e=>e.visible!==!1);if(t.length===0)return;let n=0;for(let e of t){let t=this.paneRatios.get(e.id)??e.ratio??0,r=Number.isFinite(t)&&t>0?t:0;this.paneRatios.set(e.id,r),n+=r}if(n<=0){let e=1/t.length;for(let n of t)this.paneRatios.set(n.id,e);return}for(let e of t){let t=this.paneRatios.get(e.id)??0;this.paneRatios.set(e.id,t/n)}}getPaneMinHeight(e,t){let n=this.opt.defaultPaneMinHeightPx??120,r=e.minHeightPx??n;return Math.max(1,Math.min(Math.round(r),Math.max(1,t)))}computePaneHeightsByRatio(e,t){if(e.length===0)return[];let n=e.map(e=>this.paneRatios.get(e.id)??e.ratio??0),r=n.reduce((e,t)=>e+(t>0?t:0),0),i=(r>0?n.map(e=>(e>0?e:0)/r):e.map(()=>1/e.length)).map(e=>Math.max(1,Math.round(t*e))),a=e.map(e=>this.getPaneMinHeight(e,t));for(let e=0;e<i.length;e++)i[e]=Math.max(i[e],Math.min(a[e],t));let o=i.reduce((e,t)=>e+t,0);if(o>t){let e=o-t;for(;e>0;){let n=!1;for(let r=i.length-1;r>=0&&e>0;r--){let o=Math.max(1,Math.min(a[r],t)),s=i[r];s>o&&(i[r]=s-1,e--,n=!0)}if(!n)break}}else o<t&&(i[i.length-1]=(i[i.length-1]??1)+(t-o));return o=i.reduce((e,t)=>e+t,0),o!==t&&i.length>0&&(i[i.length-1]=Math.max(1,(i[i.length-1]??1)+(t-o))),i}layoutPanes(){let e=this.viewport;if(!e)return;let t=this.opt.panes.filter(e=>e.visible!==!1);if(t.length===0)return;let n=Math.max(0,this.opt.paneGap??0),r=0,i=n*Math.max(0,t.length-1),a=Math.max(1,e.plotHeight-i);this.normalizeVisiblePaneRatios(t);let o=this.computePaneHeightsByRatio(t,a);for(let i=0;i<t.length;i++){let a=t[i];if(!a)continue;let s=this.paneRenderers.find(e=>e.getPane().id===a.id);if(!s)continue;let c=s.getPane(),l=o[i]??1;c.setLayout(r,l),c.setPadding(this.opt.yPaddingPx,this.opt.yPaddingPx),s.resize(e.plotWidth,l,e.dpr),this.rendererPluginManager.notifyResize(c.id,ue(c));let u=s.getDom();u.mainCanvas.style.top=`${r}px`,u.overlayCanvas.style.top=`${r}px`,u.yAxisCanvas.style.top=`${r}px`,u.yAxisCanvas.style.left=`0px`,r+=l+n}let s=Math.max(1,a);for(let e of t){let t=this.paneRenderers.find(t=>t.getPane().id===e.id);if(!t)continue;let n=t.getPane().height;this.paneRatios.set(e.id,n/s)}this.normalizeVisiblePaneRatios(t),this.syncPaneRatiosToSpecs()}computeViewport(){let e=this.dom.container;if(!e)return null;let t=this.observedSize.width,n=this.observedSize.height,r=t>0?t:Math.max(1,Math.round(e.clientWidth)),i=n>0?n:Math.max(1,Math.round(e.clientHeight)),a=Math.round(r),o=Math.round(i-this.opt.bottomAxisHeight),s=this.getEffectiveDpr(),c=16*1024*1024;r*s*(i*s)>c&&(s=Math.sqrt(c/(r*i)));let l=Math.round(this.cachedScrollLeft*s)/s,u=`${r}px`;this.dom.canvasLayer.style.width!==u&&(this.dom.canvasLayer.style.width=u);let d=`${i}px`;this.dom.canvasLayer.style.height!==d&&(this.dom.canvasLayer.style.height=d);let f=Math.round(a*s);this.dom.xAxisCanvas.width!==f&&(this.dom.xAxisCanvas.width=f);let p=Math.round(this.opt.bottomAxisHeight*s);this.dom.xAxisCanvas.height!==p&&(this.dom.xAxisCanvas.height=p);let m=`${f/s}px`;this.dom.xAxisCanvas.style.width!==m&&(this.dom.xAxisCanvas.style.width=m);let h=`${p/s}px`;this.dom.xAxisCanvas.style.height!==h&&(this.dom.xAxisCanvas.style.height=h);let g={viewWidth:r,viewHeight:i,plotWidth:a,plotHeight:o,scrollLeft:l,dpr:s},_=this.viewport,v=!_||_.viewWidth!==g.viewWidth||_.viewHeight!==g.viewHeight||_.plotWidth!==g.plotWidth||_.plotHeight!==g.plotHeight||_.scrollLeft!==g.scrollLeft||_.dpr!==g.dpr;return this.viewport=g,v&&this.onViewportChange?.(g),g}},Ia=3;function La(e,t){let n=(e-1)/(t.zoomLevelCount-1);return t.minKWidth+n*(t.maxKWidth-t.minKWidth)}function Ra(e,t){let n=Math.round(e*t);return Math.max(1,Math.min(Ia,Math.round(n*.6)))/t}function za(e,t,n,r,i,a,o){let s=Math.max(1,Math.min(o.zoomLevelCount,r+e));if(s===r)return null;let c=La(s,o),l=Ra(c,o.dpr),u=R(i,a,o.dpr),d=R(c,l,o.dpr),f=(Math.round((n+t)*o.dpr)-u.startXPx)/u.unitPx;return{targetLevel:s,newKWidth:c,newKGap:l,newScrollLeft:(d.startXPx+f*d.unitPx)/o.dpr-t}}function Ba(e,t,n,r,i,a,o){let s=Math.max(1,Math.min(o.zoomLevelCount,Math.round(e)))-r;return s===0?null:za(s,t,n,r,i,a,o)}function Va(e){return e.open>e.close?`down`:e.open<e.close?`up`:`flat`}var $=function(e){return e.RISE_WITH_VOLUME=`rise_with_volume`,e.RISE_WITHOUT_VOLUME=`rise_without_volume`,e.FALL_WITH_VOLUME=`fall_with_volume`,e.FALL_WITHOUT_VOLUME=`fall_without_volume`,e.OTHERS=`others`,e}({}),Ha={volumeAmplifyThreshold:1.5,volumeShrinkThreshold:.8,avgPeriod:20},Ua=class{prefixSum=[];dataLength=0;build(e){let t=e.length;if(t===0){this.prefixSum=[],this.dataLength=0;return}this.prefixSum=[0];for(let n=0;n<t;n++)this.prefixSum.push(this.prefixSum[n]+(e[n]?.volume??0));this.dataLength=t}query(e,t){return e<0||t>=this.dataLength||e>t?0:this.prefixSum[t+1]-this.prefixSum[e]}getVolumeMA(e,t){if(e<t-1)return 0;let n=e-t+1;return this.query(n,e)/t}get length(){return this.dataLength}};function Wa(e,t,n,r=Ha){let i=new Ua;i.build(e);let a=[],{volumeAmplifyThreshold:o,volumeShrinkThreshold:s,avgPeriod:c}=r;for(let r=t;r<n&&r<e.length;r++){let t=e[r]?.volume;if(r<1||!t){a.push($.OTHERS);continue}let n=i.getVolumeMA(r,c),l=e[r];if(!l){a.push($.OTHERS);continue}let u=l.close-l.open,d=u>0,f=u<0,p=t>n*o,m=t<n*s;d&&p?a.push($.RISE_WITH_VOLUME):d&&m?a.push($.RISE_WITHOUT_VOLUME):f&&p?a.push($.FALL_WITH_VOLUME):f&&m?a.push($.FALL_WITHOUT_VOLUME):a.push($.OTHERS)}return a}function Ga(){return{name:`candle`,version:`1.0.0`,description:`K线蜡烛图渲染器`,debugName:`K线`,paneId:`main`,priority:L.MAIN,draw(e){let{ctx:t,pane:n,data:r,range:i,scrollLeft:a,kWidth:o,kGap:s,dpr:c,kLinePositions:l,markerManager:u,settings:d}=e,f=r;if(!f.length)return;let p=Ka({pane:n,data:f,range:i,kWidth:o,kGap:s,dpr:c,kLinePositions:l,settings:d});Ja(e,p)?Ya(t,e):qa(t,a,p),Xa(e,p,u)}}}function Ka(e){let{pane:t,data:n,range:r,kWidth:i,kGap:a,dpr:o,kLinePositions:s,settings:c}=e,{kWidthPx:l}=R(i,a,o),u=c?.showVolumePriceMarkers!==!1,d=u?Wa(n,r.start,r.end,Ha):null,f=[],p=[],m=Math.max(1,r.end-r.start),h=new Float32Array(m*4),g=new Float32Array(m*4),_=new Float32Array(m*2*4),v=new Float32Array(m*2*4),y=0,b=0,x=0,S=0,{maxPrice:C,minPrice:w}=t.yAxis.getDisplayRange(),T=t.yAxis.getPaddingTop(),E=t.yAxis.getPaddingBottom(),D=Math.max(1,t.height-T-E),O=t.yAxis.getScaleType()!==`log`,k;if(O){let e=D/(C-w||1),t=T+D;k=n=>t-(n-w)*e}else k=e=>t.yAxis.priceToY(e);for(let e=r.start;e<r.end&&e<n.length;e++){let t=n[e];if(!t)continue;let i=k(t.open),a=k(t.close),c=k(t.high),u=k(t.low),d=s[e-r.start];if(d===void 0)continue;let m=e=>Math.round(e*o)/o,C=m(i),w=m(a),T=m(c),E=m(u),D=Math.min(C,w),O=Math.max(Math.abs(C-w),1),A=He(Math.round(d*o),D,l,O,o),j=Va(t),M={i:e,aligned:A,trend:j,openY:i,closeY:a,highY:c,lowY:u,alignedHighY:T,alignedLowY:E,e:t},N=A.bodyRect,P=j===`up`?f:p,F=j===`up`;if(P.push(M),F){let e=y++*4;h[e]=N.x,h[e+1]=N.y,h[e+2]=N.width,h[e+3]=N.height}else{let e=b++*4;g[e]=N.x,g[e+1]=N.y,g[e+2]=N.width,g[e+3]=N.height}let I=N.y,ee=N.y+N.height,te=Math.max(t.open,t.close),ne=Math.min(t.open,t.close);if(t.high>te){let e=Be(A.wickRect.x,T,I,o);if(e){let t=F?_:v,n=(F?x++:S++)*4;t[n]=e.x,t[n+1]=e.y,t[n+2]=e.width,t[n+3]=e.height}}if(t.low<ne){let e=Be(A.wickRect.x,ee,E,o);if(e){let t=F?_:v,n=(F?x++:S++)*4;t[n]=e.x,t[n+1]=e.y,t[n+2]=e.width,t[n+3]=e.height}}}let A=f[0]?.aligned.wickRect.width??p[0]?.aligned.wickRect.width??1;return{upKLines:f,downKLines:p,upBodyBuf:h,upBodyCount:y,downBodyBuf:g,downBodyCount:b,upWickBuf:_,upWickCount:x,downWickBuf:v,downWickCount:S,wickWidth:A,relations:d,showVolumePriceMarkers:u}}function qa(e,t,n){e.save(),e.translate(-t,0),e.fillStyle=V.UP;for(let t=0;t<n.upBodyCount;t++){let r=t*4;e.fillRect(n.upBodyBuf[r],n.upBodyBuf[r+1],n.upBodyBuf[r+2],n.upBodyBuf[r+3])}e.fillStyle=V.DOWN;for(let t=0;t<n.downBodyCount;t++){let r=t*4;e.fillRect(n.downBodyBuf[r],n.downBodyBuf[r+1],n.downBodyBuf[r+2],n.downBodyBuf[r+3])}e.fillStyle=V.UP;for(let t=0;t<n.upWickCount;t++){let r=t*4;e.fillRect(n.upWickBuf[r],n.upWickBuf[r+1],n.wickWidth,n.upWickBuf[r+3])}e.fillStyle=V.DOWN;for(let t=0;t<n.downWickCount;t++){let r=t*4;e.fillRect(n.downWickBuf[r],n.downWickBuf[r+1],n.wickWidth,n.downWickBuf[r+3])}e.restore()}function Ja(e,t){if(e.settings?.enableWebGLRendering===!1)return!1;let n=e.candleWebGLSurface;if(!n||!n.isAvailable())return!1;n.clear();let r=t.upBodyCount===0||n.drawRectBuffer(t.upBodyBuf.subarray(0,t.upBodyCount*4),t.upBodyCount,V.UP,e.scrollLeft),i=t.downBodyCount===0||n.drawRectBuffer(t.downBodyBuf.subarray(0,t.downBodyCount*4),t.downBodyCount,V.DOWN,e.scrollLeft),a=t.upWickCount===0||n.drawRectBuffer(t.upWickBuf.subarray(0,t.upWickCount*4),t.upWickCount,V.UP,e.scrollLeft),o=t.downWickCount===0||n.drawRectBuffer(t.downWickBuf.subarray(0,t.downWickCount*4),t.downWickCount,V.DOWN,e.scrollLeft);return r&&i&&a&&o}function Ya(e,t){let n=t.candleWebGLSurface;if(!n)return;let r=n.getCanvas();r.width<=0||r.height<=0||e.drawImage(r,0,0,r.width,r.height,0,0,r.width/t.dpr,r.height/t.dpr)}function Xa(e,t,n){let{ctx:r,range:i,kWidth:a,dpr:o}=e;if(!(!t.showVolumePriceMarkers||!n||(e.zoomLevel??1)<2)){r.save(),r.translate(-e.scrollLeft,0);for(let s of t.upKLines){let c=t.relations?.[s.i-i.start];if(c!==void 0&&c!==$.OTHERS){let t=c===$.RISE_WITH_VOLUME||c===$.RISE_WITHOUT_VOLUME?s.alignedHighY-15:s.alignedLowY+15,l=s.i-i.start,u=e.kLineCenters[l];Za(r,u,t,c,s.i,a,4,n,o)}}for(let s of t.downKLines){let c=t.relations?.[s.i-i.start];if(c!==void 0&&c!==$.OTHERS){let t=c===$.RISE_WITH_VOLUME||c===$.RISE_WITHOUT_VOLUME?s.alignedHighY-15:s.alignedLowY+15,l=s.i-i.start,u=e.kLineCenters[l];Za(r,u,t,c,s.i,a,4,n,o)}}r.restore()}}function Za(e,t,n,r,i,a,o=4,s,c){let l=e=>Math.round(e*c)/c;t=l(t),n=l(n);let u=Math.min(a,20),d=u*Math.sqrt(3)/2,f,p;switch(r){case $.RISE_WITH_VOLUME:f=`#FF4444`,p=!0;break;case $.RISE_WITHOUT_VOLUME:f=`#00C853`,p=!0;break;case $.FALL_WITH_VOLUME:f=`#FF4444`,p=!1;break;case $.FALL_WITHOUT_VOLUME:f=`#00C853`,p=!1;break;default:return}if(e.save(),e.beginPath(),p){let r=l(n-o),i=l(r-d);e.moveTo(t,i),e.lineTo(l(t-u/2),r),e.lineTo(l(t+u/2),r)}else{let r=l(n+o),i=l(r+d);e.moveTo(t,i),e.lineTo(l(t-u/2),r),e.lineTo(l(t+u/2),r)}e.closePath(),e.fillStyle=f,e.fill(),e.restore();let m,h;if(p){let e=l(l(n-o)-d);m=l(t-u/2),h=e}else{let e=l(n+o);l(e+d),m=l(t-u/2),h=e}let g;switch(r){case $.RISE_WITH_VOLUME:g=`RISE_WITH_VOLUME`;break;case $.RISE_WITHOUT_VOLUME:g=`RISE_WITHOUT_VOLUME`;break;case $.FALL_WITH_VOLUME:g=`FALL_WITH_VOLUME`;break;case $.FALL_WITHOUT_VOLUME:g=`FALL_WITHOUT_VOLUME`;break;default:return}let _=`mk_price-volume_${i}`;s.register({id:_,type:`triangle`,markerType:g,x:m,y:h,width:u,height:d,dataIndex:i,metadata:{relation:r}})}function Qa(e,t){return Math.max(3,Math.round(e/60)+1)}function $a(e){let{height:t,paddingTop:n,paddingBottom:r,isMain:i,hideEdgeTicks:a}=e,o=n,s=Math.max(n,t-r),c=Math.max(0,s-o),l=Qa(t,i),u=[];for(let e=0;e<l;e++){if(a&&(e===0||e===l-1))continue;let t=l<=1?0:e/(l-1),n=o+t*c;u.push({index:e,t,y:n})}return u}var eo=1e-10,to=[1,1.2,1.5,2,2.5,3,4,5,6,7.5,8,10];function no(e){if(!Number.isFinite(e)||e<=0)return e;let t=10**Math.floor(Math.log10(e)),n=e/t,r=to[0],i=1/0;for(let e of to){let t=Math.abs(e-n);t<i&&(i=t,r=e)}return r*t}function ro(e){let{height:t,paddingTop:n,paddingBottom:r,valueMin:i,valueMax:a,targetCount:o}=e,s=Math.max(i,eo),c=Math.max(a,s*1.001),l=n,u=Math.max(n,t-r),d=Math.max(0,u-l);if(d<=0)return[];let f=we({minPrice:s,maxPrice:c}),p=z(s,f),m=z(c,f),h=m-p;if(!Number.isFinite(h)||Math.abs(h)<1e-10)return[];let g=Math.max(2,o),_=g<=1?d:d/(g-1),v=_*.6,y=_*.15,b=[],x=null;for(let e=0;e<g;e++){let t=g<=1?0:e/(g-1),n=l+t*d,r=Ce(m-t*h,f),i=r,a=t,o=n,s=no(r);if(Number.isFinite(s)&&s>0){let e=(m-z(s,f))/h,t=l+e*d;Number.isFinite(t)&&Math.abs(t-n)<=y&&(i=s,a=e,o=t)}o<l-.5||o>u+.5||x!==null&&Math.abs(o-x)<v||(b.push({index:b.length,t:a,y:o,value:i}),x=o)}return b}var io=``,ao=[];function oo(e){return`${e.valueMin}:${e.valueMax}:${e.height}:${e.paddingTop}:${e.paddingBottom}:${e.isMain}:${e.scaleType??`linear`}:${e.hideEdgeTicks??!1}`}function so(e){let t=oo(e);if(t===io)return ao;let{valueMin:n,valueMax:r,scaleType:i=`linear`}=e;if(i===`log`){if(n<=0)return so({...e,scaleType:`linear`});let i=Math.max(n,eo),a=Math.max(r,i*1.001),{height:o,paddingTop:s,paddingBottom:c,isMain:l,hideEdgeTicks:u}=e,d=ro({height:o,paddingTop:s,paddingBottom:c,valueMin:i,valueMax:a,targetCount:Math.max(2,Qa(o,l))});u&&d.length>2&&(d=d.slice(1,-1));let f=d.map((e,t)=>({...e,index:t}));return io=t,ao=f,f}let a=$a(e),o=Qa(e.height,e.isMain),s=r-n||1,c=a.map(e=>{let t=r-s/Math.max(1,o-1)*e.index;return{...e,value:t}});return io=t,ao=c,c}function co(){return{name:`gridLines`,version:`1.0.0`,description:`网格线渲染器`,debugName:`网格线`,paneId:de,priority:L.GRID,draw(e){let{ctx:t,pane:n,data:r,range:i,scrollLeft:a,kWidth:o,dpr:s,kLinePositions:c}=e,l=r;if(!l.length)return;t.save(),t.fillStyle=Ne.HORIZONTAL,t.translate(-a,0);let u=t.canvas.width/s,d=a,f=a+u,p=n.yAxis.getPaddingTop(),m=n.yAxis.getPaddingBottom(),h=n.yAxis.getScaleType(),g;if(h===`log`&&n.role===`price`){let e=n.yAxis.getDisplayRange(n.priceRange);g=so({height:n.height,paddingTop:p,paddingBottom:m,isMain:!0,valueMin:e.minPrice,valueMax:e.maxPrice,scaleType:`log`}).map(e=>e.y)}else g=$a({height:n.height,paddingTop:p,paddingBottom:m,isMain:n.role===`price`}).map(e=>e.y);for(let e of g){let n=Ve(d,f,e,s);n&&t.fillRect(n.x,n.y,n.width,n.height)}let _=dt(l);for(let e of _){if(e<i.start||e>=i.end||e>=l.length)continue;let r=e-i.start;if(r<0||r>=c.length)continue;let a=Be(c[r]+o/2,0,n.height,s);a&&t.fillRect(a.x,a.y,a.width,a.height)}t.restore()}}}function lo(e){let{pane:t,data:n}=e,r=n,i=r[r.length-1];if(!i)return null;let a=t.yAxis.getDisplayRange(t.priceRange);return i.close<a.minPrice||i.close>a.maxPrice?null:{price:i.close,y:Math.round(t.yAxis.priceToY(i.close)),dataIndex:r.length-1}}function uo(){return{name:`lastPriceLabelRegistrar`,version:`1.0.0`,description:`最新价 label 注册`,debugName:`最新价标签注册`,paneId:`main`,layer:`overlay`,priority:L.LAST_PRICE_LABEL,draw(e){let t=lo(e);t&&(e.yAxisLabels||=[],e.yAxisLabels.push({dataIndex:t.dataIndex,price:t.price,y:t.y,type:`lastPrice`,style:{bgColor:`rgba(255, 247, 248, 0.98)`,borderColor:V.LAST_PRICE,textColor:V.LAST_PRICE}}))}}}function fo(){return{name:`lastPriceLine`,version:`1.0.0`,description:`最新价虚线渲染器`,debugName:`最新价线`,paneId:`main`,priority:L.LAST_PRICE_LABEL,draw(e){let{ctx:t,scrollLeft:n,dpr:r,kLinePositions:i,paneWidth:a}=e,o=lo(e);if(!o)return;let s=o.y;t.save(),t.translate(-n,0);let c=i[0]??0,l=a+n;t.strokeStyle=V.LAST_PRICE,t.lineWidth=1,t.setLineDash([4,3]),t.beginPath();let u=(Math.floor(s*r)+.5)/r;t.moveTo(Math.round(c*r)/r,u),t.lineTo(Math.round(l*r)/r,u),t.stroke(),t.setLineDash([]),t.restore()}}}function po(e,t,n,r,i,a){let o=t-n||1,s=Math.max(1,r-i-a);return n+(1-(Math.min(Math.max(e,i),i+s)-i)/s)*o}var mo=new Map,ho=512;function go(e,t){let n=`${e.font}\n${t}`,r=mo.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return mo.size>=ho&&mo.clear(),mo.set(n,i),i}function _o(e,t){let{x:n,y:r,width:i,height:a,crosshairX:o,timestamp:s,dpr:c,fontSize:l=16,paddingX:u=8}=t,d=at(s);e.save(),Mi(e,ji(l)),e.textBaseline=`middle`,e.textAlign=`center`;let f=Math.round(go(e,d)),p=Math.min(i,f+u*2),m=a,h=Math.min(Math.max(o,n+p/2),n+i-p/2),g=r+a/2,_=h-p/2,v=r;e.fillStyle=`rgba(0, 0, 0, 0.8)`,e.fillRect(X(_,c),X(v,c),X(p,c),X(m,c)),e.fillStyle=`#ffffff`,e.fillText(d,X(h,c),Z(g,c)),e.restore()}function vo(e,t){let{x:n,y:r,width:i,height:a,crosshairY:o,priceRange:s,yPaddingPx:c=0,dpr:l,bgColor:u=`rgba(0, 0, 0, 0.8)`,borderColor:d,textColor:f=`#ffffff`,fontSize:p=16,priceOffset:m=0,price:h,formatPrice:g}=t,_=Math.max(0,Math.min(c,Math.floor(a/2)-1)),{maxPrice:v,minPrice:y}=s,b=h??po(o-r,v,y,a,_,_)+m,x=g?g(b):b.toFixed(2);e.save(),Mi(e,ji(p)),e.textBaseline=`middle`,e.textAlign=`center`;let S=p+4,C=Math.min(Math.max(o,r+S/2),r+a-S/2),w=C-S/2,T=n,E=X(w,l),D=i,O=X(S,l);e.fillStyle=u,e.fillRect(T,E,D,O),d&&(e.strokeStyle=d,e.lineWidth=1,e.strokeRect(Z(T,l),Z(E,l),Math.max(0,D-1/l),Math.max(0,O-1/l)));let k=n+i/2;e.fillStyle=f,e.fillText(x,X(k,l),Z(C,l)),e.restore()}function yo(e,t){let{x:n,y:r,width:i,height:a,data:o,scrollLeft:s,kWidth:c,kGap:l,startIndex:u,endIndex:d,dpr:f,bgColor:p=Me.TRANSPARENT,textColor:m=je.SECONDARY,lineColor:h=H.DARK,fontSize:g=12,paddingX:_=8,drawTopBorder:v=!0,drawBottomBorder:y=!0}=t,b=Math.round(c*f),x=b%2==0?b+1:b,S=Math.round(l*f),C=x+S,w=S,T=C/f,E=w/f,D=x/f;e.fillStyle=p,e.fillRect(n,r,i,a),v&&(e.strokeStyle=h,e.lineWidth=1,e.beginPath(),e.moveTo(n,Z(r,f)),e.lineTo(n+i,Z(r,f)),e.stroke()),y&&(e.strokeStyle=h,e.lineWidth=1,e.beginPath(),e.moveTo(n,Z(r+a,f)),e.lineTo(n+i,Z(r+a,f)),e.stroke()),e.textAlign=`center`,e.textBaseline=`middle`,e.fillStyle=m;let O=r+a/2,k=ji(g),A=ji(g,{bold:!0}),j=dt(o).filter(e=>e>=u&&e<d),M=null;for(let t of j){let n=o[t];if(!n)continue;let r=E+t*T+D/2-s,a=_,c=Math.max(_,i-_);if(r>=a&&r<=c){let t=Math.min(Math.max(r,a),c),{text:i,isYear:o}=nt(n.timestamp);M!==o&&(Mi(e,o?A:k),M=o),e.fillText(i,X(t,f),Z(O,f))}}}function bo(e,t){let{x:n,y:r,width:i,height:a,priceY:o,price:s,dpr:c,bgColor:l=`rgba(0, 0, 0, 0.8)`,borderColor:u,textColor:d=`#ffffff`,fontSize:f=12}=t,p=s.toFixed(2);e.save(),Mi(e,ji(f)),e.textBaseline=`middle`,e.textAlign=`center`;let m=f+4,h=Math.min(Math.max(o,r+m/2),r+a-m/2),g=h-m/2,_=n,v=X(g,c),y=i,b=X(m,c);e.fillStyle=l,e.fillRect(_,v,y,b),u&&(e.strokeStyle=u,e.lineWidth=1,e.strokeRect(Z(_,c),Z(v,c),Math.max(0,y-1/c),Math.max(0,b-1/c)));let x=n+i/2;e.fillStyle=d,e.fillText(p,X(x,c),Z(h,c)),e.restore()}function xo(e,t){let{x:n,y:r,width:i,height:a,labelX:o,timestamp:s,dpr:c,fontSize:l=12,paddingX:u=8}=t,d=at(s);e.save(),Mi(e,ji(l)),e.textBaseline=`middle`,e.textAlign=`center`;let f=Math.round(go(e,d)),p=Math.min(i,f+u*2),m=a,h=Math.min(Math.max(o,n+p/2),n+i-p/2),g=r+a/2,_=h-p/2,v=r;e.fillStyle=t.bgColor??`rgba(0, 0, 0, 0.8)`,e.fillRect(X(_,c),X(v,c),X(p,c),X(m,c)),e.fillStyle=t.textColor??`#ffffff`,e.fillText(d,X(h,c),Z(g,c)),e.restore()}var So=new WeakMap;function Co(e){let t=So.get(e);return t||(t={},So.set(e,t)),t}var wo=`middle`,To=`center`;function Eo(e){let{ctx:t,dpr:n,axisWidth:r,height:i,paddingTop:a,paddingBottom:o,valueMin:s,valueMax:c,isMain:l,decimals:u=2,hideEdgeTicks:d=!0,scaleType:f=`linear`,formatLabel:p}=e;t.clearRect(0,0,r,i);let m=Co(t),h=ji(12);m.font!==h&&(Mi(t,h),m.font=h),m.textBaseline!==wo&&(t.textBaseline=wo,m.textBaseline=wo),m.textAlign!==To&&(t.textAlign=To,m.textAlign=To),m.fillStyle!==je.SECONDARY&&(t.fillStyle=je.SECONDARY,m.fillStyle=je.SECONDARY);let g=X(r/2,n),_=so({height:i,paddingTop:a,paddingBottom:o,isMain:l,hideEdgeTicks:d,valueMin:s,valueMax:c,scaleType:f}),v=p??(e=>e.toFixed(u));for(let e=0;e<_.length;e++){let{y:r,value:i}=_[e];t.fillText(v(i),g,Z(r,n))}}function Do(e){let{axisWidth:t,paneId:n,indicatorKey:r,label:i,decimals:a=2,yPaddingPx:o=0,scaleType:s=`linear`,getCrosshair:c,formatTickLabel:l,formatCrosshairLabel:u}=e,d=Q(r,n),f=null;return{name:`${r}Scale_${n}`,version:`1.0.0`,description:`${i} 刻度渲染器`,debugName:`${i}刻度`,paneId:n,priority:L.INDICATOR_SCALE,onInstall(e){f=e},draw(e){let{yAxisCtx:n,pane:r,dpr:i}=e;if(!n||!f)return;let p=f.getSharedState(d);if(!p)return;let m=r.yAxis.getScaleType()??s,h=r.yAxis.getDisplayRange({minPrice:p.valueMin,maxPrice:p.valueMax});Eo({ctx:n,dpr:i,axisWidth:t,height:r.height,paddingTop:r.yAxis.getPaddingTop(),paddingBottom:r.yAxis.getPaddingBottom(),valueMin:h.minPrice,valueMax:h.maxPrice,isMain:!1,decimals:a,hideEdgeTicks:!1,scaleType:m,formatLabel:l});let g=c?.();if(!g||g.activePaneId!==r.id)return;let _=g.y-r.top,v=r.yAxis.getPaddingTop(),y=r.yAxis.getPaddingBottom(),b=v,x=Math.max(v,r.height-y),S=Math.max(1,x-b),C=(Math.min(Math.max(_,b),x)-b)/S,w=h.maxPrice-C*(h.maxPrice-h.minPrice);vo(n,{x:0,y:0,width:t,height:r.height,crosshairY:_,priceRange:h,yPaddingPx:o,dpr:i,fontSize:12,priceOffset:0,price:w,formatPrice:u})}}}function Oo(e){return{name:`yAxis`,version:`1.0.0`,description:`Y轴价格刻度渲染器`,debugName:`Y轴`,paneId:de,priority:L.SYSTEM_YAXIS,draw(t){let{ctx:n,pane:r,dpr:i,yAxisCtx:a,data:o}=t,s=r.yAxis.getScaleType(),c=a||n,l=a?.canvas?a.canvas.width/i:e.axisWidth,u=r.yAxis.getDisplayRange(r.priceRange);if(r.capabilities.showPriceAxisTicks&&Eo({ctx:c,dpr:i,axisWidth:l,height:r.height,paddingTop:r.yAxis.getPaddingTop(),paddingBottom:r.yAxis.getPaddingBottom(),valueMin:u.minPrice,valueMax:u.maxPrice,isMain:!0,decimals:2,hideEdgeTicks:!1,scaleType:s}),t.yAxisRanges&&r.role===`price`)for(let e of t.yAxisRanges){let t=e.topY+r.top,n=e.bottomY-e.topY;n<=0||(c.save(),c.globalAlpha=e.opacity,c.fillStyle=e.color,c.fillRect(0,t,l,n),c.restore())}if(t.yAxisLabels&&r.role===`price`)for(let e of t.yAxisLabels){let t=e.type===`lastPrice`;bo(c,{x:0,y:r.top,width:l,height:r.height,priceY:e.y+r.top,price:e.price,dpr:i,bgColor:e.style?.bgColor??`rgba(0, 0, 0, 0.8)`,borderColor:e.style?.borderColor,textColor:e.style?.textColor??`#ffffff`,fontSize:t?12:11})}let d=e.getCrosshair?.();d&&d.activePaneId===r.id&&d.price!==null&&vo(c,{x:0,y:r.top,width:l,height:r.height,crosshairY:d.y,priceRange:u,yPaddingPx:e.yPaddingPx,dpr:i,fontSize:12,priceOffset:0,price:d.price})}}}function ko(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`macd`,label:`MACD`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}var Ao=1e8;function jo(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`volume`,label:`VOL`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair,formatTickLabel:e=>`${(e/Ao).toFixed(2)}B`,formatCrosshairLabel:e=>`${(e/Ao).toFixed(2)}B`})}function Mo(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`rsi`,label:`RSI`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function No(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`cci`,label:`CCI`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Po(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`stoch`,label:`STOCH`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Fo(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`mom`,label:`MOM`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Io(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`wmsr`,label:`WMSR`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Lo(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`kst`,label:`KST`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Ro(e){return Do({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`fastk`,label:`FASTK`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}var zo=Symbol(`time-axis`);function Bo(e){return{name:`timeAxis`,version:`1.0.0`,description:`时间轴渲染器`,debugName:`时间轴`,paneId:zo,priority:L.SYSTEM_XAXIS,isSystem:!0,draw(t){let{ctx:n,data:r,range:i,scrollLeft:a,kWidth:o,kGap:s,dpr:c,paneWidth:l}=t,u=r,d=n,f=l,p=e.height;if(d.setTransform(1,0,0,1,0,0),d.scale(c,c),d.clearRect(0,0,f,p),yo(d,{x:0,y:0,width:f,height:p,data:u,scrollLeft:a,kWidth:o,kGap:s,startIndex:i.start,endIndex:i.end,dpr:c,drawTopBorder:!1,drawBottomBorder:!1}),t.xAxisRanges)for(let e of t.xAxisRanges){let t=e.leftX-a,n=e.rightX-a-t;n<=0||(d.save(),d.globalAlpha=e.opacity,d.fillStyle=e.color,d.fillRect(t,0,n,p),d.restore())}let m=e.getCrosshair?.();if(m&&typeof m.index==`number`){let e=u[m.index];e&&_o(d,{x:0,y:0,width:f,height:p,crosshairX:m.x,timestamp:e.timestamp,dpr:c,fontSize:12})}if(t.xAxisLabels)for(let e of t.xAxisLabels){let t=e.x-a;t>=0&&t<=f&&xo(d,{x:0,y:0,width:f,height:p,labelX:t,timestamp:e.timestamp,dpr:c,fontSize:12,bgColor:e.style?.bgColor,textColor:e.style?.textColor})}}}}function Vo(e){return{name:`crosshair`,version:`1.0.0`,description:`十字线渲染器`,debugName:`十字线`,paneId:de,priority:L.SYSTEM_CROSSHAIR,layer:`overlay`,draw(t){let{pane:n,dpr:r,paneWidth:i,overlayCtx:a}=t,o=e.getCrosshairState();if(o.isDragging||!o.pos)return;let{x:s}=o.pos,c=n.id===o.activePaneId,l=-1;c&&o.price!==null&&(l=n.yAxis.priceToY(o.price));let u=a;if(!u)return;u.save(),u.beginPath(),u.rect(0,0,i,n.height),u.clip(),u.fillStyle=ze.LINE;let d=Be(s,0,n.height,r);if(d&&u.fillRect(d.x,d.y,d.width,d.height),c&&l>=0){let e=Ve(0,i,Math.min(l,n.height-1/r),r);e&&u.fillRect(e.x,e.y,e.width,e.height)}u.restore()}}}var Ho=new Map,Uo=256;function Wo(e,t){let n=`${e.font}\n${t}`,r=Ho.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return Ho.size>=Uo&&Ho.clear(),Ho.set(n,i),i}function Go(e){let t={...e};return{name:`paneTitle_${e.paneId}`,version:`1.0.0`,description:`面板标题渲染器`,debugName:`面板标题`,paneId:e.paneId,priority:L.FOREGROUND,draw(e){let{ctx:n,pane:r}=e;if(r.id!==t.paneId)return;let i=t.yOffset??12;n.save(),Mi(n,ji(12)),n.textAlign=`left`,n.textBaseline=`top`;let a=t.getTitleInfo?.();if(a){let e=12;if(n.fillStyle=je.PRIMARY,n.fillText(a.name,e,i),e+=Wo(n,a.name),a.params&&a.params.length>0){let t=`(${a.params.join(`,`)})`;n.fillStyle=je.TERTIARY,n.fillText(t,e,i),e+=Wo(n,t)+8}else e+=8;if(a.values&&a.values.length>0)for(let t of a.values){let r=`${t.label} ${t.value.toFixed(3)}`;n.fillStyle=t.color,n.fillText(r,e,i),e+=Wo(n,r)+8}}else if(n.fillStyle=je.PRIMARY,n.fillText(t.title,12,i),t.description){let e=Wo(n,t.title);n.fillStyle=je.WEAK,n.fillText(` - ${t.description}`,12+e,i)}n.restore()},setConfig(e){t={...t,...e}}}}var Ko={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function qo(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ko,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M7.904 17.563a1.2 1.2 0 0 0 2.228.308l2.09-3.093l4.907 4.907a1.067 1.067 0 0 0 1.509 0l1.047-1.047a1.067 1.067 0 0 0 0-1.509l-4.907-4.907l3.113-2.09a1.2 1.2 0 0 0-.309-2.228L4 4z`},null,-1)]])}var Jo=(0,e.markRaw)({name:`tabler-pointer`,render:qo}),Yo={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Xo(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Yo,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 19h16M4 15l4-6l4 2l4-5l4 4`},null,-1)]])}var Zo=(0,e.markRaw)({name:`tabler-chart-line`,render:Xo}),Qo={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function $o(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Qo,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M17 7L7 17M8 7h9v9`},null,-1)]])}var es=(0,e.markRaw)({name:`tabler-arrow-up-right`,render:$o}),ts={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function ns(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,ts,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M5 12h14m-6 6l6-6m-6-6l6 6`},null,-1)]])}var rs=(0,e.markRaw)({name:`tabler-arrow-right`,render:ns}),is={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function as(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,is,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M5 12h14`},null,-1)]])}var os=(0,e.markRaw)({name:`tabler-minus`,render:as}),ss={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function cs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,ss,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 12v.01M7 12h10m4 0v.01`},null,-1)]])}var ls=(0,e.markRaw)({name:`tabler-separator`,render:cs}),us={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function ds(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,us,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2M9 12h6m-3-3v6`},null,-1)]])}var fs=(0,e.markRaw)({name:`tabler-crosshair`,render:ds}),ps={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function ms(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,ps,[...n[0]||=[(0,e.createElementVNode)(`g`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0-18 0m9-3h.01`}),(0,e.createElementVNode)(`path`,{d:`M11 12h1v4h1`})],-1)]])}var hs=(0,e.markRaw)({name:`tabler-info-circle`,render:ms}),gs={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function _s(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,gs,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2`},null,-1)]])}var vs=(0,e.markRaw)({name:`tabler-maximize`,render:_s}),ys={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function bs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,ys,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M15 19v-2a2 2 0 0 1 2-2h2M15 5v2a2 2 0 0 0 2 2h2M5 15h2a2 2 0 0 1 2 2v2M5 9h2a2 2 0 0 0 2-2V5`},null,-1)]])}var xs=(0,e.markRaw)({name:`tabler-minimize`,render:bs}),Ss={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Cs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ss,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 10a7 7 0 1 0 14 0a7 7 0 1 0-14 0m4 0h6m-3-3v6m11 8l-6-6`},null,-1)]])}var ws=(0,e.markRaw)({name:`tabler-zoom-in`,render:Cs}),Ts={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Es(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ts,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 10a7 7 0 1 0 14 0a7 7 0 1 0-14 0m4 0h6m8 11l-6-6`},null,-1)]])}var Ds=(0,e.markRaw)({name:`tabler-zoom-out`,render:Es}),Os={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function ks(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Os,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 5a2 2 0 1 0 4 0a2 2 0 1 0-4 0m14 0a2 2 0 1 0 4 0a2 2 0 1 0-4 0M3 19a2 2 0 1 0 4 0a2 2 0 1 0-4 0m14 0a2 2 0 1 0 4 0a2 2 0 1 0-4 0M5 7v10M7 5h10M7 19h10m2-12v10`},null,-1)]])}var As=(0,e.markRaw)({name:`tabler-shape`,render:ks}),js={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Ms(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,js,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 7a2 2 0 1 0 4 0a2 2 0 1 0-4 0m11 8a2 2 0 1 0 4 0a2 2 0 1 0-4 0m1-9a3 3 0 1 0 6 0a3 3 0 1 0-6 0M3 18a3 3 0 1 0 6 0a3 3 0 1 0-6 0m6-1l5-1.5m-7.5-7l7.81 5.37M7 7l8-1`},null,-1)]])}var Ns=(0,e.markRaw)({name:`tabler-chart-dots-3`,render:Ms}),Ps={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Fs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ps,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`m18 10l-6-6l-6 6zm0 4l-6 6l-6-6z`},null,-1)]])}var Is=(0,e.markRaw)({name:`tabler-caret-up-down`,render:Fs}),Ls={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Rs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ls,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M8 4H5v16h3m8-16h3v16h-3`},null,-1)]])}var zs=(0,e.markRaw)({name:`tabler-brackets`,render:Rs}),Bs={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Vs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Bs,[...n[0]||=[(0,e.createElementVNode)(`g`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065`}),(0,e.createElementVNode)(`path`,{d:`M9 12a3 3 0 1 0 6 0a3 3 0 0 0-6 0`})],-1)]])}var Hs=(0,e.markRaw)({name:`tabler-settings`,render:Vs});function Us(){if(typeof navigator>`u`)return`desktop`;let e=navigator.userAgentData;if(e?.formFactor){let t=e.formFactor;if(t===`phone`)return`mobile`;if(t===`tablet`)return`tablet`;if(t===`desktop`)return`desktop`}if(e?.mobile===!0)return`mobile`;e?.mobile;let t=navigator.userAgent.toLowerCase();if(/android.*mobile|webos|iphone|ipod|blackberry|iemobile|opera mini|mobile/i.test(t))return`mobile`;let n=navigator.maxTouchPoints>1,r=window.screen.width>=768&&window.screen.width<=1366;return n&&r?`tablet`:`desktop`}var Ws=[{key:`showVolumePriceMarkers`,label:`显示量价关系标记`,type:`boolean`,default:!1,group:`main`},{key:`logarithmicScale`,label:`对数价格轴`,type:`boolean`,default:!1,group:`main`},{key:`disableMainPaneVerticalScroll`,label:`主图纵轴刻度自适应调整`,type:`boolean`,default:!0,group:`main`},{key:`enableWebGLRendering`,label:`启用 WebGL 硬件加速渲染`,type:`boolean`,default:Us()===`desktop`,group:`main`},{key:`performanceTest10kKlines`,label:`万条K线性能测试`,type:`boolean`,default:!1,group:`experimental`},{key:`enableCanvasProfiler`,label:`Canvas 性能分析插桩`,type:`boolean`,default:!1,group:`experimental`}],Gs=`kline-chart-settings`;function Ks(){return Object.create(null)}function qs(){return{ctxMethods:Ks(),ctxProps:Ks(),canvasProps:Ks(),ctxMethodSources:Object.create(null)}}function Js(e,t,n){let r=e[t]??={count:0,totalTime:0};r.count+=1,r.totalTime+=n}function Ys(e,t,n,r){Js(e.ctxMethodSources[t]??=Ks(),n,r)}function Xs(e){return Object.entries(e).filter(([,e])=>e.count>0).map(([e,t])=>({name:e,count:t.count,totalTime:t.totalTime.toFixed(2),averageTime:(t.totalTime/t.count).toFixed(4)})).sort((e,t)=>Number(t.totalTime)-Number(e.totalTime))}var Zs=!1,Qs=new Map,$s=new Map;function ec(e){Zs=e,e?typeof window<`u`&&!window.__KMAP_CANVAS_PROFILER_INSTALLED__&&ic():ac()}function tc(){if(!Zs)return`disabled`;let e=Error().stack;if(!e)return`unknown`;let t=e.split(`
49
- `).map(e=>e.trim()).filter(Boolean);for(let e of t){if(e.includes(`canvasProfiler`)||e.includes(`CanvasRenderingContext2D`)||e===`Error`)continue;let t=e.replace(/^at\s+/,``),n=t.match(/((?:src|node_modules)[^\s)]+):(\d+):(\d+)/);if(n)return`${n[1]}:${n[2]}`;let r=t.match(/\(([^)]+):(\d+):(\d+)\)$/);return r?`${r[1]}:${r[2]}`:t}return`unknown`}function nc(e,t,n,r){let i=`${e.constructor?.name??`proto`}:${t}`;if(Qs.has(i))return;let a=Reflect.get(e,t);typeof a==`function`&&(Qs.set(i,a),Reflect.set(e,t,function(...e){if(!Zs)return a.apply(this,e);let i=r?.captureSource?tc():null,o=performance.now(),s=a.apply(this,e),c=performance.now()-o;return Js(n.ctxMethods,t,c),i&&Ys(n,t,i,c),s}))}function rc(e,t,n){let r=Object.getOwnPropertyDescriptor(e,t);if(!r?.set||!r.configurable)return;let i=`${e.constructor?.name??`proto`}:${t}`;$s.has(i)||($s.set(i,r),Object.defineProperty(e,t,{configurable:!0,enumerable:r.enumerable??!1,get:r.get,set(e){if(!Zs){r.set.call(this,e);return}let i=performance.now();r.set.call(this,e),Js(n,t,performance.now()-i)}}))}function ic(){if(typeof window>`u`||window.__KMAP_CANVAS_PROFILER_INSTALLED__)return;let e=CanvasRenderingContext2D?.prototype,t=HTMLCanvasElement?.prototype;if(!e||!t)return;let n=qs();nc(e,`fillText`,n,{captureSource:!0}),nc(e,`measureText`,n,{captureSource:!0}),nc(e,`drawImage`,n),nc(e,`save`,n),nc(e,`restore`,n),nc(e,`clip`,n),nc(e,`setTransform`,n),nc(e,`scale`,n),rc(e,`font`,n.ctxProps),rc(e,`filter`,n.ctxProps),rc(e,`shadowBlur`,n.ctxProps),rc(e,`lineWidth`,n.ctxProps),rc(t,`width`,n.canvasProps),rc(t,`height`,n.canvasProps),window.__KMAP_CANVAS_PROFILER_METRICS__=n,window.__KMAP_CANVAS_PROFILER_INSTALLED__=!0,window.showCanvasReport=()=>{let e=window.__KMAP_CANVAS_PROFILER_METRICS__;if(e){console.group(`[kmap] Canvas profiler report`),console.log(`ctx methods`),console.table(Xs(e.ctxMethods)),console.log(`ctx props`),console.table(Xs(e.ctxProps)),console.log(`canvas props`),console.table(Xs(e.canvasProps));for(let t of[`fillText`,`measureText`]){let n=e.ctxMethodSources[t];n&&(console.log(`${t} sources`),console.table(Xs(n).slice(0,20)))}console.groupEnd()}},window.resetCanvasReport=()=>{window.__KMAP_CANVAS_PROFILER_METRICS__=qs()},console.info(`[kmap] Canvas profiler enabled. Use window.showCanvasReport() and window.resetCanvasReport().`)}function ac(){if(typeof window>`u`||!window.__KMAP_CANVAS_PROFILER_INSTALLED__)return;let e=CanvasRenderingContext2D?.prototype,t=HTMLCanvasElement?.prototype;Qs.forEach((n,r)=>{let i=r.match(/^(.+):(.+)$/);if(!i)return;let[,a,o]=i,s=null;a===`CanvasRenderingContext2D`?s=e:a===`HTMLCanvasElement`&&(s=t),s&&Reflect.set(s,o,n)}),Qs.clear(),$s.forEach((n,r)=>{let i=r.match(/^(.+):(.+)$/);if(!i)return;let[,a,o]=i,s=null;a===`CanvasRenderingContext2D`?s=e:a===`HTMLCanvasElement`&&(s=t),s&&n.configurable&&Object.defineProperty(s,o,n)}),$s.clear(),window.__KMAP_CANVAS_PROFILER_INSTALLED__=!1,window.__KMAP_CANVAS_PROFILER_METRICS__=void 0,window.showCanvasReport=void 0,window.resetCanvasReport=void 0,console.info(`[kmap] Canvas profiler disabled.`)}var oc={class:`left-toolbar`,"aria-label":`图表工具栏`},sc={class:`left-toolbar__group`},cc=[`title`,`aria-label`,`onClick`],lc=[`onClick`],uc=[`title`,`aria-label`,`onClick`],dc={class:`left-toolbar__group`},fc={class:`left-toolbar__group`},pc=[`title`,`aria-label`],mc={class:`left-toolbar__group`},hc={class:`settings-body`},gc={class:`settings-label`},_c=[`onUpdate:modelValue`],vc=[`onUpdate:modelValue`],yc=[`value`],bc={class:`settings-label`},xc=[`onUpdate:modelValue`],Sc=[`onUpdate:modelValue`],Cc=[`value`],wc=Lt((0,e.defineComponent)({__name:`LeftToolbar`,props:{isFullscreen:{type:Boolean}},emits:[`selectTool`,`toggleFullscreen`,`zoomIn`,`zoomOut`,`settingsChange`],setup(t,{expose:n,emit:r}){let i=r,a=[{id:`cursor`,title:`光标`,icon:Jo},{id:`lines`,title:`线条`,icon:Zo,children:[{id:`trend-line`,title:`线段`,icon:Zo},{id:`ray`,title:`射线`,icon:es},{id:`h-line`,title:`水平线`,icon:os},{id:`h-ray`,title:`水平射线`,icon:rs},{id:`v-line`,title:`垂直线`,icon:ls},{id:`crosshair-line`,title:`十字线`,icon:fs},{id:`info-line`,title:`信息线`,icon:hs}]},{id:`channels`,title:`通道`,icon:As,children:[{id:`parallel-channel`,title:`平行通道`,icon:As},{id:`regression-channel`,title:`回归趋势`,icon:Ns},{id:`flat-line`,title:`平滑顶底`,icon:Is},{id:`disjoint-channel`,title:`不相交通道`,icon:zs}]}],o=(0,e.computed)(()=>Ws.filter(e=>e.group===`main`)),s=(0,e.computed)(()=>Ws.filter(e=>e.group===`experimental`)),c=(0,e.ref)(`cursor`),l=(0,e.ref)(null),u=(0,e.ref)(!1),d=Gt();function f(){try{let e=localStorage.getItem(Gs);if(e){let t=JSON.parse(e),n={};return Ws.forEach(e=>{n[e.key]=t[e.key]??e.default}),n}}catch{}let e={};return Ws.forEach(t=>{e[t.key]=t.default}),e}function p(e){try{localStorage.setItem(Gs,JSON.stringify(e))}catch{}}let m=(0,e.ref)(f()),h=(0,e.ref)({...m.value});function g(e){return c.value===e.id?!0:e.children?e.children.some(e=>e.id===c.value):!1}function _(e){if(e.children?.length){if(!e.children.some(e=>e.id===c.value)){let t=e.children[0];c.value=t.id,i(`selectTool`,t.id)}y(e.id);return}c.value=e.id,i(`selectTool`,e.id),l.value=null}function v(e){c.value=e.id,i(`selectTool`,e.id),l.value=null}function y(e){l.value=l.value===e?null:e}function b(){h.value={...m.value},u.value=!0}function x(){u.value=!1}function S(){let e={};Ws.forEach(t=>{e[t.key]=t.default}),h.value=e}function C(){m.value={...h.value},p(m.value),ec(!!m.value.enableCanvasProfiler),i(`settingsChange`,{...m.value}),x()}function w(){return{...m.value}}n({getSettings:w});function T(e){e.target.closest(`.tool-item`)||(l.value=null)}return(0,e.onMounted)(()=>{document.addEventListener(`click`,T,!0),i(`settingsChange`,{...m.value}),ec(!!m.value.enableCanvasProfiler)}),(0,e.onUnmounted)(()=>{document.removeEventListener(`click`,T,!0)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,null,[(0,e.createElementVNode)(`nav`,oc,[(0,e.createElementVNode)(`div`,sc,[((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(a,t=>(0,e.createElementVNode)(`div`,{key:t.id,class:`tool-item`},[(0,e.createElementVNode)(`button`,{type:`button`,class:(0,e.normalizeClass)([`left-toolbar__button`,{active:g(t)}]),title:t.title,"aria-label":t.title,onClick:e=>_(t),onPointerdown:r[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[1]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[2]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.icon),{class:`tool-icon`,"aria-hidden":`true`})),t.children&&t.children.length?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,{key:0,class:(0,e.normalizeClass)([`corner-indicator`,{open:l.value===t.id}]),onClick:(0,e.withModifiers)(e=>y(t.id),[`stop`]),"aria-label":`展开子菜单`},null,10,lc)):(0,e.createCommentVNode)(``,!0)],42,cc),(0,e.createVNode)(e.Transition,{name:`dropdown`},{default:(0,e.withCtx)(()=>[l.value===t.id&&t.children&&t.children.length?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`tool-dropdown`,onPointerdown:r[3]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[4]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[5]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.children,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:t.id,type:`button`,class:(0,e.normalizeClass)([`left-toolbar__button`,{active:c.value===t.id}]),title:t.title,"aria-label":t.title,onClick:e=>v(t)},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.icon),{class:`tool-icon`,"aria-hidden":`true`}))],10,uc))),128))],32)):(0,e.createCommentVNode)(``,!0)]),_:2},1024)])),64))]),r[22]||=(0,e.createElementVNode)(`span`,{class:`left-toolbar__divider`},null,-1),(0,e.createElementVNode)(`div`,dc,[(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:`放大`,"aria-label":`放大`,onClick:r[6]||=e=>n.$emit(`zoomIn`),onPointerdown:r[7]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[8]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[9]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(ws),{class:`tool-icon`,"aria-hidden":`true`})],32),(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:`缩小`,"aria-label":`缩小`,onClick:r[10]||=e=>n.$emit(`zoomOut`),onPointerdown:r[11]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[12]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[13]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(Ds),{class:`tool-icon`,"aria-hidden":`true`})],32)]),r[23]||=(0,e.createElementVNode)(`span`,{class:`left-toolbar__divider`},null,-1),(0,e.createElementVNode)(`div`,fc,[(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:t.isFullscreen?`退出全屏`:`全屏显示`,"aria-label":t.isFullscreen?`退出全屏`:`全屏显示`,onClick:r[14]||=e=>n.$emit(`toggleFullscreen`),onPointerdown:r[15]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[16]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[17]||=(0,e.withModifiers)(()=>{},[`stop`])},[t.isFullscreen?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(xs),{key:0,class:`tool-icon`,"aria-hidden":`true`})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(vs),{key:1,class:`tool-icon`,"aria-hidden":`true`}))],40,pc)]),r[24]||=(0,e.createElementVNode)(`span`,{class:`left-toolbar__divider`},null,-1),(0,e.createElementVNode)(`div`,mc,[(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:`设置`,"aria-label":`设置`,onClick:b,onPointerdown:r[18]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[19]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[20]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(Hs),{class:`tool-icon`,"aria-hidden":`true`})],32)])]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{to:(0,e.unref)(d)},[(0,e.createVNode)(e.Transition,{name:`overlay`},{default:(0,e.withCtx)(()=>[u.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`settings-overlay`,onClick:x},[(0,e.createVNode)(e.Transition,{name:`modal`},{default:(0,e.withCtx)(()=>[(0,e.createElementVNode)(`div`,{class:`settings-modal`,onClick:r[21]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`div`,{class:`settings-header`},[r[26]||=(0,e.createElementVNode)(`div`,{class:`header-left`},[(0,e.createElementVNode)(`span`,{class:`settings-title`},`图表设置`),(0,e.createElementVNode)(`span`,{class:`settings-subtitle`},`个性化配置`)],-1),(0,e.createElementVNode)(`div`,{class:`header-right`},[(0,e.createElementVNode)(`button`,{class:`settings-close`,onClick:x},[...r[25]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M18 6L6 18M6 6l12 12`})],-1)]])])]),(0,e.createElementVNode)(`div`,hc,[o.value.length>0?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:0},[r[27]||=(0,e.createElementVNode)(`div`,{class:`settings-section-divider`},[(0,e.createElementVNode)(`span`,{class:`settings-section-label`},`主图设置`)],-1),((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(o.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.key,class:`settings-item`},[(0,e.createElementVNode)(`label`,gc,[(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.label),1),t.type===`boolean`?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`input`,{key:0,type:`checkbox`,class:`settings-checkbox`,"onUpdate:modelValue":e=>h.value[t.key]=e},null,8,_c)),[[e.vModelCheckbox,h.value[t.key]]]):t.type===`select`&&t.options?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`select`,{key:1,class:`settings-select`,"onUpdate:modelValue":e=>h.value[t.key]=e},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.options,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`option`,{key:t.value,value:t.value},(0,e.toDisplayString)(t.label),9,yc))),128))],8,vc)),[[e.vModelSelect,h.value[t.key]]]):(0,e.createCommentVNode)(``,!0)])]))),128))],64)):(0,e.createCommentVNode)(``,!0),s.value.length>0?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:1},[r[28]||=(0,e.createElementVNode)(`div`,{class:`settings-section-divider`},[(0,e.createElementVNode)(`span`,{class:`settings-section-label`},`实验性 / 调试设置`)],-1),((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(s.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.key,class:`settings-item experimental`},[(0,e.createElementVNode)(`label`,bc,[(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.label),1),t.type===`boolean`?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`input`,{key:0,type:`checkbox`,class:`settings-checkbox`,"onUpdate:modelValue":e=>h.value[t.key]=e},null,8,xc)),[[e.vModelCheckbox,h.value[t.key]]]):t.type===`select`&&t.options?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`select`,{key:1,class:`settings-select`,"onUpdate:modelValue":e=>h.value[t.key]=e},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.options,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`option`,{key:t.value,value:t.value},(0,e.toDisplayString)(t.label),9,Cc))),128))],8,Sc)),[[e.vModelSelect,h.value[t.key]]]):(0,e.createCommentVNode)(``,!0)])]))),128))],64)):(0,e.createCommentVNode)(``,!0)]),(0,e.createElementVNode)(`div`,{class:`settings-footer`},[(0,e.createElementVNode)(`button`,{class:`settings-btn reset`,onClick:S},[...r[29]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}),(0,e.createElementVNode)(`path`,{d:`M3 3v5h5`})],-1),(0,e.createTextVNode)(` 重置 `,-1)]]),(0,e.createElementVNode)(`div`,{class:`footer-right`},[(0,e.createElementVNode)(`button`,{class:`settings-btn cancel`,onClick:x},`取消`),(0,e.createElementVNode)(`button`,{class:`settings-btn confirm`,onClick:C},[...r[30]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`},[(0,e.createElementVNode)(`path`,{d:`M20 6L9 17l-5-5`})],-1),(0,e.createTextVNode)(` 确定 `,-1)]])])])])]),_:1})])):(0,e.createCommentVNode)(``,!0)]),_:1})],8,[`to`]))],64))}}),[[`__scopeId`,`data-v-20a39cb3`]]),Tc={class:`chart-wrapper`},Ec={class:`pane-separator-layer`,"aria-hidden":`true`},Dc=4,Oc=Lt((0,e.defineComponent)({__name:`KLineChart`,props:{semanticConfig:{},yPaddingPx:{default:0},minKWidth:{default:1},maxKWidth:{default:50},rightAxisWidth:{default:0},bottomAxisHeight:{default:24},priceLabelWidth:{default:60},zoomLevels:{default:20},initialZoomLevel:{default:3},isFullscreen:{type:Boolean,default:!1}},emits:[`zoomLevelChange`,`toggleFullscreen`],setup(t,{expose:n,emit:r}){let i=t,a=r,o=(0,e.ref)(null),s=(0,e.ref)(null),c=(0,e.ref)(null),l=(0,e.ref)(null),u=(0,e.ref)(null),d=(0,e.ref)(null),f=(0,e.ref)(null),p=(0,e.shallowRef)(null),m=(0,e.shallowRef)(null),h=ir({initialZoomLevel:i.initialZoomLevel??1,minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevels:i.zoomLevels,rightAxisWidth:i.rightAxisWidth,priceLabelWidth:i.priceLabelWidth});h.actions.setZoomState(h.state.zoomLevel,La(h.state.zoomLevel,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:h.state.viewportDpr}),Ra(La(h.state.zoomLevel,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:h.state.viewportDpr}),h.state.viewportDpr)),(0,e.computed)(()=>h.state.dataLength),(0,e.computed)(()=>h.state.viewportDpr);let g=(0,e.computed)(()=>h.state.zoomLevel),_=(0,e.computed)(()=>h.state.kWidth),v=(0,e.computed)(()=>h.state.kGap),y=(0,e.computed)(()=>h.state.paneRatios),b=(0,e.computed)(()=>h.state.selectedDrawingId),x=(0,e.computed)(()=>h.state.dataVersion);function S(){p.value?.scheduleDraw()}function C(e){if(p.value?.updateSettings(e),e.performanceTest10kKlines){let e=w();console.time(`updateData-10k`),p.value?.updateData(e),console.timeEnd(`updateData-10k`),h.actions.setDataLength(e.length),h.actions.bumpDataVersion()}else m.value&&p.value?.getData()?.length===1e4&&m.value.applyConfig(i.semanticConfig)}function w(){let e=[],t=new Date(`2020-01-01`).getTime(),n=3e3;for(let r=0;r<1e4;r++){let i=t+r*864e5,a=(Math.random()-.5)*2*.02+1e-4,o=n,s=o*(1+a),c=Math.max(o,s)*(1+Math.random()*.01),l=Math.min(o,s)*(1-Math.random()*.01),u=Math.floor(1e6+Math.random()*5e6);e.push({timestamp:i,open:parseFloat(o.toFixed(2)),high:parseFloat(c.toFixed(2)),low:parseFloat(l.toFixed(2)),close:parseFloat(s.toFixed(2)),volume:u}),n=s}return e}function T(e,t,n){let r=e.getBoundingClientRect();return{width:Math.max(t,Math.round(r.width)),height:Math.max(n,Math.round(r.height))}}function E(t){t&&(0,e.nextTick)(()=>{if(!t.isConnected)return;let e=T(t,180,80);p.value?.interaction.setTooltipSize(e)})}function D(t){t&&(0,e.nextTick)(()=>{t.isConnected&&(te.value=T(t,120,60))})}let O=(0,e.ref)({x:0,y:0}),k=(0,e.ref)(!1),A=null;function M(){A=null}function N(e){return A||=e.getBoundingClientRect(),A}let P=(0,e.shallowRef)({crosshairPos:null,crosshairIndex:null,crosshairPrice:null,hoveredIndex:null,activePaneId:null,tooltipPos:{x:0,y:0},tooltipAnchorPlacement:`right-bottom`,hoveredMarkerData:null,hoveredCustomMarker:null,isDragging:!1,isResizingPaneBoundary:!1,isHoveringPaneBoundary:!1,hoveredPaneBoundaryId:null,isHoveringRightAxis:!1}),F=(0,e.shallowRef)(null),I=(0,e.computed)(()=>{let e=b.value;return e?h.state.drawings.find(t=>t.id===e)??null:null}),ee=(0,e.ref)([]),te=(0,e.ref)({width:220,height:120}),ne=(0,e.computed)(()=>{let e=l.value,t=u.value;return!e||!t?{x:0,y:0}:{x:e.offsetLeft,y:e.offsetTop}}),re=(0,e.computed)(()=>P.value.hoveredMarkerData),ie=(0,e.computed)(()=>P.value.hoveredCustomMarker),ae=(0,e.computed)(()=>P.value.isDragging),oe=(0,e.computed)(()=>P.value.isResizingPaneBoundary),se=(0,e.computed)(()=>P.value.isHoveringPaneBoundary),ce=(0,e.computed)(()=>P.value.hoveredPaneBoundaryId),le=(0,e.computed)(()=>P.value.isHoveringRightAxis),ue=(0,e.computed)(()=>P.value.hoveredIndex),de=(0,e.computed)(()=>P.value.crosshairIndex),L=(0,e.computed)(()=>ae.value?`grabbing`:oe.value||se.value?`ns-resize`:ue.value===null?`crosshair`:`pointer`),fe=(0,e.computed)(()=>{let e=P.value.hoveredIndex;if(typeof e!=`number`)return null;x.value;let t=p.value?.getData();return t&&e>=0&&e<t.length?t[e]:null}),pe=(0,e.computed)(()=>P.value.hoveredIndex),me=(0,e.computed)(()=>P.value.tooltipPos),he=(0,e.computed)(()=>({x:me.value.x+ne.value.x,y:me.value.y+ne.value.y})),ge=(0,e.computed)(()=>({left:`${he.value.x}px`,top:`${he.value.y}px`})),_e=(0,e.computed)(()=>({x:O.value.x+ne.value.x,y:O.value.y+ne.value.y})),ve=(0,e.computed)(()=>({left:`${_e.value.x}px`,top:`${_e.value.y}px`})),ye=(0,e.computed)(()=>P.value.tooltipAnchorPlacement),be=(0,e.computed)(()=>{let e=p.value?.getViewport(),t=l.value,n=e?.plotWidth??(t?t.clientWidth:0);return O.value.x+12+te.value.width+12>n?`left-bottom`:`right-bottom`}),xe=(0,e.computed)(()=>(x.value,p.value?.getData()??[]));function Se(e){F.value?.setTool(e)}function z(e){let t=I.value;!t||!F.value||(F.value.updateDrawingStyle(t.id,e),h.actions.bumpDrawingVersion())}function Ce(){let e=I.value;!e||!F.value||(F.value.removeDrawing(e.id),h.actions.setSelectedDrawingId(null),h.actions.bumpDrawingVersion(),h.actions.setDrawings(F.value.getDrawings()))}function we(e){let t=l.value;if(t){if(F.value?.onPointerDown(e,t)){h.actions.setDrawings(F.value.getDrawings()),h.actions.bumpDrawingVersion();return}p.value?.interaction.onPointerDown(e)}}function Te(e){let t=l.value;if(t){let n=N(t);if(O.value={x:e.clientX-n.left,y:e.clientY-n.top},F.value?.onPointerMove(e,t)){h.actions.setDrawings(F.value.getDrawings());return}}p.value?.interaction.onPointerMove(e)}function Ee(e){let t=l.value;if(t&&F.value?.onPointerUp(e,t)){h.actions.setDrawings(F.value.getDrawings());return}p.value?.interaction.onPointerUp(e)}function B(e){p.value?.interaction.onPointerLeave(e)}function De(e){p.value?.interaction.onRightAxisPointerDown(e)}function Oe(e){p.value?.interaction.onRightAxisPointerMove(e)}function ke(e){p.value?.interaction.onRightAxisPointerUp(e)}function Ae(e){p.value?.interaction.onRightAxisPointerLeave(e)}function je(){p.value?.interaction.onScroll()}let V=(0,e.ref)([]),Me=(0,e.ref)({}),H=(0,e.ref)([]),Ne={VOLUME:{defaultParams:{},getTitleInfo:()=>({name:`VOL`,params:[],values:[]})},MACD:{defaultParams:{fastPeriod:12,slowPeriod:26,signalPeriod:9},getTitleInfo:(e,t,n)=>t===null||!p.value?null:Hi(t,n.fastPeriod??12,n.slowPeriod??26,n.signalPeriod??9,p.value.plugin,`sub_MACD`)},RSI:{defaultParams:{period1:6,period2:12,period3:24},getTitleInfo:(e,t,n)=>t===null?null:Gi(t,n.period1??6,n.period2??12,n.period3??24,p.value.plugin,`sub_RSI`)},CCI:{defaultParams:{period:14,showCCI:!0},getTitleInfo:(e,t,n)=>t===null?null:Ji(t,n.period??14,p.value.plugin,`sub_CCI`)},STOCH:{defaultParams:{n:9,m:3,showK:!0,showD:!0},getTitleInfo:(e,t,n)=>t===null?null:Zi(t,n.n??9,n.m??3,p.value.plugin,`sub_STOCH`)},MOM:{defaultParams:{period:10,showMOM:!0},getTitleInfo:(e,t,n)=>t===null?null:ea(t,n.period??10,p.value.plugin,`sub_MOM`)},WMSR:{defaultParams:{period:14,showWMSR:!0},getTitleInfo:(e,t,n)=>t===null?null:ra(t,n.period??14,p.value.plugin,`sub_WMSR`)},KST:{defaultParams:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},getTitleInfo:(e,t,n)=>t===null?null:oa(t,n.roc1??10,n.roc2??15,n.roc3??20,n.roc4??30,n.signalPeriod??9,p.value.plugin,`sub_KST`)},FASTK:{defaultParams:{period:9,showFASTK:!0},getTitleInfo:(e,t,n)=>t===null?null:la(t,n.period??9,p.value.plugin,`sub_FASTK`)}},U=Object.keys(Ne);function W(){let e=y.value.main??3;return H.value.length===0?[{id:`main`,ratio:e,visible:!0,role:`price`}]:[{id:`main`,ratio:e,visible:!0,role:`price`},...H.value.map(e=>({id:e.id,ratio:y.value[e.id]??1,visible:!0,role:`indicator`}))]}function G(e){return{...Ne[e].defaultParams}}function K(e=`VOLUME`,t){if(H.value.length>=Dc)return!1;let n=`sub_${e}`;if(H.value.some(e=>e.id===n))return!0;if(!p.value?.createSubPane(e,t??G(e)))return!1;e===`MACD`&&p.value?.getIndicatorScheduler().updateMACDConfig(t??G(e),n),e===`RSI`&&p.value?.getIndicatorScheduler().updateRSIConfig(t??G(e),n),e===`CCI`&&p.value?.getIndicatorScheduler().updateCCIConfig(t??G(e),n),e===`STOCH`&&p.value?.getIndicatorScheduler().updateSTOCHConfig(t??G(e),n),e===`MOM`&&p.value?.getIndicatorScheduler().updateMOMConfig(t??G(e),n),e===`WMSR`&&p.value?.getIndicatorScheduler().updateWMSRConfig(t??G(e),n),e===`KST`&&p.value?.getIndicatorScheduler().updateKSTConfig(t??G(e),n),e===`FASTK`&&p.value?.getIndicatorScheduler().updateFASTKConfig(t??G(e),n);let r=Go({paneId:n,title:e,getTitleInfo:()=>Re(n)});return p.value?.useRenderer(r),H.value.push({id:n,indicatorId:e,rendererName:`${e.toLowerCase()}_${n}`,paneTitleRendererName:r.name,params:t??G(e)}),V.value.includes(e)||V.value.push(e),S(),!0}function q(e){let t=H.value.findIndex(t=>t.id===e);if(t===-1)return;let n=H.value[t];n&&(p.value?.removeRenderer(n.paneTitleRendererName),p.value?.removeSubPane(n.indicatorId),H.value.splice(t,1),H.value.some(e=>e.indicatorId===n.indicatorId)||(V.value=V.value.filter(e=>e!==n.indicatorId)))}function Pe(){for(let e of H.value)p.value?.removeRenderer(e.paneTitleRendererName);p.value?.clearSubPanes(),H.value=[],V.value=V.value.filter(e=>!U.includes(e))}function J(){let e=i.semanticConfig,t=p.value;if(!t)return;let n=e.indicators?.main;if(n)for(let e of n)e.enabled&&(V.value.includes(e.type)||V.value.push(e.type),e.params&&(Me.value[e.type]=e.params),t.enableMainIndicator(e.type,e.params))}(0,e.watch)([V,Me],([e])=>{let t=p.value;t&&(t.updateRendererConfig(`mainIndicatorLegend`,{indicators:{MA:{enabled:e.includes(`MA`),params:Me.value.MA||{}},BOLL:{enabled:e.includes(`BOLL`),params:Me.value.BOLL||{}},EXPMA:{enabled:e.includes(`EXPMA`),params:Me.value.EXPMA||{}},ENE:{enabled:e.includes(`ENE`),params:Me.value.ENE||{}}}}),S())},{deep:!0});function Fe(){let e=p.value?.getSubPaneIndicators()??[];H.value=[];for(let t of e){let e=`sub_${t}`,n=Go({paneId:e,title:t,getTitleInfo:()=>Re(e)});p.value?.useRenderer(n),H.value.push({id:e,indicatorId:t,rendererName:`${t.toLowerCase()}_${e}`,paneTitleRendererName:n.name,params:G(t)}),V.value.includes(t)||V.value.push(t)}S()}function Ie(e,t){let n=H.value.find(t=>t.id===e);if(!n)return;let r=n.indicatorId;p.value?.removeRenderer(n.paneTitleRendererName),p.value?.removeSubPane(r),p.value?.createSubPane(t,G(t));let i=`sub_${t}`,a=Go({paneId:i,title:t,getTitleInfo:()=>Re(i)});p.value?.useRenderer(a);let o=H.value.findIndex(t=>t.id===e);o!==-1&&(H.value[o]={id:i,indicatorId:t,rendererName:`${t.toLowerCase()}_${i}`,paneTitleRendererName:a.name,params:G(t)}),V.value=V.value.filter(e=>e!==r),V.value.includes(t)||V.value.push(t)}let Le=new Map;function Re(e){let t=H.value.find(t=>t.id===e);if(!t)return null;let n=p.value?.getData();if(!n||n.length===0)return null;let r=de.value,i=n.length,a=Le.get(e);if(a&&a.idx===r&&a.dataLen===i)return a.result;let o=Ne[t.indicatorId],s=t.params,c=o.getTitleInfo(n,r,s);return Le.set(e,{idx:r,dataLen:i,result:c}),c}function Y(e,t){let n=p.value;if(n){if(e===`MA`||e===`BOLL`||e===`EXPMA`||e===`ENE`){n.toggleMainIndicator(e,t),t?V.value.includes(e)||V.value.push(e):V.value=V.value.filter(t=>t!==e);return}if(U.includes(e)){if(t){if(V.value.includes(e)||V.value.push(e),H.value.find(t=>t.indicatorId===e))return;if(!K(e)){let t=H.value[H.value.length-1];t&&Ie(t.id,e)}}else V.value=V.value.filter(t=>t!==e),H.value.filter(t=>t.indicatorId===e).forEach(e=>q(e.id));S()}}}function ze(e,t){if(Me.value[e]=t,e===`MA`||e===`BOLL`||e===`EXPMA`||e===`ENE`){p.value?.updateMainIndicatorParams(e,t),S();return}if(e===`MACD`){p.value?.getIndicatorScheduler().updateMACDConfig(t,`sub_MACD`),H.value.filter(e=>e.indicatorId===`MACD`).forEach(e=>{e.params={...t}}),S();return}if(e===`RSI`){p.value?.getIndicatorScheduler().updateRSIConfig(t,`sub_RSI`),H.value.filter(e=>e.indicatorId===`RSI`).forEach(e=>{e.params={...t}}),S();return}if(e===`CCI`){p.value?.getIndicatorScheduler().updateCCIConfig(t,`sub_CCI`),H.value.filter(e=>e.indicatorId===`CCI`).forEach(e=>{e.params={...t}}),S();return}if(e===`STOCH`){p.value?.getIndicatorScheduler().updateSTOCHConfig(t,`sub_STOCH`),H.value.filter(e=>e.indicatorId===`STOCH`).forEach(e=>{e.params={...t}}),S();return}if(e===`MOM`){p.value?.getIndicatorScheduler().updateMOMConfig(t,`sub_MOM`),H.value.filter(e=>e.indicatorId===`MOM`).forEach(e=>{e.params={...t}}),S();return}if(e===`WMSR`){p.value?.getIndicatorScheduler().updateWMSRConfig(t,`sub_WMSR`),H.value.filter(e=>e.indicatorId===`WMSR`).forEach(e=>{e.params={...t}}),S();return}if(e===`KST`){p.value?.getIndicatorScheduler().updateKSTConfig(t,`sub_KST`),H.value.filter(e=>e.indicatorId===`KST`).forEach(e=>{e.params={...t}}),S();return}if(e===`FASTK`){p.value?.getIndicatorScheduler().updateFASTKConfig(t,`sub_FASTK`),H.value.filter(e=>e.indicatorId===`FASTK`).forEach(e=>{e.params={...t}}),S();return}U.includes(e)&&H.value.filter(t=>t.indicatorId===e).forEach(e=>{e.params={...t},p.value?.updateRendererConfig(e.rendererName,t)}),S()}function X(e){if(!e.length||H.value.length<=1)return;let t=e.filter(e=>U.includes(e));if(!t.length)return;let n=new Map(H.value.map(e=>[e.indicatorId,e])),r=[];for(let e of t){let t=n.get(e);t&&(r.push(t),n.delete(e))}if(r.length===0)return;for(let e of H.value)n.has(e.indicatorId)&&(r.push(e),n.delete(e.indicatorId));let i=H.value.map(e=>e.id),a=r.map(e=>e.id);if(i.join(`|`)===a.join(`|`))return;H.value=r;let o=V.value.filter(e=>!U.includes(e)),s=H.value.map(e=>e.indicatorId);V.value=[...o,...s];let c=p.value;c&&c.updatePaneLayout(W())}let Z=(0,e.computed)(()=>i.rightAxisWidth+i.priceLabelWidth),Be=h.computed.totalWidth;function Ve(){let e=l.value,t=p.value;if(!e||!t)return;let n=t.getData()?.length??0;if(n===0)return;let r=t.getCurrentDpr(),{unitPx:i,startXPx:a}=R(_.value,v.value,r),o=(a+n*i)/r,s=Math.max(0,e.scrollWidth-e.clientWidth),c=Math.min(s,Math.max(0,o-e.clientWidth));e.scrollLeft=Math.round(c*r)/r,S()}function He(t,n){let r=p.value,o=l.value;if(!r||!o)return;let s=r.getCurrentDpr(),c=Ba(t,n??(r.getViewport()?.plotWidth??o.clientWidth)/2,o.scrollLeft,g.value,_.value,v.value,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:s});c&&(h.actions.setZoomState(c.targetLevel,c.newKWidth,c.newKGap),r.interaction.clearHover(),(0,e.nextTick)(()=>{let e=l.value;if(!e)return;let t=Math.max(0,e.scrollWidth-e.clientWidth),n=Math.min(Math.max(0,c.newScrollLeft),t);e.scrollLeft=Math.round(n*s)/s,r.applyRenderState(c.newKWidth,c.newKGap,c.targetLevel),a(`zoomLevelChange`,c.targetLevel,c.newKWidth)}))}n({scheduleRender:S,scrollToRight:Ve,addSubPane:K,removeSubPane:q,switchSubIndicator:Ie,clearAllSubPanes:Pe,get plugin(){return p.value?.plugin},zoomToLevel:He,zoomIn:e=>He(g.value+1,e),zoomOut:e=>He(g.value-1,e),getZoomLevel:()=>g.value,getZoomLevelCount:()=>p.value?.getZoomLevelCount()??10});function Ue(t){let n=n=>{n.preventDefault();let r=p.value;if(!r)return;let o=t.getBoundingClientRect(),s=n.clientX-o.left,c=t.scrollLeft,u=r.getCurrentDpr(),d=za(n.deltaY>0?-1:1,s,c,g.value,_.value,v.value,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:u});d&&(h.actions.setZoomState(d.targetLevel,d.newKWidth,d.newKGap),r.interaction.clearHover(),(0,e.nextTick)(()=>{let e=l.value;if(!e)return;let t=Math.max(0,e.scrollWidth-e.clientWidth),n=Math.min(Math.max(0,d.newScrollLeft),t);e.scrollLeft=Math.round(n*u)/u,r.applyRenderState(d.newKWidth,d.newKGap,d.targetLevel),a(`zoomLevelChange`,d.targetLevel,d.newKWidth)}))};return t.addEventListener(`wheel`,n,{passive:!1}),n}function We(e,t,n,r){let a=new Fa({container:e,canvasLayer:t,rightAxisLayer:n,xAxisCanvas:r},{yPaddingPx:i.yPaddingPx,rightAxisWidth:i.rightAxisWidth,bottomAxisHeight:i.bottomAxisHeight,priceLabelWidth:i.priceLabelWidth,minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,panes:[{id:`main`,ratio:1}],paneGap:0,zoomLevels:i.zoomLevels,initialZoomLevel:i.initialZoomLevel});a.useRenderer(co()),a.useRenderer(gi()),a.setRendererEnabled(`ma`,!1),a.useRenderer(Si()),a.setRendererEnabled(`boll`,!1),a.useRenderer(wi()),a.setRendererEnabled(`expma`,!1),a.useRenderer(ki()),a.setRendererEnabled(`ene`,!1),a.useRenderer(Ga()),a.useRenderer(fo()),a.useRenderer(uo()),a.useRenderer(qe());let o=i.rightAxisWidth+i.priceLabelWidth,s=()=>{let e=a.interaction.crosshairPos,t=a.interaction.crosshairPrice,n=a.interaction.activePaneId;return e&&t!==null?{y:e.y,price:t,activePaneId:n}:null};a.useRenderer(Oo({axisWidth:o,yPaddingPx:i.yPaddingPx,getCrosshair:s})),a.useRenderer(Ii({yPaddingPx:i.yPaddingPx}));let c=[{create:jo,paneId:`sub_VOLUME`},{create:ko,paneId:`sub_MACD`},{create:Mo,paneId:`sub_RSI`},{create:No,paneId:`sub_CCI`},{create:Po,paneId:`sub_STOCH`},{create:Fo,paneId:`sub_MOM`},{create:Io,paneId:`sub_WMSR`},{create:Lo,paneId:`sub_KST`},{create:Ro,paneId:`sub_FASTK`}];for(let e of c)a.useRenderer(e.create({axisWidth:o,paneId:e.paneId,yPaddingPx:i.yPaddingPx,getCrosshair:s}));return a.useRenderer(Vo({getCrosshairState:()=>({pos:a.interaction.crosshairPos,activePaneId:a.interaction.activePaneId,isDragging:a.interaction.isDraggingState(),price:a.interaction.crosshairPrice})})),a.useRenderer(Bo({height:i.bottomAxisHeight,getCrosshair:()=>{let e=a.interaction.crosshairPos,t=a.interaction.crosshairIndex;return e&&t!==null?{x:e.x,index:t}:null}})),a}function Ge(e){e.setOnViewportChange(t=>{M(),h.state.viewportDpr!==t.dpr&&h.actions.setViewportDpr(t.dpr),h.state.viewWidth!==t.plotWidth&&h.actions.setViewWidth(t.plotWidth);let n=Ra(h.state.kWidth,t.dpr);h.state.kGap!==n&&h.actions.setZoomState(h.state.zoomLevel,h.state.kWidth,n);let r=e.getOption();(r.kWidth!==h.state.kWidth||r.kGap!==n)&&e.applyRenderState(h.state.kWidth,n,h.state.zoomLevel)}),e.setOnPaneLayoutChange(t=>{M();let n={};for(let e of t)n[e.id]=e.ratio;h.actions.setPaneRatios(n);let r=e.getPaneRenderers(),i=l.value&&parseInt(getComputedStyle(l.value).borderTopWidth)||0;ee.value=r.slice(0,-1).map(e=>{let t=e.getPane();return{id:t.id,top:t.top+t.height+i}})}),e.setOnDataChange(e=>{h.actions.setDataLength(e.length),h.actions.bumpDataVersion()})}function Ke(e){let t=f.value?.getSettings()??{showVolumePriceMarkers:!0};if(e.updateSettings(t),t.performanceTest10kKlines){let t=w();console.time(`updateData-10k`),e.updateData(t),console.timeEnd(`updateData-10k`),h.actions.setDataLength(t.length),h.actions.bumpDataVersion()}}function Je(e){F.value=new pa(e),F.value.setCallbacks({onDrawingCreated:e=>{h.actions.setDrawings([...h.state.drawings,e]),h.actions.setSelectedDrawingId(e.id)},onToolChange:()=>{},onDrawingSelected:e=>{h.actions.setSelectedDrawingId(e?.id??null)}})}function Ye(t){t.interaction.setTooltipAnchorPositioning(k.value),t.interaction.setOnInteractionChange(e=>{P.value=e}),t.interaction.setOnPinchZoom((n,r)=>{let o=l.value;if(!o||!t)return;let s=r-o.getBoundingClientRect().left,c=o.scrollLeft,u=t.getCurrentDpr(),d=za(n,s,c,g.value,_.value,v.value,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:u});d&&(h.actions.setZoomState(d.targetLevel,d.newKWidth,d.newKGap),t.interaction.clearHover(),(0,e.nextTick)(()=>{let e=l.value;if(!e)return;let n=Math.max(0,e.scrollWidth-e.clientWidth),r=Math.min(Math.max(0,d.newScrollLeft),n);e.scrollLeft=Math.round(r*u)/u,t.applyRenderState(d.newKWidth,d.newKGap,d.targetLevel),a(`zoomLevelChange`,d.targetLevel,d.newKWidth)}))}),P.value=t.interaction.getInteractionSnapshot(),h.actions.setViewportDpr(t.getCurrentDpr()),t.resize()}function Xe(t){m.value=new j(t),m.value.on(`config:error`,e=>{console.error(`Semantic config error:`,e)}),m.value.on(`config:ready`,()=>{h.actions.setDataLength(t.getData()?.length??0),h.actions.bumpDataVersion(),J(),Fe(),(0,e.nextTick)(()=>Ve())}),m.value.applyConfig(i.semanticConfig).then(e=>{e&&!e.success&&console.error(`Semantic config apply failed:`,e.errors)})}return(0,e.onMounted)(()=>{k.value=!1;let e=l.value,t=s.value,n=c.value,r=o.value;if(!e||!t||!n||!r)return;let i=Ue(e),a=We(e,t,n,r);p.value=a,Ge(a),a.applyRenderState(h.state.kWidth,h.state.kGap,h.state.zoomLevel),Ke(a),Je(a),Ye(a),Xe(a),a.__onWheel=i}),(0,e.onUnmounted)(()=>{let e=p.value;if(e){let t=e.__onWheel,n=l.value;t&&n&&n.removeEventListener(`wheel`,t),e.destroy()}p.value=null,F.value=null}),(0,e.watch)(()=>i.yPaddingPx,e=>{p.value?.updateOptions({yPaddingPx:e})}),(0,e.watch)(()=>i.semanticConfig,async(e,t)=>{if(e&&e!==t){let t=await m.value?.applyConfig(e);t&&!t.success&&console.error(`Semantic config apply failed:`,t.errors)}},{deep:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Tc,[(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`chart-stage`,{"is-dragging":ae.value,"is-resizing-pane":oe.value,"is-hovering-pane-separator":se.value,"is-hovering-right-axis":le.value,"is-hovering-kline":ue.value!==null}])},[(0,e.createVNode)(wc,{ref_key:`toolbarRef`,ref:f,"is-fullscreen":t.isFullscreen,onSelectTool:Se,onToggleFullscreen:r[0]||=e=>n.$emit(`toggleFullscreen`),onZoomIn:r[1]||=e=>He(g.value+1),onZoomOut:r[2]||=e=>He(g.value-1),onSettingsChange:C},null,8,[`is-fullscreen`]),(0,e.createElementVNode)(`div`,{class:`chart-main`,ref_key:`chartMainRef`,ref:u},[(0,e.createElementVNode)(`div`,Ec,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(ee.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.id,class:(0,e.normalizeClass)([`pane-separator-line`,{"is-active":ce.value===t.id}]),style:(0,e.normalizeStyle)({top:`${t.top}px`})},null,6))),128))]),(0,e.createElementVNode)(`div`,{ref_key:`tooltipLayerRef`,ref:d,class:`tooltip-layer`},null,512),(0,e.createElementVNode)(`div`,{class:`chart-container`,style:(0,e.normalizeStyle)({cursor:L.value}),ref_key:`containerRef`,ref:l,onScrollPassive:je,onPointerdown:we,onPointermove:Te,onPointerup:Ee,onPointerleave:B},[(0,e.createElementVNode)(`div`,{class:`scroll-content`,style:(0,e.normalizeStyle)({width:(0,e.unref)(Be)+`px`})},[(0,e.createElementVNode)(`div`,{class:`canvas-layer`,ref_key:`canvasLayerRef`,ref:s},[(0,e.createElementVNode)(`canvas`,{class:`x-axis-canvas`,ref_key:`xAxisCanvasRef`,ref:o},null,512),I.value?((0,e.openBlock)(),(0,e.createBlock)(Hn,{key:0,drawing:I.value,onUpdateStyle:z,onDelete:Ce},null,8,[`drawing`])):(0,e.createCommentVNode)(``,!0)],512)],4)],36),d.value?((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{key:0,to:d.value},[fe.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`tooltip-anchor kline-tooltip-anchor`,{"use-anchor":k.value}]),style:(0,e.normalizeStyle)(ge.value)},null,6)):(0,e.createCommentVNode)(``,!0),re.value||ie.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:1,class:(0,e.normalizeClass)([`tooltip-anchor marker-tooltip-anchor`,{"use-anchor":k.value}]),style:(0,e.normalizeStyle)(ve.value)},null,6)):(0,e.createCommentVNode)(``,!0),fe.value?((0,e.openBlock)(),(0,e.createBlock)(Rt,{key:2,k:fe.value,index:pe.value,data:xe.value,pos:he.value,"set-el":E,"use-anchor":k.value,"anchor-placement":ye.value},null,8,[`k`,`index`,`data`,`pos`,`use-anchor`,`anchor-placement`])):(0,e.createCommentVNode)(``,!0),re.value||ie.value?((0,e.openBlock)(),(0,e.createBlock)(Ut,{key:3,marker:re.value||ie.value,pos:_e.value,"use-anchor":k.value,"anchor-placement":be.value,"set-el":D},null,8,[`marker`,`pos`,`use-anchor`,`anchor-placement`])):(0,e.createCommentVNode)(``,!0)],8,[`to`])):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,{class:`right-axis-host`,ref_key:`rightAxisLayerRef`,ref:c,style:(0,e.normalizeStyle)({width:Z.value+`px`}),onPointerdown:De,onPointermove:Oe,onPointerup:ke,onPointerleave:Ae},null,36)],512)],2),(0,e.createVNode)(Pn,{"active-indicators":V.value,"indicator-params":Me.value,onToggle:Y,onUpdateParams:ze,onReorderSubIndicators:X},null,8,[`active-indicators`,`indicator-params`])]))}}),[[`__scopeId`,`data-v-6dd10e17`]]),kc={install(e){e.component(`KLineChart`,Oc)}};exports.ConfigManager=me,exports.EventBus=t,exports.GLOBAL_PANE_ID=de,exports.HookSystem=pe,exports.KLineChart=Oc,exports.KMapPlugin=kc,exports.PluginHostImpl=ge,exports.PluginRegistry=fe,exports.PluginState=le,exports.RENDERER_PRIORITY=L,exports.RendererPluginManager=Ae,exports.createPluginHost=_e,exports.wrapPaneInfo=ue;
48
+ }`,ir=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),ar=class{shared;handles=null;logicalWidth=0;logicalHeight=0;available=!1;rectCapacity=0;rectScratch=new Float32Array;region=null;constructor(e){this.shared=e,this.handles=this.initRectHandles(),this.available=this.handles!==null}isAvailable(){return this.available}getCanvas(){return this.shared.getCanvas()}setRegion(e){this.region=e}resize(e,t,n){this.logicalWidth=e,this.logicalHeight=t}clear(){!this.region||this.logicalWidth<=0||this.logicalHeight<=0||this.shared.clearRegion(this.region)}compositeTo(e,t={}){this.region&&this.shared.compositeRegionTo(e,this.region,t)}drawRectBuffer(e,t,n,r){let i=this.handles;if(!i||t===0||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let a=fr(n);if(!a)return!1;let o=t*4,s=this.shared.getGL();return!s||!this.region||!this.shared.bindRegion(this.region)?!1:(s.useProgram(i.program),s.bindVertexArray(i.vao),s.bindBuffer(s.ARRAY_BUFFER,i.rectBuffer),this.rectCapacity<o&&(this.rectCapacity=sr(o),s.bufferData(s.ARRAY_BUFFER,this.rectCapacity*Float32Array.BYTES_PER_ELEMENT,s.DYNAMIC_DRAW)),s.bufferSubData(s.ARRAY_BUFFER,0,e),a[3]===1?s.disable(s.BLEND):s.enable(s.BLEND),s.uniform2f(i.resolutionLocation,this.logicalWidth,this.logicalHeight),s.uniform1f(i.scrollXLocation,r),s.uniform4f(i.colorLocation,a[0],a[1],a[2],a[3]),s.drawArraysInstanced(s.TRIANGLES,0,6,t),s.bindVertexArray(null),!0)}drawRects(e,t,n){if(!this.handles||!e.length||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let r=e.length*4;this.rectScratch.length<r&&(this.rectScratch=new Float32Array(sr(r)));for(let t=0;t<e.length;t++){let n=e[t],r=t*4;this.rectScratch[r]=n.x,this.rectScratch[r+1]=n.y,this.rectScratch[r+2]=n.width,this.rectScratch[r+3]=n.height}return this.drawRectBuffer(this.rectScratch.subarray(0,r),e.length,t,n)}destroy(){let e=this.handles;if(!e)return;let t=this.shared.getGL();if(t){let{program:n,vao:r,unitBuffer:i,rectBuffer:a}=e;t.deleteBuffer(i),t.deleteBuffer(a),t.deleteVertexArray(r),t.deleteProgram(n)}this.handles=null,this.available=!1}initRectHandles(){let e=this.shared.getGL();if(!e)return null;let t=lr(e,e.VERTEX_SHADER,tr),n=lr(e,e.FRAGMENT_SHADER,rr);if(!t||!n)return t&&e.deleteShader(t),n&&e.deleteShader(n),null;let r=ur(e,t,n);if(e.deleteShader(t),e.deleteShader(n),!r)return null;let i=e.createVertexArray(),a=e.createBuffer(),o=e.createBuffer();if(!i||!a||!o)return i&&e.deleteVertexArray(i),a&&e.deleteBuffer(a),o&&e.deleteBuffer(o),e.deleteProgram(r),null;let s=e.getUniformLocation(r,`u_resolution`),c=e.getUniformLocation(r,`u_scrollX`),l=e.getUniformLocation(r,`u_color`);if(!s||!c||!l)return e.deleteBuffer(a),e.deleteBuffer(o),e.deleteVertexArray(i),e.deleteProgram(r),null;let u=e.getAttribLocation(r,`a_unit`),d=e.getAttribLocation(r,`a_rect`);return u<0||d<0?(e.deleteBuffer(a),e.deleteBuffer(o),e.deleteVertexArray(i),e.deleteProgram(r),null):(e.bindVertexArray(i),e.bindBuffer(e.ARRAY_BUFFER,a),e.bufferData(e.ARRAY_BUFFER,ir,e.STATIC_DRAW),e.enableVertexAttribArray(u),e.vertexAttribPointer(u,2,e.FLOAT,!1,0,0),e.vertexAttribDivisor(u,0),e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(d),e.vertexAttribPointer(d,4,e.FLOAT,!1,16,0),e.vertexAttribDivisor(d,1),e.bindVertexArray(null),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),{program:r,vao:i,unitBuffer:a,rectBuffer:o,resolutionLocation:s,scrollXLocation:c,colorLocation:l})}},or=class{shared;handles=null;logicalWidth=0;logicalHeight=0;dpr=1;available=!1;vertexCapacity=0;fillScratch=new Float32Array;lineScratch=new Float32Array;region=null;msaaTargets=null;geoCache=new WeakMap;constructor(e){this.shared=e,this.handles=this.initLineHandles(),this.available=this.handles!==null}isAvailable(){return this.available}getCanvas(){return this.shared.getCanvas()}setRegion(e){this.region=e}resize(e,t,n){this.logicalWidth=e,this.logicalHeight=t,this.dpr=n}clear(){!this.region||this.logicalWidth<=0||this.logicalHeight<=0||this.shared.clearRegion(this.region)}compositeTo(e,t={}){this.region&&this.shared.compositeRegionTo(e,this.region,t)}drawLineStrips(e,t){let n=this.handles;if(!n||e.length===0||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let r=this.shared.getGL(),i=this.region;if(!r||!i)return!1;let a=[],o=0;for(let t of e){if(t.points.length<2)return!1;let e=fr(t.color);if(!e)return!1;if(t.width===1){let{vertexCount:n,vertices:i}=this.getThinLineVertices(t.points);a.push({colorValue:e,mode:r.LINE_STRIP,firstVertex:o/2,pointCount:n}),o+=i.length}else{let n=this.getLineGeometry(t);if(!n)return!1;a.push({colorValue:e,mode:r.TRIANGLES,firstVertex:o/2,pointCount:n.vertexCount}),o+=n.vertices.length}}this.lineScratch.length<o&&(this.lineScratch=new Float32Array(sr(o)));let s=0;for(let t of e){let e=t.width===1?this.getThinLineVertices(t.points).vertices:this.getLineGeometry(t).vertices;this.lineScratch.set(e,s),s+=e.length}let c=this.shared.getPhysicalRegion(i),l=c?this.ensureLineMsaaTargets(r,c):null,u=l!==null;if(u)r.bindFramebuffer(r.FRAMEBUFFER,l.msaaFramebuffer),r.viewport(0,0,l.widthPx,l.heightPx),r.disable(r.SCISSOR_TEST),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT);else if(!this.shared.bindRegion(i))return!1;r.useProgram(n.basic.program),r.bindVertexArray(n.basic.vao),r.bindBuffer(r.ARRAY_BUFFER,n.basic.vertexBuffer),this.vertexCapacity<o&&(this.vertexCapacity=sr(o),r.bufferData(r.ARRAY_BUFFER,this.vertexCapacity*Float32Array.BYTES_PER_ELEMENT,r.DYNAMIC_DRAW)),r.bufferSubData(r.ARRAY_BUFFER,0,this.lineScratch.subarray(0,o)),r.uniform2f(n.basic.resolutionLocation,this.logicalWidth,this.logicalHeight),r.uniform1f(n.basic.scrollXLocation,t);for(let e of a)r.uniform4f(n.basic.colorLocation,e.colorValue[0],e.colorValue[1],e.colorValue[2],e.colorValue[3]),r.drawArrays(e.mode,e.firstVertex,e.pointCount);return r.bindVertexArray(null),u&&l&&c&&this.resolveLineMsaaToSharedRegion(r,l,c),r.bindFramebuffer(r.FRAMEBUFFER,null),!0}getThinLineVertices(e){let t=this.geoCache.get(e);if(t){let e=t.get(0);if(e)return e}else t=new Map,this.geoCache.set(e,t);let n=e.length,r=new Float32Array(n*2),i=0;for(let t of e)r[i++]=t.x,r[i++]=t.y;let a={vertices:r,vertexCount:n};return t.set(0,a),a}getLineGeometry(e){let t=e.width/2,n=this.geoCache.get(e.points);if(n){let e=n.get(t);if(e)return e}else n=new Map,this.geoCache.set(e.points,n);let r=cr(e.points,t);return r&&n.set(t,r),r}drawFilledBand(e,t,n){let r=this.handles,i=Math.min(e.upperPoints.length,e.lowerPoints.length);if(!r||i<2||this.logicalWidth<=0||this.logicalHeight<=0)return!1;let a=fr(t);if(!a)return!1;let o=i*2,s=o*2;this.fillScratch.length<s&&(this.fillScratch=new Float32Array(sr(s)));let c=0;for(let t=0;t<i;t++){let n=e.upperPoints[t],r=e.lowerPoints[t];this.fillScratch[c++]=n.x,this.fillScratch[c++]=n.y,this.fillScratch[c++]=r.x,this.fillScratch[c++]=r.y}let l=this.shared.getGL();return!l||!this.region||!this.shared.bindRegion(this.region)?!1:(l.useProgram(r.basic.program),l.bindVertexArray(r.basic.vao),l.bindBuffer(l.ARRAY_BUFFER,r.basic.vertexBuffer),this.vertexCapacity<s&&(this.vertexCapacity=sr(s),l.bufferData(l.ARRAY_BUFFER,this.vertexCapacity*Float32Array.BYTES_PER_ELEMENT,l.DYNAMIC_DRAW)),l.bufferSubData(l.ARRAY_BUFFER,0,this.fillScratch.subarray(0,s)),l.uniform2f(r.basic.resolutionLocation,this.logicalWidth,this.logicalHeight),l.uniform1f(r.basic.scrollXLocation,n),l.uniform4f(r.basic.colorLocation,a[0],a[1],a[2],a[3]),l.drawArrays(l.TRIANGLE_STRIP,0,o),l.bindVertexArray(null),!0)}destroy(){let e=this.handles,t=this.shared.getGL();if(t&&this.destroyLineMsaaTargets(t),!e){this.vertexCapacity=0;return}if(t){let{basic:n}=e;t.deleteBuffer(n.vertexBuffer),t.deleteVertexArray(n.vao),t.deleteProgram(n.program)}this.handles=null,this.available=!1,this.vertexCapacity=0}ensureLineMsaaTargets(e,t){let n=Number(e.getParameter(e.MAX_SAMPLES))||0,r=Math.max(1,Math.min(4,n));if(r<=1)return null;let i=this.msaaTargets;if(i&&i.widthPx===t.widthPx&&i.heightPx===t.heightPx&&i.samples===r)return i;this.destroyLineMsaaTargets(e);let a=e.createFramebuffer(),o=e.createRenderbuffer(),s=e.createFramebuffer(),c=e.createTexture();if(!a||!o||!s||!c)return a&&e.deleteFramebuffer(a),o&&e.deleteRenderbuffer(o),s&&e.deleteFramebuffer(s),c&&e.deleteTexture(c),null;if(e.bindFramebuffer(e.FRAMEBUFFER,a),e.bindRenderbuffer(e.RENDERBUFFER,o),e.renderbufferStorageMultisample(e.RENDERBUFFER,r,e.RGBA8,t.widthPx,t.heightPx),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.RENDERBUFFER,o),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.deleteFramebuffer(a),e.deleteRenderbuffer(o),e.deleteFramebuffer(s),e.deleteTexture(c),null;if(e.bindFramebuffer(e.FRAMEBUFFER,s),e.bindTexture(e.TEXTURE_2D,c),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t.widthPx,t.heightPx,0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,c,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.deleteFramebuffer(a),e.deleteRenderbuffer(o),e.deleteFramebuffer(s),e.deleteTexture(c),null;e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),e.bindRenderbuffer(e.RENDERBUFFER,null);let l={samples:r,widthPx:t.widthPx,heightPx:t.heightPx,msaaFramebuffer:a,msaaColorRenderbuffer:o,resolveFramebuffer:s,resolveTexture:c};return this.msaaTargets=l,l}destroyLineMsaaTargets(e){let t=this.msaaTargets;t&&(e.deleteFramebuffer(t.msaaFramebuffer),e.deleteRenderbuffer(t.msaaColorRenderbuffer),e.deleteFramebuffer(t.resolveFramebuffer),e.deleteTexture(t.resolveTexture),this.msaaTargets=null)}resolveLineMsaaToSharedRegion(e,t,n){e.bindFramebuffer(e.READ_FRAMEBUFFER,t.msaaFramebuffer),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,t.resolveFramebuffer),e.blitFramebuffer(0,0,t.widthPx,t.heightPx,0,0,t.widthPx,t.heightPx,e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.READ_FRAMEBUFFER,t.resolveFramebuffer),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null);let r=this.shared.getCanvas().height-n.sourceY-n.heightPx;e.disable(e.SCISSOR_TEST),e.blitFramebuffer(0,0,t.widthPx,t.heightPx,n.sourceX,r,n.sourceX+n.widthPx,r+n.heightPx,e.COLOR_BUFFER_BIT,e.NEAREST),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null)}initLineHandles(){let e=this.shared.getGL();if(!e)return null;let t=lr(e,e.VERTEX_SHADER,nr),n=lr(e,e.FRAGMENT_SHADER,rr);if(!t||!n)return t&&e.deleteShader(t),n&&e.deleteShader(n),null;let r=ur(e,t,n);if(e.deleteShader(t),e.deleteShader(n),!r)return null;let i=e.createVertexArray(),a=e.createBuffer();if(!i||!a)return i&&e.deleteVertexArray(i),a&&e.deleteBuffer(a),e.deleteProgram(r),null;let o=e.getUniformLocation(r,`u_resolution`),s=e.getUniformLocation(r,`u_scrollX`),c=e.getUniformLocation(r,`u_color`);if(!o||!s||!c)return e.deleteBuffer(a),e.deleteVertexArray(i),e.deleteProgram(r),null;let l=e.getAttribLocation(r,`a_position`);return l<0?(e.deleteBuffer(a),e.deleteVertexArray(i),e.deleteProgram(r),null):(e.bindVertexArray(i),e.bindBuffer(e.ARRAY_BUFFER,a),e.enableVertexAttribArray(l),e.vertexAttribPointer(l,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),{basic:{program:r,vao:i,vertexBuffer:a,resolutionLocation:o,scrollXLocation:s,colorLocation:c}})}};function sr(e){let t=1;for(;t<e;)t<<=1;return t}function cr(e,t){if(e.length<2)return null;let n=Array(e.length-1),r=0;for(let t=0;t<e.length-1;t++){let i=e[t],a=e[t+1],o=a.x-i.x,s=a.y-i.y,c=o*o+s*s;if(c<=0){n[t]={nx:0,ny:0,valid:!1};continue}let l=1/Math.sqrt(c);n[t]={nx:-s*l,ny:o*l,valid:!0},r++}if(r===0)return null;let i=(e.length-1)*12,a=new Float32Array(i),o=0;for(let r=0;r<e.length-1;r++){let i=e[r],s=e[r+1],c=r>0?n[r-1]:null,l=n[r];if(!l.valid||!c&&!l.valid)continue;let u=0,d=0;if(c?.valid&&l.valid){u=c.nx+l.nx,d=c.ny+l.ny;let e=u*u+d*d;if(e>1e-12){let t=1/Math.sqrt(e);u*=t,d*=t;let n=u*l.nx+d*l.ny,r=1/Math.max(.2,Math.abs(n));u*=r,d*=r}else u=l.nx,d=l.ny}else if(l.valid)u=l.nx,d=l.ny;else if(c?.valid)u=c.nx,d=c.ny;else continue;let f=l.nx,p=l.ny,m=r<e.length-2?n[r+1]:null;if(m?.valid&&l.valid){f=l.nx+m.nx,p=l.ny+m.ny;let e=f*f+p*p;if(e>1e-12){let t=1/Math.sqrt(e);f*=t,p*=t;let n=f*m.nx+p*m.ny,r=1/Math.max(.2,Math.abs(n));f*=r,p*=r}else f=l.nx,p=l.ny}let h=i.x+u*t,g=i.y+d*t,_=i.x-u*t,v=i.y-d*t,y=s.x+f*t,b=s.y+p*t,x=s.x-f*t,S=s.y-p*t;a[o++]=h,a[o++]=g,a[o++]=_,a[o++]=v,a[o++]=y,a[o++]=b,a[o++]=y,a[o++]=b,a[o++]=_,a[o++]=v,a[o++]=x,a[o++]=S}return o===0?null:{vertices:o===i?a:a.subarray(0,o),vertexCount:o/2}}function lr(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(e.deleteShader(r),null)):null}function ur(e,t,n){let r=e.createProgram();return r?(e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(e.deleteProgram(r),null)):null}var dr=new Map;function fr(e){let t=dr.get(e);if(t)return t;let n=e.trim().toLowerCase(),r=null;if(n.startsWith(`rgba(`)){let e=n.slice(5,-1).split(`,`).map(e=>Number(e.trim()));e.length===4&&e.every(e=>Number.isFinite(e))&&(r=[e[0]/255,e[1]/255,e[2]/255,e[3]])}else if(n.startsWith(`rgb(`)){let e=n.slice(4,-1).split(`,`).map(e=>Number(e.trim()));e.length===3&&e.every(e=>Number.isFinite(e))&&(r=[e[0]/255,e[1]/255,e[2]/255,1])}else if(n.startsWith(`#`)){let e=n.slice(1);e.length===6?r=[Number.parseInt(e.slice(0,2),16)/255,Number.parseInt(e.slice(2,4),16)/255,Number.parseInt(e.slice(4,6),16)/255,1]:e.length===3&&(r=[Number.parseInt(e[0]+e[0],16)/255,Number.parseInt(e[1]+e[1],16)/255,Number.parseInt(e[2]+e[2],16)/255,1])}return r&&dr.set(e,r),r}var pr=class{dom;pane;opt;contexts=null;webgl;constructor(e,t,n,r){this.dom=e,this.pane=t,this.opt={...n,priceLabelWidth:n.priceLabelWidth||60},this.webgl={candleSurface:new ar(r),lineSurface:new or(r)}}getPane(){return this.pane}getDom(){return this.dom}getContexts(){return this.contexts||={mainCtx:this.dom.mainCanvas.getContext(`2d`),overlayCtx:this.dom.overlayCanvas.getContext(`2d`),yAxisCtx:this.dom.yAxisCanvas.getContext(`2d`)},this.contexts}getWebGL(){return this.webgl}setWebGLRegion(e){this.webgl.candleSurface?.setRegion(e),this.webgl.lineSurface?.setRegion(e)}resize(e,t,n){let r=this.dom.mainCanvas,i=this.dom.overlayCanvas,a=this.dom.yAxisCanvas,o=this.opt.rightAxisWidth+(this.opt.priceLabelWidth||60),s=a.parentElement?.clientWidth??0,c=s>0?s:o,l=Math.round(e*n);r.width!==l&&(r.width=l);let u=Math.round(t*n);r.height!==u&&(r.height=u);let d=`${l/n}px`;r.style.width!==d&&(r.style.width=d);let f=`${u/n}px`;r.style.height!==f&&(r.style.height=f),i.width!==l&&(i.width=l),i.height!==u&&(i.height=u),i.style.width!==d&&(i.style.width=d),i.style.height!==f&&(i.style.height=f);let p=Math.round(c*n);a.width!==p&&(a.width=p);let m=Math.round(t*n);a.height!==m&&(a.height=m);let h=`${p/n}px`;a.style.width!==h&&(a.style.width=h);let g=`${m/n}px`;a.style.height!==g&&(a.style.height=g),this.webgl.candleSurface?.resize(e,t,n),this.webgl.lineSurface?.resize(e,t,n)}destroy(){this.contexts=null,this.webgl.candleSurface?.destroy(),this.webgl.lineSurface?.destroy()}};function mr(e){let{dataLength:t,kWidth:n,kGap:r,viewWidth:i,viewportDpr:a}=e;if(t===0)return 0;let{startXPx:o,unitPx:s}=B(n,r,a),c=(o+(t+24)*s)/a;return Math.max(c,i)}function hr(t){let n=(0,e.reactive)({zoomLevel:t.initialZoomLevel,kWidth:0,kGap:1,viewportDpr:1,dataLength:0,dataVersion:0,paneRatios:{},drawings:[],selectedDrawingId:null,drawingVersion:0,viewWidth:0}),r=(0,e.computed)(()=>t.rightAxisWidth+t.priceLabelWidth),i=(0,e.computed)(()=>mr({dataLength:n.dataLength,kWidth:n.kWidth,kGap:n.kGap,viewWidth:n.viewWidth,viewportDpr:n.viewportDpr}));function a(){n.dataVersion++}function o(){n.drawingVersion++}function s(e){n.dataLength=e}function c(e){n.viewportDpr=e}function l(e){n.viewWidth=e}function u(e,t,r){n.zoomLevel=e,n.kWidth=t,n.kGap=r}function d(e){n.paneRatios=e}function f(e){n.drawings=e,n.selectedDrawingId&&!e.some(e=>e.id===n.selectedDrawingId)&&(n.selectedDrawingId=null),n.drawingVersion++}function p(e){n.selectedDrawingId=e}return{state:n,computed:{axisHostWidth:r,totalWidth:i},actions:{bumpDataVersion:a,bumpDrawingVersion:o,setDataLength:s,setViewportDpr:c,setViewWidth:l,setZoomState:u,setPaneRatios:d,setDrawings:f,setSelectedDrawingId:p}}}var gr=[5,10,20,30,60];function _r(e,t,n){let r=Array(e.length);if(e.length<t)return r;let i=0,a=[];for(let n=0;n<t;n++){let t=e[n];if(!t)return r;let o=t.close;a.push(o),i+=o}for(let o=t-1;o<e.length;o++){let s=e[o];if(!s)continue;if(o>=t){let e=a.shift();e!==void 0&&(i-=e);let t=s.close;a.push(t),i+=t}let c=i/t,l=0;for(let e=0;e<t;e++){let t=a[e];t!==void 0&&(l+=(t-c)**2)}let u=Math.sqrt(l/t);r[o]={upper:c+n*u,middle:c,lower:c-n*u}}return r}function vr(e,t,n){let r=Array(e.length);if(e.length===0)return r;let i=2/(t+1),a=2/(n+1),o=e[0].close,s=o,c=o;r[0]={fast:s,slow:c};for(let t=1;t<e.length;t++){let n=e[t].close;s=n*i+s*(1-i),c=n*a+c*(1-a),r[t]={fast:s,slow:c}}return r}function yr(e,t,n){let r=Array(e.length);if(e.length<t)return r;let i=0;for(let n=0;n<t;n++){let t=e[n];if(!t)return r;i+=t.close}let a=i/t,o=n/100;r[t-1]={upper:a*(1+o),middle:a,lower:a*(1-o)};for(let a=t;a<e.length;a++){let o=e[a-t],s=e[a];if(!o||!s)continue;i=i-o.close+s.close;let c=i/t,l=n/100;r[a]={upper:c*(1+l),middle:c,lower:c*(1-l)}}return r}function br(e,t){let n=Array(e.length);if(e.length<t)return n;let r=0;for(let i=0;i<t;i++){let t=e[i];if(!t)return n;r+=t.close}n[t-1]=r/t;for(let i=t;i<e.length;i++){let a=e[i-t],o=e[i];!a||!o||(r=r-a.close+o.close,n[i]=r/t)}return n}function xr(e,t){let n=Array(e.length);if(e.length<t+1)return n;let r=[];for(let t=1;t<e.length;t++)r.push(e[t].close-e[t-1].close);let i=0,a=0;for(let e=0;e<t;e++){let t=r[e];t!==void 0&&(t>0?i+=t:a+=Math.abs(t))}let o=i/t,s=a/t;s===0?n[t]=100:n[t]=100-100/(1+o/s);for(let e=t;e<r.length;e++){let i=r[e];if(i!==void 0)if(i>0?(o=(o*(t-1)+i)/t,s=s*(t-1)/t):(o=o*(t-1)/t,s=(s*(t-1)+Math.abs(i))/t),s===0)n[e+1]=100;else{let t=o/s;n[e+1]=100-100/(1+t)}}return n}function Sr(e,t){let n=Array(e.length);if(e.length<t)return n;let r=[];for(let t of e)r.push((t.high+t.low+t.close)/3);let i=0;for(let e=0;e<t;e++)i+=r[e];for(let a=t-1;a<e.length;a++){a>=t&&(i=i-r[a-t]+r[a]);let e=i/t,o=0;for(let n=0;n<t;n++)o+=Math.abs(r[a-n]-e);o/=t,o===0?n[a]=0:n[a]=(r[a]-e)/(.015*o)}return n}function Cr(e,t,n){let r=Array(e.length);if(e.length<t)return r;let i=Array(e.length);for(let n=t-1;n<e.length;n++){let r=-1/0,a=1/0;for(let i=0;i<t;i++){let t=e[n-i];t&&(r=Math.max(r,t.high),a=Math.min(a,t.low))}let o=e[n].close;r===a?i[n]=50:i[n]=(o-a)/(r-a)*100}for(let a=t-1+n-1;a<e.length;a++){let e=i[a];if(e===void 0)continue;let t=0,o=0;for(let e=0;e<n;e++){let n=i[a-e];n!==void 0&&(t+=n,o++)}o===n&&(r[a]={k:e,d:t/n})}return r}function wr(e,t){let n=Array(e.length);if(e.length<t+1)return n;for(let r=t;r<e.length;r++){let i=e[r]?.close,a=e[r-t]?.close;i!==void 0&&a!==void 0&&(n[r]=i-a)}return n}function Tr(e,t){let n=Array(e.length);if(e.length<t)return n;for(let r=t-1;r<e.length;r++){let i=-1/0,a=1/0;for(let n=0;n<t;n++){let t=e[r-n];t&&(i=Math.max(i,t.high),a=Math.min(a,t.low))}let o=e[r].close;i===a?n[r]=-50:n[r]=(i-o)/(i-a)*-100}return n}function Er(e,t){let n=Array(e.length);if(e.length<t+1)return n;for(let r=t;r<e.length;r++){let i=e[r]?.close,a=e[r-t]?.close;i!==void 0&&a!==void 0&&a!==0&&(n[r]=(i-a)/a*100)}return n}function Dr(e,t){let n=Array(e.length),r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o!==void 0){if(r+=o,i++,i>t){let n=e[a-t];n!==void 0&&(r-=n,i--)}i===t&&(n[a]=r/t)}}return n}function Or(e,t,n,r,i,a){let o=Array(e.length),s=Er(e,t),c=Er(e,n),l=Er(e,r),u=Er(e,i),d=Dr(s,10),f=Dr(c,10),p=Dr(l,10),m=Dr(u,15),h=Array(e.length);for(let t=0;t<e.length;t++){let e=d[t],n=f[t],r=p[t],i=m[t];e!==void 0&&n!==void 0&&r!==void 0&&i!==void 0&&(h[t]=e*1+n*2+r*3+i*4)}let g=Dr(h,a);for(let t=0;t<e.length;t++){let e=h[t],n=g[t];e!==void 0&&n!==void 0&&(o[t]={kst:e,signal:n})}return o}function kr(e,t){let n=Array(e.length);if(e.length<t)return n;for(let r=t-1;r<e.length;r++){let i=-1/0,a=1/0;for(let n=0;n<t;n++){let t=e[r-n];t&&(i=Math.max(i,t.high),a=Math.min(a,t.low))}let o=e[r].close;i===a?n[r]=50:n[r]=(o-a)/(i-a)*100}return n}function Ar(e,t){let n=Array(e.length),r=2/(t+1);if(e.length===0)return n;n[0]=e[0].close;for(let t=1;t<e.length;t++){let i=e[t];i&&(n[t]=i.close*r+n[t-1]*(1-r))}return n}function jr(e,t){let n=Array(e.length),r=2/(t+1),i=e.findIndex(e=>e!==void 0);if(i===-1)return n;n[i]=e[i];for(let t=i+1;t<e.length;t++){let i=e[t],a=n[t-1];i===void 0||a===void 0||(n[t]=i*r+a*(1-r))}return n}function Mr(e,t,n,r){let i=Array(e.length);if(e.length<n)return i;let a=Ar(e,t),o=Ar(e,n),s=Array(e.length);for(let t=0;t<e.length;t++){let e=a[t],n=o[t];e!==void 0&&n!==void 0&&(s[t]=e-n)}let c=jr(s,r);for(let t=0;t<e.length;t++){let e=s[t],n=c[t];e!==void 0&&n!==void 0&&(i[t]={dif:e,dea:n,macd:(e-n)*2})}return i}function Nr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0)return r;if(t===1){let t=e[0];r[0]=t.high-t.low;let i=t.close;for(let t=1;t<n;t++){let n=e[t];r[t]=Math.max(n.high-n.low,Math.abs(n.high-i),Math.abs(n.low-i)),i=n.close}return r}if(n<t)return r;let i=e[0],a=i.high-i.low,o=i.close;for(let n=1;n<t;n++){let t=e[n];a+=Math.max(t.high-t.low,Math.abs(t.high-o),Math.abs(t.low-o)),o=t.close}let s=a/t;r[t-1]=s;let c=t-1;for(let i=t;i<n;i++){let n=e[i],a=Math.max(n.high-n.low,Math.abs(n.high-o),Math.abs(n.low-o));s=(c*s+a)/t,r[i]=s,o=n.close}return r}function Pr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0||n<t)return r;let i=t*(t+1)/2;for(let a=t-1;a<n;a++){let n=0,o=!0;for(let r=0;r<t;r++){let i=e[a-t+1+r];if(i===void 0){o=!1;break}n+=(r+1)*i}o&&(r[a]=n/i)}return r}function Fr(e,t){if(e.length===0||t<=0)return Array(e.length).fill(void 0);let n=Array(e.length);for(let t=0;t<e.length;t++)n[t]=e[t].close;return Pr(n,t)}function Ir(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0)return r;let i=2/(t+1),a=0;for(;a<n&&e[a]===void 0;)a++;if(a>=n)return r;let o=e[a];r[a]=o;for(let t=a+1;t<n;t++){let n=e[t];n!==void 0&&(o=n*i+o*(1-i),r[t]=o)}return r}function Lr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0)return r;let i=Array(n);for(let t=0;t<n;t++)i[t]=e[t].close;let a=Ir(i,t),o=Ir(a,t);for(let e=0;e<n;e++){let t=a[e],n=o[e];t===void 0||n===void 0||(r[e]=2*t-n)}return r}function Rr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0)return r;let i=Array(n);for(let t=0;t<n;t++)i[t]=e[t].close;let a=Ir(i,t),o=Ir(a,t),s=Ir(o,t);for(let e=0;e<n;e++){let t=a[e],n=o[e],i=s[e];t===void 0||n===void 0||i===void 0||(r[e]=3*t-3*n+i)}return r}function zr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0)return r;let i=Array(n);for(let t=0;t<n;t++)i[t]=e[t].close;let a=Math.max(1,Math.floor(t/2)),o=Math.max(1,Math.round(Math.sqrt(t))),s=Pr(i,a),c=Pr(i,t),l=Array(n).fill(void 0);for(let e=0;e<n;e++){let t=s[e],n=c[e];t===void 0||n===void 0||(l[e]=2*t-n)}return Pr(l,o)}function Br(e,t,n,r){let i=e.length,a=Array(i).fill(void 0);if(i===0||t<=0||n<=0||r<=0||i<=t)return a;let o=2/(n+1),s=2/(r+1),c=o-s,l=0;for(let n=1;n<=t;n++)l+=Math.abs(e[n].close-e[n-1].close);let u=e[t-1].close;a[t-1]=u;for(let n=t;n<i;n++){let r=e[n].close,o=e[n-t].close,d=Math.abs(r-o),f=((l>0?d/l:0)*c+s)**2;u+=f*(r-u),a[n]=u,n<i-1&&(l-=Math.abs(e[n-t+1].close-e[n-t].close),l+=Math.abs(e[n+1].close-e[n].close))}return a}var Vr=.02,Hr=.2;function Ur(e,t,n){let r=e.length,i=Array(r).fill(void 0);if(r<2||t<=0||n<=0)return i;let a=e[1].close>=e[0].close?`up`:`down`,o=a===`up`?e[0].low:e[0].high,s=a===`up`?e[0].high:e[0].low,c=t;i[0]={value:o,trend:a};for(let l=1;l<r;l++){let r=e[l];if(o+=c*(s-o),a===`up`){let t=e[l-1].low,n=l>=2?e[l-2].low:t;o=Math.min(o,t,n)}else{let t=e[l-1].high,n=l>=2?e[l-2].high:t;o=Math.max(o,t,n)}a===`up`&&r.low<o?(a=`down`,o=s,s=r.low,c=t):a===`down`&&r.high>o?(a=`up`,o=s,s=r.high,c=t):a===`up`&&r.high>s?(s=r.high,c=Math.min(c+t,n)):a===`down`&&r.low<s&&(s=r.low,c=Math.min(c+t,n)),i[l]={value:o,trend:a}}return i}function Wr(e,t,n){let r=e.length,i=Array(r).fill(void 0);if(r===0||t<=0||n<=0)return i;let a=Nr(e,t),o=`up`,s=1/0,c=-1/0;for(let t=0;t<r;t++){let r=e[t],l=a[t];if(l===void 0)continue;let u=(r.high+r.low)/2,d=u+n*l,f=u-n*l,p=t>0?e[t-1].close:r.close,m=d<s||p>s?d:s,h=f>c||p<c?f:c;o===`up`&&r.close<h?o=`down`:o===`down`&&r.close>m&&(o=`up`),i[t]={value:o===`up`?h:m,trend:o},s=m,c=h}return i}function Gr(e,t,n,r){let i=e.length,a=Array(i).fill(void 0);if(i===0||t<=0||n<=0)return a;let o=Array(i);for(let t=0;t<i;t++)o[t]=e[t].close;let s=Ir(o,t),c=Nr(e,n);for(let e=0;e<i;e++){let t=s[e],n=c[e];t===void 0||n===void 0||(a[e]={upper:t+r*n,middle:t,lower:t-r*n})}return a}function Kr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n===0||t<=0||n<t)return r;for(let i=t-1;i<n;i++){let n=-1/0,a=1/0;for(let r=0;r<t;r++){let t=e[i-r];t.high>n&&(n=t.high),t.low<a&&(a=t.low)}r[i]={upper:n,middle:(n+a)/2,lower:a}}return r}var qr=class{currentData=[];dataVersion=0;config=this.getDefaultConfig();configVersion=0;cachedSeries={};cachedBollSeries=[];cachedExpmaSeries=[];cachedEneSeries=[];cachedRsiSeries={};cachedCciSeries=[];cachedStochSeries=[];cachedMomSeries=[];cachedWmsrSeries=[];cachedKstSeries=[];cachedFastkSeries=[];cachedMacdSeries=[];cachedAtrSeries=[];cachedWmaSeries=[];cachedDemaSeries=[];cachedTemaSeries=[];cachedHmaSeries=[];cachedKamaSeries=[];cachedSarSeries=[];cachedSupertrendSeries=[];cachedKeltnerSeries=[];cachedDonchianSeries=[];dirtyData=!0;dirtyMAConfig=!0;dirtyBollConfig=!0;dirtyExpmaConfig=!0;dirtyEneConfig=!0;dirtyRsiConfig=!0;dirtyCciConfig=!0;dirtyStochConfig=!0;dirtyMomConfig=!0;dirtyWmsrConfig=!0;dirtyKstConfig=!0;dirtyFastkConfig=!0;dirtyMacdConfig=!0;dirtyAtrConfig=!0;dirtyWmaConfig=!0;dirtyDemaConfig=!0;dirtyTemaConfig=!0;dirtyHmaConfig=!0;dirtyKamaConfig=!0;dirtySarConfig=!0;dirtySupertrendConfig=!0;dirtyKeltnerConfig=!0;dirtyDonchianConfig=!0;getDefaultConfig(){return{ma:{ma5:!0,ma10:!0,ma20:!0,ma30:!0,ma60:!0},boll:{period:20,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0,showBand:!0},expma:{fastPeriod:12,slowPeriod:50},ene:{period:10,deviation:11},rsi:{period1:6,period2:12,period3:24,showRSI1:!0,showRSI2:!0,showRSI3:!0},cci:{period:14,showCCI:!0},stoch:{n:9,m:3,showK:!0,showD:!0},mom:{period:10,showMOM:!0},wmsr:{period:14,showWMSR:!0},kst:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},fastk:{period:9,showFASTK:!0},macd:{fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0},atr:{period:14,showATR:!0},wma:{period:9,showWMA:!0},dema:{period:20,showDEMA:!0},tema:{period:20,showTEMA:!0},hma:{period:9,showHMA:!0},kama:{period:10,fastPeriod:2,slowPeriod:30,showKAMA:!0},sar:{step:Vr,maxStep:Hr,showSAR:!0},supertrend:{atrPeriod:10,multiplier:3,showSuperTrend:!0},keltner:{emaPeriod:20,atrPeriod:10,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0},donchian:{period:20,showUpper:!0,showMiddle:!0,showLower:!0},rsiPaneId:`sub_RSI`,cciPaneId:`sub_CCI`,stochPaneId:`sub_STOCH`,momPaneId:`sub_MOM`,wmsrPaneId:`sub_WMSR`,kstPaneId:`sub_KST`,fastkPaneId:`sub_FASTK`,macdPaneId:`sub_MACD`,atrPaneId:`sub_ATR`,wmaPaneId:`sub_WMA`,demaPaneId:`sub_DEMA`,temaPaneId:`sub_TEMA`,hmaPaneId:`sub_HMA`,kamaPaneId:`sub_KAMA`,sarPaneId:`sub_SAR`,supertrendPaneId:`sub_SuperTrend`,keltnerPaneId:`sub_Keltner`,donchianPaneId:`sub_Donchian`}}setData(e,t){this.dataVersion===t&&!this.dirtyData||(this.currentData=e,this.dataVersion=t,this.dirtyData=!0)}shallowEqual(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}setConfig(e,t){e.ma!==void 0&&!this.shallowEqual(e.ma,this.config.ma)&&(this.config.ma={...this.config.ma,...e.ma},this.dirtyMAConfig=!0),e.boll!==void 0&&!this.shallowEqual(e.boll,this.config.boll)&&(this.config.boll={...this.config.boll,...e.boll},this.dirtyBollConfig=!0),e.expma!==void 0&&!this.shallowEqual(e.expma,this.config.expma)&&(this.config.expma={...this.config.expma,...e.expma},this.dirtyExpmaConfig=!0),e.ene!==void 0&&!this.shallowEqual(e.ene,this.config.ene)&&(this.config.ene={...this.config.ene,...e.ene},this.dirtyEneConfig=!0),e.rsi!==void 0&&!this.shallowEqual(e.rsi,this.config.rsi)&&(this.config.rsi={...this.config.rsi,...e.rsi},this.dirtyRsiConfig=!0),e.cci!==void 0&&!this.shallowEqual(e.cci,this.config.cci)&&(this.config.cci={...this.config.cci,...e.cci},this.dirtyCciConfig=!0),e.stoch!==void 0&&!this.shallowEqual(e.stoch,this.config.stoch)&&(this.config.stoch={...this.config.stoch,...e.stoch},this.dirtyStochConfig=!0),e.mom!==void 0&&!this.shallowEqual(e.mom,this.config.mom)&&(this.config.mom={...this.config.mom,...e.mom},this.dirtyMomConfig=!0),e.wmsr!==void 0&&!this.shallowEqual(e.wmsr,this.config.wmsr)&&(this.config.wmsr={...this.config.wmsr,...e.wmsr},this.dirtyWmsrConfig=!0),e.kst!==void 0&&!this.shallowEqual(e.kst,this.config.kst)&&(this.config.kst={...this.config.kst,...e.kst},this.dirtyKstConfig=!0),e.fastk!==void 0&&!this.shallowEqual(e.fastk,this.config.fastk)&&(this.config.fastk={...this.config.fastk,...e.fastk},this.dirtyFastkConfig=!0),e.macd!==void 0&&!this.shallowEqual(e.macd,this.config.macd)&&(this.config.macd={...this.config.macd,...e.macd},this.dirtyMacdConfig=!0),e.atr!==void 0&&!this.shallowEqual(e.atr,this.config.atr)&&(this.config.atr={...this.config.atr,...e.atr},this.dirtyAtrConfig=!0),e.wma!==void 0&&!this.shallowEqual(e.wma,this.config.wma)&&(this.config.wma={...this.config.wma,...e.wma},this.dirtyWmaConfig=!0),e.dema!==void 0&&!this.shallowEqual(e.dema,this.config.dema)&&(this.config.dema={...this.config.dema,...e.dema},this.dirtyDemaConfig=!0),e.tema!==void 0&&!this.shallowEqual(e.tema,this.config.tema)&&(this.config.tema={...this.config.tema,...e.tema},this.dirtyTemaConfig=!0),e.hma!==void 0&&!this.shallowEqual(e.hma,this.config.hma)&&(this.config.hma={...this.config.hma,...e.hma},this.dirtyHmaConfig=!0),e.kama!==void 0&&!this.shallowEqual(e.kama,this.config.kama)&&(this.config.kama={...this.config.kama,...e.kama},this.dirtyKamaConfig=!0),e.sar!==void 0&&!this.shallowEqual(e.sar,this.config.sar)&&(this.config.sar={...this.config.sar,...e.sar},this.dirtySarConfig=!0),e.supertrend!==void 0&&!this.shallowEqual(e.supertrend,this.config.supertrend)&&(this.config.supertrend={...this.config.supertrend,...e.supertrend},this.dirtySupertrendConfig=!0),e.keltner!==void 0&&!this.shallowEqual(e.keltner,this.config.keltner)&&(this.config.keltner={...this.config.keltner,...e.keltner},this.dirtyKeltnerConfig=!0),e.donchian!==void 0&&!this.shallowEqual(e.donchian,this.config.donchian)&&(this.config.donchian={...this.config.donchian,...e.donchian},this.dirtyDonchianConfig=!0),e.rsiPaneId!==void 0&&(this.config.rsiPaneId=e.rsiPaneId),e.cciPaneId!==void 0&&(this.config.cciPaneId=e.cciPaneId),e.stochPaneId!==void 0&&(this.config.stochPaneId=e.stochPaneId),e.momPaneId!==void 0&&(this.config.momPaneId=e.momPaneId),e.wmsrPaneId!==void 0&&(this.config.wmsrPaneId=e.wmsrPaneId),e.kstPaneId!==void 0&&(this.config.kstPaneId=e.kstPaneId),e.fastkPaneId!==void 0&&(this.config.fastkPaneId=e.fastkPaneId),e.macdPaneId!==void 0&&(this.config.macdPaneId=e.macdPaneId),e.atrPaneId!==void 0&&(this.config.atrPaneId=e.atrPaneId),e.wmaPaneId!==void 0&&(this.config.wmaPaneId=e.wmaPaneId),e.demaPaneId!==void 0&&(this.config.demaPaneId=e.demaPaneId),e.temaPaneId!==void 0&&(this.config.temaPaneId=e.temaPaneId),e.hmaPaneId!==void 0&&(this.config.hmaPaneId=e.hmaPaneId),e.kamaPaneId!==void 0&&(this.config.kamaPaneId=e.kamaPaneId),e.sarPaneId!==void 0&&(this.config.sarPaneId=e.sarPaneId),e.supertrendPaneId!==void 0&&(this.config.supertrendPaneId=e.supertrendPaneId),e.keltnerPaneId!==void 0&&(this.config.keltnerPaneId=e.keltnerPaneId),e.donchianPaneId!==void 0&&(this.config.donchianPaneId=e.donchianPaneId),this.configVersion=t}forceDirty(){this.dirtyData=!0,this.dirtyMAConfig=!0,this.dirtyBollConfig=!0,this.dirtyExpmaConfig=!0,this.dirtyEneConfig=!0,this.dirtyRsiConfig=!0,this.dirtyCciConfig=!0,this.dirtyStochConfig=!0,this.dirtyMomConfig=!0,this.dirtyWmsrConfig=!0,this.dirtyKstConfig=!0,this.dirtyFastkConfig=!0,this.dirtyMacdConfig=!0,this.dirtyAtrConfig=!0,this.dirtyWmaConfig=!0,this.dirtyDemaConfig=!0,this.dirtyTemaConfig=!0,this.dirtyHmaConfig=!0,this.dirtyKamaConfig=!0,this.dirtySarConfig=!0,this.dirtySupertrendConfig=!0,this.dirtyKeltnerConfig=!0,this.dirtyDonchianConfig=!0}getDataVersion(){return this.dataVersion}getConfigVersion(){return this.configVersion}computeSeries(){let e=this.currentData,t=[];if(this.dirtyData||this.dirtyMAConfig){this.cachedSeries={};for(let t of gr){let n=`ma${t}`;this.config.ma[n]&&(this.cachedSeries[t]=br(e,t))}t.push(`ma`)}if((this.dirtyData||this.dirtyBollConfig)&&(this.cachedBollSeries=_r(e,this.config.boll.period,this.config.boll.multiplier),t.push(`boll`)),(this.dirtyData||this.dirtyExpmaConfig)&&(this.cachedExpmaSeries=vr(e,this.config.expma.fastPeriod,this.config.expma.slowPeriod),t.push(`expma`)),(this.dirtyData||this.dirtyEneConfig)&&(this.cachedEneSeries=yr(e,this.config.ene.period,this.config.ene.deviation),t.push(`ene`)),this.dirtyData||this.dirtyRsiConfig){this.cachedRsiSeries={};let n=[this.config.rsi.period1,this.config.rsi.period2,this.config.rsi.period3],r=[this.config.rsi.showRSI1,this.config.rsi.showRSI2,this.config.rsi.showRSI3];for(let t=0;t<n.length;t++)r[t]&&(this.cachedRsiSeries[n[t]]=xr(e,n[t]));t.push(`rsi`)}return(this.dirtyData||this.dirtyCciConfig)&&(this.config.cci.showCCI?this.cachedCciSeries=Sr(e,this.config.cci.period):this.cachedCciSeries=[],t.push(`cci`)),(this.dirtyData||this.dirtyStochConfig)&&(this.config.stoch.showK||this.config.stoch.showD?this.cachedStochSeries=Cr(e,this.config.stoch.n,this.config.stoch.m):this.cachedStochSeries=[],t.push(`stoch`)),(this.dirtyData||this.dirtyMomConfig)&&(this.config.mom.showMOM?this.cachedMomSeries=wr(e,this.config.mom.period):this.cachedMomSeries=[],t.push(`mom`)),(this.dirtyData||this.dirtyWmsrConfig)&&(this.config.wmsr.showWMSR?this.cachedWmsrSeries=Tr(e,this.config.wmsr.period):this.cachedWmsrSeries=[],t.push(`wmsr`)),(this.dirtyData||this.dirtyKstConfig)&&(this.config.kst.showKST||this.config.kst.showSignal?this.cachedKstSeries=Or(e,this.config.kst.roc1,this.config.kst.roc2,this.config.kst.roc3,this.config.kst.roc4,this.config.kst.signalPeriod):this.cachedKstSeries=[],t.push(`kst`)),(this.dirtyData||this.dirtyFastkConfig)&&(this.config.fastk.showFASTK?this.cachedFastkSeries=kr(e,this.config.fastk.period):this.cachedFastkSeries=[],t.push(`fastk`)),(this.dirtyData||this.dirtyMacdConfig)&&(this.config.macd.showDIF||this.config.macd.showDEA||this.config.macd.showBAR?this.cachedMacdSeries=Mr(e,this.config.macd.fastPeriod,this.config.macd.slowPeriod,this.config.macd.signalPeriod):this.cachedMacdSeries=[],t.push(`macd`)),(this.dirtyData||this.dirtyAtrConfig)&&(this.config.atr.showATR?this.cachedAtrSeries=Nr(e,this.config.atr.period):this.cachedAtrSeries=[],t.push(`atr`)),(this.dirtyData||this.dirtyWmaConfig)&&(this.config.wma.showWMA?this.cachedWmaSeries=Fr(e,this.config.wma.period):this.cachedWmaSeries=[],t.push(`wma`)),(this.dirtyData||this.dirtyDemaConfig)&&(this.config.dema.showDEMA?this.cachedDemaSeries=Lr(e,this.config.dema.period):this.cachedDemaSeries=[],t.push(`dema`)),(this.dirtyData||this.dirtyTemaConfig)&&(this.config.tema.showTEMA?this.cachedTemaSeries=Rr(e,this.config.tema.period):this.cachedTemaSeries=[],t.push(`tema`)),(this.dirtyData||this.dirtyHmaConfig)&&(this.config.hma.showHMA?this.cachedHmaSeries=zr(e,this.config.hma.period):this.cachedHmaSeries=[],t.push(`hma`)),(this.dirtyData||this.dirtyKamaConfig)&&(this.config.kama.showKAMA?this.cachedKamaSeries=Br(e,this.config.kama.period,this.config.kama.fastPeriod,this.config.kama.slowPeriod):this.cachedKamaSeries=[],t.push(`kama`)),(this.dirtyData||this.dirtySarConfig)&&(this.config.sar.showSAR?this.cachedSarSeries=Ur(e,this.config.sar.step,this.config.sar.maxStep):this.cachedSarSeries=[],t.push(`sar`)),(this.dirtyData||this.dirtySupertrendConfig)&&(this.config.supertrend.showSuperTrend?this.cachedSupertrendSeries=Wr(e,this.config.supertrend.atrPeriod,this.config.supertrend.multiplier):this.cachedSupertrendSeries=[],t.push(`supertrend`)),(this.dirtyData||this.dirtyKeltnerConfig)&&(this.config.keltner.showUpper||this.config.keltner.showMiddle||this.config.keltner.showLower?this.cachedKeltnerSeries=Gr(e,this.config.keltner.emaPeriod,this.config.keltner.atrPeriod,this.config.keltner.multiplier):this.cachedKeltnerSeries=[],t.push(`keltner`)),(this.dirtyData||this.dirtyDonchianConfig)&&(this.config.donchian.showUpper||this.config.donchian.showMiddle||this.config.donchian.showLower?this.cachedDonchianSeries=Kr(e,this.config.donchian.period):this.cachedDonchianSeries=[],t.push(`donchian`)),this.dirtyData=!1,this.dirtyMAConfig=!1,this.dirtyBollConfig=!1,this.dirtyExpmaConfig=!1,this.dirtyEneConfig=!1,this.dirtyRsiConfig=!1,this.dirtyCciConfig=!1,this.dirtyStochConfig=!1,this.dirtyMomConfig=!1,this.dirtyWmsrConfig=!1,this.dirtyKstConfig=!1,this.dirtyFastkConfig=!1,this.dirtyMacdConfig=!1,this.dirtyAtrConfig=!1,this.dirtyWmaConfig=!1,this.dirtyDemaConfig=!1,this.dirtyTemaConfig=!1,this.dirtyHmaConfig=!1,this.dirtyKamaConfig=!1,this.dirtySarConfig=!1,this.dirtySupertrendConfig=!1,this.dirtyKeltnerConfig=!1,this.dirtyDonchianConfig=!1,{ma:{series:this.cachedSeries,enabledPeriods:Object.keys(this.cachedSeries).map(Number)},boll:{series:this.cachedBollSeries,params:{...this.config.boll}},expma:{series:this.cachedExpmaSeries,params:{...this.config.expma}},ene:{series:this.cachedEneSeries,params:{...this.config.ene}},rsi:{series:this.cachedRsiSeries,enabledPeriods:Object.keys(this.cachedRsiSeries).map(Number),params:{...this.config.rsi}},cci:{series:this.cachedCciSeries,params:{...this.config.cci}},stoch:{series:this.cachedStochSeries,params:{...this.config.stoch}},mom:{series:this.cachedMomSeries,params:{...this.config.mom}},wmsr:{series:this.cachedWmsrSeries,params:{...this.config.wmsr}},kst:{series:this.cachedKstSeries,params:{...this.config.kst}},fastk:{series:this.cachedFastkSeries,params:{...this.config.fastk}},macd:{series:this.cachedMacdSeries,params:{...this.config.macd}},atr:{series:this.cachedAtrSeries,params:{...this.config.atr}},wma:{series:this.cachedWmaSeries,params:{...this.config.wma}},dema:{series:this.cachedDemaSeries,params:{...this.config.dema}},tema:{series:this.cachedTemaSeries,params:{...this.config.tema}},hma:{series:this.cachedHmaSeries,params:{...this.config.hma}},kama:{series:this.cachedKamaSeries,params:{...this.config.kama}},sar:{series:this.cachedSarSeries,params:{...this.config.sar}},supertrend:{series:this.cachedSupertrendSeries,params:{...this.config.supertrend}},keltner:{series:this.cachedKeltnerSeries,params:{...this.config.keltner}},donchian:{series:this.cachedDonchianSeries,params:{...this.config.donchian}},_changed:t}}getCachedSeries(){return{_changed:[],ma:{series:this.cachedSeries,enabledPeriods:Object.keys(this.cachedSeries).map(Number)},boll:{series:this.cachedBollSeries,params:{...this.config.boll}},expma:{series:this.cachedExpmaSeries,params:{...this.config.expma}},ene:{series:this.cachedEneSeries,params:{...this.config.ene}},rsi:{series:this.cachedRsiSeries,enabledPeriods:Object.keys(this.cachedRsiSeries).map(Number),params:{...this.config.rsi}},cci:{series:this.cachedCciSeries,params:{...this.config.cci}},stoch:{series:this.cachedStochSeries,params:{...this.config.stoch}},mom:{series:this.cachedMomSeries,params:{...this.config.mom}},wmsr:{series:this.cachedWmsrSeries,params:{...this.config.wmsr}},kst:{series:this.cachedKstSeries,params:{...this.config.kst}},fastk:{series:this.cachedFastkSeries,params:{...this.config.fastk}},macd:{series:this.cachedMacdSeries,params:{...this.config.macd}},atr:{series:this.cachedAtrSeries,params:{...this.config.atr}},wma:{series:this.cachedWmaSeries,params:{...this.config.wma}},dema:{series:this.cachedDemaSeries,params:{...this.config.dema}},tema:{series:this.cachedTemaSeries,params:{...this.config.tema}},hma:{series:this.cachedHmaSeries,params:{...this.config.hma}},kama:{series:this.cachedKamaSeries,params:{...this.config.kama}},sar:{series:this.cachedSarSeries,params:{...this.config.sar}},supertrend:{series:this.cachedSupertrendSeries,params:{...this.config.supertrend}},keltner:{series:this.cachedKeltnerSeries,params:{...this.config.keltner}},donchian:{series:this.cachedDonchianSeries,params:{...this.config.donchian}}}}};function Jr(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.type==`string`?[`ready`,`seriesResult`,`error`].includes(t.type):!1}var Z=(e,t)=>`indicator:${e}:${t}`,Yr=e=>Z(`rsi`,e),Xr={timestamp:0,series:{},enabledPeriods:[],params:{period1:6,period2:12,period3:24,showRSI1:!0,showRSI2:!0,showRSI3:!0},valueMin:0,valueMax:100,visibleMin:1/0,visibleMax:-1/0},Zr=e=>Z(`cci`,e),Qr={timestamp:0,series:[],params:{period:14,showCCI:!0},valueMin:-150,valueMax:150,visibleMin:1/0,visibleMax:-1/0},$r=e=>Z(`stoch`,e),ei={timestamp:0,series:[],params:{n:9,m:3,showK:!0,showD:!0},valueMin:0,valueMax:100,visibleMin:1/0,visibleMax:-1/0},ti=e=>Z(`mom`,e),ni={timestamp:0,series:[],params:{period:10,showMOM:!0},valueMin:0,valueMax:0,visibleMin:1/0,visibleMax:-1/0},ri=e=>Z(`wmsr`,e),ii={timestamp:0,series:[],params:{period:14,showWMSR:!0},valueMin:-100,valueMax:0,visibleMin:1/0,visibleMax:-1/0},ai=e=>Z(`kst`,e),oi={timestamp:0,series:[],params:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},valueMin:0,valueMax:0,visibleMin:1/0,visibleMax:-1/0},si=e=>Z(`fastk`,e),ci={timestamp:0,series:[],params:{period:9,showFASTK:!0},valueMin:0,valueMax:100,visibleMin:1/0,visibleMax:-1/0},li=`indicator:macd`;function ui(e){return`${li}:${e}`}var di={timestamp:0,series:[],params:{fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0},visibleMin:1/0,visibleMax:-1/0,valueMin:-1/0,valueMax:1/0},fi=e=>Z(`atr`,e),pi={timestamp:0,series:[],params:{period:14,showATR:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},mi=e=>Z(`wma`,e),hi={timestamp:0,series:[],params:{period:9,showWMA:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},gi=e=>Z(`dema`,e),_i={timestamp:0,series:[],params:{period:20,showDEMA:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},vi=e=>Z(`tema`,e),yi={timestamp:0,series:[],params:{period:20,showTEMA:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},bi=e=>Z(`hma`,e),xi={timestamp:0,series:[],params:{period:9,showHMA:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},Si=e=>Z(`kama`,e),Ci={timestamp:0,series:[],params:{period:10,fastPeriod:2,slowPeriod:30,showKAMA:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},wi=e=>Z(`sar`,e),Ti=.02,Ei=.2,Di={timestamp:0,series:[],params:{step:Ti,maxStep:Ei,showSAR:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},Oi=e=>Z(`supertrend`,e),ki={timestamp:0,series:[],params:{atrPeriod:10,multiplier:3,showSuperTrend:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},Ai=e=>Z(`keltner`,e),ji={timestamp:0,series:[],params:{emaPeriod:20,atrPeriod:10,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0},Mi=e=>Z(`donchian`,e),Ni={timestamp:0,series:[],params:{period:20,showUpper:!0,showMiddle:!0,showLower:!0},valueMin:0,valueMax:1,visibleMin:1/0,visibleMax:-1/0};function Pi(e,t){let n=t.end-1;return n>=0&&n<e.macd.series.length?e.macd.series[n]:null}function Q(e,t,n){return{...e,...n,timestamp:t}}function Fi(e,t,n,r={}){let i=r.rsi??!0,a=r.cci??!0,o=r.stoch??!0,s=r.mom??!0,c=r.wmsr??!0,l=r.kst??!0,u=r.fastk??!0,d=r.macd??!0,f=r.atr??!0,p=r.wma??!0,m=r.dema??!0,h=r.tema??!0,g=r.hma??!0,_=r.kama??!0,v=r.sar??!0,y=r.supertrend??!0,b=r.keltner??!0,x=r.donchian??!0,S=i?Vi(e.rsi.series,t):null,C=a?Hi(e.cci.series,t):null,w=o?Ui(e.stoch.series,t):null,T=s?Wi(e.mom.series,t):null,E=c?Gi(e.wmsr.series,t):null,D=l?Ki(e.kst.series,t):null,O=u?qi(e.fastk.series,t):null,k=d?Ji(e.macd.series,t):null,A=f?Yi(e.atr.series,t):null,j=p?Qi(e.wma.series,t):null,M=m?Qi(e.dema.series,t):null,N=h?Qi(e.tema.series,t):null,P=g?Qi(e.hma.series,t):null,F=_?Qi(e.kama.series,t):null,I=v?Zi(e.sar.series,t):null,L=y?Zi(e.supertrend.series,t):null,ee=b?Xi(e.keltner.series,t):null,te=x?Xi(e.donchian.series,t):null,ne=d?Pi(e,t):null,re=k?Math.max(Math.abs(k.max),Math.abs(k.min))*.1:0,ie=k&&Number.isFinite(k.min)?k.min-re:di.valueMin,ae=k&&Number.isFinite(k.max)?k.max+re:di.valueMax,oe=C?Math.min(C.min,-150):Qr.valueMin,se=C?Math.max(C.max,150):Qr.valueMax,ce=T?Math.max(Math.abs(T.max),Math.abs(T.min))*.1:0,le=T?T.min-ce:ni.valueMin,ue=T?T.max+ce:ni.valueMax,de=(D?D.max-D.min:0)*.1,R=D?D.min-de:oi.valueMin,fe=D?D.max+de:oi.valueMax,pe=A&&Number.isFinite(A.max)?A.max*1.1:pi.valueMax,z=(e,t)=>{if(!e||!Number.isFinite(e.min)||!Number.isFinite(e.max))return{valueMin:t.valueMin,valueMax:t.valueMax};let n=e.max-e.min,r=n>0?n*.05:Math.max(1,Math.abs(e.max)*.05);return{valueMin:e.min-r,valueMax:e.max+r}},me=z(j,hi),he=z(M,_i),ge=z(N,yi),_e=z(P,xi),B=z(F,Ci),ve=z(I,Di),ye=z(L,ki),be=z(ee,ji),xe=z(te,Ni);return{rsi:i?{timestamp:n,series:e.rsi.series,enabledPeriods:e.rsi.enabledPeriods,params:e.rsi.params,valueMin:0,valueMax:100,visibleMin:S.min,visibleMax:S.max}:Q(Xr,n,{series:e.rsi.series,enabledPeriods:e.rsi.enabledPeriods,params:e.rsi.params}),cci:a?{timestamp:n,series:e.cci.series,params:e.cci.params,valueMin:oe,valueMax:se,visibleMin:C.min,visibleMax:C.max}:Q(Qr,n,{series:e.cci.series,params:e.cci.params}),stoch:o?{timestamp:n,series:e.stoch.series,params:e.stoch.params,valueMin:0,valueMax:100,visibleMin:w.min,visibleMax:w.max}:Q(ei,n,{series:e.stoch.series,params:e.stoch.params}),mom:s?{timestamp:n,series:e.mom.series,params:e.mom.params,valueMin:le,valueMax:ue,visibleMin:T.min,visibleMax:T.max}:Q(ni,n,{series:e.mom.series,params:e.mom.params}),wmsr:c?{timestamp:n,series:e.wmsr.series,params:e.wmsr.params,valueMin:-100,valueMax:0,visibleMin:E.min,visibleMax:E.max}:Q(ii,n,{series:e.wmsr.series,params:e.wmsr.params}),kst:l?{timestamp:n,series:e.kst.series,params:e.kst.params,valueMin:R,valueMax:fe,visibleMin:D.min,visibleMax:D.max}:Q(oi,n,{series:e.kst.series,params:e.kst.params}),fastk:u?{timestamp:n,series:e.fastk.series,params:e.fastk.params,valueMin:0,valueMax:100,visibleMin:O.min,visibleMax:O.max}:Q(ci,n,{series:e.fastk.series,params:e.fastk.params}),macd:d?{timestamp:n,series:e.macd.series,params:e.macd.params,valueMin:ie,valueMax:ae,visibleMin:k.min,visibleMax:k.max,latestValues:ne?{dif:ne.dif,dea:ne.dea,macd:ne.macd}:void 0}:Q(di,n,{series:e.macd.series,params:e.macd.params}),atr:f?{timestamp:n,series:e.atr.series,params:e.atr.params,valueMin:0,valueMax:pe,visibleMin:A.min,visibleMax:A.max}:Q(pi,n,{series:e.atr.series,params:e.atr.params}),wma:p?{timestamp:n,series:e.wma.series,params:e.wma.params,valueMin:me.valueMin,valueMax:me.valueMax,visibleMin:j.min,visibleMax:j.max}:Q(hi,n,{series:e.wma.series,params:e.wma.params}),dema:m?{timestamp:n,series:e.dema.series,params:e.dema.params,valueMin:he.valueMin,valueMax:he.valueMax,visibleMin:M.min,visibleMax:M.max}:Q(_i,n,{series:e.dema.series,params:e.dema.params}),tema:h?{timestamp:n,series:e.tema.series,params:e.tema.params,valueMin:ge.valueMin,valueMax:ge.valueMax,visibleMin:N.min,visibleMax:N.max}:Q(yi,n,{series:e.tema.series,params:e.tema.params}),hma:g?{timestamp:n,series:e.hma.series,params:e.hma.params,valueMin:_e.valueMin,valueMax:_e.valueMax,visibleMin:P.min,visibleMax:P.max}:Q(xi,n,{series:e.hma.series,params:e.hma.params}),kama:_?{timestamp:n,series:e.kama.series,params:e.kama.params,valueMin:B.valueMin,valueMax:B.valueMax,visibleMin:F.min,visibleMax:F.max}:Q(Ci,n,{series:e.kama.series,params:e.kama.params}),sar:v?{timestamp:n,series:e.sar.series,params:e.sar.params,valueMin:ve.valueMin,valueMax:ve.valueMax,visibleMin:I.min,visibleMax:I.max}:Q(Di,n,{series:e.sar.series,params:e.sar.params}),supertrend:y?{timestamp:n,series:e.supertrend.series,params:e.supertrend.params,valueMin:ye.valueMin,valueMax:ye.valueMax,visibleMin:L.min,visibleMax:L.max}:Q(ki,n,{series:e.supertrend.series,params:e.supertrend.params}),keltner:b?{timestamp:n,series:e.keltner.series,params:e.keltner.params,valueMin:be.valueMin,valueMax:be.valueMax,visibleMin:ee.min,visibleMax:ee.max}:Q(ji,n,{series:e.keltner.series,params:e.keltner.params}),donchian:x?{timestamp:n,series:e.donchian.series,params:e.donchian.params,valueMin:xe.valueMin,valueMax:xe.valueMax,visibleMin:te.min,visibleMax:te.max}:Q(Ni,n,{series:e.donchian.series,params:e.donchian.params})}}function Ii(e,t,n){let r=Li(e.ma.series,t),i=Ri(e.boll.series,t),a=zi(e.expma.series,t),o=Bi(e.ene.series,t),s=Fi(e,t,n);return{ma:{timestamp:n,series:e.ma.series,enabledPeriods:e.ma.enabledPeriods,visibleMin:r.min,visibleMax:r.max},boll:{timestamp:n,series:e.boll.series,params:e.boll.params,visibleMin:i.min,visibleMax:i.max},expma:{timestamp:n,series:e.expma.series,params:e.expma.params,visibleMin:a.min,visibleMax:a.max},ene:{timestamp:n,series:e.ene.series,params:e.ene.params,visibleMin:o.min,visibleMax:o.max},...s}}function Li(e,t){let n=Object.values(e);if(n.length===0||t.start>=n[0].length)return{min:1/0,max:-1/0};let r=1/0,i=-1/0;for(let e of n){let n=Math.min(t.end,e.length);for(let a=t.start;a<n;a++){let t=e[a];t!==void 0&&(r=Math.min(r,t),i=Math.max(i,t))}}return{min:r,max:i}}function Ri(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.upper,t.middle,t.lower),r=Math.max(r,t.upper,t.middle,t.lower))}return{min:n,max:r}}function zi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.fast,t.slow),r=Math.max(r,t.fast,t.slow))}return{min:n,max:r}}function Bi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.upper,t.middle,t.lower),r=Math.max(r,t.upper,t.middle,t.lower))}return{min:n,max:r}}function Vi(e,t){let n=Object.values(e);if(n.length===0||t.start>=n[0].length)return{min:1/0,max:-1/0};let r=1/0,i=-1/0;for(let e of n){let n=Math.min(t.end,e.length);for(let a=t.start;a<n;a++){let t=e[a];t!==void 0&&(r=Math.min(r,t),i=Math.max(i,t))}}return{min:r,max:i}}function Hi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function Ui(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.k,t.d),r=Math.max(r,t.k,t.d))}return{min:n,max:r}}function Wi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function Gi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function Ki(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.kst,t.signal),r=Math.max(r,t.kst,t.signal))}return{min:n,max:r}}function qi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function Ji(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.dif,t.dea,t.macd),r=Math.max(r,t.dif,t.dea,t.macd))}return{min:n,max:r}}function Yi(e,t){return Qi(e,t)}function Xi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.lower),r=Math.max(r,t.upper))}return{min:n,max:r}}function Zi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t&&(n=Math.min(n,t.value),r=Math.max(r,t.value))}return{min:n,max:r}}function Qi(e,t){if(e.length===0||t.start>=e.length)return{min:1/0,max:-1/0};let n=1/0,r=-1/0,i=Math.min(t.end,e.length);for(let a=t.start;a<i;a++){let t=e[a];t!==void 0&&(n=Math.min(n,t),r=Math.max(r,t))}return{min:n,max:r}}function $i(e,t,n){let r=1/0,i=-1/0,{start:a,end:o}=t;if(n.has(`ma`)&&Object.keys(e.ma.series).length>0)for(let t of Object.values(e.ma.series))for(let e=a;e<o&&e<t.length;e++){let n=t[e];n!==void 0&&(r=Math.min(r,n),i=Math.max(i,n))}if(n.has(`boll`)&&e.boll.series.length>0)for(let t=a;t<o&&t<e.boll.series.length;t++){let n=e.boll.series[t];n&&(r=Math.min(r,n.upper,n.middle,n.lower),i=Math.max(i,n.upper,n.middle,n.lower))}if(n.has(`expma`)&&e.expma.series.length>0)for(let t=a;t<o&&t<e.expma.series.length;t++){let n=e.expma.series[t];n&&(r=Math.min(r,n.fast,n.slow),i=Math.max(i,n.fast,n.slow))}if(n.has(`ene`)&&e.ene.series.length>0)for(let t=a;t<o&&t<e.ene.series.length;t++){let n=e.ene.series[t];n&&(r=Math.min(r,n.upper,n.middle,n.lower),i=Math.max(i,n.upper,n.middle,n.lower))}return!Number.isFinite(r)||!Number.isFinite(i)?null:{min:r,max:i}}var ea=Z(`ma`,`main`),ta=Z(`boll`,`main`),na=Z(`expma`,`main`),ra=Z(`ene`,`main`),ia=class{pluginHost=null;visibleRange={start:0,end:0};activeMainIndicators=new Set;dataVersion=0;configVersion=0;requestId=0;lastAppliedRequestId=0;currentData=[];configSnapshot=this.getDefaultConfig();worker=null;workerReady=!1;useWorker=!1;pendingRequest=null;inlineRuntime=null;latestResult=null;invalidateCallback=null;getActiveSubPaneIds=null;constructor(){this.initBackend()}setPluginHost(e){this.pluginHost=e}setInvalidateCallback(e){this.invalidateCallback=e}onSubPaneChanged(){this.latestResult&&this.updateVisibleStatesOnly()}setActiveSubPaneProvider(e){this.getActiveSubPaneIds=e}destroy(){this.terminateWorker(),this.inlineRuntime=null,this.latestResult=null,this.invalidateCallback=null}getDefaultConfig(){return{ma:{ma5:!0,ma10:!0,ma20:!0,ma30:!0,ma60:!0},boll:{period:20,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0,showBand:!0},expma:{fastPeriod:12,slowPeriod:50},ene:{period:10,deviation:11},rsi:{period1:6,period2:12,period3:24,showRSI1:!0,showRSI2:!0,showRSI3:!0},cci:{period:14,showCCI:!0},stoch:{n:9,m:3,showK:!0,showD:!0},mom:{period:10,showMOM:!0},wmsr:{period:14,showWMSR:!0},kst:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},fastk:{period:9,showFASTK:!0},macd:{fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0},atr:{period:14,showATR:!0},wma:{period:9,showWMA:!0},dema:{period:20,showDEMA:!0},tema:{period:20,showTEMA:!0},hma:{period:9,showHMA:!0},kama:{period:10,fastPeriod:2,slowPeriod:30,showKAMA:!0},sar:{step:Ti,maxStep:Ei,showSAR:!0},supertrend:{atrPeriod:10,multiplier:3,showSuperTrend:!0},keltner:{emaPeriod:20,atrPeriod:10,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0},donchian:{period:20,showUpper:!0,showMiddle:!0,showLower:!0},rsiPaneId:`sub_RSI`,cciPaneId:`sub_CCI`,stochPaneId:`sub_STOCH`,momPaneId:`sub_MOM`,wmsrPaneId:`sub_WMSR`,kstPaneId:`sub_KST`,fastkPaneId:`sub_FASTK`,macdPaneId:`sub_MACD`,atrPaneId:`sub_ATR`,wmaPaneId:`sub_WMA`,demaPaneId:`sub_DEMA`,temaPaneId:`sub_TEMA`,hmaPaneId:`sub_HMA`,kamaPaneId:`sub_KAMA`,sarPaneId:`sub_SAR`,supertrendPaneId:`sub_SuperTrend`,keltnerPaneId:`sub_Keltner`,donchianPaneId:`sub_Donchian`}}initBackend(){this.tryInitWorker()||this.initInlineRuntime()}tryInitWorker(){if(console.log(`[IndicatorScheduler] tryInitWorker: Worker available?`,typeof Worker<`u`),typeof Worker>`u`)return!1;try{let e=new URL(`data:video/mp2t;base64,LyoqCiAqIEluZGljYXRvciBXb3JrZXIg5YWl5Y+jCiAqIOi/kOihjOWcqOeLrOeri+e6v+eoi++8jOi0n+i0o+aMh+agh+iuoeeulwogKi8KCmltcG9ydCB0eXBlIHsKICAgIEluZGljYXRvcldvcmtlclJlcXVlc3QsCiAgICBJbmRpY2F0b3JXb3JrZXJSZXNwb25zZSwKICAgIEluZGljYXRvckNvbmZpZ1NuYXBzaG90LAp9IGZyb20gJy4vd29ya2VyUHJvdG9jb2wnCmltcG9ydCB7IFBST1RPQ09MX1ZFUlNJT04gfSBmcm9tICcuL3dvcmtlclByb3RvY29sJwppbXBvcnQgdHlwZSB7IEtMaW5lRGF0YSB9IGZyb20gJ0AvdHlwZXMvcHJpY2UnCmltcG9ydCB7IEluZGljYXRvclJ1bnRpbWUgfSBmcm9tICcuL2luZGljYXRvclJ1bnRpbWUnCgovLyBXb3JrZXIg5YWo5bGA5L2c55So5Z+fCmNvbnN0IGN0eCA9IHNlbGYgYXMgdW5rbm93biBhcyBXb3JrZXIKCi8vIOi/kOihjOaXtuWunuS+iwpsZXQgcnVudGltZTogSW5kaWNhdG9yUnVudGltZSB8IG51bGwgPSBudWxsCgovKioKICog5Y+R6YCB5ZON5bqU5Yiw5Li757q/56iLCiAqLwpmdW5jdGlvbiBwb3N0UmVzcG9uc2UocmVzcG9uc2U6IEluZGljYXRvcldvcmtlclJlc3BvbnNlKTogdm9pZCB7CiAgICBjdHgucG9zdE1lc3NhZ2UocmVzcG9uc2UpCn0KCi8qKgogKiDlpITnkIbliJ3lp4vljJYKICovCmZ1bmN0aW9uIGhhbmRsZUluaXQoKTogdm9pZCB7CiAgICBydW50aW1lID0gbmV3IEluZGljYXRvclJ1bnRpbWUoKQogICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICB0eXBlOiAncmVhZHknLAogICAgICAgIHByb3RvY29sVmVyc2lvbjogUFJPVE9DT0xfVkVSU0lPTiwKICAgIH0pCn0KCi8qKgogKiDlpITnkIborr7nva7mlbDmja4KICovCmZ1bmN0aW9uIGhhbmRsZVNldERhdGEoZGF0YTogS0xpbmVEYXRhW10sIHZlcnNpb246IG51bWJlcik6IHZvaWQgewogICAgaWYgKCFydW50aW1lKSB7CiAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgdHlwZTogJ2Vycm9yJywKICAgICAgICAgICAgc3RhZ2U6ICdzZXREYXRhJywKICAgICAgICAgICAgbWVzc2FnZTogJ1J1bnRpbWUgbm90IGluaXRpYWxpemVkJywKICAgICAgICB9KQogICAgICAgIHJldHVybgogICAgfQogICAgcnVudGltZS5zZXREYXRhKGRhdGEsIHZlcnNpb24pCn0KCi8qKgogKiDlpITnkIborr7nva7phY3nva4KICovCmZ1bmN0aW9uIGhhbmRsZVNldENvbmZpZyhjb25maWc6IFBhcnRpYWw8SW5kaWNhdG9yQ29uZmlnU25hcHNob3Q+LCB2ZXJzaW9uOiBudW1iZXIpOiB2b2lkIHsKICAgIGlmICghcnVudGltZSkgewogICAgICAgIHBvc3RSZXNwb25zZSh7CiAgICAgICAgICAgIHR5cGU6ICdlcnJvcicsCiAgICAgICAgICAgIHN0YWdlOiAnc2V0Q29uZmlnJywKICAgICAgICAgICAgbWVzc2FnZTogJ1J1bnRpbWUgbm90IGluaXRpYWxpemVkJywKICAgICAgICB9KQogICAgICAgIHJldHVybgogICAgfQogICAgcnVudGltZS5zZXRDb25maWcoY29uZmlnLCB2ZXJzaW9uKQp9CgovKioKICog5aSE55CG6K6h566XIHNlcmllcwogKi8KZnVuY3Rpb24gaGFuZGxlQ29tcHV0ZVNlcmllcyhyZXF1ZXN0SWQ6IG51bWJlciwgZGF0YVZlcnNpb246IG51bWJlciwgY29uZmlnVmVyc2lvbjogbnVtYmVyKTogdm9pZCB7CiAgICBpZiAoIXJ1bnRpbWUpIHsKICAgICAgICBwb3N0UmVzcG9uc2UoewogICAgICAgICAgICB0eXBlOiAnZXJyb3InLAogICAgICAgICAgICByZXF1ZXN0SWQsCiAgICAgICAgICAgIHN0YWdlOiAnY29tcHV0ZVNlcmllcycsCiAgICAgICAgICAgIG1lc3NhZ2U6ICdSdW50aW1lIG5vdCBpbml0aWFsaXplZCcsCiAgICAgICAgfSkKICAgICAgICByZXR1cm4KICAgIH0KCiAgICBjb25zdCBzdGFydFRpbWUgPSBwZXJmb3JtYW5jZS5ub3coKQoKICAgIHRyeSB7CiAgICAgICAgY29uc29sZS5sb2coYFtJbmRpY2F0b3JXb3JrZXJdIGNvbXB1dGVTZXJpZXMgU1RBUlQgcmVxSWQ9JHtyZXF1ZXN0SWR9YCkKICAgICAgICBjb25zdCByZXN1bHRzID0gcnVudGltZS5jb21wdXRlU2VyaWVzKCkKICAgICAgICBjb25zdCBjb21wdXRlTXMgPSBwZXJmb3JtYW5jZS5ub3coKSAtIHN0YXJ0VGltZQogICAgICAgIGNvbnNvbGUubG9nKGBbSW5kaWNhdG9yV29ya2VyXSBjb21wdXRlU2VyaWVzIERPTkUgaW4gJHtjb21wdXRlTXMudG9GaXhlZCgxKX1tcywgY2hhbmdlZD1bJHtyZXN1bHRzLl9jaGFuZ2VkLmpvaW4oJywnKX1dYCkKCiAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgdHlwZTogJ3Nlcmllc1Jlc3VsdCcsCiAgICAgICAgICAgIHJlcXVlc3RJZCwKICAgICAgICAgICAgZGF0YVZlcnNpb24sCiAgICAgICAgICAgIGNvbmZpZ1ZlcnNpb24sCiAgICAgICAgICAgIHJlc3VsdHMsCiAgICAgICAgICAgIG1ldHJpY3M6IHsKICAgICAgICAgICAgICAgIGNvbXB1dGVNcywKICAgICAgICAgICAgICAgIGRhdGFMZW5ndGg6IDAsIC8vIOeUseiwg+eUqOaWueWhq+WFhQogICAgICAgICAgICB9LAogICAgICAgIH0pCiAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICBjb25zdCBtZXNzYWdlID0gZXJyIGluc3RhbmNlb2YgRXJyb3IgPyBlcnIubWVzc2FnZSA6IFN0cmluZyhlcnIpCiAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgdHlwZTogJ2Vycm9yJywKICAgICAgICAgICAgcmVxdWVzdElkLAogICAgICAgICAgICBzdGFnZTogJ2NvbXB1dGVTZXJpZXMnLAogICAgICAgICAgICBtZXNzYWdlLAogICAgICAgIH0pCiAgICB9Cn0KCi8qKgogKiDlpITnkIbplIDmr4EKICovCmZ1bmN0aW9uIGhhbmRsZURpc3Bvc2UoKTogdm9pZCB7CiAgICBydW50aW1lID0gbnVsbAogICAgLy8gV29ya2VyIOS8muiiq+S4u+e6v+eoiyB0ZXJtaW5hdGXvvIzov5nph4zlgZrmuIXnkIbljbPlj68KfQoKLyoqCiAqIOa2iOaBr+WkhOeQhuWZqAogKi8KY3R4Lm9ubWVzc2FnZSA9IChldmVudDogTWVzc2FnZUV2ZW50PEluZGljYXRvcldvcmtlclJlcXVlc3Q+KSA9PiB7CiAgICBjb25zdCBtc2cgPSBldmVudC5kYXRhCgogICAgaWYgKCFtc2cgfHwgdHlwZW9mIG1zZyAhPT0gJ29iamVjdCcpIHsKICAgICAgICBwb3N0UmVzcG9uc2UoewogICAgICAgICAgICB0eXBlOiAnZXJyb3InLAogICAgICAgICAgICBzdGFnZTogJ2luaXQnLAogICAgICAgICAgICBtZXNzYWdlOiAnSW52YWxpZCBtZXNzYWdlIGZvcm1hdCcsCiAgICAgICAgfSkKICAgICAgICByZXR1cm4KICAgIH0KCiAgICBzd2l0Y2ggKG1zZy50eXBlKSB7CiAgICAgICAgY2FzZSAnaW5pdCc6CiAgICAgICAgICAgIGhhbmRsZUluaXQoKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdzZXREYXRhJzoKICAgICAgICAgICAgaGFuZGxlU2V0RGF0YShtc2cuZGF0YSwgbXNnLmRhdGFWZXJzaW9uKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdzZXRDb25maWcnOgogICAgICAgICAgICBoYW5kbGVTZXRDb25maWcobXNnLmNvbmZpZ3MsIG1zZy5jb25maWdWZXJzaW9uKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdjb21wdXRlU2VyaWVzJzoKICAgICAgICAgICAgaGFuZGxlQ29tcHV0ZVNlcmllcyhtc2cucmVxdWVzdElkLCBtc2cuZGF0YVZlcnNpb24sIG1zZy5jb25maWdWZXJzaW9uKQogICAgICAgICAgICBicmVhawoKICAgICAgICBjYXNlICdkaXNwb3NlJzoKICAgICAgICAgICAgaGFuZGxlRGlzcG9zZSgpCiAgICAgICAgICAgIGJyZWFrCgogICAgICAgIGRlZmF1bHQ6IHsKICAgICAgICAgICAgY29uc3QgX2V4aGF1c3RpdmVDaGVjazogbmV2ZXIgPSBtc2cKICAgICAgICAgICAgcG9zdFJlc3BvbnNlKHsKICAgICAgICAgICAgICAgIHR5cGU6ICdlcnJvcicsCiAgICAgICAgICAgICAgICBzdGFnZTogJ2luaXQnLAogICAgICAgICAgICAgICAgbWVzc2FnZTogYFVua25vd24gbWVzc2FnZSB0eXBlOiAkeyhfZXhoYXVzdGl2ZUNoZWNrIGFzIHVua25vd24gYXMgeyB0eXBlOiBzdHJpbmcgfSkudHlwZX1gLAogICAgICAgICAgICB9KQogICAgICAgIH0KICAgIH0KfQoKLy8g6YCa55+l5Li757q/56iLIHdvcmtlciDlt7LliqDovb3vvIjlj6/pgInvvIzkuLvopoHnlKjkuo7osIPor5XvvIkKLy8gY29uc29sZS5sb2coJ1tJbmRpY2F0b3JXb3JrZXJdIExvYWRlZCcpCg==`,``+{}.url);return console.log(`[IndicatorScheduler] Creating worker from:`,e.href),this.worker=new Worker(e,{type:`module`}),console.log(`[IndicatorScheduler] Worker created, waiting for ready...`),this.worker.onmessage=e=>this.handleWorkerMessage(e.data),this.worker.onerror=e=>{console.error(`[IndicatorScheduler] Worker error:`,e),this.fallbackToInline()},this.worker.postMessage({type:`init`,protocolVersion:1}),!0}catch(e){return console.warn(`[IndicatorScheduler] Failed to init worker:`,e),!1}}initInlineRuntime(){console.log(`[IndicatorScheduler] Using INLINE runtime (fallback)`),this.inlineRuntime=new qr,this.useWorker=!1,this.workerReady=!0}fallbackToInline(){console.warn(`[IndicatorScheduler] Falling back to inline runtime`),this.terminateWorker(),this.initInlineRuntime(),this.pendingRequest&&this.computeWithInline()}terminateWorker(){this.worker&&=(this.worker.terminate(),null),this.workerReady=!1,this.useWorker=!1}handleWorkerMessage(e){if(!Jr(e)){console.warn(`[IndicatorScheduler] Invalid worker response:`,e);return}switch(e.type){case`ready`:this.workerReady=!0,this.useWorker=!0,console.log(`[IndicatorScheduler] Worker READY - using Worker backend`),this.triggerRecompute();break;case`seriesResult`:this.handleSeriesResult(e);break;case`error`:console.error(`[IndicatorScheduler] Worker error:`,e.stage,e.message),this.pendingRequest&&e.requestId===this.pendingRequest.requestId&&this.fallbackToInline();break;default:console.warn(`[IndicatorScheduler] Unknown response type:`,e.type)}}handleSeriesResult(e){e.requestId<this.lastAppliedRequestId||e.dataVersion!==this.dataVersion||e.configVersion!==this.configVersion||(console.log(`[IndicatorScheduler] << Worker result: requestId=${e.requestId} metrics=`,e.metrics),this.lastAppliedRequestId=e.requestId,this.pendingRequest=null,this.latestResult=e.results,this.applyResults(e.results),this.invalidateCallback?.())}applyResults(e){if(!this.pluginHost)return;let t=new Set(e._changed),n=Date.now(),r=Ii(e,this.visibleRange,n);if(t.has(`ma`)&&this.pluginHost.setSharedState(ea,r.ma,`ma_scheduler`),t.has(`boll`)&&this.pluginHost.setSharedState(ta,r.boll,`indicator_scheduler`),t.has(`expma`)&&this.pluginHost.setSharedState(na,r.expma,`indicator_scheduler`),t.has(`ene`)&&this.pluginHost.setSharedState(ra,r.ene,`indicator_scheduler`),t.has(`rsi`)){let e=Yr(this.configSnapshot.rsiPaneId);this.pluginHost.setSharedState(e,r.rsi,`indicator_scheduler`)}if(t.has(`cci`)){let e=Zr(this.configSnapshot.cciPaneId);this.pluginHost.setSharedState(e,r.cci,`indicator_scheduler`)}if(t.has(`stoch`)){let e=$r(this.configSnapshot.stochPaneId);this.pluginHost.setSharedState(e,r.stoch,`indicator_scheduler`)}if(t.has(`mom`)){let e=ti(this.configSnapshot.momPaneId);this.pluginHost.setSharedState(e,r.mom,`indicator_scheduler`)}if(t.has(`wmsr`)){let e=ri(this.configSnapshot.wmsrPaneId);this.pluginHost.setSharedState(e,r.wmsr,`indicator_scheduler`)}if(t.has(`kst`)){let e=ai(this.configSnapshot.kstPaneId);this.pluginHost.setSharedState(e,r.kst,`indicator_scheduler`)}if(t.has(`fastk`)){let e=si(this.configSnapshot.fastkPaneId);this.pluginHost.setSharedState(e,r.fastk,`indicator_scheduler`)}if(t.has(`macd`)){let e=ui(this.configSnapshot.macdPaneId);this.pluginHost.setSharedState(e,r.macd,`indicator_scheduler`)}if(t.has(`atr`)){let e=fi(this.configSnapshot.atrPaneId);this.pluginHost.setSharedState(e,r.atr,`indicator_scheduler`)}if(t.has(`wma`)){let e=mi(this.configSnapshot.wmaPaneId);this.pluginHost.setSharedState(e,r.wma,`indicator_scheduler`)}if(t.has(`dema`)){let e=gi(this.configSnapshot.demaPaneId);this.pluginHost.setSharedState(e,r.dema,`indicator_scheduler`)}if(t.has(`tema`)){let e=vi(this.configSnapshot.temaPaneId);this.pluginHost.setSharedState(e,r.tema,`indicator_scheduler`)}if(t.has(`hma`)){let e=bi(this.configSnapshot.hmaPaneId);this.pluginHost.setSharedState(e,r.hma,`indicator_scheduler`)}if(t.has(`kama`)){let e=Si(this.configSnapshot.kamaPaneId);this.pluginHost.setSharedState(e,r.kama,`indicator_scheduler`)}if(t.has(`sar`)){let e=wi(this.configSnapshot.sarPaneId);this.pluginHost.setSharedState(e,r.sar,`indicator_scheduler`)}if(t.has(`supertrend`)){let e=Oi(this.configSnapshot.supertrendPaneId);this.pluginHost.setSharedState(e,r.supertrend,`indicator_scheduler`)}if(t.has(`keltner`)){let e=Ai(this.configSnapshot.keltnerPaneId);this.pluginHost.setSharedState(e,r.keltner,`indicator_scheduler`)}if(t.has(`donchian`)){let e=Mi(this.configSnapshot.donchianPaneId);this.pluginHost.setSharedState(e,r.donchian,`indicator_scheduler`)}}updateVisibleStatesOnly(){if(!this.pluginHost||!this.latestResult)return;let e=Date.now(),t=this.buildActiveSubIndicatorMask(),n=Fi(this.latestResult,this.visibleRange,e,t);console.log(`[ATR-Scheduler] updateVisibleStatesOnly: atrActive=${!!t.atr} atrPaneId=${this.configSnapshot.atrPaneId} seriesLen=${n.atr.series.length}`);let r=Yr(this.configSnapshot.rsiPaneId);this.pluginHost.setSharedState(r,n.rsi,`indicator_scheduler`);let i=Zr(this.configSnapshot.cciPaneId);this.pluginHost.setSharedState(i,n.cci,`indicator_scheduler`);let a=$r(this.configSnapshot.stochPaneId);this.pluginHost.setSharedState(a,n.stoch,`indicator_scheduler`);let o=ti(this.configSnapshot.momPaneId);this.pluginHost.setSharedState(o,n.mom,`indicator_scheduler`);let s=ri(this.configSnapshot.wmsrPaneId);this.pluginHost.setSharedState(s,n.wmsr,`indicator_scheduler`);let c=ai(this.configSnapshot.kstPaneId);this.pluginHost.setSharedState(c,n.kst,`indicator_scheduler`);let l=si(this.configSnapshot.fastkPaneId);this.pluginHost.setSharedState(l,n.fastk,`indicator_scheduler`);let u=ui(this.configSnapshot.macdPaneId);this.pluginHost.setSharedState(u,n.macd,`indicator_scheduler`);let d=fi(this.configSnapshot.atrPaneId);this.pluginHost.setSharedState(d,n.atr,`indicator_scheduler`);let f=mi(this.configSnapshot.wmaPaneId);this.pluginHost.setSharedState(f,n.wma,`indicator_scheduler`);let p=gi(this.configSnapshot.demaPaneId);this.pluginHost.setSharedState(p,n.dema,`indicator_scheduler`);let m=vi(this.configSnapshot.temaPaneId);this.pluginHost.setSharedState(m,n.tema,`indicator_scheduler`);let h=bi(this.configSnapshot.hmaPaneId);this.pluginHost.setSharedState(h,n.hma,`indicator_scheduler`);let g=Si(this.configSnapshot.kamaPaneId);this.pluginHost.setSharedState(g,n.kama,`indicator_scheduler`);let _=wi(this.configSnapshot.sarPaneId);this.pluginHost.setSharedState(_,n.sar,`indicator_scheduler`);let v=Oi(this.configSnapshot.supertrendPaneId);this.pluginHost.setSharedState(v,n.supertrend,`indicator_scheduler`);let y=Ai(this.configSnapshot.keltnerPaneId);this.pluginHost.setSharedState(y,n.keltner,`indicator_scheduler`);let b=Mi(this.configSnapshot.donchianPaneId);this.pluginHost.setSharedState(b,n.donchian,`indicator_scheduler`)}buildActiveSubIndicatorMask(){let e=this.getActiveSubPaneIds?.()??[];return{rsi:e.includes(this.configSnapshot.rsiPaneId),cci:e.includes(this.configSnapshot.cciPaneId),stoch:e.includes(this.configSnapshot.stochPaneId),mom:e.includes(this.configSnapshot.momPaneId),wmsr:e.includes(this.configSnapshot.wmsrPaneId),kst:e.includes(this.configSnapshot.kstPaneId),fastk:e.includes(this.configSnapshot.fastkPaneId),macd:e.includes(this.configSnapshot.macdPaneId),atr:e.includes(this.configSnapshot.atrPaneId),wma:e.includes(this.configSnapshot.wmaPaneId),dema:e.includes(this.configSnapshot.demaPaneId),tema:e.includes(this.configSnapshot.temaPaneId),hma:e.includes(this.configSnapshot.hmaPaneId),kama:e.includes(this.configSnapshot.kamaPaneId),sar:e.includes(this.configSnapshot.sarPaneId),supertrend:e.includes(this.configSnapshot.supertrendPaneId),keltner:e.includes(this.configSnapshot.keltnerPaneId),donchian:e.includes(this.configSnapshot.donchianPaneId)}}buildActiveConfig(){let e=this.getActiveSubPaneIds?.()??[];if(e.length===0)return{...this.configSnapshot};let t={...this.configSnapshot};for(let n of[`rsi`,`cci`,`stoch`,`mom`,`wmsr`,`kst`,`fastk`,`macd`,`atr`,`wma`,`dema`,`tema`,`hma`,`kama`,`sar`,`supertrend`,`keltner`,`donchian`]){let r=t[`${n}PaneId`];if(!e.includes(r)){let e={...t[n]};for(let t of Object.keys(e))t.startsWith(`show`)&&(e[t]=!1);t[n]=e}}return t}update(e,t){this.currentData=e,this.visibleRange=t,this.dataVersion++,this.useWorker&&this.worker&&this.workerReady?this.computeWithWorker():this.computeWithInline()}updateVisibleRange(e){this.visibleRange=e,this.latestResult&&this.updateVisibleStatesOnly()}updateMAConfig(e){this.configSnapshot.ma={...e},this.configVersion++,this.triggerRecompute()}updateBOLLConfig(e){this.configSnapshot.boll={...this.configSnapshot.boll,...e},this.configVersion++,this.triggerRecompute()}updateEXPMAConfig(e){this.configSnapshot.expma={...this.configSnapshot.expma,...e},this.configVersion++,this.triggerRecompute()}updateENEConfig(e){this.configSnapshot.ene={...this.configSnapshot.ene,...e},this.configVersion++,this.triggerRecompute()}updateRSIConfig(e,t){t!==void 0&&(this.configSnapshot.rsiPaneId=t),this.configSnapshot.rsi={...this.configSnapshot.rsi,...e},this.configVersion++,this.triggerRecompute()}updateCCIConfig(e,t){t!==void 0&&(this.configSnapshot.cciPaneId=t),this.configSnapshot.cci={...this.configSnapshot.cci,...e},this.configVersion++,this.triggerRecompute()}updateSTOCHConfig(e,t){t!==void 0&&(this.configSnapshot.stochPaneId=t),this.configSnapshot.stoch={...this.configSnapshot.stoch,...e},this.configVersion++,this.triggerRecompute()}updateMOMConfig(e,t){t!==void 0&&(this.configSnapshot.momPaneId=t),this.configSnapshot.mom={...this.configSnapshot.mom,...e},this.configVersion++,this.triggerRecompute()}updateWMSRConfig(e,t){t!==void 0&&(this.configSnapshot.wmsrPaneId=t),this.configSnapshot.wmsr={...this.configSnapshot.wmsr,...e},this.configVersion++,this.triggerRecompute()}updateKSTConfig(e,t){t!==void 0&&(this.configSnapshot.kstPaneId=t),this.configSnapshot.kst={...this.configSnapshot.kst,...e},this.configVersion++,this.triggerRecompute()}updateFASTKConfig(e,t){t!==void 0&&(this.configSnapshot.fastkPaneId=t),this.configSnapshot.fastk={...this.configSnapshot.fastk,...e},this.configVersion++,this.triggerRecompute()}updateMACDConfig(e,t){t!==void 0&&(this.configSnapshot.macdPaneId=t),this.configSnapshot.macd={...this.configSnapshot.macd,...e},this.configVersion++,this.triggerRecompute()}updateATRConfig(e,t){t!==void 0&&(this.configSnapshot.atrPaneId=t),this.configSnapshot.atr={...this.configSnapshot.atr,...e},this.configVersion++,this.triggerRecompute()}updateWMAConfig(e,t){t!==void 0&&(this.configSnapshot.wmaPaneId=t),this.configSnapshot.wma={...this.configSnapshot.wma,...e},this.configVersion++,this.triggerRecompute()}updateDEMAConfig(e,t){t!==void 0&&(this.configSnapshot.demaPaneId=t),this.configSnapshot.dema={...this.configSnapshot.dema,...e},this.configVersion++,this.triggerRecompute()}updateTEMAConfig(e,t){t!==void 0&&(this.configSnapshot.temaPaneId=t),this.configSnapshot.tema={...this.configSnapshot.tema,...e},this.configVersion++,this.triggerRecompute()}updateHMAConfig(e,t){t!==void 0&&(this.configSnapshot.hmaPaneId=t),this.configSnapshot.hma={...this.configSnapshot.hma,...e},this.configVersion++,this.triggerRecompute()}updateKAMAConfig(e,t){t!==void 0&&(this.configSnapshot.kamaPaneId=t),this.configSnapshot.kama={...this.configSnapshot.kama,...e},this.configVersion++,this.triggerRecompute()}updateSARConfig(e,t){t!==void 0&&(this.configSnapshot.sarPaneId=t),this.configSnapshot.sar={...this.configSnapshot.sar,...e},this.configVersion++,this.triggerRecompute()}updateSuperTrendConfig(e,t){t!==void 0&&(this.configSnapshot.supertrendPaneId=t),this.configSnapshot.supertrend={...this.configSnapshot.supertrend,...e},this.configVersion++,this.triggerRecompute()}updateKeltnerConfig(e,t){t!==void 0&&(this.configSnapshot.keltnerPaneId=t),this.configSnapshot.keltner={...this.configSnapshot.keltner,...e},this.configVersion++,this.triggerRecompute()}updateDonchianConfig(e,t){t!==void 0&&(this.configSnapshot.donchianPaneId=t),this.configSnapshot.donchian={...this.configSnapshot.donchian,...e},this.configVersion++,this.triggerRecompute()}setActiveMainIndicators(e){this.activeMainIndicators=new Set(e.map(e=>e.toLowerCase()))}getMainIndicatorPriceRange(){return this.latestResult?$i(this.latestResult,this.visibleRange,this.activeMainIndicators):null}recompute(){this.inlineRuntime&&this.inlineRuntime.forceDirty(),this.dataVersion++,this.triggerRecompute()}triggerRecompute(){this.useWorker&&this.worker&&this.workerReady?this.computeWithWorker():this.computeWithInline()}computeWithWorker(){!this.worker||!this.workerReady||(console.log(`[IndicatorScheduler] >> Worker compute: requestId=${this.requestId+1} dataV=${this.dataVersion} configV=${this.configVersion}`),this.requestId++,this.pendingRequest={requestId:this.requestId,dataVersion:this.dataVersion,configVersion:this.configVersion},this.worker.postMessage({type:`setData`,dataVersion:this.dataVersion,format:`aos`,data:this.currentData}),this.worker.postMessage({type:`setConfig`,configVersion:this.configVersion,configs:this.buildActiveConfig()}),this.worker.postMessage({type:`computeSeries`,requestId:this.requestId,dataVersion:this.dataVersion,configVersion:this.configVersion}))}computeWithInline(){this.inlineRuntime||=new qr,console.log(`[IndicatorScheduler] >> INLINE compute: dataV=${this.dataVersion} configV=${this.configVersion}`),this.inlineRuntime.setData(this.currentData,this.dataVersion),this.inlineRuntime.setConfig(this.buildActiveConfig(),this.configVersion);let e=this.inlineRuntime.computeSeries();this.latestResult=e,this.applyResults(e),this.invalidateCallback?.()}};function aa(e={}){let{paneId:t=`sub`}=e,n=Z(`volume`,t),r=null;return{name:`volume_${t}`,version:`1.0.0`,description:`成交量渲染器`,debugName:`成交量`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:i,pane:a,data:o,range:s,dpr:c}=e,l=o;if(!l.length)return;let{start:u,end:d}=s,f=0,p=1/0;for(let e=u;e<d&&e<l.length;e++){let t=l[e];if(!t)continue;let n=t.volume;n!=null&&(f=Math.max(f,n),p=Math.min(p,n))}if(f===0||!Number.isFinite(p))return;let m=Math.max(.05,(f-p)*.1),h=Math.max(0,p-m),g=f+m,_=a.yAxis.getDisplayRange({minPrice:h,maxPrice:g}),v=_.minPrice,y=_.maxPrice-v||1,b=a.height-(0-v)/y*a.height,x=Math.round(b*c)/c;r?.setSharedState(n,{valueMin:h,valueMax:g,timestamp:Date.now()},`volume_${t}`);let S=Math.max(1,d-u),C=new Float32Array(S*4),w=new Float32Array(S*4),T=new Float32Array(S*4),E=0,D=0,O=0;for(let t=u;t<d;t++){let n=l[t];if(!n)continue;let r=n.volume;if(!r)continue;let i=e.kBarRects[t-u];if(!i)continue;let o=a.height-(r-v)/y*a.height,s=Math.round(o*c)/c,d=1/c,f=x-s,p=f<=0?d:Math.max(f,d),m=f<=0?x-d:x-p,h=la(n),g,_;h===Pe.UP?(g=C,_=E++):h===Pe.DOWN?(g=w,_=D++):(g=T,_=O++);let b=_*4;g[b]=i.x,g[b+1]=m,g[b+2]=i.width,g[b+3]=p}oa(e,C,E,w,D,T,O)?ca(i,e):sa(i,e.scrollLeft,C,E,w,D,T,O)}}}function oa(e,t,n,r,i,a,o){if(e.settings?.enableWebGLRendering===!1)return!1;let s=e.candleWebGLSurface;if(!s||!s.isAvailable())return!1;s.clear();let c=n===0||s.drawRectBuffer(t.subarray(0,n*4),n,Pe.UP,e.scrollLeft),l=i===0||s.drawRectBuffer(r.subarray(0,i*4),i,Pe.DOWN,e.scrollLeft),u=o===0||s.drawRectBuffer(a.subarray(0,o*4),o,Pe.NEUTRAL,e.scrollLeft);return c&&l&&u}function sa(e,t,n,r,i,a,o,s){e.save(),e.translate(-t,0),e.fillStyle=Pe.UP;for(let t=0;t<r;t++){let r=t*4;e.fillRect(n[r],n[r+1],n[r+2],n[r+3])}e.fillStyle=Pe.DOWN;for(let t=0;t<a;t++){let n=t*4;e.fillRect(i[n],i[n+1],i[n+2],i[n+3])}e.fillStyle=Pe.NEUTRAL;for(let t=0;t<s;t++){let n=t*4;e.fillRect(o[n],o[n+1],o[n+2],o[n+3])}e.restore()}function ca(e,t){let n=t.candleWebGLSurface;n&&n.compositeTo(e)}function la(e){return e.close>e.open?Pe.UP:e.close<e.open?Pe.DOWN:Pe.NEUTRAL}var ua={5:Ne.MA5,10:Ne.MA10,20:Ne.MA20,30:Ne.MA30,60:Ne.MA60};function da(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),r.join(`,`),n.height.toFixed(2)].join(`|`)}function fa(){let e=null,t=``,n=new Map;function r(){t=``,n=new Map}return{name:`ma`,version:`2.1.0`,description:`MA均线渲染器`,debugName:`MA均线`,paneId:`main`,priority:R.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[ea]},draw(i){let{ctx:a,pane:o,range:s,scrollLeft:c,dpr:l,kLineCenters:u,lineWebGLSurface:d}=i,f=e?.getSharedState(ea);if(!f||f.visibleMin>f.visibleMax){r();return}if(f.enabledPeriods.length===0){r();return}let p=da(s,u,o,f.enabledPeriods);if(t!==p){t=p,n=new Map;for(let[e,t]of Object.entries(f.series)){let r=Number(e),i=[];for(let e=s.start;e<s.end&&e<t.length;e++){let n=t[e];if(n===void 0)continue;let r=u[e-s.start];r!==void 0&&i.push({x:r,y:o.yAxis.priceToY(n)})}i.length>=2&&n.set(r,i)}}let m=i.settings?.enableWebGLRendering!==!1,h=!1;if(m&&d?.isAvailable()){let e=[];for(let t of f.enabledPeriods){let r=n.get(t);r&&e.push({points:r,width:1,color:ua[t]??Ne.MA5})}e.length>0&&d.drawLineStrips(e,c)&&(h=!0,d.compositeTo(a,{imageSmoothingEnabled:!1}))}if(!h){a.save(),a.translate(-c,0),a.lineWidth=1,a.lineJoin=`round`,a.lineCap=`round`;for(let e of f.enabledPeriods){let t=n.get(e);if(!(!t||t.length<2)){a.strokeStyle=ua[e]??Ne.MA5,a.beginPath(),a.moveTo(t[0].x,t[0].y);for(let e=1;e<t.length;e++){let n=t[e];a.lineTo(n.x,n.y)}a.stroke()}}a.restore()}},getConfig(){let t=e?.getSharedState(ea),n={};return t?.enabledPeriods.forEach(e=>{n[`ma${e}`]=!0}),n},setConfig(e){}}}var pa=1;function ma(e){let t=e.match(/^rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)$/i);if(!t)return 1;let n=Number(t[1]);return Number.isFinite(n)?n:1}function ha(e){return e.replace(/,\s*[\d.]+\s*\)$/i,`, 1)`)}function ga(e,t,n=1){t.compositeTo(e.ctx,{alpha:n,imageSmoothingEnabled:!1})}function _a(e,t){if(e.settings?.enableWebGLRendering===!1)return!1;let n=e.lineWebGLSurface;if(!n||!n.isAvailable())return!1;n.clear();let r=!0;t.showBand&&t.bandUpperPoints.length>=2&&t.bandLowerPoints.length>=2&&(n.clear(),r=n.drawFilledBand({upperPoints:t.bandUpperPoints,lowerPoints:t.bandLowerPoints},ha(G.BAND_FILL),e.scrollLeft),r&&ga(e,n,ma(G.BAND_FILL))),n.clear();let i=[];return t.showUpper&&t.upperPoints.length>=2&&i.push({points:t.upperPoints,width:pa,color:G.UPPER}),t.showMiddle&&t.middlePoints.length>=2&&i.push({points:t.middlePoints,width:pa,color:G.MIDDLE}),t.showLower&&t.lowerPoints.length>=2&&i.push({points:t.lowerPoints,width:pa,color:G.LOWER}),i.length>0&&(r=n.drawLineStrips(i,e.scrollLeft)),r?(ga(e,n),n.clear(),!0):(n.clear(),!1)}function va(){let e=null,t=[],n=[],r=[],i=[],a=[],o=0;function s(e){if(!(e<=o)){for(let s=o;s<e;s++)t[s]={x:0,y:0},n[s]={x:0,y:0},r[s]={x:0,y:0},i[s]={x:0,y:0},a[s]={x:0,y:0};o=e}}return{name:`boll`,version:`2.2.0`,description:`布林带渲染器(无缓存优化)`,debugName:`BOLL布林带`,paneId:`main`,priority:R.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[ta]},draw(o){let{ctx:c,pane:l,data:u,range:d,scrollLeft:f,dpr:p,kLineCenters:m}=o,h=u,g=e?.getSharedState(ta);if(!g||g.visibleMin>g.visibleMax||g.series.length===0)return;let{period:_,showUpper:v,showMiddle:y,showLower:b,showBand:x}=g.params,S=g.series;if(h.length<_)return;let C=Math.max(d.start,_-1),w=Math.min(d.end,h.length);if(w<=C)return;let T=d.start,E=l.yAxis.priceToY.bind(l.yAxis),D=w-C;s(D);let O=Array(D),k=Array(D),A=Array(D),j=x?Array(D):[],M=x?Array(D):[],N=0,P=0,F=0,I=0;for(let e=C;e<w;e++){let o=S[e];if(!o)continue;let s=m[e-T];if(s===void 0)continue;let c=X(E(o.upper),p),l=X(E(o.middle),p),u=X(E(o.lower),p),d=t[N];d.x=s,d.y=c,O[N++]=d,d=n[P],d.x=s,d.y=l,k[P++]=d,d=r[F],d.x=s,d.y=u,A[F++]=d,x&&(d=i[I],d.x=s,d.y=c,j[I]=d,d=a[I],d.x=s,d.y=u,M[I]=d,I++)}if(O.length=N,k.length=P,A.length=F,x&&(j.length=I,M.length=I),_a(o,{showUpper:v,showMiddle:y,showLower:b,showBand:x,upperPoints:O,middlePoints:k,lowerPoints:A,bandUpperPoints:j,bandLowerPoints:M}))return;if(c.save(),c.translate(-f,0),c.lineWidth=pa,c.lineJoin=`round`,c.lineCap=`round`,x&&j.length>=2){let e=new Path2D;e.moveTo(j[0].x,j[0].y);for(let t=1;t<j.length;t++)e.lineTo(j[t].x,j[t].y);for(let t=M.length-1;t>=0;t--)e.lineTo(M[t].x,M[t].y);e.closePath(),c.fillStyle=G.BAND_FILL,c.fill(e)}let L=(e,t)=>{if(!(e.length<2)){c.beginPath(),c.strokeStyle=t,c.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)c.lineTo(e[t].x,e[t].y);c.stroke()}};v&&L(O,G.UPPER),y&&L(k,G.MIDDLE),b&&L(A,G.LOWER),c.restore()},getConfig(){let t=e?.getSharedState(ta);return t?{...t.params}:{}},setConfig(e){}}}function ya(e,t,n){let r=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,r.maxPrice.toFixed(6),r.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2)].join(`|`)}function ba(){let e=null,t=``,n=[],r=[];function i(){t=``,n=[],r=[]}return{name:`expma`,version:`2.1.0`,description:`EXPMA 指数平滑移动平均线渲染器(带绘制缓存)`,debugName:`EXPMA`,paneId:`main`,priority:R.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[na]},draw(a){let{ctx:o,pane:s,data:c,range:l,scrollLeft:u,dpr:d,kLineCenters:f,lineWebGLSurface:p}=a,m=c,h=e?.getSharedState(na);if(!h||h.visibleMin>h.visibleMax){i();return}if(h.series.length===0||m.length<2){i();return}let g=h.series,_=l.start,v=Math.min(l.end,m.length),y=ya(l,f,s);if(t!==y){t=y,n=[],r=[];for(let e=_;e<v;e++){let t=g[e];if(!t)continue;let i=f[e-l.start];i!==void 0&&(n.push({x:i,y:s.yAxis.priceToY(t.fast)}),r.push({x:i,y:s.yAxis.priceToY(t.slow)}))}}let b=a.settings?.enableWebGLRendering!==!1,x=!1;if(b&&p?.isAvailable()){let e=[];n.length>=2&&e.push({points:n,width:1,color:Be.FAST}),r.length>=2&&e.push({points:r,width:1,color:Be.SLOW}),e.length>0&&p.drawLineStrips(e,u)&&(x=!0,p.compositeTo(o,{imageSmoothingEnabled:!1}))}if(!x){if(o.save(),o.translate(-u,0),o.lineWidth=1,o.lineJoin=`round`,o.lineCap=`round`,n.length>=2){o.strokeStyle=Be.FAST,o.beginPath(),o.moveTo(n[0].x,n[0].y);for(let e=1;e<n.length;e++){let t=n[e];o.lineTo(t.x,t.y)}o.stroke()}if(r.length>=2){o.strokeStyle=Be.SLOW,o.beginPath(),o.moveTo(r[0].x,r[0].y);for(let e=1;e<r.length;e++){let t=r[e];o.lineTo(t.x,t.y)}o.stroke()}o.restore()}},getConfig(){let t=e?.getSharedState(na);return t?{...t.params}:{}},setConfig(e){}}}function xa(e){let t=e.match(/^rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)$/i);if(!t)return 1;let n=Number(t[1]);return Number.isFinite(n)?n:1}function Sa(e){return e.replace(/,\s*[\d.]+\s*\)$/i,`, 1)`)}function Ca(e,t,n=1){t.compositeTo(e.ctx,{alpha:n,imageSmoothingEnabled:!1})}function wa(e,t){if(e.settings?.enableWebGLRendering===!1)return!1;let n=e.lineWebGLSurface;if(!n||!n.isAvailable())return!1;n.clear();let r=!0;t.upperPoints.length>=2&&t.lowerPoints.length>=2&&(n.clear(),r=n.drawFilledBand({upperPoints:t.upperPoints,lowerPoints:t.lowerPoints},Sa(J.BAND_FILL),e.scrollLeft),r&&Ca(e,n,xa(J.BAND_FILL))),n.clear();let i=[];return t.upperPoints.length>=2&&i.push({points:t.upperPoints,width:1,color:J.UPPER}),t.middlePoints.length>=2&&i.push({points:t.middlePoints,width:1,color:J.MIDDLE}),t.lowerPoints.length>=2&&i.push({points:t.lowerPoints,width:1,color:J.LOWER}),i.length>0&&(r=n.drawLineStrips(i,e.scrollLeft)),r?(Ca(e,n),n.clear(),!0):(n.clear(),!1)}function Ta(){let e=null;return{name:`ene`,version:`2.1.0`,description:`ENE 轨道线渲染器(无状态)`,debugName:`ENE轨道线`,paneId:`main`,priority:R.INDICATOR,onInstall(t){e=t},getDeclaredNamespaces(){return[ra]},draw(t){let{ctx:n,pane:r,data:i,range:a,scrollLeft:o,dpr:s,kLineCenters:c}=t,l=i,u=e?.getSharedState(ra);if(!u||u.visibleMin>u.visibleMax||u.series.length===0)return;let{period:d}=u.params,f=u.series;if(l.length<d)return;let p=Math.max(a.start,d-1),m=Math.min(a.end,l.length),h=[],g=[],_=[];for(let e=p;e<m;e++){let t=f[e];if(!t)continue;let n=c[e-a.start];n!==void 0&&(h.push({x:n,y:X(r.yAxis.priceToY(t.upper),s)}),g.push({x:n,y:X(r.yAxis.priceToY(t.middle),s)}),_.push({x:n,y:X(r.yAxis.priceToY(t.lower),s)}))}if(wa(t,{upperPoints:h,middlePoints:g,lowerPoints:_}))return;if(n.save(),n.translate(-o,0),n.fillStyle=J.BAND_FILL,n.beginPath(),h.length>0){n.moveTo(h[0].x,h[0].y);for(let e=1;e<h.length;e++){let t=h[e];n.lineTo(t.x,t.y)}for(let e=_.length-1;e>=0;e--){let t=_[e];n.lineTo(t.x,t.y)}}n.closePath(),n.fill(),n.lineWidth=1,n.lineJoin=`round`,n.lineCap=`round`;let v=(e,t)=>{if(e.length!==0){n.strokeStyle=t,n.beginPath(),n.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++){let r=e[t];n.lineTo(r.x,r.y)}n.stroke()}};v(h,J.UPPER),v(g,J.MIDDLE),v(_,J.LOWER),n.restore()},getConfig(){let t=e?.getSharedState(ra);return t?{...t.params}:{}},setConfig(e){}}}var Ea=`"Trebuchet MS", Roboto, Ubuntu, sans-serif`;function Da(e,t){return`${t?.bold?`bold `:``}${e}px ${Ea}`}function Oa(e,t){e.font!==t&&(e.font=t)}var ka=new Map,Aa=512;function ja(e,t){let n=`${e.font}\n${t}`,r=ka.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return ka.size>=Aa&&ka.clear(),ka.set(n,i),i}function Ma(e){let t={yPaddingPx:e.yPaddingPx,indicators:{MA:{enabled:!0,params:{}},BOLL:{enabled:!1,params:{period:20,multiplier:2}},EXPMA:{enabled:!1,params:{fastPeriod:12,slowPeriod:50}},ENE:{enabled:!1,params:{period:10,deviation:11}}}},n=null;return{name:`mainIndicatorLegend`,version:`2.1.0`,description:`主图指标图例渲染器(MA 数据来自 StateStore)`,debugName:`主图指标图例`,paneId:`main`,priority:R.FOREGROUND,enabled:!0,onInstall(e){n=e},getDeclaredNamespaces(){return[ea,ta,na,ra]},draw(e){let{ctx:r,data:i,range:a,crosshairIndex:o}=e,s=i;if(!s.length)return;r.save(),Oa(r,Da(12)),r.textAlign=`left`;let c=o??Math.min(a.end-1,s.length-1),l=[];t.indicators.MA?.enabled&&l.push({draw:e=>{let i=[],a=n?.getSharedState(ea);if(a&&a.visibleMin<=a.visibleMax)for(let e of a.enabledPeriods){let t=`MA${e}`,n=a.series[e]?.[c];i.push({label:`MA${e}`,color:Ne[t]||Ne.MA5,value:n})}if(i.length>0){let n=12,a=t.yPaddingPx/2+12+e*18;r.fillStyle=U.NEUTRAL,r.fillText(`MA`,n,a),n+=ja(r,`MA`)+10;for(let e of i){let t=typeof e.value==`number`?` ${e.value.toFixed(2)}`:``,i=`${e.label}${t}`;r.fillStyle=e.color,r.fillText(i,n,a),n+=ja(r,i)+10}}}}),t.indicators.BOLL?.enabled&&l.push({draw:e=>{let i=n?.getSharedState(ta),a=i?.series[c],o=i?.params.period??20,s=i?.params.multiplier??2,l=12,u=t.yPaddingPx/2+12+e*18,d=`BOLL(${o},${s})`;if(r.fillStyle=U.NEUTRAL,r.fillText(d,l,u),l+=ja(r,d)+10,a){let e=`上轨:${a.upper.toFixed(2)}`;r.fillStyle=G.UPPER,r.fillText(e,l,u),l+=ja(r,e)+10;let t=`中轨:${a.middle.toFixed(2)}`;r.fillStyle=G.MIDDLE,r.fillText(t,l,u),l+=ja(r,t)+10;let n=`下轨:${a.lower.toFixed(2)}`;r.fillStyle=G.LOWER,r.fillText(n,l,u)}}}),t.indicators.EXPMA?.enabled&&l.push({draw:e=>{let i=n?.getSharedState(na),a=i?.series[c],o=i?.params.fastPeriod??12,s=i?.params.slowPeriod??50,l=12,u=t.yPaddingPx/2+12+e*18,d=`EXPMA(${o},${s})`;if(r.fillStyle=U.NEUTRAL,r.fillText(d,l,u),l+=ja(r,d)+10,a){let e=`快:${a.fast.toFixed(2)}`;r.fillStyle=Be.FAST,r.fillText(e,l,u),l+=ja(r,e)+10;let t=`慢:${a.slow.toFixed(2)}`;r.fillStyle=Be.SLOW,r.fillText(t,l,u)}}}),t.indicators.ENE?.enabled&&l.push({draw:e=>{let i=n?.getSharedState(ra),a=i?.series[c],o=i?.params.period??10,s=i?.params.deviation??11,l=12,u=t.yPaddingPx/2+12+e*18,d=`ENE(${o},${s})`;if(r.fillStyle=U.NEUTRAL,r.fillText(d,l,u),l+=ja(r,d)+10,a){let e=`上轨:${a.upper.toFixed(2)}`;r.fillStyle=J.UPPER,r.fillText(e,l,u),l+=ja(r,e)+10;let t=`中轨:${a.middle.toFixed(2)}`;r.fillStyle=J.MIDDLE,r.fillText(t,l,u),l+=ja(r,t)+10;let n=`下轨:${a.lower.toFixed(2)}`;r.fillStyle=J.LOWER,r.fillText(n,l,u)}}}),l.forEach((e,t)=>e.draw(t)),r.restore()},getConfig(){return{yPaddingPx:t.yPaddingPx,indicators:{...t.indicators}}},setConfig(e){if(typeof e.yPaddingPx==`number`&&(t.yPaddingPx=e.yPaddingPx),e.indicators&&typeof e.indicators==`object`)for(let[n,r]of Object.entries(e.indicators))t.indicators[n]||(t.indicators[n]={enabled:!1,params:{}}),r.enabled!==void 0&&(t.indicators[n].enabled=r.enabled),r.params&&(t.indicators[n].params=r.params)}}}function Na(e={}){let{paneId:t=`sub`,config:n={}}=e,r=ui(t),i=null,a={fastPeriod:12,slowPeriod:26,signalPeriod:9,showDIF:!0,showDEA:!0,showBAR:!0,...n},o=``,s=[],c=[];function l(){o=``,s=[],c=[]}function u(e,t,n,r,i){return n.yAxis.getDisplayRange(),[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.toFixed(6),r.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),a.showDIF,a.showDEA].join(`|`)}return{name:`macd_${t}`,version:`1.0.0`,description:`MACD 指标渲染器`,debugName:`MACD`,paneId:t,priority:R.INDICATOR,onInstall(e){i=e},getDeclaredNamespaces(){return[r]},draw(e){let{ctx:t,pane:n,data:l,range:d,scrollLeft:f,dpr:p,kLineCenters:m,lineWebGLSurface:h}=e,g=l,_=i?.getSharedState(r);if(!_||_.visibleMin>_.visibleMax||g.length<a.slowPeriod)return;let v=_.series;if(!v||v.length===0)return;let y=_.visibleMin,b=_.visibleMax,x=Math.max(.05,(b-y)*.1);y-=x,b+=x,b-y;let S=n.yAxis.getDisplayRange({minPrice:y,maxPrice:b}),C=S.minPrice,w=S.maxPrice,T=w-C||1,E=n.height-(0-C)/T*n.height,D=Math.max(d.start,a.slowPeriod-1),O=Math.min(d.end,g.length);if(a.showBAR){let r=Math.round(E*p)/p,i=Math.max(1,O-D),a=new Float32Array(i*4),o=new Float32Array(i*4),s=new Float32Array(i*4),c=new Float32Array(i*4),l=0,u=0,m=0,h=0;for(let t=D;t<O;t++){let i=v[t];if(!i)continue;let f=e.kBarRects[t-d.start];if(!f)continue;let g=n.height-(i.macd-C)/T*n.height,_=i.macd>=0,y=t>0?v[t-1]:null,b=y?i.macd>=y.macd:!0,x=Math.round(g*p)/p,S=1/p,w,E;if(_){let e=r-x,t=e<=0?S:Math.max(e,S),n=e<=0?r-S:r-t;b?(w=a,E=l++):(w=o,E=u++);let i=E*4;w[i]=f.x,w[i+1]=n,w[i+2]=f.width,w[i+3]=t}else{let e=x-r,t=e<=0?S:Math.max(e,S);b?(w=c,E=h++):(w=s,E=m++);let n=E*4;w[n]=f.x,w[n+1]=r,w[n+2]=f.width,w[n+3]=t}}Pa(e,a,l,o,u,s,m,c,h)?La(t,e):Fa(t,f,a,l,o,u,s,m,c,h)}let k=u(d,m,n,C,w);if(o!==k){if(o=k,s=[],c=[],a.showDIF)for(let e=D;e<O;e++){let t=v[e];if(!t)continue;let r=m[e-d.start];if(r===void 0)continue;let i=n.height-(t.dif-C)/T*n.height;s.push({x:r,y:i})}if(a.showDEA)for(let e=D;e<O;e++){let t=v[e];if(!t)continue;let r=m[e-d.start];if(r===void 0)continue;let i=n.height-(t.dea-C)/T*n.height;c.push({x:r,y:i})}}let A=e.settings?.enableWebGLRendering!==!1,j=!1;if(A&&h?.isAvailable()){let e=[];a.showDIF&&s.length>=2&&e.push({points:s,width:1,color:K.DIF}),a.showDEA&&c.length>=2&&e.push({points:c,width:1,color:K.DEA}),e.length>0&&h.drawLineStrips(e,f)&&(j=!0,h.compositeTo(t,{imageSmoothingEnabled:!1}))}j||Ia(t,f,s,c,a)},onDataUpdate(){l()},getConfig(){return{...a}},setConfig(e){let t=!1;`fastPeriod`in e&&e.fastPeriod!==a.fastPeriod&&l(),`slowPeriod`in e&&e.slowPeriod!==a.slowPeriod&&l(),`signalPeriod`in e&&e.signalPeriod!==a.signalPeriod&&l(),`showDIF`in e&&e.showDIF!==a.showDIF&&(t=!0),`showDEA`in e&&e.showDEA!==a.showDEA&&(t=!0),Object.assign(a,e),t&&l()}}}function Pa(e,t,n,r,i,a,o,s,c){if(e.settings?.enableWebGLRendering===!1)return!1;let l=e.candleWebGLSurface;if(!l||!l.isAvailable())return!1;l.clear();let u=n===0||l.drawRectBuffer(t.subarray(0,n*4),n,K.BAR_UP,e.scrollLeft),d=i===0||l.drawRectBuffer(r.subarray(0,i*4),i,K.BAR_UP_LIGHT,e.scrollLeft),f=o===0||l.drawRectBuffer(a.subarray(0,o*4),o,K.BAR_DOWN,e.scrollLeft),p=c===0||l.drawRectBuffer(s.subarray(0,c*4),c,K.BAR_DOWN_LIGHT,e.scrollLeft);return u&&d&&f&&p}function Fa(e,t,n,r,i,a,o,s,c,l){e.save(),e.translate(-t,0),e.fillStyle=K.BAR_UP;for(let t=0;t<r;t++){let r=t*4;e.fillRect(n[r],n[r+1],n[r+2],n[r+3])}e.fillStyle=K.BAR_UP_LIGHT;for(let t=0;t<a;t++){let n=t*4;e.fillRect(i[n],i[n+1],i[n+2],i[n+3])}e.fillStyle=K.BAR_DOWN;for(let t=0;t<s;t++){let n=t*4;e.fillRect(o[n],o[n+1],o[n+2],o[n+3])}e.fillStyle=K.BAR_DOWN_LIGHT;for(let t=0;t<l;t++){let n=t*4;e.fillRect(c[n],c[n+1],c[n+2],c[n+3])}e.restore()}function Ia(e,t,n,r,i){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,i.showDIF&&n.length>=2){e.strokeStyle=K.DIF,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(i.showDEA&&r.length>=2){e.strokeStyle=K.DEA,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function La(e,t){let n=t.candleWebGLSurface;n&&n.compositeTo(e)}function Ra(e,t,n,r,i,a=`sub_MACD`){let o=i.getSharedState(ui(a));if(!o)return null;let s=o.series[e];return s?{name:`MACD`,params:[t,n,r],values:[{label:`DIF`,value:s.dif,color:K.DIF},{label:`DEA`,value:s.dea,color:K.DEA},{label:`MACD`,value:s.macd,color:s.macd>=0?K.BAR_UP:K.BAR_DOWN}]}:null}function za(e={}){let{paneId:t=`sub`}=e,n=null,r=``,i=[],a=[],o=[],s=null,c=null,l=``;function u(){r=``,i=[],a=[],o=[]}function d(e,t){return(!s||s.width!==e||s.height!==t)&&(s=document.createElement(`canvas`),s.width=e,s.height=t,c=s.getContext(`2d`),l=``),{canvas:s,ctx:c}}function f(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function p(e,t,n,r,i,a){let o=i-r||1,s=X(n-(80-r)/o*n,a),c=X(n-(50-r)/o*n,a),l=X(n-(20-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.lineWidth=1.1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.moveTo(0,c),e.lineTo(t,c),e.moveTo(0,l),e.lineTo(t,l),e.stroke(),e.restore()}function m(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showRSI1,r.showRSI2,r.showRSI3].join(`|`)}return{name:`rsi_${t}`,version:`2.1.0`,description:`RSI 相对强弱指标渲染器(WebGL + Canvas2D 回退)`,debugName:`RSI`,paneId:t,priority:R.MAIN,onInstall(e){n=e},getDeclaredNamespaces(){return[Yr(t)]},draw(e){let{ctx:c,pane:h,range:g,scrollLeft:_,dpr:v,kLineCenters:y,lineWebGLSurface:b}=e,x=Yr(t),S=n?.getSharedState(x);if(!S||S.visibleMin>S.visibleMax){u();return}let{valueMin:C,valueMax:w,params:T,series:E}=S,D=h.yAxis.getDisplayRange({minPrice:C,maxPrice:w}),O=D.minPrice,k=D.maxPrice,A=k-O||1,j=e.paneWidth,M=h.height,N=f(j,M,O,k,v);if(l!==N){l=N;let{ctx:e}=d(Math.ceil(j*v),Math.ceil(M*v));p(e,j,M,O,k,v)}s&&c.drawImage(s,0,0,j,M);let P=Math.max(g.start,T.period1),F=Math.min(g.end,y.length+g.start),I=m(g,y,h,T);if(r!==I){r=I;let e=M,t=e/A,n=g.start,s=r=>{let i=[];for(let a=P;a<F;a++){let o=r[a];if(o===void 0)continue;let s=y[a-n];s!==void 0&&i.push({x:s,y:e-(o-O)*t})}return i};i=T.showRSI1&&E[T.period1]?s(E[T.period1]):[],a=T.showRSI2&&E[T.period2]?s(E[T.period2]):[],o=T.showRSI3&&E[T.period3]?s(E[T.period3]):[]}let L=e.settings?.enableWebGLRendering!==!1,ee=!1;if(L&&b?.isAvailable()){let e=[];T.showRSI1&&i.length>=2&&e.push({points:i,width:1,color:q.RSI1}),T.showRSI2&&a.length>=2&&e.push({points:a,width:1,color:q.RSI2}),T.showRSI3&&o.length>=2&&e.push({points:o,width:1,color:q.RSI3}),e.length>0&&b.drawLineStrips(e,_)&&(ee=!0,b.compositeTo(c,{imageSmoothingEnabled:!1}))}ee||Ba(c,_,i,a,o,T)},getConfig(){let e=Yr(t),r=n?.getSharedState(e);return r?{...r.params}:{}},setConfig(e){}}}function Ba(e,t,n,r,i,a){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,a.showRSI1&&n.length>=2){e.strokeStyle=q.RSI1,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(a.showRSI2&&r.length>=2){e.strokeStyle=q.RSI2,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}if(a.showRSI3&&i.length>=2){e.strokeStyle=q.RSI3,e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++){let n=i[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function Va(e,t,n,r,i,a=`sub_RSI`){let o=Yr(a),s=i.getSharedState(o);if(!s)return null;let c=s.series[t]?.[e],l=s.series[n]?.[e],u=s.series[r]?.[e],d=[];return c!==void 0&&d.push({label:`RSI${t}`,value:c,color:q.RSI1}),l!==void 0&&d.push({label:`RSI${n}`,value:l,color:q.RSI2}),u!==void 0&&d.push({label:`RSI${r}`,value:u,color:q.RSI3}),d.length===0?null:{name:`RSI`,params:[t,n,r],values:d}}function Ha(e={}){let{paneId:t=`sub`}=e,n=Zr(t),r=null,i=``,a=[];function o(){i=``,a=[]}function s(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showCCI,r.period].join(`|`)}return{name:`cci_${t}`,version:`2.1.0`,description:`CCI 顺势指标渲染器(WebGL + Canvas2D 回退)`,debugName:`CCI`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:c,range:l,scrollLeft:u,dpr:d,kLineCenters:f,lineWebGLSurface:p}=e,m=r?.getSharedState(n);if(!m||m.visibleMin>m.visibleMax){o();return}let{valueMin:h,valueMax:g,params:_,series:v}=m;g-h;let y=c.yAxis.getDisplayRange({minPrice:h,maxPrice:g}),b=y.minPrice,x=y.maxPrice-b||1,S=c.height-(0-b)/x*c.height;t.save(),t.translate(-u,0);let C=c.height-(100-b)/x*c.height,w=c.height-(-100-b)/x*c.height,T=u,E=u+e.paneWidth;t.strokeStyle=Fe.OVERBOUGHT,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(T,C),t.lineTo(E,C),t.stroke(),t.strokeStyle=Fe.OVERSOLD,t.beginPath(),t.moveTo(T,w),t.lineTo(E,w),t.stroke(),t.strokeStyle=`rgba(0, 0, 0, 0.1)`,t.beginPath(),t.moveTo(T,S),t.lineTo(E,S),t.stroke(),t.setLineDash([]),t.restore();let D=Math.max(l.start,_.period-1),O=Math.min(l.end,v.length),k=s(l,f,c,_);if(i!==k&&(i=k,a=[],_.showCCI))for(let e=D;e<O;e++){let t=v[e];if(t===void 0)continue;let n=f[e-l.start];if(n===void 0)continue;let r=c.height-(t-b)/x*c.height;a.push({x:n,y:r})}let A=e.settings?.enableWebGLRendering!==!1,j=!1;A&&p?.isAvailable()&&_.showCCI&&a.length>=2&&p.drawLineStrips([{points:a,width:1,color:Fe.CCI}],u)&&(j=!0,p.compositeTo(t,{imageSmoothingEnabled:!1})),j||Ua(t,u,a,_)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function Ua(e,t,n,r){if(!(!r.showCCI||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Fe.CCI,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function Wa(e,t,n,r=`sub_CCI`){let i=n.getSharedState(Zr(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`CCI`,params:[t],values:[{label:`CCI`,value:a,color:Fe.CCI}]}}function Ga(e={}){let{paneId:t=`sub`}=e,n=$r(t),r=null,i=``,a=[],o=[],s=null,c=null,l=``;function u(){i=``,a=[],o=[]}function d(e,t){return(!s||s.width!==e||s.height!==t)&&(s=document.createElement(`canvas`),s.width=e,s.height=t,c=s.getContext(`2d`),l=``),{canvas:s,ctx:c}}function f(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function p(e,t,n,r,i,a){let o=i-r||1,s=X(n-(80-r)/o*n,a),c=X(n-(20-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.moveTo(0,c),e.lineTo(t,c),e.stroke(),e.restore()}function m(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showK,r.showD,r.n,r.m].join(`|`)}return{name:`stoch_${t}`,version:`2.1.0`,description:`STOCH 随机指标渲染器(WebGL + Canvas2D 回退)`,debugName:`STOCH`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:c,range:h,scrollLeft:g,dpr:_,kLineCenters:v,lineWebGLSurface:y}=e,b=r?.getSharedState(n);if(!b||b.visibleMin>b.visibleMax){u();return}let{valueMin:x,valueMax:S,params:C,series:w}=b,T=c.yAxis.getDisplayRange({minPrice:x,maxPrice:S}),E=T.minPrice,D=T.maxPrice,O=D-E||1,k=e.paneWidth,A=c.height,j=f(k,A,E,D,_);if(l!==j){l=j;let{ctx:e}=d(Math.ceil(k*_),Math.ceil(A*_));p(e,k,A,E,D,_)}s&&t.drawImage(s,0,0,k,A);let M=Math.max(h.start,C.n+C.m-2),N=Math.min(h.end,w.length),P=m(h,v,c,C);if(i!==P){i=P;let e=A,t=e/O,n=h.start;if(C.showK){let r=[];for(let i=M;i<N;i++){let a=w[i];if(!a)continue;let o=v[i-n];o!==void 0&&r.push({x:o,y:e-(a.k-E)*t})}a=r}else a=[];if(C.showD){let r=[];for(let i=M;i<N;i++){let a=w[i];if(!a)continue;let o=v[i-n];o!==void 0&&r.push({x:o,y:e-(a.d-E)*t})}o=r}else o=[]}let F=e.settings?.enableWebGLRendering!==!1,I=!1;if(F&&y?.isAvailable()){let e=[];C.showK&&a.length>=2&&e.push({points:a,width:1,color:Ie.K}),C.showD&&o.length>=2&&e.push({points:o,width:1,color:Ie.D}),e.length>0&&y.drawLineStrips(e,g)&&(I=!0,y.compositeTo(t,{imageSmoothingEnabled:!1}))}I||Ka(t,g,a,o,C)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function Ka(e,t,n,r,i){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,i.showK&&n.length>=2){e.strokeStyle=Ie.K,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(i.showD&&r.length>=2){e.strokeStyle=Ie.D,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function qa(e,t,n,r,i=`sub_STOCH`){let a=r.getSharedState($r(i));if(!a)return null;let o=a.series[e];if(!o||o.k===void 0)return null;let s=[];return a.params.showK&&s.push({label:`K`,value:o.k,color:Ie.K}),a.params.showD&&s.push({label:`D`,value:o.d,color:Ie.D}),s.length===0?null:{name:`STOCH`,params:[t,n],values:s}}function Ja(e={}){let{paneId:t=`sub`}=e,n=ti(t),r=null,i=``,a=[],o=null,s=null,c=``;function l(){i=``,a=[]}function u(e,t){return(!o||o.width!==e||o.height!==t)&&(o=document.createElement(`canvas`),o.width=e,o.height=t,s=o.getContext(`2d`),c=``),{canvas:o,ctx:s}}function d(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function f(e,t,n,r,i,a){let o=i-r||1,s=X(n-(0-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=Le.ZERO,e.lineWidth=1,e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.stroke(),e.restore()}function p(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showMOM,r.period].join(`|`)}return{name:`mom_${t}`,version:`2.1.0`,description:`MOM 动量指标渲染器(WebGL + Canvas2D 回退)`,debugName:`MOM`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:s,range:m,scrollLeft:h,dpr:g,kLineCenters:_,lineWebGLSurface:v}=e,y=r?.getSharedState(n);if(!y||y.visibleMin>y.visibleMax){l();return}let{valueMin:b,valueMax:x,params:S,series:C}=y,w=s.yAxis.getDisplayRange({minPrice:b,maxPrice:x}),T=w.minPrice,E=w.maxPrice,D=E-T||1,O=e.paneWidth,k=s.height,A=d(O,k,T,E,g);if(c!==A){c=A;let{ctx:e}=u(Math.ceil(O*g),Math.ceil(k*g));f(e,O,k,T,E,g)}o&&t.drawImage(o,0,0,O,k);let j=Math.max(m.start,S.period),M=Math.min(m.end,C.length),N=p(m,_,s,S);if(i!==N){i=N;let e=k,t=e/D,n=m.start;if(S.showMOM){let r=[];for(let i=j;i<M;i++){let a=C[i];if(a===void 0)continue;let o=_[i-n];o!==void 0&&r.push({x:o,y:e-(a-T)*t})}a=r}else a=[]}let P=e.settings?.enableWebGLRendering!==!1,F=!1;P&&v?.isAvailable()&&S.showMOM&&a.length>=2&&v.drawLineStrips([{points:a,width:1,color:Le.MOM}],h)&&(F=!0,v.compositeTo(t,{imageSmoothingEnabled:!1})),F||Ya(t,h,a,S)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function Ya(e,t,n,r){if(!(!r.showMOM||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Le.MOM,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function Xa(e,t,n,r=`sub_MOM`){let i=n.getSharedState(ti(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`MOM`,params:[t],values:[{label:`MOM`,value:a,color:Le.MOM}]}}function Za(e={}){let{paneId:t=`sub`}=e,n=ri(t),r=null,i=``,a=[],o=null,s=null,c=``;function l(){i=``,a=[]}function u(e,t){return(!o||o.width!==e||o.height!==t)&&(o=document.createElement(`canvas`),o.width=e,o.height=t,s=o.getContext(`2d`),c=``),{canvas:o,ctx:s}}function d(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function f(e,t,n,r,i,a){let o=i-r||1,s=X(n-(-20-r)/o*n,a),c=X(n-(-80-r)/o*n,a),l=X(n-(-50-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.lineWidth=1,e.setLineDash([4,4]),e.strokeStyle=Re.OVERBOUGHT,e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.stroke(),e.strokeStyle=Re.OVERSOLD,e.beginPath(),e.moveTo(0,c),e.lineTo(t,c),e.stroke(),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.beginPath(),e.moveTo(0,l),e.lineTo(t,l),e.stroke(),e.restore()}function p(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showWMSR,r.period].join(`|`)}return{name:`wmsr_${t}`,version:`2.1.0`,description:`WMSR 威廉指标渲染器(WebGL + Canvas2D 回退)`,debugName:`WMSR`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:s,range:m,scrollLeft:h,dpr:g,kLineCenters:_,lineWebGLSurface:v}=e,y=r?.getSharedState(n);if(!y||y.visibleMin>y.visibleMax){l();return}let{valueMin:b,valueMax:x,params:S,series:C}=y,w=s.yAxis.getDisplayRange({minPrice:b,maxPrice:x}),T=w.minPrice,E=w.maxPrice,D=E-T||1,O=e.paneWidth,k=s.height,A=d(O,k,T,E,g);if(c!==A){c=A;let{ctx:e}=u(Math.ceil(O*g),Math.ceil(k*g));f(e,O,k,T,E,g)}o&&t.drawImage(o,0,0,O,k);let j=Math.max(m.start,S.period-1),M=Math.min(m.end,C.length),N=p(m,_,s,S);if(i!==N){i=N;let e=k,t=e/D,n=m.start;if(S.showWMSR){let r=[];for(let i=j;i<M;i++){let a=C[i];if(a===void 0)continue;let o=_[i-n];o!==void 0&&r.push({x:o,y:e-(a-T)*t})}a=r}else a=[]}let P=e.settings?.enableWebGLRendering!==!1,F=!1;P&&v?.isAvailable()&&S.showWMSR&&a.length>=2&&v.drawLineStrips([{points:a,width:1,color:Re.WMSR}],h)&&(F=!0,v.compositeTo(t,{imageSmoothingEnabled:!1})),F||Qa(t,h,a,S)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function Qa(e,t,n,r){if(!(!r.showWMSR||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Re.WMSR,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function $a(e,t,n,r=`sub_WMSR`){let i=n.getSharedState(ri(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`WMSR`,params:[t],values:[{label:`WMSR`,value:a,color:Re.WMSR}]}}function eo(e={}){let{paneId:t=`sub`}=e,n=ai(t),r=null,i=``,a=[],o=[];function s(){i=``,a=[],o=[]}function c(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showKST,r.showSignal,r.roc1,r.roc2,r.roc3,r.roc4,r.signalPeriod].join(`|`)}return{name:`kst_${t}`,version:`2.1.0`,description:`KST 确知指标渲染器(WebGL + Canvas2D 回退)`,debugName:`KST`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:l,range:u,scrollLeft:d,dpr:f,kLineCenters:p,lineWebGLSurface:m}=e,h=r?.getSharedState(n);if(!h||h.visibleMin>h.visibleMax){s();return}let{valueMin:g,valueMax:_,params:v,series:y}=h;_-g;let b=l.yAxis.getDisplayRange({minPrice:g,maxPrice:_}),x=b.minPrice,S=b.maxPrice-x||1,C=l.height-(0-x)/S*l.height;t.save(),t.translate(-d,0);let w=d,T=d+e.paneWidth;t.strokeStyle=`rgba(0, 0, 0, 0.1)`,t.lineWidth=1,t.beginPath(),t.moveTo(w,C),t.lineTo(T,C),t.stroke(),t.restore();let E=Math.max(u.start,v.roc4+15+v.signalPeriod-1),D=Math.min(u.end,y.length),O=c(u,p,l,v);if(i!==O){if(i=O,a=[],o=[],v.showKST)for(let e=E;e<D;e++){let t=y[e];if(!t)continue;let n=p[e-u.start];if(n===void 0)continue;let r=l.height-(t.kst-x)/S*l.height;a.push({x:n,y:r})}if(v.showSignal)for(let e=E;e<D;e++){let t=y[e];if(!t)continue;let n=p[e-u.start];if(n===void 0)continue;let r=l.height-(t.signal-x)/S*l.height;o.push({x:n,y:r})}}let k=e.settings?.enableWebGLRendering!==!1,A=!1;if(k&&m?.isAvailable()){let e=[];v.showKST&&a.length>=2&&e.push({points:a,width:1,color:ze.KST}),v.showSignal&&o.length>=2&&e.push({points:o,width:1,color:ze.SIGNAL}),e.length>0&&m.drawLineStrips(e,d)&&(A=!0,m.compositeTo(t,{imageSmoothingEnabled:!1}))}A||to(t,d,a,o,v)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function to(e,t,n,r,i){if(e.save(),e.translate(-t,0),e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,i.showKST&&n.length>=2){e.strokeStyle=ze.KST,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke()}if(i.showSignal&&r.length>=2){e.strokeStyle=ze.SIGNAL,e.beginPath(),e.moveTo(r[0].x,r[0].y);for(let t=1;t<r.length;t++){let n=r[t];e.lineTo(n.x,n.y)}e.stroke()}e.restore()}function no(e,t,n,r,i,a,o,s=`sub_KST`){let c=o.getSharedState(ai(s));if(!c)return null;let l=c.series[e];if(!l)return null;let u=[];return c.params.showKST&&u.push({label:`KST`,value:l.kst,color:ze.KST}),c.params.showSignal&&u.push({label:`Signal`,value:l.signal,color:ze.SIGNAL}),u.length===0?null:{name:`KST`,params:[t,n,r,i,a],values:u}}function ro(e={}){let{paneId:t=`sub`}=e,n=si(t),r=null,i=``,a=[],o=null,s=null,c=``;function l(){i=``,a=[]}function u(e,t){return(!o||o.width!==e||o.height!==t)&&(o=document.createElement(`canvas`),o.width=e,o.height=t,s=o.getContext(`2d`),c=``),{canvas:o,ctx:s}}function d(e,t,n,r,i){return`${e}|${t}|${n.toFixed(4)}|${r.toFixed(4)}|${i}`}function f(e,t,n,r,i,a){let o=i-r||1,s=X(n-(80-r)/o*n,a),c=X(n-(20-r)/o*n,a);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.save(),e.scale(a,a),e.strokeStyle=`rgba(0, 0, 0, 0.1)`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(0,s),e.lineTo(t,s),e.moveTo(0,c),e.lineTo(t,c),e.stroke(),e.restore()}function p(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showFASTK,r.period].join(`|`)}return{name:`fastk_${t}`,version:`2.1.0`,description:`FASTK 快速随机指标渲染器(WebGL + Canvas2D 回退)`,debugName:`FASTK`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:s,range:m,scrollLeft:h,dpr:g,kLineCenters:_,lineWebGLSurface:v}=e,y=r?.getSharedState(n);if(!y||y.visibleMin>y.visibleMax){l();return}let{valueMin:b,valueMax:x,params:S,series:C}=y,w=s.yAxis.getDisplayRange({minPrice:b,maxPrice:x}),T=w.minPrice,E=w.maxPrice,D=E-T||1,O=e.paneWidth,k=s.height,A=d(O,k,T,E,g);if(c!==A){c=A;let{ctx:e}=u(Math.ceil(O*g),Math.ceil(k*g));f(e,O,k,T,E,g)}o&&t.drawImage(o,0,0,O,k);let j=Math.max(m.start,S.period-1),M=Math.min(m.end,C.length),N=p(m,_,s,S);if(i!==N){i=N;let e=k,t=e/D,n=m.start;if(S.showFASTK){let r=[];for(let i=j;i<M;i++){let a=C[i];if(a===void 0)continue;let o=_[i-n];o!==void 0&&r.push({x:o,y:e-(a-T)*t})}a=r}else a=[]}let P=e.settings?.enableWebGLRendering!==!1,F=!1;P&&v?.isAvailable()&&S.showFASTK&&a.length>=2&&v.drawLineStrips([{points:a,width:1,color:Ie.K}],h)&&(F=!0,v.compositeTo(t,{imageSmoothingEnabled:!1})),F||io(t,h,a,S)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function io(e,t,n,r){if(!(!r.showFASTK||n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=Ie.K,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function ao(e,t,n,r=`sub_FASTK`){let i=n.getSharedState(si(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`FASTK`,params:[t],values:[{label:`FASTK`,value:a,color:Ie.K}]}}var oo=`#d97706`;function so(e={}){let{paneId:t=`sub_ATR`}=e,n=fi(t),r=null,i=``,a=[];function o(){i=``,a=[]}function s(e,t,n,r){let i=n.yAxis.getDisplayRange();return[e.start,e.end,t.length,t[0]?.toFixed(2)??`n`,t[t.length-1]?.toFixed(2)??`n`,i.maxPrice.toFixed(6),i.minPrice.toFixed(6),n.yAxis.getPriceOffset().toFixed(6),n.yAxis.getScaleType(),n.height.toFixed(2),r.showATR,r.period].join(`|`)}return{name:`atr_${t}`,version:`1.0.0`,description:`ATR 平均真实波幅渲染器(Wilder 平滑)`,debugName:`ATR`,paneId:t,priority:R.MAIN,onInstall(e){r=e},getDeclaredNamespaces(){return[n]},draw(e){let{ctx:t,pane:c,range:l,scrollLeft:u,kLineCenters:d,lineWebGLSurface:f}=e,p=r?.getSharedState(n);if(!p||!p.params.showATR||p.visibleMin>p.visibleMax){o();return}let{valueMin:m,valueMax:h,params:g,series:_}=p;h-m;let v=c.yAxis.getDisplayRange({minPrice:m,maxPrice:h}),y=v.minPrice,b=v.maxPrice-y||1,x=c.height-(0-y)/b*c.height;t.save(),t.translate(-u,0),t.strokeStyle=`rgba(0, 0, 0, 0.1)`,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.moveTo(u,x),t.lineTo(u+e.paneWidth,x),t.stroke(),t.setLineDash([]),t.restore();let S=Math.max(l.start,g.period-1),C=Math.min(l.end,_.length),w=s(l,d,c,g);if(i!==w){i=w,a=[];for(let e=S;e<C;e++){let t=_[e];if(t===void 0)continue;let n=d[e-l.start];if(n===void 0)continue;let r=c.height-(t-y)/b*c.height;a.push({x:n,y:r})}}let T=e.settings?.enableWebGLRendering!==!1,E=!1;T&&f?.isAvailable()&&a.length>=2&&f.drawLineStrips([{points:a,width:1,color:oo}],u)&&(E=!0,f.compositeTo(t,{imageSmoothingEnabled:!1})),E||co(t,u,a)},getConfig(){return r?.getSharedState(n)?.params??{}},setConfig(){}}}function co(e,t,n){if(!(n.length<2)){e.save(),e.translate(-t,0),e.strokeStyle=oo,e.lineWidth=1,e.lineJoin=`round`,e.lineCap=`round`,e.beginPath(),e.moveTo(n[0].x,n[0].y);for(let t=1;t<n.length;t++){let r=n[t];e.lineTo(r.x,r.y)}e.stroke(),e.restore()}}function lo(e,t,n,r=`sub_ATR`){let i=n.getSharedState(fi(r));if(!i)return null;let a=i.series[e];return a===void 0?null:{name:`ATR`,params:[t],values:[{label:`ATR`,value:a,color:oo}]}}function uo(e){let{indicatorId:t,paneId:n}=e;switch(t){case`VOLUME`:return aa({paneId:n});case`MACD`:return Na({paneId:n});case`RSI`:return za({paneId:n});case`CCI`:return Ha({paneId:n});case`STOCH`:return Ga({paneId:n});case`MOM`:return Ja({paneId:n});case`WMSR`:return Za({paneId:n});case`KST`:return eo({paneId:n});case`FASTK`:return ro({paneId:n});case`ATR`:return so({paneId:n});default:throw Error(`Unknown indicator: ${t}`)}}function fo(e,t){return Math.max(3,Math.round(e/60)+1)}function po(e){let{height:t,paddingTop:n,paddingBottom:r,isMain:i,hideEdgeTicks:a}=e,o=n,s=Math.max(n,t-r),c=Math.max(0,s-o),l=fo(t,i),u=[];for(let e=0;e<l;e++){if(a&&(e===0||e===l-1))continue;let t=l<=1?0:e/(l-1),n=o+t*c;u.push({index:e,t,y:n})}return u}var mo=1e-10,ho=[1,1.2,1.5,2,2.5,3,4,5,6,7.5,8,10];function go(e){if(!Number.isFinite(e)||e<=0)return e;let t=10**Math.floor(Math.log10(e)),n=e/t,r=ho[0],i=1/0;for(let e of ho){let t=Math.abs(e-n);t<i&&(i=t,r=e)}return r*t}function _o(e){let{height:t,paddingTop:n,paddingBottom:r,valueMin:i,valueMax:a,targetCount:o}=e,s=Math.max(i,mo),c=Math.max(a,s*1.001),l=n,u=Math.max(n,t-r),d=Math.max(0,u-l);if(d<=0)return[];let f=Ce({minPrice:s,maxPrice:c}),p=V(s,f),m=V(c,f),h=m-p;if(!Number.isFinite(h)||Math.abs(h)<1e-10)return[];let g=Math.max(2,o),_=g<=1?d:d/(g-1),v=_*.6,y=_*.15,b=[],x=null;for(let e=0;e<g;e++){let t=g<=1?0:e/(g-1),n=l+t*d,r=Se(m-t*h,f),i=r,a=t,o=n,s=go(r);if(Number.isFinite(s)&&s>0){let e=(m-V(s,f))/h,t=l+e*d;Number.isFinite(t)&&Math.abs(t-n)<=y&&(i=s,a=e,o=t)}o<l-.5||o>u+.5||x!==null&&Math.abs(o-x)<v||(b.push({index:b.length,t:a,y:o,value:i}),x=o)}return b}var vo=``,yo=[];function bo(e){return`${e.valueMin}:${e.valueMax}:${e.height}:${e.paddingTop}:${e.paddingBottom}:${e.isMain}:${e.scaleType??`linear`}:${e.hideEdgeTicks??!1}`}function xo(e){let t=bo(e);if(t===vo)return yo;let{valueMin:n,valueMax:r,scaleType:i=`linear`}=e;if(i===`log`){if(n<=0)return xo({...e,scaleType:`linear`});let i=Math.max(n,mo),a=Math.max(r,i*1.001),{height:o,paddingTop:s,paddingBottom:c,isMain:l,hideEdgeTicks:u}=e,d=_o({height:o,paddingTop:s,paddingBottom:c,valueMin:i,valueMax:a,targetCount:Math.max(2,fo(o,l))});u&&d.length>2&&(d=d.slice(1,-1));let f=d.map((e,t)=>({...e,index:t}));return vo=t,yo=f,f}let a=po(e),o=fo(e.height,e.isMain),s=r-n||1,c=a.map(e=>{let t=r-s/Math.max(1,o-1)*e.index;return{...e,value:t}});return vo=t,yo=c,c}function So(e,t,n,r,i,a){let o=t-n||1,s=Math.max(1,r-i-a);return n+(1-(Math.min(Math.max(e,i),i+s)-i)/s)*o}var Co=new Map,wo=512;function To(e,t){let n=`${e.font}\n${t}`,r=Co.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return Co.size>=wo&&Co.clear(),Co.set(n,i),i}function Eo(e,t){let{x:n,y:r,width:i,height:a,crosshairX:o,timestamp:s,dpr:c,fontSize:l=16,paddingX:u=8}=t,d=st(s);e.save(),Oa(e,Da(l)),e.textBaseline=`middle`,e.textAlign=`center`;let f=Math.round(To(e,d)),p=Math.min(i,f+u*2),m=a,h=Math.min(Math.max(o,n+p/2),n+i-p/2),g=r+a/2,_=h-p/2,v=r;e.fillStyle=`rgba(0, 0, 0, 0.8)`,e.fillRect(Y(_,c),Y(v,c),Y(p,c),Y(m,c)),e.fillStyle=`#ffffff`,e.fillText(d,Y(h,c),X(g,c)),e.restore()}function Do(e,t){let{x:n,y:r,width:i,height:a,crosshairY:o,priceRange:s,yPaddingPx:c=0,dpr:l,bgColor:u=`rgba(0, 0, 0, 0.8)`,borderColor:d,textColor:f=`#ffffff`,fontSize:p=16,priceOffset:m=0,price:h,formatPrice:g}=t,_=Math.max(0,Math.min(c,Math.floor(a/2)-1)),{maxPrice:v,minPrice:y}=s,b=h??So(o-r,v,y,a,_,_)+m,x=g?g(b):b.toFixed(2);e.save(),Oa(e,Da(p)),e.textBaseline=`middle`,e.textAlign=`center`;let S=p+4,C=Math.min(Math.max(o,r+S/2),r+a-S/2),w=C-S/2,T=n,E=Y(w,l),D=i,O=Y(S,l);e.fillStyle=u,e.fillRect(T,E,D,O),d&&(e.strokeStyle=d,e.lineWidth=1,e.strokeRect(X(T,l),X(E,l),Math.max(0,D-1/l),Math.max(0,O-1/l)));let k=n+i/2;e.fillStyle=f,e.fillText(x,Y(k,l),X(C,l)),e.restore()}function Oo(e,t){let{x:n,y:r,width:i,height:a,data:o,scrollLeft:s,kWidth:c,kGap:l,startIndex:u,endIndex:d,dpr:f,bgColor:p=je.TRANSPARENT,textColor:m=Ae.SECONDARY,lineColor:h=Me.DARK,fontSize:g=12,paddingX:_=8,drawTopBorder:v=!0,drawBottomBorder:y=!0}=t,b=Math.round(c*f),x=b%2==0?b+1:b,S=Math.round(l*f),C=x+S,w=S,T=C/f,E=w/f,D=x/f;e.fillStyle=p,e.fillRect(n,r,i,a),v&&(e.strokeStyle=h,e.lineWidth=1,e.beginPath(),e.moveTo(n,X(r,f)),e.lineTo(n+i,X(r,f)),e.stroke()),y&&(e.strokeStyle=h,e.lineWidth=1,e.beginPath(),e.moveTo(n,X(r+a,f)),e.lineTo(n+i,X(r+a,f)),e.stroke()),e.textAlign=`center`,e.textBaseline=`middle`,e.fillStyle=m;let O=r+a/2,k=Da(g),A=Da(g,{bold:!0}),j=pt(o).filter(e=>e>=u&&e<d),M=null;for(let t of j){let n=o[t];if(!n)continue;let r=E+t*T+D/2-s,a=_,c=Math.max(_,i-_);if(r>=a&&r<=c){let t=Math.min(Math.max(r,a),c),{text:i,isYear:o}=it(n.timestamp);M!==o&&(Oa(e,o?A:k),M=o),e.fillText(i,Y(t,f),X(O,f))}}}function ko(e,t){let{x:n,y:r,width:i,height:a,priceY:o,price:s,dpr:c,bgColor:l=`rgba(0, 0, 0, 0.8)`,borderColor:u,textColor:d=`#ffffff`,fontSize:f=12}=t,p=s.toFixed(2);e.save(),Oa(e,Da(f)),e.textBaseline=`middle`,e.textAlign=`center`;let m=f+4,h=Math.min(Math.max(o,r+m/2),r+a-m/2),g=h-m/2,_=n,v=Y(g,c),y=i,b=Y(m,c);e.fillStyle=l,e.fillRect(_,v,y,b),u&&(e.strokeStyle=u,e.lineWidth=1,e.strokeRect(X(_,c),X(v,c),Math.max(0,y-1/c),Math.max(0,b-1/c)));let x=n+i/2;e.fillStyle=d,e.fillText(p,Y(x,c),X(h,c)),e.restore()}function Ao(e,t){let{x:n,y:r,width:i,height:a,labelX:o,timestamp:s,dpr:c,fontSize:l=12,paddingX:u=8}=t,d=st(s);e.save(),Oa(e,Da(l)),e.textBaseline=`middle`,e.textAlign=`center`;let f=Math.round(To(e,d)),p=Math.min(i,f+u*2),m=a,h=Math.min(Math.max(o,n+p/2),n+i-p/2),g=r+a/2,_=h-p/2,v=r;e.fillStyle=t.bgColor??`rgba(0, 0, 0, 0.8)`,e.fillRect(Y(_,c),Y(v,c),Y(p,c),Y(m,c)),e.fillStyle=t.textColor??`#ffffff`,e.fillText(d,Y(h,c),X(g,c)),e.restore()}var jo=`middle`,Mo=`center`;function No(e){let{ctx:t,dpr:n,axisWidth:r,height:i,paddingTop:a,paddingBottom:o,valueMin:s,valueMax:c,isMain:l,decimals:u=2,hideEdgeTicks:d=!0,scaleType:f=`linear`,formatLabel:p}=e;t.clearRect(0,0,r,i),Oa(t,Da(12)),t.textBaseline=jo,t.textAlign=Mo,t.fillStyle=Ae.SECONDARY;let m=Y(r/2,n),h=xo({height:i,paddingTop:a,paddingBottom:o,isMain:l,hideEdgeTicks:d,valueMin:s,valueMax:c,scaleType:f}),g=p??(e=>e.toFixed(u));for(let e=0;e<h.length;e++){let{y:r,value:i}=h[e];t.fillText(g(i),m,X(r,n))}}function Po(e){let{axisWidth:t,paneId:n,indicatorKey:r,label:i,decimals:a=2,yPaddingPx:o=0,scaleType:s=`linear`,getCrosshair:c,formatTickLabel:l,formatCrosshairLabel:u}=e,d=Z(r,n),f=null;return{name:`${r}Scale_${n}`,version:`1.0.0`,description:`${i} 刻度渲染器`,debugName:`${i}刻度`,paneId:n,priority:R.INDICATOR_SCALE,layer:`overlay`,onInstall(e){f=e},draw(e){let{yAxisCtx:n,pane:r,dpr:i}=e;if(!n||!f)return;let p=f.getSharedState(d);if(!p)return;let m=r.yAxis.getScaleType()??s,h=n.canvas?n.canvas.width/i:t,g=r.yAxis.getDisplayRange({minPrice:p.valueMin,maxPrice:p.valueMax});No({ctx:n,dpr:i,axisWidth:h,height:r.height,paddingTop:r.yAxis.getPaddingTop(),paddingBottom:r.yAxis.getPaddingBottom(),valueMin:g.minPrice,valueMax:g.maxPrice,isMain:!1,decimals:a,hideEdgeTicks:!1,scaleType:m,formatLabel:l});let _=c?.();if(!_||_.activePaneId!==r.id)return;let v=_.y-r.top,y=r.yAxis.getPaddingTop(),b=r.yAxis.getPaddingBottom(),x=y,S=Math.max(y,r.height-b),C=Math.max(1,S-x),w=(Math.min(Math.max(v,x),S)-x)/C,T=g.maxPrice-w*(g.maxPrice-g.minPrice);Do(n,{x:0,y:0,width:h,height:r.height,crosshairY:v,priceRange:g,yPaddingPx:o,dpr:i,fontSize:12,priceOffset:0,price:T,formatPrice:u})}}}var Fo=1e8;function Io(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`volume`,label:`VOL`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair,formatTickLabel:e=>`${(e/Fo).toFixed(2)}B`,formatCrosshairLabel:e=>`${(e/Fo).toFixed(2)}B`})}function Lo(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`macd`,label:`MACD`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Ro(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`rsi`,label:`RSI`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function zo(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`cci`,label:`CCI`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Bo(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`stoch`,label:`STOCH`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Vo(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`mom`,label:`MOM`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Ho(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`wmsr`,label:`WMSR`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Uo(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`kst`,label:`KST`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Wo(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`fastk`,label:`FASTK`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}function Go(e){return Po({axisWidth:e.axisWidth,paneId:e.paneId,indicatorKey:`atr`,label:`ATR`,decimals:2,yPaddingPx:e.yPaddingPx,getCrosshair:e.getCrosshair})}var Ko=class{entries=new Map;create(e,t,n,r){if(this.entries.has(t))return!0;let i=`${n.toLowerCase()}_${t}`,a=`${n.toLowerCase()}_scale_${t}`;if(e.hasPane(t)||e.upsertPane({id:t,ratio:1,visible:!0,role:`indicator`}),!e.getRenderer(i)){let i=uo({indicatorId:n,paneId:t});e.useRenderer(i,r)}return this.mountScaleRenderer(e,t,n,a),this.entries.set(t,{paneId:t,indicatorId:n,params:r,rendererName:i,scaleRendererName:a}),this.syncSchedulerConfig(e,t,n,r),e.getIndicatorScheduler().onSubPaneChanged(),!0}remove(e,t){let n=this.entries.get(t);n&&(e.removeRenderer(n.rendererName),e.removeRenderer(n.scaleRendererName),this.entries.delete(t),e.hasPane(t)&&e.removePaneDefinition(t),e.getIndicatorScheduler().onSubPaneChanged())}replaceIndicator(e,t,n,r){let i=this.entries.get(t);if(!i)return;i.indicatorId,e.removeRenderer(i.rendererName),e.removeRenderer(i.scaleRendererName);let a=`${n.toLowerCase()}_${t}`,o=`${n.toLowerCase()}_scale_${t}`,s=uo({indicatorId:n,paneId:t});e.useRenderer(s,r),this.mountScaleRenderer(e,t,n,o),this.syncSchedulerConfig(e,t,n,r),this.entries.set(t,{paneId:t,indicatorId:n,params:r,rendererName:a,scaleRendererName:o}),e.getIndicatorScheduler().onSubPaneChanged()}updateParams(e,t,n){let r=this.entries.get(t);r&&(r.params={...n},e.updateRendererConfig(r.rendererName,n),this.syncSchedulerConfig(e,t,r.indicatorId,r.params))}getByPaneId(e){return this.entries.get(e)}getAll(){return Array.from(this.entries.values())}getPaneIds(){return Array.from(this.entries.keys())}clear(e){for(let t of this.entries.values())e.removeRenderer(t.rendererName),e.removeRenderer(t.scaleRendererName);this.entries.clear(),e.getIndicatorScheduler().onSubPaneChanged()}syncSchedulerConfig(e,t,n,r){let i=e.getIndicatorScheduler();switch(n){case`MACD`:i.updateMACDConfig(r,t);break;case`RSI`:i.updateRSIConfig(r,t);break;case`CCI`:i.updateCCIConfig(r,t);break;case`STOCH`:i.updateSTOCHConfig(r,t);break;case`MOM`:i.updateMOMConfig(r,t);break;case`WMSR`:i.updateWMSRConfig(r,t);break;case`KST`:i.updateKSTConfig(r,t);break;case`FASTK`:i.updateFASTKConfig(r,t);break;case`ATR`:console.log(`[ATR-SubPane] syncSchedulerConfig: paneId=${t} params=${JSON.stringify(r)}`),i.updateATRConfig(r,t);break;case`VOLUME`:break}}mountScaleRenderer(e,t,n,r){if(e.getRenderer(r))return;let i={axisWidth:e.getOption().rightAxisWidth+(e.getOption().priceLabelWidth??60),paneId:t,yPaddingPx:e.getOption().yPaddingPx,getCrosshair:()=>{let t=e.interaction.crosshairPos,n=e.interaction.crosshairPrice,r=e.interaction.activePaneId;return t&&n!==null?{y:t.y,price:n,activePaneId:r}:null}},a;switch(n){case`VOLUME`:a=Io(i);break;case`MACD`:a=Lo(i);break;case`RSI`:a=Ro(i);break;case`CCI`:a=zo(i);break;case`STOCH`:a=Bo(i);break;case`MOM`:a=Vo(i);break;case`WMSR`:a=Ho(i);break;case`KST`:a=Uo(i);break;case`FASTK`:a=Wo(i);break;case`ATR`:a=Go(i);break;default:return}e.useRenderer(a)}},qo=8,Jo=6,Yo=class e{chart;activeTool=`cursor`;pendingAnchors=[];drawings=[];callbacks={};previewDrawingId=`__preview__`;dragState=null;selectedDrawingId=null;static SINGLE_ANCHOR_TOOLS=[`h-line`,`h-ray`,`v-line`,`crosshair-line`];static DOUBLE_ANCHOR_TOOLS=[`trend-line`,`ray`,`info-line`,`regression-channel`];static TRIPLE_ANCHOR_TOOLS=[`parallel-channel`,`flat-line`,`disjoint-channel`];constructor(e){this.chart=e}setCallbacks(e){this.callbacks=e}getActiveTool(){return this.activeTool}setTool(e){this.activeTool=e,this.pendingAnchors=[],this.removePreview(),this.dragState=null,this.setSelected(null),this.callbacks.onToolChange?.(e)}getDrawings(){return this.drawings}setDrawings(e){this.drawings=e,this.chart.setDrawings(e)}clear(){this.pendingAnchors=[],this.removePreview(),this.dragState=null,this.setSelected(null)}getSelectedDrawing(){return this.selectedDrawingId?this.drawings.find(e=>e.id===this.selectedDrawingId)??null:null}updateDrawingStyle(e,t){this.drawings=this.drawings.map(n=>n.id===e?{...n,style:{...n.style,...t}}:n),this.chart.setDrawings(this.drawings)}removeDrawing(e){this.drawings=this.drawings.filter(t=>t.id!==e),this.selectedDrawingId===e&&this.setSelected(null),this.chart.setDrawings(this.drawings)}onPointerMove(e,t){return this.dragState?this.handleDragMove(e,t):this.activeTool===`cursor`?!1:this.handlePreviewMove(e,t)}onPointerDown(t,n){if(this.activeTool===`cursor`)return this.handleCursorDown(t,n);let r=this.resolveAnchorFromPointer(t,n);if(!r)return!1;if(e.SINGLE_ANCHOR_TOOLS.includes(this.activeTool))return this.createSingleAnchorDrawing(r),!0;let i=e.DOUBLE_ANCHOR_TOOLS.includes(this.activeTool),a=e.TRIPLE_ANCHOR_TOOLS.includes(this.activeTool);if(!i&&!a)return!1;this.pendingAnchors.push(r);let o=i?2:3;return this.pendingAnchors.length>=o&&(this.createMultiAnchorDrawing(this.pendingAnchors),this.pendingAnchors=[]),!0}onPointerUp(e,t){return this.dragState?(this.dragState=null,!0):!1}handleCursorDown(e,t){let n=t.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top,a=this.hitTest(r,i);return a?(this.setSelected(a.drawing),this.dragState={drawingId:a.drawing.id,anchorIndex:`anchorIndex`in a?a.anchorIndex:void 0,snapshot:a.drawing.anchors.map(e=>({...e})),startMouse:{x:r,y:i}},!0):(this.setSelected(null),!1)}handleDragMove(e,t){if(!this.dragState)return!1;let n=this.drawings.find(e=>e.id===this.dragState.drawingId);if(!n)return this.dragState=null,!1;let r=this.resolveAnchorFromPointer(e,t);if(this.dragState.anchorIndex!==void 0){if(r){let e=this.dragState.anchorIndex;n.anchors[e]={...n.anchors[e],index:r.index,time:r.time,price:r.price},n.kind===`flat-line`&&e===1&&n.anchors.length>=3&&(n.anchors[2]={...n.anchors[2],index:r.index,time:r.time})}}else{let r=t.getBoundingClientRect(),i=e.clientX-r.left,a=e.clientY-r.top,o=i-this.dragState.startMouse.x,s=a-this.dragState.startMouse.y;for(let e=0;e<n.anchors.length;e++){let t=this.dragState.snapshot[e],r=this.anchorToScreen(t);if(!r)continue;let i=r.x+o,a=r.y+s,c=this.screenToAnchor(i,a);c&&(n.anchors[e]={...n.anchors[e],index:c.index,time:c.time,price:c.price})}}return this.chart.setDrawings([...this.drawings]),!0}handlePreviewMove(t,n){let r=this.resolveAnchorFromPointer(t,n);if(!r)return this.removePreview(),!1;let i=e.SINGLE_ANCHOR_TOOLS.includes(this.activeTool),a=e.DOUBLE_ANCHOR_TOOLS.includes(this.activeTool),o=e.TRIPLE_ANCHOR_TOOLS.includes(this.activeTool);if(!i&&!a&&!o)return!1;let s;if(i)s={id:this.previewDrawingId,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:r.index,time:r.time,price:r.price}],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`}};else if(a&&this.pendingAnchors.length>=1)s={id:this.previewDrawingId,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:this.pendingAnchors[0].index,time:this.pendingAnchors[0].time,price:this.pendingAnchors[0].price},{id:`${this.previewDrawingId}-b`,index:r.index,time:r.time,price:r.price}],params:this.activeTool===`regression-channel`?{sigma:2}:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`,...this.activeTool===`regression-channel`?{fillOpacity:.1}:{}}};else if(o){if(this.pendingAnchors.length===0)return!1;if(this.pendingAnchors.length===1)s={id:this.previewDrawingId,kind:`trend-line`,paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:this.pendingAnchors[0].index,time:this.pendingAnchors[0].time,price:this.pendingAnchors[0].price},{id:`${this.previewDrawingId}-b`,index:r.index,time:r.time,price:r.price}],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`}};else{let e=this.activeTool===`flat-line`?{id:`${this.previewDrawingId}-c`,index:this.pendingAnchors[1].index,time:this.pendingAnchors[1].time,price:r.price}:{id:`${this.previewDrawingId}-c`,index:r.index,time:r.time,price:r.price};s={id:this.previewDrawingId,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${this.previewDrawingId}-a`,index:this.pendingAnchors[0].index,time:this.pendingAnchors[0].time,price:this.pendingAnchors[0].price},{id:`${this.previewDrawingId}-b`,index:this.pendingAnchors[1].index,time:this.pendingAnchors[1].time,price:this.pendingAnchors[1].price},e],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`dashed`,fillOpacity:.1}}}}else return!1;return this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId),this.drawings=[...this.drawings,s],this.chart.setDrawings(this.drawings),!0}hitTest(e,t){let n=this.drawings.filter(e=>e.id!==this.previewDrawingId&&e.visible),r=new Map;for(let i of n){if(i.kind===`regression-channel`&&i.anchors.length>=2){let n=this.hitTestRegressionEndpoints(i,e,t,r);if(n)return n}for(let n=0;n<i.anchors.length;n++){let r=this.anchorToScreen(i.anchors[n]);if(r&&Math.hypot(e-r.x,t-r.y)<=qo)return{drawing:i,anchorIndex:n}}}for(let i of n){let n=this.getDrawingLineSegments(i,r);for(let r of n)if(Xo(e,t,r.a,r.b)<=Jo)return{drawing:i}}return null}getDrawingLineSegments(e,t){let n=this.chart.getViewport();if(!n)return[];if(e.kind===`regression-channel`)return this.getRegressionChannelGeometry(e,t)?.segments??[];if(e.anchors.length===1){let t=this.anchorToScreen(e.anchors[0]);if(!t)return[];let r=this.chart.getPaneRenderers().find(e=>e.getPane().id===`main`)?.getPane();if(!r)return[];let i=n.plotWidth,a=r.height;switch(e.kind){case`horizontal-line`:return[{a:{x:0,y:t.y},b:{x:i,y:t.y}}];case`horizontal-ray`:return[{a:t,b:{x:i,y:t.y}}];case`vertical-line`:return[{a:{x:t.x,y:0},b:{x:t.x,y:a}}];case`cross-line`:return[{a:{x:0,y:t.y},b:{x:i,y:t.y}},{a:{x:t.x,y:0},b:{x:t.x,y:a}}];default:return[]}}let r=e.anchors.map(e=>this.anchorToScreen(e)).filter(Boolean);if(r.length<2)return[];let i=[];if(r.length===2){let t=r[0],a=r[1],o=a.x-t.x,s=a.y-t.y,c=t,l=a,u=this.getExtendMode(e),d=Math.max(n.plotWidth,n.plotHeight)*4;(u===`right`||u===`both`)&&(l={x:a.x+o*d,y:a.y+s*d}),(u===`left`||u===`both`)&&(c={x:t.x-o*d,y:t.y-s*d}),i.push({a:c,b:l})}else if(r.length>=3)switch(e.kind){case`parallel-channel`:{let[e,t,n]=r,a=t.x-e.x,o=t.y-e.y,s={x:n.x+a,y:n.y+o};i.push({a:e,b:t},{a:n,b:s});break}case`flat-line`:{let[e,t,n]=r,a={x:e.x,y:n.y},o={x:t.x,y:n.y};i.push({a:e,b:t}),i.push({a,b:o});break}case`disjoint-channel`:{let[e,t,n]=r,a=t.x-e.x,o=t.y-e.y,s={x:n.x+a,y:n.y-o};i.push({a:e,b:t}),i.push({a:n,b:s});break}default:for(let e=0;e<r.length-1;e++)i.push({a:r[e],b:r[e+1]})}return i}hitTestRegressionEndpoints(e,t,n,r){let i=this.getRegressionChannelGeometry(e,r);if(!i)return null;for(let r of i.endpoints)if(Math.hypot(t-r.point.x,n-r.point.y)<=qo)return{drawing:e,anchorIndex:r.anchorIndex};return null}getRegressionChannelGeometry(e,t){let n=t?.get(e.id);if(n!==void 0)return n;let r=this.chart.getData();if(r.length===0||e.anchors.length<2)return t?.set(e.id,null),null;let i=Math.round(e.anchors[0].index),a=Math.round(e.anchors[1].index),o=Math.min(Math.max(i,0),r.length-1),s=Math.min(Math.max(a,0),r.length-1),c=Math.min(o,s),l=Math.max(o,s),u=r.slice(c,l+1),d=as(u.map(e=>e.close));if(!d)return t?.set(e.id,null),null;let f=e.params?.sigma??2,p=d.stdDev*f,m=d.intercept,h=d.intercept+d.slope*(u.length-1),g=this.anchorToScreen({id:``,index:i,price:m}),_=this.anchorToScreen({id:``,index:a,price:h}),v=this.anchorToScreen({id:``,index:i,price:m+p}),y=this.anchorToScreen({id:``,index:a,price:h+p}),b=this.anchorToScreen({id:``,index:i,price:m-p}),x=this.anchorToScreen({id:``,index:a,price:h-p}),S=[];g&&_&&S.push({a:g,b:_}),v&&y&&S.push({a:v,b:y}),b&&x&&S.push({a:b,b:x});let C=[];g&&C.push({point:g,anchorIndex:0}),_&&C.push({point:_,anchorIndex:1}),v&&C.push({point:v,anchorIndex:0}),y&&C.push({point:y,anchorIndex:1}),b&&C.push({point:b,anchorIndex:0}),x&&C.push({point:x,anchorIndex:1});let w={segments:S,endpoints:C};return t?.set(e.id,w),w}getExtendMode(e){switch(e.kind){case`ray`:return`right`;case`extended-line`:return`both`;default:return`none`}}anchorToScreen(e){let t=this.chart.getViewport();if(!t)return null;let n=this.chart.getOption(),r=this.chart.getCurrentDpr(),{startXPx:i,unitPx:a}=B(n.kWidth,n.kGap,r);if(!Number.isFinite(e.index))return null;let o=(i+e.index*a+(a-1)/2)/r-t.scrollLeft,s=this.chart.getPaneRenderers().find(e=>e.getPane().id===`main`)?.getPane();return s?{x:o,y:s.yAxis.priceToY(e.price)}:null}screenToAnchor(e,t){let n=this.chart.getData();if(!this.chart.getViewport()||n.length===0)return null;let r=this.chart.getLogicalIndexAtX(e);if(r===null)return null;let i=this.chart.getPaneRenderers().find(e=>e.getPane().id===`main`)?.getPane();return i?{index:r,time:this.chart.getTimestampAtLogicalIndex(r)??void 0??void 0,price:i.yAxis.yToPrice(t-i.top)}:null}setSelected(e){let t=e?.id??null;this.selectedDrawingId!==t&&(this.selectedDrawingId=t,this.chart.setSelectedDrawingId(t),this.callbacks.onDrawingSelected?.(e))}removePreview(){this.drawings.some(e=>e.id===this.previewDrawingId)&&(this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId),this.chart.setDrawings(this.drawings))}resolveAnchorFromPointer(e,t){let n=this.chart.getData(),r=this.chart.getViewport();if(!r||n.length===0)return null;let i=t.getBoundingClientRect(),a=e.clientX-i.left,o=e.clientY-i.top;if(a<0||o<0||a>r.plotWidth||o>r.plotHeight)return null;let s=this.chart.getPaneRenderers().find(e=>{let t=e.getPane();return t.id===`main`&&o>=t.top&&o<=t.top+t.height})?.getPane();if(!s)return null;let c=this.chart.getLogicalIndexAtX(a);return c===null?null:{index:c,time:this.chart.getTimestampAtLogicalIndex(c)??void 0??void 0,price:s.yAxis.yToPrice(o-s.top)}}createSingleAnchorDrawing(e){this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId);let t={id:`drawing-${Date.now()}`,kind:this.getDrawingKind(this.activeTool),paneId:`main`,visible:!0,anchors:[{id:`${Date.now()}-a`,index:e.index,time:e.time,price:e.price}],params:{},style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`solid`}};this.drawings=[...this.drawings,t],this.chart.setDrawings(this.drawings),this.callbacks.onDrawingCreated?.(t),this.activeTool=`cursor`,this.callbacks.onToolChange?.(`cursor`)}createMultiAnchorDrawing(e){this.drawings=this.drawings.filter(e=>e.id!==this.previewDrawingId);let t=this.getDrawingKind(this.activeTool),n=t===`regression-channel`?{sigma:2}:{},r=t===`flat-line`&&e.length>=3?[e[0],e[1],{index:e[1].index,time:e[1].time,price:e[2].price}]:e,i=[`parallel-channel`,`regression-channel`,`flat-line`,`disjoint-channel`].includes(t),a={id:`drawing-${Date.now()}`,kind:t,paneId:`main`,visible:!0,anchors:r.map((e,t)=>({id:`${Date.now()}-${String.fromCharCode(97+t)}`,index:e.index,time:e.time,price:e.price})),params:n,style:{stroke:`#2962ff`,strokeWidth:1,strokeStyle:`solid`,...i?{fillOpacity:.1}:{}}};this.drawings=[...this.drawings,a],this.chart.setDrawings(this.drawings),this.callbacks.onDrawingCreated?.(a),this.activeTool=`cursor`,this.callbacks.onToolChange?.(`cursor`)}getDrawingKind(e){switch(e){case`cursor`:throw Error(`cursor is not a drawing kind`);case`h-line`:return`horizontal-line`;case`h-ray`:return`horizontal-ray`;case`v-line`:return`vertical-line`;case`crosshair-line`:return`cross-line`;default:return e}}};function Xo(e,t,n,r){let i=r.x-n.x,a=r.y-n.y,o=i*i+a*a;if(o===0)return Math.hypot(e-n.x,t-n.y);let s=((e-n.x)*i+(t-n.y)*a)/o;return s=Math.max(0,Math.min(1,s)),Math.hypot(e-(n.x+s*i),t-(n.y+s*a))}var Zo=class{drawings=[];selectedId=null;getSelectedId(){return this.selectedId}setSelectedId(e){this.selectedId=e}getAll(){return this.drawings}getVisibleByPane(e){return this.drawings.filter(t=>t.visible&&t.paneId===e).sort((e,t)=>(e.zIndex??0)-(t.zIndex??0))}setAll(e){this.drawings=[...e],this.selectedId&&!this.drawings.some(e=>e.id===this.selectedId)&&(this.selectedId=null)}upsert(e){let t=this.drawings.findIndex(t=>t.id===e.id);if(t>=0){this.drawings[t]=e;return}this.drawings.push(e)}remove(e){this.drawings=this.drawings.filter(t=>t.id!==e)}clear(){this.drawings=[],this.selectedId=null}},Qo=class{definitions=new Map;register(e){this.definitions.set(e.kind,e)}get(e){return this.definitions.get(e)}compute(e,t){let n=this.get(e.kind);return n?n.compute(e,t):null}};function $o(e,t){if(e.strokeStyle=t?.stroke??`#2962ff`,e.lineWidth=t?.strokeWidth??1,t?.strokeStyle===`dashed`){e.setLineDash([6,4]);return}if(t?.strokeStyle===`dotted`){e.setLineDash([2,3]);return}e.setLineDash([])}function es(e,t){e.fillStyle=t?.fill??t?.stroke??`#2962ff`,e.globalAlpha=t?.fillOpacity??1}function ts(e,t,n,r,i){let a=(e,t)=>{let n=0;return e<i.left?n|=1:e>i.right&&(n|=2),t<i.top?n|=8:t>i.bottom&&(n|=4),n},o=e,s=t,c=n,l=r;for(;;){let e=a(o,s),t=a(c,l);if(!(e|t))return{a:{x:o,y:s},b:{x:c,y:l}};if(e&t)return null;let n=e||t,r=0,u=0;n&8?(r=o+(c-o)*(i.top-s)/(l-s),u=i.top):n&4?(r=o+(c-o)*(i.bottom-s)/(l-s),u=i.bottom):n&2?(u=s+(l-s)*(i.right-o)/(c-o),r=i.right):(u=s+(l-s)*(i.left-o)/(c-o),r=i.left),n===e?(o=r,s=u):(c=r,l=u)}}function ns(e,t){let{a:n,b:r,extend:i=`none`}=e;if(i===`none`)return ts(n.x,n.y,r.x,r.y,t);let a=r.x-n.x,o=r.y-n.y;if(a===0&&o===0)return null;let s=Math.max(t.right-t.left,t.bottom-t.top)*4,c=n,l=r;return(i===`left`||i===`both`)&&(c={x:n.x-a*s,y:n.y-o*s}),(i===`right`||i===`both`)&&(l={x:r.x+a*s,y:r.y+o*s}),ts(c.x,c.y,l.x,l.y,t)}function rs(e,t){if(!Number.isFinite(e.index))return-1;let n=Math.round(e.index);return n<0||n>=t.length?-1:n}function is(e,t=2){if(!Number.isFinite(e))return`0`;let n=e.toFixed(t);return e>0?`+${n}`:n}function as(e){let t=e.length;if(t<2)return null;let n=0,r=0,i=0,a=0;for(let o=0;o<t;o++){let t=o,s=e[o];n+=t,r+=s,i+=t*s,a+=t*t}let o=t*a-n*n;if(o===0)return null;let s=(t*i-n*r)/o,c=(r-s*n)/t,l=0;for(let n=0;n<t;n++){let t=c+s*n,r=e[n]-t;l+=r*r}return{slope:s,intercept:c,stdDev:Math.sqrt(l/t)}}function os(){return{point(e,t,n){let r=t.style?.pointRadius??4;e.save(),e.fillStyle=t.style?.fill??t.style?.stroke??`#2962ff`,e.beginPath(),e.arc(t.point.x,t.point.y,Math.max(r,1/n),0,Math.PI*2),e.fill(),e.restore()},line(e,t,n,r){let i=ns(t,n);if(!i)return;e.save(),$o(e,t.style);let a=(t.style?.strokeWidth??1)<=1?.5/r:0;if(e.beginPath(),e.moveTo(i.a.x+a,i.a.y+a),e.lineTo(i.b.x+a,i.b.y+a),e.stroke(),t.showEndpoints!==!1){let n=t.style?.pointRadius??4;e.fillStyle=t.style?.stroke??`#2962ff`,e.beginPath(),e.arc(t.a.x,t.a.y,Math.max(n,1/r),0,Math.PI*2),e.fill(),e.beginPath(),e.arc(t.b.x,t.b.y,Math.max(n,1/r),0,Math.PI*2),e.fill()}e.restore()},area(e,t){if(t.points.length!==0){e.save(),es(e,t.style),e.beginPath(),e.moveTo(t.points[0].x,t.points[0].y);for(let n=1;n<t.points.length;n++){let r=t.points[n];e.lineTo(r.x,r.y)}t.closed&&e.closePath(),e.fill(),e.restore()}},text(e,t){e.save(),e.fillStyle=t.style?.textColor??t.style?.stroke??`#2962ff`,e.font=`${t.style?.fontSize??12}px sans-serif`,e.textAlign=t.align??`left`,e.textBaseline=t.baseline??`bottom`,e.fillText(t.text,t.point.x,t.point.y),e.restore()}}}function ss(e,t){return{kind:e,minAnchors:2,maxAnchors:2,compute(e,n){let[r,i]=e.anchors;return!r||!i?{primitives:[]}:{primitives:[{kind:`line`,a:n.toScreen(r),b:n.toScreen(i),extend:t,style:e.style}]}}}}function cs(e){return{kind:e,minAnchors:1,maxAnchors:1,compute(t,n){let[r]=t.anchors;if(!r)return{primitives:[]};let i=n.toScreen(r),a=n.pane.height,o=n.viewport.plotWidth;return e===`horizontal-line`?{primitives:[{kind:`line`,a:{x:0,y:i.y},b:{x:o,y:i.y},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}:e===`horizontal-ray`?{primitives:[{kind:`line`,a:i,b:{x:o,y:i.y},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}:e===`vertical-line`?{primitives:[{kind:`line`,a:{x:i.x,y:0},b:{x:i.x,y:a},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}:{primitives:[{kind:`line`,a:{x:0,y:i.y},b:{x:o,y:i.y},showEndpoints:!1,style:t.style},{kind:`line`,a:{x:i.x,y:0},b:{x:i.x,y:a},showEndpoints:!1,style:t.style},{kind:`point`,point:i,style:t.style}]}}}}function ls(){return{kind:`info-line`,minAnchors:2,maxAnchors:2,compute(e,t){let[n,r]=e.anchors;if(!n||!r)return{primitives:[]};let i=t.toScreen(n),a=t.toScreen(r),o=Math.round(n.index),s=Math.round(r.index)-o,c=r.price-n.price,l=n.price===0?0:c/n.price*100,u=Math.atan2(a.y-i.y,a.x-i.x)*(180/Math.PI),d=`${is(c)} (${is(l)}%) ${s} bars ${is(u)}°`;return{primitives:[{kind:`line`,a:i,b:a,style:e.style},{kind:`text`,point:{x:(i.x+a.x)/2+8,y:Math.min(i.y,a.y)-8},text:d,align:`left`,baseline:`bottom`,style:e.style}],meta:{delta:c,percent:l,bars:s,angle:u}}}}}function us(){return{kind:`parallel-channel`,minAnchors:3,maxAnchors:3,compute(e,t){let[n,r,i]=e.anchors;if(!n||!r||!i)return{primitives:[]};let a=t.toScreen(n),o=t.toScreen(r),s=t.toScreen(i),c=o.x-a.x,l=o.y-a.y,u={x:s.x+c,y:s.y+l},d=e.params?.extend??`none`,f=i.index+(r.index-n.index),p=i.time?(typeof i.time==`string`?new Date(i.time).getTime():i.time)+((typeof r.time==`string`?new Date(r.time).getTime():r.time??0)-(typeof n.time==`string`?new Date(n.time).getTime():n.time??0)):void 0;return{primitives:[{kind:`area`,points:[a,o,u,s],closed:!0,style:e.style},{kind:`line`,a,b:o,extend:d,style:e.style},{kind:`line`,a:s,b:u,extend:d,style:e.style}],computedAnchors:[{id:`${e.id}-p4`,index:f,time:p,price:i.price+(r.price-n.price)}]}}}}function ds(){return{kind:`flat-line`,minAnchors:3,maxAnchors:3,compute(e,t){let[n,r,i]=e.anchors;if(!n||!r||!i)return{primitives:[]};let a=t.toScreen(n),o=t.toScreen(r),s=t.toScreen(i),c={x:a.x,y:s.y},l={x:o.x,y:s.y};return{primitives:[{kind:`area`,points:[a,o,l,c],closed:!0,style:e.style},{kind:`line`,a,b:o,style:e.style},{kind:`line`,a:c,b:l,style:e.style},{kind:`point`,point:c,style:e.style},{kind:`point`,point:l,style:e.style}],computedAnchors:[{id:`${e.id}-h1`,index:n.index,time:n.time,price:i.price},{id:`${e.id}-h2`,index:r.index,time:r.time,price:i.price}]}}}}function fs(){return{kind:`disjoint-channel`,minAnchors:3,maxAnchors:3,compute(e,t){let[n,r,i]=e.anchors;if(!n||!r||!i)return{primitives:[]};let a=t.toScreen(n),o=t.toScreen(r),s=t.toScreen(i),c=o.x-a.x,l=o.y-a.y,u={x:s.x+c,y:s.y-l},d=i.index+(r.index-n.index),f=i.price-(r.price-n.price),p=i.time?(typeof i.time==`string`?new Date(i.time).getTime():i.time)-((typeof r.time==`string`?new Date(r.time).getTime():r.time??0)-(typeof n.time==`string`?new Date(n.time).getTime():n.time??0)):void 0;return{primitives:[{kind:`area`,points:[a,o,u,s],closed:!0,style:e.style},{kind:`line`,a,b:o,style:e.style},{kind:`line`,a:s,b:u,style:e.style}],computedAnchors:[{id:`${e.id}-p4`,index:d,time:p,price:f}]}}}}function ps(){return{kind:`regression-channel`,minAnchors:2,maxAnchors:2,compute(e,t){let[n,r]=e.anchors;if(!n||!r)return{primitives:[]};let i=rs(n,t.seriesData),a=rs(r,t.seriesData);if(i<0&&a<0)return{primitives:[]};let o=Math.min(Math.max(Math.round(n.index),0),t.seriesData.length-1),s=Math.min(Math.max(Math.round(r.index),0),t.seriesData.length-1),c=Math.min(o,s),l=Math.max(o,s),u=t.seriesData.slice(c,l+1),d=as(u.map(e=>e.close));if(!d)return{primitives:[]};let f=e.params?.sigma??2,p=d.stdDev*f,m=d.intercept,h=d.intercept+d.slope*(u.length-1),g={id:`${e.id}-reg-start`,index:Math.round(n.index),time:t.seriesData[c].timestamp,price:m},_={id:`${e.id}-reg-end`,index:Math.round(r.index),time:t.seriesData[l].timestamp,price:h},v={...g,id:`${e.id}-reg-upper-start`,price:m+p},y={..._,id:`${e.id}-reg-upper-end`,price:h+p},b={...g,id:`${e.id}-reg-lower-start`,price:m-p},x={..._,id:`${e.id}-reg-lower-end`,price:h-p},S=t.toScreen(g),C=t.toScreen(_),w=t.toScreen(v),T=t.toScreen(y),E=t.toScreen(b),D=t.toScreen(x);return{primitives:[{kind:`area`,points:[w,T,D,E],closed:!0,style:e.style},{kind:`line`,a:S,b:C,style:{...e.style,strokeStyle:`dashed`}},{kind:`line`,a:w,b:T,style:e.style},{kind:`line`,a:E,b:D,style:e.style}],computedAnchors:[g,_],meta:{sigma:f,stdDev:d.stdDev,slope:d.slope}}}}}function ms(e){e.register(ss(`trend-line`,`none`)),e.register(ss(`ray`,`right`)),e.register(ss(`extended-line`,`both`)),e.register(cs(`horizontal-line`)),e.register(cs(`horizontal-ray`)),e.register(cs(`vertical-line`)),e.register(cs(`cross-line`)),e.register(ls()),e.register(us()),e.register(ps()),e.register(ds()),e.register(fs())}function hs(e){let t=e.store,n=e.definitions??new Qo,r=e.renderers??os();return ms(n),{name:`drawingRenderer`,version:`0.1.0`,description:`绘图渲染器`,debugName:`绘图层`,paneId:e.paneId??`main`,priority:-25,draw(e){let{ctx:i,pane:a,data:o,range:s,dpr:c,paneWidth:l,kLinePositions:u,kLineCenters:d,kBarRects:f,kWidth:p,kGap:m}=e,h=e.viewport??{scrollLeft:e.scrollLeft,plotWidth:l,plotHeight:a.height},{startXPx:g,unitPx:_}=B(p,m,c),v=o,y=v.slice(s.start,s.end),b=t.getVisibleByPane(a.id);if(b.length===0)return;let x={left:0,top:0,right:h.plotWidth,bottom:a.height};i.save(),i.beginPath(),i.rect(0,0,h.plotWidth,a.height),i.clip();for(let o of b){let b=n.compute(o,{pane:a,visibleData:y,seriesData:v,range:s,kLinePositions:u,kLineCenters:d,kBarRects:f,kWidth:p,kGap:m,dpr:c,paneWidth:l,viewport:h,toScreen(e){return!Number.isFinite(e.index)||e.index<0?{x:-p,y:a.yAxis.priceToY(e.price)}:{x:(g+e.index*_+(_-1)/2)/c-h.scrollLeft,y:a.yAxis.priceToY(e.price)}}});if(!b)continue;let S=t.getSelectedId()===o.id,C=S?b.primitives.map(e=>gs(e,o.style)):b.primitives;if(S&&o.visible&&a.role===`price`){let t=[...o.anchors,...b.computedAnchors??[]];if(t.length===0)continue;if(t.length>=2){let n=1/0,r=-1/0;for(let e of t)Number.isFinite(e.price)&&(e.price<n&&(n=e.price),e.price>r&&(r=e.price));Number.isFinite(n)&&Number.isFinite(r)&&n!==r&&(e.yAxisRanges||=[],e.yAxisRanges.push({topY:a.yAxis.priceToY(r),bottomY:a.yAxis.priceToY(n),color:o.style?.stroke??`#2962ff`,opacity:.15}))}if(t.length>=2){let n=1/0,r=-1/0;for(let e of t)!Number.isFinite(e.index)||e.index<0||(e.index<n&&(n=e.index),e.index>r&&(r=e.index));if(Number.isFinite(n)&&Number.isFinite(r)&&n!==r){e.xAxisRanges||=[];let t=(g+n*_+(_-1)/2)/c,i=(g+r*_+(_-1)/2)/c;e.xAxisRanges.push({leftX:t,rightX:i,color:o.style?.stroke??`#2962ff`,opacity:.15})}}let n=e=>{if(e>=0&&e<v.length)return v[e]?.timestamp??null;if(v.length>=2&&e>=v.length){let t=v.length-1,n=v.length-2,r=v[t].timestamp,i=r-v[n].timestamp;return r+(e-t)*i}return null};for(let r of t){if(!Number.isFinite(r.index)||!Number.isFinite(r.price))continue;let t=r.index<0?{x:-p,y:a.yAxis.priceToY(r.price)}:{x:(g+r.index*_+(_-1)/2)/c-h.scrollLeft,y:a.yAxis.priceToY(r.price)};if(t.y>=0&&t.y<=a.height&&(e.yAxisLabels||=[],e.yAxisLabels.push({dataIndex:Math.round(r.index),price:r.price,y:t.y,style:{bgColor:o.style?.stroke??`#2962ff`,borderColor:o.style?.stroke??`#2962ff`,textColor:`#ffffff`}})),t.x>=-p&&t.x<=h.plotWidth+p){let i=r.time?typeof r.time==`string`?new Date(r.time).getTime():r.time:n(Math.round(r.index));if(!i)continue;e.xAxisLabels||=[],e.xAxisLabels.push({dataIndex:Math.round(r.index),timestamp:i,x:t.x+h.scrollLeft,style:{bgColor:o.style?.stroke??`#2962ff`,textColor:`#ffffff`}})}}}for(let e of C){if(e.kind===`point`){r.point(i,e,c);continue}if(e.kind===`line`){r.line(i,e,x,c);continue}if(e.kind===`area`){r.area(i,e,c);continue}r.text(i,e,c)}}i.restore()}}}function gs(e,t){let n=t.stroke??`#2962ff`,r=(t.strokeWidth??1)+1,i=(t.pointRadius??4)+2;return e.kind===`point`?{...e,style:{...e.style,stroke:n,pointRadius:i}}:e.kind===`line`?{...e,style:{...e.style,stroke:n,strokeWidth:r}}:e.kind===`area`?{...e,style:{...e.style,stroke:n}}:{...e,style:{...e.style,textColor:n,fontSize:(e.style?.fontSize??12)+1}}}var _s=class{dom;opt;data=[];raf=null;pendingUpdateLevel=H.All;viewport=null;paneRenderers=[];markerManager;drawingStore=new Zo;interaction;pluginHost;rendererPluginManager;preciseDpr=0;resizeObserver;onScroll;observedSize={width:0,height:0};cachedScrollLeft=0;overlayHadCrosshair=!1;settings={};paneRatios=new Map;onViewportChange;xAxisCtx=null;sharedWebGLSurface;onPaneLayoutChange;onDataChange;currentZoomLevel=1;zoomLevelCount;indicatorScheduler;lastVisibleRange={start:0,end:0};cachedDrawFrame=null;subPaneManager;activeMainIndicators=new Set;mainIndicatorParams={MA:{ma5:!0,ma10:!0,ma20:!0,ma30:!0,ma60:!0},BOLL:{period:20,multiplier:2,showUpper:!0,showMiddle:!0,showLower:!0,showBand:!0},EXPMA:{fastPeriod:12,slowPeriod:50},ENE:{period:10,deviation:11}};enableMainIndicator(e,t){let n=e.toUpperCase();return[`MA`,`BOLL`,`EXPMA`,`ENE`].includes(n)?this.activeMainIndicators.has(n)?(t&&(this.mainIndicatorParams[n]={...this.mainIndicatorParams[n],...t},this.updateIndicatorSchedulerConfig(n)),!0):(this.activeMainIndicators.add(n),t&&(this.mainIndicatorParams[n]={...this.mainIndicatorParams[n],...t}),this.enableMainIndicatorRenderer(n),this.updateIndicatorSchedulerConfig(n),this.scheduleDraw(),!0):(console.warn(`[Chart] 未知的主图指标: ${e}`),!1)}disableMainIndicator(e){let t=e.toUpperCase();return this.activeMainIndicators.has(t)?(this.activeMainIndicators.delete(t),this.disableMainIndicatorRenderer(t),this.updateIndicatorSchedulerConfig(t),this.scheduleDraw(),!0):!1}toggleMainIndicator(e,t){t?this.enableMainIndicator(e):this.disableMainIndicator(e)}getActiveMainIndicators(){return Array.from(this.activeMainIndicators)}isMainIndicatorActive(e){return this.activeMainIndicators.has(e.toUpperCase())}updateMainIndicatorParams(e,t){let n=e.toUpperCase();this.mainIndicatorParams[n]||(this.mainIndicatorParams[n]={}),this.mainIndicatorParams[n]={...this.mainIndicatorParams[n],...t};let r=n.toLowerCase(),i=this.getRenderer(r);i&&i.setConfig&&i.setConfig(this.mainIndicatorParams[n]),this.updateIndicatorSchedulerConfig(n),this.scheduleDraw()}getMainIndicatorParams(e){return this.mainIndicatorParams[e.toUpperCase()]??null}clearMainIndicators(){for(let e of this.activeMainIndicators)this.disableMainIndicatorRenderer(e);this.activeMainIndicators.clear(),this.scheduleDraw()}enableMainIndicatorRenderer(e){let t={MA:()=>{this.getRenderer(`ma`)||this.useRenderer(fa()),this.setRendererEnabled(`ma`,!0)},BOLL:()=>{this.getRenderer(`boll`)||this.useRenderer(va()),this.setRendererEnabled(`boll`,!0)},EXPMA:()=>{this.getRenderer(`expma`)||this.useRenderer(ba()),this.setRendererEnabled(`expma`,!0)},ENE:()=>{this.getRenderer(`ene`)||this.useRenderer(Ta()),this.setRendererEnabled(`ene`,!0)}}[e];t&&t(),this.getRenderer(`mainIndicatorLegend`)||this.useRenderer(Ma({yPaddingPx:this.opt.yPaddingPx}))}disableMainIndicatorRenderer(e){let t={MA:`ma`,BOLL:`boll`,EXPMA:`expma`,ENE:`ene`}[e];t&&this.setRendererEnabled(t,!1)}updateIndicatorSchedulerConfig(e){let t=this.activeMainIndicators.has(e),n=this.mainIndicatorParams[e];switch(e){case`MA`:this.indicatorScheduler.updateMAConfig({ma5:t,ma10:t,ma20:t,ma30:t,ma60:t});break;case`BOLL`:t?this.indicatorScheduler.updateBOLLConfig(n):this.indicatorScheduler.updateBOLLConfig({...n,showUpper:!1,showMiddle:!1,showLower:!1,showBand:!1});break;case`EXPMA`:t&&this.indicatorScheduler.updateEXPMAConfig(n);break;case`ENE`:t&&this.indicatorScheduler.updateENEConfig(n);break}}setActiveMainIndicators(e){let t=new Set(e.map(e=>e.toUpperCase())),n=new Set(this.activeMainIndicators);for(let e of n)t.has(e)||this.disableMainIndicator(e);for(let e of t)n.has(e)||this.enableMainIndicator(e)}constructor(e,t){this.dom=e;let{kWidth:n,kGap:r,...i}=t;this.opt={...i,kWidth:n??0,kGap:r??0},this.interaction=new $n(this),this.markerManager=new Ht,this.pluginHost=ge(),this.rendererPluginManager=new ke,this.sharedWebGLSurface=new er,this.rendererPluginManager.setPluginHost(this.pluginHost),this.rendererPluginManager.setInvalidateCallback(()=>this.scheduleDraw()),this.syncPaneRatiosFromSpecs(this.opt.panes),this.zoomLevelCount=Math.max(2,Math.round(this.opt.zoomLevels??20)),this.currentZoomLevel=this.opt.initialZoomLevel??1,this.currentZoomLevel=Math.max(1,Math.min(this.zoomLevelCount,this.currentZoomLevel)),this.indicatorScheduler=new ia,this.indicatorScheduler.setPluginHost(this.pluginHost),this.indicatorScheduler.setInvalidateCallback(()=>this.scheduleDraw()),this.subPaneManager=new Ko,this.indicatorScheduler.setActiveSubPaneProvider(()=>this.subPaneManager.getPaneIds()),this.initPanes(),this.useRenderer(hs({store:this.drawingStore})),this.initResizeObserver()}initResizeObserver(){if(typeof ResizeObserver>`u`)return;let e=this.dom.container;if(e){this.cachedScrollLeft=e.scrollLeft,this.onScroll=()=>{this.cachedScrollLeft=e.scrollLeft},e.addEventListener(`scroll`,this.onScroll,{passive:!0}),this.resizeObserver=new ResizeObserver(e=>{let t=e[0];if(!t)return;let n=this.observedSize.width,r=this.observedSize.height,i=this.preciseDpr;this.updateObservedMetrics(t);let a=this.observedSize.width!==n,o=this.observedSize.height!==r,s=this.preciseDpr!==i;(a||o||s)&&this.resize()});try{this.resizeObserver.observe(e,{box:`device-pixel-content-box`})}catch{this.resizeObserver.observe(e)}}}updateObservedMetrics(e){let t=Math.max(1,Math.round(e.contentRect.width)),n=Math.max(1,Math.round(e.contentRect.height));this.observedSize.width=t,this.observedSize.height=n;let r=e.devicePixelContentBoxSize?.[0],i=e.contentBoxSize?.[0];if(!r||!i||i.inlineSize<=0){this.preciseDpr=0;return}let a=r.inlineSize/i.inlineSize;this.preciseDpr=Math.round(a*64)/64}getEffectiveDpr(){let e=this.preciseDpr>0?this.preciseDpr:Math.round((window.devicePixelRatio||1)*64)/64;return e<1&&(e=1),e}getViewport(){return this.viewport}getCurrentDpr(){return this.getEffectiveDpr()}getCachedScrollLeft(){return this.cachedScrollLeft}get plugin(){return this.pluginHost}useRenderer(e,t){this.rendererPluginManager.register(e),t&&e.setConfig&&e.setConfig(t)}removeRenderer(e){this.rendererPluginManager.unregister(e)}getRenderer(e){return this.rendererPluginManager.getPlugin(e)}updateRendererConfig(e,t){this.rendererPluginManager.updateConfig(e,t)}setRendererEnabled(e,t){this.rendererPluginManager.setEnabled(e,t)}getAllRenderers(){return this.rendererPluginManager.getAllPlugins()}updateSettings(e){this.settings={...e},this.interaction.updateSettings(e);let t=e.logarithmicScale?`log`:`linear`;for(let e of this.paneRenderers)e.getPane().yAxis.setScaleType(t);this.scheduleDraw()}draw(e=H.All){this.markerManager.clear();let t=this.prepareFrameData(e);if(!t)return;let{vp:n,range:r,kLinePositions:i,kLineCenters:a,kBarRects:o,kWidthPx:s,useCachedFrame:c}=t;this.interaction.setKLinePositions(i,r,s),this.indicatorScheduler.setActiveMainIndicators(Array.from(this.activeMainIndicators));let l=c?null:this.indicatorScheduler.getMainIndicatorPriceRange(),u=this.interaction.getCrosshairIndex()!==null,{sharedXAxisLabels:d,sharedXAxisRanges:f}=this.renderPanes(n,r,i,a,o,s,l,u,c,e);this.overlayHadCrosshair=u,this.renderXAxis(n,r,i,a,o,s,d,f)}prepareFrameData(e){let t=e===H.Overlay&&this.cachedDrawFrame!==null,n=t?this.cachedDrawFrame.viewport:this.computeViewport();if(!n||this.data.length===0)return null;let r=t?this.cachedDrawFrame.range:(()=>{let{start:e,end:t}=ve(n.scrollLeft,n.plotWidth,this.opt.kWidth,this.opt.kGap,this.data.length,n.dpr);return{start:e,end:t}})();!t&&(r.start!==this.lastVisibleRange.start||r.end!==this.lastVisibleRange.end)&&(this.indicatorScheduler.updateVisibleRange(r),this.lastVisibleRange=r);let i=t?this.cachedDrawFrame.kLinePositions:this.calcKLinePositions(r),a,o,s;if(t)a=this.cachedDrawFrame.kLineCenters,o=this.cachedDrawFrame.kBarRects,s=this.cachedDrawFrame.kWidthPx;else{let e=B(this.opt.kWidth,this.opt.kGap,n.dpr),t=Math.max(1,e.unitPx-1);t%2==0&&--t,a=Array(i.length),o=Array(i.length);for(let r=0;r<i.length;r++){let s=i[r],c=Math.round(s*n.dpr)+(e.kWidthPx-1)/2;a[r]=c/n.dpr;let l=c-(t-1)/2;o[r]={x:l/n.dpr,width:t/n.dpr}}s=B(this.opt.kWidth,this.opt.kGap,n.dpr).kWidthPx,this.cachedDrawFrame={viewport:{...n},range:{...r},kLinePositions:i,kLineCenters:a,kBarRects:o,kWidthPx:s}}return{vp:n,range:r,kLinePositions:i,kLineCenters:a,kBarRects:o,kWidthPx:s,useCachedFrame:t}}renderPanes(e,t,n,r,i,a,o,s,c,l){let u=[],d=[],f=[],p=[];for(let a of this.paneRenderers){let m=a.getPane(),{mainCtx:h,overlayCtx:g,yAxisCtx:_}=a.getContexts(),{candleSurface:v,lineSurface:y}=a.getWebGL();if(!c){let e=m.role===`price`?o:null;m.updateRange(this.data,t,e)}let b=l===H.Main||l===H.All,x=(l===H.Overlay||l===H.All)&&(s||this.overlayHadCrosshair);if(b&&h&&(h.setTransform(1,0,0,1,0,0),h.scale(e.dpr,e.dpr),h.clearRect(0,0,e.plotWidth+1,m.height+2/e.dpr),v?.clear(),y?.clear()),x&&g){let t=g.canvas.width/e.dpr;g.setTransform(1,0,0,1,0,0),g.scale(e.dpr,e.dpr),g.clearRect(0,0,t+1,m.height+2/e.dpr)}if(_&&!c){let t=_.canvas.width/e.dpr;_.setTransform(1,0,0,1,0,0),_.scale(e.dpr,e.dpr),_.clearRect(0,0,t,m.height+2/e.dpr)}let S={ctx:h,overlayCtx:g??void 0,pane:ue(m),data:this.data,range:t,scrollLeft:e.scrollLeft,kWidth:this.opt.kWidth,kGap:this.opt.kGap,dpr:e.dpr,paneWidth:e.plotWidth,kLinePositions:n,kLineCenters:r,kBarRects:i,markerManager:this.markerManager,crosshairIndex:this.interaction.getCrosshairIndex(),yAxisCtx:_??void 0,candleWebGLSurface:v??void 0,lineWebGLSurface:y??void 0,zoomLevel:this.currentZoomLevel,zoomLevelCount:this.zoomLevelCount,viewport:{scrollLeft:e.scrollLeft,plotWidth:e.plotWidth,plotHeight:e.plotHeight},settings:this.settings,yAxisLabels:u,xAxisLabels:d,yAxisRanges:f,xAxisRanges:p},C=this.rendererPluginManager.render(m.id,S,l);C.length>0&&this.pluginHost.events.emit(`renderer:error`,{paneId:m.id,errors:C});let w=this.rendererPluginManager.renderPlugin(`yAxis`,S);w.length>0&&this.pluginHost.events.emit(`renderer:error`,{paneId:m.id,errors:w})}return{sharedXAxisLabels:d,sharedXAxisRanges:p}}renderXAxis(e,t,n,r,i,a,o,s){let c=this.xAxisCtx??this.dom.xAxisCanvas.getContext(`2d`);if(this.xAxisCtx||=c,c){let a={ctx:c,pane:{id:`xAxis`,role:`auxiliary`,capabilities:{showPriceAxisTicks:!1,showCrosshairPriceLabel:!1,candleHitTest:!1,supportsPriceTranslate:!1},top:0,height:this.opt.bottomAxisHeight,yAxis:{priceToY:()=>0,yToPrice:()=>0,getPaddingTop:()=>0,getPaddingBottom:()=>0,getPriceOffset:()=>0,getDisplayRange:e=>e??{maxPrice:0,minPrice:0},getScaleType:()=>`linear`},priceRange:{maxPrice:0,minPrice:0}},data:this.data,range:t,scrollLeft:e.scrollLeft,kWidth:this.opt.kWidth,kGap:this.opt.kGap,dpr:e.dpr,paneWidth:e.plotWidth,kLinePositions:n,kLineCenters:r,kBarRects:i,xAxisCtx:c,viewport:{scrollLeft:e.scrollLeft,plotWidth:e.plotWidth,plotHeight:e.plotHeight},yAxisLabels:[],xAxisLabels:o,xAxisRanges:s},l=this.rendererPluginManager.renderPlugin(`timeAxis`,a);l.length>0&&this.pluginHost.events.emit(`renderer:error`,{paneId:`timeAxis`,errors:l})}}applyRenderState(e,t,n){let r=n===void 0?this.currentZoomLevel:Math.max(1,Math.min(this.zoomLevelCount,n));(this.opt.kWidth!==e||this.opt.kGap!==t||this.currentZoomLevel!==r)&&(this.opt={...this.opt,kWidth:e,kGap:t},n!==void 0&&(this.currentZoomLevel=r),this.scheduleDraw())}getZoomLevelCount(){return this.zoomLevelCount}setOnViewportChange(e){this.onViewportChange=e}setOnPaneLayoutChange(e){this.onPaneLayoutChange=e}setOnDataChange(e){this.onDataChange=e}getPaneRenderers(){return this.paneRenderers}getMarkerManager(){return this.markerManager}updateCustomMarkers(e){this.markerManager.setCustomMarkers(e),this.scheduleDraw()}clearCustomMarkers(){this.markerManager.clearCustomMarkers(),this.scheduleDraw()}getDom(){return this.dom}getOption(){return this.opt}calcKLinePositions(e){let{start:t,end:n}=e,r=n-t;if(r<=0)return[];let i=this.getEffectiveDpr(),{unitPx:a,startXPx:o}=B(this.opt.kWidth,this.opt.kGap,i),s=Array(r);for(let e=0;e<r;e++)s[e]=(o+(t+e)*a)/i;return s}updateOptions(e){if(e.kWidth!==void 0&&(console.warn(`[Chart] kWidth cannot be set directly. Use applyRenderState() instead.`),delete e.kWidth),e.kGap!==void 0&&delete e.kGap,e.panes){let t=e.panes.map(e=>({...e}));this.opt={...this.opt,...e,panes:t},this.applyPaneLayoutSpecs(t);return}this.opt={...this.opt,...e},this.resize()}updatePaneLayout(e){this.applyPaneLayoutSpecs(e)}setPaneDefinitions(e){this.applyPaneLayoutSpecs(e)}upsertPane(e){let t=this.opt.panes.findIndex(t=>t.id===e.id);if(t===-1){this.applyPaneLayoutSpecs([...this.opt.panes,{...e}]);return}let n=[...this.opt.panes];n[t]={...n[t],...e},this.applyPaneLayoutSpecs(n)}removePaneDefinition(e){this.opt.panes.some(t=>t.id===e)&&(this.paneRatios.delete(e),this.applyPaneLayoutSpecs(this.opt.panes.filter(t=>t.id!==e)))}bindIndicatorToPane(e,t,n){this.opt.panes.some(t=>t.id===e)||this.upsertPane({id:e,ratio:1,visible:!0,role:`indicator`});let r=`${t.toLowerCase()}_${e}`;if(this.getRenderer(r)){n&&this.updateRendererConfig(r,n);return}let i=uo({indicatorId:t,paneId:e});this.useRenderer(i,n)}setDrawings(e){this.drawingStore.setAll(e),this.scheduleDraw()}setSelectedDrawingId(e){this.drawingStore.getSelectedId()!==e&&(this.drawingStore.setSelectedId(e),this.scheduleDraw())}getPaneLayoutSpecs(){let e=this.opt.panes.filter(e=>e.visible!==!1).reduce((e,t)=>e+(this.paneRatios.get(t.id)??t.ratio??0),0),t=e>0?e:1;return this.opt.panes.map(e=>{let n=this.paneRatios.get(e.id)??e.ratio??0,r=e.visible===!1?n:n/t,i=this.paneRenderers.find(t=>t.getPane().id===e.id)?.getPane();return{...e,ratio:r,role:i?.role??e.role,capabilities:i?{...i.capabilities}:e.capabilities}})}emitPaneLayoutChange(){this.onPaneLayoutChange?.(this.getPaneLayoutSpecs())}applyPaneLayoutSpecs(e){this.opt.panes=e.map(e=>({...e})),this.syncPaneRatiosFromSpecs(this.opt.panes),this.initPanes(),this.layoutPanes(),this.emitPaneLayoutChange(),this.scheduleDraw()}resizePaneBoundary(e,t){if(!Number.isFinite(t)||t===0)return!1;let n=this.viewport;if(!n)return!1;let r=this.opt.panes.filter(e=>e.visible!==!1),i=r.findIndex(t=>t.id===e);if(i<0||i>=r.length-1)return!1;let a=r[i],o=r[i+1];if(!a||!o)return!1;let s=new Map;for(let e of r){let t=this.paneRenderers.find(t=>t.getPane().id===e.id);t&&s.set(e.id,t.getPane().height)}let c=t>0?i:i+1,l=t>0?i+1:i,u=t>0?1:-1,d=Math.abs(t),f=l;for(;d>0&&f>=0&&f<r.length;){let e=r[f];if(!e)break;let t=s.get(e.id)??0,i=this.getPaneMinHeight(e,n.plotHeight),a=Math.max(0,t-i);if(a>0){let n=Math.min(a,d);s.set(e.id,t-n),d-=n}d>0&&(f+=u)}if(d>0)return!1;let p=r[c];if(!p)return!1;let m=s.get(p.id)??0;s.set(p.id,m+Math.abs(t));let h=Math.max(0,this.opt.paneGap??0)*Math.max(0,r.length-1),g=Math.max(1,n.plotHeight-h);for(let e of r){let t=s.get(e.id)??0;this.paneRatios.set(e.id,t/g)}return this.normalizeVisiblePaneRatios(r),this.syncPaneRatiosToSpecs(),this.layoutPanes(),this.emitPaneLayoutChange(),this.scheduleDraw(),!0}resolvePaneRole(e,t){return e.role?e.role:t===0?`price`:`indicator`}addPane(e){if(this.opt.panes.some(t=>t.id===e)){console.warn(`Pane "${e}" already exists`);return}let t=this.opt.panes.some((e,t)=>this.resolvePaneRole(e,t)===`price`)?`indicator`:`price`;this.applyPaneLayoutSpecs([...this.opt.panes,{id:e,ratio:1,visible:!0,role:t}])}removePane(e){if(!this.opt.panes.some(t=>t.id===e))return;let t=this.opt.panes.filter(t=>t.id!==e);this.paneRatios.delete(e),this.applyPaneLayoutSpecs(t)}hasPane(e){return this.opt.panes.some(t=>t.id===e)}createSubPane(e,t,n){let r=this.opt.panes.filter(e=>e.visible!==!1),i=r.filter((e,t)=>this.resolvePaneRole(e,t)===`price`),a=r.filter((e,t)=>this.resolvePaneRole(e,t)===`indicator`);if(i.length===1){let t=i[0];t&&this.paneRatios.set(t.id,3);for(let e of a)this.paneRatios.set(e.id,1);this.paneRatios.set(e,1)}else this.paneRatios.set(e,1);return this.upsertPane({id:e,ratio:this.paneRatios.get(e)??1,visible:!0,role:`indicator`}),this.subPaneManager.create(this,e,t,n??this.getDefaultSubPaneParams(t))}removeSubPane(e){this.subPaneManager.remove(this,e),this.paneRatios.delete(e)}replaceSubPaneIndicator(e,t,n){this.subPaneManager.replaceIndicator(this,e,t,n??this.getDefaultSubPaneParams(t))}updateSubPaneParams(e,t){this.subPaneManager.updateParams(this,e,t)}clearSubPanes(){let e=this.subPaneManager.getPaneIds();if(e.length!==0){this.subPaneManager.clear(this);for(let t of e)this.paneRatios.delete(t);this.applyPaneLayoutSpecs(this.opt.panes.filter(t=>!e.includes(t.id)))}}getSubPaneIndicators(){return this.subPaneManager.getAll().map(e=>e.indicatorId)}getSubPaneEntries(){return this.subPaneManager.getAll()}getSubPaneEntry(e){return this.subPaneManager.getByPaneId(e)}getDefaultSubPaneParams(e){return{...{VOLUME:{},MACD:{fastPeriod:12,slowPeriod:26,signalPeriod:9},RSI:{period1:6,period2:12,period3:24},CCI:{period:14,showCCI:!0},STOCH:{n:9,m:3,showK:!0,showD:!0},MOM:{period:10,showMOM:!0},WMSR:{period:14,showWMSR:!0},KST:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},FASTK:{period:9,showFASTK:!0},ATR:{period:14,showATR:!0}}[e]}}static SUB_PANE_PREFIX=`sub_`;translatePrice(e,t){let n=this.paneRenderers.find(t=>t.getPane().id===e);if(!n)return;let r=n.getPane();if(!r.capabilities.supportsPriceTranslate)return;let i=r.yAxis.deltaYToPriceOffset(t),a=r.yAxis.getPriceOffset();r.yAxis.setPriceOffset(a+i),this.scheduleDraw()}resetPriceOffset(e){let t=this.paneRenderers.find(t=>t.getPane().id===e);t&&(t.getPane().yAxis.resetPriceOffset(),this.scheduleDraw())}scalePrice(e,t){let n=this.paneRenderers.find(t=>t.getPane().id===e);if(!n)return;let r=n.getPane();r.capabilities.supportsPriceTranslate&&(r.yAxis.scaleByDelta(t),this.scheduleDraw())}updateData(e){this.data=e??[],this.onDataChange?.(this.data);let t=this.dom.container;if(t){let e=this.getContentWidth(),n=Math.max(0,e-t.clientWidth);this.cachedScrollLeft>n&&(t.scrollLeft=n,this.cachedScrollLeft=n)}this.interaction.reset(),this.indicatorScheduler.update(this.data,this.lastVisibleRange),this.scheduleDraw()}getData(){return this.data}getIndicatorScheduler(){return this.indicatorScheduler}getTrailingSlotCount(){return 24}getLogicalSlotCount(){return this.data.length+this.getTrailingSlotCount()}getTimestampAtLogicalIndex(e){return!Number.isInteger(e)||e<0||e>=this.data.length?null:this.data[e]?.timestamp??null}getLogicalIndexAtX(e){let t=this.viewport;if(!t||this.data.length===0)return null;let n=this.getEffectiveDpr(),{startXPx:r,unitPx:i}=B(this.opt.kWidth,this.opt.kGap,n),a=Math.round((t.scrollLeft+e)*n),o=Math.floor((a-r)/i);return o<0?null:o}getDataIndexAtX(e){let t=this.getLogicalIndexAtX(e);return t===null||t>=this.data.length?null:t}getContentWidth(){return mr({dataLength:this.data.length,kWidth:this.opt.kWidth,kGap:this.opt.kGap,viewWidth:this.viewport?.plotWidth??0,viewportDpr:this.getEffectiveDpr()})}resize(){let e=this.computeViewport();!e||e.viewWidth<10||e.viewHeight<10||(this.cachedDrawFrame=null,this.layoutPanes(),this.emitPaneLayoutChange(),this.scheduleDraw())}scheduleDraw(e=H.All){if(this.raf!==null){if(this.pendingUpdateLevel===H.All)return;if(e===H.All){this.pendingUpdateLevel=H.All;return}if(this.pendingUpdateLevel===H.Main&&e===H.Overlay||this.pendingUpdateLevel===H.Overlay&&e===H.Main){this.pendingUpdateLevel=H.All;return}return}this.pendingUpdateLevel=e,this.raf=requestAnimationFrame(()=>{this.raf=null;let e=this.pendingUpdateLevel;this.pendingUpdateLevel=H.All,this.draw(e)})}async destroy(){this.raf!==null&&(cancelAnimationFrame(this.raf),this.raf=null),this.resizeObserver?.disconnect(),this.resizeObserver=void 0,this.preciseDpr=0,this.observedSize={width:0,height:0},this.onScroll&&=(this.dom.container?.removeEventListener(`scroll`,this.onScroll),void 0),this.viewport=null,this.cachedDrawFrame=null,this.xAxisCtx=null,this.paneRenderers.forEach(e=>e.destroy()),this.paneRenderers=[],this.sharedWebGLSurface.destroy(),this.rendererPluginManager.clear(),this.onViewportChange=void 0,this.onPaneLayoutChange=void 0,this.indicatorScheduler.destroy(),await this.pluginHost.destroy()}initPanes(){this.paneRenderers=this.opt.panes.map((e,t)=>{let n=new De(e.id,{role:this.resolvePaneRole(e,t),capabilities:e.capabilities}),r=document.createElement(`canvas`),i=document.createElement(`canvas`),a=document.createElement(`canvas`),o=n.role===`price`;return r.id=`${e.id}-main`,r.className=o?`main-canvas main`:`main-canvas sub`,r.style.position=`absolute`,r.style.left=`0`,r.style.top=`0`,i.id=`${e.id}-overlay`,i.className=`overlay-canvas`,i.style.position=`absolute`,i.style.left=`0`,i.style.top=`0`,i.style.pointerEvents=`none`,i.style.backgroundColor=`transparent`,a.id=`${e.id}-yAxis`,a.className=`right-axis`,a.style.position=`absolute`,a.style.left=`0`,new pr({mainCanvas:r,overlayCanvas:i,yAxisCanvas:a},n,{rightAxisWidth:this.opt.rightAxisWidth,yPaddingPx:this.opt.yPaddingPx,priceLabelWidth:this.opt.priceLabelWidth},this.sharedWebGLSurface)});let e=this.dom.canvasLayer,t=this.dom.rightAxisLayer;e&&e.querySelectorAll(`canvas:not(.x-axis-canvas)`).forEach(e=>e.remove()),t&&t.querySelectorAll(`canvas.right-axis`).forEach(e=>e.remove()),this.paneRenderers.forEach(n=>{let r=n.getDom();e.appendChild(r.mainCanvas),e.appendChild(r.overlayCanvas),t.appendChild(r.yAxisCanvas)}),this.rendererPluginManager.setKnownPaneIds(this.paneRenderers.map(e=>e.getPane().id))}syncPaneRatiosFromSpecs(e){let t=new Map;for(let n of e){let e=this.paneRatios.get(n.id),r=Number.isFinite(n.ratio)?n.ratio:0,i=e===void 0?r>0?r:1:e;t.set(n.id,i)}this.paneRatios=t,this.normalizeVisiblePaneRatios(e),this.syncPaneRatiosToSpecs()}syncPaneRatiosToSpecs(){let e=this.opt.panes.filter(e=>e.visible!==!1).reduce((e,t)=>e+(this.paneRatios.get(t.id)??t.ratio??0),0),t=e>0?e:1;this.opt.panes=this.opt.panes.map(e=>{let n=this.paneRatios.get(e.id)??e.ratio??0;return e.visible===!1?{...e,ratio:n}:{...e,ratio:n/t}})}normalizeVisiblePaneRatios(e){let t=e.filter(e=>e.visible!==!1);if(t.length===0)return;let n=0;for(let e of t){let t=this.paneRatios.get(e.id)??e.ratio??0,r=Number.isFinite(t)&&t>0?t:0;this.paneRatios.set(e.id,r),n+=r}if(n<=0){let e=1/t.length;for(let n of t)this.paneRatios.set(n.id,e);return}for(let e of t){let t=this.paneRatios.get(e.id)??0;this.paneRatios.set(e.id,t/n)}}getPaneMinHeight(e,t){let n=this.opt.defaultPaneMinHeightPx??120,r=e.minHeightPx??n;return Math.max(1,Math.min(Math.round(r),Math.max(1,t)))}computePaneHeightsByRatio(e,t){if(e.length===0)return[];let n=e.map(e=>this.paneRatios.get(e.id)??e.ratio??0),r=n.reduce((e,t)=>e+(t>0?t:0),0),i=(r>0?n.map(e=>(e>0?e:0)/r):e.map(()=>1/e.length)).map(e=>Math.max(1,Math.round(t*e))),a=e.map(e=>this.getPaneMinHeight(e,t));for(let e=0;e<i.length;e++)i[e]=Math.max(i[e],Math.min(a[e],t));let o=i.reduce((e,t)=>e+t,0);if(o>t){let e=o-t;for(;e>0;){let n=!1;for(let r=i.length-1;r>=0&&e>0;r--){let o=Math.max(1,Math.min(a[r],t)),s=i[r];s>o&&(i[r]=s-1,e--,n=!0)}if(!n)break}}else o<t&&(i[i.length-1]=(i[i.length-1]??1)+(t-o));return o=i.reduce((e,t)=>e+t,0),o!==t&&i.length>0&&(i[i.length-1]=Math.max(1,(i[i.length-1]??1)+(t-o))),i}layoutPanes(){let e=this.viewport;if(!e)return;let t=this.opt.panes.filter(e=>e.visible!==!1);if(t.length===0)return;let n=Math.max(0,this.opt.paneGap??0),r=0,i=n*Math.max(0,t.length-1),a=Math.max(1,e.plotHeight-i);this.normalizeVisiblePaneRatios(t);let o=this.computePaneHeightsByRatio(t,a);for(let i=0;i<t.length;i++){let a=t[i];if(!a)continue;let s=this.paneRenderers.find(e=>e.getPane().id===a.id);if(!s)continue;let c=s.getPane(),l=o[i]??1;c.setLayout(r,l),c.setPadding(this.opt.yPaddingPx,this.opt.yPaddingPx),s.resize(e.plotWidth,l,e.dpr),s.setWebGLRegion({x:0,y:r,width:e.plotWidth,height:l,dpr:e.dpr}),this.rendererPluginManager.notifyResize(c.id,ue(c));let u=s.getDom();u.mainCanvas.style.top=`${r}px`,u.overlayCanvas.style.top=`${r}px`,u.yAxisCanvas.style.top=`${r}px`,u.yAxisCanvas.style.left=`0px`,r+=l+n}let s=Math.max(1,a);for(let e of t){let t=this.paneRenderers.find(t=>t.getPane().id===e.id);if(!t)continue;let n=t.getPane().height;this.paneRatios.set(e.id,n/s)}this.normalizeVisiblePaneRatios(t),this.syncPaneRatiosToSpecs()}computeViewport(){let e=this.dom.container;if(!e)return null;let t=this.observedSize.width,n=this.observedSize.height,r=t>0?t:Math.max(1,Math.round(e.clientWidth)),i=n>0?n:Math.max(1,Math.round(e.clientHeight)),a=Math.round(r),o=Math.round(i-this.opt.bottomAxisHeight),s=this.getEffectiveDpr(),c=16*1024*1024;r*s*(i*s)>c&&(s=Math.sqrt(c/(r*i)));let l=Math.round(this.cachedScrollLeft*s)/s,u=`${r}px`;this.dom.canvasLayer.style.width!==u&&(this.dom.canvasLayer.style.width=u);let d=`${i}px`;this.dom.canvasLayer.style.height!==d&&(this.dom.canvasLayer.style.height=d);let f=Math.round(a*s);this.dom.xAxisCanvas.width!==f&&(this.dom.xAxisCanvas.width=f);let p=Math.round(this.opt.bottomAxisHeight*s);this.dom.xAxisCanvas.height!==p&&(this.dom.xAxisCanvas.height=p);let m=`${f/s}px`;this.dom.xAxisCanvas.style.width!==m&&(this.dom.xAxisCanvas.style.width=m);let h=`${p/s}px`;this.dom.xAxisCanvas.style.height!==h&&(this.dom.xAxisCanvas.style.height=h),this.sharedWebGLSurface.resize(a,o,s);let g={viewWidth:r,viewHeight:i,plotWidth:a,plotHeight:o,scrollLeft:l,dpr:s},_=this.viewport,v=!_||_.viewWidth!==g.viewWidth||_.viewHeight!==g.viewHeight||_.plotWidth!==g.plotWidth||_.plotHeight!==g.plotHeight||_.scrollLeft!==g.scrollLeft||_.dpr!==g.dpr;return this.viewport=g,v&&this.onViewportChange?.(g),g}},vs=3;function ys(e,t){let n=(e-1)/(t.zoomLevelCount-1);return t.minKWidth+n*(t.maxKWidth-t.minKWidth)}function bs(e,t){let n=Math.round(e*t);return Math.max(1,Math.min(vs,Math.round(n*.6)))/t}function xs(e,t,n,r,i,a,o){let s=Math.max(1,Math.min(o.zoomLevelCount,r+e));if(s===r)return null;let c=ys(s,o),l=bs(c,o.dpr),u=B(i,a,o.dpr),d=B(c,l,o.dpr),f=(Math.round((n+t)*o.dpr)-u.startXPx)/u.unitPx;return{targetLevel:s,newKWidth:c,newKGap:l,newScrollLeft:(d.startXPx+f*d.unitPx)/o.dpr-t}}function Ss(e,t,n,r,i,a,o){let s=Math.max(1,Math.min(o.zoomLevelCount,Math.round(e)))-r;return s===0?null:xs(s,t,n,r,i,a,o)}function Cs(e){return e.open>e.close?`down`:e.open<e.close?`up`:`flat`}var $=function(e){return e.RISE_WITH_VOLUME=`rise_with_volume`,e.RISE_WITHOUT_VOLUME=`rise_without_volume`,e.FALL_WITH_VOLUME=`fall_with_volume`,e.FALL_WITHOUT_VOLUME=`fall_without_volume`,e.OTHERS=`others`,e}({}),ws={volumeAmplifyThreshold:1.5,volumeShrinkThreshold:.8,avgPeriod:20},Ts=class{prefixSum=[];dataLength=0;build(e){let t=e.length;if(t===0){this.prefixSum=[],this.dataLength=0;return}this.prefixSum=[0];for(let n=0;n<t;n++)this.prefixSum.push(this.prefixSum[n]+(e[n]?.volume??0));this.dataLength=t}query(e,t){return e<0||t>=this.dataLength||e>t?0:this.prefixSum[t+1]-this.prefixSum[e]}getVolumeMA(e,t){if(e<t-1)return 0;let n=e-t+1;return this.query(n,e)/t}get length(){return this.dataLength}};function Es(e,t,n,r=ws){let i=new Ts;i.build(e);let a=[],{volumeAmplifyThreshold:o,volumeShrinkThreshold:s,avgPeriod:c}=r;for(let r=t;r<n&&r<e.length;r++){let t=e[r]?.volume;if(r<1||!t){a.push($.OTHERS);continue}let n=i.getVolumeMA(r,c),l=e[r];if(!l){a.push($.OTHERS);continue}let u=l.close-l.open,d=u>0,f=u<0,p=t>n*o,m=t<n*s;d&&p?a.push($.RISE_WITH_VOLUME):d&&m?a.push($.RISE_WITHOUT_VOLUME):f&&p?a.push($.FALL_WITH_VOLUME):f&&m?a.push($.FALL_WITHOUT_VOLUME):a.push($.OTHERS)}return a}function Ds(){return{name:`candle`,version:`1.0.0`,description:`K线蜡烛图渲染器`,debugName:`K线`,paneId:`main`,priority:R.MAIN,draw(e){let{ctx:t,pane:n,data:r,range:i,scrollLeft:a,kWidth:o,kGap:s,dpr:c,kLinePositions:l,markerManager:u,settings:d}=e,f=r;if(!f.length)return;let p=Os({pane:n,data:f,range:i,kWidth:o,kGap:s,dpr:c,kLinePositions:l,settings:d});As(e,p)?js(t,e):ks(t,a,p),Ms(e,p,u)}}}function Os(e){let{pane:t,data:n,range:r,kWidth:i,kGap:a,dpr:o,kLinePositions:s,settings:c}=e,{kWidthPx:l}=B(i,a,o),u=c?.showVolumePriceMarkers!==!1,d=u?Es(n,r.start,r.end,ws):null,f=[],p=[],m=Math.max(1,r.end-r.start),h=new Float32Array(m*4),g=new Float32Array(m*4),_=new Float32Array(m*2*4),v=new Float32Array(m*2*4),y=0,b=0,x=0,S=0,{maxPrice:C,minPrice:w}=t.yAxis.getDisplayRange(),T=t.yAxis.getPaddingTop(),E=t.yAxis.getPaddingBottom(),D=Math.max(1,t.height-T-E),O=t.yAxis.getScaleType()!==`log`,k;if(O){let e=D/(C-w||1),t=T+D;k=n=>t-(n-w)*e}else k=e=>t.yAxis.priceToY(e);for(let e=r.start;e<r.end&&e<n.length;e++){let t=n[e];if(!t)continue;let i=k(t.open),a=k(t.close),c=k(t.high),u=k(t.low),d=s[e-r.start];if(d===void 0)continue;let m=e=>Math.round(e*o)/o,C=m(i),w=m(a),T=m(c),E=m(u),D=Math.min(C,w),O=Math.max(Math.abs(C-w),1),A=We(Math.round(d*o),D,l,O,o),j=Cs(t),M={i:e,aligned:A,trend:j,openY:i,closeY:a,highY:c,lowY:u,alignedHighY:T,alignedLowY:E,e:t},N=A.bodyRect,P=j===`up`?f:p,F=j===`up`;if(P.push(M),F){let e=y++*4;h[e]=N.x,h[e+1]=N.y,h[e+2]=N.width,h[e+3]=N.height}else{let e=b++*4;g[e]=N.x,g[e+1]=N.y,g[e+2]=N.width,g[e+3]=N.height}let I=N.y,L=N.y+N.height,ee=Math.max(t.open,t.close),te=Math.min(t.open,t.close);if(t.high>ee){let e=He(A.wickRect.x,T,I,o);if(e){let t=F?_:v,n=(F?x++:S++)*4;t[n]=e.x,t[n+1]=e.y,t[n+2]=e.width,t[n+3]=e.height}}if(t.low<te){let e=He(A.wickRect.x,L,E,o);if(e){let t=F?_:v,n=(F?x++:S++)*4;t[n]=e.x,t[n+1]=e.y,t[n+2]=e.width,t[n+3]=e.height}}}let A=f[0]?.aligned.wickRect.width??p[0]?.aligned.wickRect.width??1;return{upKLines:f,downKLines:p,upBodyBuf:h,upBodyCount:y,downBodyBuf:g,downBodyCount:b,upWickBuf:_,upWickCount:x,downWickBuf:v,downWickCount:S,wickWidth:A,relations:d,showVolumePriceMarkers:u}}function ks(e,t,n){e.save(),e.translate(-t,0),e.fillStyle=U.UP;for(let t=0;t<n.upBodyCount;t++){let r=t*4;e.fillRect(n.upBodyBuf[r],n.upBodyBuf[r+1],n.upBodyBuf[r+2],n.upBodyBuf[r+3])}e.fillStyle=U.DOWN;for(let t=0;t<n.downBodyCount;t++){let r=t*4;e.fillRect(n.downBodyBuf[r],n.downBodyBuf[r+1],n.downBodyBuf[r+2],n.downBodyBuf[r+3])}e.fillStyle=U.UP;for(let t=0;t<n.upWickCount;t++){let r=t*4;e.fillRect(n.upWickBuf[r],n.upWickBuf[r+1],n.wickWidth,n.upWickBuf[r+3])}e.fillStyle=U.DOWN;for(let t=0;t<n.downWickCount;t++){let r=t*4;e.fillRect(n.downWickBuf[r],n.downWickBuf[r+1],n.wickWidth,n.downWickBuf[r+3])}e.restore()}function As(e,t){if(e.settings?.enableWebGLRendering===!1)return!1;let n=e.candleWebGLSurface;if(!n||!n.isAvailable())return!1;n.clear();let r=t.upBodyCount===0||n.drawRectBuffer(t.upBodyBuf.subarray(0,t.upBodyCount*4),t.upBodyCount,U.UP,e.scrollLeft),i=t.downBodyCount===0||n.drawRectBuffer(t.downBodyBuf.subarray(0,t.downBodyCount*4),t.downBodyCount,U.DOWN,e.scrollLeft),a=t.upWickCount===0||n.drawRectBuffer(t.upWickBuf.subarray(0,t.upWickCount*4),t.upWickCount,U.UP,e.scrollLeft),o=t.downWickCount===0||n.drawRectBuffer(t.downWickBuf.subarray(0,t.downWickCount*4),t.downWickCount,U.DOWN,e.scrollLeft);return r&&i&&a&&o}function js(e,t){let n=t.candleWebGLSurface;n&&n.compositeTo(e)}function Ms(e,t,n){let{ctx:r,range:i,kWidth:a,dpr:o}=e;if(!(!t.showVolumePriceMarkers||!n||(e.zoomLevel??1)<2)){r.save(),r.translate(-e.scrollLeft,0);for(let s of t.upKLines){let c=t.relations?.[s.i-i.start];if(c!==void 0&&c!==$.OTHERS){let t=c===$.RISE_WITH_VOLUME||c===$.RISE_WITHOUT_VOLUME?s.alignedHighY-15:s.alignedLowY+15,l=s.i-i.start,u=e.kLineCenters[l];Ns(r,u,t,c,s.i,a,4,n,o)}}for(let s of t.downKLines){let c=t.relations?.[s.i-i.start];if(c!==void 0&&c!==$.OTHERS){let t=c===$.RISE_WITH_VOLUME||c===$.RISE_WITHOUT_VOLUME?s.alignedHighY-15:s.alignedLowY+15,l=s.i-i.start,u=e.kLineCenters[l];Ns(r,u,t,c,s.i,a,4,n,o)}}r.restore()}}function Ns(e,t,n,r,i,a,o=4,s,c){let l=e=>Math.round(e*c)/c;t=l(t),n=l(n);let u=Math.min(a,20),d=u*Math.sqrt(3)/2,f,p;switch(r){case $.RISE_WITH_VOLUME:f=`#FF4444`,p=!0;break;case $.RISE_WITHOUT_VOLUME:f=`#00C853`,p=!0;break;case $.FALL_WITH_VOLUME:f=`#FF4444`,p=!1;break;case $.FALL_WITHOUT_VOLUME:f=`#00C853`,p=!1;break;default:return}if(e.save(),e.beginPath(),p){let r=l(n-o),i=l(r-d);e.moveTo(t,i),e.lineTo(l(t-u/2),r),e.lineTo(l(t+u/2),r)}else{let r=l(n+o),i=l(r+d);e.moveTo(t,i),e.lineTo(l(t-u/2),r),e.lineTo(l(t+u/2),r)}e.closePath(),e.fillStyle=f,e.fill(),e.restore();let m,h;if(p){let e=l(l(n-o)-d);m=l(t-u/2),h=e}else{let e=l(n+o);l(e+d),m=l(t-u/2),h=e}let g;switch(r){case $.RISE_WITH_VOLUME:g=`RISE_WITH_VOLUME`;break;case $.RISE_WITHOUT_VOLUME:g=`RISE_WITHOUT_VOLUME`;break;case $.FALL_WITH_VOLUME:g=`FALL_WITH_VOLUME`;break;case $.FALL_WITHOUT_VOLUME:g=`FALL_WITHOUT_VOLUME`;break;default:return}let _=`mk_price-volume_${i}`;s.register({id:_,type:`triangle`,markerType:g,x:m,y:h,width:u,height:d,dataIndex:i,metadata:{relation:r}})}function Ps(){return{name:`gridLines`,version:`1.0.0`,description:`网格线渲染器`,debugName:`网格线`,paneId:de,priority:R.GRID,draw(e){let{ctx:t,pane:n,data:r,range:i,scrollLeft:a,kWidth:o,dpr:s,kLinePositions:c}=e,l=r;if(!l.length)return;t.save(),t.fillStyle=W.HORIZONTAL,t.translate(-a,0);let u=t.canvas.width/s,d=a,f=a+u,p=n.yAxis.getPaddingTop(),m=n.yAxis.getPaddingBottom(),h=n.yAxis.getScaleType(),g;if(h===`log`&&n.role===`price`){let e=n.yAxis.getDisplayRange(n.priceRange);g=xo({height:n.height,paddingTop:p,paddingBottom:m,isMain:!0,valueMin:e.minPrice,valueMax:e.maxPrice,scaleType:`log`}).map(e=>e.y)}else g=po({height:n.height,paddingTop:p,paddingBottom:m,isMain:n.role===`price`}).map(e=>e.y);for(let e of g){let n=Ue(d,f,e,s);n&&t.fillRect(n.x,n.y,n.width,n.height)}let _=pt(l);for(let e of _){if(e<i.start||e>=i.end||e>=l.length)continue;let r=e-i.start;if(r<0||r>=c.length)continue;let a=He(c[r]+o/2,0,n.height,s);a&&t.fillRect(a.x,a.y,a.width,a.height)}t.restore()}}}function Fs(e){let{pane:t,data:n}=e,r=n,i=r[r.length-1];if(!i)return null;let a=t.yAxis.getDisplayRange(t.priceRange);return i.close<a.minPrice||i.close>a.maxPrice?null:{price:i.close,y:Math.round(t.yAxis.priceToY(i.close)),dataIndex:r.length-1}}function Is(){return{name:`lastPriceLabelRegistrar`,version:`1.0.0`,description:`最新价 label 注册`,debugName:`最新价标签注册`,paneId:`main`,layer:`overlay`,priority:R.LAST_PRICE_LABEL,draw(e){let t=Fs(e);t&&(e.yAxisLabels||=[],e.yAxisLabels.push({dataIndex:t.dataIndex,price:t.price,y:t.y,type:`lastPrice`,style:{bgColor:`rgba(255, 247, 248, 0.98)`,borderColor:U.LAST_PRICE,textColor:U.LAST_PRICE}}))}}}function Ls(){return{name:`lastPriceLine`,version:`1.0.0`,description:`最新价虚线渲染器`,debugName:`最新价线`,paneId:`main`,priority:R.LAST_PRICE_LABEL,draw(e){let{ctx:t,scrollLeft:n,dpr:r,kLinePositions:i,paneWidth:a}=e,o=Fs(e);if(!o)return;let s=o.y;t.save(),t.translate(-n,0);let c=i[0]??0,l=a+n;t.strokeStyle=U.LAST_PRICE,t.lineWidth=1,t.setLineDash([4,3]),t.beginPath();let u=(Math.floor(s*r)+.5)/r;t.moveTo(Math.round(c*r)/r,u),t.lineTo(Math.round(l*r)/r,u),t.stroke(),t.setLineDash([]),t.restore()}}}var Rs={VOLUME:{defaultParams:{},getTitleInfo:()=>({name:`VOL`,params:[],values:[]})},MACD:{defaultParams:{fastPeriod:12,slowPeriod:26,signalPeriod:9},getTitleInfo:(e,t,n,r,i)=>t===null?null:Ra(t,n.fastPeriod??12,n.slowPeriod??26,n.signalPeriod??9,r,i)},RSI:{defaultParams:{period1:6,period2:12,period3:24},getTitleInfo:(e,t,n,r,i)=>t===null?null:Va(t,n.period1??6,n.period2??12,n.period3??24,r,i)},CCI:{defaultParams:{period:14,showCCI:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:Wa(t,n.period??14,r,i)},STOCH:{defaultParams:{n:9,m:3,showK:!0,showD:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:qa(t,n.n??9,n.m??3,r,i)},MOM:{defaultParams:{period:10,showMOM:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:Xa(t,n.period??10,r,i)},WMSR:{defaultParams:{period:14,showWMSR:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:$a(t,n.period??14,r,i)},KST:{defaultParams:{roc1:10,roc2:15,roc3:20,roc4:30,signalPeriod:9,showKST:!0,showSignal:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:no(t,n.roc1??10,n.roc2??15,n.roc3??20,n.roc4??30,n.signalPeriod??9,r,i)},FASTK:{defaultParams:{period:9,showFASTK:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:ao(t,n.period??9,r,i)},ATR:{defaultParams:{period:14,showATR:!0},getTitleInfo:(e,t,n,r,i)=>t===null?null:lo(t,n.period??14,r,i)}},zs=Object.keys(Rs);function Bs(e){return{name:`yAxis`,version:`1.0.0`,description:`Y轴价格刻度渲染器`,debugName:`Y轴`,paneId:de,priority:R.SYSTEM_YAXIS,draw(t){let{ctx:n,pane:r,dpr:i,yAxisCtx:a,data:o}=t,s=r.yAxis.getScaleType(),c=a||n,l=a?.canvas?a.canvas.width/i:e.axisWidth,u=r.yAxis.getDisplayRange(r.priceRange);if(r.capabilities.showPriceAxisTicks&&No({ctx:c,dpr:i,axisWidth:l,height:r.height,paddingTop:r.yAxis.getPaddingTop(),paddingBottom:r.yAxis.getPaddingBottom(),valueMin:u.minPrice,valueMax:u.maxPrice,isMain:!0,decimals:2,hideEdgeTicks:!1,scaleType:s}),t.yAxisRanges&&r.role===`price`)for(let e of t.yAxisRanges){let t=e.topY+r.top,n=e.bottomY-e.topY;n<=0||(c.save(),c.globalAlpha=e.opacity,c.fillStyle=e.color,c.fillRect(0,t,l,n),c.restore())}if(t.yAxisLabels&&r.role===`price`)for(let e of t.yAxisLabels){let t=e.type===`lastPrice`;ko(c,{x:0,y:r.top,width:l,height:r.height,priceY:e.y+r.top,price:e.price,dpr:i,bgColor:e.style?.bgColor??`rgba(0, 0, 0, 0.8)`,borderColor:e.style?.borderColor,textColor:e.style?.textColor??`#ffffff`,fontSize:t?12:11})}let d=e.getCrosshair?.();d&&d.activePaneId===r.id&&d.price!==null&&Do(c,{x:0,y:r.top,width:l,height:r.height,crosshairY:d.y,priceRange:u,yPaddingPx:e.yPaddingPx,dpr:i,fontSize:12,priceOffset:0,price:d.price})}}}var Vs=Symbol(`time-axis`);function Hs(e){return{name:`timeAxis`,version:`1.0.0`,description:`时间轴渲染器`,debugName:`时间轴`,paneId:Vs,priority:R.SYSTEM_XAXIS,isSystem:!0,draw(t){let{ctx:n,data:r,range:i,scrollLeft:a,kWidth:o,kGap:s,dpr:c,paneWidth:l}=t,u=r,d=n,f=l,p=e.height;if(d.setTransform(1,0,0,1,0,0),d.scale(c,c),d.clearRect(0,0,f,p),Oo(d,{x:0,y:0,width:f,height:p,data:u,scrollLeft:a,kWidth:o,kGap:s,startIndex:i.start,endIndex:i.end,dpr:c,drawTopBorder:!1,drawBottomBorder:!1}),t.xAxisRanges)for(let e of t.xAxisRanges){let t=e.leftX-a,n=e.rightX-a-t;n<=0||(d.save(),d.globalAlpha=e.opacity,d.fillStyle=e.color,d.fillRect(t,0,n,p),d.restore())}let m=e.getCrosshair?.();if(m&&typeof m.index==`number`){let e=u[m.index];e&&Eo(d,{x:0,y:0,width:f,height:p,crosshairX:m.x,timestamp:e.timestamp,dpr:c,fontSize:12})}if(t.xAxisLabels)for(let e of t.xAxisLabels){let t=e.x-a;t>=0&&t<=f&&Ao(d,{x:0,y:0,width:f,height:p,labelX:t,timestamp:e.timestamp,dpr:c,fontSize:12,bgColor:e.style?.bgColor,textColor:e.style?.textColor})}}}}function Us(e){return{name:`crosshair`,version:`1.0.0`,description:`十字线渲染器`,debugName:`十字线`,paneId:de,priority:R.SYSTEM_CROSSHAIR,layer:`overlay`,draw(t){let{pane:n,dpr:r,paneWidth:i,overlayCtx:a}=t,o=e.getCrosshairState();if(o.isDragging||!o.pos)return;let{x:s}=o.pos,c=n.id===o.activePaneId,l=-1;c&&o.price!==null&&(l=n.yAxis.priceToY(o.price));let u=a;if(!u)return;u.save(),u.beginPath(),u.rect(0,0,i,n.height),u.clip(),u.fillStyle=Ve.LINE;let d=He(s,0,n.height,r);if(d&&u.fillRect(d.x,d.y,d.width,d.height),c&&l>=0){let e=Ue(0,i,Math.min(l,n.height-1/r),r);e&&u.fillRect(e.x,e.y,e.width,e.height)}u.restore()}}}var Ws=new Map,Gs=256;function Ks(e,t){let n=`${e.font}\n${t}`,r=Ws.get(n);if(r!==void 0)return r;let i=e.measureText(t).width;return Ws.size>=Gs&&Ws.clear(),Ws.set(n,i),i}function qs(e){let t={...e};return{name:`paneTitle_${e.paneId}`,version:`1.0.0`,description:`面板标题渲染器`,debugName:`面板标题`,paneId:e.paneId,priority:R.FOREGROUND,draw(e){let{ctx:n,pane:r}=e;if(r.id!==t.paneId)return;let i=t.yOffset??12;n.save(),Oa(n,Da(12)),n.textAlign=`left`,n.textBaseline=`top`;let a=t.getTitleInfo?.();if(a){let e=12;if(n.fillStyle=Ae.PRIMARY,n.fillText(a.name,e,i),e+=Ks(n,a.name),a.params&&a.params.length>0){let t=`(${a.params.join(`,`)})`;n.fillStyle=Ae.TERTIARY,n.fillText(t,e,i),e+=Ks(n,t)+8}else e+=8;if(a.values&&a.values.length>0)for(let t of a.values){let r=`${t.label} ${t.value.toFixed(3)}`;n.fillStyle=t.color,n.fillText(r,e,i),e+=Ks(n,r)+8}}else if(n.fillStyle=Ae.PRIMARY,n.fillText(t.title,12,i),t.description){let e=Ks(n,t.title);n.fillStyle=Ae.WEAK,n.fillText(` - ${t.description}`,12+e,i)}n.restore()},setConfig(e){t={...t,...e}}}}var Js={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Ys(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Js,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M7.904 17.563a1.2 1.2 0 0 0 2.228.308l2.09-3.093l4.907 4.907a1.067 1.067 0 0 0 1.509 0l1.047-1.047a1.067 1.067 0 0 0 0-1.509l-4.907-4.907l3.113-2.09a1.2 1.2 0 0 0-.309-2.228L4 4z`},null,-1)]])}var Xs=(0,e.markRaw)({name:`tabler-pointer`,render:Ys}),Zs={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Qs(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Zs,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 19h16M4 15l4-6l4 2l4-5l4 4`},null,-1)]])}var $s=(0,e.markRaw)({name:`tabler-chart-line`,render:Qs}),ec={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function tc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,ec,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M17 7L7 17M8 7h9v9`},null,-1)]])}var nc=(0,e.markRaw)({name:`tabler-arrow-up-right`,render:tc}),rc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function ic(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,rc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M5 12h14m-6 6l6-6m-6-6l6 6`},null,-1)]])}var ac=(0,e.markRaw)({name:`tabler-arrow-right`,render:ic}),oc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function sc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,oc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M5 12h14`},null,-1)]])}var cc=(0,e.markRaw)({name:`tabler-minus`,render:sc}),lc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function uc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,lc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 12v.01M7 12h10m4 0v.01`},null,-1)]])}var dc=(0,e.markRaw)({name:`tabler-separator`,render:uc}),fc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function pc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,fc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2M9 12h6m-3-3v6`},null,-1)]])}var mc=(0,e.markRaw)({name:`tabler-crosshair`,render:pc}),hc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function gc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,hc,[...n[0]||=[(0,e.createElementVNode)(`g`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0-18 0m9-3h.01`}),(0,e.createElementVNode)(`path`,{d:`M11 12h1v4h1`})],-1)]])}var _c=(0,e.markRaw)({name:`tabler-info-circle`,render:gc}),vc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function yc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,vc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2`},null,-1)]])}var bc=(0,e.markRaw)({name:`tabler-maximize`,render:yc}),xc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Sc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,xc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M15 19v-2a2 2 0 0 1 2-2h2M15 5v2a2 2 0 0 0 2 2h2M5 15h2a2 2 0 0 1 2 2v2M5 9h2a2 2 0 0 0 2-2V5`},null,-1)]])}var Cc=(0,e.markRaw)({name:`tabler-minimize`,render:Sc}),wc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Tc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,wc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 10a7 7 0 1 0 14 0a7 7 0 1 0-14 0m4 0h6m-3-3v6m11 8l-6-6`},null,-1)]])}var Ec=(0,e.markRaw)({name:`tabler-zoom-in`,render:Tc}),Dc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Oc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Dc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 10a7 7 0 1 0 14 0a7 7 0 1 0-14 0m4 0h6m8 11l-6-6`},null,-1)]])}var kc=(0,e.markRaw)({name:`tabler-zoom-out`,render:Oc}),Ac={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function jc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ac,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 5a2 2 0 1 0 4 0a2 2 0 1 0-4 0m14 0a2 2 0 1 0 4 0a2 2 0 1 0-4 0M3 19a2 2 0 1 0 4 0a2 2 0 1 0-4 0m14 0a2 2 0 1 0 4 0a2 2 0 1 0-4 0M5 7v10M7 5h10M7 19h10m2-12v10`},null,-1)]])}var Mc=(0,e.markRaw)({name:`tabler-shape`,render:jc}),Nc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Pc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Nc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M3 7a2 2 0 1 0 4 0a2 2 0 1 0-4 0m11 8a2 2 0 1 0 4 0a2 2 0 1 0-4 0m1-9a3 3 0 1 0 6 0a3 3 0 1 0-6 0M3 18a3 3 0 1 0 6 0a3 3 0 1 0-6 0m6-1l5-1.5m-7.5-7l7.81 5.37M7 7l8-1`},null,-1)]])}var Fc=(0,e.markRaw)({name:`tabler-chart-dots-3`,render:Pc}),Ic={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Lc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Ic,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`m18 10l-6-6l-6 6zm0 4l-6 6l-6-6z`},null,-1)]])}var Rc=(0,e.markRaw)({name:`tabler-caret-up-down`,render:Lc}),zc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Bc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,zc,[...n[0]||=[(0,e.createElementVNode)(`path`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M8 4H5v16h3m8-16h3v16h-3`},null,-1)]])}var Vc=(0,e.markRaw)({name:`tabler-brackets`,render:Bc}),Hc={viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`};function Uc(t,n){return(0,e.openBlock)(),(0,e.createElementBlock)(`svg`,Hc,[...n[0]||=[(0,e.createElementVNode)(`g`,{fill:`none`,stroke:`currentColor`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065`}),(0,e.createElementVNode)(`path`,{d:`M9 12a3 3 0 1 0 6 0a3 3 0 0 0-6 0`})],-1)]])}var Wc=(0,e.markRaw)({name:`tabler-settings`,render:Uc});function Gc(){if(typeof navigator>`u`)return`desktop`;let e=navigator.userAgentData;if(e?.formFactor){let t=e.formFactor;if(t===`phone`)return`mobile`;if(t===`tablet`)return`tablet`;if(t===`desktop`)return`desktop`}if(e?.mobile===!0)return`mobile`;e?.mobile;let t=navigator.userAgent.toLowerCase();if(/android.*mobile|webos|iphone|ipod|blackberry|iemobile|opera mini|mobile/i.test(t))return`mobile`;let n=navigator.maxTouchPoints>1,r=window.screen.width>=768&&window.screen.width<=1366;return n&&r?`tablet`:`desktop`}var Kc=[{key:`showVolumePriceMarkers`,label:`显示量价关系标记`,type:`boolean`,default:!1,group:`main`},{key:`logarithmicScale`,label:`对数价格轴`,type:`boolean`,default:!1,group:`main`},{key:`disableMainPaneVerticalScroll`,label:`主图纵轴刻度自适应调整`,type:`boolean`,default:!0,group:`main`},{key:`enableWebGLRendering`,label:`启用 WebGL 硬件加速渲染`,type:`boolean`,default:Gc()===`desktop`,group:`main`},{key:`performanceTest10kKlines`,label:`万条K线性能测试`,type:`boolean`,default:!1,group:`experimental`},{key:`enableCanvasProfiler`,label:`Canvas 性能分析插桩`,type:`boolean`,default:!1,group:`experimental`}],qc=`kline-chart-settings`;function Jc(){return Object.create(null)}function Yc(){return{ctxMethods:Jc(),ctxProps:Jc(),canvasProps:Jc(),ctxMethodSources:Object.create(null)}}function Xc(e,t,n){let r=e[t]??={count:0,totalTime:0};r.count+=1,r.totalTime+=n}function Zc(e,t,n,r){Xc(e.ctxMethodSources[t]??=Jc(),n,r)}function Qc(e){return Object.entries(e).filter(([,e])=>e.count>0).map(([e,t])=>({name:e,count:t.count,totalTime:t.totalTime.toFixed(2),averageTime:(t.totalTime/t.count).toFixed(4)})).sort((e,t)=>Number(t.totalTime)-Number(e.totalTime))}var $c=!1,el=new Map,tl=new Map;function nl(e){$c=e,e?typeof window<`u`&&!window.__KMAP_CANVAS_PROFILER_INSTALLED__&&ol():sl()}function rl(){if(!$c)return`disabled`;let e=Error().stack;if(!e)return`unknown`;let t=e.split(`
49
+ `).map(e=>e.trim()).filter(Boolean);for(let e of t){if(e.includes(`canvasProfiler`)||e.includes(`CanvasRenderingContext2D`)||e===`Error`)continue;let t=e.replace(/^at\s+/,``),n=t.match(/((?:src|node_modules)[^\s)]+):(\d+):(\d+)/);if(n)return`${n[1]}:${n[2]}`;let r=t.match(/\(([^)]+):(\d+):(\d+)\)$/);return r?`${r[1]}:${r[2]}`:t}return`unknown`}function il(e,t,n,r){let i=`${e.constructor?.name??`proto`}:${t}`;if(el.has(i))return;let a=Reflect.get(e,t);typeof a==`function`&&(el.set(i,a),Reflect.set(e,t,function(...e){if(!$c)return a.apply(this,e);let i=r?.captureSource?rl():null,o=performance.now(),s=a.apply(this,e),c=performance.now()-o;return Xc(n.ctxMethods,t,c),i&&Zc(n,t,i,c),s}))}function al(e,t,n){let r=Object.getOwnPropertyDescriptor(e,t);if(!r?.set||!r.configurable)return;let i=`${e.constructor?.name??`proto`}:${t}`;tl.has(i)||(tl.set(i,r),Object.defineProperty(e,t,{configurable:!0,enumerable:r.enumerable??!1,get:r.get,set(e){if(!$c){r.set.call(this,e);return}let i=performance.now();r.set.call(this,e),Xc(n,t,performance.now()-i)}}))}function ol(){if(typeof window>`u`||window.__KMAP_CANVAS_PROFILER_INSTALLED__)return;let e=CanvasRenderingContext2D?.prototype,t=HTMLCanvasElement?.prototype;if(!e||!t)return;let n=Yc();il(e,`fillText`,n,{captureSource:!0}),il(e,`measureText`,n,{captureSource:!0}),il(e,`drawImage`,n),il(e,`save`,n),il(e,`restore`,n),il(e,`clip`,n),il(e,`setTransform`,n),il(e,`scale`,n),al(e,`font`,n.ctxProps),al(e,`filter`,n.ctxProps),al(e,`shadowBlur`,n.ctxProps),al(e,`lineWidth`,n.ctxProps),al(t,`width`,n.canvasProps),al(t,`height`,n.canvasProps),window.__KMAP_CANVAS_PROFILER_METRICS__=n,window.__KMAP_CANVAS_PROFILER_INSTALLED__=!0,window.showCanvasReport=()=>{let e=window.__KMAP_CANVAS_PROFILER_METRICS__;if(e){console.group(`[kmap] Canvas profiler report`),console.log(`ctx methods`),console.table(Qc(e.ctxMethods)),console.log(`ctx props`),console.table(Qc(e.ctxProps)),console.log(`canvas props`),console.table(Qc(e.canvasProps));for(let t of[`fillText`,`measureText`]){let n=e.ctxMethodSources[t];n&&(console.log(`${t} sources`),console.table(Qc(n).slice(0,20)))}console.groupEnd()}},window.resetCanvasReport=()=>{window.__KMAP_CANVAS_PROFILER_METRICS__=Yc()},console.info(`[kmap] Canvas profiler enabled. Use window.showCanvasReport() and window.resetCanvasReport().`)}function sl(){if(typeof window>`u`||!window.__KMAP_CANVAS_PROFILER_INSTALLED__)return;let e=CanvasRenderingContext2D?.prototype,t=HTMLCanvasElement?.prototype;el.forEach((n,r)=>{let i=r.match(/^(.+):(.+)$/);if(!i)return;let[,a,o]=i,s=null;a===`CanvasRenderingContext2D`?s=e:a===`HTMLCanvasElement`&&(s=t),s&&Reflect.set(s,o,n)}),el.clear(),tl.forEach((n,r)=>{let i=r.match(/^(.+):(.+)$/);if(!i)return;let[,a,o]=i,s=null;a===`CanvasRenderingContext2D`?s=e:a===`HTMLCanvasElement`&&(s=t),s&&n.configurable&&Object.defineProperty(s,o,n)}),tl.clear(),window.__KMAP_CANVAS_PROFILER_INSTALLED__=!1,window.__KMAP_CANVAS_PROFILER_METRICS__=void 0,window.showCanvasReport=void 0,window.resetCanvasReport=void 0,console.info(`[kmap] Canvas profiler disabled.`)}var cl={class:`left-toolbar`,"aria-label":`图表工具栏`},ll={class:`left-toolbar__group`},ul=[`title`,`aria-label`,`onClick`],dl=[`onClick`],fl=[`title`,`aria-label`,`onClick`],pl={class:`left-toolbar__group`},ml={class:`left-toolbar__group`},hl=[`title`,`aria-label`],gl={class:`left-toolbar__group`},_l={class:`settings-body`},vl={class:`settings-label`},yl=[`onUpdate:modelValue`],bl=[`onUpdate:modelValue`],xl=[`value`],Sl={class:`settings-label`},Cl=[`onUpdate:modelValue`],wl=[`onUpdate:modelValue`],Tl=[`value`],El=zt((0,e.defineComponent)({__name:`LeftToolbar`,props:{isFullscreen:{type:Boolean}},emits:[`selectTool`,`toggleFullscreen`,`zoomIn`,`zoomOut`,`settingsChange`],setup(t,{expose:n,emit:r}){let i=r,a=[{id:`cursor`,title:`光标`,icon:Xs},{id:`lines`,title:`线条`,icon:$s,children:[{id:`trend-line`,title:`线段`,icon:$s},{id:`ray`,title:`射线`,icon:nc},{id:`h-line`,title:`水平线`,icon:cc},{id:`h-ray`,title:`水平射线`,icon:ac},{id:`v-line`,title:`垂直线`,icon:dc},{id:`crosshair-line`,title:`十字线`,icon:mc},{id:`info-line`,title:`信息线`,icon:_c}]},{id:`channels`,title:`通道`,icon:Mc,children:[{id:`parallel-channel`,title:`平行通道`,icon:Mc},{id:`regression-channel`,title:`回归趋势`,icon:Fc},{id:`flat-line`,title:`平滑顶底`,icon:Rc},{id:`disjoint-channel`,title:`不相交通道`,icon:Vc}]}],o=(0,e.computed)(()=>Kc.filter(e=>e.group===`main`)),s=(0,e.computed)(()=>Kc.filter(e=>e.group===`experimental`)),c=(0,e.ref)(`cursor`),l=(0,e.ref)(null),u=(0,e.ref)(!1),d=qt();function f(){try{let e=localStorage.getItem(qc);if(e){let t=JSON.parse(e),n={};return Kc.forEach(e=>{n[e.key]=t[e.key]??e.default}),n}}catch{}let e={};return Kc.forEach(t=>{e[t.key]=t.default}),e}function p(e){try{localStorage.setItem(qc,JSON.stringify(e))}catch{}}let m=(0,e.ref)(f()),h=(0,e.ref)({...m.value});function g(e){return c.value===e.id?!0:e.children?e.children.some(e=>e.id===c.value):!1}function _(e){if(e.children?.length){if(!e.children.some(e=>e.id===c.value)){let t=e.children[0];c.value=t.id,i(`selectTool`,t.id)}y(e.id);return}c.value=e.id,i(`selectTool`,e.id),l.value=null}function v(e){c.value=e.id,i(`selectTool`,e.id),l.value=null}function y(e){l.value=l.value===e?null:e}function b(){h.value={...m.value},u.value=!0}function x(){u.value=!1}function S(){let e={};Kc.forEach(t=>{e[t.key]=t.default}),h.value=e}function C(){m.value={...h.value},p(m.value),nl(!!m.value.enableCanvasProfiler),i(`settingsChange`,{...m.value}),x()}function w(){return{...m.value}}n({getSettings:w});function T(e){e.target.closest(`.tool-item`)||(l.value=null)}return(0,e.onMounted)(()=>{document.addEventListener(`click`,T,!0),i(`settingsChange`,{...m.value}),nl(!!m.value.enableCanvasProfiler)}),(0,e.onUnmounted)(()=>{document.removeEventListener(`click`,T,!0)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,null,[(0,e.createElementVNode)(`nav`,cl,[(0,e.createElementVNode)(`div`,ll,[((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(a,t=>(0,e.createElementVNode)(`div`,{key:t.id,class:`tool-item`},[(0,e.createElementVNode)(`button`,{type:`button`,class:(0,e.normalizeClass)([`left-toolbar__button`,{active:g(t)}]),title:t.title,"aria-label":t.title,onClick:e=>_(t),onPointerdown:r[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[1]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[2]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.icon),{class:`tool-icon`,"aria-hidden":`true`})),t.children&&t.children.length?((0,e.openBlock)(),(0,e.createElementBlock)(`span`,{key:0,class:(0,e.normalizeClass)([`corner-indicator`,{open:l.value===t.id}]),onClick:(0,e.withModifiers)(e=>y(t.id),[`stop`]),"aria-label":`展开子菜单`},null,10,dl)):(0,e.createCommentVNode)(``,!0)],42,ul),(0,e.createVNode)(e.Transition,{name:`dropdown`},{default:(0,e.withCtx)(()=>[l.value===t.id&&t.children&&t.children.length?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`tool-dropdown`,onPointerdown:r[3]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[4]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[5]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.children,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:t.id,type:`button`,class:(0,e.normalizeClass)([`left-toolbar__button`,{active:c.value===t.id}]),title:t.title,"aria-label":t.title,onClick:e=>v(t)},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.icon),{class:`tool-icon`,"aria-hidden":`true`}))],10,fl))),128))],32)):(0,e.createCommentVNode)(``,!0)]),_:2},1024)])),64))]),r[22]||=(0,e.createElementVNode)(`span`,{class:`left-toolbar__divider`},null,-1),(0,e.createElementVNode)(`div`,pl,[(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:`放大`,"aria-label":`放大`,onClick:r[6]||=e=>n.$emit(`zoomIn`),onPointerdown:r[7]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[8]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[9]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(Ec),{class:`tool-icon`,"aria-hidden":`true`})],32),(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:`缩小`,"aria-label":`缩小`,onClick:r[10]||=e=>n.$emit(`zoomOut`),onPointerdown:r[11]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[12]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[13]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(kc),{class:`tool-icon`,"aria-hidden":`true`})],32)]),r[23]||=(0,e.createElementVNode)(`span`,{class:`left-toolbar__divider`},null,-1),(0,e.createElementVNode)(`div`,ml,[(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:t.isFullscreen?`退出全屏`:`全屏显示`,"aria-label":t.isFullscreen?`退出全屏`:`全屏显示`,onClick:r[14]||=e=>n.$emit(`toggleFullscreen`),onPointerdown:r[15]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[16]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[17]||=(0,e.withModifiers)(()=>{},[`stop`])},[t.isFullscreen?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(Cc),{key:0,class:`tool-icon`,"aria-hidden":`true`})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(bc),{key:1,class:`tool-icon`,"aria-hidden":`true`}))],40,hl)]),r[24]||=(0,e.createElementVNode)(`span`,{class:`left-toolbar__divider`},null,-1),(0,e.createElementVNode)(`div`,gl,[(0,e.createElementVNode)(`button`,{type:`button`,class:`left-toolbar__button`,title:`设置`,"aria-label":`设置`,onClick:b,onPointerdown:r[18]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointermove:r[19]||=(0,e.withModifiers)(()=>{},[`stop`]),onPointerup:r[20]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(Wc),{class:`tool-icon`,"aria-hidden":`true`})],32)])]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{to:(0,e.unref)(d)},[(0,e.createVNode)(e.Transition,{name:`overlay`},{default:(0,e.withCtx)(()=>[u.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`settings-overlay`,onClick:x},[(0,e.createVNode)(e.Transition,{name:`modal`},{default:(0,e.withCtx)(()=>[(0,e.createElementVNode)(`div`,{class:`settings-modal`,onClick:r[21]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`div`,{class:`settings-header`},[r[26]||=(0,e.createElementVNode)(`div`,{class:`header-left`},[(0,e.createElementVNode)(`span`,{class:`settings-title`},`图表设置`),(0,e.createElementVNode)(`span`,{class:`settings-subtitle`},`个性化配置`)],-1),(0,e.createElementVNode)(`div`,{class:`header-right`},[(0,e.createElementVNode)(`button`,{class:`settings-close`,onClick:x},[...r[25]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M18 6L6 18M6 6l12 12`})],-1)]])])]),(0,e.createElementVNode)(`div`,_l,[o.value.length>0?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:0},[r[27]||=(0,e.createElementVNode)(`div`,{class:`settings-section-divider`},[(0,e.createElementVNode)(`span`,{class:`settings-section-label`},`主图设置`)],-1),((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(o.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.key,class:`settings-item`},[(0,e.createElementVNode)(`label`,vl,[(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.label),1),t.type===`boolean`?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`input`,{key:0,type:`checkbox`,class:`settings-checkbox`,"onUpdate:modelValue":e=>h.value[t.key]=e},null,8,yl)),[[e.vModelCheckbox,h.value[t.key]]]):t.type===`select`&&t.options?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`select`,{key:1,class:`settings-select`,"onUpdate:modelValue":e=>h.value[t.key]=e},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.options,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`option`,{key:t.value,value:t.value},(0,e.toDisplayString)(t.label),9,xl))),128))],8,bl)),[[e.vModelSelect,h.value[t.key]]]):(0,e.createCommentVNode)(``,!0)])]))),128))],64)):(0,e.createCommentVNode)(``,!0),s.value.length>0?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:1},[r[28]||=(0,e.createElementVNode)(`div`,{class:`settings-section-divider`},[(0,e.createElementVNode)(`span`,{class:`settings-section-label`},`实验性 / 调试设置`)],-1),((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(s.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.key,class:`settings-item experimental`},[(0,e.createElementVNode)(`label`,Sl,[(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.label),1),t.type===`boolean`?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`input`,{key:0,type:`checkbox`,class:`settings-checkbox`,"onUpdate:modelValue":e=>h.value[t.key]=e},null,8,Cl)),[[e.vModelCheckbox,h.value[t.key]]]):t.type===`select`&&t.options?(0,e.withDirectives)(((0,e.openBlock)(),(0,e.createElementBlock)(`select`,{key:1,class:`settings-select`,"onUpdate:modelValue":e=>h.value[t.key]=e},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(t.options,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`option`,{key:t.value,value:t.value},(0,e.toDisplayString)(t.label),9,Tl))),128))],8,wl)),[[e.vModelSelect,h.value[t.key]]]):(0,e.createCommentVNode)(``,!0)])]))),128))],64)):(0,e.createCommentVNode)(``,!0)]),(0,e.createElementVNode)(`div`,{class:`settings-footer`},[(0,e.createElementVNode)(`button`,{class:`settings-btn reset`,onClick:S},[...r[29]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`},[(0,e.createElementVNode)(`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}),(0,e.createElementVNode)(`path`,{d:`M3 3v5h5`})],-1),(0,e.createTextVNode)(` 重置 `,-1)]]),(0,e.createElementVNode)(`div`,{class:`footer-right`},[(0,e.createElementVNode)(`button`,{class:`settings-btn cancel`,onClick:x},`取消`),(0,e.createElementVNode)(`button`,{class:`settings-btn confirm`,onClick:C},[...r[30]||=[(0,e.createElementVNode)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`},[(0,e.createElementVNode)(`path`,{d:`M20 6L9 17l-5-5`})],-1),(0,e.createTextVNode)(` 确定 `,-1)]])])])])]),_:1})])):(0,e.createCommentVNode)(``,!0)]),_:1})],8,[`to`]))],64))}}),[[`__scopeId`,`data-v-20a39cb3`]]),Dl={class:`chart-wrapper`},Ol={class:`pane-separator-layer`,"aria-hidden":`true`},kl=4,Al=zt((0,e.defineComponent)({__name:`KLineChart`,props:{semanticConfig:{},yPaddingPx:{default:0},minKWidth:{default:1},maxKWidth:{default:50},rightAxisWidth:{default:0},bottomAxisHeight:{default:24},priceLabelWidth:{default:60},zoomLevels:{default:20},initialZoomLevel:{default:3},isFullscreen:{type:Boolean,default:!1}},emits:[`zoomLevelChange`,`toggleFullscreen`],setup(t,{expose:n,emit:r}){let i=t,a=r,o=(0,e.ref)(null),s=(0,e.ref)(null),c=(0,e.ref)(null),l=(0,e.ref)(null),u=(0,e.ref)(null),d=(0,e.ref)(null),f=(0,e.ref)(null),p=(0,e.shallowRef)(null),m=(0,e.shallowRef)(null),h=hr({initialZoomLevel:i.initialZoomLevel??1,minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevels:i.zoomLevels,rightAxisWidth:i.rightAxisWidth,priceLabelWidth:i.priceLabelWidth});h.actions.setZoomState(h.state.zoomLevel,ys(h.state.zoomLevel,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:h.state.viewportDpr}),bs(ys(h.state.zoomLevel,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:h.state.viewportDpr}),h.state.viewportDpr)),(0,e.computed)(()=>h.state.dataLength),(0,e.computed)(()=>h.state.viewportDpr);let g=(0,e.computed)(()=>h.state.zoomLevel),_=(0,e.computed)(()=>h.state.kWidth),v=(0,e.computed)(()=>h.state.kGap),y=(0,e.computed)(()=>h.state.paneRatios),b=(0,e.computed)(()=>h.state.selectedDrawingId),x=(0,e.computed)(()=>h.state.dataVersion);function S(){p.value?.scheduleDraw()}function C(e){if(p.value?.updateSettings(e),e.performanceTest10kKlines){let e=w();console.time(`updateData-10k`),p.value?.updateData(e),console.timeEnd(`updateData-10k`),h.actions.setDataLength(e.length),h.actions.bumpDataVersion()}else m.value&&p.value?.getData()?.length===1e4&&m.value.applyConfig(i.semanticConfig)}function w(){let e=[],t=new Date(`2020-01-01`).getTime(),n=3e3;for(let r=0;r<1e4;r++){let i=t+r*864e5,a=(Math.random()-.5)*2*.02+1e-4,o=n,s=o*(1+a),c=Math.max(o,s)*(1+Math.random()*.01),l=Math.min(o,s)*(1-Math.random()*.01),u=Math.floor(1e6+Math.random()*5e6);e.push({timestamp:i,open:parseFloat(o.toFixed(2)),high:parseFloat(c.toFixed(2)),low:parseFloat(l.toFixed(2)),close:parseFloat(s.toFixed(2)),volume:u}),n=s}return e}function T(e,t,n){let r=e.getBoundingClientRect();return{width:Math.max(t,Math.round(r.width)),height:Math.max(n,Math.round(r.height))}}function E(t){t&&(0,e.nextTick)(()=>{if(!t.isConnected)return;let e=T(t,180,80);p.value?.interaction.setTooltipSize(e)})}function D(t){t&&(0,e.nextTick)(()=>{t.isConnected&&(ee.value=T(t,120,60))})}let O=(0,e.ref)({x:0,y:0}),k=(0,e.ref)(!1),A=null;function j(){A=null}function N(e){return A||=e.getBoundingClientRect(),A}let P=(0,e.shallowRef)({crosshairPos:null,crosshairIndex:null,crosshairPrice:null,hoveredIndex:null,activePaneId:null,tooltipPos:{x:0,y:0},tooltipAnchorPlacement:`right-bottom`,hoveredMarkerData:null,hoveredCustomMarker:null,isDragging:!1,isResizingPaneBoundary:!1,isHoveringPaneBoundary:!1,hoveredPaneBoundaryId:null,isHoveringRightAxis:!1}),F=(0,e.shallowRef)(null),I=(0,e.computed)(()=>{let e=b.value;return e?h.state.drawings.find(t=>t.id===e)??null:null}),L=(0,e.ref)([]),ee=(0,e.ref)({width:220,height:120}),te=(0,e.computed)(()=>{let e=l.value,t=u.value;return!e||!t?{x:0,y:0}:{x:e.offsetLeft,y:e.offsetTop}}),ne=(0,e.computed)(()=>P.value.hoveredMarkerData),re=(0,e.computed)(()=>P.value.hoveredCustomMarker),ie=(0,e.computed)(()=>P.value.isDragging),ae=(0,e.computed)(()=>P.value.isResizingPaneBoundary),oe=(0,e.computed)(()=>P.value.isHoveringPaneBoundary),se=(0,e.computed)(()=>P.value.hoveredPaneBoundaryId),ce=(0,e.computed)(()=>P.value.isHoveringRightAxis),le=(0,e.computed)(()=>P.value.hoveredIndex),ue=(0,e.computed)(()=>P.value.crosshairIndex),de=(0,e.computed)(()=>ie.value?`grabbing`:ae.value||oe.value?`ns-resize`:le.value===null?`crosshair`:`pointer`),R=(0,e.computed)(()=>{let e=P.value.hoveredIndex;if(typeof e!=`number`)return null;x.value;let t=p.value?.getData();return t&&e>=0&&e<t.length?t[e]:null}),fe=(0,e.computed)(()=>P.value.hoveredIndex),pe=(0,e.computed)(()=>P.value.tooltipPos),z=(0,e.computed)(()=>({x:pe.value.x+te.value.x,y:pe.value.y+te.value.y})),me=(0,e.computed)(()=>({left:`${z.value.x}px`,top:`${z.value.y}px`})),he=(0,e.computed)(()=>({x:O.value.x+te.value.x,y:O.value.y+te.value.y})),ge=(0,e.computed)(()=>({left:`${he.value.x}px`,top:`${he.value.y}px`})),_e=(0,e.computed)(()=>P.value.tooltipAnchorPlacement),ve=(0,e.computed)(()=>{let e=p.value?.getViewport(),t=l.value,n=e?.plotWidth??(t?t.clientWidth:0);return O.value.x+12+ee.value.width+12>n?`left-bottom`:`right-bottom`}),ye=(0,e.computed)(()=>(x.value,p.value?.getData()??[]));function be(e){F.value?.setTool(e)}function xe(e){let t=I.value;!t||!F.value||(F.value.updateDrawingStyle(t.id,e),h.actions.bumpDrawingVersion())}function V(){let e=I.value;!e||!F.value||(F.value.removeDrawing(e.id),h.actions.setSelectedDrawingId(null),h.actions.bumpDrawingVersion(),h.actions.setDrawings(F.value.getDrawings()))}function Se(e){let t=l.value;if(t){if(F.value?.onPointerDown(e,t)){h.actions.setDrawings(F.value.getDrawings()),h.actions.bumpDrawingVersion();return}p.value?.interaction.onPointerDown(e)}}function Ce(e){let t=l.value;if(t){let n=N(t);if(O.value={x:e.clientX-n.left,y:e.clientY-n.top},F.value?.onPointerMove(e,t)){h.actions.setDrawings(F.value.getDrawings());return}}p.value?.interaction.onPointerMove(e)}function we(e){let t=l.value;if(t&&F.value?.onPointerUp(e,t)){h.actions.setDrawings(F.value.getDrawings());return}p.value?.interaction.onPointerUp(e)}function Te(e){p.value?.interaction.onPointerLeave(e)}function H(e){p.value?.interaction.onRightAxisPointerDown(e)}function Ee(e){p.value?.interaction.onRightAxisPointerMove(e)}function De(e){p.value?.interaction.onRightAxisPointerUp(e)}function Oe(e){p.value?.interaction.onRightAxisPointerLeave(e)}function ke(){p.value?.interaction.onScroll()}let Ae=(0,e.ref)([]),U=(0,e.computed)(()=>{let e=[],t=new Set;for(let n of W.value)t.has(n.indicatorId)||(t.add(n.indicatorId),e.push(n.indicatorId));return e}),je=(0,e.computed)(()=>[...Ae.value,...U.value]),Me=(0,e.ref)({}),W=(0,e.ref)([]);function Ne(){let e=y.value.main??3;return W.value.length===0?[{id:`main`,ratio:e,visible:!0,role:`price`}]:[{id:`main`,ratio:e,visible:!0,role:`price`},...W.value.map(e=>({id:e.id,ratio:y.value[e.id]??1,visible:!0,role:`indicator`}))]}function G(e){return{...Rs[e].defaultParams}}let K=new Map;function Pe(e){let t=K.get(e)??0;return K.set(e,t+1),`${e}_${t}`}let q=new Map;function Fe(e,t){let n=qs({paneId:e,title:t,getTitleInfo:()=>X(e)});p.value?.useRenderer(n),q.set(e,n.name)}function Ie(e){let t=q.get(e);t&&(p.value?.removeRenderer(t),q.delete(e))}function Le(e=`VOLUME`,t){if(W.value.length>=kl)return!1;let n=Pe(e),r=t??G(e);return p.value?.createSubPane(n,e,r)?(Fe(n,e),W.value.push({id:n,indicatorId:e,params:r}),S(),!0):!1}function Re(e){let t=W.value.findIndex(t=>t.id===e);t!==-1&&W.value[t]&&(Ie(e),p.value?.removeSubPane(e),W.value.splice(t,1))}function ze(){for(let e of W.value)Ie(e.id);p.value?.clearSubPanes(),W.value=[],K.clear(),q.clear()}function Be(){let e=i.semanticConfig,t=p.value;if(!t)return;let n=e.indicators?.main;if(n)for(let e of n)e.enabled&&(Ae.value.includes(e.type)||Ae.value.push(e.type),e.params&&(Me.value[e.type]=e.params),t.enableMainIndicator(e.type,e.params))}(0,e.watch)([je,Me],([e])=>{let t=p.value;t&&(t.updateRendererConfig(`mainIndicatorLegend`,{indicators:{MA:{enabled:e.includes(`MA`),params:Me.value.MA||{}},BOLL:{enabled:e.includes(`BOLL`),params:Me.value.BOLL||{}},EXPMA:{enabled:e.includes(`EXPMA`),params:Me.value.EXPMA||{}},ENE:{enabled:e.includes(`ENE`),params:Me.value.ENE||{}}}}),S())},{deep:!0});function J(){let e=p.value?.getSubPaneEntries()??[];W.value=[],q.clear();for(let t of e){let{paneId:e,indicatorId:n,params:r}=t,i=e.match(/^(.+)_(\d+)$/);if(i){let[,e,t]=i,n=parseInt(t,10);n>=(K.get(e)??0)&&K.set(e,n+1)}Fe(e,n),W.value.push({id:e,indicatorId:n,params:{...r}})}S()}function Ve(e,t){if(!W.value.find(t=>t.id===e))return;let n=G(t);Ie(e),p.value?.replaceSubPaneIndicator(e,t,n),Fe(e,t);let r=W.value.findIndex(t=>t.id===e);r!==-1&&(W.value[r]={id:e,indicatorId:t,params:n})}let Y=new Map;function X(e){let t=W.value.find(t=>t.id===e);if(!t)return null;let n=p.value?.getData();if(!n||n.length===0)return null;let r=ue.value,i=n.length,a=Y.get(e);if(a&&a.idx===r&&a.dataLen===i)return a.result;let o=Rs[t.indicatorId],s=t.params,c=p.value?.plugin,l=c?o.getTitleInfo(n,r,s,c,e):null;return Y.set(e,{idx:r,dataLen:i,result:l}),l}function He(e,t){let n=p.value;if(n){if(e===`MA`||e===`BOLL`||e===`EXPMA`||e===`ENE`){n.toggleMainIndicator(e,t),t?Ae.value.includes(e)||Ae.value.push(e):Ae.value=Ae.value.filter(t=>t!==e);return}if(zs.includes(e)){if(t){if(W.value.find(t=>t.indicatorId===e))return;if(!Le(e)){let t=W.value[W.value.length-1];t&&Ve(t.id,e)}}else W.value.filter(t=>t.indicatorId===e).forEach(e=>Re(e.id));S()}}}function Ue(e,t){if(Me.value[e]=t,e===`MA`||e===`BOLL`||e===`EXPMA`||e===`ENE`){p.value?.updateMainIndicatorParams(e,t),S();return}if(zs.includes(e)){W.value.filter(t=>t.indicatorId===e).forEach(e=>{p.value?.updateSubPaneParams(e.id,t),e.params={...t}}),S();return}S()}function We(e){if(!e.length||W.value.length<=1)return;let t=e.filter(e=>zs.includes(e));if(!t.length)return;let n=new Map(W.value.map(e=>[e.indicatorId,e])),r=[];for(let e of t){let t=n.get(e);t&&(r.push(t),n.delete(e))}if(r.length===0)return;for(let e of W.value)n.has(e.indicatorId)&&(r.push(e),n.delete(e.indicatorId));let i=W.value.map(e=>e.id),a=r.map(e=>e.id);if(i.join(`|`)===a.join(`|`))return;W.value=r;let o=p.value;o&&o.updatePaneLayout(Ne())}let Ge=(0,e.computed)(()=>i.rightAxisWidth+i.priceLabelWidth),Ke=h.computed.totalWidth;function qe(){let e=l.value,t=p.value;if(!e||!t)return;let n=t.getData()?.length??0;if(n===0)return;let r=t.getCurrentDpr(),{unitPx:i,startXPx:a}=B(_.value,v.value,r),o=(a+n*i)/r,s=Math.max(0,e.scrollWidth-e.clientWidth),c=Math.min(s,Math.max(0,o-e.clientWidth));e.scrollLeft=Math.round(c*r)/r,S()}function Je(t,n){let r=p.value,o=l.value;if(!r||!o)return;let s=r.getCurrentDpr(),c=Ss(t,n??(r.getViewport()?.plotWidth??o.clientWidth)/2,o.scrollLeft,g.value,_.value,v.value,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:s});c&&(h.actions.setZoomState(c.targetLevel,c.newKWidth,c.newKGap),r.interaction.clearHover(),(0,e.nextTick)(()=>{let e=l.value;if(!e)return;let t=Math.max(0,e.scrollWidth-e.clientWidth),n=Math.min(Math.max(0,c.newScrollLeft),t);e.scrollLeft=Math.round(n*s)/s,r.applyRenderState(c.newKWidth,c.newKGap,c.targetLevel),a(`zoomLevelChange`,c.targetLevel,c.newKWidth)}))}n({scheduleRender:S,scrollToRight:qe,addSubPane:Le,removeSubPane:Re,switchSubIndicator:Ve,clearAllSubPanes:ze,get plugin(){return p.value?.plugin},zoomToLevel:Je,zoomIn:e=>Je(g.value+1,e),zoomOut:e=>Je(g.value-1,e),getZoomLevel:()=>g.value,getZoomLevelCount:()=>p.value?.getZoomLevelCount()??10});function Xe(t){let n=n=>{n.preventDefault();let r=p.value;if(!r)return;let o=t.getBoundingClientRect(),s=n.clientX-o.left,c=t.scrollLeft,u=r.getCurrentDpr(),d=xs(n.deltaY>0?-1:1,s,c,g.value,_.value,v.value,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:u});d&&(h.actions.setZoomState(d.targetLevel,d.newKWidth,d.newKGap),r.interaction.clearHover(),(0,e.nextTick)(()=>{let e=l.value;if(!e)return;let t=Math.max(0,e.scrollWidth-e.clientWidth),n=Math.min(Math.max(0,d.newScrollLeft),t);e.scrollLeft=Math.round(n*u)/u,r.applyRenderState(d.newKWidth,d.newKGap,d.targetLevel),a(`zoomLevelChange`,d.targetLevel,d.newKWidth)}))};return t.addEventListener(`wheel`,n,{passive:!1}),n}function Ze(e,t,n,r){let a=new _s({container:e,canvasLayer:t,rightAxisLayer:n,xAxisCanvas:r},{yPaddingPx:i.yPaddingPx,rightAxisWidth:i.rightAxisWidth,bottomAxisHeight:i.bottomAxisHeight,priceLabelWidth:i.priceLabelWidth,minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,panes:[{id:`main`,ratio:1}],paneGap:0,zoomLevels:i.zoomLevels,initialZoomLevel:i.initialZoomLevel});return Qe(a),a}function Qe(e){e.useRenderer(Ps()),e.useRenderer(fa()),e.setRendererEnabled(`ma`,!1),e.useRenderer(va()),e.setRendererEnabled(`boll`,!1),e.useRenderer(ba()),e.setRendererEnabled(`expma`,!1),e.useRenderer(Ta()),e.setRendererEnabled(`ene`,!1),e.useRenderer(Ds()),e.useRenderer(Ls()),e.useRenderer(Is()),e.useRenderer(Ye());let t=i.rightAxisWidth+i.priceLabelWidth;e.useRenderer(Bs({axisWidth:t,yPaddingPx:i.yPaddingPx,getCrosshair:()=>{let t=e.interaction.crosshairPos,n=e.interaction.crosshairPrice,r=e.interaction.activePaneId;return t&&n!==null?{y:t.y,price:n,activePaneId:r}:null}})),e.useRenderer(Ma({yPaddingPx:i.yPaddingPx})),e.useRenderer(Us({getCrosshairState:()=>({pos:e.interaction.crosshairPos,activePaneId:e.interaction.activePaneId,isDragging:e.interaction.isDraggingState(),price:e.interaction.crosshairPrice})})),e.useRenderer(Hs({height:i.bottomAxisHeight,getCrosshair:()=>{let t=e.interaction.crosshairPos,n=e.interaction.crosshairIndex;return t&&n!==null?{x:t.x,index:n}:null}}))}function $e(e){e.setOnViewportChange(t=>{j(),h.state.viewportDpr!==t.dpr&&h.actions.setViewportDpr(t.dpr),h.state.viewWidth!==t.plotWidth&&h.actions.setViewWidth(t.plotWidth);let n=bs(h.state.kWidth,t.dpr);h.state.kGap!==n&&h.actions.setZoomState(h.state.zoomLevel,h.state.kWidth,n);let r=e.getOption();(r.kWidth!==h.state.kWidth||r.kGap!==n)&&e.applyRenderState(h.state.kWidth,n,h.state.zoomLevel)}),e.setOnPaneLayoutChange(t=>{j();let n={};for(let e of t)n[e.id]=e.ratio;h.actions.setPaneRatios(n);let r=e.getPaneRenderers(),i=l.value&&parseInt(getComputedStyle(l.value).borderTopWidth)||0;L.value=r.slice(0,-1).map(e=>{let t=e.getPane();return{id:t.id,top:t.top+t.height+i}})}),e.setOnDataChange(e=>{h.actions.setDataLength(e.length),h.actions.bumpDataVersion()})}function et(e){let t=f.value?.getSettings()??{showVolumePriceMarkers:!0};if(e.updateSettings(t),t.performanceTest10kKlines){let t=w();console.time(`updateData-10k`),e.updateData(t),console.timeEnd(`updateData-10k`),h.actions.setDataLength(t.length),h.actions.bumpDataVersion()}}function tt(e){F.value=new Yo(e),F.value.setCallbacks({onDrawingCreated:e=>{h.actions.setDrawings([...h.state.drawings,e]),h.actions.setSelectedDrawingId(e.id)},onToolChange:()=>{},onDrawingSelected:e=>{h.actions.setSelectedDrawingId(e?.id??null)}})}function nt(t){t.interaction.setTooltipAnchorPositioning(k.value),t.interaction.setOnInteractionChange(e=>{P.value=e}),t.interaction.setOnPinchZoom((n,r)=>{let o=l.value;if(!o||!t)return;let s=r-o.getBoundingClientRect().left,c=o.scrollLeft,u=t.getCurrentDpr(),d=xs(n,s,c,g.value,_.value,v.value,{minKWidth:i.minKWidth,maxKWidth:i.maxKWidth,zoomLevelCount:i.zoomLevels,dpr:u});d&&(h.actions.setZoomState(d.targetLevel,d.newKWidth,d.newKGap),t.interaction.clearHover(),(0,e.nextTick)(()=>{let e=l.value;if(!e)return;let n=Math.max(0,e.scrollWidth-e.clientWidth),r=Math.min(Math.max(0,d.newScrollLeft),n);e.scrollLeft=Math.round(r*u)/u,t.applyRenderState(d.newKWidth,d.newKGap,d.targetLevel),a(`zoomLevelChange`,d.targetLevel,d.newKWidth)}))}),P.value=t.interaction.getInteractionSnapshot(),h.actions.setViewportDpr(t.getCurrentDpr()),t.resize()}function rt(t){m.value=new M(t),m.value.on(`config:error`,e=>{console.error(`Semantic config error:`,e)}),m.value.on(`config:ready`,()=>{h.actions.setDataLength(t.getData()?.length??0),h.actions.bumpDataVersion(),Be(),J(),(0,e.nextTick)(()=>qe())}),m.value.applyConfig(i.semanticConfig).then(e=>{e&&!e.success&&console.error(`Semantic config apply failed:`,e.errors)})}return(0,e.onMounted)(()=>{k.value=!1;let e=l.value,t=s.value,n=c.value,r=o.value;if(!e||!t||!n||!r)return;let i=Xe(e),a=Ze(e,t,n,r);p.value=a,$e(a),a.applyRenderState(h.state.kWidth,h.state.kGap,h.state.zoomLevel),et(a),tt(a),nt(a),rt(a),a.__onWheel=i}),(0,e.onUnmounted)(()=>{let e=p.value;if(e){let t=e.__onWheel,n=l.value;t&&n&&n.removeEventListener(`wheel`,t),e.destroy()}p.value=null,F.value=null}),(0,e.watch)(()=>i.yPaddingPx,e=>{p.value?.updateOptions({yPaddingPx:e})}),(0,e.watch)(()=>i.semanticConfig,async(e,t)=>{if(e&&e!==t){let t=await m.value?.applyConfig(e);t&&!t.success&&console.error(`Semantic config apply failed:`,t.errors)}},{deep:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Dl,[(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`chart-stage`,{"is-dragging":ie.value,"is-resizing-pane":ae.value,"is-hovering-pane-separator":oe.value,"is-hovering-right-axis":ce.value,"is-hovering-kline":le.value!==null}])},[(0,e.createVNode)(El,{ref_key:`toolbarRef`,ref:f,"is-fullscreen":t.isFullscreen,onSelectTool:be,onToggleFullscreen:r[0]||=e=>n.$emit(`toggleFullscreen`),onZoomIn:r[1]||=e=>Je(g.value+1),onZoomOut:r[2]||=e=>Je(g.value-1),onSettingsChange:C},null,8,[`is-fullscreen`]),(0,e.createElementVNode)(`div`,{class:`chart-main`,ref_key:`chartMainRef`,ref:u},[(0,e.createElementVNode)(`div`,Ol,[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(L.value,t=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:t.id,class:(0,e.normalizeClass)([`pane-separator-line`,{"is-active":se.value===t.id}]),style:(0,e.normalizeStyle)({top:`${t.top}px`})},null,6))),128))]),(0,e.createElementVNode)(`div`,{ref_key:`tooltipLayerRef`,ref:d,class:`tooltip-layer`},null,512),(0,e.createElementVNode)(`div`,{class:`chart-container`,style:(0,e.normalizeStyle)({cursor:de.value}),ref_key:`containerRef`,ref:l,onScrollPassive:ke,onPointerdown:Se,onPointermove:Ce,onPointerup:we,onPointerleave:Te},[(0,e.createElementVNode)(`div`,{class:`scroll-content`,style:(0,e.normalizeStyle)({width:(0,e.unref)(Ke)+`px`})},[(0,e.createElementVNode)(`div`,{class:`canvas-layer`,ref_key:`canvasLayerRef`,ref:s},[(0,e.createElementVNode)(`canvas`,{class:`x-axis-canvas`,ref_key:`xAxisCanvasRef`,ref:o},null,512),I.value?((0,e.openBlock)(),(0,e.createBlock)(Yn,{key:0,drawing:I.value,onUpdateStyle:xe,onDelete:V},null,8,[`drawing`])):(0,e.createCommentVNode)(``,!0)],512)],4)],36),d.value?((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{key:0,to:d.value},[R.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`tooltip-anchor kline-tooltip-anchor`,{"use-anchor":k.value}]),style:(0,e.normalizeStyle)(me.value)},null,6)):(0,e.createCommentVNode)(``,!0),ne.value||re.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:1,class:(0,e.normalizeClass)([`tooltip-anchor marker-tooltip-anchor`,{"use-anchor":k.value}]),style:(0,e.normalizeStyle)(ge.value)},null,6)):(0,e.createCommentVNode)(``,!0),R.value?((0,e.openBlock)(),(0,e.createBlock)(Bt,{key:2,k:R.value,index:fe.value,data:ye.value,pos:z.value,"set-el":E,"use-anchor":k.value,"anchor-placement":_e.value},null,8,[`k`,`index`,`data`,`pos`,`use-anchor`,`anchor-placement`])):(0,e.createCommentVNode)(``,!0),ne.value||re.value?((0,e.openBlock)(),(0,e.createBlock)(Gt,{key:3,marker:ne.value||re.value,pos:he.value,"use-anchor":k.value,"anchor-placement":ve.value,"set-el":D},null,8,[`marker`,`pos`,`use-anchor`,`anchor-placement`])):(0,e.createCommentVNode)(``,!0)],8,[`to`])):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,{class:`right-axis-host`,ref_key:`rightAxisLayerRef`,ref:c,style:(0,e.normalizeStyle)({width:Ge.value+`px`}),onPointerdown:H,onPointermove:Ee,onPointerup:De,onPointerleave:Oe},null,36)],512)],2),(0,e.createVNode)(Vn,{"active-indicators":je.value,"indicator-params":Me.value,onToggle:He,onUpdateParams:Ue,onReorderSubIndicators:We},null,8,[`active-indicators`,`indicator-params`])]))}}),[[`__scopeId`,`data-v-2385e6a5`]]),jl={install(e){e.component(`KLineChart`,Al)}};exports.ConfigManager=z,exports.EventBus=t,exports.GLOBAL_PANE_ID=de,exports.HookSystem=pe,exports.KLineChart=Al,exports.KMapPlugin=jl,exports.PluginHostImpl=he,exports.PluginRegistry=fe,exports.PluginState=le,exports.RENDERER_PRIORITY=R,exports.RendererPluginManager=ke,exports.createPluginHost=ge,exports.wrapPaneInfo=ue;