@tradecanvas/core 1.4.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/dist/axis/PriceAxis.d.ts +10 -1
- package/dist/axis/PriceAxis.d.ts.map +1 -1
- package/dist/axis/TimeAxis.d.ts +7 -4
- package/dist/axis/TimeAxis.d.ts.map +1 -1
- package/dist/charts/BarRenderer.d.ts.map +1 -1
- package/dist/charts/CandlestickRenderer.d.ts.map +1 -1
- package/dist/charts/CompareRenderer.d.ts +21 -4
- package/dist/charts/CompareRenderer.d.ts.map +1 -1
- package/dist/charts/HiLoRenderer.d.ts +14 -0
- package/dist/charts/HiLoRenderer.d.ts.map +1 -0
- package/dist/charts/HollowCandleRenderer.d.ts.map +1 -1
- package/dist/charts/PeriodLevelsRenderer.d.ts.map +1 -1
- package/dist/charts/VolumeCandleRenderer.d.ts.map +1 -1
- package/dist/charts/VolumeRenderer.d.ts.map +1 -1
- package/dist/charts/denseBars.d.ts +28 -0
- package/dist/charts/denseBars.d.ts.map +1 -0
- package/dist/charts/index.d.ts +3 -0
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/transforms/kagi.d.ts +3 -2
- package/dist/charts/transforms/kagi.d.ts.map +1 -1
- package/dist/charts/transforms/renko.d.ts.map +1 -1
- package/dist/drawings/DrawingBase.d.ts +30 -1
- package/dist/drawings/DrawingBase.d.ts.map +1 -1
- package/dist/drawings/DrawingCreator.d.ts +51 -0
- package/dist/drawings/DrawingCreator.d.ts.map +1 -0
- package/dist/drawings/DrawingDrag.d.ts +36 -0
- package/dist/drawings/DrawingDrag.d.ts.map +1 -0
- package/dist/drawings/DrawingManager.d.ts +156 -33
- package/dist/drawings/DrawingManager.d.ts.map +1 -1
- package/dist/drawings/DrawingSelection.d.ts +28 -0
- package/dist/drawings/DrawingSelection.d.ts.map +1 -0
- package/dist/drawings/drawingHistory.d.ts +12 -0
- package/dist/drawings/drawingHistory.d.ts.map +1 -0
- package/dist/drawings/drawingShortcuts.d.ts +11 -0
- package/dist/drawings/drawingShortcuts.d.ts.map +1 -0
- package/dist/drawings/drawingState.d.ts +29 -0
- package/dist/drawings/drawingState.d.ts.map +1 -0
- package/dist/drawings/index.d.ts +2 -1
- package/dist/drawings/index.d.ts.map +1 -1
- package/dist/drawings/magnetSnap.d.ts +12 -0
- package/dist/drawings/magnetSnap.d.ts.map +1 -0
- package/dist/drawings/tools/AnchoredVWAP.d.ts.map +1 -1
- package/dist/drawings/tools/Circle.d.ts +1 -0
- package/dist/drawings/tools/Circle.d.ts.map +1 -1
- package/dist/drawings/tools/ElliottWave.d.ts +128 -3
- package/dist/drawings/tools/ElliottWave.d.ts.map +1 -1
- package/dist/drawings/tools/Ellipse.d.ts +1 -0
- package/dist/drawings/tools/Ellipse.d.ts.map +1 -1
- package/dist/drawings/tools/ExtendedLine.d.ts +1 -0
- package/dist/drawings/tools/ExtendedLine.d.ts.map +1 -1
- package/dist/drawings/tools/FibChannel.d.ts +7 -0
- package/dist/drawings/tools/FibChannel.d.ts.map +1 -1
- package/dist/drawings/tools/FibExtension.d.ts +20 -0
- package/dist/drawings/tools/FibExtension.d.ts.map +1 -1
- package/dist/drawings/tools/FibRetracement.d.ts +28 -0
- package/dist/drawings/tools/FibRetracement.d.ts.map +1 -1
- package/dist/drawings/tools/FibSpeedResistanceFan.d.ts +9 -1
- package/dist/drawings/tools/FibSpeedResistanceFan.d.ts.map +1 -1
- package/dist/drawings/tools/FibTimeZones.d.ts +16 -0
- package/dist/drawings/tools/FibTimeZones.d.ts.map +1 -1
- package/dist/drawings/tools/HorizontalLine.d.ts +1 -0
- package/dist/drawings/tools/HorizontalLine.d.ts.map +1 -1
- package/dist/drawings/tools/HorizontalRay.d.ts +1 -0
- package/dist/drawings/tools/HorizontalRay.d.ts.map +1 -1
- package/dist/drawings/tools/Measure.d.ts.map +1 -1
- package/dist/drawings/tools/ParallelChannel.d.ts +12 -0
- package/dist/drawings/tools/ParallelChannel.d.ts.map +1 -1
- package/dist/drawings/tools/PriceLabel.d.ts +1 -0
- package/dist/drawings/tools/PriceLabel.d.ts.map +1 -1
- package/dist/drawings/tools/PriceRange.d.ts.map +1 -1
- package/dist/drawings/tools/Ray.d.ts +1 -0
- package/dist/drawings/tools/Ray.d.ts.map +1 -1
- package/dist/drawings/tools/Rectangle.d.ts +1 -0
- package/dist/drawings/tools/Rectangle.d.ts.map +1 -1
- package/dist/drawings/tools/RegressionChannel.d.ts +1 -0
- package/dist/drawings/tools/RegressionChannel.d.ts.map +1 -1
- package/dist/drawings/tools/RiskReward.d.ts +59 -6
- package/dist/drawings/tools/RiskReward.d.ts.map +1 -1
- package/dist/drawings/tools/TextAnnotation.d.ts +1 -0
- package/dist/drawings/tools/TextAnnotation.d.ts.map +1 -1
- package/dist/drawings/tools/TrendLine.d.ts +3 -0
- package/dist/drawings/tools/TrendLine.d.ts.map +1 -1
- package/dist/drawings/tools/Triangle.d.ts +1 -0
- package/dist/drawings/tools/Triangle.d.ts.map +1 -1
- package/dist/drawings/tools/VolumeProfileRange.d.ts +1 -0
- package/dist/drawings/tools/VolumeProfileRange.d.ts.map +1 -1
- package/dist/drawings/tools/annotations.d.ts +113 -0
- package/dist/drawings/tools/annotations.d.ts.map +1 -0
- package/dist/drawings/tools/cycles.d.ts +37 -0
- package/dist/drawings/tools/cycles.d.ts.map +1 -0
- package/dist/drawings/tools/fibGeometry.d.ts +202 -0
- package/dist/drawings/tools/fibGeometry.d.ts.map +1 -0
- package/dist/drawings/tools/forecast.d.ts +85 -0
- package/dist/drawings/tools/forecast.d.ts.map +1 -0
- package/dist/drawings/tools/freehand.d.ts +81 -0
- package/dist/drawings/tools/freehand.d.ts.map +1 -0
- package/dist/drawings/tools/index.d.ts +7 -0
- package/dist/drawings/tools/index.d.ts.map +1 -1
- package/dist/drawings/tools/labels.d.ts +6 -3
- package/dist/drawings/tools/labels.d.ts.map +1 -1
- package/dist/drawings/tools/options.d.ts +8 -0
- package/dist/drawings/tools/options.d.ts.map +1 -0
- package/dist/drawings/tools/patterns.d.ts +32 -0
- package/dist/drawings/tools/patterns.d.ts.map +1 -1
- package/dist/drawings/tools/priceLevels.d.ts +29 -0
- package/dist/drawings/tools/priceLevels.d.ts.map +1 -0
- package/dist/drawings/tools/textBox.d.ts +39 -0
- package/dist/drawings/tools/textBox.d.ts.map +1 -0
- package/dist/engine/RenderEngine.d.ts +23 -0
- package/dist/engine/RenderEngine.d.ts.map +1 -1
- package/dist/events/EventBus.d.ts +2 -0
- package/dist/events/EventBus.d.ts.map +1 -1
- package/dist/features/AlertManager.d.ts +117 -6
- package/dist/features/AlertManager.d.ts.map +1 -1
- package/dist/features/ChartState.d.ts +19 -1
- package/dist/features/ChartState.d.ts.map +1 -1
- package/dist/features/DataExporter.d.ts +7 -2
- package/dist/features/DataExporter.d.ts.map +1 -1
- package/dist/features/ReplayManager.d.ts +7 -0
- package/dist/features/ReplayManager.d.ts.map +1 -1
- package/dist/features/SignalMarkerManager.d.ts +8 -0
- package/dist/features/SignalMarkerManager.d.ts.map +1 -1
- package/dist/features/TradeZoneManager.d.ts.map +1 -1
- package/dist/features/UndoRedoManager.d.ts +30 -1
- package/dist/features/UndoRedoManager.d.ts.map +1 -1
- package/dist/features/index.d.ts +3 -1
- package/dist/features/index.d.ts.map +1 -1
- package/dist/index.cjs +11 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10423 -5014
- package/dist/index.js.map +1 -1
- package/dist/indicators/IndicatorBase.d.ts +5 -1
- package/dist/indicators/IndicatorBase.d.ts.map +1 -1
- package/dist/indicators/IndicatorEngine.d.ts +121 -11
- package/dist/indicators/IndicatorEngine.d.ts.map +1 -1
- package/dist/indicators/PointwiseIndicator.d.ts +25 -0
- package/dist/indicators/PointwiseIndicator.d.ts.map +1 -0
- package/dist/indicators/index.d.ts +32 -0
- package/dist/indicators/index.d.ts.map +1 -1
- package/dist/indicators/math.d.ts +47 -0
- package/dist/indicators/math.d.ts.map +1 -0
- package/dist/indicators/overlay/ALMA.d.ts +20 -0
- package/dist/indicators/overlay/ALMA.d.ts.map +1 -0
- package/dist/indicators/overlay/Alligator.d.ts +2 -14
- package/dist/indicators/overlay/Alligator.d.ts.map +1 -1
- package/dist/indicators/overlay/AnchoredVWAP.d.ts +2 -9
- package/dist/indicators/overlay/AnchoredVWAP.d.ts.map +1 -1
- package/dist/indicators/overlay/BollingerBands.d.ts +2 -10
- package/dist/indicators/overlay/BollingerBands.d.ts.map +1 -1
- package/dist/indicators/overlay/ChandeKrollStop.d.ts +16 -0
- package/dist/indicators/overlay/ChandeKrollStop.d.ts.map +1 -0
- package/dist/indicators/overlay/ChandelierExit.d.ts +2 -10
- package/dist/indicators/overlay/ChandelierExit.d.ts.map +1 -1
- package/dist/indicators/overlay/DEMA.d.ts +11 -0
- package/dist/indicators/overlay/DEMA.d.ts.map +1 -0
- package/dist/indicators/overlay/DonchianChannel.d.ts +2 -9
- package/dist/indicators/overlay/DonchianChannel.d.ts.map +1 -1
- package/dist/indicators/overlay/EMA.d.ts +2 -9
- package/dist/indicators/overlay/EMA.d.ts.map +1 -1
- package/dist/indicators/overlay/Envelope.d.ts +2 -10
- package/dist/indicators/overlay/Envelope.d.ts.map +1 -1
- package/dist/indicators/overlay/GuppyMMA.d.ts +11 -0
- package/dist/indicators/overlay/GuppyMMA.d.ts.map +1 -0
- package/dist/indicators/overlay/HullMA.d.ts +2 -9
- package/dist/indicators/overlay/HullMA.d.ts.map +1 -1
- package/dist/indicators/overlay/Ichimoku.d.ts +2 -12
- package/dist/indicators/overlay/Ichimoku.d.ts.map +1 -1
- package/dist/indicators/overlay/KAMA.d.ts +15 -0
- package/dist/indicators/overlay/KAMA.d.ts.map +1 -0
- package/dist/indicators/overlay/KeltnerChannel.d.ts +2 -11
- package/dist/indicators/overlay/KeltnerChannel.d.ts.map +1 -1
- package/dist/indicators/overlay/LSMA.d.ts +19 -0
- package/dist/indicators/overlay/LSMA.d.ts.map +1 -0
- package/dist/indicators/overlay/LinearRegressionChannel.d.ts +2 -10
- package/dist/indicators/overlay/LinearRegressionChannel.d.ts.map +1 -1
- package/dist/indicators/overlay/MACross.d.ts +9 -0
- package/dist/indicators/overlay/MACross.d.ts.map +1 -0
- package/dist/indicators/overlay/MARibbon.d.ts +8 -0
- package/dist/indicators/overlay/MARibbon.d.ts.map +1 -0
- package/dist/indicators/overlay/MTFMovingAverage.d.ts +2 -10
- package/dist/indicators/overlay/MTFMovingAverage.d.ts.map +1 -1
- package/dist/indicators/overlay/McGinleyDynamic.d.ts +13 -0
- package/dist/indicators/overlay/McGinleyDynamic.d.ts.map +1 -0
- package/dist/indicators/overlay/ParabolicSAR.d.ts +2 -10
- package/dist/indicators/overlay/ParabolicSAR.d.ts.map +1 -1
- package/dist/indicators/overlay/PivotPoints.d.ts +2 -9
- package/dist/indicators/overlay/PivotPoints.d.ts.map +1 -1
- package/dist/indicators/overlay/SMA.d.ts +2 -9
- package/dist/indicators/overlay/SMA.d.ts.map +1 -1
- package/dist/indicators/overlay/SMMA.d.ts +13 -0
- package/dist/indicators/overlay/SMMA.d.ts.map +1 -0
- package/dist/indicators/overlay/SessionVWAP.d.ts +2 -9
- package/dist/indicators/overlay/SessionVWAP.d.ts.map +1 -1
- package/dist/indicators/overlay/StandardErrorBands.d.ts +12 -0
- package/dist/indicators/overlay/StandardErrorBands.d.ts.map +1 -0
- package/dist/indicators/overlay/Supertrend.d.ts +2 -10
- package/dist/indicators/overlay/Supertrend.d.ts.map +1 -1
- package/dist/indicators/overlay/TEMA.d.ts +2 -9
- package/dist/indicators/overlay/TEMA.d.ts.map +1 -1
- package/dist/indicators/overlay/VWAP.d.ts +2 -7
- package/dist/indicators/overlay/VWAP.d.ts.map +1 -1
- package/dist/indicators/overlay/VWMA.d.ts +2 -9
- package/dist/indicators/overlay/VWMA.d.ts.map +1 -1
- package/dist/indicators/overlay/WMA.d.ts +2 -9
- package/dist/indicators/overlay/WMA.d.ts.map +1 -1
- package/dist/indicators/overlay/WilliamsFractals.d.ts +15 -0
- package/dist/indicators/overlay/WilliamsFractals.d.ts.map +1 -0
- package/dist/indicators/overlay/ZigZag.d.ts +2 -9
- package/dist/indicators/overlay/ZigZag.d.ts.map +1 -1
- package/dist/indicators/panel/ADX.d.ts +2 -10
- package/dist/indicators/panel/ADX.d.ts.map +1 -1
- package/dist/indicators/panel/ATR.d.ts +2 -10
- package/dist/indicators/panel/ATR.d.ts.map +1 -1
- package/dist/indicators/panel/AcceleratorOscillator.d.ts +5 -10
- package/dist/indicators/panel/AcceleratorOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/AccumulationDistribution.d.ts +2 -8
- package/dist/indicators/panel/AccumulationDistribution.d.ts.map +1 -1
- package/dist/indicators/panel/Aroon.d.ts +2 -10
- package/dist/indicators/panel/Aroon.d.ts.map +1 -1
- package/dist/indicators/panel/AverageDayRange.d.ts +9 -0
- package/dist/indicators/panel/AverageDayRange.d.ts.map +1 -0
- package/dist/indicators/panel/AwesomeOscillator.d.ts +2 -11
- package/dist/indicators/panel/AwesomeOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/BalanceOfPower.d.ts +2 -10
- package/dist/indicators/panel/BalanceOfPower.d.ts.map +1 -1
- package/dist/indicators/panel/BollingerBandWidth.d.ts +18 -0
- package/dist/indicators/panel/BollingerBandWidth.d.ts.map +1 -0
- package/dist/indicators/panel/BollingerPercentB.d.ts +21 -0
- package/dist/indicators/panel/BollingerPercentB.d.ts.map +1 -0
- package/dist/indicators/panel/CCI.d.ts +2 -10
- package/dist/indicators/panel/CCI.d.ts.map +1 -1
- package/dist/indicators/panel/CMF.d.ts +2 -10
- package/dist/indicators/panel/CMF.d.ts.map +1 -1
- package/dist/indicators/panel/ChaikinOscillator.d.ts +2 -11
- package/dist/indicators/panel/ChaikinOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/ChaikinVolatility.d.ts +2 -11
- package/dist/indicators/panel/ChaikinVolatility.d.ts.map +1 -1
- package/dist/indicators/panel/ChandeMomentum.d.ts +2 -10
- package/dist/indicators/panel/ChandeMomentum.d.ts.map +1 -1
- package/dist/indicators/panel/ChoppinessIndex.d.ts +2 -10
- package/dist/indicators/panel/ChoppinessIndex.d.ts.map +1 -1
- package/dist/indicators/panel/ConnorsRSI.d.ts +2 -12
- package/dist/indicators/panel/ConnorsRSI.d.ts.map +1 -1
- package/dist/indicators/panel/Coppock.d.ts +2 -12
- package/dist/indicators/panel/Coppock.d.ts.map +1 -1
- package/dist/indicators/panel/DetrendedPriceOscillator.d.ts +2 -10
- package/dist/indicators/panel/DetrendedPriceOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/DisparityIndex.d.ts +2 -10
- package/dist/indicators/panel/DisparityIndex.d.ts.map +1 -1
- package/dist/indicators/panel/EaseOfMovement.d.ts +2 -12
- package/dist/indicators/panel/EaseOfMovement.d.ts.map +1 -1
- package/dist/indicators/panel/ElderRay.d.ts +3 -9
- package/dist/indicators/panel/ElderRay.d.ts.map +1 -1
- package/dist/indicators/panel/FisherTransform.d.ts +2 -10
- package/dist/indicators/panel/FisherTransform.d.ts.map +1 -1
- package/dist/indicators/panel/ForceIndex.d.ts +2 -10
- package/dist/indicators/panel/ForceIndex.d.ts.map +1 -1
- package/dist/indicators/panel/HistoricalVolatility.d.ts +22 -0
- package/dist/indicators/panel/HistoricalVolatility.d.ts.map +1 -0
- package/dist/indicators/panel/KST.d.ts +2 -18
- package/dist/indicators/panel/KST.d.ts.map +1 -1
- package/dist/indicators/panel/Klinger.d.ts +2 -12
- package/dist/indicators/panel/Klinger.d.ts.map +1 -1
- package/dist/indicators/panel/LinearRegressionSlope.d.ts +9 -0
- package/dist/indicators/panel/LinearRegressionSlope.d.ts.map +1 -0
- package/dist/indicators/panel/MACD.d.ts +2 -12
- package/dist/indicators/panel/MACD.d.ts.map +1 -1
- package/dist/indicators/panel/MFI.d.ts +2 -10
- package/dist/indicators/panel/MFI.d.ts.map +1 -1
- package/dist/indicators/panel/MassIndex.d.ts +2 -11
- package/dist/indicators/panel/MassIndex.d.ts.map +1 -1
- package/dist/indicators/panel/Momentum.d.ts +9 -0
- package/dist/indicators/panel/Momentum.d.ts.map +1 -0
- package/dist/indicators/panel/NetVolume.d.ts +11 -0
- package/dist/indicators/panel/NetVolume.d.ts.map +1 -0
- package/dist/indicators/panel/OBV.d.ts +2 -8
- package/dist/indicators/panel/OBV.d.ts.map +1 -1
- package/dist/indicators/panel/PercentagePriceOscillator.d.ts +2 -12
- package/dist/indicators/panel/PercentagePriceOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/PrettyGoodOscillator.d.ts +2 -10
- package/dist/indicators/panel/PrettyGoodOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/PriceVolumeTrend.d.ts +2 -8
- package/dist/indicators/panel/PriceVolumeTrend.d.ts.map +1 -1
- package/dist/indicators/panel/Qstick.d.ts +2 -10
- package/dist/indicators/panel/Qstick.d.ts.map +1 -1
- package/dist/indicators/panel/ROC.d.ts +2 -10
- package/dist/indicators/panel/ROC.d.ts.map +1 -1
- package/dist/indicators/panel/RSI.d.ts +2 -10
- package/dist/indicators/panel/RSI.d.ts.map +1 -1
- package/dist/indicators/panel/RelativeMomentumIndex.d.ts +2 -11
- package/dist/indicators/panel/RelativeMomentumIndex.d.ts.map +1 -1
- package/dist/indicators/panel/RelativeVigor.d.ts +2 -10
- package/dist/indicators/panel/RelativeVigor.d.ts.map +1 -1
- package/dist/indicators/panel/RelativeVolatilityIndex.d.ts +12 -0
- package/dist/indicators/panel/RelativeVolatilityIndex.d.ts.map +1 -0
- package/dist/indicators/panel/SchaffTrendCycle.d.ts +2 -12
- package/dist/indicators/panel/SchaffTrendCycle.d.ts.map +1 -1
- package/dist/indicators/panel/StandardError.d.ts +9 -0
- package/dist/indicators/panel/StandardError.d.ts.map +1 -0
- package/dist/indicators/panel/StdDev.d.ts +2 -10
- package/dist/indicators/panel/StdDev.d.ts.map +1 -1
- package/dist/indicators/panel/Stochastic.d.ts +2 -12
- package/dist/indicators/panel/Stochastic.d.ts.map +1 -1
- package/dist/indicators/panel/StochasticMomentumIndex.d.ts +12 -0
- package/dist/indicators/panel/StochasticMomentumIndex.d.ts.map +1 -0
- package/dist/indicators/panel/StochasticRSI.d.ts +2 -13
- package/dist/indicators/panel/StochasticRSI.d.ts.map +1 -1
- package/dist/indicators/panel/TRIX.d.ts +2 -11
- package/dist/indicators/panel/TRIX.d.ts.map +1 -1
- package/dist/indicators/panel/TSI.d.ts +2 -12
- package/dist/indicators/panel/TSI.d.ts.map +1 -1
- package/dist/indicators/panel/TrendStrengthIndex.d.ts +9 -0
- package/dist/indicators/panel/TrendStrengthIndex.d.ts.map +1 -0
- package/dist/indicators/panel/UlcerIndex.d.ts +15 -0
- package/dist/indicators/panel/UlcerIndex.d.ts.map +1 -0
- package/dist/indicators/panel/UltimateOscillator.d.ts +2 -12
- package/dist/indicators/panel/UltimateOscillator.d.ts.map +1 -1
- package/dist/indicators/panel/VROC.d.ts +2 -10
- package/dist/indicators/panel/VROC.d.ts.map +1 -1
- package/dist/indicators/panel/VolumeDelta.d.ts +2 -10
- package/dist/indicators/panel/VolumeDelta.d.ts.map +1 -1
- package/dist/indicators/panel/VolumeOscillator.d.ts +11 -0
- package/dist/indicators/panel/VolumeOscillator.d.ts.map +1 -0
- package/dist/indicators/panel/VolumeProfile.d.ts +2 -9
- package/dist/indicators/panel/VolumeProfile.d.ts.map +1 -1
- package/dist/indicators/panel/Vortex.d.ts +2 -10
- package/dist/indicators/panel/Vortex.d.ts.map +1 -1
- package/dist/indicators/panel/WilliamsAD.d.ts +2 -10
- package/dist/indicators/panel/WilliamsAD.d.ts.map +1 -1
- package/dist/indicators/panel/WilliamsR.d.ts +2 -10
- package/dist/indicators/panel/WilliamsR.d.ts.map +1 -1
- package/dist/indicators/plots.d.ts +49 -0
- package/dist/indicators/plots.d.ts.map +1 -0
- package/dist/indicators/registry.d.ts.map +1 -1
- package/dist/indicators/sources.d.ts +37 -0
- package/dist/indicators/sources.d.ts.map +1 -0
- package/dist/indicators/symbols/SymbolSeriesStore.d.ts +21 -0
- package/dist/indicators/symbols/SymbolSeriesStore.d.ts.map +1 -0
- package/dist/indicators/symbols/symbolIndicators.d.ts +34 -0
- package/dist/indicators/symbols/symbolIndicators.d.ts.map +1 -0
- package/dist/interaction/CrosshairHandler.d.ts +7 -4
- package/dist/interaction/CrosshairHandler.d.ts.map +1 -1
- package/dist/interaction/CrosshairTooltip.d.ts +11 -5
- package/dist/interaction/CrosshairTooltip.d.ts.map +1 -1
- package/dist/interaction/InteractionManager.d.ts +63 -1
- package/dist/interaction/InteractionManager.d.ts.map +1 -1
- package/dist/interaction/PaneResizeHandler.d.ts.map +1 -1
- package/dist/interaction/PinnedTooltip.d.ts +9 -1
- package/dist/interaction/PinnedTooltip.d.ts.map +1 -1
- package/dist/interaction/PriceAxisAddButton.d.ts +17 -0
- package/dist/interaction/PriceAxisAddButton.d.ts.map +1 -0
- package/dist/interaction/ZoomHandler.d.ts +8 -0
- package/dist/interaction/ZoomHandler.d.ts.map +1 -1
- package/dist/interaction/index.d.ts +2 -0
- package/dist/interaction/index.d.ts.map +1 -1
- package/dist/realtime/CurrentPriceLine.d.ts.map +1 -1
- package/dist/realtime/StreamManager.d.ts +5 -0
- package/dist/realtime/StreamManager.d.ts.map +1 -1
- package/dist/realtime/TickAggregator.d.ts.map +1 -1
- package/dist/realtime/TickBars.d.ts +58 -0
- package/dist/realtime/TickBars.d.ts.map +1 -0
- package/dist/realtime/adapters/BinanceAdapter.d.ts +24 -1
- package/dist/realtime/adapters/BinanceAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/BybitAdapter.d.ts +3 -1
- package/dist/realtime/adapters/BybitAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/CoinbaseAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/KrakenAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/MockAdapter.d.ts +19 -1
- package/dist/realtime/adapters/MockAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/PollingAdapter.d.ts +14 -1
- package/dist/realtime/adapters/PollingAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/ResamplingAdapter.d.ts +84 -0
- package/dist/realtime/adapters/ResamplingAdapter.d.ts.map +1 -0
- package/dist/realtime/adapters/WebSocketAdapter.d.ts +14 -1
- package/dist/realtime/adapters/WebSocketAdapter.d.ts.map +1 -1
- package/dist/realtime/adapters/binanceTypes.d.ts +10 -1
- package/dist/realtime/adapters/binanceTypes.d.ts.map +1 -1
- package/dist/realtime/adapters/index.d.ts +1 -0
- package/dist/realtime/adapters/index.d.ts.map +1 -1
- package/dist/realtime/index.d.ts +1 -0
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/trading/BracketTool.d.ts.map +1 -1
- package/dist/trading/OrderDraftTool.d.ts.map +1 -1
- package/dist/trading/OrderRenderer.d.ts +2 -1
- package/dist/trading/OrderRenderer.d.ts.map +1 -1
- package/dist/trading/PaperExecutionAdapter.d.ts +17 -3
- package/dist/trading/PaperExecutionAdapter.d.ts.map +1 -1
- package/dist/trading/PositionRenderer.d.ts +6 -1
- package/dist/trading/PositionRenderer.d.ts.map +1 -1
- package/dist/trading/TradingContextMenu.d.ts +1 -1
- package/dist/trading/TradingContextMenu.d.ts.map +1 -1
- package/dist/trading/TradingManager.d.ts +23 -2
- package/dist/trading/TradingManager.d.ts.map +1 -1
- package/dist/trading/fillMarks.d.ts +14 -0
- package/dist/trading/fillMarks.d.ts.map +1 -0
- package/dist/trading/lineButtons.d.ts +31 -0
- package/dist/trading/lineButtons.d.ts.map +1 -0
- package/dist/trading/positionFormat.d.ts +1 -1
- package/dist/trading/positionFormat.d.ts.map +1 -1
- package/dist/ui/BarCountdown.d.ts.map +1 -1
- package/dist/ui/PriceLines.d.ts +38 -0
- package/dist/ui/PriceLines.d.ts.map +1 -0
- package/dist/ui/SessionBreaks.d.ts +4 -1
- package/dist/ui/SessionBreaks.d.ts.map +1 -1
- package/dist/ui/SessionShading.d.ts +2 -0
- package/dist/ui/SessionShading.d.ts.map +1 -1
- package/dist/ui/axisValueLabels.d.ts +35 -0
- package/dist/ui/axisValueLabels.d.ts.map +1 -0
- package/dist/ui/index.d.ts +6 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/sessionHours.d.ts +12 -2
- package/dist/ui/sessionHours.d.ts.map +1 -1
- package/dist/ui/shapes.d.ts +9 -0
- package/dist/ui/shapes.d.ts.map +1 -0
- package/dist/viewport/Viewport.d.ts +35 -2
- package/dist/viewport/Viewport.d.ts.map +1 -1
- package/dist/viewport/index.d.ts +1 -1
- package/dist/viewport/index.d.ts.map +1 -1
- package/dist/viewport/rangePresets.d.ts +4 -2
- package/dist/viewport/rangePresets.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@tradecanvas/commons`);var t=class{canvas;ctx;dpr=1;constructor(e,t){this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0`,this.canvas.style.left=`0`,this.canvas.style.zIndex=String(t),this.canvas.style.pointerEvents=`none`,this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas)}resize(e,t){this.dpr=t;let n=Math.round(e.width*t),r=Math.round(e.height*t);(this.canvas.width!==n||this.canvas.height!==r)&&(this.canvas.width=n,this.canvas.height=r),this.canvas.style.width=`${e.width}px`,this.canvas.style.height=`${e.height}px`,this.ctx.setTransform(t,0,0,t,0,0)}clear(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}getSize(){return{width:this.canvas.width/this.dpr,height:this.canvas.height/this.dpr}}destroy(){this.canvas.remove()}},n=class{scene=null;top=null;constructor(e){this.container=e}createLayers(){this.destroy(),this.scene=new t(this.container,0),this.top=new t(this.container,1)}getLayer(t){return(t===e.LayerType.Hover?this.top:this.scene)??void 0}resize(e,t){this.scene?.resize(e,t),this.top?.resize(e,t)}destroy(){this.scene?.destroy(),this.top?.destroy(),this.scene=null,this.top=null}},r=class{animFrameId=0;running=!1;dirtyLayers=new Set;swapLayers=new Set;callback=null;setCallback(e){this.callback=e}markDirty(e){this.dirtyLayers.add(e),this.running&&!this.animFrameId&&this.scheduleFrame()}markAllDirty(){this.dirtyLayers.add(e.LayerType.Background),this.dirtyLayers.add(e.LayerType.Main),this.dirtyLayers.add(e.LayerType.Overlay),this.dirtyLayers.add(e.LayerType.UI),this.dirtyLayers.add(e.LayerType.Hover),this.running&&!this.animFrameId&&this.scheduleFrame()}start(){this.running=!0,this.markAllDirty()}stop(){this.running=!1,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}scheduleFrame(){this.animFrameId=requestAnimationFrame(()=>{if(this.animFrameId=0,!(!this.running||!this.callback)&&this.dirtyLayers.size>0){let e=this.dirtyLayers;this.dirtyLayers=this.swapLayers,this.callback(e),e.clear(),this.swapLayers=e}})}},i=class{observer=null;callback=null;currentDpr=1;resizeScheduled=!1;cachedSize;constructor(e){this.container=e,this.currentDpr=window.devicePixelRatio||1,this.cachedSize={width:e.clientWidth,height:e.clientHeight}}getDpr(){return this.currentDpr}getContainerSize(){return this.cachedSize}readContainerSize(){let e=this.container.clientWidth,t=this.container.clientHeight;return(e!==this.cachedSize.width||t!==this.cachedSize.height)&&(this.cachedSize={width:e,height:t}),this.cachedSize}onResize(e){this.callback=e,this.observer=new ResizeObserver(()=>{this.resizeScheduled||(this.resizeScheduled=!0,requestAnimationFrame(()=>{this.resizeScheduled=!1,this.currentDpr=window.devicePixelRatio||1;let e=this.container.clientWidth,t=this.container.clientHeight;e===this.cachedSize.width&&t===this.cachedSize.height||(this.cachedSize={width:e,height:t},this.callback?.(this.cachedSize,this.currentDpr))}))}),this.observer.observe(this.container)}destroy(){this.observer?.disconnect(),this.observer=null,this.callback=null}};function a(e,t){return e*(t.barWidth+t.barSpacing)-t.offset+t.chartRect.x+t.barWidth/2}function o(e,t){let{min:n,max:r}=t.priceRange,{y:i,height:a}=t.chartRect,o;if(t.logScale&&n>0&&r>0){let t=Math.log(n),s=Math.log(r)-t;if(s===0)return i+a/2;o=(Math.log(Math.max(e,2**-52))-t)/s}else{let t=r-n;if(t===0)return i+a/2;o=(e-n)/t}return i+a*(t.invertScale?o:1-o)}function s(e){let{min:t,max:n}=e.priceRange,{y:r,height:i}=e.chartRect,a=e.invertScale===!0;if(e.logScale&&t>0&&n>0){let e=Math.log(t),o=Math.log(n)-e;if(o===0)return()=>r+i/2;let s=i/o,c=r+i;return a?t=>r+(Math.log(Math.max(t,2**-52))-e)*s:t=>c-(Math.log(Math.max(t,2**-52))-e)*s}let o=n-t;if(o===0)return()=>r+i/2;let s=i/o;return a?e=>r+(e-t)*s:e=>r+(n-e)*s}function c(e,t,n,r){let{min:i,max:a}=n.priceRange,o=(a-i)/t,s=r(i+e*o),c=r(i+(e+1)*o);return{top:Math.min(s,c),height:Math.abs(s-c),mid:(s+c)/2}}function l(e,t){let n=t.barWidth+t.barSpacing;return Math.round((e-t.chartRect.x-t.barWidth/2+t.offset)/n)}function u(e,t){let{min:n,max:r}=t.priceRange,i=(e-t.chartRect.y)/t.chartRect.height,a=t.invertScale?i:1-i;if(t.logScale&&n>0&&r>0){let e=Math.log(n);return Math.exp(e+(Math.log(r)-e)*a)}return n+(r-n)*a}var d=new WeakMap;function f(e){let t=e.length;if(t<2)return 0;let n=d.get(e);if(n&&n.length===t)return n.step;let r=[];for(let n=Math.max(1,t-20);n<t;n++)r.push(e[n].time-e[n-1].time);r.sort((e,t)=>e-t);let i=Math.max(0,r[r.length>>1]);return d.set(e,{length:t,step:i}),i}function p(e){let t=f(e);return(e.length>0?e[e.length-1].time:0)>0xe8d4a51000?t:t*1e3}function m(e,t){let n=t.length;if(n===0)return e;let r=n-1;if(e>r)return t[r].time+(e-r)*f(t);if(e<0)return t[0].time+e*f(t);let i=Math.floor(e);return i===e||i>=r?t[i].time:t[i].time+(e-i)*(t[i+1].time-t[i].time)}function h(e,t){if(t.length===0)return-1;let n=t[0].time,r=t.length-1,i=t[r].time;if(e<=n||e>=i){if(e===n)return 0;if(e===i)return r;let a=f(t);return a<=0?e<n?0:r:e<n?(e-n)/a:r+(e-i)/a}let a=0,o=t.length-1;for(;a<=o;){let n=a+o>>>1;if(t[n].time===e)return n;t[n].time<e?a=n+1:o=n-1}if(a>=t.length)return t.length-1;if(o<0)return 0;let s=t[o].time,c=t[a].time,l=c===s?0:(e-s)/(c-s);return o+l}function g(e,t){let n=t.data;return n&&n.length>0?h(e,n):e}function _(e,t){return a(g(e,t),t)}function v(e,t){let n=l(e,t),r=t.data;return r&&r.length>0?m(n,r):n}var y=20;function b(e){return e<1?Math.ceil(-Math.log10(e))+1:+(e<10)}var x=class{layerManager;renderLoop;dprManager;renderCtx=null;sceneLayer;topLayer;onContainerResize=null;constructor(e){this.layerManager=new n(e),this.renderLoop=new r,this.dprManager=new i(e),this.layerManager.createLayers(),this.cacheLayerRefs(),this.renderLoop.setCallback(e=>this.render(e)),this.dprManager.onResize((e,t)=>{this.layerManager.resize(e,t),this.renderLoop.markAllDirty(),this.onContainerResize?.(e)});let t=this.dprManager.getContainerSize(),a=this.dprManager.getDpr();this.layerManager.resize(t,a)}cacheLayerRefs(){this.sceneLayer=this.layerManager.getLayer(e.LayerType.Main),this.topLayer=this.layerManager.getLayer(e.LayerType.Hover)}setRenderContext(e){this.renderCtx=e}start(){this.renderLoop.start()}stop(){this.renderLoop.stop()}requestRender(e){e===void 0?this.renderLoop.markAllDirty():this.renderLoop.markDirty(e)}render(t){let n=this.renderCtx;if(!n)return;let{chartRect:r}=n.viewport;if(r.width<=0||r.height<=0)return;let i=!1;for(let n of t)if(n!==e.LayerType.Hover){i=!0;break}i&&this.sceneLayer&&this.renderScene(this.sceneLayer,n),this.topLayer&&this.renderTop(this.topLayer,n)}renderScene(e,t){let{viewport:n,theme:r,data:i}=t;e.clear();let a=e.ctx;t.gridRenderer?.render(a,n,r),t.sessionShading?.render(a,i,n,r),t.sessionBreaks?.render(a,n,r,i),t.watermark?.render(a,n,r),a.save(),a.beginPath(),a.rect(n.chartRect.x,n.chartRect.y,n.chartRect.width,n.chartRect.height),a.clip(),t.depthHeatmap?.render(a,n,r),t.volumeRenderer?.render(a,i,n,r),t.volumeProfile?.render(a,i,n,r),t.marketProfile?.render(a,i,n,r),t.chartRenderer?.render(a,i,n,r),t.compareRenderer?.render(a,i,n,r),t.indicatorEngine?.renderOverlays(a,n),t.periodLevels?.render(a,i,n,r),t.pivotMarkers?.render(a,i,n,r),t.renderOverlayPlugins?.(a,`main`),a.restore(),this.renderPanels(a,t),t.priceLimits&&this.renderPriceLimits(a,n,r,t.priceLimits),t.tradeZoneManager?.render(a,n,r),t.drawingRenderer?.render(a,n),t.tradingRenderer?.render(a,n,r),t.signalMarkerManager?.render(a,n,r),t.alertManager?.render(a,n,r),t.priceAxis?.render(a,n,r),t.tradingRenderer?.renderAxisBadges(a,n,r),t.currentPriceLine?.render(a,n,r),t.timeAxis?.render(a,n,r,i,t.timeAxisY),this.renderPanelAxes(a,t)}renderTop(e,t){let{viewport:n,theme:r,data:i}=t;e.clear();let a=e.ctx;t.measureOverlay?.render(a,n,r),t.selectionBoxOverlay?.render(a,n,r),t.crosshairHandler?.render(a,n,r),t.renderOverlayPlugins?.(a,`overlay`),this.renderPanelCrosshair(a,t),t.crosshairHandler?.renderAxisLabels(a,n,r,i,t.timeAxisY),t.chartLegend?.render(a,n,r,i),t.barCountdown?.render(a,n,r,i),t.renderOverlayPlugins?.(a,`ui`),this.renderPanelHoverValues(a,t)}renderPanels(e,t){let{theme:n}=t,r=t.panels,i=t.indicatorEngine;if(!i||r.length===0)return;let a=`10px ${n.font.family}`,o=this.panelDescriptors(i);for(let s of r){if(s.rect.width<=0||s.rect.height<=0)continue;e.save(),e.beginPath(),e.rect(s.rect.x,s.rect.y,s.rect.width,s.rect.height),e.clip(),e.fillStyle=n.background,e.fillRect(s.rect.x,s.rect.y,s.rect.width,s.rect.height),e.fillStyle=n.axisLine,e.fillRect(s.rect.x,s.rect.y,s.rect.width,3),e.fillStyle=n.textSecondary,e.font=a,e.textBaseline=`top`,e.textAlign=`left`;let r=o.get(s.instanceId);r&&t.paneTitles!==!1&&e.fillText(r.descriptor.name,s.rect.x+6,s.rect.y+6),e.save(),e.beginPath(),e.rect(s.rect.x,s.rect.y+y,s.rect.width,s.rect.height-y),e.clip(),i.renderPanel(e,s.instanceId,s.viewport),e.restore(),e.restore()}}renderPanelAxes(t,n){let{theme:r}=n,i=n.numberLocale??`en-US`,a=`${r.font.sizeSmall}px ${r.font.family}`;for(let s of n.panels){let n=s.viewport,c=s.rect,{min:l,max:u}=n.priceRange;if(u-l<=0||c.height<=0)continue;let d=c.x+c.width,f=n.chartRect;t.strokeStyle=r.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(d+.5,c.y),t.lineTo(d+.5,c.y+c.height),t.stroke();let p=(0,e.computeTickStep)(l,u,4),m=Math.ceil(l/p)*p,h=b(p);t.font=a,t.textBaseline=`middle`,t.textAlign=`left`;for(let a=m;a<=u;a+=p){let s=o(a,n);s<f.y||s>f.y+f.height||(t.strokeStyle=r.axisLine,t.beginPath(),t.moveTo(d,Math.round(s)+.5),t.lineTo(d+4,Math.round(s)+.5),t.stroke(),t.fillStyle=r.axisLabel,t.fillText((0,e.formatPrice)(a,h,i),d+6,s))}}}renderPanelCrosshair(e,t){let n=t.crosshairHandler?.getPosition();if(!n||t.panels.length===0)return;let{theme:r}=t;for(let i of t.panels){let o=i.rect;if(n.x<o.x||n.x>o.x+o.width||n.y<o.y||n.y>o.y+o.height)continue;let s=i.viewport,c=l(n.x,s),u=a(Math.max(0,Math.min((t.data?.length??1)-1,Math.round(c))),s);e.save(),e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip(),e.setLineDash([4,4]),e.strokeStyle=r.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(u)+.5,o.y),e.lineTo(Math.round(u)+.5,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(o.x,Math.round(n.y)+.5),e.lineTo(o.x+o.width,Math.round(n.y)+.5),e.stroke(),e.setLineDash([]),e.restore();break}}renderPanelHoverValues(t,n){let r=n.crosshairHandler?.getPosition(),i=n.indicatorEngine;if(!r||n.panels.length===0)return;let{theme:a,viewport:o,data:s}=n,c=n.numberLocale??`en-US`,d=`${a.font.sizeSmall}px ${a.font.family}`,f=i?this.panelDescriptors(i):null;for(let p of n.panels){let m=p.viewport,h=p.rect,{min:g,max:_}=m.priceRange;if(_-g<=0||h.height<=0)continue;let v=h.x+h.width,y=b((0,e.computeTickStep)(g,_,4));if(r.x>=h.x&&r.x<=h.x+h.width&&r.y>=h.y&&r.y<=h.y+h.height){let n=(0,e.formatPrice)(u(r.y,m),y,c);t.font=`bold ${a.font.sizeSmall}px ${a.font.family}`;let i=t.measureText(n).width,s=Math.min(i+10,(o.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2);t.fillStyle=a.crosshair,t.fillRect(v+1,r.y-9,s,18),t.fillStyle=a.background,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(n,v+5,r.y)}if(!i||n.paneTitles===!1)continue;let x=Math.max(0,Math.min((s?.length??1)-1,Math.round(l(r.x,m)))),S=i.getOutput(p.instanceId),C=S?.series&&x<S.series.length?S.series[x]:null;if(!C)continue;let w=[];for(let e in C){let t=C[e];t!==void 0&&w.push(`${e}: ${t.toFixed(y)}`)}if(w.length===0)continue;let T=f?.get(p.instanceId);t.font=d;let E=T?t.measureText(T.descriptor.name).width+14:10;t.fillStyle=a.textSecondary,t.textBaseline=`top`,t.textAlign=`left`,t.fillText(w.join(` `),h.x+E,h.y+6)}}panelDescriptors(e){let t=new Map;for(let n of e.getPanelIndicators())t.set(n.instanceId,n);return t}renderPriceLimits(t,n,r,i){let{chartRect:a}=n,s=[{price:i.ceiling,color:i.colors?.ceiling??`#FF00FF`,label:`CE`},{price:i.floor,color:i.colors?.floor??`#00FFFF`,label:`FL`},{price:i.reference,color:i.colors?.reference??`#FFD700`,label:`REF`}],c=`bold 9px ${r.font.family}`,l=`10px ${r.font.family}`;for(let{price:r,color:i,label:u}of s){let s=o(r,n);if(s<a.y||s>a.y+a.height)continue;t.setLineDash([8,4]),t.strokeStyle=i,t.lineWidth=1,t.beginPath(),t.moveTo(a.x,Math.round(s)+.5),t.lineTo(a.x+a.width,Math.round(s)+.5),t.stroke(),t.setLineDash([]),t.font=c,t.fillStyle=i,t.textBaseline=`bottom`,t.textAlign=`left`,t.fillText(`${u} ${r.toFixed(2)}`,a.x+4,s-2);let d=a.x+a.width+1;t.fillStyle=i,t.fillRect(d,s-7,(n.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2,14),t.fillStyle=`#000`,t.font=l,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(r.toFixed(2),d+4,s)}}destroy(){this.renderLoop.stop(),this.dprManager.destroy(),this.layerManager.destroy()}},S=class{state;priceAxisWidth=e.PRICE_AXIS_WIDTH;stateCache=null;dataLength=0;minBarWidth;maxBarWidth;rightMarginBars;freePan=!0;minVisibleBars=3;constructor(t,n,r=2,i=30,a=5){this.minBarWidth=r,this.maxBarWidth=i,this.rightMarginBars=a;let o=this.computeChartRect(t,n);this.state={visibleRange:{from:0,to:0},priceRange:{min:0,max:1},barWidth:e.DEFAULT_BAR_WIDTH,barSpacing:e.DEFAULT_BAR_SPACING,offset:0,chartRect:o}}getState(){return this.stateCache||={visibleRange:{...this.state.visibleRange},priceRange:{...this.state.priceRange},barWidth:this.state.barWidth,barSpacing:this.state.barSpacing,offset:this.state.offset,chartRect:{...this.state.chartRect},logScale:this.state.logScale,scaleMode:this.state.scaleMode,scaleBaseline:this.state.scaleBaseline,invertScale:this.state.invertScale,priceAxisWidth:this.state.priceAxisWidth},this.stateCache}invalidate(){this.stateCache=null}setLogScale(e){this.setScaleMode(e?`logarithmic`:`regular`)}isLogScale(){return(this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`))===`logarithmic`}setScaleMode(e){this.state.scaleMode=e,this.state.logScale=e===`logarithmic`,this.invalidate()}getScaleMode(){return this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`)}setInvertScale(e){this.state.invertScale=e,this.invalidate()}isInvertScale(){return this.state.invertScale===!0}setScaleBaseline(e){this.state.scaleBaseline=e,this.invalidate()}setRightMargin(e){this.rightMarginBars=e}getRightMargin(){return this.rightMarginBars}setPanLimits(e){e.freePan!==void 0&&(this.freePan=e.freePan),e.minVisibleBars!==void 0&&(this.minVisibleBars=Math.max(1,Math.floor(e.minVisibleBars))),this.clampOffset(),this.updateVisibleRange()}endOffset(){let e=this.state.barWidth+this.state.barSpacing;return this.dataLength*e-this.state.chartRect.width+this.rightMarginBars*e}setPriceAxisWidth(e){this.priceAxisWidth!==e&&(this.priceAxisWidth=e,this.state.priceAxisWidth=e,this.invalidate())}computeChartRect(t,n){return{x:0,y:0,width:Math.max(0,t-this.priceAxisWidth),height:Math.max(0,n-e.TIME_AXIS_HEIGHT)}}resize(e,t){this.state.chartRect=this.computeChartRect(e,t),this.invalidate(),this.clampOffset()}setChartRect(e){this.state.chartRect={x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height)},this.invalidate(),this.clampOffset(),this.updateVisibleRange()}updateData(t,n){let r=this.dataLength===0;this.dataLength=t.length,this.dataLength!==0&&(r&&(this.state.offset=this.endOffset()),this.clampOffset(),this.updateVisibleRange(),n&&(this.state.priceRange=(0,e.computePriceRange)(t,this.state.visibleRange.from,Math.min(this.state.visibleRange.to,this.dataLength-1),.08),this.invalidate()))}setPriceRange(e,t){this.state.priceRange={min:e,max:t},this.invalidate()}scalePriceRange(e){if(!Number.isFinite(e)||e<=0)return;let{min:t,max:n}=this.state.priceRange,r=(t+n)/2,i=(n-t)/2,a=Math.max(i*e,1e-9);this.state.priceRange={min:r-a,max:r+a},this.invalidate()}scrollBy(e){this.state.offset+=e,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}panPriceRange(e){let t=this.state.chartRect.height;if(t<=0||e===0)return;let{min:n,max:r}=this.state.priceRange,i=(this.state.invertScale?-e:e)/t;if(this.isLogScale()&&n>0&&r>0){let e=Math.log(n),t=Math.log(r),a=(t-e)*i;this.state.priceRange={min:Math.exp(e-a),max:Math.exp(t-a)},this.invalidate();return}let a=(r-n)*i;this.state.priceRange={min:n-a,max:r-a},this.invalidate()}isAtEnd(){let e=this.state.barWidth+this.state.barSpacing;return Math.abs(this.state.offset-this.endOffset())<=e*2}scrollToEnd(){this.state.offset=this.endOffset(),this.invalidate(),this.updateVisibleRange()}zoom(t,n){let r=this.state.barWidth,i=(0,e.clamp)(r*(1+t),this.minBarWidth,this.maxBarWidth);if(i===r)return;let a=this.isAtEnd(),o=this.state.barWidth+this.state.barSpacing,s=(this.state.offset+n)/o;this.state.barWidth=i;let c=i+this.state.barSpacing;this.state.offset=a?this.endOffset():s*c-n,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}zoomToBarRange(t,n){let r=this.state.chartRect.width;if(r<=0||!Number.isFinite(t)||!Number.isFinite(n)||n<t)return;let i=n-t+1;this.state.barWidth=(0,e.clamp)(r/i-this.state.barSpacing,this.minBarWidth,this.maxBarWidth);let a=this.state.barWidth+this.state.barSpacing;this.state.offset=(t+n+1)/2*a-r/2,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}clampOffset(){if(this.state.chartRect.width<=0)return;let t=this.state.barWidth+this.state.barSpacing,n=this.state.chartRect.width,r=this.endOffset(),i,a;if(this.freePan&&this.dataLength>0){let e=Math.min(this.minVisibleBars,this.dataLength);i=e*t-n,a=(this.dataLength-e)*t,i=Math.min(i,r),a=Math.max(a,r)}else if(r>0)i=-(n*.5),a=r;else{let e=n*.5;i=r-e,a=r+e}this.state.offset=(0,e.clamp)(this.state.offset,i,a),this.invalidate()}updateVisibleRange(){let e=this.state.barWidth+this.state.barSpacing;if(e<=0||this.state.chartRect.width<=0)return;let t=Math.floor(this.state.offset/e),n=Math.ceil(this.state.chartRect.width/e)+1,r=Math.min(t+n,this.dataLength-1);this.state.visibleRange={from:Math.max(0,t),to:Math.max(0,r)},this.invalidate()}};function C(t,n){return(0,e.sliceVisibleData)(t,n.visibleRange.from,n.visibleRange.to)}var w=[`1D`,`5D`,`1M`,`3M`,`6M`,`YTD`,`1Y`,`5Y`,`All`],T=864e5,E=6e4,D={"1M":1,"3M":3,"6M":6,"1Y":12,"5Y":60};function O(e,t){let n=new Date(e),r=n.getUTCFullYear(),i=n.getUTCMonth()+t,a=new Date(Date.UTC(r,i+1,0)).getUTCDate();return Date.UTC(r,i,Math.min(n.getUTCDate(),a),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}function k(e,t){let n=new Date(e),r=n.getMonth()+t,i=new Date(n.getFullYear(),r+1,0).getDate();return new Date(n.getFullYear(),r,Math.min(n.getDate(),i),n.getHours(),n.getMinutes(),n.getSeconds(),n.getMilliseconds()).getTime()}function A(e,t,n=0){if(e===`All`)return null;if(e===`1D`)return t-T;if(e===`5D`)return t-5*T;let r=D[e]??0;if(n===null)return e===`YTD`?new Date(new Date(t).getFullYear(),0,1).getTime():k(t,-r);let i=n*E,a=t+i;return e===`YTD`?Date.UTC(new Date(a).getUTCFullYear(),0,1)-i:O(a,-r)-i}var ee=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=m(n.high),a=m(n.low),s=m(n.open),l=m(n.close),u=n.close>=n.open,d=u?h:g;d.moveTo(r,i),d.lineTo(r,a);let f=Math.min(s,l),y=Math.max(Math.abs(l-s),1);(u?_:v).rect(r-c,f,o,y)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(h),e.strokeStyle=r.candleDownWick,e.stroke(g),e.fillStyle=r.candleUp,e.fill(_),e.fillStyle=r.candleDown,e.fill(v)}};function te(e,t,n){if(t>=e){let t=Array(Math.max(0,e));for(let n=0;n<e;n++)t[n]=n;return t}if(t<=2)return e>=2?[0,e-1]:e===1?[0]:[];let r=[0],i=(e-2)/(t-2),a=0;for(let o=0;o<t-2;o++){let t=Math.floor((o+1)*i)+1,s=Math.floor((o+2)*i)+1;s>e&&(s=e);let c=0,l=0,u=0;for(let e=t;e<s;e++)c+=e,l+=n(e),u++;if(u>0)c/=u,l/=u;else{let r=Math.min(t,e-1);c=r,l=n(r)}let d=Math.floor(o*i)+1,f=Math.floor((o+1)*i)+1,p=n(a),m=-1,h=d;for(let e=d;e<f;e++){let t=Math.abs((a-c)*(n(e)-p)-(a-e)*(l-p));t>m&&(m=t,h=e)}r.push(h),a=h}return r.push(e-1),r}var ne=64;function re(e,t,n,r,i){let a=Math.max(0,e),o=Math.min(t,n-1);if(o<a)return[];let s=o-a+1,c=Math.max(ne,Math.ceil(r*2));if(s<=c){let e=Array(s);for(let t=0;t<s;t++)e[t]=a+t;return e}let l=te(s,c,e=>i(a+e));for(let e=0;e<l.length;e++)l[e]+=a;return l}var ie=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,c=-n.offset+n.chartRect.x+n.barWidth/2,{min:l,max:u}=n.priceRange;if(u-l===0)return;let d=s(n);e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let f=re(i,a,t.length,n.chartRect.width,e=>t[e].close),p=!1;for(let n of f){let r=n*o+c,i=d(t[n].close);p?e.lineTo(r,i):(e.moveTo(r,i),p=!0)}e.stroke()}},ae=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,c=-n.offset+n.chartRect.x+n.barWidth/2,{min:l,max:u}=n.priceRange;if(u-l===0)return;let d=s(n),f=d(l),p=re(i,a,t.length,n.chartRect.width,e=>t[e].close);if(p.length===0)return;let m=p[0],h=m*o+c,g=d(t[m].close),_=e.createLinearGradient(0,d(u),0,f);_.addColorStop(0,r.areaTopColor),_.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(h,f),e.lineTo(h,g);let v=h;for(let n=1;n<p.length;n++){let r=p[n];v=r*o+c,e.lineTo(v,d(t[r].close))}e.lineTo(v,f),e.closePath(),e.fillStyle=_,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`,e.moveTo(h,g);for(let n=1;n<p.length;n++){let r=p[n];e.lineTo(r*o+c,d(t[r].close))}e.stroke()}},oe=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open?h:g,a=m(n.high),o=m(n.low),s=m(n.open),l=m(n.close);i.moveTo(r,a),i.lineTo(r,o),i.moveTo(r-c,s),i.lineTo(r,s),i.moveTo(r,l),i.lineTo(r+c,l)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(h),e.strokeStyle=r.candleDown,e.stroke(g)}},se=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D,_=[],v=[],y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open,a=e===0||n.close>=t[e-1].close,s=m(n.high),l=m(n.low),u=m(n.open),d=m(n.close),f=Math.min(u,d),x=Math.max(Math.abs(d-u),1),S=a?h:g;S.moveTo(r,s),S.lineTo(r,l),i?(a?_:v).push({x:r-c,y:f,w:o,h:x}):(a?y:b).rect(r-c,f,o,x)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(h),e.strokeStyle=r.candleDown,e.stroke(g),e.fillStyle=r.candleUp,e.fill(y),e.fillStyle=r.candleDown,e.fill(b),e.lineWidth=1.5,e.strokeStyle=r.candleUp;for(let t of _)e.strokeRect(t.x,t.y,t.w,t.h);e.strokeStyle=r.candleDown;for(let t of v)e.strokeRect(t.x,t.y,t.w,t.h)}},ce=class{baselinePrice=null;setBaseline(e){this.baselinePrice=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=m(this.baselinePrice??this.computeBaseline(t,i,a)),{chartRect:g}=n,_=[],v=[];for(let e=i;e<=a&&e<t.length;e++)_.push(p(e)),v.push(m(t[e].close));if(_.length<2)return;let y=_.length-1;e.save();let b=m(f),x=m(d),S=new Path2D;S.rect(g.x,Math.min(h,b),g.width,Math.abs(b-h)),e.clip(S);let C=new Path2D;C.moveTo(_[0],h);for(let e=0;e<=y;e++)C.lineTo(_[e],v[e]);C.lineTo(_[y],h),C.closePath(),e.fillStyle=`${r.candleUp}20`,e.fill(C),e.restore(),e.save();let w=new Path2D;w.rect(g.x,Math.min(h,x),g.width,Math.abs(x-h)),e.clip(w);let T=new Path2D;T.moveTo(_[0],h);for(let e=0;e<=y;e++)T.lineTo(_[e],v[e]);T.lineTo(_[y],h),T.closePath(),e.fillStyle=`${r.candleDown}20`,e.fill(T),e.restore();let E=new Path2D,D=new Path2D;for(let e=1;e<=y;e++){let t=(n.invertScale?v[e]>=h:v[e]<=h)?E:D;t.moveTo(_[e-1],v[e-1]),t.lineTo(_[e],v[e])}e.lineWidth=2,e.strokeStyle=r.candleUp,e.stroke(E),e.strokeStyle=r.candleDown,e.stroke(D),e.setLineDash([6,4]),e.strokeStyle=r.textSecondary,e.lineWidth=1;let O=new Path2D;O.moveTo(g.x,h),O.lineTo(g.x+g.width,h),e.stroke(O),e.setLineDash([])}computeBaseline(e,t,n){let r=0,i=0;for(let a=t;a<=n&&a<e.length;a++)r+=e[a].close,i++;return i>0?r/i:0}},le=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open,a=m(Math.max(n.open,n.close)),s=m(Math.min(n.open,n.close)),l=Math.min(a,s),u=Math.max(Math.abs(s-a),1),d=r-c;i?(h.rect(d,l,o,u),_.rect(d,l,o,u)):(g.rect(d,l,o,u),v.rect(d,l,o,u))}e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g),e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(_),e.strokeStyle=r.candleDown,e.stroke(v)}},ue=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open,o=m(n.high),s=m(n.low),c=i?h:g;if(c.moveTo(r,o),c.lineTo(r,s),e<a&&e+1<t.length){let t=p(e+1),n=i?s:o;c.moveTo(r,n),c.lineTo(t,n)}}e.strokeStyle=r.candleUp,e.lineWidth=3,e.stroke(h),e.strokeStyle=r.candleDown,e.lineWidth=1,e.stroke(g)}},de=class{boxSize=1;setBoxSize(e){this.boxSize=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange,p=f-d;if(p===0)return;let m=n.chartRect.height/p,h=e=>e*l+u,g=s(n),_=Math.abs(this.boxSize*m),v=Math.min(c*.8,_*.8)*.5,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=n.high,o=n.low,s=Math.max(1,Math.round((a-o)/this.boxSize));for(let e=0;e<s;e++){let t=g(o+(e+.5)*this.boxSize);i?(y.moveTo(r-v,t-v),y.lineTo(r+v,t+v),y.moveTo(r+v,t-v),y.lineTo(r-v,t+v)):(b.moveTo(r+v,t),b.arc(r,t,v,0,Math.PI*2))}}e.lineWidth=1.5,e.strokeStyle=r.candleUp,e.stroke(y),e.strokeStyle=r.candleDown,e.stroke(b)}},fe=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:c}=n.priceRange;if(c-o===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.barWidth,f=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>f&&(f=t[e].volume);f===0&&(f=1);let p=new Path2D,m=new Path2D,h=new Path2D,g=new Path2D,_=e=>e*l+u,v=s(n);for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=_(e),i=v(n.high),a=v(n.low),o=v(n.open),s=v(n.close),c=n.close>=n.open,l=d*Math.max(.2,n.volume/f),u=l/2,y=c?p:m;y.moveTo(r,i),y.lineTo(r,a);let b=Math.min(o,s),x=Math.max(Math.abs(s-o),1);(c?h:g).rect(r-u,b,l,x)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(p),e.strokeStyle=r.candleDownWick,e.stroke(m),e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g)}},pe=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:c}=n.priceRange;if(c-o===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.barWidth,f=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>f&&(f=t[e].volume);f===0&&(f=1);let p=new Path2D,m=new Path2D,h=new Path2D,g=new Path2D,_=e=>e*l+u,v=s(n);for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e>0?t[e-1]:n,i=_(e),a=v(n.high),o=v(n.low),s=n.close>=r.close,c=d*Math.max(.15,n.volume/f),l=c/2,u=Math.min(a,o),y=Math.max(Math.abs(o-a),1),b=s?p:m,x=s?h:g;b.rect(i-l,u,c,y),x.rect(i-l,u,c,y)}e.fillStyle=me(r.candleUp,.55),e.fill(p),e.fillStyle=me(r.candleDown,.55),e.fill(m),e.lineWidth=1,e.strokeStyle=r.candleUpWick,e.stroke(h),e.strokeStyle=r.candleDownWick,e.stroke(g)}};function me(e,t){if(e.startsWith(`#`)){let n=Math.round(Math.max(0,Math.min(1,t))*255).toString(16).padStart(2,`0`);if(e.length===7)return`${e}${n}`;if(e.length===9)return`${e.slice(0,7)}${n}`}return e}var he=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:c}=n.priceRange;if(c-o===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=e=>e*l+u,f=s(n),p=[],m=[];for(let e=i;e<=a&&e<t.length;e++){let n=d(e);p.push({x:n,y:f(t[e].high)}),m.push({x:n,y:f(t[e].low)})}if(p.length===0)return;let h=e.createLinearGradient(0,f(c),0,f(o));h.addColorStop(0,r.areaTopColor),h.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(p[0].x,p[0].y);for(let t=1;t<p.length;t++)e.lineTo(p[t].x,p[t].y);for(let t=m.length-1;t>=0;t--)e.lineTo(m[t].x,m[t].y);e.closePath(),e.fillStyle=h,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;for(let n=i;n<=a&&n<t.length;n++){let r=d(n),a=f(t[n].close);n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke()}},ge=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:c}=n.priceRange;if(c-o===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=e=>e*l+u,f=s(n);e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`miter`;let p=0;for(let n=i;n<=a&&n<t.length;n++){let r=d(n),a=f(t[n].close);n===i?e.moveTo(r,a):(e.lineTo(r,p),e.lineTo(r,a)),p=a}e.stroke()}},_e=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:c}=n.priceRange;if(c-o===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=e=>e*l+u,f=s(n);e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let p=[];for(let n=i;n<=a&&n<t.length;n++){let r=d(n),a=f(t[n].close);p.push({x:r,y:a}),n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke();let m=Math.max(2,Math.min(4,n.barWidth*.3)),h=new Path2D;for(let{x:e,y:t}of p)h.moveTo(e+m,t),h.arc(e,t,m,0,Math.PI*2);e.fillStyle=r.lineColor,e.fill(h),e.strokeStyle=r.background,e.lineWidth=1,e.stroke(h)}},ve=class{visible=!0;heightRatio=.2;setVisible(e){this.visible=e}setHeightRatio(e){this.heightRatio=Math.max(.05,Math.min(.5,e))}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o}=n,s=n.barWidth,c=s/2,l=s+n.barSpacing,u=-n.offset+o.x+c,d=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>d&&(d=t[e].volume);if(d===0)return;let f=o.height*this.heightRatio,p=o.y+o.height,m=f/d,h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e*l+u,i=n.volume*m;(n.close>=n.open?h:g).rect(r-c,p-i,s,i)}e.globalAlpha=.35,e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g),e.globalAlpha=1}},ye=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;highlightPoC=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setHighlightPoC(e){this.highlightPoC=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:l}=n,u=l.max-l.min;if(u<=0)return;let d=new Float64Array(this.buckets),f=new Float64Array(this.buckets),p=new Float64Array(this.buckets);for(let e=i;e<=a&&e<t.length;e++){let n=t[e];if(n.volume<=0)continue;let r=Math.max(n.low,l.min),i=Math.min(n.high,l.max);if(i<=r)continue;let a=(r-l.min)/u,o=(i-l.min)/u,s=Math.max(0,Math.floor(a*this.buckets)),c=Math.min(this.buckets-1,Math.floor(o*this.buckets)),m=Math.max(1,c-s+1),h=n.volume/m,g=n.close>=n.open;for(let e=s;e<=c;e++)d[e]+=h,g?f[e]+=h:p[e]+=h}let m=0,h=-1;for(let e=0;e<d.length;e++)d[e]>m&&(m=d[e],h=e);if(m===0)return;let g=o.width*this.widthRatio,_=o.x+o.width,v=s(n),y=1/m;e.save(),e.globalAlpha=this.opacity;for(let t=0;t<this.buckets;t++){let i=d[t];if(i===0)continue;let a=c(t,this.buckets,n,v),s=i*y*g,l=f[t]*y*g,u=p[t]*y*g;l>0&&(e.fillStyle=r.candleUp,e.fillRect(_-l,a.top+.5,l,a.height-1)),u>0&&(e.fillStyle=r.candleDown,e.fillRect(_-s,a.top+.5,u,a.height-1)),this.highlightPoC&&t===h&&(e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(o.x,a.mid+.5),e.lineTo(_-s-2,a.mid+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=this.opacity)}e.restore()}};function be(e,t){return e<0?0:e>t?t:e}function xe(e,t,n,r={}){let i=Math.max(4,Math.min(500,Math.floor(r.buckets??48))),a=n-t;if(a<=0||e.length===0)return null;let o=a/i,s=new Float64Array(i);for(let r of e){let e=Math.min(r.low,r.high),a=Math.max(r.low,r.high);if(a<t||e>n)continue;let c=be(Math.floor((e-t)/o),i-1),l=be(Math.floor((a-t)/o),i-1);for(let e=c;e<=l;e++)s[e]+=1}let c=0,l=0,u=0;for(let e=0;e<i;e++)u+=s[e],s[e]>l&&(l=s[e],c=e);if(u===0)return null;let d=u*(r.valueAreaPct??.7),f=c,p=c,m=s[c];for(;m<d&&(f>0||p<i-1);){let e=f>0?s[f-1]:-1;(p<i-1?s[p+1]:-1)>=e?(p+=1,m+=s[p]):(--f,m+=s[f])}let h=[];for(let e=0;e<i;e++){let n=t+e*o;h.push({low:n,high:n+o,mid:n+o/2,count:s[e]})}return{buckets:h,pocIndex:c,maxCount:l,totalCount:u,valueAreaLow:t+f*o,valueAreaHigh:t+(p+1)*o}}function Se(e){let t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(97+t-26)}function Ce(e,t,n,r=48){let i=Math.max(4,Math.min(500,Math.floor(r))),a=n-t,o=Array.from({length:i},()=>[]);if(a<=0)return o;let s=a/i;return e.forEach((e,r)=>{let a=Math.min(e.low,e.high),c=Math.max(e.low,e.high);if(c<t||a>n)return;let l=Math.max(0,Math.min(i-1,Math.floor((a-t)/s))),u=Math.max(0,Math.min(i-1,Math.floor((c-t)/s)));for(let e=l;e<=u;e++)o[e].push(r)}),o}function we(t,n,r,i={}){if(t.length===0||r-n<=0)return[];let a=[],o=0,s=(0,e.timeframeBucketStart)(t[0].time,`1d`),c=(e,o,s)=>{let c=xe(t.slice(e,o+1),n,r,i);c&&a.push({startIndex:e,endIndex:o,startTime:s,profile:c})};for(let n=1;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,`1d`);r!==s&&(c(o,n-1,s),o=n,s=r)}return c(o,t.length-1,s),a}var Te=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;valueAreaPct=.7;highlightPoC=!0;showStats=!0;splitBySession=!1;letters=!1;lastStats=null;setVisible(e){this.visible=e,e||(this.lastStats=null)}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setValueAreaPct(e){this.valueAreaPct=Math.max(.3,Math.min(.95,e))}setHighlightPoC(e){this.highlightPoC=e}setShowStats(e){this.showStats=e}setSplitBySession(e){this.splitBySession=e}isSplitBySession(){return this.splitBySession}setLetters(e){this.letters=e}getStats(){return this.lastStats}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:l}=n,u=Math.max(0,i),d=Math.min(a,t.length-1);if(d<u)return;let f=t.slice(u,d+1);if(this.splitBySession){this.lastStats=null,this.renderSplit(e,f,u,n,r);return}let p=xe(f,l.min,l.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(!p){this.lastStats=null;return}let m=p.buckets[p.pocIndex].mid;this.lastStats={poc:m,vah:p.valueAreaHigh,val:p.valueAreaLow,valueAreaPct:this.valueAreaPct};let h=p.buckets.length,g=o.width*this.widthRatio,_=o.x,v=s(n),y=1/p.maxCount;e.save();for(let t=0;t<h;t++){let i=p.buckets[t];if(i.count===0)continue;let a=c(t,h,n,v),o=i.count*y*g,s=i.mid>=p.valueAreaLow&&i.mid<=p.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?r.candleUp:r.textSecondary,e.fillRect(_,a.top+.5,o,a.height-1)}e.globalAlpha=.6,e.strokeStyle=r.candleUp,e.lineWidth=1,e.setLineDash([1,3]);for(let t of[p.valueAreaHigh,p.valueAreaLow]){let n=v(t);e.beginPath(),e.moveTo(_,Math.round(n)+.5),e.lineTo(o.x+o.width,Math.round(n)+.5),e.stroke()}if(e.setLineDash([]),this.highlightPoC){let t=v(m);e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(_,Math.round(t)+.5),e.lineTo(o.x+o.width,Math.round(t)+.5),e.stroke(),e.setLineDash([])}this.showStats&&this.drawStats(e,o.x+6,o.y+6,m,p.valueAreaHigh,p.valueAreaLow,r),e.restore()}renderSplit(e,t,n,r,i){let{chartRect:o,priceRange:l}=r,u=we(t,l.min,l.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(u.length===0)return;let d=s(r),f=r.barWidth/2;e.save();for(let s of u){let u=s.profile,p=u.buckets.length,m=o.height/p,h=a(n+s.startIndex,r)-f,g=a(n+s.endIndex,r)+f,_=Math.max(2,g-h),v=1/u.maxCount,y=this.letters&&m>=7,b=y?Ce(t.slice(s.startIndex,s.endIndex+1),l.min,l.max,this.buckets):null;if(y&&b){e.font=`${Math.min(11,Math.floor(m))}px ui-monospace, monospace`,e.textBaseline=`middle`,e.textAlign=`left`;let t=Math.max(1,Math.floor(_/6));for(let n=0;n<p;n++){let a=b[n];if(a.length===0)continue;let o=c(n,p,r,d).mid,s=u.buckets[n].mid>=u.valueAreaLow&&u.buckets[n].mid<=u.valueAreaHigh;e.globalAlpha=s?.95:.6,e.fillStyle=s?i.candleUp:i.textSecondary;let l=Math.min(a.length,t);for(let t=0;t<l;t++)e.fillText(Se(a[t]),h+t*6,o)}}else for(let t=0;t<p;t++){let n=u.buckets[t];if(n.count===0)continue;let a=c(t,p,r,d),o=n.count*v*_,s=n.mid>=u.valueAreaLow&&n.mid<=u.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?i.candleUp:i.textSecondary,e.fillRect(h,a.top+.5,o,a.height-1)}if(this.highlightPoC){let t=d(u.buckets[u.pocIndex].mid);e.globalAlpha=1,e.strokeStyle=i.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(h,Math.round(t)+.5),e.lineTo(Math.min(g,o.x+o.width),Math.round(t)+.5),e.stroke(),e.setLineDash([])}}e.restore()}drawStats(e,t,n,r,i,a,o){let s=Ee(r),c=[[`POC`,r.toFixed(s),o.crosshair],[`VAH`,i.toFixed(s),o.candleUp],[`VAL`,a.toFixed(s),o.candleUp]];e.globalAlpha=1,e.font=`600 10px ${o.font.family}`,e.textBaseline=`middle`;let l=0;for(let[,t]of c)l=Math.max(l,e.measureText(t).width);let u=38+l,d=6+c.length*14;e.fillStyle=o.background,e.globalAlpha=.82,De(e,t,n,u,d,4),e.fill(),e.globalAlpha=1,c.forEach(([r,i,a],s)=>{let c=n+6/2+14/2+s*14;e.fillStyle=a,e.textAlign=`left`,e.fillText(r,t+6,c),e.fillStyle=o.text,e.textAlign=`right`,e.fillText(i,t+u-6,c)}),e.textAlign=`left`}};function Ee(e){let t=Math.abs(e);return t>=1e3?2:t>=1?4:6}function De(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function Oe(t,n){let r=n===`day`?`1d`:`1w`,i=[];for(let n of t){let t=(0,e.timeframeBucketStart)(n.time,r),a=i[i.length-1];a&&a.key===t?(a.high=Math.max(a.high,n.high),a.low=Math.min(a.low,n.low),a.close=n.close):i.push({key:t,open:n.open,high:n.high,low:n.low,close:n.close})}return i}function ke(e,t=`day`){let n=Oe(e,t);if(n.length<2)return[];let r=n[n.length-2],i=n[n.length-1],a=t===`day`?`D`:`W`;return[{id:`p${a}h`,label:`P${a}H`,price:r.high},{id:`p${a}c`,label:`P${a}C`,price:r.close},{id:`p${a}l`,label:`P${a}L`,price:r.low},{id:`open`,label:t===`day`?`Day Open`:`Week Open`,price:i.open}]}var Ae=class{visible=!1;period=`day`;setVisible(e){this.visible=e}isVisible(){return this.visible}setPeriod(e){this.period=e}getPeriod(){return this.period}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=ke(t,this.period);if(i.length===0)return;let{chartRect:a}=n,s=a.y,c=a.y+a.height;e.save(),e.font=`600 10px ${r.font.family}`,e.textBaseline=`middle`;for(let t of i){let i=o(t.price,n);if(i<s||i>c)continue;let l=je(t,r);e.strokeStyle=l,e.globalAlpha=.7,e.lineWidth=1,e.setLineDash([5,4]),e.beginPath(),e.moveTo(a.x,Math.round(i)+.5),e.lineTo(a.x+a.width,Math.round(i)+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=1;let u=t.label,d=e.measureText(u).width,f=a.x+a.width-d-10;e.fillStyle=r.background,e.globalAlpha=.85,e.fillRect(f-4,i-7,d+8,14),e.globalAlpha=1,e.fillStyle=l,e.textAlign=`left`,e.fillText(u,f,i+.5)}e.restore()}};function je(e,t){return e.id.endsWith(`h`)?t.candleUp:e.id.endsWith(`l`)?t.candleDown:t.textSecondary}function Me(e){let t,n;return e.map(e=>{let r;return e.type===`high`?(r=t===void 0||e.price>t?`HH`:`LH`,t=e.price):(r=n===void 0||e.price<n?`LL`:`HL`,n=e.price),{...e,label:r}})}function Ne(e,t=5,n=5){let r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),a=[];for(let t=r;t<e.length-i;t++){let n=e[t].high,o=e[t].low,s=!0,c=!0;for(let a=t-r;a<=t+i&&!(a!==t&&(e[a].high>=n&&(s=!1),e[a].low<=o&&(c=!1),!s&&!c));a++);s?a.push({index:t,price:n,type:`high`}):c&&a.push({index:t,price:o,type:`low`})}return a}var Pe=class{visible=!1;left=5;right=5;showLabels=!1;structureLabels=!1;setVisible(e){this.visible=e}isVisible(){return this.visible}setStrength(e,t){this.left=Math.max(1,Math.floor(e)),this.right=Math.max(1,Math.floor(t))}setShowLabels(e){this.showLabels=e}setStructureLabels(e){this.structureLabels=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=Ne(t,this.left,this.right);if(i.length===0)return;let s=this.structureLabels?Me(i):i,{from:c,to:l}=n.visibleRange;e.save(),e.font=`10px ${r.font.family}`,e.textAlign=`center`;for(let t of s){if(t.index<c-1||t.index>l+1)continue;let i=a(t.index,n),s=o(t.price,n),u=t.type===`high`,d=u?r.candleDown:r.candleUp,f=u!==(n.invertScale===!0),p=f?s-8:s+8;e.fillStyle=d,e.beginPath(),f?(e.moveTo(i-5,p-5),e.lineTo(i+5,p-5),e.lineTo(i,p)):(e.moveTo(i-5,p+5),e.lineTo(i+5,p+5),e.lineTo(i,p)),e.closePath(),e.fill();let m=this.structureLabels&&`label`in t?String(t.label):this.showLabels?Fe(t.price):null;m&&(e.textBaseline=f?`bottom`:`top`,e.fillText(m,i,f?p-5-1:p+5+1))}e.restore()}};function Fe(e){let t=Math.abs(e);return t>=1e3||t>=1?e.toFixed(2):e.toPrecision(4)}var Ie=class{buffer=[];constructor(e=240){this.capacity=e,this.capacity=Math.max(1,Math.floor(e))}push(e,t){let n={time:e,bids:t.bids.map(e=>({...e})),asks:t.asks.map(e=>({...e}))},r=this.buffer[this.buffer.length-1];r&&r.time===e?this.buffer[this.buffer.length-1]=n:(this.buffer.push(n),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity)))}snapshots(){return this.buffer}maxVolume(){let e=0;for(let t of this.buffer){for(let n of t.bids)n.volume>e&&(e=n.volume);for(let n of t.asks)n.volume>e&&(e=n.volume)}return e}setCapacity(e){this.capacity=Math.max(1,Math.floor(e)),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}clear(){this.buffer=[]}get size(){return this.buffer.length}},Le=class{buffer=new Ie(240);visible=!1;opacity=.7;setVisible(e){this.visible=e}isVisible(){return this.visible}setOpacity(e){this.opacity=Math.max(.1,Math.min(1,e))}setCapacity(e){this.buffer.setCapacity(e)}push(e,t){this.buffer.push(e,t)}clear(){this.buffer.clear()}render(e,t,n){if(!this.visible)return;let r=this.buffer.snapshots();if(r.length===0)return;let i=this.buffer.maxVolume();if(i<=0)return;let a=1/i,{chartRect:o}=t,s=Math.max(2,t.barWidth+t.barSpacing),c=o.x,l=o.x+o.width,u=o.y,d=o.y+o.height;e.save();for(let i of r){let r=_(i.time,t);if(r<c-s||r>l+s)continue;let o=r-s/2;this.drawSide(e,i.bids,n.candleUp,o,s,t,a,u,d),this.drawSide(e,i.asks,n.candleDown,o,s,t,a,u,d)}e.restore()}drawSide(e,t,n,r,i,a,s,c,l){if(t.length===0)return;let u=Re(t,a);e.fillStyle=n;for(let n of t){let t=o(n.price,a);t<c-u||t>l+u||(e.globalAlpha=Math.min(1,Math.sqrt(n.volume*s))*this.opacity,e.fillRect(r,t-u/2,i,u))}e.globalAlpha=1}};function Re(e,t){if(e.length<2)return 3;let n=e.map(e=>e.price).sort((e,t)=>e-t),r=[];for(let e=1;e<n.length;e++){let t=n[e]-n[e-1];t>0&&r.push(t)}if(r.length===0)return 3;r.sort((e,t)=>e-t);let i=r[Math.floor(r.length/2)],a=Math.abs(o(n[0],t)-o(n[0]+i,t));return Math.max(2,Math.min(a,12))}var ze=class{symbols=new Map;mode=`percent`;setMode(e){this.mode=e}addSymbol(e){this.symbols.set(e.id,e)}removeSymbol(e){this.symbols.delete(e)}setSymbolData(e,t){let n=this.symbols.get(e);n&&(n.data=t)}setSymbolVisible(e,t){let n=this.symbols.get(e);n&&(n.visible=t)}getSymbols(){return Array.from(this.symbols.values())}clear(){this.symbols.clear()}render(e,t,n,r){if(this.symbols.size===0||t.length===0)return;let{chartRect:i}=n;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.symbols.values())!i.visible||i.data.length===0||this.renderSymbol(e,i,t,n,r);e.restore()}renderSymbol(e,t,n,r,i){let{chartRect:s}=r,c=r.barWidth+r.barSpacing,l=Math.max(0,Math.floor(r.offset/c));if(l>=n.length||l>=t.data.length)return;let u=n[l].close,d=t.data[l].close;if(u===0||d===0)return;e.strokeStyle=t.color,e.lineWidth=t.lineWidth??1.5,e.lineJoin=`round`,e.beginPath();let f=!1,p=Math.min(n.length,t.data.length);for(let n=l;n<p;n++){let i=a(n,r);if(i<s.x-c)continue;if(i>s.x+s.width+c)break;let l;l=this.mode===`percent`?o(u*(1+(t.data[n].close-d)/d),r):o(t.data[n].close,r),f?e.lineTo(i,l):(e.moveTo(i,l),f=!0)}if(e.stroke(),f){let n=Math.min(l+2,p-1),i=a(n,r)+4,s;s=this.mode===`percent`?o(u*(1+(t.data[n].close-d)/d),r)-4:o(t.data[n].close,r)-4,e.fillStyle=t.color,e.font=`bold 10px sans-serif`,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(t.label,i,s)}}};function Be(e){if(e.length===0)return[];let t=[],n=e[0].open,r=(e[0].open+e[0].high+e[0].low+e[0].close)/4;for(let i=0;i<e.length;i++){let a=e[i],o=(a.open+a.high+a.low+a.close)/4,s=i===0?a.open:(n+r)/2,c=Math.max(a.high,s,o),l=Math.min(a.low,s,o);t.push({time:a.time,open:s,high:c,low:l,close:o,volume:a.volume}),n=s,r=o}return t}function Ve(e,t){if(e.length===0)return[];let n=t.brickSize;t.useATR&&e.length>(t.atrPeriod??14)&&(n=He(e,t.atrPeriod??14)),n<=0&&(n=1);let r=[],i=Math.round(e[0].close/n)*n,a=e[0].time;for(let t=1;t<e.length;t++){let o=e[t].close-i,s=Math.floor(Math.abs(o)/n);if(s>=1){let c=o>0?1:-1;for(let o=0;o<s;o++){let o=i;i+=c*n,r.push({time:a++,open:o,high:Math.max(o,i),low:Math.min(o,i),close:i,volume:e[t].volume/s})}}}return r}function He(e,t){let n=0;for(let r=1;r<=Math.min(t,e.length-1);r++){let t=Math.max(e[r].high-e[r].low,Math.abs(e[r].high-e[r-1].close),Math.abs(e[r].low-e[r-1].close));n+=t}return n/t}function Ue(e,t=3){if(e.length===0)return[];let n=[],r=0;n.push({time:r++,open:e[0].open,high:Math.max(e[0].open,e[0].close),low:Math.min(e[0].open,e[0].close),close:e[0].close,volume:e[0].volume});for(let i=1;i<e.length;i++){let a=e[i].close,o=n[n.length-1],s=o.close>=o.open,c=Math.min(t,n.length),l=-1/0,u=1/0;for(let e=n.length-c;e<n.length;e++)l=Math.max(l,n[e].high),u=Math.min(u,n[e].low);s&&a>o.close?n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume}):!s&&a<o.close||s&&a<u?n.push({time:r++,open:o.close,high:o.close,low:a,close:a,volume:e[i].volume}):!s&&a>l&&n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume})}return n}function We(e,t=4){if(e.length<2)return e.slice();let n=[],r=e[1].close>=e[0].close?1:-1,i=e[0].close,a=e[0].close,o=e[0].close,s=0;for(let c=1;c<e.length;c++){let l=e[c].close,u=t/100*o;r===1?(l>i&&(i=l),i-l>=u&&(n.push({time:s++,open:o,high:i,low:o,close:i,volume:e[c].volume}),r=-1,o=i,a=l,i=l)):(l<a&&(a=l),l-a>=u&&(n.push({time:s++,open:o,high:o,low:a,close:a,volume:e[c].volume}),r=1,o=a,i=l,a=l))}return r===1?n.push({time:s,open:o,high:i,low:o,close:i,volume:0}):n.push({time:s,open:o,high:o,low:a,close:a,volume:0}),n}function Ge(e,t,n=3){if(e.length===0||t<=0)return[];let r=[],i=0,a=0,o=0,s=0,c=Math.round(e[0].close/t)*t;a=c,o=c,i=1;for(let c=1;c<e.length;c++){let l=e[c].close,u=Math.round(l/t)*t;i===1?u>a?a=u:a-u>=t*n&&(r.push({time:s++,open:o,high:a,low:o,close:a,volume:e[c].volume}),i=-1,o=u,a-=t):u<o?o=u:u-o>=t*n&&(r.push({time:s++,open:a,high:a,low:o,close:o,volume:e[c].volume}),i=1,a=u,o+=t)}return r.push({time:s,open:i===1?o:a,high:a,low:o,close:i===1?a:o,volume:0}),r}function Ke(e,t){if(e.length===0||t.rangeSize<=0)return[];let n=[],r=e[0].time,i=e[0].open,a=i,o=i,s=0,c=(e,c)=>{for(e>a&&(a=e),e<o&&(o=e),s+=c;a-o>=t.rangeSize;){let c=e>=i,l=c?i+t.rangeSize:i-t.rangeSize;n.push({time:r++,open:i,high:c?l:i,low:c?i:l,close:l,volume:s}),i=l,a=l,o=l,s=0}};for(let t of e){let e=t.close>=t.open?[t.low,t.high,t.close]:[t.high,t.low,t.close],n=t.volume/e.length;for(let t of e)c(t,n)}return n}var j=class{canResume(e,t,n){let r=t.series;if(!r||n<=0||n>r.length||r.length>e.length)return!1;for(let i=n;i<r.length;i++)if(r[i]&&!t.values.has(e[i].time))return!1;return!0}writePoint(e,t,n,r){e.series[n]=r,r?e.values.set(t[n].time,r):e.values.delete(t[n].time)}drawLine(e,t,n,r){if(!(t.length<2)){e.beginPath(),e.strokeStyle=n,e.lineWidth=r,e.lineJoin=`round`,e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);e.stroke()}}drawBand(e,t,n,r){if(!(t.length<2||n.length<2)){e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x,n[t].y);e.closePath(),e.fillStyle=r,e.fill()}}drawHistogram(e,t,n){let r=n/2;for(let i of t){e.fillStyle=i.color;let t=Math.min(i.y,i.baseY),a=Math.abs(i.y-i.baseY);e.fillRect(i.x-r,t,n,Math.max(a,1))}}valuesToPoints(e,t,n,r){let i=[],{from:s,to:c}=r.visibleRange;for(let l=s;l<=c&&l<n.length;l++){let s=e.values.get(n[l].time);s&&s[t]!==void 0&&i.push({x:a(l,r),y:o(s[t],r)})}return i}},qe=1,Je=class{registry=new Map;instances=new Map;register(e){this.registry.set(e.descriptor.id,e)}getAvailableIndicators(){return Array.from(this.registry.values()).map(e=>e.descriptor)}addIndicator(t,n={},r){let i=this.registry.get(t);if(!i)throw Error(`Unknown indicator: ${t}`);let a=`tc_${t}_${qe++}`,o={id:t,instanceId:a,params:{...i.descriptor.defaultConfig,...n},visible:!0},s=new Set;for(let e of this.instances.values())e.config.id===t&&s.add(e.style.colors[0]);let c=e.TC_SERIES_COLORS.findIndex(e=>!s.has(e));c<0&&(c=s.size%e.TC_SERIES_COLORS.length);let l={plugin:i,config:o,output:null,style:{colors:o.style?.colors??[...e.TC_SERIES_COLORS.slice(c),...e.TC_SERIES_COLORS.slice(0,c)],lineWidths:o.style?.lineWidths??[1.5],opacity:o.style?.opacity??1}};return r&&(l.output=i.calculate(r,o)),this.instances.set(a,l),a}removeIndicator(e){this.instances.delete(e)}updateIndicator(e,t,n){let r=this.instances.get(e);r&&(Object.assign(r.config.params,t),n&&(r.output=r.plugin.calculate(n,r.config)))}recalculateAll(e){for(let t of this.instances.values())t.output=t.plugin.calculate(e,t.config)}recalculateFrom(e,t){for(let n of this.instances.values()){let r=n.output,i=null;r&&n.plugin.update&&t>0&&(i=n.plugin.update(e,n.config,r,t)),n.output=i??n.plugin.calculate(e,n.config)}}getOutput(e){return this.instances.get(e)?.output??null}renderOverlays(e,t){for(let n of this.instances.values())!n.output||!n.config.visible||n.plugin.descriptor.placement===`overlay`&&n.plugin.render(e,n.output,t,n.style)}renderPanel(e,t,n){let r=this.instances.get(t);!r?.output||!r.config.visible||r.plugin.render(e,r.output,n,r.style)}getIndicatorConfig(e){return this.instances.get(e)?.config??null}setVisible(e,t){let n=this.instances.get(e);return n?(n.config.visible=t,t):null}isVisible(e){return this.instances.get(e)?.config.visible??!1}getIndicatorDescriptor(e){return this.instances.get(e)?.plugin.descriptor??null}getActiveIndicators(){let e=[];for(let[t,n]of this.instances)e.push({instanceId:t,id:n.config.id,params:{...n.config.params},descriptor:n.plugin.descriptor,visible:n.config.visible??!0});return e}getIndicatorStyle(e){let t=this.instances.get(e)?.style;return t?{colors:[...t.colors],lineWidths:[...t.lineWidths],opacity:t.opacity}:null}updateIndicatorStyle(e,t){let n=this.instances.get(e);n&&Object.assign(n.style,t)}getOverlayPriceRange(e,t){let n=1/0,r=-1/0;for(let i of this.instances.values()){if(!i.output||!i.config.visible||i.plugin.descriptor.placement!==`overlay`)continue;let a=i.output.series;if(!a)continue;let o=Math.min(t,a.length-1);for(let t=Math.max(0,e);t<=o;t++){let e=a[t];if(e)for(let t in e){let i=e[t];i!==void 0&&isFinite(i)&&(i<n&&(n=i),i>r&&(r=i))}}}return n===1/0?null:{min:n,max:r}}getPanelIndicators(){let e=[];for(let[t,n]of this.instances)n.plugin.descriptor.placement===`panel`&&e.push({instanceId:t,descriptor:n.plugin.descriptor});return e}},M=class extends Map{keyBuf=[];valBuf=[];folded=!1;constructor(){super()}set(e,t){if(this.folded)return super.set(e,t);let n=this.keyBuf,r=n.length;if(r===0||e>n[r-1])return n.push(e),this.valBuf.push(t),this;let i=this.indexOf(e);return i>=0?(this.valBuf[i]=t,this):(this.fold(),super.set(e,t))}get(e){if(this.folded)return super.get(e);let t=this.indexOf(e);return t>=0?this.valBuf[t]:void 0}has(e){return this.folded?super.has(e):this.indexOf(e)>=0}delete(e){if(this.folded)return super.delete(e);let t=this.indexOf(e);return t<0?!1:(this.keyBuf.splice(t,1),this.valBuf.splice(t,1),!0)}clear(){super.clear(),this.keyBuf=[],this.valBuf=[],this.folded=!1}get size(){return this.folded?super.size:this.keyBuf.length}forEach(e,t){this.fold(),super.forEach(e,t)}entries(){return this.fold(),super.entries()}keys(){return this.fold(),super.keys()}values(){return this.fold(),super.values()}[Symbol.iterator](){return this.fold(),super[Symbol.iterator]()}indexOf(e){let t=this.keyBuf,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i];if(a===e)return i;a<e?n=i+1:r=i-1}return-1}fold(){if(this.folded)return;this.folded=!0;let e=this.keyBuf,t=this.valBuf;for(let n=0;n<e.length;n++)super.set(e[n],t[n]);this.keyBuf=[],this.valBuf=[]}};function N(e,t,n){let r=e.params[t];if(typeof r==`number`&&Number.isFinite(r))return r;if(typeof r==`string`){let e=Number(r);if(Number.isFinite(e))return e}return n}function P(e,t,n,r=1){let i=N(e,t,n);return Math.max(r,Math.floor(i))}var Ye=class extends j{descriptor={id:`sma`,name:`Simple Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++)if(a+=e[t].close,t>=n&&(a-=e[t-n].close),t>=n-1){let o={value:a/n};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=P(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;this.writePoint(n,e,t,{value:r/i})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Xe=class extends j{descriptor={id:`ema`,name:`Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=2/(n+1),i=new M,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++){if(t<n-1){o+=e[t].close;continue}o=t===n-1?(o+e[t].close)/n:(e[t].close-o)*r+o;let s={value:o};i.set(e[t].time,s),a[t]=s}return{values:i,series:a}}update(e,t,n,r){let i=P(t,`period`,20,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;let o=2/(i+1);for(let t=r;t<e.length;t++)a=(e[t].close-a)*o+a,this.writePoint(n,e,t,{value:a});return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Ze=class extends j{descriptor={id:`bb`,name:`Bollinger Bands`,placement:`overlay`,defaultConfig:{period:20,stdDev:2}};calculate(e,t){let n=P(t,`period`,20,1),r=N(t,`stdDev`,2),i=new M,a=Array(e.length).fill(null),o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(o+=c,s+=c*c,t>=n){let r=e[t-n].close;o-=r,s-=r*r}if(t>=n-1){let c=o/n,l=s/n-c*c,u=Math.sqrt(Math.max(0,l)),d={middle:c,upper:c+r*u,lower:c-r*u};i.set(e[t].time,d),a[t]=d}}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=P(t,`period`,20,1),a=N(t,`stdDev`,2);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=0;for(let n=t-i+1;n<=t;n++){let t=e[n].close;r+=t,o+=t*t}let s=r/i,c=Math.sqrt(Math.max(0,o/i-s*s));this.writePoint(n,e,t,{middle:s,upper:s+a*c,lower:s-a*c})}return n}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=0,d=l-c+1,f=new Float64Array(d),p=new Float64Array(d),m=new Float64Array(d),h=new Float64Array(d),g=new Float64Array(d),_=new Float64Array(d);for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t||t.upper===void 0)continue;let n=a(e,r);f[u]=n,p[u]=o(t.upper,r),m[u]=n,h[u]=o(t.middle,r),g[u]=n,_[u]=o(t.lower,r),u++}if(!(u<2)){t.beginPath(),t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);for(let e=u-1;e>=0;e--)t.lineTo(g[e],_[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[0],.1),t.fill(),t.beginPath(),t.strokeStyle=i.colors[0],t.lineWidth=i.lineWidths[0],t.lineJoin=`round`,t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[1]??i.colors[0],t.moveTo(m[0],h[0]);for(let e=1;e<u;e++)t.lineTo(m[e],h[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[0],t.moveTo(g[0],_[0]);for(let e=1;e<u;e++)t.lineTo(g[e],_[e]);t.stroke()}}},Qe=class extends j{descriptor={id:`vwap`,name:`Volume Weighted Average Price`,placement:`overlay`,defaultConfig:{}};calculate(e,t){let n=new M,r=Array(e.length).fill(null),i=0,a=0;for(let t=0;t<e.length;t++){let o=(e[t].high+e[t].low+e[t].close)/3;if(i+=e[t].volume,a+=o*e[t].volume,i>0){let o={value:a/i};n.set(e[t].time,o),r[t]=o}}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},$e=class extends j{descriptor={id:`ichimoku`,name:`Ichimoku Cloud`,placement:`overlay`,defaultConfig:{tenkan:9,kijun:26,senkou:52,displacement:26}};calculate(e,t){let n=P(t,`tenkan`,9,1),r=P(t,`kijun`,26,1),i=P(t,`senkou`,52,1),a=new M,o=Array(e.length).fill(null),s=t=>{let n=new Float64Array(e.length),r=new Float64Array(e.length);for(let i=0;i<e.length;i++){let a=-1/0,o=1/0,s=Math.max(0,i-t+1);for(let t=s;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);n[i]=a,r[i]=o}return{highs:n,lows:r}},c=s(n),l=s(r),u=s(i);for(let t=0;t<e.length;t++){let s={};t>=n-1&&(s.tenkan=(c.highs[t]+c.lows[t])/2),t>=r-1&&(s.kijun=(l.highs[t]+l.lows[t])/2),s.tenkan!==void 0&&s.kijun!==void 0&&(s.senkouA=(s.tenkan+s.kijun)/2),t>=i-1&&(s.senkouB=(u.highs[t]+u.lows[t])/2),t>=r-1&&(s.chikou=e[t].close),(s.tenkan!==void 0||s.kijun!==void 0||s.senkouA!==void 0||s.senkouB!==void 0)&&(a.set(e[t].time,s),o[t]=s)}return{values:a,series:o}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=l-c+1,d=new Float64Array(u),f=new Float64Array(u),p=0,m=new Float64Array(u),h=new Float64Array(u),g=0,_=new Float64Array(u),v=new Float64Array(u),y=0,b=new Float64Array(u),x=new Float64Array(u),S=0;for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.tenkan!==void 0&&(d[p]=n,f[p]=o(t.tenkan,r),p++),t.kijun!==void 0&&(m[g]=n,h[g]=o(t.kijun,r),g++),t.senkouA!==void 0&&(_[y]=n,v[y]=o(t.senkouA,r),y++),t.senkouB!==void 0&&(b[S]=n,x[S]=o(t.senkouB,r),S++)}if(y>1&&S>1){let n=Math.min(y,S);t.beginPath(),t.moveTo(_[0],v[0]);for(let e=1;e<n;e++)t.lineTo(_[e],v[e]);for(let e=n-1;e>=0;e--)t.lineTo(b[e],x[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[2]??`#1fa874`,.15),t.fill()}let C=(e,n,r,i,a)=>{if(!(r<2)){t.beginPath(),t.strokeStyle=i,t.lineWidth=a,t.lineJoin=`round`,t.moveTo(e[0],n[0]);for(let i=1;i<r;i++)t.lineTo(e[i],n[i]);t.stroke()}};C(d,f,p,i.colors[0],i.lineWidths[0]),C(m,h,g,i.colors[1]??`#f2a93b`,i.lineWidths[0]),C(_,v,y,i.colors[2]??`#1fa874`,1),C(b,x,S,i.colors[3]??`#e8505b`,1)}},et=class extends j{descriptor={id:`psar`,name:`Parabolic SAR`,placement:`overlay`,defaultConfig:{step:.02,max:.2}};calculate(e,t){let n=N(t,`step`,.02),r=N(t,`max`,.2),i=new M,a=Array(e.length).fill(null);if(e.length<2)return{values:i,series:a};let o=e[1].close>e[0].close,s=n,c=o?e[0].high:e[0].low,l=o?e[0].low:e[0].high,u={value:l,trend:o?1:-1};i.set(e[0].time,u),a[0]=u;for(let t=1;t<e.length;t++){let u=l;l=u+s*(c-u),o?(l=Math.min(l,e[t-1].low),t>=2&&(l=Math.min(l,e[t-2].low)),e[t].low<l?(o=!1,l=c,c=e[t].low,s=n):e[t].high>c&&(c=e[t].high,s=Math.min(s+n,r))):(l=Math.max(l,e[t-1].high),t>=2&&(l=Math.max(l,e[t-2].high)),e[t].high>l?(o=!0,l=c,c=e[t].high,s=n):e[t].low<c&&(c=e[t].low,s=Math.min(s+n,r)));let d={value:l,trend:o?1:-1};i.set(e[t].time,d),a[t]=d}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=Math.max(1.5,n.barWidth*.15);for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),u=o(s.value,n);e.beginPath(),e.arc(c,u,l,0,Math.PI*2),e.fillStyle=s.trend===1?r.colors[0]:r.colors[1]??`#e8505b`,e.fill()}}},tt=class extends j{descriptor={id:`supertrend`,name:`Supertrend`,placement:`overlay`,defaultConfig:{period:10,multiplier:3}};calculate(e,t){let n=P(t,`period`,10,1),r=N(t,`multiplier`,3),i=new M,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};let o=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)o.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let s=0;for(let e=0;e<n;e++)s+=o[e];s/=n;let c=0,l=0,u=0,d=0,f=0,p=0,m=1;for(let t=n-1;t<e.length;t++){t>n-1&&(s=(s*(n-1)+o[t])/n);let h=(e[t].high+e[t].low)/2,g=h+r*s,_=h-r*s;c=g<u||e[t-1].close>u?g:u,l=_>d||e[t-1].close<d?_:d,f=p===u?e[t].close<=c?c:l:e[t].close>=l?l:c,m=f===l?1:-1;let v={value:f,trend:m};i.set(e[t].time,v),a[t]=v,u=c,d=l,p=f}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#e8505b`,d=0,f=0,p=0;for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),m=o(s.value,n),h=s.trend??1;p!==0&&(e.beginPath(),e.strokeStyle=h===1?l:u,e.lineWidth=r.lineWidths[0]+.5,e.moveTo(d,f),e.lineTo(c,m),e.stroke()),d=c,f=m,p=h}}},nt=class extends j{descriptor={id:`keltner`,name:`Keltner Channel`,placement:`overlay`,defaultConfig:{emaPeriod:20,atrPeriod:10,multiplier:1.5}};calculate(e,t){let n=P(t,`emaPeriod`,20,1),r=P(t,`atrPeriod`,10,1),i=N(t,`multiplier`,1.5),a=new M;if(e.length<Math.max(n,r))return{values:a};let o=2/(n+1),s=e[0].close,c=[s];for(let t=1;t<e.length;t++)s=(e[t].close-s)*o+s,c.push(s);let l=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)l.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let u=0;for(let e=0;e<r;e++)u+=l[e];u/=r;let d=Array(e.length).fill(null),f=Math.max(n,r)-1;for(let t=f;t<e.length;t++){t>f&&(u=(u*(r-1)+l[t])/r);let n={middle:c[t],upper:c[t]+i*u,lower:c[t]-i*u};a.set(e[t].time,n),d[t]=n}return{values:a,series:d}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},rt=class extends j{descriptor={id:`donchian`,name:`Donchian Channel`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={upper:a,middle:(a+o)/2,lower:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??`#7d8696`,1),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},it=[`s3`,`s2`,`s1`,`pp`,`r1`,`r2`,`r3`],at=class extends j{descriptor={id:`pivots`,name:`Pivot Points (Classic)`,placement:`overlay`,defaultConfig:{lookback:24}};calculate(e,t){let n=P(t,`lookback`,24,1),r=new M,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};for(let t=n;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n;r<t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s=e[t-1].close,c=(a+o+s)/3,l=a-o,u={pp:c,r1:2*c-o,s1:2*c-a,r2:c+l,s2:c-l,r3:a+2*(c-o),s3:o-2*(a-c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#e8505b`,d=r.colors[2]??`#1fa874`,f=r.lineWidths[0],p=e=>e===`pp`?l:e.startsWith(`r`)?u:d;for(let t of it){e.beginPath(),e.strokeStyle=p(t),e.lineWidth=t===`pp`?f:Math.max(1,f-1),t!==`pp`&&e.setLineDash([4,3]);let r=!1;for(let l=s;l<=c&&l<i.length;l++){let s=i[l]?.[t];if(s===void 0)continue;let c=a(l,n),u=o(s,n);r?e.lineTo(c,u):(e.moveTo(c,u),r=!0)}e.stroke(),e.setLineDash([])}}},ot=class extends j{descriptor={id:`avwap`,name:`Anchored VWAP`,placement:`overlay`,defaultConfig:{anchorTime:0}};calculate(e,t){let n=N(t,`anchorTime`,0),r=new M,i=Array(e.length).fill(null),a=0;if(n>0&&(a=e.findIndex(e=>e.time>=n),a<0))return{values:r,series:i};let o=0,s=0;for(let t=a;t<e.length;t++){let n=(e[t].high+e[t].low+e[t].close)/3;if(o+=e[t].volume,s+=n*e[t].volume,o>0){let n={value:s/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},st=class extends j{descriptor={id:`zigzag`,name:`ZigZag`,placement:`overlay`,defaultConfig:{deviation:5}};calculate(e,t){let n=Math.max(.01,N(t,`deviation`,5))/100,r=new M,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i,meta:{pivots:[]}};let a=[],o=null,s=0,c=e[0].close;for(let t=1;t<e.length;t++){let r=e[t].high,i=e[t].low;if(o===null){r>=c*(1+n)?(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i);continue}o===`up`?r>c?(s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i):i<c?(s=t,c=i):r>=c*(1+n)&&(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r)}a.push({idx:s,price:c,type:o===`up`?`high`:`low`});for(let t of a){let n={pivot:t.price};r.set(e[t.idx].time,n),i[t.idx]=n}return{values:r,series:i,meta:{pivots:a}}}render(e,t,n,r){let i=t.meta?.pivots;if(!(!i||i.length<2)){e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;for(let t=0;t<i.length;t++){let r=i[t],s=a(r.idx,n),c=o(r.price,n);t===0?e.moveTo(s,c):e.lineTo(s,c)}e.stroke()}}},ct=class extends j{descriptor={id:`lrc`,name:`Linear Regression Channel`,placement:`overlay`,defaultConfig:{period:100,stdDev:2}};calculate(e,t){let n=P(t,`period`,100,2),r=N(t,`stdDev`,2),i=new M,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};for(let t=n-1;t<e.length;t++){let o=t-n+1,s=0,c=0,l=0,u=0;for(let t=0;t<n;t++){let n=t,r=e[o+t].close;s+=n,c+=r,l+=n*r,u+=n*n}let d=n*u-s*s;if(d===0)continue;let f=(n*l-s*c)/d,p=(c-f*s)/n,m=0;for(let t=0;t<n;t++){let n=f*t+p,r=e[o+t].close-n;m+=r*r}let h=Math.sqrt(m/n),g=f*(n-1)+p,_={middle:g,upper:g+r*h,lower:g-r*h,slope:f};i.set(e[t].time,_),a[t]=_}return{values:i,series:a}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},lt=class extends j{descriptor={id:`hma`,name:`Hull Moving Average`,placement:`overlay`,defaultConfig:{period:21}};calculate(e,t){let n=P(t,`period`,21,2),r=new M,i=Array(e.length).fill(null);if(e.length<n)return{values:r,series:i};let a=e.map(e=>e.close),o=Math.max(2,Math.floor(n/2)),s=Math.max(2,Math.floor(Math.sqrt(n))),c=ut(a,n),l=ut(a,o),u=dt(a.map((e,t)=>c[t]===null||l[t]===null?null:2*l[t]-c[t]),s);for(let t=0;t<e.length;t++){if(u[t]===null)continue;let n={value:u[t]};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}};function ut(e,t){let n=Array(e.length).fill(null);if(e.length<t)return n;let r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0;for(let n=0;n<t;n++)a+=e[i-n]*(t-n);n[i]=a/r}return n}function dt(e,t){let n=Array(e.length).fill(null),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-n];if(r===null){o=!1;break}a+=r*(t-n)}o&&(n[i]=a/r)}return n}var ft=class extends j{descriptor={id:`mtfma`,name:`MTF Moving Average`,placement:`overlay`,defaultConfig:{period:50,timeframe:`1d`}};calculate(t,n){let r=P(n,`period`,50,1),i=String(n.params.timeframe??`1d`),a=new M,o=Array(t.length).fill(null);if(t.length===0)return{values:a,series:o};let s=[],c=(0,e.timeframeBucketStart)(t[0].time,i),l=t[0].close,u=null,d=()=>{if(s.length<r)return;let e=0;for(let t=s.length-r;t<s.length;t++)e+=s[t];u=e/r};for(let n=0;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,i);if(r!==c&&(s.push(l),d(),c=r),l=t[n].close,u!==null){let e={value:u};a.set(t[n].time,e),o[n]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},pt=class extends j{descriptor={id:`svwap`,name:`Session VWAP`,placement:`overlay`,defaultConfig:{bands:1}};calculate(t,n){let r=Math.min(3,P(n,`bands`,1,0)),i=new M,a=Array(t.length).fill(null);if(t.length===0)return{values:i,series:a};let o=(0,e.timeframeBucketStart)(t[0].time,`1d`),s=0,c=0,l=0;for(let n=0;n<t.length;n++){let u=t[n],d=(0,e.timeframeBucketStart)(u.time,`1d`);d!==o&&(s=0,c=0,l=0,o=d);let f=(u.high+u.low+u.close)/3;if(s+=f*u.volume,c+=f*f*u.volume,l+=u.volume,l>0){let e=s/l,t={value:e,session:o};if(r>0){let n=Math.max(0,c/l-e*e),i=Math.sqrt(n);for(let n=1;n<=r;n++)t[`u${n}`]=e+n*i,t[`l${n}`]=e-n*i}i.set(u.time,t),a[n]=t}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:a,to:o}=n.visibleRange;e.globalAlpha=.55,e.lineWidth=1,e.setLineDash([4,3]),e.strokeStyle=r.colors[1]??r.colors[0];for(let t=1;t<=3;t++)this.strokeBandSeries(e,i,n,a,o,e=>e[`u${t}`]),this.strokeBandSeries(e,i,n,a,o,e=>e[`l${t}`]);e.setLineDash([]),e.globalAlpha=1,e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,this.strokeBandSeries(e,i,n,a,o,e=>e.value)}strokeBandSeries(e,t,n,r,i,s){e.beginPath();let c,l=!1;for(let u=r;u<=i&&u<t.length;u++){let r=t[u],i=r?s(r):void 0;if(r===null||i===void 0){l=!1;continue}let d=a(u,n),f=o(i,n),p=r.session!==c;!l||p?(e.moveTo(d,f),l=!0):e.lineTo(d,f),c=r.session}e.stroke()}},mt=class extends j{descriptor={id:`chandelier`,name:`Chandelier Exit`,placement:`overlay`,defaultConfig:{period:22,multiplier:3}};calculate(e,t){let n=P(t,`period`,22,1),r=N(t,`multiplier`,3),i=new M,a=Array(e.length).fill(null),o=e.length;if(o<=n)return{values:i,series:a};let s=Array(o).fill(0);for(let t=1;t<o;t++){let n=e[t-1].close;s[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let c=0;for(let e=1;e<=n;e++)c+=s[e];c/=n;for(let t=n;t<o;t++){t>n&&(c=(c*(n-1)+s[t])/n);let o=-1/0,l=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>o&&(o=e[r].high),e[r].low<l&&(l=e[r].low);let u={long:o-r*c,short:l+r*c};i.set(e[t].time,u),a[t]=u}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.setLineDash([5,3]);let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke(),e.setLineDash([])};l(`long`,r.colors[0]??`#1fa874`),l(`short`,r.colors[1]??`#e8505b`)}},ht=class extends j{descriptor={id:`alligator`,name:`Alligator`,placement:`overlay`,defaultConfig:{jaw:13,teeth:8,lips:5,jawShift:8,teethShift:5,lipsShift:3}};calculate(e,t){let n=P(t,`jaw`,13,1),r=P(t,`teeth`,8,1),i=P(t,`lips`,5,1),a=P(t,`jawShift`,8,0),o=P(t,`teethShift`,5,0),s=P(t,`lipsShift`,3,0),c=new M,l=e.length,u=Array(l).fill(null);if(l===0)return{values:c,series:u};let d=e.map(e=>(e.high+e.low)/2),f=gt(d,n),p=gt(d,r),m=gt(d,i),h=Array(l).fill(void 0),g=Array(l).fill(void 0),_=Array(l).fill(void 0);for(let e=0;e<l;e++)f[e]!==void 0&&e+a<l&&(h[e+a]=f[e]),p[e]!==void 0&&e+o<l&&(g[e+o]=p[e]),m[e]!==void 0&&e+s<l&&(_[e+s]=m[e]);for(let t=0;t<l;t++){if(h[t]===void 0&&g[t]===void 0&&_[t]===void 0)continue;let n={};h[t]!==void 0&&(n.jaw=h[t]),g[t]!==void 0&&(n.teeth=g[t]),_[t]!==void 0&&(n.lips=_[t]),c.set(e[t].time,n),u[t]=n}return{values:c,series:u}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke()};l(`jaw`,r.colors[0]??`#4c8dff`),l(`teeth`,r.colors[1]??`#e8505b`),l(`lips`,r.colors[2]??`#1fa874`)}};function gt(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<t)return r;let i=0;for(let n=0;n<t;n++)i+=e[n];let a=i/t;r[t-1]=a;for(let i=t;i<n;i++)a=(a*(t-1)+e[i])/t,r[i]=a;return r}var _t=class extends j{descriptor={id:`vwma`,name:`Volume Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null),a=0,o=0;for(let t=0;t<e.length;t++){let s=e[t].close*e[t].volume;if(a+=s,o+=e[t].volume,t>=n){let r=e[t-n];a-=r.close*r.volume,o-=r.volume}if(t>=n-1&&o>0){let n={value:a/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=P(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,a=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close*e[n].volume,a+=e[n].volume;this.writePoint(n,e,t,a>0?{value:r/a}:null)}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},vt=class extends j{descriptor={id:`wma`,name:`Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null),a=n*(n+1)/2,o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(s+=c*n-o,o+=c,t>=n&&(o-=e[t-n].close),t>=n-1){let n={value:s/a};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=P(t,`period`,20,1),a=i*(i+1)/2;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=t-i+1;for(let t=0;t<i;t++)r+=e[o+t].close*(t+1);this.writePoint(n,e,t,{value:r/a})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},yt=class extends j{descriptor={id:`envelope`,name:`Moving Average Envelope`,placement:`overlay`,defaultConfig:{period:20,percent:2.5}};calculate(e,t){let n=P(t,`period`,20,1),r=N(t,`percent`,2.5)/100,i=new M,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let s=o/n,c={basis:s,upper:s*(1+r),lower:s*(1-r)};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=P(t,`period`,20,1),a=N(t,`percent`,2.5)/100;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;let o=r/i;this.writePoint(n,e,t,{basis:o,upper:o*(1+a),lower:o*(1-a)})}return n}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t||t.upper===void 0)continue;let n=a(e,r);u.push({x:n,y:o(t.upper,r)}),d.push({x:n,y:o(t.lower,r)}),f.push({x:n,y:o(t.basis,r)})}this.drawBand(t,u,d,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[1]??i.colors[0],i.lineWidths[0])}};function bt(e,t){let n=2/(t+1),r=Array(e.length).fill(null),i=0,a=0;for(let o=0;o<e.length;o++){if(o<t-1){a+=e[o];continue}i=o===t-1?(a+e[o])/t:(e[o]-i)*n+i,r[o]=i}return r}function xt(e,t,n){let r=Array(n).fill(null);for(let n=0;n<e.length;n++)e[n]!==null&&(r[t[n]]=e[n]);return r}function St(e){let t=[],n=[];for(let r=0;r<e.length;r++)e[r]!==null&&(t.push(e[r]),n.push(r));return{values:t,indices:n}}var Ct=class extends j{descriptor={id:`tema`,name:`Triple EMA`,placement:`overlay`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null),a=bt(e.map(e=>e.close),n),o=St(a),s=xt(bt(o.values,n),o.indices,e.length),c=St(s),l=xt(bt(c.values,n),c.indices,e.length);for(let t=0;t<e.length;t++){let n=a[t],o=s[t],c=l[t];if(n===null||o===null||c===null)continue;let u={value:3*n-3*o+c};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},wt=class extends j{descriptor={id:`ao`,name:`Awesome Oscillator`,placement:`panel`,defaultConfig:{fast:5,slow:34}};calculate(e,t){let n=P(t,`fast`,5,1),r=P(t,`slow`,34,1),i=new M,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=Array(e.length);for(let t=0;t<e.length;t++)o[t]=(e[t].high+e[t].low)/2;let s=0,c=0,l;for(let t=0;t<e.length;t++)if(c+=o[t],t>=r&&(c-=o[t-r]),s+=o[t],t>=n&&(s-=o[t-n]),t>=r-1){let o=s/n-c/r,u={value:o,up:+(l===void 0||o>=l)};i.set(e[t].time,u),a[t]=u,l=o}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=Math.max(Math.abs(l),Math.abs(u))||1,f=e=>o.y+o.height*(1-(e+d)/(2*d)),p=f(0),m=n.barWidth/2,h=r.colors[0]??`#1fa874`,g=r.colors[1]??`#e8505b`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value),c=Math.min(s,p),l=Math.max(Math.abs(s-p),1);e.fillStyle=r.up?h:g,e.fillRect(o-m,c,n.barWidth,l)}}},Tt=class extends j{descriptor={id:`chaikinOsc`,name:`Chaikin Oscillator`,placement:`panel`,defaultConfig:{fast:3,slow:10}};calculate(e,t){let n=P(t,`fast`,3,1),r=P(t,`slow`,10,1),i=new M,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=2/(n+1),s=2/(r+1),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let{high:n,low:d,close:f,volume:p}=e[t],m=n-d,h=m===0?0:(f-d-(n-f))/m;if(c+=h*p,t===0?(l=c,u=c):(l=(c-l)*o+l,u=(c-u)*s+u),t>=r-1){let n={value:l-u,adl:c};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=Math.max(Math.abs(l),Math.abs(u))||1,f=e=>o.y+o.height*(1-(e+d)/(2*d)),p=f(0),m=n.barWidth/2,h=r.colors[0]??`#1fa874`,g=r.colors[1]??`#e8505b`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value),c=Math.min(s,p),l=Math.max(Math.abs(s-p),1);e.fillStyle=r.value>=0?h:g,e.fillRect(o-m,c,n.barWidth,l)}}},Et=class extends j{descriptor={id:`rsi`,name:`Relative Strength Index`,placement:`panel`,defaultConfig:{period:14}};smoothing=new WeakMap;calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null),a={values:r,series:i};if(e.length<n+1)return a;let o=[],s=[],c=0,l=0;for(let t=1;t<=n;t++){let n=e[t].close-e[t-1].close;n>0?c+=n:l-=n}c/=n,l/=n,o[n]=c,s[n]=l;let u={value:l===0?100:100-100/(1+c/l)};r.set(e[n].time,u),i[n]=u;for(let t=n+1;t<e.length;t++){let a=e[t].close-e[t-1].close,u=a>0?a:0,d=a<0?-a:0;c=(c*(n-1)+u)/n,l=(l*(n-1)+d)/n,o[t]=c,s[t]=l;let f={value:l===0?100:100-100/(1+c/l)};r.set(e[t].time,f),i[t]=f}return this.smoothing.set(a,{gain:o,loss:s}),a}update(e,t,n,r){let i=P(t,`period`,14,1),a=this.smoothing.get(n);if(!a||r<=i||!this.canResume(e,n,r))return null;let o=a.gain[r-1],s=a.loss[r-1];if(o===void 0||s===void 0)return null;for(let t=r;t<e.length;t++){let r=e[t].close-e[t-1].close,c=r>0?r:0,l=r<0?-r:0;o=(o*(i-1)+c)/i,s=(s*(i-1)+l)/i,a.gain[t]=o,a.loss[t]=s;let u=s===0?100:100-100/(1+o/s);this.writePoint(n,e,t,{value:u})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath();for(let t of[30,70]){let n=l(t);e.moveTo(o.x,n),e.lineTo(o.x+o.width,n)}e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},Dt=class extends j{descriptor={id:`macd`,name:`MACD`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9}};emas=new WeakMap;calculate(e,t){let n=P(t,`fast`,12,1),r=P(t,`slow`,26,1),i=P(t,`signal`,9,1),a=new M,o=Array(e.length).fill(null),s={values:a,series:o};if(e.length<r)return s;let c=2/(n+1),l=2/(r+1),u=2/(i+1),d=Array(e.length),f=Array(e.length),p=e[0].close,m=e[0].close,h=0,g=!1;for(let t=0;t<e.length;t++){let n=e[t].close;if(t===0?(p=n,m=n):(p=(n-p)*c+p,m=(n-m)*l+m),d[t]=p,f[t]=m,t>=r-1){let n=p-m;g?h=(n-h)*u+h:(h=n,g=!0);let r=n-h,i={macd:n,signal:h,histogram:r};a.set(e[t].time,i),o[t]=i}}return this.emas.set(s,{fast:d,slow:f}),s}update(e,t,n,r){let i=P(t,`fast`,12,1),a=P(t,`slow`,26,1),o=P(t,`signal`,9,1),s=this.emas.get(n);if(!s||r<a||!this.canResume(e,n,r))return null;let c=s.fast[r-1],l=s.slow[r-1],u=n.series[r-1]?.signal;if(c===void 0||l===void 0||u===void 0)return null;let d=2/(i+1),f=2/(a+1),p=2/(o+1);for(let t=r;t<e.length;t++){let r=e[t].close;c=(r-c)*d+c,l=(r-l)*f+l,s.fast[t]=c,s.slow[t]=l;let i=c-l;u=(i-u)*p+u,this.writePoint(n,e,t,{macd:i,signal:u,histogram:i-u})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&(t.macd!==void 0&&(t.macd<l&&(l=t.macd),t.macd>u&&(u=t.macd)),t.signal!==void 0&&(t.signal<l&&(l=t.signal),t.signal>u&&(u=t.signal)),t.histogram!==void 0&&(t.histogram<l&&(l=t.histogram),t.histogram>u&&(u=t.histogram)))}if(l===1/0)return;let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d),p=f(0),m=n.barWidth/2,h=r.colors[2]??`#1fa874`,g=r.colors[3]??`#e8505b`,_=r.colors[0],v=r.colors[1]??`#f2a93b`;e.beginPath();let y=new Path2D,b=new Path2D,x=!1,S=!1,C=new Path2D,w=new Path2D;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(!t)continue;let r=a(e,n);if(t.histogram!==void 0){let e=f(t.histogram),i=Math.min(e,p),a=Math.max(Math.abs(e-p),1);t.histogram>=0?y.rect(r-m,i,n.barWidth,a):b.rect(r-m,i,n.barWidth,a)}if(t.macd!==void 0){let e=f(t.macd);x?C.lineTo(r,e):(C.moveTo(r,e),x=!0)}if(t.signal!==void 0){let e=f(t.signal);S?w.lineTo(r,e):(w.moveTo(r,e),S=!0)}}e.fillStyle=h,e.fill(y),e.fillStyle=g,e.fill(b),e.strokeStyle=_,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.stroke(C),e.strokeStyle=v,e.stroke(w)}},Ot=class extends j{descriptor={id:`stochastic`,name:`Stochastic Oscillator`,placement:`panel`,defaultConfig:{kPeriod:14,dPeriod:3,smooth:3}};calculate(e,t){let n=P(t,`kPeriod`,14,1),r=P(t,`dPeriod`,3,1),i=P(t,`smooth`,3,1),a=new M,o=Array(e.length).fill(null);if(e.length<n)return{values:a,series:o};let s=[];for(let t=0;t<e.length;t++){if(t<n-1){s.push(0);continue}let r=-1/0,i=1/0;for(let a=t-n+1;a<=t;a++)e[a].high>r&&(r=e[a].high),e[a].low<i&&(i=e[a].low);s.push(r===i?50:(e[t].close-i)/(r-i)*100)}let c=[];for(let e=0;e<s.length;e++){if(e<n-1+i-1){c.push(0);continue}let t=0;for(let n=e-i+1;n<=e;n++)t+=s[n];c.push(t/i)}let l=n-1+i-1;for(let t=l;t<c.length;t++){let n={k:c[t]};if(t>=l+r-1){let e=0;for(let n=t-r+1;n<=t;n++)e+=c[n];n.d=e/r}a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=P(t,`kPeriod`,14,1),a=P(t,`dPeriod`,3,1),o=P(t,`smooth`,3,1),s=i-1+o-1,c=t=>{let n=-1/0,r=1/0;for(let a=t-i+1;a<=t;a++)e[a].high>n&&(n=e[a].high),e[a].low<r&&(r=e[a].low);return n===r?50:(e[t].close-r)/(n-r)*100},l=e=>{let t=0;for(let n=e-o+1;n<=e;n++)t+=c(n);return t/o};for(let t=r;t<e.length;t++){if(t<s||e.length<i){this.writePoint(n,e,t,null);continue}let r={k:l(t)};if(t>=s+a-1){let e=0;for(let n=t-a+1;n<=t;n++)e+=l(n);r.d=e/a}this.writePoint(n,e,t,r)}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]);let u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`k`,r.colors[0]),u(`d`,r.colors[1]??`#f2a93b`)}},kt=class extends j{descriptor={id:`atr`,name:`Average True Range`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null);if(e.length<Math.max(2,n))return{values:r,series:i};let a=[e[0].high-e[0].low];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n)}let o=0;for(let e=0;e<n;e++)o+=a[e];o/=n;let s={value:o};r.set(e[n-1].time,s),i[n-1]=s;for(let t=n;t<e.length;t++){o=(o*(n-1)+a[t])/n;let s={value:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}update(e,t,n,r){let i=P(t,`period`,14,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;for(let t=r;t<e.length;t++){let r=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a=(a*(i-1)+r)/i,this.writePoint(n,e,t,{value:a})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},At=class extends j{descriptor={id:`adx`,name:`Average Directional Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null);if(e.length<n*2)return{values:r,series:i};let a=[],o=[],s=[];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n);let r=e[t].high-e[t-1].high,i=e[t-1].low-e[t].low;o.push(r>i&&r>0?r:0),s.push(i>r&&i>0?i:0)}let c=0,l=0,u=0;for(let e=0;e<n;e++)c+=a[e],l+=o[e],u+=s[e];let d=[];for(let t=n;t<a.length;t++){t>n&&(c=c-c/n+a[t],l=l-l/n+o[t],u=u-u/n+s[t]);let f=c===0?0:l/c*100,p=c===0?0:u/c*100,m=f+p,h=m===0?0:Math.abs(f-p)/m*100;d.push(h);let g=t+1,_={plusDI:f,minusDI:p,dx:h};r.set(e[g].time,_),i[g]=_}if(d.length>=n){let t=0;for(let e=0;e<n;e++)t+=d[e];t/=n;let a=n*2;if(a<e.length){let n=r.get(e[a].time);n&&(n.adx=t),i[a]&&(i[a].adx=t)}for(let a=n;a<d.length;a++){t=(t*(n-1)+d[a])/n;let o=a+n+1;if(o<e.length){let n=r.get(e[o].time);n&&(n.adx=t),i[o]&&(i[o].adx=t)}}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100),u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`adx`,r.colors[0]),u(`plusDI`,r.colors[1]??`#1fa874`),u(`minusDI`,r.colors[2]??`#e8505b`)}},jt=class extends j{descriptor={id:`obv`,name:`On Balance Volume`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new M,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0,a={value:i};n.set(e[0].time,a),r[0]=a;for(let t=1;t<e.length;t++){e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume);let a={value:i};n.set(e[t].time,a),r[t]=a}return{values:n,series:r}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;for(let t=r;t<e.length;t++)e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume),this.writePoint(n,e,t,{value:i});return n}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},Mt=class extends j{descriptor={id:`williamsR`,name:`Williams %R`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={value:a===o?-50:(a-e[t].close)/(a-o)*-100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+100)/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-20,-80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=l(r.value);u?e.lineTo(i,o):(e.moveTo(i,o),u=!0)}}e.stroke()}},Nt=class extends j{descriptor={id:`cci`,name:`Commodity Channel Index`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=(e[r].high+e[r].low+e[r].close)/3;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=(e[r].high+e[r].low+e[r].close)/3;s+=Math.abs(t-o)}let c=s/n,l=(e[t].high+e[t].low+e[t].close)/3,u={value:c===0?0:(l-o)/(.015*c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-100,0,100])if(t>=f&&t<=p){let n=h(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}},Pt=class extends j{descriptor={id:`mfi`,name:`Money Flow Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=e.map(e=>(e.high+e.low+e.close)/3),o=a.map((t,n)=>t*e[n].volume);for(let t=n;t<e.length;t++){let s=0,c=0;for(let e=t-n+1;e<=t;e++)a[e]>a[e-1]?s+=o[e]:a[e]<a[e-1]&&(c+=o[e]);let l={value:c===0?100:100-100/(1+s/c)};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=l(r.value);u?e.lineTo(i,o):(e.moveTo(i,o),u=!0)}}e.stroke()}},Ft=class extends j{descriptor={id:`aroon`,name:`Aroon`,placement:`panel`,defaultConfig:{period:25}};calculate(e,t){let n=P(t,`period`,25,1),r=new M,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=0,o=0,s=-1/0,c=1/0;for(let r=0;r<=n;r++){let i=t-n+r;e[i].high>s&&(s=e[i].high,a=r),e[i].low<c&&(c=e[i].low,o=r)}let l={up:a/n*100,down:o/n*100};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100),u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`up`,r.colors[0]),u(`down`,r.colors[1]??`#e8505b`)}},It=class extends j{descriptor={id:`roc`,name:`Rate of Change`,placement:`panel`,defaultConfig:{period:12}};calculate(e,t){let n=P(t,`period`,12,1),r=new M,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].close,o={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);if(0>=f&&0<=p){e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);let t=h(0);e.beginPath(),e.moveTo(o.x,t),e.lineTo(o.x+o.width,t),e.stroke(),e.setLineDash([])}e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}},Lt=class extends j{descriptor={id:`tsi`,name:`True Strength Index`,placement:`panel`,defaultConfig:{longPeriod:25,shortPeriod:13,signalPeriod:7}};emaSmooth(e,t){let n=2/(t+1),r=[e[0]];for(let t=1;t<e.length;t++)r.push((e[t]-r[t-1])*n+r[t-1]);return r}calculate(e,t){let n=P(t,`longPeriod`,25,1),r=P(t,`shortPeriod`,13,1),i=P(t,`signalPeriod`,7,1),a=new M,o=Array(e.length).fill(null);if(e.length<2)return{values:a,series:o};let s=[],c=[];for(let t=1;t<e.length;t++){let n=e[t].close-e[t-1].close;s.push(n),c.push(Math.abs(n))}let l=this.emaSmooth(this.emaSmooth(s,n),r),u=this.emaSmooth(this.emaSmooth(c,n),r),d=[];for(let e=0;e<l.length;e++)d.push(u[e]===0?0:l[e]/u[e]*100);let f=this.emaSmooth(d,i);for(let t=0;t<d.length;t++){let n=t+1;if(n<e.length){let r={tsi:d[t],signal:f[t]};a.set(e[n].time,r),o[n]=r}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&(t.tsi!==void 0&&(l=Math.min(l,t.tsi),u=Math.max(u,t.tsi)),t.signal!==void 0&&(l=Math.min(l,t.signal),u=Math.max(u,t.signal)))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([]));let g=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=h(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};g(`tsi`,r.colors[0]),g(`signal`,r.colors[1]??`#f2a93b`)}},Rt=class extends j{descriptor={id:`cmf`,name:`Chaikin Money Flow`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0,o=0;for(let r=t-n+1;r<=t;r++){let t=e[r].high-e[r].low,n=t===0?0:(e[r].close-e[r].low-(e[r].high-e[r].close))/t;a+=n*e[r].volume,o+=e[r].volume}let s={value:o===0?0:a/o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([]));let g=n.barWidth/2;for(let t=s;t<=c&&t<i.length;t++){let o=i[t];if(o&&o.value!==void 0){let i=a(t,n),s=h(o.value),c=h(0);e.fillStyle=o.value>=0?r.colors[0]:r.colors[1]??`#e8505b`;let l=Math.min(s,c);e.fillRect(i-g,l,n.barWidth,Math.max(Math.abs(s-c),1))}}}},zt=class extends j{descriptor={id:`voldelta`,name:`Volume Delta`,placement:`panel`,defaultConfig:{mode:0}};calculate(e,t){let n=N(t,`mode`,0)>=1,r=new M,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++){let o=e[t],s=o.close>=o.open,c=s?o.volume:-o.volume;a+=c;let l={value:n?a:c,up:+!!s};r.set(o.time,l),i[t]=l}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2,p=r.colors[0]??`#1fa874`,m=r.colors[1]??`#e8505b`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value),c=Math.min(s,d),l=Math.max(Math.abs(s-d),1);e.fillStyle=r.up?p:m,e.fillRect(o-f,c,n.barWidth,l)}}},Bt=class extends j{descriptor={id:`vortex`,name:`Vortex Indicator`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0),o=Array(e.length).fill(0),s=Array(e.length).fill(0);for(let t=1;t<e.length;t++){a[t]=Math.abs(e[t].high-e[t-1].low),o[t]=Math.abs(e[t].low-e[t-1].high);let n=e[t].high,r=e[t].low,i=e[t-1].close;s[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let c=0,l=0,u=0;for(let t=1;t<e.length;t++)if(c+=a[t],l+=o[t],u+=s[t],t>n&&(c-=a[t-n],l-=o[t-n],u-=s[t-n]),t>=n&&u>0){let n={viPlus:c/u,viMinus:l/u};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`viPlus`,`viMinus`]){let n=t[e];n!==void 0&&(n<l&&(l=n),n>u&&(u=n))}}if(l===1/0)return;let d=(u-l)*.1||.1;l-=d,u+=d;let f=u-l||1,p=e=>o.y+o.height*(1-(e-l)/f);if(1>=l&&1<=u){e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);let t=p(1);e.beginPath(),e.moveTo(o.x,t),e.lineTo(o.x+o.width,t),e.stroke(),e.setLineDash([])}let m=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0)continue;let s=a(r,n),c=p(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};m(`viPlus`,r.colors[0]??`#1fa874`),m(`viMinus`,r.colors[1]??`#e8505b`)}},Vt=class extends j{descriptor={id:`chop`,name:`Choppiness Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,2),r=new M,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t].high,r=e[t].low,i=e[t-1].close;a[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let o=Math.log10(n),s=0;for(let t=1;t<e.length;t++)if(s+=a[t],t>n&&(s-=a[t-n]),t>=n){let a=-1/0,c=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<c&&(c=e[r].low);let l=a-c;if(l>0&&s>0){let n={value:Math.max(0,Math.min(100,100*Math.log10(s/l)/o))};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[38.2,61.8]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},Ht=class extends j{descriptor={id:`uo`,name:`Ultimate Oscillator`,placement:`panel`,defaultConfig:{fast:7,mid:14,slow:28}};calculate(e,t){let n=P(t,`fast`,7,1),r=P(t,`mid`,14,1),i=P(t,`slow`,28,1),a=new M,o=Array(e.length).fill(null);if(e.length<=i)return{values:a,series:o};let s=Array(e.length).fill(0),c=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t-1].close,r=Math.min(e[t].low,n),i=Math.max(e[t].high,n);s[t]=e[t].close-r,c[t]=i-r}let l=(e,t,n)=>{let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r};for(let t=i;t<e.length;t++){let u=Ut(l(s,t,n),l(c,t,n)),d=Ut(l(s,t,r),l(c,t,r)),f=Ut(l(s,t,i),l(c,t,i)),p={value:100*(4*u+2*d+f)/7};a.set(e[t].time,p),o[t]=p}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[30,70]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function Ut(e,t){return t===0?0:e/t}var Wt=class extends j{descriptor={id:`fi`,name:`Force Index`,placement:`panel`,defaultConfig:{period:13}};calculate(e,t){let n=P(t,`period`,13,1),r=new M,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=2/(n+1),o;for(let t=1;t<e.length;t++){let s=(e[t].close-e[t-1].close)*e[t].volume;if(o=o===void 0?s:s*a+o*(1-a),t>=n){let n={value:o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}},Gt=class extends j{descriptor={id:`crsi`,name:`Connors RSI`,placement:`panel`,defaultConfig:{rsiPeriod:3,streakPeriod:2,rankPeriod:100}};calculate(e,t){let n=P(t,`rsiPeriod`,3,1),r=P(t,`streakPeriod`,2,1),i=P(t,`rankPeriod`,100,1),a=new M,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=e.map(e=>e.close),l=Kt(c,n),u=Array(s).fill(0);for(let e=1;e<s;e++)c[e]>c[e-1]?u[e]=u[e-1]>0?u[e-1]+1:1:c[e]<c[e-1]?u[e]=u[e-1]<0?u[e-1]-1:-1:u[e]=0;let d=Kt(u,r),f=Array(s).fill(0);for(let e=1;e<s;e++)f[e]=c[e-1]===0?0:(c[e]-c[e-1])/c[e-1]*100;for(let t=0;t<s;t++){if(t<i+1)continue;let n=l[t],r=d[t];if(n===void 0||r===void 0)continue;let s=0;for(let e=t-i;e<t;e++)f[e]<f[t]&&s++;let c=s/i*100,u={value:(n+r+c)/3};a.set(e[t].time,u),o[t]=u}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[10,90]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function Kt(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1],s=n>0?n:0,c=n<0?-n:0;i=(i*(t-1)+s)/t,a=(a*(t-1)+c)/t,r[o]=a===0?100:100-100/(1+i/a)}return r}var qt=class extends j{descriptor={id:`coppock`,name:`Coppock Curve`,placement:`panel`,defaultConfig:{longRoc:14,shortRoc:11,wma:10}};calculate(e,t){let n=P(t,`longRoc`,14,1),r=P(t,`shortRoc`,11,1),i=P(t,`wma`,10,1),a=new M,o=Array(e.length).fill(null),s=e.length,c=Math.max(n,r);if(s<=c+i)return{values:a,series:o};let l=e.map(e=>e.close),u=(e,t)=>l[e-t]===0?0:(l[e]-l[e-t])/l[e-t]*100,d=Array(s).fill(void 0);for(let e=c;e<s;e++)d[e]=u(e,n)+u(e,r);let f=i*(i+1)/2;for(let t=c+i-1;t<s;t++){let n=0,r=!0;for(let e=0;e<i;e++){let a=d[t-e];if(a===void 0){r=!1;break}n+=a*(i-e)}if(!r)continue;let s={value:n/f};a.set(e[t].time,s),o[t]=s}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}},Jt=class extends j{descriptor={id:`kst`,name:`Know Sure Thing`,placement:`panel`,defaultConfig:{roc1:10,roc2:15,roc3:20,roc4:30,sma1:10,sma2:10,sma3:10,sma4:15,signal:9}};calculate(e,t){let n=P(t,`roc1`,10,1),r=P(t,`roc2`,15,1),i=P(t,`roc3`,20,1),a=P(t,`roc4`,30,1),o=P(t,`sma1`,10,1),s=P(t,`sma2`,10,1),c=P(t,`sma3`,10,1),l=P(t,`sma4`,15,1),u=P(t,`signal`,9,1),d=new M,f=Array(e.length).fill(null),p=e.length;if(p<2)return{values:d,series:f};let m=e.map(e=>e.close),h=F(Yt(m,n),o),g=F(Yt(m,r),s),_=F(Yt(m,i),c),v=F(Yt(m,a),l),y=Array(p).fill(void 0);for(let e=0;e<p;e++)h[e]===void 0||g[e]===void 0||_[e]===void 0||v[e]===void 0||(y[e]=h[e]*1+g[e]*2+_[e]*3+v[e]*4);let b=F(y,u);for(let t=0;t<p;t++){if(y[t]===void 0)continue;let n={value:y[t]};b[t]!==void 0&&(n.signal=b[t]),d.set(e[t].time,n),f[t]=n}return{values:d,series:f}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#4c8dff`),f(`signal`,r.colors[1]??`#f2a93b`)}};function Yt(e,t){let n=Array(e.length).fill(void 0);for(let r=t;r<e.length;r++)n[r]=e[r-t]===0?0:(e[r]-e[r-t])/e[r-t]*100;return n}function F(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){a=!1;break}i+=t}a&&(n[r]=i/t)}return n}var Xt=class extends j{descriptor={id:`elderray`,name:`Elder Ray`,placement:`panel`,defaultConfig:{period:13}};calculate(e,t){let n=P(t,`period`,13,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=2/(n+1),s;for(let t=0;t<a;t++)if(s=s===void 0?e[t].close:e[t].close*o+s*(1-o),t>=n-1){let n={bull:e[t].high-s,bear:e[t].low-s};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`bull`,`bear`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2;e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=r.colors[0]??`#1fa874`,m=r.colors[1]??`#e8505b`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r)continue;let o=a(t,n);if(r.bull!==void 0){let t=u(r.bull);e.fillStyle=p,e.globalAlpha=.8,e.fillRect(o-f,Math.min(t,d),Math.max(1,f),Math.abs(t-d))}if(r.bear!==void 0){let t=u(r.bear);e.fillStyle=m,e.globalAlpha=.8,e.fillRect(o,Math.min(t,d),Math.max(1,f),Math.abs(t-d))}}e.globalAlpha=1}},Zt=class extends j{descriptor={id:`stc`,name:`Schaff Trend Cycle`,placement:`panel`,defaultConfig:{fast:23,slow:50,cycle:10}};calculate(e,t){let n=P(t,`fast`,23,1),r=P(t,`slow`,50,1),i=P(t,`cycle`,10,1),a=new M,o=Array(e.length).fill(null),s=e.length;if(s===0)return{values:a,series:o};let c=e.map(e=>e.close),l=2/(n+1),u=2/(r+1),d=c[0],f=c[0],p=Array(s);for(let e=0;e<s;e++)d=e===0?c[0]:c[e]*l+d*(1-l),f=e===0?c[0]:c[e]*u+f*(1-u),p[e]=d-f;let m=Qt(Qt(p,i),i);for(let t=0;t<s;t++){let n=m[t];if(n===void 0)continue;let r={value:Math.max(0,Math.min(100,n))};a.set(e[t].time,r),o[t]=r}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[25,75]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}};function Qt(e,t){let n=e.length,r=Array(n).fill(void 0),i;for(let a=0;a<n;a++){if(a<t-1)continue;let n=1/0,o=-1/0,s=!0;for(let r=a-t+1;r<=a;r++){let t=e[r];if(t===void 0){s=!1;break}t<n&&(n=t),t>o&&(o=t)}if(!s||e[a]===void 0)continue;let c=o-n>0?(e[a]-n)/(o-n)*100:50;i=i===void 0?c:i+.5*(c-i),r[a]=i}return r}var $t=class extends j{descriptor={id:`kvo`,name:`Klinger Oscillator`,placement:`panel`,defaultConfig:{fast:34,slow:55,signal:13}};calculate(e,t){let n=P(t,`fast`,34,1),r=P(t,`slow`,55,1),i=P(t,`signal`,13,1),a=new M,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=2/(n+1),l=2/(r+1),u=2/(i+1),d,f=1,p=0,m=0,h,g,_;for(let t=0;t<s;t++){let n=e[t],i=n.high+n.low+n.close,s=d===void 0||i>d?1:-1,v=n.high-n.low;m=d===void 0?v:s===f?m+v:p+v;let y=m===0?0:n.volume*Math.abs(2*(v/m-1))*s*100;h=h===void 0?y:y*c+h*(1-c),g=g===void 0?y:y*l+g*(1-l);let b=h-g;if(_=_===void 0?b:b*u+_*(1-u),d=i,f=s,p=v,t>=r){let e={value:b,signal:_};a.set(n.time,e),o[t]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#4c8dff`),f(`signal`,r.colors[1]??`#f2a93b`)}},en=class extends j{descriptor={id:`fisher`,name:`Fisher Transform`,placement:`panel`,defaultConfig:{period:9}};calculate(e,t){let n=P(t,`period`,9,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=e.map(e=>(e.high+e.low)/2),s=0,c=0;for(let t=n-1;t<a;t++){let a=-1/0,l=1/0;for(let e=t-n+1;e<=t;e++)o[e]>a&&(a=o[e]),o[e]<l&&(l=o[e]);s=.33*(a-l>0?2*(o[t]-l)/(a-l)-1:0)+.67*s,s=Math.max(-.999,Math.min(.999,s));let u=c;c=.5*Math.log((1+s)/(1-s))+.5*c;let d={value:c,trigger:u};r.set(e[t].time,d),i[t]=d}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`trigger`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#4c8dff`),f(`trigger`,r.colors[1]??`#f2a93b`)}},tn=class extends j{descriptor={id:`dpo`,name:`Detrended Price Oscillator`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,2),r=Math.floor(n/2)+1,i=new M,a=Array(e.length).fill(null),o=e.length;if(o<n)return{values:i,series:a};let s=0;for(let t=0;t<o;t++)if(s+=e[t].close,t>=n&&(s-=e[t-n].close),t>=n-1&&t-r>=0){let o=s/n,c={value:e[t-r].close-o};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=n.barWidth/2;e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=r.colors[0]??`#1fa874`,m=r.colors[1]??`#e8505b`;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);e.fillStyle=r.value>=0?p:m,e.fillRect(o-f,Math.min(s,d),n.barWidth,Math.max(1,Math.abs(s-d)))}}},nn=class extends j{descriptor={id:`bop`,name:`Balance of Power`,placement:`panel`,defaultConfig:{smooth:14}};calculate(e,t){let n=P(t,`smooth`,14,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=Array(a);for(let t=0;t<a;t++){let n=e[t].high-e[t].low;o[t]=n>0?(e[t].close-e[t].open)/n:0}let s=0;for(let t=0;t<a;t++)if(s+=o[t],t>=n&&(s-=o[t-n]),t>=n-1){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+1)/2),u=l(0);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,u),e.lineTo(o.x+o.width,u),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let d=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(Math.max(-1,Math.min(1,r.value)));d?e.lineTo(o,s):(e.moveTo(o,s),d=!0)}e.stroke()}},rn=class extends j{descriptor={id:`massindex`,name:`Mass Index`,placement:`panel`,defaultConfig:{ema:9,sum:25}};calculate(e,t){let n=P(t,`ema`,9,1),r=P(t,`sum`,25,1),i=new M,a=Array(e.length).fill(null),o=e.length;if(o<r)return{values:i,series:a};let s=2/(n+1),c,l,u=Array(o).fill(0);for(let t=0;t<o;t++){let n=e[t].high-e[t].low;c=c===void 0?n:n*s+c*(1-s),l=l===void 0?c:c*s+l*(1-s),u[t]=l===0?1:c/l}let d=0;for(let t=0;t<o;t++)if(d+=u[t],t>=r&&(d-=u[t-r]),t>=n+r){let n={value:d};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;l=Math.min(l,26),u=Math.max(u,27.5);let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[26.5,27]){let n=f(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let p=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=f(r.value);p?e.lineTo(o,s):(e.moveTo(o,s),p=!0)}e.stroke()}},an=class extends j{descriptor={id:`cmo`,name:`Chande Momentum`,placement:`panel`,defaultConfig:{period:9}};calculate(e,t){let n=P(t,`period`,9,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=1;t<a;t++){let n=e[t].close-e[t-1].close;o[t]=n>0?n:0,s[t]=n<0?-n:0}let c=0,l=0;for(let t=1;t<a;t++)if(c+=o[t],l+=s[t],t>n&&(c-=o[t-n],l-=s[t-n]),t>=n){let n=c+l,a={value:n>0?100*(c-l)/n:0};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-(e+100)/200);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-50,0,50]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},on=class extends j{descriptor={id:`trix`,name:`TRIX`,placement:`panel`,defaultConfig:{period:15,signal:9}};calculate(e,t){let n=P(t,`period`,15,1),r=P(t,`signal`,9,1),i=new M,a=Array(e.length).fill(null),o=e.length;if(o<2)return{values:i,series:a};let s=sn(sn(sn(e.map(e=>e.close),n),n),n),c=Array(o).fill(0);for(let e=1;e<o;e++)c[e]=s[e-1]===0?0:(s[e]-s[e-1])/s[e-1]*100;let l=sn(c,r),u=3*n;for(let t=u;t<o;t++){let n={value:c[t],signal:l[t]};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#4c8dff`),f(`signal`,r.colors[1]??`#f2a93b`)}};function sn(e,t){let n=2/(t+1),r=Array(e.length).fill(0),i=e[0]??0;r[0]=i;for(let t=1;t<e.length;t++)i=e[t]*n+i*(1-n),r[t]=i;return r}var cn=class extends j{descriptor={id:`emv`,name:`Ease of Movement`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<2)return{values:r,series:i};let o=Array(a).fill(0);for(let t=1;t<a;t++){let n=(e[t].high+e[t].low)/2,r=(e[t-1].high+e[t-1].low)/2,i=e[t].high-e[t].low,a=e[t].volume;o[t]=a>0?(n-r)*i/a:0}let s=0;for(let t=1;t<a;t++)if(s+=o[t],t>n&&(s-=o[t-n]),t>=n){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}render(e,t,n,r){ln(e,t,n,r)}};function ln(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let f=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let o=a(t,n),s=u(r.value);f?e.lineTo(o,s):(e.moveTo(o,s),f=!0)}e.stroke()}var un=class extends j{descriptor={id:`wad`,name:`Williams A/D`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new M,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close,o=e[t].close;o>i?a+=o-Math.min(e[t].low,i):o<i&&(a+=o-Math.max(e[t].high,i));let s={value:a};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}render(e,t,n,r){dn(e,t,n,r,a)}};function dn(e,t,n,r,i){let a=t.series;if(!a)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<a.length;e++){let t=a[e]?.value;t!==void 0&&(t<l&&(l=t),t>u&&(u=t))}if(l===1/0)return;let d=u-l||1,f=e=>o.y+o.height*(1-(e-l)/d);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let p=!1;for(let t=s;t<=c&&t<a.length;t++){let r=a[t];if(!r||r.value===void 0)continue;let o=i(t,n),s=f(r.value);p?e.lineTo(o,s):(e.moveTo(o,s),p=!0)}e.stroke()}var fn=class extends j{descriptor={id:`pvt`,name:`Price Volume Trend`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new M,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close;i!==0&&(a+=e[t].volume*(e[t].close-i)/i);let o={value:a};n.set(e[t].time,o),r[t]=o}return{values:n,series:r}}render(e,t,n,r){dn(e,t,n,r,a)}},pn=class extends j{descriptor={id:`chaikinvol`,name:`Chaikin Volatility`,placement:`panel`,defaultConfig:{ema:10,roc:10}};calculate(e,t){let n=P(t,`ema`,10,1),r=P(t,`roc`,10,1),i=new M,a=Array(e.length).fill(null),o=e.length;if(o<=r)return{values:i,series:a};let s=2/(n+1),c=Array(o),l=e[0].high-e[0].low;c[0]=l;for(let t=1;t<o;t++)l=(e[t].high-e[t].low)*s+l*(1-s),c[t]=l;for(let t=n+r;t<o;t++){let n=c[t-r],o={value:n===0?0:(c[t]-n)/n*100};i.set(e[t].time,o),a[t]=o}return{values:i,series:a}}render(e,t,n,r){ln(e,t,n,r)}},mn=class extends j{descriptor={id:`rvi`,name:`Relative Vigor Index`,placement:`panel`,defaultConfig:{period:10}};calculate(e,t){let n=P(t,`period`,10,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<n+3)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=0;t<a;t++)o[t]=e[t].close-e[t].open,s[t]=e[t].high-e[t].low;let c=(e,t)=>(e[t]+2*e[t-1]+2*e[t-2]+e[t-3])/6,l=Array(a).fill(void 0),u=Array(a).fill(void 0);for(let e=3;e<a;e++)l[e]=c(o,e),u[e]=c(s,e);let d=Array(a).fill(void 0);for(let e=3+n-1;e<a;e++){let t=0,r=0;for(let i=e-n+1;i<=e;i++)t+=l[i],r+=u[i];d[e]=r===0?0:t/r}for(let t=0;t<a;t++){if(d[t]===void 0)continue;let n={value:d[t]};t>=3&&d[t-3]!==void 0&&(n.signal=(d[t]+2*d[t-1]+2*d[t-2]+d[t-3])/6),r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};f(`value`,r.colors[0]??`#4c8dff`),f(`signal`,r.colors[1]??`#f2a93b`)}},hn=class extends j{descriptor={id:`stochrsi`,name:`Stochastic RSI`,placement:`panel`,defaultConfig:{rsiPeriod:14,stochPeriod:14,k:3,d:3}};calculate(e,t){let n=P(t,`rsiPeriod`,14,1),r=P(t,`stochPeriod`,14,1),i=P(t,`k`,3,1),a=P(t,`d`,3,1),o=new M,s=Array(e.length).fill(null),c=e.length;if(c<=n+r)return{values:o,series:s};let l=gn(e.map(e=>e.close),n),u=Array(c).fill(void 0);for(let e=0;e<c;e++){if(l[e]===void 0)continue;let t=1/0,n=-1/0,i=!0;for(let a=e-r+1;a<=e;a++){if(a<0||l[a]===void 0){i=!1;break}l[a]<t&&(t=l[a]),l[a]>n&&(n=l[a])}i&&(u[e]=n-t>0?(l[e]-t)/(n-t)*100:0)}let d=_n(u,i),f=_n(d,a);for(let t=0;t<c;t++){if(d[t]===void 0)continue;let n={k:d[t]};f[t]!==void 0&&(n.d=f[t]),o.set(e[t].time,n),s[t]=n}return{values:o,series:s}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[20,80]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]);let u=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){u=!1;continue}let s=a(r,n),c=l(o[t]);u?e.lineTo(s,c):(e.moveTo(s,c),u=!0)}e.stroke()};u(`k`,r.colors[0]??`#4c8dff`),u(`d`,r.colors[1]??`#f2a93b`)}};function gn(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1];i=(i*(t-1)+(n>0?n:0))/t,a=(a*(t-1)+(n<0?-n:0))/t,r[o]=a===0?100:100-100/(1+i/a)}return r}function _n(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){if(e[n]===void 0){a=!1;break}i+=e[n]}a&&(n[r]=i/t)}return n}var vn=class extends j{descriptor={id:`ppo`,name:`Percentage Price Oscillator`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9}};calculate(e,t){let n=P(t,`fast`,12,1),r=P(t,`slow`,26,1),i=P(t,`signal`,9,1),a=new M,o=Array(e.length).fill(null),s=e.length;if(s<=r)return{values:a,series:o};let c=e.map(e=>e.close),l=yn(c,n),u=yn(c,r),d=Array(s).fill(void 0);for(let e=0;e<s;e++)l[e]===void 0||u[e]===void 0||u[e]===0||(d[e]=(l[e]-u[e])/u[e]*100);let f=yn(d,i);for(let t=0;t<s;t++){if(d[t]===void 0)continue;let n={value:d[t]};f[t]!==void 0&&(n.signal=f[t],n.hist=d[t]-f[t]),a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];if(t)for(let e of[`value`,`signal`,`hist`]){let n=t[e];n!==void 0&&Math.abs(n)>l&&(l=Math.abs(n))}}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0),f=Math.max(1,o.width/(c-s+1)*.6);for(let t=s;t<=c&&t<i.length;t++){let r=i[t]?.hist;if(r===void 0)continue;let o=a(t,n),s=u(r);e.fillStyle=r>=0?`rgba(31, 168, 116,0.5)`:`rgba(232, 80, 91,0.5)`;let c=Math.min(s,d);e.fillRect(o-f/2,c,f,Math.max(1,Math.abs(s-d)))}e.strokeStyle=r.colors[2]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let p=(t,o)=>{e.beginPath(),e.strokeStyle=o,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let r=s;r<=c&&r<i.length;r++){let o=i[r];if(!o||o[t]===void 0){l=!1;continue}let s=a(r,n),c=u(o[t]);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()};p(`value`,r.colors[0]??`#4c8dff`),p(`signal`,r.colors[1]??`#f2a93b`)}};function yn(e,t){let n=e.length,r=Array(n).fill(void 0),i=2/(t+1),a,o=0,s=0;for(let c=0;c<n;c++){let n=e[c];n!==void 0&&(a===void 0?(o+=n,s++,s===t&&(a=o/t,r[c]=a)):(a=n*i+a*(1-i),r[c]=a))}return r}var bn=class extends j{descriptor={id:`ac`,name:`Accelerator Oscillator`,placement:`panel`,defaultConfig:{}};calculate(e){let t=new M,n=Array(e.length).fill(null),r=e.length;if(r<38)return{values:t,series:n};let i=e.map(e=>(e.high+e.low)/2),a=Array(r).fill(void 0);for(let e=33;e<r;e++)a[e]=xn(i,e,5)-xn(i,e,34);for(let i=37;i<r;i++){let r=0;for(let e=i-4;e<=i;e++)r+=a[e];let o={value:a[i]-r/5};t.set(e[i].time,o),n[i]=o}return{values:t,series:n}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}if(l===0)return;let u=e=>o.y+o.height*(1-(e+l)/(2*l)),d=u(0);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,d),e.lineTo(o.x+o.width,d),e.stroke(),e.setLineDash([]);let f=Math.max(1,o.width/(c-s+1)*.6),p;for(let t=s;t<=c&&t<i.length;t++){let r=i[t]?.value;if(r===void 0){p=void 0;continue}let o=a(t,n),s=u(r);e.fillStyle=(p===void 0?r>=0:r>=p)?`rgba(31, 168, 116,0.85)`:`rgba(232, 80, 91,0.85)`;let c=Math.min(s,d);e.fillRect(o-f/2,c,f,Math.max(1,Math.abs(s-d))),p=r}}};function xn(e,t,n){let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r/n}var Sn=class extends j{descriptor={id:`rmi`,name:`Relative Momentum Index`,placement:`panel`,defaultConfig:{period:20,momentum:5}};calculate(e,t){let n=P(t,`period`,20,1),r=P(t,`momentum`,5,1),i=new M,a=Array(e.length).fill(null),o=e.length;if(o<=n+r)return{values:i,series:a};let s=e.map(e=>e.close),c=Array(o).fill(0),l=Array(o).fill(0);for(let e=r;e<o;e++){let t=s[e]-s[e-r];c[e]=t>0?t:0,l[e]=t<0?-t:0}let u=0,d=0,f=r+n;for(let e=r+1;e<=f;e++)u+=c[e],d+=l[e];u/=n,d/=n;let p=t=>{let n={value:d===0?100:100-100/(1+u/d)};i.set(e[t].time,n),a[t]=n};p(f);for(let e=f+1;e<o;e++)u=(u*(n-1)+c[e])/n,d=(d*(n-1)+l[e])/n,p(e);return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=e=>o.y+o.height*(1-e/100);e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[30,70]){let n=l(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0]??`#4c8dff`,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0){u=!1;continue}let o=a(t,n),s=l(r.value);u?e.lineTo(o,s):(e.moveTo(o,s),u=!0)}e.stroke()}},Cn=class extends j{descriptor={id:`disparity`,name:`Disparity Index`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let a=o/n,s={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(e,t,n,r){ln(e,t,n,r)}},wn=class extends j{descriptor={id:`qstick`,name:`Qstick`,placement:`panel`,defaultConfig:{period:8}};calculate(e,t){let n=P(t,`period`,8,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++){let a=e[t].close-e[t].open;if(o+=a,t>=n&&(o-=e[t-n].close-e[t-n].open),t>=n-1){let a={value:o/n};r.set(e[t].time,a),i[t]=a}}return{values:r,series:i}}render(e,t,n,r){ln(e,t,n,r)}},Tn=class extends j{descriptor={id:`pgo`,name:`Pretty Good Oscillator`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0);for(let t=0;t<a;t++){if(t===0){o[t]=e[t].high-e[t].low;continue}let n=e[t-1].close;o[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let s=Array(a).fill(void 0),c=0;for(let e=1;e<=n;e++)c+=o[e];s[n]=c/n;for(let e=n+1;e<a;e++)s[e]=(s[e-1]*(n-1)+o[e])/n;let l=0;for(let t=0;t<a;t++)if(l+=e[t].close,t>=n&&(l-=e[t-n].close),t>=n&&s[t]!==void 0&&s[t]>0){let a=l/n,o={value:(e[t].close-a)/s[t]};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=3;for(let e=s;e<=c&&e<i.length;e++){let t=i[e]?.value;t!==void 0&&Math.abs(t)>l&&(l=Math.abs(t))}let u=e=>o.y+o.height*(1-(e+l)/(2*l));e.strokeStyle=r.colors[1]??`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]);for(let t of[-3,0,3]){let n=u(t);e.beginPath(),e.moveTo(o.x,n),e.lineTo(o.x+o.width,n),e.stroke()}e.setLineDash([]),e.beginPath(),e.strokeStyle=r.colors[0]??`#4c8dff`,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let d=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0){d=!1;continue}let o=a(t,n),s=u(r.value);d?e.lineTo(o,s):(e.moveTo(o,s),d=!0)}e.stroke()}},En=class extends j{descriptor={id:`stddev`,name:`Standard Deviation`,placement:`panel`,defaultConfig:{period:20}};calculate(e,t){let n=P(t,`period`,20,1),r=new M,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=e[r].close;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=e[r].close-o;s+=t*t}let c={value:Math.sqrt(s/n)};r.set(e[t].time,c),i[t]=c}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},Dn=class extends j{descriptor={id:`volumeProfile`,name:`Volume Profile`,placement:`panel`,defaultConfig:{rows:24}};calculate(e,t){let n=P(t,`rows`,24,1),r=new M,i=Array(e.length).fill(null);if(e.length===0)return{values:r,series:i};let a=1/0,o=-1/0;for(let t of e)t.low<a&&(a=t.low),t.high>o&&(o=t.high);let s=(o-a||1)/n,c=Array(n).fill(0);for(let t of e){let e=(t.high+t.low+t.close)/3,r=Math.min(n-1,Math.floor((e-a)/s));c[r]+=t.volume}for(let e=0;e<n;e++){let t=a+(e+.5)*s;r.set(e,{price:t,volume:c[e],rowIndex:e})}return{values:r,series:i,meta:{minPrice:a,maxPrice:o,rows:n,rowHeight:s,bins:c,maxVolume:Math.max(...c)}}}render(e,t,n,r){let{chartRect:i}=n,a=t.meta;if(!a||a.maxVolume===0)return;let{minPrice:o,rows:c,rowHeight:l,bins:u,maxVolume:d}=a,f=i.width*.3,p=s(n);for(let t=0;t<c;t++){let n=p(o+t*l),a=p(o+(t+1)*l),s=u[t]/d*f;e.fillStyle=u[t]>d*.7?r.colors[1]??`rgba(242, 169, 59, 0.5)`:r.colors[0]??`rgba(76, 141, 255, 0.3)`,e.fillRect(i.x,Math.min(n,a),s,Math.max(Math.abs(n-a)-1,1))}}},On=class extends j{descriptor={id:`ad`,name:`Accumulation/Distribution`,placement:`panel`,defaultConfig:{}};calculate(e,t){let n=new M,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0;for(let t=0;t<e.length;t++){let a=e[t].high-e[t].low,o=a===0?0:(e[t].close-e[t].low-(e[t].high-e[t].close))/a;i+=o*e[t].volume;let s={value:i};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d-f,m=e=>o.y+o.height*(1-(e-f)/p);e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let h=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=m(r.value);h?e.lineTo(i,o):(e.moveTo(i,o),h=!0)}}e.stroke()}},kn=class extends j{descriptor={id:`vroc`,name:`Volume Rate of Change`,placement:`panel`,defaultConfig:{period:14}};calculate(e,t){let n=P(t,`period`,14,1),r=new M,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].volume,o={value:a===0?0:(e[t].volume-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{chartRect:o}=n,{from:s,to:c}=n.visibleRange,l=1/0,u=-1/0;for(let e=s;e<=c&&e<i.length;e++){let t=i[e];t&&t.value!==void 0&&(l=Math.min(l,t.value),u=Math.max(u,t.value))}if(l===1/0)return;let d=(u-l||1)*.1,f=l-d,p=u+d,m=p-f,h=e=>o.y+o.height*(1-(e-f)/m);0>=f&&0<=p&&(e.strokeStyle=`#7d8696`,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(o.x,h(0)),e.lineTo(o.x+o.width,h(0)),e.stroke(),e.setLineDash([])),e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let g=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(r&&r.value!==void 0){let i=a(t,n),o=h(r.value);g?e.lineTo(i,o):(e.moveTo(i,o),g=!0)}}e.stroke()}};function An(e){e.register(new Ye),e.register(new Xe),e.register(new Ze),e.register(new Qe),e.register(new $e),e.register(new et),e.register(new tt),e.register(new nt),e.register(new rt),e.register(new at),e.register(new ot),e.register(new st),e.register(new ct),e.register(new lt),e.register(new ft),e.register(new pt),e.register(new mt),e.register(new ht),e.register(new _t),e.register(new vt),e.register(new yt),e.register(new Ct),e.register(new Et),e.register(new Dt),e.register(new Ot),e.register(new kt),e.register(new At),e.register(new jt),e.register(new Mt),e.register(new Nt),e.register(new Pt),e.register(new Ft),e.register(new It),e.register(new Lt),e.register(new Rt),e.register(new En),e.register(new Dn),e.register(new On),e.register(new kn),e.register(new wt),e.register(new Tt),e.register(new zt),e.register(new Bt),e.register(new Vt),e.register(new Ht),e.register(new Wt),e.register(new Gt),e.register(new qt),e.register(new Jt),e.register(new Xt),e.register(new Zt),e.register(new $t),e.register(new en),e.register(new tn),e.register(new nn),e.register(new rn),e.register(new an),e.register(new on),e.register(new cn),e.register(new fn),e.register(new un),e.register(new pn),e.register(new mn),e.register(new hn),e.register(new vn),e.register(new bn),e.register(new Sn),e.register(new Cn),e.register(new wn),e.register(new Tn)}function jn(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.requestId==`number`?t.type===`result`||t.type===`pong`||t.type===`error`:!1}var Mn=class{worker;fallbackPlugins;timeoutMs;nextRequestId=1;pending=new Map;messageHandler;constructor(e,t={}){this.worker=e,this.fallbackPlugins=t.fallbackPlugins??new Map,this.timeoutMs=t.timeoutMs??3e4,this.messageHandler=e=>this.handleMessage(e),this.worker&&(this.worker.addEventListener(`message`,this.messageHandler),this.worker.addEventListener(`error`,this.messageHandler))}hasWorker(){return this.worker!==null}registerFallbackPlugin(e){this.fallbackPlugins.set(e.descriptor.id,e)}async calculate(e,t,n){if(!this.worker){let r=this.fallbackPlugins.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);return r.calculate(n,t)}let r=this.nextRequestId++,i={type:`calculate`,requestId:r,indicatorId:e,config:t,data:n};return new Promise((t,n)=>{let a={resolve:t,reject:n,timer:null};this.timeoutMs>0&&(a.timer=setTimeout(()=>{this.pending.delete(r),n(Error(`Indicator worker timeout (${this.timeoutMs}ms): ${e}`))},this.timeoutMs)),this.pending.set(r,a),this.worker.postMessage(i)})}ping(){if(!this.worker)return Promise.resolve();let e=this.nextRequestId++;return new Promise((t,n)=>{let r={resolve:()=>t(),reject:n,timer:this.timeoutMs>0?setTimeout(()=>{this.pending.delete(e),n(Error(`Indicator worker ping timeout`))},this.timeoutMs):null};this.pending.set(e,r),this.worker.postMessage({type:`ping`,requestId:e})})}terminate(){this.worker&&=(this.worker.removeEventListener(`message`,this.messageHandler),this.worker.removeEventListener(`error`,this.messageHandler),this.worker.terminate(),null);for(let e of this.pending.values())e.timer&&clearTimeout(e.timer),e.reject(Error(`Indicator worker terminated`));this.pending.clear()}handleMessage(e){let t=e.data;if(t!==void 0){if(!jn(t))return;this.dispatchResponse(t);return}let n=e.message??`Indicator worker error`;for(let[e,t]of this.pending)t.timer&&clearTimeout(t.timer),t.reject(Error(n)),this.pending.delete(e)}dispatchResponse(e){let t=this.pending.get(e.requestId);if(t){if(this.pending.delete(e.requestId),t.timer&&clearTimeout(t.timer),e.type===`error`){t.reject(Error(e.message));return}if(e.type===`pong`){t.resolve(void 0);return}t.resolve(e.output)}}},Nn=class{visible=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}render(t,n,r){if(!this.visible)return;let{chartRect:i,priceRange:a}=n;if(t.strokeStyle=r.grid,t.lineWidth=1,a.max-a.min<=0)return;let o=s(n);t.beginPath();let c=(0,e.computeTickStep)(a.min,a.max,8),l=Math.ceil(a.min/c)*c;for(let e=l;e<=a.max;e+=c){let n=Math.round(o(e))+.5;t.moveTo(i.x,n),t.lineTo(i.x+i.width,n)}let u=n.barWidth+n.barSpacing,d=Math.max(1,Math.ceil(80/u)),f=-n.offset+i.x+n.barWidth/2,p=Math.floor(n.offset/u),m=Math.ceil((n.offset+i.width)/u);for(let e=p;e<=m;e++){if(e%d!==0)continue;let n=Math.round(e*u+f)+.5;t.moveTo(n,i.y),t.lineTo(n,i.y+i.height)}t.stroke()}},Pn=12,Fn=class{locale=`en-US`;reservedPrice=null;setReservedPriceProvider(e){this.reservedPrice=e}setLocale(e){this.locale=e}render(t,n,r){let{chartRect:i,priceRange:a}=n,c=i.x+i.width;if(a.max-a.min<=0)return;let l=s(n);t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(c+.5,i.y),t.lineTo(c+.5,i.y+i.height),t.stroke(),t.globalAlpha=1;let u=(0,e.computeTickStep)(a.min,a.max,8),d=Math.ceil(a.min/u)*u,f=(0,e.autoPricePrecision)(a.min,a.max),p=`500 ${r.font.sizeSmall}px ${r.font.family}`,m=n.scaleMode??(n.logScale?`logarithmic`:`regular`),h=n.scaleBaseline,g=[],_=this.reservedPrice?.()??null,v=_===null?null:o(_,n);for(let t=d;t<=a.max;t+=u){let n=l(t);v!==null&&Math.abs(n-v)<Pn||g.push({y:n,text:(0,e.formatPriceScaleLabel)(t,m,h,f,this.locale)})}t.font=p,t.textBaseline=`middle`,t.textAlign=`left`,t.strokeStyle=r.axisLine,t.globalAlpha=.45,t.beginPath();for(let{y:e}of g)t.moveTo(c+1,e+.5),t.lineTo(c+4,e+.5);t.stroke(),t.globalAlpha=1,t.fillStyle=r.axisLabel;for(let{y:e,text:n}of g)t.fillText(n,c+8,e)}},In=e=>e<10?`0`+e:``+e,Ln=class{tzOffsetMinutes=null;setTimezoneOffset(e){this.tzOffsetMinutes=e}render(t,n,r,i,a){let{chartRect:o}=n,s=a??o.y+o.height;t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(o.x,s+.5),t.lineTo(o.x+o.width,s+.5),t.stroke(),t.globalAlpha=1;let c=n.barWidth+n.barSpacing,l=Math.max(1,Math.ceil(80/c)),u=-n.offset+o.x+n.barWidth/2,d=Math.floor(n.offset/c),f=Math.ceil((n.offset+o.width)/c),p=(0,e.tzLabel)(this.tzOffsetMinutes),h=`500 ${r.font.sizeSmall-1}px ${r.font.family}`,g=o.x+o.width-4;t.font=h;let _=g-t.measureText(p).width-8;t.font=`500 ${r.font.sizeSmall}px ${r.font.family}`,t.textBaseline=`top`,t.textAlign=`center`,t.fillStyle=r.axisLabel;let v=-1;for(let n=d;n<=f&&i.length>0;n++){if(n%l!==0)continue;let r=n*c+u,a=m(n,i),o=(0,e.timeParts)(a>0xe8d4a51000?a:a*1e3,this.tzOffsetMinutes),{year:d,day:f,month:p,hours:h,minutes:g}=o,y;(0,e.isDateOnly)(o)?y=`${p}/${f}/${d}`:f===v?y=`${In(h)}:${In(g)}`:(y=`${p}/${f}`,v=f),!(r+t.measureText(y).width/2>_)&&t.fillText(y,r,s+7)}t.font=h,t.textAlign=`right`,t.textBaseline=`top`,t.globalAlpha=.75,t.fillStyle=r.textSecondary,t.fillText(p,g,s+7),t.globalAlpha=1}},Rn=new Set,I=null,zn=class{panHandler=null;zoomHandler=null;crosshairHandler=null;axisDragHandler=null;alertDragHandler=null;axisViewportGetter=null;onAxisDoubleClick=null;measureHandlers=null;measuring=!1;boxSelectHandlers=null;boxSelecting=!1;onAltClick=null;onEscape=null;onConfirm=null;onClick=null;downPos=null;downMoved=!1;pressForClick=!1;drawingManager=null;tradingManager=null;paneResizeHandler=null;viewportGetter=null;onOverlayDirty=null;boundHandlers=[];lastTouchDist=0;lastTouchMid={x:0,y:0};touchActive=!1;touchStartPos={x:0,y:0};longPressTimer=null;longPressMs=500;longPressMaxMove=8;cachedRect=null;constructor(e){this.element=e}setOverlayDirtyCallback(e){this.onOverlayDirty=e}setPanHandler(e){this.panHandler=e}setZoomHandler(e){this.zoomHandler=e}setCrosshairHandler(e){this.crosshairHandler=e}setAltClickHandler(e){this.onAltClick=e}setEscapeHandler(e){this.onEscape=e}setConfirmHandler(e){this.onConfirm=e}setClickHandler(e){this.onClick=e}setBoxSelectHandlers(e){this.boxSelectHandlers=e}setMeasureHandlers(e){this.measureHandlers=e}setAxisDragHandler(e,t,n){this.axisDragHandler=e,this.axisViewportGetter=t,this.onAxisDoubleClick=n??null}setDrawingManager(e,t){this.drawingManager=e,this.viewportGetter=t}setAlertDragHandler(e){this.alertDragHandler=e}setTradingManager(e,t){this.tradingManager=e,this.viewportGetter=t}setPaneResizeHandler(e){this.paneResizeHandler=e}attach(){let e=()=>this.viewportGetter?.()??null;Rn.add(this.element);let t=e=>{let t=this.axisViewportGetter?.();if(!t)return null;let n=t.chartRect;return e.y>n.y+n.height?`time`:e.x>n.x+n.width?`price`:null},n=e=>{let t=(this.viewportGetter?.()??this.axisViewportGetter?.())?.chartRect;return t?{x:Math.max(t.x,Math.min(t.x+t.width,e.x)),y:Math.max(t.y,Math.min(t.y+t.height,e.y))}:e},r=()=>this.crosshairHandler&&this.crosshairHandler.getMode()!==`hidden`?`crosshair`:``,i=e=>{this.element.style.cursor!==e&&(this.element.style.cursor=e)},a=n=>{let i=t(n);if(i===`price`)return`ns-resize`;if(i===`time`)return`ew-resize`;let a=this.paneResizeHandler?.cursorAt(n);if(a)return a;if(this.alertDragHandler?.isOverAlert(n))return`ns-resize`;let o=e();return o&&this.tradingManager?.isOverDraggableLine(n,o)?`ns-resize`:(o?this.drawingManager?.hoverCursorAt(n,o):null)??r()},o=!1,s=``,c=e=>{if(!(e.buttons&1)){h(e);return}m(e)},l=()=>{o||(o=!0,s=document.documentElement.style.userSelect,document.documentElement.style.userSelect=`none`,document.addEventListener(`mousemove`,c))},u=()=>{o&&(o=!1,document.documentElement.style.userSelect=s,document.removeEventListener(`mousemove`,c))},d=e=>e===this.element||e instanceof HTMLCanvasElement,f=n=>{if(I=this.element,n.button!==0||!d(n.target))return;this.panHandler?.cancelMomentum(),l(),this.invalidateRect();let a=this.getMousePos(n),o=e();this.downPos=a,this.downMoved=!1,this.pressForClick=!1;let s=t(a);if(s&&this.axisDragHandler){this.axisDragHandler.begin(s,a);return}if(this.paneResizeHandler?.tryBegin(a))return;let c=!!this.drawingManager?.getActiveTool()||!!this.tradingManager?.isBracketActive()||!!this.tradingManager?.isOrderDraftActive();if((n.ctrlKey||n.metaKey)&&this.boxSelectHandlers&&!c){this.boxSelecting=!0,this.boxSelectHandlers.begin(a),i(r()),this.onOverlayDirty?.(!0);return}if(n.shiftKey&&this.measureHandlers){this.measuring=!0,this.measureHandlers.begin(a),this.onOverlayDirty?.(!0);return}if(n.altKey&&this.onAltClick){this.onAltClick(a);return}if(this.tradingManager&&o&&this.tradingManager.onPointerDown(a,o)){i(`ns-resize`);return}if(this.drawingManager&&o&&this.drawingManager.onPointerDown(a,o)){this.drawingManager.isDragging()&&i(`grabbing`);return}if(this.alertDragHandler?.tryBegin(a)){this.onOverlayDirty?.();return}this.pressForClick=!0,this.panHandler&&(this.panHandler.onPointerDown(a),i(`grabbing`))},p=e=>{o||d(e.target)&&m(e)},m=t=>{let r=this.getMousePos(t),s=e();if(this.downPos&&!this.downMoved){let e=r.x-this.downPos.x,t=r.y-this.downPos.y;e*e+t*t>16&&(this.downMoved=!0)}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(r);return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(r);return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.move(n(r)),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measureHandlers.move(r),this.onOverlayDirty?.(!0);return}if(this.boxSelecting&&this.boxSelectHandlers){this.boxSelectHandlers.move(r),this.onOverlayDirty?.(!0);return}if(o||i(a(r)),this.tradingManager&&s&&this.tradingManager.onPointerMove(o?n(r):r,s)){this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.();return}if(this.drawingManager&&s&&this.drawingManager.onPointerMove(r,s)){this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(r),this.crosshairHandler?.onPointerMove(r),this.onOverlayDirty?.(!o)},h=e=>{if(!(e.button!==0&&e.type===`mouseup`)&&o){if(u(),i(a(this.getMousePos(e))),this.boxSelecting&&this.boxSelectHandlers){this.boxSelecting=!1,this.boxSelectHandlers.end(),this.onOverlayDirty?.(!0);return}if(this.axisDragHandler?.isActive()){this.axisDragHandler.end();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.end();return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.end(),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measuring=!1,this.measureHandlers.end(),this.onOverlayDirty?.(!0);return}this.tradingManager?.onPointerUp()||this.drawingManager?.onPointerUp()||(this.panHandler?.onPointerUp(),this.pressForClick&&!this.downMoved&&this.downPos&&this.onClick&&this.onClick(this.downPos),this.pressForClick=!1,this.downPos=null)}},g=e=>{let n=t(this.getMousePos(e));n&&this.onAxisDoubleClick&&this.onAxisDoubleClick(n)},_=()=>{if(o){this.crosshairHandler?.onPointerLeave(),this.onOverlayDirty?.(!0);return}i(``),this.panHandler?.onPointerUp(),this.drawingManager?.onPointerUp(),this.tradingManager?.onPointerUp(),this.alertDragHandler?.end(),this.paneResizeHandler?.end(),this.crosshairHandler?.onPointerLeave(),this.pressForClick=!1,this.downPos=null,this.onOverlayDirty?.()},v=e=>{e.preventDefault();let t=this.getMousePos(e);this.zoomHandler?.onWheel(e.deltaY,t)},y=e=>{if(e.key===`Escape`&&this.boxSelecting&&this.boxSelectHandlers&&(this.boxSelecting=!1,this.boxSelectHandlers.cancel(),this.onOverlayDirty?.(!0)),e.key===`Escape`&&this.onEscape&&this.onEscape(),e.key===`Enter`&&this.onConfirm&&this.onConfirm()){e.preventDefault();return}e.key!==`Escape`&&!this.ownsShortcuts()||this.drawingManager?.onKeyDown(e.key,e.ctrlKey||e.metaKey)&&e.preventDefault()},b=t=>{let n=e();!this.tradingManager||!n||this.tradingManager.onContextMenu(this.getMousePos(t),n)&&t.preventDefault()},x=n=>{if(I=this.element,!(!this.touchActive&&!d(n.target)))if(n.preventDefault(),this.invalidateRect(),n.touches.length===1){let r=this.getTouchPos(n.touches[0]);this.touchStartPos=r;let i=t(r);if(i&&this.axisDragHandler){this.axisDragHandler.begin(i,r),this.touchActive=!0;return}if(this.paneResizeHandler?.tryBegin(r)){this.touchActive=!0;return}let a=e();if(this.tradingManager&&a&&this.tradingManager.onPointerDown(r,a)){this.touchActive=!0,this.onOverlayDirty?.();return}this.onAltClick&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null,this.onAltClick?.(r),this.panHandler?.onPointerUp(),this.onOverlayDirty?.(!0)},this.longPressMs)),this.panHandler?.onPointerDown(r),this.crosshairHandler?.onPointerMove(r),this.touchActive=!0}else n.touches.length===2&&(this.clearLongPress(),this.panHandler?.onPointerUp(),this.lastTouchDist=this.getTouchDistance(n.touches[0],n.touches[1]),this.lastTouchMid=this.getTouchMidpoint(n.touches[0],n.touches[1]),this.touchActive=!0)},S=t=>{if(!(!this.touchActive&&!d(t.target))){if(t.preventDefault(),t.touches.length===1&&this.touchActive){let n=this.getTouchPos(t.touches[0]);if(this.longPressTimer){let e=n.x-this.touchStartPos.x,t=n.y-this.touchStartPos.y;Math.hypot(e,t)>this.longPressMaxMove&&this.clearLongPress()}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(n),this.onOverlayDirty?.();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(n),this.onOverlayDirty?.();return}let r=e();if(this.tradingManager&&r&&this.tradingManager.onPointerMove(n,r)){this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(n),this.crosshairHandler?.onPointerMove(n)}else if(t.touches.length===2){let e=this.getTouchDistance(t.touches[0],t.touches[1]),n=this.getTouchMidpoint(t.touches[0],t.touches[1]);if(this.lastTouchDist>0){let t=(e/this.lastTouchDist-1)*.5;this.zoomHandler?.onWheel(-t*100,n)}let r=this.lastTouchMid.x-n.x;Math.abs(r)>1&&(this.panHandler?.onPointerDown(this.lastTouchMid),this.panHandler?.onPointerMove({x:n.x,y:this.lastTouchMid.y})),this.lastTouchDist=e,this.lastTouchMid=n}this.onOverlayDirty?.()}},C=e=>{if(this.clearLongPress(),e.touches.length===0)this.axisDragHandler?.isActive()&&this.axisDragHandler.end(),this.paneResizeHandler?.end(),this.tradingManager?.onPointerUp(),this.panHandler?.onPointerUp(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.lastTouchDist=0;else if(e.touches.length===1){let t=this.getTouchPos(e.touches[0]);this.panHandler?.onPointerDown(t)}},w=()=>this.invalidateRect(),T=()=>this.invalidateRect(),E=()=>this.invalidateRect();this.element.addEventListener(`mousedown`,f),this.element.addEventListener(`mousemove`,p),document.addEventListener(`mouseup`,h),this.element.addEventListener(`mouseleave`,_),this.element.addEventListener(`dblclick`,g),this.element.addEventListener(`wheel`,v,{passive:!1}),this.element.addEventListener(`contextmenu`,b),this.element.addEventListener(`touchstart`,x,{passive:!1}),this.element.addEventListener(`touchmove`,S,{passive:!1}),this.element.addEventListener(`touchend`,C),document.addEventListener(`keydown`,y),window.addEventListener(`resize`,w),document.addEventListener(`scroll`,T,{capture:!0,passive:!0}),this.element.addEventListener(`mouseenter`,E),this.boundHandlers.push(u,()=>this.element.removeEventListener(`mousedown`,f),()=>this.element.removeEventListener(`mousemove`,p),()=>document.removeEventListener(`mouseup`,h),()=>this.element.removeEventListener(`mouseleave`,_),()=>this.element.removeEventListener(`dblclick`,g),()=>this.element.removeEventListener(`wheel`,v),()=>this.element.removeEventListener(`contextmenu`,b),()=>this.element.removeEventListener(`touchstart`,x),()=>this.element.removeEventListener(`touchmove`,S),()=>this.element.removeEventListener(`touchend`,C),()=>document.removeEventListener(`keydown`,y),()=>window.removeEventListener(`resize`,w),()=>document.removeEventListener(`scroll`,T,{capture:!0}),()=>this.element.removeEventListener(`mouseenter`,E))}detach(){Rn.delete(this.element),I===this.element&&(I=null);for(let e of this.boundHandlers)e();this.boundHandlers=[],this.cachedRect=null,this.clearLongPress()}clearLongPress(){this.longPressTimer&&=(clearTimeout(this.longPressTimer),null)}invalidateRect(){this.cachedRect=null}getRect(){return this.cachedRect||=this.element.getBoundingClientRect(),this.cachedRect}ownsShortcuts(){let e=document.activeElement;if(e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||e.isContentEditable))return!1;for(let t of Rn)if(e&&t.contains(e))return t===this.element;return I===null||I===this.element}getMousePos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchPos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchDistance(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}getTouchMidpoint(e,t){let n=this.getRect();return{x:(e.clientX+t.clientX)/2-n.left,y:(e.clientY+t.clientY)/2-n.top}}},Bn=100,Vn=50,Hn=.1,Un=60,Wn=16,Gn=class{dragging=!1;lastX=0;lastY=0;samples=[];momentumId=0;callback;onStart;friction=.92;constructor(e,t){this.callback=e,this.onStart=t}isDragging(){return this.dragging}onPointerDown(e){this.dragging=!0,this.lastX=e.x,this.lastY=e.y,this.samples=[{t:Date.now(),x:e.x,y:e.y}],this.stopMomentum(),this.onStart?.()}onPointerMove(e){if(!this.dragging)return;let t=this.lastX-e.x,n=this.lastY-e.y;this.lastX=e.x,this.lastY=e.y;let r=Date.now();for(this.samples.push({t:r,x:e.x,y:e.y});this.samples.length>2&&r-this.samples[1].t>Bn;)this.samples.shift();(t||n)&&this.callback(t,n)}onPointerUp(){if(!this.dragging)return;this.dragging=!1;let e=this.releaseVelocity(Date.now());this.samples=[],e&&Math.hypot(e.x,e.y)>Hn&&this.startMomentum(e.x,e.y)}cancelMomentum(){this.stopMomentum()}releaseVelocity(e){let t=this.samples[this.samples.length-1];if(!t||e-t.t>Vn)return null;let n=this.samples.find(e=>t.t-e.t<=Bn)??this.samples[0],r=t.t-n.t;return r<=0?null:{x:(n.x-t.x)/r,y:(n.y-t.y)/r}}startMomentum(e,t){this.stopMomentum();let n=e*Wn,r=t*Wn,i=Math.hypot(n,r);i>Un&&(n*=Un/i,r*=Un/i);let a=()=>{if(n*=this.friction,r*=this.friction,Math.hypot(n,r)<.5){this.momentumId=0;return}this.callback(n,r),this.momentumId=requestAnimationFrame(a)};this.momentumId=requestAnimationFrame(a)}stopMomentum(){this.momentumId&&=(cancelAnimationFrame(this.momentumId),0)}},Kn=class{callback;sensitivity;pendingDelta=0;pendingCenterX=0;rafId=0;constructor(e,t=.001){this.callback=e,this.sensitivity=t}onWheel(e,t){this.pendingDelta+=-e*this.sensitivity,this.pendingCenterX=t.x,this.rafId||=requestAnimationFrame(()=>{this.rafId=0;let e=this.pendingDelta,t=this.pendingCenterX;this.pendingDelta=0,this.callback(e,t)})}dispose(){this.rafId&&=(cancelAnimationFrame(this.rafId),0)}},qn=class{dragging=!1;axis=null;startPos={x:0,y:0};lastPos={x:0,y:0};moved=!1;threshold=3;sensitivity=.005;constructor(e,t){this.onPriceScale=e,this.onTimeScale=t}begin(e,t){this.dragging=!0,this.axis=e,this.startPos=t,this.lastPos=t,this.moved=!1}move(e){if(!this.dragging||!this.axis)return!1;let t=e.x-this.startPos.x,n=e.y-this.startPos.y;if(!this.moved&&Math.hypot(t,n)<this.threshold)return!1;if(this.moved=!0,this.axis===`price`){let t=e.y-this.lastPos.y,n=Math.exp(t*this.sensitivity);this.onPriceScale(n)}else{let t=e.x-this.lastPos.x,n=Math.exp(t*this.sensitivity);this.onTimeScale(n)}return this.lastPos=e,!0}end(){let e=this.dragging&&this.moved;return this.dragging=!1,this.axis=null,this.moved=!1,e}isActive(){return this.dragging}},Jn=class{draggingId=null;constructor(e,t){this.alerts=e,this.viewportGetter=t}isOverAlert(e){let t=this.viewportGetter();return t?this.alerts.getAlertAtPoint(e,t)!==null:!1}tryBegin(e){let t=this.viewportGetter();if(!t)return!1;let n=this.alerts.getAlertAtPoint(e,t);return n?(this.draggingId=n.id,!0):!1}move(e){if(this.draggingId===null)return;let t=this.viewportGetter();t&&this.alerts.updateAlertPrice(this.draggingId,u(e.y,t))}end(){this.draggingId=null}isActive(){return this.draggingId!==null}},Yn=class{state=null;layoutGetter=null;onResize=null;constructor(e=4){this.tolerance=e}configure(e,t){this.layoutGetter=e,this.onResize=t}hitTest(e,t){for(let n of t.dividers)if(Xn(e,n.rect,this.tolerance)){let e=t.panels.find(e=>e.config.id===n.panelId);if(e)return{panelId:n.panelId,orientation:n.orientation,position:e.config.position,size:e.config.size}}return null}cursorAt(e){let t=this.layoutGetter?.();if(!t)return null;let n=this.hitTest(e,t);return n?n.orientation===`horizontal`?`ns-resize`:`ew-resize`:null}tryBegin(e){let t=this.layoutGetter?.();if(!t)return!1;let n=this.hitTest(e,t);return n?(this.state={panelId:n.panelId,position:n.position,startSize:n.size,startPos:e},!0):!1}move(e){let t=this.computeSize(e);t&&this.onResize?.(t.panelId,t.size)}computeSize(e){let t=this.state;if(!t)return null;let n=0;switch(t.position){case`bottom`:n=t.startPos.y-e.y;break;case`top`:n=e.y-t.startPos.y;break;case`left`:n=e.x-t.startPos.x;break;case`right`:n=t.startPos.x-e.x;break}return{panelId:t.panelId,size:t.startSize+n}}end(){this.state=null}isActive(){return this.state!==null}};function Xn(e,t,n){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var Zn=class{position=null;callback=null;data=[];tzOffsetMinutes=null;setTimezoneOffset(e){this.tzOffsetMinutes=e}magnetMode=!0;mode=`magnet`;pricePrecision=null;locale=`en-US`;syncedSlot=null;pendingBarIndex=null;pendingPoint=null;callbackScheduled=!1;lastCallbackBarIndex=-1;reportTop=null;reportBottom=null;setCallback(e){this.callback=e}setData(e){this.data=e}setMagnetMode(e){this.magnetMode=e,this.mode=e?`magnet`:`normal`}setMode(e){this.mode=e,this.magnetMode=e===`magnet`}getMode(){return this.mode}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}getPosition(){return this.position}setSyncedSlot(e){this.syncedSlot=e!==null&&Number.isFinite(e)?e:null}getSyncedSlot(){return this.syncedSlot}setReportBounds(e){this.reportTop=e?.top??null,this.reportBottom=e?.bottom??null}onPointerMove(e){this.position=e}onPointerLeave(){this.position=null,this.pendingBarIndex=null,this.pendingPoint=null,this.lastCallbackBarIndex=-1,this.flushCallback(null,null)}render(e,t,n){if(this.mode===`hidden`)return;if(!this.position){this.syncedSlot!==null&&this.renderSynced(e,t,n,this.syncedSlot);return}let{chartRect:r}=t,{x:i,y:o}=this.position;if(i<r.x||i>r.x+r.width)return;let s=r.y+r.height;if(o<Math.min(this.reportTop??r.y,r.y)||o>Math.max(this.reportBottom??s,s))return;let c=o>=r.y&&o<=s,u=l(i,t),d=Math.max(0,Math.min(this.data.length-1,u)),f=u>=0&&u<this.data.length;this.magnetMode&&(i=a(u,t)),d!==this.lastCallbackBarIndex&&(this.pendingBarIndex=d,this.pendingPoint={x:i,y:o},this.lastCallbackBarIndex=d,this.scheduleCallback()),c&&(this.magnetMode&&f&&Qn(e,i,t,n),$n(e,i,r,n),e.setLineDash([4,4]),e.beginPath(),e.moveTo(r.x,Math.round(o)+.5),e.lineTo(r.x+r.width,Math.round(o)+.5),e.stroke(),e.setLineDash([]))}renderAxisLabels(t,n,r,i,o){if(this.mode===`hidden`)return;if(!this.position){this.syncedSlot!==null&&this.renderSyncedTimeLabel(t,n,r,i,this.syncedSlot,o);return}let{chartRect:s}=n,{x:c,y:d}=this.position;if(c<s.x||c>s.x+s.width||d<s.y||d>s.y+s.height)return;let f=l(c,n);this.magnetMode&&(c=a(f,n));let p=`600 ${r.font.sizeSmall}px ${r.font.family}`;er(t,{text:(0,e.formatPrice)(u(d,n),this.pricePrecision??(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max),this.locale),anchorX:s.x+s.width,anchorY:d,orientation:`right`,bg:r.text,fg:r.background,font:p}),this.drawTimePill(t,n,r,i,f,c,o)}renderSynced(e,t,n,r){let i=a(r,t),{chartRect:o}=t;i<o.x||i>o.x+o.width||(this.magnetMode&&r>=0&&r<this.data.length&&Qn(e,i,t,n),$n(e,i,o,n))}renderSyncedTimeLabel(e,t,n,r,i,o){let s=a(i,t),{chartRect:c}=t;s<c.x||s>c.x+c.width||this.drawTimePill(e,t,n,r,i,s,o)}drawTimePill(e,t,n,r,i,a,o){r.length!==0&&er(e,{text:tr(m(i,r),this.tzOffsetMinutes),anchorX:a,anchorY:o??t.chartRect.y+t.chartRect.height,orientation:`bottom`,bg:n.text,fg:n.background,font:`600 ${n.font.sizeSmall}px ${n.font.family}`})}scheduleCallback(){this.callbackScheduled||(this.callbackScheduled=!0,queueMicrotask(()=>{this.callbackScheduled=!1,this.flushCallback(this.pendingBarIndex,this.pendingPoint)}))}flushCallback(e,t){this.callback?.(e,t)}};function Qn(e,t,n,r){let i=n.barWidth+n.barSpacing;e.fillStyle=r.crosshair,e.globalAlpha=.08,e.fillRect(t-i/2,n.chartRect.y,i,n.chartRect.height),e.globalAlpha=1}function $n(e,t,n,r){e.setLineDash([4,4]),e.strokeStyle=r.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(t)+.5,n.y),e.lineTo(Math.round(t)+.5,n.y+n.height),e.stroke(),e.setLineDash([])}function er(e,t){e.save(),e.font=t.font;let n=Math.ceil(e.measureText(t.text).width)+16;if(t.orientation===`right`){let r=t.anchorX+5,i=t.anchorY-20/2;e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(r,t.anchorY-5),e.lineTo(r,i),e.lineTo(r+n,i),e.lineTo(r+n,i+20),e.lineTo(r,i+20),e.lineTo(r,t.anchorY+5),e.closePath(),e.fillStyle=t.bg,e.fill(),e.fillStyle=t.fg,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(t.text,r+8,t.anchorY)}else{let r=t.anchorX-n/2,i=t.anchorY+5;e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(t.anchorX+5,i),e.lineTo(r+n,i),e.lineTo(r+n,i+20),e.lineTo(r,i+20),e.lineTo(r,i),e.lineTo(t.anchorX-5,i),e.closePath(),e.fillStyle=t.bg,e.fill(),e.fillStyle=t.fg,e.textBaseline=`middle`,e.textAlign=`center`,e.fillText(t.text,t.anchorX,i+20/2)}e.restore()}function tr(t,n){let r=(0,e.timeParts)(t>0xe8d4a51000?t:t*1e3,n),{year:i,month:a,day:o,hours:s,minutes:c}=r;return(0,e.isDateOnly)(r)?`${a}/${o}/${i}`:`${a}/${o} ${s<10?`0`+s:s}:${c<10?`0`+c:c}`}var nr=class{callbacks;enabled=!0;constructor(e){this.callbacks=e}setEnabled(e){this.enabled=e}handleKey(e){if(!this.enabled)return!1;let t=e.shiftKey?10:1;switch(e.key){case`ArrowLeft`:return this.callbacks.scrollBars(-t),!0;case`ArrowRight`:return this.callbacks.scrollBars(t),!0;case`ArrowUp`:case`+`:case`=`:return this.callbacks.zoom(.1),!0;case`ArrowDown`:case`-`:return this.callbacks.zoom(-.1),!0;case`Home`:return this.callbacks.goToStart(),!0;case`End`:return this.callbacks.goToEnd(),!0;case` `:return this.callbacks.fitContent(),!0;default:return!1}}},rr=16,ir=80,ar=864e5,or=new Map;function sr(e,t,n,r){let i=t!==null,a=`${n}|${r?`y`:``}|${i?`utc`:`local`}`,o=or.get(a);if(!o){let e={month:`short`,day:`numeric`,...r?{year:`numeric`}:{},...i?{timeZone:`UTC`}:{}};try{o=new Intl.DateTimeFormat(n,e)}catch{o=new Intl.DateTimeFormat(`en-US`,e)}or.set(a,o)}return o.format(new Date(i?e+t*6e4:e))}var cr=e=>e<10?`0${e}`:`${e}`;function lr(t,n,r,i=`en-US`){let a=(0,e.normalizeBarTime)(t),o=(0,e.timeParts)(a,n);if(r!==void 0&&r>0?r>=ar:(0,e.isDateOnly)(o))return sr(a,n,i,!0);let s=sr(a,n,i,!1),c=`${cr(o.hours)}:${cr(o.minutes)}`;return r!==void 0&&r>0&&r<6e4?`${s} · ${c}:${cr(new Date(a).getUTCSeconds())}`:`${s} · ${c}`}function ur(t,n){return Number.isFinite(t)?t>=1e9?`${(0,e.formatPrice)(t/1e9,2,n)}B`:t>=1e6?`${(0,e.formatPrice)(t/1e6,2,n)}M`:t>=1e3?`${(0,e.formatPrice)(t/1e3,1,n)}K`:(0,e.formatPrice)(t,t%1==0?0:2,n):`—`}var dr=class{el=null;visible=!1;appliedTheme=null;locale=`en-US`;pricePrecision=null;tzOffsetMinutes=null;dirEl;timeEl;changeEl;valueEls;labelEls=[];dividerEl;width=176;height=112;create(e){if(this.el)return;let t=document.createElement(`div`);t.setAttribute(`aria-hidden`,`true`),Object.assign(t.style,{position:`absolute`,left:`0`,top:`0`,display:`none`,minWidth:`168px`,padding:`8px 10px 9px`,borderRadius:`8px`,fontSize:`11.5px`,lineHeight:`1.45`,fontVariantNumeric:`tabular-nums`,pointerEvents:`none`,zIndex:`100`,whiteSpace:`nowrap`,willChange:`transform`,contain:`layout paint`,backdropFilter:`blur(10px)`});let n=L({display:`flex`,alignItems:`center`,gap:`7px`,marginBottom:`6px`});this.dirEl=L({width:`3px`,height:`12px`,borderRadius:`2px`,flex:`none`}),this.timeEl=L({flex:`1`,fontSize:`11px`,letterSpacing:`0.01em`}),this.changeEl=L({padding:`1px 6px`,borderRadius:`999px`,fontSize:`10.5px`,fontWeight:`600`}),n.append(this.dirEl,this.timeEl,this.changeEl);let r=L({display:`grid`,gridTemplateColumns:`auto 1fr auto 1fr`,columnGap:`8px`,rowGap:`1px`,alignItems:`baseline`}),i=e=>{let t=L({fontSize:`10px`,letterSpacing:`0.04em`});t.textContent=e,this.labelEls.push(t);let n=L({textAlign:`right`,fontWeight:`500`});return r.append(t,n),n},a=i(`O`),o=i(`H`),s=i(`L`),c=i(`C`);this.dividerEl=L({height:`1px`,margin:`6px 0 5px`});let l=L({display:`flex`,justifyContent:`space-between`,gap:`12px`}),u=L({fontSize:`10px`,letterSpacing:`0.04em`});u.textContent=`VOL`,this.labelEls.push(u);let d=L({fontWeight:`500`});l.append(u,d),this.valueEls={open:a,high:o,low:s,close:c,volume:d},t.append(n,r,this.dividerEl,l),e.appendChild(t),this.el=t}setLocale(e){this.locale=e}setPricePrecision(e){this.pricePrecision=e}setTimezoneOffset(e){this.tzOffsetMinutes=e}show(t,n,r,i,a={}){let o=this.el;if(!o)return;this.appliedTheme!==r&&this.applyTheme(r);let s=this.pricePrecision??(a.priceRange?(0,e.autoPricePrecision)(a.priceRange.min,a.priceRange.max):(0,e.autoPricePrecision)(n.low,n.high)),c=t=>(0,e.formatPrice)(t,s,this.locale),l=a.prevClose??n.open,u=n.close-l,d=l===0?0:u/l*100,f=u>=0,p=f?r.candleUp:r.candleDown,m=f?`+`:`−`;this.timeEl.textContent=lr(n.time,this.tzOffsetMinutes,a.barStepMs,this.locale),this.changeEl.textContent=`${m}${(0,e.formatPrice)(Math.abs(d),2,this.locale)}%`,this.changeEl.style.color=p,this.changeEl.style.background=mr(p,.14),this.dirEl.style.background=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.open.textContent=c(n.open),this.valueEls.high.textContent=c(n.high),this.valueEls.low.textContent=c(n.low),this.valueEls.close.textContent=c(n.close),this.valueEls.close.style.color=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.volume.textContent=ur(n.volume,this.locale),this.visible||=(o.style.display=`block`,!0),this.width=o.offsetWidth||this.width,this.height=o.offsetHeight||this.height;let h=a.plot??{x:0,y:0,width:i.width-ir,height:i.height},g=h.x+h.width,_=h.y+h.height,v=t.x+rr,y=t.y-this.height/2;v+this.width>g-4&&(v=t.x-this.width-rr),v<h.x+4&&(v=h.x+4),y+this.height>_-4&&(y=_-this.height-4),y<h.y+4&&(y=h.y+4),o.style.transform=`translate(${Math.round(v)}px, ${Math.round(y)}px)`}hide(){this.el&&this.visible&&(this.el.style.display=`none`,this.visible=!1)}isVisible(){return this.visible}destroy(){this.el?.remove(),this.el=null,this.visible=!1,this.appliedTheme=null,this.labelEls=[]}applyTheme(e){let t=this.el,n=fr(e.background);t.style.background=mr(e.background,n?.9:.94),t.style.border=`1px solid ${e.axisLine}`,t.style.boxShadow=n?`0 12px 32px -8px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35)`:`0 12px 32px -10px rgba(15, 19, 26, 0.22), 0 2px 6px rgba(15, 19, 26, 0.08)`,t.style.color=e.text,t.style.fontFamily=e.font.family,this.timeEl.style.color=e.textSecondary;for(let t of this.labelEls)t.style.color=e.textSecondary;this.dividerEl.style.background=e.axisLine,this.appliedTheme=e}};function L(e){let t=document.createElement(`div`);return Object.assign(t.style,e),t}function fr(e){let t=pr(e);return t?(.299*t[0]+.587*t[1]+.114*t[2])/255<.5:!0}function pr(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6);return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function mr(e,t){let n=pr(e);return n?`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var hr=class{el=null;deltaEl=null;timeEl=null;ohlcEl=null;pinnedBar=null;pinnedIndex=-1;create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`4px`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`auto`,cursor:`pointer`,zIndex:`99`,whiteSpace:`nowrap`,willChange:`transform`}),this.timeEl=document.createElement(`div`),this.ohlcEl=document.createElement(`div`),this.deltaEl=document.createElement(`div`),this.deltaEl.style.marginTop=`4px`,this.deltaEl.style.paddingTop=`4px`,this.deltaEl.style.borderTop=`1px solid currentColor`,this.deltaEl.style.opacity=`0.85`,this.deltaEl.style.fontVariantNumeric=`tabular-nums`,this.el.appendChild(this.timeEl),this.el.appendChild(this.ohlcEl),this.el.appendChild(this.deltaEl);let t=document.createElement(`div`);t.textContent=`📌 pinned`,t.style.fontSize=`9px`,t.style.opacity=`0.6`,t.style.marginBottom=`2px`,t.style.letterSpacing=`0.04em`,t.style.textTransform=`uppercase`,this.el.insertBefore(t,this.timeEl),e.appendChild(this.el)}pin(e,t,n){if(!this.el||!this.timeEl||!this.ohlcEl)return;this.pinnedBar=e,this.pinnedIndex=t;let r=e.close>=e.open?n.candleUp:n.candleDown,i=new Date(e.time>0xe8d4a51000?e.time:e.time*1e3);this.timeEl.textContent=`${i.getMonth()+1}/${i.getDate()} ${gr(i.getHours())}:${gr(i.getMinutes())}`,this.timeEl.style.color=n.textSecondary,this.ohlcEl.innerHTML=`
|
|
2
|
-
<span style="opacity:.6">O </span><span style="color:${
|
|
3
|
-
<span style="opacity:.6"> H </span><span style="color:${
|
|
4
|
-
<span style="opacity:.6"> L </span><span style="color:${
|
|
5
|
-
<span style="opacity:.6"> C </span><span style="color:${
|
|
6
|
-
`;let a=_r(n.background);this.el.style.background=vr(n.background,a?.96:.97),this.el.style.border=`1px solid ${r}`,this.el.style.boxShadow=a?`0 4px 12px rgba(0,0,0,0.55)`:`0 4px 12px rgba(0,0,0,0.18)`,this.el.style.color=n.text,this.el.style.backdropFilter=`blur(8px)`,this.el.style.display=`block`}unpin(){this.pinnedBar=null,this.pinnedIndex=-1,this.el&&(this.el.style.display=`none`)}isPinned(){return this.pinnedBar!==null}getPinnedIndex(){return this.pinnedIndex}reposition(e,t,n,r){if(!this.el||!this.pinnedBar)return;let i=a(this.pinnedIndex,e),s=o(this.pinnedBar.close,e),c=e.chartRect,l=i>=c.x-4&&i<=c.x+c.width+4;this.el.style.opacity=l?`1`:`0.35`;let u=Math.max(c.x,Math.min(c.x+c.width-180,i+8)),d=Math.max(c.y,Math.min(c.y+c.height-90,s-64));if(this.el.style.transform=`translate(${Math.round(u)}px, ${Math.round(d)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.deltaEl)if(t&&n!==null&&n!==this.pinnedIndex){let e=t.close-this.pinnedBar.close,i=this.pinnedBar.close===0?0:e/this.pinnedBar.close*100,a=e>0?`+`:e<0?`−`:``,o=n-this.pinnedIndex,s=e>=0?r.candleUp:r.candleDown;this.deltaEl.style.color=s,this.deltaEl.innerHTML=`Δ ${a}${R(Math.abs(e))} <span style="opacity:.7">(${a}${Math.abs(i).toFixed(2)}%)</span> · ${o>0?`+`:``}${o} bars`,this.deltaEl.style.display=`block`}else this.deltaEl.style.display=`none`}destroy(){this.el?.remove(),this.el=null,this.deltaEl=null,this.timeEl=null,this.ohlcEl=null,this.pinnedBar=null,this.pinnedIndex=-1}};function R(e){return e.toFixed(2)}function gr(e){return e<10?`0`+e:``+e}function _r(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}return!0}function vr(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var yr=class{listeners=new Map;tauriBridge=null;on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n={type:e,timestamp:Date.now(),payload:t},r=this.listeners.get(e);if(r)for(let e of r)e(n);if(this.tauriBridge?.enabled&&window.__TAURI__){let t=this.tauriBridge.eventPrefix??`tc-chart`;window.__TAURI__.event.emit(`${t}:${e}`,n).catch(()=>{})}}enableTauriBridge(e){this.tauriBridge=e}disableTauriBridge(){this.tauriBridge=null}destroy(){this.listeners.clear(),this.tauriBridge=null}},z=class{hitTestAnchor(e,t,n,r){for(let i=0;i<t.anchors.length;i++){let a=this.anchorToPixel(t.anchors[i],n);if(Math.hypot(e.x-a.x,e.y-a.y)<=r)return i}return-1}anchorToPixel(e,t){return{x:_(e.time,t),y:o(e.price,t)}}pixelToAnchor(e,t){return{time:v(e.x,t),price:u(e.y,t)}}applyLineStyle(e,t){switch(e.strokeStyle=t.color,e.lineWidth=t.lineWidth,t.lineStyle){case`dashed`:e.setLineDash([6,4]);break;case`dotted`:e.setLineDash([2,2]);break;default:e.setLineDash([]);break}}resetLineStyle(e){e.setLineDash([])}renderAnchorHandles(e,t,n){e.fillStyle=`#FFFFFF`,e.strokeStyle=t.style.color,e.lineWidth=1;for(let r of t.anchors){let t=this.anchorToPixel(r,n);e.fillRect(t.x-4,t.y-4,8,8),e.strokeRect(t.x-4,t.y-4,8,8)}}distanceToLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;o=Math.max(0,Math.min(1,o));let s=t.x+o*r,c=t.y+o*i;return Math.hypot(e.x-s,e.y-c)}distanceToInfiniteLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.hypot(r,i);return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(r*(t.y-e.y)-i*(t.x-e.x))/a}},br=1,B={drawings:[],pastes:0};function V(e){return{...e,anchors:e.anchors.map(e=>({...e})),style:{...e.style},meta:e.meta?{...e.meta}:void 0}}var xr=3;function Sr(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].time!==t[n].time||e[n].price!==t[n].price)return!1;return!0}var Cr=class{registry=new Map;drawings=[];state=`idle`;activeTool=null;activeStyle={color:`#4c8dff`,lineWidth:1,lineStyle:`solid`,fillColor:`rgba(76, 141, 255, 0.1)`,fillOpacity:.1,fontSize:12};creatingDrawing=null;committedAnchors=0;previewAnchor=null;selectedDrawingId=null;groupIds=new Set;groupDrag=[];dragAnchorIndex=-1;dragStartPoint=null;dragStartAnchors=[];dragBeforeState=null;eventCallback=null;requestRender=null;undoRedo=null;magnetMode=`none`;dataGetter=null;displayDataGetter=null;stayInDrawingMode=!1;toolAllowed=()=>!0;register(e){this.registry.set(e.descriptor.type,e)}setEventCallback(e){this.eventCallback=e}setRequestRender(e){this.requestRender=e}setUndoRedoManager(e){this.undoRedo=e}setMagnetMode(e){this.magnetMode=e}getMagnetMode(){return this.magnetMode}setDataGetter(e){this.dataGetter=e}setDisplayDataGetter(e){this.displayDataGetter=e}snapToOHLC(e,t,n){if(this.magnetMode===`none`||!this.dataGetter)return{time:e,price:t};let r=this.displayDataGetter?.()??this.dataGetter();if(r.length===0)return{time:e,price:t};let i=!!(n?.data&&n.data.length>0),a=Math.round(i?h(e,r):e);if(a<0||a>r.length-1)return{time:e,price:t};let o=a,s=r[o],c=[s.open,s.high,s.low,s.close],l=c[0],u=Math.abs(t-l);for(let e=1;e<c.length;e++){let n=Math.abs(t-c[e]);n<u&&(u=n,l=c[e])}if(n){let e=n.chartRect.height/(n.priceRange.max-n.priceRange.min||1);if(u*e>30)return{time:i?s.time:o,price:t}}return{time:i?s.time:o,price:l}}undo(){if(!this.undoRedo)return!1;let e=this.undoRedo.undo();return e?(this.applyUndoAction(e),!0):!1}redo(){if(!this.undoRedo)return!1;let e=this.undoRedo.redo();return e?(this.applyRedoAction(e),!0):!1}applyUndoAction(e){this.undoOne(e),this.settleAfterHistory()}settleAfterHistory(){this.clearSelection(),this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null,this.state=this.activeTool?`creating`:`idle`,this.requestRender?.()}undoOne(e){switch(e.type){case`drawingBatch`:for(let t of[...e.actions??[]].reverse())this.undoOne(t);break;case`drawingCreate`:e.after&&(this.drawings=this.drawings.filter(t=>t.id!==e.after.id));break;case`drawingRemove`:e.before&&this.drawings.push(e.before);break;case`drawingModify`:if(e.before){let t=this.drawings.findIndex(t=>t.id===e.before.id);t>=0&&(this.drawings[t]=structuredClone(e.before))}break}}applyRedoAction(e){this.redoOne(e),this.settleAfterHistory()}redoOne(e){switch(e.type){case`drawingBatch`:for(let t of e.actions??[])this.redoOne(t);break;case`drawingCreate`:e.after&&this.drawings.push(structuredClone(e.after));break;case`drawingRemove`:e.before&&(this.drawings=this.drawings.filter(t=>t.id!==e.before.id));break;case`drawingModify`:if(e.after){let t=this.drawings.findIndex(t=>t.id===e.after.id);t>=0&&(this.drawings[t]=structuredClone(e.after))}break}}batchUndo(e){let t=this.undoRedo;if(!t){e();return}let n=[];this.undoRedo={push:e=>{n.push(e)}};try{e()}finally{this.undoRedo=t}n.length===1?t.push(n[0]):n.length>1&&t.push({type:`drawingBatch`,before:null,after:null,actions:n})}isSelectedId(e){return e===this.selectedDrawingId||this.groupIds.has(e)}clearSelection(){this.selectedDrawingId=null,this.groupIds.clear()}addToSelection(e){this.selectedDrawingId?e!==this.selectedDrawingId&&this.groupIds.add(e):this.selectedDrawingId=e,this.state=`selected`}getSelectedDrawingIds(){return this.selectedDrawingId?[this.selectedDrawingId,...this.groupIds]:[]}selectInRect(e,t){if(this.state===`creating`)return 0;this.clearSelection(),this.state=`idle`;let n=Math.min(e.x0,e.x1),r=Math.max(e.x0,e.x1),i=Math.min(e.y0,e.y1),a=Math.max(e.y0,e.y1);for(let e of this.drawings)e.visible&&e.anchors.some(e=>{let s=_(e.time,t),c=o(e.price,t);return s>=n&&s<=r&&c>=i&&c<=a})&&this.addToSelection(e.id);return this.requestRender?.(),this.getSelectedDrawingIds().length}toggleSelectionAt(e,t){if(this.state===`creating`)return!1;for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(r.visible&&this.registry.get(r.type)?.hitTest(e,r,t,8)){if(!this.isSelectedId(r.id))this.addToSelection(r.id);else if(r.id===this.selectedDrawingId){let e=this.groupIds.values().next();this.selectedDrawingId=e.done?null:e.value,e.done||this.groupIds.delete(e.value)}else this.groupIds.delete(r.id);return this.selectedDrawingId||(this.state=`idle`),this.requestRender?.(),!0}}return!1}beginMove(e,t){this.state=`moving`,this.dragStartPoint=e,this.dragStartAnchors=t.anchors.map(e=>({...e})),this.dragBeforeState=V(t),this.groupDrag=[];for(let e of this.getSelectedDrawingIds()){if(e===t.id)continue;let n=this.drawings.find(t=>t.id===e);n&&!n.locked&&this.groupDrag.push({id:e,anchors:n.anchors.map(e=>({...e})),before:V(n)})}}lockAllDrawings(){for(let e of this.drawings)e.locked=!0;this.requestRender?.()}unlockAllDrawings(){for(let e of this.drawings)e.locked=!1;this.requestRender?.()}hideAllDrawings(){for(let e of this.drawings)e.visible=!1;this.clearSelection(),this.state=`idle`,this.requestRender?.()}showAllDrawings(){for(let e of this.drawings)e.visible=!0;this.requestRender?.()}setDrawingVisible(e,t){let n=this.drawings.find(t=>t.id===e);return n?(n.visible=t,!t&&this.isSelectedId(e)&&this.clearSelection(),this.requestRender?.(),t):null}setDrawingLocked(e,t){let n=this.drawings.find(t=>t.id===e);return n?(n.locked=t,this.requestRender?.(),t):null}setActiveTool(e){let t=e!==this.activeTool;this.activeTool=e,this.state=e?`creating`:`idle`,this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null,t&&this.eventCallback?.(`drawingToolChange`,{tool:e})}setStayInDrawingMode(e){this.stayInDrawingMode=e}isStayInDrawingMode(){return this.stayInDrawingMode}setToolFilter(e){this.toolAllowed=e}copySelection(){let e=this.getSelectedDrawingIds().map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0);return e.length===0?0:(B.drawings=e.map(e=>structuredClone(e)),B.pastes=0,e.length)}paste(){if(B.drawings.length===0||this.state===`creating`)return[];let e=B.drawings.every(e=>this.drawings.some(t=>t.id===e.id));B.pastes+=1;let t=e?this.computeBarOffsetTime(3*B.pastes):0,n=[];if(this.batchUndo(()=>{for(let e of B.drawings)!this.registry.has(e.type)||!this.toolAllowed(e.type)||n.push(this.addDrawing({type:e.type,anchors:e.anchors.map(e=>({...e,time:e.time+t})),style:{...e.style},meta:e.meta?structuredClone(e.meta):void 0}))}),n.length===0)return n;this.clearSelection();for(let e of n)this.addToSelection(e);return this.requestRender?.(),n}getActiveTool(){return this.activeTool}setStyle(e){Object.assign(this.activeStyle,e)}getActiveStyle(){return{...this.activeStyle}}setSelectedDrawingStyle(e,t){let n=t?[t]:this.getSelectedDrawingIds(),r=!1;return this.batchUndo(()=>{for(let t of n){let n=this.drawings.find(e=>e.id===t);if(!n||n.locked)continue;let i=V(n);n.style={...n.style,...e},this.undoRedo?.push({type:`drawingModify`,before:i,after:V(n)}),r=!0}}),r&&this.requestRender?.(),r}onPointerDown(e,t){return this.state===`creating`&&this.activeTool?this.handleCreationClick(e,t):this.state===`idle`||this.state===`selected`?this.handleSelectionClick(e,t):!1}onPointerMove(e,t){if(this.state===`creating`&&this.creatingDrawing){let n=this.registry.get(this.creatingDrawing.type);if(n&&this.committedAnchors<n.descriptor.requiredAnchors){let n=v(e.x,t),r=u(e.y,t);return this.previewAnchor=this.snapToOHLC(n,r,t),this.requestRender?.(),!0}}return this.state===`moving`&&this.selectedDrawingId&&this.dragStartPoint?this.handleMove(e,t):this.state===`resizing`&&this.selectedDrawingId&&this.dragAnchorIndex>=0?this.handleResize(e,t):!1}onPointerUp(){if(this.state===`moving`||this.state===`resizing`){let e=[...this.dragBeforeState&&this.selectedDrawingId?[{id:this.selectedDrawingId,before:this.dragBeforeState}]:[],...this.groupDrag.map(e=>({id:e.id,before:e.before}))];return this.batchUndo(()=>{for(let{id:t,before:n}of e){let e=this.drawings.find(e=>e.id===t);e&&!Sr(e.anchors,n.anchors)&&this.undoRedo?.push({type:`drawingModify`,before:n,after:V(e)})}}),this.groupDrag=[],this.state=`selected`,this.dragStartPoint=null,this.dragStartAnchors=[],this.dragAnchorIndex=-1,this.dragBeforeState=null,!0}return!1}onKeyDown(e,t=!1){if(t&&(e===`c`||e===`C`))return this.state===`selected`&&this.copySelection()>0;if(t&&(e===`v`||e===`V`))return this.paste().length>0;if(t&&(e===`d`||e===`D`)&&this.state===`selected`&&this.selectedDrawingId&&this.duplicateDrawing(this.selectedDrawingId)||t&&(e===`z`||e===`Z`)&&this.undo()||t&&(e===`y`||e===`Y`)&&this.redo())return!0;if(e===`Escape`){if(this.state===`creating`)return this.setActiveTool(null),this.requestRender?.(),!0;if(this.state===`selected`)return this.clearSelection(),this.state=`idle`,this.requestRender?.(),!0}if((e===`Delete`||e===`Backspace`)&&this.state===`selected`&&this.selectedDrawingId){let e=this.getSelectedDrawingIds().filter(e=>!this.drawings.find(t=>t.id===e)?.locked);return e.length===0?!1:(this.batchUndo(()=>{for(let t of e)this.removeDrawing(t)}),this.clearSelection(),this.state=`idle`,this.requestRender?.(),!0)}return!1}getDrawings(){return this.drawings}setDrawings(e){this.drawings=this.upgradeLegacyAnchors(e),this.requestRender?.()}addDrawing(e){let t=e.id??`tc_drawing_${br++}`,n={id:t,type:e.type,anchors:e.anchors.map(e=>({...e})),style:{...this.activeStyle,...e.style},visible:e.visible??!0,locked:e.locked??!1,meta:e.meta};return this.drawings=[...this.drawings,n],this.undoRedo?.push({type:`drawingCreate`,before:null,after:V(n)}),this.eventCallback?.(`drawingCreate`,{id:t,type:n.type}),this.requestRender?.(),t}upgradeLegacyAnchors(e){let t=this.dataGetter?.();return!t||t.length===0?e:e.map(e=>({...e,anchors:e.anchors.map(e=>{if(e.time>=1e9)return e;let n=Math.max(0,Math.min(t.length-1,Math.round(e.time)));return{...e,time:t[n].time}})}))}removeDrawing(e){let t=this.drawings.find(t=>t.id===e);this.drawings=this.drawings.filter(t=>t.id!==e),t&&this.undoRedo?.push({type:`drawingRemove`,before:structuredClone(t),after:null}),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}duplicateDrawing(e){let t=this.drawings.find(t=>t.id===e);if(!t)return null;let n=structuredClone(t);n.id=`tc_drawing_${br++}`;let r=this.computeBarOffsetTime(3);return n.anchors=n.anchors.map(e=>({...e,time:e.time+r})),n.locked=!1,this.drawings.push(n),this.undoRedo?.push({type:`drawingCreate`,before:null,after:structuredClone(n)}),this.selectedDrawingId=n.id,this.state=`selected`,this.eventCallback?.(`drawingCreate`,{drawing:n}),this.requestRender?.(),n.id}clearDrawings(){this.drawings=[],this.clearSelection(),this.state=`idle`,this.requestRender?.()}getSelectedDrawingId(){return this.selectedDrawingId}render(e,t){e.save(),e.beginPath(),e.rect(t.chartRect.x,t.chartRect.y,t.chartRect.width,t.chartRect.height),e.clip();for(let n of this.drawings){if(!n.visible)continue;let r=this.registry.get(n.type);if(!r)continue;let i=this.isSelectedId(n.id);r.render(e,n,t,i)}if(this.creatingDrawing&&this.committedAnchors>0){let n=this.registry.get(this.creatingDrawing.type);if(n){let r={...this.creatingDrawing,anchors:this.previewAnchor?[...this.creatingDrawing.anchors,this.previewAnchor]:[...this.creatingDrawing.anchors]};n.render(e,r,t,!1)}}e.restore()}computeBarOffsetTime(e){let t=this.dataGetter?.();if(!t||t.length<2)return e;let n=Math.max(0,t.length-20),r=[];for(let e=n+1;e<t.length;e++)r.push(t[e].time-t[e-1].time);return r.length===0?e:(r.sort((e,t)=>e-t),e*r[Math.floor(r.length/2)])}handleCreationClick(e,t){if(!this.activeTool)return!1;let n=this.registry.get(this.activeTool);if(!n)return!1;let r=v(e.x,t),i=u(e.y,t),a=this.snapToOHLC(r,i,t);return this.creatingDrawing?(this.creatingDrawing.anchors.push(a),this.committedAnchors++,this.previewAnchor=null,this.committedAnchors>=n.descriptor.requiredAnchors&&this.finalizeCreation(),this.requestRender?.(),!0):(this.creatingDrawing={id:`tc_drawing_${br++}`,type:this.activeTool,anchors:[a],style:{...this.activeStyle},visible:!0,locked:!1},this.committedAnchors=1,this.previewAnchor=null,n.descriptor.requiredAnchors===1&&this.finalizeCreation(),this.requestRender?.(),!0)}finalizeCreation(){if(this.creatingDrawing){if(this.drawings.push(this.creatingDrawing),this.selectedDrawingId=this.creatingDrawing.id,this.undoRedo?.push({type:`drawingCreate`,before:null,after:structuredClone(this.creatingDrawing)}),this.eventCallback?.(`drawingCreate`,{drawing:this.creatingDrawing}),this.creatingDrawing=null,this.committedAnchors=0,this.previewAnchor=null,this.stayInDrawingMode&&this.activeTool){this.clearSelection(),this.state=`creating`;return}this.activeTool=null,this.state=`selected`,this.eventCallback?.(`drawingToolChange`,{tool:null})}}isDragging(){return this.state===`moving`||this.state===`resizing`}hoverCursorAt(e,t){if(this.activeTool||this.state===`creating`)return null;if(this.selectedDrawingId){let n=this.drawings.find(e=>e.id===this.selectedDrawingId),r=n&&!n.locked?this.registry.get(n.type):void 0;if(n&&r&&r.hitTestAnchor(e,n,t,8)>=0)return`move`}for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!(!r.visible||r.locked)&&this.registry.get(r.type)?.hitTest(e,r,t,8))return`pointer`}return null}handleSelectionClick(e,t){if(this.selectedDrawingId){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);if(n&&!n.locked){let r=this.registry.get(n.type);if(r){let i=r.hitTestAnchor(e,n,t,8);if(i>=0)return this.state=`resizing`,this.dragAnchorIndex=i,this.dragStartPoint=e,this.dragBeforeState=V(n),!0;if(r.hitTest(e,n,t,8))return this.beginMove(e,n),!0}}}for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!r.visible)continue;let i=this.registry.get(r.type);if(i&&i.hitTest(e,r,t,8))return this.isSelectedId(r.id)?(this.selectedDrawingId&&this.selectedDrawingId!==r.id&&this.groupIds.add(this.selectedDrawingId),this.groupIds.delete(r.id),this.selectedDrawingId=r.id):(this.clearSelection(),this.selectedDrawingId=r.id),this.requestRender?.(),r.locked?(this.state=`selected`,!1):(this.beginMove(e,r),!0)}return this.selectedDrawingId&&(this.clearSelection(),this.state=`idle`,this.requestRender?.()),!1}handleMove(e,t){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);if(!n||!this.dragStartPoint)return!1;if(Math.hypot(e.x-this.dragStartPoint.x,e.y-this.dragStartPoint.y)<xr&&n.anchors.every((e,t)=>e.time===this.dragStartAnchors[t]?.time&&e.price===this.dragStartAnchors[t]?.price))return!0;let r=v(e.x,t)-v(this.dragStartPoint.x,t),i=u(e.y,t)-u(this.dragStartPoint.y,t);n.anchors=this.dragStartAnchors.map(e=>({time:e.time+r,price:e.price+i}));for(let e of this.groupDrag){let t=this.drawings.find(t=>t.id===e.id);t&&(t.anchors=e.anchors.map(e=>({time:e.time+r,price:e.price+i})))}return this.requestRender?.(),!0}handleResize(e,t){let n=this.drawings.find(e=>e.id===this.selectedDrawingId);return!n||this.dragAnchorIndex<0?!1:(n.anchors[this.dragAnchorIndex]={time:v(e.x,t),price:u(e.y,t)},this.requestRender?.(),!0)}},wr=class{constructor(e){this.manager=e}render(e,t){this.manager.render(e,t)}};function Tr(e,t,n){let r=Math.max(0,t),i=Math.min(e.length-1,n);if(i<=r)return null;let a=r,o=r;for(let t=r;t<=i;t++)e[t].high>e[a].high&&(a=t),e[t].low<e[o].low&&(o=t);if(a===o)return null;let s={time:e[a].time,price:e[a].high},c={time:e[o].time,price:e[o].low};return a<o?[s,c]:[c,s]}var Er=class extends z{descriptor={type:`trendLine`,name:`Trend Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},Dr=class extends z{descriptor={type:`horizontalLine`,name:`Horizontal Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=o(t.anchors[0].price,n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(a.x,i),e.lineTo(a.x+a.width,i),e.stroke(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`11px sans-serif`,e.textBaseline=`bottom`,e.fillText(t.anchors[0].price.toFixed(2),a.x+4,i-3),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=o(t.anchors[0].price,n);return Math.abs(e.y-i)<=r&&e.x>=n.chartRect.x&&e.x<=n.chartRect.x+n.chartRect.width}},Or=class extends z{descriptor={type:`horizontalRay`,name:`Horizontal Ray`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=i.y,{chartRect:o}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,a),e.lineTo(o.x+o.width,a),e.stroke(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`11px sans-serif`,e.textBaseline=`bottom`,e.fillText(t.anchors[0].price.toFixed(2),i.x+4,a-3),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return Math.abs(e.y-i.y)<=r&&e.x>=i.x-r&&e.x<=n.chartRect.x+n.chartRect.width}},kr=class extends z{descriptor={type:`verticalLine`,name:`Vertical Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,a.y),e.lineTo(i.x,a.y+a.height),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;return Math.abs(e.x-i.x)<=r&&e.y>=a.y&&e.y<=a.y+a.height}},Ar=class extends z{descriptor={type:`ray`,name:`Ray`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x+s/l*u,f=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(d,f),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;return((e.x-i.x)*o+(e.y-i.y)*s)/(o*o+s*s)<0?!1:this.distanceToInfiniteLine(e,i,a)<=r}},jr=class extends z{descriptor={type:`extendedLine`,name:`Extended Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x-s/l*u,f=i.y-c/l*u,p=i.x+s/l*u,m=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToInfiniteLine(e,i,a)<=r}},Mr=class extends z{descriptor={type:`parallelChannel`,name:`Parallel Channel`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),t.anchors.length>=3){let r=this.anchorToPixel(t.anchors[2],n),o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s)||1,l=-s/c,u=o/c,d=(r.x-i.x)*l+(r.y-i.y)*u,f={x:i.x+l*d,y:i.y+u*d},p={x:a.x+l*d,y:a.y+u*d};e.beginPath(),e.moveTo(f.x,f.y),e.lineTo(p.x,p.y),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.lineTo(p.x,p.y),e.lineTo(f.x,f.y),e.closePath(),e.fill())}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(this.distanceToLine(e,i,a)<=r)return!0;if(t.anchors.length>=3){let o=this.anchorToPixel(t.anchors[2],n),s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c)||1,u=-c/l,d=s/l,f=(o.x-i.x)*u+(o.y-i.y)*d,p={x:i.x+u*f,y:i.y+d*f},m={x:a.x+u*f,y:a.y+d*f};if(this.distanceToLine(e,p,m)<=r)return!0}return!1}},Nr=class extends z{descriptor={type:`regressionChannel`,name:`Regression Channel`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s);if(c===0){this.resetLineStyle(e);return}let l=Math.max(10,Math.min(c*.2,100)),u=-s/c*l,d=o/c*l;e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.stroke(),e.beginPath(),e.moveTo(i.x-u,i.y-d),e.lineTo(a.x-u,a.y-d),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.lineTo(a.x-u,a.y-d),e.lineTo(i.x-u,i.y-d),e.closePath(),e.fill()),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.hypot(a.x-i.x,a.y-i.y),s=Math.max(10,Math.min(o*.2,100));return this.distanceToLine(e,i,a)<=r+s}},H=[0,.236,.382,.5,.618,.786,1],Pr=class extends z{descriptor={type:`fibRetracement`,name:`Fibonacci Retracement`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let{chartRect:i}=n,a=t.anchors[0].price,s=t.anchors[1].price,c=a-s;e.font=`11px sans-serif`,e.textBaseline=`middle`;for(let r of H){let a=s+c*(1-r),l=o(a,n);this.applyLineStyle(e,t.style),e.globalAlpha=r===0||r===1?1:.7,e.beginPath(),e.moveTo(i.x,l),e.lineTo(i.x+i.width,l),e.stroke(),e.fillStyle=t.style.color,e.textAlign=`left`,e.fillText(`${(r*100).toFixed(1)}% (${a.toFixed(2)})`,i.x+4,l-2)}if(e.globalAlpha=1,t.style.fillColor){for(let r=0;r<H.length-1;r++){let a=s+c*(1-H[r]),l=s+c*(1-H[r+1]),u=o(a,n),d=o(l,n);e.fillStyle=t.style.fillColor,e.globalAlpha=.05+r*.02,e.fillRect(i.x,Math.min(u,d),i.width,Math.abs(d-u))}e.globalAlpha=1}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{chartRect:i}=n;if(e.x<i.x-r||e.x>i.x+i.width+r)return!1;let a=t.anchors[0].price,s=t.anchors[1].price,c=a-s;for(let t of H){let i=o(s+c*(1-t),n);if(Math.abs(e.y-i)<=r)return!0}return!1}},Fr=[0,.618,1,1.618,2,2.618,3.618,4.236],Ir=class extends z{descriptor={type:`fibExtension`,name:`Fibonacci Extension`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let{chartRect:i}=n,a=t.anchors[0].price,s=t.anchors[1].price,c=t.anchors[2].price,l=a-s;e.font=`11px sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;for(let r of Fr){let a=o(c+l*r,n);this.applyLineStyle(e,t.style),e.globalAlpha=r===0||r===1?1:.6,e.beginPath(),e.moveTo(i.x,a),e.lineTo(i.x+i.width,a),e.stroke(),e.fillStyle=t.style.color,e.fillText(`${(r*100).toFixed(1)}%`,i.x+4,a-2)}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let{chartRect:i}=n;if(e.x<i.x-r||e.x>i.x+i.width+r)return!1;let a=t.anchors[0].price-t.anchors[1].price;for(let i of Fr){let s=o(t.anchors[2].price+a*i,n);if(Math.abs(e.y-s)<=r)return!0}return!1}},Lr=class extends z{descriptor={type:`rectangle`,name:`Rectangle`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y);t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fillRect(o,s,c,l)),this.applyLineStyle(e,t.style),e.strokeRect(o,s,c,l),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.min(i.y,a.y)-r,c=Math.max(i.x,a.x)+r,l=Math.max(i.y,a.y)+r;if(e.x<o||e.x>c||e.y<s||e.y>l)return!1;let u=Math.min(i.x,a.x)+r,d=Math.min(i.y,a.y)+r,f=Math.max(i.x,a.x)-r,p=Math.max(i.y,a.y)-r;return!(e.x>u&&e.x<f&&e.y>d&&e.y<p)||!!t.style.fillColor}},Rr=class extends z{descriptor={type:`ellipse`,name:`Ellipse`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.abs(a.x-i.x)/2,l=Math.abs(a.y-i.y)/2;e.beginPath(),e.ellipse(o,s,Math.max(c,1),Math.max(l,1),0,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.max(Math.abs(a.x-i.x)/2,1),l=Math.max(Math.abs(a.y-i.y)/2,1),u=(e.x-o)/c,d=(e.y-s)/l,f=Math.sqrt(u*u+d*d),p=r/Math.max(Math.min(c,l),4);return t.style.fillColor?f<=1+p:Math.abs(f-1)<=p}},zr=class extends z{descriptor={type:`triangle`,name:`Triangle`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=t.anchors.map(e=>this.anchorToPixel(e,n));e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.lineTo(i[2].x,i[2].y),e.closePath(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<3;t++){let n=(t+1)%3;if(this.distanceToLine(e,i[t],i[n])<=r)return!0}return!1}},U=class extends z{descriptor={type:`pitchfork`,name:`Andrews' Pitchfork`,requiredAnchors:3};origin(e,t){return e}render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n),s=this.origin(i,a),c={x:(a.x+o.x)/2,y:(a.y+o.y)/2};(s.x!==i.x||s.y!==i.y)&&(e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(s.x,s.y),e.stroke(),e.setLineDash([]));let l=c.x-s.x,u=c.y-s.y,d=Math.hypot(l,u)||1,f=Math.hypot(n.chartRect.width,n.chartRect.height),p=s.x+l/d*f,m=s.y+u/d*f;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(p,m),e.stroke(),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x+l/d*f,a.y+u/d*f),e.stroke(),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x+l/d*f,o.y+u/d*f),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[1],n),a=this.anchorToPixel(t.anchors[2],n),o=this.origin(this.anchorToPixel(t.anchors[0],n),i),s={x:(i.x+a.x)/2,y:(i.y+a.y)/2};if(this.distanceToInfiniteLine(e,o,s)<=r)return!0;let c=s.x-o.x,l=s.y-o.y,u={x:i.x+c,y:i.y+l},d={x:a.x+c,y:a.y+l};return this.distanceToInfiniteLine(e,i,u)<=r||this.distanceToInfiniteLine(e,a,d)<=r}},Br=class extends U{descriptor={type:`schiffPitchfork`,name:`Schiff Pitchfork`,requiredAnchors:3};origin(e,t){return{x:e.x,y:(e.y+t.y)/2}}},Vr=class extends U{descriptor={type:`modifiedSchiffPitchfork`,name:`Modified Schiff Pitchfork`,requiredAnchors:3};origin(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}},Hr=[`1`,`2`,`3`,`4`,`5`,`A`,`B`,`C`],Ur=class extends z{descriptor={type:`elliottWave`,name:`Elliott Wave`,requiredAnchors:8};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++)e.lineTo(i[t].x,i[t].y);e.stroke(),this.resetLineStyle(e),e.font=`bold 12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`;for(let t=0;t<i.length&&t<Hr.length;t++){let n=t%2==0?-12:12;e.textBaseline=n<0?`bottom`:`top`,e.fillText(Hr[t],i[t].x,i[t].y+n)}r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<i.length-1;t++)if(this.distanceToLine(e,i[t],i[t+1])<=r)return!0;return!1}},Wr=class extends z{descriptor={type:`priceRange`,name:`Price Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.abs(a.x-i.x),c=Math.min(i.y,a.y),l=Math.abs(a.y-i.y),u=t.anchors[1].price>t.anchors[0].price;e.fillStyle=u?`rgba(31, 168, 116, 0.15)`:`rgba(232, 80, 91, 0.15)`,e.fillRect(o,c,s,l),this.applyLineStyle(e,t.style),e.strokeRect(o,c,s,l),this.resetLineStyle(e);let d=t.anchors[1].price-t.anchors[0].price,f=t.anchors[0].price===0?0:d/t.anchors[0].price*100,p=`${d>=0?`+`:``}${d.toFixed(2)} (${f>=0?`+`:``}${f.toFixed(2)}%)`;e.font=`12px sans-serif`,e.fillStyle=u?`#1fa874`:`#e8505b`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(p,o+s/2,c+l/2),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return e.x>=o-r&&e.x<=s+r&&e.y>=c-r&&e.y<=l+r}},Gr=class extends z{descriptor={type:`dateRange`,name:`Date Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);e.fillStyle=`rgba(76, 141, 255, 0.08)`,e.fillRect(s,o.y,c-s,o.height),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(c,o.y),e.lineTo(c,o.y+o.height),e.stroke(),this.resetLineStyle(e);let l=g(t.anchors[0].time,n),u=g(t.anchors[1].time,n),d=Math.max(0,Math.round(Math.abs(u-l)));e.font=`12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`,e.textBaseline=`top`,e.fillText(`${d} bars`,(s+c)/2,o.y+4),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);return e.x>=s-r&&e.x<=c+r&&e.y>=o.y&&e.y<=o.y+o.height}},Kr=class extends z{descriptor={type:`measure`,name:`Measure`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=t.anchors[1].price-t.anchors[0].price,s=g(t.anchors[0].time,n),c=g(t.anchors[1].time,n),l=Math.max(0,Math.round(Math.abs(c-s))),u=t.anchors[0].price===0?0:o/t.anchors[0].price*100,d=[`Price: ${o>=0?`+`:``}${o.toFixed(2)} (${u>=0?`+`:``}${u.toFixed(2)}%)`,`Bars: ${l}`],f=(i.x+a.x)/2,p=(i.y+a.y)/2;e.font=`11px sans-serif`,e.textAlign=`center`,e.textBaseline=`bottom`;let m=Math.max(...d.map(t=>e.measureText(t).width));e.fillStyle=`rgba(0, 0, 0, 0.7)`,e.fillRect(f-m/2-6,p-d.length*14-4,m+12,d.length*14+8),e.fillStyle=`#FFFFFF`;for(let t=0;t<d.length;t++)e.fillText(d[t],f,p-(d.length-1-t)*14);r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}};function qr(e,t=`Text`){if(typeof e.style.text==`string`&&e.style.text.length>0)return e.style.text;let n=e.meta?.text;return typeof n==`string`&&n.length>0?n:t}var Jr=class extends z{descriptor={type:`text`,name:`Text`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=qr(t),o=t.style.fontSize||14;if(e.font=`${o}px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`left`,e.textBaseline=`top`,r){let n=e.measureText(a);e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.strokeRect(i.x-2,i.y-2,n.width+4,o+4),e.setLineDash([])}e.fillText(a,i.x,i.y),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=t.style.fontSize||14;return e.x>=i.x-r&&e.x<=i.x+80+r&&e.y>=i.y-r&&e.y<=i.y+a+r}},Yr=class extends z{descriptor={type:`arrow`,name:`Arrow`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=Math.atan2(a.y-i.y,a.x-i.x);e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x-12*Math.cos(o-Math.PI/6),a.y-12*Math.sin(o-Math.PI/6)),e.lineTo(a.x-12*Math.cos(o+Math.PI/6),a.y-12*Math.sin(o+Math.PI/6)),e.closePath(),e.fillStyle=t.style.color,e.fill(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},Xr=[{label:`8x1`,ratio:8},{label:`4x1`,ratio:4},{label:`3x1`,ratio:3},{label:`2x1`,ratio:2},{label:`1x1`,ratio:1},{label:`1x2`,ratio:.5},{label:`1x3`,ratio:1/3},{label:`1x4`,ratio:.25},{label:`1x8`,ratio:.125}],Zr=class extends z{descriptor={type:`gannFan`,name:`Gann Fan`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;this.applyLineStyle(e,t.style);for(let{label:n,ratio:r}of Xr){let a=c*r,o=d,s=i.y+a*(o-i.x);e.globalAlpha=r===1?1:.5,e.lineWidth=r===1?t.style.lineWidth:Math.max(.5,t.style.lineWidth*.7),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o,s),e.stroke();let f=o-l*4,p=s;p>u.y&&p<u.y+u.height&&(e.globalAlpha=.7,e.fillStyle=t.style.color,e.font=`9px sans-serif`,e.textAlign=l>0?`right`:`left`,e.textBaseline=`bottom`,e.fillText(n,f,p-2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return!1;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;for(let{ratio:t}of Xr){let n=c*t,a=d,o=i.y+n*(a-i.x);if(this.distanceToLine(e,i,{x:a,y:o})<=r)return!0}return!1}},Qr=[0,.25,.333,.5,.667,.75,1],$r=class extends z{descriptor={type:`gannBox`,name:`Gann Box`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y),u=s-o,d=l-c;if(!(u<2||d<2)){this.applyLineStyle(e,t.style),e.strokeRect(o,c,u,d),e.save(),e.globalAlpha=.35;for(let t of Qr){if(t===0||t===1)continue;let n=c+d*t;e.beginPath(),e.moveTo(o,n),e.lineTo(s,n),e.stroke()}for(let t of Qr){if(t===0||t===1)continue;let n=o+u*t;e.beginPath(),e.moveTo(n,c),e.lineTo(n,l),e.stroke()}e.globalAlpha=.5,e.setLineDash([4,3]),e.beginPath(),e.moveTo(o,c),e.lineTo(s,l),e.stroke(),e.beginPath(),e.moveTo(s,c),e.lineTo(o,l),e.stroke(),e.restore(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`8px sans-serif`,e.globalAlpha=.6,e.textBaseline=`bottom`,e.textAlign=`right`;for(let t of Qr){if(t===0||t===1)continue;let n=c+d*t;e.fillText(`${(t*100).toFixed(0)}%`,o-3,n)}e.globalAlpha=1,r&&this.renderAnchorHandles(e,t,n)}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return Math.abs(e.x-o)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.x-s)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.y-c)<=r&&e.x>=o-r&&e.x<=s+r||Math.abs(e.y-l)<=r&&e.x>=o-r&&e.x<=s+r||this.distanceToLine(e,{x:o,y:c},{x:s,y:l})<=r||this.distanceToLine(e,{x:s,y:c},{x:o,y:l})<=r}},ei=class extends z{descriptor={type:`anchoredVWAP`,name:`Anchored VWAP`,requiredAnchors:1};dataGetter=null;showBands=!0;setDataGetter(e){this.dataGetter=e}setShowBands(e){this.showBands=e}render(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return;let i=this.dataGetter(),s=Math.max(0,Math.round(g(t.anchors[0].time,n)));if(s>=i.length)return;let{vwap:c,upper1:l,lower1:u,upper2:d,lower2:f}=this.computeVWAP(i,s),{chartRect:p}=n,m=n.barWidth+n.barSpacing;if(this.applyLineStyle(e,t.style),e.lineWidth=t.style.lineWidth+.5,this.drawLine(e,c,s,n,p,m),this.showBands&&c.length>1&&(e.globalAlpha=.4,e.lineWidth=Math.max(.5,t.style.lineWidth*.6),e.setLineDash([4,3]),this.drawLine(e,l,s,n,p,m),this.drawLine(e,u,s,n,p,m),e.globalAlpha=.25,this.drawLine(e,d,s,n,p,m),this.drawLine(e,f,s,n,p,m),e.globalAlpha=1),this.resetLineStyle(e),c.length>0){let r=c[c.length-1],i=a(s+c.length-1,n),l=o(r,n);i>=p.x&&i<=p.x+p.width&&(e.fillStyle=t.style.color,e.font=`bold 9px sans-serif`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`AVWAP ${r.toFixed(2)}`,i+6,l))}r&&this.renderAnchorHandles(e,t,n)}drawLine(e,t,n,r,i,s){e.beginPath();let c=!1;for(let l=0;l<t.length;l++){let u=a(n+l,r);if(u<i.x-s)continue;if(u>i.x+i.width+s)break;let d=o(t[l],r);c?e.lineTo(u,d):(e.moveTo(u,d),c=!0)}e.stroke()}vwapCache=null;computeVWAP(e,t){let n=e[e.length-1],r=this.vwapCache;if(r&&r.data===e&&r.length===e.length&&r.startIdx===t&&r.lastClose===n?.close&&r.lastVolume===(n?.volume??0))return r.result;let i=this.computeVWAPUncached(e,t);return this.vwapCache={data:e,length:e.length,startIdx:t,lastClose:n?.close,lastVolume:n?.volume??0,result:i},i}computeVWAPUncached(e,t){let n=e.length-t,r=Array(n),i=Array(n),a=Array(n),o=Array(n),s=Array(n),c=0,l=0,u=0;for(let d=0;d<n;d++){let n=e[t+d],f=(n.high+n.low+n.close)/3,p=n.volume??1;c+=f*p,l+=p,u+=f*f*p;let m=l>0?c/l:f;r[d]=m;let h=l>0?u/l-m*m:0,g=Math.sqrt(Math.max(0,h));i[d]=m+g,a[d]=m-g,o[d]=m+2*g,s[d]=m-2*g}return{vwap:r,upper1:i,lower1:a,upper2:o,lower2:s}}hitTest(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return!1;let i=this.dataGetter(),s=Math.max(0,Math.round(g(t.anchors[0].time,n)));if(s>=i.length)return!1;let{vwap:c}=this.computeVWAP(i,s);for(let t=1;t<c.length;t++){let i=a(s+t-1,n),l=o(c[t-1],n),u=a(s+t,n),d=o(c[t],n);if(this.distanceToLine(e,{x:i,y:l},{x:u,y:d})<=r)return!0}return!1}},ti=class extends z{descriptor={type:`volumeProfileRange`,name:`Volume Profile (Range)`,requiredAnchors:2};dataGetter=null;numBins=40;setDataGetter(e){this.dataGetter=e}render(e,t,n,r){if(t.anchors.length<2||!this.dataGetter)return;let i=this.dataGetter(),s=Math.round(g(t.anchors[0].time,n)),c=Math.round(g(t.anchors[1].time,n)),l=Math.max(0,Math.min(s,c)),u=Math.min(i.length-1,Math.max(s,c));if(l>=i.length||u<0||l>u)return;let d=1/0,f=-1/0;for(let e=l;e<=u;e++)i[e].low<d&&(d=i[e].low),i[e].high>f&&(f=i[e].high);if(d>=f)return;let p=(f-d)/this.numBins,m=new Float64Array(this.numBins),h=0;for(let e=l;e<=u;e++){let t=i[e],n=t.volume??1,r=Math.max(0,Math.floor((t.low-d)/p)),a=Math.min(this.numBins-1,Math.floor((t.high-d)/p)),o=n/(a-r+1);for(let e=r;e<=a;e++)m[e]+=o,m[e]>h&&(h=m[e])}if(h===0)return;let _=0;for(let e=1;e<this.numBins;e++)m[e]>m[_]&&(_=e);let v=a(u,n)+n.barWidth,y=t.style.color,b=t.style.fillColor??`#f2a93b`;e.save();for(let t=0;t<this.numBins;t++){let r=m[t]/h*100,i=d+(t+1)*p,a=d+t*p,s=o(i,n),c=o(a,n),l=Math.abs(c-s);e.globalAlpha=.35,e.fillStyle=t===_?b:y,e.fillRect(v,Math.min(s,c),r,Math.max(1,l-.5))}let x=d+(_+.5)*p,S=o(x,n);e.globalAlpha=.7,e.strokeStyle=b,e.lineWidth=1,e.setLineDash([4,3]),e.beginPath();let C=a(l,n)-n.barWidth/2;e.moveTo(C,S),e.lineTo(v+100,S),e.stroke(),e.fillStyle=b,e.font=`9px sans-serif`,e.textAlign=`left`,e.textBaseline=`bottom`,e.globalAlpha=.8,e.fillText(`POC ${x.toFixed(2)}`,v+100+4,S-2),e.restore(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.max(i.x,a.x)+100+r,c=Math.min(i.y,a.y)-r,l=Math.max(i.y,a.y)+r;return e.x>=o&&e.x<=s&&e.y>=c&&e.y<=l}},ni=[1,2,3,5,8,13,21,34,55],ri=class extends z{descriptor={type:`fibTimeZones`,name:`Fibonacci Time Zones`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return;let{chartRect:o}=n;e.font=`11px sans-serif`,e.textBaseline=`top`,e.textAlign=`center`,this.applyLineStyle(e,t.style);for(let r of ni){let s=_(i.time+a*r,n);s<o.x||s>o.x+o.width||(e.globalAlpha=r===1?1:.55,e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.fillStyle=t.style.color,e.fillText(String(r),s,o.y+2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return!1;let{chartRect:o}=n;if(e.y<o.y||e.y>o.y+o.height)return!1;for(let t of ni){let o=_(i.time+a*t,n);if(Math.abs(e.x-o)<=r)return!0}return!1}},W=2,ii=class extends z{descriptor={type:`riskReward`,name:`Long/Short Position`,requiredAnchors:2};geometry(e){let t=e.anchors[0].price,n=e.anchors[1].price,r=Math.abs(t-n),i=n<t;return{entryPrice:t,stopPrice:n,targetPrice:i?t+r*W:t-r*W,risk:r,isLong:i}}render(e,t,n,r){if(t.anchors.length<2)return;let{entryPrice:i,stopPrice:a,targetPrice:o,risk:s,isLong:c}=this.geometry(t),l=this.anchorToPixel(t.anchors[0],n),u=this.anchorToPixel(t.anchors[1],n),d=Math.min(l.x,u.x),f=Math.max(Math.abs(u.x-l.x),40),p=l.y,m=u.y,h=this.anchorToPixel({time:t.anchors[1].time,price:o},n).y,g=Math.min(p,m),_=Math.abs(m-p),v=Math.min(p,h),y=Math.abs(h-p);e.fillStyle=`rgba(232, 80, 91, 0.18)`,e.fillRect(d,g,f,_),e.fillStyle=`rgba(31, 168, 116, 0.18)`,e.fillRect(d,v,f,y),e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([]),e.beginPath(),e.moveTo(d,p),e.lineTo(d+f,p),e.stroke();let b=e=>i===0?0:(e-i)/i*100;e.font=`11px sans-serif`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillStyle=`#e8505b`,e.fillText(`Risk ${s.toFixed(2)} (${b(a).toFixed(2)}%)`,d+4,(p+m)/2),e.fillStyle=`#1fa874`;let x=`R:R 1:${W}`;e.fillText(`Reward ${(s*W).toFixed(2)} (${b(o).toFixed(2)}%) · ${x}`,d+4,(p+h)/2),e.fillStyle=t.style.color,e.fillText(c?`Long`:`Short`,d+4,p-8),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{targetPrice:i}=this.geometry(t),a=this.anchorToPixel(t.anchors[0],n),o=this.anchorToPixel(t.anchors[1],n),s=this.anchorToPixel({time:t.anchors[1].time,price:i},n).y,c=Math.min(a.x,o.x)-r,l=Math.max(a.x,o.x)+r,u=Math.min(a.y,o.y,s)-r,d=Math.max(a.y,o.y,s)+r;return e.x>=c&&e.x<=l&&e.y>=u&&e.y<=d}},ai=class extends z{descriptor={type:`crossLine`,name:`Cross Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(a.x,i.y),e.lineTo(a.x+a.width,i.y),e.moveTo(i.x,a.y),e.lineTo(i.x,a.y+a.height),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return Math.abs(e.y-i.y)<=r||Math.abs(e.x-i.x)<=r}},oi=28,si=48;function ci(e,t){return Math.atan2(e.y-t.y,t.x-e.x)*180/Math.PI}var li=class extends z{descriptor={type:`trendAngle`,name:`Trend Angle`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=ci(i,a),s=a.x>=i.x?1:-1;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x+s*si,i.y),e.stroke(),e.setLineDash([]);let c=Math.atan2(a.y-i.y,a.x-i.x),l=s>0?0:Math.PI;s<0&&c<0&&(c+=2*Math.PI),e.beginPath(),e.arc(i.x,i.y,oi,Math.min(l,c),Math.max(l,c)),e.stroke(),e.font=`11px sans-serif`,e.fillStyle=t.style.color,e.textAlign=s>0?`left`:`right`,e.textBaseline=`middle`,e.fillText(`${o.toFixed(1)}°`,i.x+s*(oi+6),i.y+(o>=0?-8:8)),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},ui=`11px sans-serif`,di=14,fi=6,pi=4,mi=`rgba(19, 23, 34, 0.85)`,hi=`#FFFFFF`,gi=6e4,G=60*gi,_i=24*G;function vi(e){let t=Math.abs(e);return t>=10||t===0?2:t>=1?4:Math.min(10,Math.ceil(-Math.log10(t))+3)}function yi(e,t=e){return e.toFixed(vi(t))}function bi(e,t){let n=t-e,r=e===0?0:n/e*100,i=n>=0?`+`:``;return`${i}${yi(n,e)} (${i}${r.toFixed(2)}%)`}function xi(e){let t=Math.abs(e);if(t<G)return`${Math.round(t/gi)}m`;if(t<_i){let e=Math.floor(t/G),n=Math.round((t-e*G)/gi);return n>0?`${e}h ${n}m`:`${e}h`}let n=Math.floor(t/_i),r=Math.round((t-n*_i)/G);if(n>=7){let e=Math.floor(n/7),t=n-e*7;return t>0?`${e}w ${t}d`:`${e}w`}return r>0?`${n}d ${r}h`:`${n}d`}function Si(e){return!!e.data&&e.data.length>0}function Ci(e,t,n,r){let i=g(e.anchors[t].time,r),a=g(e.anchors[n].time,r);return Math.round(Math.abs(a-i))}function wi(e,t,n,r){return Si(r)?xi(e.anchors[n].time-e.anchors[t].time):null}function Ti(e,t,n,r,i=`center`,a=!0){e.font=ui;let o=0;for(let n of t)o=Math.max(o,e.measureText(n).width);let s=o+fi*2,c=t.length*di+pi*2,l=i===`left`?n:i===`right`?n-s:n-s/2,u=a?r-c:r;e.fillStyle=mi,e.fillRect(l,u,s,c),e.fillStyle=hi,e.textAlign=`left`,e.textBaseline=`top`;for(let n=0;n<t.length;n++)e.fillText(t[n],l+fi,u+pi+n*di);return{x:l,y:u,width:s,height:c}}function Ei(e,t,n){let r=Math.abs(e.anchors[t[1]].price-e.anchors[t[0]].price),i=Math.abs(e.anchors[n[1]].price-e.anchors[n[0]].price);return i===0?`—`:(r/i).toFixed(3)}function Di(e,t,n){let r=wi(e,0,1,t),i=Ci(e,0,1,t);return[bi(e.anchors[0].price,e.anchors[1].price),r?`${i} bars, ${r}`:`${i} bars`,`${n.toFixed(1)}°`]}var Oi=class extends z{descriptor={type:`infoLine`,name:`Info Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=Di(t,n,ci(i,a)),s=a.y<=i.y;Ti(e,o,a.x+(a.x>=i.x?8:-8),a.y+(s?-6:6),a.x>=i.x?`left`:`right`,s),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},ki=[0,.236,.382,.5,.618,.786,1,1.618];function Ai(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=r*r+i*i;if(a===0)return{x:n.x-e.x,y:n.y-e.y};let o=((n.x-e.x)*r+(n.y-e.y)*i)/a;return{x:n.x-(e.x+o*r),y:n.y-(e.y+o*i)}}function ji(e,t,n,r){let i=Ai(e,t,n);return[{x:e.x+i.x*r,y:e.y+i.y*r},{x:t.x+i.x*r,y:t.y+i.y*r}]}var Mi=class extends z{descriptor={type:`fibChannel`,name:`Fibonacci Channel`,requiredAnchors:3};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(t.anchors.length<3){this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);return}let o=this.anchorToPixel(t.anchors[2],n);e.font=`11px sans-serif`,e.textAlign=`right`,e.textBaseline=`middle`;for(let n of ki){let[r,s]=ji(i,a,o,n);this.applyLineStyle(e,t.style),e.globalAlpha=n===0||n===1?1:.6,e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(s.x,s.y),e.stroke(),e.fillStyle=t.style.color;let c=r.x<=s.x?r:s;e.fillText(String(n),c.x-4,c.y)}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n);for(let t of ki){let[n,s]=ji(i,a,o,t);if(this.distanceToLine(e,n,s)<=r)return!0}return!1}},Ni=[.25,.382,.5,.618,.75];function Pi(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.hypot(r,i);if(a===0)return null;let o=(n.chartRect.width+n.chartRect.height)*2;return{x:e.x+r/a*o,y:e.y+i/a*o}}function Fi(e,t){let n=[{level:1,kind:`diagonal`,point:t}];for(let r of Ni)n.push({level:r,kind:`price`,point:{x:t.x,y:e.y+(t.y-e.y)*r}}),n.push({level:r,kind:`time`,point:{x:e.x+(t.x-e.x)*r,y:t.y}});return n}var Ii=class extends z{descriptor={type:`fibSpeedResistanceFan`,name:`Fib Speed Resistance Fan`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);e.strokeStyle=t.style.color,e.lineWidth=1,e.globalAlpha=.25,e.strokeRect(Math.min(i.x,a.x),Math.min(i.y,a.y),Math.abs(a.x-i.x),Math.abs(a.y-i.y)),e.globalAlpha=1,e.font=`11px sans-serif`,e.textBaseline=`middle`;for(let r of Fi(i,a)){let o=Pi(i,r.point,n);o&&(this.applyLineStyle(e,t.style),e.globalAlpha=r.kind===`diagonal`?1:.65,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o.x,o.y),e.stroke(),r.kind===`price`&&(e.fillStyle=t.style.color,e.textAlign=a.x>=i.x?`left`:`right`,e.fillText(String(r.level),r.point.x+(a.x>=i.x?4:-4),r.point.y)))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);for(let t of Fi(i,a)){let a=Pi(i,t.point,n);if(a&&this.distanceToLine(e,i,a)<=r)return!0}return!1}},Li=class extends z{ratioLinks=[];triangles=[];render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));t.anchors.length>=this.descriptor.requiredAnchors&&this.renderTriangles(e,t,i),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++)e.lineTo(i[t].x,i[t].y);e.stroke(),this.resetLineStyle(e),this.renderRatioLinks(e,t,i),this.renderPointLabels(e,t,i),this.renderExtras(e,t,i,n),r&&this.renderAnchorHandles(e,t,n)}renderExtras(e,t,n,r){}renderTriangles(e,t,n){e.fillStyle=t.style.fillColor??t.style.color,e.globalAlpha=t.style.fillColor?1:.12;for(let[t,r,i]of this.triangles)e.beginPath(),e.moveTo(n[t].x,n[t].y),e.lineTo(n[r].x,n[r].y),e.lineTo(n[i].x,n[i].y),e.closePath(),e.fill();e.globalAlpha=1}renderRatioLinks(e,t,n){e.font=`11px sans-serif`,e.textAlign=`center`,e.textBaseline=`middle`;for(let r of this.ratioLinks){if(Math.max(r.from,r.to,...r.num,...r.den)>=n.length)continue;let i=n[r.from],a=n[r.to];e.strokeStyle=t.style.color,e.lineWidth=1,e.globalAlpha=.7,e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),e.setLineDash([]),e.globalAlpha=1,e.fillStyle=t.style.color,e.fillText(Ei(t,r.num,r.den),(i.x+a.x)/2,(i.y+a.y)/2)}}renderPointLabels(e,t,n){e.font=`bold 12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`;for(let t=0;t<n.length&&t<this.pointLabels.length;t++){let r=n[t-1]??n[t+1],i=n[t+1]??n[t-1],a=!r||!i?!0:n[t].y<=Math.min(r.y,i.y);e.textBaseline=a?`bottom`:`top`,e.fillText(this.pointLabels[t],n[t].x,n[t].y+(a?-6:6))}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<i.length-1;t++)if(this.distanceToLine(e,i[t],i[t+1])<=r)return!0;return!1}},Ri=class extends Li{descriptor={type:`xabcdPattern`,name:`XABCD Pattern`,requiredAnchors:5};pointLabels=[`X`,`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:1,to:3,num:[2,3],den:[1,2]},{from:2,to:4,num:[3,4],den:[2,3]},{from:0,to:4,num:[1,4],den:[0,1]}];triangles=[[0,1,2],[2,3,4]]},zi=class extends Li{descriptor={type:`abcdPattern`,name:`ABCD Pattern`,requiredAnchors:4};pointLabels=[`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:1,to:3,num:[2,3],den:[1,2]}]},Bi=class extends Li{descriptor={type:`headAndShoulders`,name:`Head and Shoulders`,requiredAnchors:7};pointLabels=[``,`Left Shoulder`,``,`Head`,``,`Right Shoulder`,``];triangles=[[0,1,2],[2,3,4],[4,5,6]];renderExtras(e,t,n){if(n.length<5)return;let r=n[2],i=n[4],a=n[0],o=n[n.length-1],s=i.x===r.x?0:(i.y-r.y)/(i.x-r.x),c=e=>r.y+s*(e-r.x);e.strokeStyle=t.style.color,e.lineWidth=Math.max(1,t.style.lineWidth),e.setLineDash([6,4]),e.beginPath(),e.moveTo(a.x,c(a.x)),e.lineTo(o.x,c(o.x)),e.stroke(),e.setLineDash([])}},Vi=class extends z{descriptor={type:`circle`,name:`Circle`,requiredAnchors:2};geometry(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return{c:n,r:Math.hypot(r.x-n.x,r.y-n.y)}}render(e,t,n,r){if(t.anchors.length<2)return;let{c:i,r:a}=this.geometry(t,n);e.beginPath(),e.arc(i.x,i.y,a,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{c:i,r:a}=this.geometry(t,n),o=Math.hypot(e.x-i.x,e.y-i.y);return t.style.fillColor?o<=a+r:Math.abs(o-a)<=r}},Hi=`rgba(76, 141, 255, 0.12)`,Ui=`rgba(232, 80, 91, 0.12)`;function Wi(e,t){let n=t.data;if(!n||n.length===0)return null;let r=Math.round(g(e.anchors[0].time,t)),i=Math.round(g(e.anchors[1].time,t)),a=Math.max(0,Math.min(r,i)),o=Math.min(n.length-1,Math.max(r,i)),s=0;for(let e=a;e<=o;e++)s+=n[e].volume??0;return s}function Gi(e){return e>=1e9?`${(e/1e9).toFixed(2)}B`:e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(2)}K`:e.toFixed(0)}function Ki(e,t){let n=wi(e,0,1,t),r=Ci(e,0,1,t),i=[bi(e.anchors[0].price,e.anchors[1].price),n?`${r} bars, ${n}`:`${r} bars`],a=Wi(e,t);return a!==null&&i.push(`Vol ${Gi(a)}`),i}var qi=class extends z{descriptor={type:`dateAndPriceRange`,name:`Date and Price Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y),u=t.anchors[1].price>=t.anchors[0].price;e.fillStyle=u?Hi:Ui,e.fillRect(o,s,c,l),this.applyLineStyle(e,t.style);let d=o+c/2,f=s+l/2;e.beginPath(),e.moveTo(d,i.y),e.lineTo(d,a.y),e.moveTo(i.x,f),e.lineTo(a.x,f),e.stroke(),this.resetLineStyle(e),Ti(e,Ki(t,n),d,u?s-6:s+l+6,`center`,u),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return e.x>=Math.min(i.x,a.x)-r&&e.x<=Math.max(i.x,a.x)+r&&e.y>=Math.min(i.y,a.y)-r&&e.y<=Math.max(i.y,a.y)+r}},Ji=400,Yi=2;function Xi(e,t,n){let r=Math.abs(t.x-e.x);if(r<Yi)return[e.x];let i=n.chartRect.x+n.chartRect.width,a=[],o=Math.min(e.x,t.x);for(let e=o;e<=i&&a.length<Ji;e+=r)a.push(e);return a}var Zi=class extends z{descriptor={type:`cyclicLines`,name:`Cyclic Lines`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n;this.applyLineStyle(e,t.style),e.beginPath();for(let t of Xi(i,a,n))t<o.x||(e.moveTo(t,o.y),e.lineTo(t,o.y+o.height));e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:Xi(this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n),n).some(t=>Math.abs(e.x-t)<=r)}},Qi=14,$i=18,ea=6,ta=20,na=class extends z{descriptor={type:`priceLabel`,name:`Price Label`,requiredAnchors:1};text(e){return e.style.text||yi(e.anchors[0].price)}box(e,t,n){let r=t.style.fontSize??12,i=e?e.measureText(this.text(t)).width:this.text(t).length*r*.6;return{x:n.x+Qi,y:n.y-$i-ta/2,w:i+ea*2,h:ta}}render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n);e.font=`${t.style.fontSize??12}px sans-serif`;let a=this.box(e,t,i);e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y+a.h),e.stroke(),e.fillStyle=t.style.color,e.fillRect(a.x,a.y,a.w,a.h),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(this.text(t),a.x+ea,a.y+a.h/2),e.beginPath(),e.arc(i.x,i.y,3,0,Math.PI*2),e.fillStyle=t.style.color,e.fill(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);if(Math.hypot(e.x-i.x,e.y-i.y)<=r)return!0;let a=this.box(null,t,i);return e.x>=a.x-r&&e.x<=a.x+a.w+r&&e.y>=a.y-r&&e.y<=a.y+a.h+r}};function ra(e){e.register(new Er),e.register(new Dr),e.register(new Or),e.register(new kr),e.register(new Ar),e.register(new jr),e.register(new Mr),e.register(new Nr),e.register(new Pr),e.register(new Ir),e.register(new Lr),e.register(new Rr),e.register(new zr),e.register(new U),e.register(new Ur),e.register(new Wr),e.register(new Gr),e.register(new Kr),e.register(new Jr),e.register(new Yr),e.register(new Zr),e.register(new $r),e.register(new ei),e.register(new ti),e.register(new ri),e.register(new ii),e.register(new ai),e.register(new li),e.register(new Oi),e.register(new Mi),e.register(new Ii),e.register(new Br),e.register(new Vr),e.register(new Ri),e.register(new zi),e.register(new Bi),e.register(new Vi),e.register(new qi),e.register(new Zi),e.register(new na)}var ia=class{render(e,t,n,r,i,a){let s=i.orderColors?.buy??`#1fa874`,c=i.orderColors?.sell??`#e8505b`,{chartRect:l}=n;for(let i of t){let t=a?.orderId===i.id&&a.sourceType===`order`,u=o(t?a.currentPrice:i.price,n);if(u<l.y||u>l.y+l.height)continue;let d=i.side===`buy`?s:c;e.setLineDash([6,4]),e.strokeStyle=d,e.lineWidth=1,e.beginPath(),e.moveTo(l.x,Math.round(u)+.5),e.lineTo(l.x+l.width,Math.round(u)+.5),e.stroke(),e.setLineDash([]);let f=i.label??i.type.toUpperCase();e.font=`bold 10px ${r.font.family}`;let p=e.measureText(f).width+8;e.fillStyle=d,e.fillRect(l.x+4,u-8,p,16),e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(f,l.x+8,u);let m=l.x+4+p+6;if(e.fillStyle=d,e.beginPath(),i.side===`buy`?(e.moveTo(m,u+4),e.lineTo(m+5,u-2),e.lineTo(m+10,u+4)):(e.moveTo(m,u-4),e.lineTo(m+5,u+2),e.lineTo(m+10,u-4)),e.fill(),t){let t=o(a.startPrice,n);e.setLineDash([2,4]),e.strokeStyle=d,e.globalAlpha=.3,e.beginPath(),e.moveTo(l.x,Math.round(t)+.5),e.lineTo(l.x+l.width,Math.round(t)+.5),e.stroke(),e.globalAlpha=1,e.setLineDash([])}}}renderAxisBadges(t,n,r,i,a,s){let c=a.orderColors?.buy??`#1fa874`,l=a.orderColors?.sell??`#e8505b`,u=a.pricePrecision??2,{chartRect:d}=r,f=d.x+d.width+1;for(let a of n){let n=s?.orderId===a.id&&s.sourceType===`order`?s.currentPrice:a.price,p=o(n,r);if(p<d.y||p>d.y+d.height)continue;let m=a.side===`buy`?c:l,h=`${n.toFixed(u)} x ${a.quantity}`;t.font=`11px ${i.font.family}`;let g=t.measureText(h).width+10;t.fillStyle=m,t.fillRect(f,p-9,Math.min(g,(r.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2),18),t.fillStyle=`#FFFFFF`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(h,f+5,p)}}hitTest(e,t,n,r){for(let i of t){if(i.draggable===!1)continue;let t=o(i.price,n);if(Math.abs(e-t)<=r)return i}return null}};function aa(e,t,n){let r=Math.min(Math.max(e.closedQuantity??0,0),e.quantity),i=e.quantity-r,a=e.side===`buy`?1:-1,o=(t-e.entryPrice)*i*a,s=e.entryPrice===0?0:(t-e.entryPrice)/e.entryPrice*100*a;return{side:e.side,quantity:e.quantity,closedQuantity:r,openQuantity:i,entryPrice:e.entryPrice,currentPrice:t,pnl:o,pnlPct:s,precision:n}}var oa=/\{(side|qty|closedQty|openQty|entry|price|pnl|pnlPct|pnlSign)\}/g;function sa(e,t){return e.replace(oa,(e,n)=>{switch(n){case`side`:return t.side.toUpperCase();case`qty`:return String(t.quantity);case`closedQty`:return String(t.closedQuantity);case`openQty`:return String(t.openQuantity);case`entry`:return t.entryPrice.toFixed(t.precision);case`price`:return t.currentPrice.toFixed(t.precision);case`pnl`:return t.pnl.toFixed(t.precision);case`pnlPct`:return`${t.pnlPct.toFixed(2)}%`;case`pnlSign`:return t.pnl>=0?`+`:``;default:return``}})}function ca(e,t){return typeof e==`function`?e(t):sa(e??`{side} {qty} | P&L: {pnlSign}{pnl}`,t)}function la(e,t,n){if(!t||t.length===0)return n;let r=[...t].sort((e,t)=>e.pnl-t.pnl),i;for(let t of r)if(e>=t.pnl)i=t.color;else break;return i??n}var ua=class{render(e,t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.profit??`#1fa874`,l=a.positionColors?.loss??`#e8505b`,u=a.positionColors?.entry??`#4c8dff`,d=a.pricePrecision??2;for(let f of t){let t=o(f.entryPrice,r);if(e.strokeStyle=u,e.lineWidth=1.5,e.setLineDash([]),e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),n!==null){let p=o(n,r),m=aa(f,n,d),h=m.pnl,g=h>=0?c:l,_=la(h,a.pnlThresholds,g);e.fillStyle=_,e.globalAlpha=.08;let v=Math.min(t,p),y=Math.abs(p-t);if(e.fillRect(s.x,v,s.width,y),e.globalAlpha=1,m.closedQuantity>0&&f.quantity>0){let t=m.closedQuantity/f.quantity;e.fillStyle=u,e.globalAlpha=.25,e.fillRect(s.x,v,Math.max(2,s.width*t*.04)+2,y),e.globalAlpha=1}let b=ca(a.positionLabel,m);e.font=`bold 11px ${i.font.family}`;let x=e.measureText(b).width+12,S=s.x+8;e.fillStyle=_,e.globalAlpha=.9,e.fillRect(S,t-10,x,20),e.globalAlpha=1,e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(b,S+6,t)}if(f.stopLoss!==void 0){let t=o(f.stopLoss,r);e.setLineDash([4,4]),e.strokeStyle=l,e.lineWidth=1,e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=l,e.fillRect(s.x+4,t-8,24,16),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`SL`,s.x+8,t)}if(f.takeProfit!==void 0){let t=o(f.takeProfit,r);e.setLineDash([4,4]),e.strokeStyle=c,e.lineWidth=1,e.beginPath(),e.moveTo(s.x,Math.round(t)+.5),e.lineTo(s.x+s.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=c,e.fillRect(s.x+4,t-8,24,16),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`TP`,s.x+8,t)}e.setLineDash([])}}renderAxisBadges(t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.entry??`#4c8dff`,l=a.pricePrecision??2,u=s.x+s.width+1;for(let a of n){let n=o(a.entryPrice,r);t.fillStyle=c,t.fillRect(u,n-9,(r.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2,18),t.fillStyle=`#FFFFFF`,t.font=`11px ${i.font.family}`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(a.entryPrice.toFixed(l),u+5,n)}}},da=class{render(e,t,n,r){if(!r.depthOverlay?.enabled)return;let{chartRect:i}=n,a=r.depthOverlay.bidColor??`rgba(31, 168, 116,0.15)`,s=r.depthOverlay.askColor??`rgba(232, 80, 91,0.15)`,c=r.depthOverlay.maxWidth??100,l=0,u=[],d=0;for(let e of t.bids)d+=e.volume,u.push({price:e.price,cumVol:d}),d>l&&(l=d);let f=[];d=0;for(let e of t.asks)d+=e.volume,f.push({price:e.price,cumVol:d}),d>l&&(l=d);if(l===0)return;let p=Math.max(1,t.bids.length>1?Math.abs(o(t.bids[0].price,n)-o(t.bids[1].price,n)):4),m=i.x+i.width;e.fillStyle=a;for(let{price:t,cumVol:r}of u){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}e.fillStyle=s;for(let{price:t,cumVol:r}of f){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}}},fa=class{dragState=null;startY=0;dragging=!1;constructor(e=3){this.dragThreshold=e}onPointerDown(e,t,n,r,i){for(let n of t){if(n.draggable===!1)continue;let t=o(n.price,r);if(Math.abs(e.y-t)<=i)return this.dragState={orderId:n.id,sourceType:`order`,startPrice:n.price,currentPrice:n.price},this.startY=e.y,this.dragging=!1,!0}for(let t of n){if(t.stopLoss!==void 0){let n=o(t.stopLoss,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`stopLoss`,startPrice:t.stopLoss,currentPrice:t.stopLoss},this.startY=e.y,this.dragging=!1,!0}if(t.takeProfit!==void 0){let n=o(t.takeProfit,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`takeProfit`,startPrice:t.takeProfit,currentPrice:t.takeProfit},this.startY=e.y,this.dragging=!1,!0}}return!1}onPointerMove(e,t){if(!this.dragState)return!1;if(!this.dragging){if(Math.abs(e.y-this.startY)<this.dragThreshold)return!0;this.dragging=!0}return this.dragState.currentPrice=u(e.y,t),!0}onPointerUp(){if(!this.dragState)return null;let e=this.dragState;return this.dragState=null,this.dragging?(this.dragging=!1,{sourceType:e.sourceType,id:e.orderId,newPrice:e.currentPrice,previousPrice:e.startPrice}):null}getDragState(){return this.dragState}isActive(){return this.dragState!==null}},pa=class{menuElement=null;removeHandler=null;onItemSelect=null;show(e,t,n,r){if(this.hide(),!r.contextMenu?.enabled)return;let i=r.pricePrecision??2,a=t.toFixed(i),o=document.createElement(`div`);o.style.cssText=`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@tradecanvas/commons`);var t=class{canvas;ctx;dpr=1;constructor(e,t){this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0`,this.canvas.style.left=`0`,this.canvas.style.zIndex=String(t),this.canvas.style.pointerEvents=`none`,this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas)}resize(e,t){this.dpr=t;let n=Math.round(e.width*t),r=Math.round(e.height*t);(this.canvas.width!==n||this.canvas.height!==r)&&(this.canvas.width=n,this.canvas.height=r),this.canvas.style.width=`${e.width}px`,this.canvas.style.height=`${e.height}px`,this.ctx.setTransform(t,0,0,t,0,0)}clear(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}getSize(){return{width:this.canvas.width/this.dpr,height:this.canvas.height/this.dpr}}destroy(){this.canvas.remove()}},n=class{scene=null;top=null;constructor(e){this.container=e}createLayers(){this.destroy(),this.scene=new t(this.container,0),this.top=new t(this.container,1)}getLayer(t){return(t===e.LayerType.Hover?this.top:this.scene)??void 0}resize(e,t){this.scene?.resize(e,t),this.top?.resize(e,t)}destroy(){this.scene?.destroy(),this.top?.destroy(),this.scene=null,this.top=null}},r=class{animFrameId=0;running=!1;dirtyLayers=new Set;swapLayers=new Set;callback=null;setCallback(e){this.callback=e}markDirty(e){this.dirtyLayers.add(e),this.running&&!this.animFrameId&&this.scheduleFrame()}markAllDirty(){this.dirtyLayers.add(e.LayerType.Background),this.dirtyLayers.add(e.LayerType.Main),this.dirtyLayers.add(e.LayerType.Overlay),this.dirtyLayers.add(e.LayerType.UI),this.dirtyLayers.add(e.LayerType.Hover),this.running&&!this.animFrameId&&this.scheduleFrame()}start(){this.running=!0,this.markAllDirty()}stop(){this.running=!1,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}scheduleFrame(){this.animFrameId=requestAnimationFrame(()=>{if(this.animFrameId=0,!(!this.running||!this.callback)&&this.dirtyLayers.size>0){let e=this.dirtyLayers;this.dirtyLayers=this.swapLayers,this.callback(e),e.clear(),this.swapLayers=e}})}},i=class{observer=null;callback=null;currentDpr=1;resizeScheduled=!1;cachedSize;constructor(e){this.container=e,this.currentDpr=window.devicePixelRatio||1,this.cachedSize={width:e.clientWidth,height:e.clientHeight}}getDpr(){return this.currentDpr}getContainerSize(){return this.cachedSize}readContainerSize(){let e=this.container.clientWidth,t=this.container.clientHeight;return(e!==this.cachedSize.width||t!==this.cachedSize.height)&&(this.cachedSize={width:e,height:t}),this.cachedSize}onResize(e){this.callback=e,this.observer=new ResizeObserver(()=>{this.resizeScheduled||(this.resizeScheduled=!0,requestAnimationFrame(()=>{this.resizeScheduled=!1,this.currentDpr=window.devicePixelRatio||1;let e=this.container.clientWidth,t=this.container.clientHeight;e===this.cachedSize.width&&t===this.cachedSize.height||(this.cachedSize={width:e,height:t},this.callback?.(this.cachedSize,this.currentDpr))}))}),this.observer.observe(this.container)}destroy(){this.observer?.disconnect(),this.observer=null,this.callback=null}};function a(e,t){return e*(t.barWidth+t.barSpacing)-t.offset+t.chartRect.x+t.barWidth/2}function o(e,t){let{min:n,max:r}=t.priceRange,{y:i,height:a}=t.chartRect,o;if(t.logScale&&n>0&&r>0){let t=Math.log(n),s=Math.log(r)-t;if(s===0)return i+a/2;o=(Math.log(Math.max(e,2**-52))-t)/s}else{let t=r-n;if(t===0)return i+a/2;o=(e-n)/t}return i+a*(t.invertScale?o:1-o)}function s(e){let{min:t,max:n}=e.priceRange,{y:r,height:i}=e.chartRect,a=e.invertScale===!0;if(e.logScale&&t>0&&n>0){let e=Math.log(t),o=Math.log(n)-e;if(o===0)return()=>r+i/2;let s=i/o,c=r+i;return a?t=>r+(Math.log(Math.max(t,2**-52))-e)*s:t=>c-(Math.log(Math.max(t,2**-52))-e)*s}let o=n-t;if(o===0)return()=>r+i/2;let s=i/o;return a?e=>r+(e-t)*s:e=>r+(n-e)*s}function c(e,t,n,r){let{min:i,max:a}=n.priceRange,o=(a-i)/t,s=r(i+e*o),c=r(i+(e+1)*o);return{top:Math.min(s,c),height:Math.abs(s-c),mid:(s+c)/2}}function l(e,t){let n=t.barWidth+t.barSpacing;return Math.round((e-t.chartRect.x-t.barWidth/2+t.offset)/n)}function u(e,t){let{min:n,max:r}=t.priceRange,i=(e-t.chartRect.y)/t.chartRect.height,a=t.invertScale?i:1-i;if(t.logScale&&n>0&&r>0){let e=Math.log(n);return Math.exp(e+(Math.log(r)-e)*a)}return n+(r-n)*a}var d=new WeakMap;function f(e){let t=e.length;if(t<2)return 0;let n=d.get(e);if(n&&n.length===t)return n.step;let r=[];for(let n=Math.max(1,t-20);n<t;n++)r.push(e[n].time-e[n-1].time);r.sort((e,t)=>e-t);let i=Math.max(0,r[r.length>>1]);return d.set(e,{length:t,step:i}),i}function p(e){let t=f(e);return(e.length>0?e[e.length-1].time:0)>0xe8d4a51000?t:t*1e3}function m(e,t){let n=t.length;if(n===0)return e;let r=n-1;if(e>r)return t[r].time+(e-r)*f(t);if(e<0)return t[0].time+e*f(t);let i=Math.floor(e);return i===e||i>=r?t[i].time:t[i].time+(e-i)*(t[i+1].time-t[i].time)}function h(e,t){if(t.length===0)return-1;let n=t[0].time,r=t.length-1,i=t[r].time;if(e<=n||e>=i){if(e===n)return 0;if(e===i)return r;let a=f(t);return a<=0?e<n?0:r:e<n?(e-n)/a:r+(e-i)/a}let a=0,o=t.length-1;for(;a<=o;){let n=a+o>>>1;if(t[n].time===e)return n;t[n].time<e?a=n+1:o=n-1}if(a>=t.length)return t.length-1;if(o<0)return 0;let s=t[o].time,c=t[a].time,l=c===s?0:(e-s)/(c-s);return o+l}function g(e,t){let n=t.data;return n&&n.length>0?h(e,n):e}function _(e,t){return a(g(e,t),t)}function v(e,t){let n=l(e,t),r=t.data;return r&&r.length>0?m(n,r):n}function y(t,n,r,i){let a=n.scaleMode??(n.logScale?`logarithmic`:`regular`);return(a===`percentage`||a===`indexedTo100`)&&n.scaleBaseline?(0,e.formatPriceScaleLabel)(t,a,n.scaleBaseline,r,i):n.formatPrice?n.formatPrice(t):(0,e.formatPriceScaleLabel)(t,`regular`,void 0,r,i)}function b(e,t){if(!t||!(t>0)||e>=1)return e;let n=t;for(;n<e;)n*=2;return n}var x=12,S=class{locale=`en-US`;reservedPrice=null;setReservedPriceProvider(e){this.reservedPrice=e}setLocale(e){this.locale=e}render(t,n,r,i=`right`){let{chartRect:a,priceRange:c}=n,l=i===`left`,u=l?a.x:a.x+a.width;if(c.max-c.min<=0)return;let d=s(n);t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(u+.5,a.y),t.lineTo(u+.5,a.y+a.height),t.stroke(),t.globalAlpha=1;let f=b((0,e.computeTickStep)(c.min,c.max,8),n.priceUnit),p=Math.ceil(c.min/f)*f,m=(0,e.autoPricePrecision)(c.min,c.max),h=`500 ${r.font.sizeSmall}px ${r.font.family}`,g=[],_=l?null:this.reservedPrice?.()??null,v=_===null?null:o(_,n);for(let e=p;e<=c.max;e+=f){let t=d(e);v!==null&&Math.abs(t-v)<x||g.push({y:t,text:y(e,n,m,this.locale)})}t.font=h,t.textBaseline=`middle`,t.textAlign=l?`right`:`left`,t.strokeStyle=r.axisLine,t.globalAlpha=.45,t.beginPath();let S=l?-1:1;for(let{y:e}of g)t.moveTo(u+S,e+.5),t.lineTo(u+4*S,e+.5);t.stroke(),t.globalAlpha=1,t.fillStyle=r.axisLabel;for(let{y:e,text:n}of g)t.fillText(n,u+8*S,e)}};function C(e,t,n,r,i,a){let o=a.shape?.tagRadius,s=typeof o==`number`&&Number.isFinite(o)?Math.max(0,Math.min(o,i/2,r/2)):0;if(!(s>0)){e.fillRect(t,n,r,i);return}e.beginPath(),e.moveTo(t+s,n),e.lineTo(t+r-s,n),e.arcTo(t+r,n,t+r,n+s,s),e.lineTo(t+r,n+i-s),e.arcTo(t+r,n+i,t+r-s,n+i,s),e.lineTo(t+s,n+i),e.arcTo(t,n+i,t,n+i-s,s),e.lineTo(t,n+s),e.arcTo(t,n,t+s,n,s),e.closePath(),e.fill()}function w(e){let t=Math.abs(e);return t>=1e3?1:t>=1?2:t>=.01?4:6}var T=16;function E(e,t,n,r=16){let i=r/2,a=e.map(e=>Math.min(Math.max(e,t+i),n-i));for(let e=1;e<a.length;e++)a[e]=Math.max(a[e],a[e-1]+r);a.length>0&&(a[a.length-1]=Math.min(a[a.length-1],n-i));for(let e=a.length-2;e>=0;e--)a[e]=Math.min(a[e],a[e+1]-r);if(a.length>0&&a[0]<t+i){a[0]=t+i;for(let e=1;e<a.length;e++)a[e]=Math.max(a[e],a[e-1]+r)}return a}function D(e){let t=O(e);if(!t)return`#ffffff`;let[n,r,i]=t;return(.299*n+.587*r+.114*i)/255>.62?`#10131a`:`#ffffff`}function O(e){let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(t){let e=t[1].length===3?t[1].replace(/./g,e=>e+e):t[1];return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let n=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(e.trim());return n?[Number(n[1]),Number(n[2]),Number(n[3])]:null}function k(e,t,n,r,i,a){let o=t.filter(e=>e.y>=i.top&&e.y<=i.bottom).sort((e,t)=>e.y-t.y);if(o.length===0)return;let s=E(o.map(e=>e.y),i.top,i.bottom);e.save(),e.font=`bold ${a.font.sizeSmall}px ${a.font.family}`,e.textBaseline=`middle`,e.textAlign=`left`;for(let t=0;t<o.length;t++){let c=o[t],l=s[t];if(l+8>i.bottom+.5)break;let u=Math.min(e.measureText(c.text).width+10,r-2);e.fillStyle=c.color,C(e,n+1,Math.round(l-8),u,16,a),e.fillStyle=D(c.color),e.fillText(c.text,n+5,Math.round(l))}e.restore()}var A=20,ee=8;function te(e){return e<1?Math.ceil(-Math.log10(e))+1:+(e<10)}var ne=class{layerManager;renderLoop;dprManager;renderCtx=null;sceneLayer;topLayer;onContainerResize=null;constructor(e){this.layerManager=new n(e),this.renderLoop=new r,this.dprManager=new i(e),this.layerManager.createLayers(),this.cacheLayerRefs(),this.renderLoop.setCallback(e=>this.render(e)),this.dprManager.onResize((e,t)=>{this.layerManager.resize(e,t),this.renderLoop.markAllDirty(),this.onContainerResize?.(e)});let t=this.dprManager.getContainerSize(),a=this.dprManager.getDpr();this.layerManager.resize(t,a)}cacheLayerRefs(){this.sceneLayer=this.layerManager.getLayer(e.LayerType.Main),this.topLayer=this.layerManager.getLayer(e.LayerType.Hover)}setRenderContext(e){this.renderCtx=e}start(){this.renderLoop.start()}stop(){this.renderLoop.stop()}requestRender(e){e===void 0?this.renderLoop.markAllDirty():this.renderLoop.markDirty(e)}render(t){let n=this.renderCtx;if(!n)return;let{chartRect:r}=n.viewport;if(r.width<=0||r.height<=0)return;let i=!1;for(let n of t)if(n!==e.LayerType.Hover){i=!0;break}i&&this.sceneLayer&&this.renderScene(this.sceneLayer,n),this.topLayer&&this.renderTop(this.topLayer,n)}renderScene(e,t){let{viewport:n,theme:r,data:i}=t;e.clear();let a=e.ctx;t.gridRenderer?.render(a,n,r),t.sessionShading?.render(a,i,n,r),t.sessionBreaks?.render(a,n,r,i),t.watermark?.render(a,n,r),a.save(),a.beginPath(),a.rect(n.chartRect.x,n.chartRect.y,n.chartRect.width,n.chartRect.height),a.clip(),t.depthHeatmap?.render(a,n,r),t.volumeRenderer?.render(a,i,n,r),t.volumeProfile?.render(a,i,n,r),t.marketProfile?.render(a,i,n,r),t.chartRenderer?.render(a,i,n,r),t.compareRenderer?.render(a,i,n,r),t.indicatorEngine?.renderOverlays(a,n,t.leftViewport??void 0),t.periodLevels?.render(a,i,n,r),t.pivotMarkers?.render(a,i,n,r),t.renderOverlayPlugins?.(a,`main`),a.restore(),this.renderPanels(a,t),t.priceLimits&&this.renderPriceLimits(a,n,r,t.priceLimits),t.tradeZoneManager?.render(a,n,r),t.drawingRenderer?.render(a,n),t.tradingRenderer?.render(a,n,r),t.signalMarkerManager?.render(a,n,r),t.alertManager?.render(a,n,r),t.priceLines?.render(a,n,r,i),t.priceAxis?.render(a,n,r),t.indicatorValueLabels!==!1&&this.renderOverlayValueLabels(a,t),t.leftViewport&&(t.leftPriceAxis?.render(a,t.leftViewport,r,`left`),t.indicatorValueLabels!==!1&&this.renderLeftValueLabels(a,t,t.leftViewport)),t.tradingRenderer?.renderAxisBadges(a,n,r),t.priceLines?.renderAxisTags(a,n,r,i),t.currentPriceLine?.render(a,n,r),t.timeAxis?.render(a,n,r,i,t.timeAxisY),this.renderPanelAxes(a,t)}renderTop(e,t){let{viewport:n,theme:r,data:i}=t;e.clear();let a=e.ctx;t.measureOverlay?.render(a,n,r),t.selectionBoxOverlay?.render(a,n,r),t.crosshairHandler?.render(a,n,r),t.renderOverlayPlugins?.(a,`overlay`),this.renderPanelCrosshair(a,t),t.crosshairHandler?.renderAxisLabels(a,n,r,i,t.timeAxisY),t.priceAxisAddButton?.render(a,n,r,t.crosshairHandler?.getPosition()??null),t.chartLegend?.render(a,n,r,i),t.barCountdown?.render(a,n,r,i),t.renderOverlayPlugins?.(a,`ui`),this.renderPanelHoverValues(a,t)}renderPanels(e,t){let{theme:n}=t,r=t.panels,i=t.indicatorEngine;if(!i||r.length===0)return;let a=`10px ${n.font.family}`,o=this.panelDescriptors(i);for(let s of r){if(s.rect.width<=0||s.rect.height<=0)continue;e.save(),e.beginPath(),e.rect(s.rect.x,s.rect.y,s.rect.width,s.rect.height),e.clip(),e.fillStyle=n.background,e.fillRect(s.rect.x,s.rect.y,s.rect.width,s.rect.height),e.fillStyle=n.axisLine,e.fillRect(s.rect.x,s.rect.y,s.rect.width,3),e.fillStyle=n.textSecondary,e.font=a,e.textBaseline=`top`,e.textAlign=`left`;let r=o.get(s.instanceId);r&&t.paneTitles!==!1&&e.fillText(r.descriptor.name,s.rect.x+6,s.rect.y+6),e.save(),e.beginPath(),e.rect(s.rect.x,s.rect.y+A,s.rect.width,s.rect.height-A),e.clip();let c=s.members?.length?[s.instanceId,...s.members]:[s.instanceId];for(let t of c)i.isVisible(t)&&this.renderLevels(e,i.getLevels(t),s.viewport,n);for(let t of c)i.renderPanel(e,t,s.viewport);e.restore(),e.restore()}}renderOverlayValueLabels(t,n){let r=n.indicatorEngine?.getLatestOverlayValues();if(!r?.length)return;let{viewport:i,theme:a}=n,{chartRect:s}=i,c=n.formatPrice??(t=>(0,e.formatPrice)(t,2,n.numberLocale??`en-US`));k(t,r.map(e=>({y:o(e.value,i),text:c(e.value),color:e.color})),s.x+s.width,i.priceAxisWidth??e.PRICE_AXIS_WIDTH,{top:s.y,bottom:s.y+s.height},a)}renderLeftValueLabels(t,n,r){let i=n.indicatorEngine?.getLatestOverlayValues(`left`);if(!i?.length)return;let{chartRect:a}=r,s=n.leftAxisWidth??e.PRICE_AXIS_WIDTH,c=(0,e.autoPricePrecision)(r.priceRange.min,r.priceRange.max),l=n.numberLocale??`en-US`;k(t,i.map(t=>({y:o(t.value,r),text:(0,e.formatPrice)(t.value,c,l),color:t.color})),a.x-s,s,{top:a.y,bottom:a.y+a.height},n.theme)}renderLevels(e,t,n,r){if(t.length===0)return;let{chartRect:i}=n;e.save(),e.strokeStyle=r.axisLabel,e.globalAlpha=.45,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath();for(let r of t){let t=Math.round(o(r,n))+.5;e.moveTo(i.x,t),e.lineTo(i.x+i.width,t)}e.stroke(),e.restore()}renderPanelAxes(t,n){let{theme:r}=n,i=n.numberLocale??`en-US`,a=`${r.font.sizeSmall}px ${r.font.family}`;for(let s of n.panels){let c=s.viewport,l=s.rect,{min:u,max:d}=c.priceRange;if(d-u<=0||l.height<=0||c.chartRect.height<ee)continue;let f=l.x+l.width,p=c.chartRect;t.strokeStyle=r.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(f+.5,l.y),t.lineTo(f+.5,l.y+l.height),t.stroke();let m=(0,e.computeTickStep)(u,d,4),h=Math.ceil(u/m)*m,g=te(m);t.font=a,t.textBaseline=`middle`,t.textAlign=`left`;for(let e=h;e<=d;e+=m){let n=Math.abs(e)<m*1e-6?0:e,a=o(n,c);a<p.y||a>p.y+p.height||(t.strokeStyle=r.axisLine,t.beginPath(),t.moveTo(f,Math.round(a)+.5),t.lineTo(f+4,Math.round(a)+.5),t.stroke(),t.fillStyle=r.axisLabel,t.fillText(y(n,c,g,i),f+6,a))}let _=n.indicatorValueLabels===!1?null:[s.instanceId,...s.members??[]].flatMap(e=>n.indicatorEngine?.getLatestValues(e)??[]);_?.length&&k(t,_.map(t=>({y:o(t.value,c),text:c.scaleMode===`percentage`&&c.scaleBaseline?y(t.value,c,2,i):(0,e.formatPrice)(t.value,w(t.value),i),color:t.color})),f,n.viewport.priceAxisWidth??e.PRICE_AXIS_WIDTH,{top:p.y,bottom:p.y+p.height},r)}}renderPanelCrosshair(e,t){let n=t.crosshairHandler?.getPosition();if(!n||t.panels.length===0)return;let{theme:r}=t;for(let i of t.panels){let o=i.rect;if(n.x<o.x||n.x>o.x+o.width||n.y<o.y||n.y>o.y+o.height)continue;let s=i.viewport;if(s.chartRect.height<ee)continue;let c=l(n.x,s),u=a(Math.max(0,Math.min((t.data?.length??1)-1,Math.round(c))),s);e.save(),e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip(),e.setLineDash([4,4]),e.strokeStyle=r.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(u)+.5,o.y),e.lineTo(Math.round(u)+.5,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(o.x,Math.round(n.y)+.5),e.lineTo(o.x+o.width,Math.round(n.y)+.5),e.stroke(),e.setLineDash([]),e.restore();break}}renderPanelHoverValues(t,n){let r=n.crosshairHandler?.getPosition(),i=n.indicatorEngine;if(!r||n.panels.length===0)return;let{theme:a,viewport:o,data:s}=n,c=n.numberLocale??`en-US`,d=`${a.font.sizeSmall}px ${a.font.family}`,f=i?this.panelDescriptors(i):null;for(let p of n.panels){let m=p.viewport,h=p.rect,{min:g,max:_}=m.priceRange;if(_-g<=0||h.height<=0||m.chartRect.height<ee)continue;let v=h.x+h.width,b=te((0,e.computeTickStep)(g,_,4));if(r.x>=h.x&&r.x<=h.x+h.width&&r.y>=h.y&&r.y<=h.y+h.height){let n=y(u(r.y,m),m,b,c);t.font=`bold ${a.font.sizeSmall}px ${a.font.family}`;let i=t.measureText(n).width,s=Math.min(i+10,(o.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2);t.fillStyle=a.crosshair,C(t,v+1,r.y-9,s,18,a),t.fillStyle=a.background,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(n,v+5,r.y)}if(!i||n.paneTitles===!1)continue;let x=Math.max(0,Math.min((s?.length??1)-1,Math.round(l(r.x,m)))),S=i.getOutput(p.instanceId),w=S?.series&&x<S.series.length?S.series[x]:null;if(!w)continue;let T=f?.get(p.instanceId),E=T?.descriptor.plots,D=[];if(E)for(let e of E){let t=w[e.key];t!==void 0&&Number.isFinite(t)&&D.push(`${e.title} ${y(t,m,b,c)}`)}else for(let e in w){let t=w[e];t!==void 0&&D.push(`${e}: ${t.toFixed(b)}`)}if(D.length===0)continue;t.font=d;let O=T?t.measureText(T.descriptor.name).width+14:10;t.fillStyle=a.textSecondary,t.textBaseline=`top`,t.textAlign=`left`,t.fillText(D.join(` `),h.x+O,h.y+6)}}panelDescriptors(e){let t=new Map;for(let n of e.getPanelIndicators())t.set(n.instanceId,n);return t}renderPriceLimits(t,n,r,i){let{chartRect:a}=n,s=[{price:i.ceiling,color:i.colors?.ceiling??`#FF00FF`,label:`CE`},{price:i.floor,color:i.colors?.floor??`#00FFFF`,label:`FL`},{price:i.reference,color:i.colors?.reference??`#FFD700`,label:`REF`}],c=`bold 9px ${r.font.family}`,l=`10px ${r.font.family}`;for(let{price:i,color:u,label:d}of s){let s=o(i,n);if(s<a.y||s>a.y+a.height)continue;t.setLineDash([8,4]),t.strokeStyle=u,t.lineWidth=1,t.beginPath(),t.moveTo(a.x,Math.round(s)+.5),t.lineTo(a.x+a.width,Math.round(s)+.5),t.stroke(),t.setLineDash([]),t.font=c,t.fillStyle=u,t.textBaseline=`bottom`,t.textAlign=`left`,t.fillText(`${d} ${n.formatPrice?.(i)??i.toFixed(2)}`,a.x+4,s-2);let f=a.x+a.width+1;t.fillStyle=u,C(t,f,s-7,(n.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2,14,r),t.fillStyle=`#000`,t.font=l,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(n.formatPrice?.(i)??i.toFixed(2),f+4,s)}}destroy(){this.renderLoop.stop(),this.dprManager.destroy(),this.layerManager.destroy()}},re=.25,ie=class{state;priceAxisWidth=e.PRICE_AXIS_WIDTH;stateCache=null;dataLength=0;minBarWidth;maxBarWidth;rightMarginBars;freePan=!0;minVisibleBars=3;constructor(t,n,r=2,i=30,a=5){this.minBarWidth=r,this.maxBarWidth=i,this.rightMarginBars=a;let o=this.computeChartRect(t,n);this.state={visibleRange:{from:0,to:0},priceRange:{min:0,max:1},barWidth:e.DEFAULT_BAR_WIDTH,barSpacing:e.DEFAULT_BAR_SPACING,offset:0,chartRect:o}}getState(){return this.stateCache||={visibleRange:{...this.state.visibleRange},priceRange:{...this.state.priceRange},barWidth:this.state.barWidth,barSpacing:this.state.barSpacing,offset:this.state.offset,chartRect:{...this.state.chartRect},logScale:this.state.logScale,scaleMode:this.state.scaleMode,scaleBaseline:this.state.scaleBaseline,invertScale:this.state.invertScale,priceAxisWidth:this.state.priceAxisWidth,formatPrice:this.state.formatPrice,priceUnit:this.state.priceUnit},this.stateCache}invalidate(){this.stateCache=null}setLogScale(e){this.setScaleMode(e?`logarithmic`:`regular`)}isLogScale(){return(this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`))===`logarithmic`}setScaleMode(e){this.state.scaleMode=e,this.state.logScale=e===`logarithmic`,this.invalidate()}getScaleMode(){return this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`)}setInvertScale(e){this.state.invertScale=e,this.invalidate()}isInvertScale(){return this.state.invertScale===!0}setPriceFormat(e,t=null){this.state.formatPrice=e??void 0,this.state.priceUnit=t??void 0,this.invalidate()}setScaleBaseline(e){this.state.scaleBaseline=e,this.invalidate()}setRightMargin(e){this.rightMarginBars=e}getRightMargin(){return this.rightMarginBars}setPanLimits(e){e.freePan!==void 0&&(this.freePan=e.freePan),e.minVisibleBars!==void 0&&(this.minVisibleBars=Math.max(1,Math.floor(e.minVisibleBars))),this.clampOffset(),this.updateVisibleRange()}endOffset(){let e=this.state.barWidth+this.state.barSpacing;return this.dataLength*e-this.state.chartRect.width+this.rightMarginBars*e}setPriceAxisWidth(e){this.priceAxisWidth!==e&&(this.priceAxisWidth=e,this.state.priceAxisWidth=e,this.invalidate())}computeChartRect(t,n){return{x:0,y:0,width:Math.max(0,t-this.priceAxisWidth),height:Math.max(0,n-e.TIME_AXIS_HEIGHT)}}resize(e,t){this.state.chartRect=this.computeChartRect(e,t),this.invalidate(),this.clampUnit(),this.clampOffset()}setChartRect(e){this.state.chartRect={x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height)},this.invalidate(),this.clampUnit(),this.clampOffset(),this.updateVisibleRange()}floorUnit(){return this.minBarWidth+e.DEFAULT_BAR_SPACING}minUnit(){let e=this.floorUnit(),t=this.state.chartRect.width,n=this.dataLength+this.rightMarginBars;return t<=0||n<=0?e:Math.max(re,Math.min(e,t/n))}maxUnit(){return this.maxBarWidth+e.DEFAULT_BAR_SPACING}applyUnit(t){let n=this.floorUnit();if(t>=n)this.state.barWidth=t-e.DEFAULT_BAR_SPACING,this.state.barSpacing=e.DEFAULT_BAR_SPACING;else{let e=this.minBarWidth/n;this.state.barWidth=t*e,this.state.barSpacing=t-this.state.barWidth}this.invalidate()}clampUnit(){let t=this.state.barWidth+this.state.barSpacing,n=(0,e.clamp)(t,this.minUnit(),this.maxUnit());n===t||t<=0||(this.state.offset=this.state.offset/t*n,this.applyUnit(n))}updateData(t,n){let r=this.dataLength===0;this.dataLength=t.length,this.dataLength!==0&&(this.clampUnit(),r&&(this.state.offset=this.endOffset()),this.clampOffset(),this.updateVisibleRange(),n&&(this.state.priceRange=(0,e.computePriceRange)(t,this.state.visibleRange.from,Math.min(this.state.visibleRange.to,this.dataLength-1),.08),this.invalidate()))}prependBars(e){e===0||!Number.isFinite(e)||(this.dataLength+=e,this.state.offset+=e*(this.state.barWidth+this.state.barSpacing),this.invalidate(),this.updateVisibleRange())}setPriceRange(e,t){this.state.priceRange={min:e,max:t},this.invalidate()}scalePriceRange(e){if(!Number.isFinite(e)||e<=0)return;let{min:t,max:n}=this.state.priceRange,r=(t+n)/2,i=(n-t)/2,a=Math.max(i*e,1e-9);this.state.priceRange={min:r-a,max:r+a},this.invalidate()}scrollBy(e){this.state.offset+=e,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}panPriceRange(e){let t=this.state.chartRect.height;if(t<=0||e===0)return;let{min:n,max:r}=this.state.priceRange,i=(this.state.invertScale?-e:e)/t;if(this.isLogScale()&&n>0&&r>0){let e=Math.log(n),t=Math.log(r),a=(t-e)*i;this.state.priceRange={min:Math.exp(e-a),max:Math.exp(t-a)},this.invalidate();return}let a=(r-n)*i;this.state.priceRange={min:n-a,max:r-a},this.invalidate()}isAtEnd(){let e=this.state.barWidth+this.state.barSpacing;return Math.abs(this.state.offset-this.endOffset())<=e*2}scrollToEnd(){this.state.offset=this.endOffset(),this.invalidate(),this.updateVisibleRange()}zoom(t,n){let r=this.state.barWidth+this.state.barSpacing,i=this.state.barWidth*(1+t),a=(0,e.clamp)(r>=this.floorUnit()&&i>=this.minBarWidth?i+e.DEFAULT_BAR_SPACING:r*(1+t),this.minUnit(),this.maxUnit());if(a===r)return;let o=this.isAtEnd(),s=(this.state.offset+n)/r;this.applyUnit(a),this.state.offset=o?this.endOffset():s*a-n,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}zoomToBarRange(t,n){let r=this.state.chartRect.width;if(r<=0||!Number.isFinite(t)||!Number.isFinite(n)||n<t)return;let i=(0,e.clamp)(r/(n-t+1),this.minUnit(),this.maxUnit());this.applyUnit(i),this.state.offset=(t+n+1)/2*i-r/2,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}clampOffset(){if(this.state.chartRect.width<=0)return;let t=this.state.barWidth+this.state.barSpacing,n=this.state.chartRect.width,r=this.endOffset(),i,a;if(this.freePan&&this.dataLength>0){let e=Math.min(this.minVisibleBars,this.dataLength);i=e*t-n,a=(this.dataLength-e)*t,i=Math.min(i,r),a=Math.max(a,r)}else if(r>0)i=-(n*.5),a=r;else{let e=n*.5;i=r-e,a=r+e}this.state.offset=(0,e.clamp)(this.state.offset,i,a),this.invalidate()}updateVisibleRange(){let e=this.state.barWidth+this.state.barSpacing;if(e<=0||this.state.chartRect.width<=0)return;let t=Math.floor(this.state.offset/e),n=Math.ceil(this.state.chartRect.width/e)+1,r=Math.min(t+n,this.dataLength-1);this.state.visibleRange={from:Math.max(0,t),to:Math.max(0,r)},this.invalidate()}};function ae(t,n){return(0,e.sliceVisibleData)(t,n.visibleRange.from,n.visibleRange.to)}var oe=[`1D`,`5D`,`1M`,`3M`,`6M`,`YTD`,`1Y`,`5Y`,`All`],se=864e5,ce=6e4,le={"1M":1,"3M":3,"6M":6,"1Y":12,"5Y":60};function ue(e,t){let n=new Date(e),r=n.getUTCFullYear(),i=n.getUTCMonth()+t,a=new Date(Date.UTC(r,i+1,0)).getUTCDate();return Date.UTC(r,i,Math.min(n.getUTCDate(),a),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}function de(t,n,r=0){if(t===`All`)return null;if(t===`1D`)return n-se;if(t===`5D`)return n-5*se;let i=n+(0,e.offsetAt)(r,n)*ce;return t===`YTD`?(0,e.wallToUtc)(Date.UTC(new Date(i).getUTCFullYear(),0,1),r):(0,e.wallToUtc)(ue(i,-(le[t]??0)),r)}var fe=1;function j(e){return e.barWidth<1}function pe(e,t,n,r,i){let a=Math.min(n,e.length-1);if(t>a)return;let o={x:0,open:0,high:0,low:0,close:0,volume:0},s=!1;for(let n=Math.max(0,t);n<=a;n++){let t=e[n],a=Math.floor(r(n));s&&a!==o.x&&(i(o),s=!1),s?(t.high>o.high&&(o.high=t.high),t.low<o.low&&(o.low=t.low),t.volume>o.volume&&(o.volume=t.volume)):(o.x=a,o.open=t.open,o.high=t.high,o.low=t.low,o.volume=t.volume,s=!0),o.close=t.close}s&&i(o)}function me(e,t,n,r,i){let{from:a,to:o}=n.visibleRange,c=n.barWidth+n.barSpacing,l=-n.offset+n.chartRect.x+n.barWidth/2,u=s(n),d=new Path2D,f=new Path2D;pe(t,a,o,e=>e*c+l,e=>{let t=e.close>=e.open?d:f,n=e.x+.5,r=u(e.high),i=u(e.low);t.moveTo(n,Math.min(r,i)-.5),t.lineTo(n,Math.max(r,i,Math.min(r,i)+1)+.5)}),e.lineWidth=1,e.strokeStyle=r,e.stroke(d),e.strokeStyle=i,e.stroke(f)}var he=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;if(j(n)){me(e,t,n,r.candleUp,r.candleDown);return}let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=m(n.high),a=m(n.low),s=m(n.open),l=m(n.close),u=n.close>=n.open,d=u?h:g;d.moveTo(r,i),d.lineTo(r,a);let f=Math.min(s,l),y=Math.max(Math.abs(l-s),1);(u?_:v).rect(r-c,f,o,y)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(h),e.strokeStyle=r.candleDownWick,e.stroke(g),e.fillStyle=r.candleUp,e.fill(_),e.fillStyle=r.candleDown,e.fill(v)}};function ge(e,t,n){if(t>=e){let t=Array(Math.max(0,e));for(let n=0;n<e;n++)t[n]=n;return t}if(t<=2)return e>=2?[0,e-1]:e===1?[0]:[];let r=[0],i=(e-2)/(t-2),a=0;for(let o=0;o<t-2;o++){let t=Math.floor((o+1)*i)+1,s=Math.floor((o+2)*i)+1;s>e&&(s=e);let c=0,l=0,u=0;for(let e=t;e<s;e++)c+=e,l+=n(e),u++;if(u>0)c/=u,l/=u;else{let r=Math.min(t,e-1);c=r,l=n(r)}let d=Math.floor(o*i)+1,f=Math.floor((o+1)*i)+1,p=n(a),m=-1,h=d;for(let e=d;e<f;e++){let t=Math.abs((a-c)*(n(e)-p)-(a-e)*(l-p));t>m&&(m=t,h=e)}r.push(h),a=h}return r.push(e-1),r}var _e=64;function ve(e,t,n,r,i){let a=Math.max(0,e),o=Math.min(t,n-1);if(o<a)return[];let s=o-a+1,c=Math.max(_e,Math.ceil(r*2));if(s<=c){let e=Array(s);for(let t=0;t<s;t++)e[t]=a+t;return e}let l=ge(s,c,e=>i(a+e));for(let e=0;e<l.length;e++)l[e]+=a;return l}var ye=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,c=-n.offset+n.chartRect.x+n.barWidth/2,{min:l,max:u}=n.priceRange;if(u-l===0)return;let d=s(n);e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let f=ve(i,a,t.length,n.chartRect.width,e=>t[e].close),p=!1;for(let n of f){let r=n*o+c,i=d(t[n].close);p?e.lineTo(r,i):(e.moveTo(r,i),p=!0)}e.stroke()}},be=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth+n.barSpacing,c=-n.offset+n.chartRect.x+n.barWidth/2,{min:l,max:u}=n.priceRange;if(u-l===0)return;let d=s(n),f=d(l),p=ve(i,a,t.length,n.chartRect.width,e=>t[e].close);if(p.length===0)return;let m=p[0],h=m*o+c,g=d(t[m].close),_=e.createLinearGradient(0,d(u),0,f);_.addColorStop(0,r.areaTopColor),_.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(h,f),e.lineTo(h,g);let v=h;for(let n=1;n<p.length;n++){let r=p[n];v=r*o+c,e.lineTo(v,d(t[r].close))}e.lineTo(v,f),e.closePath(),e.fillStyle=_,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`,e.moveTo(h,g);for(let n=1;n<p.length;n++){let r=p[n];e.lineTo(r*o+c,d(t[r].close))}e.stroke()}},xe=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;if(j(n)){me(e,t,n,r.candleUp,r.candleDown);return}let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open?h:g,a=m(n.high),o=m(n.low),s=m(n.open),l=m(n.close);i.moveTo(r,a),i.lineTo(r,o),i.moveTo(r-c,s),i.lineTo(r,s),i.moveTo(r,l),i.lineTo(r+c,l)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(h),e.strokeStyle=r.candleDown,e.stroke(g)}},Se=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;if(j(n)){me(e,t,n,r.candleUp,r.candleDown);return}let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D,_=[],v=[],y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open,a=e===0||n.close>=t[e-1].close,s=m(n.high),l=m(n.low),u=m(n.open),d=m(n.close),f=Math.min(u,d),x=Math.max(Math.abs(d-u),1),S=a?h:g;S.moveTo(r,s),S.lineTo(r,l),i?(a?_:v).push({x:r-c,y:f,w:o,h:x}):(a?y:b).rect(r-c,f,o,x)}e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(h),e.strokeStyle=r.candleDown,e.stroke(g),e.fillStyle=r.candleUp,e.fill(y),e.fillStyle=r.candleDown,e.fill(b),e.lineWidth=1.5,e.strokeStyle=r.candleUp;for(let t of _)e.strokeRect(t.x,t.y,t.w,t.h);e.strokeStyle=r.candleDown;for(let t of v)e.strokeRect(t.x,t.y,t.w,t.h)}},Ce=class{baselinePrice=null;setBaseline(e){this.baselinePrice=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=m(this.baselinePrice??this.computeBaseline(t,i,a)),{chartRect:g}=n,_=[],v=[];for(let e=i;e<=a&&e<t.length;e++)_.push(p(e)),v.push(m(t[e].close));if(_.length<2)return;let y=_.length-1;e.save();let b=m(f),x=m(d),S=new Path2D;S.rect(g.x,Math.min(h,b),g.width,Math.abs(b-h)),e.clip(S);let C=new Path2D;C.moveTo(_[0],h);for(let e=0;e<=y;e++)C.lineTo(_[e],v[e]);C.lineTo(_[y],h),C.closePath(),e.fillStyle=`${r.candleUp}20`,e.fill(C),e.restore(),e.save();let w=new Path2D;w.rect(g.x,Math.min(h,x),g.width,Math.abs(x-h)),e.clip(w);let T=new Path2D;T.moveTo(_[0],h);for(let e=0;e<=y;e++)T.lineTo(_[e],v[e]);T.lineTo(_[y],h),T.closePath(),e.fillStyle=`${r.candleDown}20`,e.fill(T),e.restore();let E=new Path2D,D=new Path2D;for(let e=1;e<=y;e++){let t=(n.invertScale?v[e]>=h:v[e]<=h)?E:D;t.moveTo(_[e-1],v[e-1]),t.lineTo(_[e],v[e])}e.lineWidth=2,e.strokeStyle=r.candleUp,e.stroke(E),e.strokeStyle=r.candleDown,e.stroke(D),e.setLineDash([6,4]),e.strokeStyle=r.textSecondary,e.lineWidth=1;let O=new Path2D;O.moveTo(g.x,h),O.lineTo(g.x+g.width,h),e.stroke(O),e.setLineDash([])}computeBaseline(e,t,n){let r=0,i=0;for(let a=t;a<=n&&a<e.length;a++)r+=e[a].close,i++;return i>0?r/i:0}},we=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open,a=m(Math.max(n.open,n.close)),s=m(Math.min(n.open,n.close)),l=Math.min(a,s),u=Math.max(Math.abs(s-a),1),d=r-c;i?(h.rect(d,l,o,u),_.rect(d,l,o,u)):(g.rect(d,l,o,u),v.rect(d,l,o,u))}e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g),e.lineWidth=1,e.strokeStyle=r.candleUp,e.stroke(_),e.strokeStyle=r.candleDown,e.stroke(v)}},Te=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=s(n),h=new Path2D,g=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=p(e),i=n.close>=n.open,o=m(n.high),s=m(n.low),c=i?h:g;if(c.moveTo(r,o),c.lineTo(r,s),e<a&&e+1<t.length){let t=p(e+1),n=i?s:o;c.moveTo(r,n),c.lineTo(t,n)}}e.strokeStyle=r.candleUp,e.lineWidth=3,e.stroke(h),e.strokeStyle=r.candleDown,e.lineWidth=1,e.stroke(g)}},Ee=class{boxSize=1;setBoxSize(e){this.boxSize=e}render(e,t,n,r){let{from:i,to:a}=n.visibleRange,o=n.barWidth,c=o/2,l=o+n.barSpacing,u=-n.offset+n.chartRect.x+c,{min:d,max:f}=n.priceRange,p=f-d;if(p===0)return;let m=n.chartRect.height/p,h=e=>e*l+u,g=s(n),_=Math.abs(this.boxSize*m),v=Math.min(c*.8,_*.8)*.5,y=new Path2D,b=new Path2D;for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=h(e),i=n.close>=n.open,a=n.high,o=n.low,s=Math.max(1,Math.round((a-o)/this.boxSize));for(let e=0;e<s;e++){let t=g(o+(e+.5)*this.boxSize);i?(y.moveTo(r-v,t-v),y.lineTo(r+v,t+v),y.moveTo(r+v,t-v),y.lineTo(r-v,t+v)):(b.moveTo(r+v,t),b.arc(r,t,v,0,Math.PI*2))}}e.lineWidth=1.5,e.strokeStyle=r.candleUp,e.stroke(y),e.strokeStyle=r.candleDown,e.stroke(b)}},De=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:c}=n.priceRange;if(c-o===0||i>a||t.length===0)return;if(j(n)){me(e,t,n,r.candleUp,r.candleDown);return}let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.barWidth,f=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>f&&(f=t[e].volume);f===0&&(f=1);let p=new Path2D,m=new Path2D,h=new Path2D,g=new Path2D,_=e=>e*l+u,v=s(n);for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=_(e),i=v(n.high),a=v(n.low),o=v(n.open),s=v(n.close),c=n.close>=n.open,l=d*Math.max(.2,n.volume/f),u=l/2,y=c?p:m;y.moveTo(r,i),y.lineTo(r,a);let b=Math.min(o,s),x=Math.max(Math.abs(s-o),1);(c?h:g).rect(r-u,b,l,x)}e.strokeStyle=r.candleUpWick,e.lineWidth=1,e.stroke(p),e.strokeStyle=r.candleDownWick,e.stroke(m),e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g)}},Oe=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange,{min:o,max:c}=n.priceRange;if(c-o===0||i>a||t.length===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=n.barWidth,f=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>f&&(f=t[e].volume);f===0&&(f=1);let p=new Path2D,m=new Path2D,h=new Path2D,g=new Path2D,_=e=>e*l+u,v=s(n);for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e>0?t[e-1]:n,i=_(e),a=v(n.high),o=v(n.low),s=n.close>=r.close,c=d*Math.max(.15,n.volume/f),l=c/2,u=Math.min(a,o),y=Math.max(Math.abs(o-a),1),b=s?p:m,x=s?h:g;b.rect(i-l,u,c,y),x.rect(i-l,u,c,y)}e.fillStyle=ke(r.candleUp,.55),e.fill(p),e.fillStyle=ke(r.candleDown,.55),e.fill(m),e.lineWidth=1,e.strokeStyle=r.candleUpWick,e.stroke(h),e.strokeStyle=r.candleDownWick,e.stroke(g)}};function ke(e,t){if(e.startsWith(`#`)){let n=Math.round(Math.max(0,Math.min(1,t))*255).toString(16).padStart(2,`0`);if(e.length===7)return`${e}${n}`;if(e.length===9)return`${e.slice(0,7)}${n}`}return e}var Ae=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:c}=n.priceRange;if(c-o===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=e=>e*l+u,f=s(n),p=[],m=[];for(let e=i;e<=a&&e<t.length;e++){let n=d(e);p.push({x:n,y:f(t[e].high)}),m.push({x:n,y:f(t[e].low)})}if(p.length===0)return;let h=e.createLinearGradient(0,f(c),0,f(o));h.addColorStop(0,r.areaTopColor),h.addColorStop(1,r.areaBottomColor),e.beginPath(),e.moveTo(p[0].x,p[0].y);for(let t=1;t<p.length;t++)e.lineTo(p[t].x,p[t].y);for(let t=m.length-1;t>=0;t--)e.lineTo(m[t].x,m[t].y);e.closePath(),e.fillStyle=h,e.fill(),e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;for(let n=i;n<=a&&n<t.length;n++){let r=d(n),a=f(t[n].close);n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke()}},je=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:c}=n.priceRange;if(c-o===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=e=>e*l+u,f=s(n);e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`miter`;let p=0;for(let n=i;n<=a&&n<t.length;n++){let r=d(n),a=f(t[n].close);n===i?e.moveTo(r,a):(e.lineTo(r,p),e.lineTo(r,a)),p=a}e.stroke()}},Me=class{render(e,t,n,r){let{from:i,to:a}=n.visibleRange;if(i>a||t.length===0)return;let{min:o,max:c}=n.priceRange;if(c-o===0)return;let l=n.barWidth+n.barSpacing,u=-n.offset+n.chartRect.x+n.barWidth/2,d=e=>e*l+u,f=s(n);e.beginPath(),e.strokeStyle=r.lineColor,e.lineWidth=2,e.lineJoin=`round`;let p=[];for(let n=i;n<=a&&n<t.length;n++){let r=d(n),a=f(t[n].close);p.push({x:r,y:a}),n===i?e.moveTo(r,a):e.lineTo(r,a)}e.stroke();let m=Math.max(2,Math.min(4,n.barWidth*.3)),h=new Path2D;for(let{x:e,y:t}of p)h.moveTo(e+m,t),h.arc(e,t,m,0,Math.PI*2);e.fillStyle=r.lineColor,e.fill(h),e.strokeStyle=r.background,e.lineWidth=1,e.stroke(h)}},Ne=28,Pe=3,Fe=class{priceText=null;setPriceText(e){this.priceText=e}render(t,n,r,i){let{from:a,to:o}=r.visibleRange,{min:c,max:l}=r.priceRange;if(l===c)return;if(j(r)){me(t,n,r,i.candleUp,i.candleDown);return}let u=r.barWidth+r.barSpacing,d=-r.offset+r.chartRect.x+r.barWidth/2,f=s(r),p=Math.max(1,Math.round(r.barWidth*.6)),m=r.barWidth>=Ne,h=(0,e.autoPricePrecision)(c,l),g=t=>r.formatPrice?.(t)??this.priceText?.(t)??(0,e.formatPrice)(t,h);m&&(t.font=`${i.font.sizeSmall}px ${i.font.family}`,t.textAlign=`center`);for(let e=Math.max(0,a);e<=o&&e<n.length;e++){let r=n[e],a=e*u+d,o=Math.min(f(r.high),f(r.low)),s=Math.max(f(r.high),f(r.low));if(t.fillStyle=r.close>=r.open?i.candleUp:i.candleDown,t.fillRect(Math.round(a-p/2),o,p,Math.max(1,s-o)),!m)continue;let c=f(r.high)<=f(r.low);t.textBaseline=`bottom`,t.fillText(g(c?r.high:r.low),a,o-Pe),t.textBaseline=`top`,t.fillText(g(c?r.low:r.high),a,s+Pe)}}},Ie=class{visible=!0;heightRatio=.2;setVisible(e){this.visible=e}setHeightRatio(e){this.heightRatio=Math.max(.05,Math.min(.5,e))}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o}=n,s=n.barWidth,c=s/2,l=s+n.barSpacing,u=-n.offset+o.x+c,d=0;for(let e=i;e<=a&&e<t.length;e++)t[e].volume>d&&(d=t[e].volume);if(d===0)return;let f=o.height*this.heightRatio,p=o.y+o.height,m=f/d,h=new Path2D,g=new Path2D;if(j(n))pe(t,i,a,e=>e*l+u,e=>{let t=e.volume*m;(e.close>=e.open?h:g).rect(e.x,p-t,1,t)});else for(let e=i;e<=a&&e<t.length;e++){let n=t[e],r=e*l+u,i=n.volume*m;(n.close>=n.open?h:g).rect(r-c,p-i,s,i)}e.globalAlpha=.35,e.fillStyle=r.candleUp,e.fill(h),e.fillStyle=r.candleDown,e.fill(g),e.globalAlpha=1}},Le=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;highlightPoC=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setHighlightPoC(e){this.highlightPoC=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:l}=n,u=l.max-l.min;if(u<=0)return;let d=new Float64Array(this.buckets),f=new Float64Array(this.buckets),p=new Float64Array(this.buckets);for(let e=i;e<=a&&e<t.length;e++){let n=t[e];if(n.volume<=0)continue;let r=Math.max(n.low,l.min),i=Math.min(n.high,l.max);if(i<=r)continue;let a=(r-l.min)/u,o=(i-l.min)/u,s=Math.max(0,Math.floor(a*this.buckets)),c=Math.min(this.buckets-1,Math.floor(o*this.buckets)),m=Math.max(1,c-s+1),h=n.volume/m,g=n.close>=n.open;for(let e=s;e<=c;e++)d[e]+=h,g?f[e]+=h:p[e]+=h}let m=0,h=-1;for(let e=0;e<d.length;e++)d[e]>m&&(m=d[e],h=e);if(m===0)return;let g=o.width*this.widthRatio,_=o.x+o.width,v=s(n),y=1/m;e.save(),e.globalAlpha=this.opacity;for(let t=0;t<this.buckets;t++){let i=d[t];if(i===0)continue;let a=c(t,this.buckets,n,v),s=i*y*g,l=f[t]*y*g,u=p[t]*y*g;l>0&&(e.fillStyle=r.candleUp,e.fillRect(_-l,a.top+.5,l,a.height-1)),u>0&&(e.fillStyle=r.candleDown,e.fillRect(_-s,a.top+.5,u,a.height-1)),this.highlightPoC&&t===h&&(e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(o.x,a.mid+.5),e.lineTo(_-s-2,a.mid+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=this.opacity)}e.restore()}};function Re(e,t){return e<0?0:e>t?t:e}function ze(e,t,n,r={}){let i=Math.max(4,Math.min(500,Math.floor(r.buckets??48))),a=n-t;if(a<=0||e.length===0)return null;let o=a/i,s=new Float64Array(i);for(let r of e){let e=Math.min(r.low,r.high),a=Math.max(r.low,r.high);if(a<t||e>n)continue;let c=Re(Math.floor((e-t)/o),i-1),l=Re(Math.floor((a-t)/o),i-1);for(let e=c;e<=l;e++)s[e]+=1}let c=0,l=0,u=0;for(let e=0;e<i;e++)u+=s[e],s[e]>l&&(l=s[e],c=e);if(u===0)return null;let d=u*(r.valueAreaPct??.7),f=c,p=c,m=s[c];for(;m<d&&(f>0||p<i-1);){let e=f>0?s[f-1]:-1;(p<i-1?s[p+1]:-1)>=e?(p+=1,m+=s[p]):(--f,m+=s[f])}let h=[];for(let e=0;e<i;e++){let n=t+e*o;h.push({low:n,high:n+o,mid:n+o/2,count:s[e]})}return{buckets:h,pocIndex:c,maxCount:l,totalCount:u,valueAreaLow:t+f*o,valueAreaHigh:t+(p+1)*o}}function Be(e){let t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(97+t-26)}function Ve(e,t,n,r=48){let i=Math.max(4,Math.min(500,Math.floor(r))),a=n-t,o=Array.from({length:i},()=>[]);if(a<=0)return o;let s=a/i;return e.forEach((e,r)=>{let a=Math.min(e.low,e.high),c=Math.max(e.low,e.high);if(c<t||a>n)return;let l=Math.max(0,Math.min(i-1,Math.floor((a-t)/s))),u=Math.max(0,Math.min(i-1,Math.floor((c-t)/s)));for(let e=l;e<=u;e++)o[e].push(r)}),o}function He(t,n,r,i={}){if(t.length===0||r-n<=0)return[];let a=[],o=0,s=(0,e.timeframeBucketStart)(t[0].time,`1d`),c=(e,o,s)=>{let c=ze(t.slice(e,o+1),n,r,i);c&&a.push({startIndex:e,endIndex:o,startTime:s,profile:c})};for(let n=1;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,`1d`);r!==s&&(c(o,n-1,s),o=n,s=r)}return c(o,t.length-1,s),a}var Ue=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;valueAreaPct=.7;highlightPoC=!0;showStats=!0;splitBySession=!1;letters=!1;lastStats=null;setVisible(e){this.visible=e,e||(this.lastStats=null)}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setValueAreaPct(e){this.valueAreaPct=Math.max(.3,Math.min(.95,e))}setHighlightPoC(e){this.highlightPoC=e}setShowStats(e){this.showStats=e}setSplitBySession(e){this.splitBySession=e}isSplitBySession(){return this.splitBySession}setLetters(e){this.letters=e}getStats(){return this.lastStats}render(e,t,n,r){if(!this.visible||t.length===0)return;let{from:i,to:a}=n.visibleRange,{chartRect:o,priceRange:l}=n,u=Math.max(0,i),d=Math.min(a,t.length-1);if(d<u)return;let f=t.slice(u,d+1);if(this.splitBySession){this.lastStats=null,this.renderSplit(e,f,u,n,r);return}let p=ze(f,l.min,l.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(!p){this.lastStats=null;return}let m=p.buckets[p.pocIndex].mid;this.lastStats={poc:m,vah:p.valueAreaHigh,val:p.valueAreaLow,valueAreaPct:this.valueAreaPct};let h=p.buckets.length,g=o.width*this.widthRatio,_=o.x,v=s(n),y=1/p.maxCount;e.save();for(let t=0;t<h;t++){let i=p.buckets[t];if(i.count===0)continue;let a=c(t,h,n,v),o=i.count*y*g,s=i.mid>=p.valueAreaLow&&i.mid<=p.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?r.candleUp:r.textSecondary,e.fillRect(_,a.top+.5,o,a.height-1)}e.globalAlpha=.6,e.strokeStyle=r.candleUp,e.lineWidth=1,e.setLineDash([1,3]);for(let t of[p.valueAreaHigh,p.valueAreaLow]){let n=v(t);e.beginPath(),e.moveTo(_,Math.round(n)+.5),e.lineTo(o.x+o.width,Math.round(n)+.5),e.stroke()}if(e.setLineDash([]),this.highlightPoC){let t=v(m);e.globalAlpha=1,e.strokeStyle=r.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(_,Math.round(t)+.5),e.lineTo(o.x+o.width,Math.round(t)+.5),e.stroke(),e.setLineDash([])}this.showStats&&this.drawStats(e,o.x+6,o.y+6,m,p.valueAreaHigh,p.valueAreaLow,r),e.restore()}renderSplit(e,t,n,r,i){let{chartRect:o,priceRange:l}=r,u=He(t,l.min,l.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(u.length===0)return;let d=s(r),f=r.barWidth/2;e.save();for(let s of u){let u=s.profile,p=u.buckets.length,m=o.height/p,h=a(n+s.startIndex,r)-f,g=a(n+s.endIndex,r)+f,_=Math.max(2,g-h),v=1/u.maxCount,y=this.letters&&m>=7,b=y?Ve(t.slice(s.startIndex,s.endIndex+1),l.min,l.max,this.buckets):null;if(y&&b){e.font=`${Math.min(11,Math.floor(m))}px ui-monospace, monospace`,e.textBaseline=`middle`,e.textAlign=`left`;let t=Math.max(1,Math.floor(_/6));for(let n=0;n<p;n++){let a=b[n];if(a.length===0)continue;let o=c(n,p,r,d).mid,s=u.buckets[n].mid>=u.valueAreaLow&&u.buckets[n].mid<=u.valueAreaHigh;e.globalAlpha=s?.95:.6,e.fillStyle=s?i.candleUp:i.textSecondary;let l=Math.min(a.length,t);for(let t=0;t<l;t++)e.fillText(Be(a[t]),h+t*6,o)}}else for(let t=0;t<p;t++){let n=u.buckets[t];if(n.count===0)continue;let a=c(t,p,r,d),o=n.count*v*_,s=n.mid>=u.valueAreaLow&&n.mid<=u.valueAreaHigh;e.globalAlpha=s?Math.min(1,this.opacity+.18):this.opacity,e.fillStyle=s?i.candleUp:i.textSecondary,e.fillRect(h,a.top+.5,o,a.height-1)}if(this.highlightPoC){let t=d(u.buckets[u.pocIndex].mid);e.globalAlpha=1,e.strokeStyle=i.crosshair,e.lineWidth=1,e.setLineDash([3,2]),e.beginPath(),e.moveTo(h,Math.round(t)+.5),e.lineTo(Math.min(g,o.x+o.width),Math.round(t)+.5),e.stroke(),e.setLineDash([])}}e.restore()}drawStats(e,t,n,r,i,a,o){let s=We(r),c=[[`POC`,r.toFixed(s),o.crosshair],[`VAH`,i.toFixed(s),o.candleUp],[`VAL`,a.toFixed(s),o.candleUp]];e.globalAlpha=1,e.font=`600 10px ${o.font.family}`,e.textBaseline=`middle`;let l=0;for(let[,t]of c)l=Math.max(l,e.measureText(t).width);let u=38+l,d=6+c.length*14;e.fillStyle=o.background,e.globalAlpha=.82,Ge(e,t,n,u,d,4),e.fill(),e.globalAlpha=1,c.forEach(([r,i,a],s)=>{let c=n+6/2+14/2+s*14;e.fillStyle=a,e.textAlign=`left`,e.fillText(r,t+6,c),e.fillStyle=o.text,e.textAlign=`right`,e.fillText(i,t+u-6,c)}),e.textAlign=`left`}};function We(e){let t=Math.abs(e);return t>=1e3?2:t>=1?4:6}function Ge(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function Ke(t,n){let r=n===`day`?`1d`:`1w`,i=[];for(let n of t){let t=(0,e.timeframeBucketStart)(n.time,r),a=i[i.length-1];a&&a.key===t?(a.high=Math.max(a.high,n.high),a.low=Math.min(a.low,n.low),a.close=n.close):i.push({key:t,open:n.open,high:n.high,low:n.low,close:n.close})}return i}function qe(e,t=`day`){let n=Ke(e,t);if(n.length<2)return[];let r=n[n.length-2],i=n[n.length-1],a=t===`day`?`D`:`W`;return[{id:`p${a}h`,label:`P${a}H`,price:r.high},{id:`p${a}c`,label:`P${a}C`,price:r.close},{id:`p${a}l`,label:`P${a}L`,price:r.low},{id:`open`,label:t===`day`?`Day Open`:`Week Open`,price:i.open}]}var Je=class{visible=!1;period=`day`;setVisible(e){this.visible=e}isVisible(){return this.visible}setPeriod(e){this.period=e}getPeriod(){return this.period}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=qe(t,this.period);if(i.length===0)return;let{chartRect:a}=n,s=a.y,c=a.y+a.height;e.save(),e.font=`600 10px ${r.font.family}`,e.textBaseline=`middle`;for(let t of i){let i=o(t.price,n);if(i<s||i>c)continue;let l=Ye(t,r);e.strokeStyle=l,e.globalAlpha=.7,e.lineWidth=1,e.setLineDash([5,4]),e.beginPath(),e.moveTo(a.x,Math.round(i)+.5),e.lineTo(a.x+a.width,Math.round(i)+.5),e.stroke(),e.setLineDash([]),e.globalAlpha=1;let u=t.label,d=e.measureText(u).width,f=a.x+a.width-d-10;e.fillStyle=r.background,e.globalAlpha=.85,C(e,f-4,i-7,d+8,14,r),e.globalAlpha=1,e.fillStyle=l,e.textAlign=`left`,e.fillText(u,f,i+.5)}e.restore()}};function Ye(e,t){return e.id.endsWith(`h`)?t.candleUp:e.id.endsWith(`l`)?t.candleDown:t.textSecondary}function Xe(e){let t,n;return e.map(e=>{let r;return e.type===`high`?(r=t===void 0||e.price>t?`HH`:`LH`,t=e.price):(r=n===void 0||e.price<n?`LL`:`HL`,n=e.price),{...e,label:r}})}function Ze(e,t=5,n=5){let r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),a=[];for(let t=r;t<e.length-i;t++){let n=e[t].high,o=e[t].low,s=!0,c=!0;for(let a=t-r;a<=t+i&&!(a!==t&&(e[a].high>=n&&(s=!1),e[a].low<=o&&(c=!1),!s&&!c));a++);s?a.push({index:t,price:n,type:`high`}):c&&a.push({index:t,price:o,type:`low`})}return a}var Qe=class{visible=!1;left=5;right=5;showLabels=!1;structureLabels=!1;setVisible(e){this.visible=e}isVisible(){return this.visible}setStrength(e,t){this.left=Math.max(1,Math.floor(e)),this.right=Math.max(1,Math.floor(t))}setShowLabels(e){this.showLabels=e}setStructureLabels(e){this.structureLabels=e}render(e,t,n,r){if(!this.visible||t.length===0)return;let i=Ze(t,this.left,this.right);if(i.length===0)return;let s=this.structureLabels?Xe(i):i,{from:c,to:l}=n.visibleRange;e.save(),e.font=`10px ${r.font.family}`,e.textAlign=`center`;for(let t of s){if(t.index<c-1||t.index>l+1)continue;let i=a(t.index,n),s=o(t.price,n),u=t.type===`high`,d=u?r.candleDown:r.candleUp,f=u!==(n.invertScale===!0),p=f?s-8:s+8;e.fillStyle=d,e.beginPath(),f?(e.moveTo(i-5,p-5),e.lineTo(i+5,p-5),e.lineTo(i,p)):(e.moveTo(i-5,p+5),e.lineTo(i+5,p+5),e.lineTo(i,p)),e.closePath(),e.fill();let m=this.structureLabels&&`label`in t?String(t.label):this.showLabels?n.formatPrice?.(t.price)??$e(t.price):null;m&&(e.textBaseline=f?`bottom`:`top`,e.fillText(m,i,f?p-5-1:p+5+1))}e.restore()}};function $e(e){let t=Math.abs(e);return t>=1e3||t>=1?e.toFixed(2):e.toPrecision(4)}var et=class{buffer=[];constructor(e=240){this.capacity=e,this.capacity=Math.max(1,Math.floor(e))}push(e,t){let n={time:e,bids:t.bids.map(e=>({...e})),asks:t.asks.map(e=>({...e}))},r=this.buffer[this.buffer.length-1];r&&r.time===e?this.buffer[this.buffer.length-1]=n:(this.buffer.push(n),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity)))}snapshots(){return this.buffer}maxVolume(){let e=0;for(let t of this.buffer){for(let n of t.bids)n.volume>e&&(e=n.volume);for(let n of t.asks)n.volume>e&&(e=n.volume)}return e}setCapacity(e){this.capacity=Math.max(1,Math.floor(e)),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}clear(){this.buffer=[]}get size(){return this.buffer.length}},tt=class{buffer=new et(240);visible=!1;opacity=.7;setVisible(e){this.visible=e}isVisible(){return this.visible}setOpacity(e){this.opacity=Math.max(.1,Math.min(1,e))}setCapacity(e){this.buffer.setCapacity(e)}push(e,t){this.buffer.push(e,t)}clear(){this.buffer.clear()}render(e,t,n){if(!this.visible)return;let r=this.buffer.snapshots();if(r.length===0)return;let i=this.buffer.maxVolume();if(i<=0)return;let a=1/i,{chartRect:o}=t,s=Math.max(2,t.barWidth+t.barSpacing),c=o.x,l=o.x+o.width,u=o.y,d=o.y+o.height;e.save();for(let i of r){let r=_(i.time,t);if(r<c-s||r>l+s)continue;let o=r-s/2;this.drawSide(e,i.bids,n.candleUp,o,s,t,a,u,d),this.drawSide(e,i.asks,n.candleDown,o,s,t,a,u,d)}e.restore()}drawSide(e,t,n,r,i,a,s,c,l){if(t.length===0)return;let u=nt(t,a);e.fillStyle=n;for(let n of t){let t=o(n.price,a);t<c-u||t>l+u||(e.globalAlpha=Math.min(1,Math.sqrt(n.volume*s))*this.opacity,e.fillRect(r,t-u/2,i,u))}e.globalAlpha=1}};function nt(e,t){if(e.length<2)return 3;let n=e.map(e=>e.price).sort((e,t)=>e-t),r=[];for(let e=1;e<n.length;e++){let t=n[e]-n[e-1];t>0&&r.push(t)}if(r.length===0)return 3;r.sort((e,t)=>e-t);let i=r[Math.floor(r.length/2)],a=Math.abs(o(n[0],t)-o(n[0]+i,t));return Math.max(2,Math.min(a,12))}var rt=class{series=new Map;set(t,n){if(!n||n.length===0){this.series.delete(t);return}let r=[...n].sort((t,n)=>(0,e.normalizeBarTime)(t.time)-(0,e.normalizeBarTime)(n.time)),i=r.map(t=>(0,e.normalizeBarTime)(t.time)),a=i[i.length-1],o=i.length>1?a-i[i.length-2]:0;this.series.set(t,{bars:r,times:i,end:a+o})}has(e){return this.series.has(e)}get(e){return this.series.get(e)?.bars}symbols(){return[...this.series.keys()]}closeAt(t,n){let r=this.series.get(t);if(!r)return;let i=(0,e.normalizeBarTime)(n),{times:a,bars:o}=r;if(i<a[0])return;let s=a.length-1;if(i>a[s]&&(r.end<=a[s]||i>=r.end))return;let c=0,l=s;for(;c<l;){let e=c+l+1>>1;a[e]<=i?c=e:l=e-1}return o[c].close}},it=class{symbols=new Map;mode=`percent`;store=new rt;aligned=new Map;setMode(e){this.mode=e}getMode(){return this.mode}addSymbol(e){this.symbols.set(e.id,e),this.store.set(e.id,e.data),this.aligned.delete(e.id)}removeSymbol(e){this.symbols.delete(e),this.store.set(e,null),this.aligned.delete(e)}setSymbolData(e,t){let n=this.symbols.get(e);n&&(n.data=t,this.store.set(e,t),this.aligned.delete(e))}setSymbolVisible(e,t){let n=this.symbols.get(e);n&&(n.visible=t)}getSymbols(){return Array.from(this.symbols.values())}clear(){for(let e of this.symbols.keys())this.store.set(e,null);this.symbols.clear(),this.aligned.clear()}getPriceRange(e,t){let n=1/0,r=-1/0;for(let i of this.symbols.values()){if(!i.visible||i.data.length===0)continue;let a=this.line(i,e,t);if(a)for(let e=a.from;e<=a.to;e++){let t=a.priceAt(e);t!==null&&(t<n&&(n=t),t>r&&(r=t))}}return n<=r?{min:n,max:r}:null}render(e,t,n,r){if(this.symbols.size===0||t.length===0)return;let{chartRect:i}=n;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let r of this.symbols.values())!r.visible||r.data.length===0||this.renderSymbol(e,r,t,n);e.restore()}closesOn(e,t){let n=t.length>0?t[t.length-1].time:NaN,r=this.aligned.get(e.id);if(r&&r.main===t&&r.data===e.data&&r.length===t.length&&r.lastTime===n)return r.closes;let i=new Float64Array(t.length);for(let n=0;n<t.length;n++)i[n]=this.store.closeAt(e.id,t[n].time)??NaN;return this.aligned.set(e.id,{main:t,data:e.data,length:t.length,lastTime:n,closes:i}),i}line(e,t,n){let r=this.closesOn(e,t),i=Math.max(0,n.visibleRange.from),a=Math.min(t.length-1,n.visibleRange.to),o=-1;for(let e=i;e<=a;e++)if(Number.isFinite(r[e])&&r[e]!==0&&t[e].close!==0){o=e;break}if(o<0)return null;let s=t[o].close,c=r[o],l=this.mode===`percent`;return{from:o,to:a,priceAt:e=>{let t=r[e];return Number.isFinite(t)?l?t/c*s:t:null}}}renderSymbol(e,t,n,r){let i=this.line(t,n,r);if(!i)return;e.strokeStyle=t.color,e.lineWidth=t.lineWidth??1.5,e.lineJoin=`round`,e.beginPath();let s=0,c=null;for(let t=i.from;t<=i.to;t++){let n=i.priceAt(t);if(n===null)continue;let l=a(t,r),u=o(n,r);s===0?e.moveTo(l,u):e.lineTo(l,u),(s===2||s===0&&c===null)&&(c={x:l+4,y:u-4}),s++}e.stroke(),c&&(e.fillStyle=t.color,e.font=`bold 10px sans-serif`,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(t.label,c.x,c.y))}};function at(e){if(e.length===0)return[];let t=[],n=e[0].open,r=(e[0].open+e[0].high+e[0].low+e[0].close)/4;for(let i=0;i<e.length;i++){let a=e[i],o=(a.open+a.high+a.low+a.close)/4,s=i===0?a.open:(n+r)/2,c=Math.max(a.high,s,o),l=Math.min(a.low,s,o);t.push({time:a.time,open:s,high:c,low:l,close:o,volume:a.volume}),n=s,r=o}return t}function ot(e,t){if(e.length===0)return[];let n=t.brickSize;t.useATR&&e.length>2&&(n=st(e,t.atrPeriod??14)),n>0||(n=Math.abs(e[e.length-1].close)/100||1);let r=[],i=Math.round(e[0].close/n)*n,a=e[0].time;for(let t=1;t<e.length;t++){let o=e[t].close-i,s=Math.floor(Math.abs(o)/n);if(s>=1){let c=o>0?1:-1;for(let o=0;o<s;o++){let o=i;i+=c*n,r.push({time:a++,open:o,high:Math.max(o,i),low:Math.min(o,i),close:i,volume:e[t].volume/s})}}}return r}function st(e,t){let n=e.length-1,r=Math.max(1,n-t),i=0;for(let t=r;t<n;t++)i+=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));let a=n>r?i/(n-r):0;if(!(a>0))return 0;let o=10**(Math.floor(Math.log10(a))-1);return Math.round(a/o)*o}function ct(e,t=3){if(e.length===0)return[];let n=[],r=0;n.push({time:r++,open:e[0].open,high:Math.max(e[0].open,e[0].close),low:Math.min(e[0].open,e[0].close),close:e[0].close,volume:e[0].volume});for(let i=1;i<e.length;i++){let a=e[i].close,o=n[n.length-1],s=o.close>=o.open,c=Math.min(t,n.length),l=-1/0,u=1/0;for(let e=n.length-c;e<n.length;e++)l=Math.max(l,n[e].high),u=Math.min(u,n[e].low);s&&a>o.close?n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume}):!s&&a<o.close||s&&a<u?n.push({time:r++,open:o.close,high:o.close,low:a,close:a,volume:e[i].volume}):!s&&a>l&&n.push({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume})}return n}function lt(e,t=4,n=`percent`){if(e.length<2)return e.slice();let r=[],i=e[1].close>=e[0].close?1:-1,a=e[0].close,o=e[0].close,s=e[0].close,c=0;for(let l=1;l<e.length;l++){let u=e[l].close,d=n===`price`?t:t/100*s;i===1?(u>a&&(a=u),a-u>=d&&(r.push({time:c++,open:s,high:a,low:s,close:a,volume:e[l].volume}),i=-1,s=a,o=u,a=u)):(u<o&&(o=u),u-o>=d&&(r.push({time:c++,open:s,high:s,low:o,close:o,volume:e[l].volume}),i=1,s=o,a=u,o=u))}return i===1?r.push({time:c,open:s,high:a,low:s,close:a,volume:0}):r.push({time:c,open:s,high:s,low:o,close:o,volume:0}),r}function ut(e,t,n=3){if(e.length===0||t<=0)return[];let r=[],i=0,a=0,o=0,s=0,c=Math.round(e[0].close/t)*t;a=c,o=c,i=1;for(let c=1;c<e.length;c++){let l=e[c].close,u=Math.round(l/t)*t;i===1?u>a?a=u:a-u>=t*n&&(r.push({time:s++,open:o,high:a,low:o,close:a,volume:e[c].volume}),i=-1,o=u,a-=t):u<o?o=u:u-o>=t*n&&(r.push({time:s++,open:a,high:a,low:o,close:o,volume:e[c].volume}),i=1,a=u,o+=t)}return r.push({time:s,open:i===1?o:a,high:a,low:o,close:i===1?a:o,volume:0}),r}function dt(e,t){if(e.length===0||t.rangeSize<=0)return[];let n=[],r=e[0].time,i=e[0].open,a=i,o=i,s=0,c=(e,c)=>{for(e>a&&(a=e),e<o&&(o=e),s+=c;a-o>=t.rangeSize;){let c=e>=i,l=c?i+t.rangeSize:i-t.rangeSize;n.push({time:r++,open:i,high:c?l:i,low:c?i:l,close:l,volume:s}),i=l,a=l,o=l,s=0}};for(let t of e){let e=t.close>=t.open?[t.low,t.high,t.close]:[t.high,t.low,t.close],n=t.volume/e.length;for(let t of e)c(t,n)}return n}var ft=.1;function pt(e){return e.plots?e.plots.map(e=>e.key):null}function mt(e,t){return e.tone?e.tone===`sign`?(t[e.key]??0)>=0:t[e.tone.field]===1:!0}function ht(e,t,n){let r=t.colors[e.color]??t.colors[0];return!e.tone||e.downColor===void 0||!n||mt(e,n)?r:t.colors[e.downColor]??r}function gt(e,t,n,r){let{lo:i,hi:a}=vt(e,t,n,r.keys),o=r.scale,s=o?.min,c=o?.max;if(i===1/0){if(s===void 0&&c===void 0)return null;i=s??0,a=c??i+1}else{let e=a-i||Math.abs(a)||1;i-=e*ft,a+=e*ft}for(let e of r.levels??[])e<i&&(i=e),e>a&&(a=e);return(r.zero||o?.zero)&&(i>0&&(i=0),a<0&&(a=0)),s!==void 0&&(i=s),c!==void 0&&(a=c),a>i||(a=i+1),{min:i,max:a}}function _t(e,t,n,r){let{lo:i,hi:a}=vt(e,t,n,r.keys),o=e=>e!==void 0&&e>0,s=o(r.scale?.min)?r.scale?.min:void 0,c=o(r.scale?.max)?r.scale?.max:void 0;if(i===1/0){if(s===void 0||c===void 0)return null;i=s,a=c}else{if(!(i>0))return!1;let e=Math.exp((Math.log(a/i)||Math.LN2/4)*ft);i/=e,a*=e}for(let e of r.levels??[])e>0&&(e<i&&(i=e),e>a&&(a=e));return s!==void 0&&(i=s),c!==void 0&&(a=c),a>i?{min:i,max:a}:null}function vt(e,t,n,r){let i=1/0,a=-1/0,o=e=>{e===void 0||!Number.isFinite(e)||(e<i&&(i=e),e>a&&(a=e))},s=e=>{if(e){if(r){for(let t=0;t<r.length;t++)o(e[r[t]]);return}for(let t in e)o(e[t])}},c=e?.series;if(c){let e=Math.min(n,c.length-1);for(let n=Math.max(0,t);n<=e;n++)s(c[n])}else if(e){let r=0;for(let i of e.values.values()){if(r>n)break;r>=t&&s(i),r++}}return{lo:i,hi:a}}function yt(e){return!!e?.some(e=>e.kind===`histogram`)}function bt(e,t,n,r,i){let a=t.series;if(!a)return;let o=Math.max(0,n.visibleRange.from),c=Math.min(n.visibleRange.to,a.length-1);if(c<o)return;let l=s(n);for(let t=0;t<i.length;t++){let s=i[t],u=r.lineWidths[t]??r.lineWidths[0]??1.5,d=s.kind??`line`,f=s.tone&&s.downColor!==void 0?[!0,!1]:[null];for(let t of f){let i=r.colors[s.color]??r.colors[0],f=t===!1?r.colors[s.downColor]??i:i,p=e=>t===null||mt(s,e)===t;d===`histogram`?wt(e,a,s.key,o,c,n,l,f,p):d===`dots`?Ct(e,a,s.key,o,c,n,l,f,p):St(e,a,s.key,o,c,n,l,f,u,d===`step`,t===null?null:p)}}}function xt(e,t){let n=e?.[t];return n!==void 0&&Number.isFinite(n)?n:void 0}function St(e,t,n,r,i,o,s,c,l,u,d){e.beginPath(),e.strokeStyle=c,e.lineWidth=l,e.lineJoin=`round`;let f=0,p=0,m=!1;for(let c=r;c<=i;c++){let r=t[c],i=xt(r,n);if(i===void 0){m=!1;continue}let l=a(c,o),h=s(i);d?m&&d(r)&&(e.moveTo(f,p),u&&e.lineTo(l,p),e.lineTo(l,h)):m?(u&&e.lineTo(l,p),e.lineTo(l,h)):e.moveTo(l,h),f=l,p=h,m=!0}e.stroke()}function Ct(e,t,n,r,i,o,s,c,l){let u=Math.max(1.5,o.barWidth*.15);e.beginPath(),e.fillStyle=c;for(let c=r;c<=i;c++){let r=t[c],i=xt(r,n);if(i===void 0||!l(r))continue;let d=a(c,o),f=s(i);e.moveTo(d+u,f),e.arc(d,f,u,0,Math.PI*2)}e.fill()}function wt(e,t,n,r,i,o,s,c,l){let u=Math.max(1,o.barWidth),d=s(0);e.beginPath(),e.fillStyle=c;for(let c=r;c<=i;c++){let r=t[c],i=xt(r,n);if(i===void 0||!l(r))continue;let f=a(c,o),p=s(i);e.rect(f-u/2,Math.min(p,d),u,Math.max(1,Math.abs(p-d)))}e.fill()}var M=class{canResume(e,t,n){let r=t.series;if(!r||n<=0||n>r.length||r.length>e.length)return!1;for(let i=n;i<r.length;i++)if(r[i]&&!t.values.has(e[i].time))return!1;return!0}writePoint(e,t,n,r){e.series[n]=r,r?e.values.set(t[n].time,r):e.values.delete(t[n].time)}render(e,t,n,r){this.descriptor.plots&&bt(e,t,n,r,this.descriptor.plots)}drawLine(e,t,n,r){if(!(t.length<2)){e.beginPath(),e.strokeStyle=n,e.lineWidth=r,e.lineJoin=`round`,e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);e.stroke()}}drawBand(e,t,n,r){if(!(t.length<2||n.length<2)){e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x,n[t].y);e.closePath(),e.fillStyle=r,e.fill()}}drawHistogram(e,t,n){let r=n/2;for(let i of t){e.fillStyle=i.color;let t=Math.min(i.y,i.baseY),a=Math.abs(i.y-i.baseY);e.fillRect(i.x-r,t,n,Math.max(a,1))}}valuesToPoints(e,t,n,r){let i=[],{from:s,to:c}=r.visibleRange;for(let l=s;l<=c&&l<n.length;l++){let s=e.values.get(n[l].time);s&&s[t]!==void 0&&i.push({x:a(l,r),y:o(s[t],r)})}return i}};function Tt(e){let t=e.inputs;if(!t)return null;for(let e in t)if(t[e]?.source)return e;return null}function Et(t,n){let r=Tt(t);if(!r)return{kind:`bars`};let i=n[r],a=(0,e.parseIndicatorSource)(i);return a?{kind:`line`,...a}:(0,e.isPriceSource)(i)&&i!==`close`?{kind:`price`,source:i}:{kind:`bars`}}function Dt(t,n,r=null,i=0){let a=r&&i>0&&i<=r.length?r:[],o=a===r?i:0;a.length=t.length;for(let r=o;r<t.length;r++){let i=t[r];a[r]={...i,close:(0,e.sourcePrice)(i,n)}}return a}function Ot(e,t,n){if(!t)return null;let r=-1;for(let i=0;i<e.length&&i<t.length;i++){let e=t[i]?.[n];if(e!==void 0&&Number.isFinite(e)){r=i;break}}if(r<0)return null;let i=Array(e.length-r),a=t[r][n];for(let o=r;o<e.length;o++){let s=t[o]?.[n];s!==void 0&&Number.isFinite(s)&&(a=s);let c=e[o];i[o-r]={time:c.time,open:a,high:a,low:a,close:a,volume:c.volume}}return{bars:i,start:r}}function kt(e,t,n){if(t===0||!e.series)return e;let r=Array(n).fill(null);for(let i=0;i<e.series.length&&t+i<n;i++)r[t+i]=e.series[i];return{...e,series:r}}function At(e){return{values:new Map,series:Array(e).fill(null)}}var jt=1,Mt=class{registry=new Map;instances=new Map;order=null;register(e){this.registry.set(e.descriptor.id,e)}getAvailableIndicators(){return Array.from(this.registry.values()).map(e=>e.descriptor)}addIndicator(e,t={},n,r={}){let i=this.registry.get(e);if(!i)throw Error(`Unknown indicator: ${e}`);let a=this.claimInstanceId(e,r.instanceId),o={id:e,instanceId:a,params:{...i.descriptor.defaultConfig,...t},visible:!0};r.pane&&this.canHost(r.pane)&&(o.pane=r.pane),r.scale===`left`&&i.descriptor.placement===`overlay`&&!o.pane&&(o.scale=`left`);let s={plugin:i,config:o,output:null,style:{colors:o.style?.colors??Pt(this.freeColor(e,i.descriptor.placement,o.pane??null)),lineWidths:o.style?.lineWidths??[1.5],opacity:o.style?.opacity??1},changedFrom:0};return this.instances.set(a,s),this.order=null,n&&this.compute(s,n),a}removeIndicator(e){this.instances.delete(e),this.order=null}updateIndicator(e,t,n){let r=this.instances.get(e);if(!r)return;let i=Tt(r.plugin.descriptor);if(i&&i in t&&this.readsFromItself(e,{...r.config.params,...t})){let{[i]:e,...n}=t;t=n}if(Object.assign(r.config.params,t),delete r.sourceBars,delete r.lineInput,this.order=null,!n)return;let a=new Set([e,...this.getDependents(e)]);for(let e of this.ordered())a.has(e.config.instanceId)&&this.compute(e,n)}recalculateAll(e){for(let t of this.ordered())this.compute(t,e)}recalculateFrom(e,t){for(let n of this.ordered())this.compute(n,e,t)}compute(e,t,n){let{plugin:r,config:i}=e,a=Et(r.descriptor,i.params);if(a.kind===`line`){this.computeFromLine(e,t,a.instanceId,a.key,n);return}delete e.lineInput;let o=t;a.kind===`price`?(e.sourceBars=Dt(t,a.source,e.sourceBars??null,n??0),o=e.sourceBars):delete e.sourceBars;let s=e.output,c=null;n!==void 0&&n>0&&s&&r.update&&(c=r.update(o,i,s,n)),e.changedFrom=c?Math.max(0,n-(r.revisesBefore?.(i)??0)):0,e.output=c??r.calculate(o,i)}computeFromLine(e,t,n,r,i){let{plugin:a,config:o}=e,s=this.instances.get(n),c=s?.output?.series,l=e.lineInput,u=i===void 0?void 0:Math.min(i,s?.changedFrom??0);if(u!==void 0&&c&&a.update&&l&&l.raw.series&&l.aligned.series&&l.sourceId===n&&l.key===r&&l.start<u&&u<=l.start+l.bars.length){let{start:n,bars:i}=l;i.length=t.length-n;let s=i[u-1-n].close;for(let e=u;e<t.length;e++){let a=c[e]?.[r];a!==void 0&&Number.isFinite(a)&&(s=a),i[e-n]={time:t[e].time,open:s,high:s,low:s,close:s,volume:t[e].volume}}let d=a.update(i,o,l.raw,u-n);if(d?.series){let r=Math.max(n,u-(a.revisesBefore?.(o)??0));if(l.raw=d,n===0)l.aligned=d;else{let e=l.aligned.series;e.length=t.length;for(let i=r;i<t.length;i++)e[i]=d.series[i-n]??null;l.aligned.values=d.values,l.aligned.meta=d.meta}e.output=l.aligned,e.changedFrom=r;return}}e.changedFrom=0;let d=Ot(t,c,r);if(!d){delete e.lineInput,e.output=At(t.length);return}let f=a.calculate(d.bars,o),p=kt(f,d.start,t.length);e.lineInput={sourceId:n,key:r,start:d.start,bars:d.bars,raw:f,aligned:p},e.output=p}ordered(){if(this.order)return this.order;let e=[],t=new Map,n=r=>{let i=r.config.instanceId;if(t.get(i))return;t.set(i,`visiting`);let a=Et(r.plugin.descriptor,r.config.params),o=a.kind===`line`?this.instances.get(a.instanceId):void 0;o&&n(o),t.set(i,`done`),e.push(r)};for(let e of this.instances.values())n(e);return this.order=e,e}readsFromItself(e,t){let n=this.instances.get(e);if(!n)return!1;let r=Et(n.plugin.descriptor,t),i=new Set;for(;r.kind===`line`;){if(r.instanceId===e)return!0;if(i.has(r.instanceId))return!1;i.add(r.instanceId);let t=this.instances.get(r.instanceId);if(!t)return!1;r=Et(t.plugin.descriptor,t.config.params)}return!1}canHost(e){let t=this.instances.get(e);return!!t&&t.plugin.descriptor.placement===`panel`&&!t.config.pane}getDependents(e){let t=[],n=new Set([e]),r=[e];for(;r.length;){let e=r.shift();for(let i of this.instances.values()){let a=Et(i.plugin.descriptor,i.config.params),o=i.config.instanceId;a.kind===`line`&&a.instanceId===e&&!n.has(o)&&(n.add(o),t.push(o),r.push(o))}}return t}claimInstanceId(e,t){if(t&&!this.instances.has(t)){let e=Number(/_(\d+)$/.exec(t)?.[1]);return Number.isSafeInteger(e)&&e>=jt&&(jt=e+1),t}let n=`tc_${e}_${jt++}`;for(;this.instances.has(n);)n=`tc_${e}_${jt++}`;return n}getPaneMembers(e){let t=[];for(let n of this.instances.values())n.config.pane===e&&t.push(n.config.instanceId);return t}setPane(e,t){let n=this.instances.get(e);if(!n||t===e||t!==null&&!this.canHost(t))return!1;if(t===null?delete n.config.pane:(n.config.pane=t,delete n.config.scale),Ft(n.style.colors)){let t=n.plugin.descriptor.placement,r=n.config.pane??null;this.colorsInPane(t,r,e).has(n.style.colors[0])&&(n.style.colors=Pt(this.freeColor(n.config.id,t,r,e)))}return!0}colorsInPane(e,t,n){let r=new Set;for(let i of this.instances.values())i.config.instanceId!==n&&(t===null?e===`overlay`&&i.plugin.descriptor.placement===`overlay`&&!i.config.pane:i.config.instanceId===t||i.config.pane===t)&&r.add(i.style.colors[0]);return r}freeColor(t,n,r,i){let a=this.colorsInPane(n,r,i);for(let e of this.instances.values())e.config.id===t&&e.config.instanceId!==i&&a.add(e.style.colors[0]);let o=e.TC_SERIES_COLORS.findIndex(e=>!a.has(e));return o>=0?o:a.size%e.TC_SERIES_COLORS.length}getOutput(e){return this.instances.get(e)?.output??null}renderOverlays(e,t,n){for(let r of this.instances.values()){if(!r.output||!r.config.visible||r.plugin.descriptor.placement!==`overlay`||r.config.pane)continue;let i=r.config.scale===`left`;r.plugin.render(e,r.output,i?n??t:t,r.style)}}hasLeftScaleOverlays(){for(let e of this.instances.values())if(e.config.scale===`left`&&e.config.visible)return!0;return!1}setScale(e,t){let n=this.instances.get(e);return!n||n.plugin.descriptor.placement!==`overlay`||n.config.pane?!1:(t===`left`?n.config.scale=`left`:delete n.config.scale,!0)}renderPanel(e,t,n){let r=this.instances.get(t);!r?.output||!r.config.visible||r.plugin.render(e,r.output,n,r.style)}getLatestValues(e){let t=this.instances.get(e);return t?Nt(t):[]}getLatestOverlayValues(e=`right`){let t=[];for(let n of this.instances.values())n.plugin.descriptor.placement!==`overlay`||n.config.pane||n.config.scale===`left`==(e===`left`)&&t.push(...Nt(n));return t}getIndicatorConfig(e){return this.instances.get(e)?.config??null}setVisible(e,t){let n=this.instances.get(e);return n?(n.config.visible=t,t):null}isVisible(e){return this.instances.get(e)?.config.visible??!1}getLevels(e){let t=this.instances.get(e);return t?[...t.config.levels??t.plugin.descriptor.levels??[]]:[]}setLevels(e,t){let n=this.instances.get(e);return n?(t===null?delete n.config.levels:n.config.levels=t.filter(e=>Number.isFinite(e)),!0):!1}getPaneValueRange(e,t,n,r=!1){let i=null;for(let a of[e,...this.getPaneMembers(e)]){let e=this.instances.get(a);if(!e||e.config.visible===!1)continue;let o=e.plugin.descriptor,s={keys:pt(o),scale:o.scale,levels:e.config.levels??o.levels,zero:yt(o.plots)},c=r?_t(e.output,t,n,s):gt(e.output,t,n,s);if(c===!1)return null;c&&(i=i?{min:Math.min(i.min,c.min),max:Math.max(i.max,c.max)}:c)}return i}getIndicatorDescriptor(e){return this.instances.get(e)?.plugin.descriptor??null}getActiveIndicators(){let e=[];for(let[t,n]of this.instances)e.push({instanceId:t,id:n.config.id,params:{...n.config.params},descriptor:n.plugin.descriptor,visible:n.config.visible??!0,...n.config.pane?{pane:n.config.pane}:{}});return e}getIndicatorStyle(e){let t=this.instances.get(e)?.style;return t?{colors:[...t.colors],lineWidths:[...t.lineWidths],opacity:t.opacity}:null}updateIndicatorStyle(e,t){let n=this.instances.get(e);n&&Object.assign(n.style,t)}getOverlayPriceRange(e,t,n=`right`){let r=1/0,i=-1/0;for(let a of this.instances.values()){if(!a.output||!a.config.visible||a.plugin.descriptor.placement!==`overlay`||a.config.pane||a.config.scale===`left`!=(n===`left`))continue;let o=a.output.series;if(!o)continue;let s=pt(a.plugin.descriptor),c=Math.min(t,o.length-1);for(let t=Math.max(0,e);t<=c;t++){let e=o[t];if(e){if(s){for(let t=0;t<s.length;t++){let n=e[s[t]];n!==void 0&&isFinite(n)&&(n<r&&(r=n),n>i&&(i=n))}continue}for(let t in e){let n=e[t];n!==void 0&&isFinite(n)&&(n<r&&(r=n),n>i&&(i=n))}}}}return r===1/0?null:{min:r,max:i}}getPanelIndicators(){let e=[];for(let[t,n]of this.instances)n.plugin.descriptor.placement===`panel`&&e.push({instanceId:t,descriptor:n.plugin.descriptor});return e}};function Nt(e){let t=e.output?.series,n=e.plugin.descriptor.plots;if(!t||!n||e.config.visible===!1)return[];let r=t[t.length-1];if(!r)return[];let i=[];for(let t of n){let n=r[t.key];n!==void 0&&Number.isFinite(n)&&i.push({value:n,color:ht(t,e.style,r)})}return i}function Pt(t){return[...e.TC_SERIES_COLORS.slice(t),...e.TC_SERIES_COLORS.slice(0,t)]}function Ft(t){let n=e.TC_SERIES_COLORS.length;if(t.length!==n)return!1;let r=e.TC_SERIES_COLORS.indexOf(t[0]);return r>=0&&t.every((t,i)=>t===e.TC_SERIES_COLORS[(r+i)%n])}var N=class extends Map{keyBuf=[];valBuf=[];folded=!1;constructor(){super()}set(e,t){if(this.folded)return super.set(e,t);let n=this.keyBuf,r=n.length;if(r===0||e>n[r-1])return n.push(e),this.valBuf.push(t),this;let i=this.indexOf(e);return i>=0?(this.valBuf[i]=t,this):(this.fold(),super.set(e,t))}get(e){if(this.folded)return super.get(e);let t=this.indexOf(e);return t>=0?this.valBuf[t]:void 0}has(e){return this.folded?super.has(e):this.indexOf(e)>=0}delete(e){if(this.folded)return super.delete(e);let t=this.indexOf(e);return t<0?!1:(this.keyBuf.splice(t,1),this.valBuf.splice(t,1),!0)}clear(){super.clear(),this.keyBuf=[],this.valBuf=[],this.folded=!1}get size(){return this.folded?super.size:this.keyBuf.length}forEach(e,t){this.fold(),super.forEach(e,t)}entries(){return this.fold(),super.entries()}keys(){return this.fold(),super.keys()}values(){return this.fold(),super.values()}[Symbol.iterator](){return this.fold(),super[Symbol.iterator]()}indexOf(e){let t=this.keyBuf,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i];if(a===e)return i;a<e?n=i+1:r=i-1}return-1}fold(){if(this.folded)return;this.folded=!0;let e=this.keyBuf,t=this.valBuf;for(let n=0;n<e.length;n++)super.set(e[n],t[n]);this.keyBuf=[],this.valBuf=[]}};function P(e,t,n){let r=e.params[t];if(typeof r==`number`&&Number.isFinite(r))return r;if(typeof r==`string`){let e=Number(r);if(Number.isFinite(e))return e}return n}function F(e,t,n,r=1){let i=P(e,t,n);return Math.max(r,Math.floor(i))}var It=class extends M{descriptor={id:`sma`,name:`Simple Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`SMA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`SMA`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++)if(a+=e[t].close,t>=n&&(a-=e[t-n].close),t>=n-1){let o={value:a/n};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;this.writePoint(n,e,t,{value:r/i})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Lt=class extends M{descriptor={id:`ema`,name:`Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`EMA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`EMA`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=2/(n+1),i=new N,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++){if(t<n-1){o+=e[t].close;continue}o=t===n-1?(o+e[t].close)/n:(e[t].close-o)*r+o;let s={value:o};i.set(e[t].time,s),a[t]=s}return{values:i,series:a}}update(e,t,n,r){let i=F(t,`period`,20,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;let o=2/(i+1);for(let t=r;t<e.length;t++)a=(e[t].close-a)*o+a,this.writePoint(n,e,t,{value:a});return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Rt=class extends M{descriptor={id:`bb`,name:`Bollinger Bands`,placement:`overlay`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`BB`,inputs:{source:{source:!0}},plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=P(t,`stdDev`,2),i=new N,a=Array(e.length).fill(null),o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(o+=c,s+=c*c,t>=n){let r=e[t-n].close;o-=r,s-=r*r}if(t>=n-1){let c=o/n,l=s/n-c*c,u=Math.sqrt(Math.max(0,l)),d={middle:c,upper:c+r*u,lower:c-r*u};i.set(e[t].time,d),a[t]=d}}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`period`,20,1),a=P(t,`stdDev`,2);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=0;for(let n=t-i+1;n<=t;n++){let t=e[n].close;r+=t,o+=t*t}let s=r/i,c=Math.sqrt(Math.max(0,o/i-s*s));this.writePoint(n,e,t,{middle:s,upper:s+a*c,lower:s-a*c})}return n}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=0,d=l-c+1,f=new Float64Array(d),p=new Float64Array(d),m=new Float64Array(d),h=new Float64Array(d),g=new Float64Array(d),_=new Float64Array(d);for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t||t.upper===void 0)continue;let n=a(e,r);f[u]=n,p[u]=o(t.upper,r),m[u]=n,h[u]=o(t.middle,r),g[u]=n,_[u]=o(t.lower,r),u++}if(!(u<2)){t.beginPath(),t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);for(let e=u-1;e>=0;e--)t.lineTo(g[e],_[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[0],.1),t.fill(),t.beginPath(),t.strokeStyle=i.colors[0],t.lineWidth=i.lineWidths[0],t.lineJoin=`round`,t.moveTo(f[0],p[0]);for(let e=1;e<u;e++)t.lineTo(f[e],p[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[1]??i.colors[0],t.moveTo(m[0],h[0]);for(let e=1;e<u;e++)t.lineTo(m[e],h[e]);t.stroke(),t.beginPath(),t.strokeStyle=i.colors[0],t.moveTo(g[0],_[0]);for(let e=1;e<u;e++)t.lineTo(g[e],_[e]);t.stroke()}}},zt=class extends M{descriptor={id:`vwap`,name:`Volume Weighted Average Price`,placement:`overlay`,defaultConfig:{},shortName:`VWAP`,plots:[{key:`value`,title:`VWAP`,color:0}]};calculate(e,t){let n=new N,r=Array(e.length).fill(null),i=0,a=0;for(let t=0;t<e.length;t++){let o=(e[t].high+e[t].low+e[t].close)/3;if(i+=e[t].volume,a+=o*e[t].volume,i>0){let o={value:a/i};n.set(e[t].time,o),r[t]=o}}return{values:n,series:r}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Bt=class extends M{descriptor={id:`ichimoku`,name:`Ichimoku Cloud`,placement:`overlay`,defaultConfig:{tenkan:9,kijun:26,senkou:52,displacement:26},shortName:`Ichimoku`,plots:[{key:`tenkan`,title:`Conversion`,color:0},{key:`kijun`,title:`Base`,color:1},{key:`senkouA`,title:`Lead A`,color:2},{key:`senkouB`,title:`Lead B`,color:3}]};calculate(e,t){let n=F(t,`tenkan`,9,1),r=F(t,`kijun`,26,1),i=F(t,`senkou`,52,1),a=new N,o=Array(e.length).fill(null),s=t=>{let n=new Float64Array(e.length),r=new Float64Array(e.length);for(let i=0;i<e.length;i++){let a=-1/0,o=1/0,s=Math.max(0,i-t+1);for(let t=s;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);n[i]=a,r[i]=o}return{highs:n,lows:r}},c=s(n),l=s(r),u=s(i);for(let t=0;t<e.length;t++){let s={};t>=n-1&&(s.tenkan=(c.highs[t]+c.lows[t])/2),t>=r-1&&(s.kijun=(l.highs[t]+l.lows[t])/2),s.tenkan!==void 0&&s.kijun!==void 0&&(s.senkouA=(s.tenkan+s.kijun)/2),t>=i-1&&(s.senkouB=(u.highs[t]+u.lows[t])/2),t>=r-1&&(s.chikou=e[t].close),(s.tenkan!==void 0||s.kijun!==void 0||s.senkouA!==void 0||s.senkouB!==void 0)&&(a.set(e[t].time,s),o[t]=s)}return{values:a,series:o}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=l-c+1,d=new Float64Array(u),f=new Float64Array(u),p=0,m=new Float64Array(u),h=new Float64Array(u),g=0,_=new Float64Array(u),v=new Float64Array(u),y=0,b=new Float64Array(u),x=new Float64Array(u),S=0;for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.tenkan!==void 0&&(d[p]=n,f[p]=o(t.tenkan,r),p++),t.kijun!==void 0&&(m[g]=n,h[g]=o(t.kijun,r),g++),t.senkouA!==void 0&&(_[y]=n,v[y]=o(t.senkouA,r),y++),t.senkouB!==void 0&&(b[S]=n,x[S]=o(t.senkouB,r),S++)}if(y>1&&S>1){let n=Math.min(y,S);t.beginPath(),t.moveTo(_[0],v[0]);for(let e=1;e<n;e++)t.lineTo(_[e],v[e]);for(let e=n-1;e>=0;e--)t.lineTo(b[e],x[e]);t.closePath(),t.fillStyle=(0,e.withAlpha)(i.colors[2]??`#1fa874`,.15),t.fill()}let C=(e,n,r,i,a)=>{if(!(r<2)){t.beginPath(),t.strokeStyle=i,t.lineWidth=a,t.lineJoin=`round`,t.moveTo(e[0],n[0]);for(let i=1;i<r;i++)t.lineTo(e[i],n[i]);t.stroke()}};C(d,f,p,i.colors[0],i.lineWidths[0]),C(m,h,g,i.colors[1]??`#f2a93b`,i.lineWidths[0]),C(_,v,y,i.colors[2]??`#1fa874`,1),C(b,x,S,i.colors[3]??`#e8505b`,1)}},Vt=class extends M{descriptor={id:`psar`,name:`Parabolic SAR`,placement:`overlay`,defaultConfig:{step:.02,max:.2},shortName:`SAR`,plots:[{key:`value`,title:`SAR`,color:0,kind:`dots`,tone:{field:`trend`},downColor:1}]};calculate(e,t){let n=P(t,`step`,.02),r=P(t,`max`,.2),i=new N,a=Array(e.length).fill(null);if(e.length<2)return{values:i,series:a};let o=e[1].close>e[0].close,s=n,c=o?e[0].high:e[0].low,l=o?e[0].low:e[0].high,u={value:l,trend:o?1:-1};i.set(e[0].time,u),a[0]=u;for(let t=1;t<e.length;t++){let u=l;l=u+s*(c-u),o?(l=Math.min(l,e[t-1].low),t>=2&&(l=Math.min(l,e[t-2].low)),e[t].low<l?(o=!1,l=c,c=e[t].low,s=n):e[t].high>c&&(c=e[t].high,s=Math.min(s+n,r))):(l=Math.max(l,e[t-1].high),t>=2&&(l=Math.max(l,e[t-2].high)),e[t].high>l?(o=!0,l=c,c=e[t].high,s=n):e[t].low<c&&(c=e[t].low,s=Math.min(s+n,r)));let d={value:l,trend:o?1:-1};i.set(e[t].time,d),a[t]=d}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=Math.max(1.5,n.barWidth*.15);for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),u=o(s.value,n);e.beginPath(),e.arc(c,u,l,0,Math.PI*2),e.fillStyle=s.trend===1?r.colors[0]:r.colors[1]??`#e8505b`,e.fill()}}},Ht=class extends M{descriptor={id:`supertrend`,name:`Supertrend`,placement:`overlay`,defaultConfig:{period:10,multiplier:3},shortName:`Supertrend`,plots:[{key:`value`,title:`Supertrend`,color:0,tone:{field:`trend`},downColor:1}]};calculate(e,t){let n=F(t,`period`,10,1),r=P(t,`multiplier`,3),i=new N,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};let o=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)o.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let s=0;for(let e=0;e<n;e++)s+=o[e];s/=n;let c=0,l=0,u=0,d=0,f=0,p=0,m=1;for(let t=n-1;t<e.length;t++){t>n-1&&(s=(s*(n-1)+o[t])/n);let h=(e[t].high+e[t].low)/2,g=h+r*s,_=h-r*s;c=g<u||e[t-1].close>u?g:u,l=_>d||e[t-1].close<d?_:d,f=p===u?e[t].close<=c?c:l:e[t].close>=l?l:c,m=f===l?1:-1;let v={value:f,trend:m};i.set(e[t].time,v),a[t]=v,u=c,d=l,p=f}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#e8505b`,d=0,f=0,p=0;for(let t=s;t<=c&&t<i.length;t++){let s=i[t];if(!s||s.value===void 0)continue;let c=a(t,n),m=o(s.value,n),h=s.trend??1;p!==0&&(e.beginPath(),e.strokeStyle=h===1?l:u,e.lineWidth=r.lineWidths[0]+.5,e.moveTo(d,f),e.lineTo(c,m),e.stroke()),d=c,f=m,p=h}}},Ut=class extends M{descriptor={id:`keltner`,name:`Keltner Channel`,placement:`overlay`,defaultConfig:{emaPeriod:20,atrPeriod:10,multiplier:1.5},shortName:`KC`,plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=F(t,`emaPeriod`,20,1),r=F(t,`atrPeriod`,10,1),i=P(t,`multiplier`,1.5),a=new N;if(e.length<Math.max(n,r))return{values:a};let o=2/(n+1),s=e[0].close,c=[s];for(let t=1;t<e.length;t++)s=(e[t].close-s)*o+s,c.push(s);let l=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)l.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let u=0;for(let e=0;e<r;e++)u+=l[e];u/=r;let d=Array(e.length).fill(null),f=Math.max(n,r)-1;for(let t=f;t<e.length;t++){t>f&&(u=(u*(r-1)+l[t])/r);let n={middle:c[t],upper:c[t]+i*u,lower:c[t]-i*u};a.set(e[t].time,n),d[t]=n}return{values:a,series:d}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},Wt=class extends M{descriptor={id:`donchian`,name:`Donchian Channel`,placement:`overlay`,defaultConfig:{period:20},shortName:`DC`,plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={upper:a,middle:(a+o)/2,lower:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??`#7d8696`,1),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},Gt=[`s3`,`s2`,`s1`,`pp`,`r1`,`r2`,`r3`],Kt=class extends M{descriptor={id:`pivots`,name:`Pivot Points (Classic)`,placement:`overlay`,defaultConfig:{lookback:24},shortName:`Pivots`,plots:[{key:`r3`,title:`R3`,color:1},{key:`r2`,title:`R2`,color:1},{key:`r1`,title:`R1`,color:1},{key:`pp`,title:`P`,color:0},{key:`s1`,title:`S1`,color:2},{key:`s2`,title:`S2`,color:2},{key:`s3`,title:`S3`,color:2}]};calculate(e,t){let n=F(t,`lookback`,24,1),r=new N,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};for(let t=n;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n;r<t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s=e[t-1].close,c=(a+o+s)/3,l=a-o,u={pp:c,r1:2*c-o,s1:2*c-a,r2:c+l,s2:c-l,r3:a+2*(c-o),s3:o-2*(a-c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=r.colors[0],u=r.colors[1]??`#e8505b`,d=r.colors[2]??`#1fa874`,f=r.lineWidths[0],p=e=>e===`pp`?l:e.startsWith(`r`)?u:d;for(let t of Gt){e.beginPath(),e.strokeStyle=p(t),e.lineWidth=t===`pp`?f:Math.max(1,f-1),t!==`pp`&&e.setLineDash([4,3]);let r=!1;for(let l=s;l<=c&&l<i.length;l++){let s=i[l]?.[t];if(s===void 0)continue;let c=a(l,n),u=o(s,n);r?e.lineTo(c,u):(e.moveTo(c,u),r=!0)}e.stroke(),e.setLineDash([])}}},qt=class extends M{descriptor={id:`avwap`,name:`Anchored VWAP`,placement:`overlay`,defaultConfig:{anchorTime:0},shortName:`AVWAP`,plots:[{key:`value`,title:`AVWAP`,color:0}]};calculate(e,t){let n=P(t,`anchorTime`,0),r=new N,i=Array(e.length).fill(null),a=0;if(n>0&&(a=e.findIndex(e=>e.time>=n),a<0))return{values:r,series:i};let o=0,s=0;for(let t=a;t<e.length;t++){let n=(e[t].high+e[t].low+e[t].close)/3;if(o+=e[t].volume,s+=n*e[t].volume,o>0){let n={value:s/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},Jt=class extends M{descriptor={id:`zigzag`,name:`ZigZag`,placement:`overlay`,defaultConfig:{deviation:5},shortName:`ZigZag`,plots:[{key:`pivot`,title:`Pivot`,color:0}]};calculate(e,t){let n=Math.max(.01,P(t,`deviation`,5))/100,r=new N,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i,meta:{pivots:[]}};let a=[],o=null,s=0,c=e[0].close;for(let t=1;t<e.length;t++){let r=e[t].high,i=e[t].low;if(o===null){r>=c*(1+n)?(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i);continue}o===`up`?r>c?(s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i):i<c?(s=t,c=i):r>=c*(1+n)&&(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r)}a.push({idx:s,price:c,type:o===`up`?`high`:`low`});for(let t of a){let n={pivot:t.price};r.set(e[t.idx].time,n),i[t.idx]=n}return{values:r,series:i,meta:{pivots:a}}}render(e,t,n,r){let i=t.meta?.pivots;if(!(!i||i.length<2)){e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;for(let t=0;t<i.length;t++){let r=i[t],s=a(r.idx,n),c=o(r.price,n);t===0?e.moveTo(s,c):e.lineTo(s,c)}e.stroke()}}},Yt=class extends M{descriptor={id:`lrc`,name:`Linear Regression Channel`,placement:`overlay`,defaultConfig:{period:100,stdDev:2,source:`close`},shortName:`LRC`,inputs:{source:{source:!0}},plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=F(t,`period`,100,2),r=P(t,`stdDev`,2),i=new N,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};for(let t=n-1;t<e.length;t++){let o=t-n+1,s=0,c=0,l=0,u=0;for(let t=0;t<n;t++){let n=t,r=e[o+t].close;s+=n,c+=r,l+=n*r,u+=n*n}let d=n*u-s*s;if(d===0)continue;let f=(n*l-s*c)/d,p=(c-f*s)/n,m=0;for(let t=0;t<n;t++){let n=f*t+p,r=e[o+t].close-n;m+=r*r}let h=Math.sqrt(m/n),g=f*(n-1)+p,_={middle:g,upper:g+r*h,lower:g-r*h,slope:f};i.set(e[t].time,_),a[t]=_}return{values:i,series:a}}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t)continue;let n=a(e,r);t.middle!==void 0&&d.push({x:n,y:o(t.middle,r)}),t.upper!==void 0&&u.push({x:n,y:o(t.upper,r)}),t.lower!==void 0&&f.push({x:n,y:o(t.lower,r)})}this.drawBand(t,u,f,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[1]??i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[0],i.lineWidths[0])}},Xt=class extends M{descriptor={id:`hma`,name:`Hull Moving Average`,placement:`overlay`,defaultConfig:{period:21,source:`close`},shortName:`HMA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`HMA`,color:0}]};calculate(e,t){let n=F(t,`period`,21,2),r=new N,i=Array(e.length).fill(null);if(e.length<n)return{values:r,series:i};let a=e.map(e=>e.close),o=Math.max(2,Math.floor(n/2)),s=Math.max(2,Math.floor(Math.sqrt(n))),c=Zt(a,n),l=Zt(a,o),u=Qt(a.map((e,t)=>c[t]===null||l[t]===null?null:2*l[t]-c[t]),s);for(let t=0;t<e.length;t++){if(u[t]===null)continue;let n={value:u[t]};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}};function Zt(e,t){let n=Array(e.length).fill(null);if(e.length<t)return n;let r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0;for(let n=0;n<t;n++)a+=e[i-n]*(t-n);n[i]=a/r}return n}function Qt(e,t){let n=Array(e.length).fill(null),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-n];if(r===null){o=!1;break}a+=r*(t-n)}o&&(n[i]=a/r)}return n}var $t=class extends M{descriptor={id:`mtfma`,name:`MTF Moving Average`,placement:`overlay`,defaultConfig:{period:50,timeframe:`1d`,source:`close`},shortName:`MTF MA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`MA`,color:0}]};calculate(t,n){let r=F(n,`period`,50,1),i=String(n.params.timeframe??`1d`),a=new N,o=Array(t.length).fill(null);if(t.length===0)return{values:a,series:o};let s=[],c=(0,e.timeframeBucketStart)(t[0].time,i),l=t[0].close,u=null,d=()=>{if(s.length<r)return;let e=0;for(let t=s.length-r;t<s.length;t++)e+=s[t];u=e/r};for(let n=0;n<t.length;n++){let r=(0,e.timeframeBucketStart)(t[n].time,i);if(r!==c&&(s.push(l),d(),c=r),l=t[n].close,u!==null){let e={value:u};a.set(t[n].time,e),o[n]=e}}return{values:a,series:o}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},en=class extends M{descriptor={id:`svwap`,name:`Session VWAP`,placement:`overlay`,defaultConfig:{bands:1},shortName:`SVWAP`,plots:[{key:`value`,title:`VWAP`,color:0},{key:`u1`,title:`+1σ`,color:1},{key:`l1`,title:`−1σ`,color:1},{key:`u2`,title:`+2σ`,color:1},{key:`l2`,title:`−2σ`,color:1},{key:`u3`,title:`+3σ`,color:1},{key:`l3`,title:`−3σ`,color:1}]};calculate(t,n){let r=Math.min(3,F(n,`bands`,1,0)),i=new N,a=Array(t.length).fill(null);if(t.length===0)return{values:i,series:a};let o=(0,e.timeframeBucketStart)(t[0].time,`1d`),s=0,c=0,l=0;for(let n=0;n<t.length;n++){let u=t[n],d=(0,e.timeframeBucketStart)(u.time,`1d`);d!==o&&(s=0,c=0,l=0,o=d);let f=(u.high+u.low+u.close)/3;if(s+=f*u.volume,c+=f*f*u.volume,l+=u.volume,l>0){let e=s/l,t={value:e,session:o};if(r>0){let n=Math.max(0,c/l-e*e),i=Math.sqrt(n);for(let n=1;n<=r;n++)t[`u${n}`]=e+n*i,t[`l${n}`]=e-n*i}i.set(u.time,t),a[n]=t}}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:a,to:o}=n.visibleRange;e.globalAlpha=.55,e.lineWidth=1,e.setLineDash([4,3]),e.strokeStyle=r.colors[1]??r.colors[0];for(let t=1;t<=3;t++)this.strokeBandSeries(e,i,n,a,o,e=>e[`u${t}`]),this.strokeBandSeries(e,i,n,a,o,e=>e[`l${t}`]);e.setLineDash([]),e.globalAlpha=1,e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,this.strokeBandSeries(e,i,n,a,o,e=>e.value)}strokeBandSeries(e,t,n,r,i,s){e.beginPath();let c,l=!1;for(let u=r;u<=i&&u<t.length;u++){let r=t[u],i=r?s(r):void 0;if(r===null||i===void 0){l=!1;continue}let d=a(u,n),f=o(i,n),p=r.session!==c;!l||p?(e.moveTo(d,f),l=!0):e.lineTo(d,f),c=r.session}e.stroke()}},tn=class extends M{descriptor={id:`chandelier`,name:`Chandelier Exit`,placement:`overlay`,defaultConfig:{period:22,multiplier:3},shortName:`CE`,plots:[{key:`long`,title:`Long`,color:0},{key:`short`,title:`Short`,color:1}]};calculate(e,t){let n=F(t,`period`,22,1),r=P(t,`multiplier`,3),i=new N,a=Array(e.length).fill(null),o=e.length;if(o<=n)return{values:i,series:a};let s=Array(o).fill(0);for(let t=1;t<o;t++){let n=e[t-1].close;s[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let c=0;for(let e=1;e<=n;e++)c+=s[e];c/=n;for(let t=n;t<o;t++){t>n&&(c=(c*(n-1)+s[t])/n);let o=-1/0,l=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>o&&(o=e[r].high),e[r].low<l&&(l=e[r].low);let u={long:o-r*c,short:l+r*c};i.set(e[t].time,u),a[t]=u}return{values:i,series:a}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`,e.setLineDash([5,3]);let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke(),e.setLineDash([])};l(`long`,r.colors[0]??`#1fa874`),l(`short`,r.colors[1]??`#e8505b`)}},nn=class extends M{descriptor={id:`alligator`,name:`Alligator`,placement:`overlay`,defaultConfig:{jaw:13,teeth:8,lips:5,jawShift:8,teethShift:5,lipsShift:3},shortName:`Alligator`,plots:[{key:`jaw`,title:`Jaw`,color:0},{key:`teeth`,title:`Teeth`,color:1},{key:`lips`,title:`Lips`,color:2}]};calculate(e,t){let n=F(t,`jaw`,13,1),r=F(t,`teeth`,8,1),i=F(t,`lips`,5,1),a=F(t,`jawShift`,8,0),o=F(t,`teethShift`,5,0),s=F(t,`lipsShift`,3,0),c=new N,l=e.length,u=Array(l).fill(null);if(l===0)return{values:c,series:u};let d=e.map(e=>(e.high+e.low)/2),f=rn(d,n),p=rn(d,r),m=rn(d,i),h=Array(l).fill(void 0),g=Array(l).fill(void 0),_=Array(l).fill(void 0);for(let e=0;e<l;e++)f[e]!==void 0&&e+a<l&&(h[e+a]=f[e]),p[e]!==void 0&&e+o<l&&(g[e+o]=p[e]),m[e]!==void 0&&e+s<l&&(_[e+s]=m[e]);for(let t=0;t<l;t++){if(h[t]===void 0&&g[t]===void 0&&_[t]===void 0)continue;let n={};h[t]!==void 0&&(n.jaw=h[t]),g[t]!==void 0&&(n.teeth=g[t]),_[t]!==void 0&&(n.lips=_[t]),c.set(e[t].time,n),u[t]=n}return{values:c,series:u}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange,l=(t,l)=>{e.beginPath(),e.strokeStyle=l,e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let u=!1;for(let r=s;r<=c&&r<i.length;r++){let s=i[r];if(!s||s[t]===void 0){u=!1;continue}let c=a(r,n),l=o(s[t],n);u?e.lineTo(c,l):(e.moveTo(c,l),u=!0)}e.stroke()};l(`jaw`,r.colors[0]??`#4c8dff`),l(`teeth`,r.colors[1]??`#e8505b`),l(`lips`,r.colors[2]??`#1fa874`)}};function rn(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<t)return r;let i=0;for(let n=0;n<t;n++)i+=e[n];let a=i/t;r[t-1]=a;for(let i=t;i<n;i++)a=(a*(t-1)+e[i])/t,r[i]=a;return r}var an=class extends M{descriptor={id:`vwma`,name:`Volume Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`VWMA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`VWMA`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null),a=0,o=0;for(let t=0;t<e.length;t++){let s=e[t].close*e[t].volume;if(a+=s,o+=e[t].volume,t>=n){let r=e[t-n];a-=r.close*r.volume,o-=r.volume}if(t>=n-1&&o>0){let n={value:a/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,a=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close*e[n].volume,a+=e[n].volume;this.writePoint(n,e,t,a>0?{value:r/a}:null)}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},on=class extends M{descriptor={id:`wma`,name:`Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`WMA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`WMA`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null),a=n*(n+1)/2,o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(s+=c*n-o,o+=c,t>=n&&(o-=e[t-n].close),t>=n-1){let n={value:s/a};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`period`,20,1),a=i*(i+1)/2;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=t-i+1;for(let t=0;t<i;t++)r+=e[o+t].close*(t+1);this.writePoint(n,e,t,{value:r/a})}return n}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},sn=class extends M{descriptor={id:`envelope`,name:`Moving Average Envelope`,placement:`overlay`,defaultConfig:{period:20,percent:2.5,source:`close`},shortName:`Env`,inputs:{source:{source:!0}},plots:[{key:`upper`,title:`Upper`,color:0},{key:`basis`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=P(t,`percent`,2.5)/100,i=new N,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let s=o/n,c={basis:s,upper:s*(1+r),lower:s*(1-r)};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`period`,20,1),a=P(t,`percent`,2.5)/100;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;let o=r/i;this.writePoint(n,e,t,{basis:o,upper:o*(1+a),lower:o*(1-a)})}return n}render(t,n,r,i){let s=n.series;if(!s)return;let{from:c,to:l}=r.visibleRange,u=[],d=[],f=[];for(let e=c;e<=l&&e<s.length;e++){let t=s[e];if(!t||t.upper===void 0)continue;let n=a(e,r);u.push({x:n,y:o(t.upper,r)}),d.push({x:n,y:o(t.lower,r)}),f.push({x:n,y:o(t.basis,r)})}this.drawBand(t,u,d,(0,e.withAlpha)(i.colors[0],.08)),this.drawLine(t,u,i.colors[0],i.lineWidths[0]),this.drawLine(t,d,i.colors[0],i.lineWidths[0]),this.drawLine(t,f,i.colors[1]??i.colors[0],i.lineWidths[0])}};function cn(e,t){let n=2/(t+1),r=Array(e.length).fill(null),i=0,a=0;for(let o=0;o<e.length;o++){if(o<t-1){a+=e[o];continue}i=o===t-1?(a+e[o])/t:(e[o]-i)*n+i,r[o]=i}return r}function ln(e,t,n){let r=Array(n).fill(null);for(let n=0;n<e.length;n++)e[n]!==null&&(r[t[n]]=e[n]);return r}function un(e){let t=[],n=[];for(let r=0;r<e.length;r++)e[r]!==null&&(t.push(e[r]),n.push(r));return{values:t,indices:n}}var dn=class extends M{descriptor={id:`tema`,name:`Triple EMA`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`TEMA`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`TEMA`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null),a=cn(e.map(e=>e.close),n),o=un(a),s=ln(cn(o.values,n),o.indices,e.length),c=un(s),l=ln(cn(c.values,n),c.indices,e.length);for(let t=0;t<e.length;t++){let n=a[t],o=s[t],c=l[t];if(n===null||o===null||c===null)continue;let u={value:3*n-3*o+c};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let{from:s,to:c}=n.visibleRange;e.beginPath(),e.strokeStyle=r.colors[0],e.lineWidth=r.lineWidths[0],e.lineJoin=`round`;let l=!1;for(let t=s;t<=c&&t<i.length;t++){let r=i[t];if(!r||r.value===void 0)continue;let s=a(t,n),c=o(r.value,n);l?e.lineTo(s,c):(e.moveTo(s,c),l=!0)}e.stroke()}},fn=class extends M{descriptor={id:`ao`,name:`Awesome Oscillator`,placement:`panel`,defaultConfig:{fast:5,slow:34},shortName:`AO`,plots:[{key:`value`,title:`AO`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e,t){let n=F(t,`fast`,5,1),r=F(t,`slow`,34,1),i=new N,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=Array(e.length);for(let t=0;t<e.length;t++)o[t]=(e[t].high+e[t].low)/2;let s=0,c=0,l;for(let t=0;t<e.length;t++)if(c+=o[t],t>=r&&(c-=o[t-r]),s+=o[t],t>=n&&(s-=o[t-n]),t>=r-1){let o=s/n-c/r,u={value:o,up:+(l===void 0||o>=l)};i.set(e[t].time,u),a[t]=u,l=o}return{values:i,series:a}}},pn=class extends M{descriptor={id:`chaikinOsc`,name:`Chaikin Oscillator`,placement:`panel`,defaultConfig:{fast:3,slow:10},shortName:`Chaikin Osc`,plots:[{key:`value`,title:`Chaikin`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=F(t,`fast`,3,1),r=F(t,`slow`,10,1),i=new N,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=2/(n+1),s=2/(r+1),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let{high:n,low:d,close:f,volume:p}=e[t],m=n-d,h=m===0?0:(f-d-(n-f))/m;if(c+=h*p,t===0?(l=c,u=c):(l=(c-l)*o+l,u=(c-u)*s+u),t>=r-1){let n={value:l-u,adl:c};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},mn=class extends M{descriptor={id:`rsi`,name:`Relative Strength Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`RSI`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`RSI`,color:0}],scale:{min:0,max:100},levels:[30,70]};smoothing=new WeakMap;calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null),a={values:r,series:i};if(e.length<n+1)return a;let o=[],s=[],c=0,l=0;for(let t=1;t<=n;t++){let n=e[t].close-e[t-1].close;n>0?c+=n:l-=n}c/=n,l/=n,o[n]=c,s[n]=l;let u={value:l===0?100:100-100/(1+c/l)};r.set(e[n].time,u),i[n]=u;for(let t=n+1;t<e.length;t++){let a=e[t].close-e[t-1].close,u=a>0?a:0,d=a<0?-a:0;c=(c*(n-1)+u)/n,l=(l*(n-1)+d)/n,o[t]=c,s[t]=l;let f={value:l===0?100:100-100/(1+c/l)};r.set(e[t].time,f),i[t]=f}return this.smoothing.set(a,{gain:o,loss:s}),a}update(e,t,n,r){let i=F(t,`period`,14,1),a=this.smoothing.get(n);if(!a||r<=i||!this.canResume(e,n,r))return null;let o=a.gain[r-1],s=a.loss[r-1];if(o===void 0||s===void 0)return null;for(let t=r;t<e.length;t++){let r=e[t].close-e[t-1].close,c=r>0?r:0,l=r<0?-r:0;o=(o*(i-1)+c)/i,s=(s*(i-1)+l)/i,a.gain[t]=o,a.loss[t]=s;let u=s===0?100:100-100/(1+o/s);this.writePoint(n,e,t,{value:u})}return n}},hn=class extends M{descriptor={id:`macd`,name:`MACD`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9,source:`close`},shortName:`MACD`,inputs:{source:{source:!0}},plots:[{key:`histogram`,title:`Histogram`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`macd`,title:`MACD`,color:0},{key:`signal`,title:`Signal`,color:1}]};emas=new WeakMap;calculate(e,t){let n=F(t,`fast`,12,1),r=F(t,`slow`,26,1),i=F(t,`signal`,9,1),a=new N,o=Array(e.length).fill(null),s={values:a,series:o};if(e.length<r)return s;let c=2/(n+1),l=2/(r+1),u=2/(i+1),d=Array(e.length),f=Array(e.length),p=e[0].close,m=e[0].close,h=0,g=!1;for(let t=0;t<e.length;t++){let n=e[t].close;if(t===0?(p=n,m=n):(p=(n-p)*c+p,m=(n-m)*l+m),d[t]=p,f[t]=m,t>=r-1){let n=p-m;g?h=(n-h)*u+h:(h=n,g=!0);let r=n-h,i={macd:n,signal:h,histogram:r};a.set(e[t].time,i),o[t]=i}}return this.emas.set(s,{fast:d,slow:f}),s}update(e,t,n,r){let i=F(t,`fast`,12,1),a=F(t,`slow`,26,1),o=F(t,`signal`,9,1),s=this.emas.get(n);if(!s||r<a||!this.canResume(e,n,r))return null;let c=s.fast[r-1],l=s.slow[r-1],u=n.series[r-1]?.signal;if(c===void 0||l===void 0||u===void 0)return null;let d=2/(i+1),f=2/(a+1),p=2/(o+1);for(let t=r;t<e.length;t++){let r=e[t].close;c=(r-c)*d+c,l=(r-l)*f+l,s.fast[t]=c,s.slow[t]=l;let i=c-l;u=(i-u)*p+u,this.writePoint(n,e,t,{macd:i,signal:u,histogram:i-u})}return n}},gn=class extends M{descriptor={id:`stochastic`,name:`Stochastic Oscillator`,placement:`panel`,defaultConfig:{kPeriod:14,dPeriod:3,smooth:3},shortName:`Stoch`,plots:[{key:`k`,title:`%K`,color:0},{key:`d`,title:`%D`,color:1}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=F(t,`kPeriod`,14,1),r=F(t,`dPeriod`,3,1),i=F(t,`smooth`,3,1),a=new N,o=Array(e.length).fill(null);if(e.length<n)return{values:a,series:o};let s=[];for(let t=0;t<e.length;t++){if(t<n-1){s.push(0);continue}let r=-1/0,i=1/0;for(let a=t-n+1;a<=t;a++)e[a].high>r&&(r=e[a].high),e[a].low<i&&(i=e[a].low);s.push(r===i?50:(e[t].close-i)/(r-i)*100)}let c=[];for(let e=0;e<s.length;e++){if(e<n-1+i-1){c.push(0);continue}let t=0;for(let n=e-i+1;n<=e;n++)t+=s[n];c.push(t/i)}let l=n-1+i-1;for(let t=l;t<c.length;t++){let n={k:c[t]};if(t>=l+r-1){let e=0;for(let n=t-r+1;n<=t;n++)e+=c[n];n.d=e/r}a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`kPeriod`,14,1),a=F(t,`dPeriod`,3,1),o=F(t,`smooth`,3,1),s=i-1+o-1,c=t=>{let n=-1/0,r=1/0;for(let a=t-i+1;a<=t;a++)e[a].high>n&&(n=e[a].high),e[a].low<r&&(r=e[a].low);return n===r?50:(e[t].close-r)/(n-r)*100},l=e=>{let t=0;for(let n=e-o+1;n<=e;n++)t+=c(n);return t/o};for(let t=r;t<e.length;t++){if(t<s||e.length<i){this.writePoint(n,e,t,null);continue}let r={k:l(t)};if(t>=s+a-1){let e=0;for(let n=t-a+1;n<=t;n++)e+=l(n);r.d=e/a}this.writePoint(n,e,t,r)}return n}},_n=class extends M{descriptor={id:`atr`,name:`Average True Range`,placement:`panel`,defaultConfig:{period:14},shortName:`ATR`,plots:[{key:`value`,title:`ATR`,color:0}]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null);if(e.length<Math.max(2,n))return{values:r,series:i};let a=[e[0].high-e[0].low];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n)}let o=0;for(let e=0;e<n;e++)o+=a[e];o/=n;let s={value:o};r.set(e[n-1].time,s),i[n-1]=s;for(let t=n;t<e.length;t++){o=(o*(n-1)+a[t])/n;let s={value:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}update(e,t,n,r){let i=F(t,`period`,14,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;for(let t=r;t<e.length;t++){let r=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a=(a*(i-1)+r)/i,this.writePoint(n,e,t,{value:a})}return n}},vn=class extends M{descriptor={id:`adx`,name:`Average Directional Index`,placement:`panel`,defaultConfig:{period:14},shortName:`ADX`,plots:[{key:`adx`,title:`ADX`,color:0},{key:`plusDI`,title:`+DI`,color:1},{key:`minusDI`,title:`−DI`,color:2}],scale:{min:0}};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null);if(e.length<n*2)return{values:r,series:i};let a=[],o=[],s=[];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n);let r=e[t].high-e[t-1].high,i=e[t-1].low-e[t].low;o.push(r>i&&r>0?r:0),s.push(i>r&&i>0?i:0)}let c=0,l=0,u=0;for(let e=0;e<n;e++)c+=a[e],l+=o[e],u+=s[e];let d=[];for(let t=n;t<a.length;t++){t>n&&(c=c-c/n+a[t],l=l-l/n+o[t],u=u-u/n+s[t]);let f=c===0?0:l/c*100,p=c===0?0:u/c*100,m=f+p,h=m===0?0:Math.abs(f-p)/m*100;d.push(h);let g=t+1,_={plusDI:f,minusDI:p,dx:h};r.set(e[g].time,_),i[g]=_}if(d.length>=n){let t=0;for(let e=0;e<n;e++)t+=d[e];t/=n;let a=n*2;if(a<e.length){let n=r.get(e[a].time);n&&(n.adx=t),i[a]&&(i[a].adx=t)}for(let a=n;a<d.length;a++){t=(t*(n-1)+d[a])/n;let o=a+n+1;if(o<e.length){let n=r.get(e[o].time);n&&(n.adx=t),i[o]&&(i[o].adx=t)}}}return{values:r,series:i}}},yn=class extends M{descriptor={id:`obv`,name:`On Balance Volume`,placement:`panel`,defaultConfig:{},shortName:`OBV`,plots:[{key:`value`,title:`OBV`,color:0}]};calculate(e,t){let n=new N,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0,a={value:i};n.set(e[0].time,a),r[0]=a;for(let t=1;t<e.length;t++){e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume);let a={value:i};n.set(e[t].time,a),r[t]=a}return{values:n,series:r}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;for(let t=r;t<e.length;t++)e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume),this.writePoint(n,e,t,{value:i});return n}},bn=class extends M{descriptor={id:`williamsR`,name:`Williams %R`,placement:`panel`,defaultConfig:{period:14},shortName:`%R`,plots:[{key:`value`,title:`%R`,color:0}],scale:{min:-100,max:0},levels:[-80,-20]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={value:a===o?-50:(a-e[t].close)/(a-o)*-100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},xn=class extends M{descriptor={id:`cci`,name:`Commodity Channel Index`,placement:`panel`,defaultConfig:{period:20},shortName:`CCI`,plots:[{key:`value`,title:`CCI`,color:0}],levels:[-100,0,100]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=(e[r].high+e[r].low+e[r].close)/3;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=(e[r].high+e[r].low+e[r].close)/3;s+=Math.abs(t-o)}let c=s/n,l=(e[t].high+e[t].low+e[t].close)/3,u={value:c===0?0:(l-o)/(.015*c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}},Sn=class extends M{descriptor={id:`mfi`,name:`Money Flow Index`,placement:`panel`,defaultConfig:{period:14},shortName:`MFI`,plots:[{key:`value`,title:`MFI`,color:0}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=e.map(e=>(e.high+e.low+e.close)/3),o=a.map((t,n)=>t*e[n].volume);for(let t=n;t<e.length;t++){let s=0,c=0;for(let e=t-n+1;e<=t;e++)a[e]>a[e-1]?s+=o[e]:a[e]<a[e-1]&&(c+=o[e]);let l={value:c===0?100:100-100/(1+s/c)};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}},Cn=class extends M{descriptor={id:`aroon`,name:`Aroon`,placement:`panel`,defaultConfig:{period:25},shortName:`Aroon`,plots:[{key:`up`,title:`Up`,color:0},{key:`down`,title:`Down`,color:1}],scale:{min:0,max:100}};calculate(e,t){let n=F(t,`period`,25,1),r=new N,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=0,o=0,s=-1/0,c=1/0;for(let r=0;r<=n;r++){let i=t-n+r;e[i].high>s&&(s=e[i].high,a=r),e[i].low<c&&(c=e[i].low,o=r)}let l={up:a/n*100,down:o/n*100};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}},wn=class extends M{descriptor={id:`roc`,name:`Rate of Change`,placement:`panel`,defaultConfig:{period:12,source:`close`},shortName:`ROC`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`ROC`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`period`,12,1),r=new N,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].close,o={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},Tn=class extends M{descriptor={id:`tsi`,name:`True Strength Index`,placement:`panel`,defaultConfig:{longPeriod:25,shortPeriod:13,signalPeriod:7,source:`close`},shortName:`TSI`,inputs:{source:{source:!0}},plots:[{key:`tsi`,title:`TSI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};emaSmooth(e,t){let n=2/(t+1),r=[e[0]];for(let t=1;t<e.length;t++)r.push((e[t]-r[t-1])*n+r[t-1]);return r}calculate(e,t){let n=F(t,`longPeriod`,25,1),r=F(t,`shortPeriod`,13,1),i=F(t,`signalPeriod`,7,1),a=new N,o=Array(e.length).fill(null);if(e.length<2)return{values:a,series:o};let s=[],c=[];for(let t=1;t<e.length;t++){let n=e[t].close-e[t-1].close;s.push(n),c.push(Math.abs(n))}let l=this.emaSmooth(this.emaSmooth(s,n),r),u=this.emaSmooth(this.emaSmooth(c,n),r),d=[];for(let e=0;e<l.length;e++)d.push(u[e]===0?0:l[e]/u[e]*100);let f=this.emaSmooth(d,i);for(let t=0;t<d.length;t++){let n=t+1;if(n<e.length){let r={tsi:d[t],signal:f[t]};a.set(e[n].time,r),o[n]=r}}return{values:a,series:o}}},En=class extends M{descriptor={id:`cmf`,name:`Chaikin Money Flow`,placement:`panel`,defaultConfig:{period:20},shortName:`CMF`,plots:[{key:`value`,title:`CMF`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0,o=0;for(let r=t-n+1;r<=t;r++){let t=e[r].high-e[r].low,n=t===0?0:(e[r].close-e[r].low-(e[r].high-e[r].close))/t;a+=n*e[r].volume,o+=e[r].volume}let s={value:o===0?0:a/o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Dn=class extends M{descriptor={id:`voldelta`,name:`Volume Delta`,placement:`panel`,defaultConfig:{mode:0},shortName:`Vol Δ`,plots:[{key:`value`,title:`Delta`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e,t){let n=P(t,`mode`,0)>=1,r=new N,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++){let o=e[t],s=o.close>=o.open,c=s?o.volume:-o.volume;a+=c;let l={value:n?a:c,up:+!!s};r.set(o.time,l),i[t]=l}return{values:r,series:i}}},On=class extends M{descriptor={id:`vortex`,name:`Vortex Indicator`,placement:`panel`,defaultConfig:{period:14},shortName:`VI`,plots:[{key:`viPlus`,title:`VI+`,color:0},{key:`viMinus`,title:`VI−`,color:1}],levels:[1]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0),o=Array(e.length).fill(0),s=Array(e.length).fill(0);for(let t=1;t<e.length;t++){a[t]=Math.abs(e[t].high-e[t-1].low),o[t]=Math.abs(e[t].low-e[t-1].high);let n=e[t].high,r=e[t].low,i=e[t-1].close;s[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let c=0,l=0,u=0;for(let t=1;t<e.length;t++)if(c+=a[t],l+=o[t],u+=s[t],t>n&&(c-=a[t-n],l-=o[t-n],u-=s[t-n]),t>=n&&u>0){let n={viPlus:c/u,viMinus:l/u};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}},kn=class extends M{descriptor={id:`chop`,name:`Choppiness Index`,placement:`panel`,defaultConfig:{period:14},shortName:`CHOP`,plots:[{key:`value`,title:`CHOP`,color:0}],scale:{min:0,max:100},levels:[38.2,61.8]};calculate(e,t){let n=F(t,`period`,14,2),r=new N,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t].high,r=e[t].low,i=e[t-1].close;a[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let o=Math.log10(n),s=0;for(let t=1;t<e.length;t++)if(s+=a[t],t>n&&(s-=a[t-n]),t>=n){let a=-1/0,c=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<c&&(c=e[r].low);let l=a-c;if(l>0&&s>0){let n={value:Math.max(0,Math.min(100,100*Math.log10(s/l)/o))};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}},An=class extends M{descriptor={id:`uo`,name:`Ultimate Oscillator`,placement:`panel`,defaultConfig:{fast:7,mid:14,slow:28},shortName:`UO`,plots:[{key:`value`,title:`UO`,color:0}],scale:{min:0,max:100},levels:[30,70]};calculate(e,t){let n=F(t,`fast`,7,1),r=F(t,`mid`,14,1),i=F(t,`slow`,28,1),a=new N,o=Array(e.length).fill(null);if(e.length<=i)return{values:a,series:o};let s=Array(e.length).fill(0),c=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t-1].close,r=Math.min(e[t].low,n),i=Math.max(e[t].high,n);s[t]=e[t].close-r,c[t]=i-r}let l=(e,t,n)=>{let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r};for(let t=i;t<e.length;t++){let u=jn(l(s,t,n),l(c,t,n)),d=jn(l(s,t,r),l(c,t,r)),f=jn(l(s,t,i),l(c,t,i)),p={value:100*(4*u+2*d+f)/7};a.set(e[t].time,p),o[t]=p}return{values:a,series:o}}};function jn(e,t){return t===0?0:e/t}var Mn=class extends M{descriptor={id:`fi`,name:`Force Index`,placement:`panel`,defaultConfig:{period:13},shortName:`EFI`,plots:[{key:`value`,title:`EFI`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`period`,13,1),r=new N,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=2/(n+1),o;for(let t=1;t<e.length;t++){let s=(e[t].close-e[t-1].close)*e[t].volume;if(o=o===void 0?s:s*a+o*(1-a),t>=n){let n={value:o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}},Nn=class extends M{descriptor={id:`crsi`,name:`Connors RSI`,placement:`panel`,defaultConfig:{rsiPeriod:3,streakPeriod:2,rankPeriod:100,source:`close`},shortName:`CRSI`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`CRSI`,color:0}],scale:{min:0,max:100},levels:[10,90]};calculate(e,t){let n=F(t,`rsiPeriod`,3,1),r=F(t,`streakPeriod`,2,1),i=F(t,`rankPeriod`,100,1),a=new N,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=e.map(e=>e.close),l=Pn(c,n),u=Array(s).fill(0);for(let e=1;e<s;e++)c[e]>c[e-1]?u[e]=u[e-1]>0?u[e-1]+1:1:c[e]<c[e-1]?u[e]=u[e-1]<0?u[e-1]-1:-1:u[e]=0;let d=Pn(u,r),f=Array(s).fill(0);for(let e=1;e<s;e++)f[e]=c[e-1]===0?0:(c[e]-c[e-1])/c[e-1]*100;for(let t=0;t<s;t++){if(t<i+1)continue;let n=l[t],r=d[t];if(n===void 0||r===void 0)continue;let s=0;for(let e=t-i;e<t;e++)f[e]<f[t]&&s++;let c=s/i*100,u={value:(n+r+c)/3};a.set(e[t].time,u),o[t]=u}return{values:a,series:o}}};function Pn(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1],s=n>0?n:0,c=n<0?-n:0;i=(i*(t-1)+s)/t,a=(a*(t-1)+c)/t,r[o]=a===0?100:100-100/(1+i/a)}return r}var Fn=class extends M{descriptor={id:`coppock`,name:`Coppock Curve`,placement:`panel`,defaultConfig:{longRoc:14,shortRoc:11,wma:10,source:`close`},shortName:`Coppock`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`Coppock`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`longRoc`,14,1),r=F(t,`shortRoc`,11,1),i=F(t,`wma`,10,1),a=new N,o=Array(e.length).fill(null),s=e.length,c=Math.max(n,r);if(s<=c+i)return{values:a,series:o};let l=e.map(e=>e.close),u=(e,t)=>l[e-t]===0?0:(l[e]-l[e-t])/l[e-t]*100,d=Array(s).fill(void 0);for(let e=c;e<s;e++)d[e]=u(e,n)+u(e,r);let f=i*(i+1)/2;for(let t=c+i-1;t<s;t++){let n=0,r=!0;for(let e=0;e<i;e++){let a=d[t-e];if(a===void 0){r=!1;break}n+=a*(i-e)}if(!r)continue;let s={value:n/f};a.set(e[t].time,s),o[t]=s}return{values:a,series:o}}},In=class extends M{descriptor={id:`kst`,name:`Know Sure Thing`,placement:`panel`,defaultConfig:{roc1:10,roc2:15,roc3:20,roc4:30,sma1:10,sma2:10,sma3:10,sma4:15,signal:9,source:`close`},shortName:`KST`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`KST`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=F(t,`roc1`,10,1),r=F(t,`roc2`,15,1),i=F(t,`roc3`,20,1),a=F(t,`roc4`,30,1),o=F(t,`sma1`,10,1),s=F(t,`sma2`,10,1),c=F(t,`sma3`,10,1),l=F(t,`sma4`,15,1),u=F(t,`signal`,9,1),d=new N,f=Array(e.length).fill(null),p=e.length;if(p<2)return{values:d,series:f};let m=e.map(e=>e.close),h=Rn(Ln(m,n),o),g=Rn(Ln(m,r),s),_=Rn(Ln(m,i),c),v=Rn(Ln(m,a),l),y=Array(p).fill(void 0);for(let e=0;e<p;e++)h[e]===void 0||g[e]===void 0||_[e]===void 0||v[e]===void 0||(y[e]=h[e]*1+g[e]*2+_[e]*3+v[e]*4);let b=Rn(y,u);for(let t=0;t<p;t++){if(y[t]===void 0)continue;let n={value:y[t]};b[t]!==void 0&&(n.signal=b[t]),d.set(e[t].time,n),f[t]=n}return{values:d,series:f}}};function Ln(e,t){let n=Array(e.length).fill(void 0);for(let r=t;r<e.length;r++)n[r]=e[r-t]===0?0:(e[r]-e[r-t])/e[r-t]*100;return n}function Rn(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){a=!1;break}i+=t}a&&(n[r]=i/t)}return n}var zn=class extends M{descriptor={id:`elderray`,name:`Elder Ray`,placement:`panel`,defaultConfig:{period:13},shortName:`Elder Ray`,plots:[{key:`bull`,title:`Bull`,color:0,kind:`histogram`},{key:`bear`,title:`Bear`,color:1,kind:`histogram`}]};calculate(e,t){let n=F(t,`period`,13,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=2/(n+1),s;for(let t=0;t<a;t++)if(s=s===void 0?e[t].close:e[t].close*o+s*(1-o),t>=n-1){let n={bull:e[t].high-s,bear:e[t].low-s};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(e,t,n,r){let i=t.series;if(!i)return;let o=Math.max(0,n.visibleRange.from),c=Math.min(n.visibleRange.to,i.length-1),l=s(n),u=l(0),d=Math.max(1,n.barWidth/2),f=[[`bull`,r.colors[0],-d],[`bear`,r.colors[1]??r.colors[0],0]];for(let[t,r,s]of f){e.beginPath(),e.fillStyle=r;for(let r=o;r<=c;r++){let o=i[r]?.[t];if(o===void 0||!Number.isFinite(o))continue;let c=l(o);e.rect(a(r,n)+s,Math.min(c,u),d,Math.max(1,Math.abs(c-u)))}e.fill()}}},Bn=class extends M{descriptor={id:`stc`,name:`Schaff Trend Cycle`,placement:`panel`,defaultConfig:{fast:23,slow:50,cycle:10,source:`close`},shortName:`STC`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`STC`,color:0}],scale:{min:0,max:100},levels:[25,75]};calculate(e,t){let n=F(t,`fast`,23,1),r=F(t,`slow`,50,1),i=F(t,`cycle`,10,1),a=new N,o=Array(e.length).fill(null),s=e.length;if(s===0)return{values:a,series:o};let c=e.map(e=>e.close),l=2/(n+1),u=2/(r+1),d=c[0],f=c[0],p=Array(s);for(let e=0;e<s;e++)d=e===0?c[0]:c[e]*l+d*(1-l),f=e===0?c[0]:c[e]*u+f*(1-u),p[e]=d-f;let m=Vn(Vn(p,i),i);for(let t=0;t<s;t++){let n=m[t];if(n===void 0)continue;let r={value:Math.max(0,Math.min(100,n))};a.set(e[t].time,r),o[t]=r}return{values:a,series:o}}};function Vn(e,t){let n=e.length,r=Array(n).fill(void 0),i;for(let a=0;a<n;a++){if(a<t-1)continue;let n=1/0,o=-1/0,s=!0;for(let r=a-t+1;r<=a;r++){let t=e[r];if(t===void 0){s=!1;break}t<n&&(n=t),t>o&&(o=t)}if(!s||e[a]===void 0)continue;let c=o-n>0?(e[a]-n)/(o-n)*100:50;i=i===void 0?c:i+.5*(c-i),r[a]=i}return r}var Hn=class extends M{descriptor={id:`kvo`,name:`Klinger Oscillator`,placement:`panel`,defaultConfig:{fast:34,slow:55,signal:13},shortName:`KVO`,plots:[{key:`value`,title:`KVO`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=F(t,`fast`,34,1),r=F(t,`slow`,55,1),i=F(t,`signal`,13,1),a=new N,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=2/(n+1),l=2/(r+1),u=2/(i+1),d,f=1,p=0,m=0,h,g,_;for(let t=0;t<s;t++){let n=e[t],i=n.high+n.low+n.close,s=d===void 0||i>d?1:-1,v=n.high-n.low;m=d===void 0?v:s===f?m+v:p+v;let y=m===0?0:n.volume*Math.abs(2*(v/m-1))*s*100;h=h===void 0?y:y*c+h*(1-c),g=g===void 0?y:y*l+g*(1-l);let b=h-g;if(_=_===void 0?b:b*u+_*(1-u),d=i,f=s,p=v,t>=r){let e={value:b,signal:_};a.set(n.time,e),o[t]=e}}return{values:a,series:o}}},Un=class extends M{descriptor={id:`fisher`,name:`Fisher Transform`,placement:`panel`,defaultConfig:{period:9},shortName:`Fisher`,plots:[{key:`value`,title:`Fisher`,color:0},{key:`trigger`,title:`Trigger`,color:1}],levels:[0]};calculate(e,t){let n=F(t,`period`,9,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=e.map(e=>(e.high+e.low)/2),s=0,c=0;for(let t=n-1;t<a;t++){let a=-1/0,l=1/0;for(let e=t-n+1;e<=t;e++)o[e]>a&&(a=o[e]),o[e]<l&&(l=o[e]);s=.33*(a-l>0?2*(o[t]-l)/(a-l)-1:0)+.67*s,s=Math.max(-.999,Math.min(.999,s));let u=c;c=.5*Math.log((1+s)/(1-s))+.5*c;let d={value:c,trigger:u};r.set(e[t].time,d),i[t]=d}return{values:r,series:i}}},Wn=class extends M{descriptor={id:`dpo`,name:`Detrended Price Oscillator`,placement:`panel`,defaultConfig:{period:20,source:`close`},shortName:`DPO`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`DPO`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=F(t,`period`,20,2),r=Math.floor(n/2)+1,i=new N,a=Array(e.length).fill(null),o=e.length;if(o<n)return{values:i,series:a};let s=0;for(let t=0;t<o;t++)if(s+=e[t].close,t>=n&&(s-=e[t-n].close),t>=n-1&&t-r>=0){let o=s/n,c={value:e[t-r].close-o};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}},Gn=class extends M{descriptor={id:`bop`,name:`Balance of Power`,placement:`panel`,defaultConfig:{smooth:14},shortName:`BOP`,plots:[{key:`value`,title:`BOP`,color:0}],scale:{min:-1,max:1},levels:[0]};calculate(e,t){let n=F(t,`smooth`,14,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=Array(a);for(let t=0;t<a;t++){let n=e[t].high-e[t].low;o[t]=n>0?(e[t].close-e[t].open)/n:0}let s=0;for(let t=0;t<a;t++)if(s+=o[t],t>=n&&(s-=o[t-n]),t>=n-1){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},Kn=class extends M{descriptor={id:`massindex`,name:`Mass Index`,placement:`panel`,defaultConfig:{ema:9,sum:25},shortName:`Mass`,plots:[{key:`value`,title:`Mass`,color:0}],levels:[26.5,27]};calculate(e,t){let n=F(t,`ema`,9,1),r=F(t,`sum`,25,1),i=new N,a=Array(e.length).fill(null),o=e.length;if(o<r)return{values:i,series:a};let s=2/(n+1),c,l,u=Array(o).fill(0);for(let t=0;t<o;t++){let n=e[t].high-e[t].low;c=c===void 0?n:n*s+c*(1-s),l=l===void 0?c:c*s+l*(1-s),u[t]=l===0?1:c/l}let d=0;for(let t=0;t<o;t++)if(d+=u[t],t>=r&&(d-=u[t-r]),t>=n+r){let n={value:d};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}},qn=class extends M{descriptor={id:`cmo`,name:`Chande Momentum`,placement:`panel`,defaultConfig:{period:9,source:`close`},shortName:`CMO`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`CMO`,color:0}],scale:{min:-100,max:100},levels:[-50,0,50]};calculate(e,t){let n=F(t,`period`,9,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=1;t<a;t++){let n=e[t].close-e[t-1].close;o[t]=n>0?n:0,s[t]=n<0?-n:0}let c=0,l=0;for(let t=1;t<a;t++)if(c+=o[t],l+=s[t],t>n&&(c-=o[t-n],l-=s[t-n]),t>=n){let n=c+l,a={value:n>0?100*(c-l)/n:0};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},Jn=class extends M{descriptor={id:`trix`,name:`TRIX`,placement:`panel`,defaultConfig:{period:15,signal:9,source:`close`},shortName:`TRIX`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`TRIX`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=F(t,`period`,15,1),r=F(t,`signal`,9,1),i=new N,a=Array(e.length).fill(null),o=e.length;if(o<2)return{values:i,series:a};let s=Yn(Yn(Yn(e.map(e=>e.close),n),n),n),c=Array(o).fill(0);for(let e=1;e<o;e++)c[e]=s[e-1]===0?0:(s[e]-s[e-1])/s[e-1]*100;let l=Yn(c,r),u=3*n;for(let t=u;t<o;t++){let n={value:c[t],signal:l[t]};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}};function Yn(e,t){let n=2/(t+1),r=Array(e.length).fill(0),i=e[0]??0;r[0]=i;for(let t=1;t<e.length;t++)i=e[t]*n+i*(1-n),r[t]=i;return r}var Xn=class extends M{descriptor={id:`emv`,name:`Ease of Movement`,placement:`panel`,defaultConfig:{period:14},shortName:`EOM`,plots:[{key:`value`,title:`EOM`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<2)return{values:r,series:i};let o=Array(a).fill(0);for(let t=1;t<a;t++){let n=(e[t].high+e[t].low)/2,r=(e[t-1].high+e[t-1].low)/2,i=e[t].high-e[t].low,a=e[t].volume;o[t]=a>0?(n-r)*i/a:0}let s=0;for(let t=1;t<a;t++)if(s+=o[t],t>n&&(s-=o[t-n]),t>=n){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},Zn=class extends M{descriptor={id:`pvt`,name:`Price Volume Trend`,placement:`panel`,defaultConfig:{},shortName:`PVT`,plots:[{key:`value`,title:`PVT`,color:0}]};calculate(e,t){let n=new N,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close;i!==0&&(a+=e[t].volume*(e[t].close-i)/i);let o={value:a};n.set(e[t].time,o),r[t]=o}return{values:n,series:r}}},Qn=class extends M{descriptor={id:`wad`,name:`Williams A/D`,placement:`panel`,defaultConfig:{},shortName:`WAD`,plots:[{key:`value`,title:`WAD`,color:0}]};calculate(e,t){let n=new N,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close,o=e[t].close;o>i?a+=o-Math.min(e[t].low,i):o<i&&(a+=o-Math.max(e[t].high,i));let s={value:a};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}},$n=class extends M{descriptor={id:`chaikinvol`,name:`Chaikin Volatility`,placement:`panel`,defaultConfig:{ema:10,roc:10},shortName:`CV`,plots:[{key:`value`,title:`CV`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`ema`,10,1),r=F(t,`roc`,10,1),i=new N,a=Array(e.length).fill(null),o=e.length;if(o<=r)return{values:i,series:a};let s=2/(n+1),c=Array(o),l=e[0].high-e[0].low;c[0]=l;for(let t=1;t<o;t++)l=(e[t].high-e[t].low)*s+l*(1-s),c[t]=l;for(let t=n+r;t<o;t++){let n=c[t-r],o={value:n===0?0:(c[t]-n)/n*100};i.set(e[t].time,o),a[t]=o}return{values:i,series:a}}},er=class extends M{descriptor={id:`rvi`,name:`Relative Vigor Index`,placement:`panel`,defaultConfig:{period:10},shortName:`RVGI`,plots:[{key:`value`,title:`RVGI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=F(t,`period`,10,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<n+3)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=0;t<a;t++)o[t]=e[t].close-e[t].open,s[t]=e[t].high-e[t].low;let c=(e,t)=>(e[t]+2*e[t-1]+2*e[t-2]+e[t-3])/6,l=Array(a).fill(void 0),u=Array(a).fill(void 0);for(let e=3;e<a;e++)l[e]=c(o,e),u[e]=c(s,e);let d=Array(a).fill(void 0);for(let e=3+n-1;e<a;e++){let t=0,r=0;for(let i=e-n+1;i<=e;i++)t+=l[i],r+=u[i];d[e]=r===0?0:t/r}for(let t=0;t<a;t++){if(d[t]===void 0)continue;let n={value:d[t]};t>=3&&d[t-3]!==void 0&&(n.signal=(d[t]+2*d[t-1]+2*d[t-2]+d[t-3])/6),r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}},tr=class extends M{descriptor={id:`stochrsi`,name:`Stochastic RSI`,placement:`panel`,defaultConfig:{rsiPeriod:14,stochPeriod:14,k:3,d:3,source:`close`},shortName:`Stoch RSI`,inputs:{source:{source:!0}},plots:[{key:`k`,title:`%K`,color:0},{key:`d`,title:`%D`,color:1}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=F(t,`rsiPeriod`,14,1),r=F(t,`stochPeriod`,14,1),i=F(t,`k`,3,1),a=F(t,`d`,3,1),o=new N,s=Array(e.length).fill(null),c=e.length;if(c<=n+r)return{values:o,series:s};let l=nr(e.map(e=>e.close),n),u=Array(c).fill(void 0);for(let e=0;e<c;e++){if(l[e]===void 0)continue;let t=1/0,n=-1/0,i=!0;for(let a=e-r+1;a<=e;a++){if(a<0||l[a]===void 0){i=!1;break}l[a]<t&&(t=l[a]),l[a]>n&&(n=l[a])}i&&(u[e]=n-t>0?(l[e]-t)/(n-t)*100:0)}let d=rr(u,i),f=rr(d,a);for(let t=0;t<c;t++){if(d[t]===void 0)continue;let n={k:d[t]};f[t]!==void 0&&(n.d=f[t]),o.set(e[t].time,n),s[t]=n}return{values:o,series:s}}};function nr(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1];i=(i*(t-1)+(n>0?n:0))/t,a=(a*(t-1)+(n<0?-n:0))/t,r[o]=a===0?100:100-100/(1+i/a)}return r}function rr(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){if(e[n]===void 0){a=!1;break}i+=e[n]}a&&(n[r]=i/t)}return n}var ir=class extends M{descriptor={id:`ppo`,name:`Percentage Price Oscillator`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9,source:`close`},shortName:`PPO`,inputs:{source:{source:!0}},plots:[{key:`hist`,title:`Histogram`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`value`,title:`PPO`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=F(t,`fast`,12,1),r=F(t,`slow`,26,1),i=F(t,`signal`,9,1),a=new N,o=Array(e.length).fill(null),s=e.length;if(s<=r)return{values:a,series:o};let c=e.map(e=>e.close),l=ar(c,n),u=ar(c,r),d=Array(s).fill(void 0);for(let e=0;e<s;e++)l[e]===void 0||u[e]===void 0||u[e]===0||(d[e]=(l[e]-u[e])/u[e]*100);let f=ar(d,i);for(let t=0;t<s;t++){if(d[t]===void 0)continue;let n={value:d[t]};f[t]!==void 0&&(n.signal=f[t],n.hist=d[t]-f[t]),a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}};function ar(e,t){let n=e.length,r=Array(n).fill(void 0),i=2/(t+1),a,o=0,s=0;for(let c=0;c<n;c++){let n=e[c];n!==void 0&&(a===void 0?(o+=n,s++,s===t&&(a=o/t,r[c]=a)):(a=n*i+a*(1-i),r[c]=a))}return r}var or=class extends M{descriptor={id:`ac`,name:`Accelerator Oscillator`,placement:`panel`,defaultConfig:{},shortName:`AC`,plots:[{key:`value`,title:`AC`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e){let t=new N,n=Array(e.length).fill(null),r=e.length;if(r<38)return{values:t,series:n};let i=e.map(e=>(e.high+e.low)/2),a=Array(r).fill(void 0);for(let e=33;e<r;e++)a[e]=sr(i,e,5)-sr(i,e,34);let o;for(let i=37;i<r;i++){let r=0;for(let e=i-4;e<=i;e++)r+=a[e];let s=a[i]-r/5,c=o===void 0?s>=0:s>=o;o=s;let l={value:s,up:+!!c};t.set(e[i].time,l),n[i]=l}return{values:t,series:n}}};function sr(e,t,n){let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r/n}var cr=class extends M{descriptor={id:`rmi`,name:`Relative Momentum Index`,placement:`panel`,defaultConfig:{period:20,momentum:5,source:`close`},shortName:`RMI`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`RMI`,color:0}],scale:{min:0,max:100},levels:[30,70]};calculate(e,t){let n=F(t,`period`,20,1),r=F(t,`momentum`,5,1),i=new N,a=Array(e.length).fill(null),o=e.length;if(o<=n+r)return{values:i,series:a};let s=e.map(e=>e.close),c=Array(o).fill(0),l=Array(o).fill(0);for(let e=r;e<o;e++){let t=s[e]-s[e-r];c[e]=t>0?t:0,l[e]=t<0?-t:0}let u=0,d=0,f=r+n;for(let e=r+1;e<=f;e++)u+=c[e],d+=l[e];u/=n,d/=n;let p=t=>{let n={value:d===0?100:100-100/(1+u/d)};i.set(e[t].time,n),a[t]=n};p(f);for(let e=f+1;e<o;e++)u=(u*(n-1)+c[e])/n,d=(d*(n-1)+l[e])/n,p(e);return{values:i,series:a}}},lr=class extends M{descriptor={id:`disparity`,name:`Disparity Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`DI`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`DI`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let a=o/n,s={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},ur=class extends M{descriptor={id:`qstick`,name:`Qstick`,placement:`panel`,defaultConfig:{period:8},shortName:`Qstick`,plots:[{key:`value`,title:`Qstick`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`period`,8,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++){let a=e[t].close-e[t].open;if(o+=a,t>=n&&(o-=e[t-n].close-e[t-n].open),t>=n-1){let a={value:o/n};r.set(e[t].time,a),i[t]=a}}return{values:r,series:i}}},dr=class extends M{descriptor={id:`pgo`,name:`Pretty Good Oscillator`,placement:`panel`,defaultConfig:{period:14},shortName:`PGO`,plots:[{key:`value`,title:`PGO`,color:0}],levels:[-3,0,3]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0);for(let t=0;t<a;t++){if(t===0){o[t]=e[t].high-e[t].low;continue}let n=e[t-1].close;o[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let s=Array(a).fill(void 0),c=0;for(let e=1;e<=n;e++)c+=o[e];s[n]=c/n;for(let e=n+1;e<a;e++)s[e]=(s[e-1]*(n-1)+o[e])/n;let l=0;for(let t=0;t<a;t++)if(l+=e[t].close,t>=n&&(l-=e[t-n].close),t>=n&&s[t]!==void 0&&s[t]>0){let a=l/n,o={value:(e[t].close-a)/s[t]};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},fr=class extends M{descriptor={id:`stddev`,name:`Standard Deviation`,placement:`panel`,defaultConfig:{period:20,source:`close`},shortName:`StdDev`,inputs:{source:{source:!0}},plots:[{key:`value`,title:`StdDev`,color:0}]};calculate(e,t){let n=F(t,`period`,20,1),r=new N,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=e[r].close;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=e[r].close-o;s+=t*t}let c={value:Math.sqrt(s/n)};r.set(e[t].time,c),i[t]=c}return{values:r,series:i}}},pr=class extends M{descriptor={id:`volumeProfile`,name:`Volume Profile`,placement:`overlay`,defaultConfig:{rows:24},shortName:`VP`,plots:[]};calculate(e,t){let n=F(t,`rows`,24,1),r=new N,i=Array(e.length).fill(null);if(e.length===0)return{values:r,series:i};let a=1/0,o=-1/0;for(let t of e)t.low<a&&(a=t.low),t.high>o&&(o=t.high);let s=(o-a||1)/n,c=Array(n).fill(0);for(let t of e){let e=(t.high+t.low+t.close)/3,r=Math.min(n-1,Math.floor((e-a)/s));c[r]+=t.volume}for(let e=0;e<n;e++){let t=a+(e+.5)*s;r.set(e,{price:t,volume:c[e],rowIndex:e})}return{values:r,series:i,meta:{minPrice:a,maxPrice:o,rows:n,rowHeight:s,bins:c,maxVolume:Math.max(...c)}}}render(e,t,n,r){let{chartRect:i}=n,a=t.meta;if(!a||a.maxVolume===0)return;let{minPrice:o,rows:c,rowHeight:l,bins:u,maxVolume:d}=a,f=i.width*.3,p=s(n);for(let t=0;t<c;t++){let n=p(o+t*l),a=p(o+(t+1)*l),s=u[t]/d*f;e.fillStyle=u[t]>d*.7?r.colors[1]??`rgba(242, 169, 59, 0.5)`:r.colors[0]??`rgba(76, 141, 255, 0.3)`,e.fillRect(i.x,Math.min(n,a),s,Math.max(Math.abs(n-a)-1,1))}}},mr=class extends M{descriptor={id:`ad`,name:`Accumulation/Distribution`,placement:`panel`,defaultConfig:{},shortName:`A/D`,plots:[{key:`value`,title:`A/D`,color:0}]};calculate(e,t){let n=new N,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0;for(let t=0;t<e.length;t++){let a=e[t].high-e[t].low,o=a===0?0:(e[t].close-e[t].low-(e[t].high-e[t].close))/a;i+=o*e[t].volume;let s={value:i};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}},hr=class extends M{descriptor={id:`vroc`,name:`Volume Rate of Change`,placement:`panel`,defaultConfig:{period:14},shortName:`VROC`,plots:[{key:`value`,title:`VROC`,color:0}],levels:[0]};calculate(e,t){let n=F(t,`period`,14,1),r=new N,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].volume,o={value:a===0?0:(e[t].volume-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}};function I(e,t){let n=new N;for(let r=0;r<t.length;r++){let i=t[r];i&&n.set(e[r].time,i)}return{values:n,series:t}}function gr(e){return e.map(e=>e.close)}function _r(e,t){let n=Array(e.length).fill(void 0),r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o===void 0){r=0,i=0;continue}r+=o,i++,i>t&&(r-=e[a-t]),i>=t&&(n[a]=r/t)}return n}function vr(e,t,n){let r=Array(e.length).fill(void 0),i=0,a=0,o;for(let s=0;s<e.length;s++){let c=e[s];if(c!==void 0){if(o===void 0){i+=c,a++,a===t&&(r[s]=o=i/t);continue}o+=n*(c-o),r[s]=o}}return r}function L(e,t){return vr(e,t,2/(t+1))}function yr(e,t){return vr(e,t,1/t)}function br(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=0,o=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){o=!1;break}i+=t,a+=t*t}if(!o)continue;let s=i/t;n[r]=Math.sqrt(Math.max(0,a/t-s*s))}return n}function xr(e){return e.map((t,n)=>{if(n===0)return t.high-t.low;let r=e[n-1].close;return Math.max(t.high-t.low,Math.abs(t.high-r),Math.abs(t.low-r))})}function Sr(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return;t>r&&(r=t)}return r}function Cr(e,t,n){if(t<n-1)return;let r=1/0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return;t<r&&(r=t)}return r}function wr(e,t=`value`){return e.map(e=>e!==void 0&&Number.isFinite(e)?{[t]:e}:null)}function Tr(e,t,n){if(t<n-1||t>=e.length)return;let r=0,i=0;for(let a=t-n+1;a<=t;a++){let t=e[a].close;r+=t,i+=t*t}let a=r/n;return{mean:a,sd:Math.sqrt(Math.max(0,i/n-a*a))}}function Er(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++)e[i].high>r&&(r=e[i].high);return r}function Dr(e,t,n){if(t<n-1)return;let r=1/0;for(let i=t-n+1;i<=t;i++)e[i].low<r&&(r=e[i].low);return r}function Or(e,t,n){if(t<n-1)return;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].close;return r/n}function kr(e,t,n){if(n<2||t<n-1)return;let r=n,i=(r-1)/2,a=0;for(let n=0;n<r;n++)a+=e[t-r+1+n].close;a/=r;let o=0,s=0,c=0;for(let n=0;n<r;n++){let l=n-i,u=e[t-r+1+n].close-a;o+=l*u,s+=l*l,c+=u*u}let l=o/s,u=a-l*i,d=0;for(let n=0;n<r;n++){let i=e[t-r+1+n].close-(u+l*n);d+=i*i}return{slope:l,end:u+l*(r-1),stdErr:r>2?Math.sqrt(d/(r-2)):0,r:c===0?0:o/Math.sqrt(s*c)}}var Ar=class extends M{descriptor={id:`dema`,name:`Double Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`DEMA`,inputs:{period:{min:1},source:{source:!0}},plots:[{key:`value`,title:`DEMA`,color:0}]};emas=new WeakMap;calculate(e,t){let n=F(t,`period`,20,1),r=L(gr(e),n),i=L(r,n),a=I(e,wr(r.map((e,t)=>e!==void 0&&i[t]!==void 0?2*e-i[t]:void 0)));return this.emas.set(a,{e1:r,e2:i}),a}update(e,t,n,r){let i=this.emas.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.e1[r-1],o=i.e2[r-1];if(a===void 0||o===void 0)return null;let s=2/(F(t,`period`,20,1)+1);for(let t=r;t<e.length;t++)a+=s*(e[t].close-a),o+=s*(a-o),i.e1[t]=a,i.e2[t]=o,this.writePoint(n,e,t,{value:2*a-o});return n}},jr=class extends M{descriptor={id:`smma`,name:`Smoothed Moving Average`,placement:`overlay`,defaultConfig:{period:14,source:`close`},shortName:`SMMA`,inputs:{period:{min:1},source:{source:!0}},plots:[{key:`value`,title:`SMMA`,color:0}]};calculate(e,t){return I(e,wr(yr(gr(e),F(t,`period`,14,1))))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;let a=F(t,`period`,14,1);for(let t=r;t<e.length;t++)i+=(e[t].close-i)/a,this.writePoint(n,e,t,{value:i});return n}},R=class extends M{times=new WeakMap;lookback(e){return 0}revisesBefore(e){return this.lookback(this.read(e))}calculate(e,t){let n=this.read(t),r=Array(e.length);for(let t=0;t<e.length;t++)r[t]=this.pointAt(e,t,n);let i=I(e,r);return this.times.set(i,e.map(e=>e.time)),i}update(e,t,n,r){let i=this.times.get(n);if(!i||!this.canResume(e,n,r))return null;for(let t=r;t<i.length&&t<e.length;t++)if(i[t]!==e[t].time)return null;let a=this.read(t);for(let t=Math.max(0,r-this.lookback(a));t<e.length;t++)this.writePoint(n,e,t,this.pointAt(e,t,a));i.length=e.length;for(let t=r;t<e.length;t++)i[t]=e[t].time;return n}},Mr=class extends R{descriptor={id:`alma`,name:`Arnaud Legoux Moving Average`,placement:`overlay`,defaultConfig:{period:9,offset:.85,sigma:6,source:`close`},shortName:`ALMA`,inputs:{period:{min:1,max:5e3},offset:{min:0,max:1,step:.05},sigma:{min:.5,step:.5},source:{source:!0}},plots:[{key:`value`,title:`ALMA`,color:0}]};read(e){let t=Math.min(5e3,F(e,`period`,9,1)),n=Math.min(1,Math.max(0,P(e,`offset`,.85))),r=Math.max(.5,P(e,`sigma`,6)),i=n*(t-1),a=t/r,o=Array.from({length:t},(e,t)=>Math.exp(-((t-i)**2)/(2*a*a)));return{period:t,weights:o,norm:o.reduce((e,t)=>e+t,0)}}pointAt(e,t,{period:n,weights:r,norm:i}){if(t<n-1)return null;let a=0;for(let i=0;i<n;i++)a+=r[i]*e[t-n+1+i].close;return{value:a/i}}},Nr=class extends M{descriptor={id:`kama`,name:`Kaufman Adaptive Moving Average`,placement:`overlay`,defaultConfig:{period:10,fast:2,slow:30,source:`close`},shortName:`KAMA`,inputs:{period:{min:1},fast:{min:1},slow:{min:1},source:{source:!0}},plots:[{key:`value`,title:`KAMA`,color:0}]};calculate(e,t){let n=I(e,Array(e.length).fill(null)),r=F(t,`period`,10,1);return e.length<=r||this.extend(e,t,n,r,e[r-1].close),n}update(e,t,n,r){if(r<=F(t,`period`,10,1)||!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;return i===void 0?null:(this.extend(e,t,n,r,i),n)}extend(e,t,n,r,i){let a=F(t,`period`,10,1),o=2/(F(t,`fast`,2,1)+1),s=2/(F(t,`slow`,30,1)+1);for(let t=r;t<e.length;t++){let r=0;for(let n=t-a+1;n<=t;n++)r+=Math.abs(e[n].close-e[n-1].close);let c=Math.abs(e[t].close-e[t-a].close),l=((r>0?c/r:0)*(o-s)+s)**2;i+=l*(e[t].close-i),this.writePoint(n,e,t,{value:i})}}},Pr=class extends R{descriptor={id:`lsma`,name:`Least Squares Moving Average`,placement:`overlay`,defaultConfig:{period:25,offset:0,source:`close`},shortName:`LSMA`,inputs:{period:{min:2,max:5e3},offset:{step:1},source:{source:!0}},plots:[{key:`value`,title:`LSMA`,color:0}]};read(e){let t=Math.min(5e3,F(e,`period`,25,2)),n=Math.round(F(e,`offset`,0,-1e3)),r=t*(t-1)/2;return{period:t,offset:n,sx:r,denom:t*((t-1)*t*(2*t-1)/6)-r*r}}pointAt(e,t,{period:n,offset:r,sx:i,denom:a}){if(t<n-1)return null;let o=0,s=0;for(let r=0;r<n;r++){let i=e[t-n+1+r].close;o+=i,s+=r*i}let c=(n*s-i*o)/a;return{value:(o-c*i)/n+c*(n-1-r)}}},Fr=class extends M{descriptor={id:`mcginley`,name:`McGinley Dynamic`,placement:`overlay`,defaultConfig:{period:14,source:`close`},shortName:`McGinley`,inputs:{period:{min:1},source:{source:!0}},plots:[{key:`value`,title:`McGinley`,color:0}]};calculate(e,t){let n=F(t,`period`,14,1),r=L(gr(e),n),i=Array(e.length).fill(void 0),a;for(let t=0;t<e.length;t++)a=a===void 0?r[t]:Ir(a,e[t].close,n),i[t]=a;return I(e,wr(i))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;let a=F(t,`period`,14,1);for(let t=r;t<e.length;t++)i=Ir(i,e[t].close,a),this.writePoint(n,e,t,{value:i});return n}};function Ir(e,t,n){return e>0&&t>0?e+(t-e)/(n*(t/e)**4):t}var Lr=class extends M{descriptor={id:`macross`,name:`MA Cross`,placement:`overlay`,defaultConfig:{fast:9,slow:21,type:`sma`,source:`close`},shortName:`MA Cross`,inputs:{fast:{min:1},slow:{min:1},type:{options:[`sma`,`ema`]},source:{source:!0}},plots:[{key:`fast`,title:`Fast`,color:0},{key:`slow`,title:`Slow`,color:1}]};calculate(e,t){let n=F(t,`fast`,9,1),r=F(t,`slow`,21,1);if(t.params.type!==`ema`)return I(e,e.map((t,i)=>Rr(Or(e,i,n),Or(e,i,r))));let i=gr(e),a=L(i,n),o=L(i,r);return I(e,a.map((e,t)=>Rr(e,o[t])))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=F(t,`fast`,9,1),a=F(t,`slow`,21,1);if(t.params.type!==`ema`){for(let t=r;t<e.length;t++)this.writePoint(n,e,t,Rr(Or(e,t,i),Or(e,t,a)));return n}let o=n.series[r-1]?.fast,s=n.series[r-1]?.slow;if(o===void 0||s===void 0)return null;for(let t=r;t<e.length;t++)o+=2/(i+1)*(e[t].close-o),s+=2/(a+1)*(e[t].close-s),this.writePoint(n,e,t,{fast:o,slow:s});return n}};function Rr(e,t){return e===void 0&&t===void 0?null:{...e===void 0?{}:{fast:e},...t===void 0?{}:{slow:t}}}var zr=class extends R{descriptor={id:`fractals`,name:`Williams Fractals`,placement:`overlay`,defaultConfig:{period:2},shortName:`Fractals`,inputs:{period:{min:1,max:10}},plots:[{key:`up`,title:`Up`,color:0,kind:`dots`},{key:`down`,title:`Down`,color:1,kind:`dots`}]};read(e){return F(e,`period`,2,1)}lookback(e){return e}pointAt(e,t,n){if(t<n||t>e.length-n-1)return null;let r=!0,i=!0;for(let a=t-n;a<=t+n&&(r||i);a++)a!==t&&(e[a].high>=e[t].high&&(r=!1),e[a].low<=e[t].low&&(i=!1));return!r&&!i?null:{...r?{up:e[t].high}:{},...i?{down:e[t].low}:{}}}},Br=class extends M{descriptor={id:`cks`,name:`Chande Kroll Stop`,placement:`overlay`,defaultConfig:{p:10,x:1,q:9},shortName:`CKS`,inputs:{p:{label:`ATR length`,min:1},x:{label:`ATR multiplier`,min:0,step:.1},q:{label:`Stop length`,min:1}},plots:[{key:`long`,title:`Stop Long`,color:0},{key:`short`,title:`Stop Short`,color:1}]};states=new WeakMap;calculate(e,t){let n=F(t,`p`,10,1),r=P(t,`x`,1),i=F(t,`q`,9,1),a={atr:yr(xr(e),n),firstHigh:[],firstLow:[]};for(let t=0;t<e.length;t++)Vr(e,a,t,n,r);let o=I(e,e.map((e,t)=>Hr(a,t,i)));return this.states.set(o,a),o}update(e,t,n,r){let i=this.states.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.atr[r-1];if(a===void 0)return null;let o=F(t,`p`,10,1),s=P(t,`x`,1),c=F(t,`q`,9,1);for(let t=r;t<e.length;t++){let r=e[t-1].close,l=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-r),Math.abs(e[t].low-r));a+=(l-a)/o,i.atr[t]=a,Vr(e,i,t,o,s),this.writePoint(n,e,t,Hr(i,t,c))}return n}};function Vr(e,t,n,r,i){let a=t.atr[n],o=Er(e,n,r),s=Dr(e,n,r);t.firstHigh[n]=o!==void 0&&a!==void 0?o-i*a:void 0,t.firstLow[n]=s!==void 0&&a!==void 0?s+i*a:void 0}function Hr(e,t,n){let r=Sr(e.firstHigh,t,n),i=Cr(e.firstLow,t,n);return r!==void 0&&i!==void 0?{long:i,short:r}:null}var Ur=class extends R{descriptor={id:`bbpb`,name:`Bollinger Bands %B`,placement:`panel`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`%B`,inputs:{period:{min:2},stdDev:{min:.1,step:.1},source:{source:!0}},plots:[{key:`value`,title:`%B`,color:0}],levels:[0,.5,1]};read(e){return{period:F(e,`period`,20,2),k:P(e,`stdDev`,2)}}pointAt(e,t,{period:n,k:r}){let i=Tr(e,t,n);return!i||i.sd===0?null:{value:(e[t].close-(i.mean-r*i.sd))/(2*r*i.sd)}}},Wr=class extends R{descriptor={id:`bbw`,name:`Bollinger BandWidth`,placement:`panel`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`BBW`,inputs:{period:{min:2},stdDev:{min:.1,step:.1},source:{source:!0}},plots:[{key:`value`,title:`BBW`,color:0}]};read(e){return{period:F(e,`period`,20,2),k:P(e,`stdDev`,2)}}pointAt(e,t,{period:n,k:r}){let i=Tr(e,t,n);return!i||i.mean===0?null:{value:2*r*i.sd/i.mean}}},Gr=class extends R{descriptor={id:`mom`,name:`Momentum`,placement:`panel`,defaultConfig:{period:10,source:`close`},shortName:`MOM`,inputs:{period:{min:1},source:{source:!0}},plots:[{key:`value`,title:`MOM`,color:0}],levels:[0]};read(e){return F(e,`period`,10,1)}pointAt(e,t,n){return t>=n?{value:e[t].close-e[t-n].close}:null}},Kr=class extends R{descriptor={id:`hv`,name:`Historical Volatility`,placement:`panel`,defaultConfig:{period:10,annual:365,source:`close`},shortName:`HV`,inputs:{period:{min:2},annual:{label:`Bars per year`,min:1},source:{source:!0}},plots:[{key:`value`,title:`HV`,color:0}],scale:{min:0}};read(e){return{period:F(e,`period`,10,2),annual:Math.max(1,P(e,`annual`,365))}}pointAt(e,t,{period:n,annual:r}){if(t<n)return null;let i=0,a=0;for(let r=t-n+1;r<=t;r++){let t=e[r-1].close,n=e[r].close;if(!(t>0&&n>0))return null;let o=Math.log(n/t);i+=o,a+=o*o}let o=i/n;return{value:100*Math.sqrt(Math.max(0,a/n-o*o))*Math.sqrt(r)}}},qr=class extends M{descriptor={id:`vo`,name:`Volume Oscillator`,placement:`panel`,defaultConfig:{short:5,long:10},shortName:`Vol Osc`,inputs:{short:{min:1},long:{min:1}},plots:[{key:`value`,title:`Vol Osc`,color:0}],levels:[0]};emas=new WeakMap;calculate(e,t){let n=e.map(e=>e.volume),r=L(n,F(t,`short`,5,1)),i=L(n,F(t,`long`,10,1)),a=I(e,wr(r.map((e,t)=>Jr(e,i[t]))));return this.emas.set(a,{fast:r,slow:i}),a}update(e,t,n,r){let i=this.emas.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.fast[r-1],o=i.slow[r-1];if(a===void 0||o===void 0)return null;let s=2/(F(t,`short`,5,1)+1),c=2/(F(t,`long`,10,1)+1);for(let t=r;t<e.length;t++){a+=s*(e[t].volume-a),o+=c*(e[t].volume-o),i.fast[t]=a,i.slow[t]=o;let r=Jr(a,o);this.writePoint(n,e,t,r===void 0?null:{value:r})}return n}};function Jr(e,t){return e===void 0||t===void 0||t===0?void 0:100*(e-t)/t}var Yr=class extends M{descriptor={id:`ulcer`,name:`Ulcer Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`Ulcer`,inputs:{period:{min:1},source:{source:!0}},plots:[{key:`value`,title:`Ulcer`,color:0}],scale:{min:0}};drawdowns=new WeakMap;calculate(e,t){let n=F(t,`period`,14,1),r=e.map((t,r)=>Xr(e,r,n)),i=I(e,e.map((e,t)=>Zr(r,t,n)));return this.drawdowns.set(i,r),i}update(e,t,n,r){let i=this.drawdowns.get(n);if(!i||!this.canResume(e,n,r))return null;let a=F(t,`period`,14,1);for(let t=r;t<e.length;t++)i[t]=Xr(e,t,a);i.length=e.length;for(let t=r;t<e.length;t++)this.writePoint(n,e,t,Zr(i,t,a));return n}};function Xr(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++)e[i].close>r&&(r=e[i].close);return r===0?void 0:100*(e[t].close-r)/r}function Zr(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return null;r+=t*t}return{value:Math.sqrt(r/n)}}var Qr=class extends M{descriptor={id:`smi`,name:`Stochastic Momentum Index`,placement:`panel`,defaultConfig:{period:10,smooth:3,signal:3},shortName:`SMI`,inputs:{period:{min:1},smooth:{min:1},signal:{min:1}},plots:[{key:`smi`,title:`SMI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[40,-40]};calculate(e,t){let n=F(t,`period`,10,1),r=F(t,`smooth`,3,1),i=F(t,`signal`,3,1),a=Array(e.length).fill(void 0),o=Array(e.length).fill(void 0);for(let t=n-1;t<e.length;t++){let r=Er(e,t,n),i=Dr(e,t,n);r===void 0||i===void 0||(a[t]=e[t].close-(r+i)/2,o[t]=r-i)}let s=L(L(a,r),r),c=L(L(o,r),r),l=s.map((e,t)=>{let n=c[t]===void 0?void 0:c[t]/2;if(!(e===void 0||n===void 0))return n===0?0:Math.max(-100,Math.min(100,100*e/n))}),u=L(l,i);return I(e,l.map((e,t)=>{if(e===void 0)return null;let n={smi:e};return u[t]!==void 0&&(n.signal=u[t]),n}))}},$r=class extends M{descriptor={id:`rvix`,name:`Relative Volatility Index`,placement:`panel`,defaultConfig:{period:10,smooth:14},shortName:`RVI (vol)`,inputs:{period:{min:2},smooth:{min:1}},plots:[{key:`value`,title:`RVI`,color:0}],levels:[80,50,20],scale:{min:0,max:100}};calculate(e,t){let n=F(t,`period`,10,2),r=F(t,`smooth`,14,1),i=br(gr(e),n),a=i.map((t,n)=>t===void 0||n===0?void 0:e[n].close>e[n-1].close?t:0),o=i.map((t,n)=>t===void 0||n===0?void 0:e[n].close<e[n-1].close?t:0),s=L(a,r),c=L(o,r);return I(e,wr(s.map((e,t)=>{let n=c[t];if(!(e===void 0||n===void 0))return e+n===0?50:100*e/(e+n)})))}},ei=class extends R{descriptor={id:`trendstrength`,name:`Trend Strength Index`,placement:`panel`,defaultConfig:{period:14},shortName:`TSI (trend)`,inputs:{period:{min:2}},plots:[{key:`value`,title:`Trend`,color:0}],levels:[0],scale:{min:-1,max:1}};read(e){return F(e,`period`,14,2)}pointAt(e,t,n){let r=kr(e,t,n);return r?{value:r.r}:null}},ti=class extends R{descriptor={id:`lrslope`,name:`Linear Regression Slope`,placement:`panel`,defaultConfig:{period:14},shortName:`LR Slope`,inputs:{period:{min:2}},plots:[{key:`value`,title:`Slope`,color:0}],levels:[0]};read(e){return F(e,`period`,14,2)}pointAt(e,t,n){let r=kr(e,t,n);return r?{value:r.slope}:null}},ni=class extends R{descriptor={id:`stderror`,name:`Standard Error`,placement:`panel`,defaultConfig:{period:14},shortName:`StdErr`,inputs:{period:{min:3}},plots:[{key:`value`,title:`StdErr`,color:0}],scale:{min:0}};read(e){return F(e,`period`,14,3)}pointAt(e,t,n){let r=kr(e,t,n);return r?{value:r.stdErr}:null}},ri=class extends R{descriptor={id:`adr`,name:`Average Day Range`,placement:`panel`,defaultConfig:{period:14},shortName:`ADR`,inputs:{period:{min:1}},plots:[{key:`value`,title:`ADR`,color:0}],scale:{min:0}};read(e){return F(e,`period`,14,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].high-e[i].low;return{value:r/n}}},ii=class extends R{descriptor={id:`netvolume`,name:`Net Volume`,placement:`panel`,defaultConfig:{},shortName:`Net Vol`,plots:[{key:`value`,title:`Net`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],levels:[0]};read(e){return null}pointAt(e,t){if(t===0)return null;let n=e[t].close-e[t-1].close,r=e[t].volume??0;return{value:n>0?r:n<0?-r:0,up:+(n>=0)}}lookback(){return 1}},ai=class extends M{descriptor={id:`seb`,name:`Standard Error Bands`,placement:`overlay`,defaultConfig:{period:21,mult:2,smooth:3},shortName:`SEB`,inputs:{period:{min:3},mult:{min:0,step:.1},smooth:{min:1}},plots:[{key:`upper`,title:`Upper`,color:1},{key:`middle`,title:`Middle`,color:0},{key:`lower`,title:`Lower`,color:1}]};calculate(e,t){let n=F(t,`period`,21,3),r=P(t,`mult`,2),i=F(t,`smooth`,3,1),a=Array(e.length).fill(void 0),o=Array(e.length).fill(void 0),s=Array(e.length).fill(void 0);for(let t=0;t<e.length;t++){let i=kr(e,t,n);i&&(a[t]=i.end,o[t]=i.end+r*i.stdErr,s[t]=i.end-r*i.stdErr)}let c=_r(a,i),l=_r(o,i),u=_r(s,i);return I(e,c.map((e,t)=>e===void 0||l[t]===void 0||u[t]===void 0?null:{middle:e,upper:l[t],lower:u[t]}))}},oi=[3,5,8,10,12,15],si=[30,35,40,45,50,60],ci=class extends M{descriptor={id:`gmma`,name:`Guppy Multiple Moving Average`,placement:`overlay`,defaultConfig:{},shortName:`GMMA`,plots:[...oi.map(e=>({key:`s${e}`,title:`EMA ${e}`,color:0})),...si.map(e=>({key:`l${e}`,title:`EMA ${e}`,color:1}))]};calculate(e,t){let n=gr(e),r=[...oi.map(e=>[`s${e}`,L(n,e)]),...si.map(e=>[`l${e}`,L(n,e)])];return I(e,e.map((e,t)=>{let n={},i=!1;for(let[e,a]of r)a[t]!==void 0&&(n[e]=a[t],i=!0);return i?n:null}))}},li=class extends M{descriptor={id:`maribbon`,name:`Moving Average Ribbon`,placement:`overlay`,defaultConfig:{ma1:20,ma2:50,ma3:100,ma4:200,exponential:0},shortName:`MA Ribbon`,inputs:{ma1:{min:1},ma2:{min:1},ma3:{min:1},ma4:{min:1},exponential:{min:0,max:1}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1},{key:`ma3`,title:`MA 3`,color:2},{key:`ma4`,title:`MA 4`,color:3}]};calculate(e,t){let n=P(t,`exponential`,0)>=1?L:_r,r=gr(e),i=[`ma1`,`ma2`,`ma3`,`ma4`],a=[20,50,100,200],o=i.map((e,i)=>[e,n(r,F(t,e,a[i],1))]);return I(e,e.map((e,t)=>{let n={},r=!1;for(let[e,i]of o)i[t]!==void 0&&(n[e]=i[t],r=!0);return r?n:null}))}};function ui(e){e.register(new It),e.register(new Lt),e.register(new Rt),e.register(new zt),e.register(new Bt),e.register(new Vt),e.register(new Ht),e.register(new Ut),e.register(new Wt),e.register(new Kt),e.register(new qt),e.register(new Jt),e.register(new Yt),e.register(new Xt),e.register(new $t),e.register(new en),e.register(new tn),e.register(new nn),e.register(new an),e.register(new on),e.register(new sn),e.register(new dn),e.register(new mn),e.register(new hn),e.register(new gn),e.register(new _n),e.register(new vn),e.register(new yn),e.register(new bn),e.register(new xn),e.register(new Sn),e.register(new Cn),e.register(new wn),e.register(new Tn),e.register(new En),e.register(new fr),e.register(new pr),e.register(new mr),e.register(new hr),e.register(new fn),e.register(new pn),e.register(new Dn),e.register(new On),e.register(new kn),e.register(new An),e.register(new Mn),e.register(new Nn),e.register(new Fn),e.register(new In),e.register(new zn),e.register(new Bn),e.register(new Hn),e.register(new Un),e.register(new Wn),e.register(new Gn),e.register(new Kn),e.register(new qn),e.register(new Jn),e.register(new Xn),e.register(new Zn),e.register(new Qn),e.register(new $n),e.register(new er),e.register(new tr),e.register(new ir),e.register(new or),e.register(new cr),e.register(new lr),e.register(new ur),e.register(new dr),e.register(new Ar),e.register(new jr),e.register(new Mr),e.register(new Nr),e.register(new Pr),e.register(new Fr),e.register(new Lr),e.register(new zr),e.register(new Br),e.register(new Ur),e.register(new Wr),e.register(new Gr),e.register(new Kr),e.register(new qr),e.register(new Yr),e.register(new Qr),e.register(new $r),e.register(new ei),e.register(new ti),e.register(new ni),e.register(new ri),e.register(new ii),e.register(new ai),e.register(new ci),e.register(new li)}function di(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.requestId==`number`?t.type===`result`||t.type===`pong`||t.type===`error`:!1}var fi=class{worker;fallbackPlugins;timeoutMs;nextRequestId=1;pending=new Map;messageHandler;constructor(e,t={}){this.worker=e,this.fallbackPlugins=t.fallbackPlugins??new Map,this.timeoutMs=t.timeoutMs??3e4,this.messageHandler=e=>this.handleMessage(e),this.worker&&(this.worker.addEventListener(`message`,this.messageHandler),this.worker.addEventListener(`error`,this.messageHandler))}hasWorker(){return this.worker!==null}registerFallbackPlugin(e){this.fallbackPlugins.set(e.descriptor.id,e)}async calculate(e,t,n){if(!this.worker){let r=this.fallbackPlugins.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);return r.calculate(n,t)}let r=this.nextRequestId++,i={type:`calculate`,requestId:r,indicatorId:e,config:t,data:n};return new Promise((t,n)=>{let a={resolve:t,reject:n,timer:null};this.timeoutMs>0&&(a.timer=setTimeout(()=>{this.pending.delete(r),n(Error(`Indicator worker timeout (${this.timeoutMs}ms): ${e}`))},this.timeoutMs)),this.pending.set(r,a),this.worker.postMessage(i)})}ping(){if(!this.worker)return Promise.resolve();let e=this.nextRequestId++;return new Promise((t,n)=>{let r={resolve:()=>t(),reject:n,timer:this.timeoutMs>0?setTimeout(()=>{this.pending.delete(e),n(Error(`Indicator worker ping timeout`))},this.timeoutMs):null};this.pending.set(e,r),this.worker.postMessage({type:`ping`,requestId:e})})}terminate(){this.worker&&=(this.worker.removeEventListener(`message`,this.messageHandler),this.worker.removeEventListener(`error`,this.messageHandler),this.worker.terminate(),null);for(let e of this.pending.values())e.timer&&clearTimeout(e.timer),e.reject(Error(`Indicator worker terminated`));this.pending.clear()}handleMessage(e){let t=e.data;if(t!==void 0){if(!di(t))return;this.dispatchResponse(t);return}let n=e.message??`Indicator worker error`;for(let[e,t]of this.pending)t.timer&&clearTimeout(t.timer),t.reject(Error(n)),this.pending.delete(e)}dispatchResponse(e){let t=this.pending.get(e.requestId);if(t){if(this.pending.delete(e.requestId),t.timer&&clearTimeout(t.timer),e.type===`error`){t.reject(Error(e.message));return}if(e.type===`pong`){t.resolve(void 0);return}t.resolve(e.output)}}},pi=e=>typeof e.params.symbol==`string`?e.params.symbol.trim():``,mi=class extends R{descriptor={id:`compareSymbol`,name:`Compare Symbol`,placement:`overlay`,defaultConfig:{symbol:``},shortName:`Compare`,plots:[{key:`value`,title:`Close`,color:0}]};constructor(e){super(),this.store=e}read(e){return{symbol:pi(e)}}pointAt(e,t,{symbol:n}){if(!n)return null;let r=this.store.closeAt(n,e[t].time);return r===void 0?null:{value:r}}},hi=class extends R{descriptor={id:`spread`,name:`Spread / Ratio`,placement:`panel`,defaultConfig:{symbol:``,mode:`spread`},shortName:`Spread`,plots:[{key:`value`,title:`Spread`,color:0}],inputs:{mode:{options:[`spread`,`ratio`]}}};constructor(e){super(),this.store=e}read(e){return{symbol:pi(e),ratio:e.params.mode===`ratio`}}pointAt(e,t,{symbol:n,ratio:r}){if(!n)return null;let i=this.store.closeAt(n,e[t].time);return i===void 0?null:r?i===0?null:{value:e[t].close/i}:{value:e[t].close-i}}},gi=class{visible=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}render(t,n,r){if(!this.visible)return;let{chartRect:i,priceRange:a}=n;if(t.strokeStyle=r.grid,t.lineWidth=1,a.max-a.min<=0)return;let o=s(n);t.beginPath();let c=(0,e.computeTickStep)(a.min,a.max,8),l=Math.ceil(a.min/c)*c;for(let e=l;e<=a.max;e+=c){let n=Math.round(o(e))+.5;t.moveTo(i.x,n),t.lineTo(i.x+i.width,n)}let u=n.barWidth+n.barSpacing,d=Math.max(1,Math.ceil(80/u)),f=-n.offset+i.x+n.barWidth/2,p=Math.floor(n.offset/u),m=Math.ceil((n.offset+i.width)/u);for(let e=p;e<=m;e++){if(e%d!==0)continue;let n=Math.round(e*u+f)+.5;t.moveTo(n,i.y),t.lineTo(n,i.y+i.height)}t.stroke()}},_i=e=>e<10?`0`+e:``+e,vi=class{tz=null;timeFormatter=null;setTimezoneOffset(e){this.tz=e}setTimeFormatter(e){this.timeFormatter=e}render(t,n,r,i,a){let{chartRect:o}=n,s=a??o.y+o.height;t.strokeStyle=r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(o.x,s+.5),t.lineTo(o.x+o.width,s+.5),t.stroke(),t.globalAlpha=1;let c=n.barWidth+n.barSpacing,l=Math.max(1,Math.ceil(80/c)),u=-n.offset+o.x+n.barWidth/2,d=Math.floor(n.offset/c),f=Math.ceil((n.offset+o.width)/c),p=i.length>0?m(Math.min(f,i.length-1),i):Date.now(),h=(0,e.tzLabel)(this.tz,p>0xe8d4a51000?p:p*1e3),g=`500 ${r.font.sizeSmall-1}px ${r.font.family}`,_=o.x+o.width-4;t.font=g;let v=_-t.measureText(h).width-8;t.font=`500 ${r.font.sizeSmall}px ${r.font.family}`,t.textBaseline=`top`,t.textAlign=`center`,t.fillStyle=r.axisLabel;let y=-1;for(let n=d;n<=f&&i.length>0;n++){if(n%l!==0)continue;let r=n*c+u,a=m(n,i),o=a>0xe8d4a51000?a:a*1e3,d=(0,e.timeParts)(o,this.tz),{year:f,day:p,month:h,hours:g,minutes:_}=d,b;(0,e.isDateOnly)(d)?b=`date`:p===y?b=`time`:(b=`day`,y=p);let x=this.timeFormatter?this.timeFormatter(o,{kind:b,timeZone:this.tz}):b===`date`?`${h}/${p}/${f}`:b===`day`?`${h}/${p}`:`${_i(g)}:${_i(_)}`;r+t.measureText(x).width/2>v||t.fillText(x,r,s+7)}t.font=g,t.textAlign=`right`,t.textBaseline=`top`,t.globalAlpha=.75,t.fillStyle=r.textSecondary,t.fillText(h,_,s+7),t.globalAlpha=1}},yi=new Set,bi=null;function xi(){let e=typeof document<`u`?document.activeElement:null;return e instanceof Element&&e.closest(`[aria-modal="true"], [role="dialog"], [role="menu"]`)!==null}var Si=class{panHandler=null;zoomHandler=null;crosshairHandler=null;axisDragHandler=null;alertDragHandler=null;axisViewportGetter=null;onAxisDoubleClick=null;onDrawingDoubleClick=null;onDrawingContextMenu=null;zoomArea=!1;onChartContextMenu=null;priceAxisAdd=null;axisStrips=null;savedTouchAction=``;measureHandlers=null;measuring=!1;boxSelectHandlers=null;boxSelecting=!1;onAltClick=null;onEscape=null;onConfirm=null;onClick=null;markerAt=null;onMarkerHover=null;markerClickable=()=>!0;markerPos={x:0,y:0};hoveredMarker=null;downPos=null;downMoved=!1;pressForClick=!1;drawingManager=null;tradingManager=null;paneResizeHandler=null;viewportGetter=null;onOverlayDirty=null;boundHandlers=[];lastTouchDist=0;lastTouchMid={x:0,y:0};touchActive=!1;touchStartPos={x:0,y:0};longPressTimer=null;longPressMs=500;longPressMaxMove=8;cachedRect=null;constructor(e){this.element=e}setOverlayDirtyCallback(e){this.onOverlayDirty=e}setPanHandler(e){this.panHandler=e}setZoomHandler(e){this.zoomHandler=e}setCrosshairHandler(e){this.crosshairHandler=e}setAltClickHandler(e){this.onAltClick=e}setEscapeHandler(e){this.onEscape=e}setConfirmHandler(e){this.onConfirm=e}setSignalMarkerHitTest(e,t,n=()=>!0){this.markerAt=e,this.onMarkerHover=t,this.markerClickable=n,e||(this.hoveredMarker=null)}leaveMarker(){this.hoveredMarker!==null&&(this.hoveredMarker=null,this.onMarkerHover?.(null,this.markerPos))}setClickHandler(e){this.onClick=e}setBoxSelectHandlers(e){this.boxSelectHandlers=e}setMeasureHandlers(e){this.measureHandlers=e}setAxisDragHandler(e,t,n){this.axisDragHandler=e,this.axisViewportGetter=t,this.onAxisDoubleClick=n??null}setDrawingManager(e,t){this.drawingManager=e,this.viewportGetter=t}setChartContextMenu(e){this.onChartContextMenu=e}setPriceAxisAddButton(e,t){this.priceAxisAdd={button:e,onClick:t}}setZoomAreaMode(e){this.zoomArea=e}setDrawingContextMenu(e){this.onDrawingContextMenu=e}setDrawingDoubleClick(e){this.onDrawingDoubleClick=e}setAlertDragHandler(e){this.alertDragHandler=e}setTradingManager(e,t){this.tradingManager=e,this.viewportGetter=t}setAxisStrips(e){this.axisStrips=e}setPaneResizeHandler(e){this.paneResizeHandler=e}attach(){let e=()=>this.viewportGetter?.()??null;yi.add(this.element),this.savedTouchAction=this.element.style.getPropertyValue(`touch-action`),this.element.style.setProperty(`touch-action`,`none`);let t=e=>{let t=this.axisStrips?.()??null,n=t?.plot??this.axisViewportGetter?.()?.chartRect;if(!n)return null;let r=this.axisDragHandler!==null;if(e.y>(t?.timeAxisTop??n.y+n.height))return r?`time`:null;let i=e.y>=n.y&&e.y<=n.y+n.height;if(e.x>n.x+n.width)return i?r?`price`:null:`inert`;let a=t?.left;return a&&a.width>0&&e.x<n.x&&e.x>=n.x-a.width?i&&a.scales&&r?`price`:`inert`:null},n=e=>{let t=this.axisStrips?.()??null,n=t?.plot??this.axisViewportGetter?.()?.chartRect;if(!n)return`plot`;if(e.y>(t?.timeAxisTop??n.y+n.height))return`timeAxis`;let r=e.y>=n.y&&e.y<=n.y+n.height,i=t?.left,a=!!i&&i.width>0&&e.x<n.x&&e.x>=n.x-i.width;return e.x>n.x+n.width||a?r?`priceAxis`:`pane`:r?`plot`:`pane`},r=e=>{let t=(this.viewportGetter?.()??this.axisViewportGetter?.())?.chartRect;return t?{x:Math.max(t.x,Math.min(t.x+t.width,e.x)),y:Math.max(t.y,Math.min(t.y+t.height,e.y))}:e},i=()=>this.zoomArea?`zoom-in`:this.crosshairHandler&&this.crosshairHandler.getMode()!==`hidden`?`crosshair`:``,a=e=>{this.element.style.cursor!==e&&(this.element.style.cursor=e)},o=n=>{let r=t(n);if(r===`price`)return`ns-resize`;if(r===`time`)return`ew-resize`;if(r===`inert`)return`default`;let a=this.paneResizeHandler?.cursorAt(n);if(a)return a;if(this.alertDragHandler?.isOverAlert(n))return`ns-resize`;let o=e();return this.tradingManager?.isOverButton(n)?`pointer`:o&&this.tradingManager?.isOverDraggableLine(n,o)?`ns-resize`:this.zoomArea?`zoom-in`:(o?this.drawingManager?.hoverCursorAt(n,o):null)||(o&&this.priceAxisAdd?.button.hit(n,o)?`pointer`:i())},s=!1,c=``,l=e=>{if(!(e.buttons&1)){g(e);return}h(e)},u=()=>{s||(s=!0,this.leaveMarker(),c=document.documentElement.style.userSelect,document.documentElement.style.userSelect=`none`,document.addEventListener(`mousemove`,l))},d=()=>{s&&(s=!1,document.documentElement.style.userSelect=c,document.removeEventListener(`mousemove`,l))},f=e=>e===this.element||e instanceof HTMLCanvasElement,p=n=>{if(bi=this.element,n.button!==0||!f(n.target))return;this.panHandler?.cancelMomentum(),u(),this.invalidateRect();let r=this.getMousePos(n),o=e();this.downPos=r,this.downMoved=!1,this.pressForClick=!1;let s=t(r);if(s===`inert`)return;if(s&&this.axisDragHandler){this.axisDragHandler.begin(s,r);return}if(this.paneResizeHandler?.tryBegin(r))return;let c=!!this.drawingManager?.getActiveTool()||!!this.tradingManager?.isBracketActive()||!!this.tradingManager?.isOrderDraftActive();if(this.boxSelectHandlers&&(this.zoomArea||(n.ctrlKey||n.metaKey)&&!c)){this.boxSelecting=!0,this.boxSelectHandlers.begin(r),a(i()),this.onOverlayDirty?.(!0);return}if(n.shiftKey&&this.measureHandlers){this.measuring=!0,this.measureHandlers.begin(r),this.onOverlayDirty?.(!0);return}if(n.altKey&&this.onAltClick){this.onAltClick(r);return}if(this.priceAxisAdd&&o&&!c&&this.priceAxisAdd.button.hit(r,o)&&!this.alertDragHandler?.isOverAlert(r)&&!this.tradingManager?.isOverButton(r)&&!this.tradingManager?.isOverDraggableLine(r,o)&&!this.drawingManager?.hoverCursorAt(r,o)){n.preventDefault(),this.priceAxisAdd.onClick(r);return}if(this.tradingManager&&o&&this.tradingManager.onPointerDown(r,o)){a(this.tradingManager.isOverButton(r)?`pointer`:`ns-resize`);return}if(this.drawingManager&&o&&this.drawingManager.onPointerDown(r,o)){this.drawingManager.isDragging()&&a(`grabbing`);return}if(this.alertDragHandler?.tryBegin(r)){this.onOverlayDirty?.();return}this.pressForClick=!0,this.panHandler&&(this.panHandler.onPointerDown(r),a(`grabbing`))},m=e=>{if(!s){if(!f(e.target)){this.leaveMarker();return}h(e)}},h=t=>{let n=this.getMousePos(t),i=e();if(this.downPos&&!this.downMoved){let e=n.x-this.downPos.x,t=n.y-this.downPos.y;e*e+t*t>16&&(this.downMoved=!0)}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(n);return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(n);return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.move(r(n)),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measureHandlers.move(n),this.onOverlayDirty?.(!0);return}if(this.boxSelecting&&this.boxSelectHandlers){this.boxSelectHandlers.move(n),this.onOverlayDirty?.(!0);return}if(!s){let e=this.markerAt?.(n)??null;e!==this.hoveredMarker&&(this.hoveredMarker=e,this.onMarkerHover?.(e,n)),e&&(this.markerPos=n),a(e&&this.markerClickable()?`pointer`:o(n))}if(this.tradingManager&&i&&this.tradingManager.onPointerMove(s?r(n):n,i)){this.crosshairHandler?.onPointerMove(n),this.onOverlayDirty?.();return}if(this.drawingManager&&i&&this.drawingManager.onPointerMove(n,i)){this.crosshairHandler?.onPointerMove(n),this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(n),this.crosshairHandler?.onPointerMove(n),this.onOverlayDirty?.(!s)},g=e=>{if(!(e.button!==0&&e.type===`mouseup`)&&s){if(d(),a(o(this.getMousePos(e))),this.boxSelecting&&this.boxSelectHandlers){this.boxSelecting=!1,this.boxSelectHandlers.end(),this.onOverlayDirty?.(!0);return}if(this.axisDragHandler?.isActive()){this.axisDragHandler.end();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.end();return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.end(),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measuring=!1,this.measureHandlers.end(),this.onOverlayDirty?.(!0);return}this.tradingManager?.onPointerUp(this.getMousePos(e))||this.drawingManager?.onPointerUp()||(this.panHandler?.onPointerUp(),this.pressForClick&&!this.downMoved&&this.downPos&&this.onClick&&this.onClick(this.downPos),this.pressForClick=!1,this.downPos=null)}},_=n=>{let r=this.getMousePos(n),i=t(r);if(i){i!==`inert`&&this.onAxisDoubleClick?.(i);return}let a=e();if(!a||this.drawingManager?.justFinished())return;let o=this.drawingManager?.drawingAt(r,a);o&&this.onDrawingDoubleClick?.(o)},v=()=>{if(this.leaveMarker(),s){this.crosshairHandler?.onPointerLeave(),this.onOverlayDirty?.(!0);return}a(``),this.panHandler?.onPointerUp(),this.drawingManager?.onPointerUp(),this.tradingManager?.onPointerUp(),this.alertDragHandler?.end(),this.paneResizeHandler?.end(),this.crosshairHandler?.onPointerLeave(),this.pressForClick=!1,this.downPos=null,this.onOverlayDirty?.()},y=e=>{e.preventDefault();let t=this.getMousePos(e);this.zoomHandler?.onWheel(e.deltaY,t)},b=e=>{if(!xi()){if(e.key===`Escape`&&this.boxSelecting&&this.boxSelectHandlers&&(this.boxSelecting=!1,this.boxSelectHandlers.cancel(),this.onOverlayDirty?.(!0)),e.key===`Escape`&&this.onEscape&&this.onEscape(),e.key===`Enter`&&this.onConfirm&&this.onConfirm()){e.preventDefault();return}e.key!==`Escape`&&!this.ownsShortcuts()||this.drawingManager?.onKeyDown(e.key,e.ctrlKey||e.metaKey,e.shiftKey)&&e.preventDefault()}},x=t=>{let r=e();if(!r)return;let i=this.getMousePos(t),a=r.chartRect,o=i.x>=a.x&&i.x<=a.x+a.width&&i.y>=a.y&&i.y<=a.y+a.height,s=this.onDrawingContextMenu&&o&&!this.drawingManager?.getActiveTool()?this.drawingManager?.drawingAt(i,r):null;if(s){t.preventDefault(),this.onDrawingContextMenu?.(s,i);return}if(this.tradingManager?.onContextMenu(i,r)){t.preventDefault();return}this.onChartContextMenu?.(n(i),i)&&t.preventDefault()},S=n=>{if(bi=this.element,!(!this.touchActive&&!f(n.target)))if(n.preventDefault(),this.invalidateRect(),n.touches.length===1){let r=this.getTouchPos(n.touches[0]);this.touchStartPos=r;let i=t(r);if(i===`inert`){this.touchActive=!0;return}if(i&&this.axisDragHandler){this.axisDragHandler.begin(i,r),this.touchActive=!0;return}if(this.paneResizeHandler?.tryBegin(r)){this.touchActive=!0;return}let a=e();if(this.tradingManager&&a&&this.tradingManager.onPointerDown(r,a)){this.touchActive=!0,this.onOverlayDirty?.();return}this.onAltClick&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null,this.onAltClick?.(r),this.panHandler?.onPointerUp(),this.onOverlayDirty?.(!0)},this.longPressMs)),this.panHandler?.onPointerDown(r),this.crosshairHandler?.onPointerMove(r),this.touchActive=!0}else n.touches.length===2&&(this.clearLongPress(),this.panHandler?.onPointerUp(),this.lastTouchDist=this.getTouchDistance(n.touches[0],n.touches[1]),this.lastTouchMid=this.getTouchMidpoint(n.touches[0],n.touches[1]),this.touchActive=!0)},C=t=>{if(!(!this.touchActive&&!f(t.target))){if(t.preventDefault(),t.touches.length===1&&this.touchActive){let n=this.getTouchPos(t.touches[0]);if(this.longPressTimer){let e=n.x-this.touchStartPos.x,t=n.y-this.touchStartPos.y;Math.hypot(e,t)>this.longPressMaxMove&&this.clearLongPress()}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(n),this.onOverlayDirty?.();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(n),this.onOverlayDirty?.();return}let r=e();if(this.tradingManager&&r&&this.tradingManager.onPointerMove(n,r)){this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(n),this.crosshairHandler?.onPointerMove(n)}else if(t.touches.length===2){let e=this.getTouchDistance(t.touches[0],t.touches[1]),n=this.getTouchMidpoint(t.touches[0],t.touches[1]);this.lastTouchDist>0&&e>0&&this.zoomHandler?.onPinch(e/this.lastTouchDist,n);let r=this.lastTouchMid.x-n.x;Math.abs(r)>1&&(this.panHandler?.onPointerDown(this.lastTouchMid),this.panHandler?.onPointerMove({x:n.x,y:this.lastTouchMid.y})),this.lastTouchDist=e,this.lastTouchMid=n}this.onOverlayDirty?.()}},w=e=>{if(this.clearLongPress(),e.touches.length===0){this.axisDragHandler?.isActive()&&this.axisDragHandler.end(),this.paneResizeHandler?.end();let t=e.changedTouches[0];this.tradingManager?.onPointerUp(t?this.getTouchPos(t):void 0),this.panHandler?.onPointerUp(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.lastTouchDist=0}else if(e.touches.length===1){let t=this.getTouchPos(e.touches[0]);this.panHandler?.onPointerDown(t)}},T=()=>this.invalidateRect(),E=()=>this.invalidateRect(),D=()=>this.invalidateRect();this.element.addEventListener(`mousedown`,p),this.element.addEventListener(`mousemove`,m),document.addEventListener(`mouseup`,g),this.element.addEventListener(`mouseleave`,v),this.element.addEventListener(`dblclick`,_),this.element.addEventListener(`wheel`,y,{passive:!1}),this.element.addEventListener(`contextmenu`,x),this.element.addEventListener(`touchstart`,S,{passive:!1}),this.element.addEventListener(`touchmove`,C,{passive:!1}),this.element.addEventListener(`touchend`,w),document.addEventListener(`keydown`,b),window.addEventListener(`resize`,T),document.addEventListener(`scroll`,E,{capture:!0,passive:!0}),this.element.addEventListener(`mouseenter`,D),this.boundHandlers.push(d,()=>this.element.removeEventListener(`mousedown`,p),()=>this.element.removeEventListener(`mousemove`,m),()=>document.removeEventListener(`mouseup`,g),()=>this.element.removeEventListener(`mouseleave`,v),()=>this.element.removeEventListener(`dblclick`,_),()=>this.element.removeEventListener(`wheel`,y),()=>this.element.removeEventListener(`contextmenu`,x),()=>this.element.removeEventListener(`touchstart`,S),()=>this.element.removeEventListener(`touchmove`,C),()=>this.element.removeEventListener(`touchend`,w),()=>document.removeEventListener(`keydown`,b),()=>window.removeEventListener(`resize`,T),()=>document.removeEventListener(`scroll`,E,{capture:!0}),()=>this.element.removeEventListener(`mouseenter`,D))}detach(){yi.delete(this.element),this.savedTouchAction?this.element.style.setProperty(`touch-action`,this.savedTouchAction):this.element.style.removeProperty(`touch-action`),bi===this.element&&(bi=null);for(let e of this.boundHandlers)e();this.boundHandlers=[],this.cachedRect=null,this.clearLongPress()}clearLongPress(){this.longPressTimer&&=(clearTimeout(this.longPressTimer),null)}invalidateRect(){this.cachedRect=null}getRect(){return this.cachedRect||=this.element.getBoundingClientRect(),this.cachedRect}ownsShortcuts(){let e=document.activeElement;if(e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||e.isContentEditable))return!1;for(let t of yi)if(e&&t.contains(e))return t===this.element;return bi===null||bi===this.element}getMousePos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchPos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchDistance(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}getTouchMidpoint(e,t){let n=this.getRect();return{x:(e.clientX+t.clientX)/2-n.left,y:(e.clientY+t.clientY)/2-n.top}}},Ci=16,wi=3,Ti=class{enabled=!1;setEnabled(e){this.enabled=e}isEnabled(){return this.enabled}hit(e,t){if(!this.enabled)return!1;let{x:n,y:r,width:i,height:a}=t.chartRect,o=n+i-Ci-wi;return e.x>=o&&e.x<=n+i&&e.y>=r&&e.y<=r+a}render(e,t,n,r){if(!this.enabled||!r)return;let{x:i,y:a,width:o,height:s}=t.chartRect;if(r.y<a||r.y>a+s||r.x<i||r.x>i+o)return;let c=i+o-wi-Ci/2,l=Ci/2;e.fillStyle=n.background,e.strokeStyle=n.axisLabelBackground,e.lineWidth=1,e.beginPath(),e.arc(c,r.y,l-.5,0,Math.PI*2),e.fill(),e.stroke(),e.strokeStyle=n.text,e.lineWidth=1.5,e.beginPath(),e.moveTo(c-l*.45,r.y),e.lineTo(c+l*.45,r.y),e.moveTo(c,r.y-l*.45),e.lineTo(c,r.y+l*.45),e.stroke()}},Ei=100,Di=50,Oi=.1,ki=60,Ai=16,ji=class{dragging=!1;lastX=0;lastY=0;samples=[];momentumId=0;callback;onStart;friction=.92;constructor(e,t){this.callback=e,this.onStart=t}isDragging(){return this.dragging}onPointerDown(e){this.dragging=!0,this.lastX=e.x,this.lastY=e.y,this.samples=[{t:Date.now(),x:e.x,y:e.y}],this.stopMomentum(),this.onStart?.()}onPointerMove(e){if(!this.dragging)return;let t=this.lastX-e.x,n=this.lastY-e.y;this.lastX=e.x,this.lastY=e.y;let r=Date.now();for(this.samples.push({t:r,x:e.x,y:e.y});this.samples.length>2&&r-this.samples[1].t>Ei;)this.samples.shift();(t||n)&&this.callback(t,n)}onPointerUp(){if(!this.dragging)return;this.dragging=!1;let e=this.releaseVelocity(Date.now());this.samples=[],e&&Math.hypot(e.x,e.y)>Oi&&this.startMomentum(e.x,e.y)}cancelMomentum(){this.stopMomentum()}releaseVelocity(e){let t=this.samples[this.samples.length-1];if(!t||e-t.t>Di)return null;let n=this.samples.find(e=>t.t-e.t<=Ei)??this.samples[0],r=t.t-n.t;return r<=0?null:{x:(n.x-t.x)/r,y:(n.y-t.y)/r}}startMomentum(e,t){this.stopMomentum();let n=e*Ai,r=t*Ai,i=Math.hypot(n,r);i>ki&&(n*=ki/i,r*=ki/i);let a=()=>{if(n*=this.friction,r*=this.friction,Math.hypot(n,r)<.5){this.momentumId=0;return}this.callback(n,r),this.momentumId=requestAnimationFrame(a)};this.momentumId=requestAnimationFrame(a)}stopMomentum(){this.momentumId&&=(cancelAnimationFrame(this.momentumId),0)}},Mi=class{callback;sensitivity;pendingDelta=0;pendingScale=1;pendingCenterX=0;rafId=0;constructor(e,t=.001){this.callback=e,this.sensitivity=t}onWheel(e,t){this.pendingDelta+=-e*this.sensitivity,this.pendingCenterX=t.x,this.schedule()}onPinch(e,t){!(e>0)||!Number.isFinite(e)||(this.pendingScale*=e,this.pendingCenterX=t.x,this.schedule())}schedule(){this.rafId||=requestAnimationFrame(()=>{this.rafId=0;let e=(1+this.pendingDelta)*this.pendingScale-1,t=this.pendingCenterX;this.pendingDelta=0,this.pendingScale=1,this.callback(e,t)})}dispose(){this.rafId&&=(cancelAnimationFrame(this.rafId),0)}},Ni=class{dragging=!1;axis=null;startPos={x:0,y:0};lastPos={x:0,y:0};moved=!1;threshold=3;sensitivity=.005;constructor(e,t){this.onPriceScale=e,this.onTimeScale=t}begin(e,t){this.dragging=!0,this.axis=e,this.startPos=t,this.lastPos=t,this.moved=!1}move(e){if(!this.dragging||!this.axis)return!1;let t=e.x-this.startPos.x,n=e.y-this.startPos.y;if(!this.moved&&Math.hypot(t,n)<this.threshold)return!1;if(this.moved=!0,this.axis===`price`){let t=e.y-this.lastPos.y,n=Math.exp(t*this.sensitivity);this.onPriceScale(n)}else{let t=e.x-this.lastPos.x,n=Math.exp(t*this.sensitivity);this.onTimeScale(n)}return this.lastPos=e,!0}end(){let e=this.dragging&&this.moved;return this.dragging=!1,this.axis=null,this.moved=!1,e}isActive(){return this.dragging}},Pi=class{draggingId=null;constructor(e,t){this.alerts=e,this.viewportGetter=t}isOverAlert(e){let t=this.viewportGetter();return t?this.alerts.getAlertAtPoint(e,t)!==null:!1}tryBegin(e){let t=this.viewportGetter();if(!t)return!1;let n=this.alerts.getAlertAtPoint(e,t);return n?(this.draggingId=n.id,!0):!1}move(e){if(this.draggingId===null)return;let t=this.viewportGetter();t&&this.alerts.updateAlertPrice(this.draggingId,u(e.y,t))}end(){this.draggingId=null}isActive(){return this.draggingId!==null}},Fi=class{state=null;layoutGetter=null;onResize=null;constructor(e=4){this.tolerance=e}configure(e,t){this.layoutGetter=e,this.onResize=t}hitTest(e,t){for(let n of t.dividers)if(Ii(e,n.rect,this.tolerance)){let e=t.panels.find(e=>e.config.id===n.panelId);if(e)return{panelId:n.panelId,orientation:n.orientation,position:e.config.position,size:n.orientation===`horizontal`?e.rect.height:e.rect.width}}return null}cursorAt(e){let t=this.layoutGetter?.();if(!t)return null;let n=this.hitTest(e,t);return n?n.orientation===`horizontal`?`ns-resize`:`ew-resize`:null}tryBegin(e){let t=this.layoutGetter?.();if(!t)return!1;let n=this.hitTest(e,t);return n?(this.state={panelId:n.panelId,position:n.position,startSize:n.size,startPos:e},!0):!1}move(e){let t=this.computeSize(e);t&&this.onResize?.(t.panelId,t.size)}computeSize(e){let t=this.state;if(!t)return null;let n=0;switch(t.position){case`bottom`:n=t.startPos.y-e.y;break;case`top`:n=e.y-t.startPos.y;break;case`left`:n=e.x-t.startPos.x;break;case`right`:n=t.startPos.x-e.x;break}return{panelId:t.panelId,size:t.startSize+n}}end(){this.state=null}isActive(){return this.state!==null}};function Ii(e,t,n){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var Li=class{position=null;callback=null;data=[];tz=null;timeFormatter=null;setTimeFormatter(e){this.timeFormatter=e}setTimezoneOffset(e){this.tz=e}magnetMode=!0;mode=`magnet`;pricePrecision=null;locale=`en-US`;syncedSlot=null;pendingBarIndex=null;pendingPoint=null;callbackScheduled=!1;lastCallbackBarIndex=-1;reportTop=null;reportBottom=null;setCallback(e){this.callback=e}setData(e){this.data=e}setMagnetMode(e){this.magnetMode=e,this.mode=e?`magnet`:`normal`}setMode(e){this.mode=e,this.magnetMode=e===`magnet`}getMode(){return this.mode}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}getPosition(){return this.position}setSyncedSlot(e){this.syncedSlot=e!==null&&Number.isFinite(e)?e:null}getSyncedSlot(){return this.syncedSlot}setReportBounds(e){this.reportTop=e?.top??null,this.reportBottom=e?.bottom??null}onPointerMove(e){this.position=e}onPointerLeave(){this.position=null,this.pendingBarIndex=null,this.pendingPoint=null,this.lastCallbackBarIndex=-1,this.flushCallback(null,null)}render(e,t,n){if(this.mode===`hidden`)return;if(!this.position){this.syncedSlot!==null&&this.renderSynced(e,t,n,this.syncedSlot);return}let{chartRect:r}=t,{x:i,y:o}=this.position;if(i<r.x||i>r.x+r.width)return;let s=r.y+r.height;if(o<Math.min(this.reportTop??r.y,r.y)||o>Math.max(this.reportBottom??s,s))return;let c=o>=r.y&&o<=s,u=l(i,t),d=Math.max(0,Math.min(this.data.length-1,u)),f=u>=0&&u<this.data.length;this.magnetMode&&(i=a(u,t)),d!==this.lastCallbackBarIndex&&(this.pendingBarIndex=d,this.pendingPoint={x:i,y:o},this.lastCallbackBarIndex=d,this.scheduleCallback()),c&&(this.magnetMode&&f&&Ri(e,i,t,n),zi(e,i,r,n),e.setLineDash([4,4]),e.beginPath(),e.moveTo(r.x,Math.round(o)+.5),e.lineTo(r.x+r.width,Math.round(o)+.5),e.stroke(),e.setLineDash([]))}renderAxisLabels(t,n,r,i,o){if(this.mode===`hidden`)return;if(!this.position){this.syncedSlot!==null&&this.renderSyncedTimeLabel(t,n,r,i,this.syncedSlot,o);return}let{chartRect:s}=n,{x:c,y:d}=this.position;if(c<s.x||c>s.x+s.width||d<s.y||d>s.y+s.height)return;let f=l(c,n);this.magnetMode&&(c=a(f,n));let p=`600 ${r.font.sizeSmall}px ${r.font.family}`;Bi(t,{text:y(u(d,n),n,this.pricePrecision??(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max),this.locale),anchorX:s.x+s.width,anchorY:d,orientation:`right`,bg:r.text,fg:r.background,theme:r,font:p}),this.drawTimePill(t,n,r,i,f,c,o)}renderSynced(e,t,n,r){let i=a(r,t),{chartRect:o}=t;i<o.x||i>o.x+o.width||(this.magnetMode&&r>=0&&r<this.data.length&&Ri(e,i,t,n),zi(e,i,o,n))}renderSyncedTimeLabel(e,t,n,r,i,o){let s=a(i,t),{chartRect:c}=t;s<c.x||s>c.x+c.width||this.drawTimePill(e,t,n,r,i,s,o)}drawTimePill(e,t,n,r,i,a,o){if(r.length===0)return;let s=m(i,r);Bi(e,{text:this.timeFormatter?this.timeFormatter(s>0xe8d4a51000?s:s*1e3,{kind:`crosshair`,timeZone:this.tz}):Vi(s,this.tz),anchorX:a,anchorY:o??t.chartRect.y+t.chartRect.height,orientation:`bottom`,bg:n.text,fg:n.background,theme:n,font:`600 ${n.font.sizeSmall}px ${n.font.family}`})}scheduleCallback(){this.callbackScheduled||(this.callbackScheduled=!0,queueMicrotask(()=>{this.callbackScheduled=!1,this.flushCallback(this.pendingBarIndex,this.pendingPoint)}))}flushCallback(e,t){this.callback?.(e,t)}};function Ri(e,t,n,r){let i=n.barWidth+n.barSpacing;e.fillStyle=r.crosshair,e.globalAlpha=.08,e.fillRect(t-i/2,n.chartRect.y,i,n.chartRect.height),e.globalAlpha=1}function zi(e,t,n,r){e.setLineDash([4,4]),e.strokeStyle=r.crosshair,e.lineWidth=1,e.beginPath(),e.moveTo(Math.round(t)+.5,n.y),e.lineTo(Math.round(t)+.5,n.y+n.height),e.stroke(),e.setLineDash([])}function Bi(e,t){e.save(),e.font=t.font;let n=Math.ceil(e.measureText(t.text).width)+16;if(e.fillStyle=t.bg,e.textBaseline=`middle`,t.orientation===`right`){let r=t.anchorX+5;C(e,r,t.anchorY-20/2,n,20,t.theme),e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(r+2,t.anchorY-5),e.lineTo(r+2,t.anchorY+5),e.closePath(),e.fill(),e.fillStyle=t.fg,e.textAlign=`left`,e.fillText(t.text,r+8,t.anchorY)}else{let r=t.anchorX-n/2,i=t.anchorY+5;C(e,r,i,n,20,t.theme),e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(t.anchorX-5,i+1),e.lineTo(t.anchorX+5,i+1),e.closePath(),e.fill(),e.fillStyle=t.fg,e.textAlign=`center`,e.fillText(t.text,t.anchorX,i+20/2)}e.restore()}function Vi(t,n){let r=(0,e.timeParts)(t>0xe8d4a51000?t:t*1e3,n),{year:i,month:a,day:o,hours:s,minutes:c}=r;return(0,e.isDateOnly)(r)?`${a}/${o}/${i}`:`${a}/${o} ${s<10?`0`+s:s}:${c<10?`0`+c:c}`}var Hi=class{callbacks;enabled=!0;constructor(e){this.callbacks=e}setEnabled(e){this.enabled=e}handleKey(e){if(!this.enabled)return!1;let t=e.shiftKey?10:1;switch(e.key){case`ArrowLeft`:return this.callbacks.scrollBars(-t),!0;case`ArrowRight`:return this.callbacks.scrollBars(t),!0;case`ArrowUp`:case`+`:case`=`:return this.callbacks.zoom(.1),!0;case`ArrowDown`:case`-`:return this.callbacks.zoom(-.1),!0;case`Home`:return this.callbacks.goToStart(),!0;case`End`:return this.callbacks.goToEnd(),!0;case` `:return this.callbacks.fitContent(),!0;default:return!1}}},Ui=16,Wi=80,Gi=864e5,Ki={month:`short`,day:`numeric`},qi={month:`short`,day:`numeric`,year:`numeric`};function Ji(t,n,r,i){return(0,e.zonedDateFormatter)(r,i?qi:Ki,n)(t)}var Yi=e=>e<10?`0${e}`:`${e}`;function Xi(t,n,r,i=`en-US`){let a=(0,e.normalizeBarTime)(t),o=(0,e.timeParts)(a,n);if(r!==void 0&&r>0?r>=Gi:(0,e.isDateOnly)(o))return Ji(a,n,i,!0);let s=Ji(a,n,i,!1),c=`${Yi(o.hours)}:${Yi(o.minutes)}`;return r!==void 0&&r>0&&r<6e4?`${s} · ${c}:${Yi(new Date(a).getUTCSeconds())}`:`${s} · ${c}`}function Zi(t,n){return Number.isFinite(t)?t>=1e9?`${(0,e.formatPrice)(t/1e9,2,n)}B`:t>=1e6?`${(0,e.formatPrice)(t/1e6,2,n)}M`:t>=1e3?`${(0,e.formatPrice)(t/1e3,1,n)}K`:(0,e.formatPrice)(t,t%1==0?0:2,n):`—`}var Qi=class{el=null;visible=!1;appliedTheme=null;locale=`en-US`;pricePrecision=null;tz=null;priceFormatter=null;timeFormatter=null;dirEl;timeEl;changeEl;valueEls;labelEls=[];dividerEl;width=176;height=112;create(e){if(this.el)return;let t=document.createElement(`div`);t.setAttribute(`aria-hidden`,`true`),Object.assign(t.style,{position:`absolute`,left:`0`,top:`0`,display:`none`,minWidth:`168px`,padding:`8px 10px 9px`,borderRadius:`var(--tcw-tooltip-radius, 8px)`,fontSize:`11.5px`,lineHeight:`1.45`,fontVariantNumeric:`tabular-nums`,pointerEvents:`none`,zIndex:`100`,whiteSpace:`nowrap`,willChange:`transform`,contain:`layout paint`,backdropFilter:`blur(10px)`});let n=z({display:`flex`,alignItems:`center`,gap:`7px`,marginBottom:`6px`});this.dirEl=z({width:`3px`,height:`12px`,borderRadius:`2px`,flex:`none`}),this.timeEl=z({flex:`1`,fontSize:`11px`,letterSpacing:`0.01em`}),this.changeEl=z({padding:`1px 6px`,borderRadius:`999px`,fontSize:`10.5px`,fontWeight:`600`}),n.append(this.dirEl,this.timeEl,this.changeEl);let r=z({display:`grid`,gridTemplateColumns:`auto 1fr auto 1fr`,columnGap:`8px`,rowGap:`1px`,alignItems:`baseline`}),i=e=>{let t=z({fontSize:`10px`,letterSpacing:`0.04em`});t.textContent=e,this.labelEls.push(t);let n=z({textAlign:`right`,fontWeight:`500`});return r.append(t,n),n},a=i(`O`),o=i(`H`),s=i(`L`),c=i(`C`);this.dividerEl=z({height:`1px`,margin:`6px 0 5px`});let l=z({display:`flex`,justifyContent:`space-between`,gap:`12px`}),u=z({fontSize:`10px`,letterSpacing:`0.04em`});u.textContent=`VOL`,this.labelEls.push(u);let d=z({fontWeight:`500`});l.append(u,d),this.valueEls={open:a,high:o,low:s,close:c,volume:d},t.append(n,r,this.dividerEl,l),e.appendChild(t),this.el=t}setLocale(e){this.locale=e}setPricePrecision(e){this.pricePrecision=e}setTimezoneOffset(e){this.tz=e}setPriceFormatter(e){this.priceFormatter=e}setTimeFormatter(e){this.timeFormatter=e}show(t,n,r,i,a={}){let o=this.el;if(!o)return;this.appliedTheme!==r&&this.applyTheme(r);let s=this.pricePrecision??(a.priceRange?(0,e.autoPricePrecision)(a.priceRange.min,a.priceRange.max):(0,e.autoPricePrecision)(n.low,n.high)),c=t=>this.priceFormatter?.(t)??(0,e.formatPrice)(t,s,this.locale),l=a.prevClose??n.open,u=n.close-l,d=l===0?0:u/l*100,f=u>=0,p=f?r.candleUp:r.candleDown,m=f?`+`:`−`;this.timeEl.textContent=this.timeFormatter?this.timeFormatter((0,e.normalizeBarTime)(n.time),{kind:`crosshair`,timeZone:this.tz}):Xi(n.time,this.tz,a.barStepMs,this.locale),this.changeEl.textContent=`${m}${(0,e.formatPrice)(Math.abs(d),2,this.locale)}%`,this.changeEl.style.color=p,this.changeEl.style.background=ta(p,.14),this.dirEl.style.background=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.open.textContent=c(n.open),this.valueEls.high.textContent=c(n.high),this.valueEls.low.textContent=c(n.low),this.valueEls.close.textContent=c(n.close),this.valueEls.close.style.color=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.volume.textContent=Zi(n.volume,this.locale),this.visible||=(o.style.display=`block`,!0),this.width=o.offsetWidth||this.width,this.height=o.offsetHeight||this.height;let h=a.plot??{x:0,y:0,width:i.width-Wi,height:i.height},g=h.x+h.width,_=h.y+h.height,v=t.x+Ui,y=t.y-this.height/2;v+this.width>g-4&&(v=t.x-this.width-Ui),v<h.x+4&&(v=h.x+4),y+this.height>_-4&&(y=_-this.height-4),y<h.y+4&&(y=h.y+4),o.style.transform=`translate(${Math.round(v)}px, ${Math.round(y)}px)`}hide(){this.el&&this.visible&&(this.el.style.display=`none`,this.visible=!1)}isVisible(){return this.visible}destroy(){this.el?.remove(),this.el=null,this.visible=!1,this.appliedTheme=null,this.labelEls=[]}applyTheme(e){let t=this.el,n=$i(e.background);t.style.background=ta(e.background,n?.9:.94),t.style.border=`1px solid ${e.axisLine}`,t.style.boxShadow=n?`0 12px 32px -8px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35)`:`0 12px 32px -10px rgba(15, 19, 26, 0.22), 0 2px 6px rgba(15, 19, 26, 0.08)`,t.style.color=e.text,t.style.fontFamily=e.font.family,this.timeEl.style.color=e.textSecondary;for(let t of this.labelEls)t.style.color=e.textSecondary;this.dividerEl.style.background=e.axisLine,this.appliedTheme=e}};function z(e){let t=document.createElement(`div`);return Object.assign(t.style,e),t}function $i(e){let t=ea(e);return t?(.299*t[0]+.587*t[1]+.114*t[2])/255<.5:!0}function ea(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6);return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function ta(e,t){let n=ea(e);return n?`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var na=class{el=null;deltaEl=null;timeEl=null;ohlcEl=null;pinnedBar=null;pinnedIndex=-1;tz=null;priceFormatter=null;setTimezone(e){this.tz=e}setPriceFormatter(e){this.priceFormatter=e}fmt(e){return ra(this.priceFormatter?this.priceFormatter(e):e.toFixed(2))}create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`var(--tcw-tooltip-radius, 4px)`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`auto`,cursor:`pointer`,zIndex:`99`,whiteSpace:`nowrap`,willChange:`transform`}),this.timeEl=document.createElement(`div`),this.ohlcEl=document.createElement(`div`),this.deltaEl=document.createElement(`div`),this.deltaEl.style.marginTop=`4px`,this.deltaEl.style.paddingTop=`4px`,this.deltaEl.style.borderTop=`1px solid currentColor`,this.deltaEl.style.opacity=`0.85`,this.deltaEl.style.fontVariantNumeric=`tabular-nums`,this.el.appendChild(this.timeEl),this.el.appendChild(this.ohlcEl),this.el.appendChild(this.deltaEl);let t=document.createElement(`div`);t.textContent=`📌 pinned`,t.style.fontSize=`9px`,t.style.opacity=`0.6`,t.style.marginBottom=`2px`,t.style.letterSpacing=`0.04em`,t.style.textTransform=`uppercase`,this.el.insertBefore(t,this.timeEl),e.appendChild(this.el)}pin(t,n,r){if(!this.el||!this.timeEl||!this.ohlcEl)return;this.pinnedBar=t,this.pinnedIndex=n;let i=t.close>=t.open?r.candleUp:r.candleDown,a=(0,e.timeParts)(t.time>0xe8d4a51000?t.time:t.time*1e3,this.tz);this.timeEl.textContent=`${a.month}/${a.day} ${ia(a.hours)}:${ia(a.minutes)}`,this.timeEl.style.color=r.textSecondary,this.ohlcEl.innerHTML=`
|
|
2
|
+
<span style="opacity:.6">O </span><span style="color:${i}">${this.fmt(t.open)}</span>
|
|
3
|
+
<span style="opacity:.6"> H </span><span style="color:${i}">${this.fmt(t.high)}</span>
|
|
4
|
+
<span style="opacity:.6"> L </span><span style="color:${i}">${this.fmt(t.low)}</span>
|
|
5
|
+
<span style="opacity:.6"> C </span><span style="color:${i}">${this.fmt(t.close)}</span>
|
|
6
|
+
`;let o=aa(r.background);this.el.style.background=oa(r.background,o?.96:.97),this.el.style.border=`1px solid ${i}`,this.el.style.boxShadow=o?`0 4px 12px rgba(0,0,0,0.55)`:`0 4px 12px rgba(0,0,0,0.18)`,this.el.style.color=r.text,this.el.style.backdropFilter=`blur(8px)`,this.el.style.display=`block`}unpin(){this.pinnedBar=null,this.pinnedIndex=-1,this.el&&(this.el.style.display=`none`)}isPinned(){return this.pinnedBar!==null}getPinnedIndex(){return this.pinnedIndex}reposition(e,t,n,r){if(!this.el||!this.pinnedBar)return;let i=a(this.pinnedIndex,e),s=o(this.pinnedBar.close,e),c=e.chartRect,l=i>=c.x-4&&i<=c.x+c.width+4;this.el.style.opacity=l?`1`:`0.35`;let u=Math.max(c.x,Math.min(c.x+c.width-180,i+8)),d=Math.max(c.y,Math.min(c.y+c.height-90,s-64));if(this.el.style.transform=`translate(${Math.round(u)}px, ${Math.round(d)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.deltaEl)if(t&&n!==null&&n!==this.pinnedIndex){let e=t.close-this.pinnedBar.close,i=this.pinnedBar.close===0?0:e/this.pinnedBar.close*100,a=e>0?`+`:e<0?`−`:``,o=n-this.pinnedIndex,s=e>=0?r.candleUp:r.candleDown;this.deltaEl.style.color=s,this.deltaEl.innerHTML=`Δ ${a}${this.fmt(Math.abs(e))} <span style="opacity:.7">(${a}${Math.abs(i).toFixed(2)}%)</span> · ${o>0?`+`:``}${o} bars`,this.deltaEl.style.display=`block`}else this.deltaEl.style.display=`none`}destroy(){this.el?.remove(),this.el=null,this.deltaEl=null,this.timeEl=null,this.ohlcEl=null,this.pinnedBar=null,this.pinnedIndex=-1}};function ra(e){return e.replace(/[&<>"']/g,e=>`&#${e.charCodeAt(0)};`)}function ia(e){return e<10?`0`+e:``+e}function aa(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}return!0}function oa(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var sa=class{listeners=new Map;tauriBridge=null;on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}hasListeners(e){return(this.listeners.get(e)?.size??0)>0}emit(e,t){let n={type:e,timestamp:Date.now(),payload:t},r=this.listeners.get(e);if(r)for(let e of r)e(n);if(this.tauriBridge?.enabled&&window.__TAURI__){let t=this.tauriBridge.eventPrefix??`tc-chart`;window.__TAURI__.event.emit(`${t}:${e}`,n).catch(()=>{})}}enableTauriBridge(e){this.tauriBridge=e}disableTauriBridge(){this.tauriBridge=null}destroy(){this.listeners.clear(),this.tauriBridge=null}},ca={at:e=>e,value:e=>e,price:e=>e};function la(e){if(!e)return ca;let{min:t,max:n}=e.priceRange,r=e.logScale===!0&&t>0&&n>0;return{at:t=>g(t,e),value:r?e=>Math.log(Math.max(e,2**-52)):e=>e,price:r?Math.exp:e=>e}}function B(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function V(e,t,n,r=!1){for(let r=0;r<t.length-1;r++)if(B(e,t[r],t[r+1])<=n)return!0;return r&&t.length>2&&B(e,t[t.length-1],t[0])<=n}function ua(e,t){switch(e.kind){case`boolean`:return typeof t==`boolean`;case`number`:return typeof t==`number`&&Number.isFinite(t);case`levels`:return Array.isArray(t);default:return typeof t==`string`}}var H=class{hitTestAnchor(e,t,n,r){for(let i=0;i<t.anchors.length;i++){let a=this.anchorToPixel(t.anchors[i],n);if(Math.hypot(e.x-a.x,e.y-a.y)<=r)return i}return-1}option(e,t){let n=this.descriptor.options?.[t],r=e.options?.[t];return n?r!==void 0&&ua(n,r)?r:n.default:r}visibleLevels(e,t=`levels`){return this.option(e,t).filter(e=>e.visible&&Number.isFinite(e.value))}extendLine(e,t,n,r,i){let a=t.x-e.x,o=t.y-e.y,s=Math.hypot(a,o);if(s===0||!r&&!i)return[e,t];let c=Math.hypot(n.chartRect.width,n.chartRect.height)*2,l=a/s*c,u=o/s*c;return[r?{x:e.x-l,y:e.y-u}:e,i?{x:t.x+l,y:t.y+u}:t]}linePriceAt(e,t,n,r,i,a=ca){let o=this.lineValueAt(e,t,n,r,i,a);return o===null?null:a.price(o)}lineValueAt(e,t,n,r,i,a){let o=a.at(e.time),s=a.at(t.time);if(o===s)return null;let c=(a.at(n)-o)/(s-o);if(!Number.isFinite(c)||c<0&&!r||c>1&&!i)return null;let l=a.value(e.price);return l+(a.value(t.price)-l)*c}anchorToPixel(e,t){return{x:_(e.time,t),y:o(e.price,t)}}pixelToAnchor(e,t){return{time:v(e.x,t),price:u(e.y,t)}}applyLineStyle(e,t){switch(e.strokeStyle=t.color,e.lineWidth=t.lineWidth,t.lineStyle){case`dashed`:e.setLineDash([6,4]);break;case`dotted`:e.setLineDash([2,2]);break;default:e.setLineDash([]);break}}resetLineStyle(e){e.setLineDash([])}renderAnchorHandles(e,t,n){e.fillStyle=`#FFFFFF`,e.strokeStyle=t.style.color,e.lineWidth=1;for(let r of t.anchors){let t=this.anchorToPixel(r,n);e.fillRect(t.x-4,t.y-4,8,8),e.strokeRect(t.x-4,t.y-4,8,8)}}distanceToLine(e,t,n){return B(e,t,n)}distanceToInfiniteLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.hypot(r,i);return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(r*(t.y-e.y)-i*(t.x-e.x))/a}};function da(e){let t={};for(let[n,r]of Object.entries(e))t[n]=Array.isArray(r)?r.map(e=>({...e})):r;return t}function U(e){return{...e,anchors:e.anchors.map(e=>({...e})),style:{...e.style},options:e.options?da(e.options):void 0,group:e.group?{...e.group}:void 0,meta:e.meta?{...e.meta}:void 0}}function fa(e,t){return JSON.stringify(e??{})===JSON.stringify(t??{})}function pa(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].time!==t[n].time||e[n].price!==t[n].price)return!1;return!0}var ma=1,ha=1,ga=/^tc_drawing_(\d+)$/,_a=/^tc_group_(\d+)$/;function va(){return`tc_drawing_${ma++}`}function ya(){let e=ha++;return{id:`tc_group_${e}`,number:e}}function ba(e){for(let t of e){let e=ga.exec(t.id);e&&(ma=Math.max(ma,Number(e[1])+1));let n=t.group?_a.exec(t.group.id):null;n&&(ha=Math.max(ha,Number(n[1])+1))}}function xa(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Set(t);return[...t.map(e=>n.get(e)).filter(e=>e!==void 0),...e.filter(e=>!r.has(e.id))]}function Sa(e,t,n){let r=t-1;switch(n){case`front`:return r;case`back`:return 0;case`forward`:return Math.min(r,e+1);case`backward`:return Math.max(0,e-1)}}function Ca(e,t){return e.map(e=>e.id===t.id?structuredClone(t):e)}function wa(e,t){switch(t.type){case`drawingBatch`:return[...t.actions??[]].reverse().reduce(wa,[...e]);case`drawingCreate`:return t.after?e.filter(e=>e.id!==t.after.id):[...e];case`drawingRemove`:{if(!t.before)return[...e];let n=[...e];return n.splice(Math.min(t.index??n.length,n.length),0,structuredClone(t.before)),n}case`drawingOrder`:return t.order?xa(e,t.order.before):[...e];case`drawingModify`:return t.before?Ca(e,t.before):[...e];default:return[...e]}}function Ta(e,t){switch(t.type){case`drawingBatch`:return(t.actions??[]).reduce(Ta,[...e]);case`drawingCreate`:return t.after?[...e,structuredClone(t.after)]:[...e];case`drawingRemove`:return t.before?e.filter(e=>e.id!==t.before.id):[...e];case`drawingOrder`:return t.order?xa(e,t.order.after):[...e];case`drawingModify`:return t.after?Ca(e,t.after):[...e];default:return[...e]}}var Ea={"]":[`forward`,`front`],"}":[`front`,`front`],"[":[`backward`,`back`],"{":[`back`,`back`]};function Da(e,t,n){if(e===`Escape`)return`escape`;if(e===`Enter`&&!t)return`finish`;if(e===`Delete`||e===`Backspace`)return`delete`;if(!t)return null;let r=n??(e.length===1&&e!==e.toLowerCase()),i=Ea[e];if(i)return i[+!!r];switch(e.toLowerCase()){case`c`:return`copy`;case`v`:return`paste`;case`d`:return`duplicate`;case`g`:return r?`ungroup`:`group`;case`z`:return r?`redo`:`undo`;case`y`:return`redo`;default:return null}}var Oa=2,ka=6;function Aa(e){return e.descriptor.creation??`clicks`}var ja=class{drawing=null;plugin=null;preview=null;lastPos=null;dragging=!1;step=Oa;get current(){return this.drawing}reset(){this.drawing=null,this.plugin=null,this.preview=null,this.lastPos=null,this.dragging=!1,this.step=Oa}press(e,t,n,r,i){if(this.dragging)return`continue`;let a=Aa(e);if(!this.drawing)return this.plugin=e,this.drawing={...t(),anchors:[n]},this.preview=null,this.lastPos=r,a===`freehand`?(this.dragging=!0,`continue`):a===`clicks`&&e.descriptor.requiredAnchors<=1?`done`:`continue`;let o=this.drawing.anchors[this.drawing.anchors.length-1],s=i?i(o):this.lastPos;if(a===`path`&&s&&Math.hypot(r.x-s.x,r.y-s.y)<=ka)return this.finish();this.commit(n,r);let c=a===`path`?e.descriptor.maxAnchors??100:e.descriptor.requiredAnchors;return this.drawing.anchors.length>=c?`done`:`continue`}move(e,t){if(!this.drawing||!this.plugin)return!1;if(this.dragging){let n=this.lastPos;return n&&Math.hypot(t.x-n.x,t.y-n.y)<this.step?!0:(this.drawing.anchors.length>=2e3&&(this.drawing.anchors=this.drawing.anchors.filter((e,t)=>t%2==0),this.step*=2),this.commit(e,t),!0)}return Aa(this.plugin)===`path`||this.drawing.anchors.length<this.plugin.descriptor.requiredAnchors?(this.preview=e,!0):!1}release(){return this.dragging?(this.dragging=!1,this.hasEnough()?`done`:`cancel`):null}undoPoint(){return!this.drawing||this.dragging||this.drawing.anchors.length<=1?(this.reset(),!1):(this.drawing.anchors.pop(),this.preview=null,this.lastPos=null,!0)}finish(){return!this.plugin||Aa(this.plugin)!==`path`||!this.hasEnough()?`continue`:(this.preview=null,`done`)}previewState(){return this.drawing?this.preview?{...this.drawing,anchors:[...this.drawing.anchors,this.preview]}:this.drawing:null}take(){let e=this.drawing;return this.reset(),e}hasEnough(){return!!this.drawing&&!!this.plugin&&this.drawing.anchors.length>=Math.max(2,this.plugin.descriptor.requiredAnchors)}commit(e,t){this.drawing.anchors.push(e),this.preview=null,this.lastPos=t}},Ma=30;function Na(e,t,n,r,i){if(n===`none`||r.length===0)return{time:e,price:t};let a=!!(i?.data&&i.data.length>0),s=Math.round(a?h(e,r):e);if(s<0||s>r.length-1)return{time:e,price:t};let c=r[s],l=a?c.time:s,u=c.open;for(let e of[c.high,c.low,c.close])Math.abs(t-e)<Math.abs(t-u)&&(u=e);return n===`magnet`&&i&&Math.abs(o(t,i)-o(u,i))>Ma?{time:l,price:t}:{time:l,price:u}}var Pa=class{primaryId=null;others=new Set;listener=null;setListener(e){this.listener=e}change(e){let t=this.ids().join(`\0`),n=e();return this.listener&&this.ids().join(`\0`)!==t&&this.listener(this.ids()),n}get primary(){return this.primaryId}has(e){return e===this.primaryId||this.others.has(e)}ids(){return this.primaryId?[this.primaryId,...this.others]:[]}clear(){this.change(()=>{this.primaryId=null,this.others.clear()})}add(e){this.change(()=>{this.primaryId?e!==this.primaryId&&this.others.add(e):this.primaryId=e})}only(e,t=[]){this.change(()=>{this.primaryId=e,this.others.clear();for(let n of t)n!==e&&this.others.add(n)})}focus(e){e===this.primaryId||!this.others.has(e)||this.change(()=>{this.primaryId&&this.others.add(this.primaryId),this.others.delete(e),this.primaryId=e})}remove(e){return this.change(()=>this.removeNow(e))}removeNow(e){let t=!1;for(let n of e)this.others.delete(n)&&(t=!0),n===this.primaryId&&(this.primaryId=null,t=!0);if(!this.primaryId){let e=this.others.values().next();e.done||(this.primaryId=e.value,this.others.delete(e.value))}return t}},Fa=3,Ia=class{start=null;handle=-1;grabbed=[];constructor(e){this.find=e}isActive(){return this.start!==null}beginMove(e,t){this.start=e,this.handle=-1,this.grabbed=t.map(e=>({id:e.id,anchors:e.anchors.map(e=>({...e})),before:U(e)}))}beginResize(e,t,n){this.start=e,this.handle=n,this.grabbed=[{id:t.id,anchors:t.anchors.map(e=>({...e})),before:U(t)}]}move(e,t,n){return!this.start||this.grabbed.length===0?!1:this.handle>=0?this.reshape(e,t,n):this.translate(e,t)}end(){let e=this.grabbed.flatMap(({id:e,before:t})=>{let n=this.find(e);return n?[{before:t,drawing:n}]:[]});return this.start=null,this.handle=-1,this.grabbed=[],e}translate(e,t){let n=this.start,r=e.x-n.x,i=e.y-n.y;if(Math.hypot(r,i)<Fa&&this.unmoved())return!0;let a=t.barWidth+t.barSpacing,s=a>0?Math.round(r/a):0,c=t.data,l=e=>{let n=g(e,t)+s;return c&&c.length>0?m(n,c):n};for(let{id:e,anchors:n}of this.grabbed){let r=this.find(e);!r||r.locked||(r.anchors=n.map(e=>({time:s===0?e.time:l(e.time),price:i===0?e.price:u(o(e.price,t)+i,t)})))}return!0}unmoved(){return this.grabbed.every(({id:e,anchors:t})=>{let n=this.find(e)?.anchors;return!n||n.every((e,n)=>e.time===t[n]?.time&&e.price===t[n]?.price)})}reshape(t,n,r){let i=this.find(this.grabbed[0].id);if(!i)return!1;let a={time:v(t.x,n),price:u(t.y,n)};if(r?.moveHandle){let t=r.moveHandle(U(i),this.handle,a);i.anchors=t.anchors,i.options=t.options&&Object.keys(t.options).length>0?(0,e.sanitizeDrawingOptions)(r.descriptor.options,t.options):void 0}else this.handle<i.anchors.length&&(i.anchors[this.handle]=a);return!0}},W={drawings:[],pastes:0},La=class{registry=new Map;drawings=[];state=`idle`;activeTool=null;activeStyle={color:`#4c8dff`,lineWidth:1,lineStyle:`solid`,fillColor:`rgba(76, 141, 255, 0.1)`,fillOpacity:.1,fontSize:12};creator=new ja;finishedAt=-1/0;creationPressAt=-1/0;eraser=!1;selection=new Pa;drag=new Ia(e=>this.drawings.find(t=>t.id===e));eventCallback=null;requestRender=null;undoRedo=null;magnetMode=`none`;dataGetter=null;displayDataGetter=null;stayInDrawingMode=!1;toolAllowed=()=>!0;toolDefaults=new Map;edits=new Map;batch=null;register(e){this.registry.set(e.descriptor.type,e),this.dataGetter&&e.setDataGetter?.(this.dataGetter)}setEventCallback(e){this.eventCallback=e}setRequestRender(e){this.requestRender=e}setUndoRedoManager(e){this.undoRedo=e}setMagnetMode(e){this.magnetMode=e}getMagnetMode(){return this.magnetMode}setDataGetter(e){this.dataGetter=e;for(let t of this.registry.values())t.setDataGetter?.(e)}setDisplayDataGetter(e){this.displayDataGetter=e}snapToOHLC(e,t,n){let r=this.magnetMode===`none`?[]:this.displayDataGetter?.()??this.dataGetter?.()??[];return Na(e,t,this.magnetMode,r,n)}undo(){if(!this.undoRedo)return!1;let e=this.undoRedo.undo();return e?(this.applyUndoAction(e),!0):!1}redo(){if(!this.undoRedo)return!1;let e=this.undoRedo.redo();return e?(this.applyRedoAction(e),!0):!1}foreignHistory=null;setForeignHistory(e){this.foreignHistory=e}applyUndoAction(e){if(e.type===`indicators`||e.type===`custom`){this.foreignHistory?.(e,`undo`);return}this.applyHistory(wa(this.drawings,e))}applyRedoAction(e){if(e.type===`indicators`||e.type===`custom`){this.foreignHistory?.(e,`redo`);return}this.applyHistory(Ta(this.drawings,e))}applyHistory(e){let t=new Map(this.drawings.map((e,t)=>[e.id,{d:e,index:t}]));this.drawings=e,this.settleAfterHistory();let n=new Set(e.map(e=>e.id));for(let e of t.keys())n.has(e)||(this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}));e.forEach((e,n)=>{let r=t.get(e.id);r?(r.d!==e||r.index!==n)&&this.eventCallback?.(`drawingUpdate`,{id:e.id}):this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e})})}settleAfterHistory(){this.selection.clear(),this.creator.reset(),this.state=this.activeTool?`creating`:`idle`,this.requestRender?.()}record(e){this.batch?this.batch.push(e):this.undoRedo?.push(e)}batchUndo(e){if(this.batch){e();return}let t=[];this.batch=t;try{e()}finally{this.batch=null}t.length===1?this.undoRedo?.push(t[0]):t.length>1&&this.undoRedo?.push({type:`drawingBatch`,before:null,after:null,actions:t})}deselect(e){this.selection.remove(e)&&!this.selection.primary&&this.state===`selected`&&(this.state=`idle`)}addToSelection(e){this.selection.add(e),this.state=`selected`}groupMates(e){let t=e.group?.id;return t?this.drawings.filter(n=>n.group?.id===t&&n.id!==e.id).map(e=>e.id):[]}select(e){if(this.state===`creating`)return!1;let t=this.drawings.find(t=>t.id===e);return!t||!t.visible?!1:(this.selection.has(e)||this.selection.only(e,this.groupMates(t)),this.state=`selected`,this.requestRender?.(),!0)}setSelectionListener(e){this.selection.setListener(e)}getSelectedDrawingIds(){return this.selection.ids()}selectInRect(e,t){if(this.state===`creating`)return 0;this.selection.clear(),this.state=`idle`;let n=Math.min(e.x0,e.x1),r=Math.max(e.x0,e.x1),i=Math.min(e.y0,e.y1),a=Math.max(e.y0,e.y1);for(let e of this.drawings)e.visible&&e.anchors.some(e=>{let s=_(e.time,t),c=o(e.price,t);return s>=n&&s<=r&&c>=i&&c<=a})&&this.addToSelection(e.id);return this.requestRender?.(),this.getSelectedDrawingIds().length}toggleSelectionAt(e,t){if(this.state===`creating`)return!1;for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(r.visible&&this.registry.get(r.type)?.hitTest(e,r,t,8))return this.selection.has(r.id)?this.deselect([r.id]):this.addToSelection(r.id),this.requestRender?.(),!0}return!1}beginMove(e,t){this.state=`moving`;let n=this.getSelectedDrawingIds().filter(e=>e!==t.id).map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&!e.locked);this.drag.beginMove(e,[t,...n])}setFlags(e,t){this.batchUndo(()=>{for(let n of e){if((t.visible===void 0||n.visible===t.visible)&&(t.locked===void 0||n.locked===t.locked))continue;let e=U(n);Object.assign(n,t),this.record({type:`drawingModify`,before:e,after:U(n)})}}),t.visible===!1&&this.deselect(e.map(e=>e.id)),this.requestRender?.()}lockAllDrawings(){this.setFlags(this.drawings,{locked:!0})}unlockAllDrawings(){this.setFlags(this.drawings,{locked:!1})}hideAllDrawings(){this.setFlags(this.drawings,{visible:!1})}showAllDrawings(){this.setFlags(this.drawings,{visible:!0})}setDrawingVisible(e,t){let n=this.drawings.find(t=>t.id===e);return n?(this.setFlags([n],{visible:t}),t):null}setDrawingsVisible(e,t){let n=new Set(e);this.setFlags(this.drawings.filter(e=>n.has(e.id)),{visible:t})}setDrawingsLocked(e,t){let n=new Set(e);this.setFlags(this.drawings.filter(e=>n.has(e.id)),{locked:t})}setDrawingLocked(e,t){let n=this.drawings.find(t=>t.id===e);return n?(this.setFlags([n],{locked:t}),t):null}setActiveTool(e){e&&this.setEraser(!1);let t=e!==this.activeTool;this.activeTool=e,this.state=e?`creating`:`idle`,this.creator.reset(),t&&this.eventCallback?.(`drawingToolChange`,{tool:e})}setStayInDrawingMode(e){this.stayInDrawingMode=e}isStayInDrawingMode(){return this.stayInDrawingMode}setToolFilter(e){this.toolAllowed=e}copySelection(){let e=this.getSelectedDrawingIds().map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0);return e.length===0?0:(W.drawings=e.map(e=>structuredClone(e)),W.pastes=0,e.length)}paste(){if(W.drawings.length===0||this.state===`creating`)return[];let e=W.drawings.every(e=>this.drawings.some(t=>t.id===e.id));W.pastes+=1;let t=e?this.computeBarOffsetTime(3*W.pastes):0,n=[];if(this.batchUndo(()=>{for(let e of W.drawings)!this.registry.has(e.type)||!this.toolAllowed(e.type)||n.push(this.addDrawing({type:e.type,anchors:e.anchors.map(e=>({...e,time:e.time+t})),style:{...e.style},options:e.options?da(e.options):void 0,meta:e.meta?structuredClone(e.meta):void 0}))}),n.length===0)return n;this.selection.clear();for(let e of n)this.addToSelection(e);return this.requestRender?.(),n}getActiveTool(){return this.activeTool}setStyle(e){Object.assign(this.activeStyle,e)}getActiveStyle(){return{...this.activeStyle}}setSelectedDrawingStyle(e,t){let n=t?[t]:this.getSelectedDrawingIds(),r=!1;return this.batchUndo(()=>{for(let t of n){let n=this.drawings.find(e=>e.id===t);if(!n||n.locked)continue;let i=U(n);n.style={...n.style,...e},this.record({type:`drawingModify`,before:i,after:U(n)}),r=!0}}),r&&this.requestRender?.(),r}onPointerDown(e,t){return this.eraser?this.erase(e,t):this.state===`creating`&&this.activeTool?this.handleCreationClick(e,t):this.state===`idle`||this.state===`selected`?this.handleSelectionClick(e,t):!1}onPointerMove(e,t){let n=this.state===`creating`?this.creator.current:null;if(n&&this.creator.move(this.creationAnchor(n.type,e,t),e))return this.requestRender?.(),!0;if((this.state===`moving`||this.state===`resizing`)&&this.drag.isActive()){let n=this.drawings.find(e=>e.id===this.selection.primary);return this.drag.move(e,t,n&&this.registry.get(n.type))?(this.requestRender?.(),!0):!1}return!1}onPointerUp(){let e=this.state===`creating`?this.creator.release():null;if(e)return this.afterCreationStep(e),!0;if(this.state===`moving`||this.state===`resizing`){let e=this.drag.end();return this.batchUndo(()=>{for(let{before:t,drawing:n}of e)pa(n.anchors,t.anchors)&&fa(n.options,t.options)||this.record({type:`drawingModify`,before:t,after:U(n)})}),this.state=`selected`,!0}return!1}onKeyDown(e,t=!1,n){let r=Da(e,t,n);if(!r)return!1;let i=this.state===`selected`?this.selection.primary:null;switch(r){case`copy`:return i!==null&&this.copySelection()>0;case`paste`:return this.paste().length>0;case`duplicate`:return i!==null&&this.duplicateDrawing(i)!==null;case`group`:return i!==null&&this.groupDrawings(this.getSelectedDrawingIds())!==null;case`ungroup`:return this.ungroupSelection();case`front`:case`forward`:case`backward`:case`back`:return i!==null&&this.moveDrawing(i,r);case`undo`:return this.state===`creating`&&this.creator.current?(this.creator.undoPoint(),this.requestRender?.(),!0):this.undo();case`redo`:return this.redo();case`escape`:return this.escape();case`delete`:return i!==null&&this.removeDrawings(this.getSelectedDrawingIds())>0;case`finish`:{if(this.state!==`creating`||!this.creator.current)return!1;let e=this.creator.finish();return e===`done`?(this.afterCreationStep(e),!0):!1}}}escape(){return this.eraser?(this.setEraser(!1),!0):this.state===`creating`?(this.setActiveTool(null),this.requestRender?.(),!0):this.state===`selected`?(this.selection.clear(),this.state=`idle`,this.requestRender?.(),!0):!1}ungroupSelection(){let e=new Set;for(let t of this.getSelectedDrawingIds()){let n=this.drawings.find(e=>e.id===t)?.group;n&&e.add(n.id)}for(let t of e)this.ungroup(t);return e.size>0}getDrawings(){return this.drawings}setDrawings(t){ba(t),this.drawings=this.upgradeLegacyAnchors(t).map(t=>{if(!t.options)return t;let n=(0,e.sanitizeDrawingOptions)(this.optionDefs(t.type),t.options);return{...t,options:Object.keys(n).length>0?n:void 0}});let n=new Set(this.drawings.map(e=>e.id));this.deselect(this.getSelectedDrawingIds().filter(e=>!n.has(e)));for(let e of[...this.edits.keys()])n.has(e)||this.edits.delete(e);this.requestRender?.()}moveDrawing(e,t){let n=this.drawings.findIndex(t=>t.id===e);if(n<0)return!1;let r=Sa(n,this.drawings.length,t);if(r===n)return!1;let i=this.drawings.map(e=>e.id),a=[...this.drawings],[o]=a.splice(n,1);return a.splice(r,0,o),this.drawings=a,this.record({type:`drawingOrder`,before:null,after:null,order:{before:i,after:a.map(e=>e.id)}}),this.eventCallback?.(`drawingUpdate`,{id:e}),this.requestRender?.(),!0}getGroups(){let e=new Map;for(let t of this.drawings){if(!t.group)continue;let n=e.get(t.group.id)??{id:t.group.id,name:t.group.name,ids:[]};n.ids.push(t.id),e.set(t.group.id,n)}return[...e.values()]}updateGroup(e,t){let n=this.drawings.filter(t=>t.group?.id===e);return n.length===0?!1:(this.batchUndo(()=>{for(let e of n){let n=U(e);t(e),this.record({type:`drawingModify`,before:n,after:U(e)}),this.eventCallback?.(`drawingUpdate`,{id:e.id})}}),this.requestRender?.(),!0)}groupDrawings(e,t){let n=new Set(e),r=this.drawings.filter(e=>n.has(e.id));if(r.length<2)return null;let{id:i,number:a}=ya(),o={id:i,name:Ra(t)||`Group ${a}`};return this.batchUndo(()=>{for(let e of r){let t=U(e);e.group={...o},this.record({type:`drawingModify`,before:t,after:U(e)}),this.eventCallback?.(`drawingUpdate`,{id:e.id})}}),this.requestRender?.(),o.id}ungroup(e){return this.updateGroup(e,e=>{delete e.group})}renameGroup(e,t){let n=Ra(t);return n.length>0&&this.updateGroup(e,t=>{t.group={id:e,name:n}})}setGroupVisible(e,t){let n=this.updateGroup(e,e=>{e.visible=t});return n&&!t&&this.deselect(this.drawings.filter(t=>t.group?.id===e).map(e=>e.id)),n}setGroupLocked(e,t){return this.updateGroup(e,e=>{e.locked=t})}priceAt(e,t,n){let r=this.drawings.find(t=>t.id===e);if(!r)return null;let i=this.registry.get(r.type)?.priceAt?.(r,t,n)??null;return i&&i.every(Number.isFinite)?i:null}hasPriceLevels(e){let t=this.drawings.find(t=>t.id===e);return!!t&&typeof this.registry.get(t.type)?.priceAt==`function`}getDescriptor(e){return this.registry.get(e)?.descriptor??null}getOptionDefs(e){return this.optionDefs(e)??{}}optionDefs(e){return this.registry.get(e)?.descriptor.options}initialOptions(t,n){let r=this.optionDefs(t),i={...da(this.toolDefaults.get(t)??{}),...(0,e.sanitizeDrawingOptions)(r,n)};return Object.keys(i).length>0?i:void 0}setToolDefaults(t,n){let r=n?(0,e.sanitizeDrawingOptions)(this.optionDefs(t),n):{};Object.keys(r).length>0?this.toolDefaults.set(t,r):this.toolDefaults.delete(t)}getToolDefaults(e){return da(this.toolDefaults.get(e)??{})}getDrawingOptions(t){let n=this.drawings.find(e=>e.id===t);return n?(0,e.resolveDrawingOptions)(this.optionDefs(n.type),n.options):{}}setDrawingOptions(e,t){return this.updateDrawing(e,{options:t})}updateDrawing(t,n){let r=this.drawings.find(e=>e.id===t);if(!r||n.anchors&&!(n.anchors.length===r.anchors.length&&n.anchors.every(e=>Number.isFinite(e.time)&&Number.isFinite(e.price))))return!1;let i=this.edits.has(t)?null:U(r);if(n.anchors&&(r.anchors=n.anchors.map(e=>({time:e.time,price:e.price}))),n.style&&(r.style={...r.style,...n.style}),n.options){let t={...r.options,...(0,e.sanitizeDrawingOptions)(this.optionDefs(r.type),n.options)};r.options=Object.keys(t).length>0?t:void 0}return i&&this.record({type:`drawingModify`,before:i,after:U(r)}),this.eventCallback?.(`drawingUpdate`,{id:t}),this.requestRender?.(),!0}beginEdit(e){let t=this.drawings.find(t=>t.id===e);return t?(this.edits.has(e)||this.edits.set(e,U(t)),!0):!1}endEdit(e,{cancel:t=!1}={}){let n=this.edits.get(e);if(!n)return;this.edits.delete(e);let r=this.drawings.findIndex(t=>t.id===e);r<0||(t?(this.drawings[r]=n,this.requestRender?.()):JSON.stringify(n)!==JSON.stringify(this.drawings[r])&&this.record({type:`drawingModify`,before:n,after:U(this.drawings[r])}),this.eventCallback?.(`drawingUpdate`,{id:e}))}addDrawing(e){e.id&&ba([{id:e.id}]);let t=e.id??va(),n={id:t,type:e.type,anchors:e.anchors.map(e=>({...e})),style:{...this.activeStyle,...e.style},visible:e.visible??!0,locked:e.locked??!1,options:this.initialOptions(e.type,e.options),meta:e.meta};return this.drawings=[...this.drawings,n],this.record({type:`drawingCreate`,before:null,after:U(n)}),this.eventCallback?.(`drawingCreate`,{id:t,type:n.type,drawing:n}),this.requestRender?.(),t}upgradeLegacyAnchors(e){let t=this.dataGetter?.();return!t||t.length===0?e:e.map(e=>({...e,anchors:e.anchors.map(e=>{if(e.time>=1e9)return e;let n=Math.max(0,Math.min(t.length-1,Math.round(e.time)));return{...e,time:t[n].time}})}))}removeDrawing(e){let t=this.drawings.findIndex(t=>t.id===e),n=this.drawings[t];this.drawings=this.drawings.filter(t=>t.id!==e),n&&this.record({type:`drawingRemove`,before:structuredClone(n),after:null,index:t}),this.deselect([e]),this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}removeDrawings(e){let t=[...new Set(e)].filter(e=>{let t=this.drawings.find(t=>t.id===e);return t!==void 0&&!t.locked});return t.length===0?0:(this.batchUndo(()=>{for(let e of t)this.removeDrawing(e)}),t.length)}duplicateDrawing(e){let t=this.drawings.find(t=>t.id===e);if(!t)return null;let n=structuredClone(t);n.id=va();let r=this.computeBarOffsetTime(3);return n.anchors=n.anchors.map(e=>({...e,time:e.time+r})),n.locked=!1,this.drawings.push(n),this.record({type:`drawingCreate`,before:null,after:structuredClone(n)}),this.selection.only(n.id),this.state=`selected`,this.eventCallback?.(`drawingCreate`,{id:n.id,type:n.type,drawing:n}),this.requestRender?.(),n.id}clearDrawings(){this.drawings=[],this.selection.clear(),this.state=`idle`,this.requestRender?.()}getSelectedDrawingId(){return this.selection.primary}render(e,t){e.save(),e.beginPath(),e.rect(t.chartRect.x,t.chartRect.y,t.chartRect.width,t.chartRect.height),e.clip();for(let n of this.drawings){if(!n.visible)continue;let r=this.registry.get(n.type);if(!r)continue;let i=this.selection.has(n.id);r.render(e,n,t,i)}let n=this.creator.previewState();n&&this.registry.get(n.type)?.render(e,n,t,!1),e.restore()}computeBarOffsetTime(e){let t=this.dataGetter?.();if(!t||t.length<2)return e;let n=Math.max(0,t.length-20),r=[];for(let e=n+1;e<t.length;e++)r.push(t[e].time-t[e-1].time);return r.length===0?e:(r.sort((e,t)=>e-t),e*r[Math.floor(r.length/2)])}creationAnchor(e,t,n){let r=v(t.x,n),i=u(t.y,n);return this.registry.get(e)?.descriptor.creation===`freehand`?{time:r,price:i}:this.snapToOHLC(r,i,n)}handleCreationClick(e,t){let n=this.activeTool,r=n?this.registry.get(n):void 0;if(!n||!r)return!1;let i=()=>({id:va(),type:n,anchors:[],style:{...this.activeStyle},visible:!0,locked:!1,options:this.initialOptions(n)});return this.creationPressAt=Date.now(),this.afterCreationStep(this.creator.press(r,i,this.creationAnchor(n,e,t),e,e=>({x:_(e.time,t),y:o(e.price,t)}))),!0}afterCreationStep(e){e===`done`?this.finalizeCreation():e===`cancel`&&this.creator.reset(),this.requestRender?.()}setEraser(e){e!==this.eraser&&(this.eraser=e,e&&(this.setActiveTool(null),this.selection.clear(),this.state=`idle`),this.eventCallback?.(`toolModeChange`,{eraser:e}),this.requestRender?.())}isEraser(){return this.eraser}erase(e,t){let n=this.erasableAt(e,t);return n?(this.removeDrawing(n),!0):!1}erasableAt(e,t){for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!(!r.visible||r.locked)&&this.registry.get(r.type)?.hitTest(e,r,t,8))return r.id}return null}justFinished(e=500){return Date.now()-this.creationPressAt<e&&this.finishedAt>=this.creationPressAt}finalizeCreation(){let e=this.creator.take();if(e){if(this.finishedAt=Date.now(),this.drawings.push(e),this.selection.only(e.id),this.record({type:`drawingCreate`,before:null,after:structuredClone(e)}),this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e}),this.stayInDrawingMode&&this.activeTool){this.selection.clear(),this.state=`creating`;return}this.activeTool=null,this.state=`selected`,this.eventCallback?.(`drawingToolChange`,{tool:null})}}isDragging(){return this.state===`moving`||this.state===`resizing`}drawingAt(e,t,n=8){for(let r=this.drawings.length-1;r>=0;r--){let i=this.drawings[r];if(i.visible&&this.registry.get(i.type)?.hitTest(e,i,t,n))return i.id}return null}hoverCursorAt(e,t){if(this.eraser)return this.erasableAt(e,t)?`pointer`:null;if(this.activeTool||this.state===`creating`)return null;if(this.selection.primary){let n=this.drawings.find(e=>e.id===this.selection.primary),r=n&&n.visible&&!n.locked?this.registry.get(n.type):void 0;if(n&&r&&r.hitTestAnchor(e,n,t,8)>=0)return`move`}for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!(!r.visible||r.locked)&&this.registry.get(r.type)?.hitTest(e,r,t,8))return`pointer`}return null}handleSelectionClick(e,t){if(this.selection.primary){let n=this.drawings.find(e=>e.id===this.selection.primary);if(n&&n.visible&&!n.locked){let r=this.registry.get(n.type);if(r){let i=r.hitTestAnchor(e,n,t,8);if(i>=0)return this.state=`resizing`,this.drag.beginResize(e,n,i),!0;if(r.hitTest(e,n,t,8))return this.beginMove(e,n),!0}}}for(let n=this.drawings.length-1;n>=0;n--){let r=this.drawings[n];if(!r.visible)continue;let i=this.registry.get(r.type);if(i&&i.hitTest(e,r,t,8))return this.selection.has(r.id)?this.selection.focus(r.id):this.selection.only(r.id,this.groupMates(r)),this.requestRender?.(),r.locked?(this.state=`selected`,!1):(this.beginMove(e,r),!0)}return this.selection.primary&&(this.selection.clear(),this.state=`idle`,this.requestRender?.()),!1}};function Ra(e){return(e??``).trim().slice(0,80)}var za=class{constructor(e){this.manager=e}render(e,t){this.manager.render(e,t)}};function Ba(e,t,n){let r=Math.max(0,t),i=Math.min(e.length-1,n);if(i<=r)return null;let a=r,o=r;for(let t=r;t<=i;t++)e[t].high>e[a].high&&(a=t),e[t].low<e[o].low&&(o=t);if(a===o)return null;let s={time:e[a].time,price:e[a].high},c={time:e[o].time,price:e[o].low};return a<o?[s,c]:[c,s]}function Va(e,t=[]){return[...e.map(e=>({value:e,visible:!0})),...t.map(e=>({value:e,visible:!1}))].sort((e,t)=>e.value-t.value)}function Ha(e=!1,t=!1){return{extendLeft:{kind:`boolean`,label:`Extend left`,default:e},extendRight:{kind:`boolean`,label:`Extend right`,default:t}}}var Ua={showLevels:{kind:`boolean`,label:`Show levels`,default:!0},showPrices:{kind:`boolean`,label:`Show prices`,default:!0},labelPosition:{kind:`choice`,label:`Labels`,default:`left`,choices:[{value:`left`,label:`Left`},{value:`right`,label:`Right`}]}},Wa=class extends H{descriptor={type:`trendLine`,name:`Trend Line`,requiredAnchors:2,options:Ha()};segment(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return this.extendLine(n,r,t,this.option(e,`extendLeft`),this.option(e,`extendRight`))}render(e,t,n,r){if(t.anchors.length<2)return;let[i,a]=this.segment(t,n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<2)return null;let r=this.linePriceAt(e.anchors[0],e.anchors[1],t,this.option(e,`extendLeft`),this.option(e,`extendRight`),la(n));return r===null?null:[r]}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let[i,a]=this.segment(t,n);return this.distanceToLine(e,i,a)<=r}},Ga=`11px sans-serif`,Ka=14,qa=6,Ja=4,Ya=`rgba(19, 23, 34, 0.85)`,Xa=`#FFFFFF`,Za=6e4,Qa=60*Za,$a=24*Qa;function eo(e){let t=Math.abs(e);return t>=10||t===0?2:t>=1?4:Math.min(10,Math.ceil(-Math.log10(t))+3)}function G(e,t=e,n){return n?.formatPrice?n.formatPrice(e):e.toFixed(eo(t))}function to(e,t,n){let r=t-e,i=e===0?0:r/e*100,a=r>=0?`+`:``;return`${a}${G(r,e,n)} (${a}${i.toFixed(2)}%)`}function no(e){let t=Math.abs(e);if(t<Qa)return`${Math.round(t/Za)}m`;if(t<$a){let e=Math.floor(t/Qa),n=Math.round((t-e*Qa)/Za);return n>0?`${e}h ${n}m`:`${e}h`}let n=Math.floor(t/$a),r=Math.round((t-n*$a)/Qa);if(n>=7){let e=Math.floor(n/7),t=n-e*7;return t>0?`${e}w ${t}d`:`${e}w`}return r>0?`${n}d ${r}h`:`${n}d`}function ro(e){return!!e.data&&e.data.length>0}function io(e,t,n,r){let i=g(e.anchors[t].time,r),a=g(e.anchors[n].time,r);return Math.round(Math.abs(a-i))}function ao(e,t,n,r){return ro(r)?no(e.anchors[n].time-e.anchors[t].time):null}function oo(e,t,n,r,i=`center`,a=!0){e.font=Ga;let o=0;for(let n of t)o=Math.max(o,e.measureText(n).width);let s=o+qa*2,c=t.length*Ka+Ja*2,l=i===`left`?n:i===`right`?n-s:n-s/2,u=a?r-c:r;e.fillStyle=Ya,e.fillRect(l,u,s,c),e.fillStyle=Xa,e.textAlign=`left`,e.textBaseline=`top`;for(let n=0;n<t.length;n++)e.fillText(t[n],l+qa,u+Ja+n*Ka);return{x:l,y:u,width:s,height:c}}function so(e,t,n){let r=Math.abs(e.anchors[t[1]].price-e.anchors[t[0]].price),i=Math.abs(e.anchors[n[1]].price-e.anchors[n[0]].price);return i===0?`—`:(r/i).toFixed(3)}var co=class extends H{descriptor={type:`horizontalLine`,name:`Horizontal Line`,requiredAnchors:1};priceAt(e){return e.anchors.length<1?null:[e.anchors[0].price]}render(e,t,n,r){if(t.anchors.length<1)return;let i=o(t.anchors[0].price,n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(a.x,i),e.lineTo(a.x+a.width,i),e.stroke(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`11px sans-serif`,e.textBaseline=`bottom`,e.fillText(G(t.anchors[0].price,t.anchors[0].price,n),a.x+4,i-3),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=o(t.anchors[0].price,n);return Math.abs(e.y-i)<=r&&e.x>=n.chartRect.x&&e.x<=n.chartRect.x+n.chartRect.width}},lo=class extends H{descriptor={type:`horizontalRay`,name:`Horizontal Ray`,requiredAnchors:1};priceAt(e,t){return e.anchors.length<1||t<e.anchors[0].time?null:[e.anchors[0].price]}render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=i.y,{chartRect:o}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,a),e.lineTo(o.x+o.width,a),e.stroke(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`11px sans-serif`,e.textBaseline=`bottom`,e.fillText(G(t.anchors[0].price,t.anchors[0].price,n),i.x+4,a-3),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return Math.abs(e.y-i.y)<=r&&e.x>=i.x-r&&e.x<=n.chartRect.x+n.chartRect.width}},uo=class extends H{descriptor={type:`verticalLine`,name:`Vertical Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,a.y),e.lineTo(i.x,a.y+a.height),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;return Math.abs(e.x-i.x)<=r&&e.y>=a.y&&e.y<=a.y+a.height}},fo=class extends H{descriptor={type:`ray`,name:`Ray`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x+s/l*u,f=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(d,f),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<2)return null;let r=this.linePriceAt(e.anchors[0],e.anchors[1],t,!1,!0,la(n));return r===null?null:[r]}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;return((e.x-i.x)*o+(e.y-i.y)*s)/(o*o+s*s)<0?!1:this.distanceToInfiniteLine(e,i,a)<=r}},po=class extends H{descriptor={type:`extendedLine`,name:`Extended Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x-s/l*u,f=i.y-c/l*u,p=i.x+s/l*u,m=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<2)return null;let r=this.linePriceAt(e.anchors[0],e.anchors[1],t,!0,!0,la(n));return r===null?null:[r]}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToInfiniteLine(e,i,a)<=r}},mo=class extends H{descriptor={type:`parallelChannel`,name:`Parallel Channel`,requiredAnchors:3,fill:!0,options:{...Ha(),middleLine:{kind:`boolean`,label:`Middle line`,default:!1}}};lines(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i=this.option(e,`extendLeft`),a=this.option(e,`extendRight`),o=this.extendLine(n,r,t,i,a);if(e.anchors.length<3)return{base:o,parallel:null,middle:null,corners:null};let s=this.anchorToPixel(e.anchors[2],t),c=r.x-n.x,l=r.y-n.y,u=Math.hypot(c,l)||1,d=-l/u,f=c/u,p=(s.x-n.x)*d+(s.y-n.y)*f,m=(e,t)=>({x:e.x+d*p*t,y:e.y+f*p*t}),h=m(n,1),g=m(r,1);return{base:o,parallel:this.extendLine(h,g,t,i,a),middle:this.option(e,`middleLine`)?this.extendLine(m(n,.5),m(r,.5),t,i,a):null,corners:[n,r,g,h]}}render(e,t,n,r){if(t.anchors.length<2)return;let{base:i,parallel:a,middle:o,corners:s}=this.lines(t,n);this.applyLineStyle(e,t.style);for(let t of[i,a])t&&(e.beginPath(),e.moveTo(t[0].x,t[0].y),e.lineTo(t[1].x,t[1].y),e.stroke());if(o&&(e.setLineDash([4,4]),e.beginPath(),e.moveTo(o[0].x,o[0].y),e.lineTo(o[1].x,o[1].y),e.stroke()),s&&t.style.fillColor){e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(s[0].x,s[0].y);for(let t of s.slice(1))e.lineTo(t.x,t.y);e.closePath(),e.fill()}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<3)return null;let[r,i,a]=e.anchors,o=la(n),s=this.lineValueAt(r,i,t,this.option(e,`extendLeft`),this.option(e,`extendRight`),o),c=this.lineValueAt(r,i,a.time,!0,!0,o);if(s===null||c===null)return null;let l=o.value(a.price)-c,u=[s,s+l];return this.option(e,`middleLine`)&&u.push(s+l/2),u.map(o.price)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{base:i,parallel:a,middle:o}=this.lines(t,n);return[i,a,o].some(t=>t!==null&&this.distanceToLine(e,t[0],t[1])<=r)}},ho=class extends H{descriptor={type:`regressionChannel`,name:`Regression Channel`,requiredAnchors:2,fill:!0};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=a.x-i.x,s=a.y-i.y,c=Math.hypot(o,s);if(c===0){this.resetLineStyle(e);return}let l=Math.max(10,Math.min(c*.2,100)),u=-s/c*l,d=o/c*l;e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.stroke(),e.beginPath(),e.moveTo(i.x-u,i.y-d),e.lineTo(a.x-u,a.y-d),e.stroke(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.beginPath(),e.moveTo(i.x+u,i.y+d),e.lineTo(a.x+u,a.y+d),e.lineTo(a.x-u,a.y-d),e.lineTo(i.x-u,i.y-d),e.closePath(),e.fill()),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.hypot(a.x-i.x,a.y-i.y),s=Math.max(10,Math.min(o*.2,100));return this.distanceToLine(e,i,a)<=r+s}};function go(e,t,n,r,i=e=>e.toFixed(2)){let a=`${(e*100).toFixed(1)}%`,o=i(t);return n&&r?`${a} (${o})`:n?a:r?o:``}function _o(e,t,n,r,i,a){let s=i.x1-i.x0;if(i.background&&r.length>1){let a=[...r].sort((e,t)=>e.level.value-t.level.value);for(let r=0;r<a.length-1;r++){let c=o(a[r].price,n),l=o(a[r+1].price,n),u=a[r+1].level.color,d=u??t.style.fillColor;d&&(e.fillStyle=d,e.globalAlpha=u?.12:.05+r*.02,e.fillRect(i.x0,Math.min(c,l),s,Math.abs(l-c)))}e.globalAlpha=1}e.font=`11px sans-serif`,e.textBaseline=`middle`,e.textAlign=i.labelPosition===`right`?`right`:`left`;let c=i.labelPosition===`right`?i.x1-4:i.x0+4;for(let{level:s,price:l}of r){let r=o(l,n),u=s.color??t.style.color;a(u),e.globalAlpha=s.value===0||s.value===1?1:.7,e.beginPath(),e.moveTo(i.x0,r),e.lineTo(i.x1,r),e.stroke();let d=go(s.value,l,i.showLevels,i.showPrices,e=>G(e,e,n));d&&(e.fillStyle=u,e.fillText(d,c,r-2))}e.globalAlpha=1}function vo(e,t,n,r,i,a){return e.x<r-a||e.x>i+a?!1:n.some(({price:n})=>Math.abs(e.y-o(n,t))<=a)}var yo=Va([0,.236,.382,.5,.618,.786,1],[1.272,1.414,1.618,2.618,3.618,4.236]),bo=class extends H{descriptor={type:`fibRetracement`,name:`Fibonacci Retracement`,requiredAnchors:2,fill:!0,options:{levels:{kind:`levels`,label:`Levels`,default:yo},...Ha(!0,!0),reverse:{kind:`boolean`,label:`Reverse`,default:!1},...Ua,background:{kind:`boolean`,label:`Background`,default:!0}}};levels(e){let t=this.option(e,`reverse`),n=e.anchors[+!!t].price,r=e.anchors[+!t].price;return this.visibleLevels(e).map(e=>({level:e,price:n+(r-n)*e.value}))}span(e,t){let{chartRect:n}=t,r=this.anchorToPixel(e.anchors[0],t).x,i=this.anchorToPixel(e.anchors[1],t).x;return[this.option(e,`extendLeft`)?n.x:Math.min(r,i),this.option(e,`extendRight`)?n.x+n.width:Math.max(r,i)]}render(e,t,n,r){if(t.anchors.length<2)return;let[i,a]=this.span(t,n);_o(e,t,n,this.levels(t),{x0:i,x1:a,showLevels:this.option(t,`showLevels`),showPrices:this.option(t,`showPrices`),labelPosition:this.option(t,`labelPosition`),background:this.option(t,`background`)},n=>this.applyLineStyle(e,{...t.style,color:n})),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let[i,a]=this.span(t,n);return vo(e,n,this.levels(t),i,a,r)}},xo=Va([0,.618,1,1.618,2,2.618,3.618,4.236],[.382,.5,.786,1.272,1.414]),So=class extends H{descriptor={type:`fibExtension`,name:`Fibonacci Extension`,requiredAnchors:3,fill:!0,options:{levels:{kind:`levels`,label:`Levels`,default:xo},...Ha(!0,!0),...Ua,background:{kind:`boolean`,label:`Background`,default:!1}}};levels(e){let t=e.anchors[1].price-e.anchors[0].price,n=e.anchors[2].price;return this.visibleLevels(e).map(e=>({level:e,price:n+t*e.value}))}span(e,t){let{chartRect:n}=t,r=e.anchors.map(e=>this.anchorToPixel(e,t).x);return[this.option(e,`extendLeft`)?n.x:Math.min(...r),this.option(e,`extendRight`)?n.x+n.width:Math.max(...r)]}render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let[i,a]=this.span(t,n);_o(e,t,n,this.levels(t),{x0:i,x1:a,showLevels:this.option(t,`showLevels`),showPrices:this.option(t,`showPrices`),labelPosition:this.option(t,`labelPosition`),background:this.option(t,`background`)},n=>this.applyLineStyle(e,{...t.style,color:n})),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let[i,a]=this.span(t,n);return vo(e,n,this.levels(t),i,a,r)}},Co=class extends H{descriptor={type:`rectangle`,name:`Rectangle`,requiredAnchors:2,fill:!0};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y);t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fillRect(o,s,c,l)),this.applyLineStyle(e,t.style),e.strokeRect(o,s,c,l),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.min(i.y,a.y)-r,c=Math.max(i.x,a.x)+r,l=Math.max(i.y,a.y)+r;if(e.x<o||e.x>c||e.y<s||e.y>l)return!1;let u=Math.min(i.x,a.x)+r,d=Math.min(i.y,a.y)+r,f=Math.max(i.x,a.x)-r,p=Math.max(i.y,a.y)-r;return!(e.x>u&&e.x<f&&e.y>d&&e.y<p)||!!t.style.fillColor}},wo=class extends H{descriptor={type:`ellipse`,name:`Ellipse`,requiredAnchors:2,fill:!0};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.abs(a.x-i.x)/2,l=Math.abs(a.y-i.y)/2;e.beginPath(),e.ellipse(o,s,Math.max(c,1),Math.max(l,1),0,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.max(Math.abs(a.x-i.x)/2,1),l=Math.max(Math.abs(a.y-i.y)/2,1),u=(e.x-o)/c,d=(e.y-s)/l,f=Math.sqrt(u*u+d*d),p=r/Math.max(Math.min(c,l),4);return t.style.fillColor?f<=1+p:Math.abs(f-1)<=p}},To=class extends H{descriptor={type:`triangle`,name:`Triangle`,requiredAnchors:3,fill:!0};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=t.anchors.map(e=>this.anchorToPixel(e,n));e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.lineTo(i[2].x,i[2].y),e.closePath(),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<3;t++){let n=(t+1)%3;if(this.distanceToLine(e,i[t],i[n])<=r)return!0}return!1}},Eo=class extends H{descriptor={type:`pitchfork`,name:`Andrews' Pitchfork`,requiredAnchors:3};origin(e,t){return e}render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n),s=this.origin(i,a),c={x:(a.x+o.x)/2,y:(a.y+o.y)/2};(s.x!==i.x||s.y!==i.y)&&(e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(s.x,s.y),e.stroke(),e.setLineDash([]));let l=c.x-s.x,u=c.y-s.y,d=Math.hypot(l,u)||1,f=Math.hypot(n.chartRect.width,n.chartRect.height),p=s.x+l/d*f,m=s.y+u/d*f;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(p,m),e.stroke(),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x+l/d*f,a.y+u/d*f),e.stroke(),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x+l/d*f,o.y+u/d*f),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[1],n),a=this.anchorToPixel(t.anchors[2],n),o=this.origin(this.anchorToPixel(t.anchors[0],n),i),s={x:(i.x+a.x)/2,y:(i.y+a.y)/2};if(this.distanceToInfiniteLine(e,o,s)<=r)return!0;let c=s.x-o.x,l=s.y-o.y,u={x:i.x+c,y:i.y+l},d={x:a.x+c,y:a.y+l};return this.distanceToInfiniteLine(e,i,u)<=r||this.distanceToInfiniteLine(e,a,d)<=r}},Do=class extends Eo{descriptor={type:`schiffPitchfork`,name:`Schiff Pitchfork`,requiredAnchors:3};origin(e,t){return{x:e.x,y:(e.y+t.y)/2}}},Oo=class extends Eo{descriptor={type:`modifiedSchiffPitchfork`,name:`Modified Schiff Pitchfork`,requiredAnchors:3};origin(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}},ko=[`0`,`i`,`ii`,`iii`,`iv`,`v`];function Ao(e,t){let n=/^[0-9]$/.test(e);switch(t){case`primary`:return n?e===`0`?`⓪`:String.fromCodePoint(9312+Number(e)-1):/^[A-Z]$/.test(e)?String.fromCodePoint(9398+e.charCodeAt(0)-65):e;case`intermediate`:return`(${e})`;case`minute`:return n?ko[Number(e)]??e:e.toLowerCase();default:return e}}var jo={degree:{kind:`choice`,label:`Degree`,default:`minor`,choices:[{value:`primary`,label:`Primary`},{value:`intermediate`,label:`Intermediate`},{value:`minor`,label:`Minor`},{value:`minute`,label:`Minute`}]}},Mo=class extends H{render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));this.applyLineStyle(e,t.style),e.beginPath(),i.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke(),this.resetLineStyle(e);let a=this.option(t,`degree`);e.font=`bold 12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`;for(let t=0;t<i.length&&t<this.labels.length;t++){let n=i[t-1]??i[t+1],r=i[t+1]??i[t-1],o=i[t].y<=Math.min(n.y,r.y);e.textBaseline=o?`bottom`:`top`,e.fillText(Ao(this.labels[t],a),i[t].x,i[t].y+(o?-6:6))}r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:V(e,t.anchors.map(e=>this.anchorToPixel(e,n)),r)}},No=class extends Mo{descriptor={type:`elliottWave`,name:`Elliott Wave`,requiredAnchors:8,options:jo};labels=[`1`,`2`,`3`,`4`,`5`,`A`,`B`,`C`]},Po=class extends Mo{descriptor={type:`elliottImpulse`,name:`Elliott Impulse Wave`,requiredAnchors:6,options:jo};labels=[`0`,`1`,`2`,`3`,`4`,`5`]},Fo=class extends Mo{descriptor={type:`elliottCorrection`,name:`Elliott Correction Wave`,requiredAnchors:4,options:jo};labels=[`0`,`A`,`B`,`C`]},Io=class extends Mo{descriptor={type:`elliottTriangle`,name:`Elliott Triangle Wave`,requiredAnchors:6,options:jo};labels=[`0`,`A`,`B`,`C`,`D`,`E`]},Lo=class extends Mo{descriptor={type:`elliottDoubleCombo`,name:`Elliott Double Combo Wave`,requiredAnchors:4,options:jo};labels=[`0`,`W`,`X`,`Y`]},Ro=class extends Mo{descriptor={type:`elliottTripleCombo`,name:`Elliott Triple Combo Wave`,requiredAnchors:6,options:jo};labels=[`0`,`W`,`X`,`Y`,`X`,`Z`]},zo=class extends H{descriptor={type:`priceRange`,name:`Price Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.abs(a.x-i.x),c=Math.min(i.y,a.y),l=Math.abs(a.y-i.y),u=t.anchors[1].price>t.anchors[0].price;e.fillStyle=u?`rgba(31, 168, 116, 0.15)`:`rgba(232, 80, 91, 0.15)`,e.fillRect(o,c,s,l),this.applyLineStyle(e,t.style),e.strokeRect(o,c,s,l),this.resetLineStyle(e);let d=to(t.anchors[0].price,t.anchors[1].price,n);e.font=`12px sans-serif`,e.fillStyle=u?`#1fa874`:`#e8505b`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(d,o+s/2,c+l/2),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return e.x>=o-r&&e.x<=s+r&&e.y>=c-r&&e.y<=l+r}},Bo=class extends H{descriptor={type:`dateRange`,name:`Date Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);e.fillStyle=`rgba(76, 141, 255, 0.08)`,e.fillRect(s,o.y,c-s,o.height),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s,o.y),e.lineTo(s,o.y+o.height),e.stroke(),e.beginPath(),e.moveTo(c,o.y),e.lineTo(c,o.y+o.height),e.stroke(),this.resetLineStyle(e);let l=g(t.anchors[0].time,n),u=g(t.anchors[1].time,n),d=Math.max(0,Math.round(Math.abs(u-l)));e.font=`12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`,e.textBaseline=`top`,e.fillText(`${d} bars`,(s+c)/2,o.y+4),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);return e.x>=s-r&&e.x<=c+r&&e.y>=o.y&&e.y<=o.y+o.height}},Vo=class extends H{descriptor={type:`measure`,name:`Measure`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=g(t.anchors[0].time,n),s=g(t.anchors[1].time,n),c=Math.max(0,Math.round(Math.abs(s-o))),l=[`Price: ${to(t.anchors[0].price,t.anchors[1].price,n)}`,`Bars: ${c}`],u=(i.x+a.x)/2,d=(i.y+a.y)/2;e.font=`11px sans-serif`,e.textAlign=`center`,e.textBaseline=`bottom`;let f=Math.max(...l.map(t=>e.measureText(t).width));e.fillStyle=`rgba(0, 0, 0, 0.7)`,e.fillRect(u-f/2-6,d-l.length*14-4,f+12,l.length*14+8),e.fillStyle=`#FFFFFF`;for(let t=0;t<l.length;t++)e.fillText(l[t],u,d-(l.length-1-t)*14);r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}};function Ho(e,t=`Text`){if(typeof e.style.text==`string`&&e.style.text.length>0)return e.style.text;let n=e.meta?.text;return typeof n==`string`&&n.length>0?n:t}var Uo=class extends H{descriptor={type:`text`,name:`Text`,requiredAnchors:1,text:!0};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=Ho(t),o=t.style.fontSize||14;if(e.font=`${o}px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`left`,e.textBaseline=`top`,r){let n=e.measureText(a);e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.strokeRect(i.x-2,i.y-2,n.width+4,o+4),e.setLineDash([])}e.fillText(a,i.x,i.y),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=t.style.fontSize||14;return e.x>=i.x-r&&e.x<=i.x+80+r&&e.y>=i.y-r&&e.y<=i.y+a+r}},Wo=class extends H{descriptor={type:`arrow`,name:`Arrow`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke();let o=Math.atan2(a.y-i.y,a.x-i.x);e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(a.x-12*Math.cos(o-Math.PI/6),a.y-12*Math.sin(o-Math.PI/6)),e.lineTo(a.x-12*Math.cos(o+Math.PI/6),a.y-12*Math.sin(o+Math.PI/6)),e.closePath(),e.fillStyle=t.style.color,e.fill(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},Go=[{label:`8x1`,ratio:8},{label:`4x1`,ratio:4},{label:`3x1`,ratio:3},{label:`2x1`,ratio:2},{label:`1x1`,ratio:1},{label:`1x2`,ratio:.5},{label:`1x3`,ratio:1/3},{label:`1x4`,ratio:.25},{label:`1x8`,ratio:.125}],Ko=class extends H{descriptor={type:`gannFan`,name:`Gann Fan`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;this.applyLineStyle(e,t.style);for(let{label:n,ratio:r}of Go){let a=c*r,o=d,s=i.y+a*(o-i.x);e.globalAlpha=r===1?1:.5,e.lineWidth=r===1?t.style.lineWidth:Math.max(.5,t.style.lineWidth*.7),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o,s),e.stroke();let f=o-l*4,p=s;p>u.y&&p<u.y+u.height&&(e.globalAlpha=.7,e.fillStyle=t.style.color,e.font=`9px sans-serif`,e.textAlign=l>0?`right`:`left`,e.textBaseline=`bottom`,e.fillText(n,f,p-2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return!1;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;for(let{ratio:t}of Go){let n=c*t,a=d,o=i.y+n*(a-i.x);if(this.distanceToLine(e,i,{x:a,y:o})<=r)return!0}return!1}},qo=[0,.25,.333,.5,.667,.75,1],Jo=class extends H{descriptor={type:`gannBox`,name:`Gann Box`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y),u=s-o,d=l-c;if(!(u<2||d<2)){this.applyLineStyle(e,t.style),e.strokeRect(o,c,u,d),e.save(),e.globalAlpha=.35;for(let t of qo){if(t===0||t===1)continue;let n=c+d*t;e.beginPath(),e.moveTo(o,n),e.lineTo(s,n),e.stroke()}for(let t of qo){if(t===0||t===1)continue;let n=o+u*t;e.beginPath(),e.moveTo(n,c),e.lineTo(n,l),e.stroke()}e.globalAlpha=.5,e.setLineDash([4,3]),e.beginPath(),e.moveTo(o,c),e.lineTo(s,l),e.stroke(),e.beginPath(),e.moveTo(s,c),e.lineTo(o,l),e.stroke(),e.restore(),this.resetLineStyle(e),e.fillStyle=t.style.color,e.font=`8px sans-serif`,e.globalAlpha=.6,e.textBaseline=`bottom`,e.textAlign=`right`;for(let t of qo){if(t===0||t===1)continue;let n=c+d*t;e.fillText(`${(t*100).toFixed(0)}%`,o-3,n)}e.globalAlpha=1,r&&this.renderAnchorHandles(e,t,n)}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return Math.abs(e.x-o)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.x-s)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.y-c)<=r&&e.x>=o-r&&e.x<=s+r||Math.abs(e.y-l)<=r&&e.x>=o-r&&e.x<=s+r||this.distanceToLine(e,{x:o,y:c},{x:s,y:l})<=r||this.distanceToLine(e,{x:s,y:c},{x:o,y:l})<=r}},Yo=class extends H{descriptor={type:`anchoredVWAP`,name:`Anchored VWAP`,requiredAnchors:1};dataGetter=null;showBands=!0;setDataGetter(e){this.dataGetter=e}setShowBands(e){this.showBands=e}render(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return;let i=this.dataGetter(),s=Math.max(0,Math.round(g(t.anchors[0].time,n)));if(s>=i.length)return;let{vwap:c,upper1:l,lower1:u,upper2:d,lower2:f}=this.computeVWAP(i,s),{chartRect:p}=n,m=n.barWidth+n.barSpacing;if(this.applyLineStyle(e,t.style),e.lineWidth=t.style.lineWidth+.5,this.drawLine(e,c,s,n,p,m),this.showBands&&c.length>1&&(e.globalAlpha=.4,e.lineWidth=Math.max(.5,t.style.lineWidth*.6),e.setLineDash([4,3]),this.drawLine(e,l,s,n,p,m),this.drawLine(e,u,s,n,p,m),e.globalAlpha=.25,this.drawLine(e,d,s,n,p,m),this.drawLine(e,f,s,n,p,m),e.globalAlpha=1),this.resetLineStyle(e),c.length>0){let r=c[c.length-1],i=a(s+c.length-1,n),l=o(r,n);i>=p.x&&i<=p.x+p.width&&(e.fillStyle=t.style.color,e.font=`bold 9px sans-serif`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`AVWAP ${G(r,r,n)}`,i+6,l))}r&&this.renderAnchorHandles(e,t,n)}drawLine(e,t,n,r,i,s){e.beginPath();let c=!1;for(let l=0;l<t.length;l++){let u=a(n+l,r);if(u<i.x-s)continue;if(u>i.x+i.width+s)break;let d=o(t[l],r);c?e.lineTo(u,d):(e.moveTo(u,d),c=!0)}e.stroke()}vwapCache=null;computeVWAP(e,t){let n=e[e.length-1],r=this.vwapCache;if(r&&r.data===e&&r.length===e.length&&r.startIdx===t&&r.lastClose===n?.close&&r.lastVolume===(n?.volume??0))return r.result;let i=this.computeVWAPUncached(e,t);return this.vwapCache={data:e,length:e.length,startIdx:t,lastClose:n?.close,lastVolume:n?.volume??0,result:i},i}computeVWAPUncached(e,t){let n=e.length-t,r=Array(n),i=Array(n),a=Array(n),o=Array(n),s=Array(n),c=0,l=0,u=0;for(let d=0;d<n;d++){let n=e[t+d],f=(n.high+n.low+n.close)/3,p=n.volume??1;c+=f*p,l+=p,u+=f*f*p;let m=l>0?c/l:f;r[d]=m;let h=l>0?u/l-m*m:0,g=Math.sqrt(Math.max(0,h));i[d]=m+g,a[d]=m-g,o[d]=m+2*g,s[d]=m-2*g}return{vwap:r,upper1:i,lower1:a,upper2:o,lower2:s}}hitTest(e,t,n,r){if(t.anchors.length<1||!this.dataGetter)return!1;let i=this.dataGetter(),s=Math.max(0,Math.round(g(t.anchors[0].time,n)));if(s>=i.length)return!1;let{vwap:c}=this.computeVWAP(i,s);for(let t=1;t<c.length;t++){let i=a(s+t-1,n),l=o(c[t-1],n),u=a(s+t,n),d=o(c[t],n);if(this.distanceToLine(e,{x:i,y:l},{x:u,y:d})<=r)return!0}return!1}},Xo=class extends H{descriptor={type:`volumeProfileRange`,name:`Volume Profile (Range)`,requiredAnchors:2,fill:!0};dataGetter=null;numBins=40;setDataGetter(e){this.dataGetter=e}render(e,t,n,r){if(t.anchors.length<2||!this.dataGetter)return;let i=this.dataGetter(),s=Math.round(g(t.anchors[0].time,n)),c=Math.round(g(t.anchors[1].time,n)),l=Math.max(0,Math.min(s,c)),u=Math.min(i.length-1,Math.max(s,c));if(l>=i.length||u<0||l>u)return;let d=1/0,f=-1/0;for(let e=l;e<=u;e++)i[e].low<d&&(d=i[e].low),i[e].high>f&&(f=i[e].high);if(d>=f)return;let p=(f-d)/this.numBins,m=new Float64Array(this.numBins),h=0;for(let e=l;e<=u;e++){let t=i[e],n=t.volume??1,r=Math.max(0,Math.floor((t.low-d)/p)),a=Math.min(this.numBins-1,Math.floor((t.high-d)/p)),o=n/(a-r+1);for(let e=r;e<=a;e++)m[e]+=o,m[e]>h&&(h=m[e])}if(h===0)return;let _=0;for(let e=1;e<this.numBins;e++)m[e]>m[_]&&(_=e);let v=a(u,n)+n.barWidth,y=t.style.color,b=t.style.fillColor??`#f2a93b`;e.save();for(let t=0;t<this.numBins;t++){let r=m[t]/h*100,i=d+(t+1)*p,a=d+t*p,s=o(i,n),c=o(a,n),l=Math.abs(c-s);e.globalAlpha=.35,e.fillStyle=t===_?b:y,e.fillRect(v,Math.min(s,c),r,Math.max(1,l-.5))}let x=d+(_+.5)*p,S=o(x,n);e.globalAlpha=.7,e.strokeStyle=b,e.lineWidth=1,e.setLineDash([4,3]),e.beginPath();let C=a(l,n)-n.barWidth/2;e.moveTo(C,S),e.lineTo(v+100,S),e.stroke(),e.fillStyle=b,e.font=`9px sans-serif`,e.textAlign=`left`,e.textBaseline=`bottom`,e.globalAlpha=.8,e.fillText(`POC ${G(x,x,n)}`,v+100+4,S-2),e.restore(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.max(i.x,a.x)+100+r,c=Math.min(i.y,a.y)-r,l=Math.max(i.y,a.y)+r;return e.x>=o&&e.x<=s&&e.y>=c&&e.y<=l}},Zo=[1,2,3,5,8,13,21,34,55],Qo=class extends H{descriptor={type:`fibTimeZones`,name:`Fibonacci Time Zones`,requiredAnchors:2,options:{levels:{kind:`levels`,label:`Levels`,default:Va(Zo,[0,89,144])}}};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return;let{chartRect:o}=n;e.font=`11px sans-serif`,e.textBaseline=`top`,e.textAlign=`center`;for(let{value:r,color:s}of this.visibleLevels(t)){this.applyLineStyle(e,{...t.style,color:s??t.style.color});let c=_(i.time+a*r,n);c<o.x||c>o.x+o.width||(e.globalAlpha=r===1?1:.55,e.beginPath(),e.moveTo(c,o.y),e.lineTo(c,o.y+o.height),e.stroke(),e.fillStyle=s??t.style.color,e.fillText(String(r),c,o.y+2))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors[0],a=t.anchors[1].time-i.time;if(a===0)return!1;let{chartRect:o}=n;if(e.y<o.y||e.y>o.y+o.height)return!1;for(let{value:o}of this.visibleLevels(t)){let t=_(i.time+a*o,n);if(Math.abs(e.x-t)<=r)return!0}return!1}},$o=40,es=2,ts=.1,ns=100,rs=0x38d7ea4c68000,is=class extends H{descriptor={type:`riskReward`,name:`Long/Short Position`,requiredAnchors:2,options:{rewardRatio:{kind:`number`,label:`Reward:risk`,default:2,min:ts,max:ns,step:.1},accountSize:{kind:`number`,label:`Account size`,default:1e3,min:0,max:rs},riskMode:{kind:`choice`,label:`Risk as`,default:`percent`,choices:[{value:`percent`,label:`Percent of account`},{value:`amount`,label:`Amount`}]},risk:{kind:`number`,label:`Risk`,default:1,min:0,max:rs},qtyDecimals:{kind:`number`,label:`Quantity decimals`,default:2,min:0,max:8,step:1},showLabels:{kind:`boolean`,label:`Show labels`,default:!0}}};geometry(e){let t=e.anchors[0].price,n=e.anchors[1].price,r=this.option(e,`rewardRatio`),i=Math.abs(t-n),a=n<t,o=a?t+i*r:t-i*r,s=this.option(e,`risk`),c=this.option(e,`riskMode`)===`amount`?s:this.option(e,`accountSize`)*s/100,l=i>0?c/i:0;return{entry:t,stop:n,target:o,ratio:r,isLong:a,qty:l,riskAmount:c,rewardAmount:l*i*r}}span(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return{x:Math.min(n.x,r.x),width:Math.max(Math.abs(r.x-n.x),$o),stopX:r.x}}handles(e,t){let{target:n}=this.geometry(e),r=this.anchorToPixel(e.anchors[0],t),i=this.anchorToPixel(e.anchors[1],t),a=this.anchorToPixel({time:e.anchors[1].time,price:n},t).y;return[r,i,{x:i.x,y:a}]}render(t,n,r,i){if(n.anchors.length<2)return;let a=this.geometry(n),{x:o,width:s}=this.span(n,r),[c,l,u]=this.handles(n,r);if(t.fillStyle=`rgba(232, 80, 91, 0.18)`,t.fillRect(o,Math.min(c.y,l.y),s,Math.abs(l.y-c.y)),t.fillStyle=`rgba(31, 168, 116, 0.18)`,t.fillRect(o,Math.min(c.y,u.y),s,Math.abs(u.y-c.y)),t.strokeStyle=n.style.color,t.lineWidth=1,t.setLineDash([]),t.beginPath(),t.moveTo(o,c.y),t.lineTo(o+s,c.y),t.stroke(),this.option(n,`showLabels`)){let i=(0,e.autoPricePrecision)(Math.min(a.stop,a.target),Math.max(a.stop,a.target)),s=this.option(n,`qtyDecimals`),d=e=>(a.entry===0?0:(e-a.entry)/a.entry*100).toFixed(2),f=Number(a.ratio.toFixed(2));t.font=`11px sans-serif`,t.textAlign=`left`,t.textBaseline=`middle`;let p=e=>e+(e<c.y?8:-8);t.fillStyle=`#1fa874`;let m=e=>r.formatPrice?.(e)??e.toFixed(i);t.fillText(`Target: ${m(a.target)} (${d(a.target)}%) ${a.rewardAmount.toFixed(2)}`,o+4,p(u.y)),t.fillStyle=n.style.color,t.fillText(`${a.isLong?`Long`:`Short`} · Qty: ${a.qty.toFixed(s)} · R:R ${f}`,o+4,c.y+(a.isLong?8:-8)),t.fillStyle=`#e8505b`,t.fillText(`Stop: ${m(a.stop)} (${d(a.stop)}%) ${a.riskAmount.toFixed(2)}`,o+4,p(l.y))}i&&this.renderHandles(t,n,r)}renderHandles(e,t,n){e.fillStyle=`#FFFFFF`,e.strokeStyle=t.style.color,e.lineWidth=1;for(let r of this.handles(t,n))e.fillRect(r.x-4,r.y-4,8,8),e.strokeRect(r.x-4,r.y-4,8,8)}hitTestAnchor(e,t,n,r){return t.anchors.length<2?super.hitTestAnchor(e,t,n,r):this.handles(t,n).findIndex(t=>Math.hypot(e.x-t.x,e.y-t.y)<=r)}moveHandle(e,t,n){if(t!==es){let r=e.anchors.map((e,r)=>r===t?{...n}:{...e});return{...e,anchors:r}}let{entry:r,isLong:i}=this.geometry(e),a=Math.abs(r-e.anchors[1].price),o=i?n.price-r:r-n.price,s=a>0?Math.min(ns,Math.max(ts,o/a)):ts;return{...e,options:{...e.options,rewardRatio:Math.round(s*100)/100}}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{x:i,width:a}=this.span(t,n),o=this.handles(t,n).map(e=>e.y);return e.x>=i-r&&e.x<=i+a+r&&e.y>=Math.min(...o)-r&&e.y<=Math.max(...o)+r}},as=class extends H{descriptor={type:`crossLine`,name:`Cross Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(a.x,i.y),e.lineTo(a.x+a.width,i.y),e.moveTo(i.x,a.y),e.lineTo(i.x,a.y+a.height),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return Math.abs(e.y-i.y)<=r||Math.abs(e.x-i.x)<=r}},os=28,ss=48;function cs(e,t){return Math.atan2(e.y-t.y,t.x-e.x)*180/Math.PI}var ls=class extends H{descriptor={type:`trendAngle`,name:`Trend Angle`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=cs(i,a),s=a.x>=i.x?1:-1;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x+s*ss,i.y),e.stroke(),e.setLineDash([]);let c=Math.atan2(a.y-i.y,a.x-i.x),l=s>0?0:Math.PI;s<0&&c<0&&(c+=2*Math.PI),e.beginPath(),e.arc(i.x,i.y,os,Math.min(l,c),Math.max(l,c)),e.stroke(),e.font=`11px sans-serif`,e.fillStyle=t.style.color,e.textAlign=s>0?`left`:`right`,e.textBaseline=`middle`,e.fillText(`${o.toFixed(1)}°`,i.x+s*(os+6),i.y+(o>=0?-8:8)),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}};function us(e,t,n){let r=ao(e,0,1,t),i=io(e,0,1,t);return[to(e.anchors[0].price,e.anchors[1].price,t),r?`${i} bars, ${r}`:`${i} bars`,`${n.toFixed(1)}°`]}var ds=class extends H{descriptor={type:`infoLine`,name:`Info Line`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=us(t,n,cs(i,a)),s=a.y<=i.y;oo(e,o,a.x+(a.x>=i.x?8:-8),a.y+(s?-6:6),a.x>=i.x?`left`:`right`,s),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},fs=[0,.236,.382,.5,.618,.786,1,1.618];function ps(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=r*r+i*i;if(a===0)return{x:n.x-e.x,y:n.y-e.y};let o=((n.x-e.x)*r+(n.y-e.y)*i)/a;return{x:n.x-(e.x+o*r),y:n.y-(e.y+o*i)}}function ms(e,t,n,r){let i=ps(e,t,n);return[{x:e.x+i.x*r,y:e.y+i.y*r},{x:t.x+i.x*r,y:t.y+i.y*r}]}var hs=class extends H{descriptor={type:`fibChannel`,name:`Fibonacci Channel`,requiredAnchors:3,options:{levels:{kind:`levels`,label:`Levels`,default:Va(fs,[2.618,3.618,4.236])}}};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(t.anchors.length<3){this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);return}let o=this.anchorToPixel(t.anchors[2],n);e.font=`11px sans-serif`,e.textAlign=`right`,e.textBaseline=`middle`;for(let{value:n,color:r}of this.visibleLevels(t)){let[s,c]=ms(i,a,o,n);this.applyLineStyle(e,{...t.style,color:r??t.style.color}),e.globalAlpha=n===0||n===1?1:.6,e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(c.x,c.y),e.stroke(),e.fillStyle=r??t.style.color;let l=s.x<=c.x?s:c;e.fillText(String(n),l.x-4,l.y)}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n);for(let{value:n}of this.visibleLevels(t)){let[t,s]=ms(i,a,o,n);if(this.distanceToLine(e,t,s)<=r)return!0}return!1}},gs=[.25,.382,.5,.618,.75];function _s(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.hypot(r,i);if(a===0)return null;let o=(n.chartRect.width+n.chartRect.height)*2;return{x:e.x+r/a*o,y:e.y+i/a*o}}function vs(e,t,n=gs){let r=[{level:1,kind:`diagonal`,point:t}];for(let i of n)r.push({level:i,kind:`price`,point:{x:t.x,y:e.y+(t.y-e.y)*i}}),r.push({level:i,kind:`time`,point:{x:e.x+(t.x-e.x)*i,y:t.y}});return r}var ys=class extends H{descriptor={type:`fibSpeedResistanceFan`,name:`Fib Speed Resistance Fan`,requiredAnchors:2,options:{levels:{kind:`levels`,label:`Levels`,default:Va(gs,[.236,.786])}}};targets(e,t,n){return vs(t,n,this.visibleLevels(e).map(e=>e.value))}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);e.strokeStyle=t.style.color,e.lineWidth=1,e.globalAlpha=.25,e.strokeRect(Math.min(i.x,a.x),Math.min(i.y,a.y),Math.abs(a.x-i.x),Math.abs(a.y-i.y)),e.globalAlpha=1,e.font=`11px sans-serif`,e.textBaseline=`middle`;for(let r of this.targets(t,i,a)){let o=_s(i,r.point,n);o&&(this.applyLineStyle(e,t.style),e.globalAlpha=r.kind===`diagonal`?1:.65,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o.x,o.y),e.stroke(),r.kind===`price`&&(e.fillStyle=t.style.color,e.textAlign=a.x>=i.x?`left`:`right`,e.fillText(String(r.level),r.point.x+(a.x>=i.x?4:-4),r.point.y)))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);for(let o of this.targets(t,i,a)){let t=_s(i,o.point,n);if(t&&this.distanceToLine(e,i,t)<=r)return!0}return!1}},bs=class extends H{ratioLinks=[];triangles=[];render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));t.anchors.length>=this.descriptor.requiredAnchors&&this.renderTriangles(e,t,i),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++)e.lineTo(i[t].x,i[t].y);e.stroke(),this.resetLineStyle(e),this.renderRatioLinks(e,t,i),this.renderPointLabels(e,t,i),this.renderExtras(e,t,i,n),r&&this.renderAnchorHandles(e,t,n)}renderExtras(e,t,n,r){}renderTriangles(e,t,n){e.fillStyle=t.style.fillColor??t.style.color,e.globalAlpha=t.style.fillColor?1:.12;for(let[t,r,i]of this.triangles)e.beginPath(),e.moveTo(n[t].x,n[t].y),e.lineTo(n[r].x,n[r].y),e.lineTo(n[i].x,n[i].y),e.closePath(),e.fill();e.globalAlpha=1}renderRatioLinks(e,t,n){e.font=`11px sans-serif`,e.textAlign=`center`,e.textBaseline=`middle`;for(let r of this.ratioLinks){if(Math.max(r.from,r.to,...r.num,...r.den)>=n.length)continue;let i=n[r.from],a=n[r.to];e.strokeStyle=t.style.color,e.lineWidth=1,e.globalAlpha=.7,e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),e.setLineDash([]),e.globalAlpha=1,e.fillStyle=t.style.color,e.fillText(so(t,r.num,r.den),(i.x+a.x)/2,(i.y+a.y)/2)}}renderPointLabels(e,t,n){e.font=`bold 12px sans-serif`,e.fillStyle=t.style.color,e.textAlign=`center`;for(let t=0;t<n.length&&t<this.pointLabels.length;t++){let r=n[t-1]??n[t+1],i=n[t+1]??n[t-1],a=!r||!i?!0:n[t].y<=Math.min(r.y,i.y);e.textBaseline=a?`bottom`:`top`,e.fillText(this.pointLabels[t],n[t].x,n[t].y+(a?-6:6))}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<i.length-1;t++)if(this.distanceToLine(e,i[t],i[t+1])<=r)return!0;return!1}},xs=class extends bs{descriptor={type:`xabcdPattern`,name:`XABCD Pattern`,requiredAnchors:5,fill:!0};pointLabels=[`X`,`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:1,to:3,num:[2,3],den:[1,2]},{from:2,to:4,num:[3,4],den:[2,3]},{from:0,to:4,num:[1,4],den:[0,1]}];triangles=[[0,1,2],[2,3,4]]},Ss=class extends bs{descriptor={type:`abcdPattern`,name:`ABCD Pattern`,requiredAnchors:4,fill:!0};pointLabels=[`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:1,to:3,num:[2,3],den:[1,2]}]},Cs=class extends bs{descriptor={type:`headAndShoulders`,name:`Head and Shoulders`,requiredAnchors:7,fill:!0};pointLabels=[``,`Left Shoulder`,``,`Head`,``,`Right Shoulder`,``];triangles=[[0,1,2],[2,3,4],[4,5,6]];renderExtras(e,t,n){if(n.length<5)return;let r=n[2],i=n[4],a=n[0],o=n[n.length-1],s=i.x===r.x?0:(i.y-r.y)/(i.x-r.x),c=e=>r.y+s*(e-r.x);e.strokeStyle=t.style.color,e.lineWidth=Math.max(1,t.style.lineWidth),e.setLineDash([6,4]),e.beginPath(),e.moveTo(a.x,c(a.x)),e.lineTo(o.x,c(o.x)),e.stroke(),e.setLineDash([])}},ws=class extends bs{descriptor={type:`threeDrives`,name:`Three Drives Pattern`,requiredAnchors:6};pointLabels=[``,`1`,`A`,`2`,`B`,`3`];ratioLinks=[{from:1,to:3,num:[2,3],den:[1,2]},{from:3,to:5,num:[4,5],den:[3,4]}]},Ts=class extends bs{descriptor={type:`cypherPattern`,name:`Cypher Pattern`,requiredAnchors:5,fill:!0};pointLabels=[`X`,`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:0,to:3,num:[2,3],den:[0,1]},{from:0,to:4,num:[3,4],den:[0,3]}];triangles=[[0,1,2],[2,3,4]]},Es=class extends H{descriptor={type:`circle`,name:`Circle`,requiredAnchors:2,fill:!0};geometry(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return{c:n,r:Math.hypot(r.x-n.x,r.y-n.y)}}render(e,t,n,r){if(t.anchors.length<2)return;let{c:i,r:a}=this.geometry(t,n);e.beginPath(),e.arc(i.x,i.y,a,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=t.style.fillColor,e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{c:i,r:a}=this.geometry(t,n),o=Math.hypot(e.x-i.x,e.y-i.y);return t.style.fillColor?o<=a+r:Math.abs(o-a)<=r}},Ds=`rgba(76, 141, 255, 0.12)`,Os=`rgba(232, 80, 91, 0.12)`;function ks(e,t){let n=t.data;if(!n||n.length===0)return null;let r=Math.round(g(e.anchors[0].time,t)),i=Math.round(g(e.anchors[1].time,t)),a=Math.max(0,Math.min(r,i)),o=Math.min(n.length-1,Math.max(r,i)),s=0;for(let e=a;e<=o;e++)s+=n[e].volume??0;return s}function As(e){return e>=1e9?`${(e/1e9).toFixed(2)}B`:e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(2)}K`:e.toFixed(0)}function js(e,t){let n=ao(e,0,1,t),r=io(e,0,1,t),i=[to(e.anchors[0].price,e.anchors[1].price,t),n?`${r} bars, ${n}`:`${r} bars`],a=ks(e,t);return a!==null&&i.push(`Vol ${As(a)}`),i}var Ms=class extends H{descriptor={type:`dateAndPriceRange`,name:`Date and Price Range`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y),u=t.anchors[1].price>=t.anchors[0].price;e.fillStyle=u?Ds:Os,e.fillRect(o,s,c,l),this.applyLineStyle(e,t.style);let d=o+c/2,f=s+l/2;e.beginPath(),e.moveTo(d,i.y),e.lineTo(d,a.y),e.moveTo(i.x,f),e.lineTo(a.x,f),e.stroke(),this.resetLineStyle(e),oo(e,js(t,n),d,u?s-6:s+l+6,`center`,u),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return e.x>=Math.min(i.x,a.x)-r&&e.x<=Math.max(i.x,a.x)+r&&e.y>=Math.min(i.y,a.y)-r&&e.y<=Math.max(i.y,a.y)+r}},Ns=400,Ps=2;function Fs(e,t,n){let r=Math.abs(t.x-e.x);if(r<Ps)return[e.x];let i=n.chartRect.x+n.chartRect.width,a=[],o=Math.min(e.x,t.x);for(let e=o;e<=i&&a.length<Ns;e+=r)a.push(e);return a}var Is=class extends H{descriptor={type:`cyclicLines`,name:`Cyclic Lines`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n;this.applyLineStyle(e,t.style),e.beginPath();for(let t of Fs(i,a,n))t<o.x||(e.moveTo(t,o.y),e.lineTo(t,o.y+o.height));e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:Fs(this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n),n).some(t=>Math.abs(e.x-t)<=r)}},Ls=14,Rs=18,zs=6,Bs=20,Vs=class extends H{descriptor={type:`priceLabel`,name:`Price Label`,requiredAnchors:1,text:!0};text(e,t){return e.style.text||G(e.anchors[0].price,e.anchors[0].price,t)}box(e,t,n,r){let i=t.style.fontSize??12,a=this.text(t,r),o=e?e.measureText(a).width:a.length*i*.6;return{x:n.x+Ls,y:n.y-Rs-Bs/2,w:o+zs*2,h:Bs}}render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n);e.font=`${t.style.fontSize??12}px sans-serif`;let a=this.box(e,t,i,n);e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y+a.h),e.stroke(),e.fillStyle=t.style.color,e.fillRect(a.x,a.y,a.w,a.h),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(this.text(t,n),a.x+zs,a.y+a.h/2),e.beginPath(),e.arc(i.x,i.y,3,0,Math.PI*2),e.fillStyle=t.style.color,e.fill(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);if(Math.hypot(e.x-i.x,e.y-i.y)<=r)return!0;let a=this.box(null,t,i,n);return e.x>=a.x-r&&e.x<=a.x+a.w+r&&e.y>=a.y-r&&e.y<=a.y+a.h+r}},Hs=8,Us=6,Ws=1.3,Gs=12;function Ks(e){return`${e}px sans-serif`}function qs(e,t,n){let r=[];for(let i of t.split(`
|
|
7
|
+
`)){let t=``;for(let a of i.split(/\s+/).filter(Boolean)){let i=t?`${t} ${a}`:a;if(e(i)<=n){t=i;continue}t&&r.push(t),t=e(a)<=n?a:Js(e,a,n)}if(r.push(t),r.length>=Gs)break}return r.length>Gs&&(r.length=Gs),r}function Js(e,t,n){if(e(t)<=n)return t;let r=1,i=t.length-1;for(;r<i;){let a=Math.ceil((r+i)/2);e(`${t.slice(0,a)}…`)<=n?r=a:i=a-1}return`${t.slice(0,r)}…`}var Ys=200,Xs=new Map;function Zs(e,t,n,r){let i=`${r}|${n}|${t}`,a=Xs.get(i);if(a)return a;Xs.size>=Ys&&Xs.clear();let o=qs(e,t,n);return Xs.set(i,o),o}function Qs(e,t,n,r,i){return{x:n,y:r,width:Math.max(0,...t.map(e))+Hs*2,height:t.length*i*Ws+Us*2}}function $s(e,t,n,r,i){e.font=Ks(i.fontSize);let a=t=>e.measureText(t).width,o=Zs(a,t,i.maxWidth,i.fontSize),s=Qs(a,o,n,r,i.fontSize);return i.fill&&(e.fillStyle=i.fill,e.fillRect(s.x,s.y,s.width,s.height)),i.stroke&&(e.strokeStyle=i.stroke,e.lineWidth=1,e.strokeRect(s.x+.5,s.y+.5,s.width-1,s.height-1)),e.fillStyle=i.color,e.textAlign=`left`,e.textBaseline=`top`,o.forEach((t,a)=>e.fillText(t,n+Hs,r+Us+a*i.fontSize*Ws)),s}function ec(e,t,n=0){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var tc=1e3,nc=class{boxes=new Map;set(e,t){this.boxes.size>=tc&&!this.boxes.has(e)&&this.boxes.clear(),this.boxes.set(e,t)}get(e){return this.boxes.get(e)}},rc=240,ic=13;function ac(e){return e.style.fontSize||ic}function oc(e){return{fontSize:ac(e),color:e.style.color,fill:e.style.fillColor??`rgba(76, 141, 255, 0.1)`,stroke:e.style.color,maxWidth:rc}}function sc(e,t,n,r){let i=ac(e),a=Math.max(...t.split(`
|
|
8
|
+
`).map(e=>e.length));return{x:n,y:r,width:Math.min(rc,a*i*.6)+16,height:i*1.3+12}}var K=7,cc=16,lc=class extends H{descriptor={type:`note`,name:`Note`,requiredAnchors:1,text:!0,fill:!0,options:{showText:{kind:`boolean`,label:`Show text`,default:!0}}};boxes=new nc;render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n);if(this.renderPin(e,t,i),this.option(t,`showText`)){let n=$s(e,Ho(t,`Note`),i.x+K+6,i.y-cc-K,oc(t));this.boxes.set(t.id,n)}r&&this.renderAnchorHandles(e,t,n)}renderPin(e,t,n){let r=n.y-cc;e.fillStyle=t.style.color,e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x-K*.7,r+K*.5),e.arc(n.x,r,K,Math.PI*.8,Math.PI*.2),e.closePath(),e.fill(),e.fillStyle=`#ffffff`,e.beginPath(),e.arc(n.x,r,K*.4,0,Math.PI*2),e.fill()}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return ec(e,{x:i.x-K,y:i.y-cc-K,width:K*2,height:cc+K},r)?!0:this.option(t,`showText`)?ec(e,this.boxes.get(t.id)??sc(t,Ho(t,`Note`),i.x+K+6,i.y-cc-K),r):!1}},uc=class extends H{descriptor={type:`callout`,name:`Callout`,requiredAnchors:2,text:!0,fill:!0};boxes=new nc;render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n);if(e.fillStyle=t.style.color,e.beginPath(),e.arc(i.x,i.y,3,0,Math.PI*2),e.fill(),t.anchors.length<2)return;let a=this.anchorToPixel(t.anchors[1],n),o=$s(e,Ho(t,`Callout`),a.x,a.y,oc(t));this.boxes.set(t.id,o);let s=dc(o,i);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.boxes.get(t.id)??sc(t,Ho(t,`Callout`),a.x,a.y);return ec(e,o,r)||this.distanceToLine(e,dc(o,i),i)<=r}};function dc(e,t){let n=e.x+e.width/2,r=e.y+e.height/2,i=t.x-n,a=t.y-r;return Math.abs(i)*e.height>Math.abs(a)*e.width?{x:i>0?e.x+e.width:e.x,y:r}:{x:n,y:a>0?e.y+e.height:e.y}}var fc=24,pc=18,mc=10,hc=class extends H{descriptor={type:`flag`,name:`Flag Mark`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=i.y-fc;e.strokeStyle=t.style.color,e.lineWidth=1.5,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x,a),e.stroke(),e.fillStyle=t.style.color,e.beginPath(),e.moveTo(i.x,a),e.lineTo(i.x+pc,a),e.lineTo(i.x+pc-5,a+mc/2),e.lineTo(i.x+pc,a+mc),e.lineTo(i.x,a+mc),e.closePath(),e.fill(),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return ec(e,{x:i.x,y:i.y-fc,width:pc,height:fc},r)}},gc={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function _c(e,t,n){let r=n*.5,i=n*.4,a=n*.17,o=(n,r)=>({x:e.x-t.x*n-t.y*r,y:e.y-t.y*n+t.x*r});return[o(0,0),o(r,i),o(r,a),o(n,a),o(n,-a),o(r,-a),o(r,-i)]}var vc=class extends H{descriptor={type:`arrowMark`,name:`Arrow Mark`,requiredAnchors:1,text:!0,options:{direction:{kind:`choice`,label:`Direction`,default:`up`,choices:[{value:`up`,label:`Up`},{value:`down`,label:`Down`},{value:`left`,label:`Left`},{value:`right`,label:`Right`}]},size:{kind:`number`,label:`Size`,default:22,min:10,max:80,step:2}}};outline(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=gc[this.option(e,`direction`)]??gc.up,i=this.option(e,`size`);return{points:_c(n,r,i),dir:r,tail:{x:n.x-r.x*i,y:n.y-r.y*i}}}render(e,t,n,r){if(t.anchors.length<1)return;let{points:i,dir:a,tail:o}=this.outline(t,n);e.fillStyle=t.style.color,e.beginPath(),i.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath(),e.fill();let s=t.style.text;s&&(e.font=`${t.style.fontSize||12}px sans-serif`,e.textAlign=a.x===0?`center`:a.x>0?`right`:`left`,e.textBaseline=a.y===0?`middle`:a.y<0?`top`:`bottom`,e.fillText(s,o.x-a.x*4,o.y-a.y*4)),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let{points:i}=this.outline(t,n),a=i.map(e=>e.x),o=i.map(e=>e.y);return ec(e,{x:Math.min(...a),y:Math.min(...o),width:Math.max(...a)-Math.min(...a),height:Math.max(...o)-Math.min(...o)},r)}},yc=[`star`,`heart`,`check`,`cross`,`circle`,`triangleUp`,`triangleDown`,`bolt`];function bc(e,t,n,r){let i=r/2;switch(e.beginPath(),t){case`star`:for(let t=0;t<10;t++){let r=-Math.PI/2+t*Math.PI/5,a=t%2==0?i:i*.42,o=n.x+Math.cos(r)*a,s=n.y+Math.sin(r)*a;t===0?e.moveTo(o,s):e.lineTo(o,s)}return e.closePath(),!1;case`heart`:return e.moveTo(n.x,n.y+i*.85),e.bezierCurveTo(n.x-i*1.3,n.y-i*.1,n.x-i*.6,n.y-i*1.1,n.x,n.y-i*.35),e.bezierCurveTo(n.x+i*.6,n.y-i*1.1,n.x+i*1.3,n.y-i*.1,n.x,n.y+i*.85),e.closePath(),!1;case`check`:return e.moveTo(n.x-i*.8,n.y),e.lineTo(n.x-i*.2,n.y+i*.6),e.lineTo(n.x+i*.85,n.y-i*.65),!0;case`cross`:return e.moveTo(n.x-i*.7,n.y-i*.7),e.lineTo(n.x+i*.7,n.y+i*.7),e.moveTo(n.x+i*.7,n.y-i*.7),e.lineTo(n.x-i*.7,n.y+i*.7),!0;case`circle`:return e.arc(n.x,n.y,i*.8,0,Math.PI*2),!1;case`triangleUp`:return e.moveTo(n.x,n.y-i*.85),e.lineTo(n.x+i*.9,n.y+i*.7),e.lineTo(n.x-i*.9,n.y+i*.7),e.closePath(),!1;case`triangleDown`:return e.moveTo(n.x,n.y+i*.85),e.lineTo(n.x+i*.9,n.y-i*.7),e.lineTo(n.x-i*.9,n.y-i*.7),e.closePath(),!1;case`bolt`:return e.moveTo(n.x+i*.15,n.y-i),e.lineTo(n.x-i*.6,n.y+i*.1),e.lineTo(n.x-i*.05,n.y+i*.1),e.lineTo(n.x-i*.15,n.y+i),e.lineTo(n.x+i*.6,n.y-i*.1),e.lineTo(n.x+i*.05,n.y-i*.1),e.closePath(),!1}}var xc=class extends H{descriptor={type:`icon`,name:`Icon`,requiredAnchors:1,options:{glyph:{kind:`choice`,label:`Icon`,default:`star`,choices:[{value:`star`,label:`Star`},{value:`heart`,label:`Heart`},{value:`check`,label:`Check`},{value:`cross`,label:`Cross`},{value:`circle`,label:`Circle`},{value:`triangleUp`,label:`Triangle up`},{value:`triangleDown`,label:`Triangle down`},{value:`bolt`,label:`Bolt`}]},size:{kind:`number`,label:`Size`,default:22,min:10,max:80,step:2}}};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.option(t,`size`),o=this.option(t,`glyph`);bc(e,yc.includes(o)?o:`star`,i,a)?(e.strokeStyle=t.style.color,e.lineWidth=Math.max(2,a/8),e.lineCap=`round`,e.lineJoin=`round`,e.stroke(),e.lineCap=`butt`,e.lineJoin=`miter`):(e.fillStyle=t.style.color,e.fill()),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.option(t,`size`)/2;return Math.abs(e.x-i.x)<=a+r&&Math.abs(e.y-i.y)<=a+r}},Sc=48,Cc=10;function wc(e,t){if(e.beginPath(),e.moveTo(t[0].x,t[0].y),t.length===2)e.lineTo(t[1].x,t[1].y);else{for(let n=1;n<t.length-1;n++){let r=(t[n].x+t[n+1].x)/2,i=(t[n].y+t[n+1].y)/2;e.quadraticCurveTo(t[n].x,t[n].y,r,i)}let n=t[t.length-1];e.lineTo(n.x,n.y)}e.stroke()}function Tc(e,t,n=!1){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),n&&e.closePath()}function Ec(e,t,n,r=Cc){let i=Math.atan2(n.y-t.y,n.x-t.x);e.beginPath(),e.moveTo(n.x-r*Math.cos(i-Math.PI/6),n.y-r*Math.sin(i-Math.PI/6)),e.lineTo(n.x,n.y),e.lineTo(n.x-r*Math.cos(i+Math.PI/6),n.y-r*Math.sin(i+Math.PI/6)),e.stroke()}function Dc(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let a=t[r],o=t[i];a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}var Oc=new WeakMap;function kc(e){let t=Oc.get(e);if(!t){t={t0:1/0,t1:-1/0,p0:1/0,p1:-1/0};for(let n of e)n.time<t.t0&&(t.t0=n.time),n.time>t.t1&&(t.t1=n.time),n.price<t.p0&&(t.p0=n.price),n.price>t.p1&&(t.p1=n.price);Oc.set(e,t)}return t}var Ac=class extends H{descriptor={type:`brush`,name:`Brush`,requiredAnchors:2,creation:`freehand`};stroke(e){return{width:e.style.lineWidth,alpha:1}}render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n)),{width:a,alpha:o}=this.stroke(t);this.applyLineStyle(e,t.style),e.lineWidth=a,e.lineCap=`round`,e.lineJoin=`round`,e.globalAlpha=o,wc(e,i),e.globalAlpha=1,e.lineCap=`butt`,e.lineJoin=`miter`,this.resetLineStyle(e),r&&this.renderBounds(e,t,n)}renderBounds(e,t,n){let r=this.screenBox(t,n),i=this.stroke(t).width/2+3;e.strokeStyle=t.style.color,e.lineWidth=1,e.setLineDash([3,3]),e.strokeRect(r.x0-i,r.y0-i,r.x1-r.x0+i*2,r.y1-r.y0+i*2),e.setLineDash([])}screenBox(e,t){let{t0:n,t1:r,p0:i,p1:a}=kc(e.anchors),s=o(i,t),c=o(a,t);return{x0:_(n,t),x1:_(r,t),y0:Math.min(s,c),y1:Math.max(s,c)}}hitTestAnchor(){return-1}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=r+this.stroke(t).width/2,a=this.screenBox(t,n);return e.x<a.x0-i||e.x>a.x1+i||e.y<a.y0-i||e.y>a.y1+i?!1:V(e,t.anchors.map(e=>this.anchorToPixel(e,n)),i)}},jc=class extends Ac{descriptor={type:`highlighter`,name:`Highlighter`,requiredAnchors:2,creation:`freehand`};stroke(e){return{width:Math.max(10,e.style.lineWidth*8),alpha:.3}}},Mc=class extends H{descriptor={type:`path`,name:`Path`,requiredAnchors:2,creation:`path`,options:{arrowEnd:{kind:`boolean`,label:`Arrow at the end`,default:!0}}};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));this.applyLineStyle(e,t.style),e.lineJoin=`round`,Tc(e,i),e.stroke(),this.resetLineStyle(e),this.option(t,`arrowEnd`)&&Ec(e,i[i.length-2],i[i.length-1]),e.lineJoin=`miter`,r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:V(e,t.anchors.map(e=>this.anchorToPixel(e,n)),r)}},Nc=class extends H{descriptor={type:`polyline`,name:`Polyline`,requiredAnchors:3,creation:`path`,fill:!0};render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n)),a=i.length>=3;Tc(e,i,a),a&&(e.fillStyle=t.style.fillColor??`rgba(76, 141, 255, 0.1)`,e.fill()),this.applyLineStyle(e,t.style),e.lineJoin=`round`,e.stroke(),e.lineJoin=`miter`,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));return V(e,i,r,!0)||i.length>=3&&Dc(e,i)}};function Pc(e,t,n,r=Sc){let i={x:2*t.x-(e.x+n.x)/2,y:2*t.y-(e.y+n.y)/2},a=[];for(let t=0;t<=r;t++){let o=t/r,s=1-o;a.push({x:s*s*e.x+2*s*o*i.x+o*o*n.x,y:s*s*e.y+2*s*o*i.y+o*o*n.y})}return a}function Fc(e,t,n,r=Sc){let i=2*(e.x*(t.y-n.y)+t.x*(n.y-e.y)+n.x*(e.y-t.y));if(Math.abs(i)<1e-9)return[e,n];let a=e.x*e.x+e.y*e.y,o=t.x*t.x+t.y*t.y,s=n.x*n.x+n.y*n.y,c=(a*(t.y-n.y)+o*(n.y-e.y)+s*(e.y-t.y))/i,l=(a*(n.x-t.x)+o*(e.x-n.x)+s*(t.x-e.x))/i,u=Math.hypot(e.x-c,e.y-l),d=Math.atan2(e.y-l,e.x-c),f=Math.atan2(t.y-l,t.x-c),p=Math.atan2(n.y-l,n.x-c),m=(e,t)=>((t-e)%(2*Math.PI)+2*Math.PI)%(2*Math.PI),h=m(d,p),g=m(d,f)<=h?h:h-2*Math.PI,_=[];for(let e=0;e<=r;e++){let t=d+g*e/r;_.push({x:c+u*Math.cos(t),y:l+u*Math.sin(t)})}return _}var Ic=class extends H{descriptor={type:`curve`,name:`Curve`,requiredAnchors:3};shape(e,t,n){return Pc(e,t,n)}points(e,t){let n=e.anchors.map(e=>this.anchorToPixel(e,t));return n.length<3?n:this.shape(n[0],n[2],n[1])}render(e,t,n,r){t.anchors.length<2||(this.applyLineStyle(e,t.style),Tc(e,this.points(t,n)),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n))}hitTest(e,t,n,r){return t.anchors.length<2?!1:V(e,this.points(t,n),r)}},Lc=class extends Ic{descriptor={type:`arc`,name:`Arc`,requiredAnchors:3};shape(e,t,n){return Fc(e,t,n)}},Rc=(1+Math.sqrt(5))/2,zc=64,Bc=`11px sans-serif`,Vc=34,Hc=12;function Uc(e,t=[]){return{levels:{kind:`levels`,label:`Levels`,default:Va(e,t)},showLevels:{kind:`boolean`,label:`Show levels`,default:!0}}}var Wc=[.236,.382,.5,.618,.786,1];function Gc(e){return String(Number(e.toFixed(3)))}function Kc(e,t,n,r,i,a=zc){let o=[];for(let s=0;s<=a;s++){let c=r+i*s/a;o.push({x:e.x+t*Math.cos(c),y:e.y+n*Math.sin(c)})}return o}function qc(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke()}var Jc=class extends H{guides(e){return e.length>=2?[[e[0],e[1]]]:[]}pixels(e,t){return e.anchors.map(e=>this.anchorToPixel(e,t))}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.pixels(t,n);this.applyLineStyle(e,t.style),e.globalAlpha=.6,e.setLineDash([4,4]);for(let[t,n]of this.guides(i))qc(e,[t,n]);e.globalAlpha=1,this.applyLineStyle(e,t.style);let a=this.option(t,`showLevels`);e.font=Bc,e.textAlign=`left`,e.textBaseline=`bottom`;let o=this.shapes(i,this.visibleLevels(t),n,t);for(let n of o)e.strokeStyle=n.level.color??t.style.color,qc(e,n.points);a&&this.renderLabels(e,t,o),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}renderLabels(e,t,n){let r=[];for(let{level:i,label:a}of[...n].reverse())r.some(e=>Math.abs(e.x-a.x)<Vc&&Math.abs(e.y-a.y)<Hc)||(r.push(a),e.fillStyle=i.color??t.style.color,e.fillText(Gc(i.value),a.x+3,a.y-2))}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.pixels(t,n);return this.guides(i).some(([t,n])=>B(e,t,n)<=r)?!0:this.shapes(i,this.visibleLevels(t),n,t).some(t=>V(e,t.points,r))}},Yc=class extends Jc{descriptor={type:`fibCircles`,name:`Fib Circles`,requiredAnchors:2,options:Uc([...Wc,1.618,2.618],[3.618,4.236])};shapes(e,t){let[n,r]=e,i=Math.hypot(r.x-n.x,r.y-n.y);return t.map(e=>{let t=i*e.value;return{level:e,points:Kc(n,t,t,0,Math.PI*2),label:{x:n.x+t,y:n.y}}})}},Xc=class extends Jc{descriptor={type:`fibArcs`,name:`Fib Speed Resistance Arcs`,requiredAnchors:2,options:{...Uc(Wc),fullCircles:{kind:`boolean`,label:`Full circles`,default:!1}}};shapes(e,t,n,r){let[i,a]=e,o=Math.hypot(a.x-i.x,a.y-i.y),s=Math.atan2(a.y-i.y,a.x-i.x),c=this.option(r,`fullCircles`);return t.map(e=>{let t=o*e.value;return{level:e,points:c?Kc(i,t,t,0,Math.PI*2):Kc(i,t,t,s-Math.PI/2,Math.PI),label:{x:i.x+t*Math.cos(s),y:i.y+t*Math.sin(s)}}})}},Zc=class extends Jc{descriptor={type:`fibWedge`,name:`Fib Wedge`,requiredAnchors:3,options:Uc(Wc)};guides(e){return e.slice(1).map(t=>[e[0],t])}shapes(e,t){if(e.length<3)return[];let[n,r,i]=e,a=Math.hypot(r.x-n.x,r.y-n.y),o=Math.atan2(r.y-n.y,r.x-n.x),s=Math.atan2(i.y-n.y,i.x-n.x)-o;return s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI),t.map(e=>{let t=a*e.value;return{level:e,points:Kc(n,t,t,o,s,32),label:{x:n.x+t*Math.cos(o),y:n.y+t*Math.sin(o)}}})}},Qc=class extends Jc{descriptor={type:`pitchfan`,name:`Pitchfan`,requiredAnchors:3,options:Uc([0,.25,.382,.5,.618,.75,1])};guides(e){return e.length>=3?[[e[1],e[2]]]:[[e[0],e[1]]]}shapes(e,t,n){if(e.length<3)return[];let[r,i,a]=e,o=Math.hypot(n.chartRect.width,n.chartRect.height)*2;return t.map(e=>{let t={x:i.x+(a.x-i.x)*e.value,y:i.y+(a.y-i.y)*e.value},n=Math.hypot(t.x-r.x,t.y-r.y)||1;return{level:e,points:[r,{x:r.x+(t.x-r.x)/n*o,y:r.y+(t.y-r.y)/n*o}],label:t}})}},$c=class extends H{descriptor={type:`fibSpiral`,name:`Fib Spiral`,requiredAnchors:2,options:{clockwise:{kind:`boolean`,label:`Clockwise`,default:!1}}};points(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i=Math.hypot(r.x-n.x,r.y-n.y);if(i===0)return[];let a=Math.atan2(r.y-n.y,r.x-n.x),o=this.option(e,`clockwise`)?1:-1,s=Math.hypot(t.chartRect.width,t.chartRect.height)*1.5,c=Math.PI/2,l=Math.log(s/i)/Math.log(Rc),u=Math.log(i/2)/Math.log(Rc),d=-Math.max(0,u)*c,f=Math.max(1,l)*c,p=[],m=Math.min(720,Math.ceil((f-d)/c*24));for(let e=0;e<=m;e++){let t=d+(f-d)*e/m,r=i*Rc**+(t/c);p.push({x:n.x+r*Math.cos(a+o*t),y:n.y+r*Math.sin(a+o*t)})}return p}render(e,t,n,r){t.anchors.length<2||(this.applyLineStyle(e,t.style),qc(e,this.points(t,n)),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n))}hitTest(e,t,n,r){return t.anchors.length<2?!1:V(e,this.points(t,n),r)}},el=class extends H{descriptor={type:`gannSquare`,name:`Gann Square`,requiredAnchors:2,options:{...Uc([.25,.382,.5,.618,.75]),arcs:{kind:`boolean`,label:`Arcs`,default:!0}}};lines(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i=r.x-n.x,a=r.y-n.y,o=[[n,{x:r.x,y:n.y}],[{x:r.x,y:n.y},r],[r,{x:n.x,y:r.y}],[{x:n.x,y:r.y},n],[n,r],[{x:r.x,y:n.y},{x:n.x,y:r.y}]],s=this.visibleLevels(e);for(let{value:e}of s)o.push([{x:n.x+i*e,y:n.y},{x:n.x+i*e,y:r.y}]),o.push([{x:n.x,y:n.y+a*e},{x:r.x,y:n.y+a*e}]);return{grid:o,arcs:this.option(e,`arcs`)?[...s.map(e=>e.value),1].map(e=>{let t=Math.atan2(0,Math.sign(i)||1),r=(Math.sign(i)||1)*(Math.sign(a)||1)*(Math.PI/2);return Kc(n,Math.abs(i)*e,Math.abs(a)*e,t,r,24)}):[]}}render(e,t,n,r){if(t.anchors.length<2)return;let{grid:i,arcs:a}=this.lines(t,n);this.applyLineStyle(e,t.style),i.forEach(([t,n],r)=>{e.globalAlpha=r<6?1:.55,qc(e,[t,n])}),e.globalAlpha=.8;for(let t of a)qc(e,t);e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{grid:i}=this.lines(t,n);return i.slice(0,6).some(([t,n])=>B(e,t,n)<=r)}},tl=400,nl=32,rl=3,il=class extends H{descriptor={type:`timeCycles`,name:`Time Cycles`,requiredAnchors:2,fill:!0};visibleCycles(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t).x-n.x,i=Math.abs(r)/2;if(i<1)return{y:n.y,r:i,centres:[]};let a=t.chartRect.x,o=a+t.chartRect.width,s=Math.max(0,Math.floor(((r>0?a:o)-n.x)/r)-1),c=[];for(let e=s;c.length<tl;e++){let t=n.x+r*(e+.5);if(t-i>o||t+i<a){if(c.length>0||(r>0?t-i>o:t+i<a))break;continue}c.push(t)}return{y:n.y,r:i,centres:c}}cycles(e,t){let{y:n,r,centres:i}=this.visibleCycles(e,t);return i.map(e=>{let t=[];for(let i=0;i<=nl;i++){let a=Math.PI+Math.PI*i/nl;t.push({x:e+r*Math.cos(a),y:n+r*Math.sin(a)})}return t})}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.cycles(t,n);e.fillStyle=t.style.fillColor??`rgba(76, 141, 255, 0.1)`,this.applyLineStyle(e,t.style);for(let t of i)e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.fill(),e.stroke();this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{y:i,r:a,centres:o}=this.visibleCycles(t,n);return e.y>i+r?!1:o.some(t=>Math.abs(Math.hypot(e.x-t,e.y-i)-a)<=r)}},al=class extends H{descriptor={type:`sineLine`,name:`Sine Line`,requiredAnchors:2};points(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i=r.x-n.x;if(Math.abs(i)<1)return[n,r];let a=(n.y+r.y)/2,o=(n.y-r.y)/2,{x:s,width:c}=t.chartRect,l=[];for(let e=s;e<=s+c;e+=rl)l.push({x:e,y:a+o*Math.cos(Math.PI*(e-n.x)/i)});return l}render(e,t,n,r){t.anchors.length<2||(this.applyLineStyle(e,t.style),e.beginPath(),this.points(t,n).forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n))}hitTest(e,t,n,r){return t.anchors.length<2?!1:V(e,this.points(t,n),r)}},ol=`#26a69a`,sl=`#ef5350`,cl=500;function ll(e,t,n){let r=n.price>=t.price,i=e.length>0?Math.max(0,Math.floor(h(t.time,e))+1):0;for(let a=i;a<e.length;a++){let i=e[a];if(!(i.time<=t.time)){if(i.time>n.time)return`missed`;if(r?i.high>=n.price:i.low<=n.price)return`reached`}}return`pending`}var ul=class extends H{descriptor={type:`forecast`,name:`Forecast`,requiredAnchors:2};bars=()=>[];setDataGetter(e){this.bars=e}render(e,t,n,r){if(t.anchors.length<2)return;let[i,a]=t.anchors,o=this.anchorToPixel(i,n),s=this.anchorToPixel(a,n),c=ll(this.bars(),i,a),l=c===`reached`?ol:c===`missed`?sl:t.style.color;this.applyLineStyle(e,{...t.style,color:l}),e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(s.x,s.y),e.stroke(),Ec(e,o,s),this.resetLineStyle(e),e.strokeStyle=l,e.beginPath(),e.arc(s.x,s.y,5,0,Math.PI*2),e.stroke();let u=ao(t,0,1,n);oo(e,[to(i.price,a.price,n),`${G(a.price,i.price,n)} · ${io(t,0,1,n)} bars${u?`, ${u}`:``}`,c===`reached`?`Target reached`:c===`missed`?`Target missed`:`Pending`],s.x,s.y+(s.y<o.y?-10:10),`center`,s.y<o.y),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:B(e,this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n))<=r}},dl=class extends H{descriptor={type:`projection`,name:`Projection`,requiredAnchors:3,fill:!0};target(e,t){let[n,r,i]=e.anchors,s=g(r.time,t)-g(n.time,t);return{x:a(g(i.time,t)+s,t),y:o(i.price+(r.price-n.price),t)}}render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));if(this.applyLineStyle(e,t.style),e.setLineDash([5,4]),e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.stroke(),t.anchors.length>=3){let r=i[2],a=this.target(t,n);e.fillStyle=t.style.fillColor??`rgba(76, 141, 255, 0.1)`,e.fillRect(Math.min(r.x,a.x),Math.min(r.y,a.y),Math.abs(a.x-r.x),Math.abs(a.y-r.y)),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(a.x,a.y),e.stroke(),Ec(e,r,a);let[o,s,c]=t.anchors,l=c.price+(s.price-o.price);oo(e,[G(l,c.price,n),to(c.price,l,n)],a.x,a.y+(a.y<r.y?-8:8),`center`,a.y<r.y)}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));return B(e,i[0],i[1])<=r?!0:i.length>=3&&B(e,i[2],this.target(t,n))<=r}},fl=class extends H{descriptor={type:`barsPattern`,name:`Bars Pattern`,requiredAnchors:3,options:{mode:{kind:`choice`,label:`Show as`,default:`bars`,choices:[{value:`bars`,label:`Bars`},{value:`line`,label:`Line`},{value:`highLow`,label:`High-low`}]},mirrored:{kind:`boolean`,label:`Mirrored`,default:!1},flipped:{kind:`boolean`,label:`Flipped`,default:!1}}};bars=()=>[];setDataGetter(e){this.bars=e}copied(e){let t=this.bars();if(t.length===0)return[];let[n,r,i]=e.anchors,a=Math.max(0,Math.round(h(Math.min(n.time,r.time),t))),o=Math.min(t.length-1,Math.round(h(Math.max(n.time,r.time),t)));if(o<a)return[];let s=t.slice(a,Math.min(o+1,a+cl));if(s.length===0)return[];let c=this.option(e,`flipped`),l=this.option(e,`mirrored`)?[...s].reverse():s,u=l[0].open,d=e=>i.price+(c?u-e:e-u);return l.map(e=>{let t=d(e.high),n=d(e.low);return{...e,open:d(e.open),close:d(e.close),high:Math.max(t,n),low:Math.min(t,n)}})}box(e,t,n){if(n.length===0)return null;let r=g(e.anchors[2].time,t),i=a(r,t)-t.barWidth/2,s=a(r+n.length-1,t)+t.barWidth/2,c=-1/0,l=1/0;for(let e of n)e.high>c&&(c=e.high),e.low<l&&(l=e.low);let u=o(c,t),d=o(l,t);return{x:i,y:Math.min(u,d),width:s-i,height:Math.abs(d-u)}}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.setLineDash([4,4]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),t.anchors.length>=3&&this.renderCopy(e,t,n),r&&this.renderAnchorHandles(e,t,n)}renderCopy(e,t,n){let r=this.copied(t);if(r.length===0)return;let i=g(t.anchors[2].time,n),s=this.option(t,`mode`);if(e.strokeStyle=t.style.color,e.fillStyle=t.style.color,e.lineWidth=1,e.globalAlpha=.7,s===`line`)e.beginPath(),r.forEach((t,r)=>{let s=a(i+r,n),c=o(t.close,n);r===0?e.moveTo(s,c):e.lineTo(s,c)}),e.stroke();else{let t=Math.max(1,n.barWidth/2);r.forEach((r,c)=>{let l=a(i+c,n);if(e.beginPath(),e.moveTo(l,o(r.high,n)),e.lineTo(l,o(r.low,n)),e.stroke(),s===`highLow`)return;let u=o(Math.max(r.open,r.close),n),d=Math.max(1,o(Math.min(r.open,r.close),n)-u);r.close>=r.open?e.strokeRect(l-t,u,t*2,d):e.fillRect(l-t,u,t*2,d)})}e.globalAlpha=1}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;if(B(e,this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n))<=r)return!0;let i=t.anchors.length>=3?this.box(t,n,this.copied(t)):null;return i!==null&&ec(e,i,r)}};function pl(e){e.register(new Wa),e.register(new co),e.register(new lo),e.register(new uo),e.register(new fo),e.register(new po),e.register(new mo),e.register(new ho),e.register(new bo),e.register(new So),e.register(new Co),e.register(new wo),e.register(new To),e.register(new Eo),e.register(new No),e.register(new zo),e.register(new Bo),e.register(new Vo),e.register(new Uo),e.register(new Wo),e.register(new Ko),e.register(new Jo),e.register(new Yo),e.register(new Xo),e.register(new Qo),e.register(new is),e.register(new as),e.register(new ls),e.register(new ds),e.register(new hs),e.register(new ys),e.register(new Do),e.register(new Oo),e.register(new xs),e.register(new Ss),e.register(new Cs),e.register(new Es),e.register(new Ms),e.register(new Is),e.register(new Vs),e.register(new lc),e.register(new uc),e.register(new hc),e.register(new vc),e.register(new xc),e.register(new Ac),e.register(new jc),e.register(new Mc),e.register(new Nc),e.register(new Ic),e.register(new Lc),e.register(new Yc),e.register(new $c),e.register(new Xc),e.register(new Zc),e.register(new Qc),e.register(new el),e.register(new Po),e.register(new Fo),e.register(new Io),e.register(new Lo),e.register(new Ro),e.register(new ws),e.register(new Ts),e.register(new il),e.register(new al),e.register(new ul),e.register(new dl),e.register(new fl)}var ml=2;function hl(e,t){return e.type===t.type?e.type===`cancelOrder`?e.orderId===t.orderId:e.type===`removeStop`?e.positionId===t.positionId&&e.which===t.which:e.positionId===t.positionId:!1}function gl(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(t.x>=r.x-ml&&t.x<=r.x+r.size+ml&&t.y>=r.y-ml&&t.y<=r.y+r.size+ml)return r}return null}function _l(e,t,n,r,i){e.fillStyle=i,e.fillRect(t,n,r,r);let a=r*.3;e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.beginPath(),e.moveTo(t+a,n+a),e.lineTo(t+r-a,n+r-a),e.moveTo(t+r-a,n+a),e.lineTo(t+a,n+r-a),e.stroke()}function vl(e,t,n,r,i){e.fillStyle=i,e.fillRect(t,n,r,r);let a=n+r*.25,o=n+r*.75,s=t+r*.35,c=t+r*.65,l=r*.14;e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.beginPath(),e.moveTo(s,o),e.lineTo(s,a),e.moveTo(s-l,a+l),e.lineTo(s,a),e.lineTo(s+l,a+l),e.moveTo(c,a),e.lineTo(c,o),e.moveTo(c-l,o-l),e.lineTo(c,o),e.lineTo(c+l,o-l),e.stroke()}var yl=16,bl=class{render(e,t,n,r,i,a,s=[]){let c=i.orderColors?.buy??`#1fa874`,l=i.orderColors?.sell??`#e8505b`,{chartRect:u}=n,d=i.lineButtons?.cancel!==!1;for(let i of t){let t=a?.orderId===i.id&&a.sourceType===`order`,f=o(t?a.currentPrice:i.price,n);if(f<u.y||f>u.y+u.height)continue;let p=i.side===`buy`?c:l;e.setLineDash([6,4]),e.strokeStyle=p,e.lineWidth=1,e.beginPath(),e.moveTo(u.x,Math.round(f)+.5),e.lineTo(u.x+u.width,Math.round(f)+.5),e.stroke(),e.setLineDash([]);let m=i.label??i.type.toUpperCase();e.font=`bold 10px ${r.font.family}`;let h=e.measureText(m).width+8;e.fillStyle=p,C(e,u.x+4,f-8,h,16,r),e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(m,u.x+8,f);let g=u.x+4+h+6;if(e.fillStyle=p,e.beginPath(),i.side===`buy`?(e.moveTo(g,f+4),e.lineTo(g+5,f-2),e.lineTo(g+10,f+4)):(e.moveTo(g,f-4),e.lineTo(g+5,f+2),e.lineTo(g+10,f-4)),e.fill(),d&&!t){let t=g+16;_l(e,t,f-yl/2,yl,p),s.push({x:t,y:f-yl/2,size:yl,action:{type:`cancelOrder`,orderId:i.id}})}if(t){let t=o(a.startPrice,n);e.setLineDash([2,4]),e.strokeStyle=p,e.globalAlpha=.3,e.beginPath(),e.moveTo(u.x,Math.round(t)+.5),e.lineTo(u.x+u.width,Math.round(t)+.5),e.stroke(),e.globalAlpha=1,e.setLineDash([])}}}renderAxisBadges(t,n,r,i,a,s){let c=a.orderColors?.buy??`#1fa874`,l=a.orderColors?.sell??`#e8505b`,u=a.pricePrecision??2,{chartRect:d}=r,f=d.x+d.width+1;for(let a of n){let n=s?.orderId===a.id&&s.sourceType===`order`?s.currentPrice:a.price,p=o(n,r);if(p<d.y||p>d.y+d.height)continue;let m=a.side===`buy`?c:l,h=`${r.formatPrice?.(n)??n.toFixed(u)} x ${a.quantity}`;t.font=`11px ${i.font.family}`;let g=t.measureText(h).width+10;t.fillStyle=m,C(t,f,p-9,Math.min(g,(r.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2),18,i),t.fillStyle=`#FFFFFF`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(h,f+5,p)}}hitTest(e,t,n,r){for(let i of t){if(i.draggable===!1)continue;let t=o(i.price,n);if(Math.abs(e-t)<=r)return i}return null}};function xl(e,t,n,r){let i=Math.min(Math.max(e.closedQuantity??0,0),e.quantity),a=e.quantity-i,o=e.side===`buy`?1:-1,s=(t-e.entryPrice)*a*o,c=e.entryPrice===0?0:(t-e.entryPrice)/e.entryPrice*100*o;return{side:e.side,quantity:e.quantity,closedQuantity:i,openQuantity:a,entryPrice:e.entryPrice,currentPrice:t,pnl:s,pnlPct:c,precision:n,formatPrice:r}}var Sl=/\{(side|qty|closedQty|openQty|entry|price|pnl|pnlPct|pnlSign)\}/g;function Cl(e,t){return e.replace(Sl,(e,n)=>{switch(n){case`side`:return t.side.toUpperCase();case`qty`:return String(t.quantity);case`closedQty`:return String(t.closedQuantity);case`openQty`:return String(t.openQuantity);case`entry`:return t.formatPrice?.(t.entryPrice)??t.entryPrice.toFixed(t.precision);case`price`:return t.formatPrice?.(t.currentPrice)??t.currentPrice.toFixed(t.precision);case`pnl`:return t.pnl.toFixed(t.precision);case`pnlPct`:return`${t.pnlPct.toFixed(2)}%`;case`pnlSign`:return t.pnl>=0?`+`:``;default:return``}})}function wl(e,t){return typeof e==`function`?e(t):Cl(e??`{side} {qty} | P&L: {pnlSign}{pnl}`,t)}function Tl(e,t,n){if(!t||t.length===0)return n;let r=[...t].sort((e,t)=>e.pnl-t.pnl),i;for(let t of r)if(e>=t.pnl)i=t.color;else break;return i??n}var q=20,El=16;function Dl(e,t,n){let{chartRect:r}=n;return e-t/2>=r.y&&e+t/2<=r.y+r.height}var Ol=class{render(e,t,n,r,i,a,s=[]){let{chartRect:c}=r,l=a.positionColors?.profit??`#1fa874`,u=a.positionColors?.loss??`#e8505b`,d=a.positionColors?.entry??`#4c8dff`,f=a.pricePrecision??2,p=a.lineButtons??{};for(let m of t){let t=o(m.entryPrice,r);if(e.strokeStyle=d,e.lineWidth=1.5,e.setLineDash([]),e.beginPath(),e.moveTo(c.x,Math.round(t)+.5),e.lineTo(c.x+c.width,Math.round(t)+.5),e.stroke(),n!==null){let h=o(n,r),g=xl(m,n,f,r.formatPrice),_=g.pnl,v=_>=0?l:u,y=Tl(_,a.pnlThresholds,v);e.fillStyle=y,e.globalAlpha=.08;let b=Math.min(t,h),x=Math.abs(h-t);if(e.fillRect(c.x,b,c.width,x),e.globalAlpha=1,g.closedQuantity>0&&m.quantity>0){let t=g.closedQuantity/m.quantity;e.fillStyle=d,e.globalAlpha=.25,e.fillRect(c.x,b,Math.max(2,c.width*t*.04)+2,x),e.globalAlpha=1}let S=wl(a.positionLabel,g);e.font=`bold 11px ${i.font.family}`;let w=e.measureText(S).width+12,T=c.x+8;e.fillStyle=y,e.globalAlpha=.9,C(e,T,t-10,w,20,i),e.globalAlpha=1,e.fillStyle=`#FFFFFF`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillText(S,T+6,t),Dl(t,q,r)&&this.renderButtons(e,m.id,T+w+2,t,y,p,s)}else Dl(t,q,r)&&this.renderButtons(e,m.id,c.x+8,t,d,p,s);if(m.stopLoss!==void 0){let t=o(m.stopLoss,r);e.setLineDash([4,4]),e.strokeStyle=u,e.lineWidth=1,e.beginPath(),e.moveTo(c.x,Math.round(t)+.5),e.lineTo(c.x+c.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=u,C(e,c.x+4,t-8,24,16,i),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`SL`,c.x+8,t),p.removeStops!==!1&&Dl(t,El,r)&&this.renderStopButton(e,m.id,`stopLoss`,c.x+30,t,u,s)}if(m.takeProfit!==void 0){let t=o(m.takeProfit,r);e.setLineDash([4,4]),e.strokeStyle=l,e.lineWidth=1,e.beginPath(),e.moveTo(c.x,Math.round(t)+.5),e.lineTo(c.x+c.width,Math.round(t)+.5),e.stroke(),e.font=`bold 10px ${i.font.family}`,e.fillStyle=l,C(e,c.x+4,t-8,24,16,i),e.fillStyle=`#FFFFFF`,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(`TP`,c.x+8,t),p.removeStops!==!1&&Dl(t,El,r)&&this.renderStopButton(e,m.id,`takeProfit`,c.x+30,t,l,s)}e.setLineDash([])}}renderButtons(e,t,n,r,i,a,o){let s=r-q/2,c=n;e.globalAlpha=.9,a.reverse!==!1&&(vl(e,c,s,q,i),o.push({x:c,y:s,size:q,action:{type:`reversePosition`,positionId:t}}),c+=q+2),a.close!==!1&&(_l(e,c,s,q,i),o.push({x:c,y:s,size:q,action:{type:`closePosition`,positionId:t}})),e.globalAlpha=1}renderStopButton(e,t,n,r,i,a,o){let s=i-El/2;_l(e,r,s,El,a),o.push({x:r,y:s,size:El,action:{type:`removeStop`,positionId:t,which:n}})}renderAxisBadges(t,n,r,i,a){let{chartRect:s}=r,c=a.positionColors?.entry??`#4c8dff`,l=a.pricePrecision??2,u=s.x+s.width+1;for(let a of n){let n=o(a.entryPrice,r);t.fillStyle=c,C(t,u,n-9,(r.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2,18,i),t.fillStyle=`#FFFFFF`,t.font=`11px ${i.font.family}`,t.textAlign=`left`,t.textBaseline=`middle`,t.fillText(r.formatPrice?.(a.entryPrice)??a.entryPrice.toFixed(l),u+5,n)}}},kl=class{render(e,t,n,r){if(!r.depthOverlay?.enabled)return;let{chartRect:i}=n,a=r.depthOverlay.bidColor??`rgba(31, 168, 116,0.15)`,s=r.depthOverlay.askColor??`rgba(232, 80, 91,0.15)`,c=r.depthOverlay.maxWidth??100,l=0,u=[],d=0;for(let e of t.bids)d+=e.volume,u.push({price:e.price,cumVol:d}),d>l&&(l=d);let f=[];d=0;for(let e of t.asks)d+=e.volume,f.push({price:e.price,cumVol:d}),d>l&&(l=d);if(l===0)return;let p=Math.max(1,t.bids.length>1?Math.abs(o(t.bids[0].price,n)-o(t.bids[1].price,n)):4),m=i.x+i.width;e.fillStyle=a;for(let{price:t,cumVol:r}of u){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}e.fillStyle=s;for(let{price:t,cumVol:r}of f){let a=o(t,n);if(a<i.y||a>i.y+i.height)continue;let s=r/l*c;e.fillRect(m-s,a-p/2,s,p)}}},Al=class{dragState=null;startY=0;dragging=!1;constructor(e=3){this.dragThreshold=e}onPointerDown(e,t,n,r,i){for(let n of t){if(n.draggable===!1)continue;let t=o(n.price,r);if(Math.abs(e.y-t)<=i)return this.dragState={orderId:n.id,sourceType:`order`,startPrice:n.price,currentPrice:n.price},this.startY=e.y,this.dragging=!1,!0}for(let t of n){if(t.stopLoss!==void 0){let n=o(t.stopLoss,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`stopLoss`,startPrice:t.stopLoss,currentPrice:t.stopLoss},this.startY=e.y,this.dragging=!1,!0}if(t.takeProfit!==void 0){let n=o(t.takeProfit,r);if(Math.abs(e.y-n)<=i)return this.dragState={orderId:t.id,sourceType:`takeProfit`,startPrice:t.takeProfit,currentPrice:t.takeProfit},this.startY=e.y,this.dragging=!1,!0}}return!1}onPointerMove(e,t){if(!this.dragState)return!1;if(!this.dragging){if(Math.abs(e.y-this.startY)<this.dragThreshold)return!0;this.dragging=!0}return this.dragState.currentPrice=u(e.y,t),!0}onPointerUp(){if(!this.dragState)return null;let e=this.dragState;return this.dragState=null,this.dragging?(this.dragging=!1,{sourceType:e.sourceType,id:e.orderId,newPrice:e.currentPrice,previousPrice:e.startPrice}):null}getDragState(){return this.dragState}isActive(){return this.dragState!==null}},jl=class{menuElement=null;removeHandler=null;onItemSelect=null;show(e,t,n,r,i){if(this.hide(),!r.contextMenu?.enabled)return;let a=r.pricePrecision??2,o=i?.(t)??t.toFixed(a),s=document.createElement(`div`);s.style.cssText=`
|
|
7
9
|
position: absolute;
|
|
8
10
|
left: ${e.x}px;
|
|
9
11
|
top: ${e.y}px;
|
|
@@ -16,11 +18,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
16
18
|
box-shadow: 0 4px 12px rgba(0,0,0,0.4);
|
|
17
19
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
18
20
|
font-size: 12px;
|
|
19
|
-
`;let
|
|
21
|
+
`;let c=[{label:`Buy Limit @ ${o}`,intent:{side:`buy`,type:`limit`,price:t}},{label:`Sell Limit @ ${o}`,intent:{side:`sell`,type:`limit`,price:t}},{label:`Buy Stop @ ${o}`,intent:{side:`buy`,type:`stop`,price:t}},{label:`Sell Stop @ ${o}`,intent:{side:`sell`,type:`stop`,price:t}}];for(let e of c){let t=document.createElement(`div`),n=e.intent.side===`buy`;t.textContent=e.label,t.style.cssText=`
|
|
20
22
|
padding: 6px 12px;
|
|
21
23
|
cursor: pointer;
|
|
22
24
|
color: ${n?`#1fa874`:`#e8505b`};
|
|
23
25
|
transition: background 0.1s;
|
|
24
|
-
`,t.addEventListener(`mouseenter`,()=>{t.style.background=`#1f2630`}),t.addEventListener(`mouseleave`,()=>{t.style.background=`transparent`}),t.addEventListener(`click`,()=>{this.onItemSelect?.(e.intent),this.hide()}),o.appendChild(t)}n.appendChild(o),this.menuElement=o;let c=e=>{(e instanceof KeyboardEvent&&e.key===`Escape`||e instanceof MouseEvent&&!o.contains(e.target))&&this.hide()};document.addEventListener(`mousedown`,c),document.addEventListener(`keydown`,c),this.removeHandler=()=>{document.removeEventListener(`mousedown`,c),document.removeEventListener(`keydown`,c)}}hide(){this.menuElement?.remove(),this.menuElement=null,this.removeHandler?.(),this.removeHandler=null}destroy(){this.hide(),this.onItemSelect=null}};function ma(e,t,n={}){let r=Math.max(Math.abs(t)*(n.riskFraction??.01),1e-8),i=r*(n.riskReward??2);return e===`buy`?{side:e,entry:t,stopLoss:t-r,takeProfit:t+i}:{side:e,entry:t,stopLoss:t+r,takeProfit:t-i}}function ha(e){let t=Math.abs(e.entry-e.stopLoss);return t===0?0:Math.abs(e.takeProfit-e.entry)/t}var ga=6,_a=class{draft=null;dragging=null;defaults;constructor(e={}){this.defaults=e}start(e,t){this.draft=ma(e,t,this.defaults),this.dragging=null}cancel(){this.draft=null,this.dragging=null}isActive(){return this.draft!==null}getDraft(){return this.draft?{...this.draft}:null}hitTest(e,t){if(!this.draft)return null;let n=[`entry`,`sl`,`tp`],r=null,i=ga;for(let a of n){let n=o(this.priceOf(a),t),s=Math.abs(n-e.y);s<=i&&(i=s,r=a)}return r}beginDrag(e,t){let n=this.hitTest(e,t);return n?(this.dragging=n,!0):!1}drag(e,t){if(!this.draft||!this.dragging)return!1;let n=u(e.y,t);return this.draft=va(this.draft,this.dragging,n),!0}endDrag(){this.dragging=null}isDragging(){return this.dragging!==null}priceOf(e){let t=this.draft;return e===`entry`?t.entry:e===`sl`?t.stopLoss:t.takeProfit}render(e,t,n,r=2){let i=this.draft;if(!i)return;let{chartRect:a}=t,s=a.x,c=a.x+a.width,l=o(i.entry,t),u=o(i.stopLoss,t),d=o(i.takeProfit,t),f=n.candleUp,p=n.candleDown;e.save(),e.globalAlpha=.12,e.fillStyle=f,e.fillRect(s,Math.min(l,d),a.width,Math.abs(d-l)),e.fillStyle=p,e.fillRect(s,Math.min(l,u),a.width,Math.abs(u-l)),e.globalAlpha=1,ya(e,s,c,l,n.text,[6,3]),ya(e,s,c,d,f,[]),ya(e,s,c,u,p,[]);let m=ha(i),h=i.side===`buy`?`LONG`:`SHORT`;ba(e,s+6,l,`${h} entry ${i.entry.toFixed(r)}`,n.text,n.background),ba(e,s+6,d,`TP ${i.takeProfit.toFixed(r)} · ${m.toFixed(2)}R`,f,n.background),ba(e,s+6,u,`SL ${i.stopLoss.toFixed(r)}`,p,n.background);for(let[r,a]of[[i.entry,n.text],[i.takeProfit,f],[i.stopLoss,p]]){let n=o(r,t);e.fillStyle=a,e.beginPath(),e.arc(c-6,n,3.5,0,Math.PI*2),e.fill()}e.restore()}};function va(e,t,n){let r=e.side===`buy`;if(t===`entry`){let t=n-e.entry;return{side:e.side,entry:n,stopLoss:e.stopLoss+t,takeProfit:e.takeProfit+t}}if(t===`sl`){let t=r?Math.min(n,e.entry):Math.max(n,e.entry);return{...e,stopLoss:t}}let i=r?Math.max(n,e.entry):Math.min(n,e.entry);return{...e,takeProfit:i}}function ya(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function ba(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a,e.fillRect(t-3,n-8,o+6,16),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}function xa(e,t,n){return n==null?`limit`:e===`buy`?t<=n?`limit`:`stop`:t>=n?`limit`:`stop`}var Sa=6,Ca=class{draft=null;dragging=!1;start(e,t,n=1){this.draft={side:e,price:t,quantity:n},this.dragging=!1}cancel(){this.draft=null,this.dragging=!1}isActive(){return this.draft!==null}isDragging(){return this.dragging}getDraft(){return this.draft?{...this.draft}:null}setPrice(e){return this.draft?(this.draft={...this.draft,price:e},!0):!1}toIntent(e){return this.draft?{side:this.draft.side,type:xa(this.draft.side,this.draft.price,e),price:this.draft.price,quantity:this.draft.quantity}:null}hitTest(e,t){return this.draft?Math.abs(o(this.draft.price,t)-e.y)<=Sa:!1}beginDrag(e,t){return this.hitTest(e,t)?(this.dragging=!0,!0):!1}drag(e,t){return!this.draft||!this.dragging?!1:this.setPrice(u(e.y,t))}endDrag(){this.dragging=!1}render(e,t,n,r,i=2){let a=this.draft;if(!a)return;let{chartRect:s}=t,c=s.x,l=s.x+s.width,u=o(a.price,t),d=xa(a.side,a.price,r),f=a.side===`buy`?n.candleUp:n.candleDown;e.save(),wa(e,c,l,u,f,[6,3]);let p=a.side===`buy`?`BUY`:`SELL`;Ta(e,c+6,u,`${p} ${d.toUpperCase()} ${a.price.toFixed(i)}`,f,n.background),e.fillStyle=f,e.beginPath(),e.arc(l-6,u,3.5,0,Math.PI*2),e.fill(),e.restore()}};function wa(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function Ta(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a,e.fillRect(t-3,n-8,o+6,16),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}var Ea=class{orders=[];positions=[];depthData=null;currentPrice=null;config;orderRenderer=new ia;positionRenderer=new ua;depthOverlay=new da;dragHandler;contextMenu=new pa;bracket=new _a;orderDraft=new Ca;requestRender=null;eventCallback=null;container=null;constructor(t){this.config={...e.DEFAULT_TRADING_CONFIG,...t},this.dragHandler=new fa(this.config.dragThreshold),this.contextMenu.onItemSelect=e=>{this.eventCallback?.(`orderPlace`,e)}}setContainer(e){this.container=e}setRequestRender(e){this.requestRender=e}setEventCallback(e){this.eventCallback=e}setOrders(e){this.orders=e,this.requestRender?.()}setPositions(e){this.positions=e,this.requestRender?.()}setDepthData(e){this.depthData=e,this.requestRender?.()}setCurrentPrice(e){this.currentPrice=e,this.requestRender?.()}setConfig(e){Object.assign(this.config,e),this.requestRender?.()}startBracket(e,t){this.bracket.start(e,t),this.requestRender?.()}cancelBracket(){this.bracket.isActive()&&(this.bracket.cancel(),this.requestRender?.())}confirmBracket(){let e=this.bracket.getDraft();return e?(this.eventCallback?.(`bracketPlace`,{side:e.side,entry:e.entry,stopLoss:e.stopLoss,takeProfit:e.takeProfit,riskReward:ha(e)}),this.bracket.cancel(),this.requestRender?.(),!0):!1}isBracketActive(){return this.bracket.isActive()}startOrderDraft(e,t){this.orderDraft.start(e,t),this.requestRender?.()}cancelOrderDraft(){this.orderDraft.isActive()&&(this.orderDraft.cancel(),this.requestRender?.())}confirmOrderDraft(){let e=this.orderDraft.toIntent(this.currentPrice);return e?(this.eventCallback?.(`orderPlace`,e),this.orderDraft.cancel(),this.requestRender?.(),!0):!1}isOrderDraftActive(){return this.orderDraft.isActive()}isOverDraggableLine(e,t,n=8){if(!this.config.enabled)return!1;let r=r=>r!==void 0&&Math.abs(e.y-o(r,t))<=n;for(let e of this.orders)if(e.draggable!==!1&&r(e.price))return!0;for(let e of this.positions)if(r(e.stopLoss)||r(e.takeProfit))return!0;return!1}onPointerDown(e,t){return this.config.enabled?this.bracket.isActive()&&this.bracket.beginDrag(e,t)||this.orderDraft.isActive()&&this.orderDraft.beginDrag(e,t)?(this.requestRender?.(),!0):this.dragHandler.onPointerDown(e,this.orders,this.positions,t,8):!1}onPointerMove(e,t){if(this.bracket.isDragging()){let n=this.bracket.drag(e,t);return n&&this.requestRender?.(),n}if(this.orderDraft.isDragging()){let n=this.orderDraft.drag(e,t);return n&&this.requestRender?.(),n}if(!this.dragHandler.isActive())return!1;let n=this.dragHandler.onPointerMove(e,t);return n&&this.requestRender?.(),n}onPointerUp(){if(this.bracket.isDragging())return this.bracket.endDrag(),this.requestRender?.(),!0;if(this.orderDraft.isDragging())return this.orderDraft.endDrag(),this.requestRender?.(),!0;let e=this.dragHandler.onPointerUp();return e?(e.sourceType===`order`?this.eventCallback?.(`orderModify`,{orderId:e.id,newPrice:e.newPrice,previousPrice:e.previousPrice}):this.eventCallback?.(`positionModify`,{positionId:e.id,[e.sourceType]:e.newPrice}),this.requestRender?.(),!0):!1}onContextMenu(e,t){if(!this.config.enabled||!this.config.contextMenu?.enabled||!this.container)return!1;let n=u(e.y,t);return this.contextMenu.show(e,n,this.container,this.config),!0}render(e,t,n){this.config.enabled&&(this.depthData&&this.depthOverlay.render(e,this.depthData,t,this.config),this.positions.length>0&&this.positionRenderer.render(e,this.positions,this.currentPrice,t,n,this.config),this.orders.length>0&&this.orderRenderer.render(e,this.orders,t,n,this.config,this.dragHandler.getDragState()),this.bracket.isActive()&&this.bracket.render(e,t,n,this.config.pricePrecision??2),this.orderDraft.isActive()&&this.orderDraft.render(e,t,n,this.currentPrice,this.config.pricePrecision??2))}renderAxisBadges(e,t,n){this.config.enabled&&(this.positions.length>0&&this.positionRenderer.renderAxisBadges(e,this.positions,t,n,this.config),this.orders.length>0&&this.orderRenderer.renderAxisBadges(e,this.orders,t,n,this.config,this.dragHandler.getDragState()))}destroy(){this.contextMenu.destroy()}},Da=class{constructor(e){this.manager=e}render(e,t,n){this.manager.render(e,t,n)}renderAxisBadges(e,t,n){this.manager.renderAxisBadges(e,t,n)}},Oa=class{name=`paper`;state=`disconnected`;listeners=new Map;orders=[];positions=[];markPrice;seq=0;constructor(e={}){this.markPrice=e.markPrice??0}connect(e){this.state=`connected`,this.emit(`connectionChange`,this.state),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}disconnect(){this.state=`disconnected`,this.emit(`connectionChange`,this.state)}getConnectionState(){return this.state}setMarkPrice(e){this.markPrice=e,this.checkPendingOrders(),this.checkStops()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}async placeOrder(e){let t={id:this.nextId(`ord`),side:e.side,type:e.type,price:e.price,stopPrice:e.stopPrice,quantity:e.quantity??1,label:e.type===`market`?void 0:ka(e.type),draggable:!0};return e.type===`market`?this.fill(t,this.markPrice||e.price):(this.orders=[...this.orders,t],this.emit(`orders`,this.orders)),t}async modifyOrder(e){this.orders=this.orders.map(t=>t.id===e.orderId?{...t,price:e.newPrice}:t),this.emit(`orders`,this.orders)}async cancelOrder(e){this.orders=this.orders.filter(t=>t.id!==e.orderId),this.emit(`orders`,this.orders)}async modifyPosition(e){this.positions=this.positions.map(t=>t.id===e.positionId?{...t,stopLoss:e.stopLoss??t.stopLoss,takeProfit:e.takeProfit??t.takeProfit}:t),this.emit(`positions`,this.positions)}async closePosition(e){this.positions=this.positions.filter(t=>t.id!==e.positionId),this.emit(`positions`,this.positions)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear(),this.orders=[],this.positions=[]}fill(e,t){this.orders=this.orders.filter(t=>t.id!==e.id);let n={id:this.nextId(`pos`),side:e.side,entryPrice:t,quantity:e.quantity};this.positions=[...this.positions,n];let r={orderId:e.id,side:e.side,price:t,quantity:e.quantity,time:Date.now()};this.emit(`fill`,r),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}checkPendingOrders(){let e=this.orders.filter(e=>this.isTriggered(e));for(let t of e)this.fill(t,t.type===`limit`?t.price:t.stopPrice??t.price)}isTriggered(e){if(e.type===`limit`)return e.side===`buy`?this.markPrice<=e.price:this.markPrice>=e.price;if(e.type===`stop`||e.type===`stopLimit`){let t=e.stopPrice??e.price;return e.side===`buy`?this.markPrice>=t:this.markPrice<=t}return!1}checkStops(){let e=[],t=!1;for(let n of this.positions){let r=n.stopLoss!==void 0&&(n.side===`buy`?this.markPrice<=n.stopLoss:this.markPrice>=n.stopLoss),i=n.takeProfit!==void 0&&(n.side===`buy`?this.markPrice>=n.takeProfit:this.markPrice<=n.takeProfit);if(r||i){t=!0;continue}e.push(n)}t&&(this.positions=e,this.emit(`positions`,this.positions))}nextId(e){return`${e}-${++this.seq}`}emit(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function ka(e){switch(e){case`stop`:return`STOP`;case`stopLimit`:return`STOP LIMIT`;default:return`LIMIT`}}var K=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let e of n)e(t)}removeAllListeners(){this.listeners.clear()}},Aa=class extends K{currentBar=null;timeframeMs;tickRing;ringHead=0;ringCount=0;ringCapacity;constructor(t,n=1e3){super(),this.timeframeMs=(0,e.timeframeToMs)(t),this.ringCapacity=n,this.tickRing=Array(n)}setTimeframe(t){this.timeframeMs=(0,e.timeframeToMs)(t),this.currentBar=null,this.ringHead=0,this.ringCount=0}processTick(e){let t=(this.ringHead+this.ringCount)%this.ringCapacity;this.tickRing[t]=e,this.ringCount<this.ringCapacity?this.ringCount++:this.ringHead=(this.ringHead+1)%this.ringCapacity;let n=this.alignToTimeframe(e.time);!this.currentBar||this.currentBar.time!==n?(this.currentBar&&(this.currentBar.closed=!0,this.emit(`barClose`,this.currentBar)),this.currentBar={time:n,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.volume,closed:!1,tickCount:1}):(this.currentBar.high=Math.max(this.currentBar.high,e.price),this.currentBar.low=Math.min(this.currentBar.low,e.price),this.currentBar.close=e.price,this.currentBar.volume+=e.volume,this.currentBar.tickCount++),this.emit(`bar`,this.currentBar)}processBar(e,t){if(t&&this.currentBar&&this.currentBar.time===e.time)this.currentBar={...e,closed:!0,tickCount:this.currentBar.tickCount+1},this.emit(`barClose`,this.currentBar),this.currentBar=null;else if(!t)this.currentBar={...e,closed:!1,tickCount:(this.currentBar?.tickCount??0)+1},this.emit(`bar`,this.currentBar);else{let t={...e,closed:!0,tickCount:1};this.emit(`barClose`,t),this.currentBar=null}}getCurrentBar(){return this.currentBar?{...this.currentBar}:null}getTickBuffer(){let e=Array(this.ringCount);for(let t=0;t<this.ringCount;t++)e[t]=this.tickRing[(this.ringHead+t)%this.ringCapacity];return e}reset(){this.currentBar=null,this.ringHead=0,this.ringCount=0}alignToTimeframe(e){return Math.floor(e/this.timeframeMs)*this.timeframeMs}},ja=class extends K{config;attempt=0;timer=null;active=!1;constructor(t){super(),this.config={...e.DEFAULT_RECONNECT,...t}}schedule(e){if(!this.config.enabled||!this.active)return;if(this.attempt++,this.attempt>this.config.maxRetries){this.emit(`giveUp`,{attempts:this.attempt-1}),this.active=!1;return}let t=this.computeDelay();this.emit(`attempt`,{attempt:this.attempt,delay:t}),this.timer=setTimeout(()=>{this.timer=null,this.active&&e()},t)}onConnected(){this.attempt=0,this.cancel(),this.emit(`success`,void 0)}start(){this.active=!0}stop(){this.active=!1,this.cancel(),this.attempt=0}cancel(){this.timer&&=(clearTimeout(this.timer),null)}getAttempt(){return this.attempt}isActive(){return this.active}computeDelay(){let e=this.config.baseDelay,t=this.config.backoffMultiplier**(this.attempt-1),n=Math.min(e*t,this.config.maxDelay),r=n*.25*(Math.random()*2-1);return Math.max(0,Math.round(n+r))}},Ma=class{price=null;previousClose=null;visible=!0;flashUntil=0;pricePrecision=null;locale=`en-US`;setLocale(e){this.locale=e}setPrice(e,t){this.price!==null&&e!==this.price&&(this.flashUntil=Date.now()+300),this.previousClose=t??this.price??e,this.price=e}setVisible(e){this.visible=e}isVisible(){return this.visible}setPricePrecision(e){this.pricePrecision=e}getPrice(){return this.price}render(t,n,r){if(!this.visible||this.price===null)return;let i=o(this.price,n),{chartRect:a}=n;if(i<a.y||i>a.y+a.height)return;let s=this.previousClose===null||this.price>=this.previousClose?r.candleUp??`#1fa874`:r.candleDown??`#e8505b`,c=Date.now()<this.flashUntil;t.setLineDash([4,3]),t.strokeStyle=s,t.lineWidth=1,t.globalAlpha=c?1:.7,t.beginPath(),t.moveTo(a.x,Math.round(i)+.5),t.lineTo(a.x+a.width,Math.round(i)+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=1;let l=a.x+a.width+1,u=this.pricePrecision??(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max),d=(0,e.formatPrice)(this.price,u,this.locale);t.font=`bold 11px ${r.font.family}`;let f=t.measureText(d).width,p=n.priceAxisWidth??e.PRICE_AXIS_WIDTH,m=Math.min(f+12,p-2);t.fillStyle=s,t.fillRect(l,i-10,m,20);let h=l-5;t.beginPath(),t.moveTo(h,i),t.lineTo(h+5,i-5),t.lineTo(h+5,i+5),t.closePath(),t.fill(),t.fillStyle=`#FFFFFF`,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(d,l+5,i)}},Na=class extends K{config=null;adapter=null;aggregator=null;reconnector;priceLine=new Ma;state=`disconnected`;lastPrice=null;previousClose=null;unsubscribers=[];heartbeatTimer=null;lastMessageTime=0;connectSeq=0;constructor(){super(),this.reconnector=new ja,this.wireReconnector()}async connect(t){this.disconnect(),this.config={...e.DEFAULT_STREAM_CONFIG,...t},this.adapter=t.adapter,this.aggregator=new Aa(t.timeframe),this.reconnector.removeAllListeners(),this.reconnector.stop(),this.reconnector=new ja(t.reconnect??e.DEFAULT_RECONNECT),this.wireReconnector(),this.aggregator.on(`bar`,e=>{this.emit(`barUpdate`,e),this.updatePrice(e.close)}),this.aggregator.on(`barClose`,e=>{this.previousClose=e.close,this.emit(`barClose`,e)}),this.wireAdapter(),this.reconnector.start(),await this.doConnect()}disconnect(){this.connectSeq++,this.reconnector.stop(),this.stopHeartbeat();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.adapter&&=(this.adapter.disconnect(),null),this.aggregator?.reset(),this.aggregator?.removeAllListeners(),this.aggregator=null,this.config=null,this.lastPrice=null,this.previousClose=null,this.setState(`disconnected`)}async switchTo(e,t){!this.config||!this.adapter||(this.reconnector.stop(),this.adapter.disconnect(),this.reconnector.start(),this.aggregator?.reset(),this.aggregator?.setTimeframe(t),this.lastPrice=null,this.previousClose=null,this.config.symbol=e,this.config.timeframe=t,await this.doConnect())}getConnectionState(){return this.state}getConnectionInfo(){return{state:this.state,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}}getLastPrice(){return this.lastPrice}async doConnect(){if(!this.config||!this.adapter)return;let e=++this.connectSeq,{symbol:t,timeframe:n}=this.config;this.setState(`connecting`);try{let r=await this.adapter.fetchHistory(t,n,this.config.historyLimit??500);if(e!==this.connectSeq||!this.adapter)return;r.length>0&&(this.previousClose=r[r.length-1].close,this.updatePrice(r[r.length-1].close)),this.emit(`snapshot`,r),this.adapter.connect({symbol:t,timeframe:n}),this.startHeartbeat()}catch(t){if(e!==this.connectSeq)return;let n=t instanceof Error?t.message:String(t);this.emit(`error`,{message:n,code:`CONNECT_FAILED`}),this.setState(`error`),this.reconnector.schedule(()=>this.doConnect())}}wireReconnector(){this.reconnector.on(`attempt`,({attempt:e,delay:t})=>{this.setState(`reconnecting`),this.emit(`connectionChange`,{state:`reconnecting`,reconnectAttempt:e,lastMessageTime:this.lastMessageTime})}),this.reconnector.on(`giveUp`,({attempts:e})=>{this.setState(`error`),this.emit(`error`,{message:`Reconnection failed after ${e} attempts`,code:`RECONNECT_EXHAUSTED`})})}wireAdapter(){if(!this.adapter)return;let e=this.adapter,t=e=>{let t=e.data;this.lastMessageTime=Date.now(),t===`connected`?(this.reconnector.onConnected(),this.setState(`connected`)):(t===`disconnected`||t===`error`)&&this.reconnector.schedule(()=>this.doConnect())};e.on(`connectionChange`,t),this.unsubscribers.push(()=>e.off(`connectionChange`,t));let n=e=>{this.lastMessageTime=Date.now();let t=e.data;this.emit(`tick`,t),this.config?.aggregateTicks&&this.aggregator?this.aggregator.processTick(t):this.updatePrice(t.price)};e.on(`tick`,n),this.unsubscribers.push(()=>e.off(`tick`,n));let r=e=>{this.lastMessageTime=Date.now();let{bar:t,closed:n}=e.data;this.aggregator&&this.aggregator.processBar(t,n)};e.on(`bar`,r),this.unsubscribers.push(()=>e.off(`bar`,r));let i=e=>{this.emit(`error`,{message:e.data?.message??`Adapter error`})};e.on(`error`,i),this.unsubscribers.push(()=>e.off(`error`,i))}updatePrice(e){e!==this.lastPrice&&(this.lastPrice=e,this.priceLine.setPrice(e,this.previousClose??void 0),this.emit(`priceChange`,{price:e,previousClose:this.previousClose}))}setState(e){this.state!==e&&(this.state=e,this.emit(`connectionChange`,{state:e,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}))}startHeartbeat(){this.stopHeartbeat(),this.heartbeatTimer=setInterval(()=>{Date.now()-this.lastMessageTime>6e4&&this.state===`connected`&&(this.emit(`error`,{message:`Heartbeat timeout`,code:`HEARTBEAT_TIMEOUT`}),this.adapter?.disconnect(),this.reconnector.schedule(()=>this.doConnect()))},3e4)}stopHeartbeat(){this.heartbeatTimer&&=(clearInterval(this.heartbeatTimer),null)}dispose(){this.disconnect(),this.removeAllListeners()}},Pa=class extends K{data;speed;index;status=`idle`;timer=null;constructor(e){if(super(),e.data.length===0)throw Error(`ReplayController requires non-empty data`);this.data=e.data,this.speed=Math.max(.01,e.speed??1),this.index=Math.max(0,Math.min(e.startIndex??0,e.data.length)),e.autoStart&&this.start()}getStatus(){return this.status}getIndex(){return this.index}getTotal(){return this.data.length}getPrefix(){return this.data.slice(0,this.index)}start(){if(this.status!==`playing`){if(this.index>=this.data.length){this.transition(`finished`);return}this.transition(`playing`),this.scheduleNext()}}pause(){this.status===`playing`&&(this.clearTimer(),this.transition(`paused`))}resume(){this.status===`paused`&&this.start()}stop(){this.clearTimer(),this.index=0,this.transition(`idle`)}step(e=1){if(!(e<=0)){this.clearTimer();for(let t=0;t<e;t++)if(!this.emitNext())return;this.status!==`finished`&&this.transition(`paused`)}}seek(e){let t=Math.max(0,Math.min(e,this.data.length));this.clearTimer(),this.index=t;let n=t>=this.data.length?`finished`:`paused`;this.transition(n)}setSpeed(e){this.speed=Math.max(.01,e),this.status===`playing`&&(this.clearTimer(),this.scheduleNext())}destroy(){this.clearTimer(),this.removeAllListeners()}scheduleNext(){let e=1e3/this.speed;this.timer=setTimeout(()=>{this.timer=null,this.status===`playing`&&this.emitNext()&&this.scheduleNext()},e)}emitNext(){if(this.index>=this.data.length)return this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1;let e=this.data[this.index],t=this.index;return this.index++,this.emit(`bar`,{bar:e,index:t,total:this.data.length}),this.index>=this.data.length?(this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1):!0}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}transition(e){this.status!==e&&(this.status=e,this.emit(`stateChange`,{status:e,index:this.index,total:this.data.length}))}};function Fa(e){if(!Array.isArray(e)||e.length<6)return null;let t=e[0];if(typeof t!=`number`||!Number.isFinite(t))return null;let n=q(e[1]),r=q(e[2]),i=q(e[3]),a=q(e[4]),o=q(e[5]);return n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}function Ia(e){if(!La(e))return null;let t=e.t;if(typeof t!=`number`||!Number.isFinite(t))return null;let n=q(e.o),r=q(e.h),i=q(e.l),a=q(e.c),o=q(e.v);if(n===null||r===null||i===null||a===null||o===null)return null;let s=typeof e.x==`boolean`?e.x:!1;return{bar:{time:t,open:n,high:r,low:i,close:a,volume:o},closed:s}}function q(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function La(e){return typeof e==`object`&&!!e}var Ra={"1s":`1s`,"1m":`1m`,"3m":`3m`,"5m":`5m`,"15m":`15m`,"30m":`30m`,"1h":`1h`,"2h":`2h`,"4h":`4h`,"6h":`6h`,"8h":`8h`,"12h":`12h`,"1d":`1d`,"3d":`3d`,"1w":`1w`,"1M":`1M`},za=class{name=`binance`;ws=null;state=`disconnected`;listeners=new Map;config=null;restBase;wsBase;constructor(e){this.restBase=e?.restBase??`https://api.binance.com/api/v3`,this.wsBase=e?.wsBase??`wss://stream.binance.com:9443/ws`}connect(e){this.config=e,this.connectWs()}disconnect(){if(this.ws){let e=this.ws;e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,e.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}async fetchHistory(e,t,n=500){let r=Ra[t]??`15m`,i=`${this.restBase}/klines?symbol=${e}&interval=${r}&limit=${n}`,a=await fetch(i);if(!a.ok)throw Error(`Binance REST error: ${a.status}`);let o=await a.json();if(!Array.isArray(o))return[];let s=[];for(let e of o){let t=Fa(e);t&&s.push(t)}return s}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}connectWs(){if(!this.config)return;let e=`${this.config.symbol.toLowerCase()}@kline_${Ra[this.config.timeframe]??`15m`}`,t=`${this.wsBase}/${e}`;this.setState(`connecting`);try{this.ws=new WebSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws.onopen=()=>{this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`)},this.ws.onmessage=e=>{let t;try{t=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}typeof t==`object`&&t&&t.e===`kline`&&this.handleKline(t.k)},this.ws.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},this.ws.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}handleKline(e){let t=Ia(e);if(!t)return;let{bar:n,closed:r}=t;this.emitEvent(`bar`,{bar:n,closed:r}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume})}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Ba=class{name=`mock`;state=`disconnected`;listeners=new Map;config=null;options;tickTimer=null;currentPrice;constructor(e){this.options={basePrice:100,volatility:1.5,tickInterval:2e3,historySize:500,...e},this.currentPrice=this.options.basePrice}connect(e){this.config=e,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startTicking()}disconnect(){this.stopTicking(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}async fetchHistory(e,t,n){return this.options.historyGenerator?this.options.historyGenerator(e,t,n??this.options.historySize):this.generateHistory(t,n??this.options.historySize)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}generateHistory(t,n){let r=[],i=Date.now(),a=(0,e.timeframeToMs)(t),o=this.options.basePrice,s=this.options.volatility/100;for(let e=n-1;e>=0;e--){let t=i-e*a,n=(Math.random()-.48)*o*s,c=o;o+=n;let l=Math.max(c,o)+Math.random()*o*s*.3,u=Math.min(c,o)-Math.random()*o*s*.3,d=Math.floor(1e4+Math.random()*1e5);r.push({time:t,open:c,high:l,low:u,close:o,volume:d})}return this.currentPrice=o,r}startTicking(){this.stopTicking();let t=this.options.tickInterval??2e3;this.tickTimer=setInterval(()=>{if(this.state!==`connected`||!this.config)return;let t=this.options.volatility/100,n=(Math.random()-.48)*this.currentPrice*t*.3;this.currentPrice+=n;let r=Date.now(),i=(0,e.timeframeToMs)(this.config.timeframe),a={time:Math.floor(r/i)*i,open:this.currentPrice-n,high:Math.max(this.currentPrice,this.currentPrice-n)+Math.abs(n)*.2,low:Math.min(this.currentPrice,this.currentPrice-n)-Math.abs(n)*.2,close:this.currentPrice,volume:Math.floor(100+Math.random()*5e3)};this.emitEvent(`bar`,{bar:a,closed:!1}),this.emitEvent(`tick`,{time:r,price:this.currentPrice,volume:a.volume})},t)}stopTicking(){this.tickTimer&&=(clearInterval(this.tickTimer),null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Va=class{name;ws=null;state=`disconnected`;config=null;listeners=new Map;opts;constructor(e){this.opts=e,this.name=e.name}connect(e){this.config=e,this.openSocket()}disconnect(){let e=this.config;if(this.ws){if(this.opts.unsubscribeMessage&&e)try{this.sendMessage(this.opts.unsubscribeMessage(e))}catch{}let t=this.ws;t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,t.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchHistory(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}openSocket(){let e=this.config;if(!e)return;let t=this.opts.wsUrl(e);this.setState(`connecting`);let n;try{n=this.createSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws=n,n.onopen=()=>{if(this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`),this.opts.subscribeMessage)try{this.sendMessage(this.opts.subscribeMessage(e))}catch{}},n.onmessage=t=>{let n=this.decode(t.data);if(n===void 0)return;let r;try{r=this.opts.parseMessage(n,e)}catch{return}r&&(r.bar&&this.emitEvent(`bar`,{bar:r.bar,closed:r.closed??!1}),r.tick?this.emitEvent(`tick`,r.tick):r.bar&&this.emitEvent(`tick`,{time:Date.now(),price:r.bar.close,volume:r.bar.volume}))},n.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},n.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}sendMessage(e){e===void 0||!this.ws||this.ws.send(typeof e==`string`?e:JSON.stringify(e))}decode(e){if(this.opts.decode)try{return this.opts.decode(e)}catch{return}if(typeof e==`string`)try{return JSON.parse(e)}catch{return}return e}createSocket(e){if(this.opts.socketFactory)return this.opts.socketFactory(e);let t=globalThis.WebSocket;if(!t)throw Error(`No WebSocket implementation available`);return new t(e)}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Ha=class{name;state=`disconnected`;listeners=new Map;config=null;timer=null;lastBarTime=0;opts;constructor(e){this.opts=e,this.name=e.name}connect(e){this.config=e,this.lastBarTime=0,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startPolling()}disconnect(){this.stopPolling(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchBars(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}async poll(){let e=this.config;if(!e||this.state!==`connected`)return;let t;try{t=await this.opts.fetchBars(e.symbol,e.timeframe,this.opts.pollLimit??2)}catch(e){this.emitEvent(`error`,{message:`Poll failed`,cause:e});return}if(t.length===0)return;let n=t[t.length-1];if(this.lastBarTime>0&&n.time>this.lastBarTime){let e=t.find(e=>e.time===this.lastBarTime);e&&this.emitEvent(`bar`,{bar:e,closed:!0})}this.emitEvent(`bar`,{bar:n,closed:!1}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume}),this.lastBarTime=n.time}startPolling(){this.stopPolling(),this.poll();let e=this.opts.setInterval??((e,t)=>setInterval(e,t));this.timer=e(()=>{this.poll()},this.opts.intervalMs??5e3)}stopPolling(){this.timer!==null&&((this.opts.clearInterval??(e=>clearInterval(e)))(this.timer),this.timer=null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function J(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Y(e){return typeof e==`object`&&!!e}var Ua={"1m":60,"5m":300,"15m":900,"1h":3600,"6h":21600,"1d":86400};function Wa(e){return Ua[e]??3600}var Ga=class extends Ha{constructor(e={}){let t=e.restBase??`https://api.exchange.coinbase.com`;super({name:`coinbase`,intervalMs:e.intervalMs??5e3,pollLimit:2,fetchBars:(e,n)=>Ka(t,e,n)})}};async function Ka(e,t,n){let r=`${e}/products/${t}/candles?granularity=${Wa(n)}`,i=await fetch(r);if(!i.ok)throw Error(`Coinbase REST error: ${i.status}`);return qa(await i.json())}function qa(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=Ja(n);e&&t.push(e)}return t.sort((e,t)=>e.time-t.time),t}function Ja(e){if(!Array.isArray(e)||e.length<6)return null;let t=J(e[0]),n=J(e[1]),r=J(e[2]),i=J(e[3]),a=J(e[4]),o=J(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:i,high:r,low:n,close:a,volume:o}}var Ya={"1m":`1`,"3m":`3`,"5m":`5`,"15m":`15`,"30m":`30`,"1h":`60`,"2h":`120`,"4h":`240`,"6h":`360`,"12h":`720`,"1d":`D`,"1w":`W`,"1M":`M`};function Xa(e){return Ya[e]??`1`}var Za=class extends Va{constructor(e={}){let t=e.restBase??`https://api.bybit.com`,n=e.wsBase??`wss://stream.bybit.com/v5/public/spot`,r=e.category??`spot`;super({name:`bybit`,wsUrl:()=>n,subscribeMessage:e=>({op:`subscribe`,args:[`kline.${Xa(e.timeframe)}.${e.symbol}`]}),unsubscribeMessage:e=>({op:`unsubscribe`,args:[`kline.${Xa(e.timeframe)}.${e.symbol}`]}),parseMessage:Qa,fetchHistory:(e,n,i)=>$a(t,r,e,n,i)})}};function Qa(e){if(!Y(e)||typeof e.topic!=`string`||!e.topic.startsWith(`kline.`))return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Y(n))return null;let r=J(n.start),i=J(n.open),a=J(n.high),o=J(n.low),s=J(n.close),c=J(n.volume);if(r===null||i===null||a===null||o===null||s===null||c===null)return null;let l=typeof n.confirm==`boolean`?n.confirm:!1;return{bar:{time:r,open:i,high:a,low:o,close:s,volume:c},closed:l}}async function $a(e,t,n,r,i){let a=`${e}/v5/market/kline?category=${t}&symbol=${n}&interval=${Xa(r)}&limit=${Math.min(Math.max(i,1),1e3)}`,o=await fetch(a);if(!o.ok)throw Error(`Bybit REST error: ${o.status}`);return eo(await o.json())}function eo(e){if(!Y(e)||!Y(e.result))return[];let t=e.result.list;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=to(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function to(e){if(!Array.isArray(e)||e.length<6)return null;let t=J(e[0]),n=J(e[1]),r=J(e[2]),i=J(e[3]),a=J(e[4]),o=J(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}var no={"1m":1,"5m":5,"15m":15,"30m":30,"1h":60,"4h":240,"1d":1440,"1w":10080};function ro(e){return no[e]??1}var io=class extends Va{constructor(e={}){let t=e.restBase??`https://api.kraken.com`,n=e.wsBase??`wss://ws.kraken.com/v2`;super({name:`kraken`,wsUrl:()=>n,subscribeMessage:e=>({method:`subscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ro(e.timeframe)}}),unsubscribeMessage:e=>({method:`unsubscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ro(e.timeframe)}}),parseMessage:ao,fetchHistory:(e,n)=>oo(t,e,n)})}};function ao(e){if(!Y(e)||e.channel!==`ohlc`)return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Y(n))return null;let r=J(n.open),i=J(n.high),a=J(n.low),o=J(n.close),s=J(n.volume),c=typeof n.interval_begin==`string`?Date.parse(n.interval_begin):NaN;return r===null||i===null||a===null||o===null||s===null||!Number.isFinite(c)?null:{bar:{time:c,open:r,high:i,low:a,close:o,volume:s},closed:!1}}async function oo(e,t,n){let r=ro(n),i=t.replace(`/`,``),a=`${e}/0/public/OHLC?pair=${encodeURIComponent(i)}&interval=${r}`,o=await fetch(a);if(!o.ok)throw Error(`Kraken REST error: ${o.status}`);return so(await o.json())}function so(e){if(!Y(e)||!Y(e.result))return[];let t=null;for(let[n,r]of Object.entries(e.result))if(n!==`last`&&Array.isArray(r)){t=r;break}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=co(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function co(e){if(!Array.isArray(e)||e.length<7)return null;let t=J(e[0]),n=J(e[1]),r=J(e[2]),i=J(e[3]),a=J(e[4]),o=J(e[6]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:n,high:r,low:i,close:a,volume:o}}var lo={visible:!0,showSymbol:!0,showOHLC:!0,showChange:!0,showVolume:!0,position:`top-left`,fontSize:12},uo=class{config={...lo};symbol=``;timeframe=``;hoverBar=null;indicators=[];statusText=null;locale=`en-US`;pricePrecision=null;setConfig(e){Object.assign(this.config,e)}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}setSymbol(e){this.symbol=e}setTimeframe(e){this.timeframe=e}setChartType(e){}setHoverBar(e){this.hoverBar=e}setIndicatorValues(e){this.indicators=e}setStatusText(e){this.statusText=e}getHeight(){if(!this.config.visible||this.config.position!==`top-left`)return 0;let e=this.config.fontSize,t=6;return this.config.showSymbol?t+=e+6:this.statusText&&(t+=e+4),this.config.showOHLC&&(t+=e+3),this.config.showVolume&&(t+=e+2),t}render(t,n,r,i){if(!this.config.visible||i.length===0)return;let a=this.hoverBar??i[i.length-1],o=i.length>1?i[i.length-2]:a,{chartRect:s}=n,c=this.config.fontSize,l=this.config.position===`top-left`,u=l?s.x+8:s.x+s.width-8,d=s.y+6;if(t.textAlign=l?`left`:`right`,t.textBaseline=`top`,this.config.showSymbol){t.font=`bold ${c+2}px ${r.font.family}`,t.fillStyle=r.text;let e=[this.symbol,this.timeframe].filter(Boolean).join(` · `),n=this.statusText?`${e} ${this.statusText}`:e;t.fillText(n,u,d),d+=c+6}else this.statusText&&(t.font=`${c}px ${r.font.family}`,t.fillStyle=r.textSecondary,t.fillText(this.statusText,u,d),d+=c+4);if(this.config.showOHLC){t.font=`${c}px ${r.font.family}`;let i=a.close>=a.open,s=this.pricePrecision??(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max),f=t=>(0,e.formatPrice)(t,s,this.locale),p=[{label:`O`,value:f(a.open),color:r.text},{label:`H`,value:f(a.high),color:r.text},{label:`L`,value:f(a.low),color:r.text},{label:`C`,value:f(a.close),color:i?r.candleUp:r.candleDown}];if(this.config.showChange){let t=a.close-o.close,n=o.close===0?0:t/o.close*100,i=t>=0?`+`:``,s=(0,e.formatPrice)(n,2,this.locale);p.push({label:``,value:`${i}${f(t)} (${i}${s}%)`,color:t>=0?r.candleUp:r.candleDown})}let m=u;if(l)for(let e of p)e.label&&(t.fillStyle=r.textSecondary,t.fillText(e.label,m,d),m+=t.measureText(e.label+` `).width),t.fillStyle=e.color,t.fillText(e.value,m,d),m+=t.measureText(e.value+` `).width;else{let e=p.map(e=>`${e.label} ${e.value}`).join(` `);t.fillStyle=r.text,t.fillText(e,u,d)}d+=c+3}if(this.config.showVolume){t.font=`${c-1}px ${r.font.family}`,t.fillStyle=r.textSecondary;let e=a.volume>=1e6?`${(a.volume/1e6).toFixed(2)}M`:a.volume>=1e3?`${(a.volume/1e3).toFixed(2)}K`:a.volume.toFixed(0);t.fillText(`Vol ${e}`,u,d),d+=c+2}if(this.indicators.length>0){t.font=`${c-1}px ${r.font.family}`;let e=u;for(let n of this.indicators){t.fillStyle=n.color;let r=`${n.name} ${n.value}`;t.fillText(r,e,d),e+=t.measureText(r+` `).width}}}},fo=class{static toDataURL(e,t){let n=e.querySelectorAll(`canvas`);if(n.length===0)return``;let r=n[0],i=r.width,a=r.height,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);t&&(s.fillStyle=t,s.fillRect(0,0,i,a));let c=Array.from(n).sort((e,t)=>(parseInt(e.style.zIndex)||0)-(parseInt(t.style.zIndex)||0));for(let e of c)s.drawImage(e,0,0);return o.toDataURL(`image/png`)}static async toBlob(e,t){let n=this.toDataURL(e,t);return n?(await fetch(n)).blob():null}static download(e,t=`chart.png`,n){let r=this.toDataURL(e,n);if(!r)return;let i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}},po=class{config=null;setConfig(e){this.config=e}render(e,t,n){if(!this.config?.text)return;let{chartRect:r}=t,i=this.config.fontSize??48,a=this.config.color??n.textSecondary;e.save(),e.globalAlpha=.07,e.font=`bold ${i}px ${n.font.family}`,e.fillStyle=a,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(this.config.text,r.x+r.width/2,r.y+r.height/2),e.restore()}},mo=class{visible=!0;timeframeMs=0;setVisible(e){this.visible=e}isVisible(){return this.visible}setTimeframeMs(e){this.timeframeMs=e}render(e,t,n,r){if(!this.visible||this.timeframeMs<=0||r.length===0)return;let i=r[r.length-1],o=(i.time>0xe8d4a51000?i.time:i.time*1e3)+this.timeframeMs-Date.now();if(o<=0)return;let s=this.formatRemaining(o),c=a(r.length-1,t),l=t.chartRect.y+t.chartRect.height-4;c<t.chartRect.x||c>t.chartRect.x+t.chartRect.width||(e.font=`${n.font.sizeSmall}px ${n.font.family}`,e.textBaseline=`bottom`,e.textAlign=`center`,e.fillStyle=n.textSecondary,e.fillText(s,c,l))}formatRemaining(e){let t=Math.ceil(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}},ho=class{config={visible:!1};cachedBreaksTyped=[];cachedMedianStep=0;cacheValid=!1;lastDataLength=0;locale=`en-US`;setConfig(e){Object.assign(this.config,e)}setLocale(e){this.locale=e}isVisible(){return this.config.visible}setVisible(e){this.config.visible=e}computeBreaksTyped(e){if(e.length<2)return[];if(this.cacheValid&&e.length===this.lastDataLength)return this.cachedBreaksTyped;let t=[],n=new Date(this.toMs(e[0].time));for(let r=1;r<e.length;r++){let i=new Date(this.toMs(e[r].time));if(i.getFullYear()!==n.getFullYear())t.push({idx:r,kind:`year`,date:i});else if(i.getMonth()!==n.getMonth())t.push({idx:r,kind:`month`,date:i});else if(i.getDate()!==n.getDate()){let e=i.getDay()===1;t.push({idx:r,kind:e?`week`:`day`,date:i})}n=i}return this.lastDataLength=e.length,this.cachedBreaksTyped=t,this.cachedMedianStep=xo(e),this.cacheValid=!0,t}toMs(e){return e>0xe8d4a51000?e:e*1e3}render(e,t,n,r){if(!this.config.visible||r.length<2)return;let i=this.computeBreaksTyped(r);if(i.length===0||this.cachedMedianStep>=1380*60*1e3)return;let{chartRect:o}=t,s=this.config.color??n.axisLine,c=this.config.lineWidth??1,l=this.config.lineStyle??`dashed`;e.save(),l===`dashed`?e.setLineDash([6,4]):l===`dotted`&&e.setLineDash([2,3]),e.font=`600 11px ${n.font.family}`,e.textBaseline=`top`,e.textAlign=`left`;for(let r of i){let i=a(r.idx,t)-(t.barWidth+t.barSpacing)/2;if(i<o.x-1||i>o.x+o.width+1)continue;let l=Math.round(i)+.5,u=.25,d=c,f=null;r.kind===`day`?u=.22:r.kind===`week`?(u=.34,f=yo(r.date,this.locale)):r.kind===`month`?(u=.5,d=c+.5,f=bo(r.date,this.locale)):(u=.7,d=c+1,f=String(r.date.getFullYear())),e.globalAlpha=u,e.strokeStyle=s,e.lineWidth=d,e.beginPath(),e.moveTo(l,o.y),e.lineTo(l,o.y+o.height),e.stroke(),f&&(e.globalAlpha=Math.min(1,u+.35),e.fillStyle=n.textSecondary,e.fillText(f,l+4,o.y+4))}e.restore()}invalidateCache(){this.lastDataLength=0,this.cachedBreaksTyped=[],this.cachedMedianStep=0,this.cacheValid=!1}},go=new Map,_o=new Map;function vo(e,t,n){let r=e.get(t);return r||(r=new Intl.DateTimeFormat(t,n),e.set(t,r)),r}function yo(e,t){return vo(go,t,{month:`short`,day:`numeric`}).format(e)}function bo(e,t){return vo(_o,t,{month:`short`,year:`numeric`}).format(e)}function xo(e){if(e.length<2)return 0;let t=Math.min(50,e.length-1),n=[];for(let r=1;r<=t;r++){let t=e[r-1].time,i=e[r].time,a=t>0xe8d4a51000?t:t*1e3,o=i>0xe8d4a51000?i:i*1e3;n.push(o-a)}return n.sort((e,t)=>e-t),n[Math.floor(n.length/2)]}var So=864e5;function Co(e,t){let n=((e+t*6e4)%So+So)%So;return Math.floor(n/6e4)}function wo(e,t,n){return t===n?!0:t<n?e>=t&&e<n:e>=t||e<n}function To(e,t){let n=Co(e,t.tzOffsetMinutes);return t.windows&&t.windows.length>0?t.windows.some(e=>wo(n,e.startMinute,e.endMinute)):wo(n,t.startMinute,t.endMinute)}var Eo={startMinute:570,endMinute:960,tzOffsetMinutes:-300},Do=class{visible=!1;config={...Eo};setVisible(e){this.visible=e}isVisible(){return this.visible}setConfig(e){let t={...this.config,...e};t.windows=t.windows?t.windows.map(e=>({...e})):void 0,this.config=t}getConfig(){return{...this.config,windows:this.config.windows?.map(e=>({...e}))}}render(e,t,n,r){if(!this.visible||t.length===0)return;let{chartRect:i}=n,{from:o,to:s}=n.visibleRange,c=Math.max(0,o),l=Math.min(s,t.length-1);if(l<c)return;let u=n.barWidth+n.barSpacing,d=r.name===`light`;e.save(),e.fillStyle=d?`rgba(0,0,0,0.045)`:`rgba(0,0,0,0.28)`;let f=-1,p=(t,r)=>{let o=a(t,n)-u/2,s=a(r,n)+u/2;e.fillRect(o,i.y,s-o,i.height)};for(let e=c;e<=l;e++){let n=!To(t[e].time,this.config);n&&f===-1?f=e:!n&&f!==-1&&(p(f,e-1),f=-1)}f!==-1&&p(f,l),e.restore()}},Oo=1,ko=class extends K{alerts=[];lastValues=new Map;requestRender=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setPricePrecision(e){this.pricePrecision=e}addAlert(e,t=`crossing`,n,r=!1,i=`price`,a){let o=`tc_alert_${Oo++}`,s={id:o,price:e,condition:t,message:n,triggered:!1,repeating:r,channel:i,label:a};return this.alerts.push(s),this.emit(`added`,s),this.requestRender?.(),o}removeAlert(e){this.alerts=this.alerts.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getAlerts(){return[...this.alerts]}getAlertAtPoint(e,t,n=6){let{chartRect:r}=t;if(e.y<r.y||e.y>r.y+r.height)return null;let i=null,a=n;for(let n of this.alerts){if(n.channel!==`price`)continue;let r=Math.abs(o(n.price,t)-e.y);r<=a&&(a=r,i=n)}return i}updateAlertPrice(e,t){let n=this.alerts.find(t=>t.id===e);!n||!Number.isFinite(t)||(n.price=t,n.triggered=!1,this.emit(`updated`,{...n}),this.requestRender?.())}clearAlerts(){this.alerts=[],this.requestRender?.()}checkPrice(e){this.checkChannel(`price`,e)}checkChannel(e,t){if(!Number.isFinite(t))return;let n=this.lastValues.get(e);if(n===void 0){this.lastValues.set(e,t);return}for(let r of this.alerts){if(r.channel!==e)continue;let i=!1;switch(r.condition){case`crossingUp`:i=n<r.price&&t>=r.price;break;case`crossingDown`:i=n>r.price&&t<=r.price;break;case`crossing`:i=n<r.price&&t>=r.price||n>r.price&&t<=r.price;break;case`greaterThan`:i=t>r.price;break;case`lessThan`:i=t<r.price;break}i?r.triggered||(r.triggered=!0,this.emit(`triggered`,{...r})):r.repeating&&(r.triggered=!1)}this.lastValues.set(e,t)}clearLastValues(){this.lastValues.clear()}saveToStorage(e){try{let t=this.alerts.map(e=>({id:e.id,price:e.price,condition:e.condition,message:e.message,triggered:e.triggered,repeating:e.repeating,channel:e.channel,label:e.label}));localStorage.setItem(e,JSON.stringify(t))}catch{}}loadFromStorage(e){try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);if(!Array.isArray(n))return;for(let e of n)e.price!=null&&Number.isFinite(e.price)&&e.condition&&!e.triggered&&this.addAlert(e.price,e.condition,e.message,e.repeating??!1,e.channel??`price`,e.label)}catch{}}render(e,t,n){let{chartRect:r}=t;for(let i of this.alerts){if(i.channel!==`price`)continue;let a=o(i.price,t);if(a<r.y||a>r.y+r.height)continue;let s=i.triggered?`#f2a93b`:`#4c8dff`;e.setLineDash([2,6]),e.strokeStyle=s,e.lineWidth=1,e.beginPath(),e.moveTo(r.x,Math.round(a)+.5),e.lineTo(r.x+r.width,Math.round(a)+.5),e.stroke(),e.setLineDash([]),e.font=`10px ${n.font.family}`,e.fillStyle=s,e.textBaseline=`bottom`,e.textAlign=`right`;let c=`🔔 ${i.price.toFixed(this.pricePrecision)}${i.message?` - ${i.message}`:``}`;e.fillText(c,r.x+r.width-4,a-2)}}},Ao=class extends K{data=[];cursor=-1;timer=null;state=`stopped`;config={speed:1,interval:500};load(e){this.stop(),this.data=e,this.cursor=-1}play(e){if(this.data.length!==0){if(e){let{startIndex:t,paused:n,...r}=e;Object.assign(this.config,r);let i=t===void 0?null:this.clamp(t);if(n){this.clearTimer(),this.seekTo(i??Math.max(0,this.cursor)),this.setState(`paused`);return}i!==null&&(this.cursor=i-1)}if(this.isAtEnd()){this.clearTimer(),this.setState(`paused`);return}this.clearTimer(),this.setState(`playing`),this.timer=setInterval(()=>this.tick(),this.config.interval/this.config.speed)}}pause(){this.clearTimer(),this.setState(`paused`)}resume(){this.state===`paused`&&this.play()}stop(){this.clearTimer(),this.cursor=-1,this.setState(`stopped`)}seekTo(e){this.data.length!==0&&(this.cursor=this.clamp(e),this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}))}setSpeed(e){this.config.speed=e,this.state===`playing`&&this.play()}getState(){return this.state}isAtEnd(){return this.data.length>0&&this.cursor>=this.data.length-1}getProgress(){let e=this.data.length;return{current:Math.max(0,this.cursor),total:e,percent:e>0?(this.cursor+1)/e*100:0}}dispose(){this.stop(),this.removeAllListeners(),this.data=[]}tick(){if(this.isAtEnd()){this.clearTimer(),this.setState(`paused`),this.emit(`complete`,void 0);return}this.cursor++,this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}),this.isAtEnd()&&(this.clearTimer(),this.setState(`paused`),this.emit(`complete`,void 0))}clamp(e){return Number.isFinite(e)?Math.max(0,Math.min(Math.floor(e),this.data.length-1)):0}clearTimer(){this.timer&&=(clearInterval(this.timer),null)}setState(e){this.state!==e&&(this.state=e,this.emit(`stateChange`,e))}},jo=2,Mo=2;function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e){return Array.isArray(e)?e:[]}function No(e,t){return typeof e==`string`?e:t}function Po(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function Fo(e){if(!X(e)||typeof e.id!=`string`||typeof e.type!=`string`||!Array.isArray(e.anchors)||e.anchors.length===0||!X(e.style))return null;let t=[];for(let n of e.anchors){if(!X(n)||typeof n.time!=`number`||typeof n.price!=`number`||!Number.isFinite(n.time)||!Number.isFinite(n.price))return null;t.push({time:n.time,price:n.price})}let n=e.style;return typeof n.color!=`string`||typeof n.lineWidth!=`number`?null:{id:e.id,type:e.type,anchors:t,style:n,visible:typeof e.visible==`boolean`?e.visible:!0,locked:typeof e.locked==`boolean`?e.locked:!1,meta:X(e.meta)?e.meta:void 0}}function Io(e){return!X(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.type!=`string`||typeof e.price!=`number`||typeof e.quantity!=`number`?null:e}function Lo(e){if(!X(e))return;let t={},n=Z(e.colors).filter(e=>typeof e==`string`);n.length>0&&(t.colors=n);let r=Z(e.lineWidths).filter(e=>typeof e==`number`&&Number.isFinite(e)&&e>0);return r.length>0&&(t.lineWidths=r),typeof e.opacity==`number`&&Number.isFinite(e.opacity)&&(t.opacity=Math.min(1,Math.max(0,e.opacity))),Object.keys(t).length>0?t:void 0}var Ro=[`crossingUp`,`crossingDown`,`crossing`,`greaterThan`,`lessThan`];function zo(e){return!X(e)||typeof e.id!=`string`||typeof e.price!=`number`||!Number.isFinite(e.price)?null:{id:e.id,price:e.price,condition:Ro.find(t=>t===e.condition)??`crossing`,message:typeof e.message==`string`?e.message:void 0,triggered:e.triggered===!0,repeating:e.repeating===!0,channel:No(e.channel,`price`),label:typeof e.label==`string`?e.label:void 0}}function Bo(e){return!X(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.entryPrice!=`number`||typeof e.quantity!=`number`?null:e}function Vo(e){if(!X(e))return Ho();typeof e.version==`number`&&e.version>Mo&&console.warn(`Chart state from a newer version (${e.version}); loading what this version understands.`);let t=X(e.viewport)?e.viewport:{},n=[];for(let t of Z(e.indicators))X(t)&&(typeof t.id!=`string`||typeof t.instanceId!=`string`||X(t.params)&&n.push({id:t.id,instanceId:t.instanceId,params:t.params,position:typeof t.position==`string`?t.position:void 0,style:Lo(t.style),visible:typeof t.visible==`boolean`?t.visible:void 0}));let r=[];for(let t of Z(e.drawings)){let e=Fo(t);e&&r.push(e)}let i=[];for(let t of Z(e.orders)){let e=Io(t);e&&i.push(e)}let a=[];for(let t of Z(e.positions)){let e=Bo(t);e&&a.push(e)}let o=[];for(let t of Z(e.alerts)){let e=zo(t);e&&o.push(e)}return{version:typeof e.version==`number`&&Array.isArray(e.indicators)?e.version:1,timestamp:Po(e.timestamp,Date.now()),symbol:typeof e.symbol==`string`?e.symbol:void 0,timeframe:typeof e.timeframe==`string`?e.timeframe:void 0,chartType:No(e.chartType,`candlestick`),viewport:{barWidth:Po(t.barWidth,8),barSpacing:Po(t.barSpacing,2),offset:Po(t.offset,0)},theme:typeof e.theme==`string`?e.theme:void 0,locale:typeof e.locale==`string`?e.locale:void 0,indicators:n,drawings:r,orders:i,positions:a,alerts:o}}function Ho(){return{version:1,timestamp:Date.now(),chartType:`candlestick`,viewport:{barWidth:8,barSpacing:2,offset:0},indicators:[],drawings:[],orders:[],positions:[],alerts:[]}}var Uo=class{static capture(e,t){return{version:e.getIndicators?Mo:1,timestamp:Date.now(),chartType:t?.chartType??`candlestick`,symbol:t?.symbol,timeframe:t?.timeframe,viewport:{barWidth:8,barSpacing:2,offset:0},theme:e.getTheme().name,indicators:e.getIndicators?.()??[],drawings:e.getDrawings(),orders:e.getOrders?.()??[],positions:e.getPositions?.()??[],alerts:e.getAlerts?.()??[]}}static serialize(e){return JSON.stringify(e)}static deserialize(e){return Vo(JSON.parse(e))}static saveToStorage(e,t){localStorage.setItem(e,this.serialize(t))}static loadFromStorage(e){let t=localStorage.getItem(e);return t?this.deserialize(t):null}static downloadFile(e,t=`tc-chart-state.json`){let n=new Blob([this.serialize(e)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}static loadFromFile(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async()=>{let r=n.files?.[0];if(!r){t(Error(`No file selected`));return}let i=await r.text();e(this.deserialize(i))},n.click()})}},Wo=class{undoStack=[];redoStack=[];maxHistory=50;onChange=null;setOnChange(e){this.onChange=e}push(e){this.undoStack.push(e),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack.length=0,this.onChange?.()}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){let e=this.undoStack.pop();return e?(this.redoStack.push(e),this.onChange?.(),e):null}redo(){let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.onChange?.(),e):null}clear(){this.undoStack.length=0,this.redoStack.length=0}getState(){return{canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoCount:this.undoStack.length,redoCount:this.redoStack.length}}},Go=class{static toCSV(e){return[`Time,Open,High,Low,Close,Volume`,...e.map(e=>`${new Date(e.time).toISOString()},${e.open},${e.high},${e.low},${e.close},${e.volume}`)].join(`
|
|
25
|
-
`)}static toJSON(e){return JSON.stringify(e.map(e=>({time:new Date(e.time).toISOString(),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume})),null,2)}static download(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}},Ko=1,qo=class extends K{markers=[];style={...e.DEFAULT_SIGNAL_STYLE};requestRender=null;dataGetter=null;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addMarker(e){let t=e.id??`tc_signal_${Ko++}`,n={...e,id:t};return this.markers.push(n),this.emit(`added`,n),this.requestRender?.(),t}removeMarker(e){this.markers=this.markers.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getMarkers(){return[...this.markers]}clearMarkers(){this.markers=[],this.emit(`cleared`,void 0),this.requestRender?.()}setMarkers(e){this.markers=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.markers.length===0)return;let{chartRect:i}=t,s=this.style,c=s.arrowSize??12;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let l of this.markers){let u=a(h(l.time,r),t),d=o(l.price,t);if(u<i.x-c||u>i.x+i.width+c||d<i.y-c||d>i.y+i.height+c)continue;let f=this.resolveColor(l,s),p=c*Math.max(.6,Math.min(1,l.confidence));if(this.renderArrow(e,u,d,l.direction,p,f),s.showLabel&&l.label){e.font=`10px ${n.font.family}`,e.fillStyle=f,e.textAlign=`center`,e.textBaseline=l.direction===`long`?`top`:`bottom`;let t=l.direction===`long`?d+p+3:d-p-3;e.fillText(l.label,u,t)}if(s.showConfidence&&l.confidence<1){e.font=`9px ${n.font.family}`,e.fillStyle=f,e.globalAlpha=.7,e.textAlign=`center`,e.textBaseline=l.direction===`long`?`top`:`bottom`;let t=l.direction===`long`?d+p+(l.label?14:3):d-p-(l.label?14:3);e.fillText(`${Math.round(l.confidence*100)}%`,u,t),e.globalAlpha=1}}e.restore()}resolveColor(e,t){if(e.color)return e.color;if(t.sourceColors?.[e.source])return t.sourceColors[e.source];switch(e.direction){case`long`:return t.longColor??`#1fa874`;case`short`:return t.shortColor??`#e8505b`;default:return t.neutralColor??`#9E9E9E`}}renderArrow(e,t,n,r,i,a){e.fillStyle=a,e.beginPath(),r===`long`?(e.moveTo(t,n-i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n+i*.4),e.lineTo(t+i*.2,n+i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):r===`short`?(e.moveTo(t,n+i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n-i*.4),e.lineTo(t+i*.2,n-i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):e.arc(t,n,i*.4,0,Math.PI*2),e.closePath(),e.fill()}},Jo=1,Yo=class extends K{zones=[];style={...e.DEFAULT_TRADE_ZONE_STYLE};requestRender=null;dataGetter=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setPricePrecision(e){this.pricePrecision=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addZone(e){let t=e.id??`tc_zone_${Jo++}`,n={...e,id:t};return this.zones.push(n),this.emit(`added`,n),this.requestRender?.(),t}updateZone(e,t){let n=this.zones.findIndex(t=>t.id===e);n!==-1&&(this.zones[n]={...this.zones[n],...t},this.requestRender?.())}removeZone(e){this.zones=this.zones.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getZones(){return[...this.zones]}clearZones(){this.zones=[],this.emit(`cleared`,void 0),this.requestRender?.()}setZones(e){this.zones=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.zones.length===0)return;let{chartRect:i}=t,a=this.style;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.zones)this.renderZone(e,i,r,t,n,a);e.restore()}renderZone(e,t,n,r,i,s){let{chartRect:c}=r,l=h(t.entryTime,n),u=t.exitTime==null?n.length-1:h(t.exitTime,n),d=a(l,r),f=a(u,r),p=Math.max(c.x,Math.min(d,f)),m=Math.min(c.x+c.width,Math.max(d,f));if(m-p<1)return;let g=o(t.entryPrice,r),_=t.exitPrice==null?o(t.entryPrice,r):o(t.exitPrice,r),v=Math.min(g,_),y=Math.max(Math.max(g,_)-v,2),b=t.exitTime==null,x=t.pnl==null?t.direction===`long`?(t.exitPrice??t.entryPrice)>=t.entryPrice:(t.exitPrice??t.entryPrice)<=t.entryPrice:t.pnl>=0,S=b?s.activeColor??`#4c8dff`:x?s.profitColor??`#1fa874`:s.lossColor??`#e8505b`;e.fillStyle=S,e.globalAlpha=s.fillOpacity??.12,e.fillRect(p,v,m-p,y),e.globalAlpha=1;let C=s.borderWidth??1;e.strokeStyle=S,e.lineWidth=C,e.setLineDash([]),e.beginPath(),e.moveTo(p,Math.round(g)+.5),e.lineTo(m,Math.round(g)+.5),e.stroke(),!b&&t.exitPrice!=null&&(e.setLineDash([3,3]),e.beginPath(),e.moveTo(p,Math.round(_)+.5),e.lineTo(m,Math.round(_)+.5),e.stroke(),e.setLineDash([]));let w=t.direction===`long`?`▲`:`▼`;if(e.font=`bold 10px ${i.font.family}`,e.fillStyle=S,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(`${w} ${t.entryPrice.toFixed(this.pricePrecision)}`,p+4,g-3),s.showPnl&&!b&&t.pnl!=null){let n=t.pnl>=0?`+`:``,r=t.pnlPercent==null?`${n}${t.pnl.toFixed(2)}`:`${n}${t.pnl.toFixed(2)} (${n}${t.pnlPercent.toFixed(2)}%)`;e.font=`bold 10px ${i.font.family}`,e.fillStyle=S,e.textBaseline=`top`,e.textAlign=`right`;let a=e.measureText(r).width+8,o=m-a-2,s=v+2;e.globalAlpha=.85,e.fillStyle=i.background,e.fillRect(o,s,a,14),e.globalAlpha=1,e.fillStyle=S,e.fillText(r,m-4,s+1)}s.showLabel&&t.label&&(e.font=`9px ${i.font.family}`,e.fillStyle=S,e.globalAlpha=.8,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(t.label,p+4,g+3),e.globalAlpha=1)}},Xo=class{active=!1;startBar=0;startPrice=0;endBar=0;endPrice=0;startTime=null;endTime=null;isActive(){return this.active}begin(e,t,n){let r=Math.round(l(e.x,t)),i=u(e.y,t);this.startBar=r,this.startPrice=i,this.endBar=r,this.endPrice=i,this.startTime=Zo(r,n),this.endTime=this.startTime,this.active=!0}update(e,t,n){if(!this.active)return;let r=Math.round(l(e.x,t));this.endBar=r,this.endPrice=u(e.y,t),this.endTime=Zo(r,n)}end(){this.active=!1}render(e,t,n){if(!this.active)return;let r=a(this.startBar,t),i=a(this.endBar,t),s=o(this.startPrice,t),c=o(this.endPrice,t),l=Math.min(r,i),u=Math.max(r,i),d=Math.min(s,c),f=Math.max(s,c),p=u-l,m=f-d,h=this.endPrice>=this.startPrice?n.candleUp:n.candleDown,g=rs(h,.14);e.save();let{chartRect:_}=t;e.beginPath(),e.rect(_.x,_.y,_.width,_.height),e.clip(),e.fillStyle=g,e.fillRect(l,d,p,m),e.strokeStyle=h,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(l+.5,d+.5,p,m),e.setLineDash([]),e.strokeStyle=h,e.lineWidth=1.5,e.beginPath(),e.moveTo(r,s),e.lineTo(i,c),e.stroke(),es(e,r,s,h),es(e,i,c,h),e.restore();let v=Math.abs(this.endBar-this.startBar),y=this.endPrice-this.startPrice,b=this.startPrice===0?0:y/this.startPrice*100,x=this.startTime!==null&&this.endTime!==null?$o(Math.abs(this.endTime-this.startTime)):null,S=[],C=y>0?`+`:y<0?`−`:``,w=Math.abs(y);S.push(`${C}${Qo(w)} (${C}${Math.abs(b).toFixed(2)}%)`),S.push(`${v} bars${x?` · `+x:``}`),e.save(),ts(e,i,c,S,h,n),e.restore()}};function Zo(e,t){if(e<0||e>=t.length)return null;let n=t[e].time;return n>0xe8d4a51000?n:n*1e3}function Qo(e){return e>=1e3?e.toFixed(2):e>=1?e.toFixed(4):e.toPrecision(4)}function $o(e){let t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;let n=t/60;if(n<60)return`${n.toFixed(1)}m`;let r=n/60;if(r<24)return`${r.toFixed(1)}h`;let i=r/24;if(i<30)return`${i.toFixed(1)}d`;let a=i/30;return a<12?`${a.toFixed(1)}mo`:`${(i/365).toFixed(1)}y`}function es(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t,n,3.5,0,Math.PI*2),e.fill(),e.fillStyle=`#fff`,e.beginPath(),e.arc(t,n,1.5,0,Math.PI*2),e.fill()}function ts(e,t,n,r,i,a){e.font=`600 11px ${a.font.family}`;let o=0;for(let t of r){let n=e.measureText(t).width;n>o&&(o=n)}let s=Math.ceil(o)+16,c=r.length*14+12,l=t+8,u=n+8,d=e.canvas.clientWidth||e.canvas.width;l+s>d-4&&(l=t-s-8),l<4&&(l=4),e.fillStyle=a.background,e.globalAlpha=.96,ns(e,l,u,s,c,6),e.fill(),e.globalAlpha=1,e.strokeStyle=i,e.lineWidth=1,ns(e,l+.5,u+.5,s-1,c-1,6),e.stroke(),e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<r.length;t++)e.fillStyle=t===0?i:a.textSecondary,e.fillText(r[t],l+8,u+6+t*14)}function ns(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function rs(e,t){if(e.startsWith(`#`)){let n=0,r=0,i=0;return e.length===4?(n=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16),i=parseInt(e[3]+e[3],16)):e.length>=7&&(n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16)),`rgba(${n},${r},${i},${t})`}if(e.startsWith(`rgb`)){let n=e.match(/[\d.]+/g);if(n&&n.length>=3)return`rgba(${n[0]},${n[1]},${n[2]},${t})`}return e}var is=6,as=class{start=null;current=null;isActive(){return this.start!==null}begin(e){this.start=e,this.current=e}update(e){this.start&&(this.current=e)}end(){let e=this.start,t=this.current;if(this.cancel(),!e||!t)return null;let n=Math.min(e.x,t.x),r=Math.max(e.x,t.x),i=Math.min(e.y,t.y),a=Math.max(e.y,t.y);return{x0:n,y0:i,x1:r,y1:a,isClick:r-n<6&&a-i<6}}cancel(){this.start=null,this.current=null}render(e,t,n){if(!this.start||!this.current)return;let{chartRect:r}=t,i=e=>Math.max(r.x,Math.min(r.x+r.width,e)),a=e=>Math.max(r.y,Math.min(r.y+r.height,e)),o=i(Math.min(this.start.x,this.current.x)),s=i(Math.max(this.start.x,this.current.x)),c=a(Math.min(this.start.y,this.current.y)),l=a(Math.max(this.start.y,this.current.y));e.save(),e.fillStyle=n.crosshair,e.globalAlpha=.1,e.fillRect(o,c,s-o,l-c),e.globalAlpha=.8,e.strokeStyle=n.crosshair,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(Math.round(o)+.5,Math.round(c)+.5,Math.round(s-o),Math.round(l-c)),e.restore()}},os={linear:e=>e,easeOutCubic:e=>1-(1-e)**3,easeOutQuart:e=>1-(1-e)**4,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeOutExpo:e=>e===1?1:1-2**(-10*e),easeOutElastic:e=>e===0||e===1?e:2**(-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,spring:e=>1-Math.E**(-6*e)*Math.cos(8*e)},ss=class{animations=new Map;frameId=0;running=!1;animate(e,t){this.animations.set(e,{startTime:-1,duration:t.duration,easing:t.easing??os.easeOutCubic,onUpdate:t.onUpdate,onComplete:t.onComplete}),this.running||(this.running=!0,this.tick())}cancel(e){this.animations.delete(e),this.animations.size===0&&this.stop()}cancelAll(){this.animations.clear(),this.stop()}isAnimating(e){return e?this.animations.has(e):this.animations.size>0}tick(){this.frameId=requestAnimationFrame(e=>{let t=[];for(let[n,r]of this.animations){r.startTime<0&&(r.startTime=e);let i=e-r.startTime,a=Math.min(1,i/r.duration),o=r.easing(a);r.onUpdate(o),a>=1&&(r.onComplete?.(),t.push(n))}for(let e of t)this.animations.delete(e);this.animations.size>0?this.tick():this.running=!1})}stop(){this.frameId&&=(cancelAnimationFrame(this.frameId),0),this.running=!1}dispose(){this.cancelAll()}};function cs(t){return!t||t===`dark`?e.DARK_THEME:t===`light`?e.LIGHT_THEME:t}var ls=class{canvas;ctx;container;theme;width=0;height=0;dpr=1;frameId=null;resizeObserver;constructor(e,t){this.container=e,this.theme=cs(t),this.canvas=document.createElement(`canvas`),this.canvas.style.width=`100%`,this.canvas.style.height=`100%`,this.canvas.style.display=`block`,e.appendChild(this.canvas),this.ctx=this.canvas.getContext(`2d`),this.dpr=window.devicePixelRatio||1,this.updateSize(),this.resizeObserver=new ResizeObserver(()=>{this.updateSize(),this.requestRender()}),this.resizeObserver.observe(e)}updateSize(){this.dpr=window.devicePixelRatio||1;let e=this.container.getBoundingClientRect();this.width=e.width||this.container.clientWidth,this.height=e.height||this.container.clientHeight,this.canvas.width=Math.max(1,Math.floor(this.width*this.dpr)),this.canvas.height=Math.max(1,Math.floor(this.height*this.dpr))}requestRender(){this.frameId===null&&(this.frameId=requestAnimationFrame(()=>{this.frameId=null,(this.width===0||this.height===0)&&this.updateSize(),!(this.width===0||this.height===0)&&(this.ctx.save(),this.ctx.scale(this.dpr,this.dpr),this.ctx.clearRect(0,0,this.width,this.height),this.renderChart(this.ctx,this.width,this.height,this.theme),this.ctx.restore())}))}setTheme(e){this.theme=cs(e),this.requestRender()}destroy(){this.frameId!==null&&cancelAnimationFrame(this.frameId),this.resizeObserver.disconnect(),this.canvas.remove()}},us=class{pos=null;canvas;onUpdate;handleMove;handleLeave;constructor(e,t){this.canvas=e,this.onUpdate=t,this.handleMove=t=>{let n=e.getBoundingClientRect();this.pos={x:t.clientX-n.left,y:t.clientY-n.top},this.onUpdate()},this.handleLeave=()=>{this.pos=null,this.onUpdate()},e.addEventListener(`pointermove`,this.handleMove),e.addEventListener(`pointerleave`,this.handleLeave)}getPosition(){return this.pos}isActive(){return this.pos!==null}drawCrosshair(e,t,n,r){this.pos&&(e.save(),e.strokeStyle=r,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(this.pos.x,0),e.lineTo(this.pos.x,n),e.stroke(),e.beginPath(),e.moveTo(0,this.pos.y),e.lineTo(t,this.pos.y),e.stroke(),e.restore())}destroy(){this.canvas.removeEventListener(`pointermove`,this.handleMove),this.canvas.removeEventListener(`pointerleave`,this.handleLeave)}};function ds(e,t,n,r,i){let{data:a,mode:o=`area`,lineWidth:s=1.5,showLastPoint:c=!1,showMinMax:l=!1}=r;if(a.length<2||t<=0||n<=0)return;let u=r.color??i.lineColor,d=r.fillColor??u,f=t-4,p=n-4,m=1/0,h=-1/0,g=0,_=0;for(let e=0;e<a.length;e++)a[e]<m&&(m=a[e],g=e),a[e]>h&&(h=a[e],_=e);let v=h-m||1,y=e=>2+e/(a.length-1)*f,b=e=>2+p-(e-m)/v*p;if(o===`area`){let t=e.createLinearGradient(0,2,0,n-2);t.addColorStop(0,d+(d.startsWith(`#`)?`40`:``)),t.addColorStop(1,`transparent`),e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));e.lineTo(y(a.length-1),n-2),e.lineTo(y(0),n-2),e.closePath(),e.fillStyle=t,e.fill()}e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));if(e.strokeStyle=u,e.lineWidth=s,e.lineJoin=`round`,e.stroke(),c){let t=r.lastPointColor??u,n=y(a.length-1),i=b(a[a.length-1]);e.beginPath(),e.arc(n,i,3,0,Math.PI*2),e.fillStyle=t,e.fill()}if(l){let t=r.minPointColor??i.candleDown,n=r.maxPointColor??i.candleUp;e.beginPath(),e.arc(y(g),b(m),2.5,0,Math.PI*2),e.fillStyle=t,e.fill(),e.beginPath(),e.arc(y(_),b(h),2.5,0,Math.PI*2),e.fillStyle=n,e.fill()}}var fs=50,ps=60,ms=20,hs=.2;function gs(e){let t=[...e].sort((e,t)=>t.price-e.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function _s(e){let t=[...e].sort((e,t)=>e.price-t.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function vs(e,t){return{left:fs,right:e-ps,top:ms,bottom:t-ms,plotWidth:e-fs-ps,plotHeight:t-ms*2}}function ys(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function bs(t,n,r,i,a,o,s,c){let{left:l,right:u,top:d,bottom:f,plotWidth:p,plotHeight:m}=n;t.save(),t.strokeStyle=o.grid,t.lineWidth=.5,t.fillStyle=o.axisLabel,t.font=`${o.font.sizeSmall}px ${o.font.family}`;let h=(0,e.computeTickStep)(0,a,5);for(let e=0;e<=a;e+=h){let n=f-e/a*m;t.beginPath(),t.moveTo(l,n),t.lineTo(u,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),l-4,n)}let g=i-r,_=(0,e.computeTickStep)(r,i,6),v=Math.ceil(r/_)*_;for(let e=v;e<=i;e+=_){let n=l+(e-r)/g*p;t.beginPath(),t.moveTo(n,d),t.lineTo(n,f),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(s(e),n,f+4)}t.restore()}function xs(e,t,n,r,i,a,o,s,c){if(t.length===0)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-e/a*f;if(e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}else{e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}if(e.closePath(),e.fillStyle=o,e.fill(),e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);n>0&&e.lineTo(r,m(t[n-1].cumulativeVolume)),e.lineTo(r,i)}}else{e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=1;n<t.length;n++){let r=m(t[n-1].cumulativeVolume),i=p(t[n].price),a=m(t[n].cumulativeVolume);e.lineTo(i,r),e.lineTo(i,a)}}e.strokeStyle=s,e.lineWidth=1.5,e.stroke()}function Ss(e,t,n,r,i,a,o,s,c){let{left:l,top:u,bottom:d,plotWidth:f}=r,p=l+(t-i)/a*f;if(e.save(),e.strokeStyle=o.textSecondary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(p,u),e.lineTo(p,d),e.stroke(),e.restore(),s){let t=`Spread: ${c(n)}`;e.save(),e.font=`${o.font.sizeSmall}px ${o.font.family}`,e.fillStyle=o.textSecondary,e.textAlign=`center`,e.textBaseline=`bottom`,e.fillText(t,p,u-2),e.restore()}}function Cs(e,t,n,r,i,a,o,s,c,l,u){let{left:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=i,g=t.x;if(g<d||g>i.right)return;let _=a+(g-d)/m*o,v=0,y=``;if(n.length>0&&_<=n[0].price){y=`Bid`;for(let e of n)if(_<=e.price)v=e.cumulativeVolume;else break}if(r.length>0&&_>=r[0].price){y=`Ask`;for(let e of r)if(_>=e.price)v=e.cumulativeVolume;else break}if(e.save(),e.strokeStyle=c.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(g,f),e.lineTo(g,p),e.stroke(),v>0){let t=p-v/s*h;e.beginPath(),e.moveTo(d,t),e.lineTo(i.right,t),e.stroke()}e.restore();let b=[`Price: ${l(_)}`,y?`${y} Vol: ${u(v)}`:``].filter(Boolean);e.save(),e.font=`${c.font.sizeSmall}px ${c.font.family}`;let x=Math.max(...b.map(t=>e.measureText(t).width))+16,S=b.length*(c.font.sizeSmall+4)+12,C=g+10,w=t.y-S/2;C+x>i.right&&(C=g-x-10),w<f&&(w=f),w+S>p&&(w=p-S),e.fillStyle=c.axisLabelBackground,e.globalAlpha=.9,e.fillRect(C,w,x,S),e.globalAlpha=1,e.fillStyle=c.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<b.length;t++)e.fillText(b[t],C+8,w+6+t*(c.font.sizeSmall+4));e.restore()}function ws(e){return e.toFixed(2)}function Ts(e){return e>=1e6?(e/1e6).toFixed(2)+`M`:e>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(0)}function Es(e,t,n,r,i,a){let{data:o}=r;if(o.bids.length===0&&o.asks.length===0||t<=0||n<=0)return;let s=r.bidColor??i.candleUp,c=r.askColor??i.candleDown,l=r.bidFillColor??s+`40`,u=r.askFillColor??c+`40`,d=r.midPriceLine!==!1,f=r.spreadLabel!==!1,p=r.priceFormat??ws,m=r.volumeFormat??Ts,h=gs(o.bids),g=_s(o.asks),_=h.length>0?h[0].price:0,v=g.length>0?g[0].price:0,y=h.length>0&&g.length>0?(_+v)/2:_||v,b=g.length>0&&h.length>0?v-_:0,x=h.length>0?h[h.length-1].price:y,S=g.length>0?g[g.length-1].price:y,C=Math.max(y-x,S-y)*(1+hs),w=y-C,T=y+C,E=T-w,D=h.length>0?h[h.length-1].cumulativeVolume:0,O=g.length>0?g[g.length-1].cumulativeVolume:0,k=Math.max(D,O)||1,A=vs(t,n);ys(e,t,n,i.background),bs(e,A,w,T,k,i,p,m),xs(e,h,A,w,E,k,l,s,`bid`),xs(e,g,A,w,E,k,u,c,`ask`),d&&Ss(e,y,b,A,w,E,i,f,p),a&&Cs(e,a,h,g,A,w,E,k,i,p,m)}var Ds=70,Os=30,ks=20,As=20,js=.05;function Ms(e,t){return{left:Ds,right:e-ks,top:As,bottom:t-Os,plotWidth:e-Ds-ks,plotHeight:t-As-Os}}function Ns(e,t){let n=1/0,r=-1/0;for(let t of e)t.value<n&&(n=t.value),t.value>r&&(r=t.value);if(t)for(let e of t)e.value<n&&(n=e.value),e.value>r&&(r=e.value);let i=(r-n)*js;return{valMin:n-i,valMax:r+i}}function Ps(e){let t=[],n=-1/0;for(let r of e)r.value>n&&(n=r.value),t.push(n);return t}function Fs(e){let t=864e5;if(365.25*t,e<7*t){let e=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`});return t=>e.format(new Date(t))}if(e<315576e5){let e=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`});return t=>e.format(new Date(t))}let n=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});return e=>n.format(new Date(e))}function Is(e){return Math.abs(e)>=1e6?(e/1e6).toFixed(2)+`M`:Math.abs(e)>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function Ls(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function Rs(t,n,r,i,a,o,s,c,l){let{left:u,right:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=n;t.save(),t.strokeStyle=s.grid,t.lineWidth=.5,t.fillStyle=s.axisLabel,t.font=`${s.font.sizeSmall}px ${s.font.family}`;let g=(0,e.computeTickStep)(r,i,6),_=Math.ceil(r/g)*g;for(let e=_;e<=i;e+=g){let n=p-(e-r)/(i-r)*h;t.beginPath(),t.moveTo(u,n),t.lineTo(d,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),u-6,n)}let v=o-a,y=(0,e.computeTickStep)(a,o,6),b=Math.ceil(a/y)*y;for(let e=b;e<=o;e+=y){let n=u+(e-a)/v*m;t.beginPath(),t.moveTo(n,f),t.lineTo(n,p),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(l(e),n,p+4)}t.restore()}function zs(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-(e-a)/o*f;e.save(),e.beginPath(),e.moveTo(p(t[0].time),m(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(p(t[n].time),m(t[n].value));e.strokeStyle=s,e.lineWidth=c,e.lineJoin=`round`,e.stroke(),e.restore()}function Bs(e,t,n,r,i,a,o,s){if(t.length<2)return;let{left:c,bottom:l,plotWidth:u,plotHeight:d}=n,f=e=>c+(e-r)/i*u,p=e=>l-(e-a)/o*d,m=e.createLinearGradient(0,n.top,0,l);m.addColorStop(0,s+`40`),m.addColorStop(1,`transparent`),e.save(),e.beginPath(),e.moveTo(f(t[0].time),p(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(f(t[n].time),p(t[n].value));e.lineTo(f(t[t.length-1].time),l),e.lineTo(f(t[0].time),l),e.closePath(),e.fillStyle=m,e.fill(),e.restore()}function Vs(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=r,p=e=>l+(e-i)/a*d,m=e=>u-(e-o)/s*f;e.save(),e.fillStyle=c,e.beginPath(),e.moveTo(p(t[0].time),m(n[0]));for(let r=1;r<t.length;r++)e.lineTo(p(t[r].time),m(n[r]));for(let n=t.length-1;n>=0;n--)e.lineTo(p(t[n].time),m(t[n].value));e.closePath(),e.fill(),e.restore()}function Hs(e,t,n,r,i,a,o,s,c,l){if(t.length===0)return;let{left:u,bottom:d,plotWidth:f,plotHeight:p}=n,m=t[t.length-1],h=u+(m.time-r)/i*f,g=d-(m.value-a)/o*p;e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`,e.fillStyle=c,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(s,h+4,g),e.restore()}function Us(e,t,n,r,i,a,o,s,c,l,u,d){let{left:f,top:p,bottom:m,plotWidth:h,plotHeight:g}=i,_=t.x;if(_<f||_>i.right)return;e.save(),e.strokeStyle=l.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(_,p),e.lineTo(_,m),e.stroke(),e.restore();let v=a+(_-f)/h*o,y=0,b=1/0;for(let e=0;e<n.length;e++){let t=Math.abs(n[e].time-v);t<b&&(b=t,y=e)}let x=n[y],S=[u(x.time),`Value: ${d(x.value)}`];r&&r.length>y&&S.push(`Benchmark: ${d(r[y].value)}`);let C=f+(x.time-a)/o*h,w=m-(x.value-s)/c*g;e.beginPath(),e.arc(C,w,3,0,Math.PI*2),e.fillStyle=l.lineColor,e.fill(),e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`;let T=Math.max(...S.map(t=>e.measureText(t).width))+16,E=S.length*(l.font.sizeSmall+4)+12,D=_+10,O=t.y-E/2;D+T>i.right&&(D=_-T-10),O<p&&(O=p),O+E>m&&(O=m-E),e.fillStyle=l.axisLabelBackground,e.globalAlpha=.9,e.fillRect(D,O,T,E),e.globalAlpha=1,e.fillStyle=l.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<S.length;t++)e.fillText(S[t],D+8,O+6+t*(l.font.sizeSmall+4));e.restore()}function Ws(e,t,n,r,i,a){let{data:o}=r;if(o.length<2||t<=0||n<=0)return;let s=r.lineColor??i.lineColor,c=r.lineWidth??1.5,l=r.drawdown===!0,u=r.drawdownColor??i.candleDown+`30`,d=r.fillArea===!0,f=r.benchmark,p=r.benchmarkColor??i.textSecondary,m=r.benchmarkLabel??`Benchmark`,h=r.valueFormat??Is,{valMin:g,valMax:_}=Ns(o,f),v=_-g||1,y=o[0].time,b=o[o.length-1].time,x=b-y||1,S=r.timeFormat??Fs(x),C=Ms(t,n);Ls(e,t,n,i.background),Rs(e,C,g,_,y,b,i,h,S),l&&Vs(e,o,Ps(o),C,y,x,g,v,u),d&&Bs(e,o,C,y,x,g,v,s),zs(e,o,C,y,x,g,v,s,c),f&&f.length>=2&&(zs(e,f,C,y,x,g,v,p,1),Hs(e,f,C,y,x,g,v,m,p,i)),a&&Us(e,a,o,f,C,y,x,g,v,i,S,h)}function Gs(e,t,n){if(e.length===0)return[];let r=e.length,i=Math.ceil(Math.sqrt(r)),a=Math.ceil(r/i),o=t.width/i,s=t.height/a,c=[];for(let a=0;a<r;a++){let r=a%i,l=Math.floor(a/i);c.push({id:e[a].id,rect:{x:t.x+r*o+n,y:t.y+l*s+n,width:Math.max(0,o-n*2),height:Math.max(0,s-n*2)}})}return c}function Ks(e,t){let n=e.reduce((e,t)=>e+t,0);if(n===0||t===0)return 1/0;let r=0;for(let i of e){let e=n/t,a=i/e,o=e>a?e/a:a/e;o>r&&(r=o)}return r}function qs(e,t,n,r,i,a){let o=r?n.height:n.width,s=e.reduce((e,t)=>e+t,0),c=o>0?s/o:0,l=0;for(let o=0;o<e.length;o++){let s=c>0?e[o]/c:0,u;u=r?{x:n.x+i,y:n.y+l+i,width:Math.max(0,c-i*2),height:Math.max(0,s-i*2)}:{x:n.x+l+i,y:n.y+i,width:Math.max(0,s-i*2),height:Math.max(0,c-i*2)},a.push({id:t[o],rect:u}),l+=s}}function Js(e,t,n,r,i){if(e.length===0)return;let a=n.width>=n.height,o=a?n.height:n.width;if(e.length===1){qs(e,t,n,a,r,i);return}let s=[],c=[],l=0;for(;l<e.length;){let u=[...s,e[l]];if(s.length===0||Ks(u,o)<=Ks(s,o))s.push(e[l]),c.push(t[l]),l++;else{qs(s,c,n,a,r,i);let u=s.reduce((e,t)=>e+t,0),d=o>0?u/o:0;n=a?{x:n.x+d,y:n.y,width:n.width-d,height:n.height}:{x:n.x,y:n.y+d,width:n.width,height:n.height-d},Js(e.slice(l),t.slice(l),n,r,i);return}}s.length>0&&qs(s,c,n,a,r,i)}function Ys(e,t,n){if(e.length===0)return[];let r=[...e].sort((e,t)=>t.weight-e.weight),i=r.reduce((e,t)=>e+Math.max(0,t.weight),0);if(i===0)return[];let a=t.width*t.height,o=r.map(e=>Math.max(0,e.weight)/i*a),s=r.map(e=>e.id),c=[];return Js(o,s,{...t},n,c),c}function Xs(e){return(e>=0?`+`:``)+e.toFixed(2)+`%`}function Zs(e){return e.label}function Qs(t,n){let r=n.min??-5,i=n.max??5;if(t<=r)return n.negative;if(t>=i)return n.positive;if(t<0){let i=1-t/r;return(0,e.lerpColor)(n.negative,n.zero,i)}let a=t/i;return(0,e.lerpColor)(n.zero,n.positive,a)}function $s(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function ec(e,t,n,r,i,a,o,s,c,l,u){if(i<40||a<30)return;let d=n+i/2,f=r+a/2;if(e.save(),e.shadowColor=`rgba(0,0,0,0.6)`,e.shadowBlur=2,e.fillStyle=`#FFFFFF`,e.textAlign=`center`,s){let n=l(t),r=Math.min(o.font.sizeMedium,i/n.length*1.5,a/4);e.font=`bold `+Math.max(8,r)+`px `+o.font.family,e.textBaseline=c?`bottom`:`middle`,e.fillText(n,d,c?f-1:f,i-8)}if(c){let n=u(t.value),r=Math.min(o.font.sizeSmall,i/n.length*1.5,a/4);e.font=Math.max(7,r)+`px `+o.font.family,e.textBaseline=s?`top`:`middle`,e.fillText(n,d,s?f+1:f,i-8)}e.restore()}function tc(e,t,n,r,i,a,o,s){let c=[o(t),s(t.value)];if(t.meta)for(let[e,n]of Object.entries(t.meta))c.push(e+`: `+String(n));e.save(),e.font=a.font.sizeSmall+`px `+a.font.family;let l=Math.max(...c.map(t=>e.measureText(t).width))+16,u=a.font.sizeSmall+4,d=c.length*u+12,f=n.x+14,p=n.y-d/2;f+l>r&&(f=n.x-l-14),p<0&&(p=0),p+d>i&&(p=i-d),e.fillStyle=a.axisLabelBackground,e.globalAlpha=.92,$s(e,f,p,l,d,4),e.fill(),e.globalAlpha=1,e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<c.length;t++)e.fillText(c[t],f+8,p+6+t*u);e.restore()}function nc(e,t,n,r,i,a,o,s){if(r.length===0||i.length===0||t<=0||n<=0)return null;let c=a.colorScale??{negative:`#e8505b`,zero:`#424242`,positive:`#1fa874`},l=a.cellRadius??4,u=a.showLabels!==!1,d=a.showValues!==!1,f=a.valueFormat??Xs,p=a.labelFormat??Zs,m=new Map;for(let e of r)m.set(e.id,e);let h=null,g=null;if(s)for(let e of i){let{x:t,y:n,width:r,height:i}=e.rect;if(s.x>=t&&s.x<=t+r&&s.y>=n&&s.y<=n+i){h=e.id;let t=m.get(e.id);t&&(g={cell:t,rect:e});break}}e.fillStyle=o.background,e.fillRect(0,0,t,n);for(let t of i){let n=m.get(t.id);if(!n)continue;let{x:r,y:i,width:a,height:s}=t.rect;if(a<=0||s<=0)continue;let g=Qs(n.value,c);$s(e,r,i,a,s,l),e.fillStyle=g,e.fill(),ec(e,n,r,i,a,s,o,u,d,p,f),t.id===h&&($s(e,r,i,a,s,l),e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.stroke())}return g&&s&&tc(e,g.cell,s,t,n,o,p,f),g}var rc=60,ic=12,ac=24,oc=40,sc=.7,cc=1;function lc(e){return e.type?e.type:e.value>0?`positive`:e.value<0?`negative`:`subtotal`}function uc(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function dc(e,t){return{left:rc,right:e-ic,top:ac,bottom:t-oc,plotWidth:e-rc-ic,plotHeight:t-ac-oc}}function fc(e,t,n,r,i){let a=Array(e.length),o=Array(e.length),s=t.plotWidth/e.length,c=s*n,l=(s-c)/2,{left:u,bottom:d,plotHeight:f}=t,p=0;for(let t=0;t<e.length;t++){let n=e[t],m=lc(n),h,g;m===`total`||m===`subtotal`?(h=0,g=n.value,p=n.value):(h=p,g=p+n.value,p=g);let _=Math.min(h,g),v=Math.max(h,g),y=d-(_-r)/i*f,b=d-(v-r)/i*f,x=Math.min(y,b),S=Math.max(Math.abs(b-y),cc),C=u+t*s,w=C+l;a[t]={label:n.label,value:n.value,start:h,end:g,type:m,rectX:w,rectY:x,rectW:c,rectH:S,slotX:C,slotW:s},o[t]=p}return{bars:a,cumulatives:o}}function pc(e){if(e.length===0)return{valMin:0,valMax:1};let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=lc(a),s,c;o===`total`||o===`subtotal`?(s=0,c=a.value,r=a.value):(s=r,c=r+a.value,r=c),s<t&&(t=s),c<t&&(t=c),s>n&&(n=s),c>n&&(n=c)}let i=(n-t||1)*.1;return{valMin:t-i,valMax:n+i}}function mc(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function hc(t,n,r,i,a,o){let{left:s,right:c,top:l,bottom:u,plotHeight:d}=n,f=i-r||1;t.strokeStyle=a.grid,t.lineWidth=.5,t.fillStyle=a.axisLabel,t.font=`${a.font.sizeSmall}px ${a.font.family}`,t.textAlign=`right`,t.textBaseline=`middle`;let p=(0,e.computeTickStep)(r,i,5),m=Math.ceil(r/p)*p;t.beginPath();for(let e=m;e<=i;e+=p){let n=Math.round(u-(e-r)/f*d)+.5;n<l||n>u||(t.moveTo(s,n),t.lineTo(c,n))}t.stroke();for(let e=m;e<=i;e+=p){let n=u-(e-r)/f*d;n<l-1||n>u+1||t.fillText(o(e),s-6,n)}if(r<0&&i>0){let e=Math.round(u-(0-r)/f*d)+.5;t.strokeStyle=a.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(s,e),t.lineTo(c,e),t.stroke()}}function gc(e,t,n){let r=[`positive`,`negative`,`total`,`subtotal`];for(let i=0;i<r.length;i++){let a=r[i],o=n[a],s=!1;e.beginPath();for(let n=0;n<t.length;n++){let r=t[n];if(r.type!==a)continue;let i=Math.round(r.rectX),o=Math.round(r.rectY),c=Math.round(r.rectW),l=Math.round(r.rectH);e.rect(i,o,c,l),s=!0}s&&(e.fillStyle=o,e.fill())}}function _c(e,t,n,r,i,a,o){if(o===`none`||t.length<2)return;let{bottom:s,plotHeight:c}=n;e.strokeStyle=a,e.lineWidth=1,o===`dashed`?e.setLineDash([4,4]):e.setLineDash([]),e.beginPath();for(let n=0;n<t.length-1;n++){let a=t[n],o=t[n+1],l=a.end,u=Math.round(s-(l-r)/i*c)+.5,d=Math.round(a.rectX+a.rectW),f=Math.round(o.rectX);f<=d||(e.moveTo(d,u),e.lineTo(f,u))}e.stroke(),e.setLineDash([])}function vc(e,t,n,r,i,a){e.fillStyle=r.text,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`;for(let r=0;r<t.length;r++){let o=t[r],s;s=o.type===`total`||o.type===`subtotal`?i(o.value):a?`${o.value>=0?`+`:``}${i(o.value)}`:i(n[r]);let c=o.rectX+o.rectW/2;o.end<o.start?(e.textBaseline=`top`,e.fillText(s,c,o.rectY+o.rectH+4)):(e.textBaseline=`bottom`,e.fillText(s,c,o.rectY-4))}}function yc(e,t,n,r,i){e.fillStyle=r.axisLabel,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`top`;let a=n.bottom+6,o=t.length>0?t[0].slotW-4:0,s=!1;for(let n=0;n<t.length;n++)if(e.measureText(i(t[n].label)).width>o){s=!0;break}if(!s){for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.fillText(i(r.label),o,a)}return}e.save(),e.textAlign=`right`,e.textBaseline=`middle`;for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.setTransform(1,0,0,1,o,a+4),e.rotate(-Math.PI/4),e.fillText(i(r.label),0,0)}e.setTransform(1,0,0,1,0,0),e.restore()}function bc(e,t,n){if(t<n.left||t>n.right)return null;for(let n=0;n<e.length;n++){let r=e[n];if(t>=r.slotX&&t<=r.slotX+r.slotW)return n}return null}function xc(e,t,n,r,i,a,o,s){let c=t[r],l=n[r],u=Math.round(c.slotX+c.slotW/2)+.5;e.strokeStyle=o.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(u,a.top),e.lineTo(u,a.bottom),e.stroke(),e.setLineDash([]);let d=[c.label,`Value: ${c.value>=0&&(c.type===`positive`||c.type===`negative`)?`+`:``}${s(c.value)}`,`Total: ${s(l)}`];e.font=`${o.font.sizeSmall}px ${o.font.family}`;let f=0;for(let t=0;t<d.length;t++){let n=e.measureText(d[t]).width;n>f&&(f=n)}let p=f+16,m=d.length*(o.font.sizeSmall+4)+12,h=i.x+10,g=i.y-m/2;h+p>a.right&&(h=i.x-p-10),g<a.top&&(g=a.top),g+m>a.bottom&&(g=a.bottom-m),e.fillStyle=o.axisLabelBackground,e.globalAlpha=.9,e.fillRect(h,g,p,m),e.globalAlpha=1,e.fillStyle=o.text,e.textAlign=`left`,e.textBaseline=`top`;let _=o.font.sizeSmall+4;for(let t=0;t<d.length;t++)e.fillText(d[t],h+8,g+6+t*_)}function Sc(e,t,n,r,i,a){let{data:o}=r;if(!o||o.length===0||t<=0||n<=0)return{hitBar:null};let s=r.positiveColor??i.candleUp,c=r.negativeColor??i.candleDown,l=r.totalColor??i.lineColor,u=r.subtotalColor??i.textSecondary,d=r.connectorColor??i.textSecondary,f=r.connectorStyle??`dashed`,p=r.barWidth??sc,m=r.showValues!==!1,h=r.showDelta!==!1,g=r.valueFormat??uc,_=r.labelFormat??(e=>e),{valMin:v,valMax:y}=pc(o),b=y-v||1,x=dc(t,n),{bars:S,cumulatives:C}=fc(o,x,p,v,b);mc(e,t,n,i.background),hc(e,x,v,y,i,g),_c(e,S,x,v,b,d,f),gc(e,S,{positive:s,negative:c,total:l,subtotal:u}),m&&vc(e,S,C,i,g,h),yc(e,S,x,i,_);let w=a?bc(S,a.x,x):null;return a&&w!==null&&xc(e,S,C,w,a,x,i,g),{hitBar:w}}var Cc=Math.PI/180,wc=150,Tc=240,Ec=90,Dc=.14,Oc=1.6*Cc,kc=.22,Ac=8,jc=18,Mc=16,Nc=6.5,Pc=20,Fc=5,Ic=28;function Q(e,t,n){return e<t?t:e>n?n:e}function Lc(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:Number.isInteger(e)?e.toFixed(0):e.toFixed(1)}function Rc(e){let t=Number.isFinite(e.startAngle)?e.startAngle:wc,n=(Number.isFinite(e.endAngle)?e.endAngle:t+Tc)-t;return n<=0&&(n=(n%360+360)%360||360),n=Q(n,Ec,360),{start:(t%360+360)%360*Cc,sweep:n*Cc}}function zc(e,t){let n=Math.min(Math.cos(e),Math.cos(t)),r=Math.max(Math.cos(e),Math.cos(t)),i=Math.min(Math.sin(e),Math.sin(t)),a=Math.max(Math.sin(e),Math.sin(t));for(let o=Math.ceil(e/(Math.PI/2));Math.PI/2*o<=t;o++){let e=Math.PI/2*o;n=Math.min(n,Math.cos(e)),r=Math.max(r,Math.cos(e)),i=Math.min(i,Math.sin(e)),a=Math.max(a,Math.sin(e))}return{minX:n,maxX:r,minY:i,maxY:a}}function Bc(e){if(e.showZoneLabels!==!0||!e.zones)return 0;let t=e.zones.reduce((e,t)=>Math.max(e,t.label?.length??0),0);return t>0?t*Nc+12:0}function Vc(e,t,n){let r=Number.isFinite(n.min)?n.min:0,i=Number.isFinite(n.max)?n.max:100;i-r>Math.abs(r)*1e-9||(i=r+Math.max(1,Math.abs(r)*1e-6));let{start:a,sweep:o}=Rc(n),s=a,c=a+o,l=Q(n.thickness??Dc,.04,.5),u=zc(s,c),d=Math.max(u.maxY,.18),f=Bc(n),p=f>0?Mc:0,m=Math.max(1,e-2*Ac-2*f),h=Math.max(1,t-2*Ac-jc-p),g=1+l/2,_=Math.max(8,Math.min(m/((u.maxX-u.minX)*g),h/((d-u.minY)*g))),v=_*l,y=(d-u.minY)*_*g+jc+p,b=e/2-(u.maxX+u.minX)/2*_,x=(t-y)/2+p-u.minY*_*g,S=_-v/2,C=Math.max(11,Math.round(S*.46)),w=u.maxY>.3?x-C*.12:x-C*.55,T=Math.max(Math.sin(s),Math.sin(c)),E=T>.2?x+T*_+v/2+2:1/0,D=Math.min(t-Ac,E);return{cx:b,cy:x,radius:_,thickness:v,startAngle:s,endAngle:c,min:r,max:i,valueY:w,valueSize:C,textBottom:D}}function Hc(e,t){let n=Number.isFinite(e)?Q((e-t.min)/(t.max-t.min),0,1):0;return t.startAngle+(t.endAngle-t.startAngle)*n}function Uc(e,t){if(!t||!Number.isFinite(e))return;let n;for(let r of t)e>=r.from&&e<=r.to&&(n=r);return n}function Wc(e,t,n){let r=(t??[]).map(t=>({a0:Hc(t.from,e),a1:Hc(t.to,e),color:t.color,track:!1})).filter(e=>e.a1>e.a0).sort((e,t)=>e.a0-t.a0),i=[],a=e.startAngle;for(let e of r)e.a1<=a||(e.a0>a+1e-9&&i.push({a0:a,a1:e.a0,color:n,track:!0}),i.push({...e,a0:Math.max(e.a0,a)}),a=e.a1);return a<e.endAngle-1e-9&&i.push({a0:a,a1:e.endAngle,color:n,track:!0}),i}function $(e,t,n,r,i){r<=n||(e.beginPath(),e.arc(t.cx,t.cy,t.radius,n,r,!1),e.lineWidth=t.thickness,e.lineCap=`butt`,e.strokeStyle=i,e.stroke())}function Gc(e,t,n,r,i,a){let o=t.cx+Math.cos(n)*t.radius,s=t.cy+Math.sin(n)*t.radius,c=a===`start`?n-Math.PI:n;e.globalAlpha=i,e.beginPath(),e.arc(o,s,t.thickness/2,c,c+(i>=1?Math.PI*2:Math.PI),!1),e.closePath(),e.fillStyle=r,e.fill(),e.globalAlpha=1}function Kc(e,t,n,r,i,a){let o=Wc(t,n,i),s=o.some(e=>!e.track);o.forEach((n,i)=>{let a=i>0&&!n.track&&!o[i-1].track?Oc/2:0,s=i<o.length-1&&!n.track&&!o[i+1].track?Oc/2:0,c=n.a0+a,l=n.a1-s;if(n.track){$(e,t,c,l,n.color);return}e.globalAlpha=kc,$(e,t,c,l,n.color),e.globalAlpha=1,$(e,t,c,Math.min(l,r),n.color)}),s||$(e,t,t.startAngle,r,a);let c=r>t.startAngle+1e-9,l=r>=t.endAngle-1e-9,u=(e,t)=>e.track?[!s&&t?a:i,1]:[e.color,t?1:kc],[d,f]=u(o[0],c),[p,m]=u(o[o.length-1],l);Gc(e,t,t.startAngle,d,f,`start`),Gc(e,t,t.endAngle,p,m,`end`)}function qc(e,t,n){let r=t.radius-t.thickness/2;if(r<Ic)return;let i=Math.max(4,t.thickness*.45);e.strokeStyle=n,e.lineCap=`butt`;for(let n=0;n<=Pc;n++){let a=n%Fc===0,o=t.startAngle+(t.endAngle-t.startAngle)*n/Pc,s=r-i,c=s-(a?Math.max(6,t.thickness*.55):Math.max(3,t.thickness*.3));e.globalAlpha=a?.55:.3,e.lineWidth=a?1.5:1,e.beginPath(),e.moveTo(t.cx+Math.cos(o)*s,t.cy+Math.sin(o)*s),e.lineTo(t.cx+Math.cos(o)*c,t.cy+Math.sin(o)*c),e.stroke()}e.globalAlpha=1}function Jc(e,t,n,r,i){let a=t.cx+Math.cos(n)*t.radius,o=t.cy+Math.sin(n)*t.radius;e.beginPath(),e.arc(a,o,t.thickness*.78,0,Math.PI*2),e.fillStyle=r,e.fill(),e.lineWidth=Math.max(2,t.thickness*.32),e.strokeStyle=i,e.stroke()}function Yc(e,t,n,r,i){let a=Math.cos(n),o=Math.sin(n),s=t.radius-t.thickness*.9,c=Math.max(6,t.thickness*.6),l=Math.max(1.5,t.thickness*.14);e.beginPath(),e.moveTo(t.cx+a*s,t.cy+o*s),e.lineTo(t.cx-o*l-a*c,t.cy+a*l-o*c),e.lineTo(t.cx+o*l-a*c,t.cy-a*l-o*c),e.closePath(),e.fillStyle=r,e.fill(),e.beginPath(),e.arc(t.cx,t.cy,Math.max(4,t.thickness*.42),0,Math.PI*2),e.fill(),e.lineWidth=2,e.strokeStyle=i,e.stroke()}function Xc(e,t,n,r,i,a,o){e.font=`${n} ${r}px ${i}`;let s=e.measureText(t).width;if(s<=a)return r;let c=Math.floor(r*a/s);return c<o?0:(e.font=`${n} ${c}px ${i}`,c)}function Zc(e,t,n,r,i,a,o){let s=a.font.family,c=(t.radius-t.thickness/2)*1.3,l=a.font.sizeSmall;e.textAlign=`center`,e.textBaseline=`middle`;let u=Xc(e,n,`600`,t.valueSize,s,c,l);if(u===0)return;let d=o?Math.min(t.cy+u*.8,t.textBottom-u/2):t.valueY;e.fillStyle=a.text,e.fillText(n,t.cx,d);let f=Math.max(l,Math.round(u*.26));if(i?.label&&!o){let n=i.label.toUpperCase();Xc(e,n,`600`,f,s,c*.9,l)>0&&(e.fillStyle=i.color,e.fillText(n,t.cx,d-u*.78))}if(r){let n=d+u*.72;n+f/2<=t.textBottom&&Xc(e,r,`400`,f,s,c,l)>0&&(e.fillStyle=a.textSecondary,e.fillText(r,t.cx,n))}}function Qc(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall+1}px ${r.font.family}`;let i=t.thickness/2+6;for(let[r,a]of[[t.startAngle,t.min],[t.endAngle,t.max]]){let o=Math.cos(r),s=Math.sin(r),c=t.cx+o*t.radius,l=t.cy+s*t.radius;s>.2?(e.textAlign=`center`,e.textBaseline=`top`,e.fillText(n(a),c,l+i)):(e.textAlign=o<-.2?`right`:o>.2?`left`:`center`,e.textBaseline=s<-.2?`bottom`:`middle`,e.fillText(n(a),c+o*i,l+s*i))}}function $c(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textBaseline=`middle`;let i=t.radius+t.thickness/2+8;for(let r of n){if(!r.label)continue;let n=Hc((Q(r.from,t.min,t.max)+Q(r.to,t.min,t.max))/2,t),a=Math.cos(n);e.textAlign=a<-.2?`right`:a>.2?`left`:`center`,e.fillText(r.label,t.cx+a*i,t.cy+Math.sin(n)*i)}}function el(e,t,n,r,i,a){if(t<=0||n<=0)return;let o=Vc(t,n,r),s=Number.isFinite(a),c=s?Q(a,o.min,o.max):o.min,l=Hc(c,o),u=s?Uc(c,r.zones):void 0,d=r.pointer===`needle`,f=r.valueFormat??Lc,p=u?.color??r.needleColor??i.lineColor;e.save(),e.fillStyle=i.background,e.fillRect(0,0,t,n),Kc(e,o,r.zones,l,r.trackColor??i.grid,p),qc(e,o,i.textSecondary),s&&(d?Yc(e,o,l,r.needleColor??i.text,i.background):Jc(e,o,l,p,i.background)),r.showValue!==!1&&Zc(e,o,s?f(c):`—`,r.label,u,i,d),Qc(e,o,f,i),r.showZoneLabels===!0&&r.zones?.length&&$c(e,o,r.zones,i),e.restore()}exports.ABCDPatternTool=zi,exports.ADXIndicator=At,exports.ATRIndicator=kt,exports.AcceleratorOscillatorIndicator=bn,exports.AccumulationDistributionIndicator=On,exports.AlertDragHandler=Jn,exports.AlertManager=ko,exports.AlligatorIndicator=ht,exports.AnchoredVWAPIndicator=ot,exports.AnchoredVWAPTool=ei,exports.Animator=ss,exports.AreaRenderer=ae,exports.AroonIndicator=Ft,exports.ArrowTool=Yr,exports.AwesomeOscillatorIndicator=wt,exports.AxisDragHandler=qn,exports.BalanceOfPowerIndicator=nn,exports.BarCountdown=mo,exports.BarRenderer=oe,exports.BaseFinanceChart=ls,exports.BaselineRenderer=ce,exports.BinanceAdapter=za,exports.BollingerBandsIndicator=Ze,exports.BracketTool=_a,exports.BybitAdapter=Za,exports.CCIIndicator=Nt,exports.CMFIndicator=Rt,exports.CandlestickRenderer=ee,exports.CanvasLayer=t,exports.ChaikinOscillatorIndicator=Tt,exports.ChaikinVolatilityIndicator=pn,exports.ChandeMomentumIndicator=an,exports.ChandelierExitIndicator=mt,exports.ChartLegend=uo,exports.ChartStateManager=Uo,exports.ChoppinessIndexIndicator=Vt,exports.CircleTool=Vi,exports.CoinbaseAdapter=Ga,exports.CompareRenderer=ze,exports.ConnorsRSIIndicator=Gt,exports.CoppockIndicator=qt,exports.CrossLineTool=ai,exports.CrosshairHandler=Zn,exports.CrosshairTooltip=dr,exports.CurrentPriceLine=Ma,exports.CyclicLinesTool=Zi,exports.DEFAULT_LEGEND_CONFIG=lo,exports.DEFAULT_SESSION_HOURS=Eo,exports.DPRManager=i,exports.DataExporter=Go,exports.DateAndPriceRangeTool=qi,exports.DateRangeTool=Gr,exports.DepthHeatmapBuffer=Ie,exports.DepthHeatmapRenderer=Le,exports.DepthOverlay=da,exports.DetrendedPriceOscillatorIndicator=tn,exports.DisparityIndexIndicator=Cn,exports.DonchianChannelIndicator=rt,exports.DrawingBase=z,exports.DrawingManager=Cr,exports.DrawingRenderer=wr,exports.EMAIndicator=Xe,exports.EaseOfMovementIndicator=cn,exports.Easing=os,exports.ElderRayIndicator=Xt,exports.ElliottWaveTool=Ur,exports.EllipseTool=Rr,exports.Emitter=K,exports.EnvelopeIndicator=yt,exports.EquivolumeRenderer=pe,exports.EventBus=yr,exports.ExtendedLineTool=jr,exports.FibChannelTool=Mi,exports.FibExtensionTool=Ir,exports.FibRetracementTool=Pr,exports.FibSpeedResistanceFanTool=Ii,exports.FibTimeZonesTool=ri,exports.FinanceCrosshair=us,exports.FisherTransformIndicator=en,exports.ForceIndexIndicator=Wt,exports.GannBoxTool=$r,exports.GannFanTool=Zr,exports.GridRenderer=Nn,exports.HLCAreaRenderer=he,exports.HeadAndShouldersTool=Bi,exports.HollowCandleRenderer=se,exports.HorizontalLineTool=Dr,exports.HorizontalRayTool=Or,exports.HullMAIndicator=lt,exports.IchimokuIndicator=$e,exports.IndicatorBase=j,exports.IndicatorEngine=Je,exports.IndicatorValueMap=M,exports.IndicatorWorkerHost=Mn,exports.InfoLineTool=Oi,exports.InteractionManager=zn,exports.KSTIndicator=Jt,exports.KagiRenderer=ue,exports.KeltnerChannelIndicator=nt,exports.KeyboardHandler=nr,exports.KlingerIndicator=$t,exports.KrakenAdapter=io,exports.LayerManager=n,exports.LineRenderer=ie,exports.LineWithMarkersRenderer=_e,exports.LinearRegressionChannelIndicator=ct,exports.MACDIndicator=Dt,exports.MFIIndicator=Pt,exports.MTFMovingAverageIndicator=ft,exports.MarketProfileRenderer=Te,exports.MassIndexIndicator=rn,exports.MeasureOverlay=Xo,exports.MeasureTool=Kr,exports.MockAdapter=Ba,exports.ModifiedSchiffPitchforkTool=Vr,exports.OBVIndicator=jt,exports.OrderDraftTool=Ca,exports.OrderRenderer=ia,exports.PanHandler=Gn,exports.PaneResizeHandler=Yn,exports.PaperExecutionAdapter=Oa,exports.ParabolicSARIndicator=et,exports.ParallelChannelTool=Mr,exports.PercentagePriceOscillatorIndicator=vn,exports.PeriodLevelsRenderer=Ae,exports.PinnedTooltip=hr,exports.PitchforkTool=U,exports.PivotMarkersRenderer=Pe,exports.PivotPointsIndicator=at,exports.PointAndFigureRenderer=de,exports.PollingAdapter=Ha,exports.PositionRenderer=ua,exports.PrettyGoodOscillatorIndicator=Tn,exports.PriceAxis=Fn,exports.PriceLabelTool=na,exports.PriceRangeTool=Wr,exports.PriceVolumeTrendIndicator=fn,exports.QstickIndicator=wn,exports.RANGE_PRESETS=w,exports.ROCIndicator=It,exports.RSIIndicator=Et,exports.RayTool=Ar,exports.ReconnectManager=ja,exports.RectangleTool=Lr,exports.RegressionChannelTool=Nr,exports.RelativeMomentumIndexIndicator=Sn,exports.RelativeVigorIndicator=mn,exports.RenderEngine=x,exports.RenderLoop=r,exports.RenkoRenderer=le,exports.ReplayController=Pa,exports.ReplayManager=Ao,exports.RiskRewardTool=ii,exports.SELECTION_BOX_MIN_SIZE=is,exports.SMAIndicator=Ye,exports.SNAPSHOT_VERSION=jo,exports.SchaffTrendCycleIndicator=Zt,exports.SchiffPitchforkTool=Br,exports.Screenshot=fo,exports.SelectionBoxOverlay=as,exports.SessionBreaks=ho,exports.SessionShading=Do,exports.SessionVWAPIndicator=pt,exports.SignalMarkerManager=qo,exports.StdDevIndicator=En,exports.StepLineRenderer=ge,exports.StochasticIndicator=Ot,exports.StochasticRSIIndicator=hn,exports.StreamManager=Na,exports.SupertrendIndicator=tt,exports.TEMAIndicator=Ct,exports.TRIXIndicator=on,exports.TSIIndicator=Lt,exports.TextAnnotationTool=Jr,exports.TickAggregator=Aa,exports.TimeAxis=Ln,exports.TradeZoneManager=Yo,exports.TradingContextMenu=pa,exports.TradingDragHandler=fa,exports.TradingManager=Ea,exports.TradingRenderer=Da,exports.TrendAngleTool=li,exports.TrendLineTool=Er,exports.TriangleTool=zr,exports.UltimateOscillatorIndicator=Ht,exports.UndoRedoManager=Wo,exports.VROCIndicator=kn,exports.VWAPIndicator=Qe,exports.VWMAIndicator=_t,exports.VerticalLineTool=kr,exports.Viewport=S,exports.VolumeCandleRenderer=fe,exports.VolumeDeltaIndicator=zt,exports.VolumeProfileIndicator=Dn,exports.VolumeProfileRangeTool=ti,exports.VolumeProfileRenderer=ye,exports.VolumeRenderer=ve,exports.VortexIndicator=Bt,exports.WMAIndicator=vt,exports.Watermark=po,exports.WebSocketAdapter=Va,exports.WilliamsADIndicator=un,exports.WilliamsRIndicator=Mt,exports.XABCDPatternTool=Ri,exports.ZigZagIndicator=st,exports.ZoomHandler=Kn,exports.assignSessionLetters=Ce,exports.barIndexToTime=m,exports.barIndexToX=a,exports.barTimeStep=f,exports.barTimeStepMs=p,exports.bracketRiskReward=ha,exports.classifyPivots=Me,exports.computeBracketDefaults=ma,exports.computeMarketProfile=xe,exports.computePeriodLevels=ke,exports.computeSessionProfiles=we,exports.findDominantSwing=Tr,exports.findPivots=Ne,exports.formatTooltipTime=lr,exports.getIntParam=P,exports.getNumberParam=N,exports.getVisibleData=C,exports.inferOrderType=xa,exports.isInWindow=wo,exports.isRegularSession=To,exports.isWorkerResponse=jn,exports.layoutSquarifiedTreemap=Ys,exports.layoutUniformGrid=Gs,exports.lttbDownsample=te,exports.lttbVisibleIndices=re,exports.minuteOfDay=Co,exports.priceBucketRow=c,exports.priceToY=o,exports.priceToYMapper=s,exports.rangePresetStart=A,exports.registerBuiltInDrawingTools=ra,exports.registerBuiltInIndicators=An,exports.renderDepthChart=Es,exports.renderEquityCurve=Ws,exports.renderGauge=el,exports.renderHeatmap=nc,exports.renderSparkline=ds,exports.renderWaterfall=Sc,exports.resolveBarIndex=g,exports.timeToX=_,exports.timestampToBarIndex=h,exports.toHeikinAshi=Be,exports.toKagi=We,exports.toLineBreak=Ue,exports.toPointAndFigure=Ge,exports.toRangeBars=Ke,exports.toRenko=Ve,exports.tpoLetter=Se,exports.xToBarIndex=l,exports.xToTime=v,exports.yToPrice=u;
|
|
26
|
+
`,t.addEventListener(`mouseenter`,()=>{t.style.background=`#1f2630`}),t.addEventListener(`mouseleave`,()=>{t.style.background=`transparent`}),t.addEventListener(`click`,()=>{this.onItemSelect?.(e.intent),this.hide()}),s.appendChild(t)}n.appendChild(s),this.menuElement=s;let l=e=>{(e instanceof KeyboardEvent&&e.key===`Escape`||e instanceof MouseEvent&&!s.contains(e.target))&&this.hide()};document.addEventListener(`mousedown`,l),document.addEventListener(`keydown`,l),this.removeHandler=()=>{document.removeEventListener(`mousedown`,l),document.removeEventListener(`keydown`,l)}}hide(){this.menuElement?.remove(),this.menuElement=null,this.removeHandler?.(),this.removeHandler=null}destroy(){this.hide(),this.onItemSelect=null}};function Ml(e,t,n={}){let r=Math.max(Math.abs(t)*(n.riskFraction??.01),1e-8),i=r*(n.riskReward??2);return e===`buy`?{side:e,entry:t,stopLoss:t-r,takeProfit:t+i}:{side:e,entry:t,stopLoss:t+r,takeProfit:t-i}}function Nl(e){let t=Math.abs(e.entry-e.stopLoss);return t===0?0:Math.abs(e.takeProfit-e.entry)/t}var Pl=6,Fl=class{draft=null;dragging=null;defaults;constructor(e={}){this.defaults=e}start(e,t){this.draft=Ml(e,t,this.defaults),this.dragging=null}cancel(){this.draft=null,this.dragging=null}isActive(){return this.draft!==null}getDraft(){return this.draft?{...this.draft}:null}hitTest(e,t){if(!this.draft)return null;let n=[`entry`,`sl`,`tp`],r=null,i=Pl;for(let a of n){let n=o(this.priceOf(a),t),s=Math.abs(n-e.y);s<=i&&(i=s,r=a)}return r}beginDrag(e,t){let n=this.hitTest(e,t);return n?(this.dragging=n,!0):!1}drag(e,t){if(!this.draft||!this.dragging)return!1;let n=u(e.y,t);return this.draft=Il(this.draft,this.dragging,n),!0}endDrag(){this.dragging=null}isDragging(){return this.dragging!==null}priceOf(e){let t=this.draft;return e===`entry`?t.entry:e===`sl`?t.stopLoss:t.takeProfit}render(e,t,n,r=2){let i=this.draft;if(!i)return;let{chartRect:a}=t,s=a.x,c=a.x+a.width,l=o(i.entry,t),u=o(i.stopLoss,t),d=o(i.takeProfit,t),f=n.candleUp,p=n.candleDown;e.save(),e.globalAlpha=.12,e.fillStyle=f,e.fillRect(s,Math.min(l,d),a.width,Math.abs(d-l)),e.fillStyle=p,e.fillRect(s,Math.min(l,u),a.width,Math.abs(u-l)),e.globalAlpha=1,Ll(e,s,c,l,n.text,[6,3]),Ll(e,s,c,d,f,[]),Ll(e,s,c,u,p,[]);let m=Nl(i),h=i.side===`buy`?`LONG`:`SHORT`,g=e=>t.formatPrice?.(e)??e.toFixed(r);Rl(e,s+6,l,`${h} entry ${g(i.entry)}`,n.text,n),Rl(e,s+6,d,`TP ${g(i.takeProfit)} · ${m.toFixed(2)}R`,f,n),Rl(e,s+6,u,`SL ${g(i.stopLoss)}`,p,n);for(let[r,a]of[[i.entry,n.text],[i.takeProfit,f],[i.stopLoss,p]]){let n=o(r,t);e.fillStyle=a,e.beginPath(),e.arc(c-6,n,3.5,0,Math.PI*2),e.fill()}e.restore()}};function Il(e,t,n){let r=e.side===`buy`;if(t===`entry`){let t=n-e.entry;return{side:e.side,entry:n,stopLoss:e.stopLoss+t,takeProfit:e.takeProfit+t}}if(t===`sl`){let t=r?Math.min(n,e.entry):Math.max(n,e.entry);return{...e,stopLoss:t}}let i=r?Math.max(n,e.entry):Math.min(n,e.entry);return{...e,takeProfit:i}}function Ll(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function Rl(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a.background,C(e,t-3,n-8,o+6,16,a),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}function zl(e,t,n){return n==null?`limit`:e===`buy`?t<=n?`limit`:`stop`:t>=n?`limit`:`stop`}var Bl=6,Vl=class{draft=null;dragging=!1;start(e,t,n=1){this.draft={side:e,price:t,quantity:n},this.dragging=!1}cancel(){this.draft=null,this.dragging=!1}isActive(){return this.draft!==null}isDragging(){return this.dragging}getDraft(){return this.draft?{...this.draft}:null}setPrice(e){return this.draft?(this.draft={...this.draft,price:e},!0):!1}toIntent(e){return this.draft?{side:this.draft.side,type:zl(this.draft.side,this.draft.price,e),price:this.draft.price,quantity:this.draft.quantity}:null}hitTest(e,t){return this.draft?Math.abs(o(this.draft.price,t)-e.y)<=Bl:!1}beginDrag(e,t){return this.hitTest(e,t)?(this.dragging=!0,!0):!1}drag(e,t){return!this.draft||!this.dragging?!1:this.setPrice(u(e.y,t))}endDrag(){this.dragging=!1}render(e,t,n,r,i=2){let a=this.draft;if(!a)return;let{chartRect:s}=t,c=s.x,l=s.x+s.width,u=o(a.price,t),d=zl(a.side,a.price,r),f=a.side===`buy`?n.candleUp:n.candleDown;e.save(),Hl(e,c,l,u,f,[6,3]);let p=a.side===`buy`?`BUY`:`SELL`;Ul(e,c+6,u,`${p} ${d.toUpperCase()} ${t.formatPrice?.(a.price)??a.price.toFixed(i)}`,f,n),e.fillStyle=f,e.beginPath(),e.arc(l-6,u,3.5,0,Math.PI*2),e.fill(),e.restore()}};function Hl(e,t,n,r,i,a){e.strokeStyle=i,e.lineWidth=1,e.setLineDash(a),e.beginPath(),e.moveTo(t,Math.round(r)+.5),e.lineTo(n,Math.round(r)+.5),e.stroke(),e.setLineDash([])}function Ul(e,t,n,r,i,a){e.font=`600 10px system-ui, sans-serif`,e.textBaseline=`middle`,e.textAlign=`left`;let o=e.measureText(r).width;e.globalAlpha=.85,e.fillStyle=a.background,C(e,t-3,n-8,o+6,16,a),e.globalAlpha=1,e.fillStyle=i,e.fillText(r,t,n+.5)}var Wl=5,Gl=7,Kl=2;function ql(e,t){let n=t.data,r=n&&n.length>0?n[n.length-1].time:0;return r>0&&r<0xe8d4a51000?e/1e3:e}function Jl(e,t,n,r){if(t.length===0)return;let{chartRect:i}=n,a=r.orderColors?.buy??`#1fa874`,s=r.orderColors?.sell??`#e8505b`;e.lineWidth=1.5;for(let r of t){let t=_(ql(r.time,n),n),c=o(r.price,n);if(t<i.x||t>i.x+i.width||c<i.y||c>i.y+i.height)continue;let l=r.side===`buy`,u=l?c+Kl:c-Kl,d=l?u+Gl:u-Gl;e.beginPath(),e.moveTo(t,u),e.lineTo(t-Wl,d),e.lineTo(t+Wl,d),e.closePath();let f=l?a:s;!r.reason||r.reason===`order`?(e.fillStyle=f,e.fill()):(e.strokeStyle=f,e.stroke())}}var Yl=1e3,Xl=class{orders=[];positions=[];depthData=null;currentPrice=null;config;orderRenderer=new bl;positionRenderer=new Ol;depthOverlay=new kl;dragHandler;contextMenu=new jl;bracket=new Fl;orderDraft=new Vl;buttons=[];fills=[];realisedPnl=0;requestRender=null;eventCallback=null;container=null;constructor(t){this.config={...e.DEFAULT_TRADING_CONFIG,...t},this.dragHandler=new Al(this.config.dragThreshold),this.contextMenu.onItemSelect=e=>{this.eventCallback?.(`orderPlace`,e)}}setContainer(e){this.container=e}setRequestRender(e){this.requestRender=e}setEventCallback(e){this.eventCallback=e}setOrders(e){this.orders=e,this.requestRender?.()}setPositions(e){this.positions=e,this.requestRender?.()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}getCurrentPrice(){return this.currentPrice}setDepthData(e){this.depthData=e,this.requestRender?.()}setCurrentPrice(e){this.currentPrice=e,this.requestRender?.()}setConfig(e){Object.assign(this.config,e),this.requestRender?.()}addFill(e){this.fills=[...this.fills.slice(-(Yl-1)),e],this.realisedPnl+=e.pnl??0,this.requestRender?.()}setFills(e){this.fills=e.slice(-Yl),this.realisedPnl=e.reduce((e,t)=>e+(t.pnl??0),0),this.requestRender?.()}getRealisedPnl(){return this.realisedPnl}getFills(){return[...this.fills]}armed=null;isOverButton(e){return this.config.enabled&&gl(this.buttons,e)!==null}runButton(e){switch(e.type){case`cancelOrder`:this.eventCallback?.(`orderCancel`,{orderId:e.orderId});break;case`closePosition`:this.eventCallback?.(`positionClose`,{positionId:e.positionId});break;case`reversePosition`:this.eventCallback?.(`positionReverse`,{positionId:e.positionId});break;case`removeStop`:this.eventCallback?.(`positionModify`,{positionId:e.positionId,[e.which]:null});break}}startBracket(e,t){this.bracket.start(e,t),this.requestRender?.()}cancelBracket(){this.bracket.isActive()&&(this.bracket.cancel(),this.requestRender?.())}confirmBracket(){let e=this.bracket.getDraft();return e?(this.eventCallback?.(`bracketPlace`,{side:e.side,entry:e.entry,stopLoss:e.stopLoss,takeProfit:e.takeProfit,riskReward:Nl(e)}),this.bracket.cancel(),this.requestRender?.(),!0):!1}isBracketActive(){return this.bracket.isActive()}startOrderDraft(e,t){this.orderDraft.start(e,t),this.requestRender?.()}cancelOrderDraft(){this.orderDraft.isActive()&&(this.orderDraft.cancel(),this.requestRender?.())}confirmOrderDraft(){let e=this.orderDraft.toIntent(this.currentPrice);return e?(this.eventCallback?.(`orderPlace`,e),this.orderDraft.cancel(),this.requestRender?.(),!0):!1}isOrderDraftActive(){return this.orderDraft.isActive()}isOverDraggableLine(e,t,n=8){if(!this.config.enabled)return!1;let r=r=>r!==void 0&&Math.abs(e.y-o(r,t))<=n;for(let e of this.orders)if(e.draggable!==!1&&r(e.price))return!0;for(let e of this.positions)if(r(e.stopLoss)||r(e.takeProfit))return!0;return!1}onPointerDown(e,t){if(!this.config.enabled)return!1;if(this.bracket.isActive()&&this.bracket.beginDrag(e,t)||this.orderDraft.isActive()&&this.orderDraft.beginDrag(e,t))return this.requestRender?.(),!0;let n=gl(this.buttons,e);return n?(this.armed=n.action,!0):this.dragHandler.onPointerDown(e,this.orders,this.positions,t,8)}onPointerMove(e,t){if(this.armed)return!0;if(this.bracket.isDragging()){let n=this.bracket.drag(e,t);return n&&this.requestRender?.(),n}if(this.orderDraft.isDragging()){let n=this.orderDraft.drag(e,t);return n&&this.requestRender?.(),n}if(!this.dragHandler.isActive())return!1;let n=this.dragHandler.onPointerMove(e,t);return n&&this.requestRender?.(),n}onPointerUp(e){if(this.armed){let t=this.armed;this.armed=null;let n=e?gl(this.buttons,e):null;return n&&hl(n.action,t)&&this.runButton(t),!0}if(this.bracket.isDragging())return this.bracket.endDrag(),this.requestRender?.(),!0;if(this.orderDraft.isDragging())return this.orderDraft.endDrag(),this.requestRender?.(),!0;let t=this.dragHandler.onPointerUp();return t?(t.sourceType===`order`?this.eventCallback?.(`orderModify`,{orderId:t.id,newPrice:t.newPrice,previousPrice:t.previousPrice}):this.eventCallback?.(`positionModify`,{positionId:t.id,[t.sourceType]:t.newPrice}),this.requestRender?.(),!0):!1}onContextMenu(e,t){if(!this.config.enabled||!this.config.contextMenu?.enabled||!this.container)return!1;let n=u(e.y,t);return this.contextMenu.show(e,n,this.container,this.config,t.formatPrice),!0}render(e,t,n){this.buttons=[],this.config.enabled&&(this.depthData&&this.depthOverlay.render(e,this.depthData,t,this.config),this.config.fillMarks!==!1&&Jl(e,this.fills,t,this.config),this.positions.length>0&&this.positionRenderer.render(e,this.positions,this.currentPrice,t,n,this.config,this.buttons),this.orders.length>0&&this.orderRenderer.render(e,this.orders,t,n,this.config,this.dragHandler.getDragState(),this.buttons),this.bracket.isActive()&&this.bracket.render(e,t,n,this.config.pricePrecision??2),this.orderDraft.isActive()&&this.orderDraft.render(e,t,n,this.currentPrice,this.config.pricePrecision??2))}renderAxisBadges(e,t,n){this.config.enabled&&(this.positions.length>0&&this.positionRenderer.renderAxisBadges(e,this.positions,t,n,this.config),this.orders.length>0&&this.orderRenderer.renderAxisBadges(e,this.orders,t,n,this.config,this.dragHandler.getDragState()))}destroy(){this.contextMenu.destroy()}},Zl=class{constructor(e){this.manager=e}render(e,t,n){this.manager.render(e,t,n)}renderAxisBadges(e,t,n){this.manager.renderAxisBadges(e,t,n)}},Ql=class{name=`paper`;state=`disconnected`;listeners=new Map;orders=[];positions=[];markPrice;markTime;seq=0;constructor(e={}){this.markPrice=e.markPrice??0}connect(e){this.state=`connected`,this.emit(`connectionChange`,this.state),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}disconnect(){this.state=`disconnected`,this.emit(`connectionChange`,this.state)}getConnectionState(){return this.state}setMarkPrice(e,t){this.markPrice=e,this.markTime=t!==void 0&&Number.isFinite(t)?t:void 0,this.checkPendingOrders(),this.checkStops()}fillTime(){return this.markTime??Date.now()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}async placeOrder(e){let t={id:this.nextId(`ord`),side:e.side,type:e.type,price:e.price,stopPrice:e.stopPrice,quantity:e.quantity??1,label:e.type===`market`?void 0:eu(e.type),draggable:!0,stopLoss:e.stopLoss,takeProfit:e.takeProfit,timeInForce:e.timeInForce};return e.type===`market`?this.fill(t,this.markPrice||e.price):(this.orders=[...this.orders,t],this.emit(`orders`,this.orders)),t}async modifyOrder(e){this.orders=this.orders.map(t=>t.id===e.orderId?{...t,price:e.newPrice}:t),this.emit(`orders`,this.orders)}async cancelOrder(e){this.orders=this.orders.filter(t=>t.id!==e.orderId),this.emit(`orders`,this.orders)}async modifyPosition(e){let t=(e,t)=>e===void 0?t:e??void 0;this.positions=this.positions.map(n=>n.id===e.positionId?{...n,stopLoss:t(e.stopLoss,n.stopLoss),takeProfit:t(e.takeProfit,n.takeProfit)}:n),this.emit(`positions`,this.positions)}async closePosition(e){let t=this.positions.find(t=>t.id===e.positionId);t&&(this.close(t,this.markPrice||t.entryPrice,`close`),this.emit(`positions`,this.positions))}async reversePosition(e){let t=this.positions.find(t=>t.id===e.positionId);if(!t)return;let n=this.markPrice||t.entryPrice;this.close(t,n,`reverse`);let r=t.quantity-(t.closedQuantity??0),i={id:this.nextId(`ord`),side:$l(t.side),type:`market`,price:n,quantity:r};this.fill(i,n)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear(),this.orders=[],this.positions=[]}fill(e,t){this.orders=this.orders.filter(t=>t.id!==e.id);let n={id:this.nextId(`pos`),side:e.side,entryPrice:t,quantity:e.quantity,stopLoss:e.stopLoss,takeProfit:e.takeProfit};this.positions=[...this.positions,n];let r={orderId:e.id,side:e.side,price:t,quantity:e.quantity,time:this.fillTime(),positionId:n.id,reason:`order`};this.emit(`fill`,r),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}close(e,t,n){this.positions=this.positions.filter(t=>t.id!==e.id);let r=e.quantity-(e.closedQuantity??0),i=e.side===`buy`?1:-1;this.emit(`fill`,{orderId:this.nextId(`ord`),side:$l(e.side),price:t,quantity:r,time:this.fillTime(),positionId:e.id,reason:n,pnl:(t-e.entryPrice)*r*i})}checkPendingOrders(){let e=this.orders.filter(e=>this.isTriggered(e));for(let t of e)this.fill(t,t.type===`limit`?t.price:t.stopPrice??t.price)}isTriggered(e){if(e.type===`limit`)return e.side===`buy`?this.markPrice<=e.price:this.markPrice>=e.price;if(e.type===`stop`||e.type===`stopLimit`){let t=e.stopPrice??e.price;return e.side===`buy`?this.markPrice>=t:this.markPrice<=t}return!1}checkStops(){let e=!1;for(let t of[...this.positions]){let n=t.stopLoss!==void 0&&(t.side===`buy`?this.markPrice<=t.stopLoss:this.markPrice>=t.stopLoss),r=t.takeProfit!==void 0&&(t.side===`buy`?this.markPrice>=t.takeProfit:this.markPrice<=t.takeProfit);!n&&!r||(this.close(t,n?t.stopLoss:t.takeProfit,n?`stopLoss`:`takeProfit`),e=!0)}e&&this.emit(`positions`,this.positions)}nextId(e){return`${e}-${++this.seq}`}emit(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function $l(e){return e===`buy`?`sell`:`buy`}function eu(e){switch(e){case`stop`:return`STOP`;case`stopLimit`:return`STOP LIMIT`;default:return`LIMIT`}}var J=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let e of n)e(t)}removeAllListeners(){this.listeners.clear()}},tu=class extends J{currentBar=null;timeframeMs;tickRing;ringHead=0;ringCount=0;ringCapacity;constructor(t,n=1e3){super(),this.timeframeMs=(0,e.timeframeToMs)(t),this.ringCapacity=n,this.tickRing=Array(n)}setTimeframe(t){this.timeframeMs=(0,e.timeframeToMs)(t),this.currentBar=null,this.ringHead=0,this.ringCount=0}processTick(e){let t=(this.ringHead+this.ringCount)%this.ringCapacity;this.tickRing[t]=e,this.ringCount<this.ringCapacity?this.ringCount++:this.ringHead=(this.ringHead+1)%this.ringCapacity;let n=this.alignToTimeframe(e.time);!this.currentBar||this.currentBar.time!==n?(this.currentBar&&(this.currentBar.closed=!0,this.emit(`barClose`,this.currentBar)),this.currentBar={time:n,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.volume,closed:!1,tickCount:1}):(this.currentBar.high=Math.max(this.currentBar.high,e.price),this.currentBar.low=Math.min(this.currentBar.low,e.price),this.currentBar.close=e.price,this.currentBar.volume+=e.volume,this.currentBar.tickCount++),this.emit(`bar`,this.currentBar)}processBar(e,t){if(t&&this.currentBar&&this.currentBar.time===e.time)this.currentBar={...e,closed:!0,tickCount:this.currentBar.tickCount+1},this.emit(`barClose`,this.currentBar),this.currentBar=null;else if(!t)this.currentBar={...e,closed:!1,tickCount:(this.currentBar?.tickCount??0)+1},this.emit(`bar`,this.currentBar);else{let t={...e,closed:!0,tickCount:1};this.emit(`barClose`,t),this.currentBar=null}}getCurrentBar(){return this.currentBar?{...this.currentBar}:null}getTickBuffer(){let e=Array(this.ringCount);for(let t=0;t<this.ringCount;t++)e[t]=this.tickRing[(this.ringHead+t)%this.ringCapacity];return e}reset(){this.currentBar=null,this.ringHead=0,this.ringCount=0}alignToTimeframe(e){return this.timeframeMs>0?Math.floor(e/this.timeframeMs)*this.timeframeMs:e}},nu=class extends J{config;attempt=0;timer=null;active=!1;constructor(t){super(),this.config={...e.DEFAULT_RECONNECT,...t}}schedule(e){if(!this.config.enabled||!this.active)return;if(this.attempt++,this.attempt>this.config.maxRetries){this.emit(`giveUp`,{attempts:this.attempt-1}),this.active=!1;return}let t=this.computeDelay();this.emit(`attempt`,{attempt:this.attempt,delay:t}),this.timer=setTimeout(()=>{this.timer=null,this.active&&e()},t)}onConnected(){this.attempt=0,this.cancel(),this.emit(`success`,void 0)}start(){this.active=!0}stop(){this.active=!1,this.cancel(),this.attempt=0}cancel(){this.timer&&=(clearTimeout(this.timer),null)}getAttempt(){return this.attempt}isActive(){return this.active}computeDelay(){let e=this.config.baseDelay,t=this.config.backoffMultiplier**(this.attempt-1),n=Math.min(e*t,this.config.maxDelay),r=n*.25*(Math.random()*2-1);return Math.max(0,Math.round(n+r))}},ru=class{price=null;previousClose=null;visible=!0;flashUntil=0;pricePrecision=null;locale=`en-US`;setLocale(e){this.locale=e}setPrice(e,t){this.price!==null&&e!==this.price&&(this.flashUntil=Date.now()+300),this.previousClose=t??this.price??e,this.price=e}setVisible(e){this.visible=e}isVisible(){return this.visible}setPricePrecision(e){this.pricePrecision=e}getPrice(){return this.price}render(t,n,r){if(!this.visible||this.price===null)return;let i=o(this.price,n),{chartRect:a}=n;if(i<a.y||i>a.y+a.height)return;let s=this.previousClose===null||this.price>=this.previousClose?r.candleUp??`#1fa874`:r.candleDown??`#e8505b`,c=Date.now()<this.flashUntil;t.setLineDash([4,3]),t.strokeStyle=s,t.lineWidth=1,t.globalAlpha=c?1:.7,t.beginPath(),t.moveTo(a.x,Math.round(i)+.5),t.lineTo(a.x+a.width,Math.round(i)+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=1;let l=a.x+a.width+1,u=this.pricePrecision??(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max),d=n.formatPrice?n.formatPrice(this.price):(0,e.formatPrice)(this.price,u,this.locale);t.font=`bold 11px ${r.font.family}`;let f=t.measureText(d).width,p=n.priceAxisWidth??e.PRICE_AXIS_WIDTH,m=Math.min(f+12,p-2);t.fillStyle=s,C(t,l,i-10,m,20,r);let h=l-5;t.beginPath(),t.moveTo(h,i),t.lineTo(h+5,i-5),t.lineTo(h+5,i+5),t.closePath(),t.fill(),t.fillStyle=`#FFFFFF`,t.textBaseline=`middle`,t.textAlign=`left`,t.fillText(d,l+5,i)}},iu=1e3,au=10,ou=1440,su=[`tick`,`barClose`,`snapshot`,`connectionChange`,`error`],cu=new WeakMap;function lu(e){if(e instanceof mu||!e.supportedTimeframes?.length)return e;let t=cu.get(e);return t||(t=new mu(e,e.supportedTimeframes),cu.set(e,t)),t}function uu(t,n){if(n.includes(t))return t;let r=(0,e.pickBaseTimeframe)(t,n);return r&&Math.ceil((0,e.timeframeToMs)(t)/(0,e.timeframeToMs)(r))<=1440?r:null}function du(t,n){if((0,e.tickBarCount)(n)!==null)return typeof t.fetchTrades==`function`&&typeof t.subscribeTrades==`function`;let r=t.supportedTimeframes;return!r?.length||uu(n,r)!==null}function fu(t,n){let r=(0,e.parseTimeframe)(n);if(r?.unit===`M`){let e=new Date(t);return Date.UTC(e.getUTCFullYear(),e.getUTCMonth()+r.count,1)}return t+(0,e.timeframeToMs)(n)}function pu(e,t){let n=t[0],r={time:e,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume};for(let e=1;e<t.length;e++){let n=t[e];n.high>r.high&&(r.high=n.high),n.low<r.low&&(r.low=n.low),r.close=n.close,r.volume+=n.volume}return r}var mu=class{name;fetchHistoryBefore;searchSymbols;resolveSymbol;subscribeQuotes;fetchNews;fetchTrades;subscribeTrades;listeners=new Map;unsubscribe=[];live=null;bucket=null;parts=new Map;tail=null;generation=0;constructor(e,t){this.inner=e,this.baseTimeframes=t,this.name=e.name,e.fetchHistoryBefore&&(this.fetchHistoryBefore=(e,t,n,r)=>this.historyBefore(e,t,n,r)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols.bind(e)),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol.bind(e)),e.subscribeQuotes&&(this.subscribeQuotes=e.subscribeQuotes.bind(e)),e.fetchNews&&(this.fetchNews=e.fetchNews.bind(e)),e.fetchTrades&&(this.fetchTrades=e.fetchTrades.bind(e)),e.subscribeTrades&&(this.subscribeTrades=e.subscribeTrades.bind(e)),this.listen(`bar`,e=>this.onBar(e));for(let e of su)this.listen(e,t=>this.emit(e,t.data))}baseFor(e){let t=uu(e,this.baseTimeframes);if(!t)throw RangeError(`${this.name} cannot serve the ${e} timeframe`);return t}connect(e){let t=this.baseFor(e.timeframe);this.generation++,this.resetBucket(),this.live=t===e.timeframe?null:{symbol:e.symbol,target:e.timeframe,base:t},this.live&&this.resumeFromHistory(this.live.symbol,this.live.target),this.inner.connect({...e,timeframe:t})}disconnect(){this.generation++,this.inner.disconnect(),this.resetBucket(),this.live=null}getConnectionState(){return this.inner.getConnectionState()}async fetchHistory(e,t,n=500){let r=this.baseFor(t);if(r===t)return this.inner.fetchHistory(e,t,n);let i=this.generation,a=this.baseBarsFor(t,r,n),o=await this.inner.fetchHistory(e,r,Math.min(a,iu)),s=await this.extendBack(e,r,o,a,i);return this.rememberTail(e,t,s),this.toTarget(s,t,n)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.generation++;for(let e of this.unsubscribe)e();this.unsubscribe.length=0,this.listeners.clear(),this.inner.dispose()}async historyBefore(e,t,n,r){let i=this.inner.fetchHistoryBefore.bind(this.inner),a=this.baseFor(t);if(a===t)return i(e,t,n,r);let o=this.generation,s=this.baseBarsFor(t,a,r),c=await i(e,a,n,Math.min(s,iu)),l=await this.extendBack(e,a,c.filter(e=>e.time<n),s,o,1);return this.toTarget(l,t,r)}baseBarsFor(t,n,r){return(r+1)*Math.ceil((0,e.timeframeToMs)(t)/(0,e.timeframeToMs)(n))}async extendBack(e,t,n,r,i,a=1){let o=this.inner.fetchHistoryBefore?.bind(this.inner),s=n,c=a;for(;o&&s.length>0&&s.length<r&&c<10&&i===this.generation;){let n=s[0].time,i=await o(e,t,n,Math.min(r-s.length,iu));c++;let a=i.filter(e=>e.time<n);if(a.length===0)break;s=a.concat(s)}return s}toTarget(t,n,r){if(t.length===0)return[];let i=(0,e.resampleBars)(t,n);return i.length>1&&i[0].time!==t[0].time&&i.shift(),i.length>r?i.slice(i.length-r):i}rememberTail(t,n,r){if(r.length===0)return;let i=(0,e.timeframeBucketStart)(r[r.length-1].time,n),a=r.length;for(;a>0&&(0,e.timeframeBucketStart)(r[a-1].time,n)===i;)a--;this.tail={symbol:t,target:n,bucket:i,bars:r.slice(a)}}resumeFromHistory(e,t){let n=this.tail;if(!(!n||n.symbol!==e||n.target!==t)){this.bucket=n.bucket;for(let e of n.bars)this.parts.set(e.time,e)}}onBar(t){let n=this.live;if(!n){this.emit(`bar`,t.data);return}let{bar:r,closed:i}=t.data,a=(0,e.timeframeBucketStart)(r.time,n.target);if(this.bucket!==null&&a<this.bucket)return;if(this.bucket!==null&&a>this.bucket){let e=this.composed();e&&this.emit(`bar`,{bar:e,closed:!0}),this.resetBucket()}this.bucket=a,this.parts.set(r.time,r);let o=this.composed();if(!o)return;let s=i&&(0,e.timeframeBucketStart)(fu(r.time,n.base),n.target)!==a;this.emit(`bar`,{bar:o,closed:s}),s&&(this.resetBucket(),this.bucket=(0,e.timeframeBucketStart)(fu(r.time,n.base),n.target))}composed(){if(this.bucket===null||this.parts.size===0)return null;let e=[...this.parts.values()].sort((e,t)=>e.time-t.time);return pu(this.bucket,e)}resetBucket(){this.bucket=null,this.parts=new Map}listen(e,t){let n=e=>t(e);this.inner.on(e,n),this.unsubscribe.push(()=>this.inner.off(e,n))}emit(e,t){let n=this.listeners.get(e);if(!n)return;let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}},hu=1e3,gu=15e3,_u=[`tick`,`bar`,`barClose`,`snapshot`,`connectionChange`,`error`],vu=class{bar=null;count=0;lastTime=-1/0;constructor(e){this.tradesPerBar=e}push(e){let t=[],n=!1;for(let r of e){if(this.bar)this.bar={...this.bar,high:Math.max(this.bar.high,r.price),low:Math.min(this.bar.low,r.price),close:r.price,volume:this.bar.volume+r.volume};else{let e=Math.max(r.time,this.lastTime+1);this.lastTime=e,this.bar={time:e,open:r.price,high:r.price,low:r.price,close:r.price,volume:r.volume},this.count=0}this.count++,n=!0,this.count>=this.tradesPerBar&&(t.push({bar:this.bar,closed:!0}),this.bar=null,n=!1)}return n&&this.bar&&t.push({bar:this.bar,closed:!1}),t}build(e){return this.bar=null,this.count=0,this.lastTime=-1/0,this.push(e).map(e=>e.bar)}},yu=class{name;supportedTimeframes;searchSymbols;resolveSymbol;subscribeQuotes;fetchNews;fetchTrades;subscribeTrades;listeners=new Map;tick=null;stopTrades=null;keepAlive=null;tickMode=!1;state=`disconnected`;constructor(e){this.inner=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes,e.searchSymbols&&(this.searchSymbols=e.searchSymbols.bind(e)),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol.bind(e)),e.subscribeQuotes&&(this.subscribeQuotes=e.subscribeQuotes.bind(e)),e.fetchNews&&(this.fetchNews=e.fetchNews.bind(e)),this.fetchTrades=e.fetchTrades.bind(e),this.subscribeTrades=e.subscribeTrades.bind(e);for(let t of _u)e.on(t,e=>{this.tickMode||this.emit(t,e.data)})}async fetchHistory(t,n,r){let i=(0,e.tickBarCount)(n);if(i===null)return this.inner.fetchHistory(t,n,r);let a=(await this.inner.fetchTrades(t,hu)).filter(Cu).sort((e,t)=>e.time-t.time),o=new vu(i),s=o.build(a);return this.tick={symbol:t,builder:o,after:a.length?a[a.length-1].time:-1/0},r!==void 0&&r>0?s.slice(-r):s}fetchHistoryBefore(t,n,r,i){return(0,e.tickBarCount)(n)!==null||!this.inner.fetchHistoryBefore?Promise.resolve([]):this.inner.fetchHistoryBefore(t,n,r,i)}connect(t){this.disconnect();let n=(0,e.tickBarCount)(t.timeframe);if(n===null){this.tickMode=!1,this.inner.connect(t);return}this.tickMode=!0;let r=this.tick?.symbol===t.symbol?this.tick:{symbol:t.symbol,builder:new vu(n),after:-1/0};this.tick=r,this.stopTrades=this.inner.subscribeTrades(t.symbol,e=>{let t=e.filter(e=>Cu(e)&&e.time>=r.after);for(let{bar:e,closed:n}of r.builder.push(t))this.emit(`bar`,{bar:e,closed:n}),this.emit(`tick`,{time:e.time,price:e.close,volume:e.volume})}),this.state=`connected`,this.emit(`connectionChange`,`connected`),this.keepAlive=setInterval(()=>this.emit(`connectionChange`,`connected`),gu)}disconnect(){this.tickMode?(this.stopTrades?.(),this.stopTrades=null,this.keepAlive&&clearInterval(this.keepAlive),this.keepAlive=null,this.state=`disconnected`):this.inner.disconnect()}getConnectionState(){return this.tickMode?this.state:this.inner.getConnectionState()}dispose(){this.stopTrades?.(),this.stopTrades=null,this.keepAlive&&clearInterval(this.keepAlive),this.keepAlive=null,this.listeners.clear(),this.inner.dispose()}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(!n)return;let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}},bu=new WeakMap;function xu(e){if(e instanceof yu||!Su(e))return e;let t=bu.get(e);return t||(t=new yu(e),bu.set(e,t)),t}function Su(e){return typeof e.fetchTrades==`function`&&typeof e.subscribeTrades==`function`}function Cu(e){return Number.isFinite(e?.time)&&Number.isFinite(e?.price)&&Number.isFinite(e?.volume)}var wu=class extends J{config=null;adapter=null;aggregator=null;reconnector;priceLine=new ru;state=`disconnected`;lastPrice=null;previousClose=null;unsubscribers=[];heartbeatTimer=null;lastMessageTime=0;connectSeq=0;constructor(){super(),this.reconnector=new nu,this.wireReconnector()}async connect(t){this.disconnect();let n=xu(lu(t.adapter));this.config={...e.DEFAULT_STREAM_CONFIG,...t,adapter:n},this.adapter=n,this.aggregator=new tu(t.timeframe),this.reconnector.removeAllListeners(),this.reconnector.stop(),this.reconnector=new nu(t.reconnect??e.DEFAULT_RECONNECT),this.wireReconnector(),this.aggregator.on(`bar`,e=>{this.emit(`barUpdate`,e),this.updatePrice(e.close)}),this.aggregator.on(`barClose`,e=>{this.previousClose=e.close,this.emit(`barClose`,e)}),this.wireAdapter(),this.reconnector.start(),await this.doConnect()}disconnect(){this.connectSeq++,this.reconnector.stop(),this.stopHeartbeat();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.adapter&&=(this.adapter.disconnect(),null),this.aggregator?.reset(),this.aggregator?.removeAllListeners(),this.aggregator=null,this.config=null,this.lastPrice=null,this.previousClose=null,this.setState(`disconnected`)}async switchTo(e,t){!this.config||!this.adapter||(this.reconnector.stop(),this.adapter.disconnect(),this.reconnector.start(),this.aggregator?.reset(),this.aggregator?.setTimeframe(t),this.lastPrice=null,this.previousClose=null,this.config.symbol=e,this.config.timeframe=t,await this.doConnect())}getConnectionState(){return this.state}getConnectionInfo(){return{state:this.state,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}}getLastPrice(){return this.lastPrice}async doConnect(){if(!this.config||!this.adapter)return;let e=++this.connectSeq,{symbol:t,timeframe:n}=this.config;this.setState(`connecting`);try{let r=await this.adapter.fetchHistory(t,n,this.config.historyLimit??500);if(e!==this.connectSeq||!this.adapter)return;r.length>0&&(this.previousClose=r[r.length-1].close,this.updatePrice(r[r.length-1].close)),this.emit(`snapshot`,r),this.adapter.connect({symbol:t,timeframe:n}),this.startHeartbeat()}catch(t){if(e!==this.connectSeq)return;let n=t instanceof Error?t.message:String(t);this.emit(`error`,{message:n,code:`CONNECT_FAILED`}),this.setState(`error`),this.reconnector.schedule(()=>this.doConnect())}}wireReconnector(){this.reconnector.on(`attempt`,({attempt:e,delay:t})=>{this.setState(`reconnecting`),this.emit(`connectionChange`,{state:`reconnecting`,reconnectAttempt:e,lastMessageTime:this.lastMessageTime})}),this.reconnector.on(`giveUp`,({attempts:e})=>{this.setState(`error`),this.emit(`error`,{message:`Reconnection failed after ${e} attempts`,code:`RECONNECT_EXHAUSTED`})})}wireAdapter(){if(!this.adapter)return;let e=this.adapter,t=e=>{let t=e.data;this.lastMessageTime=Date.now(),t===`connected`?(this.reconnector.onConnected(),this.setState(`connected`)):(t===`disconnected`||t===`error`)&&this.reconnector.schedule(()=>this.doConnect())};e.on(`connectionChange`,t),this.unsubscribers.push(()=>e.off(`connectionChange`,t));let n=e=>{this.lastMessageTime=Date.now();let t=e.data;this.emit(`tick`,t),(t.bid!==void 0||t.ask!==void 0)&&this.emit(`quote`,{bid:t.bid,ask:t.ask}),this.config?.aggregateTicks&&this.aggregator?this.aggregator.processTick(t):this.updatePrice(t.price)};e.on(`tick`,n),this.unsubscribers.push(()=>e.off(`tick`,n));let r=e=>{this.lastMessageTime=Date.now();let{bar:t,closed:n}=e.data;this.aggregator&&this.aggregator.processBar(t,n)};e.on(`bar`,r),this.unsubscribers.push(()=>e.off(`bar`,r));let i=e=>{this.emit(`error`,{message:e.data?.message??`Adapter error`})};e.on(`error`,i),this.unsubscribers.push(()=>e.off(`error`,i))}updatePrice(e){e!==this.lastPrice&&(this.lastPrice=e,this.priceLine.setPrice(e,this.previousClose??void 0),this.emit(`priceChange`,{price:e,previousClose:this.previousClose}))}setState(e){this.state!==e&&(this.state=e,this.emit(`connectionChange`,{state:e,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}))}startHeartbeat(){this.stopHeartbeat(),this.heartbeatTimer=setInterval(()=>{Date.now()-this.lastMessageTime>6e4&&this.state===`connected`&&(this.emit(`error`,{message:`Heartbeat timeout`,code:`HEARTBEAT_TIMEOUT`}),this.adapter?.disconnect(),this.reconnector.schedule(()=>this.doConnect()))},3e4)}stopHeartbeat(){this.heartbeatTimer&&=(clearInterval(this.heartbeatTimer),null)}dispose(){this.disconnect(),this.removeAllListeners()}},Tu=class extends J{data;speed;index;status=`idle`;timer=null;constructor(e){if(super(),e.data.length===0)throw Error(`ReplayController requires non-empty data`);this.data=e.data,this.speed=Math.max(.01,e.speed??1),this.index=Math.max(0,Math.min(e.startIndex??0,e.data.length)),e.autoStart&&this.start()}getStatus(){return this.status}getIndex(){return this.index}getTotal(){return this.data.length}getPrefix(){return this.data.slice(0,this.index)}start(){if(this.status!==`playing`){if(this.index>=this.data.length){this.transition(`finished`);return}this.transition(`playing`),this.scheduleNext()}}pause(){this.status===`playing`&&(this.clearTimer(),this.transition(`paused`))}resume(){this.status===`paused`&&this.start()}stop(){this.clearTimer(),this.index=0,this.transition(`idle`)}step(e=1){if(!(e<=0)){this.clearTimer();for(let t=0;t<e;t++)if(!this.emitNext())return;this.status!==`finished`&&this.transition(`paused`)}}seek(e){let t=Math.max(0,Math.min(e,this.data.length));this.clearTimer(),this.index=t;let n=t>=this.data.length?`finished`:`paused`;this.transition(n)}setSpeed(e){this.speed=Math.max(.01,e),this.status===`playing`&&(this.clearTimer(),this.scheduleNext())}destroy(){this.clearTimer(),this.removeAllListeners()}scheduleNext(){let e=1e3/this.speed;this.timer=setTimeout(()=>{this.timer=null,this.status===`playing`&&this.emitNext()&&this.scheduleNext()},e)}emitNext(){if(this.index>=this.data.length)return this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1;let e=this.data[this.index],t=this.index;return this.index++,this.emit(`bar`,{bar:e,index:t,total:this.data.length}),this.index>=this.data.length?(this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1):!0}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}transition(e){this.status!==e&&(this.status=e,this.emit(`stateChange`,{status:e,index:this.index,total:this.data.length}))}};function Eu(e){if(!Array.isArray(e)||e.length<6)return null;let t=e[0];if(typeof t!=`number`||!Number.isFinite(t))return null;let n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[5]);return n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}function Du(e){if(!Ou(e))return null;let t=e.t;if(typeof t!=`number`||!Number.isFinite(t))return null;let n=Y(e.o),r=Y(e.h),i=Y(e.l),a=Y(e.c),o=Y(e.v);if(n===null||r===null||i===null||a===null||o===null)return null;let s=typeof e.x==`boolean`?e.x:!1;return{bar:{time:t,open:n,high:r,low:i,close:a,volume:o},closed:s}}function Y(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Ou(e){return typeof e==`object`&&!!e}function X(e){let t=typeof e==`string`?Number(e):e;return typeof t==`number`&&Number.isFinite(t)?t:void 0}function ku(t){let n=t&&typeof t==`object`&&`data`in t?t.data:t;if(!n||typeof n!=`object`)return null;let r=n;return r.e===`24hrMiniTicker`?(0,e.readQuote)({symbol:r.s,last:X(r.c),open:X(r.o),high:X(r.h),low:X(r.l),volume:X(r.v),time:X(r.E)}):null}function Au(t){if(!t||typeof t!=`object`)return null;let n=t;return(0,e.readQuote)({symbol:n.symbol,last:X(n.lastPrice),change:X(n.priceChange),changePercent:X(n.priceChangePercent),open:X(n.openPrice),high:X(n.highPrice),low:X(n.lowPrice),prevClose:X(n.prevClosePrice),volume:X(n.volume),bid:X(n.bidPrice),ask:X(n.askPrice),time:X(n.closeTime)})}function ju(e){if(!e||typeof e!=`object`)return null;let t=e,n=X(t.T),r=X(t.p),i=X(t.q);return n!==void 0&&r!==void 0&&i!==void 0?{time:n,price:r,volume:i}:null}var Mu={"1s":`1s`,"1m":`1m`,"3m":`3m`,"5m":`5m`,"15m":`15m`,"30m":`30m`,"1h":`1h`,"2h":`2h`,"4h":`4h`,"6h":`6h`,"8h":`8h`,"12h":`12h`,"1d":`1d`,"3d":`3d`,"1w":`1w`,"1M":`1M`},Nu=1e3,Pu=200,Fu=[`USDT`,`USDC`,`FDUSD`,`BTC`,`ETH`,`BNB`,`EUR`,`TRY`,`BRL`,`JPY`];function Iu(e){let t=e.currency?Fu.indexOf(e.currency):-1;return t<0?0:40-t*3}function Lu(t){if(typeof t.symbol!=`string`||t.status!==`TRADING`)return null;let n=typeof t.baseAsset==`string`?t.baseAsset:``,r=typeof t.quoteAsset==`string`?t.quoteAsset:``,i=Array.isArray(t.filters)?t.filters.find(e=>typeof e==`object`&&!!e&&e.filterType===`PRICE_FILTER`&&typeof e.tickSize==`string`):void 0,a={symbol:t.symbol,description:n&&r?`${n} / ${r}`:t.symbol,exchange:`Binance`,type:`crypto`};return i&&(a.pricePrecision=(0,e.stepDecimals)(i.tickSize),a.minTick=Number(i.tickSize)),a.timezone=`UTC`,r&&(a.currency=r),a}function Ru(e){let t=e?.symbols;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=Lu(e);t&&n.push(t)}return n}var zu=class{name=`binance`;supportedTimeframes=Object.keys(Mu);ws=null;state=`disconnected`;listeners=new Map;config=null;restBase;wsBase;symbolList=null;constructor(e){this.restBase=e?.restBase??`https://api.binance.com/api/v3`,this.wsBase=e?.wsBase??`wss://stream.binance.com:9443/ws`}connect(e){this.config=e,this.connectWs()}disconnect(){if(this.ws){let e=this.ws;e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,e.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n=500){return this.fetchKlines(e,t,n,``)}async searchSymbols(t,n){return(0,e.rankSymbols)(await this.loadSymbols(),t,n?.limit??50,Iu)}async resolveSymbol(e){if(this.symbolList){let t=(await this.symbolList.catch(()=>null))?.find(t=>t.symbol===e);if(t)return t}let t=await fetch(`${this.restBase}/exchangeInfo?symbol=${encodeURIComponent(e)}`);return t.ok?Ru(await t.json())[0]??null:null}loadSymbols(){return this.symbolList||(this.symbolList=(async()=>{let e=await fetch(`${this.restBase}/exchangeInfo`);if(!e.ok)throw Error(`Binance REST error: ${e.status}`);return Ru(await e.json())})(),this.symbolList.catch(()=>{this.symbolList=null})),this.symbolList}subscribeQuotes(e,t){let n=[...new Set(e.map(e=>e.trim().toUpperCase()))].filter(e=>/^[A-Z0-9]{2,30}$/.test(e)).slice(0,Pu);if(n.length===0)return()=>{};let r=!1,i=null,a=null,o=0,s=new Set,c=new AbortController;(async()=>{let e=await fetch(`${this.restBase}/ticker/24hr?symbols=${encodeURIComponent(JSON.stringify(n))}`,{signal:c.signal});if(e.ok)return e.json();let t=await fetch(`${this.restBase}/ticker/24hr`,{signal:c.signal});if(!t.ok)return[];let r=await t.json(),i=new Set(n);return Array.isArray(r)?r.filter(e=>i.has(e?.symbol)):[]})().then(e=>{if(r||!Array.isArray(e))return;let n=e.map(Au).filter(e=>e!==null&&!s.has(e.symbol));n.length>0&&t(n)}).catch(()=>{});let l=this.wsBase.replace(/\/ws\/?$/,``),u=()=>{if(!r){try{i=new WebSocket(`${l}/stream?streams=${n.map(e=>`${e.toLowerCase()}@miniTicker`).join(`/`)}`)}catch{d();return}i.onopen=()=>{o=0},i.onmessage=e=>{let n;try{n=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}let i=ku(n);!i||r||(s.add(i.symbol),t([i]))},i.onclose=()=>{i=null,d()}}},d=()=>{r||(a=setTimeout(u,Math.min(3e4,1e3*2**o++)))};return u(),()=>{r=!0,c.abort(),a&&clearTimeout(a),i&&=(i.onopen=null,i.onmessage=null,i.onclose=null,i.close(),null)}}async fetchTrades(e,t=1e3){let n=Math.max(1,Math.min(1e3,Math.floor(t))),r=await fetch(`${this.restBase}/aggTrades?symbol=${encodeURIComponent(e.toUpperCase())}&limit=${n}`);if(!r.ok)throw Error(`Binance aggTrades ${r.status}`);let i=await r.json();return Array.isArray(i)?i.map(ju).filter(e=>e!==null):[]}subscribeTrades(e,t){let n=`${e.trim().toLowerCase()}@aggTrade`;if(!/^[a-z0-9]{2,30}@aggTrade$/.test(n))return()=>{};let r=!1,i=null,a=null,o=0,s=()=>{if(!r){try{i=new WebSocket(`${this.wsBase}/${n}`)}catch{c();return}i.onopen=()=>{o=0},i.onmessage=e=>{let n;try{n=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}let i=ju(n);i&&!r&&t([i])},i.onclose=()=>{i=null,c()}}},c=()=>{r||(a=setTimeout(s,Math.min(3e4,1e3*2**o++)))};return s(),()=>{r=!0,a&&clearTimeout(a),i&&=(i.onopen=null,i.onmessage=null,i.onclose=null,i.close(),null)}}fetchHistoryBefore(e,t,n,r=500){return this.fetchKlines(e,t,Math.min(r,Nu),`&endTime=${Math.floor(n)-1}`)}async fetchKlines(e,t,n,r){let i=Mu[t]??`15m`,a=`${this.restBase}/klines?symbol=${e}&interval=${i}&limit=${n}${r}`,o=await fetch(a);if(!o.ok)throw Error(`Binance REST error: ${o.status}`);let s=await o.json();if(!Array.isArray(s))return[];let c=[];for(let e of s){let t=Eu(e);t&&c.push(t)}return c}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}connectWs(){if(!this.config)return;let e=`${this.config.symbol.toLowerCase()}@kline_${Mu[this.config.timeframe]??`15m`}`,t=`${this.wsBase}/${e}`;this.setState(`connecting`);try{this.ws=new WebSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws.onopen=()=>{this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`)},this.ws.onmessage=e=>{let t;try{t=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}typeof t==`object`&&t&&t.e===`kline`&&this.handleKline(t.k)},this.ws.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},this.ws.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}handleKline(e){let t=Du(e);if(!t)return;let{bar:n,closed:r}=t;this.emitEvent(`bar`,{bar:n,closed:r}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume})}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Bu=class{name=`mock`;state=`disconnected`;listeners=new Map;config=null;options;tickTimer=null;currentPrice;oldestOpen=new Map;constructor(e){this.options={basePrice:100,volatility:1.5,tickInterval:2e3,historySize:500,...e},this.currentPrice=this.options.basePrice}connect(e){this.config=e,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startTicking()}disconnect(){this.stopTicking(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}subscribeQuotes(e,t){let n=[...new Set(e)].map(e=>{let t=this.options.basePrice*(.5+Vu(e)%1e3/1e3);return{symbol:e,open:t,last:t,high:t,low:t,volume:0}});if(n.length===0)return()=>{};let r=this.options.volatility/100,i=()=>t(n.map(e=>({symbol:e.symbol,last:e.last,open:e.open,high:e.high,low:e.low,volume:e.volume,change:e.last-e.open,changePercent:(e.last-e.open)/e.open*100,time:Date.now()})));i();let a=setInterval(()=>{for(let e of n)e.last=Math.max(e.open*.01,e.last*(1+(Math.random()-.5)*r)),e.high=Math.max(e.high,e.last),e.low=Math.min(e.low,e.last),e.volume+=Math.random()*100;i()},this.options.tickInterval);return()=>clearInterval(a)}async fetchTrades(e,t=1e3){let n=Math.max(1,Math.min(1e3,Math.floor(t))),r=Date.now(),i=this.options.volatility/1e3,a=this.options.basePrice*(.5+Vu(e)%1e3/1e3),o=[];for(let e=n-1;e>=0;e--)a=Math.max(a*.5,a*(1+(Math.random()-.5)*i)),o.push({time:r-e*1e3,price:a,volume:Math.random()*5});return o}subscribeTrades(e,t){let n=this.options.volatility/1e3,r=this.options.basePrice*(.5+Vu(e)%1e3/1e3),i=setInterval(()=>{let e=[];for(let t=0;t<3;t++)r=Math.max(r*.5,r*(1+(Math.random()-.5)*n)),e.push({time:Date.now(),price:r,volume:Math.random()*5});t(e)},this.options.tickInterval);return()=>clearInterval(i)}async fetchHistory(e,t,n){let r=this.options.historyGenerator?this.options.historyGenerator(e,t,n??this.options.historySize):this.generateHistory(t,n??this.options.historySize);return r.length>0&&this.oldestOpen.set(e,r[0].open),r}async fetchHistoryBefore(t,n,r,i){let a=(0,e.timeframeToMs)(n),o=this.options.volatility/100,s=Array(Math.max(0,i)),c=this.oldestOpen.get(t)??this.options.basePrice;for(let e=0;e<i;e++){let t=c/(1+(Math.random()-.52)*o),n=Math.max(t,c)+Math.random()*c*o*.3,l=Math.max(0,Math.min(t,c)-Math.random()*c*o*.3),u=Math.floor(1e4+Math.random()*1e5);s[i-1-e]={time:r-(e+1)*a,open:t,high:n,low:l,close:c,volume:u},c=t}return this.oldestOpen.set(t,c),s}async searchSymbols(t,n){return(0,e.rankSymbols)(this.options.symbols??[],t,n?.limit??50)}async resolveSymbol(e){return this.options.symbols?.find(t=>t.symbol===e)??null}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}generateHistory(t,n){let r=[],i=Date.now(),a=(0,e.timeframeToMs)(t),o=this.options.basePrice,s=this.options.volatility/100;for(let e=n-1;e>=0;e--){let t=i-e*a,n=(Math.random()-.48)*o*s,c=o;o+=n;let l=Math.max(c,o)+Math.random()*o*s*.3,u=Math.min(c,o)-Math.random()*o*s*.3,d=Math.floor(1e4+Math.random()*1e5);r.push({time:t,open:c,high:l,low:u,close:o,volume:d})}return this.currentPrice=o,r}startTicking(){this.stopTicking();let t=this.options.tickInterval??2e3;this.tickTimer=setInterval(()=>{if(this.state!==`connected`||!this.config)return;let t=this.options.volatility/100,n=(Math.random()-.48)*this.currentPrice*t*.3;this.currentPrice+=n;let r=Date.now(),i=(0,e.timeframeToMs)(this.config.timeframe),a={time:Math.floor(r/i)*i,open:this.currentPrice-n,high:Math.max(this.currentPrice,this.currentPrice-n)+Math.abs(n)*.2,low:Math.min(this.currentPrice,this.currentPrice-n)-Math.abs(n)*.2,close:this.currentPrice,volume:Math.floor(100+Math.random()*5e3)};this.emitEvent(`bar`,{bar:a,closed:!1}),this.emitEvent(`tick`,{time:r,price:this.currentPrice,volume:a.volume})},t)}stopTicking(){this.tickTimer&&=(clearInterval(this.tickTimer),null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Vu(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)>>>0;return t}var Hu=class{name;supportedTimeframes;ws=null;state=`disconnected`;config=null;listeners=new Map;opts;fetchHistoryBefore;searchSymbols;resolveSymbol;constructor(e){this.opts=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes;let t=e.fetchHistoryBefore;t&&(this.fetchHistoryBefore=(e,n,r,i)=>t(e,n,r,i)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol)}connect(e){this.config=e,this.openSocket()}disconnect(){let e=this.config;if(this.ws){if(this.opts.unsubscribeMessage&&e)try{this.sendMessage(this.opts.unsubscribeMessage(e))}catch{}let t=this.ws;t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,t.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchHistory(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}openSocket(){let e=this.config;if(!e)return;let t=this.opts.wsUrl(e);this.setState(`connecting`);let n;try{n=this.createSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws=n,n.onopen=()=>{if(this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`),this.opts.subscribeMessage)try{this.sendMessage(this.opts.subscribeMessage(e))}catch{}},n.onmessage=t=>{let n=this.decode(t.data);if(n===void 0)return;let r;try{r=this.opts.parseMessage(n,e)}catch{return}r&&(r.bar&&this.emitEvent(`bar`,{bar:r.bar,closed:r.closed??!1}),r.tick?this.emitEvent(`tick`,r.tick):r.bar&&this.emitEvent(`tick`,{time:Date.now(),price:r.bar.close,volume:r.bar.volume}))},n.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},n.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}sendMessage(e){e===void 0||!this.ws||this.ws.send(typeof e==`string`?e:JSON.stringify(e))}decode(e){if(this.opts.decode)try{return this.opts.decode(e)}catch{return}if(typeof e==`string`)try{return JSON.parse(e)}catch{return}return e}createSocket(e){if(this.opts.socketFactory)return this.opts.socketFactory(e);let t=globalThis.WebSocket;if(!t)throw Error(`No WebSocket implementation available`);return new t(e)}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Uu=class{name;supportedTimeframes;state=`disconnected`;listeners=new Map;config=null;timer=null;lastBarTime=0;opts;fetchHistoryBefore;searchSymbols;resolveSymbol;constructor(e){this.opts=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes;let t=e.fetchHistoryBefore;t&&(this.fetchHistoryBefore=(e,n,r,i)=>t(e,n,r,i)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol)}connect(e){this.config=e,this.lastBarTime=0,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startPolling()}disconnect(){this.stopPolling(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchBars(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}async poll(){let e=this.config;if(!e||this.state!==`connected`)return;let t;try{t=await this.opts.fetchBars(e.symbol,e.timeframe,this.opts.pollLimit??2)}catch(e){this.emitEvent(`error`,{message:`Poll failed`,cause:e});return}if(t.length===0)return;let n=t[t.length-1];if(this.lastBarTime>0&&n.time>this.lastBarTime){let e=t.find(e=>e.time===this.lastBarTime);e&&this.emitEvent(`bar`,{bar:e,closed:!0})}this.emitEvent(`bar`,{bar:n,closed:!1}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume}),this.lastBarTime=n.time}startPolling(){this.stopPolling(),this.poll();let e=this.opts.setInterval??((e,t)=>setInterval(e,t));this.timer=e(()=>{this.poll()},this.opts.intervalMs??5e3)}stopPolling(){this.timer!==null&&((this.opts.clearInterval??(e=>clearInterval(e)))(this.timer),this.timer=null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Z(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Q(e){return typeof e==`object`&&!!e}var Wu={"1m":60,"5m":300,"15m":900,"1h":3600,"6h":21600,"1d":86400};function Gu(e){return Wu[e]??3600}var Ku=class extends Uu{constructor(e={}){let t=e.restBase??`https://api.exchange.coinbase.com`;super({name:`coinbase`,supportedTimeframes:Object.keys(Wu),intervalMs:e.intervalMs??5e3,pollLimit:2,fetchBars:(e,n)=>qu(t,e,n)})}};async function qu(e,t,n){let r=`${e}/products/${t}/candles?granularity=${Gu(n)}`,i=await fetch(r);if(!i.ok)throw Error(`Coinbase REST error: ${i.status}`);return Ju(await i.json())}function Ju(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=Yu(n);e&&t.push(e)}return t.sort((e,t)=>e.time-t.time),t}function Yu(e){if(!Array.isArray(e)||e.length<6)return null;let t=Z(e[0]),n=Z(e[1]),r=Z(e[2]),i=Z(e[3]),a=Z(e[4]),o=Z(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:i,high:r,low:n,close:a,volume:o}}var Xu={"1m":`1`,"3m":`3`,"5m":`5`,"15m":`15`,"30m":`30`,"1h":`60`,"2h":`120`,"4h":`240`,"6h":`360`,"12h":`720`,"1d":`D`,"1w":`W`,"1M":`M`};function Zu(e){return Xu[e]??`1`}var Qu=class extends Hu{constructor(e={}){let t=e.restBase??`https://api.bybit.com`,n=e.wsBase??`wss://stream.bybit.com/v5/public/spot`,r=e.category??`spot`;super({name:`bybit`,wsUrl:()=>n,subscribeMessage:e=>({op:`subscribe`,args:[`kline.${Zu(e.timeframe)}.${e.symbol}`]}),unsubscribeMessage:e=>({op:`unsubscribe`,args:[`kline.${Zu(e.timeframe)}.${e.symbol}`]}),supportedTimeframes:Object.keys(Xu),parseMessage:$u,fetchHistory:(e,n,i)=>ed(t,r,e,n,i),fetchHistoryBefore:(e,n,i,a)=>ed(t,r,e,n,a,Math.floor(i)-1)})}};function $u(e){if(!Q(e)||typeof e.topic!=`string`||!e.topic.startsWith(`kline.`))return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Q(n))return null;let r=Z(n.start),i=Z(n.open),a=Z(n.high),o=Z(n.low),s=Z(n.close),c=Z(n.volume);if(r===null||i===null||a===null||o===null||s===null||c===null)return null;let l=typeof n.confirm==`boolean`?n.confirm:!1;return{bar:{time:r,open:i,high:a,low:o,close:s,volume:c},closed:l}}async function ed(e,t,n,r,i,a){let o=`${e}/v5/market/kline?category=${t}&symbol=${n}&interval=${Zu(r)}&limit=${Math.min(Math.max(i,1),1e3)}${a===void 0?``:`&end=${a}`}`,s=await fetch(o);if(!s.ok)throw Error(`Bybit REST error: ${s.status}`);return td(await s.json())}function td(e){if(!Q(e)||!Q(e.result))return[];let t=e.result.list;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=nd(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function nd(e){if(!Array.isArray(e)||e.length<6)return null;let t=Z(e[0]),n=Z(e[1]),r=Z(e[2]),i=Z(e[3]),a=Z(e[4]),o=Z(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}var rd={"1m":1,"5m":5,"15m":15,"30m":30,"1h":60,"4h":240,"1d":1440,"1w":10080};function id(e){return rd[e]??1}var ad=class extends Hu{constructor(e={}){let t=e.restBase??`https://api.kraken.com`,n=e.wsBase??`wss://ws.kraken.com/v2`;super({name:`kraken`,wsUrl:()=>n,subscribeMessage:e=>({method:`subscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:id(e.timeframe)}}),unsubscribeMessage:e=>({method:`unsubscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:id(e.timeframe)}}),supportedTimeframes:Object.keys(rd),parseMessage:od,fetchHistory:(e,n)=>sd(t,e,n)})}};function od(e){if(!Q(e)||e.channel!==`ohlc`)return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Q(n))return null;let r=Z(n.open),i=Z(n.high),a=Z(n.low),o=Z(n.close),s=Z(n.volume),c=typeof n.interval_begin==`string`?Date.parse(n.interval_begin):NaN;return r===null||i===null||a===null||o===null||s===null||!Number.isFinite(c)?null:{bar:{time:c,open:r,high:i,low:a,close:o,volume:s},closed:!1}}async function sd(e,t,n){let r=id(n),i=t.replace(`/`,``),a=`${e}/0/public/OHLC?pair=${encodeURIComponent(i)}&interval=${r}`,o=await fetch(a);if(!o.ok)throw Error(`Kraken REST error: ${o.status}`);return cd(await o.json())}function cd(e){if(!Q(e)||!Q(e.result))return[];let t=null;for(let[n,r]of Object.entries(e.result))if(n!==`last`&&Array.isArray(r)){t=r;break}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=ld(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function ld(e){if(!Array.isArray(e)||e.length<7)return null;let t=Z(e[0]),n=Z(e[1]),r=Z(e[2]),i=Z(e[3]),a=Z(e[4]),o=Z(e[6]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:n,high:r,low:i,close:a,volume:o}}var ud={visible:!0,showSymbol:!0,showOHLC:!0,showChange:!0,showVolume:!0,position:`top-left`,fontSize:12},dd=class{config={...ud};symbol=``;timeframe=``;hoverBar=null;indicators=[];statusText=null;locale=`en-US`;pricePrecision=null;setConfig(e){Object.assign(this.config,e)}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}setSymbol(e){this.symbol=e}setTimeframe(e){this.timeframe=e}setChartType(e){}setHoverBar(e){this.hoverBar=e}setIndicatorValues(e){this.indicators=e}setStatusText(e){this.statusText=e}getHeight(){if(!this.config.visible||this.config.position!==`top-left`)return 0;let e=this.config.fontSize,t=6;return this.config.showSymbol?t+=e+6:this.statusText&&(t+=e+4),this.config.showOHLC&&(t+=e+3),this.config.showVolume&&(t+=e+2),t}render(t,n,r,i){if(!this.config.visible||i.length===0)return;let a=this.hoverBar??i[i.length-1],o=i.length>1?i[i.length-2]:a,{chartRect:s}=n,c=this.config.fontSize,l=this.config.position===`top-left`,u=l?s.x+8:s.x+s.width-8,d=s.y+6;if(t.textAlign=l?`left`:`right`,t.textBaseline=`top`,this.config.showSymbol){t.font=`bold ${c+2}px ${r.font.family}`,t.fillStyle=r.text;let e=[this.symbol,this.timeframe].filter(Boolean).join(` · `),n=this.statusText?`${e} ${this.statusText}`:e;t.fillText(n,u,d),d+=c+6}else this.statusText&&(t.font=`${c}px ${r.font.family}`,t.fillStyle=r.textSecondary,t.fillText(this.statusText,u,d),d+=c+4);if(this.config.showOHLC){t.font=`${c}px ${r.font.family}`;let i=a.close>=a.open,s=this.pricePrecision??(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max),f=t=>n.formatPrice?.(t)??(0,e.formatPrice)(t,s,this.locale),p=[{label:`O`,value:f(a.open),color:r.text},{label:`H`,value:f(a.high),color:r.text},{label:`L`,value:f(a.low),color:r.text},{label:`C`,value:f(a.close),color:i?r.candleUp:r.candleDown}];if(this.config.showChange){let t=a.close-o.close,n=o.close===0?0:t/o.close*100,i=t>=0?`+`:``,s=(0,e.formatPrice)(n,2,this.locale);p.push({label:``,value:`${i}${f(t)} (${i}${s}%)`,color:t>=0?r.candleUp:r.candleDown})}let m=u;if(l)for(let e of p)e.label&&(t.fillStyle=r.textSecondary,t.fillText(e.label,m,d),m+=t.measureText(e.label+` `).width),t.fillStyle=e.color,t.fillText(e.value,m,d),m+=t.measureText(e.value+` `).width;else{let e=p.map(e=>`${e.label} ${e.value}`).join(` `);t.fillStyle=r.text,t.fillText(e,u,d)}d+=c+3}if(this.config.showVolume){t.font=`${c-1}px ${r.font.family}`,t.fillStyle=r.textSecondary;let e=a.volume>=1e6?`${(a.volume/1e6).toFixed(2)}M`:a.volume>=1e3?`${(a.volume/1e3).toFixed(2)}K`:a.volume.toFixed(0);t.fillText(`Vol ${e}`,u,d),d+=c+2}if(this.indicators.length>0){t.font=`${c-1}px ${r.font.family}`;let e=u;for(let n of this.indicators){t.fillStyle=n.color;let r=`${n.name} ${n.value}`;t.fillText(r,e,d),e+=t.measureText(r+` `).width}}}},fd=class{static toDataURL(e,t){let n=e.querySelectorAll(`canvas`);if(n.length===0)return``;let r=n[0],i=r.width,a=r.height,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);t&&(s.fillStyle=t,s.fillRect(0,0,i,a));let c=Array.from(n).sort((e,t)=>(parseInt(e.style.zIndex)||0)-(parseInt(t.style.zIndex)||0));for(let e of c)s.drawImage(e,0,0);return o.toDataURL(`image/png`)}static async toBlob(e,t){let n=this.toDataURL(e,t);return n?(await fetch(n)).blob():null}static download(e,t=`chart.png`,n){let r=this.toDataURL(e,n);if(!r)return;let i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}},pd=class{config=null;setConfig(e){this.config=e}render(e,t,n){if(!this.config?.text)return;let{chartRect:r}=t,i=this.config.fontSize??48,a=this.config.color??n.textSecondary;e.save(),e.globalAlpha=.07,e.font=`bold ${i}px ${n.font.family}`,e.fillStyle=a,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(this.config.text,r.x+r.width/2,r.y+r.height/2),e.restore()}},md=class{visible=!0;timeframeMs=0;setVisible(e){this.visible=e}isVisible(){return this.visible}setTimeframeMs(e){this.timeframeMs=e}render(e,t,n,r){if(!this.visible||!(this.timeframeMs>0)||r.length===0)return;let i=r[r.length-1],o=(i.time>0xe8d4a51000?i.time:i.time*1e3)+this.timeframeMs-Date.now();if(o<=0)return;let s=this.formatRemaining(o),c=a(r.length-1,t),l=t.chartRect.y+t.chartRect.height-4;c<t.chartRect.x||c>t.chartRect.x+t.chartRect.width||(e.font=`${n.font.sizeSmall}px ${n.font.family}`,e.textBaseline=`bottom`,e.textAlign=`center`,e.fillStyle=n.textSecondary,e.fillText(s,c,l))}formatRemaining(e){let t=Math.ceil(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}},hd=class{config={visible:!1};cachedBreaksTyped=[];cachedMedianStep=0;cacheValid=!1;lastDataLength=0;locale=`en-US`;tz=null;setConfig(e){Object.assign(this.config,e)}setLocale(e){this.locale=e}setTimezone(e){e!==this.tz&&(this.tz=e,this.invalidateCache())}isVisible(){return this.config.visible}setVisible(e){this.config.visible=e}computeBreaksTyped(t){if(t.length<2)return[];if(this.cacheValid&&t.length===this.lastDataLength)return this.cachedBreaksTyped;let n=[],r=(0,e.timeParts)(this.toMs(t[0].time),this.tz);for(let i=1;i<t.length;i++){let a=this.toMs(t[i].time),o=(0,e.timeParts)(a,this.tz);if(o.year!==r.year)n.push({idx:i,kind:`year`,time:a,year:o.year});else if(o.month!==r.month)n.push({idx:i,kind:`month`,time:a,year:o.year});else if(o.day!==r.day){let e=new Date(Date.UTC(o.year,o.month-1,o.day)).getUTCDay()===1;n.push({idx:i,kind:e?`week`:`day`,time:a,year:o.year})}r=o}return this.lastDataLength=t.length,this.cachedBreaksTyped=n,this.cachedMedianStep=vd(t),this.cacheValid=!0,n}toMs(e){return e>0xe8d4a51000?e:e*1e3}render(t,n,r,i){if(!this.config.visible||i.length<2)return;let o=this.computeBreaksTyped(i);if(o.length===0||this.cachedMedianStep>=1380*60*1e3)return;let{chartRect:s}=n,c=this.config.color??r.axisLine,l=this.config.lineWidth??1,u=this.config.lineStyle??`dashed`;t.save(),u===`dashed`?t.setLineDash([6,4]):u===`dotted`&&t.setLineDash([2,3]),t.font=`600 11px ${r.font.family}`,t.textBaseline=`top`,t.textAlign=`left`;for(let i of o){let o=a(i.idx,n)-(n.barWidth+n.barSpacing)/2;if(o<s.x-1||o>s.x+s.width+1)continue;let u=Math.round(o)+.5,d=.25,f=l,p=null;i.kind===`day`?d=.22:i.kind===`week`?(d=.34,p=(0,e.zonedDateFormatter)(this.locale,gd,this.tz)(i.time)):i.kind===`month`?(d=.5,f=l+.5,p=(0,e.zonedDateFormatter)(this.locale,_d,this.tz)(i.time)):(d=.7,f=l+1,p=String(i.year)),t.globalAlpha=d,t.strokeStyle=c,t.lineWidth=f,t.beginPath(),t.moveTo(u,s.y),t.lineTo(u,s.y+s.height),t.stroke(),p&&(t.globalAlpha=Math.min(1,d+.35),t.fillStyle=r.textSecondary,t.fillText(p,u+4,s.y+4))}t.restore()}invalidateCache(){this.lastDataLength=0,this.cachedBreaksTyped=[],this.cachedMedianStep=0,this.cacheValid=!1}},gd={month:`short`,day:`numeric`},_d={month:`short`,year:`numeric`};function vd(e){if(e.length<2)return 0;let t=Math.min(50,e.length-1),n=[];for(let r=1;r<=t;r++){let t=e[r-1].time,i=e[r].time,a=t>0xe8d4a51000?t:t*1e3,o=i>0xe8d4a51000?i:i*1e3;n.push(o-a)}return n.sort((e,t)=>e-t),n[Math.floor(n.length/2)]}var yd=864e5;function bd(e,t){let n={...e,...t};return t.tzOffsetMinutes!==void 0&&t.timeZone===void 0&&delete n.timeZone,n.windows?n.windows=n.windows.map(e=>({...e})):delete n.windows,n}function xd(e,t){let n=((e+t*6e4)%yd+yd)%yd;return Math.floor(n/6e4)}function Sd(e,t,n){return t===n?!0:t<n?e>=t&&e<n:e>=t||e<n}function Cd(t,n){let r=xd(t,n.timeZone?(0,e.zoneOffsetMinutes)(n.timeZone,t):n.tzOffsetMinutes??0);return n.windows&&n.windows.length>0?n.windows.some(e=>Sd(r,e.startMinute,e.endMinute)):Sd(r,n.startMinute,n.endMinute)}var wd={startMinute:570,endMinute:960,tzOffsetMinutes:-300,timeZone:`America/New_York`},Td=class{visible=!1;config={...wd};setVisible(e){this.visible=e}isVisible(){return this.visible}setConfig(e){this.config=bd(this.config,e)}replaceConfig(e){this.config=bd(e,{})}getConfig(){return{...this.config,windows:this.config.windows?.map(e=>({...e}))}}render(e,t,n,r){if(!this.visible||t.length===0)return;let{chartRect:i}=n,{from:o,to:s}=n.visibleRange,c=Math.max(0,o),l=Math.min(s,t.length-1);if(l<c)return;let u=n.barWidth+n.barSpacing,d=r.name===`light`;e.save(),e.fillStyle=d?`rgba(0,0,0,0.045)`:`rgba(0,0,0,0.28)`;let f=-1,p=(t,r)=>{let o=a(t,n)-u/2,s=a(r,n)+u/2;e.fillRect(o,i.y,s-o,i.height)};for(let e=c;e<=l;e++){let n=!Cd(t[e].time,this.config);n&&f===-1?f=e:!n&&f!==-1&&(p(f,e-1),f=-1)}f!==-1&&p(f,l),e.restore()}},Ed=[2,3],Dd=16,Od=class{highLow=!1;quote=null;quoteShown=!0;priceText=null;setPriceText(e){this.priceText=e}setQuoteShown(e){this.quoteShown=e}setHighLow(e){this.highLow=e}isHighLowVisible(){return this.highLow}setBidAsk(e){this.quote=e?{...e}:null}getBidAsk(){return this.quote?{...this.quote}:null}levels(e,t){let n=[];if(this.highLow){let r=Math.max(0,t.visibleRange.from),i=Math.min(e.length-1,t.visibleRange.to),a=-1/0,o=1/0;for(let t=r;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);Number.isFinite(a)&&n.push({kind:`high`,price:a}),Number.isFinite(o)&&n.push({kind:`low`,price:o})}let{bid:r,ask:i}=(this.quoteShown?this.quote:null)??{};return r!==void 0&&Number.isFinite(r)&&n.push({kind:`bid`,price:r}),i!==void 0&&Number.isFinite(i)&&n.push({kind:`ask`,price:i}),n}render(e,t,n,r){let{chartRect:i}=t;e.save(),e.setLineDash(Ed),e.lineWidth=1;for(let a of this.levels(r,t)){let r=Math.round(o(a.price,t))+.5;r<i.y||r>i.y+i.height||(e.strokeStyle=kd(a.kind,n),e.beginPath(),e.moveTo(i.x,r),e.lineTo(i.x+i.width,r),e.stroke())}e.restore()}renderAxisTags(t,n,r,i){let{chartRect:a}=n,s=a.x+a.width+1,c=(n.priceAxisWidth??e.PRICE_AXIS_WIDTH)-2,l=(0,e.autoPricePrecision)(n.priceRange.min,n.priceRange.max);t.save(),t.font=`${r.font.sizeSmall}px ${r.font.family}`,t.textBaseline=`middle`,t.textAlign=`left`;for(let u of this.levels(i,n)){let i=o(u.price,n);if(i<a.y||i>a.y+a.height)continue;t.fillStyle=kd(u.kind,r),C(t,s,i-Dd/2,c,Dd,r),t.fillStyle=r.background;let d=n.formatPrice?.(u.price)??this.priceText?.(u.price)??(0,e.formatPrice)(u.price,l);t.fillText(d,s+5,i)}t.restore()}};function kd(e,t){switch(e){case`bid`:return t.candleUp;case`ask`:return t.candleDown;default:return t.textSecondary}}var Ad=500,jd=2,Md=[`movesUp`,`movesDown`];function Nd(e){return e.channel===`price`&&!e.drawingId&&!e.target&&!Md.includes(e.condition)}function Pd(e,t,n,r){switch(r){case`crossingUp`:return e!==void 0&&e<n&&t>=n;case`crossingDown`:return e!==void 0&&e>n&&t<=n;case`crossing`:return e!==void 0&&(e<n&&t>=n||e>n&&t<=n);case`greaterThan`:return t>n;case`lessThan`:return t<n;default:return!1}}var Fd=[`crossing`,`crossingUp`,`crossingDown`];function Id(e,t,n){let r=e<0&&t>=0,i=e>0&&t<=0;return n===`crossingUp`?r:n===`crossingDown`?i:r||i}var Ld=1,Rd=2**31-1,zd=class extends J{alerts=[];lastValues=new Map;drawingSides=new Map;drawingLevels=null;requestRender=null;pricePrecision=2;barTime=null;expiryTimer=null;history=new Map;lastDiffs=new Map;setBarTime(e){this.barTime=e}setRequestRender(e){this.requestRender=e}setPricePrecision(e){this.pricePrecision=e}addAlert(e,t=`crossing`,n,r=!1,i=`price`,a,o={}){let s=Bd(t,i,o),c=`tc_alert_${Ld++}`,l={id:c,price:e,condition:t,message:n,triggered:!1,repeating:r,channel:i,label:a,...s};return this.alerts.push(l),s.expiresAt!==void 0&&this.scheduleExpiry(),this.emit(`added`,l),this.requestRender?.(),c}setDrawingLevels(e){this.drawingLevels=e}addDrawingAlert(e,t=`crossing`,n,r=!1,i){if(!Fd.includes(t))throw RangeError(`An alert on a drawing takes a crossing condition, not "${t}"`);let a=`tc_alert_${Ld++}`,o={id:a,price:this.drawingLevels?.(e)?.[0]??NaN,condition:t,message:n,triggered:!1,repeating:r,channel:`price`,label:i,drawingId:e};return this.alerts.push(o),this.emit(`added`,o),a}removeDrawingAlerts(e){for(let t of this.alerts.filter(t=>t.drawingId===e))this.removeAlert(t.id)}takeDrawingAlerts(e){let t=this.alerts.filter(t=>t.drawingId===e);for(let e of t)this.removeAlert(e.id);return t.map(e=>({...e}))}restoreAlerts(e){for(let t of e){if(this.alerts.some(e=>e.id===t.id))continue;let e={...t};this.alerts.push(e),this.emit(`added`,e)}this.scheduleExpiry(),this.requestRender?.()}pruneDrawingAlerts(e){let t=this.alerts.filter(t=>t.drawingId!==void 0&&!e.has(t.drawingId));for(let e of t)this.removeAlert(e.id);return t.length}removeAlert(e){this.drawingSides.delete(e),this.lastDiffs.delete(e);let t=this.alerts.some(t=>t.id===e&&t.expiresAt!==void 0);this.alerts=this.alerts.filter(t=>t.id!==e),t&&this.scheduleExpiry(),this.emit(`removed`,e),this.requestRender?.()}getAlerts(){return[...this.alerts]}getAlertAtPoint(e,t,n=6){let{chartRect:r}=t;if(e.y<r.y||e.y>r.y+r.height)return null;let i=null,a=n;for(let n of this.alerts){if(!Nd(n))continue;let r=Math.abs(o(n.price,t)-e.y);r<=a&&(a=r,i=n)}return i}updateAlertPrice(e,t){let n=this.alerts.find(t=>t.id===e);!n||!Number.isFinite(t)||(n.price=t,n.triggered=!1,n.expiresAt!==void 0&&this.scheduleExpiry(),this.emit(`updated`,{...n}),this.requestRender?.())}clearAlerts(){this.alerts=[],this.lastDiffs.clear(),this.drawingSides.clear(),this.scheduleExpiry(),this.requestRender?.()}checkPrice(e){this.checkChannel(`price`,e),this.checkDrawingAlerts(e)}checkDrawings(e){this.checkDrawingAlerts(e)}expire(){let e=Date.now(),t=this.alerts.filter(t=>!t.expired&&t.expiresAt!==void 0&&e>=t.expiresAt&&!(t.triggered&&!t.repeating));if(t.length!==0){for(let e of t)e.expired=!0;try{for(let e of t)this.emit(`expired`,{...e}),this.emit(`updated`,{...e})}finally{this.requestRender?.(),this.scheduleExpiry()}}}scheduleExpiry(){this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null;let e=Math.min(...this.alerts.filter(e=>!e.expired&&e.expiresAt!==void 0&&!(e.triggered&&!e.repeating)).map(e=>e.expiresAt));if(!Number.isFinite(e))return;let t=Math.min(Math.max(0,e-Date.now()),Rd);this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.expire(),this.expiryTimer||this.scheduleExpiry()},t)}dispose(){this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}checkDrawingAlerts(e){if(!(!this.drawingLevels||!Number.isFinite(e)))for(let t of this.alerts){if(!t.drawingId||t.expired)continue;let n=this.drawingLevels(t.drawingId);if(!n||n.length===0){this.drawingSides.delete(t.id);continue}t.price=n[0];let r=n.map(t=>Math.sign(e-t)),i=this.drawingSides.get(t.id);this.drawingSides.set(t.id,r),!(!i||i.length!==r.length)&&(r.some((e,n)=>Id(i[n],e,t.condition))?t.triggered||(t.triggered=!0,this.emit(`triggered`,{...t})):t.repeating&&(t.triggered=!1))}}checkChannel(e,t){this.checkChannels(new Map([[e,t]]))}checkChannels(e,t={}){let n=(e instanceof Map?[...e.entries()]:Object.entries(e)).filter(([,e])=>Number.isFinite(e));if(n.length===0)return;this.expire();let r=new Map,i=new Map;for(let[e,t]of n){r.set(e,this.lastValues.get(e));let n=this.recordBar(e,t);n&&i.set(e,n),this.lastValues.set(e,t)}for(let e of this.alerts){if(e.drawingId||e.expired)continue;let n=r.has(e.channel),a=e.target!==void 0&&r.has(e.target);if(!n&&!a||e.target!==void 0&&t.together&&!(n&&a))continue;let o;if(e.onBarClose){let t=i.get(e.channel)??(e.target?i.get(e.target):void 0);if(!t)continue;o=this.closedBarMet(e,t)}else if(e.target)o=this.targetMet(e);else if(Md.includes(e.condition)){if(!n)continue;o=this.moveMet(e,this.history.get(e.channel)??[])}else{let t=r.get(e.channel);if(!n||t===void 0)continue;o=Pd(t,this.lastValues.get(e.channel),e.price,e.condition)}this.settle(e,o)}}settle(e,t){t?e.triggered||(e.triggered=!0,this.emit(`triggered`,{...e})):e.repeating&&(e.triggered=!1)}targetMet(e){let t=this.lastValues.get(e.channel),n=e.target?this.lastValues.get(e.target):void 0;if(t===void 0||n===void 0)return!1;let r=t-n,i=this.lastDiffs.get(e.id);return this.lastDiffs.set(e.id,r),e.price=n,Pd(i,r,0,e.condition)}moveMet(e,t,n=t.length){let r=e.bars??1,i=t.slice(Math.max(0,n-r),n);if(i.length<2||e.percent===void 0)return!1;let a=i[i.length-1].value,o=i.map(e=>e.value);if(e.condition===`movesUp`){let t=Math.min(...o);return t!==0&&(a-t)/Math.abs(t)*100>=e.percent}let s=Math.max(...o);return s!==0&&(s-a)/Math.abs(s)*100>=e.percent}closedBarMet(e,t){let n=this.history.get(e.channel)??[],r=n.findIndex(e=>e.time===t.time);if(r<0)return!1;if(Md.includes(e.condition))return this.moveMet(e,n,r+1);let i=(e,t)=>{let r=this.history.get(e)??[],i=n[t]?.time;return i===void 0?void 0:r.find(e=>e.time===i)?.value},a=n[r].value,o=r>0?n[r-1].value:void 0,s=e.price;if(e.target){let t=i(e.target,r),n=r>0?i(e.target,r-1):void 0;if(t===void 0)return!1;a-=t,o=o!==void 0&&n!==void 0?o-n:void 0,s=0,e.price=t}return Pd(o,a,s,e.condition)}recordBar(e,t){let n=this.barTime;if(n===null)return null;let r=this.history.get(e)??[],i=r[r.length-1];if(i&&n<i.time)return r=r.filter(e=>e.time<n),r.push({time:n,value:t}),this.history.set(e,r),null;if(i&&i.time===n)return r[r.length-1]={time:n,value:t},null;i=r[r.length-1],r.push({time:n,value:t});let a=Math.min(502,Math.max(3,...this.alerts.map(e=>(e.bars??1)+2)));return r.length>a&&r.splice(0,r.length-a),this.history.set(e,r),i?{channel:e,time:i.time}:null}clearLastValues(){this.lastValues.clear(),this.drawingSides.clear(),this.history.clear(),this.lastDiffs.clear()}saveToStorage(e){try{let t=this.alerts.map(e=>({id:e.id,price:e.price,condition:e.condition,message:e.message,triggered:e.triggered,repeating:e.repeating,channel:e.channel,label:e.label,drawingId:e.drawingId,target:e.target,percent:e.percent,bars:e.bars,onBarClose:e.onBarClose,expiresAt:e.expiresAt,expired:e.expired}));localStorage.setItem(e,JSON.stringify(t))}catch{}}loadFromStorage(e){try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);if(!Array.isArray(n))return;for(let e of n){if(typeof e.drawingId==`string`&&e.condition&&!e.triggered){Fd.includes(e.condition)&&this.addDrawingAlert(e.drawingId,e.condition,e.message,e.repeating??!1,e.label);continue}if(!e.condition||e.triggered||e.expired)continue;let t=Vd(e),n=!t.target&&!Md.includes(e.condition),r=typeof e.price==`number`&&Number.isFinite(e.price)?e.price:NaN;if(!(n&&Number.isNaN(r)))try{this.addAlert(r,e.condition,e.message,e.repeating??!1,e.channel??`price`,e.label,t)}catch{}}}catch{}}render(e,t,n){let{chartRect:r}=t;for(let i of this.alerts){if(!Nd(i))continue;let a=o(i.price,t);if(a<r.y||a>r.y+r.height)continue;let s=i.expired?`#8a93a3`:i.triggered?`#f2a93b`:`#4c8dff`;e.setLineDash([2,6]),e.strokeStyle=s,e.lineWidth=1,e.beginPath(),e.moveTo(r.x,Math.round(a)+.5),e.lineTo(r.x+r.width,Math.round(a)+.5),e.stroke(),e.setLineDash([]),e.font=`10px ${n.font.family}`,e.fillStyle=s,e.textBaseline=`bottom`,e.textAlign=`right`;let c=`🔔 ${t.formatPrice?.(i.price)??i.price.toFixed(this.pricePrecision)}${i.message?` - ${i.message}`:``}`;e.fillText(c,r.x+r.width-4,a-2)}}};function Bd(e,t,n){let r={},i=Md.includes(e);if(n.target!==void 0){if(i)throw RangeError(`An alert on a move takes no other line`);if(n.target===t)throw RangeError(`An alert can’t compare a line with itself`);r.target=n.target}if(i){let{percent:e,bars:t}=n;if(e===void 0||!Number.isFinite(e)||e<=0)throw RangeError(`An alert on a move needs a percent above 0`);if(t===void 0||!Number.isInteger(t)||t<2||t>500)throw RangeError(`An alert on a move needs 2 to 500 bars`);r.percent=e,r.bars=t}return n.onBarClose&&(r.onBarClose=!0),n.expiresAt!==void 0&&Number.isFinite(n.expiresAt)&&(r.expiresAt=n.expiresAt),r}function Vd(e){let t={};return typeof e.target==`string`&&e.target&&(t.target=e.target),typeof e.percent==`number`&&Number.isFinite(e.percent)&&(t.percent=e.percent),typeof e.bars==`number`&&Number.isInteger(e.bars)&&(t.bars=e.bars),e.onBarClose===!0&&(t.onBarClose=!0),typeof e.expiresAt==`number`&&Number.isFinite(e.expiresAt)&&(t.expiresAt=e.expiresAt),t}var Hd=class extends J{data=[];cursor=-1;timer=null;state=`stopped`;config={speed:1,interval:500};load(e){this.stop(),this.data=e,this.cursor=-1}play(e){if(this.data.length!==0){if(e){let{startIndex:t,paused:n,...r}=e;Object.assign(this.config,r);let i=t===void 0?null:this.clamp(t);if(n){this.clearTimer(),this.seekTo(i??Math.max(0,this.cursor)),this.setState(`paused`);return}i!==null&&(this.cursor=i-1)}if(this.isAtEnd()){this.clearTimer(),this.setState(`paused`);return}this.clearTimer(),this.setState(`playing`),this.timer=setInterval(()=>this.tick(),this.config.interval/this.config.speed)}}pause(){this.clearTimer(),this.setState(`paused`)}resume(){this.state===`paused`&&this.play()}stop(){this.clearTimer(),this.cursor=-1,this.setState(`stopped`)}seekTo(e){this.data.length!==0&&(this.cursor=this.clamp(e),this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}))}setSpeed(e){this.config.speed=e,this.state===`playing`&&this.play()}getState(){return this.state}isAtEnd(){return this.data.length>0&&this.cursor>=this.data.length-1}getProgress(){let e=this.data.length;return{current:Math.max(0,this.cursor),total:e,percent:e>0?(this.cursor+1)/e*100:0}}dispose(){this.stop(),this.removeAllListeners(),this.data=[]}tick(){if(this.isAtEnd()){this.clearTimer(),this.setState(`paused`),this.emit(`complete`,void 0);return}this.cursor++,this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}),this.isAtEnd()&&(this.clearTimer(),this.setState(`paused`),this.emit(`complete`,void 0))}clamp(e){return Number.isFinite(e)?Math.max(0,Math.min(Math.floor(e),this.data.length-1)):0}clearTimer(){this.timer&&=(clearInterval(this.timer),null)}setState(e){this.state!==e&&(this.state=e,this.emit(`stateChange`,e))}},Ud=2,Wd=2;function $(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Gd(e){return Array.isArray(e)?e:[]}function Kd(e,t){return typeof e==`string`?e:t}function qd(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function Jd(t){if(!$(t)||typeof t.id!=`string`||typeof t.type!=`string`||!Array.isArray(t.anchors)||t.anchors.length===0||t.anchors.length>Yd||!$(t.style))return null;let n=[];for(let e of t.anchors){if(!$(e)||typeof e.time!=`number`||typeof e.price!=`number`||!Number.isFinite(e.time)||!Number.isFinite(e.price))return null;n.push({time:e.time,price:e.price})}let r=(0,e.sanitizeDrawingStyle)(t.style);return r.color===void 0||r.lineWidth===void 0?null:{id:t.id,type:t.type,anchors:n,style:{lineStyle:`solid`,...r,color:r.color,lineWidth:r.lineWidth},visible:typeof t.visible==`boolean`?t.visible:!0,locked:typeof t.locked==`boolean`?t.locked:!1,options:$(t.options)?t.options:void 0,group:Qd(t.group),meta:$(t.meta)?t.meta:void 0}}var Yd=5e3,Xd=64,Zd=80;function Qd(e){if(!(!$(e)||typeof e.id!=`string`||typeof e.name!=`string`)&&!(e.id===``||e.id.length>Xd))return{id:e.id,name:e.name.slice(0,Zd)}}function $d(e){return!$(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.type!=`string`||typeof e.price!=`number`||typeof e.quantity!=`number`?null:e}function ef(e){if(!$(e))return;let t={},n=Gd(e.colors).filter(e=>typeof e==`string`);n.length>0&&(t.colors=n);let r=Gd(e.lineWidths).filter(e=>typeof e==`number`&&Number.isFinite(e)&&e>0);return r.length>0&&(t.lineWidths=r),typeof e.opacity==`number`&&Number.isFinite(e.opacity)&&(t.opacity=Math.min(1,Math.max(0,e.opacity))),Object.keys(t).length>0?t:void 0}var tf=[`crossingUp`,`crossingDown`,`crossing`,`greaterThan`,`lessThan`,`movesUp`,`movesDown`];function nf(e){if(!$(e)||typeof e.id!=`string`)return null;let t=typeof e.drawingId==`string`?e.drawingId:void 0,n=typeof e.price==`number`&&Number.isFinite(e.price)?e.price:null,r=tf.find(t=>t===e.condition)??`crossing`,i=Vd(e),a=i.target!==void 0||r===`movesUp`||r===`movesDown`;return n===null&&!t&&!a?null:{id:e.id,price:n??NaN,drawingId:t,condition:r,message:typeof e.message==`string`?e.message:void 0,triggered:e.triggered===!0,repeating:e.repeating===!0,channel:Kd(e.channel,`price`),label:typeof e.label==`string`?e.label:void 0,...i,...e.expired===!0?{expired:!0}:{}}}function rf(e){return!$(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.entryPrice!=`number`||typeof e.quantity!=`number`?null:e}var af=4e3;function of(t){if(!$(t))return sf();typeof t.version==`number`&&t.version>Wd&&console.warn(`Chart state from a newer version (${t.version}); loading what this version understands.`);let n=$(t.viewport)?t.viewport:{},r=[];for(let e of Gd(t.indicators))$(e)&&(typeof e.id!=`string`||typeof e.instanceId!=`string`||$(e.params)&&r.push({id:e.id,instanceId:e.instanceId,params:e.params,position:typeof e.position==`string`?e.position:void 0,style:ef(e.style),visible:typeof e.visible==`boolean`?e.visible:void 0,levels:Array.isArray(e.levels)?e.levels.filter(e=>typeof e==`number`&&Number.isFinite(e)):void 0,pane:typeof e.pane==`string`?e.pane:void 0,scale:e.scale===`left`?`left`:void 0,paneSize:typeof e.paneSize==`number`&&Number.isFinite(e.paneSize)&&e.paneSize>0?Math.min(e.paneSize,af):void 0,paneOrder:typeof e.paneOrder==`number`&&Number.isInteger(e.paneOrder)&&e.paneOrder>=0?e.paneOrder:void 0,paneCollapsed:e.paneCollapsed===!0?!0:void 0,paneMaximized:e.paneMaximized===!0?!0:void 0,paneLog:e.paneLog===!0?!0:void 0,paneInvert:e.paneInvert===!0?!0:void 0,panePercent:e.panePercent===!0?!0:void 0}));let i=[];for(let e of Gd(t.drawings)){let t=Jd(e);t&&i.push(t)}let a=[];for(let e of Gd(t.orders)){let t=$d(e);t&&a.push(t)}let o=[];for(let e of Gd(t.positions)){let t=rf(e);t&&o.push(t)}let s=[];for(let e of Gd(t.alerts)){let t=nf(e);t&&s.push(t)}return{version:typeof t.version==`number`&&Array.isArray(t.indicators)?t.version:1,timestamp:qd(t.timestamp,Date.now()),symbol:typeof t.symbol==`string`?t.symbol:void 0,timeframe:typeof t.timeframe==`string`?t.timeframe:void 0,chartType:Kd(t.chartType,`candlestick`),...t.chartTypeOptions===void 0?{}:{chartTypeOptions:(0,e.readChartTypeOptions)(t.chartTypeOptions)},viewport:{barWidth:qd(n.barWidth,8),barSpacing:qd(n.barSpacing,2),offset:qd(n.offset,0)},theme:typeof t.theme==`string`?t.theme:void 0,locale:typeof t.locale==`string`?t.locale:void 0,indicators:r,drawings:i,orders:a,positions:o,alerts:s}}function sf(){return{version:1,timestamp:Date.now(),chartType:`candlestick`,viewport:{barWidth:8,barSpacing:2,offset:0},indicators:[],drawings:[],orders:[],positions:[],alerts:[]}}var cf=class{static capture(e,t){return{version:e.getIndicators?Wd:1,timestamp:Date.now(),chartType:t?.chartType??`candlestick`,...t?.chartTypeOptions&&Object.keys(t.chartTypeOptions).length>0?{chartTypeOptions:t.chartTypeOptions}:{},symbol:t?.symbol,timeframe:t?.timeframe,viewport:{barWidth:8,barSpacing:2,offset:0},theme:e.getTheme().name,indicators:e.getIndicators?.()??[],drawings:e.getDrawings(),orders:e.getOrders?.()??[],positions:e.getPositions?.()??[],alerts:e.getAlerts?.()??[]}}static serialize(e){return JSON.stringify(e)}static deserialize(e){return of(JSON.parse(e))}static saveToStorage(e,t){localStorage.setItem(e,this.serialize(t))}static loadFromStorage(e){let t=localStorage.getItem(e);return t?this.deserialize(t):null}static downloadFile(e,t=`tc-chart-state.json`){let n=new Blob([this.serialize(e)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}static loadFromFile(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async()=>{let r=n.files?.[0];if(!r){t(Error(`No file selected`));return}let i=await r.text();e(this.deserialize(i))},n.click()})}},lf=class{undoStack=[];redoStack=[];maxHistory=50;onChange=null;setOnChange(e){this.onChange=e}push(e){this.undoStack.push(e),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack.length=0,this.onChange?.()}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){let e=this.undoStack.pop();return e?(this.redoStack.push(e),this.onChange?.(),e):null}redo(){let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.onChange?.(),e):null}clear(){this.undoStack.length=0,this.redoStack.length=0,this.onChange?.()}last(){return this.undoStack[this.undoStack.length-1]??null}dropLast(){this.undoStack.pop()&&(this.redoStack.length=0,this.onChange?.())}replaceLast(e){if(this.undoStack.length===0){this.push(e);return}this.undoStack[this.undoStack.length-1]=e,this.redoStack.length=0,this.onChange?.()}getState(){return{canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoCount:this.undoStack.length,redoCount:this.redoStack.length}}},uf=[`Time`,`Open`,`High`,`Low`,`Close`,`Volume`];function df(t){return new Date((0,e.normalizeBarTime)(t)).toISOString()}function ff(e){let t=/^[=+\-@\t\r]/.test(e)&&!/^-?\d/.test(e)?`'${e}`:e;return/[",\r\n]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var pf=e=>e==null||!Number.isFinite(e)?``:String(e),mf=class{static toCSV(e,t=[]){return[[...uf,...t.map(e=>ff(e.name))].join(`,`),...e.map((e,n)=>[df(e.time),e.open,e.high,e.low,e.close,e.volume,...t.map(e=>pf(e.values[n]))].join(`,`))].join(`
|
|
27
|
+
`)}static toJSON(e,t=[]){return JSON.stringify(e.map((e,n)=>{let r={time:df(e.time),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume};for(let e of t){let t=e.values[n];r[e.name]=t==null||!Number.isFinite(t)?null:t}return r}),null,2)}static download(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}},hf=1,gf=3,_f=class extends J{markers=[];style={...e.DEFAULT_SIGNAL_STYLE};requestRender=null;dataGetter=null;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addMarker(e){let t=e.id??`tc_signal_${hf++}`,n={...e,id:t};return this.markers.push(n),this.emit(`added`,n),this.requestRender?.(),t}removeMarker(e){this.markers=this.markers.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getMarkers(){return[...this.markers]}clearMarkers(){this.markers=[],this.emit(`cleared`,void 0),this.requestRender?.()}setMarkers(e){this.markers=[...e],this.requestRender?.()}markerAt(e,t){let n=this.dataGetter?.();if(!n||n.length===0)return null;let{chartRect:r}=t;if(e.x<r.x||e.x>r.x+r.width||e.y<r.y||e.y>r.y+r.height)return null;let i=this.style.arrowSize??12;for(let r=this.markers.length-1;r>=0;r--){let s=this.markers[r],c=a(h(s.time,n),t),l=o(s.price,t),u=i*Math.max(.6,Math.min(1,s.confidence)),d=s.direction===`long`?l-u:(s.direction,l-u*.4),f=s.direction===`long`?l+u*.4:s.direction===`short`?l+u:l+u*.4;if(Math.abs(e.x-c)<=u*.6+gf&&e.y>=d-gf&&e.y<=f+gf)return s}return null}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.markers.length===0)return;let{chartRect:i}=t,s=this.style,c=s.arrowSize??12;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let l of this.markers){let u=a(h(l.time,r),t),d=o(l.price,t);if(u<i.x-c||u>i.x+i.width+c||d<i.y-c||d>i.y+i.height+c)continue;let f=this.resolveColor(l,s),p=c*Math.max(.6,Math.min(1,l.confidence));if(this.renderArrow(e,u,d,l.direction,p,f),s.showLabel&&l.label){e.font=`10px ${n.font.family}`,e.fillStyle=f,e.textAlign=`center`,e.textBaseline=l.direction===`long`?`top`:`bottom`;let t=l.direction===`long`?d+p+3:d-p-3;e.fillText(l.label,u,t)}if(s.showConfidence&&l.confidence<1){e.font=`9px ${n.font.family}`,e.fillStyle=f,e.globalAlpha=.7,e.textAlign=`center`,e.textBaseline=l.direction===`long`?`top`:`bottom`;let t=l.direction===`long`?d+p+(l.label?14:3):d-p-(l.label?14:3);e.fillText(`${Math.round(l.confidence*100)}%`,u,t),e.globalAlpha=1}}e.restore()}resolveColor(e,t){if(e.color)return e.color;if(t.sourceColors?.[e.source])return t.sourceColors[e.source];switch(e.direction){case`long`:return t.longColor??`#1fa874`;case`short`:return t.shortColor??`#e8505b`;default:return t.neutralColor??`#9E9E9E`}}renderArrow(e,t,n,r,i,a){e.fillStyle=a,e.beginPath(),r===`long`?(e.moveTo(t,n-i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n+i*.4),e.lineTo(t+i*.2,n+i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):r===`short`?(e.moveTo(t,n+i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n-i*.4),e.lineTo(t+i*.2,n-i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):e.arc(t,n,i*.4,0,Math.PI*2),e.closePath(),e.fill()}},vf=1,yf=class extends J{zones=[];style={...e.DEFAULT_TRADE_ZONE_STYLE};requestRender=null;dataGetter=null;pricePrecision=2;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setPricePrecision(e){this.pricePrecision=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addZone(e){let t=e.id??`tc_zone_${vf++}`,n={...e,id:t};return this.zones.push(n),this.emit(`added`,n),this.requestRender?.(),t}updateZone(e,t){let n=this.zones.findIndex(t=>t.id===e);n!==-1&&(this.zones[n]={...this.zones[n],...t},this.requestRender?.())}removeZone(e){this.zones=this.zones.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getZones(){return[...this.zones]}clearZones(){this.zones=[],this.emit(`cleared`,void 0),this.requestRender?.()}setZones(e){this.zones=[...e],this.requestRender?.()}render(e,t,n){let r=this.dataGetter?.();if(!r||r.length===0||this.zones.length===0)return;let{chartRect:i}=t,a=this.style;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();for(let i of this.zones)this.renderZone(e,i,r,t,n,a);e.restore()}renderZone(e,t,n,r,i,s){let{chartRect:c}=r,l=h(t.entryTime,n),u=t.exitTime==null?n.length-1:h(t.exitTime,n),d=a(l,r),f=a(u,r),p=Math.max(c.x,Math.min(d,f)),m=Math.min(c.x+c.width,Math.max(d,f));if(m-p<1)return;let g=o(t.entryPrice,r),_=t.exitPrice==null?o(t.entryPrice,r):o(t.exitPrice,r),v=Math.min(g,_),y=Math.max(Math.max(g,_)-v,2),b=t.exitTime==null,x=t.pnl==null?t.direction===`long`?(t.exitPrice??t.entryPrice)>=t.entryPrice:(t.exitPrice??t.entryPrice)<=t.entryPrice:t.pnl>=0,S=b?s.activeColor??`#4c8dff`:x?s.profitColor??`#1fa874`:s.lossColor??`#e8505b`;e.fillStyle=S,e.globalAlpha=s.fillOpacity??.12,e.fillRect(p,v,m-p,y),e.globalAlpha=1;let w=s.borderWidth??1;e.strokeStyle=S,e.lineWidth=w,e.setLineDash([]),e.beginPath(),e.moveTo(p,Math.round(g)+.5),e.lineTo(m,Math.round(g)+.5),e.stroke(),!b&&t.exitPrice!=null&&(e.setLineDash([3,3]),e.beginPath(),e.moveTo(p,Math.round(_)+.5),e.lineTo(m,Math.round(_)+.5),e.stroke(),e.setLineDash([]));let T=t.direction===`long`?`▲`:`▼`;if(e.font=`bold 10px ${i.font.family}`,e.fillStyle=S,e.textBaseline=`bottom`,e.textAlign=`left`,e.fillText(`${T} ${r.formatPrice?.(t.entryPrice)??t.entryPrice.toFixed(this.pricePrecision)}`,p+4,g-3),s.showPnl&&!b&&t.pnl!=null){let n=t.pnl>=0?`+`:``,r=t.pnlPercent==null?`${n}${t.pnl.toFixed(2)}`:`${n}${t.pnl.toFixed(2)} (${n}${t.pnlPercent.toFixed(2)}%)`;e.font=`bold 10px ${i.font.family}`,e.fillStyle=S,e.textBaseline=`top`,e.textAlign=`right`;let a=e.measureText(r).width+8,o=m-a-2,s=v+2;e.globalAlpha=.85,e.fillStyle=i.background,C(e,o,s,a,14,i),e.globalAlpha=1,e.fillStyle=S,e.fillText(r,m-4,s+1)}s.showLabel&&t.label&&(e.font=`9px ${i.font.family}`,e.fillStyle=S,e.globalAlpha=.8,e.textBaseline=`top`,e.textAlign=`left`,e.fillText(t.label,p+4,g+3),e.globalAlpha=1)}},bf=class{active=!1;startBar=0;startPrice=0;endBar=0;endPrice=0;startTime=null;endTime=null;isActive(){return this.active}begin(e,t,n){let r=Math.round(l(e.x,t)),i=u(e.y,t);this.startBar=r,this.startPrice=i,this.endBar=r,this.endPrice=i,this.startTime=xf(r,n),this.endTime=this.startTime,this.active=!0}update(e,t,n){if(!this.active)return;let r=Math.round(l(e.x,t));this.endBar=r,this.endPrice=u(e.y,t),this.endTime=xf(r,n)}end(){this.active=!1}render(e,t,n){if(!this.active)return;let r=a(this.startBar,t),i=a(this.endBar,t),s=o(this.startPrice,t),c=o(this.endPrice,t),l=Math.min(r,i),u=Math.max(r,i),d=Math.min(s,c),f=Math.max(s,c),p=u-l,m=f-d,h=this.endPrice>=this.startPrice?n.candleUp:n.candleDown,g=Df(h,.14);e.save();let{chartRect:_}=t;e.beginPath(),e.rect(_.x,_.y,_.width,_.height),e.clip(),e.fillStyle=g,e.fillRect(l,d,p,m),e.strokeStyle=h,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(l+.5,d+.5,p,m),e.setLineDash([]),e.strokeStyle=h,e.lineWidth=1.5,e.beginPath(),e.moveTo(r,s),e.lineTo(i,c),e.stroke(),wf(e,r,s,h),wf(e,i,c,h),e.restore();let v=Math.abs(this.endBar-this.startBar),y=this.endPrice-this.startPrice,b=this.startPrice===0?0:y/this.startPrice*100,x=this.startTime!==null&&this.endTime!==null?Cf(Math.abs(this.endTime-this.startTime)):null,S=[],C=y>0?`+`:y<0?`−`:``,w=Math.abs(y);S.push(`${C}${t.formatPrice?.(w)??Sf(w)} (${C}${Math.abs(b).toFixed(2)}%)`),S.push(`${v} bars${x?` · `+x:``}`),e.save(),Tf(e,i,c,S,h,n),e.restore()}};function xf(e,t){if(e<0||e>=t.length)return null;let n=t[e].time;return n>0xe8d4a51000?n:n*1e3}function Sf(e){return e>=1e3?e.toFixed(2):e>=1?e.toFixed(4):e.toPrecision(4)}function Cf(e){let t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;let n=t/60;if(n<60)return`${n.toFixed(1)}m`;let r=n/60;if(r<24)return`${r.toFixed(1)}h`;let i=r/24;if(i<30)return`${i.toFixed(1)}d`;let a=i/30;return a<12?`${a.toFixed(1)}mo`:`${(i/365).toFixed(1)}y`}function wf(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t,n,3.5,0,Math.PI*2),e.fill(),e.fillStyle=`#fff`,e.beginPath(),e.arc(t,n,1.5,0,Math.PI*2),e.fill()}function Tf(e,t,n,r,i,a){e.font=`600 11px ${a.font.family}`;let o=0;for(let t of r){let n=e.measureText(t).width;n>o&&(o=n)}let s=Math.ceil(o)+16,c=r.length*14+12,l=t+8,u=n+8,d=e.canvas.clientWidth||e.canvas.width;l+s>d-4&&(l=t-s-8),l<4&&(l=4),e.fillStyle=a.background,e.globalAlpha=.96,Ef(e,l,u,s,c,6),e.fill(),e.globalAlpha=1,e.strokeStyle=i,e.lineWidth=1,Ef(e,l+.5,u+.5,s-1,c-1,6),e.stroke(),e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<r.length;t++)e.fillStyle=t===0?i:a.textSecondary,e.fillText(r[t],l+8,u+6+t*14)}function Ef(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function Df(e,t){if(e.startsWith(`#`)){let n=0,r=0,i=0;return e.length===4?(n=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16),i=parseInt(e[3]+e[3],16)):e.length>=7&&(n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16)),`rgba(${n},${r},${i},${t})`}if(e.startsWith(`rgb`)){let n=e.match(/[\d.]+/g);if(n&&n.length>=3)return`rgba(${n[0]},${n[1]},${n[2]},${t})`}return e}var Of=6,kf=class{start=null;current=null;isActive(){return this.start!==null}begin(e){this.start=e,this.current=e}update(e){this.start&&(this.current=e)}end(){let e=this.start,t=this.current;if(this.cancel(),!e||!t)return null;let n=Math.min(e.x,t.x),r=Math.max(e.x,t.x),i=Math.min(e.y,t.y),a=Math.max(e.y,t.y);return{x0:n,y0:i,x1:r,y1:a,isClick:r-n<6&&a-i<6}}cancel(){this.start=null,this.current=null}render(e,t,n){if(!this.start||!this.current)return;let{chartRect:r}=t,i=e=>Math.max(r.x,Math.min(r.x+r.width,e)),a=e=>Math.max(r.y,Math.min(r.y+r.height,e)),o=i(Math.min(this.start.x,this.current.x)),s=i(Math.max(this.start.x,this.current.x)),c=a(Math.min(this.start.y,this.current.y)),l=a(Math.max(this.start.y,this.current.y));e.save(),e.fillStyle=n.crosshair,e.globalAlpha=.1,e.fillRect(o,c,s-o,l-c),e.globalAlpha=.8,e.strokeStyle=n.crosshair,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(Math.round(o)+.5,Math.round(c)+.5,Math.round(s-o),Math.round(l-c)),e.restore()}},Af={linear:e=>e,easeOutCubic:e=>1-(1-e)**3,easeOutQuart:e=>1-(1-e)**4,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeOutExpo:e=>e===1?1:1-2**(-10*e),easeOutElastic:e=>e===0||e===1?e:2**(-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,spring:e=>1-Math.E**(-6*e)*Math.cos(8*e)},jf=class{animations=new Map;frameId=0;running=!1;animate(e,t){this.animations.set(e,{startTime:-1,duration:t.duration,easing:t.easing??Af.easeOutCubic,onUpdate:t.onUpdate,onComplete:t.onComplete}),this.running||(this.running=!0,this.tick())}cancel(e){this.animations.delete(e),this.animations.size===0&&this.stop()}cancelAll(){this.animations.clear(),this.stop()}isAnimating(e){return e?this.animations.has(e):this.animations.size>0}tick(){this.frameId=requestAnimationFrame(e=>{let t=[];for(let[n,r]of this.animations){r.startTime<0&&(r.startTime=e);let i=e-r.startTime,a=Math.min(1,i/r.duration),o=r.easing(a);r.onUpdate(o),a>=1&&(r.onComplete?.(),t.push(n))}for(let e of t)this.animations.delete(e);this.animations.size>0?this.tick():this.running=!1})}stop(){this.frameId&&=(cancelAnimationFrame(this.frameId),0),this.running=!1}dispose(){this.cancelAll()}};function Mf(t){return!t||t===`dark`?e.DARK_THEME:t===`light`?e.LIGHT_THEME:t}var Nf=class{canvas;ctx;container;theme;width=0;height=0;dpr=1;frameId=null;resizeObserver;constructor(e,t){this.container=e,this.theme=Mf(t),this.canvas=document.createElement(`canvas`),this.canvas.style.width=`100%`,this.canvas.style.height=`100%`,this.canvas.style.display=`block`,e.appendChild(this.canvas),this.ctx=this.canvas.getContext(`2d`),this.dpr=window.devicePixelRatio||1,this.updateSize(),this.resizeObserver=new ResizeObserver(()=>{this.updateSize(),this.requestRender()}),this.resizeObserver.observe(e)}updateSize(){this.dpr=window.devicePixelRatio||1;let e=this.container.getBoundingClientRect();this.width=e.width||this.container.clientWidth,this.height=e.height||this.container.clientHeight,this.canvas.width=Math.max(1,Math.floor(this.width*this.dpr)),this.canvas.height=Math.max(1,Math.floor(this.height*this.dpr))}requestRender(){this.frameId===null&&(this.frameId=requestAnimationFrame(()=>{this.frameId=null,(this.width===0||this.height===0)&&this.updateSize(),!(this.width===0||this.height===0)&&(this.ctx.save(),this.ctx.scale(this.dpr,this.dpr),this.ctx.clearRect(0,0,this.width,this.height),this.renderChart(this.ctx,this.width,this.height,this.theme),this.ctx.restore())}))}setTheme(e){this.theme=Mf(e),this.requestRender()}destroy(){this.frameId!==null&&cancelAnimationFrame(this.frameId),this.resizeObserver.disconnect(),this.canvas.remove()}},Pf=class{pos=null;canvas;onUpdate;handleMove;handleLeave;constructor(e,t){this.canvas=e,this.onUpdate=t,this.handleMove=t=>{let n=e.getBoundingClientRect();this.pos={x:t.clientX-n.left,y:t.clientY-n.top},this.onUpdate()},this.handleLeave=()=>{this.pos=null,this.onUpdate()},e.addEventListener(`pointermove`,this.handleMove),e.addEventListener(`pointerleave`,this.handleLeave)}getPosition(){return this.pos}isActive(){return this.pos!==null}drawCrosshair(e,t,n,r){this.pos&&(e.save(),e.strokeStyle=r,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(this.pos.x,0),e.lineTo(this.pos.x,n),e.stroke(),e.beginPath(),e.moveTo(0,this.pos.y),e.lineTo(t,this.pos.y),e.stroke(),e.restore())}destroy(){this.canvas.removeEventListener(`pointermove`,this.handleMove),this.canvas.removeEventListener(`pointerleave`,this.handleLeave)}};function Ff(e,t,n,r,i){let{data:a,mode:o=`area`,lineWidth:s=1.5,showLastPoint:c=!1,showMinMax:l=!1}=r;if(a.length<2||t<=0||n<=0)return;let u=r.color??i.lineColor,d=r.fillColor??u,f=t-4,p=n-4,m=1/0,h=-1/0,g=0,_=0;for(let e=0;e<a.length;e++)a[e]<m&&(m=a[e],g=e),a[e]>h&&(h=a[e],_=e);let v=h-m||1,y=e=>2+e/(a.length-1)*f,b=e=>2+p-(e-m)/v*p;if(o===`area`){let t=e.createLinearGradient(0,2,0,n-2);t.addColorStop(0,d+(d.startsWith(`#`)?`40`:``)),t.addColorStop(1,`transparent`),e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));e.lineTo(y(a.length-1),n-2),e.lineTo(y(0),n-2),e.closePath(),e.fillStyle=t,e.fill()}e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));if(e.strokeStyle=u,e.lineWidth=s,e.lineJoin=`round`,e.stroke(),c){let t=r.lastPointColor??u,n=y(a.length-1),i=b(a[a.length-1]);e.beginPath(),e.arc(n,i,3,0,Math.PI*2),e.fillStyle=t,e.fill()}if(l){let t=r.minPointColor??i.candleDown,n=r.maxPointColor??i.candleUp;e.beginPath(),e.arc(y(g),b(m),2.5,0,Math.PI*2),e.fillStyle=t,e.fill(),e.beginPath(),e.arc(y(_),b(h),2.5,0,Math.PI*2),e.fillStyle=n,e.fill()}}var If=50,Lf=60,Rf=20,zf=.2;function Bf(e){let t=[...e].sort((e,t)=>t.price-e.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function Vf(e){let t=[...e].sort((e,t)=>e.price-t.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function Hf(e,t){return{left:If,right:e-Lf,top:Rf,bottom:t-Rf,plotWidth:e-If-Lf,plotHeight:t-Rf*2}}function Uf(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function Wf(t,n,r,i,a,o,s,c){let{left:l,right:u,top:d,bottom:f,plotWidth:p,plotHeight:m}=n;t.save(),t.strokeStyle=o.grid,t.lineWidth=.5,t.fillStyle=o.axisLabel,t.font=`${o.font.sizeSmall}px ${o.font.family}`;let h=(0,e.computeTickStep)(0,a,5);for(let e=0;e<=a;e+=h){let n=f-e/a*m;t.beginPath(),t.moveTo(l,n),t.lineTo(u,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),l-4,n)}let g=i-r,_=(0,e.computeTickStep)(r,i,6),v=Math.ceil(r/_)*_;for(let e=v;e<=i;e+=_){let n=l+(e-r)/g*p;t.beginPath(),t.moveTo(n,d),t.lineTo(n,f),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(s(e),n,f+4)}t.restore()}function Gf(e,t,n,r,i,a,o,s,c){if(t.length===0)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-e/a*f;if(e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}else{e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}if(e.closePath(),e.fillStyle=o,e.fill(),e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);n>0&&e.lineTo(r,m(t[n-1].cumulativeVolume)),e.lineTo(r,i)}}else{e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=1;n<t.length;n++){let r=m(t[n-1].cumulativeVolume),i=p(t[n].price),a=m(t[n].cumulativeVolume);e.lineTo(i,r),e.lineTo(i,a)}}e.strokeStyle=s,e.lineWidth=1.5,e.stroke()}function Kf(e,t,n,r,i,a,o,s,c){let{left:l,top:u,bottom:d,plotWidth:f}=r,p=l+(t-i)/a*f;if(e.save(),e.strokeStyle=o.textSecondary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(p,u),e.lineTo(p,d),e.stroke(),e.restore(),s){let t=`Spread: ${c(n)}`;e.save(),e.font=`${o.font.sizeSmall}px ${o.font.family}`,e.fillStyle=o.textSecondary,e.textAlign=`center`,e.textBaseline=`bottom`,e.fillText(t,p,u-2),e.restore()}}function qf(e,t,n,r,i,a,o,s,c,l,u){let{left:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=i,g=t.x;if(g<d||g>i.right)return;let _=a+(g-d)/m*o,v=0,y=``;if(n.length>0&&_<=n[0].price){y=`Bid`;for(let e of n)if(_<=e.price)v=e.cumulativeVolume;else break}if(r.length>0&&_>=r[0].price){y=`Ask`;for(let e of r)if(_>=e.price)v=e.cumulativeVolume;else break}if(e.save(),e.strokeStyle=c.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(g,f),e.lineTo(g,p),e.stroke(),v>0){let t=p-v/s*h;e.beginPath(),e.moveTo(d,t),e.lineTo(i.right,t),e.stroke()}e.restore();let b=[`Price: ${l(_)}`,y?`${y} Vol: ${u(v)}`:``].filter(Boolean);e.save(),e.font=`${c.font.sizeSmall}px ${c.font.family}`;let x=Math.max(...b.map(t=>e.measureText(t).width))+16,S=b.length*(c.font.sizeSmall+4)+12,C=g+10,w=t.y-S/2;C+x>i.right&&(C=g-x-10),w<f&&(w=f),w+S>p&&(w=p-S),e.fillStyle=c.axisLabelBackground,e.globalAlpha=.9,e.fillRect(C,w,x,S),e.globalAlpha=1,e.fillStyle=c.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<b.length;t++)e.fillText(b[t],C+8,w+6+t*(c.font.sizeSmall+4));e.restore()}function Jf(e){return e.toFixed(2)}function Yf(e){return e>=1e6?(e/1e6).toFixed(2)+`M`:e>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(0)}function Xf(e,t,n,r,i,a){let{data:o}=r;if(o.bids.length===0&&o.asks.length===0||t<=0||n<=0)return;let s=r.bidColor??i.candleUp,c=r.askColor??i.candleDown,l=r.bidFillColor??s+`40`,u=r.askFillColor??c+`40`,d=r.midPriceLine!==!1,f=r.spreadLabel!==!1,p=r.priceFormat??Jf,m=r.volumeFormat??Yf,h=Bf(o.bids),g=Vf(o.asks),_=h.length>0?h[0].price:0,v=g.length>0?g[0].price:0,y=h.length>0&&g.length>0?(_+v)/2:_||v,b=g.length>0&&h.length>0?v-_:0,x=h.length>0?h[h.length-1].price:y,S=g.length>0?g[g.length-1].price:y,C=Math.max(y-x,S-y)*(1+zf),w=y-C,T=y+C,E=T-w,D=h.length>0?h[h.length-1].cumulativeVolume:0,O=g.length>0?g[g.length-1].cumulativeVolume:0,k=Math.max(D,O)||1,A=Hf(t,n);Uf(e,t,n,i.background),Wf(e,A,w,T,k,i,p,m),Gf(e,h,A,w,E,k,l,s,`bid`),Gf(e,g,A,w,E,k,u,c,`ask`),d&&Kf(e,y,b,A,w,E,i,f,p),a&&qf(e,a,h,g,A,w,E,k,i,p,m)}var Zf=70,Qf=30,$f=20,ep=20,tp=.05;function np(e,t){return{left:Zf,right:e-$f,top:ep,bottom:t-Qf,plotWidth:e-Zf-$f,plotHeight:t-ep-Qf}}function rp(e,t){let n=1/0,r=-1/0;for(let t of e)t.value<n&&(n=t.value),t.value>r&&(r=t.value);if(t)for(let e of t)e.value<n&&(n=e.value),e.value>r&&(r=e.value);let i=(r-n)*tp;return{valMin:n-i,valMax:r+i}}function ip(e){let t=[],n=-1/0;for(let r of e)r.value>n&&(n=r.value),t.push(n);return t}function ap(e){let t=864e5;if(365.25*t,e<7*t){let e=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`});return t=>e.format(new Date(t))}if(e<315576e5){let e=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`});return t=>e.format(new Date(t))}let n=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});return e=>n.format(new Date(e))}function op(e){return Math.abs(e)>=1e6?(e/1e6).toFixed(2)+`M`:Math.abs(e)>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function sp(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function cp(t,n,r,i,a,o,s,c,l){let{left:u,right:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=n;t.save(),t.strokeStyle=s.grid,t.lineWidth=.5,t.fillStyle=s.axisLabel,t.font=`${s.font.sizeSmall}px ${s.font.family}`;let g=(0,e.computeTickStep)(r,i,6),_=Math.ceil(r/g)*g;for(let e=_;e<=i;e+=g){let n=p-(e-r)/(i-r)*h;t.beginPath(),t.moveTo(u,n),t.lineTo(d,n),t.stroke(),t.textAlign=`right`,t.textBaseline=`middle`,t.fillText(c(e),u-6,n)}let v=o-a,y=(0,e.computeTickStep)(a,o,6),b=Math.ceil(a/y)*y;for(let e=b;e<=o;e+=y){let n=u+(e-a)/v*m;t.beginPath(),t.moveTo(n,f),t.lineTo(n,p),t.stroke(),t.textAlign=`center`,t.textBaseline=`top`,t.fillText(l(e),n,p+4)}t.restore()}function lp(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-(e-a)/o*f;e.save(),e.beginPath(),e.moveTo(p(t[0].time),m(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(p(t[n].time),m(t[n].value));e.strokeStyle=s,e.lineWidth=c,e.lineJoin=`round`,e.stroke(),e.restore()}function up(e,t,n,r,i,a,o,s){if(t.length<2)return;let{left:c,bottom:l,plotWidth:u,plotHeight:d}=n,f=e=>c+(e-r)/i*u,p=e=>l-(e-a)/o*d,m=e.createLinearGradient(0,n.top,0,l);m.addColorStop(0,s+`40`),m.addColorStop(1,`transparent`),e.save(),e.beginPath(),e.moveTo(f(t[0].time),p(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(f(t[n].time),p(t[n].value));e.lineTo(f(t[t.length-1].time),l),e.lineTo(f(t[0].time),l),e.closePath(),e.fillStyle=m,e.fill(),e.restore()}function dp(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=r,p=e=>l+(e-i)/a*d,m=e=>u-(e-o)/s*f;e.save(),e.fillStyle=c,e.beginPath(),e.moveTo(p(t[0].time),m(n[0]));for(let r=1;r<t.length;r++)e.lineTo(p(t[r].time),m(n[r]));for(let n=t.length-1;n>=0;n--)e.lineTo(p(t[n].time),m(t[n].value));e.closePath(),e.fill(),e.restore()}function fp(e,t,n,r,i,a,o,s,c,l){if(t.length===0)return;let{left:u,bottom:d,plotWidth:f,plotHeight:p}=n,m=t[t.length-1],h=u+(m.time-r)/i*f,g=d-(m.value-a)/o*p;e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`,e.fillStyle=c,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(s,h+4,g),e.restore()}function pp(e,t,n,r,i,a,o,s,c,l,u,d){let{left:f,top:p,bottom:m,plotWidth:h,plotHeight:g}=i,_=t.x;if(_<f||_>i.right)return;e.save(),e.strokeStyle=l.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(_,p),e.lineTo(_,m),e.stroke(),e.restore();let v=a+(_-f)/h*o,y=0,b=1/0;for(let e=0;e<n.length;e++){let t=Math.abs(n[e].time-v);t<b&&(b=t,y=e)}let x=n[y],S=[u(x.time),`Value: ${d(x.value)}`];r&&r.length>y&&S.push(`Benchmark: ${d(r[y].value)}`);let C=f+(x.time-a)/o*h,w=m-(x.value-s)/c*g;e.beginPath(),e.arc(C,w,3,0,Math.PI*2),e.fillStyle=l.lineColor,e.fill(),e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`;let T=Math.max(...S.map(t=>e.measureText(t).width))+16,E=S.length*(l.font.sizeSmall+4)+12,D=_+10,O=t.y-E/2;D+T>i.right&&(D=_-T-10),O<p&&(O=p),O+E>m&&(O=m-E),e.fillStyle=l.axisLabelBackground,e.globalAlpha=.9,e.fillRect(D,O,T,E),e.globalAlpha=1,e.fillStyle=l.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<S.length;t++)e.fillText(S[t],D+8,O+6+t*(l.font.sizeSmall+4));e.restore()}function mp(e,t,n,r,i,a){let{data:o}=r;if(o.length<2||t<=0||n<=0)return;let s=r.lineColor??i.lineColor,c=r.lineWidth??1.5,l=r.drawdown===!0,u=r.drawdownColor??i.candleDown+`30`,d=r.fillArea===!0,f=r.benchmark,p=r.benchmarkColor??i.textSecondary,m=r.benchmarkLabel??`Benchmark`,h=r.valueFormat??op,{valMin:g,valMax:_}=rp(o,f),v=_-g||1,y=o[0].time,b=o[o.length-1].time,x=b-y||1,S=r.timeFormat??ap(x),C=np(t,n);sp(e,t,n,i.background),cp(e,C,g,_,y,b,i,h,S),l&&dp(e,o,ip(o),C,y,x,g,v,u),d&&up(e,o,C,y,x,g,v,s),lp(e,o,C,y,x,g,v,s,c),f&&f.length>=2&&(lp(e,f,C,y,x,g,v,p,1),fp(e,f,C,y,x,g,v,m,p,i)),a&&pp(e,a,o,f,C,y,x,g,v,i,S,h)}function hp(e,t,n){if(e.length===0)return[];let r=e.length,i=Math.ceil(Math.sqrt(r)),a=Math.ceil(r/i),o=t.width/i,s=t.height/a,c=[];for(let a=0;a<r;a++){let r=a%i,l=Math.floor(a/i);c.push({id:e[a].id,rect:{x:t.x+r*o+n,y:t.y+l*s+n,width:Math.max(0,o-n*2),height:Math.max(0,s-n*2)}})}return c}function gp(e,t){let n=e.reduce((e,t)=>e+t,0);if(n===0||t===0)return 1/0;let r=0;for(let i of e){let e=n/t,a=i/e,o=e>a?e/a:a/e;o>r&&(r=o)}return r}function _p(e,t,n,r,i,a){let o=r?n.height:n.width,s=e.reduce((e,t)=>e+t,0),c=o>0?s/o:0,l=0;for(let o=0;o<e.length;o++){let s=c>0?e[o]/c:0,u;u=r?{x:n.x+i,y:n.y+l+i,width:Math.max(0,c-i*2),height:Math.max(0,s-i*2)}:{x:n.x+l+i,y:n.y+i,width:Math.max(0,s-i*2),height:Math.max(0,c-i*2)},a.push({id:t[o],rect:u}),l+=s}}function vp(e,t,n,r,i){if(e.length===0)return;let a=n.width>=n.height,o=a?n.height:n.width;if(e.length===1){_p(e,t,n,a,r,i);return}let s=[],c=[],l=0;for(;l<e.length;){let u=[...s,e[l]];if(s.length===0||gp(u,o)<=gp(s,o))s.push(e[l]),c.push(t[l]),l++;else{_p(s,c,n,a,r,i);let u=s.reduce((e,t)=>e+t,0),d=o>0?u/o:0;n=a?{x:n.x+d,y:n.y,width:n.width-d,height:n.height}:{x:n.x,y:n.y+d,width:n.width,height:n.height-d},vp(e.slice(l),t.slice(l),n,r,i);return}}s.length>0&&_p(s,c,n,a,r,i)}function yp(e,t,n){if(e.length===0)return[];let r=[...e].sort((e,t)=>t.weight-e.weight),i=r.reduce((e,t)=>e+Math.max(0,t.weight),0);if(i===0)return[];let a=t.width*t.height,o=r.map(e=>Math.max(0,e.weight)/i*a),s=r.map(e=>e.id),c=[];return vp(o,s,{...t},n,c),c}function bp(e){return(e>=0?`+`:``)+e.toFixed(2)+`%`}function xp(e){return e.label}function Sp(t,n){let r=n.min??-5,i=n.max??5;if(t<=r)return n.negative;if(t>=i)return n.positive;if(t<0){let i=1-t/r;return(0,e.lerpColor)(n.negative,n.zero,i)}let a=t/i;return(0,e.lerpColor)(n.zero,n.positive,a)}function Cp(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function wp(e,t,n,r,i,a,o,s,c,l,u){if(i<40||a<30)return;let d=n+i/2,f=r+a/2;if(e.save(),e.shadowColor=`rgba(0,0,0,0.6)`,e.shadowBlur=2,e.fillStyle=`#FFFFFF`,e.textAlign=`center`,s){let n=l(t),r=Math.min(o.font.sizeMedium,i/n.length*1.5,a/4);e.font=`bold `+Math.max(8,r)+`px `+o.font.family,e.textBaseline=c?`bottom`:`middle`,e.fillText(n,d,c?f-1:f,i-8)}if(c){let n=u(t.value),r=Math.min(o.font.sizeSmall,i/n.length*1.5,a/4);e.font=Math.max(7,r)+`px `+o.font.family,e.textBaseline=s?`top`:`middle`,e.fillText(n,d,s?f+1:f,i-8)}e.restore()}function Tp(e,t,n,r,i,a,o,s){let c=[o(t),s(t.value)];if(t.meta)for(let[e,n]of Object.entries(t.meta))c.push(e+`: `+String(n));e.save(),e.font=a.font.sizeSmall+`px `+a.font.family;let l=Math.max(...c.map(t=>e.measureText(t).width))+16,u=a.font.sizeSmall+4,d=c.length*u+12,f=n.x+14,p=n.y-d/2;f+l>r&&(f=n.x-l-14),p<0&&(p=0),p+d>i&&(p=i-d),e.fillStyle=a.axisLabelBackground,e.globalAlpha=.92,Cp(e,f,p,l,d,4),e.fill(),e.globalAlpha=1,e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<c.length;t++)e.fillText(c[t],f+8,p+6+t*u);e.restore()}function Ep(e,t,n,r,i,a,o,s){if(r.length===0||i.length===0||t<=0||n<=0)return null;let c=a.colorScale??{negative:`#e8505b`,zero:`#424242`,positive:`#1fa874`},l=a.cellRadius??4,u=a.showLabels!==!1,d=a.showValues!==!1,f=a.valueFormat??bp,p=a.labelFormat??xp,m=new Map;for(let e of r)m.set(e.id,e);let h=null,g=null;if(s)for(let e of i){let{x:t,y:n,width:r,height:i}=e.rect;if(s.x>=t&&s.x<=t+r&&s.y>=n&&s.y<=n+i){h=e.id;let t=m.get(e.id);t&&(g={cell:t,rect:e});break}}e.fillStyle=o.background,e.fillRect(0,0,t,n);for(let t of i){let n=m.get(t.id);if(!n)continue;let{x:r,y:i,width:a,height:s}=t.rect;if(a<=0||s<=0)continue;let g=Sp(n.value,c);Cp(e,r,i,a,s,l),e.fillStyle=g,e.fill(),wp(e,n,r,i,a,s,o,u,d,p,f),t.id===h&&(Cp(e,r,i,a,s,l),e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.stroke())}return g&&s&&Tp(e,g.cell,s,t,n,o,p,f),g}var Dp=60,Op=12,kp=24,Ap=40,jp=.7,Mp=1;function Np(e){return e.type?e.type:e.value>0?`positive`:e.value<0?`negative`:`subtotal`}function Pp(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function Fp(e,t){return{left:Dp,right:e-Op,top:kp,bottom:t-Ap,plotWidth:e-Dp-Op,plotHeight:t-kp-Ap}}function Ip(e,t,n,r,i){let a=Array(e.length),o=Array(e.length),s=t.plotWidth/e.length,c=s*n,l=(s-c)/2,{left:u,bottom:d,plotHeight:f}=t,p=0;for(let t=0;t<e.length;t++){let n=e[t],m=Np(n),h,g;m===`total`||m===`subtotal`?(h=0,g=n.value,p=n.value):(h=p,g=p+n.value,p=g);let _=Math.min(h,g),v=Math.max(h,g),y=d-(_-r)/i*f,b=d-(v-r)/i*f,x=Math.min(y,b),S=Math.max(Math.abs(b-y),Mp),C=u+t*s,w=C+l;a[t]={label:n.label,value:n.value,start:h,end:g,type:m,rectX:w,rectY:x,rectW:c,rectH:S,slotX:C,slotW:s},o[t]=p}return{bars:a,cumulatives:o}}function Lp(e){if(e.length===0)return{valMin:0,valMax:1};let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=Np(a),s,c;o===`total`||o===`subtotal`?(s=0,c=a.value,r=a.value):(s=r,c=r+a.value,r=c),s<t&&(t=s),c<t&&(t=c),s>n&&(n=s),c>n&&(n=c)}let i=(n-t||1)*.1;return{valMin:t-i,valMax:n+i}}function Rp(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function zp(t,n,r,i,a,o){let{left:s,right:c,top:l,bottom:u,plotHeight:d}=n,f=i-r||1;t.strokeStyle=a.grid,t.lineWidth=.5,t.fillStyle=a.axisLabel,t.font=`${a.font.sizeSmall}px ${a.font.family}`,t.textAlign=`right`,t.textBaseline=`middle`;let p=(0,e.computeTickStep)(r,i,5),m=Math.ceil(r/p)*p;t.beginPath();for(let e=m;e<=i;e+=p){let n=Math.round(u-(e-r)/f*d)+.5;n<l||n>u||(t.moveTo(s,n),t.lineTo(c,n))}t.stroke();for(let e=m;e<=i;e+=p){let n=u-(e-r)/f*d;n<l-1||n>u+1||t.fillText(o(e),s-6,n)}if(r<0&&i>0){let e=Math.round(u-(0-r)/f*d)+.5;t.strokeStyle=a.axisLine,t.lineWidth=1,t.beginPath(),t.moveTo(s,e),t.lineTo(c,e),t.stroke()}}function Bp(e,t,n){let r=[`positive`,`negative`,`total`,`subtotal`];for(let i=0;i<r.length;i++){let a=r[i],o=n[a],s=!1;e.beginPath();for(let n=0;n<t.length;n++){let r=t[n];if(r.type!==a)continue;let i=Math.round(r.rectX),o=Math.round(r.rectY),c=Math.round(r.rectW),l=Math.round(r.rectH);e.rect(i,o,c,l),s=!0}s&&(e.fillStyle=o,e.fill())}}function Vp(e,t,n,r,i,a,o){if(o===`none`||t.length<2)return;let{bottom:s,plotHeight:c}=n;e.strokeStyle=a,e.lineWidth=1,o===`dashed`?e.setLineDash([4,4]):e.setLineDash([]),e.beginPath();for(let n=0;n<t.length-1;n++){let a=t[n],o=t[n+1],l=a.end,u=Math.round(s-(l-r)/i*c)+.5,d=Math.round(a.rectX+a.rectW),f=Math.round(o.rectX);f<=d||(e.moveTo(d,u),e.lineTo(f,u))}e.stroke(),e.setLineDash([])}function Hp(e,t,n,r,i,a){e.fillStyle=r.text,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`;for(let r=0;r<t.length;r++){let o=t[r],s;s=o.type===`total`||o.type===`subtotal`?i(o.value):a?`${o.value>=0?`+`:``}${i(o.value)}`:i(n[r]);let c=o.rectX+o.rectW/2;o.end<o.start?(e.textBaseline=`top`,e.fillText(s,c,o.rectY+o.rectH+4)):(e.textBaseline=`bottom`,e.fillText(s,c,o.rectY-4))}}function Up(e,t,n,r,i){e.fillStyle=r.axisLabel,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`top`;let a=n.bottom+6,o=t.length>0?t[0].slotW-4:0,s=!1;for(let n=0;n<t.length;n++)if(e.measureText(i(t[n].label)).width>o){s=!0;break}if(!s){for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.fillText(i(r.label),o,a)}return}e.save(),e.textAlign=`right`,e.textBaseline=`middle`;for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.setTransform(1,0,0,1,o,a+4),e.rotate(-Math.PI/4),e.fillText(i(r.label),0,0)}e.setTransform(1,0,0,1,0,0),e.restore()}function Wp(e,t,n){if(t<n.left||t>n.right)return null;for(let n=0;n<e.length;n++){let r=e[n];if(t>=r.slotX&&t<=r.slotX+r.slotW)return n}return null}function Gp(e,t,n,r,i,a,o,s){let c=t[r],l=n[r],u=Math.round(c.slotX+c.slotW/2)+.5;e.strokeStyle=o.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(u,a.top),e.lineTo(u,a.bottom),e.stroke(),e.setLineDash([]);let d=[c.label,`Value: ${c.value>=0&&(c.type===`positive`||c.type===`negative`)?`+`:``}${s(c.value)}`,`Total: ${s(l)}`];e.font=`${o.font.sizeSmall}px ${o.font.family}`;let f=0;for(let t=0;t<d.length;t++){let n=e.measureText(d[t]).width;n>f&&(f=n)}let p=f+16,m=d.length*(o.font.sizeSmall+4)+12,h=i.x+10,g=i.y-m/2;h+p>a.right&&(h=i.x-p-10),g<a.top&&(g=a.top),g+m>a.bottom&&(g=a.bottom-m),e.fillStyle=o.axisLabelBackground,e.globalAlpha=.9,e.fillRect(h,g,p,m),e.globalAlpha=1,e.fillStyle=o.text,e.textAlign=`left`,e.textBaseline=`top`;let _=o.font.sizeSmall+4;for(let t=0;t<d.length;t++)e.fillText(d[t],h+8,g+6+t*_)}function Kp(e,t,n,r,i,a){let{data:o}=r;if(!o||o.length===0||t<=0||n<=0)return{hitBar:null};let s=r.positiveColor??i.candleUp,c=r.negativeColor??i.candleDown,l=r.totalColor??i.lineColor,u=r.subtotalColor??i.textSecondary,d=r.connectorColor??i.textSecondary,f=r.connectorStyle??`dashed`,p=r.barWidth??jp,m=r.showValues!==!1,h=r.showDelta!==!1,g=r.valueFormat??Pp,_=r.labelFormat??(e=>e),{valMin:v,valMax:y}=Lp(o),b=y-v||1,x=Fp(t,n),{bars:S,cumulatives:C}=Ip(o,x,p,v,b);Rp(e,t,n,i.background),zp(e,x,v,y,i,g),Vp(e,S,x,v,b,d,f),Bp(e,S,{positive:s,negative:c,total:l,subtotal:u}),m&&Hp(e,S,C,i,g,h),Up(e,S,x,i,_);let w=a?Wp(S,a.x,x):null;return a&&w!==null&&Gp(e,S,C,w,a,x,i,g),{hitBar:w}}var qp=Math.PI/180,Jp=150,Yp=240,Xp=90,Zp=.14,Qp=1.6*qp,$p=.22,em=8,tm=18,nm=16,rm=6.5,im=20,am=5,om=28;function sm(e,t,n){return e<t?t:e>n?n:e}function cm(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:Number.isInteger(e)?e.toFixed(0):e.toFixed(1)}function lm(e){let t=Number.isFinite(e.startAngle)?e.startAngle:Jp,n=(Number.isFinite(e.endAngle)?e.endAngle:t+Yp)-t;return n<=0&&(n=(n%360+360)%360||360),n=sm(n,Xp,360),{start:(t%360+360)%360*qp,sweep:n*qp}}function um(e,t){let n=Math.min(Math.cos(e),Math.cos(t)),r=Math.max(Math.cos(e),Math.cos(t)),i=Math.min(Math.sin(e),Math.sin(t)),a=Math.max(Math.sin(e),Math.sin(t));for(let o=Math.ceil(e/(Math.PI/2));Math.PI/2*o<=t;o++){let e=Math.PI/2*o;n=Math.min(n,Math.cos(e)),r=Math.max(r,Math.cos(e)),i=Math.min(i,Math.sin(e)),a=Math.max(a,Math.sin(e))}return{minX:n,maxX:r,minY:i,maxY:a}}function dm(e){if(e.showZoneLabels!==!0||!e.zones)return 0;let t=e.zones.reduce((e,t)=>Math.max(e,t.label?.length??0),0);return t>0?t*rm+12:0}function fm(e,t,n){let r=Number.isFinite(n.min)?n.min:0,i=Number.isFinite(n.max)?n.max:100;i-r>Math.abs(r)*1e-9||(i=r+Math.max(1,Math.abs(r)*1e-6));let{start:a,sweep:o}=lm(n),s=a,c=a+o,l=sm(n.thickness??Zp,.04,.5),u=um(s,c),d=Math.max(u.maxY,.18),f=dm(n),p=f>0?nm:0,m=Math.max(1,e-2*em-2*f),h=Math.max(1,t-2*em-tm-p),g=1+l/2,_=Math.max(8,Math.min(m/((u.maxX-u.minX)*g),h/((d-u.minY)*g))),v=_*l,y=(d-u.minY)*_*g+tm+p,b=e/2-(u.maxX+u.minX)/2*_,x=(t-y)/2+p-u.minY*_*g,S=_-v/2,C=Math.max(11,Math.round(S*.46)),w=u.maxY>.3?x-C*.12:x-C*.55,T=Math.max(Math.sin(s),Math.sin(c)),E=T>.2?x+T*_+v/2+2:1/0,D=Math.min(t-em,E);return{cx:b,cy:x,radius:_,thickness:v,startAngle:s,endAngle:c,min:r,max:i,valueY:w,valueSize:C,textBottom:D}}function pm(e,t){let n=Number.isFinite(e)?sm((e-t.min)/(t.max-t.min),0,1):0;return t.startAngle+(t.endAngle-t.startAngle)*n}function mm(e,t){if(!t||!Number.isFinite(e))return;let n;for(let r of t)e>=r.from&&e<=r.to&&(n=r);return n}function hm(e,t,n){let r=(t??[]).map(t=>({a0:pm(t.from,e),a1:pm(t.to,e),color:t.color,track:!1})).filter(e=>e.a1>e.a0).sort((e,t)=>e.a0-t.a0),i=[],a=e.startAngle;for(let e of r)e.a1<=a||(e.a0>a+1e-9&&i.push({a0:a,a1:e.a0,color:n,track:!0}),i.push({...e,a0:Math.max(e.a0,a)}),a=e.a1);return a<e.endAngle-1e-9&&i.push({a0:a,a1:e.endAngle,color:n,track:!0}),i}function gm(e,t,n,r,i){r<=n||(e.beginPath(),e.arc(t.cx,t.cy,t.radius,n,r,!1),e.lineWidth=t.thickness,e.lineCap=`butt`,e.strokeStyle=i,e.stroke())}function _m(e,t,n,r,i,a){let o=t.cx+Math.cos(n)*t.radius,s=t.cy+Math.sin(n)*t.radius,c=a===`start`?n-Math.PI:n;e.globalAlpha=i,e.beginPath(),e.arc(o,s,t.thickness/2,c,c+(i>=1?Math.PI*2:Math.PI),!1),e.closePath(),e.fillStyle=r,e.fill(),e.globalAlpha=1}function vm(e,t,n,r,i,a){let o=hm(t,n,i),s=o.some(e=>!e.track);o.forEach((n,i)=>{let a=i>0&&!n.track&&!o[i-1].track?Qp/2:0,s=i<o.length-1&&!n.track&&!o[i+1].track?Qp/2:0,c=n.a0+a,l=n.a1-s;if(n.track){gm(e,t,c,l,n.color);return}e.globalAlpha=$p,gm(e,t,c,l,n.color),e.globalAlpha=1,gm(e,t,c,Math.min(l,r),n.color)}),s||gm(e,t,t.startAngle,r,a);let c=r>t.startAngle+1e-9,l=r>=t.endAngle-1e-9,u=(e,t)=>e.track?[!s&&t?a:i,1]:[e.color,t?1:$p],[d,f]=u(o[0],c),[p,m]=u(o[o.length-1],l);_m(e,t,t.startAngle,d,f,`start`),_m(e,t,t.endAngle,p,m,`end`)}function ym(e,t,n){let r=t.radius-t.thickness/2;if(r<om)return;let i=Math.max(4,t.thickness*.45);e.strokeStyle=n,e.lineCap=`butt`;for(let n=0;n<=im;n++){let a=n%am===0,o=t.startAngle+(t.endAngle-t.startAngle)*n/im,s=r-i,c=s-(a?Math.max(6,t.thickness*.55):Math.max(3,t.thickness*.3));e.globalAlpha=a?.55:.3,e.lineWidth=a?1.5:1,e.beginPath(),e.moveTo(t.cx+Math.cos(o)*s,t.cy+Math.sin(o)*s),e.lineTo(t.cx+Math.cos(o)*c,t.cy+Math.sin(o)*c),e.stroke()}e.globalAlpha=1}function bm(e,t,n,r,i){let a=t.cx+Math.cos(n)*t.radius,o=t.cy+Math.sin(n)*t.radius;e.beginPath(),e.arc(a,o,t.thickness*.78,0,Math.PI*2),e.fillStyle=r,e.fill(),e.lineWidth=Math.max(2,t.thickness*.32),e.strokeStyle=i,e.stroke()}function xm(e,t,n,r,i){let a=Math.cos(n),o=Math.sin(n),s=t.radius-t.thickness*.9,c=Math.max(6,t.thickness*.6),l=Math.max(1.5,t.thickness*.14);e.beginPath(),e.moveTo(t.cx+a*s,t.cy+o*s),e.lineTo(t.cx-o*l-a*c,t.cy+a*l-o*c),e.lineTo(t.cx+o*l-a*c,t.cy-a*l-o*c),e.closePath(),e.fillStyle=r,e.fill(),e.beginPath(),e.arc(t.cx,t.cy,Math.max(4,t.thickness*.42),0,Math.PI*2),e.fill(),e.lineWidth=2,e.strokeStyle=i,e.stroke()}function Sm(e,t,n,r,i,a,o){e.font=`${n} ${r}px ${i}`;let s=e.measureText(t).width;if(s<=a)return r;let c=Math.floor(r*a/s);return c<o?0:(e.font=`${n} ${c}px ${i}`,c)}function Cm(e,t,n,r,i,a,o){let s=a.font.family,c=(t.radius-t.thickness/2)*1.3,l=a.font.sizeSmall;e.textAlign=`center`,e.textBaseline=`middle`;let u=Sm(e,n,`600`,t.valueSize,s,c,l);if(u===0)return;let d=o?Math.min(t.cy+u*.8,t.textBottom-u/2):t.valueY;e.fillStyle=a.text,e.fillText(n,t.cx,d);let f=Math.max(l,Math.round(u*.26));if(i?.label&&!o){let n=i.label.toUpperCase();Sm(e,n,`600`,f,s,c*.9,l)>0&&(e.fillStyle=i.color,e.fillText(n,t.cx,d-u*.78))}if(r){let n=d+u*.72;n+f/2<=t.textBottom&&Sm(e,r,`400`,f,s,c,l)>0&&(e.fillStyle=a.textSecondary,e.fillText(r,t.cx,n))}}function wm(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall+1}px ${r.font.family}`;let i=t.thickness/2+6;for(let[r,a]of[[t.startAngle,t.min],[t.endAngle,t.max]]){let o=Math.cos(r),s=Math.sin(r),c=t.cx+o*t.radius,l=t.cy+s*t.radius;s>.2?(e.textAlign=`center`,e.textBaseline=`top`,e.fillText(n(a),c,l+i)):(e.textAlign=o<-.2?`right`:o>.2?`left`:`center`,e.textBaseline=s<-.2?`bottom`:`middle`,e.fillText(n(a),c+o*i,l+s*i))}}function Tm(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textBaseline=`middle`;let i=t.radius+t.thickness/2+8;for(let r of n){if(!r.label)continue;let n=pm((sm(r.from,t.min,t.max)+sm(r.to,t.min,t.max))/2,t),a=Math.cos(n);e.textAlign=a<-.2?`right`:a>.2?`left`:`center`,e.fillText(r.label,t.cx+a*i,t.cy+Math.sin(n)*i)}}function Em(e,t,n,r,i,a){if(t<=0||n<=0)return;let o=fm(t,n,r),s=Number.isFinite(a),c=s?sm(a,o.min,o.max):o.min,l=pm(c,o),u=s?mm(c,r.zones):void 0,d=r.pointer===`needle`,f=r.valueFormat??cm,p=u?.color??r.needleColor??i.lineColor;e.save(),e.fillStyle=i.background,e.fillRect(0,0,t,n),vm(e,o,r.zones,l,r.trackColor??i.grid,p),ym(e,o,i.textSecondary),s&&(d?xm(e,o,l,r.needleColor??i.text,i.background):bm(e,o,l,p,i.background)),r.showValue!==!1&&Cm(e,o,s?f(c):`—`,r.label,u,i,d),wm(e,o,f,i),r.showZoneLabels===!0&&r.zones?.length&&Tm(e,o,r.zones,i),e.restore()}exports.ABCDPatternTool=Ss,exports.ADXIndicator=vn,exports.ALMAIndicator=Mr,exports.ATRIndicator=_n,exports.AXIS_LABEL_HEIGHT=T,exports.AcceleratorOscillatorIndicator=or,exports.AccumulationDistributionIndicator=mr,exports.AlertDragHandler=Pi,exports.AlertManager=zd,exports.AlligatorIndicator=nn,exports.AnchoredVWAPIndicator=qt,exports.AnchoredVWAPTool=Yo,exports.Animator=jf,exports.ArcTool=Lc,exports.AreaRenderer=be,exports.AroonIndicator=Cn,exports.ArrowMarkTool=vc,exports.ArrowTool=Wo,exports.AverageDayRangeIndicator=ri,exports.AwesomeOscillatorIndicator=fn,exports.AxisDragHandler=Ni,exports.BalanceOfPowerIndicator=Gn,exports.BarCountdown=md,exports.BarRenderer=xe,exports.BarsPatternTool=fl,exports.BaseFinanceChart=Nf,exports.BaselineRenderer=Ce,exports.BinanceAdapter=zu,exports.BollingerBandWidthIndicator=Wr,exports.BollingerBandsIndicator=Rt,exports.BollingerPercentBIndicator=Ur,exports.BracketTool=Fl,exports.BrushTool=Ac,exports.BybitAdapter=Qu,exports.CCIIndicator=xn,exports.CMFIndicator=En,exports.CalloutTool=uc,exports.CandlestickRenderer=he,exports.CanvasLayer=t,exports.ChaikinOscillatorIndicator=pn,exports.ChaikinVolatilityIndicator=$n,exports.ChandeKrollStopIndicator=Br,exports.ChandeMomentumIndicator=qn,exports.ChandelierExitIndicator=tn,exports.ChartLegend=dd,exports.ChartStateManager=cf,exports.ChoppinessIndexIndicator=kn,exports.CircleTool=Es,exports.CoinbaseAdapter=Ku,exports.CompareRenderer=it,exports.CompareSymbolIndicator=mi,exports.ConnorsRSIIndicator=Nn,exports.CoppockIndicator=Fn,exports.CrossLineTool=as,exports.CrosshairHandler=Li,exports.CrosshairTooltip=Qi,exports.CurrentPriceLine=ru,exports.CurveTool=Ic,exports.CyclicLinesTool=Is,exports.CypherPatternTool=Ts,exports.DEFAULT_LEGEND_CONFIG=ud,exports.DEFAULT_SESSION_HOURS=wd,exports.DEMAIndicator=Ar,exports.DENSE_BAR_WIDTH=fe,exports.DPRManager=i,exports.DataExporter=mf,exports.DateAndPriceRangeTool=Ms,exports.DateRangeTool=Bo,exports.DepthHeatmapBuffer=et,exports.DepthHeatmapRenderer=tt,exports.DepthOverlay=kl,exports.DetrendedPriceOscillatorIndicator=Wn,exports.DisparityIndexIndicator=lr,exports.DonchianChannelIndicator=Wt,exports.DrawingBase=H,exports.DrawingManager=La,exports.DrawingRenderer=za,exports.EMAIndicator=Lt,exports.EaseOfMovementIndicator=Xn,exports.Easing=Af,exports.ElderRayIndicator=zn,exports.ElliottCorrectionTool=Fo,exports.ElliottDoubleComboTool=Lo,exports.ElliottImpulseTool=Po,exports.ElliottTriangleTool=Io,exports.ElliottTripleComboTool=Ro,exports.ElliottWaveTool=No,exports.EllipseTool=wo,exports.Emitter=J,exports.EnvelopeIndicator=sn,exports.EquivolumeRenderer=Oe,exports.EventBus=sa,exports.ExtendedLineTool=po,exports.FibArcsTool=Xc,exports.FibChannelTool=hs,exports.FibCirclesTool=Yc,exports.FibExtensionTool=So,exports.FibRetracementTool=bo,exports.FibSpeedResistanceFanTool=ys,exports.FibSpiralTool=$c,exports.FibTimeZonesTool=Qo,exports.FibWedgeTool=Zc,exports.FinanceCrosshair=Pf,exports.FisherTransformIndicator=Un,exports.FlagTool=hc,exports.ForceIndexIndicator=Mn,exports.ForecastTool=ul,exports.GannBoxTool=Jo,exports.GannFanTool=Ko,exports.GannSquareTool=el,exports.GridRenderer=gi,exports.GuppyMMAIndicator=ci,exports.HLCAreaRenderer=Ae,exports.HeadAndShouldersTool=Cs,exports.HiLoRenderer=Fe,exports.HighlighterTool=jc,exports.HistoricalVolatilityIndicator=Kr,exports.HollowCandleRenderer=Se,exports.HorizontalLineTool=co,exports.HorizontalRayTool=lo,exports.HullMAIndicator=Xt,exports.ICON_GLYPHS=yc,exports.IchimokuIndicator=Bt,exports.IconTool=xc,exports.IndicatorBase=M,exports.IndicatorEngine=Mt,exports.IndicatorValueMap=N,exports.IndicatorWorkerHost=fi,exports.InfoLineTool=ds,exports.InteractionManager=Si,exports.KAMAIndicator=Nr,exports.KSTIndicator=In,exports.KagiRenderer=Te,exports.KeltnerChannelIndicator=Ut,exports.KeyboardHandler=Hi,exports.KlingerIndicator=Hn,exports.KrakenAdapter=ad,exports.LSMAIndicator=Pr,exports.LayerManager=n,exports.LineRenderer=ye,exports.LineWithMarkersRenderer=Me,exports.LinearRegressionChannelIndicator=Yt,exports.LinearRegressionSlopeIndicator=ti,exports.MACDIndicator=hn,exports.MACrossIndicator=Lr,exports.MARibbonIndicator=li,exports.MAX_ALERT_BARS=Ad,exports.MAX_BASE_RATIO=ou,exports.MAX_BASE_REQUESTS=au,exports.MFIIndicator=Sn,exports.MIN_ALERT_BARS=jd,exports.MIN_BAR_UNIT=re,exports.MTFMovingAverageIndicator=$t,exports.MarketProfileRenderer=Ue,exports.MassIndexIndicator=Kn,exports.McGinleyDynamicIndicator=Fr,exports.MeasureOverlay=bf,exports.MeasureTool=Vo,exports.MockAdapter=Bu,exports.ModifiedSchiffPitchforkTool=Oo,exports.MomentumIndicator=Gr,exports.NetVolumeIndicator=ii,exports.NoteTool=lc,exports.OBVIndicator=yn,exports.OrderDraftTool=Vl,exports.OrderRenderer=bl,exports.PanHandler=ji,exports.PaneResizeHandler=Fi,exports.PaperExecutionAdapter=Ql,exports.ParabolicSARIndicator=Vt,exports.ParallelChannelTool=mo,exports.PathTool=Mc,exports.PercentagePriceOscillatorIndicator=ir,exports.PeriodLevelsRenderer=Je,exports.PinnedTooltip=na,exports.PitchfanTool=Qc,exports.PitchforkTool=Eo,exports.PivotMarkersRenderer=Qe,exports.PivotPointsIndicator=Kt,exports.PointAndFigureRenderer=Ee,exports.PollingAdapter=Uu,exports.PolylineTool=Nc,exports.PositionRenderer=Ol,exports.PrettyGoodOscillatorIndicator=dr,exports.PriceAxis=S,exports.PriceAxisAddButton=Ti,exports.PriceLabelTool=Vs,exports.PriceLines=Od,exports.PriceRangeTool=zo,exports.PriceVolumeTrendIndicator=Zn,exports.ProjectionTool=dl,exports.QstickIndicator=ur,exports.RANGE_PRESETS=oe,exports.ROCIndicator=wn,exports.RSIIndicator=mn,exports.RayTool=fo,exports.ReconnectManager=nu,exports.RectangleTool=Co,exports.RegressionChannelTool=ho,exports.RelativeMomentumIndexIndicator=cr,exports.RelativeVigorIndicator=er,exports.RelativeVolatilityIndexIndicator=$r,exports.RenderEngine=ne,exports.RenderLoop=r,exports.RenkoRenderer=we,exports.ReplayController=Tu,exports.ReplayManager=Hd,exports.ResamplingAdapter=mu,exports.RiskRewardTool=is,exports.SELECTION_BOX_MIN_SIZE=Of,exports.SMAIndicator=It,exports.SMMAIndicator=jr,exports.SNAPSHOT_VERSION=Ud,exports.SchaffTrendCycleIndicator=Bn,exports.SchiffPitchforkTool=Do,exports.Screenshot=fd,exports.SelectionBoxOverlay=kf,exports.SessionBreaks=hd,exports.SessionShading=Td,exports.SessionVWAPIndicator=en,exports.SignalMarkerManager=_f,exports.SineLineTool=al,exports.SpreadIndicator=hi,exports.StandardErrorBandsIndicator=ai,exports.StandardErrorIndicator=ni,exports.StdDevIndicator=fr,exports.StepLineRenderer=je,exports.StochasticIndicator=gn,exports.StochasticMomentumIndexIndicator=Qr,exports.StochasticRSIIndicator=tr,exports.StreamManager=wu,exports.SupertrendIndicator=Ht,exports.SymbolSeriesStore=rt,exports.TEMAIndicator=dn,exports.TRIXIndicator=Jn,exports.TSIIndicator=Tn,exports.TextAnnotationTool=Uo,exports.ThreeDrivesTool=ws,exports.TickAggregator=tu,exports.TickBarAdapter=yu,exports.TickBarBuilder=vu,exports.TimeAxis=vi,exports.TimeCyclesTool=il,exports.TradeZoneManager=yf,exports.TradingContextMenu=jl,exports.TradingDragHandler=Al,exports.TradingManager=Xl,exports.TradingRenderer=Zl,exports.TrendAngleTool=ls,exports.TrendLineTool=Wa,exports.TrendStrengthIndexIndicator=ei,exports.TriangleTool=To,exports.UlcerIndexIndicator=Yr,exports.UltimateOscillatorIndicator=An,exports.UndoRedoManager=lf,exports.VROCIndicator=hr,exports.VWAPIndicator=zt,exports.VWMAIndicator=an,exports.VerticalLineTool=uo,exports.Viewport=ie,exports.VolumeCandleRenderer=De,exports.VolumeDeltaIndicator=Dn,exports.VolumeOscillatorIndicator=qr,exports.VolumeProfileIndicator=pr,exports.VolumeProfileRangeTool=Xo,exports.VolumeProfileRenderer=Le,exports.VolumeRenderer=Ie,exports.VortexIndicator=On,exports.WMAIndicator=on,exports.Watermark=pd,exports.WebSocketAdapter=Hu,exports.WilliamsADIndicator=Qn,exports.WilliamsFractalsIndicator=zr,exports.WilliamsRIndicator=bn,exports.XABCDPatternTool=xs,exports.ZigZagIndicator=Jt,exports.ZoomHandler=Mi,exports.alignOutput=kt,exports.arcPoints=Fc,exports.assignSessionLetters=Ve,exports.barIndexToTime=m,exports.barIndexToX=a,exports.barTimeStep=f,exports.barTimeStepMs=p,exports.bracketRiskReward=Nl,exports.classifyPivots=Xe,exports.computeBracketDefaults=Ml,exports.computeMarketProfile=ze,exports.computePeriodLevels=qe,exports.computeSessionProfiles=He,exports.curvePoints=Pc,exports.drawnKeys=pt,exports.fillTag=C,exports.findDominantSwing=Ba,exports.findPivots=Ze,exports.forEachPixelColumn=pe,exports.forecastOutcome=ll,exports.formatTooltipTime=Xi,exports.getIntParam=F,exports.getNumberParam=P,exports.getVisibleData=ae,exports.hasHistogram=yt,exports.hasTrades=Su,exports.indicatorValuePrecision=w,exports.inferOrderType=zl,exports.inputSource=Et,exports.isDense=j,exports.isInWindow=Sd,exports.isPriceLevelAlert=Nd,exports.isRegularSession=Cd,exports.isUpTone=mt,exports.isWorkerResponse=di,exports.labelTextColor=D,exports.layoutSquarifiedTreemap=yp,exports.layoutUniformGrid=hp,exports.lineSourceBars=Ot,exports.lineSpace=la,exports.lttbDownsample=ge,exports.lttbVisibleIndices=ve,exports.mergeSessionHours=bd,exports.minuteOfDay=xd,exports.paneLogRange=_t,exports.paneValueRange=gt,exports.plotColor=ht,exports.priceBucketRow=c,exports.priceSourceBars=Dt,exports.priceToY=o,exports.priceToYMapper=s,exports.rangePresetStart=de,exports.readAlertOptions=Vd,exports.registerBuiltInDrawingTools=pl,exports.registerBuiltInIndicators=ui,exports.renderAxisValueLabels=k,exports.renderDenseBars=me,exports.renderDepthChart=Xf,exports.renderEquityCurve=mp,exports.renderGauge=Em,exports.renderHeatmap=Ep,exports.renderPlots=bt,exports.renderSparkline=Ff,exports.renderWaterfall=Kp,exports.resolveBarIndex=g,exports.servesTimeframe=du,exports.sourceParam=Tt,exports.spreadLabels=E,exports.timeToX=_,exports.timestampToBarIndex=h,exports.toHeikinAshi=at,exports.toKagi=lt,exports.toLineBreak=ct,exports.toPointAndFigure=ut,exports.toRangeBars=dt,exports.toRenko=ot,exports.tpoLetter=Be,exports.waveLabel=Ao,exports.withResampling=lu,exports.withTickBars=xu,exports.xToBarIndex=l,exports.xToTime=v,exports.yToPrice=u;
|
|
26
28
|
//# sourceMappingURL=index.cjs.map
|