@tradecanvas/core 1.4.0 → 1.10.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/README.md +107 -107
- package/dist/WebGLSeriesRenderer-DQOPCwno.js +1643 -0
- package/dist/WebGLSeriesRenderer-DQOPCwno.js.map +1 -0
- package/dist/WebGLSeriesRenderer-DspCYR38.cjs +429 -0
- package/dist/WebGLSeriesRenderer-DspCYR38.cjs.map +1 -0
- package/dist/axis/GridRenderer.d.ts.map +1 -1
- package/dist/axis/PriceAxis.d.ts +12 -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/axis/gridLines.d.ts +9 -0
- package/dist/axis/gridLines.d.ts.map +1 -0
- 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 +6 -3
- 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/pixelGrid.d.ts +49 -0
- package/dist/charts/pixelGrid.d.ts.map +1 -0
- 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 +34 -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/DrawingRenderer.d.ts +2 -2
- package/dist/drawings/DrawingRenderer.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/CrossLine.d.ts.map +1 -1
- package/dist/drawings/tools/DateRange.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/GannBox.d.ts.map +1 -1
- package/dist/drawings/tools/GannFan.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/TrendAngle.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/VerticalLine.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 +32 -3
- package/dist/drawings/tools/labels.d.ts.map +1 -1
- package/dist/drawings/tools/options.d.ts +16 -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/LayerManager.d.ts +23 -0
- package/dist/engine/LayerManager.d.ts.map +1 -1
- package/dist/engine/RenderEngine.d.ts +53 -1
- package/dist/engine/RenderEngine.d.ts.map +1 -1
- package/dist/engine/gpu.d.ts +83 -0
- package/dist/engine/gpu.d.ts.map +1 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/loadWebGL.d.ts +9 -0
- package/dist/engine/loadWebGL.d.ts.map +1 -0
- package/dist/engine/plotSteps.d.ts +39 -0
- package/dist/engine/plotSteps.d.ts.map +1 -0
- 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/gridLines-J41F0DQ6.cjs +2 -0
- package/dist/gridLines-J41F0DQ6.cjs.map +1 -0
- package/dist/gridLines-kFhXyH-u.js +218 -0
- package/dist/gridLines-kFhXyH-u.js.map +1 -0
- package/dist/index.cjs +11 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10638 -4930
- 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 +123 -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/linePen.d.ts +38 -0
- package/dist/indicators/linePen.d.ts.map +1 -0
- 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/TradingDragHandler.d.ts.map +1 -1
- package/dist/trading/TradingManager.d.ts +26 -2
- package/dist/trading/TradingManager.d.ts.map +1 -1
- package/dist/trading/TradingRenderer.d.ts +2 -0
- package/dist/trading/TradingRenderer.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/plot.d.ts +4 -0
- package/dist/trading/plot.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 +14 -1
- package/dist/ui/SessionBreaks.d.ts.map +1 -1
- package/dist/ui/SessionShading.d.ts +5 -0
- package/dist/ui/SessionShading.d.ts.map +1 -1
- package/dist/ui/Watermark.d.ts +2 -0
- package/dist/ui/Watermark.d.ts.map +1 -1
- package/dist/ui/axisValueLabels.d.ts +52 -0
- package/dist/ui/axisValueLabels.d.ts.map +1 -0
- package/dist/ui/index.d.ts +7 -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/dist/webgl/WebGLSeriesRenderer.d.ts +70 -0
- package/dist/webgl/WebGLSeriesRenderer.d.ts.map +1 -0
- package/dist/webgl/commandDrawer.d.ts +31 -0
- package/dist/webgl/commandDrawer.d.ts.map +1 -0
- package/dist/webgl/glColor.d.ts +13 -0
- package/dist/webgl/glColor.d.ts.map +1 -0
- package/dist/webgl/glKit.d.ts +26 -0
- package/dist/webgl/glKit.d.ts.map +1 -0
- package/dist/webgl/index.d.ts +5 -0
- package/dist/webgl/index.d.ts.map +1 -0
- package/dist/webgl/polygonSpans.d.ts +20 -0
- package/dist/webgl/polygonSpans.d.ts.map +1 -0
- package/dist/webgl/recordedCommands.d.ts +75 -0
- package/dist/webgl/recordedCommands.d.ts.map +1 -0
- package/dist/webgl/recordedPath.d.ts +51 -0
- package/dist/webgl/recordedPath.d.ts.map +1 -0
- package/dist/webgl/recordedShaders.d.ts +38 -0
- package/dist/webgl/recordedShaders.d.ts.map +1 -0
- package/dist/webgl/recorder.d.ts +67 -0
- package/dist/webgl/recorder.d.ts.map +1 -0
- package/dist/webgl/seriesUploads.d.ts +40 -0
- package/dist/webgl/seriesUploads.d.ts.map +1 -0
- package/dist/webgl/shaders.d.ts +39 -0
- package/dist/webgl/shaders.d.ts.map +1 -0
- package/dist/webgl/strokeGeometry.d.ts +28 -0
- package/dist/webgl/strokeGeometry.d.ts.map +1 -0
- package/dist/webgl/yMapping.d.ts +32 -0
- package/dist/webgl/yMapping.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,1643 @@
|
|
|
1
|
+
import { i as e, o as t, r as n, t as r } from "./gridLines-kFhXyH-u.js";
|
|
2
|
+
import { resolveVolumeColors as i } from "@tradecanvas/commons";
|
|
3
|
+
var a = (e, t) => e.time === t.time && e.open === t.open && e.high === t.high && e.low === t.low && e.close === t.close && e.volume === t.volume, o = class {
|
|
4
|
+
buffer = new Float32Array();
|
|
5
|
+
count = 0;
|
|
6
|
+
basePrice = 0;
|
|
7
|
+
samples = [];
|
|
8
|
+
last = null;
|
|
9
|
+
source = null;
|
|
10
|
+
get values() {
|
|
11
|
+
return this.buffer;
|
|
12
|
+
}
|
|
13
|
+
get length() {
|
|
14
|
+
return this.count;
|
|
15
|
+
}
|
|
16
|
+
get base() {
|
|
17
|
+
return this.basePrice;
|
|
18
|
+
}
|
|
19
|
+
sync(e) {
|
|
20
|
+
let t = e.length;
|
|
21
|
+
if (t === 0) return this.reset(), {
|
|
22
|
+
full: !0,
|
|
23
|
+
from: 0,
|
|
24
|
+
to: 0
|
|
25
|
+
};
|
|
26
|
+
let n = this.count;
|
|
27
|
+
if (!(e === this.source && n > 0 && t >= n && this.samples.every(({ index: t, bar: n }) => a(e[t], n)))) return this.basePrice = e[t - 1].close, this.ensure(t), this.write(e, 0, t), this.remember(e), {
|
|
28
|
+
full: !0,
|
|
29
|
+
from: 0,
|
|
30
|
+
to: t
|
|
31
|
+
};
|
|
32
|
+
let r = this.last !== null && a(e[n - 1], this.last) ? n : n - 1;
|
|
33
|
+
return t > this.buffer.length / 6 ? (this.ensure(t), this.write(e, 0, t), this.remember(e), {
|
|
34
|
+
full: !0,
|
|
35
|
+
from: 0,
|
|
36
|
+
to: t
|
|
37
|
+
}) : (this.write(e, r, t), this.remember(e), {
|
|
38
|
+
full: !1,
|
|
39
|
+
from: r,
|
|
40
|
+
to: t
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
reset() {
|
|
44
|
+
this.count = 0, this.samples = [], this.last = null, this.source = null;
|
|
45
|
+
}
|
|
46
|
+
ensure(e) {
|
|
47
|
+
e * 6 <= this.buffer.length || (this.buffer = new Float32Array(Math.max(e + 1024, Math.ceil(e * 1.25)) * 6));
|
|
48
|
+
}
|
|
49
|
+
write(e, t, n) {
|
|
50
|
+
let r = this.buffer, i = this.basePrice;
|
|
51
|
+
for (let a = t; a < n; a++) {
|
|
52
|
+
let t = e[a], n = a * 6;
|
|
53
|
+
r[n] = t.open - i, r[n + 1] = t.high - i, r[n + 2] = t.low - i, r[n + 3] = t.close - i, r[n + 4] = t.volume, r[n + 5] = +(t.close >= t.open);
|
|
54
|
+
}
|
|
55
|
+
this.count = n;
|
|
56
|
+
}
|
|
57
|
+
remember(e) {
|
|
58
|
+
let t = e.length, n = t - 1, r = /* @__PURE__ */ new Set();
|
|
59
|
+
if (n > 0) for (let e = 0; e < 16; e++) r.add(Math.min(n - 1, Math.round(e * (n - 1) / 15)));
|
|
60
|
+
this.samples = [...r].map((t) => ({
|
|
61
|
+
index: t,
|
|
62
|
+
bar: { ...e[t] }
|
|
63
|
+
})), this.last = { ...e[t - 1] }, this.source = e;
|
|
64
|
+
}
|
|
65
|
+
}, s = /* @__PURE__ */ new Map(), c;
|
|
66
|
+
function l(e, t) {
|
|
67
|
+
return e.endsWith("%") ? parseFloat(e) / 100 : parseFloat(e) / t;
|
|
68
|
+
}
|
|
69
|
+
function u(e) {
|
|
70
|
+
let t = e.trim();
|
|
71
|
+
if (t.toLowerCase() === "transparent") return [
|
|
72
|
+
0,
|
|
73
|
+
0,
|
|
74
|
+
0,
|
|
75
|
+
0
|
|
76
|
+
];
|
|
77
|
+
let n = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(t);
|
|
78
|
+
if (n) {
|
|
79
|
+
let e = n[1];
|
|
80
|
+
e.length <= 4 && (e = [...e].map((e) => e + e).join(""));
|
|
81
|
+
let t = (t) => parseInt(e.slice(t, t + 2), 16) / 255;
|
|
82
|
+
return [
|
|
83
|
+
t(0),
|
|
84
|
+
t(2),
|
|
85
|
+
t(4),
|
|
86
|
+
e.length === 8 ? t(6) : 1
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
let r = /^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i.exec(t);
|
|
90
|
+
return r ? [
|
|
91
|
+
l(r[1], 255),
|
|
92
|
+
l(r[2], 255),
|
|
93
|
+
l(r[3], 255),
|
|
94
|
+
r[4] === void 0 ? 1 : l(r[4], 1)
|
|
95
|
+
] : null;
|
|
96
|
+
}
|
|
97
|
+
function d() {
|
|
98
|
+
if (c !== void 0) return c;
|
|
99
|
+
try {
|
|
100
|
+
c = typeof OffscreenCanvas < "u" ? new OffscreenCanvas(1, 1).getContext("2d") : typeof document < "u" ? document.createElement("canvas").getContext("2d") : null;
|
|
101
|
+
} catch {
|
|
102
|
+
c = null;
|
|
103
|
+
}
|
|
104
|
+
return c;
|
|
105
|
+
}
|
|
106
|
+
function f(e) {
|
|
107
|
+
let t = d();
|
|
108
|
+
if (!t) return null;
|
|
109
|
+
t.fillStyle = "#000", t.fillStyle = e;
|
|
110
|
+
let n = String(t.fillStyle);
|
|
111
|
+
if (t.fillStyle = "#fff", t.fillStyle = e, String(t.fillStyle) !== n) return null;
|
|
112
|
+
let r = u(n);
|
|
113
|
+
if (r) return r;
|
|
114
|
+
t.clearRect(0, 0, 1, 1), t.fillRect(0, 0, 1, 1);
|
|
115
|
+
let i = t.getImageData(0, 0, 1, 1).data;
|
|
116
|
+
return [
|
|
117
|
+
i[0] / 255,
|
|
118
|
+
i[1] / 255,
|
|
119
|
+
i[2] / 255,
|
|
120
|
+
i[3] / 255
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
var p = /* @__PURE__ */ new Set();
|
|
124
|
+
function m(e) {
|
|
125
|
+
let t = s.get(e);
|
|
126
|
+
if (t) return t;
|
|
127
|
+
if (p.has(e)) return null;
|
|
128
|
+
let n = u(e) ?? f(e);
|
|
129
|
+
return s.size > 256 && s.clear(), p.size > 256 && p.clear(), n ? s.set(e, n) : p.add(e), n;
|
|
130
|
+
}
|
|
131
|
+
function h(e) {
|
|
132
|
+
return m(e) ?? [
|
|
133
|
+
0,
|
|
134
|
+
0,
|
|
135
|
+
0,
|
|
136
|
+
0
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
function g([e, t, n, r]) {
|
|
140
|
+
return [
|
|
141
|
+
e * r,
|
|
142
|
+
t * r,
|
|
143
|
+
n * r,
|
|
144
|
+
r
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/webgl/yMapping.ts
|
|
149
|
+
function _(e, t) {
|
|
150
|
+
let { min: n, max: r } = e.priceRange, { y: i, height: a } = e.chartRect, o = +(e.invertScale === !0), s = {
|
|
151
|
+
log: 0,
|
|
152
|
+
invert: o,
|
|
153
|
+
yA: i + a / 2,
|
|
154
|
+
yB: 0,
|
|
155
|
+
logOffset: 0,
|
|
156
|
+
min: 1,
|
|
157
|
+
logFloor: 0,
|
|
158
|
+
logK: 0,
|
|
159
|
+
top: i,
|
|
160
|
+
bottom: i + a
|
|
161
|
+
};
|
|
162
|
+
if (e.logScale && n > 0 && r > 0) {
|
|
163
|
+
let e = Math.log(r) - Math.log(n);
|
|
164
|
+
return e === 0 ? s : {
|
|
165
|
+
...s,
|
|
166
|
+
log: 1,
|
|
167
|
+
logOffset: t - n,
|
|
168
|
+
min: n,
|
|
169
|
+
logFloor: 2 ** -52 / n,
|
|
170
|
+
logK: a / e
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
let c = r - n;
|
|
174
|
+
if (c === 0) return s;
|
|
175
|
+
let l = a / c;
|
|
176
|
+
return o ? {
|
|
177
|
+
...s,
|
|
178
|
+
yA: i + (t - n) * l,
|
|
179
|
+
yB: l
|
|
180
|
+
} : {
|
|
181
|
+
...s,
|
|
182
|
+
yA: i + (r - t) * l,
|
|
183
|
+
yB: -l
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/webgl/glKit.ts
|
|
188
|
+
var v = class {
|
|
189
|
+
constructor(e) {
|
|
190
|
+
this.gl = e;
|
|
191
|
+
}
|
|
192
|
+
program(e, t, n) {
|
|
193
|
+
let r = this.gl, i = (e, t) => {
|
|
194
|
+
let n = r.createShader(e);
|
|
195
|
+
if (!n) throw Error("WebGL: no shader");
|
|
196
|
+
if (r.shaderSource(n, t), r.compileShader(n), !r.getShaderParameter(n, r.COMPILE_STATUS)) {
|
|
197
|
+
let e = r.getShaderInfoLog(n);
|
|
198
|
+
throw r.deleteShader(n), Error(`WebGL shader: ${e}`);
|
|
199
|
+
}
|
|
200
|
+
return n;
|
|
201
|
+
}, a = i(r.VERTEX_SHADER, e), o = i(r.FRAGMENT_SHADER, t), s = r.createProgram();
|
|
202
|
+
if (!s) throw Error("WebGL: no program");
|
|
203
|
+
if (r.attachShader(s, a), r.attachShader(s, o), r.linkProgram(s), r.deleteShader(a), r.deleteShader(o), !r.getProgramParameter(s, r.LINK_STATUS)) throw Error(`WebGL program: ${r.getProgramInfoLog(s)}`);
|
|
204
|
+
let c = r.createVertexArray();
|
|
205
|
+
if (!c) throw Error("WebGL: no vertex array");
|
|
206
|
+
let l = /* @__PURE__ */ new Map();
|
|
207
|
+
for (let e of n) l.set(e, r.getAttribLocation(s, e));
|
|
208
|
+
return {
|
|
209
|
+
program: s,
|
|
210
|
+
vao: c,
|
|
211
|
+
uniforms: /* @__PURE__ */ new Map(),
|
|
212
|
+
attribs: l
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
buffer() {
|
|
216
|
+
let e = this.gl.createBuffer();
|
|
217
|
+
if (!e) throw Error("WebGL: no buffer");
|
|
218
|
+
return e;
|
|
219
|
+
}
|
|
220
|
+
use(e) {
|
|
221
|
+
return this.gl.useProgram(e.program), this.gl.bindVertexArray(e.vao), e;
|
|
222
|
+
}
|
|
223
|
+
attrib(e, t, n, r, i, a = 1) {
|
|
224
|
+
let o = e.attribs.get(t);
|
|
225
|
+
if (o === void 0 || o < 0) return;
|
|
226
|
+
let s = this.gl;
|
|
227
|
+
s.enableVertexAttribArray(o), s.vertexAttribPointer(o, n, s.FLOAT, !1, r, i), s.vertexAttribDivisor(o, a);
|
|
228
|
+
}
|
|
229
|
+
int(e, t, n) {
|
|
230
|
+
this.gl.uniform1i(this.loc(e, t), n);
|
|
231
|
+
}
|
|
232
|
+
float(e, t, n) {
|
|
233
|
+
this.gl.uniform1f(this.loc(e, t), n);
|
|
234
|
+
}
|
|
235
|
+
vec2(e, t, n, r) {
|
|
236
|
+
this.gl.uniform2f(this.loc(e, t), n, r);
|
|
237
|
+
}
|
|
238
|
+
vec4(e, t, n) {
|
|
239
|
+
this.gl.uniform4f(this.loc(e, t), n[0], n[1], n[2], n[3]);
|
|
240
|
+
}
|
|
241
|
+
loc(e, t) {
|
|
242
|
+
return e.uniforms.has(t) || e.uniforms.set(t, this.gl.getUniformLocation(e.program, t)), e.uniforms.get(t) ?? null;
|
|
243
|
+
}
|
|
244
|
+
deleteProgram(e) {
|
|
245
|
+
this.gl.deleteVertexArray(e.vao), this.gl.deleteProgram(e.program);
|
|
246
|
+
}
|
|
247
|
+
scissor(e, t, n, r, i, a) {
|
|
248
|
+
let o = Math.max(0, Math.floor(e)), s = Math.max(0, Math.floor(t)), c = Math.min(i, Math.ceil(n)), l = Math.min(a, Math.ceil(r));
|
|
249
|
+
if (!(c > o && l > s)) return !1;
|
|
250
|
+
let u = this.gl;
|
|
251
|
+
return u.enable(u.SCISSOR_TEST), u.scissor(o, a - l, c - o, l - s), !0;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/webgl/polygonSpans.ts
|
|
256
|
+
function ee(e) {
|
|
257
|
+
let t = e.length / 2;
|
|
258
|
+
if (t < 3) return [];
|
|
259
|
+
let n = 0, r = 0;
|
|
260
|
+
for (let i = 1; i < t; i++) e[2 * i] < e[2 * n] && (n = i), e[2 * i] > e[2 * r] && (r = i);
|
|
261
|
+
if (e[2 * n] === e[2 * r]) return [];
|
|
262
|
+
let i = b(e, n, r, 1, t), a = b(e, n, r, -1, t);
|
|
263
|
+
return !i || !a ? null : te(i, a);
|
|
264
|
+
}
|
|
265
|
+
function y(e) {
|
|
266
|
+
let t = 0, n = e.length / 2;
|
|
267
|
+
for (let r = 0; r < n; r++) {
|
|
268
|
+
let i = (r + 1) % n;
|
|
269
|
+
t += e[2 * r] * e[2 * i + 1] - e[2 * i] * e[2 * r + 1];
|
|
270
|
+
}
|
|
271
|
+
return t / 2;
|
|
272
|
+
}
|
|
273
|
+
function b(e, t, n, r, i) {
|
|
274
|
+
let a = [e[2 * t], e[2 * t + 1]];
|
|
275
|
+
for (let o = t; o !== n;) {
|
|
276
|
+
if (o = (o + r + i) % i, e[2 * o] < a[a.length - 2]) return null;
|
|
277
|
+
a.push(e[2 * o], e[2 * o + 1]);
|
|
278
|
+
}
|
|
279
|
+
return a;
|
|
280
|
+
}
|
|
281
|
+
var x = class {
|
|
282
|
+
i = 0;
|
|
283
|
+
constructor(e) {
|
|
284
|
+
this.c = e;
|
|
285
|
+
}
|
|
286
|
+
at(e, t) {
|
|
287
|
+
let n = this.c;
|
|
288
|
+
for (; this.i + 5 < n.length && (n[this.i + 2] < t || n[this.i + 2] === n[this.i]);) this.i += 2;
|
|
289
|
+
let r = n[this.i], i = n[this.i + 1], a = n[this.i + 2], o = n[this.i + 3], s = (e) => a === r ? i : i + (o - i) * (e - r) / (a - r);
|
|
290
|
+
return [s(e), s(t)];
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
function te(e, t) {
|
|
294
|
+
let n = /* @__PURE__ */ new Set();
|
|
295
|
+
for (let t = 0; t < e.length; t += 2) n.add(e[t]);
|
|
296
|
+
for (let e = 0; e < t.length; e += 2) n.add(t[e]);
|
|
297
|
+
let r = [...n].sort((e, t) => e - t), i = new x(e), a = new x(t), o = [], s = r.length - 2;
|
|
298
|
+
for (let e = 0; e <= s; e++) {
|
|
299
|
+
let t = r[e], n = r[e + 1], [c, l] = i.at(t, n), [u, d] = a.at(t, n);
|
|
300
|
+
c === u && l === d || o.push(t, n, c, l, u, d, +(e === 0), +(e === s));
|
|
301
|
+
}
|
|
302
|
+
return o;
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/webgl/recordedShaders.ts
|
|
306
|
+
var S = "#version 300 es\nprecision highp float;\nuniform vec2 u_canvas;\nuniform vec4 u_clip;\n\nvec4 toClip(vec2 dev) {\n return vec4(dev.x / u_canvas.x * 2.0 - 1.0, 1.0 - dev.y / u_canvas.y * 2.0, 0.0, 1.0);\n}\n", C = "\nvec2 corner(int k) {\n if (k == 0) return vec2(0.0, 0.0);\n if (k == 1 || k == 4) return vec2(1.0, 0.0);\n if (k == 2 || k == 3) return vec2(0.0, 1.0);\n return vec2(1.0, 1.0);\n}\nconst vec4 NOWHERE = vec4(-2.0, -2.0, 0.0, 1.0);\n", w = "\n// This fragment's pixel centre in device pixels, y down.\nvec2 pixelCentre() { return vec2(gl_FragCoord.x, u_canvas.y - gl_FragCoord.y); }\n\n// The share of the pixel centred at p inside the clip.\nfloat clipCoverage(vec2 p) {\n vec2 lo = p - 0.5;\n vec2 c = clamp(min(lo + 1.0, u_clip.zw) - max(lo, u_clip.xy), 0.0, 1.0);\n return c.x * c.y;\n}\n", ne = `${S}${C}
|
|
307
|
+
uniform float u_hw;
|
|
308
|
+
in vec4 a_p0;
|
|
309
|
+
in vec4 a_p1;
|
|
310
|
+
in vec4 a_p2;
|
|
311
|
+
in vec4 a_p3;
|
|
312
|
+
in vec4 a_p4;
|
|
313
|
+
in vec4 a_p5;
|
|
314
|
+
flat out vec4 v_p0;
|
|
315
|
+
flat out vec4 v_p1;
|
|
316
|
+
flat out vec4 v_p2;
|
|
317
|
+
flat out vec4 v_p3;
|
|
318
|
+
flat out vec4 v_p4;
|
|
319
|
+
flat out vec4 v_p5;
|
|
320
|
+
|
|
321
|
+
void main() {
|
|
322
|
+
v_p0 = a_p0; v_p1 = a_p1; v_p2 = a_p2; v_p3 = a_p3; v_p4 = a_p4; v_p5 = a_p5;
|
|
323
|
+
if (a_p2.z < 0.5 || a_p3.z < 0.5) { gl_Position = NOWHERE; return; }
|
|
324
|
+
vec2 a = a_p2.xy;
|
|
325
|
+
vec2 b = a_p3.xy;
|
|
326
|
+
vec2 d = b - a;
|
|
327
|
+
float len = length(d);
|
|
328
|
+
vec2 dir = len > 0.0 ? d / len : vec2(1.0, 0.0);
|
|
329
|
+
vec2 n = vec2(-dir.y, dir.x);
|
|
330
|
+
float m = u_hw + 1.0;
|
|
331
|
+
vec2 cr = corner(gl_VertexID % 6);
|
|
332
|
+
vec2 pos = mix(a - dir * m, b + dir * m, cr.x) + n * mix(-m, m, cr.y);
|
|
333
|
+
gl_Position = toClip(pos);
|
|
334
|
+
}
|
|
335
|
+
`, re = `${S}${w}
|
|
336
|
+
uniform vec4 u_color;
|
|
337
|
+
uniform float u_hw;
|
|
338
|
+
uniform int u_cap;
|
|
339
|
+
uniform vec4 u_dash;
|
|
340
|
+
flat in vec4 v_p0;
|
|
341
|
+
flat in vec4 v_p1;
|
|
342
|
+
flat in vec4 v_p2;
|
|
343
|
+
flat in vec4 v_p3;
|
|
344
|
+
flat in vec4 v_p4;
|
|
345
|
+
flat in vec4 v_p5;
|
|
346
|
+
out vec4 outColor;
|
|
347
|
+
|
|
348
|
+
float segDist(vec2 p, vec2 a, vec2 b) {
|
|
349
|
+
vec2 ab = b - a;
|
|
350
|
+
float l2 = dot(ab, ab);
|
|
351
|
+
float t = l2 > 0.0 ? clamp(dot(p - a, ab) / l2, 0.0, 1.0) : 0.0;
|
|
352
|
+
return length(p - a - t * ab);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
bool joined(vec4 a, vec4 b) { return a.z > -0.5 && b.z > -0.5; }
|
|
356
|
+
|
|
357
|
+
// The share of a pixel at distance d from the centre line inside a line hw either side.
|
|
358
|
+
float across(float d) { return clamp(min(u_hw, d + 0.5) - max(-u_hw, d - 0.5), 0.0, 1.0); }
|
|
359
|
+
|
|
360
|
+
// The share of [s - 0.5, s + 0.5] inside [lo, hi].
|
|
361
|
+
float span(float s, float lo, float hi) { return clamp(min(s + 0.5, hi) - max(s - 0.5, lo), 0.0, 1.0); }
|
|
362
|
+
|
|
363
|
+
// The share of [s - 0.5, s + 0.5] on a dash.
|
|
364
|
+
float onDash(float s) {
|
|
365
|
+
float period = u_dash.x + u_dash.y + u_dash.z + u_dash.w;
|
|
366
|
+
float base = s - mod(s, period);
|
|
367
|
+
float on = 0.0;
|
|
368
|
+
for (int k = -1; k <= 1; k++) {
|
|
369
|
+
float p0 = base + float(k) * period;
|
|
370
|
+
on += span(s, p0, p0 + u_dash.x);
|
|
371
|
+
on += span(s, p0 + u_dash.x + u_dash.y, p0 + u_dash.x + u_dash.y + u_dash.z);
|
|
372
|
+
}
|
|
373
|
+
return min(on, 1.0);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
void main() {
|
|
377
|
+
vec2 p = pixelCentre();
|
|
378
|
+
float clipCov = clipCoverage(p);
|
|
379
|
+
if (clipCov <= 0.0) discard;
|
|
380
|
+
vec2 a = v_p2.xy;
|
|
381
|
+
vec2 b = v_p3.xy;
|
|
382
|
+
vec2 ab = b - a;
|
|
383
|
+
float len = length(ab);
|
|
384
|
+
vec2 dir = len > 0.0 ? ab / len : vec2(1.0, 0.0);
|
|
385
|
+
float along = dot(p - a, dir);
|
|
386
|
+
float perp = abs(dot(p - a, vec2(-dir.y, dir.x)));
|
|
387
|
+
bool startEnd = v_p1.z < -0.5;
|
|
388
|
+
bool finalEnd = v_p4.z < -0.5;
|
|
389
|
+
|
|
390
|
+
float cov;
|
|
391
|
+
if (u_dash.x + u_dash.y > 0.0) {
|
|
392
|
+
cov = across(perp) * onDash(v_p2.w + along) * span(along, 0.0, len);
|
|
393
|
+
} else {
|
|
394
|
+
float self = segDist(p, a, b);
|
|
395
|
+
float nearest = self;
|
|
396
|
+
if (joined(v_p0, v_p1)) { float d = segDist(p, v_p0.xy, v_p1.xy); if (d <= self) discard; nearest = min(nearest, d); }
|
|
397
|
+
if (joined(v_p1, v_p2)) { float d = segDist(p, v_p1.xy, v_p2.xy); if (d <= self) discard; nearest = min(nearest, d); }
|
|
398
|
+
if (joined(v_p3, v_p4)) { float d = segDist(p, v_p3.xy, v_p4.xy); if (d < self) discard; nearest = min(nearest, d); }
|
|
399
|
+
if (joined(v_p4, v_p5)) { float d = segDist(p, v_p4.xy, v_p5.xy); if (d < self) discard; nearest = min(nearest, d); }
|
|
400
|
+
cov = across(nearest);
|
|
401
|
+
// Past an end of the line: its cap, square-ended (butt or square) or round.
|
|
402
|
+
float before = startEnd ? -along : -1e9;
|
|
403
|
+
float after = finalEnd ? along - len : -1e9;
|
|
404
|
+
if (u_cap != 1 && (before > -0.5 || after > -0.5)) {
|
|
405
|
+
float reach = u_cap == 2 ? u_hw : 0.0;
|
|
406
|
+
float lo = startEnd ? -reach : -1e9;
|
|
407
|
+
float hi = finalEnd ? len + reach : 1e9;
|
|
408
|
+
cov = across(perp) * span(along, lo, hi);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (cov <= 0.0) discard;
|
|
412
|
+
outColor = u_color * (cov * clipCov);
|
|
413
|
+
}
|
|
414
|
+
`, ie = `${S}${C}
|
|
415
|
+
in vec2 a_x;
|
|
416
|
+
in vec4 a_ab;
|
|
417
|
+
in vec2 a_ends;
|
|
418
|
+
flat out vec2 v_x;
|
|
419
|
+
flat out vec4 v_ab;
|
|
420
|
+
flat out vec2 v_ends;
|
|
421
|
+
|
|
422
|
+
void main() {
|
|
423
|
+
v_x = a_x;
|
|
424
|
+
v_ab = a_ab;
|
|
425
|
+
v_ends = a_ends;
|
|
426
|
+
float lo = min(min(a_ab.x, a_ab.y), min(a_ab.z, a_ab.w));
|
|
427
|
+
float hi = max(max(a_ab.x, a_ab.y), max(a_ab.z, a_ab.w));
|
|
428
|
+
vec2 cr = corner(gl_VertexID % 6);
|
|
429
|
+
gl_Position = toClip(mix(vec2(floor(a_x.x), floor(lo) - 1.0), vec2(ceil(a_x.y), ceil(hi) + 1.0), cr));
|
|
430
|
+
}
|
|
431
|
+
`, ae = `${S}${w}
|
|
432
|
+
uniform int u_kind;
|
|
433
|
+
uniform vec4 u_color;
|
|
434
|
+
uniform vec4 u_line;
|
|
435
|
+
uniform vec4 u_offsets;
|
|
436
|
+
uniform int u_stops;
|
|
437
|
+
uniform vec4 u_stop0;
|
|
438
|
+
uniform vec4 u_stop1;
|
|
439
|
+
uniform vec4 u_stop2;
|
|
440
|
+
uniform vec4 u_stop3;
|
|
441
|
+
flat in vec2 v_x;
|
|
442
|
+
flat in vec4 v_ab;
|
|
443
|
+
flat in vec2 v_ends;
|
|
444
|
+
out vec4 outColor;
|
|
445
|
+
|
|
446
|
+
vec4 stopColor(int i) {
|
|
447
|
+
if (i == 0) return u_stop0;
|
|
448
|
+
if (i == 1) return u_stop1;
|
|
449
|
+
if (i == 2) return u_stop2;
|
|
450
|
+
return u_stop3;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
vec4 gradient(vec2 p) {
|
|
454
|
+
vec2 g = u_line.zw - u_line.xy;
|
|
455
|
+
float l2 = dot(g, g);
|
|
456
|
+
// A gradient of no length paints nothing.
|
|
457
|
+
if (l2 <= 0.0) return vec4(0.0);
|
|
458
|
+
float t = dot(p - u_line.xy, g) / l2;
|
|
459
|
+
vec4 c = stopColor(0);
|
|
460
|
+
for (int i = 1; i < 4; i++) {
|
|
461
|
+
if (i >= u_stops) break;
|
|
462
|
+
float o0 = u_offsets[i - 1];
|
|
463
|
+
float o1 = u_offsets[i];
|
|
464
|
+
if (t >= o1) c = stopColor(i);
|
|
465
|
+
else if (t > o0) { c = mix(stopColor(i - 1), stopColor(i), (t - o0) / max(o1 - o0, 1e-6)); break; }
|
|
466
|
+
else break;
|
|
467
|
+
}
|
|
468
|
+
return vec4(c.rgb * c.a, c.a);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
void main() {
|
|
472
|
+
vec2 p = pixelCentre();
|
|
473
|
+
float x0 = v_x.x;
|
|
474
|
+
float x1 = v_x.y;
|
|
475
|
+
float left = v_ends.x > 0.5 ? clamp(p.x + 0.5 - x0, 0.0, 1.0) : (p.x >= x0 ? 1.0 : 0.0);
|
|
476
|
+
float right = v_ends.y > 0.5 ? clamp(x1 - (p.x - 0.5), 0.0, 1.0) : (p.x < x1 ? 1.0 : 0.0);
|
|
477
|
+
float along = v_ends.x > 0.5 && v_ends.y > 0.5
|
|
478
|
+
? clamp(min(p.x + 0.5, x1) - max(p.x - 0.5, x0), 0.0, 1.0)
|
|
479
|
+
: min(left, right);
|
|
480
|
+
float t = clamp((clamp(p.x, x0, x1) - x0) / max(x1 - x0, 1e-6), 0.0, 1.0);
|
|
481
|
+
float ya = mix(v_ab.x, v_ab.y, t);
|
|
482
|
+
float yb = mix(v_ab.z, v_ab.w, t);
|
|
483
|
+
float across = clamp(min(p.y + 0.5, max(ya, yb)) - max(p.y - 0.5, min(ya, yb)), 0.0, 1.0);
|
|
484
|
+
float cov = along * across * clipCoverage(p);
|
|
485
|
+
if (cov <= 0.0) discard;
|
|
486
|
+
vec4 color = u_kind == 1 ? gradient(p) : u_color;
|
|
487
|
+
outColor = color * cov;
|
|
488
|
+
}
|
|
489
|
+
`, oe = `${S}${C}
|
|
490
|
+
in vec3 a_disc;
|
|
491
|
+
in vec4 a_color;
|
|
492
|
+
flat out vec3 v_disc;
|
|
493
|
+
flat out vec4 v_color;
|
|
494
|
+
void main() {
|
|
495
|
+
v_disc = a_disc;
|
|
496
|
+
v_color = a_color;
|
|
497
|
+
float m = a_disc.z + 1.0;
|
|
498
|
+
gl_Position = toClip(mix(a_disc.xy - m, a_disc.xy + m, corner(gl_VertexID % 6)));
|
|
499
|
+
}
|
|
500
|
+
`, se = `${S}${w}
|
|
501
|
+
flat in vec3 v_disc;
|
|
502
|
+
flat in vec4 v_color;
|
|
503
|
+
out vec4 outColor;
|
|
504
|
+
void main() {
|
|
505
|
+
vec2 p = pixelCentre();
|
|
506
|
+
float cov = clamp(v_disc.z + 0.5 - length(p - v_disc.xy), 0.0, 1.0) * clipCoverage(p);
|
|
507
|
+
if (cov <= 0.0) discard;
|
|
508
|
+
outColor = v_color * cov;
|
|
509
|
+
}
|
|
510
|
+
`, T = 4, E = T * 4, D = 32, O = 7, k = O * 4, A = class {
|
|
511
|
+
stroke;
|
|
512
|
+
span;
|
|
513
|
+
disc;
|
|
514
|
+
buffer;
|
|
515
|
+
constructor(e) {
|
|
516
|
+
this.kit = e, this.stroke = e.program(ne, re, [
|
|
517
|
+
"a_p0",
|
|
518
|
+
"a_p1",
|
|
519
|
+
"a_p2",
|
|
520
|
+
"a_p3",
|
|
521
|
+
"a_p4",
|
|
522
|
+
"a_p5"
|
|
523
|
+
]), this.span = e.program(ie, ae, [
|
|
524
|
+
"a_x",
|
|
525
|
+
"a_ab",
|
|
526
|
+
"a_ends"
|
|
527
|
+
]), this.disc = e.program(oe, se, ["a_disc", "a_color"]), this.buffer = e.buffer();
|
|
528
|
+
}
|
|
529
|
+
draw(e, t, n, r) {
|
|
530
|
+
let i = this.kit.gl;
|
|
531
|
+
i.enable(i.BLEND);
|
|
532
|
+
for (let a of e) i.blendFunc(i.ONE, i.ONE_MINUS_SRC_ALPHA), i.disable(i.SCISSOR_TEST), a.type === "rects" ? this.drawRects(a.values, r) : a.type === "stroke" ? this.drawStroke(a, t, n) : a.type === "fill" ? this.drawFill(a, t, n) : this.drawDiscs(a.values, a.clip, t, n);
|
|
533
|
+
i.disable(i.SCISSOR_TEST);
|
|
534
|
+
}
|
|
535
|
+
destroy() {
|
|
536
|
+
for (let e of [
|
|
537
|
+
this.stroke,
|
|
538
|
+
this.span,
|
|
539
|
+
this.disc
|
|
540
|
+
]) this.kit.deleteProgram(e);
|
|
541
|
+
this.kit.gl.deleteBuffer(this.buffer);
|
|
542
|
+
}
|
|
543
|
+
upload(e) {
|
|
544
|
+
let t = this.kit.gl;
|
|
545
|
+
t.bindBuffer(t.ARRAY_BUFFER, this.buffer), t.bufferData(t.ARRAY_BUFFER, e, t.STREAM_DRAW);
|
|
546
|
+
}
|
|
547
|
+
common(e, t, n, r) {
|
|
548
|
+
let i = this.kit;
|
|
549
|
+
return i.scissor(t.x0, t.y0, t.x1, t.y1, n, r) ? (i.use(e), i.vec2(e, "u_canvas", n, r), i.vec4(e, "u_clip", [
|
|
550
|
+
t.x0,
|
|
551
|
+
t.y0,
|
|
552
|
+
Math.min(t.x1, n),
|
|
553
|
+
Math.min(t.y1, r)
|
|
554
|
+
]), !0) : !1;
|
|
555
|
+
}
|
|
556
|
+
drawRects(e, t) {
|
|
557
|
+
let n = e.length / 8, r = new Float32Array(n * 10);
|
|
558
|
+
for (let t = 0; t < n; t++) for (let n = 0; n < 8; n++) r[t * 10 + n] = e[t * 8 + n];
|
|
559
|
+
t(r, n);
|
|
560
|
+
}
|
|
561
|
+
drawStroke(e, t, n) {
|
|
562
|
+
let r = this.stroke;
|
|
563
|
+
if (!this.common(r, e.clip, t, n)) return;
|
|
564
|
+
let i = this.kit;
|
|
565
|
+
i.vec4(r, "u_color", e.color), i.float(r, "u_hw", e.width / 2), i.int(r, "u_cap", e.cap), i.vec4(r, "u_dash", e.dash ?? [
|
|
566
|
+
0,
|
|
567
|
+
0,
|
|
568
|
+
0,
|
|
569
|
+
0
|
|
570
|
+
]), this.upload(new Float32Array(e.points));
|
|
571
|
+
for (let e = 0; e < 6; e++) i.attrib(r, `a_p${e}`, 4, E, e * E);
|
|
572
|
+
let a = e.points.length / T - 5;
|
|
573
|
+
a > 0 && i.gl.drawArraysInstanced(i.gl.TRIANGLES, 0, 6, a);
|
|
574
|
+
}
|
|
575
|
+
drawFill(e, t, n) {
|
|
576
|
+
let r = this.kit, i = e.bounds;
|
|
577
|
+
if (!r.scissor(i.x0, i.y0, i.x1, i.y1, t, n)) return;
|
|
578
|
+
let a = r.use(this.span);
|
|
579
|
+
r.vec2(a, "u_canvas", t, n), r.vec4(a, "u_clip", [
|
|
580
|
+
e.clip.x0,
|
|
581
|
+
e.clip.y0,
|
|
582
|
+
Math.min(e.clip.x1, t),
|
|
583
|
+
Math.min(e.clip.y1, n)
|
|
584
|
+
]), this.upload(new Float32Array(e.spans)), r.attrib(a, "a_x", 2, D, 0), r.attrib(a, "a_ab", 4, D, 8), r.attrib(a, "a_ends", 2, D, 24), this.paint(a, e.paint), r.gl.drawArraysInstanced(r.gl.TRIANGLES, 0, 6, e.spans.length / 8);
|
|
585
|
+
}
|
|
586
|
+
paint(e, t) {
|
|
587
|
+
let n = this.kit;
|
|
588
|
+
if (t.kind === "solid") {
|
|
589
|
+
n.int(e, "u_kind", 0), n.vec4(e, "u_color", t.color);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
n.int(e, "u_kind", 1), n.vec4(e, "u_line", [
|
|
593
|
+
t.x0,
|
|
594
|
+
t.y0,
|
|
595
|
+
t.x1,
|
|
596
|
+
t.y1
|
|
597
|
+
]);
|
|
598
|
+
let r = [
|
|
599
|
+
0,
|
|
600
|
+
0,
|
|
601
|
+
0,
|
|
602
|
+
0
|
|
603
|
+
];
|
|
604
|
+
t.stops.forEach((e, t) => {
|
|
605
|
+
r[t] = e.offset;
|
|
606
|
+
}), n.vec4(e, "u_offsets", r), n.int(e, "u_stops", t.stops.length);
|
|
607
|
+
for (let r = 0; r < 4; r++) n.vec4(e, `u_stop${r}`, (t.stops[r] ?? t.stops[t.stops.length - 1]).color);
|
|
608
|
+
}
|
|
609
|
+
drawDiscs(e, t, n, r) {
|
|
610
|
+
let i = this.disc;
|
|
611
|
+
this.common(i, t, n, r) && (this.upload(new Float32Array(e)), this.kit.attrib(i, "a_disc", 3, k, 0), this.kit.attrib(i, "a_color", 4, k, 12), this.kit.gl.drawArraysInstanced(this.kit.gl.TRIANGLES, 0, 6, e.length / O));
|
|
612
|
+
}
|
|
613
|
+
}, j = (e, t) => ({
|
|
614
|
+
x0: Math.max(e.x0, t.x0),
|
|
615
|
+
y0: Math.max(e.y0, t.y0),
|
|
616
|
+
x1: Math.min(e.x1, t.x1),
|
|
617
|
+
y1: Math.min(e.y1, t.y1)
|
|
618
|
+
}), M = (e) => !(e.x1 > e.x0 && e.y1 > e.y0);
|
|
619
|
+
function N(e, t = 0) {
|
|
620
|
+
let n = Infinity, r = Infinity, i = -Infinity, a = -Infinity;
|
|
621
|
+
for (let t = 0; t < e.length; t += 2) {
|
|
622
|
+
let o = e[t], s = e[t + 1];
|
|
623
|
+
o < n && (n = o), o > i && (i = o), s < r && (r = s), s > a && (a = s);
|
|
624
|
+
}
|
|
625
|
+
return {
|
|
626
|
+
x0: n - t,
|
|
627
|
+
y0: r - t,
|
|
628
|
+
x1: i + t,
|
|
629
|
+
y1: a + t
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function P(e) {
|
|
633
|
+
let t = [...e].sort((e, t) => e.x0 - t.x0), n = [];
|
|
634
|
+
for (let e of t) {
|
|
635
|
+
for (let t = n.length - 1; t >= 0; t--) n[t].x1 <= e.x0 && n.splice(t, 1);
|
|
636
|
+
for (let t of n) if (t.y0 < e.y1 && e.y0 < t.y1) return !0;
|
|
637
|
+
n.push(e);
|
|
638
|
+
}
|
|
639
|
+
return !1;
|
|
640
|
+
}
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region src/webgl/recordedPath.ts
|
|
643
|
+
var F = class {
|
|
644
|
+
stops = [];
|
|
645
|
+
constructor(e, t, n, r) {
|
|
646
|
+
this.x0 = e, this.y0 = t, this.x1 = n, this.y1 = r;
|
|
647
|
+
}
|
|
648
|
+
addColorStop(e, t) {
|
|
649
|
+
if (!(e >= 0 && e <= 1)) throw RangeError("offset out of range");
|
|
650
|
+
this.stops.push({
|
|
651
|
+
offset: e,
|
|
652
|
+
color: t
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
}, I = typeof Path2D == "function" ? Path2D : class {}, L = class e extends I {
|
|
656
|
+
calls = [];
|
|
657
|
+
unsupported = !1;
|
|
658
|
+
constructor(t) {
|
|
659
|
+
super(t), t instanceof e ? (this.calls.push(...t.calls), this.unsupported = t.unsupported) : t !== void 0 && (this.unsupported = !0);
|
|
660
|
+
}
|
|
661
|
+
note(e, t, n = t) {
|
|
662
|
+
this.calls.push([e, t]), I.prototype[e]?.apply(this, n);
|
|
663
|
+
}
|
|
664
|
+
unfollowed(e, t) {
|
|
665
|
+
this.unsupported = !0, this.note(e, [], t);
|
|
666
|
+
}
|
|
667
|
+
moveTo(e, t) {
|
|
668
|
+
this.note("moveTo", [e, t]);
|
|
669
|
+
}
|
|
670
|
+
lineTo(e, t) {
|
|
671
|
+
this.note("lineTo", [e, t]);
|
|
672
|
+
}
|
|
673
|
+
closePath() {
|
|
674
|
+
this.note("closePath", []);
|
|
675
|
+
}
|
|
676
|
+
rect(e, t, n, r) {
|
|
677
|
+
this.note("rect", [
|
|
678
|
+
e,
|
|
679
|
+
t,
|
|
680
|
+
n,
|
|
681
|
+
r
|
|
682
|
+
]);
|
|
683
|
+
}
|
|
684
|
+
arc(e, t, n, r, i, a) {
|
|
685
|
+
this.note("arc", [
|
|
686
|
+
e,
|
|
687
|
+
t,
|
|
688
|
+
n,
|
|
689
|
+
r,
|
|
690
|
+
i,
|
|
691
|
+
+!!a
|
|
692
|
+
]);
|
|
693
|
+
}
|
|
694
|
+
quadraticCurveTo(e, t, n, r) {
|
|
695
|
+
this.note("quadraticCurveTo", [
|
|
696
|
+
e,
|
|
697
|
+
t,
|
|
698
|
+
n,
|
|
699
|
+
r
|
|
700
|
+
]);
|
|
701
|
+
}
|
|
702
|
+
bezierCurveTo(e, t, n, r, i, a) {
|
|
703
|
+
this.note("bezierCurveTo", [
|
|
704
|
+
e,
|
|
705
|
+
t,
|
|
706
|
+
n,
|
|
707
|
+
r,
|
|
708
|
+
i,
|
|
709
|
+
a
|
|
710
|
+
]);
|
|
711
|
+
}
|
|
712
|
+
arcTo(...e) {
|
|
713
|
+
this.unfollowed("arcTo", e);
|
|
714
|
+
}
|
|
715
|
+
ellipse(...e) {
|
|
716
|
+
this.unfollowed("ellipse", e);
|
|
717
|
+
}
|
|
718
|
+
roundRect(...e) {
|
|
719
|
+
this.unfollowed("roundRect", e);
|
|
720
|
+
}
|
|
721
|
+
addPath(t, n) {
|
|
722
|
+
!(t instanceof e) || n !== void 0 ? this.unsupported = !0 : (this.calls.push(...t.calls), this.unsupported ||= t.unsupported), I.prototype.addPath?.call(this, t, n);
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
function ce(e) {
|
|
726
|
+
let t = globalThis, n = Object.prototype.hasOwnProperty.call(t, "Path2D"), r = t.Path2D;
|
|
727
|
+
t.Path2D = L;
|
|
728
|
+
try {
|
|
729
|
+
e();
|
|
730
|
+
} finally {
|
|
731
|
+
n ? t.Path2D = r : delete t.Path2D;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/webgl/strokeGeometry.ts
|
|
736
|
+
var le = .25;
|
|
737
|
+
function ue(e, t, n, r) {
|
|
738
|
+
if (n === "round") return !1;
|
|
739
|
+
let i = e.points, a = i.length / 2, o = +!e.closed, s = e.closed ? a : a - 1;
|
|
740
|
+
for (let e = o; e < s; e++) {
|
|
741
|
+
let o = (e - 1 + a) % a, s = (e + 1) % a, c = i[2 * e] - i[2 * o], l = i[2 * e + 1] - i[2 * o + 1], u = i[2 * s] - i[2 * e], d = i[2 * s + 1] - i[2 * e + 1], f = Math.hypot(c, l), p = Math.hypot(u, d);
|
|
742
|
+
if (f === 0 || p === 0) continue;
|
|
743
|
+
let m = Math.max(-1, Math.min(1, (c * u + l * d) / (f * p))), h = Math.sqrt((1 + m) / 2);
|
|
744
|
+
if ((n === "miter" && h > 0 && 1 / h <= r ? t * (1 / h - 1) : t * (1 - h)) > le) return !0;
|
|
745
|
+
}
|
|
746
|
+
return !1;
|
|
747
|
+
}
|
|
748
|
+
function de(e, t) {
|
|
749
|
+
let n = e.points;
|
|
750
|
+
for (let e = 2; e < n.length; e += 2) if (Math.hypot(n[e] - n[e - 2], n[e + 1] - n[e - 1]) < t) return !0;
|
|
751
|
+
return !1;
|
|
752
|
+
}
|
|
753
|
+
function fe(e) {
|
|
754
|
+
let t = [], n = () => t.push(0, 0, -1, 0);
|
|
755
|
+
n(), n();
|
|
756
|
+
for (let { points: r, closed: i } of e) {
|
|
757
|
+
let e = r.length / 2, a = i && e >= 3;
|
|
758
|
+
a && t.push(r[2 * (e - 2)], r[2 * (e - 2) + 1], 0, 0, r[2 * (e - 1)], r[2 * (e - 1) + 1], 0, 0);
|
|
759
|
+
let o = 0;
|
|
760
|
+
for (let n = 0; n < e; n++) n > 0 && (o += Math.hypot(r[2 * n] - r[2 * n - 2], r[2 * n + 1] - r[2 * n - 1])), t.push(r[2 * n], r[2 * n + 1], 1, o);
|
|
761
|
+
a && (o += Math.hypot(r[0] - r[2 * (e - 1)], r[1] - r[2 * (e - 1) + 1]), t.push(r[0], r[1], 1, o), t.push(r[2], r[3], 0, 0, r[4], r[5], 0, 0)), n();
|
|
762
|
+
}
|
|
763
|
+
return n(), t;
|
|
764
|
+
}
|
|
765
|
+
//#endregion
|
|
766
|
+
//#region src/webgl/recorder.ts
|
|
767
|
+
var R = Math.PI * 2;
|
|
768
|
+
function pe(e, t) {
|
|
769
|
+
let n = 2 * Math.sqrt(Math.max(.2 / Math.max(e, .1), 1e-6));
|
|
770
|
+
return Math.min(512, Math.max(4, Math.ceil(Math.abs(t) / Math.min(n, Math.PI / 4))));
|
|
771
|
+
}
|
|
772
|
+
var z = new Set([
|
|
773
|
+
"fillStyle",
|
|
774
|
+
"strokeStyle",
|
|
775
|
+
"lineWidth",
|
|
776
|
+
"lineCap",
|
|
777
|
+
"lineJoin",
|
|
778
|
+
"miterLimit",
|
|
779
|
+
"globalAlpha",
|
|
780
|
+
"globalCompositeOperation",
|
|
781
|
+
"lineDashOffset",
|
|
782
|
+
"font",
|
|
783
|
+
"textAlign",
|
|
784
|
+
"textBaseline",
|
|
785
|
+
"direction",
|
|
786
|
+
"shadowBlur",
|
|
787
|
+
"shadowColor",
|
|
788
|
+
"shadowOffsetX",
|
|
789
|
+
"shadowOffsetY",
|
|
790
|
+
"filter"
|
|
791
|
+
]), B = new Set([
|
|
792
|
+
"fontKerning",
|
|
793
|
+
"fontStretch",
|
|
794
|
+
"fontVariantCaps",
|
|
795
|
+
"letterSpacing",
|
|
796
|
+
"wordSpacing",
|
|
797
|
+
"textRendering"
|
|
798
|
+
]), V = new Set(["imageSmoothingEnabled", "imageSmoothingQuality"]), H = (e) => !!(e.rect || e.circle) || e.points.length >= 6, U = class {
|
|
799
|
+
commands = [];
|
|
800
|
+
ctx;
|
|
801
|
+
texts = [];
|
|
802
|
+
state;
|
|
803
|
+
stack = [];
|
|
804
|
+
path = [];
|
|
805
|
+
ok = !0;
|
|
806
|
+
constructor(e, t) {
|
|
807
|
+
this.dpr = e, this.measure = t, this.reset({
|
|
808
|
+
x0: 0,
|
|
809
|
+
y0: 0,
|
|
810
|
+
x1: Infinity,
|
|
811
|
+
y1: Infinity
|
|
812
|
+
}), this.ctx = this.proxy();
|
|
813
|
+
}
|
|
814
|
+
region(e) {
|
|
815
|
+
let t = this.dpr, n = {
|
|
816
|
+
x0: e.x * t,
|
|
817
|
+
y0: e.y * t,
|
|
818
|
+
x1: (e.x + e.width) * t,
|
|
819
|
+
y1: (e.y + e.height) * t
|
|
820
|
+
}, r = [];
|
|
821
|
+
return {
|
|
822
|
+
step: (e) => {
|
|
823
|
+
this.reset(n), this.texts = r;
|
|
824
|
+
let t = {
|
|
825
|
+
commands: this.commands.length,
|
|
826
|
+
texts: r.length
|
|
827
|
+
};
|
|
828
|
+
this.ok = !0;
|
|
829
|
+
try {
|
|
830
|
+
ce(() => e(this.ctx));
|
|
831
|
+
} catch {
|
|
832
|
+
this.ok = !1;
|
|
833
|
+
}
|
|
834
|
+
return this.ok ? !0 : (this.commands.length = t.commands, r.length = t.texts, !1);
|
|
835
|
+
},
|
|
836
|
+
drawText: (e) => me(e, r)
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
reset(e) {
|
|
840
|
+
this.state = {
|
|
841
|
+
fillStyle: "#000000",
|
|
842
|
+
strokeStyle: "#000000",
|
|
843
|
+
lineWidth: 1,
|
|
844
|
+
lineCap: "butt",
|
|
845
|
+
lineJoin: "miter",
|
|
846
|
+
miterLimit: 10,
|
|
847
|
+
globalAlpha: 1,
|
|
848
|
+
globalCompositeOperation: "source-over",
|
|
849
|
+
lineDash: [],
|
|
850
|
+
lineDashOffset: 0,
|
|
851
|
+
font: "10px sans-serif",
|
|
852
|
+
textAlign: "start",
|
|
853
|
+
textBaseline: "alphabetic",
|
|
854
|
+
direction: "inherit",
|
|
855
|
+
shadowBlur: 0,
|
|
856
|
+
shadowColor: "rgba(0, 0, 0, 0)",
|
|
857
|
+
shadowOffsetX: 0,
|
|
858
|
+
shadowOffsetY: 0,
|
|
859
|
+
filter: "none",
|
|
860
|
+
textExtras: {},
|
|
861
|
+
transform: [
|
|
862
|
+
this.dpr,
|
|
863
|
+
0,
|
|
864
|
+
0,
|
|
865
|
+
this.dpr,
|
|
866
|
+
0,
|
|
867
|
+
0
|
|
868
|
+
],
|
|
869
|
+
clip: e
|
|
870
|
+
}, this.stack = [], this.path = [];
|
|
871
|
+
}
|
|
872
|
+
unsupported() {
|
|
873
|
+
this.ok = !1;
|
|
874
|
+
}
|
|
875
|
+
copyState() {
|
|
876
|
+
let e = this.state;
|
|
877
|
+
return {
|
|
878
|
+
...e,
|
|
879
|
+
lineDash: [...e.lineDash],
|
|
880
|
+
textExtras: { ...e.textExtras }
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
axisAligned() {
|
|
884
|
+
let e = this.state.transform;
|
|
885
|
+
return e[1] === 0 && e[2] === 0;
|
|
886
|
+
}
|
|
887
|
+
uniform() {
|
|
888
|
+
let e = this.state.transform;
|
|
889
|
+
return this.axisAligned() && Math.abs(e[0]) === Math.abs(e[3]);
|
|
890
|
+
}
|
|
891
|
+
setMatrix(e) {
|
|
892
|
+
e.every(Number.isFinite) && (this.state.transform = e);
|
|
893
|
+
}
|
|
894
|
+
multiply(e, t, n, r, i, a) {
|
|
895
|
+
let [o, s, c, l, u, d] = this.state.transform;
|
|
896
|
+
this.setMatrix([
|
|
897
|
+
o * e + c * t,
|
|
898
|
+
s * e + l * t,
|
|
899
|
+
o * n + c * r,
|
|
900
|
+
s * n + l * r,
|
|
901
|
+
o * i + c * a + u,
|
|
902
|
+
s * i + l * a + d
|
|
903
|
+
]);
|
|
904
|
+
}
|
|
905
|
+
current() {
|
|
906
|
+
return this.path[this.path.length - 1];
|
|
907
|
+
}
|
|
908
|
+
moveTo(e, t) {
|
|
909
|
+
if (!Number.isFinite(e) || !Number.isFinite(t)) return;
|
|
910
|
+
let n = this.state.transform;
|
|
911
|
+
this.path.push({
|
|
912
|
+
points: [n[0] * e + n[2] * t + n[4], n[1] * e + n[3] * t + n[5]],
|
|
913
|
+
closed: !1
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
lineTo(e, t) {
|
|
917
|
+
if (!Number.isFinite(e) || !Number.isFinite(t)) return;
|
|
918
|
+
let n = this.current();
|
|
919
|
+
if (!n || n.closed) return this.moveTo(e, t);
|
|
920
|
+
let r = this.state.transform;
|
|
921
|
+
n.points.push(r[0] * e + r[2] * t + r[4], r[1] * e + r[3] * t + r[5]), n.rect = void 0, n.circle = void 0;
|
|
922
|
+
}
|
|
923
|
+
closePath() {
|
|
924
|
+
let e = this.current();
|
|
925
|
+
!e || e.closed || (e.closed = !0, this.path.push({
|
|
926
|
+
points: [e.points[0], e.points[1]],
|
|
927
|
+
closed: !1
|
|
928
|
+
}));
|
|
929
|
+
}
|
|
930
|
+
rect(e, t, n, r) {
|
|
931
|
+
if (![
|
|
932
|
+
e,
|
|
933
|
+
t,
|
|
934
|
+
n,
|
|
935
|
+
r
|
|
936
|
+
].every(Number.isFinite)) return;
|
|
937
|
+
let i = this.state.transform, a = i[0] * e + i[2] * t + i[4], o = i[1] * e + i[3] * t + i[5], s = i[0] * (e + n) + i[2] * t + i[4], c = i[1] * (e + n) + i[3] * t + i[5], l = i[0] * (e + n) + i[2] * (t + r) + i[4], u = i[1] * (e + n) + i[3] * (t + r) + i[5], d = {
|
|
938
|
+
points: [
|
|
939
|
+
a,
|
|
940
|
+
o,
|
|
941
|
+
s,
|
|
942
|
+
c,
|
|
943
|
+
l,
|
|
944
|
+
u,
|
|
945
|
+
i[0] * e + i[2] * (t + r) + i[4],
|
|
946
|
+
i[1] * e + i[3] * (t + r) + i[5]
|
|
947
|
+
],
|
|
948
|
+
closed: !0
|
|
949
|
+
};
|
|
950
|
+
this.axisAligned() && (d.rect = {
|
|
951
|
+
x0: Math.min(a, l),
|
|
952
|
+
y0: Math.min(o, u),
|
|
953
|
+
x1: Math.max(a, l),
|
|
954
|
+
y1: Math.max(o, u)
|
|
955
|
+
}), this.path.push(d), this.path.push({
|
|
956
|
+
points: [a, o],
|
|
957
|
+
closed: !1
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
arc(e, t, n, r, i, a = !1) {
|
|
961
|
+
if (![
|
|
962
|
+
e,
|
|
963
|
+
t,
|
|
964
|
+
n,
|
|
965
|
+
r,
|
|
966
|
+
i
|
|
967
|
+
].every(Number.isFinite)) return;
|
|
968
|
+
if (n < 0) throw new DOMException("negative radius", "IndexSizeError");
|
|
969
|
+
let o = i - r;
|
|
970
|
+
o = !a && o >= R ? R : a && -o >= R ? -R : a ? -(((r - i) % R + R) % R) : (o % R + R) % R;
|
|
971
|
+
let s = this.current(), c = this.state.transform, l = e + n * Math.cos(r), u = t + n * Math.sin(r), d = !s || s.closed || s.points.length === 2 && Math.abs(s.points[0] - (c[0] * l + c[2] * u + c[4])) < 1e-6 && Math.abs(s.points[1] - (c[1] * l + c[3] * u + c[5])) < 1e-6, f = pe(n * Math.abs(c[0]), o);
|
|
972
|
+
for (let i = 0; i <= f; i++) {
|
|
973
|
+
let a = r + o * i / f;
|
|
974
|
+
this.lineTo(e + n * Math.cos(a), t + n * Math.sin(a));
|
|
975
|
+
}
|
|
976
|
+
let p = this.current();
|
|
977
|
+
Math.abs(o) >= R - 1e-9 && d && this.uniform() && p && (p.circle = {
|
|
978
|
+
x: c[0] * e + c[4],
|
|
979
|
+
y: c[3] * t + c[5],
|
|
980
|
+
r: n * Math.abs(c[0])
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
curve(e, t) {
|
|
984
|
+
(!this.current() || this.current().closed) && this.moveTo(e[0], e[1]);
|
|
985
|
+
let n = this.current(), r = this.state.transform;
|
|
986
|
+
if (!n || !this.axisAligned() || r[0] === 0 || r[3] === 0) return this.unsupported();
|
|
987
|
+
let i = [
|
|
988
|
+
(n.points[n.points.length - 2] - r[4]) / r[0],
|
|
989
|
+
(n.points[n.points.length - 1] - r[5]) / r[3],
|
|
990
|
+
...e,
|
|
991
|
+
...t
|
|
992
|
+
], a = 0;
|
|
993
|
+
for (let e = 2; e < i.length; e += 2) a += Math.hypot((i[e] - i[e - 2]) * r[0], (i[e + 1] - i[e - 1]) * r[3]);
|
|
994
|
+
let o = Math.max(4, Math.min(64, Math.ceil(a / 3)));
|
|
995
|
+
for (let e = 1; e <= o; e++) {
|
|
996
|
+
let t = e / o, n = i.length === 6 ? [
|
|
997
|
+
(1 - t) ** 2,
|
|
998
|
+
2 * t * (1 - t),
|
|
999
|
+
t * t
|
|
1000
|
+
] : [
|
|
1001
|
+
(1 - t) ** 3,
|
|
1002
|
+
3 * t * (1 - t) ** 2,
|
|
1003
|
+
3 * t * t * (1 - t),
|
|
1004
|
+
t ** 3
|
|
1005
|
+
], r = 0, a = 0;
|
|
1006
|
+
n.forEach((e, t) => {
|
|
1007
|
+
r += e * i[2 * t], a += e * i[2 * t + 1];
|
|
1008
|
+
}), this.lineTo(r, a);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
withPath(e, t) {
|
|
1012
|
+
let n = this.path;
|
|
1013
|
+
this.path = [], e(), t(), this.path = n;
|
|
1014
|
+
}
|
|
1015
|
+
onPath(e, t) {
|
|
1016
|
+
if (!(e instanceof L) || e.unsupported) return this.unsupported();
|
|
1017
|
+
this.withPath(() => {
|
|
1018
|
+
for (let [t, n] of e.calls) t === "moveTo" ? this.moveTo(n[0], n[1]) : t === "lineTo" ? this.lineTo(n[0], n[1]) : t === "closePath" ? this.closePath() : t === "rect" ? this.rect(n[0], n[1], n[2], n[3]) : t === "arc" ? this.arc(n[0], n[1], n[2], n[3], n[4], !!n[5]) : t === "quadraticCurveTo" ? this.curve([n[0], n[1]], [n[2], n[3]]) : t === "bezierCurveTo" && this.curve([
|
|
1019
|
+
n[0],
|
|
1020
|
+
n[1],
|
|
1021
|
+
n[2],
|
|
1022
|
+
n[3]
|
|
1023
|
+
], [n[4], n[5]]);
|
|
1024
|
+
}, t);
|
|
1025
|
+
}
|
|
1026
|
+
paint(e) {
|
|
1027
|
+
let t = Math.max(0, Math.min(1, this.state.globalAlpha));
|
|
1028
|
+
if (typeof e == "string") {
|
|
1029
|
+
let n = g(h(e));
|
|
1030
|
+
return {
|
|
1031
|
+
kind: "solid",
|
|
1032
|
+
color: [
|
|
1033
|
+
n[0] * t,
|
|
1034
|
+
n[1] * t,
|
|
1035
|
+
n[2] * t,
|
|
1036
|
+
n[3] * t
|
|
1037
|
+
]
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
if (!(e instanceof F)) return null;
|
|
1041
|
+
if (e.stops.length === 0) return {
|
|
1042
|
+
kind: "solid",
|
|
1043
|
+
color: [
|
|
1044
|
+
0,
|
|
1045
|
+
0,
|
|
1046
|
+
0,
|
|
1047
|
+
0
|
|
1048
|
+
]
|
|
1049
|
+
};
|
|
1050
|
+
if (e.stops.length > 4) return null;
|
|
1051
|
+
let n = this.state.transform, r = e.x0 === e.x1 || e.y0 === e.y1;
|
|
1052
|
+
if (!this.axisAligned() || !this.uniform() && !r) return null;
|
|
1053
|
+
let i = [...e.stops].sort((e, t) => e.offset - t.offset).map((e) => {
|
|
1054
|
+
let n = h(e.color);
|
|
1055
|
+
return {
|
|
1056
|
+
offset: e.offset,
|
|
1057
|
+
color: [
|
|
1058
|
+
n[0],
|
|
1059
|
+
n[1],
|
|
1060
|
+
n[2],
|
|
1061
|
+
n[3] * t
|
|
1062
|
+
]
|
|
1063
|
+
};
|
|
1064
|
+
});
|
|
1065
|
+
return {
|
|
1066
|
+
kind: "linear",
|
|
1067
|
+
x0: n[0] * e.x0 + n[4],
|
|
1068
|
+
y0: n[3] * e.y0 + n[5],
|
|
1069
|
+
x1: n[0] * e.x1 + n[4],
|
|
1070
|
+
y1: n[3] * e.y1 + n[5],
|
|
1071
|
+
stops: i
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
plain() {
|
|
1075
|
+
let e = this.state;
|
|
1076
|
+
return e.globalCompositeOperation !== "source-over" || e.filter !== "none" ? !1 : !(h(e.shadowColor)[3] > 0 && (e.shadowBlur > 0 || e.shadowOffsetX !== 0 || e.shadowOffsetY !== 0));
|
|
1077
|
+
}
|
|
1078
|
+
fill(e = "nonzero") {
|
|
1079
|
+
if (!this.plain()) return this.unsupported();
|
|
1080
|
+
let t = this.paint(this.state.fillStyle);
|
|
1081
|
+
if (!t) return this.unsupported();
|
|
1082
|
+
let n = this.path.filter(H);
|
|
1083
|
+
if (n.length === 0 || t.kind === "solid" && t.color[3] === 0) return;
|
|
1084
|
+
if (n.length > 1 && P(n.map((e) => N(e.points)))) {
|
|
1085
|
+
let r = t.kind === "solid" && t.color[3] >= 1, i = Math.sign(y(n[0].points));
|
|
1086
|
+
if (!r || e !== "nonzero" || n.some((e) => Math.sign(y(e.points)) !== i)) return this.unsupported();
|
|
1087
|
+
}
|
|
1088
|
+
if (t.kind === "solid" && n.every((e) => e.rect)) return this.fillRects(n, t.color);
|
|
1089
|
+
if (t.kind === "solid" && n.every((e) => e.circle)) {
|
|
1090
|
+
let e = [];
|
|
1091
|
+
for (let r of n) e.push(r.circle.x, r.circle.y, r.circle.r, ...t.color);
|
|
1092
|
+
this.commands.push({
|
|
1093
|
+
type: "circles",
|
|
1094
|
+
values: e,
|
|
1095
|
+
clip: this.state.clip
|
|
1096
|
+
});
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
let r = [];
|
|
1100
|
+
for (let e of n) {
|
|
1101
|
+
let t = ee(e.points);
|
|
1102
|
+
if (!t) return this.unsupported();
|
|
1103
|
+
for (let e of t) r.push(e);
|
|
1104
|
+
}
|
|
1105
|
+
let i = N(n.flatMap((e) => e.points)), a = j({
|
|
1106
|
+
x0: Math.floor(i.x0),
|
|
1107
|
+
y0: Math.floor(i.y0),
|
|
1108
|
+
x1: Math.ceil(i.x1),
|
|
1109
|
+
y1: Math.ceil(i.y1)
|
|
1110
|
+
}, this.state.clip);
|
|
1111
|
+
r.length > 0 && !M(a) && this.commands.push({
|
|
1112
|
+
type: "fill",
|
|
1113
|
+
spans: r,
|
|
1114
|
+
bounds: a,
|
|
1115
|
+
paint: t,
|
|
1116
|
+
clip: this.state.clip
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
fillRects(e, t) {
|
|
1120
|
+
let n = [];
|
|
1121
|
+
for (let r of e) {
|
|
1122
|
+
let e = j(r.rect, this.state.clip);
|
|
1123
|
+
M(e) || n.push(e.x0, e.y0, e.x1, e.y1, t[0], t[1], t[2], t[3]);
|
|
1124
|
+
}
|
|
1125
|
+
n.length && this.commands.push({
|
|
1126
|
+
type: "rects",
|
|
1127
|
+
values: n
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
stroke() {
|
|
1131
|
+
if (!this.plain()) return this.unsupported();
|
|
1132
|
+
let e = this.paint(this.state.strokeStyle);
|
|
1133
|
+
if (!e || e.kind !== "solid" || !this.uniform()) return this.unsupported();
|
|
1134
|
+
if (e.color[3] === 0) return;
|
|
1135
|
+
let t = this.state, n = Math.abs(t.transform[0]), r = t.lineWidth * n, i = this.path.filter((e) => e.points.length >= 4 && (t.lineCap !== "butt" || e.points.some((t, n) => t !== e.points[n % 2])));
|
|
1136
|
+
if (i.length === 0) return;
|
|
1137
|
+
let a = this.dash(i, n);
|
|
1138
|
+
if (a === void 0 || !this.drawsAlike(i, r, e.color[3])) return this.unsupported();
|
|
1139
|
+
let o = t.lineCap === "round" ? 1 : t.lineCap === "square" ? 2 : 0;
|
|
1140
|
+
this.commands.push({
|
|
1141
|
+
type: "stroke",
|
|
1142
|
+
points: fe(i),
|
|
1143
|
+
color: e.color,
|
|
1144
|
+
width: r,
|
|
1145
|
+
cap: o,
|
|
1146
|
+
dash: a,
|
|
1147
|
+
clip: t.clip
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
dash(e, t) {
|
|
1151
|
+
let n = this.state;
|
|
1152
|
+
if (n.lineDash.length === 0) return null;
|
|
1153
|
+
if (n.lineDash.length > 4 || n.lineDashOffset !== 0 || n.lineCap !== "butt" || e.some((e) => e.closed || e.points.length !== 4)) return;
|
|
1154
|
+
let r = n.lineDash.map((e) => e * t);
|
|
1155
|
+
for (; r.length < 4;) r.push(...r.slice(0, 4 - r.length));
|
|
1156
|
+
return r;
|
|
1157
|
+
}
|
|
1158
|
+
drawsAlike(e, t, n) {
|
|
1159
|
+
let r = this.state, i = t / 2;
|
|
1160
|
+
if (t > 1 && e.some((e) => ue(e, i, r.lineJoin, r.miterLimit))) return !1;
|
|
1161
|
+
let a = i + (r.lineCap === "butt" ? 0 : i);
|
|
1162
|
+
return !(e.length > 1 && P(e.map((e) => N(e.points, a))) || n < 1 && e.some((e) => de(e, t)));
|
|
1163
|
+
}
|
|
1164
|
+
clip() {
|
|
1165
|
+
let e = this.path.filter(H);
|
|
1166
|
+
if (e.length !== 1 || !e[0].rect) return this.unsupported();
|
|
1167
|
+
this.state.clip = j(this.state.clip, e[0].rect);
|
|
1168
|
+
}
|
|
1169
|
+
text(e, t, n, r, i) {
|
|
1170
|
+
if (typeof (e ? this.state.strokeStyle : this.state.fillStyle) != "string" || !this.plain()) return this.unsupported();
|
|
1171
|
+
this.texts.push({
|
|
1172
|
+
stroke: e,
|
|
1173
|
+
text: String(t),
|
|
1174
|
+
x: n,
|
|
1175
|
+
y: r,
|
|
1176
|
+
maxWidth: i,
|
|
1177
|
+
state: this.copyState()
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
measureText(e) {
|
|
1181
|
+
let t = this.measure;
|
|
1182
|
+
if (!t) return { width: String(e).length * 6 };
|
|
1183
|
+
let n = t.font;
|
|
1184
|
+
t.font = this.state.font;
|
|
1185
|
+
let r = t.measureText(e);
|
|
1186
|
+
return t.font = n, r;
|
|
1187
|
+
}
|
|
1188
|
+
methods() {
|
|
1189
|
+
let e = () => this.state, t = Object.create(null);
|
|
1190
|
+
return Object.assign(t, {
|
|
1191
|
+
save: () => {
|
|
1192
|
+
this.stack.push(this.copyState());
|
|
1193
|
+
},
|
|
1194
|
+
restore: () => {
|
|
1195
|
+
let e = this.stack.pop();
|
|
1196
|
+
e && (this.state = e);
|
|
1197
|
+
},
|
|
1198
|
+
beginPath: () => {
|
|
1199
|
+
this.path = [];
|
|
1200
|
+
},
|
|
1201
|
+
moveTo: (e, t) => this.moveTo(e, t),
|
|
1202
|
+
lineTo: (e, t) => this.lineTo(e, t),
|
|
1203
|
+
closePath: () => this.closePath(),
|
|
1204
|
+
rect: (e, t, n, r) => this.rect(e, t, n, r),
|
|
1205
|
+
arc: (e, t, n, r, i, a) => this.arc(e, t, n, r, i, a),
|
|
1206
|
+
quadraticCurveTo: (e, t, n, r) => this.curve([e, t], [n, r]),
|
|
1207
|
+
bezierCurveTo: (e, t, n, r, i, a) => this.curve([
|
|
1208
|
+
e,
|
|
1209
|
+
t,
|
|
1210
|
+
n,
|
|
1211
|
+
r
|
|
1212
|
+
], [i, a]),
|
|
1213
|
+
fill: (e, t) => typeof e == "object" ? this.onPath(e, () => this.fill(t)) : this.fill(e),
|
|
1214
|
+
stroke: (e) => e ? this.onPath(e, () => this.stroke()) : this.stroke(),
|
|
1215
|
+
clip: (e) => typeof e == "object" ? this.onPath(e, () => this.clip()) : this.clip(),
|
|
1216
|
+
fillRect: (e, t, n, r) => this.withPath(() => this.rect(e, t, n, r), () => this.fill()),
|
|
1217
|
+
strokeRect: (e, t, n, r) => this.withPath(() => this.rect(e, t, n, r), () => this.stroke()),
|
|
1218
|
+
fillText: (e, t, n, r) => this.text(!1, e, t, n, r),
|
|
1219
|
+
strokeText: (e, t, n, r) => this.text(!0, e, t, n, r),
|
|
1220
|
+
measureText: (e) => this.measureText(e),
|
|
1221
|
+
setLineDash: (t) => {
|
|
1222
|
+
t.every((e) => Number.isFinite(e) && e >= 0) && (e().lineDash = t.length % 2 ? [...t, ...t] : [...t]);
|
|
1223
|
+
},
|
|
1224
|
+
getLineDash: () => [...e().lineDash],
|
|
1225
|
+
translate: (e, t) => this.multiply(1, 0, 0, 1, e, t),
|
|
1226
|
+
scale: (e, t) => this.multiply(e, 0, 0, t, 0, 0),
|
|
1227
|
+
rotate: (e) => this.multiply(Math.cos(e), Math.sin(e), -Math.sin(e), Math.cos(e), 0, 0),
|
|
1228
|
+
transform: (e, t, n, r, i, a) => this.multiply(e, t, n, r, i, a),
|
|
1229
|
+
setTransform: (e, t, n, r, i, a) => typeof e == "number" ? this.setMatrix([
|
|
1230
|
+
e,
|
|
1231
|
+
t ?? 0,
|
|
1232
|
+
n ?? 0,
|
|
1233
|
+
r ?? 1,
|
|
1234
|
+
i ?? 0,
|
|
1235
|
+
a ?? 0
|
|
1236
|
+
]) : this.unsupported(),
|
|
1237
|
+
resetTransform: () => this.setMatrix([
|
|
1238
|
+
1,
|
|
1239
|
+
0,
|
|
1240
|
+
0,
|
|
1241
|
+
1,
|
|
1242
|
+
0,
|
|
1243
|
+
0
|
|
1244
|
+
]),
|
|
1245
|
+
getTransform: () => {
|
|
1246
|
+
let [t, n, r, i, a, o] = e().transform;
|
|
1247
|
+
return {
|
|
1248
|
+
a: t,
|
|
1249
|
+
b: n,
|
|
1250
|
+
c: r,
|
|
1251
|
+
d: i,
|
|
1252
|
+
e: a,
|
|
1253
|
+
f: o,
|
|
1254
|
+
m11: t,
|
|
1255
|
+
m12: n,
|
|
1256
|
+
m21: r,
|
|
1257
|
+
m22: i,
|
|
1258
|
+
m41: a,
|
|
1259
|
+
m42: o,
|
|
1260
|
+
is2D: !0,
|
|
1261
|
+
isIdentity: t === 1 && n === 0 && r === 0 && i === 1 && a === 0 && o === 0
|
|
1262
|
+
};
|
|
1263
|
+
},
|
|
1264
|
+
createLinearGradient: (e, t, n, r) => new F(e, t, n, r)
|
|
1265
|
+
}), t;
|
|
1266
|
+
}
|
|
1267
|
+
proxy() {
|
|
1268
|
+
let e = this.methods();
|
|
1269
|
+
return new Proxy({}, {
|
|
1270
|
+
get: (t, n) => {
|
|
1271
|
+
if (typeof n == "string") {
|
|
1272
|
+
if (n in e) return e[n];
|
|
1273
|
+
if (z.has(n)) return this.state[n];
|
|
1274
|
+
if (B.has(n)) return this.state.textExtras[n];
|
|
1275
|
+
if (n === "canvas") return this.measure?.canvas;
|
|
1276
|
+
if (!V.has(n)) return this.unsupported(), () => void 0;
|
|
1277
|
+
}
|
|
1278
|
+
},
|
|
1279
|
+
set: (e, t, n) => (typeof t == "string" && this.setProp(t, n), !0)
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
setProp(e, t) {
|
|
1283
|
+
let n = this.state;
|
|
1284
|
+
e === "lineWidth" || e === "miterLimit" ? typeof t == "number" && Number.isFinite(t) && t > 0 && (n[e] = t) : e === "globalAlpha" ? typeof t == "number" && Number.isFinite(t) && t >= 0 && t <= 1 && (n.globalAlpha = t) : e === "fillStyle" || e === "strokeStyle" ? t instanceof F ? n[e] = t : typeof t == "string" ? m(t) && (n[e] = t) : this.unsupported() : z.has(e) ? n[e] = t : B.has(e) ? this.state.textExtras[e] = t : V.has(e) || this.unsupported();
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
function me(e, t) {
|
|
1288
|
+
for (let n of t) {
|
|
1289
|
+
let t = n.state;
|
|
1290
|
+
if (M(t.clip)) continue;
|
|
1291
|
+
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), Number.isFinite(t.clip.x1) && Number.isFinite(t.clip.y1) && (e.beginPath(), e.rect(t.clip.x0, t.clip.y0, t.clip.x1 - t.clip.x0, t.clip.y1 - t.clip.y0), e.clip());
|
|
1292
|
+
let [r, i, a, o, s, c] = t.transform;
|
|
1293
|
+
e.setTransform(r, i, a, o, s, c), e.font = t.font, e.textAlign = t.textAlign, e.textBaseline = t.textBaseline, e.direction = t.direction, e.globalAlpha = t.globalAlpha, Object.assign(e, t.textExtras), n.stroke ? (e.strokeStyle = t.strokeStyle, e.lineWidth = t.lineWidth, e.strokeText(n.text, n.x, n.y, n.maxWidth)) : (e.fillStyle = t.fillStyle, e.fillText(n.text, n.x, n.y, n.maxWidth)), e.restore();
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
function he(e, t) {
|
|
1297
|
+
return new U(e, t);
|
|
1298
|
+
}
|
|
1299
|
+
//#endregion
|
|
1300
|
+
//#region src/webgl/shaders.ts
|
|
1301
|
+
var W = "#version 300 es\nprecision highp float;\nuniform vec2 u_canvas;\nuniform float u_dpr;\nuniform int u_log;\nuniform int u_invert;\nuniform float u_yA;\nuniform float u_yB;\nuniform float u_logOffset;\nuniform float u_min;\nuniform float u_logFloor;\nuniform float u_logK;\nuniform float u_top;\nuniform float u_bottom;\nout vec4 v_color;\n\n// A price (relative to the base price) to a CSS-pixel y, as priceToYMapper\n// does; mappedY in yMapping.ts is the same steps in TypeScript.\nfloat cssY(float rel) {\n if (u_log == 1) {\n float v = log(max(1.0 + (rel + u_logOffset) / u_min, u_logFloor)) * u_logK;\n return u_invert == 1 ? u_top + v : u_bottom - v;\n }\n return u_yA + rel * u_yB;\n}\n\nfloat snap(float v) { return floor(v + 0.5); }\n\nvec4 toClip(vec2 dev) {\n return vec4(dev.x / u_canvas.x * 2.0 - 1.0, 1.0 - dev.y / u_canvas.y * 2.0, 0.0, 1.0);\n}\n\n// The corners of a quad as two triangles.\nvec2 corner(int k) {\n if (k == 0) return vec2(0.0, 0.0);\n if (k == 1 || k == 4) return vec2(1.0, 0.0);\n if (k == 2 || k == 3) return vec2(0.0, 1.0);\n return vec2(1.0, 1.0);\n}\n\n// Nothing to draw: every vertex at one point off the canvas.\nconst vec4 NOWHERE = vec4(-2.0, -2.0, 0.0, 1.0);\n", ge = `${W}
|
|
1302
|
+
in vec4 a_ohlc;
|
|
1303
|
+
in vec2 a_vd;
|
|
1304
|
+
uniform float u_x0;
|
|
1305
|
+
uniform float u_unit;
|
|
1306
|
+
uniform float u_wick;
|
|
1307
|
+
uniform float u_body;
|
|
1308
|
+
uniform vec4 u_upBody;
|
|
1309
|
+
uniform vec4 u_downBody;
|
|
1310
|
+
uniform vec4 u_upWick;
|
|
1311
|
+
uniform vec4 u_downWick;
|
|
1312
|
+
|
|
1313
|
+
void main() {
|
|
1314
|
+
int vid = gl_VertexID % 12;
|
|
1315
|
+
vec2 cr = corner(vid % 6);
|
|
1316
|
+
bool up = a_vd.y > 0.5;
|
|
1317
|
+
float cx = (u_x0 + float(gl_InstanceID) * u_unit) * u_dpr;
|
|
1318
|
+
float wickLeft = snap(cx - u_wick * 0.5);
|
|
1319
|
+
float left;
|
|
1320
|
+
float width;
|
|
1321
|
+
float top;
|
|
1322
|
+
float height;
|
|
1323
|
+
if (vid < 6) {
|
|
1324
|
+
float h = snap(cssY(a_ohlc.y) * u_dpr);
|
|
1325
|
+
float l = snap(cssY(a_ohlc.z) * u_dpr);
|
|
1326
|
+
left = wickLeft;
|
|
1327
|
+
width = u_wick;
|
|
1328
|
+
top = min(h, l);
|
|
1329
|
+
height = max(abs(l - h), 1.0);
|
|
1330
|
+
v_color = up ? u_upWick : u_downWick;
|
|
1331
|
+
} else {
|
|
1332
|
+
float o = snap(cssY(a_ohlc.x) * u_dpr);
|
|
1333
|
+
float c = snap(cssY(a_ohlc.w) * u_dpr);
|
|
1334
|
+
left = wickLeft - (u_body - u_wick) * 0.5;
|
|
1335
|
+
width = u_body;
|
|
1336
|
+
top = min(o, c);
|
|
1337
|
+
height = max(abs(c - o), u_wick);
|
|
1338
|
+
v_color = up ? u_upBody : u_downBody;
|
|
1339
|
+
}
|
|
1340
|
+
gl_Position = toClip(vec2(left + cr.x * width, top + cr.y * height));
|
|
1341
|
+
}
|
|
1342
|
+
`, _e = `${W}
|
|
1343
|
+
in vec4 a_ohlc;
|
|
1344
|
+
in vec2 a_vd;
|
|
1345
|
+
uniform float u_x0;
|
|
1346
|
+
uniform float u_unit;
|
|
1347
|
+
uniform float u_wick;
|
|
1348
|
+
uniform float u_body;
|
|
1349
|
+
uniform float u_volBottom;
|
|
1350
|
+
uniform float u_volScale;
|
|
1351
|
+
uniform vec4 u_volUp;
|
|
1352
|
+
uniform vec4 u_volDown;
|
|
1353
|
+
|
|
1354
|
+
void main() {
|
|
1355
|
+
vec2 cr = corner(gl_VertexID % 6);
|
|
1356
|
+
float cx = (u_x0 + float(gl_InstanceID) * u_unit) * u_dpr;
|
|
1357
|
+
float left = snap(cx - u_wick * 0.5) - (u_body - u_wick) * 0.5;
|
|
1358
|
+
float bottom = snap(u_volBottom * u_dpr);
|
|
1359
|
+
float top = snap((u_volBottom - a_vd.x * u_volScale) * u_dpr);
|
|
1360
|
+
if (bottom - top < 1.0) { gl_Position = NOWHERE; v_color = vec4(0.0); return; }
|
|
1361
|
+
v_color = a_vd.y > 0.5 ? u_volUp : u_volDown;
|
|
1362
|
+
gl_Position = toClip(vec2(left + cr.x * u_body, top + cr.y * (bottom - top)));
|
|
1363
|
+
}
|
|
1364
|
+
`, ve = `${W}
|
|
1365
|
+
in vec4 a_col;
|
|
1366
|
+
in float a_up;
|
|
1367
|
+
uniform vec4 u_upBody;
|
|
1368
|
+
uniform vec4 u_downBody;
|
|
1369
|
+
|
|
1370
|
+
void main() {
|
|
1371
|
+
vec2 cr = corner(gl_VertexID % 6);
|
|
1372
|
+
float left = snap(a_col.x * u_dpr);
|
|
1373
|
+
float width = max(1.0, snap((a_col.x + 1.0) * u_dpr) - left);
|
|
1374
|
+
float t = snap(cssY(a_col.y) * u_dpr);
|
|
1375
|
+
float b = snap(cssY(a_col.z) * u_dpr);
|
|
1376
|
+
v_color = a_up > 0.5 ? u_upBody : u_downBody;
|
|
1377
|
+
gl_Position = toClip(vec2(left + cr.x * width, min(t, b) + cr.y * max(abs(b - t), 1.0)));
|
|
1378
|
+
}
|
|
1379
|
+
`, ye = `${W}
|
|
1380
|
+
in vec4 a_col;
|
|
1381
|
+
in float a_up;
|
|
1382
|
+
uniform float u_volBottom;
|
|
1383
|
+
uniform float u_volScale;
|
|
1384
|
+
uniform vec4 u_volUp;
|
|
1385
|
+
uniform vec4 u_volDown;
|
|
1386
|
+
|
|
1387
|
+
void main() {
|
|
1388
|
+
vec2 cr = corner(gl_VertexID % 6);
|
|
1389
|
+
float left = snap(a_col.x * u_dpr);
|
|
1390
|
+
float width = max(1.0, snap((a_col.x + 1.0) * u_dpr) - left);
|
|
1391
|
+
float bottom = snap(u_volBottom * u_dpr);
|
|
1392
|
+
float top = snap((u_volBottom - a_col.w * u_volScale) * u_dpr);
|
|
1393
|
+
if (bottom - top < 1.0) { gl_Position = NOWHERE; v_color = vec4(0.0); return; }
|
|
1394
|
+
v_color = a_up > 0.5 ? u_volUp : u_volDown;
|
|
1395
|
+
gl_Position = toClip(vec2(left + cr.x * width, top + cr.y * (bottom - top)));
|
|
1396
|
+
}
|
|
1397
|
+
`, be = `${W}
|
|
1398
|
+
in vec4 a_rect;
|
|
1399
|
+
in vec4 a_color;
|
|
1400
|
+
in vec2 a_dash;
|
|
1401
|
+
flat out vec4 v_rect;
|
|
1402
|
+
flat out vec2 v_dash;
|
|
1403
|
+
|
|
1404
|
+
void main() {
|
|
1405
|
+
vec2 cr = corner(gl_VertexID % 6);
|
|
1406
|
+
v_rect = a_rect * u_dpr;
|
|
1407
|
+
v_dash = a_dash * u_dpr;
|
|
1408
|
+
v_color = a_color;
|
|
1409
|
+
gl_Position = toClip(mix(floor(v_rect.xy), ceil(v_rect.zw), cr));
|
|
1410
|
+
}
|
|
1411
|
+
`, xe = "#version 300 es\nprecision highp float;\nuniform vec2 u_canvas;\nuniform int u_union;\nin vec4 v_color;\nflat in vec4 v_rect;\nflat in vec2 v_dash;\nout vec4 outColor;\n\n// The share of rows [y, y + 1] inside the rectangle and, dashed, on a dash.\nfloat rows(float y) {\n float lo = max(y, v_rect.y);\n float hi = min(y + 1.0, v_rect.w);\n if (hi <= lo) return 0.0;\n if (v_dash.x <= 0.0) return hi - lo;\n // A dash period is longer than a device pixel, so the row meets the dash\n // of the period it starts in and the next (a third to spare).\n float period = v_dash.x + v_dash.y;\n float first = v_rect.y + floor((lo - v_rect.y) / period) * period;\n float on = 0.0;\n for (int i = 0; i < 3; i++) {\n float start = first + float(i) * period;\n on += max(0.0, min(hi, start + v_dash.x) - max(lo, start));\n }\n return on;\n}\n\nvoid main() {\n // This pixel's top-left corner in device pixels, y down.\n vec2 p = vec2(floor(gl_FragCoord.x), u_canvas.y - floor(gl_FragCoord.y) - 1.0);\n float coverage = clamp(min(p.x + 1.0, v_rect.z) - max(p.x, v_rect.x), 0.0, 1.0) * rows(p.y);\n outColor = u_union == 1 ? vec4(v_color.rgb * coverage, coverage) : v_color * coverage;\n}\n", G = "#version 300 es\nprecision highp float;\nuniform vec2 u_canvas;\nuniform vec4 u_clip;\nin vec4 v_color;\nout vec4 outColor;\n\nvoid main() {\n vec2 p = vec2(floor(gl_FragCoord.x), u_canvas.y - floor(gl_FragCoord.y) - 1.0);\n vec2 c = clamp(min(p + 1.0, u_clip.zw) - max(p, u_clip.xy), 0.0, 1.0);\n outColor = v_color * (c.x * c.y);\n}\n", K = 24, q = 5, J = q * 4, Y = 10, X = Y * 4, Z = [
|
|
1412
|
+
"a_ohlc",
|
|
1413
|
+
"a_vd",
|
|
1414
|
+
"a_col",
|
|
1415
|
+
"a_up",
|
|
1416
|
+
"a_rect",
|
|
1417
|
+
"a_color",
|
|
1418
|
+
"a_dash"
|
|
1419
|
+
], Se = class a {
|
|
1420
|
+
label;
|
|
1421
|
+
gl;
|
|
1422
|
+
kit;
|
|
1423
|
+
drawer;
|
|
1424
|
+
candleBars;
|
|
1425
|
+
volumeBars;
|
|
1426
|
+
candleColumns;
|
|
1427
|
+
volumeColumns;
|
|
1428
|
+
rects;
|
|
1429
|
+
seriesBuffer;
|
|
1430
|
+
columnBuffer;
|
|
1431
|
+
rectBuffer;
|
|
1432
|
+
uploads = new o();
|
|
1433
|
+
gpuFloats = 0;
|
|
1434
|
+
columns = new Float32Array(4096 * q);
|
|
1435
|
+
rectValues = new Float32Array(64 * Y);
|
|
1436
|
+
clip = [
|
|
1437
|
+
0,
|
|
1438
|
+
0,
|
|
1439
|
+
0,
|
|
1440
|
+
0
|
|
1441
|
+
];
|
|
1442
|
+
lost = !1;
|
|
1443
|
+
lostCallback = null;
|
|
1444
|
+
static create(e = {}) {
|
|
1445
|
+
if (typeof document > "u") return null;
|
|
1446
|
+
let t = document.createElement("canvas"), n = null;
|
|
1447
|
+
try {
|
|
1448
|
+
n = t.getContext("webgl2", {
|
|
1449
|
+
alpha: !0,
|
|
1450
|
+
premultipliedAlpha: !0,
|
|
1451
|
+
antialias: !1,
|
|
1452
|
+
depth: !1,
|
|
1453
|
+
stencil: !1,
|
|
1454
|
+
preserveDrawingBuffer: !1,
|
|
1455
|
+
failIfMajorPerformanceCaveat: e.failIfMajorPerformanceCaveat ?? !1
|
|
1456
|
+
});
|
|
1457
|
+
} catch (e) {
|
|
1458
|
+
return $(e), null;
|
|
1459
|
+
}
|
|
1460
|
+
if (!n) return null;
|
|
1461
|
+
try {
|
|
1462
|
+
return new a(t, n);
|
|
1463
|
+
} catch (e) {
|
|
1464
|
+
return $(e), Q(n), null;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
constructor(e, t) {
|
|
1468
|
+
this.canvas = e, this.gl = t, this.kit = new v(t);
|
|
1469
|
+
let n = t.getExtension("WEBGL_debug_renderer_info");
|
|
1470
|
+
this.label = String(n ? t.getParameter(n.UNMASKED_RENDERER_WEBGL) : t.getParameter(t.RENDERER));
|
|
1471
|
+
let r = this.kit;
|
|
1472
|
+
this.candleBars = r.program(ge, G, Z), this.volumeBars = r.program(_e, G, Z), this.candleColumns = r.program(ve, G, Z), this.volumeColumns = r.program(ye, G, Z), this.rects = r.program(be, xe, Z), this.seriesBuffer = r.buffer(), this.columnBuffer = r.buffer(), this.rectBuffer = r.buffer(), this.drawer = new A(r), e.addEventListener("webglcontextlost", this.handleLost);
|
|
1473
|
+
}
|
|
1474
|
+
onLost(e) {
|
|
1475
|
+
this.lostCallback = e, (this.lost || this.gl.isContextLost()) && (this.lost = !0, queueMicrotask(() => {
|
|
1476
|
+
this.lostCallback === e && e();
|
|
1477
|
+
}));
|
|
1478
|
+
}
|
|
1479
|
+
recorder(e, t) {
|
|
1480
|
+
return he(e, t);
|
|
1481
|
+
}
|
|
1482
|
+
render(e) {
|
|
1483
|
+
let t = this.gl;
|
|
1484
|
+
if (this.lost || t.isContextLost()) return {
|
|
1485
|
+
series: !1,
|
|
1486
|
+
volume: !1,
|
|
1487
|
+
background: !1,
|
|
1488
|
+
recorded: !1
|
|
1489
|
+
};
|
|
1490
|
+
let n = Ce(e.recorded) ? e.recorded : null, r = {
|
|
1491
|
+
series: e.candles,
|
|
1492
|
+
volume: e.volume !== null,
|
|
1493
|
+
background: e.background !== null,
|
|
1494
|
+
recorded: n !== null
|
|
1495
|
+
};
|
|
1496
|
+
return t.viewport(0, 0, this.canvas.width, this.canvas.height), t.disable(t.SCISSOR_TEST), t.clearColor(0, 0, 0, 0), t.clear(t.COLOR_BUFFER_BIT), t.enable(t.BLEND), e.background && this.drawBackground(e, e.background), this.drawSeries(e), n && n.commands.length > 0 && this.drawer.draw(n.commands, this.canvas.width, this.canvas.height, (t, n) => this.drawRecordedRects(e, t, n)), r;
|
|
1497
|
+
}
|
|
1498
|
+
drawSeries(t) {
|
|
1499
|
+
let n = this.gl, { data: r, viewport: i, dpr: a } = t;
|
|
1500
|
+
if (r.length === 0 || !t.candles && !t.volume) return;
|
|
1501
|
+
this.syncSeries(t);
|
|
1502
|
+
let o = Math.max(0, i.visibleRange.from), s = Math.min(i.visibleRange.to, r.length - 1);
|
|
1503
|
+
if (s < o) return;
|
|
1504
|
+
let { chartRect: c } = i;
|
|
1505
|
+
this.clip = [
|
|
1506
|
+
c.x * a,
|
|
1507
|
+
c.y * a,
|
|
1508
|
+
(c.x + c.width) * a,
|
|
1509
|
+
(c.y + c.height) * a
|
|
1510
|
+
];
|
|
1511
|
+
let l = Math.floor(this.clip[0]), u = Math.floor(this.clip[1]), d = Math.ceil(this.clip[2]) - l, f = Math.ceil(this.clip[3]) - u;
|
|
1512
|
+
n.enable(n.SCISSOR_TEST), n.scissor(l, this.canvas.height - u - f, Math.max(0, d), Math.max(0, f)), n.blendFunc(n.ONE, n.ONE_MINUS_SRC_ALPHA);
|
|
1513
|
+
let p = e(i), m = p ? this.buildColumns(t, o, s) : 0;
|
|
1514
|
+
t.volume && this.drawVolume(t, o, s, p, m);
|
|
1515
|
+
let { min: h, max: g } = i.priceRange;
|
|
1516
|
+
t.candles && g - h !== 0 && this.drawCandles(t, o, s, p, m), n.disable(n.SCISSOR_TEST);
|
|
1517
|
+
}
|
|
1518
|
+
drawRecordedRects(e, t, n) {
|
|
1519
|
+
let r = this.gl, i = this.use(this.rects, e);
|
|
1520
|
+
this.kit.float(i, "u_dpr", 1), this.kit.int(i, "u_union", 0), r.bindBuffer(r.ARRAY_BUFFER, this.rectBuffer), r.bufferData(r.ARRAY_BUFFER, t, r.STREAM_DRAW), this.bindRects(i, 0), r.drawArraysInstanced(r.TRIANGLES, 0, 6, n);
|
|
1521
|
+
}
|
|
1522
|
+
destroy() {
|
|
1523
|
+
this.canvas.removeEventListener("webglcontextlost", this.handleLost), this.lostCallback = null;
|
|
1524
|
+
let e = this.gl;
|
|
1525
|
+
if (!e.isContextLost()) {
|
|
1526
|
+
for (let e of [
|
|
1527
|
+
this.candleBars,
|
|
1528
|
+
this.volumeBars,
|
|
1529
|
+
this.candleColumns,
|
|
1530
|
+
this.volumeColumns,
|
|
1531
|
+
this.rects
|
|
1532
|
+
]) this.kit.deleteProgram(e);
|
|
1533
|
+
this.drawer.destroy(), e.deleteBuffer(this.seriesBuffer), e.deleteBuffer(this.columnBuffer), e.deleteBuffer(this.rectBuffer), Q(e);
|
|
1534
|
+
}
|
|
1535
|
+
this.canvas.remove();
|
|
1536
|
+
}
|
|
1537
|
+
handleLost = (e) => {
|
|
1538
|
+
e.preventDefault(), !this.lost && (this.lost = !0, this.lostCallback?.());
|
|
1539
|
+
};
|
|
1540
|
+
syncSeries(e) {
|
|
1541
|
+
let t = this.gl, n = this.uploads.sync(e.data), r = this.uploads.values;
|
|
1542
|
+
t.bindBuffer(t.ARRAY_BUFFER, this.seriesBuffer), n.full || r.length !== this.gpuFloats ? (t.bufferData(t.ARRAY_BUFFER, r, t.DYNAMIC_DRAW), this.gpuFloats = r.length) : n.to > n.from && t.bufferSubData(t.ARRAY_BUFFER, n.from * K, r, n.from * 6, (n.to - n.from) * 6);
|
|
1543
|
+
}
|
|
1544
|
+
buildColumns(e, t, r) {
|
|
1545
|
+
let { viewport: i, data: a } = e, o = i.barWidth + i.barSpacing, s = -i.offset + i.chartRect.x + i.barWidth / 2, c = this.uploads.base, l = 0;
|
|
1546
|
+
n(a, t, r, (e) => e * o + s, (e) => {
|
|
1547
|
+
if ((l + 1) * q > this.columns.length) {
|
|
1548
|
+
let e = new Float32Array(this.columns.length * 2);
|
|
1549
|
+
e.set(this.columns), this.columns = e;
|
|
1550
|
+
}
|
|
1551
|
+
let t = l * q;
|
|
1552
|
+
this.columns[t] = e.x, this.columns[t + 1] = e.high - c, this.columns[t + 2] = e.low - c, this.columns[t + 3] = e.volume, this.columns[t + 4] = +(e.close >= e.open), l++;
|
|
1553
|
+
});
|
|
1554
|
+
let u = this.gl;
|
|
1555
|
+
return u.bindBuffer(u.ARRAY_BUFFER, this.columnBuffer), u.bufferData(u.ARRAY_BUFFER, this.columns.subarray(0, l * q), u.STREAM_DRAW), l;
|
|
1556
|
+
}
|
|
1557
|
+
drawBackground(e, t) {
|
|
1558
|
+
let { viewport: n, theme: i } = e, a = t.grid ? r(n) : {
|
|
1559
|
+
horizontal: [],
|
|
1560
|
+
vertical: []
|
|
1561
|
+
}, o = a.horizontal.length + a.vertical.length, s = o + t.rects.length;
|
|
1562
|
+
if (s === 0) return;
|
|
1563
|
+
this.rectValues.length < s * Y && (this.rectValues = new Float32Array(s * Y * 2));
|
|
1564
|
+
let c = this.rectValues, l = 0, u = (e, t, n, r, i, a, o) => {
|
|
1565
|
+
c[l++] = e, c[l++] = t, c[l++] = n, c[l++] = r;
|
|
1566
|
+
for (let e = 0; e < 4; e++) c[l++] = i[e] * a;
|
|
1567
|
+
c[l++] = o ? o[0] : 0, c[l++] = o ? o[1] : 0;
|
|
1568
|
+
}, d = g(h(i.grid)), { chartRect: f } = n;
|
|
1569
|
+
for (let e of a.horizontal) u(f.x, e - .5, f.x + f.width, e + .5, d, 1);
|
|
1570
|
+
for (let e of a.vertical) u(e - .5, f.y, e + .5, f.y + f.height, d, 1);
|
|
1571
|
+
let p = "", m = d;
|
|
1572
|
+
for (let e of t.rects) e.color !== p && (p = e.color, m = g(h(e.color))), u(e.x, e.y, e.x + e.width, e.y + e.height, m, e.alpha, e.dash);
|
|
1573
|
+
let _ = this.gl, v = this.use(this.rects, e);
|
|
1574
|
+
_.bindBuffer(_.ARRAY_BUFFER, this.rectBuffer), _.bufferData(_.ARRAY_BUFFER, c.subarray(0, l), _.STREAM_DRAW), o > 0 && (_.uniform1i(this.loc(v, "u_union"), 1), _.blendColor(0, 0, 0, d[3]), _.blendFuncSeparate(_.ONE, _.ONE_MINUS_SRC_ALPHA, _.CONSTANT_ALPHA, _.ONE_MINUS_SRC_ALPHA), this.bindRects(v, 0), _.drawArraysInstanced(_.TRIANGLES, 0, 6, o)), t.rects.length > 0 && (_.uniform1i(this.loc(v, "u_union"), 0), _.blendFunc(_.ONE, _.ONE_MINUS_SRC_ALPHA), this.bindRects(v, o), _.drawArraysInstanced(_.TRIANGLES, 0, 6, t.rects.length));
|
|
1575
|
+
}
|
|
1576
|
+
drawCandles(e, t, n, r, i) {
|
|
1577
|
+
let { theme: a, viewport: o, dpr: s } = e, c = g(h(a.candleUp)), l = g(h(a.candleDown));
|
|
1578
|
+
if (r) {
|
|
1579
|
+
let t = this.use(this.candleColumns, e);
|
|
1580
|
+
this.vec4(t, "u_upBody", c), this.vec4(t, "u_downBody", l), this.bindColumns(t), this.gl.drawArraysInstanced(this.gl.TRIANGLES, 0, 6, i);
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
let u = this.use(this.candleBars, e);
|
|
1584
|
+
this.barUniforms(u, o, t, s), this.vec4(u, "u_upBody", c), this.vec4(u, "u_downBody", l), this.vec4(u, "u_upWick", g(h(a.candleUpWick))), this.vec4(u, "u_downWick", g(h(a.candleDownWick))), this.bindBars(u, t), this.gl.drawArraysInstanced(this.gl.TRIANGLES, 0, 12, n - t + 1);
|
|
1585
|
+
}
|
|
1586
|
+
drawVolume(e, t, n, r, a) {
|
|
1587
|
+
let { data: o, viewport: s, theme: c, dpr: l } = e, u = 0;
|
|
1588
|
+
for (let e = t; e <= n; e++) o[e].volume > u && (u = o[e].volume);
|
|
1589
|
+
if (u === 0) return;
|
|
1590
|
+
let { chartRect: d } = s, f = i(c), p = this.use(r ? this.volumeColumns : this.volumeBars, e);
|
|
1591
|
+
if (this.float(p, "u_volBottom", d.y + d.height), this.float(p, "u_volScale", d.height * (e.volume?.heightRatio ?? .15) / u), this.vec4(p, "u_volUp", g(h(f.up))), this.vec4(p, "u_volDown", g(h(f.down))), r) {
|
|
1592
|
+
this.bindColumns(p), this.gl.drawArraysInstanced(this.gl.TRIANGLES, 0, 6, a);
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
this.barUniforms(p, s, t, l), this.bindBars(p, t), this.gl.drawArraysInstanced(this.gl.TRIANGLES, 0, 6, n - t + 1);
|
|
1596
|
+
}
|
|
1597
|
+
barUniforms(e, n, r, i) {
|
|
1598
|
+
let a = n.barWidth + n.barSpacing, o = -n.offset + n.chartRect.x + n.barWidth / 2, { body: s, wick: c } = t(n.barWidth, i);
|
|
1599
|
+
this.float(e, "u_x0", r * a + o), this.float(e, "u_unit", a), this.float(e, "u_wick", c), this.float(e, "u_body", s);
|
|
1600
|
+
}
|
|
1601
|
+
use(e, t) {
|
|
1602
|
+
let n = this.gl;
|
|
1603
|
+
this.kit.use(e), n.uniform2f(this.loc(e, "u_canvas"), this.canvas.width, this.canvas.height), this.vec4(e, "u_clip", this.clip), this.float(e, "u_dpr", t.dpr);
|
|
1604
|
+
let r = _(t.viewport, this.uploads.base);
|
|
1605
|
+
return n.uniform1i(this.loc(e, "u_log"), r.log), n.uniform1i(this.loc(e, "u_invert"), r.invert), this.float(e, "u_yA", r.yA), this.float(e, "u_yB", r.yB), this.float(e, "u_logOffset", r.logOffset), this.float(e, "u_min", r.min), this.float(e, "u_logFloor", r.logFloor), this.float(e, "u_logK", r.logK), this.float(e, "u_top", r.top), this.float(e, "u_bottom", r.bottom), e;
|
|
1606
|
+
}
|
|
1607
|
+
bindBars(e, t) {
|
|
1608
|
+
let n = this.gl;
|
|
1609
|
+
n.bindBuffer(n.ARRAY_BUFFER, this.seriesBuffer), this.attrib(e, "a_ohlc", 4, K, t * K), this.attrib(e, "a_vd", 2, K, t * K + 16);
|
|
1610
|
+
}
|
|
1611
|
+
bindRects(e, t) {
|
|
1612
|
+
this.attrib(e, "a_rect", 4, X, t * X), this.attrib(e, "a_color", 4, X, t * X + 16), this.attrib(e, "a_dash", 2, X, t * X + 32);
|
|
1613
|
+
}
|
|
1614
|
+
bindColumns(e) {
|
|
1615
|
+
let t = this.gl;
|
|
1616
|
+
t.bindBuffer(t.ARRAY_BUFFER, this.columnBuffer), this.attrib(e, "a_col", 4, J, 0), this.attrib(e, "a_up", 1, J, 16);
|
|
1617
|
+
}
|
|
1618
|
+
attrib(e, t, n, r, i) {
|
|
1619
|
+
this.kit.attrib(e, t, n, r, i);
|
|
1620
|
+
}
|
|
1621
|
+
float(e, t, n) {
|
|
1622
|
+
this.kit.float(e, t, n);
|
|
1623
|
+
}
|
|
1624
|
+
vec4(e, t, n) {
|
|
1625
|
+
this.kit.vec4(e, t, n);
|
|
1626
|
+
}
|
|
1627
|
+
loc(e, t) {
|
|
1628
|
+
return this.kit.loc(e, t);
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
function Ce(e) {
|
|
1632
|
+
return typeof e == "object" && !!e && Array.isArray(e.commands);
|
|
1633
|
+
}
|
|
1634
|
+
function Q(e) {
|
|
1635
|
+
e.getExtension("WEBGL_lose_context")?.loseContext();
|
|
1636
|
+
}
|
|
1637
|
+
function $(e) {
|
|
1638
|
+
console.warn("TradeCanvas: WebGL renderer unavailable, drawing with Canvas 2D.", e);
|
|
1639
|
+
}
|
|
1640
|
+
//#endregion
|
|
1641
|
+
export { Se as WebGLSeriesRenderer };
|
|
1642
|
+
|
|
1643
|
+
//# sourceMappingURL=WebGLSeriesRenderer-DQOPCwno.js.map
|