p1-charts 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +100 -2
- package/dist/CategoryBarChart-1Kn3Vozc.js +580 -0
- package/dist/CategoryBarChart-1Kn3Vozc.js.map +1 -0
- package/dist/ChartFrame-B1bVFM2E.js +403 -0
- package/dist/ChartFrame-B1bVFM2E.js.map +1 -0
- package/dist/{Heatmap-C1XcTUg1.js → Heatmap-CFC753mV.js} +278 -272
- package/dist/Heatmap-CFC753mV.js.map +1 -0
- package/dist/{PieLegend-BZsv9IbF.js → PieLegend-CbpjaOJH.js} +94 -111
- package/dist/PieLegend-CbpjaOJH.js.map +1 -0
- package/dist/PolarChart-hcNTWKfJ.js +450 -0
- package/dist/PolarChart-hcNTWKfJ.js.map +1 -0
- package/dist/Sparkline-BApLVWfg.js +110 -0
- package/dist/Sparkline-BApLVWfg.js.map +1 -0
- package/dist/{TimeSeriesChart-BIwJxgnD.js → TimeSeriesChart-BzeHEtQl.js} +120 -119
- package/dist/{TimeSeriesChart-BIwJxgnD.js.map → TimeSeriesChart-BzeHEtQl.js.map} +1 -1
- package/dist/category.d.ts +1 -1
- package/dist/category.d.ts.map +1 -1
- package/dist/category.js +1 -1
- package/dist/charts/CategoryBarChart/index.d.ts +1 -1
- package/dist/charts/CategoryBarChart/index.d.ts.map +1 -1
- package/dist/charts/Heatmap/index.d.ts.map +1 -1
- package/dist/charts/PolarChart/index.d.ts.map +1 -1
- package/dist/charts/ScatterChart/index.d.ts +1 -1
- package/dist/charts/ScatterChart/index.d.ts.map +1 -1
- package/dist/charts/Sparkline/index.d.ts +5 -2
- package/dist/charts/Sparkline/index.d.ts.map +1 -1
- package/dist/components/ChartFrame/index.d.ts +7 -0
- package/dist/components/ChartFrame/index.d.ts.map +1 -0
- package/dist/components/ChartStory/index.d.ts +7 -0
- package/dist/components/ChartStory/index.d.ts.map +1 -0
- package/dist/components/HeatmapCells/index.d.ts +1 -1
- package/dist/components/HeatmapCells/index.d.ts.map +1 -1
- package/dist/{css-C-rsk7-l.js → css-BtFQ2bM4.js} +2 -2
- package/dist/{css-C-rsk7-l.js.map → css-BtFQ2bM4.js.map} +1 -1
- package/dist/heatmap.js +1 -1
- package/dist/hooks/useMarkMemory.d.ts +9 -0
- package/dist/hooks/useMarkMemory.d.ts.map +1 -0
- package/dist/hooks/usePieTween.d.ts.map +1 -1
- package/dist/hooks/useSteps.d.ts +4 -0
- package/dist/hooks/useSteps.d.ts.map +1 -0
- package/dist/hooks/useTween.d.ts +12 -0
- package/dist/hooks/useTween.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -118
- package/dist/index.js.map +1 -1
- package/dist/motion.utils-DFoqptDi.js +55 -0
- package/dist/motion.utils-DFoqptDi.js.map +1 -0
- package/dist/pie.js +1 -1
- package/dist/scatter.js +1 -1
- package/dist/series.js +1 -1
- package/dist/{tooltip.utils-D7xaBSUK.js → shared-C1pGJV4T.js} +3 -7
- package/dist/shared-C1pGJV4T.js.map +1 -0
- package/dist/sparkline.d.ts +1 -1
- package/dist/sparkline.d.ts.map +1 -1
- package/dist/sparkline.js +2 -2
- package/dist/story.d.ts +11 -0
- package/dist/story.d.ts.map +1 -0
- package/dist/story.js +7 -0
- package/dist/theme.js +3 -3
- package/dist/{theme.utils-CP1XtGIe.js → theme.utils-DgmWROoe.js} +40 -20
- package/dist/theme.utils-DgmWROoe.js.map +1 -0
- package/dist/tooltip.utils-CXD_NapA.js +9 -0
- package/dist/tooltip.utils-CXD_NapA.js.map +1 -0
- package/dist/types/category.d.ts +10 -0
- package/dist/types/category.d.ts.map +1 -1
- package/dist/types/heatmap.d.ts +3 -0
- package/dist/types/heatmap.d.ts.map +1 -1
- package/dist/types/heatmapParts.d.ts +2 -0
- package/dist/types/heatmapParts.d.ts.map +1 -1
- package/dist/types/motion.d.ts +31 -0
- package/dist/types/motion.d.ts.map +1 -0
- package/dist/types/pie.d.ts +3 -4
- package/dist/types/pie.d.ts.map +1 -1
- package/dist/types/polar.d.ts +3 -0
- package/dist/types/polar.d.ts.map +1 -1
- package/dist/types/scatter.d.ts +3 -0
- package/dist/types/scatter.d.ts.map +1 -1
- package/dist/types/sparkline.d.ts +3 -0
- package/dist/types/sparkline.d.ts.map +1 -1
- package/dist/types/story.d.ts +73 -0
- package/dist/types/story.d.ts.map +1 -0
- package/dist/{useChartTheme-B06p_jvu.js → useChartTheme-KKtc1C4K.js} +2 -2
- package/dist/{useChartTheme-B06p_jvu.js.map → useChartTheme-KKtc1C4K.js.map} +1 -1
- package/dist/useControllable-Crsr0byh.js +11 -0
- package/dist/useControllable-Crsr0byh.js.map +1 -0
- package/dist/useMarkMemory-CLNY6TtT.js +15 -0
- package/dist/useMarkMemory-CLNY6TtT.js.map +1 -0
- package/dist/useTween-B0G0CcvM.js +46 -0
- package/dist/useTween-B0G0CcvM.js.map +1 -0
- package/dist/utils/category.utils.d.ts +2 -0
- package/dist/utils/category.utils.d.ts.map +1 -1
- package/dist/utils/color.utils.d.ts +9 -0
- package/dist/utils/color.utils.d.ts.map +1 -1
- package/dist/utils/csv.utils.d.ts +6 -0
- package/dist/utils/csv.utils.d.ts.map +1 -0
- package/dist/utils/motion.utils.d.ts +25 -0
- package/dist/utils/motion.utils.d.ts.map +1 -1
- package/dist/utils/pieTween.utils.d.ts +1 -1
- package/dist/utils/pieTween.utils.d.ts.map +1 -1
- package/dist/utils/sparkline.utils.d.ts +15 -0
- package/dist/utils/sparkline.utils.d.ts.map +1 -1
- package/dist/{visibility.utils-nMI5a_Et.js → visibility.utils-wuc3ZS8D.js} +18 -25
- package/dist/visibility.utils-wuc3ZS8D.js.map +1 -0
- package/package.json +10 -3
- package/src/category.ts +1 -0
- package/src/charts/CategoryBarChart/index.tsx +203 -44
- package/src/charts/Heatmap/index.tsx +4 -0
- package/src/charts/PolarChart/index.tsx +98 -5
- package/src/charts/ScatterChart/index.tsx +96 -13
- package/src/charts/Sparkline/index.tsx +54 -7
- package/src/components/ChartFrame/index.tsx +180 -0
- package/src/components/ChartStory/index.tsx +184 -0
- package/src/components/HeatmapCells/index.tsx +5 -2
- package/src/hooks/useMarkMemory.ts +29 -0
- package/src/hooks/usePieTween.ts +9 -44
- package/src/hooks/useSteps.ts +77 -0
- package/src/hooks/useTween.ts +112 -0
- package/src/index.ts +19 -0
- package/src/sparkline.ts +1 -1
- package/src/story.ts +19 -0
- package/src/types/category.ts +11 -0
- package/src/types/heatmap.ts +3 -0
- package/src/types/heatmapParts.ts +2 -0
- package/src/types/motion.ts +35 -0
- package/src/types/pie.ts +3 -3
- package/src/types/polar.ts +3 -0
- package/src/types/scatter.ts +3 -0
- package/src/types/sparkline.ts +3 -0
- package/src/types/story.ts +103 -0
- package/src/utils/category.utils.ts +22 -0
- package/src/utils/color.utils.ts +48 -0
- package/src/utils/csv.utils.ts +28 -0
- package/src/utils/motion.utils.ts +124 -0
- package/src/utils/pieTween.utils.ts +1 -2
- package/src/utils/sparkline.utils.ts +69 -0
- package/dist/CategoryBarChart-YEJ9VB8h.js +0 -453
- package/dist/CategoryBarChart-YEJ9VB8h.js.map +0 -1
- package/dist/Heatmap-C1XcTUg1.js.map +0 -1
- package/dist/PieLegend-BZsv9IbF.js.map +0 -1
- package/dist/PolarChart-BUEhn3CI.js +0 -334
- package/dist/PolarChart-BUEhn3CI.js.map +0 -1
- package/dist/Sparkline-DtNhxGVo.js +0 -67
- package/dist/Sparkline-DtNhxGVo.js.map +0 -1
- package/dist/motion.utils-C1eaZJdQ.js +0 -9
- package/dist/motion.utils-C1eaZJdQ.js.map +0 -1
- package/dist/theme.utils-CP1XtGIe.js.map +0 -1
- package/dist/tooltip.utils-D7xaBSUK.js.map +0 -1
- package/dist/visibility.utils-nMI5a_Et.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeSeriesChart-BIwJxgnD.js","names":["_Fragment","_Fragment","histogramColorsFromTheme","textStyle","withAlpha","resetOptions","chartOptionsFromTheme","deepMerge","referenceLine","candleOptionsFromTheme","TOOLTIP","placeTip","useChartTheme","prefersReducedMotion","timeAt","x","timeScale","index","time","timeToX","exact","nearest","left","leftTime","rightTime","leftX","rightX","barEdgesX","indexOf","first","from","next","to","firstTime","nextTime","last","right","half","WRAPPER","FILL","BAND","FLASH","PILL_POSITION","PILL","BAND_LEGEND","BAND_LEGEND_ITEM","BAND_MARK","RANGE_SELECT","withoutCreationOnly","options","layout","resetAndMerge","previous","applied","owner","defaults","useChart","instance","setInstance","useState","generation","setGeneration","creationOptions","useRef","chartOptions","appliedChart","appliedSeries","useEffect","element","container","chart","createChart","series","definition","value","seriesOptions","MS_THRESHOLD","toUnixSeconds","isMs","trimmed","normalizeSeries","byTime","point","input","config","times","a","b","data","points","rows","indexByTime","isValid","candle","normalizeCandles","color","borderColor","wickColor","normalizePoints","timeKey","indexAtOrBefore","low","high","found","mid","barTime","UNSTYLED_FILL","sortBands","bands","start","band","end","bandKeys","resolveBandStyles","categorical","theme","keys","fill","own","bandStyles","key","bandAt","hovered","before","bars","styles","LABEL_INSET","dash","style","width","paint","item","rect","context","y","height","hatch","spacing","offset","stroke","lineWidth","text","TimeRangePrimitive","target","requestUpdate","mediaSize","useBands","sorted","useMemo","primitive","latest","enabled","pane","created","entries","bandOf","useCallback","normalized","useOverlays","list","create","LineSeries","overlays","overlay","entry","MIN_VISIBLE_BARS","ZOOM_SPEED","HALF_BAR","tickDirection","after","beforeTime","afterTime","secondLast","sameBar","appended","flashColors","record","up","down","topLine","bottomLine","zoomRange","factor","delta","anchor","range","wheelPixels","event","scaled","isLive","lastIndex","useWheelZoom","onWheel","nextBucketSize","pxPerRawBar","current","rawCount","minBarWidth","buckets","bucketSize","result","i","items","SETTLE_MS","DEFAULT_MIN_BAR_WIDTH","minBarWidthOf","autoBucket","useAutoBucket","setBucketSize","size","raw","timer","frame","measure","span","schedule","useSeriesData","normalize","aggregate","appliedBucket","ratio","keep","IDLE_MS","PAUSE_EVENTS","sameRange","useLiveFollow","away","setAway","lastIndexRef","check","paused","resume","shift","wasLive","touch","type","FLASH_MS","LABEL_PADDING","usePriceFlash","flash","direction","colors","NO_LINES","usePriceLines","lines","line","useSeriesTheme","resolved","magnet","magnetMode","ctrlWheelZoom","themedLine","anchorLine","DAY","monthsBefore","date","seconds","months","startOf","preset","presetRange","useRangePreset","hasData","percent","highLow","row","visibleStats","MIN_DRAG","useRangeSelect","selecting","setSelecting","plotX","box","stop","onMove","onUp","onKey","fromLogical","toLogical","stats","onDown","onDoubleClick","toSeriesSummary","anchorIndex","tooltipTransform","flipX","gap","DEFAULT_LINE","useAnchor","price","useChartEvents","handlersRef","handlers","selectRef","onSelect","stale","active","setActive","activate","track","select","eventAt","bar","build","fromParam","param","onClick","useKeyboardNav","actionsRef","actions","driving","reveal","goTo","release","onKeyDown","step","onBlur","onPointerMove","useCrosshairBand","place","KEYS","TOOLTIP_GAP","tooltipAt","useInteractions","pinned","setPinned","pinnedTime","pinOnClick","pinnedIndex","events","summary","legend","tooltip","placeBand","keyboard","legendSummary","tipSummary","transform","useVisibleStats","handler","onChange","emit","BandLegend","render","Fragment","border","legendColor","label","LEGEND","InteractionSlots","renderLegend","renderTooltip","SeriesChartInner","CrosshairMode","selection","overlaySeries","themedOverlays","priceLines","onVisibleStatsChange","interactions","themedAnchorLine","flashLastPrice","rangeSelect","doubleClickReset","followLive","useImperativeHandle","ref","ariaLabel","renderBandLegend","classNames","liveButtonClassName","unstyled","jumpToLive","liveButtonLabel","SeriesChart","forwardRef","barColor","mode","threshold","colorBars","ownAutoscale","original","symmetricAutoscale","info","extent","minValue","maxValue","histogramOptions","histogramPriceLines","thresholdLine","zeroLine","aggregatePoints","slice","toLinePoints","candles","stylePoints","rest","source","styled","colorKeys","styleKeys","BarChart","props","upColor","downColor","base","HistogramSeries","VARIANTS","AreaSeries","BaselineSeries","LineChart","variant","lineOptionsFromTheme","baseValue","isUp","HistogramChart","over","positive","negative","CandlestickChart","CandlestickSeries","RibbonPrimitive","min","max","coords","upper","lower","containers","installed","patchSquareCanvasLabels","proto","root","w","h","radii","FALLBACK_FONT","editorialChartOptions","scale","palette","hairline","LineStyle","ColorType","typography","leftPriceScale","rightPriceScale","tickMarkFormatter","timeFormatter","ORDINAL_STEP","ordinalIndex","categories","ordinalTime","ordinalLabel","seriesTime","unix","seriesRows","unique","ribbonSamples","below","samples","defaultTimeLabel","STROKE","DEFINITION","NO_CATEGORIES","NO_RIBBONS","NO_RANGES","NO_GUIDES","NO_MARKERS","TIP","scaleOf","seriesColor","spec","TimeSeriesChart","setChart","tip","setTip","callbacks","editorial","profile","labels","axis","look","defaultTheme","ribbons","formatTick","api","hosts","painted","kind","common","apiSeries","marks","markers","marker","createSeriesMarkers","ribbon","side","host","rangeHost","ranges","guideValues","guide","guides","values","hit","extra","timeVisible","placed"],"sources":["../src/utils/timeScale.utils.ts","../src/styles/seriesChart.ts","../src/hooks/useChart.ts","../src/utils/time.utils.ts","../src/utils/data.utils.ts","../src/utils/bands.utils.ts","../src/primitives/TimeRangePrimitive.ts","../src/hooks/useBands.ts","../src/hooks/useOverlays.ts","../src/utils/live.utils.ts","../src/hooks/useWheelZoom.ts","../src/utils/bucket.utils.ts","../src/hooks/useAutoBucket.ts","../src/hooks/useSeriesData.ts","../src/hooks/useLiveFollow.ts","../src/hooks/usePriceFlash.ts","../src/hooks/usePriceLines.ts","../src/hooks/useSeriesTheme.ts","../src/utils/range.utils.ts","../src/hooks/useRangePreset.ts","../src/utils/stats.utils.ts","../src/hooks/useRangeSelect.ts","../src/utils/interaction.utils.ts","../src/hooks/useAnchor.ts","../src/hooks/useChartEvents.ts","../src/hooks/useKeyboardNav.ts","../src/hooks/useCrosshairBand.ts","../src/hooks/useInteractions.ts","../src/hooks/useVisibleStats.ts","../src/components/BandLegend/index.tsx","../src/components/InteractionSlots/index.tsx","../src/charts/SeriesChart/index.tsx","../src/utils/histogram.utils.ts","../src/utils/line.utils.ts","../src/charts/BarChart/index.tsx","../src/charts/LineChart/index.tsx","../src/utils/candlestick.utils.ts","../src/charts/HistogramChart/index.tsx","../src/charts/CandlestickChart/index.tsx","../src/primitives/RibbonPrimitive.ts","../src/utils/canvas.utils.ts","../src/utils/editorial.utils.ts","../src/utils/ordinal.utils.ts","../src/utils/timeSeries.utils.ts","../src/charts/TimeSeriesChart/index.tsx"],"sourcesContent":["import type {\n Time,\n Logical,\n UTCTimestamp,\n ITimeScaleApi,\n} from \"lightweight-charts\";\n\nfunction timeAt(timeScale: ITimeScaleApi<Time>, index: number): number | null {\n const x = timeScale.logicalToCoordinate(index as Logical);\n const time = x === null ? null : timeScale.coordinateToTime(x);\n\n return time === null ? null : Number(time);\n}\n\nexport function timeToX(\n timeScale: ITimeScaleApi<Time>,\n time: number,\n): number | null {\n const exact = timeScale.timeToCoordinate(time as UTCTimestamp);\n\n if (exact !== null) return exact;\n\n const nearest = timeScale.timeToIndex(time as UTCTimestamp, true);\n\n if (nearest === null) return null;\n\n const left = Math.max(0, nearest - 1);\n const leftTime = timeAt(timeScale, left);\n const rightTime = timeAt(timeScale, left + 1);\n const leftX = timeScale.logicalToCoordinate(left as Logical);\n const rightX = timeScale.logicalToCoordinate((left + 1) as Logical);\n\n if (\n leftTime === null ||\n rightTime === null ||\n leftX === null ||\n rightX === null ||\n !(rightTime > leftTime)\n )\n return null;\n\n return (\n leftX + ((time - leftTime) / (rightTime - leftTime)) * (rightX - leftX)\n );\n}\n\nexport function barEdgesX(\n timeScale: ITimeScaleApi<Time>,\n from: number,\n to: number,\n): [number, number] | null {\n const indexOf = (time: number) => {\n const index = timeScale.timeToIndex(time as UTCTimestamp, true);\n\n return index === null ? null : Number(index);\n };\n const first = indexOf(from);\n const next = indexOf(to);\n\n if (first === null || next === null) return null;\n\n const firstTime = timeAt(timeScale, first);\n const nextTime = timeAt(timeScale, next);\n\n if (firstTime === null || nextTime === null || firstTime < from) return null;\n\n const last = nextTime < to ? next : next - 1;\n const left = timeScale.logicalToCoordinate(first as Logical);\n const right = timeScale.logicalToCoordinate(last as Logical);\n\n if (last < first || left === null || right === null) return null;\n\n const half = timeScale.options().barSpacing / 2;\n\n return [left - half, right + half];\n}\n","import type { CSSProperties } from \"react\";\n\nexport const WRAPPER: CSSProperties = { position: \"relative\" };\nexport const FILL: CSSProperties = {\n position: \"absolute\",\n inset: 0,\n zIndex: 0,\n};\nexport const BAND: CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n display: \"none\",\n opacity: 0.15,\n pointerEvents: \"none\",\n};\nexport const FLASH: CSSProperties = {\n position: \"absolute\",\n top: 0,\n right: 0,\n opacity: 0,\n pointerEvents: \"none\",\n};\nexport const PILL_POSITION: CSSProperties = {\n position: \"absolute\",\n bottom: 40,\n left: \"50%\",\n transform: \"translateX(-50%)\",\n};\nexport const PILL: CSSProperties = {\n ...PILL_POSITION,\n minHeight: 28,\n padding: \"4px 12px\",\n borderRadius: 999,\n border: \"1px solid color-mix(in srgb, currentColor 25%, transparent)\",\n background: \"Canvas\",\n color: \"CanvasText\",\n font: \"inherit\",\n fontSize: 12,\n cursor: \"pointer\",\n touchAction: \"manipulation\",\n};\nexport const BAND_LEGEND: CSSProperties = {\n position: \"absolute\",\n top: 8,\n right: 8,\n zIndex: 1,\n display: \"flex\",\n flexWrap: \"wrap\",\n gap: 12,\n margin: 0,\n padding: 0,\n listStyle: \"none\",\n pointerEvents: \"none\",\n};\nexport const BAND_LEGEND_ITEM: CSSProperties = {\n display: \"flex\",\n alignItems: \"center\",\n gap: 6,\n};\nexport const BAND_MARK: CSSProperties = {\n flex: \"none\",\n width: 10,\n height: 10,\n boxSizing: \"border-box\",\n};\nexport const RANGE_SELECT: CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n display: \"none\",\n pointerEvents: \"none\",\n};\n","import {\n createChart,\n type SeriesType,\n type DeepPartial,\n type ChartOptions,\n type SeriesDefinition,\n type SeriesPartialOptionsMap,\n} from \"lightweight-charts\";\n\nimport type {\n ChartInstance,\n AppliedOptions,\n InternalInstance,\n} from \"../types/chart.js\";\n\nimport { deepMerge, resetOptions } from \"../utils/merge.utils.js\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\n\nfunction withoutCreationOnly(\n options: DeepPartial<ChartOptions> = {},\n): DeepPartial<ChartOptions> {\n if (!options.layout) return options;\n\n const { colorSpace, colorParsers, ...layout } = options.layout;\n\n return { ...options, layout };\n}\n\nfunction resetAndMerge<O>(\n applied: RefObject<AppliedOptions>,\n owner: unknown,\n defaults: unknown,\n next: O,\n): O | null {\n const previous =\n applied.current.owner === owner ? applied.current.options : {};\n const options = resetOptions(defaults, previous, next);\n\n if (options) applied.current = { owner, options: next };\n\n return options;\n}\n\nexport function useChart<T extends SeriesType>(\n container: RefObject<HTMLDivElement | null>,\n definition: SeriesDefinition<T>,\n chartOptions?: DeepPartial<ChartOptions>,\n seriesOptions?: SeriesPartialOptionsMap[T],\n): ChartInstance<T> | null {\n const [instance, setInstance] = useState<InternalInstance<T> | null>(null);\n const [generation, setGeneration] = useState(0);\n const creationOptions = useRef(chartOptions);\n const appliedChart = useRef<AppliedOptions>({ owner: null, options: {} });\n const appliedSeries = useRef<AppliedOptions>({ owner: null, options: {} });\n creationOptions.current = chartOptions;\n\n useEffect(() => {\n const element = container.current;\n\n if (!element) return;\n\n const layout = creationOptions.current?.layout;\n const chart = createChart(\n element,\n deepMerge(\n { autoSize: true },\n {\n layout: {\n colorSpace: layout?.colorSpace,\n colorParsers: layout?.colorParsers,\n },\n },\n ),\n );\n const series = chart.addSeries(definition);\n\n setInstance({\n chart,\n series,\n chartDefaults: withoutCreationOnly(deepMerge(chart.options())),\n seriesDefaults: deepMerge(series.options()),\n });\n\n return () => {\n setInstance(null);\n chart.remove();\n };\n }, [container, definition, generation]);\n\n useEffect(() => {\n if (!instance) return;\n\n const next = withoutCreationOnly(chartOptions);\n const options = resetAndMerge(\n appliedChart,\n instance,\n instance.chartDefaults,\n next,\n );\n\n if (options) instance.chart.applyOptions(options);\n else setGeneration((value) => value + 1);\n }, [instance, chartOptions]);\n\n useEffect(() => {\n if (!instance) return;\n\n const next = seriesOptions ?? ({} as SeriesPartialOptionsMap[T]);\n const options = resetAndMerge(\n appliedSeries,\n instance,\n instance.seriesDefaults,\n next,\n );\n\n if (options) instance.series.applyOptions(options);\n else setGeneration((value) => value + 1);\n }, [instance, seriesOptions]);\n\n return instance;\n}\n","import type { Time } from \"../types/chart.js\";\n\nconst MS_THRESHOLD = 1e11;\n\nexport function toUnixSeconds(time: Time): number | null {\n let value: number;\n let isMs: boolean;\n\n if (time instanceof Date) {\n value = time.getTime();\n isMs = true;\n } else if (typeof time === \"string\") {\n value = Date.parse(time);\n isMs = true;\n\n if (!Number.isFinite(value)) {\n const trimmed = time.trim();\n\n value = trimmed === \"\" ? Number.NaN : Number(trimmed);\n isMs = Math.abs(value) > MS_THRESHOLD;\n }\n } else {\n value = time;\n isMs = Math.abs(value) > MS_THRESHOLD;\n }\n\n if (!Number.isFinite(value)) return null;\n\n return Math.floor(isMs ? value / 1000 : value);\n}\n","import type {\n LineData,\n UTCTimestamp,\n CandlestickData,\n} from \"lightweight-charts\";\n\nimport type {\n SeriesRow,\n NormalizeConfig,\n NormalizedSeries,\n} from \"../types/series.js\";\n\nimport { toUnixSeconds } from \"./time.utils.js\";\nimport type { LinePoint } from \"../types/chart.js\";\nimport type { OHLC } from \"../types/candlestick.js\";\n\nfunction normalizeSeries<TPoint, TData>(\n input: ReadonlyArray<TPoint>,\n config: NormalizeConfig<TPoint, TData>,\n): NormalizedSeries<TPoint, TData> {\n const byTime = new Map<number, TPoint>();\n\n for (const point of input) {\n const time = config.time(point);\n\n if (time === null || !config.valid(point)) continue;\n byTime.set(time, point);\n }\n\n const times = [...byTime.keys()].sort((a, b) => a - b);\n const data: TData[] = [];\n const points: TPoint[] = [];\n const rows: SeriesRow[] = [];\n const indexByTime = new Map<number, number>();\n\n times.forEach((time, index) => {\n const point = byTime.get(time)!;\n\n data.push(config.data(point, time));\n points.push(point);\n rows.push(config.row(point));\n indexByTime.set(time, index);\n });\n\n return { data, points, rows, indexByTime };\n}\n\nfunction isValid(candle: OHLC): boolean {\n return [candle.open, candle.high, candle.low, candle.close].every(\n Number.isFinite,\n );\n}\n\nexport function normalizeCandles(\n input: ReadonlyArray<OHLC>,\n): NormalizedSeries<OHLC, CandlestickData> {\n return normalizeSeries<OHLC, CandlestickData>(input, {\n time: (candle) => toUnixSeconds(candle.time),\n valid: isValid,\n row: (candle) => candle,\n data: (candle, time) => {\n const { open, high, low, close, color, borderColor, wickColor } = candle;\n\n return {\n time: time as UTCTimestamp,\n open,\n high,\n low,\n close,\n ...(color !== undefined && { color }),\n ...(borderColor !== undefined && { borderColor }),\n ...(wickColor !== undefined && { wickColor }),\n };\n },\n });\n}\n\nexport function normalizePoints(\n input: ReadonlyArray<LinePoint>,\n): NormalizedSeries<LinePoint, LineData> {\n return normalizeSeries<LinePoint, LineData>(input, {\n time: (point) => toUnixSeconds(point.time),\n valid: (point) => Number.isFinite(point.value),\n row: (point) => ({\n time: point.time,\n open: point.value,\n high: point.value,\n low: point.value,\n close: point.value,\n }),\n data: (point, time) => ({\n time: time as UTCTimestamp,\n value: point.value,\n ...(point.color !== undefined && { color: point.color }),\n }),\n });\n}\n\nfunction timeKey(time: unknown): number | null {\n return typeof time === \"number\" ||\n typeof time === \"string\" ||\n time instanceof Date\n ? toUnixSeconds(time)\n : null;\n}\n\nexport function indexAtOrBefore(\n data: ReadonlyArray<{ time: unknown }>,\n time: number,\n): number | null {\n let low = 0;\n let high = data.length - 1;\n let found: number | null = null;\n\n while (low <= high) {\n const mid = (low + high) >> 1;\n const barTime = timeKey(data[mid]!.time);\n\n if (barTime !== null && barTime <= time) {\n found = mid;\n low = mid + 1;\n } else high = mid - 1;\n }\n\n return found;\n}\n","import type {\n BandItem,\n BandStyle,\n BandAtPoint,\n BandStyleInput,\n} from \"../types/bands.js\";\n\nimport { deepMerge } from \"./merge.utils.js\";\nimport { withAlpha } from \"./theme.utils.js\";\nimport type { Theme } from \"../types/theme.js\";\nimport { toUnixSeconds } from \"./time.utils.js\";\nimport { indexAtOrBefore } from \"./data.utils.js\";\n\nconst UNSTYLED_FILL = \"rgba(128,128,128,0.15)\";\n\nexport function sortBands(\n bands: ReadonlyArray<BandItem>,\n): Array<BandItem & { start: number; end: number }> {\n return bands\n .flatMap((band) => {\n const start = toUnixSeconds(band.from);\n const end = toUnixSeconds(band.to);\n\n return start === null || end === null || end < start\n ? []\n : [{ ...band, start, end }];\n })\n .sort((a, b) => a.start - b.start);\n}\n\nexport function bandKeys(bands: ReadonlyArray<BandItem>): string[] {\n return [...new Set(bands.map((band) => band.key))];\n}\n\nexport function resolveBandStyles(\n keys: ReadonlyArray<string>,\n theme: Theme | null,\n bandStyles: Record<string, BandStyleInput> = {},\n): Record<string, BandStyle> {\n const categorical = theme?.palette.categorical ?? [];\n\n return Object.fromEntries(\n keys.map((key, index) => {\n const color = categorical[index % categorical.length];\n const fill =\n (theme && (withAlpha(color, theme.bands.opacity) ?? color)) ||\n UNSTYLED_FILL;\n const own = bandStyles[key];\n\n return [\n key,\n deepMerge<BandStyle>(\n { fill, label: key },\n theme?.bands.styles?.[key],\n typeof own === \"string\" ? { fill: own } : own,\n ),\n ];\n }),\n );\n}\n\nexport function bandAt(\n bands: ReadonlyArray<BandItem>,\n time: number,\n data: ReadonlyArray<{ time: unknown }>,\n styles: Record<string, BandStyle> = {},\n): BandAtPoint | null {\n const band = sortBands(bands)\n .filter(({ start, end }) => start <= time && time < end)\n .pop();\n\n if (!band) return null;\n\n const hovered = indexAtOrBefore(data, time);\n const before = indexAtOrBefore(data, band.start - 1);\n const bars = hovered === null ? 0 : hovered - (before ?? -1);\n\n return {\n key: band.key,\n label: styles[band.key]?.label ?? band.key,\n from: band.from,\n to: band.to,\n bars,\n };\n}\n","import type {\n Time,\n IChartApi,\n IPanePrimitive,\n IPrimitivePaneView,\n PaneAttachedParameter,\n IPrimitivePaneRenderer,\n PrimitivePaneViewZOrder,\n} from \"lightweight-charts\";\n\nimport type { LayoutRect } from \"../types/layout.js\";\nimport { toUnixSeconds } from \"../utils/time.utils.js\";\nimport { barEdgesX, timeToX } from \"../utils/timeScale.utils.js\";\nimport type { PlacedRange, TimeRangeOptions } from \"../types/timeline.js\";\n\ntype Target = Parameters<IPrimitivePaneRenderer[\"draw\"]>[0];\n\nconst LABEL_INSET = 8;\n\nfunction dash(style: string | undefined, width: number): number[] {\n if (style === \"dashed\") return [4 * width, 3 * width];\n if (style === \"dotted\") return [width, 2 * width];\n return [];\n}\n\nfunction paint(\n context: CanvasRenderingContext2D,\n rect: LayoutRect,\n item: PlacedRange,\n) {\n const { style } = item;\n const { x, y, width, height } = rect;\n const fill = item.color ?? style.fill;\n const { stroke, hatch, text } = style;\n\n context.save();\n context.beginPath();\n context.rect(x, y, width, height);\n context.clip();\n\n if (fill) {\n context.fillStyle = fill;\n context.fillRect(x, y, width, height);\n }\n\n if (hatch && hatch.color) {\n const spacing = Math.max(1, hatch.spacing ?? 6);\n\n context.globalAlpha = hatch.opacity ?? 1;\n context.strokeStyle = hatch.color;\n context.lineWidth = hatch.width ?? 1;\n context.beginPath();\n for (let offset = 0; offset < width + height; offset += spacing) {\n context.moveTo(x + offset - height, y + height);\n context.lineTo(x + offset, y);\n }\n context.stroke();\n context.globalAlpha = 1;\n }\n\n if (stroke?.color) {\n const lineWidth = stroke.width ?? 1;\n\n context.strokeStyle = stroke.color;\n context.lineWidth = lineWidth;\n context.setLineDash(dash(stroke.style, lineWidth));\n context.strokeRect(\n x + lineWidth / 2,\n y + lineWidth / 2,\n width - lineWidth,\n height - lineWidth,\n );\n context.setLineDash([]);\n }\n\n if (item.label && text?.color) {\n context.fillStyle = text.color;\n context.font = `${text.weight ?? 400} ${text.size ?? 12}px ${text.family ?? \"sans-serif\"}`;\n context.textBaseline = \"middle\";\n context.fillText(\n item.label,\n x + (style.inset ?? LABEL_INSET),\n y + height / 2,\n );\n }\n\n context.restore();\n}\n\nexport class TimeRangePrimitive implements IPanePrimitive<Time> {\n private zOrder: PrimitivePaneViewZOrder = \"normal\";\n private edges: TimeRangeOptions[\"edges\"] = \"time\";\n private items: PlacedRange[] = [];\n private chart: IChartApi | null = null;\n private requestUpdate: (() => void) | null = null;\n private readonly view: IPrimitivePaneView = {\n zOrder: () => this.zOrder,\n renderer: () => ({ draw: (target) => this.draw(target) }),\n };\n\n constructor(options: TimeRangeOptions) {\n this.applyOptions(options);\n }\n\n applyOptions(options: TimeRangeOptions) {\n this.zOrder = options.zOrder ?? \"normal\";\n this.edges = options.edges ?? \"time\";\n this.items = options.items.flatMap((item) => {\n const from = toUnixSeconds(item.from);\n const to = toUnixSeconds(item.to);\n\n return from === null || to === null\n ? []\n : [\n {\n ...item,\n from: Math.min(from, to),\n to: Math.max(from, to),\n style: options.style(item.key),\n },\n ];\n });\n this.requestUpdate?.();\n }\n\n attached({ chart, requestUpdate }: PaneAttachedParameter<Time>) {\n this.chart = chart;\n this.requestUpdate = requestUpdate;\n requestUpdate();\n }\n\n detached() {\n this.chart = null;\n this.requestUpdate = null;\n }\n\n paneViews() {\n return [this.view];\n }\n\n private draw(target: Target) {\n const chart = this.chart;\n\n if (!chart) return;\n\n const timeScale = chart.timeScale();\n\n target.useMediaCoordinateSpace(({ context, mediaSize }) => {\n for (const item of this.items) {\n const [from = null, to = null] =\n this.edges === \"between-bars\"\n ? (barEdgesX(timeScale, item.from, item.to) ?? [])\n : [timeToX(timeScale, item.from), timeToX(timeScale, item.to)];\n\n if (from === null || to === null) continue;\n\n const left = Math.max(0, from);\n const right = Math.min(mediaSize.width, to);\n\n if (right <= left) continue;\n\n const height = Math.min(\n mediaSize.height,\n item.style.height ?? Infinity,\n );\n\n paint(\n context,\n {\n x: left,\n y: (mediaSize.height - height) / 2,\n width: right - left,\n height,\n },\n item,\n );\n }\n });\n }\n}\n","import type {\n BandItem,\n BandAtPoint,\n BandStyleInput,\n BandLegendEntry,\n} from \"../types/bands.js\";\n\nimport {\n bandAt,\n bandKeys,\n sortBands,\n resolveBandStyles,\n} from \"../utils/bands.utils.js\";\n\nimport type { Theme } from \"../types/theme.js\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { TimeRangeOptions } from \"../types/timeline.js\";\nimport { useMemo, useRef, useEffect, useCallback } from \"react\";\nimport { TimeRangePrimitive } from \"../primitives/TimeRangePrimitive.js\";\n\nexport function useBands<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<unknown, { time: unknown }>,\n bands: ReadonlyArray<BandItem> | undefined,\n bandStyles: Record<string, BandStyleInput> | undefined,\n theme: Theme | null,\n) {\n const sorted = useMemo(() => (bands ? sortBands(bands) : null), [bands]);\n const styles = useMemo(\n () =>\n sorted ? resolveBandStyles(bandKeys(sorted), theme, bandStyles) : {},\n [sorted, theme, bandStyles],\n );\n const options = useMemo<TimeRangeOptions | null>(\n () =>\n sorted && {\n items: sorted.map(({ from, to, key }) => ({ from, to, key })),\n style: (key) => styles[key] ?? {},\n zOrder: \"bottom\",\n edges: \"between-bars\",\n },\n [sorted, styles],\n );\n const primitive = useRef<TimeRangePrimitive | null>(null);\n const applied = useRef<TimeRangeOptions | null>(null);\n const latest = useRef(options);\n const enabled = options !== null;\n latest.current = options;\n\n useEffect(() => {\n const pane = instance?.chart.panes()[0];\n\n if (!pane || !latest.current) return;\n\n const created = new TimeRangePrimitive(latest.current);\n\n pane.attachPrimitive(created);\n primitive.current = created;\n applied.current = latest.current;\n\n return () => {\n pane.detachPrimitive(created);\n primitive.current = null;\n };\n }, [instance, enabled]);\n\n useEffect(() => {\n if (!options || !primitive.current || applied.current === options) return;\n\n primitive.current.applyOptions(options);\n applied.current = options;\n }, [options]);\n\n const entries = useMemo<BandLegendEntry[]>(\n () =>\n Object.entries(styles).map(([key, style]) => ({\n key,\n label: style.label ?? key,\n fill: style.fill ?? \"\",\n legendColor: style.legendColor,\n })),\n [styles],\n );\n\n const bandOf = useCallback(\n (index: number): BandAtPoint | null => {\n const time = normalized.data[index]?.time;\n\n return sorted && typeof time === \"number\"\n ? bandAt(sorted, time, normalized.data, styles)\n : null;\n },\n [sorted, normalized, styles],\n );\n\n return { entries, bandOf: sorted ? bandOf : undefined };\n}\n","import {\n LineSeries,\n type SeriesType,\n type LineSeriesPartialOptions,\n} from \"lightweight-charts\";\n\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { normalizePoints } from \"../utils/data.utils.js\";\nimport { useEffect, useRef, type RefObject } from \"react\";\nimport { deepMerge, resetOptions } from \"../utils/merge.utils.js\";\nimport type { LineOverlay, OverlayEntry } from \"../types/series.js\";\n\nexport function useOverlays<T extends SeriesType>(\n instance: ChartInstance<T> | null,\n overlays: ReadonlyArray<LineOverlay> = [],\n): RefObject<OverlayEntry[]> {\n const entries = useRef<OverlayEntry[]>([]);\n\n useEffect(() => {\n entries.current = [];\n }, [instance]);\n\n useEffect(() => {\n if (!instance) return;\n\n const { chart } = instance;\n const list = entries.current;\n\n const create = (options: LineSeriesPartialOptions): OverlayEntry => {\n const series = chart.addSeries(LineSeries, options);\n\n return {\n series,\n defaults: deepMerge(series.options()),\n options,\n };\n };\n\n overlays.forEach((overlay, index) => {\n const next = overlay.seriesOptions ?? {};\n let entry = list[index];\n\n if (entry && entry.options !== next) {\n const options = resetOptions(entry.defaults, entry.options, next);\n\n if (options) {\n entry.series.applyOptions(options);\n entry.options = next;\n } else {\n chart.removeSeries(entry.series);\n entry = undefined;\n }\n }\n\n if (!entry) list[index] = entry = create(next);\n\n entry.series.setData(normalizePoints(overlay.data).data);\n });\n\n list\n .splice(overlays.length)\n .forEach((entry) => chart.removeSeries(entry.series));\n }, [instance, overlays]);\n\n return entries;\n}\n","import { toUnixSeconds } from \"./time.utils.js\";\nimport type { IRange } from \"lightweight-charts\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nconst MIN_VISIBLE_BARS = 2;\nconst ZOOM_SPEED = 0.002;\nexport const HALF_BAR = 0.5;\n\nexport function tickDirection<TPoint, TData>(\n previous: NormalizedSeries<TPoint, TData> | null,\n next: NormalizedSeries<TPoint, TData>,\n): \"up\" | \"down\" | null {\n if (!previous) return null;\n\n const before = previous.rows[previous.rows.length - 1];\n const after = next.rows[next.rows.length - 1];\n\n if (!before || !after) return null;\n\n const beforeTime = toUnixSeconds(before.time);\n const afterTime = toUnixSeconds(after.time);\n const secondLast = next.rows[next.rows.length - 2];\n\n const sameBar =\n next.rows.length === previous.rows.length && afterTime === beforeTime;\n const appended =\n next.rows.length === previous.rows.length + 1 &&\n secondLast !== undefined &&\n toUnixSeconds(secondLast.time) === beforeTime;\n\n if ((!sameBar && !appended) || after.close === before.close) return null;\n\n return after.close > before.close ? \"up\" : \"down\";\n}\n\nexport function flashColors(options: unknown): {\n up: string;\n down: string;\n} | null {\n if (options === null || typeof options !== \"object\") return null;\n\n const record = options as Record<string, unknown>;\n const up = record.upColor;\n const down = record.downColor;\n\n if (typeof up === \"string\" && typeof down === \"string\") return { up, down };\n\n const topLine = record.topLineColor;\n const bottomLine = record.bottomLineColor;\n\n if (typeof topLine === \"string\" && typeof bottomLine === \"string\")\n return { up: topLine, down: bottomLine };\n\n const color = record.color ?? record.lineColor;\n\n return typeof color === \"string\" ? { up: color, down: color } : null;\n}\n\nexport function zoomRange(\n range: IRange<number>,\n anchor: number,\n delta: number,\n): IRange<number> | null {\n const factor = Math.exp(delta * ZOOM_SPEED);\n\n if (!Number.isFinite(factor)) return null;\n\n const next = {\n from: anchor - (anchor - range.from) * factor,\n to: anchor + (range.to - anchor) * factor,\n };\n\n return next.to - next.from < MIN_VISIBLE_BARS ? null : next;\n}\n\nexport function wheelPixels(event: WheelEvent): number {\n const delta =\n Math.abs(event.deltaX) > Math.abs(event.deltaY)\n ? event.deltaX\n : event.deltaY;\n\n const scaled = event.deltaMode === 1 ? delta * 16 : delta;\n\n return Number.isFinite(scaled) ? scaled : 0;\n}\n\nexport function isLive(\n range: IRange<number> | null,\n lastIndex: number,\n): boolean {\n return range === null || lastIndex < 0 || range.to >= lastIndex - HALF_BAR;\n}\n","import { useEffect, type RefObject } from \"react\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { wheelPixels, zoomRange } from \"../utils/live.utils.js\";\n\nexport function useWheelZoom<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): void {\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element || !enabled) return;\n\n const { chart } = instance;\n const timeScale = chart.timeScale();\n\n const onWheel = (event: WheelEvent) => {\n const delta = wheelPixels(event);\n\n if (delta === 0) return;\n\n event.preventDefault();\n\n if (!event.ctrlKey) {\n const spacing = timeScale.options().barSpacing;\n timeScale.scrollToPosition(\n timeScale.scrollPosition() + delta / spacing,\n false,\n );\n return;\n }\n\n const rect = element.getBoundingClientRect();\n const x = event.clientX - rect.left - chart.priceScale(\"left\").width();\n const anchor = timeScale.coordinateToLogical(x);\n const range = timeScale.getVisibleLogicalRange();\n\n if (anchor === null || range === null) return;\n\n const next = zoomRange(range, anchor, delta);\n\n if (next) timeScale.setVisibleLogicalRange(next);\n };\n\n element.addEventListener(\"wheel\", onWheel, { passive: false });\n\n return () => element.removeEventListener(\"wheel\", onWheel);\n }, [instance, container, enabled]);\n}\n","export function nextBucketSize(\n current: number,\n pxPerRawBar: number,\n minBarWidth: number,\n rawCount: number,\n): number {\n if (!(pxPerRawBar > 0) || !Number.isFinite(pxPerRawBar)) return current;\n\n let next = current;\n\n if (!Number.isFinite(next) || next <= 0) return current;\n\n while (next < rawCount && pxPerRawBar * next < minBarWidth) next *= 2;\n while (next > 1 && pxPerRawBar * (next / 2) >= minBarWidth * 1.5) next /= 2;\n\n return next;\n}\n\nexport function buckets<T>(items: ReadonlyArray<T>, bucketSize: number): T[][] {\n if (!Number.isInteger(bucketSize) || bucketSize <= 0)\n throw new Error(\"bucketSize must be a positive integer\");\n\n const result: T[][] = [];\n\n for (let i = 0; i < items.length; i += bucketSize)\n result.push(items.slice(i, i + bucketSize));\n\n return result;\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { nextBucketSize } from \"../utils/bucket.utils.js\";\nimport type { AutoBucketOptions } from \"../types/chart.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nconst SETTLE_MS = 150;\nconst DEFAULT_MIN_BAR_WIDTH = 6;\n\nfunction minBarWidthOf(\n autoBucket: boolean | AutoBucketOptions | undefined,\n): number | null {\n if (!autoBucket) return null;\n if (autoBucket === true) return DEFAULT_MIN_BAR_WIDTH;\n\n return autoBucket.minBarWidth ?? DEFAULT_MIN_BAR_WIDTH;\n}\n\nexport function useAutoBucket<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n raw: NormalizedSeries<TPoint, TData>,\n autoBucket?: boolean | AutoBucketOptions,\n): number {\n const [bucketSize, setBucketSize] = useState(1);\n const minBarWidth = minBarWidthOf(autoBucket);\n const size = useRef(bucketSize);\n const rawCount = useRef(raw.points.length);\n size.current = bucketSize;\n rawCount.current = raw.points.length;\n\n useEffect(() => {\n if (!instance || minBarWidth === null) {\n setBucketSize(1);\n return;\n }\n\n const timeScale = instance.chart.timeScale();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let frame = 0;\n\n const measure = () => {\n const range = timeScale.getVisibleLogicalRange();\n const span = range ? range.to - range.from : 0;\n\n if (span <= 0) return;\n\n const pxPerRawBar = timeScale.width() / (span * size.current);\n setBucketSize(\n nextBucketSize(\n size.current,\n pxPerRawBar,\n minBarWidth,\n rawCount.current,\n ),\n );\n };\n const schedule = () => {\n clearTimeout(timer);\n cancelAnimationFrame(frame);\n timer = setTimeout(() => {\n frame = requestAnimationFrame(measure);\n }, SETTLE_MS);\n };\n\n timeScale.subscribeVisibleLogicalRangeChange(schedule);\n schedule();\n\n return () => {\n timeScale.unsubscribeVisibleLogicalRangeChange(schedule);\n clearTimeout(timer);\n cancelAnimationFrame(frame);\n };\n }, [instance, minBarWidth]);\n\n return bucketSize;\n}\n","import { useAutoBucket } from \"./useAutoBucket.js\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { SeriesChartProps } from \"../types/series.js\";\nimport type { AutoBucketOptions } from \"../types/chart.js\";\nimport type { SeriesType, SeriesDataItemTypeMap } from \"lightweight-charts\";\n\nexport function useSeriesData<\n TSeries extends SeriesType,\n TPoint,\n TData extends SeriesDataItemTypeMap[TSeries],\n>(\n instance: ChartInstance<TSeries> | null,\n data: ReadonlyArray<TPoint>,\n normalize: SeriesChartProps<TSeries, TPoint, TData>[\"normalize\"],\n aggregate: SeriesChartProps<TSeries, TPoint, TData>[\"aggregate\"],\n autoBucket: boolean | AutoBucketOptions | undefined,\n) {\n const raw = useMemo(() => normalize(data), [data, normalize]);\n const bucketSize = useAutoBucket(instance, raw, autoBucket);\n const normalized = useMemo(\n () =>\n bucketSize > 1 && aggregate\n ? normalize(aggregate(raw.points, bucketSize))\n : raw,\n [raw, bucketSize, normalize, aggregate],\n );\n const appliedBucket = useRef(bucketSize);\n\n useEffect(() => {\n if (!instance) return;\n\n const timeScale = instance.chart.timeScale();\n const ratio = appliedBucket.current / bucketSize;\n const keep = ratio !== 1 ? timeScale.getVisibleLogicalRange() : null;\n appliedBucket.current = bucketSize;\n\n instance.series.setData(normalized.data);\n if (keep)\n timeScale.setVisibleLogicalRange({\n from: (keep.from + 0.5) * ratio - 0.5,\n to: (keep.to + 0.5) * ratio - 0.5,\n });\n }, [instance, normalized, bucketSize]);\n\n return normalized;\n}\n","import type { ChartInstance } from \"../types/chart.js\";\nimport { HALF_BAR, isLive } from \"../utils/live.utils.js\";\nimport type { IRange, SeriesType } from \"lightweight-charts\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\n\nconst IDLE_MS = 3000;\nconst PAUSE_EVENTS = [\n \"pointermove\",\n \"pointerdown\",\n \"wheel\",\n \"keydown\",\n] as const;\n\nfunction sameRange(\n a: IRange<number> | null,\n b: IRange<number> | null,\n): boolean {\n if (a === null || b === null) return a === b;\n\n return (\n Math.abs(a.from - b.from) < HALF_BAR && Math.abs(a.to - b.to) < HALF_BAR\n );\n}\n\nexport function useLiveFollow<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n lastIndex: number,\n enabled: boolean,\n) {\n const [away, setAway] = useState(false);\n const lastIndexRef = useRef(lastIndex);\n lastIndexRef.current = lastIndex;\n\n useEffect(() => {\n if (!instance || !enabled) {\n setAway(false);\n return;\n }\n\n const timeScale = instance.chart.timeScale();\n const check = () =>\n setAway(!isLive(timeScale.getVisibleLogicalRange(), lastIndex));\n\n check();\n timeScale.subscribeVisibleLogicalRangeChange(check);\n\n return () => timeScale.unsubscribeVisibleLogicalRangeChange(check);\n }, [instance, enabled, lastIndex]);\n\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element || !enabled) return;\n\n const timeScale = instance.chart.timeScale();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let paused: {\n range: IRange<number> | null;\n wasLive: boolean;\n shift: boolean;\n } | null = null;\n\n const resume = () => {\n if (!paused) return;\n\n const { range, wasLive, shift } = paused;\n paused = null;\n timeScale.applyOptions({ shiftVisibleRangeOnNewBar: shift });\n\n if (\n wasLive &&\n shift &&\n sameRange(range, timeScale.getVisibleLogicalRange())\n )\n timeScale.scrollToRealTime();\n };\n\n const touch = () => {\n if (!paused) {\n const range = timeScale.getVisibleLogicalRange();\n paused = {\n range,\n wasLive: isLive(range, lastIndexRef.current),\n shift: timeScale.options().shiftVisibleRangeOnNewBar,\n };\n timeScale.applyOptions({ shiftVisibleRangeOnNewBar: false });\n }\n\n clearTimeout(timer);\n timer = setTimeout(resume, IDLE_MS);\n };\n\n PAUSE_EVENTS.forEach((type) =>\n element.addEventListener(type, touch, { passive: true }),\n );\n\n return () => {\n clearTimeout(timer);\n PAUSE_EVENTS.forEach((type) => element.removeEventListener(type, touch));\n if (paused)\n timeScale.applyOptions({ shiftVisibleRangeOnNewBar: paused.shift });\n };\n }, [instance, container, enabled]);\n\n return {\n away,\n jumpToLive: () => instance?.chart.timeScale().scrollToRealTime(),\n };\n}\n","import type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { useEffect, useRef, type RefObject } from \"react\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport { prefersReducedMotion } from \"../utils/motion.utils.js\";\nimport { flashColors, tickDirection } from \"../utils/live.utils.js\";\n\nconst FLASH_MS = 600;\nconst LABEL_PADDING = 8;\n\nexport function usePriceFlash<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n flash: RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): void {\n const previous = useRef<NormalizedSeries<TPoint, TData> | null>(null);\n\n useEffect(() => {\n const before = previous.current;\n previous.current = normalized;\n\n const element = flash.current;\n const direction = tickDirection(before, normalized);\n const last = normalized.rows[normalized.rows.length - 1];\n\n if (!instance || !element || !enabled || !direction || !last) return;\n if (typeof element.animate !== \"function\" || prefersReducedMotion()) return;\n\n const { chart, series } = instance;\n\n const frame = requestAnimationFrame(() => {\n const y = series.priceToCoordinate(last.close);\n const width = chart.priceScale(\"right\").width();\n const colors = flashColors(series.options());\n\n if (y === null || width === 0 || colors === null) return;\n\n const height = chart.options().layout.fontSize + LABEL_PADDING;\n\n element.style.width = `${width}px`;\n element.style.height = `${height}px`;\n element.style.transform = `translateY(${y - height / 2}px)`;\n element.style.background = direction === \"up\" ? colors.up : colors.down;\n element.animate([{ opacity: 0.9 }, { opacity: 0 }], {\n duration: FLASH_MS,\n easing: \"ease-out\",\n });\n });\n\n return () => cancelAnimationFrame(frame);\n }, [instance, normalized, flash, enabled]);\n}\n","import { useEffect } from \"react\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { SeriesType, CreatePriceLineOptions } from \"lightweight-charts\";\n\nconst NO_LINES: ReadonlyArray<CreatePriceLineOptions> = [];\n\nexport function usePriceLines<T extends SeriesType>(\n instance: ChartInstance<T> | null,\n lines: ReadonlyArray<CreatePriceLineOptions> = NO_LINES,\n): void {\n useEffect(() => {\n if (!instance) return;\n\n const { series } = instance;\n const created = lines.map((line) => series.createPriceLine(line));\n\n return () => created.forEach((line) => series.removePriceLine(line));\n }, [instance, lines]);\n}\n","import {\n themedLine,\n referenceLine,\n chartOptionsFromTheme,\n} from \"../utils/theme.utils.js\";\n\nimport type {\n DeepPartial,\n ChartOptions,\n LineSeriesPartialOptions,\n} from \"lightweight-charts\";\n\nimport { useMemo } from \"react\";\nimport type { Theme } from \"../types/theme.js\";\nimport { deepMerge } from \"../utils/merge.utils.js\";\nimport type { SeriesThemeInputs } from \"../types/series.js\";\n\nexport function useSeriesTheme(\n resolved: Theme | null,\n {\n magnet,\n magnetMode,\n ctrlWheelZoom,\n chartOptions,\n anchorLine,\n overlays,\n }: SeriesThemeInputs,\n) {\n const options = useMemo(\n () =>\n deepMerge<DeepPartial<ChartOptions>>(\n chartOptionsFromTheme(resolved),\n magnet && { crosshair: { mode: magnetMode } },\n ctrlWheelZoom && {\n handleScale: { mouseWheel: false },\n handleScroll: { mouseWheel: false },\n },\n chartOptions,\n ),\n [resolved, magnet, magnetMode, ctrlWheelZoom, chartOptions],\n );\n const themedAnchorLine = useMemo(\n () =>\n themedLine(\n referenceLine(resolved, resolved?.anchor, undefined),\n anchorLine,\n ),\n [resolved, anchorLine],\n );\n const themedOverlays = useMemo(() => {\n const colors = resolved?.line.overlays;\n\n return colors?.length && overlays\n ? overlays.map((overlay, i) => ({\n ...overlay,\n seriesOptions: deepMerge<LineSeriesPartialOptions>(\n { color: colors[i % colors.length] },\n overlay.seriesOptions,\n ),\n }))\n : overlays;\n }, [resolved, overlays]);\n\n return { options, themedAnchorLine, themedOverlays };\n}\n","import type { RangePreset } from \"../types/chart.js\";\n\nconst DAY = 86_400;\n\nfunction monthsBefore(seconds: number, months: number): number {\n const date = new Date(seconds * 1000);\n const target = new Date(\n Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - months + 1, 0),\n );\n\n target.setUTCDate(Math.min(date.getUTCDate(), target.getUTCDate()));\n target.setUTCHours(\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n );\n\n return target.getTime() / 1000;\n}\n\nfunction startOf(preset: RangePreset, last: number): number | null {\n switch (preset) {\n case \"1D\":\n return last - DAY;\n case \"1W\":\n return last - 7 * DAY;\n case \"1M\":\n return monthsBefore(last, 1);\n case \"3M\":\n return monthsBefore(last, 3);\n case \"1Y\":\n return monthsBefore(last, 12);\n case \"3Y\":\n return monthsBefore(last, 36);\n case \"5Y\":\n return monthsBefore(last, 60);\n case \"YTD\":\n return Date.UTC(new Date(last * 1000).getUTCFullYear(), 0, 1) / 1000;\n case \"All\":\n return null;\n }\n}\n\nexport function presetRange(\n first: number,\n last: number,\n preset: RangePreset,\n): { from: number; to: number } | null {\n const from = startOf(preset, last);\n\n if (from === null || from <= first) return null;\n\n return { from, to: last };\n}\n","import { useEffect, useRef } from \"react\";\nimport type { RangePreset } from \"../types/chart.js\";\nimport { presetRange } from \"../utils/range.utils.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { toUnixSeconds } from \"../utils/time.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { SeriesType, UTCTimestamp } from \"lightweight-charts\";\n\nexport function useRangePreset<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n range?: RangePreset,\n): void {\n const current = useRef(normalized);\n const hasData = normalized.data.length > 0;\n current.current = normalized;\n\n useEffect(() => {\n if (!instance || !range || !hasData) return;\n\n const rows = current.current.rows;\n const timeScale = instance.chart.timeScale();\n const first = rows[0];\n const last = rows[rows.length - 1];\n\n if (!first || !last) return;\n\n const from = toUnixSeconds(first.time);\n const to = toUnixSeconds(last.time);\n\n if (from === null || to === null) return;\n\n const target = presetRange(from, to, range);\n\n if (!target) {\n timeScale.fitContent();\n return;\n }\n\n timeScale.setVisibleRange({\n from: target.from as UTCTimestamp,\n to: target.to as UTCTimestamp,\n });\n }, [instance, range, hasData]);\n}\n","import type { SeriesRow } from \"../types/series.js\";\nimport type { VisibleStats } from \"../types/chart.js\";\n\nexport function percent(from: number, to: number): number | null {\n return from !== 0 ? ((to - from) / from) * 100 : null;\n}\n\nexport function highLow(rows: ReadonlyArray<{ high: number; low: number }>): {\n high: number;\n low: number;\n} {\n let { high, low } = rows[0]!;\n\n for (const row of rows) {\n if (row.high > high) high = row.high;\n if (row.low < low) low = row.low;\n }\n\n return { high, low };\n}\n\nexport function visibleStats(\n rows: ReadonlyArray<SeriesRow>,\n from: number,\n to: number,\n): VisibleStats | null {\n const start = Math.max(0, Math.ceil(from));\n const end = Math.min(rows.length - 1, Math.floor(to));\n const first = rows[start];\n const last = rows[end];\n\n if (start > end || !first || !last) return null;\n\n return {\n from: first.time,\n to: last.time,\n open: first.open,\n ...highLow(rows.slice(start, end + 1)),\n close: last.close,\n change: percent(first.open, last.close),\n bars: end - start + 1,\n };\n}\n","import type { ChartInstance } from \"../types/chart.js\";\nimport { visibleStats } from \"../utils/stats.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { Logical, SeriesType } from \"lightweight-charts\";\nimport type { RangeSelectOptions } from \"../types/interaction.js\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\n\nconst MIN_DRAG = 3;\n\nexport function useRangeSelect<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n rect: RefObject<HTMLDivElement | null>,\n normalized: NormalizedSeries<unknown, unknown>,\n options: RangeSelectOptions,\n): boolean {\n const [selecting, setSelecting] = useState(false);\n const latest = useRef({ normalized, options });\n latest.current = { normalized, options };\n\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element) return;\n\n const { chart } = instance;\n const timeScale = chart.timeScale();\n let start: number | null = null;\n let end = 0;\n\n const plotX = (event: MouseEvent) =>\n event.clientX -\n element.getBoundingClientRect().left -\n chart.priceScale(\"left\").width();\n\n const paint = () => {\n const box = rect.current;\n const left = Math.min(start ?? 0, end);\n\n if (!box) return;\n\n box.style.display = \"block\";\n box.style.left = `${left + chart.priceScale(\"left\").width()}px`;\n box.style.width = `${Math.abs(end - (start ?? 0))}px`;\n box.style.height = `${chart.paneSize().height}px`;\n };\n\n const stop = () => {\n start = null;\n setSelecting(false);\n window.removeEventListener(\"mousemove\", onMove);\n window.removeEventListener(\"mouseup\", onUp);\n window.removeEventListener(\"keydown\", onKey);\n };\n\n const onMove = (event: MouseEvent) => {\n end = plotX(event);\n paint();\n };\n\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") stop();\n };\n\n const onUp = (event: MouseEvent) => {\n const from = Math.min(start ?? 0, plotX(event));\n const to = Math.max(start ?? 0, plotX(event));\n\n stop();\n if (to - from < MIN_DRAG) return;\n\n const fromLogical = timeScale.coordinateToLogical(from);\n const toLogical = timeScale.coordinateToLogical(to);\n const stats =\n fromLogical === null || toLogical === null\n ? null\n : visibleStats(\n latest.current.normalized.rows,\n fromLogical,\n toLogical,\n );\n\n if (!stats || fromLogical === null || toLogical === null) return;\n\n timeScale.setVisibleLogicalRange({\n from: (fromLogical - 0.5) as Logical,\n to: (toLogical + 0.5) as Logical,\n });\n latest.current.options.onRangeSelect?.(stats);\n };\n\n const onDown = (event: MouseEvent) => {\n if (!latest.current.options.enabled || !event.shiftKey) return;\n if (event.button !== 0) return;\n\n event.preventDefault();\n event.stopPropagation();\n start = end = plotX(event);\n setSelecting(true);\n window.addEventListener(\"mousemove\", onMove);\n window.addEventListener(\"mouseup\", onUp);\n window.addEventListener(\"keydown\", onKey);\n };\n\n const onDoubleClick = () => {\n if (!latest.current.options.reset) return;\n\n timeScale.fitContent();\n latest.current.options.onReset?.();\n };\n\n element.addEventListener(\"mousedown\", onDown, true);\n element.addEventListener(\"dblclick\", onDoubleClick);\n\n return () => {\n stop();\n element.removeEventListener(\"mousedown\", onDown, true);\n element.removeEventListener(\"dblclick\", onDoubleClick);\n };\n }, [instance, container, rect]);\n\n return selecting;\n}\n","import { percent } from \"./stats.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { BandAtPoint } from \"../types/bands.js\";\nimport type { TooltipBox, SeriesSummary } from \"../types/interaction.js\";\n\nexport function toSeriesSummary<TPoint>(\n { points, rows }: NormalizedSeries<TPoint, unknown>,\n index: number,\n anchorIndex: number | null,\n bandOf?: (index: number) => BandAtPoint | null,\n): SeriesSummary<TPoint> | null {\n const point = points[index];\n const row = rows[index];\n\n if (point === undefined || !row) return null;\n\n const previous = rows[index - 1];\n const anchor = anchorIndex === null ? undefined : rows[anchorIndex];\n const band = bandOf?.(index);\n\n return {\n point,\n index,\n change: previous ? percent(previous.close, row.close) : null,\n fromAnchor:\n anchor && anchorIndex !== null\n ? {\n change: percent(anchor.close, row.close),\n bars: index - anchorIndex,\n }\n : null,\n ...(band && { band }),\n };\n}\n\nexport function tooltipTransform({\n x,\n y,\n gap,\n offset,\n width,\n height,\n}: TooltipBox): string {\n const flipX = x > width / 2;\n const left = offset + x + (flipX ? -gap : gap);\n\n return `translate(calc(${left}px - ${flipX ? 100 : 0}%), calc(${y}px - ${y > height / 2 ? 100 : 0}%))`;\n}\n","import { useEffect, useMemo } from \"react\";\nimport type { Time } from \"../types/chart.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { toUnixSeconds } from \"../utils/time.utils.js\";\nimport { indexAtOrBefore } from \"../utils/data.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { SeriesType, PriceLineOptions } from \"lightweight-charts\";\n\nconst DEFAULT_LINE: Partial<PriceLineOptions> = { title: \"Anchor\" };\n\nexport function useAnchor<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n anchor?: Time | null,\n line: Partial<PriceLineOptions> | false = DEFAULT_LINE,\n): number | null {\n const time = anchor == null ? null : toUnixSeconds(anchor);\n const index = useMemo(\n () => (time === null ? null : indexAtOrBefore(normalized.rows, time)),\n [normalized, time],\n );\n const price = index === null ? null : (normalized.rows[index]?.close ?? null);\n\n useEffect(() => {\n if (!instance || price === null || line === false) return;\n\n const { series } = instance;\n const created = series.createPriceLine({\n ...DEFAULT_LINE,\n ...line,\n price,\n });\n\n return () => series.removePriceLine(created);\n }, [instance, price, line]);\n\n return index;\n}\n","import type {\n SeriesPointEvent,\n PointEventHandlers,\n} from \"../types/interaction.js\";\n\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport { useRef, useState, useEffect, useCallback } from \"react\";\nimport type { Time, SeriesType, MouseEventParams } from \"lightweight-charts\";\n\nexport function useChartEvents<TSeries extends SeriesType, TPoint>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<unknown, { time: Time }>,\n handlers: PointEventHandlers<TPoint>,\n build: (\n index: number,\n coordinate: { x: number; y: number },\n price: number | null,\n ) => SeriesPointEvent<TPoint> | null,\n track: boolean,\n onSelect?: (index: number) => void,\n) {\n const handlersRef = useRef(handlers);\n const selectRef = useRef(onSelect);\n const hovered = useRef<number | null>(null);\n const stale = useRef(false);\n const [active, setActive] = useState<number | null>(null);\n\n useEffect(() => {\n handlersRef.current = handlers;\n selectRef.current = onSelect;\n });\n\n const activate = useCallback(\n (index: number | null, event: SeriesPointEvent<TPoint> | null = null) => {\n if (index === hovered.current && (index === null || !stale.current))\n return;\n hovered.current = index;\n stale.current = false;\n if (track) setActive(index);\n if (index === null) handlersRef.current.onPointLeave?.();\n else if (event) handlersRef.current.onPointHover?.(event);\n },\n [track],\n );\n\n const select = useCallback((event: SeriesPointEvent<TPoint> | null) => {\n if (!event) return;\n handlersRef.current.onPointClick?.(event);\n selectRef.current?.(event.index);\n }, []);\n\n const eventAt = useCallback(\n (index: number): SeriesPointEvent<TPoint> | null => {\n const bar = normalized.data[index];\n const row = normalized.rows[index];\n\n if (!instance || !bar || !row) return null;\n\n const x = instance.chart.timeScale().timeToCoordinate(bar.time);\n const y = instance.series.priceToCoordinate(row.close);\n\n return x === null || y === null\n ? null\n : build(index, { x, y }, row.close);\n },\n [instance, normalized, build],\n );\n\n useEffect(() => {\n if (!instance) return;\n const { chart, series } = instance;\n stale.current = true;\n\n const fromParam = (\n param: MouseEventParams,\n ): SeriesPointEvent<TPoint> | null => {\n if (typeof param.time !== \"number\" || !param.point) return null;\n\n const index = normalized.indexByTime.get(param.time);\n\n return index === undefined\n ? null\n : build(\n index,\n { x: param.point.x, y: param.point.y },\n series.coordinateToPrice(param.point.y),\n );\n };\n\n const onMove = (param: MouseEventParams) => {\n const event = fromParam(param);\n activate(event ? event.index : null, event);\n };\n\n const onClick = (param: MouseEventParams) => select(fromParam(param));\n\n chart.subscribeCrosshairMove(onMove);\n chart.subscribeClick(onClick);\n\n return () => {\n chart.unsubscribeCrosshairMove(onMove);\n chart.unsubscribeClick(onClick);\n };\n }, [instance, normalized, build, activate, select]);\n\n return { active, hovered, activate, select, eventAt };\n}\n","import { HALF_BAR } from \"../utils/live.utils.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { useRef, useEffect, type RefObject } from \"react\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { Time, SeriesType } from \"lightweight-charts\";\nimport type { KeyboardActions } from \"../types/interaction.js\";\n\nexport function useKeyboardNav<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n normalized: NormalizedSeries<unknown, { time: Time }>,\n enabled: boolean,\n actions: KeyboardActions,\n): void {\n const actionsRef = useRef(actions);\n\n useEffect(() => {\n actionsRef.current = actions;\n });\n\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element || !enabled) return;\n\n const { chart, series } = instance;\n const last = normalized.data.length - 1;\n let driving = false;\n\n const reveal = (index: number) => {\n const timeScale = chart.timeScale();\n const range = timeScale.getVisibleLogicalRange();\n\n if (!range) return;\n\n const shift =\n index - HALF_BAR < range.from\n ? index - HALF_BAR - range.from\n : index + HALF_BAR > range.to\n ? index + HALF_BAR - range.to\n : 0;\n\n if (shift !== 0)\n timeScale.setVisibleLogicalRange({\n from: range.from + shift,\n to: range.to + shift,\n });\n };\n\n const goTo = (index: number) => {\n const bar = normalized.data[index];\n const row = normalized.rows[index];\n\n if (!bar || !row) return;\n\n driving = true;\n reveal(index);\n chart.setCrosshairPosition(row.close, bar.time, series);\n actionsRef.current.move(index);\n };\n\n const release = () => {\n driving = false;\n chart.clearCrosshairPosition();\n actionsRef.current.move(null);\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.altKey || event.ctrlKey || event.metaKey || last < 0) return;\n\n const current = actionsRef.current.current();\n const step = (delta: number) =>\n current === null ? last : Math.min(last, Math.max(0, current + delta));\n\n switch (event.key) {\n case \"ArrowLeft\":\n goTo(step(-1));\n break;\n case \"ArrowRight\":\n goTo(step(1));\n break;\n case \"Home\":\n goTo(0);\n break;\n case \"End\":\n goTo(last);\n break;\n case \"Enter\":\n case \" \":\n if (current === null) return;\n actionsRef.current.select(current);\n break;\n case \"Escape\":\n release();\n actionsRef.current.clear();\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const onBlur = () => {\n if (driving) release();\n };\n\n const onPointerMove = () => {\n driving = false;\n };\n\n element.addEventListener(\"keydown\", onKeyDown);\n element.addEventListener(\"blur\", onBlur);\n element.addEventListener(\"pointermove\", onPointerMove);\n\n return () => {\n element.removeEventListener(\"keydown\", onKeyDown);\n element.removeEventListener(\"blur\", onBlur);\n element.removeEventListener(\"pointermove\", onPointerMove);\n };\n }, [instance, container, normalized, enabled]);\n}\n","import type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { useEffect, useCallback, type RefObject } from \"react\";\nimport type { Time, MouseEventParams } from \"lightweight-charts\";\n\nexport function useCrosshairBand<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n band: RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): (time: Time | null) => void {\n const place = useCallback(\n (time: Time | null) => {\n const element = band.current;\n\n if (!instance || !element || !enabled) return;\n\n const { chart } = instance;\n const x = time === null ? null : chart.timeScale().timeToCoordinate(time);\n\n if (x === null) {\n element.style.display = \"none\";\n return;\n }\n\n const width = Math.max(1, chart.timeScale().options().barSpacing);\n const left = chart.priceScale(\"left\").width() + x - width / 2;\n\n element.style.display = \"block\";\n element.style.width = `${width}px`;\n element.style.height = `${chart.paneSize().height}px`;\n element.style.transform = `translateX(${left}px)`;\n element.style.background = chart.options().crosshair.vertLine.color;\n },\n [instance, band, enabled],\n );\n\n useEffect(() => {\n if (!instance || !enabled) return;\n\n const { chart } = instance;\n const onMove = (param: MouseEventParams) =>\n place(param.time === undefined || !param.point ? null : param.time);\n\n chart.subscribeCrosshairMove(onMove);\n\n return () => {\n chart.unsubscribeCrosshairMove(onMove);\n place(null);\n };\n }, [instance, enabled, place]);\n\n return place;\n}\n","import type {\n Interactions,\n SeriesPointEvent,\n InteractionOptions,\n} from \"../types/interaction.js\";\n\nimport {\n tooltipTransform,\n toSeriesSummary,\n} from \"../utils/interaction.utils.js\";\n\nimport { useAnchor } from \"./useAnchor.js\";\nimport { useChartEvents } from \"./useChartEvents.js\";\nimport { useKeyboardNav } from \"./useKeyboardNav.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { indexAtOrBefore } from \"../utils/data.utils.js\";\nimport { useCrosshairBand } from \"./useCrosshairBand.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { Time, SeriesType } from \"lightweight-charts\";\nimport { useMemo, useState, useCallback, type RefObject } from \"react\";\n\nconst KEYS = \"ArrowLeft ArrowRight Home End Enter Escape Space\";\nconst TOOLTIP_GAP = 8;\n\nfunction tooltipAt<TSeries extends SeriesType>(\n { chart, series }: ChartInstance<TSeries>,\n normalized: NormalizedSeries<unknown, { time: Time }>,\n index: number,\n): string | null {\n const bar = normalized.data[index];\n const row = normalized.rows[index];\n\n if (!bar || !row) return null;\n\n const timeScale = chart.timeScale();\n const x = timeScale.timeToCoordinate(bar.time);\n const y = series.priceToCoordinate(row.high);\n\n if (x === null || y === null) return null;\n\n return tooltipTransform({\n x,\n y,\n gap: timeScale.options().barSpacing / 2 + TOOLTIP_GAP,\n offset: chart.priceScale(\"left\").width(),\n ...chart.paneSize(),\n });\n}\n\nexport function useInteractions<TSeries extends SeriesType, TPoint>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n band: RefObject<HTMLDivElement | null>,\n normalized: NormalizedSeries<TPoint, { time: Time }>,\n options: InteractionOptions<TPoint>,\n): Interactions<TPoint> {\n const { anchor, anchorLine, magnet, pinOnClick, keyboard } = options;\n const { legend, tooltip, handlers, bandOf } = options;\n const [pinned, setPinned] = useState<number | null>(null);\n const pinnedTime = pinOnClick ? pinned : null;\n const pinnedIndex = useMemo(\n () =>\n pinnedTime === null ? null : indexAtOrBefore(normalized.data, pinnedTime),\n [normalized, pinnedTime],\n );\n const anchorIndex = useAnchor(\n instance,\n normalized,\n anchor !== undefined ? anchor : pinnedTime,\n anchorLine,\n );\n\n const build = useCallback(\n (\n index: number,\n coordinate: { x: number; y: number },\n price: number | null,\n ): SeriesPointEvent<TPoint> | null => {\n const summary = toSeriesSummary(normalized, index, anchorIndex, bandOf);\n return summary && { ...summary, price, coordinate };\n },\n [normalized, anchorIndex, bandOf],\n );\n\n const events = useChartEvents(\n instance,\n normalized,\n handlers,\n build,\n legend || tooltip,\n pinOnClick\n ? (index) =>\n setPinned(\n index === pinnedIndex\n ? null\n : ((normalized.data[index]?.time as number | undefined) ?? null),\n )\n : undefined,\n );\n const placeBand = useCrosshairBand(instance, band, magnet);\n\n useKeyboardNav(instance, container, normalized, keyboard, {\n current: () => events.hovered.current ?? pinnedIndex,\n move: (index) => {\n placeBand(index === null ? null : (normalized.data[index]?.time ?? null));\n events.activate(index, index === null ? null : events.eventAt(index));\n },\n select: (index) => events.select(events.eventAt(index)),\n clear: () => setPinned(null),\n });\n\n const { active } = events;\n const legendSummary = legend\n ? toSeriesSummary(\n normalized,\n active ?? pinnedIndex ?? normalized.data.length - 1,\n anchorIndex,\n bandOf,\n )\n : null;\n const tipSummary =\n tooltip && active !== null\n ? toSeriesSummary(normalized, active, anchorIndex, bandOf)\n : null;\n const transform =\n tipSummary !== null && instance && active !== null\n ? tooltipAt(instance, normalized, active)\n : null;\n\n return {\n container: keyboard\n ? { role: \"application\", tabIndex: 0, \"aria-keyshortcuts\": KEYS }\n : { role: \"img\" },\n legend:\n legendSummary === null\n ? null\n : {\n summary: legendSummary,\n source:\n active !== null\n ? \"hover\"\n : pinnedIndex !== null\n ? \"pinned\"\n : \"last\",\n },\n tooltip:\n tipSummary === null || transform === null\n ? null\n : { summary: tipSummary, transform },\n };\n}\n","import { useEffect, useRef } from \"react\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { VisibleStats } from \"../types/chart.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { visibleStats } from \"../utils/stats.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nexport function useVisibleStats<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n onChange?: (stats: VisibleStats | null) => void,\n): void {\n const handler = useRef(onChange);\n const enabled = onChange !== undefined;\n handler.current = onChange;\n\n useEffect(() => {\n if (!instance || !enabled) return;\n\n const timeScale = instance.chart.timeScale();\n let frame = 0;\n\n const emit = () => {\n frame = 0;\n const range = timeScale.getVisibleLogicalRange();\n handler.current?.(\n range ? visibleStats(normalized.rows, range.from, range.to) : null,\n );\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(emit);\n };\n\n timeScale.subscribeVisibleLogicalRangeChange(schedule);\n schedule();\n\n return () => {\n timeScale.unsubscribeVisibleLogicalRangeChange(schedule);\n cancelAnimationFrame(frame);\n };\n }, [instance, normalized, enabled]);\n}\n","import {\n BAND_MARK,\n BAND_LEGEND,\n BAND_LEGEND_ITEM,\n} from \"../../styles/seriesChart.js\";\n\nimport { textStyle } from \"../../utils/theme.utils.js\";\nimport type { BandLegendProps } from \"../../types/bands.js\";\n\nexport function BandLegend({\n entries,\n render,\n theme,\n className,\n style,\n}: BandLegendProps) {\n if (render === null || entries.length === 0) return null;\n if (render) return <>{render([...entries])}</>;\n\n const border = theme ? `1px solid ${theme.palette.border}` : \"1px solid\";\n\n return (\n <ul\n data-part=\"band-legend\"\n className={className}\n style={{\n ...BAND_LEGEND,\n ...textStyle(theme?.typography.label),\n ...style,\n }}\n >\n {entries.map(({ key, label, fill, legendColor }) => (\n <li key={key} data-part=\"band-legend-item\" style={BAND_LEGEND_ITEM}>\n <span\n aria-hidden=\"true\"\n style={{\n ...BAND_MARK,\n background: legendColor ?? fill,\n border: legendColor ? \"none\" : border,\n }}\n />\n {label}\n </li>\n ))}\n </ul>\n );\n}\n","import type { CSSProperties } from \"react\";\nimport { TOOLTIP } from \"../../styles/shared.js\";\nimport type { InteractionSlotsProps } from \"../../types/interaction.js\";\n\nconst LEGEND: CSSProperties = {\n position: \"absolute\",\n inset: 0,\n pointerEvents: \"none\",\n};\n\nexport function InteractionSlots<TPoint>({\n interactions: { legend, tooltip },\n renderLegend,\n renderTooltip,\n}: InteractionSlotsProps<TPoint>) {\n return (\n <>\n {legend && renderLegend && (\n <div style={LEGEND} aria-live=\"polite\" aria-atomic=\"true\">\n {renderLegend(legend)}\n </div>\n )}\n {tooltip && renderTooltip && (\n <div\n style={{ ...TOOLTIP, transform: tooltip.transform }}\n aria-live={renderLegend ? undefined : \"polite\"}\n aria-atomic={renderLegend ? undefined : true}\n aria-hidden={renderLegend ? true : undefined}\n >\n {renderTooltip(tooltip.summary)}\n </div>\n )}\n </>\n );\n}\n","import {\n useRef,\n forwardRef,\n type ForwardedRef,\n type ReactElement,\n useImperativeHandle,\n} from \"react\";\n\nimport {\n CrosshairMode,\n type SeriesType,\n type SeriesDataItemTypeMap,\n} from \"lightweight-charts\";\n\nimport type {\n SeriesChartProps,\n SeriesChartHandle,\n} from \"../../types/series.js\";\n\nimport {\n BAND,\n FILL,\n PILL,\n FLASH,\n WRAPPER,\n RANGE_SELECT,\n PILL_POSITION,\n} from \"../../styles/seriesChart.js\";\n\nimport { useChart } from \"../../hooks/useChart.js\";\nimport { useBands } from \"../../hooks/useBands.js\";\nimport { withAlpha } from \"../../utils/theme.utils.js\";\nimport { useOverlays } from \"../../hooks/useOverlays.js\";\nimport { useWheelZoom } from \"../../hooks/useWheelZoom.js\";\nimport { useSeriesData } from \"../../hooks/useSeriesData.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { useLiveFollow } from \"../../hooks/useLiveFollow.js\";\nimport { usePriceFlash } from \"../../hooks/usePriceFlash.js\";\nimport { usePriceLines } from \"../../hooks/usePriceLines.js\";\nimport { useSeriesTheme } from \"../../hooks/useSeriesTheme.js\";\nimport { useRangePreset } from \"../../hooks/useRangePreset.js\";\nimport { useRangeSelect } from \"../../hooks/useRangeSelect.js\";\nimport { useInteractions } from \"../../hooks/useInteractions.js\";\nimport { useVisibleStats } from \"../../hooks/useVisibleStats.js\";\nimport { BandLegend } from \"../../components/BandLegend/index.js\";\nimport { InteractionSlots } from \"../../components/InteractionSlots/index.js\";\n\nfunction SeriesChartInner<\n TSeries extends SeriesType,\n TPoint,\n TData extends SeriesDataItemTypeMap[TSeries],\n>(\n {\n data,\n definition,\n normalize,\n aggregate,\n magnetMode = CrosshairMode.MagnetOHLC,\n chartOptions,\n seriesOptions,\n className,\n ariaLabel = \"Chart\",\n liveButtonClassName,\n liveButtonLabel = \"Jump to live\",\n magnet = true,\n flashLastPrice = true,\n followLive = true,\n ctrlWheelZoom = true,\n renderLegend,\n renderTooltip,\n pinOnClick = false,\n keyboard = false,\n range,\n anchor,\n anchorLine,\n autoBucket,\n onVisibleStatsChange,\n onPointClick,\n onPointHover,\n onPointLeave,\n overlays,\n priceLines,\n bands,\n bandStyles,\n renderBandLegend,\n classNames = {},\n styles = {},\n rangeSelect = true,\n doubleClickReset = true,\n onRangeSelect,\n onReset,\n theme,\n unstyled,\n }: SeriesChartProps<TSeries, TPoint, TData>,\n ref: ForwardedRef<SeriesChartHandle<TSeries> | null>,\n): ReactElement {\n const container = useRef<HTMLDivElement>(null);\n const band = useRef<HTMLDivElement>(null);\n const flash = useRef<HTMLDivElement>(null);\n const selection = useRef<HTMLDivElement>(null);\n const resolved = useChartTheme({ theme, unstyled });\n const { options, themedAnchorLine, themedOverlays } = useSeriesTheme(\n resolved,\n { magnet, magnetMode, ctrlWheelZoom, chartOptions, anchorLine, overlays },\n );\n const instance = useChart(container, definition, options, seriesOptions);\n const normalized = useSeriesData(\n instance,\n data,\n normalize,\n aggregate,\n autoBucket,\n );\n\n const overlaySeries = useOverlays(instance, themedOverlays);\n const { entries, bandOf } = useBands(\n instance,\n normalized,\n bands,\n bandStyles,\n resolved,\n );\n usePriceLines(instance, priceLines);\n useRangePreset(instance, normalized, range);\n useVisibleStats(instance, normalized, onVisibleStatsChange);\n\n const interactions = useInteractions(instance, container, band, normalized, {\n anchor,\n anchorLine: themedAnchorLine,\n magnet,\n pinOnClick,\n keyboard,\n legend: renderLegend !== undefined,\n tooltip: renderTooltip !== undefined,\n handlers: { onPointClick, onPointHover, onPointLeave },\n bandOf,\n });\n usePriceFlash(instance, normalized, flash, flashLastPrice);\n const selecting = useRangeSelect(instance, container, selection, normalized, {\n enabled: rangeSelect,\n reset: doubleClickReset,\n onRangeSelect,\n onReset,\n });\n useWheelZoom(instance, container, ctrlWheelZoom);\n\n const { away, jumpToLive } = useLiveFollow(\n instance,\n container,\n normalized.rows.length - 1,\n followLive,\n );\n\n useImperativeHandle<\n SeriesChartHandle<TSeries> | null,\n SeriesChartHandle<TSeries> | null\n >(\n ref,\n () =>\n instance\n ? {\n chart: instance.chart,\n series: instance.series,\n get overlays() {\n return overlaySeries.current.map((entry) => entry.series);\n },\n }\n : null,\n [instance, overlaySeries],\n );\n\n return (\n <div className={className} style={WRAPPER}>\n <div\n ref={container}\n style={FILL}\n aria-label={ariaLabel}\n {...interactions.container}\n />\n <div ref={band} style={BAND} aria-hidden=\"true\" />\n <BandLegend\n entries={entries}\n render={renderBandLegend}\n theme={resolved}\n className={classNames.bandLegend}\n style={styles.bandLegend}\n />\n <InteractionSlots\n interactions={interactions}\n renderLegend={renderLegend}\n renderTooltip={renderTooltip}\n />\n <div ref={flash} style={FLASH} aria-hidden=\"true\" />\n {selecting && (\n <div\n ref={selection}\n data-part=\"range-select\"\n className={classNames.rangeSelect}\n style={{\n ...RANGE_SELECT,\n background: withAlpha(resolved?.palette.crosshair, 0.1),\n ...styles.rangeSelect,\n }}\n aria-hidden=\"true\"\n />\n )}\n {away && (\n <button\n type=\"button\"\n className={liveButtonClassName}\n style={liveButtonClassName || unstyled ? PILL_POSITION : PILL}\n onClick={jumpToLive}\n >\n {liveButtonLabel}\n </button>\n )}\n </div>\n );\n}\n\nexport const SeriesChart = forwardRef(SeriesChartInner) as <\n TSeries extends SeriesType,\n TPoint,\n TData extends SeriesDataItemTypeMap[TSeries],\n>(\n props: SeriesChartProps<TSeries, TPoint, TData> & {\n ref?: ForwardedRef<SeriesChartHandle<TSeries> | null>;\n },\n) => ReactElement;\n","import type {\n LineData,\n AutoscaleInfo,\n PriceLineOptions,\n AutoscaleInfoProvider,\n CreatePriceLineOptions,\n HistogramSeriesPartialOptions,\n} from \"lightweight-charts\";\n\nimport { deepMerge } from \"./merge.utils.js\";\nimport type { HistogramMode, HistogramColors } from \"../types/series.js\";\n\nfunction barColor(\n value: number,\n mode: HistogramMode,\n threshold: number | undefined,\n colors: HistogramColors,\n): string | undefined {\n if (mode === \"diverging\")\n return value < 0 ? colors.negative : colors.positive;\n\n if (mode === \"threshold\" && threshold !== undefined && value > threshold)\n return colors.over;\n\n return colors.bar;\n}\n\nexport function colorBars(\n data: ReadonlyArray<LineData>,\n mode: HistogramMode,\n threshold: number | undefined,\n colors: HistogramColors,\n): LineData[] {\n return data.map((bar) => {\n if (bar.color !== undefined) return bar;\n\n const color = barColor(bar.value, mode, threshold, colors);\n\n return color === undefined ? bar : { ...bar, color };\n });\n}\n\nexport const ownAutoscale: AutoscaleInfoProvider = (original) => original();\n\nexport const symmetricAutoscale: AutoscaleInfoProvider = (original) => {\n const info: AutoscaleInfo | null = original();\n\n if (!info?.priceRange) return info;\n\n const { minValue, maxValue } = info.priceRange;\n const extent = Math.max(Math.abs(minValue), Math.abs(maxValue));\n\n return { ...info, priceRange: { minValue: -extent, maxValue: extent } };\n};\n\nexport function histogramOptions(\n mode: HistogramMode,\n seriesOptions: HistogramSeriesPartialOptions | undefined,\n): HistogramSeriesPartialOptions {\n return deepMerge<HistogramSeriesPartialOptions>(\n {\n autoscaleInfoProvider:\n mode === \"diverging\" ? symmetricAutoscale : ownAutoscale,\n },\n seriesOptions,\n );\n}\n\nexport function histogramPriceLines(\n mode: HistogramMode,\n threshold: number | undefined,\n thresholdLine: Partial<PriceLineOptions> | false,\n zeroLine: Partial<PriceLineOptions> | false,\n): CreatePriceLineOptions[] {\n const lines: CreatePriceLineOptions[] = [];\n\n if (\n mode === \"threshold\" &&\n threshold !== undefined &&\n thresholdLine !== false\n )\n lines.push({ ...thresholdLine, price: threshold });\n\n if (mode === \"diverging\" && zeroLine !== false)\n lines.push({ axisLabelVisible: false, ...zeroLine, price: 0 });\n\n return lines;\n}\n","import { buckets } from \"./bucket.utils.js\";\nimport type { LineData } from \"lightweight-charts\";\nimport type { LinePoint } from \"../types/chart.js\";\nimport type { OHLC } from \"../types/candlestick.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nexport function aggregatePoints(\n points: ReadonlyArray<LinePoint>,\n bucketSize: number,\n): LinePoint[] {\n return buckets(points, bucketSize).map((slice) => ({\n ...slice[slice.length - 1]!,\n time: slice[0]!.time,\n }));\n}\n\nexport function toLinePoints(candles: ReadonlyArray<OHLC>): LinePoint[] {\n return candles.map((candle) => ({\n time: candle.time,\n value: candle.close,\n ...(candle.color !== undefined && { color: candle.color }),\n }));\n}\n\nexport function stylePoints(\n normalized: NormalizedSeries<LinePoint, LineData>,\n colorKeys: ReadonlyArray<string>,\n styleKeys: ReadonlyArray<string>,\n): LineData[] {\n return normalized.data.map(({ color, ...rest }, index) => {\n const source: Partial<Record<string, unknown>> = {\n ...normalized.points[index],\n };\n const styled: LineData & Record<string, unknown> = { ...rest };\n\n if (color !== undefined) colorKeys.forEach((key) => (styled[key] = color));\n styleKeys.forEach((key) => {\n if (typeof source[key] === \"string\") styled[key] = source[key];\n });\n\n return styled;\n });\n}\n","import type { LinePoint } from \"../../types/chart.js\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { useCallback, forwardRef, useMemo } from \"react\";\nimport { colorBars } from \"../../utils/histogram.utils.js\";\nimport { aggregatePoints } from \"../../utils/line.utils.js\";\nimport { normalizePoints } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { CrosshairMode, HistogramSeries } from \"lightweight-charts\";\nimport type { BarChartProps, BarChartHandle } from \"../../types/series.js\";\n\nexport const BarChart = forwardRef<BarChartHandle | null, BarChartProps>(\n function BarChart({ seriesOptions, ariaLabel = \"Bar chart\", ...props }, ref) {\n const theme = useChartTheme(props);\n const { upColor, downColor, options } = useMemo(() => {\n const {\n upColor = theme?.palette.up,\n downColor = theme?.palette.down,\n ...options\n } = seriesOptions ?? {};\n return { upColor, downColor, options };\n }, [theme, seriesOptions]);\n const { base = 0, color } = options;\n\n const normalize = useCallback(\n (data: ReadonlyArray<LinePoint>) => {\n const normalized = normalizePoints(data);\n\n return color !== undefined || !upColor || !downColor\n ? normalized\n : {\n ...normalized,\n data: colorBars(normalized.data, \"threshold\", base, {\n over: upColor,\n bar: downColor,\n }),\n };\n },\n [base, upColor, downColor, color],\n );\n\n return (\n <SeriesChart\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n definition={HistogramSeries}\n normalize={normalize}\n aggregate={aggregatePoints}\n magnetMode={CrosshairMode.Magnet}\n />\n );\n },\n);\n","import {\n LineSeries,\n AreaSeries,\n CrosshairMode,\n BaselineSeries,\n} from \"lightweight-charts\";\n\nimport type {\n LineVariant,\n LineChartProps,\n LineChartHandle,\n LineVariantConfig,\n} from \"../../types/series.js\";\n\nimport type { LinePoint } from \"../../types/chart.js\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { forwardRef, useCallback, useMemo } from \"react\";\nimport { normalizePoints } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { lineOptionsFromTheme } from \"../../utils/theme.utils.js\";\nimport { aggregatePoints, stylePoints } from \"../../utils/line.utils.js\";\n\nconst VARIANTS: Record<LineVariant, LineVariantConfig> = {\n line: {\n definition: LineSeries,\n label: \"Line chart\",\n colorKeys: [\"color\"],\n styleKeys: [],\n },\n area: {\n definition: AreaSeries,\n label: \"Area chart\",\n colorKeys: [\"lineColor\"],\n styleKeys: [\"lineColor\", \"topColor\", \"bottomColor\"],\n },\n baseline: {\n definition: BaselineSeries,\n label: \"Baseline chart\",\n colorKeys: [\"topLineColor\", \"bottomLineColor\"],\n styleKeys: [\n \"topLineColor\",\n \"topFillColor1\",\n \"topFillColor2\",\n \"bottomLineColor\",\n \"bottomFillColor1\",\n \"bottomFillColor2\",\n ],\n },\n};\n\nexport const LineChart = forwardRef<\n LineChartHandle<LineVariant> | null,\n LineChartProps\n>(function LineChart(\n {\n variant = \"line\",\n seriesOptions,\n baseValue,\n ariaLabel = VARIANTS[variant].label,\n ...props\n },\n ref,\n) {\n const theme = useChartTheme(props);\n const options = useMemo(\n () =>\n deepMerge<NonNullable<typeof seriesOptions>>(\n lineOptionsFromTheme(theme, variant),\n baseValue !== undefined && {\n baseValue: { type: \"price\", price: baseValue },\n },\n seriesOptions,\n ),\n [theme, variant, baseValue, seriesOptions],\n );\n\n const normalize = useCallback(\n (data: ReadonlyArray<LinePoint>) => {\n const normalized = normalizePoints(data);\n const { colorKeys, styleKeys } = VARIANTS[variant];\n\n return {\n ...normalized,\n data: stylePoints(normalized, colorKeys, styleKeys),\n };\n },\n [variant],\n );\n\n return (\n <SeriesChart\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n definition={VARIANTS[variant].definition}\n magnetMode={CrosshairMode.Magnet}\n normalize={normalize}\n aggregate={aggregatePoints}\n />\n );\n});\n","import { highLow } from \"./stats.utils.js\";\nimport { buckets } from \"./bucket.utils.js\";\nimport type { OHLC } from \"../types/candlestick.js\";\n\nexport function isUp(candle: OHLC): boolean {\n return candle.close >= candle.open;\n}\n\nexport function aggregate(\n candles: ReadonlyArray<OHLC>,\n bucketSize: number,\n): OHLC[] {\n return buckets(candles, bucketSize).map((slice) => ({\n time: slice[0]!.time,\n open: slice[0]!.open,\n ...highLow(slice),\n close: slice[slice.length - 1]!.close,\n }));\n}\n","import {\n colorBars,\n histogramOptions,\n histogramPriceLines,\n} from \"../../utils/histogram.utils.js\";\n\nimport type {\n HistogramColors,\n HistogramChartProps,\n HistogramChartHandle,\n} from \"../../types/series.js\";\n\nimport {\n themedLine,\n referenceLine,\n histogramColorsFromTheme,\n} from \"../../utils/theme.utils.js\";\n\nimport type { LinePoint } from \"../../types/chart.js\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { forwardRef, useCallback, useMemo } from \"react\";\nimport { aggregatePoints } from \"../../utils/line.utils.js\";\nimport { normalizePoints } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { CrosshairMode, HistogramSeries } from \"lightweight-charts\";\n\nexport const HistogramChart = forwardRef<\n HistogramChartHandle | null,\n HistogramChartProps\n>(function HistogramChart(\n {\n mode = \"plain\",\n threshold,\n thresholdLine,\n zeroLine,\n colors,\n seriesOptions,\n ariaLabel = \"Histogram chart\",\n ...props\n },\n ref,\n) {\n const options = useMemo(\n () => histogramOptions(mode, seriesOptions),\n [mode, seriesOptions],\n );\n\n const theme = useChartTheme(props);\n const priceLines = useMemo(\n () =>\n histogramPriceLines(\n mode,\n threshold,\n themedLine(\n referenceLine(theme, theme?.histogram.threshold, \"dashed\"),\n thresholdLine,\n ),\n themedLine(\n referenceLine(theme, theme?.histogram.zero, \"solid\"),\n zeroLine,\n ),\n ),\n [theme, mode, threshold, thresholdLine, zeroLine],\n );\n\n const { bar, over, positive, negative } = useMemo(\n () => deepMerge<HistogramColors>(histogramColorsFromTheme(theme), colors),\n [theme, colors],\n );\n\n const normalize = useCallback(\n (data: ReadonlyArray<LinePoint>) => {\n const normalized = normalizePoints(data);\n\n return {\n ...normalized,\n data: colorBars(normalized.data, mode, threshold, {\n bar,\n over,\n positive,\n negative,\n }),\n };\n },\n [mode, threshold, bar, over, positive, negative],\n );\n\n return (\n <SeriesChart\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n priceLines={priceLines}\n definition={HistogramSeries}\n normalize={normalize}\n aggregate={aggregatePoints}\n magnetMode={CrosshairMode.Magnet}\n />\n );\n});\n","import type {\n OHLC,\n CandlestickChartProps,\n CandlestickChartHandle,\n} from \"../../types/candlestick.js\";\n\nimport { useMemo, forwardRef } from \"react\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { aggregate } from \"../../utils/candlestick.utils.js\";\nimport { normalizeCandles } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { candleOptionsFromTheme } from \"../../utils/theme.utils.js\";\nimport { CandlestickSeries, type CandlestickData } from \"lightweight-charts\";\n\nexport const CandlestickChart = forwardRef<\n CandlestickChartHandle | null,\n CandlestickChartProps\n>(function CandlestickChart(\n { ariaLabel = \"Candlestick chart\", seriesOptions, ...props },\n ref,\n) {\n const theme = useChartTheme(props);\n const options = useMemo(\n () =>\n deepMerge<typeof seriesOptions>(\n candleOptionsFromTheme(theme),\n seriesOptions,\n ),\n [theme, seriesOptions],\n );\n\n return (\n <SeriesChart<\"Candlestick\", OHLC, CandlestickData>\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n definition={CandlestickSeries}\n normalize={normalizeCandles}\n aggregate={aggregate}\n />\n );\n});\n","import type {\n ISeriesPrimitive,\n IPrimitivePaneRenderer,\n IPrimitivePaneView,\n SeriesAttachedParameter,\n Time,\n ISeriesApi,\n SeriesType,\n AutoscaleInfo,\n} from \"lightweight-charts\";\n\nimport { withAlpha } from \"../utils/color.utils.js\";\nimport { timeToX } from \"../utils/timeScale.utils.js\";\nimport type { RibbonSample } from \"../utils/timeSeries.utils.js\";\n\ntype Target = Parameters<IPrimitivePaneRenderer[\"draw\"]>[0];\n\nexport interface RibbonPrimitiveOptions {\n points: readonly RibbonSample[];\n color: string;\n opacity?: number;\n}\n\n/**\n * Fills between two value lines on one price scale. Regime bands stay\n * full-height tints; this is the P10–P90 wash.\n */\nexport class RibbonPrimitive implements ISeriesPrimitive<Time> {\n private points: RibbonSample[] = [];\n private color = \"#000000\";\n private opacity = 0.16;\n private chart: SeriesAttachedParameter<Time>[\"chart\"] | null = null;\n private series: ISeriesApi<SeriesType, Time> | null = null;\n private requestUpdate: (() => void) | null = null;\n private readonly view: IPrimitivePaneView = {\n zOrder: () => \"bottom\",\n renderer: () => ({ draw: (target) => this.draw(target) }),\n };\n\n constructor(options: RibbonPrimitiveOptions) {\n this.applyOptions(options);\n }\n\n applyOptions(options: RibbonPrimitiveOptions) {\n this.points = [...options.points];\n this.color = options.color;\n this.opacity = options.opacity ?? 0.16;\n this.requestUpdate?.();\n }\n\n attached(param: SeriesAttachedParameter<Time>) {\n this.chart = param.chart;\n this.series = param.series;\n this.requestUpdate = param.requestUpdate;\n param.requestUpdate();\n }\n\n detached() {\n this.chart = null;\n this.series = null;\n this.requestUpdate = null;\n }\n\n paneViews() {\n return [this.view];\n }\n\n autoscaleInfo(): AutoscaleInfo | null {\n let min = Infinity;\n let max = -Infinity;\n\n for (const point of this.points) {\n min = Math.min(min, point.lower, point.upper);\n max = Math.max(max, point.lower, point.upper);\n }\n\n return Number.isFinite(min)\n ? { priceRange: { minValue: min, maxValue: max } }\n : null;\n }\n\n private draw(target: Target) {\n const chart = this.chart;\n const series = this.series;\n\n if (!chart || !series || this.points.length < 2) return;\n\n const timeScale = chart.timeScale();\n const coords = this.points.flatMap((point) => {\n const x = timeToX(timeScale, point.time);\n const upper = series.priceToCoordinate(point.upper);\n const lower = series.priceToCoordinate(point.lower);\n\n return x === null || upper === null || lower === null\n ? []\n : [{ x, upper, lower }];\n });\n const first = coords[0];\n\n if (!first || coords.length < 2) return;\n\n target.useMediaCoordinateSpace(({ context }) => {\n context.beginPath();\n context.moveTo(first.x, first.upper);\n\n for (const point of coords) context.lineTo(point.x, point.upper);\n\n for (let index = coords.length - 1; index >= 0; index -= 1) {\n const point = coords[index]!;\n\n context.lineTo(point.x, point.lower);\n }\n\n context.closePath();\n context.fillStyle = withAlpha(this.color, this.opacity) ?? this.color;\n context.fill();\n });\n }\n}\n","const containers = new Set<HTMLElement>();\nlet installed = false;\nlet original: typeof CanvasRenderingContext2D.prototype.roundRect | undefined;\n\n/**\n * Lightweight Charts draws axis and crosshair labels with rounded corners.\n * Zero the radius for canvases inside `container`, and leave every other\n * canvas on the page alone. Several charts share one prototype patch.\n */\nexport function patchSquareCanvasLabels(container: HTMLElement): () => void {\n const proto = globalThis.CanvasRenderingContext2D?.prototype;\n\n if (!proto?.roundRect) return () => {};\n\n containers.add(container);\n\n if (!installed) {\n original = proto.roundRect;\n proto.roundRect = function (x, y, w, h, radii) {\n for (const root of containers) {\n if (root.contains(this.canvas))\n return original!.call(this, x, y, w, h, 0);\n }\n\n return original!.call(this, x, y, w, h, radii);\n };\n installed = true;\n }\n\n return () => {\n containers.delete(container);\n\n if (containers.size === 0 && installed && original) {\n proto.roundRect = original;\n installed = false;\n original = undefined;\n }\n };\n}\n","import {\n ColorType,\n CrosshairMode,\n LineStyle,\n type DeepPartial,\n type ChartOptions,\n type Time,\n} from \"lightweight-charts\";\n\nimport type { Theme } from \"../types/theme.js\";\n\nconst FALLBACK_FONT = \"ui-sans-serif, system-ui, sans-serif\";\n\nexport interface EditorialScaleOptions {\n height?: number;\n timeVisible?: boolean;\n rightOffset?: number;\n leftPriceScale?: boolean;\n rightPriceScale?: boolean;\n tickMarkFormatter?: (time: Time) => string;\n timeFormatter?: (time: Time) => string;\n}\n\n/**\n * House look for product charts: transparent canvas, hairline grid, square\n * labels (applied separately), no wheel handler, sharp crosshair labels.\n * Pass `typography.axis.family` from `next/font` or `p1ThemeFromCss`.\n */\nexport function editorialChartOptions(\n theme: Theme,\n {\n height = 340,\n timeVisible = false,\n rightOffset = 2,\n leftPriceScale = false,\n rightPriceScale = true,\n tickMarkFormatter,\n timeFormatter,\n }: EditorialScaleOptions = {},\n): DeepPartial<ChartOptions> {\n const { palette, typography } = theme;\n const scale = {\n borderColor: palette.border,\n scaleMargins: { top: 0.12, bottom: 0.08 },\n };\n const hairline = {\n color: palette.crosshair,\n width: 1 as const,\n style: LineStyle.Dashed,\n labelBackgroundColor: palette.crosshairLabel,\n };\n\n return {\n height,\n layout: {\n background: { type: ColorType.Solid, color: \"transparent\" },\n textColor: palette.text,\n fontFamily: typography.axis.family || FALLBACK_FONT,\n fontSize: typography.axis.size ?? 11,\n attributionLogo: false,\n },\n grid: {\n vertLines: { color: palette.grid, style: LineStyle.Solid },\n horzLines: { color: palette.grid, style: LineStyle.Solid },\n },\n crosshair: {\n mode: CrosshairMode.Normal,\n vertLine: hairline,\n horzLine: hairline,\n },\n leftPriceScale: { ...scale, visible: leftPriceScale },\n rightPriceScale: { ...scale, visible: rightPriceScale },\n timeScale: {\n borderColor: palette.border,\n timeVisible,\n fixLeftEdge: true,\n fixRightEdge: false,\n rightOffset,\n ...(tickMarkFormatter ? { tickMarkFormatter } : {}),\n },\n localization: timeFormatter ? { timeFormatter } : undefined,\n handleScroll: { mouseWheel: false, vertTouchDrag: false },\n handleScale: { mouseWheel: false },\n };\n}\n","import type { UTCTimestamp } from \"lightweight-charts\";\nimport type { Time } from \"../types/chart.js\";\n\nexport const ORDINAL_STEP = 86_400;\n\nexport function ordinalIndex(\n time: Time,\n categories: readonly string[],\n): number | null {\n if (typeof time === \"number\" && Number.isInteger(time))\n return time >= 0 && time < categories.length ? time : null;\n\n if (typeof time === \"string\") {\n const index = categories.indexOf(time);\n\n return index < 0 ? null : index;\n }\n\n return null;\n}\n\nexport function ordinalTime(\n time: Time,\n categories: readonly string[],\n): UTCTimestamp | null {\n const index = ordinalIndex(time, categories);\n\n return index === null ? null : ((index * ORDINAL_STEP) as UTCTimestamp);\n}\n\nexport function ordinalLabel(\n time: number,\n categories: readonly string[],\n): string {\n const index = Math.round(time / ORDINAL_STEP);\n\n return categories[index] ?? \"\";\n}\n","import type { UTCTimestamp } from \"lightweight-charts\";\nimport type { Time } from \"../types/chart.js\";\nimport type { TimeSeriesPoint } from \"../types/timeSeries.js\";\nimport { toUnixSeconds } from \"./time.utils.js\";\nimport { ordinalTime } from \"./ordinal.utils.js\";\n\nexport interface RibbonSample {\n time: number;\n upper: number;\n lower: number;\n}\n\nexport function seriesTime(\n time: Time,\n categories: readonly string[] | null,\n): UTCTimestamp | null {\n if (categories) return ordinalTime(time, categories);\n\n const unix = toUnixSeconds(time);\n\n return unix === null ? null : (unix as UTCTimestamp);\n}\n\nexport function seriesRows(\n data: readonly TimeSeriesPoint[],\n categories: readonly string[] | null,\n): { time: UTCTimestamp; value: number }[] {\n const rows: { time: UTCTimestamp; value: number }[] = [];\n\n for (const point of data) {\n const time = seriesTime(point.time, categories);\n\n if (time === null || !Number.isFinite(point.value)) continue;\n\n const last = rows[rows.length - 1];\n\n if (last && last.time === time) rows[rows.length - 1] = { time, value: point.value };\n else rows.push({ time, value: point.value });\n }\n\n rows.sort((a, b) => a.time - b.time);\n\n const unique: typeof rows = [];\n\n for (const row of rows) {\n const last = unique[unique.length - 1];\n\n if (last && last.time === row.time) unique[unique.length - 1] = row;\n else unique.push(row);\n }\n\n return unique;\n}\n\nexport function ribbonSamples(\n upper: readonly TimeSeriesPoint[],\n lower: readonly TimeSeriesPoint[],\n categories: readonly string[] | null,\n): RibbonSample[] {\n const below = new Map<number, number>();\n\n for (const point of lower) {\n const time = seriesTime(point.time, categories);\n\n if (time !== null && Number.isFinite(point.value)) below.set(time, point.value);\n }\n\n const samples: RibbonSample[] = [];\n\n for (const point of upper) {\n const time = seriesTime(point.time, categories);\n const low = time === null ? undefined : below.get(time);\n\n if (time === null || low === undefined || !Number.isFinite(point.value))\n continue;\n\n samples.push({ time, upper: point.value, lower: low });\n }\n\n samples.sort((a, b) => a.time - b.time);\n\n return samples;\n}\n\nexport function defaultTimeLabel(time: Time): string {\n const unix = toUnixSeconds(time);\n\n if (unix === null) return String(time);\n\n return new Date(unix * 1000).toISOString().slice(0, 10);\n}\n","import {\n useEffect,\n useRef,\n useState,\n type CSSProperties,\n} from \"react\";\n\nimport {\n AreaSeries,\n CrosshairMode,\n HistogramSeries,\n LineSeries,\n LineStyle,\n createChart,\n createSeriesMarkers,\n type AutoscaleInfoProvider,\n type IChartApi,\n type ISeriesApi,\n type LineWidth,\n type SeriesMarker,\n type SeriesType,\n type Time,\n type UTCTimestamp,\n} from \"lightweight-charts\";\n\nimport type { ChartInstance } from \"../../types/chart.js\";\nimport type {\n TimeSeriesChartProps,\n TimeSeriesKind,\n TimeSeriesScale,\n TimeSeriesSpec,\n TimeSeriesTooltipRow,\n} from \"../../types/timeSeries.js\";\n\nimport { FILL, WRAPPER } from \"../../styles/seriesChart.js\";\nimport { TOOLTIP } from \"../../styles/shared.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { useWheelZoom } from \"../../hooks/useWheelZoom.js\";\nimport { RibbonPrimitive } from \"../../primitives/RibbonPrimitive.js\";\nimport { TimeRangePrimitive } from \"../../primitives/TimeRangePrimitive.js\";\nimport { patchSquareCanvasLabels } from \"../../utils/canvas.utils.js\";\nimport { withAlpha } from \"../../utils/color.utils.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { editorialChartOptions } from \"../../utils/editorial.utils.js\";\nimport { ordinalLabel } from \"../../utils/ordinal.utils.js\";\nimport { chartOptionsFromTheme, defaultTheme } from \"../../utils/theme.utils.js\";\nimport {\n defaultTimeLabel,\n ribbonSamples,\n seriesRows,\n seriesTime,\n} from \"../../utils/timeSeries.utils.js\";\nimport { toUnixSeconds } from \"../../utils/time.utils.js\";\nimport { placeTip } from \"../../utils/tooltip.utils.js\";\n\nconst STROKE = {\n solid: LineStyle.Solid,\n dotted: LineStyle.Dotted,\n dashed: LineStyle.Dashed,\n} as const;\n\nconst DEFINITION = {\n line: LineSeries,\n area: AreaSeries,\n histogram: HistogramSeries,\n} as const;\n\nconst NO_CATEGORIES: readonly string[] = [];\nconst NO_RIBBONS: NonNullable<TimeSeriesChartProps[\"ribbons\"]> = [];\nconst NO_RANGES: NonNullable<TimeSeriesChartProps[\"ranges\"]> = [];\nconst NO_GUIDES: NonNullable<TimeSeriesChartProps[\"guides\"]> = [];\nconst NO_MARKERS: NonNullable<TimeSeriesChartProps[\"markers\"]> = [];\n\nconst TIP: CSSProperties = {\n ...TOOLTIP,\n minWidth: 140,\n padding: \"8px 10px\",\n borderRadius: 0,\n fontSize: 12,\n lineHeight: 1.4,\n};\n\ninterface TipState {\n label: string;\n rows: TimeSeriesTooltipRow[];\n x: number;\n y: number;\n time: number;\n}\n\nfunction scaleOf(series: TimeSeriesSpec): TimeSeriesScale {\n return series.priceScale ?? \"right\";\n}\n\nfunction seriesColor(\n spec: TimeSeriesSpec,\n index: number,\n categorical: readonly string[],\n): string {\n return spec.color ?? categorical[index % Math.max(1, categorical.length)] ?? \"#191919\";\n}\n\nexport function TimeSeriesChart({\n series,\n ribbons = NO_RIBBONS,\n ranges = NO_RANGES,\n guides = NO_GUIDES,\n markers = NO_MARKERS,\n onPointClick,\n height = 340,\n className,\n ariaLabel = \"Time series chart\",\n profile = \"editorial\",\n axis = \"time\",\n categories,\n timeVisible = false,\n formatTime,\n formatValue,\n extraTooltipRows,\n renderTooltip,\n chartOptions,\n theme,\n unstyled,\n}: TimeSeriesChartProps) {\n const container = useRef<HTMLDivElement>(null);\n const resolved = useChartTheme({ theme, unstyled });\n const [chart, setChart] = useState<IChartApi | null>(null);\n const [tip, setTip] = useState<TipState | null>(null);\n const callbacks = useRef({\n formatTime,\n formatValue,\n extraTooltipRows,\n renderTooltip,\n onPointClick,\n });\n callbacks.current = {\n formatTime,\n formatValue,\n extraTooltipRows,\n renderTooltip,\n onPointClick,\n };\n const editorial = profile === \"editorial\";\n const labels = axis === \"ordinal\" ? (categories ?? NO_CATEGORIES) : null;\n const look = resolved ?? defaultTheme;\n\n useEffect(() => {\n const element = container.current;\n\n if (!element || !editorial) return;\n\n return patchSquareCanvasLabels(element);\n }, [editorial]);\n\n useEffect(() => {\n const element = container.current;\n\n if (!element) return;\n\n const palette = look.palette;\n const categorical = palette.categorical;\n const left = series.some((item) => scaleOf(item) === \"left\") ||\n ribbons.some((item) => item.priceScale === \"left\");\n const right =\n series.length === 0 ||\n series.some((item) => scaleOf(item) === \"right\") ||\n ribbons.some((item) => (item.priceScale ?? \"right\") === \"right\");\n const formatTick = (time: Time) => {\n const unix = typeof time === \"number\" ? time : toUnixSeconds(time as never);\n\n if (unix === null) return \"\";\n if (labels) return ordinalLabel(unix, labels);\n\n return callbacks.current.formatTime?.(unix) ?? defaultTimeLabel(unix);\n };\n const base = editorial\n ? editorialChartOptions(look, {\n height,\n timeVisible,\n leftPriceScale: left,\n rightPriceScale: right,\n tickMarkFormatter: formatTick,\n timeFormatter: formatTick,\n })\n : deepMerge(chartOptionsFromTheme(look), {\n height,\n crosshair: { mode: CrosshairMode.Magnet },\n handleScale: { mouseWheel: false },\n handleScroll: { mouseWheel: false },\n leftPriceScale: { visible: left },\n rightPriceScale: { visible: right },\n timeScale: {\n timeVisible,\n tickMarkFormatter: formatTick,\n },\n localization: { timeFormatter: formatTick },\n });\n const api = createChart(element, deepMerge({ autoSize: true }, base, chartOptions));\n const hosts = new Map<TimeSeriesScale, ISeriesApi<SeriesType>>();\n const painted = series.map((spec, index) => {\n const color = seriesColor(spec, index, categorical);\n const kind: TimeSeriesKind = spec.kind ?? \"line\";\n const width = (spec.lineWidth ?? (kind === \"line\" ? 2 : 1)) as LineWidth;\n const common = {\n priceScaleId: scaleOf(spec),\n priceLineVisible: false,\n lastValueVisible: spec.lastValueVisible ?? false,\n };\n const options =\n kind === \"area\"\n ? {\n ...common,\n lineColor: color,\n lineWidth: width,\n lineStyle: STROKE[spec.lineStyle ?? \"solid\"],\n topColor: withAlpha(color, 0.2) ?? color,\n bottomColor: withAlpha(color, 0) ?? color,\n }\n : kind === \"histogram\"\n ? { ...common, color }\n : {\n ...common,\n color,\n lineWidth: width,\n lineStyle: STROKE[spec.lineStyle ?? \"solid\"],\n crosshairMarkerVisible: true,\n };\n const apiSeries = api.addSeries(DEFINITION[kind], options);\n const rows = seriesRows(spec.data, labels);\n\n apiSeries.setData(rows);\n hosts.set(scaleOf(spec), apiSeries);\n\n const marks = markers.flatMap((marker) => {\n if (marker.seriesId !== spec.id) return [];\n\n const time = seriesTime(marker.time, labels);\n\n return time === null\n ? []\n : [\n {\n time,\n position: marker.position ?? \"inBar\",\n shape: marker.shape ?? \"circle\",\n color: marker.color ?? color,\n text: marker.text,\n } satisfies SeriesMarker<Time>,\n ];\n });\n\n if (marks.length > 0) createSeriesMarkers(apiSeries, marks);\n\n return { spec, color, rows, apiSeries };\n });\n\n for (const ribbon of ribbons) {\n const side = ribbon.priceScale ?? \"right\";\n const host = hosts.get(side) ?? painted[0]?.apiSeries;\n\n if (!host) continue;\n\n const color = ribbon.color ?? categorical[0] ?? palette.down;\n\n host.attachPrimitive(\n new RibbonPrimitive({\n points: ribbonSamples(ribbon.upper, ribbon.lower, labels),\n color,\n opacity: ribbon.opacity,\n }),\n );\n }\n\n const rangeHost = painted[0]?.apiSeries;\n\n if (rangeHost && ranges.length > 0) {\n rangeHost.attachPrimitive(\n new TimeRangePrimitive({\n items: ranges.map((range) => ({\n from: range.from,\n to: range.to,\n key: range.id,\n label: range.label,\n color: range.fill,\n })),\n style: (key) => {\n const range = ranges.find((item) => item.id === key);\n const hatch = range?.hatch;\n\n return {\n fill: range?.fill,\n hatch:\n hatch === false\n ? false\n : {\n color: hatch ?? range?.fill ?? palette.down,\n spacing: 8,\n width: 1,\n opacity: 0.45,\n },\n };\n },\n }),\n );\n }\n\n const guideValues = new Map<ISeriesApi<SeriesType>, number[]>();\n\n for (const guide of guides) {\n const host = hosts.get(guide.scale ?? \"right\") ?? painted[0]?.apiSeries;\n\n if (!host) continue;\n\n host.createPriceLine({\n price: guide.value,\n color: guide.color ?? palette.down,\n lineWidth: 1,\n lineStyle: LineStyle.Dashed,\n axisLabelVisible: Boolean(guide.label),\n title: guide.label ?? \"\",\n });\n\n if (!Number.isFinite(guide.value)) continue;\n\n const values = guideValues.get(host) ?? [];\n\n values.push(guide.value);\n guideValues.set(host, values);\n }\n\n for (const [host, values] of guideValues) {\n host.applyOptions({\n autoscaleInfoProvider: ((original) => {\n const info = original();\n\n if (!info?.priceRange) return info;\n\n return {\n ...info,\n priceRange: {\n minValue: Math.min(info.priceRange.minValue, ...values),\n maxValue: Math.max(info.priceRange.maxValue, ...values),\n },\n };\n }) satisfies AutoscaleInfoProvider,\n });\n }\n\n api.timeScale().fitContent();\n\n const onMove = (param: { time?: Time; point?: { x: number; y: number } }) => {\n const unix = typeof param.time === \"number\" ? param.time : null;\n const point = param.point;\n\n if (unix === null || !point) {\n setTip(null);\n return;\n }\n\n const rows: TimeSeriesTooltipRow[] = painted.flatMap(({ spec, color, rows: data }) => {\n if (spec.includeInTooltip === false) return [];\n\n const hit = data.find((item) => item.time === unix);\n\n if (!hit) return [];\n\n return [\n {\n label: spec.name,\n value: callbacks.current.formatValue?.(spec.id, hit.value) ?? String(hit.value),\n color,\n swatch: spec.kind === \"histogram\" ? \"bar\" as const : \"line\" as const,\n },\n ];\n });\n const extra = callbacks.current.extraTooltipRows?.(unix) ?? [];\n const label = labels\n ? ordinalLabel(unix, labels)\n : (callbacks.current.formatTime?.(unix) ?? defaultTimeLabel(unix));\n\n setTip({\n label,\n rows: [...rows, ...extra],\n x: point.x,\n y: point.y,\n time: unix,\n });\n };\n\n const onClick = (param: { time?: Time }) => {\n const handler = callbacks.current.onPointClick;\n const unix = typeof param.time === \"number\" ? param.time : null;\n\n if (!handler || unix === null) return;\n\n const points = painted.flatMap(({ spec, rows: data }) => {\n const hit = data.find((item) => item.time === unix);\n\n return hit ? [{ seriesId: spec.id, value: hit.value }] : [];\n });\n\n if (points.length > 0) handler({ time: unix, points });\n };\n\n api.subscribeCrosshairMove(onMove);\n api.subscribeClick(onClick);\n setChart(api);\n\n return () => {\n setChart(null);\n setTip(null);\n api.unsubscribeCrosshairMove(onMove);\n api.unsubscribeClick(onClick);\n api.remove();\n };\n }, [\n series,\n ribbons,\n ranges,\n guides,\n markers,\n resolved,\n height,\n editorial,\n labels,\n timeVisible,\n chartOptions,\n look,\n ]);\n\n useWheelZoom(\n chart ? ({ chart, series: null as never } satisfies ChartInstance<SeriesType>) : null,\n container,\n !editorial,\n );\n\n const box = container.current?.getBoundingClientRect();\n const placed = tip\n ? placeTip([tip.x, tip.y], 12, [180, 56], [box?.width || height, box?.height || height])\n : null;\n\n return (\n <div\n className={className}\n data-profile={profile}\n data-axis={axis}\n style={{ ...WRAPPER, height }}\n >\n <div ref={container} style={FILL} role=\"img\" aria-label={ariaLabel} />\n {tip && placed && (\n <div\n data-part=\"tooltip\"\n style={{\n ...TIP,\n left: placed[0],\n top: placed[1],\n background: resolved?.palette.background ?? \"#fff\",\n color: resolved?.palette.text ?? \"#191919\",\n border: `1px solid ${resolved?.palette.border ?? \"#2B2B43\"}`,\n }}\n >\n <div data-part=\"tooltip-time\">{tip.label}</div>\n {callbacks.current.renderTooltip\n ? callbacks.current.renderTooltip(tip.rows, {\n time: tip.time,\n x: tip.x,\n y: tip.y,\n })\n : tip.rows.map((row) => (\n <div key={`${row.label}:${row.value}`} data-part=\"tooltip-row\">\n <span\n data-part=\"swatch\"\n data-swatch={row.swatch}\n style={{\n display: \"inline-block\",\n width: 8,\n height: row.swatch === \"bar\" ? 8 : 2,\n marginRight: 6,\n background: row.color,\n }}\n />\n <span>{row.label}</span> <span>{row.value}</span>\n </div>\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAOA,SAASc,EAAO,GAAgC,GAA8B;CAC5E,IAAMC,IAAIC,EAAU,oBAAoBC,CAAgB,GAClDC,IAAOH,MAAM,OAAO,OAAOC,EAAU,iBAAiBD,CAAC;CAE7D,OAAOG,MAAS,OAAO,OAAO,OAAOA,CAAI;AAC3C;AAEA,SAAgBC,EACd,GACA,GACe;CACf,IAAMC,IAAQJ,EAAU,iBAAiBE,CAAoB;CAE7D,IAAIE,MAAU,MAAM,OAAOA;CAE3B,IAAMC,IAAUL,EAAU,YAAYE,GAAsB,EAAI;CAEhE,IAAIG,MAAY,MAAM,OAAO;CAE7B,IAAMC,IAAO,KAAK,IAAI,GAAGD,IAAU,CAAC,GAC9BE,IAAWT,EAAOE,GAAWM,CAAI,GACjCE,IAAYV,EAAOE,GAAWM,IAAO,CAAC,GACtCG,IAAQT,EAAU,oBAAoBM,CAAe,GACrDI,IAASV,EAAU,oBAAqBM,IAAO,CAAa;CAWlE,OAREC,MAAa,QACbC,MAAc,QACdC,MAAU,QACVC,MAAW,QACX,EAAEF,IAAYD,KAEP,OAGPE,KAAUP,IAAOK,MAAaC,IAAYD,MAAcG,IAASD;AAErE;AAEA,SAAgBE,EACd,GACA,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C,OAAD;GACE,aAAU;GACV,OAAO;IACL,GAAGvC;IACH,MAAMuC,EAAO;IACb,KAAKA,EAAO;IACZ,YAAYnQ,GAAU,QAAQ,cAAc;IAC5C,OAAOA,GAAU,QAAQ,QAAQ;IACjC,QAAQ,aAAaA,GAAU,QAAQ,UAAU;GACnD;GATF,UAAA,CAWE,kBAAC,OAAD;IAAK,aAAU;IAAgB,UAAAkO,EAAI;GAAW,CAAA,GAC7CE,EAAU,QAAQ,gBACfA,EAAU,QAAQ,cAAcF,EAAI,MAAM;IACxC,MAAMA,EAAI;IACV,GAAGA,EAAI;IACP,GAAGA,EAAI;GACT,CAAC,IACDA,EAAI,KAAK,KAAK,MACZ,kBAAC,OAAD;IAAuC,aAAU;IAAjD,UAAA;KACE,kBAAC,QAAD;MACE,aAAU;MACV,eAAahN,EAAI;MACjB,OAAO;OACL,SAAS;OACT,OAAO;OACP,QAAQA,EAAI,WAAW,QAAQ,IAAI;OACnC,aAAa;OACb,YAAYA,EAAI;MAClB;KACD,CAAA;KACD,kBAAC,QAAD,EAAA,UAAOA,EAAI,MAAY,CAAA;KAAC;KAAC,kBAAC,QAAD,EAAA,UAAOA,EAAI,MAAY,CAAA;IAC7C;GAbK,GAAA,GAAGA,EAAI,MAAM,GAAGA,EAAI,OAazB,CACN,CACF;EAEJ,CAAA,CAAA;;AAET"}
|
|
1
|
+
{"version":3,"file":"TimeSeriesChart-BzeHEtQl.js","names":["_Fragment","_Fragment","histogramColorsFromTheme","textStyle","deepMerge","defaultTheme","withAlpha","chartOptionsFromTheme","candleOptionsFromTheme","themedLine","resetOptions","TOOLTIP","prefersReducedMotion","useChartTheme","placeTip","timeAt","x","timeScale","index","time","timeToX","exact","nearest","left","leftTime","rightTime","leftX","rightX","barEdgesX","indexOf","first","from","next","to","firstTime","nextTime","last","right","half","WRAPPER","FILL","BAND","FLASH","PILL_POSITION","PILL","BAND_LEGEND","BAND_LEGEND_ITEM","BAND_MARK","RANGE_SELECT","withoutCreationOnly","options","layout","resetAndMerge","previous","applied","owner","defaults","useChart","instance","setInstance","useState","generation","setGeneration","creationOptions","useRef","chartOptions","appliedChart","appliedSeries","useEffect","element","container","chart","createChart","series","definition","value","seriesOptions","MS_THRESHOLD","toUnixSeconds","isMs","trimmed","normalizeSeries","byTime","point","input","config","times","a","b","data","points","rows","indexByTime","isValid","candle","normalizeCandles","color","borderColor","wickColor","normalizePoints","timeKey","indexAtOrBefore","low","high","found","mid","barTime","UNSTYLED_FILL","sortBands","bands","start","band","end","bandKeys","resolveBandStyles","categorical","theme","keys","fill","own","bandStyles","key","bandAt","hovered","before","bars","styles","LABEL_INSET","dash","style","width","paint","item","rect","context","y","height","hatch","spacing","offset","stroke","lineWidth","text","TimeRangePrimitive","target","requestUpdate","mediaSize","useBands","sorted","useMemo","primitive","latest","enabled","pane","created","entries","bandOf","useCallback","normalized","useOverlays","list","create","LineSeries","overlays","overlay","entry","MIN_VISIBLE_BARS","ZOOM_SPEED","HALF_BAR","tickDirection","after","beforeTime","afterTime","secondLast","sameBar","appended","flashColors","record","up","down","topLine","bottomLine","zoomRange","factor","delta","anchor","range","wheelPixels","event","scaled","isLive","lastIndex","useWheelZoom","onWheel","nextBucketSize","pxPerRawBar","current","rawCount","minBarWidth","buckets","bucketSize","result","i","items","SETTLE_MS","DEFAULT_MIN_BAR_WIDTH","minBarWidthOf","autoBucket","useAutoBucket","setBucketSize","size","raw","timer","frame","measure","span","schedule","useSeriesData","normalize","aggregate","appliedBucket","ratio","keep","IDLE_MS","PAUSE_EVENTS","sameRange","useLiveFollow","away","setAway","lastIndexRef","check","paused","resume","shift","wasLive","touch","type","FLASH_MS","LABEL_PADDING","usePriceFlash","flash","direction","colors","NO_LINES","usePriceLines","lines","line","useSeriesTheme","resolved","magnet","magnetMode","ctrlWheelZoom","referenceLine","anchorLine","DAY","monthsBefore","date","seconds","months","startOf","preset","presetRange","useRangePreset","hasData","percent","highLow","row","visibleStats","MIN_DRAG","useRangeSelect","selecting","setSelecting","plotX","box","stop","onMove","onUp","onKey","fromLogical","toLogical","stats","onDown","onDoubleClick","toSeriesSummary","anchorIndex","tooltipTransform","flipX","gap","DEFAULT_LINE","useAnchor","price","useChartEvents","handlersRef","handlers","selectRef","onSelect","stale","active","setActive","activate","track","select","eventAt","bar","build","fromParam","param","onClick","useKeyboardNav","actionsRef","actions","driving","reveal","goTo","release","onKeyDown","step","onBlur","onPointerMove","useCrosshairBand","place","KEYS","TOOLTIP_GAP","tooltipAt","useInteractions","pinned","setPinned","pinnedTime","pinOnClick","pinnedIndex","events","summary","legend","tooltip","placeBand","keyboard","legendSummary","tipSummary","transform","useVisibleStats","handler","onChange","emit","BandLegend","render","Fragment","border","legendColor","label","LEGEND","InteractionSlots","renderLegend","renderTooltip","SeriesChartInner","CrosshairMode","selection","overlaySeries","themedOverlays","priceLines","onVisibleStatsChange","interactions","themedAnchorLine","flashLastPrice","rangeSelect","doubleClickReset","followLive","useImperativeHandle","ref","ariaLabel","renderBandLegend","classNames","liveButtonClassName","unstyled","jumpToLive","liveButtonLabel","SeriesChart","forwardRef","barColor","mode","threshold","colorBars","ownAutoscale","original","symmetricAutoscale","info","extent","minValue","maxValue","histogramOptions","histogramPriceLines","thresholdLine","zeroLine","aggregatePoints","slice","toLinePoints","candles","stylePoints","rest","source","styled","colorKeys","styleKeys","BarChart","props","upColor","downColor","base","HistogramSeries","VARIANTS","AreaSeries","BaselineSeries","LineChart","variant","lineOptionsFromTheme","baseValue","isUp","HistogramChart","over","positive","negative","CandlestickChart","CandlestickSeries","RibbonPrimitive","min","max","coords","upper","lower","containers","installed","patchSquareCanvasLabels","proto","root","w","h","radii","FALLBACK_FONT","editorialChartOptions","scale","palette","hairline","LineStyle","ColorType","typography","leftPriceScale","rightPriceScale","tickMarkFormatter","timeFormatter","ORDINAL_STEP","ordinalIndex","categories","ordinalTime","ordinalLabel","seriesTime","unix","seriesRows","unique","ribbonSamples","below","samples","defaultTimeLabel","STROKE","DEFINITION","NO_CATEGORIES","NO_RIBBONS","NO_RANGES","NO_GUIDES","NO_MARKERS","TIP","scaleOf","seriesColor","spec","TimeSeriesChart","setChart","tip","setTip","callbacks","editorial","profile","labels","axis","look","ribbons","formatTick","api","hosts","painted","kind","common","apiSeries","marks","markers","marker","createSeriesMarkers","ribbon","side","host","rangeHost","ranges","guideValues","guide","guides","values","hit","extra","timeVisible","placed"],"sources":["../src/utils/timeScale.utils.ts","../src/styles/seriesChart.ts","../src/hooks/useChart.ts","../src/utils/time.utils.ts","../src/utils/data.utils.ts","../src/utils/bands.utils.ts","../src/primitives/TimeRangePrimitive.ts","../src/hooks/useBands.ts","../src/hooks/useOverlays.ts","../src/utils/live.utils.ts","../src/hooks/useWheelZoom.ts","../src/utils/bucket.utils.ts","../src/hooks/useAutoBucket.ts","../src/hooks/useSeriesData.ts","../src/hooks/useLiveFollow.ts","../src/hooks/usePriceFlash.ts","../src/hooks/usePriceLines.ts","../src/hooks/useSeriesTheme.ts","../src/utils/range.utils.ts","../src/hooks/useRangePreset.ts","../src/utils/stats.utils.ts","../src/hooks/useRangeSelect.ts","../src/utils/interaction.utils.ts","../src/hooks/useAnchor.ts","../src/hooks/useChartEvents.ts","../src/hooks/useKeyboardNav.ts","../src/hooks/useCrosshairBand.ts","../src/hooks/useInteractions.ts","../src/hooks/useVisibleStats.ts","../src/components/BandLegend/index.tsx","../src/components/InteractionSlots/index.tsx","../src/charts/SeriesChart/index.tsx","../src/utils/histogram.utils.ts","../src/utils/line.utils.ts","../src/charts/BarChart/index.tsx","../src/charts/LineChart/index.tsx","../src/utils/candlestick.utils.ts","../src/charts/HistogramChart/index.tsx","../src/charts/CandlestickChart/index.tsx","../src/primitives/RibbonPrimitive.ts","../src/utils/canvas.utils.ts","../src/utils/editorial.utils.ts","../src/utils/ordinal.utils.ts","../src/utils/timeSeries.utils.ts","../src/charts/TimeSeriesChart/index.tsx"],"sourcesContent":["import type {\n Time,\n Logical,\n UTCTimestamp,\n ITimeScaleApi,\n} from \"lightweight-charts\";\n\nfunction timeAt(timeScale: ITimeScaleApi<Time>, index: number): number | null {\n const x = timeScale.logicalToCoordinate(index as Logical);\n const time = x === null ? null : timeScale.coordinateToTime(x);\n\n return time === null ? null : Number(time);\n}\n\nexport function timeToX(\n timeScale: ITimeScaleApi<Time>,\n time: number,\n): number | null {\n const exact = timeScale.timeToCoordinate(time as UTCTimestamp);\n\n if (exact !== null) return exact;\n\n const nearest = timeScale.timeToIndex(time as UTCTimestamp, true);\n\n if (nearest === null) return null;\n\n const left = Math.max(0, nearest - 1);\n const leftTime = timeAt(timeScale, left);\n const rightTime = timeAt(timeScale, left + 1);\n const leftX = timeScale.logicalToCoordinate(left as Logical);\n const rightX = timeScale.logicalToCoordinate((left + 1) as Logical);\n\n if (\n leftTime === null ||\n rightTime === null ||\n leftX === null ||\n rightX === null ||\n !(rightTime > leftTime)\n )\n return null;\n\n return (\n leftX + ((time - leftTime) / (rightTime - leftTime)) * (rightX - leftX)\n );\n}\n\nexport function barEdgesX(\n timeScale: ITimeScaleApi<Time>,\n from: number,\n to: number,\n): [number, number] | null {\n const indexOf = (time: number) => {\n const index = timeScale.timeToIndex(time as UTCTimestamp, true);\n\n return index === null ? null : Number(index);\n };\n const first = indexOf(from);\n const next = indexOf(to);\n\n if (first === null || next === null) return null;\n\n const firstTime = timeAt(timeScale, first);\n const nextTime = timeAt(timeScale, next);\n\n if (firstTime === null || nextTime === null || firstTime < from) return null;\n\n const last = nextTime < to ? next : next - 1;\n const left = timeScale.logicalToCoordinate(first as Logical);\n const right = timeScale.logicalToCoordinate(last as Logical);\n\n if (last < first || left === null || right === null) return null;\n\n const half = timeScale.options().barSpacing / 2;\n\n return [left - half, right + half];\n}\n","import type { CSSProperties } from \"react\";\n\nexport const WRAPPER: CSSProperties = { position: \"relative\" };\nexport const FILL: CSSProperties = {\n position: \"absolute\",\n inset: 0,\n zIndex: 0,\n};\nexport const BAND: CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n display: \"none\",\n opacity: 0.15,\n pointerEvents: \"none\",\n};\nexport const FLASH: CSSProperties = {\n position: \"absolute\",\n top: 0,\n right: 0,\n opacity: 0,\n pointerEvents: \"none\",\n};\nexport const PILL_POSITION: CSSProperties = {\n position: \"absolute\",\n bottom: 40,\n left: \"50%\",\n transform: \"translateX(-50%)\",\n};\nexport const PILL: CSSProperties = {\n ...PILL_POSITION,\n minHeight: 28,\n padding: \"4px 12px\",\n borderRadius: 999,\n border: \"1px solid color-mix(in srgb, currentColor 25%, transparent)\",\n background: \"Canvas\",\n color: \"CanvasText\",\n font: \"inherit\",\n fontSize: 12,\n cursor: \"pointer\",\n touchAction: \"manipulation\",\n};\nexport const BAND_LEGEND: CSSProperties = {\n position: \"absolute\",\n top: 8,\n right: 8,\n zIndex: 1,\n display: \"flex\",\n flexWrap: \"wrap\",\n gap: 12,\n margin: 0,\n padding: 0,\n listStyle: \"none\",\n pointerEvents: \"none\",\n};\nexport const BAND_LEGEND_ITEM: CSSProperties = {\n display: \"flex\",\n alignItems: \"center\",\n gap: 6,\n};\nexport const BAND_MARK: CSSProperties = {\n flex: \"none\",\n width: 10,\n height: 10,\n boxSizing: \"border-box\",\n};\nexport const RANGE_SELECT: CSSProperties = {\n position: \"absolute\",\n top: 0,\n left: 0,\n display: \"none\",\n pointerEvents: \"none\",\n};\n","import {\n createChart,\n type SeriesType,\n type DeepPartial,\n type ChartOptions,\n type SeriesDefinition,\n type SeriesPartialOptionsMap,\n} from \"lightweight-charts\";\n\nimport type {\n ChartInstance,\n AppliedOptions,\n InternalInstance,\n} from \"../types/chart.js\";\n\nimport { deepMerge, resetOptions } from \"../utils/merge.utils.js\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\n\nfunction withoutCreationOnly(\n options: DeepPartial<ChartOptions> = {},\n): DeepPartial<ChartOptions> {\n if (!options.layout) return options;\n\n const { colorSpace, colorParsers, ...layout } = options.layout;\n\n return { ...options, layout };\n}\n\nfunction resetAndMerge<O>(\n applied: RefObject<AppliedOptions>,\n owner: unknown,\n defaults: unknown,\n next: O,\n): O | null {\n const previous =\n applied.current.owner === owner ? applied.current.options : {};\n const options = resetOptions(defaults, previous, next);\n\n if (options) applied.current = { owner, options: next };\n\n return options;\n}\n\nexport function useChart<T extends SeriesType>(\n container: RefObject<HTMLDivElement | null>,\n definition: SeriesDefinition<T>,\n chartOptions?: DeepPartial<ChartOptions>,\n seriesOptions?: SeriesPartialOptionsMap[T],\n): ChartInstance<T> | null {\n const [instance, setInstance] = useState<InternalInstance<T> | null>(null);\n const [generation, setGeneration] = useState(0);\n const creationOptions = useRef(chartOptions);\n const appliedChart = useRef<AppliedOptions>({ owner: null, options: {} });\n const appliedSeries = useRef<AppliedOptions>({ owner: null, options: {} });\n creationOptions.current = chartOptions;\n\n useEffect(() => {\n const element = container.current;\n\n if (!element) return;\n\n const layout = creationOptions.current?.layout;\n const chart = createChart(\n element,\n deepMerge(\n { autoSize: true },\n {\n layout: {\n colorSpace: layout?.colorSpace,\n colorParsers: layout?.colorParsers,\n },\n },\n ),\n );\n const series = chart.addSeries(definition);\n\n setInstance({\n chart,\n series,\n chartDefaults: withoutCreationOnly(deepMerge(chart.options())),\n seriesDefaults: deepMerge(series.options()),\n });\n\n return () => {\n setInstance(null);\n chart.remove();\n };\n }, [container, definition, generation]);\n\n useEffect(() => {\n if (!instance) return;\n\n const next = withoutCreationOnly(chartOptions);\n const options = resetAndMerge(\n appliedChart,\n instance,\n instance.chartDefaults,\n next,\n );\n\n if (options) instance.chart.applyOptions(options);\n else setGeneration((value) => value + 1);\n }, [instance, chartOptions]);\n\n useEffect(() => {\n if (!instance) return;\n\n const next = seriesOptions ?? ({} as SeriesPartialOptionsMap[T]);\n const options = resetAndMerge(\n appliedSeries,\n instance,\n instance.seriesDefaults,\n next,\n );\n\n if (options) instance.series.applyOptions(options);\n else setGeneration((value) => value + 1);\n }, [instance, seriesOptions]);\n\n return instance;\n}\n","import type { Time } from \"../types/chart.js\";\n\nconst MS_THRESHOLD = 1e11;\n\nexport function toUnixSeconds(time: Time): number | null {\n let value: number;\n let isMs: boolean;\n\n if (time instanceof Date) {\n value = time.getTime();\n isMs = true;\n } else if (typeof time === \"string\") {\n value = Date.parse(time);\n isMs = true;\n\n if (!Number.isFinite(value)) {\n const trimmed = time.trim();\n\n value = trimmed === \"\" ? Number.NaN : Number(trimmed);\n isMs = Math.abs(value) > MS_THRESHOLD;\n }\n } else {\n value = time;\n isMs = Math.abs(value) > MS_THRESHOLD;\n }\n\n if (!Number.isFinite(value)) return null;\n\n return Math.floor(isMs ? value / 1000 : value);\n}\n","import type {\n LineData,\n UTCTimestamp,\n CandlestickData,\n} from \"lightweight-charts\";\n\nimport type {\n SeriesRow,\n NormalizeConfig,\n NormalizedSeries,\n} from \"../types/series.js\";\n\nimport { toUnixSeconds } from \"./time.utils.js\";\nimport type { LinePoint } from \"../types/chart.js\";\nimport type { OHLC } from \"../types/candlestick.js\";\n\nfunction normalizeSeries<TPoint, TData>(\n input: ReadonlyArray<TPoint>,\n config: NormalizeConfig<TPoint, TData>,\n): NormalizedSeries<TPoint, TData> {\n const byTime = new Map<number, TPoint>();\n\n for (const point of input) {\n const time = config.time(point);\n\n if (time === null || !config.valid(point)) continue;\n byTime.set(time, point);\n }\n\n const times = [...byTime.keys()].sort((a, b) => a - b);\n const data: TData[] = [];\n const points: TPoint[] = [];\n const rows: SeriesRow[] = [];\n const indexByTime = new Map<number, number>();\n\n times.forEach((time, index) => {\n const point = byTime.get(time)!;\n\n data.push(config.data(point, time));\n points.push(point);\n rows.push(config.row(point));\n indexByTime.set(time, index);\n });\n\n return { data, points, rows, indexByTime };\n}\n\nfunction isValid(candle: OHLC): boolean {\n return [candle.open, candle.high, candle.low, candle.close].every(\n Number.isFinite,\n );\n}\n\nexport function normalizeCandles(\n input: ReadonlyArray<OHLC>,\n): NormalizedSeries<OHLC, CandlestickData> {\n return normalizeSeries<OHLC, CandlestickData>(input, {\n time: (candle) => toUnixSeconds(candle.time),\n valid: isValid,\n row: (candle) => candle,\n data: (candle, time) => {\n const { open, high, low, close, color, borderColor, wickColor } = candle;\n\n return {\n time: time as UTCTimestamp,\n open,\n high,\n low,\n close,\n ...(color !== undefined && { color }),\n ...(borderColor !== undefined && { borderColor }),\n ...(wickColor !== undefined && { wickColor }),\n };\n },\n });\n}\n\nexport function normalizePoints(\n input: ReadonlyArray<LinePoint>,\n): NormalizedSeries<LinePoint, LineData> {\n return normalizeSeries<LinePoint, LineData>(input, {\n time: (point) => toUnixSeconds(point.time),\n valid: (point) => Number.isFinite(point.value),\n row: (point) => ({\n time: point.time,\n open: point.value,\n high: point.value,\n low: point.value,\n close: point.value,\n }),\n data: (point, time) => ({\n time: time as UTCTimestamp,\n value: point.value,\n ...(point.color !== undefined && { color: point.color }),\n }),\n });\n}\n\nfunction timeKey(time: unknown): number | null {\n return typeof time === \"number\" ||\n typeof time === \"string\" ||\n time instanceof Date\n ? toUnixSeconds(time)\n : null;\n}\n\nexport function indexAtOrBefore(\n data: ReadonlyArray<{ time: unknown }>,\n time: number,\n): number | null {\n let low = 0;\n let high = data.length - 1;\n let found: number | null = null;\n\n while (low <= high) {\n const mid = (low + high) >> 1;\n const barTime = timeKey(data[mid]!.time);\n\n if (barTime !== null && barTime <= time) {\n found = mid;\n low = mid + 1;\n } else high = mid - 1;\n }\n\n return found;\n}\n","import type {\n BandItem,\n BandStyle,\n BandAtPoint,\n BandStyleInput,\n} from \"../types/bands.js\";\n\nimport { deepMerge } from \"./merge.utils.js\";\nimport { withAlpha } from \"./theme.utils.js\";\nimport type { Theme } from \"../types/theme.js\";\nimport { toUnixSeconds } from \"./time.utils.js\";\nimport { indexAtOrBefore } from \"./data.utils.js\";\n\nconst UNSTYLED_FILL = \"rgba(128,128,128,0.15)\";\n\nexport function sortBands(\n bands: ReadonlyArray<BandItem>,\n): Array<BandItem & { start: number; end: number }> {\n return bands\n .flatMap((band) => {\n const start = toUnixSeconds(band.from);\n const end = toUnixSeconds(band.to);\n\n return start === null || end === null || end < start\n ? []\n : [{ ...band, start, end }];\n })\n .sort((a, b) => a.start - b.start);\n}\n\nexport function bandKeys(bands: ReadonlyArray<BandItem>): string[] {\n return [...new Set(bands.map((band) => band.key))];\n}\n\nexport function resolveBandStyles(\n keys: ReadonlyArray<string>,\n theme: Theme | null,\n bandStyles: Record<string, BandStyleInput> = {},\n): Record<string, BandStyle> {\n const categorical = theme?.palette.categorical ?? [];\n\n return Object.fromEntries(\n keys.map((key, index) => {\n const color = categorical[index % categorical.length];\n const fill =\n (theme && (withAlpha(color, theme.bands.opacity) ?? color)) ||\n UNSTYLED_FILL;\n const own = bandStyles[key];\n\n return [\n key,\n deepMerge<BandStyle>(\n { fill, label: key },\n theme?.bands.styles?.[key],\n typeof own === \"string\" ? { fill: own } : own,\n ),\n ];\n }),\n );\n}\n\nexport function bandAt(\n bands: ReadonlyArray<BandItem>,\n time: number,\n data: ReadonlyArray<{ time: unknown }>,\n styles: Record<string, BandStyle> = {},\n): BandAtPoint | null {\n const band = sortBands(bands)\n .filter(({ start, end }) => start <= time && time < end)\n .pop();\n\n if (!band) return null;\n\n const hovered = indexAtOrBefore(data, time);\n const before = indexAtOrBefore(data, band.start - 1);\n const bars = hovered === null ? 0 : hovered - (before ?? -1);\n\n return {\n key: band.key,\n label: styles[band.key]?.label ?? band.key,\n from: band.from,\n to: band.to,\n bars,\n };\n}\n","import type {\n Time,\n IChartApi,\n IPanePrimitive,\n IPrimitivePaneView,\n PaneAttachedParameter,\n IPrimitivePaneRenderer,\n PrimitivePaneViewZOrder,\n} from \"lightweight-charts\";\n\nimport type { LayoutRect } from \"../types/layout.js\";\nimport { toUnixSeconds } from \"../utils/time.utils.js\";\nimport { barEdgesX, timeToX } from \"../utils/timeScale.utils.js\";\nimport type { PlacedRange, TimeRangeOptions } from \"../types/timeline.js\";\n\ntype Target = Parameters<IPrimitivePaneRenderer[\"draw\"]>[0];\n\nconst LABEL_INSET = 8;\n\nfunction dash(style: string | undefined, width: number): number[] {\n if (style === \"dashed\") return [4 * width, 3 * width];\n if (style === \"dotted\") return [width, 2 * width];\n return [];\n}\n\nfunction paint(\n context: CanvasRenderingContext2D,\n rect: LayoutRect,\n item: PlacedRange,\n) {\n const { style } = item;\n const { x, y, width, height } = rect;\n const fill = item.color ?? style.fill;\n const { stroke, hatch, text } = style;\n\n context.save();\n context.beginPath();\n context.rect(x, y, width, height);\n context.clip();\n\n if (fill) {\n context.fillStyle = fill;\n context.fillRect(x, y, width, height);\n }\n\n if (hatch && hatch.color) {\n const spacing = Math.max(1, hatch.spacing ?? 6);\n\n context.globalAlpha = hatch.opacity ?? 1;\n context.strokeStyle = hatch.color;\n context.lineWidth = hatch.width ?? 1;\n context.beginPath();\n for (let offset = 0; offset < width + height; offset += spacing) {\n context.moveTo(x + offset - height, y + height);\n context.lineTo(x + offset, y);\n }\n context.stroke();\n context.globalAlpha = 1;\n }\n\n if (stroke?.color) {\n const lineWidth = stroke.width ?? 1;\n\n context.strokeStyle = stroke.color;\n context.lineWidth = lineWidth;\n context.setLineDash(dash(stroke.style, lineWidth));\n context.strokeRect(\n x + lineWidth / 2,\n y + lineWidth / 2,\n width - lineWidth,\n height - lineWidth,\n );\n context.setLineDash([]);\n }\n\n if (item.label && text?.color) {\n context.fillStyle = text.color;\n context.font = `${text.weight ?? 400} ${text.size ?? 12}px ${text.family ?? \"sans-serif\"}`;\n context.textBaseline = \"middle\";\n context.fillText(\n item.label,\n x + (style.inset ?? LABEL_INSET),\n y + height / 2,\n );\n }\n\n context.restore();\n}\n\nexport class TimeRangePrimitive implements IPanePrimitive<Time> {\n private zOrder: PrimitivePaneViewZOrder = \"normal\";\n private edges: TimeRangeOptions[\"edges\"] = \"time\";\n private items: PlacedRange[] = [];\n private chart: IChartApi | null = null;\n private requestUpdate: (() => void) | null = null;\n private readonly view: IPrimitivePaneView = {\n zOrder: () => this.zOrder,\n renderer: () => ({ draw: (target) => this.draw(target) }),\n };\n\n constructor(options: TimeRangeOptions) {\n this.applyOptions(options);\n }\n\n applyOptions(options: TimeRangeOptions) {\n this.zOrder = options.zOrder ?? \"normal\";\n this.edges = options.edges ?? \"time\";\n this.items = options.items.flatMap((item) => {\n const from = toUnixSeconds(item.from);\n const to = toUnixSeconds(item.to);\n\n return from === null || to === null\n ? []\n : [\n {\n ...item,\n from: Math.min(from, to),\n to: Math.max(from, to),\n style: options.style(item.key),\n },\n ];\n });\n this.requestUpdate?.();\n }\n\n attached({ chart, requestUpdate }: PaneAttachedParameter<Time>) {\n this.chart = chart;\n this.requestUpdate = requestUpdate;\n requestUpdate();\n }\n\n detached() {\n this.chart = null;\n this.requestUpdate = null;\n }\n\n paneViews() {\n return [this.view];\n }\n\n private draw(target: Target) {\n const chart = this.chart;\n\n if (!chart) return;\n\n const timeScale = chart.timeScale();\n\n target.useMediaCoordinateSpace(({ context, mediaSize }) => {\n for (const item of this.items) {\n const [from = null, to = null] =\n this.edges === \"between-bars\"\n ? (barEdgesX(timeScale, item.from, item.to) ?? [])\n : [timeToX(timeScale, item.from), timeToX(timeScale, item.to)];\n\n if (from === null || to === null) continue;\n\n const left = Math.max(0, from);\n const right = Math.min(mediaSize.width, to);\n\n if (right <= left) continue;\n\n const height = Math.min(\n mediaSize.height,\n item.style.height ?? Infinity,\n );\n\n paint(\n context,\n {\n x: left,\n y: (mediaSize.height - height) / 2,\n width: right - left,\n height,\n },\n item,\n );\n }\n });\n }\n}\n","import type {\n BandItem,\n BandAtPoint,\n BandStyleInput,\n BandLegendEntry,\n} from \"../types/bands.js\";\n\nimport {\n bandAt,\n bandKeys,\n sortBands,\n resolveBandStyles,\n} from \"../utils/bands.utils.js\";\n\nimport type { Theme } from \"../types/theme.js\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { TimeRangeOptions } from \"../types/timeline.js\";\nimport { useMemo, useRef, useEffect, useCallback } from \"react\";\nimport { TimeRangePrimitive } from \"../primitives/TimeRangePrimitive.js\";\n\nexport function useBands<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<unknown, { time: unknown }>,\n bands: ReadonlyArray<BandItem> | undefined,\n bandStyles: Record<string, BandStyleInput> | undefined,\n theme: Theme | null,\n) {\n const sorted = useMemo(() => (bands ? sortBands(bands) : null), [bands]);\n const styles = useMemo(\n () =>\n sorted ? resolveBandStyles(bandKeys(sorted), theme, bandStyles) : {},\n [sorted, theme, bandStyles],\n );\n const options = useMemo<TimeRangeOptions | null>(\n () =>\n sorted && {\n items: sorted.map(({ from, to, key }) => ({ from, to, key })),\n style: (key) => styles[key] ?? {},\n zOrder: \"bottom\",\n edges: \"between-bars\",\n },\n [sorted, styles],\n );\n const primitive = useRef<TimeRangePrimitive | null>(null);\n const applied = useRef<TimeRangeOptions | null>(null);\n const latest = useRef(options);\n const enabled = options !== null;\n latest.current = options;\n\n useEffect(() => {\n const pane = instance?.chart.panes()[0];\n\n if (!pane || !latest.current) return;\n\n const created = new TimeRangePrimitive(latest.current);\n\n pane.attachPrimitive(created);\n primitive.current = created;\n applied.current = latest.current;\n\n return () => {\n pane.detachPrimitive(created);\n primitive.current = null;\n };\n }, [instance, enabled]);\n\n useEffect(() => {\n if (!options || !primitive.current || applied.current === options) return;\n\n primitive.current.applyOptions(options);\n applied.current = options;\n }, [options]);\n\n const entries = useMemo<BandLegendEntry[]>(\n () =>\n Object.entries(styles).map(([key, style]) => ({\n key,\n label: style.label ?? key,\n fill: style.fill ?? \"\",\n legendColor: style.legendColor,\n })),\n [styles],\n );\n\n const bandOf = useCallback(\n (index: number): BandAtPoint | null => {\n const time = normalized.data[index]?.time;\n\n return sorted && typeof time === \"number\"\n ? bandAt(sorted, time, normalized.data, styles)\n : null;\n },\n [sorted, normalized, styles],\n );\n\n return { entries, bandOf: sorted ? bandOf : undefined };\n}\n","import {\n LineSeries,\n type SeriesType,\n type LineSeriesPartialOptions,\n} from \"lightweight-charts\";\n\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { normalizePoints } from \"../utils/data.utils.js\";\nimport { useEffect, useRef, type RefObject } from \"react\";\nimport { deepMerge, resetOptions } from \"../utils/merge.utils.js\";\nimport type { LineOverlay, OverlayEntry } from \"../types/series.js\";\n\nexport function useOverlays<T extends SeriesType>(\n instance: ChartInstance<T> | null,\n overlays: ReadonlyArray<LineOverlay> = [],\n): RefObject<OverlayEntry[]> {\n const entries = useRef<OverlayEntry[]>([]);\n\n useEffect(() => {\n entries.current = [];\n }, [instance]);\n\n useEffect(() => {\n if (!instance) return;\n\n const { chart } = instance;\n const list = entries.current;\n\n const create = (options: LineSeriesPartialOptions): OverlayEntry => {\n const series = chart.addSeries(LineSeries, options);\n\n return {\n series,\n defaults: deepMerge(series.options()),\n options,\n };\n };\n\n overlays.forEach((overlay, index) => {\n const next = overlay.seriesOptions ?? {};\n let entry = list[index];\n\n if (entry && entry.options !== next) {\n const options = resetOptions(entry.defaults, entry.options, next);\n\n if (options) {\n entry.series.applyOptions(options);\n entry.options = next;\n } else {\n chart.removeSeries(entry.series);\n entry = undefined;\n }\n }\n\n if (!entry) list[index] = entry = create(next);\n\n entry.series.setData(normalizePoints(overlay.data).data);\n });\n\n list\n .splice(overlays.length)\n .forEach((entry) => chart.removeSeries(entry.series));\n }, [instance, overlays]);\n\n return entries;\n}\n","import { toUnixSeconds } from \"./time.utils.js\";\nimport type { IRange } from \"lightweight-charts\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nconst MIN_VISIBLE_BARS = 2;\nconst ZOOM_SPEED = 0.002;\nexport const HALF_BAR = 0.5;\n\nexport function tickDirection<TPoint, TData>(\n previous: NormalizedSeries<TPoint, TData> | null,\n next: NormalizedSeries<TPoint, TData>,\n): \"up\" | \"down\" | null {\n if (!previous) return null;\n\n const before = previous.rows[previous.rows.length - 1];\n const after = next.rows[next.rows.length - 1];\n\n if (!before || !after) return null;\n\n const beforeTime = toUnixSeconds(before.time);\n const afterTime = toUnixSeconds(after.time);\n const secondLast = next.rows[next.rows.length - 2];\n\n const sameBar =\n next.rows.length === previous.rows.length && afterTime === beforeTime;\n const appended =\n next.rows.length === previous.rows.length + 1 &&\n secondLast !== undefined &&\n toUnixSeconds(secondLast.time) === beforeTime;\n\n if ((!sameBar && !appended) || after.close === before.close) return null;\n\n return after.close > before.close ? \"up\" : \"down\";\n}\n\nexport function flashColors(options: unknown): {\n up: string;\n down: string;\n} | null {\n if (options === null || typeof options !== \"object\") return null;\n\n const record = options as Record<string, unknown>;\n const up = record.upColor;\n const down = record.downColor;\n\n if (typeof up === \"string\" && typeof down === \"string\") return { up, down };\n\n const topLine = record.topLineColor;\n const bottomLine = record.bottomLineColor;\n\n if (typeof topLine === \"string\" && typeof bottomLine === \"string\")\n return { up: topLine, down: bottomLine };\n\n const color = record.color ?? record.lineColor;\n\n return typeof color === \"string\" ? { up: color, down: color } : null;\n}\n\nexport function zoomRange(\n range: IRange<number>,\n anchor: number,\n delta: number,\n): IRange<number> | null {\n const factor = Math.exp(delta * ZOOM_SPEED);\n\n if (!Number.isFinite(factor)) return null;\n\n const next = {\n from: anchor - (anchor - range.from) * factor,\n to: anchor + (range.to - anchor) * factor,\n };\n\n return next.to - next.from < MIN_VISIBLE_BARS ? null : next;\n}\n\nexport function wheelPixels(event: WheelEvent): number {\n const delta =\n Math.abs(event.deltaX) > Math.abs(event.deltaY)\n ? event.deltaX\n : event.deltaY;\n\n const scaled = event.deltaMode === 1 ? delta * 16 : delta;\n\n return Number.isFinite(scaled) ? scaled : 0;\n}\n\nexport function isLive(\n range: IRange<number> | null,\n lastIndex: number,\n): boolean {\n return range === null || lastIndex < 0 || range.to >= lastIndex - HALF_BAR;\n}\n","import { useEffect, type RefObject } from \"react\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { wheelPixels, zoomRange } from \"../utils/live.utils.js\";\n\nexport function useWheelZoom<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): void {\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element || !enabled) return;\n\n const { chart } = instance;\n const timeScale = chart.timeScale();\n\n const onWheel = (event: WheelEvent) => {\n const delta = wheelPixels(event);\n\n if (delta === 0) return;\n\n event.preventDefault();\n\n if (!event.ctrlKey) {\n const spacing = timeScale.options().barSpacing;\n timeScale.scrollToPosition(\n timeScale.scrollPosition() + delta / spacing,\n false,\n );\n return;\n }\n\n const rect = element.getBoundingClientRect();\n const x = event.clientX - rect.left - chart.priceScale(\"left\").width();\n const anchor = timeScale.coordinateToLogical(x);\n const range = timeScale.getVisibleLogicalRange();\n\n if (anchor === null || range === null) return;\n\n const next = zoomRange(range, anchor, delta);\n\n if (next) timeScale.setVisibleLogicalRange(next);\n };\n\n element.addEventListener(\"wheel\", onWheel, { passive: false });\n\n return () => element.removeEventListener(\"wheel\", onWheel);\n }, [instance, container, enabled]);\n}\n","export function nextBucketSize(\n current: number,\n pxPerRawBar: number,\n minBarWidth: number,\n rawCount: number,\n): number {\n if (!(pxPerRawBar > 0) || !Number.isFinite(pxPerRawBar)) return current;\n\n let next = current;\n\n if (!Number.isFinite(next) || next <= 0) return current;\n\n while (next < rawCount && pxPerRawBar * next < minBarWidth) next *= 2;\n while (next > 1 && pxPerRawBar * (next / 2) >= minBarWidth * 1.5) next /= 2;\n\n return next;\n}\n\nexport function buckets<T>(items: ReadonlyArray<T>, bucketSize: number): T[][] {\n if (!Number.isInteger(bucketSize) || bucketSize <= 0)\n throw new Error(\"bucketSize must be a positive integer\");\n\n const result: T[][] = [];\n\n for (let i = 0; i < items.length; i += bucketSize)\n result.push(items.slice(i, i + bucketSize));\n\n return result;\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { nextBucketSize } from \"../utils/bucket.utils.js\";\nimport type { AutoBucketOptions } from \"../types/chart.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nconst SETTLE_MS = 150;\nconst DEFAULT_MIN_BAR_WIDTH = 6;\n\nfunction minBarWidthOf(\n autoBucket: boolean | AutoBucketOptions | undefined,\n): number | null {\n if (!autoBucket) return null;\n if (autoBucket === true) return DEFAULT_MIN_BAR_WIDTH;\n\n return autoBucket.minBarWidth ?? DEFAULT_MIN_BAR_WIDTH;\n}\n\nexport function useAutoBucket<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n raw: NormalizedSeries<TPoint, TData>,\n autoBucket?: boolean | AutoBucketOptions,\n): number {\n const [bucketSize, setBucketSize] = useState(1);\n const minBarWidth = minBarWidthOf(autoBucket);\n const size = useRef(bucketSize);\n const rawCount = useRef(raw.points.length);\n size.current = bucketSize;\n rawCount.current = raw.points.length;\n\n useEffect(() => {\n if (!instance || minBarWidth === null) {\n setBucketSize(1);\n return;\n }\n\n const timeScale = instance.chart.timeScale();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let frame = 0;\n\n const measure = () => {\n const range = timeScale.getVisibleLogicalRange();\n const span = range ? range.to - range.from : 0;\n\n if (span <= 0) return;\n\n const pxPerRawBar = timeScale.width() / (span * size.current);\n setBucketSize(\n nextBucketSize(\n size.current,\n pxPerRawBar,\n minBarWidth,\n rawCount.current,\n ),\n );\n };\n const schedule = () => {\n clearTimeout(timer);\n cancelAnimationFrame(frame);\n timer = setTimeout(() => {\n frame = requestAnimationFrame(measure);\n }, SETTLE_MS);\n };\n\n timeScale.subscribeVisibleLogicalRangeChange(schedule);\n schedule();\n\n return () => {\n timeScale.unsubscribeVisibleLogicalRangeChange(schedule);\n clearTimeout(timer);\n cancelAnimationFrame(frame);\n };\n }, [instance, minBarWidth]);\n\n return bucketSize;\n}\n","import { useAutoBucket } from \"./useAutoBucket.js\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { SeriesChartProps } from \"../types/series.js\";\nimport type { AutoBucketOptions } from \"../types/chart.js\";\nimport type { SeriesType, SeriesDataItemTypeMap } from \"lightweight-charts\";\n\nexport function useSeriesData<\n TSeries extends SeriesType,\n TPoint,\n TData extends SeriesDataItemTypeMap[TSeries],\n>(\n instance: ChartInstance<TSeries> | null,\n data: ReadonlyArray<TPoint>,\n normalize: SeriesChartProps<TSeries, TPoint, TData>[\"normalize\"],\n aggregate: SeriesChartProps<TSeries, TPoint, TData>[\"aggregate\"],\n autoBucket: boolean | AutoBucketOptions | undefined,\n) {\n const raw = useMemo(() => normalize(data), [data, normalize]);\n const bucketSize = useAutoBucket(instance, raw, autoBucket);\n const normalized = useMemo(\n () =>\n bucketSize > 1 && aggregate\n ? normalize(aggregate(raw.points, bucketSize))\n : raw,\n [raw, bucketSize, normalize, aggregate],\n );\n const appliedBucket = useRef(bucketSize);\n\n useEffect(() => {\n if (!instance) return;\n\n const timeScale = instance.chart.timeScale();\n const ratio = appliedBucket.current / bucketSize;\n const keep = ratio !== 1 ? timeScale.getVisibleLogicalRange() : null;\n appliedBucket.current = bucketSize;\n\n instance.series.setData(normalized.data);\n if (keep)\n timeScale.setVisibleLogicalRange({\n from: (keep.from + 0.5) * ratio - 0.5,\n to: (keep.to + 0.5) * ratio - 0.5,\n });\n }, [instance, normalized, bucketSize]);\n\n return normalized;\n}\n","import type { ChartInstance } from \"../types/chart.js\";\nimport { HALF_BAR, isLive } from \"../utils/live.utils.js\";\nimport type { IRange, SeriesType } from \"lightweight-charts\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\n\nconst IDLE_MS = 3000;\nconst PAUSE_EVENTS = [\n \"pointermove\",\n \"pointerdown\",\n \"wheel\",\n \"keydown\",\n] as const;\n\nfunction sameRange(\n a: IRange<number> | null,\n b: IRange<number> | null,\n): boolean {\n if (a === null || b === null) return a === b;\n\n return (\n Math.abs(a.from - b.from) < HALF_BAR && Math.abs(a.to - b.to) < HALF_BAR\n );\n}\n\nexport function useLiveFollow<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n lastIndex: number,\n enabled: boolean,\n) {\n const [away, setAway] = useState(false);\n const lastIndexRef = useRef(lastIndex);\n lastIndexRef.current = lastIndex;\n\n useEffect(() => {\n if (!instance || !enabled) {\n setAway(false);\n return;\n }\n\n const timeScale = instance.chart.timeScale();\n const check = () =>\n setAway(!isLive(timeScale.getVisibleLogicalRange(), lastIndex));\n\n check();\n timeScale.subscribeVisibleLogicalRangeChange(check);\n\n return () => timeScale.unsubscribeVisibleLogicalRangeChange(check);\n }, [instance, enabled, lastIndex]);\n\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element || !enabled) return;\n\n const timeScale = instance.chart.timeScale();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let paused: {\n range: IRange<number> | null;\n wasLive: boolean;\n shift: boolean;\n } | null = null;\n\n const resume = () => {\n if (!paused) return;\n\n const { range, wasLive, shift } = paused;\n paused = null;\n timeScale.applyOptions({ shiftVisibleRangeOnNewBar: shift });\n\n if (\n wasLive &&\n shift &&\n sameRange(range, timeScale.getVisibleLogicalRange())\n )\n timeScale.scrollToRealTime();\n };\n\n const touch = () => {\n if (!paused) {\n const range = timeScale.getVisibleLogicalRange();\n paused = {\n range,\n wasLive: isLive(range, lastIndexRef.current),\n shift: timeScale.options().shiftVisibleRangeOnNewBar,\n };\n timeScale.applyOptions({ shiftVisibleRangeOnNewBar: false });\n }\n\n clearTimeout(timer);\n timer = setTimeout(resume, IDLE_MS);\n };\n\n PAUSE_EVENTS.forEach((type) =>\n element.addEventListener(type, touch, { passive: true }),\n );\n\n return () => {\n clearTimeout(timer);\n PAUSE_EVENTS.forEach((type) => element.removeEventListener(type, touch));\n if (paused)\n timeScale.applyOptions({ shiftVisibleRangeOnNewBar: paused.shift });\n };\n }, [instance, container, enabled]);\n\n return {\n away,\n jumpToLive: () => instance?.chart.timeScale().scrollToRealTime(),\n };\n}\n","import type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { useEffect, useRef, type RefObject } from \"react\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport { prefersReducedMotion } from \"../utils/motion.utils.js\";\nimport { flashColors, tickDirection } from \"../utils/live.utils.js\";\n\nconst FLASH_MS = 600;\nconst LABEL_PADDING = 8;\n\nexport function usePriceFlash<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n flash: RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): void {\n const previous = useRef<NormalizedSeries<TPoint, TData> | null>(null);\n\n useEffect(() => {\n const before = previous.current;\n previous.current = normalized;\n\n const element = flash.current;\n const direction = tickDirection(before, normalized);\n const last = normalized.rows[normalized.rows.length - 1];\n\n if (!instance || !element || !enabled || !direction || !last) return;\n if (typeof element.animate !== \"function\" || prefersReducedMotion()) return;\n\n const { chart, series } = instance;\n\n const frame = requestAnimationFrame(() => {\n const y = series.priceToCoordinate(last.close);\n const width = chart.priceScale(\"right\").width();\n const colors = flashColors(series.options());\n\n if (y === null || width === 0 || colors === null) return;\n\n const height = chart.options().layout.fontSize + LABEL_PADDING;\n\n element.style.width = `${width}px`;\n element.style.height = `${height}px`;\n element.style.transform = `translateY(${y - height / 2}px)`;\n element.style.background = direction === \"up\" ? colors.up : colors.down;\n element.animate([{ opacity: 0.9 }, { opacity: 0 }], {\n duration: FLASH_MS,\n easing: \"ease-out\",\n });\n });\n\n return () => cancelAnimationFrame(frame);\n }, [instance, normalized, flash, enabled]);\n}\n","import { useEffect } from \"react\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { SeriesType, CreatePriceLineOptions } from \"lightweight-charts\";\n\nconst NO_LINES: ReadonlyArray<CreatePriceLineOptions> = [];\n\nexport function usePriceLines<T extends SeriesType>(\n instance: ChartInstance<T> | null,\n lines: ReadonlyArray<CreatePriceLineOptions> = NO_LINES,\n): void {\n useEffect(() => {\n if (!instance) return;\n\n const { series } = instance;\n const created = lines.map((line) => series.createPriceLine(line));\n\n return () => created.forEach((line) => series.removePriceLine(line));\n }, [instance, lines]);\n}\n","import {\n themedLine,\n referenceLine,\n chartOptionsFromTheme,\n} from \"../utils/theme.utils.js\";\n\nimport type {\n DeepPartial,\n ChartOptions,\n LineSeriesPartialOptions,\n} from \"lightweight-charts\";\n\nimport { useMemo } from \"react\";\nimport type { Theme } from \"../types/theme.js\";\nimport { deepMerge } from \"../utils/merge.utils.js\";\nimport type { SeriesThemeInputs } from \"../types/series.js\";\n\nexport function useSeriesTheme(\n resolved: Theme | null,\n {\n magnet,\n magnetMode,\n ctrlWheelZoom,\n chartOptions,\n anchorLine,\n overlays,\n }: SeriesThemeInputs,\n) {\n const options = useMemo(\n () =>\n deepMerge<DeepPartial<ChartOptions>>(\n chartOptionsFromTheme(resolved),\n magnet && { crosshair: { mode: magnetMode } },\n ctrlWheelZoom && {\n handleScale: { mouseWheel: false },\n handleScroll: { mouseWheel: false },\n },\n chartOptions,\n ),\n [resolved, magnet, magnetMode, ctrlWheelZoom, chartOptions],\n );\n const themedAnchorLine = useMemo(\n () =>\n themedLine(\n referenceLine(resolved, resolved?.anchor, undefined),\n anchorLine,\n ),\n [resolved, anchorLine],\n );\n const themedOverlays = useMemo(() => {\n const colors = resolved?.line.overlays;\n\n return colors?.length && overlays\n ? overlays.map((overlay, i) => ({\n ...overlay,\n seriesOptions: deepMerge<LineSeriesPartialOptions>(\n { color: colors[i % colors.length] },\n overlay.seriesOptions,\n ),\n }))\n : overlays;\n }, [resolved, overlays]);\n\n return { options, themedAnchorLine, themedOverlays };\n}\n","import type { RangePreset } from \"../types/chart.js\";\n\nconst DAY = 86_400;\n\nfunction monthsBefore(seconds: number, months: number): number {\n const date = new Date(seconds * 1000);\n const target = new Date(\n Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - months + 1, 0),\n );\n\n target.setUTCDate(Math.min(date.getUTCDate(), target.getUTCDate()));\n target.setUTCHours(\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n );\n\n return target.getTime() / 1000;\n}\n\nfunction startOf(preset: RangePreset, last: number): number | null {\n switch (preset) {\n case \"1D\":\n return last - DAY;\n case \"1W\":\n return last - 7 * DAY;\n case \"1M\":\n return monthsBefore(last, 1);\n case \"3M\":\n return monthsBefore(last, 3);\n case \"1Y\":\n return monthsBefore(last, 12);\n case \"3Y\":\n return monthsBefore(last, 36);\n case \"5Y\":\n return monthsBefore(last, 60);\n case \"YTD\":\n return Date.UTC(new Date(last * 1000).getUTCFullYear(), 0, 1) / 1000;\n case \"All\":\n return null;\n }\n}\n\nexport function presetRange(\n first: number,\n last: number,\n preset: RangePreset,\n): { from: number; to: number } | null {\n const from = startOf(preset, last);\n\n if (from === null || from <= first) return null;\n\n return { from, to: last };\n}\n","import { useEffect, useRef } from \"react\";\nimport type { RangePreset } from \"../types/chart.js\";\nimport { presetRange } from \"../utils/range.utils.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { toUnixSeconds } from \"../utils/time.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { SeriesType, UTCTimestamp } from \"lightweight-charts\";\n\nexport function useRangePreset<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n range?: RangePreset,\n): void {\n const current = useRef(normalized);\n const hasData = normalized.data.length > 0;\n current.current = normalized;\n\n useEffect(() => {\n if (!instance || !range || !hasData) return;\n\n const rows = current.current.rows;\n const timeScale = instance.chart.timeScale();\n const first = rows[0];\n const last = rows[rows.length - 1];\n\n if (!first || !last) return;\n\n const from = toUnixSeconds(first.time);\n const to = toUnixSeconds(last.time);\n\n if (from === null || to === null) return;\n\n const target = presetRange(from, to, range);\n\n if (!target) {\n timeScale.fitContent();\n return;\n }\n\n timeScale.setVisibleRange({\n from: target.from as UTCTimestamp,\n to: target.to as UTCTimestamp,\n });\n }, [instance, range, hasData]);\n}\n","import type { SeriesRow } from \"../types/series.js\";\nimport type { VisibleStats } from \"../types/chart.js\";\n\nexport function percent(from: number, to: number): number | null {\n return from !== 0 ? ((to - from) / from) * 100 : null;\n}\n\nexport function highLow(rows: ReadonlyArray<{ high: number; low: number }>): {\n high: number;\n low: number;\n} {\n let { high, low } = rows[0]!;\n\n for (const row of rows) {\n if (row.high > high) high = row.high;\n if (row.low < low) low = row.low;\n }\n\n return { high, low };\n}\n\nexport function visibleStats(\n rows: ReadonlyArray<SeriesRow>,\n from: number,\n to: number,\n): VisibleStats | null {\n const start = Math.max(0, Math.ceil(from));\n const end = Math.min(rows.length - 1, Math.floor(to));\n const first = rows[start];\n const last = rows[end];\n\n if (start > end || !first || !last) return null;\n\n return {\n from: first.time,\n to: last.time,\n open: first.open,\n ...highLow(rows.slice(start, end + 1)),\n close: last.close,\n change: percent(first.open, last.close),\n bars: end - start + 1,\n };\n}\n","import type { ChartInstance } from \"../types/chart.js\";\nimport { visibleStats } from \"../utils/stats.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { Logical, SeriesType } from \"lightweight-charts\";\nimport type { RangeSelectOptions } from \"../types/interaction.js\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\n\nconst MIN_DRAG = 3;\n\nexport function useRangeSelect<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n rect: RefObject<HTMLDivElement | null>,\n normalized: NormalizedSeries<unknown, unknown>,\n options: RangeSelectOptions,\n): boolean {\n const [selecting, setSelecting] = useState(false);\n const latest = useRef({ normalized, options });\n latest.current = { normalized, options };\n\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element) return;\n\n const { chart } = instance;\n const timeScale = chart.timeScale();\n let start: number | null = null;\n let end = 0;\n\n const plotX = (event: MouseEvent) =>\n event.clientX -\n element.getBoundingClientRect().left -\n chart.priceScale(\"left\").width();\n\n const paint = () => {\n const box = rect.current;\n const left = Math.min(start ?? 0, end);\n\n if (!box) return;\n\n box.style.display = \"block\";\n box.style.left = `${left + chart.priceScale(\"left\").width()}px`;\n box.style.width = `${Math.abs(end - (start ?? 0))}px`;\n box.style.height = `${chart.paneSize().height}px`;\n };\n\n const stop = () => {\n start = null;\n setSelecting(false);\n window.removeEventListener(\"mousemove\", onMove);\n window.removeEventListener(\"mouseup\", onUp);\n window.removeEventListener(\"keydown\", onKey);\n };\n\n const onMove = (event: MouseEvent) => {\n end = plotX(event);\n paint();\n };\n\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") stop();\n };\n\n const onUp = (event: MouseEvent) => {\n const from = Math.min(start ?? 0, plotX(event));\n const to = Math.max(start ?? 0, plotX(event));\n\n stop();\n if (to - from < MIN_DRAG) return;\n\n const fromLogical = timeScale.coordinateToLogical(from);\n const toLogical = timeScale.coordinateToLogical(to);\n const stats =\n fromLogical === null || toLogical === null\n ? null\n : visibleStats(\n latest.current.normalized.rows,\n fromLogical,\n toLogical,\n );\n\n if (!stats || fromLogical === null || toLogical === null) return;\n\n timeScale.setVisibleLogicalRange({\n from: (fromLogical - 0.5) as Logical,\n to: (toLogical + 0.5) as Logical,\n });\n latest.current.options.onRangeSelect?.(stats);\n };\n\n const onDown = (event: MouseEvent) => {\n if (!latest.current.options.enabled || !event.shiftKey) return;\n if (event.button !== 0) return;\n\n event.preventDefault();\n event.stopPropagation();\n start = end = plotX(event);\n setSelecting(true);\n window.addEventListener(\"mousemove\", onMove);\n window.addEventListener(\"mouseup\", onUp);\n window.addEventListener(\"keydown\", onKey);\n };\n\n const onDoubleClick = () => {\n if (!latest.current.options.reset) return;\n\n timeScale.fitContent();\n latest.current.options.onReset?.();\n };\n\n element.addEventListener(\"mousedown\", onDown, true);\n element.addEventListener(\"dblclick\", onDoubleClick);\n\n return () => {\n stop();\n element.removeEventListener(\"mousedown\", onDown, true);\n element.removeEventListener(\"dblclick\", onDoubleClick);\n };\n }, [instance, container, rect]);\n\n return selecting;\n}\n","import { percent } from \"./stats.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { BandAtPoint } from \"../types/bands.js\";\nimport type { TooltipBox, SeriesSummary } from \"../types/interaction.js\";\n\nexport function toSeriesSummary<TPoint>(\n { points, rows }: NormalizedSeries<TPoint, unknown>,\n index: number,\n anchorIndex: number | null,\n bandOf?: (index: number) => BandAtPoint | null,\n): SeriesSummary<TPoint> | null {\n const point = points[index];\n const row = rows[index];\n\n if (point === undefined || !row) return null;\n\n const previous = rows[index - 1];\n const anchor = anchorIndex === null ? undefined : rows[anchorIndex];\n const band = bandOf?.(index);\n\n return {\n point,\n index,\n change: previous ? percent(previous.close, row.close) : null,\n fromAnchor:\n anchor && anchorIndex !== null\n ? {\n change: percent(anchor.close, row.close),\n bars: index - anchorIndex,\n }\n : null,\n ...(band && { band }),\n };\n}\n\nexport function tooltipTransform({\n x,\n y,\n gap,\n offset,\n width,\n height,\n}: TooltipBox): string {\n const flipX = x > width / 2;\n const left = offset + x + (flipX ? -gap : gap);\n\n return `translate(calc(${left}px - ${flipX ? 100 : 0}%), calc(${y}px - ${y > height / 2 ? 100 : 0}%))`;\n}\n","import { useEffect, useMemo } from \"react\";\nimport type { Time } from \"../types/chart.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { toUnixSeconds } from \"../utils/time.utils.js\";\nimport { indexAtOrBefore } from \"../utils/data.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { SeriesType, PriceLineOptions } from \"lightweight-charts\";\n\nconst DEFAULT_LINE: Partial<PriceLineOptions> = { title: \"Anchor\" };\n\nexport function useAnchor<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n anchor?: Time | null,\n line: Partial<PriceLineOptions> | false = DEFAULT_LINE,\n): number | null {\n const time = anchor == null ? null : toUnixSeconds(anchor);\n const index = useMemo(\n () => (time === null ? null : indexAtOrBefore(normalized.rows, time)),\n [normalized, time],\n );\n const price = index === null ? null : (normalized.rows[index]?.close ?? null);\n\n useEffect(() => {\n if (!instance || price === null || line === false) return;\n\n const { series } = instance;\n const created = series.createPriceLine({\n ...DEFAULT_LINE,\n ...line,\n price,\n });\n\n return () => series.removePriceLine(created);\n }, [instance, price, line]);\n\n return index;\n}\n","import type {\n SeriesPointEvent,\n PointEventHandlers,\n} from \"../types/interaction.js\";\n\nimport type { ChartInstance } from \"../types/chart.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport { useRef, useState, useEffect, useCallback } from \"react\";\nimport type { Time, SeriesType, MouseEventParams } from \"lightweight-charts\";\n\nexport function useChartEvents<TSeries extends SeriesType, TPoint>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<unknown, { time: Time }>,\n handlers: PointEventHandlers<TPoint>,\n build: (\n index: number,\n coordinate: { x: number; y: number },\n price: number | null,\n ) => SeriesPointEvent<TPoint> | null,\n track: boolean,\n onSelect?: (index: number) => void,\n) {\n const handlersRef = useRef(handlers);\n const selectRef = useRef(onSelect);\n const hovered = useRef<number | null>(null);\n const stale = useRef(false);\n const [active, setActive] = useState<number | null>(null);\n\n useEffect(() => {\n handlersRef.current = handlers;\n selectRef.current = onSelect;\n });\n\n const activate = useCallback(\n (index: number | null, event: SeriesPointEvent<TPoint> | null = null) => {\n if (index === hovered.current && (index === null || !stale.current))\n return;\n hovered.current = index;\n stale.current = false;\n if (track) setActive(index);\n if (index === null) handlersRef.current.onPointLeave?.();\n else if (event) handlersRef.current.onPointHover?.(event);\n },\n [track],\n );\n\n const select = useCallback((event: SeriesPointEvent<TPoint> | null) => {\n if (!event) return;\n handlersRef.current.onPointClick?.(event);\n selectRef.current?.(event.index);\n }, []);\n\n const eventAt = useCallback(\n (index: number): SeriesPointEvent<TPoint> | null => {\n const bar = normalized.data[index];\n const row = normalized.rows[index];\n\n if (!instance || !bar || !row) return null;\n\n const x = instance.chart.timeScale().timeToCoordinate(bar.time);\n const y = instance.series.priceToCoordinate(row.close);\n\n return x === null || y === null\n ? null\n : build(index, { x, y }, row.close);\n },\n [instance, normalized, build],\n );\n\n useEffect(() => {\n if (!instance) return;\n const { chart, series } = instance;\n stale.current = true;\n\n const fromParam = (\n param: MouseEventParams,\n ): SeriesPointEvent<TPoint> | null => {\n if (typeof param.time !== \"number\" || !param.point) return null;\n\n const index = normalized.indexByTime.get(param.time);\n\n return index === undefined\n ? null\n : build(\n index,\n { x: param.point.x, y: param.point.y },\n series.coordinateToPrice(param.point.y),\n );\n };\n\n const onMove = (param: MouseEventParams) => {\n const event = fromParam(param);\n activate(event ? event.index : null, event);\n };\n\n const onClick = (param: MouseEventParams) => select(fromParam(param));\n\n chart.subscribeCrosshairMove(onMove);\n chart.subscribeClick(onClick);\n\n return () => {\n chart.unsubscribeCrosshairMove(onMove);\n chart.unsubscribeClick(onClick);\n };\n }, [instance, normalized, build, activate, select]);\n\n return { active, hovered, activate, select, eventAt };\n}\n","import { HALF_BAR } from \"../utils/live.utils.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { useRef, useEffect, type RefObject } from \"react\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { Time, SeriesType } from \"lightweight-charts\";\nimport type { KeyboardActions } from \"../types/interaction.js\";\n\nexport function useKeyboardNav<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n normalized: NormalizedSeries<unknown, { time: Time }>,\n enabled: boolean,\n actions: KeyboardActions,\n): void {\n const actionsRef = useRef(actions);\n\n useEffect(() => {\n actionsRef.current = actions;\n });\n\n useEffect(() => {\n const element = container.current;\n\n if (!instance || !element || !enabled) return;\n\n const { chart, series } = instance;\n const last = normalized.data.length - 1;\n let driving = false;\n\n const reveal = (index: number) => {\n const timeScale = chart.timeScale();\n const range = timeScale.getVisibleLogicalRange();\n\n if (!range) return;\n\n const shift =\n index - HALF_BAR < range.from\n ? index - HALF_BAR - range.from\n : index + HALF_BAR > range.to\n ? index + HALF_BAR - range.to\n : 0;\n\n if (shift !== 0)\n timeScale.setVisibleLogicalRange({\n from: range.from + shift,\n to: range.to + shift,\n });\n };\n\n const goTo = (index: number) => {\n const bar = normalized.data[index];\n const row = normalized.rows[index];\n\n if (!bar || !row) return;\n\n driving = true;\n reveal(index);\n chart.setCrosshairPosition(row.close, bar.time, series);\n actionsRef.current.move(index);\n };\n\n const release = () => {\n driving = false;\n chart.clearCrosshairPosition();\n actionsRef.current.move(null);\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.altKey || event.ctrlKey || event.metaKey || last < 0) return;\n\n const current = actionsRef.current.current();\n const step = (delta: number) =>\n current === null ? last : Math.min(last, Math.max(0, current + delta));\n\n switch (event.key) {\n case \"ArrowLeft\":\n goTo(step(-1));\n break;\n case \"ArrowRight\":\n goTo(step(1));\n break;\n case \"Home\":\n goTo(0);\n break;\n case \"End\":\n goTo(last);\n break;\n case \"Enter\":\n case \" \":\n if (current === null) return;\n actionsRef.current.select(current);\n break;\n case \"Escape\":\n release();\n actionsRef.current.clear();\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const onBlur = () => {\n if (driving) release();\n };\n\n const onPointerMove = () => {\n driving = false;\n };\n\n element.addEventListener(\"keydown\", onKeyDown);\n element.addEventListener(\"blur\", onBlur);\n element.addEventListener(\"pointermove\", onPointerMove);\n\n return () => {\n element.removeEventListener(\"keydown\", onKeyDown);\n element.removeEventListener(\"blur\", onBlur);\n element.removeEventListener(\"pointermove\", onPointerMove);\n };\n }, [instance, container, normalized, enabled]);\n}\n","import type { SeriesType } from \"lightweight-charts\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { useEffect, useCallback, type RefObject } from \"react\";\nimport type { Time, MouseEventParams } from \"lightweight-charts\";\n\nexport function useCrosshairBand<TSeries extends SeriesType>(\n instance: ChartInstance<TSeries> | null,\n band: RefObject<HTMLDivElement | null>,\n enabled: boolean,\n): (time: Time | null) => void {\n const place = useCallback(\n (time: Time | null) => {\n const element = band.current;\n\n if (!instance || !element || !enabled) return;\n\n const { chart } = instance;\n const x = time === null ? null : chart.timeScale().timeToCoordinate(time);\n\n if (x === null) {\n element.style.display = \"none\";\n return;\n }\n\n const width = Math.max(1, chart.timeScale().options().barSpacing);\n const left = chart.priceScale(\"left\").width() + x - width / 2;\n\n element.style.display = \"block\";\n element.style.width = `${width}px`;\n element.style.height = `${chart.paneSize().height}px`;\n element.style.transform = `translateX(${left}px)`;\n element.style.background = chart.options().crosshair.vertLine.color;\n },\n [instance, band, enabled],\n );\n\n useEffect(() => {\n if (!instance || !enabled) return;\n\n const { chart } = instance;\n const onMove = (param: MouseEventParams) =>\n place(param.time === undefined || !param.point ? null : param.time);\n\n chart.subscribeCrosshairMove(onMove);\n\n return () => {\n chart.unsubscribeCrosshairMove(onMove);\n place(null);\n };\n }, [instance, enabled, place]);\n\n return place;\n}\n","import type {\n Interactions,\n SeriesPointEvent,\n InteractionOptions,\n} from \"../types/interaction.js\";\n\nimport {\n tooltipTransform,\n toSeriesSummary,\n} from \"../utils/interaction.utils.js\";\n\nimport { useAnchor } from \"./useAnchor.js\";\nimport { useChartEvents } from \"./useChartEvents.js\";\nimport { useKeyboardNav } from \"./useKeyboardNav.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { indexAtOrBefore } from \"../utils/data.utils.js\";\nimport { useCrosshairBand } from \"./useCrosshairBand.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\nimport type { Time, SeriesType } from \"lightweight-charts\";\nimport { useMemo, useState, useCallback, type RefObject } from \"react\";\n\nconst KEYS = \"ArrowLeft ArrowRight Home End Enter Escape Space\";\nconst TOOLTIP_GAP = 8;\n\nfunction tooltipAt<TSeries extends SeriesType>(\n { chart, series }: ChartInstance<TSeries>,\n normalized: NormalizedSeries<unknown, { time: Time }>,\n index: number,\n): string | null {\n const bar = normalized.data[index];\n const row = normalized.rows[index];\n\n if (!bar || !row) return null;\n\n const timeScale = chart.timeScale();\n const x = timeScale.timeToCoordinate(bar.time);\n const y = series.priceToCoordinate(row.high);\n\n if (x === null || y === null) return null;\n\n return tooltipTransform({\n x,\n y,\n gap: timeScale.options().barSpacing / 2 + TOOLTIP_GAP,\n offset: chart.priceScale(\"left\").width(),\n ...chart.paneSize(),\n });\n}\n\nexport function useInteractions<TSeries extends SeriesType, TPoint>(\n instance: ChartInstance<TSeries> | null,\n container: RefObject<HTMLDivElement | null>,\n band: RefObject<HTMLDivElement | null>,\n normalized: NormalizedSeries<TPoint, { time: Time }>,\n options: InteractionOptions<TPoint>,\n): Interactions<TPoint> {\n const { anchor, anchorLine, magnet, pinOnClick, keyboard } = options;\n const { legend, tooltip, handlers, bandOf } = options;\n const [pinned, setPinned] = useState<number | null>(null);\n const pinnedTime = pinOnClick ? pinned : null;\n const pinnedIndex = useMemo(\n () =>\n pinnedTime === null ? null : indexAtOrBefore(normalized.data, pinnedTime),\n [normalized, pinnedTime],\n );\n const anchorIndex = useAnchor(\n instance,\n normalized,\n anchor !== undefined ? anchor : pinnedTime,\n anchorLine,\n );\n\n const build = useCallback(\n (\n index: number,\n coordinate: { x: number; y: number },\n price: number | null,\n ): SeriesPointEvent<TPoint> | null => {\n const summary = toSeriesSummary(normalized, index, anchorIndex, bandOf);\n return summary && { ...summary, price, coordinate };\n },\n [normalized, anchorIndex, bandOf],\n );\n\n const events = useChartEvents(\n instance,\n normalized,\n handlers,\n build,\n legend || tooltip,\n pinOnClick\n ? (index) =>\n setPinned(\n index === pinnedIndex\n ? null\n : ((normalized.data[index]?.time as number | undefined) ?? null),\n )\n : undefined,\n );\n const placeBand = useCrosshairBand(instance, band, magnet);\n\n useKeyboardNav(instance, container, normalized, keyboard, {\n current: () => events.hovered.current ?? pinnedIndex,\n move: (index) => {\n placeBand(index === null ? null : (normalized.data[index]?.time ?? null));\n events.activate(index, index === null ? null : events.eventAt(index));\n },\n select: (index) => events.select(events.eventAt(index)),\n clear: () => setPinned(null),\n });\n\n const { active } = events;\n const legendSummary = legend\n ? toSeriesSummary(\n normalized,\n active ?? pinnedIndex ?? normalized.data.length - 1,\n anchorIndex,\n bandOf,\n )\n : null;\n const tipSummary =\n tooltip && active !== null\n ? toSeriesSummary(normalized, active, anchorIndex, bandOf)\n : null;\n const transform =\n tipSummary !== null && instance && active !== null\n ? tooltipAt(instance, normalized, active)\n : null;\n\n return {\n container: keyboard\n ? { role: \"application\", tabIndex: 0, \"aria-keyshortcuts\": KEYS }\n : { role: \"img\" },\n legend:\n legendSummary === null\n ? null\n : {\n summary: legendSummary,\n source:\n active !== null\n ? \"hover\"\n : pinnedIndex !== null\n ? \"pinned\"\n : \"last\",\n },\n tooltip:\n tipSummary === null || transform === null\n ? null\n : { summary: tipSummary, transform },\n };\n}\n","import { useEffect, useRef } from \"react\";\nimport type { SeriesType } from \"lightweight-charts\";\nimport type { VisibleStats } from \"../types/chart.js\";\nimport type { ChartInstance } from \"../types/chart.js\";\nimport { visibleStats } from \"../utils/stats.utils.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nexport function useVisibleStats<TSeries extends SeriesType, TPoint, TData>(\n instance: ChartInstance<TSeries> | null,\n normalized: NormalizedSeries<TPoint, TData>,\n onChange?: (stats: VisibleStats | null) => void,\n): void {\n const handler = useRef(onChange);\n const enabled = onChange !== undefined;\n handler.current = onChange;\n\n useEffect(() => {\n if (!instance || !enabled) return;\n\n const timeScale = instance.chart.timeScale();\n let frame = 0;\n\n const emit = () => {\n frame = 0;\n const range = timeScale.getVisibleLogicalRange();\n handler.current?.(\n range ? visibleStats(normalized.rows, range.from, range.to) : null,\n );\n };\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(emit);\n };\n\n timeScale.subscribeVisibleLogicalRangeChange(schedule);\n schedule();\n\n return () => {\n timeScale.unsubscribeVisibleLogicalRangeChange(schedule);\n cancelAnimationFrame(frame);\n };\n }, [instance, normalized, enabled]);\n}\n","import {\n BAND_MARK,\n BAND_LEGEND,\n BAND_LEGEND_ITEM,\n} from \"../../styles/seriesChart.js\";\n\nimport { textStyle } from \"../../utils/theme.utils.js\";\nimport type { BandLegendProps } from \"../../types/bands.js\";\n\nexport function BandLegend({\n entries,\n render,\n theme,\n className,\n style,\n}: BandLegendProps) {\n if (render === null || entries.length === 0) return null;\n if (render) return <>{render([...entries])}</>;\n\n const border = theme ? `1px solid ${theme.palette.border}` : \"1px solid\";\n\n return (\n <ul\n data-part=\"band-legend\"\n className={className}\n style={{\n ...BAND_LEGEND,\n ...textStyle(theme?.typography.label),\n ...style,\n }}\n >\n {entries.map(({ key, label, fill, legendColor }) => (\n <li key={key} data-part=\"band-legend-item\" style={BAND_LEGEND_ITEM}>\n <span\n aria-hidden=\"true\"\n style={{\n ...BAND_MARK,\n background: legendColor ?? fill,\n border: legendColor ? \"none\" : border,\n }}\n />\n {label}\n </li>\n ))}\n </ul>\n );\n}\n","import type { CSSProperties } from \"react\";\nimport { TOOLTIP } from \"../../styles/shared.js\";\nimport type { InteractionSlotsProps } from \"../../types/interaction.js\";\n\nconst LEGEND: CSSProperties = {\n position: \"absolute\",\n inset: 0,\n pointerEvents: \"none\",\n};\n\nexport function InteractionSlots<TPoint>({\n interactions: { legend, tooltip },\n renderLegend,\n renderTooltip,\n}: InteractionSlotsProps<TPoint>) {\n return (\n <>\n {legend && renderLegend && (\n <div style={LEGEND} aria-live=\"polite\" aria-atomic=\"true\">\n {renderLegend(legend)}\n </div>\n )}\n {tooltip && renderTooltip && (\n <div\n style={{ ...TOOLTIP, transform: tooltip.transform }}\n aria-live={renderLegend ? undefined : \"polite\"}\n aria-atomic={renderLegend ? undefined : true}\n aria-hidden={renderLegend ? true : undefined}\n >\n {renderTooltip(tooltip.summary)}\n </div>\n )}\n </>\n );\n}\n","import {\n useRef,\n forwardRef,\n type ForwardedRef,\n type ReactElement,\n useImperativeHandle,\n} from \"react\";\n\nimport {\n CrosshairMode,\n type SeriesType,\n type SeriesDataItemTypeMap,\n} from \"lightweight-charts\";\n\nimport type {\n SeriesChartProps,\n SeriesChartHandle,\n} from \"../../types/series.js\";\n\nimport {\n BAND,\n FILL,\n PILL,\n FLASH,\n WRAPPER,\n RANGE_SELECT,\n PILL_POSITION,\n} from \"../../styles/seriesChart.js\";\n\nimport { useChart } from \"../../hooks/useChart.js\";\nimport { useBands } from \"../../hooks/useBands.js\";\nimport { withAlpha } from \"../../utils/theme.utils.js\";\nimport { useOverlays } from \"../../hooks/useOverlays.js\";\nimport { useWheelZoom } from \"../../hooks/useWheelZoom.js\";\nimport { useSeriesData } from \"../../hooks/useSeriesData.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { useLiveFollow } from \"../../hooks/useLiveFollow.js\";\nimport { usePriceFlash } from \"../../hooks/usePriceFlash.js\";\nimport { usePriceLines } from \"../../hooks/usePriceLines.js\";\nimport { useSeriesTheme } from \"../../hooks/useSeriesTheme.js\";\nimport { useRangePreset } from \"../../hooks/useRangePreset.js\";\nimport { useRangeSelect } from \"../../hooks/useRangeSelect.js\";\nimport { useInteractions } from \"../../hooks/useInteractions.js\";\nimport { useVisibleStats } from \"../../hooks/useVisibleStats.js\";\nimport { BandLegend } from \"../../components/BandLegend/index.js\";\nimport { InteractionSlots } from \"../../components/InteractionSlots/index.js\";\n\nfunction SeriesChartInner<\n TSeries extends SeriesType,\n TPoint,\n TData extends SeriesDataItemTypeMap[TSeries],\n>(\n {\n data,\n definition,\n normalize,\n aggregate,\n magnetMode = CrosshairMode.MagnetOHLC,\n chartOptions,\n seriesOptions,\n className,\n ariaLabel = \"Chart\",\n liveButtonClassName,\n liveButtonLabel = \"Jump to live\",\n magnet = true,\n flashLastPrice = true,\n followLive = true,\n ctrlWheelZoom = true,\n renderLegend,\n renderTooltip,\n pinOnClick = false,\n keyboard = false,\n range,\n anchor,\n anchorLine,\n autoBucket,\n onVisibleStatsChange,\n onPointClick,\n onPointHover,\n onPointLeave,\n overlays,\n priceLines,\n bands,\n bandStyles,\n renderBandLegend,\n classNames = {},\n styles = {},\n rangeSelect = true,\n doubleClickReset = true,\n onRangeSelect,\n onReset,\n theme,\n unstyled,\n }: SeriesChartProps<TSeries, TPoint, TData>,\n ref: ForwardedRef<SeriesChartHandle<TSeries> | null>,\n): ReactElement {\n const container = useRef<HTMLDivElement>(null);\n const band = useRef<HTMLDivElement>(null);\n const flash = useRef<HTMLDivElement>(null);\n const selection = useRef<HTMLDivElement>(null);\n const resolved = useChartTheme({ theme, unstyled });\n const { options, themedAnchorLine, themedOverlays } = useSeriesTheme(\n resolved,\n { magnet, magnetMode, ctrlWheelZoom, chartOptions, anchorLine, overlays },\n );\n const instance = useChart(container, definition, options, seriesOptions);\n const normalized = useSeriesData(\n instance,\n data,\n normalize,\n aggregate,\n autoBucket,\n );\n\n const overlaySeries = useOverlays(instance, themedOverlays);\n const { entries, bandOf } = useBands(\n instance,\n normalized,\n bands,\n bandStyles,\n resolved,\n );\n usePriceLines(instance, priceLines);\n useRangePreset(instance, normalized, range);\n useVisibleStats(instance, normalized, onVisibleStatsChange);\n\n const interactions = useInteractions(instance, container, band, normalized, {\n anchor,\n anchorLine: themedAnchorLine,\n magnet,\n pinOnClick,\n keyboard,\n legend: renderLegend !== undefined,\n tooltip: renderTooltip !== undefined,\n handlers: { onPointClick, onPointHover, onPointLeave },\n bandOf,\n });\n usePriceFlash(instance, normalized, flash, flashLastPrice);\n const selecting = useRangeSelect(instance, container, selection, normalized, {\n enabled: rangeSelect,\n reset: doubleClickReset,\n onRangeSelect,\n onReset,\n });\n useWheelZoom(instance, container, ctrlWheelZoom);\n\n const { away, jumpToLive } = useLiveFollow(\n instance,\n container,\n normalized.rows.length - 1,\n followLive,\n );\n\n useImperativeHandle<\n SeriesChartHandle<TSeries> | null,\n SeriesChartHandle<TSeries> | null\n >(\n ref,\n () =>\n instance\n ? {\n chart: instance.chart,\n series: instance.series,\n get overlays() {\n return overlaySeries.current.map((entry) => entry.series);\n },\n }\n : null,\n [instance, overlaySeries],\n );\n\n return (\n <div className={className} style={WRAPPER}>\n <div\n ref={container}\n style={FILL}\n aria-label={ariaLabel}\n {...interactions.container}\n />\n <div ref={band} style={BAND} aria-hidden=\"true\" />\n <BandLegend\n entries={entries}\n render={renderBandLegend}\n theme={resolved}\n className={classNames.bandLegend}\n style={styles.bandLegend}\n />\n <InteractionSlots\n interactions={interactions}\n renderLegend={renderLegend}\n renderTooltip={renderTooltip}\n />\n <div ref={flash} style={FLASH} aria-hidden=\"true\" />\n {selecting && (\n <div\n ref={selection}\n data-part=\"range-select\"\n className={classNames.rangeSelect}\n style={{\n ...RANGE_SELECT,\n background: withAlpha(resolved?.palette.crosshair, 0.1),\n ...styles.rangeSelect,\n }}\n aria-hidden=\"true\"\n />\n )}\n {away && (\n <button\n type=\"button\"\n className={liveButtonClassName}\n style={liveButtonClassName || unstyled ? PILL_POSITION : PILL}\n onClick={jumpToLive}\n >\n {liveButtonLabel}\n </button>\n )}\n </div>\n );\n}\n\nexport const SeriesChart = forwardRef(SeriesChartInner) as <\n TSeries extends SeriesType,\n TPoint,\n TData extends SeriesDataItemTypeMap[TSeries],\n>(\n props: SeriesChartProps<TSeries, TPoint, TData> & {\n ref?: ForwardedRef<SeriesChartHandle<TSeries> | null>;\n },\n) => ReactElement;\n","import type {\n LineData,\n AutoscaleInfo,\n PriceLineOptions,\n AutoscaleInfoProvider,\n CreatePriceLineOptions,\n HistogramSeriesPartialOptions,\n} from \"lightweight-charts\";\n\nimport { deepMerge } from \"./merge.utils.js\";\nimport type { HistogramMode, HistogramColors } from \"../types/series.js\";\n\nfunction barColor(\n value: number,\n mode: HistogramMode,\n threshold: number | undefined,\n colors: HistogramColors,\n): string | undefined {\n if (mode === \"diverging\")\n return value < 0 ? colors.negative : colors.positive;\n\n if (mode === \"threshold\" && threshold !== undefined && value > threshold)\n return colors.over;\n\n return colors.bar;\n}\n\nexport function colorBars(\n data: ReadonlyArray<LineData>,\n mode: HistogramMode,\n threshold: number | undefined,\n colors: HistogramColors,\n): LineData[] {\n return data.map((bar) => {\n if (bar.color !== undefined) return bar;\n\n const color = barColor(bar.value, mode, threshold, colors);\n\n return color === undefined ? bar : { ...bar, color };\n });\n}\n\nexport const ownAutoscale: AutoscaleInfoProvider = (original) => original();\n\nexport const symmetricAutoscale: AutoscaleInfoProvider = (original) => {\n const info: AutoscaleInfo | null = original();\n\n if (!info?.priceRange) return info;\n\n const { minValue, maxValue } = info.priceRange;\n const extent = Math.max(Math.abs(minValue), Math.abs(maxValue));\n\n return { ...info, priceRange: { minValue: -extent, maxValue: extent } };\n};\n\nexport function histogramOptions(\n mode: HistogramMode,\n seriesOptions: HistogramSeriesPartialOptions | undefined,\n): HistogramSeriesPartialOptions {\n return deepMerge<HistogramSeriesPartialOptions>(\n {\n autoscaleInfoProvider:\n mode === \"diverging\" ? symmetricAutoscale : ownAutoscale,\n },\n seriesOptions,\n );\n}\n\nexport function histogramPriceLines(\n mode: HistogramMode,\n threshold: number | undefined,\n thresholdLine: Partial<PriceLineOptions> | false,\n zeroLine: Partial<PriceLineOptions> | false,\n): CreatePriceLineOptions[] {\n const lines: CreatePriceLineOptions[] = [];\n\n if (\n mode === \"threshold\" &&\n threshold !== undefined &&\n thresholdLine !== false\n )\n lines.push({ ...thresholdLine, price: threshold });\n\n if (mode === \"diverging\" && zeroLine !== false)\n lines.push({ axisLabelVisible: false, ...zeroLine, price: 0 });\n\n return lines;\n}\n","import { buckets } from \"./bucket.utils.js\";\nimport type { LineData } from \"lightweight-charts\";\nimport type { LinePoint } from \"../types/chart.js\";\nimport type { OHLC } from \"../types/candlestick.js\";\nimport type { NormalizedSeries } from \"../types/series.js\";\n\nexport function aggregatePoints(\n points: ReadonlyArray<LinePoint>,\n bucketSize: number,\n): LinePoint[] {\n return buckets(points, bucketSize).map((slice) => ({\n ...slice[slice.length - 1]!,\n time: slice[0]!.time,\n }));\n}\n\nexport function toLinePoints(candles: ReadonlyArray<OHLC>): LinePoint[] {\n return candles.map((candle) => ({\n time: candle.time,\n value: candle.close,\n ...(candle.color !== undefined && { color: candle.color }),\n }));\n}\n\nexport function stylePoints(\n normalized: NormalizedSeries<LinePoint, LineData>,\n colorKeys: ReadonlyArray<string>,\n styleKeys: ReadonlyArray<string>,\n): LineData[] {\n return normalized.data.map(({ color, ...rest }, index) => {\n const source: Partial<Record<string, unknown>> = {\n ...normalized.points[index],\n };\n const styled: LineData & Record<string, unknown> = { ...rest };\n\n if (color !== undefined) colorKeys.forEach((key) => (styled[key] = color));\n styleKeys.forEach((key) => {\n if (typeof source[key] === \"string\") styled[key] = source[key];\n });\n\n return styled;\n });\n}\n","import type { LinePoint } from \"../../types/chart.js\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { useCallback, forwardRef, useMemo } from \"react\";\nimport { colorBars } from \"../../utils/histogram.utils.js\";\nimport { aggregatePoints } from \"../../utils/line.utils.js\";\nimport { normalizePoints } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { CrosshairMode, HistogramSeries } from \"lightweight-charts\";\nimport type { BarChartProps, BarChartHandle } from \"../../types/series.js\";\n\nexport const BarChart = forwardRef<BarChartHandle | null, BarChartProps>(\n function BarChart({ seriesOptions, ariaLabel = \"Bar chart\", ...props }, ref) {\n const theme = useChartTheme(props);\n const { upColor, downColor, options } = useMemo(() => {\n const {\n upColor = theme?.palette.up,\n downColor = theme?.palette.down,\n ...options\n } = seriesOptions ?? {};\n return { upColor, downColor, options };\n }, [theme, seriesOptions]);\n const { base = 0, color } = options;\n\n const normalize = useCallback(\n (data: ReadonlyArray<LinePoint>) => {\n const normalized = normalizePoints(data);\n\n return color !== undefined || !upColor || !downColor\n ? normalized\n : {\n ...normalized,\n data: colorBars(normalized.data, \"threshold\", base, {\n over: upColor,\n bar: downColor,\n }),\n };\n },\n [base, upColor, downColor, color],\n );\n\n return (\n <SeriesChart\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n definition={HistogramSeries}\n normalize={normalize}\n aggregate={aggregatePoints}\n magnetMode={CrosshairMode.Magnet}\n />\n );\n },\n);\n","import {\n LineSeries,\n AreaSeries,\n CrosshairMode,\n BaselineSeries,\n} from \"lightweight-charts\";\n\nimport type {\n LineVariant,\n LineChartProps,\n LineChartHandle,\n LineVariantConfig,\n} from \"../../types/series.js\";\n\nimport type { LinePoint } from \"../../types/chart.js\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { forwardRef, useCallback, useMemo } from \"react\";\nimport { normalizePoints } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { lineOptionsFromTheme } from \"../../utils/theme.utils.js\";\nimport { aggregatePoints, stylePoints } from \"../../utils/line.utils.js\";\n\nconst VARIANTS: Record<LineVariant, LineVariantConfig> = {\n line: {\n definition: LineSeries,\n label: \"Line chart\",\n colorKeys: [\"color\"],\n styleKeys: [],\n },\n area: {\n definition: AreaSeries,\n label: \"Area chart\",\n colorKeys: [\"lineColor\"],\n styleKeys: [\"lineColor\", \"topColor\", \"bottomColor\"],\n },\n baseline: {\n definition: BaselineSeries,\n label: \"Baseline chart\",\n colorKeys: [\"topLineColor\", \"bottomLineColor\"],\n styleKeys: [\n \"topLineColor\",\n \"topFillColor1\",\n \"topFillColor2\",\n \"bottomLineColor\",\n \"bottomFillColor1\",\n \"bottomFillColor2\",\n ],\n },\n};\n\nexport const LineChart = forwardRef<\n LineChartHandle<LineVariant> | null,\n LineChartProps\n>(function LineChart(\n {\n variant = \"line\",\n seriesOptions,\n baseValue,\n ariaLabel = VARIANTS[variant].label,\n ...props\n },\n ref,\n) {\n const theme = useChartTheme(props);\n const options = useMemo(\n () =>\n deepMerge<NonNullable<typeof seriesOptions>>(\n lineOptionsFromTheme(theme, variant),\n baseValue !== undefined && {\n baseValue: { type: \"price\", price: baseValue },\n },\n seriesOptions,\n ),\n [theme, variant, baseValue, seriesOptions],\n );\n\n const normalize = useCallback(\n (data: ReadonlyArray<LinePoint>) => {\n const normalized = normalizePoints(data);\n const { colorKeys, styleKeys } = VARIANTS[variant];\n\n return {\n ...normalized,\n data: stylePoints(normalized, colorKeys, styleKeys),\n };\n },\n [variant],\n );\n\n return (\n <SeriesChart\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n definition={VARIANTS[variant].definition}\n magnetMode={CrosshairMode.Magnet}\n normalize={normalize}\n aggregate={aggregatePoints}\n />\n );\n});\n","import { highLow } from \"./stats.utils.js\";\nimport { buckets } from \"./bucket.utils.js\";\nimport type { OHLC } from \"../types/candlestick.js\";\n\nexport function isUp(candle: OHLC): boolean {\n return candle.close >= candle.open;\n}\n\nexport function aggregate(\n candles: ReadonlyArray<OHLC>,\n bucketSize: number,\n): OHLC[] {\n return buckets(candles, bucketSize).map((slice) => ({\n time: slice[0]!.time,\n open: slice[0]!.open,\n ...highLow(slice),\n close: slice[slice.length - 1]!.close,\n }));\n}\n","import {\n colorBars,\n histogramOptions,\n histogramPriceLines,\n} from \"../../utils/histogram.utils.js\";\n\nimport type {\n HistogramColors,\n HistogramChartProps,\n HistogramChartHandle,\n} from \"../../types/series.js\";\n\nimport {\n themedLine,\n referenceLine,\n histogramColorsFromTheme,\n} from \"../../utils/theme.utils.js\";\n\nimport type { LinePoint } from \"../../types/chart.js\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { forwardRef, useCallback, useMemo } from \"react\";\nimport { aggregatePoints } from \"../../utils/line.utils.js\";\nimport { normalizePoints } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { CrosshairMode, HistogramSeries } from \"lightweight-charts\";\n\nexport const HistogramChart = forwardRef<\n HistogramChartHandle | null,\n HistogramChartProps\n>(function HistogramChart(\n {\n mode = \"plain\",\n threshold,\n thresholdLine,\n zeroLine,\n colors,\n seriesOptions,\n ariaLabel = \"Histogram chart\",\n ...props\n },\n ref,\n) {\n const options = useMemo(\n () => histogramOptions(mode, seriesOptions),\n [mode, seriesOptions],\n );\n\n const theme = useChartTheme(props);\n const priceLines = useMemo(\n () =>\n histogramPriceLines(\n mode,\n threshold,\n themedLine(\n referenceLine(theme, theme?.histogram.threshold, \"dashed\"),\n thresholdLine,\n ),\n themedLine(\n referenceLine(theme, theme?.histogram.zero, \"solid\"),\n zeroLine,\n ),\n ),\n [theme, mode, threshold, thresholdLine, zeroLine],\n );\n\n const { bar, over, positive, negative } = useMemo(\n () => deepMerge<HistogramColors>(histogramColorsFromTheme(theme), colors),\n [theme, colors],\n );\n\n const normalize = useCallback(\n (data: ReadonlyArray<LinePoint>) => {\n const normalized = normalizePoints(data);\n\n return {\n ...normalized,\n data: colorBars(normalized.data, mode, threshold, {\n bar,\n over,\n positive,\n negative,\n }),\n };\n },\n [mode, threshold, bar, over, positive, negative],\n );\n\n return (\n <SeriesChart\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n priceLines={priceLines}\n definition={HistogramSeries}\n normalize={normalize}\n aggregate={aggregatePoints}\n magnetMode={CrosshairMode.Magnet}\n />\n );\n});\n","import type {\n OHLC,\n CandlestickChartProps,\n CandlestickChartHandle,\n} from \"../../types/candlestick.js\";\n\nimport { useMemo, forwardRef } from \"react\";\nimport { SeriesChart } from \"../SeriesChart/index.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { aggregate } from \"../../utils/candlestick.utils.js\";\nimport { normalizeCandles } from \"../../utils/data.utils.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { candleOptionsFromTheme } from \"../../utils/theme.utils.js\";\nimport { CandlestickSeries, type CandlestickData } from \"lightweight-charts\";\n\nexport const CandlestickChart = forwardRef<\n CandlestickChartHandle | null,\n CandlestickChartProps\n>(function CandlestickChart(\n { ariaLabel = \"Candlestick chart\", seriesOptions, ...props },\n ref,\n) {\n const theme = useChartTheme(props);\n const options = useMemo(\n () =>\n deepMerge<typeof seriesOptions>(\n candleOptionsFromTheme(theme),\n seriesOptions,\n ),\n [theme, seriesOptions],\n );\n\n return (\n <SeriesChart<\"Candlestick\", OHLC, CandlestickData>\n {...props}\n ref={ref}\n ariaLabel={ariaLabel}\n seriesOptions={options}\n definition={CandlestickSeries}\n normalize={normalizeCandles}\n aggregate={aggregate}\n />\n );\n});\n","import type {\n ISeriesPrimitive,\n IPrimitivePaneRenderer,\n IPrimitivePaneView,\n SeriesAttachedParameter,\n Time,\n ISeriesApi,\n SeriesType,\n AutoscaleInfo,\n} from \"lightweight-charts\";\n\nimport { withAlpha } from \"../utils/color.utils.js\";\nimport { timeToX } from \"../utils/timeScale.utils.js\";\nimport type { RibbonSample } from \"../utils/timeSeries.utils.js\";\n\ntype Target = Parameters<IPrimitivePaneRenderer[\"draw\"]>[0];\n\nexport interface RibbonPrimitiveOptions {\n points: readonly RibbonSample[];\n color: string;\n opacity?: number;\n}\n\n/**\n * Fills between two value lines on one price scale. Regime bands stay\n * full-height tints; this is the P10–P90 wash.\n */\nexport class RibbonPrimitive implements ISeriesPrimitive<Time> {\n private points: RibbonSample[] = [];\n private color = \"#000000\";\n private opacity = 0.16;\n private chart: SeriesAttachedParameter<Time>[\"chart\"] | null = null;\n private series: ISeriesApi<SeriesType, Time> | null = null;\n private requestUpdate: (() => void) | null = null;\n private readonly view: IPrimitivePaneView = {\n zOrder: () => \"bottom\",\n renderer: () => ({ draw: (target) => this.draw(target) }),\n };\n\n constructor(options: RibbonPrimitiveOptions) {\n this.applyOptions(options);\n }\n\n applyOptions(options: RibbonPrimitiveOptions) {\n this.points = [...options.points];\n this.color = options.color;\n this.opacity = options.opacity ?? 0.16;\n this.requestUpdate?.();\n }\n\n attached(param: SeriesAttachedParameter<Time>) {\n this.chart = param.chart;\n this.series = param.series;\n this.requestUpdate = param.requestUpdate;\n param.requestUpdate();\n }\n\n detached() {\n this.chart = null;\n this.series = null;\n this.requestUpdate = null;\n }\n\n paneViews() {\n return [this.view];\n }\n\n autoscaleInfo(): AutoscaleInfo | null {\n let min = Infinity;\n let max = -Infinity;\n\n for (const point of this.points) {\n min = Math.min(min, point.lower, point.upper);\n max = Math.max(max, point.lower, point.upper);\n }\n\n return Number.isFinite(min)\n ? { priceRange: { minValue: min, maxValue: max } }\n : null;\n }\n\n private draw(target: Target) {\n const chart = this.chart;\n const series = this.series;\n\n if (!chart || !series || this.points.length < 2) return;\n\n const timeScale = chart.timeScale();\n const coords = this.points.flatMap((point) => {\n const x = timeToX(timeScale, point.time);\n const upper = series.priceToCoordinate(point.upper);\n const lower = series.priceToCoordinate(point.lower);\n\n return x === null || upper === null || lower === null\n ? []\n : [{ x, upper, lower }];\n });\n const first = coords[0];\n\n if (!first || coords.length < 2) return;\n\n target.useMediaCoordinateSpace(({ context }) => {\n context.beginPath();\n context.moveTo(first.x, first.upper);\n\n for (const point of coords) context.lineTo(point.x, point.upper);\n\n for (let index = coords.length - 1; index >= 0; index -= 1) {\n const point = coords[index]!;\n\n context.lineTo(point.x, point.lower);\n }\n\n context.closePath();\n context.fillStyle = withAlpha(this.color, this.opacity) ?? this.color;\n context.fill();\n });\n }\n}\n","const containers = new Set<HTMLElement>();\nlet installed = false;\nlet original: typeof CanvasRenderingContext2D.prototype.roundRect | undefined;\n\n/**\n * Lightweight Charts draws axis and crosshair labels with rounded corners.\n * Zero the radius for canvases inside `container`, and leave every other\n * canvas on the page alone. Several charts share one prototype patch.\n */\nexport function patchSquareCanvasLabels(container: HTMLElement): () => void {\n const proto = globalThis.CanvasRenderingContext2D?.prototype;\n\n if (!proto?.roundRect) return () => {};\n\n containers.add(container);\n\n if (!installed) {\n original = proto.roundRect;\n proto.roundRect = function (x, y, w, h, radii) {\n for (const root of containers) {\n if (root.contains(this.canvas))\n return original!.call(this, x, y, w, h, 0);\n }\n\n return original!.call(this, x, y, w, h, radii);\n };\n installed = true;\n }\n\n return () => {\n containers.delete(container);\n\n if (containers.size === 0 && installed && original) {\n proto.roundRect = original;\n installed = false;\n original = undefined;\n }\n };\n}\n","import {\n ColorType,\n CrosshairMode,\n LineStyle,\n type DeepPartial,\n type ChartOptions,\n type Time,\n} from \"lightweight-charts\";\n\nimport type { Theme } from \"../types/theme.js\";\n\nconst FALLBACK_FONT = \"ui-sans-serif, system-ui, sans-serif\";\n\nexport interface EditorialScaleOptions {\n height?: number;\n timeVisible?: boolean;\n rightOffset?: number;\n leftPriceScale?: boolean;\n rightPriceScale?: boolean;\n tickMarkFormatter?: (time: Time) => string;\n timeFormatter?: (time: Time) => string;\n}\n\n/**\n * House look for product charts: transparent canvas, hairline grid, square\n * labels (applied separately), no wheel handler, sharp crosshair labels.\n * Pass `typography.axis.family` from `next/font` or `p1ThemeFromCss`.\n */\nexport function editorialChartOptions(\n theme: Theme,\n {\n height = 340,\n timeVisible = false,\n rightOffset = 2,\n leftPriceScale = false,\n rightPriceScale = true,\n tickMarkFormatter,\n timeFormatter,\n }: EditorialScaleOptions = {},\n): DeepPartial<ChartOptions> {\n const { palette, typography } = theme;\n const scale = {\n borderColor: palette.border,\n scaleMargins: { top: 0.12, bottom: 0.08 },\n };\n const hairline = {\n color: palette.crosshair,\n width: 1 as const,\n style: LineStyle.Dashed,\n labelBackgroundColor: palette.crosshairLabel,\n };\n\n return {\n height,\n layout: {\n background: { type: ColorType.Solid, color: \"transparent\" },\n textColor: palette.text,\n fontFamily: typography.axis.family || FALLBACK_FONT,\n fontSize: typography.axis.size ?? 11,\n attributionLogo: false,\n },\n grid: {\n vertLines: { color: palette.grid, style: LineStyle.Solid },\n horzLines: { color: palette.grid, style: LineStyle.Solid },\n },\n crosshair: {\n mode: CrosshairMode.Normal,\n vertLine: hairline,\n horzLine: hairline,\n },\n leftPriceScale: { ...scale, visible: leftPriceScale },\n rightPriceScale: { ...scale, visible: rightPriceScale },\n timeScale: {\n borderColor: palette.border,\n timeVisible,\n fixLeftEdge: true,\n fixRightEdge: false,\n rightOffset,\n ...(tickMarkFormatter ? { tickMarkFormatter } : {}),\n },\n localization: timeFormatter ? { timeFormatter } : undefined,\n handleScroll: { mouseWheel: false, vertTouchDrag: false },\n handleScale: { mouseWheel: false },\n };\n}\n","import type { UTCTimestamp } from \"lightweight-charts\";\nimport type { Time } from \"../types/chart.js\";\n\nexport const ORDINAL_STEP = 86_400;\n\nexport function ordinalIndex(\n time: Time,\n categories: readonly string[],\n): number | null {\n if (typeof time === \"number\" && Number.isInteger(time))\n return time >= 0 && time < categories.length ? time : null;\n\n if (typeof time === \"string\") {\n const index = categories.indexOf(time);\n\n return index < 0 ? null : index;\n }\n\n return null;\n}\n\nexport function ordinalTime(\n time: Time,\n categories: readonly string[],\n): UTCTimestamp | null {\n const index = ordinalIndex(time, categories);\n\n return index === null ? null : ((index * ORDINAL_STEP) as UTCTimestamp);\n}\n\nexport function ordinalLabel(\n time: number,\n categories: readonly string[],\n): string {\n const index = Math.round(time / ORDINAL_STEP);\n\n return categories[index] ?? \"\";\n}\n","import type { UTCTimestamp } from \"lightweight-charts\";\nimport type { Time } from \"../types/chart.js\";\nimport type { TimeSeriesPoint } from \"../types/timeSeries.js\";\nimport { toUnixSeconds } from \"./time.utils.js\";\nimport { ordinalTime } from \"./ordinal.utils.js\";\n\nexport interface RibbonSample {\n time: number;\n upper: number;\n lower: number;\n}\n\nexport function seriesTime(\n time: Time,\n categories: readonly string[] | null,\n): UTCTimestamp | null {\n if (categories) return ordinalTime(time, categories);\n\n const unix = toUnixSeconds(time);\n\n return unix === null ? null : (unix as UTCTimestamp);\n}\n\nexport function seriesRows(\n data: readonly TimeSeriesPoint[],\n categories: readonly string[] | null,\n): { time: UTCTimestamp; value: number }[] {\n const rows: { time: UTCTimestamp; value: number }[] = [];\n\n for (const point of data) {\n const time = seriesTime(point.time, categories);\n\n if (time === null || !Number.isFinite(point.value)) continue;\n\n const last = rows[rows.length - 1];\n\n if (last && last.time === time) rows[rows.length - 1] = { time, value: point.value };\n else rows.push({ time, value: point.value });\n }\n\n rows.sort((a, b) => a.time - b.time);\n\n const unique: typeof rows = [];\n\n for (const row of rows) {\n const last = unique[unique.length - 1];\n\n if (last && last.time === row.time) unique[unique.length - 1] = row;\n else unique.push(row);\n }\n\n return unique;\n}\n\nexport function ribbonSamples(\n upper: readonly TimeSeriesPoint[],\n lower: readonly TimeSeriesPoint[],\n categories: readonly string[] | null,\n): RibbonSample[] {\n const below = new Map<number, number>();\n\n for (const point of lower) {\n const time = seriesTime(point.time, categories);\n\n if (time !== null && Number.isFinite(point.value)) below.set(time, point.value);\n }\n\n const samples: RibbonSample[] = [];\n\n for (const point of upper) {\n const time = seriesTime(point.time, categories);\n const low = time === null ? undefined : below.get(time);\n\n if (time === null || low === undefined || !Number.isFinite(point.value))\n continue;\n\n samples.push({ time, upper: point.value, lower: low });\n }\n\n samples.sort((a, b) => a.time - b.time);\n\n return samples;\n}\n\nexport function defaultTimeLabel(time: Time): string {\n const unix = toUnixSeconds(time);\n\n if (unix === null) return String(time);\n\n return new Date(unix * 1000).toISOString().slice(0, 10);\n}\n","import {\n useEffect,\n useRef,\n useState,\n type CSSProperties,\n} from \"react\";\n\nimport {\n AreaSeries,\n CrosshairMode,\n HistogramSeries,\n LineSeries,\n LineStyle,\n createChart,\n createSeriesMarkers,\n type AutoscaleInfoProvider,\n type IChartApi,\n type ISeriesApi,\n type LineWidth,\n type SeriesMarker,\n type SeriesType,\n type Time,\n type UTCTimestamp,\n} from \"lightweight-charts\";\n\nimport type { ChartInstance } from \"../../types/chart.js\";\nimport type {\n TimeSeriesChartProps,\n TimeSeriesKind,\n TimeSeriesScale,\n TimeSeriesSpec,\n TimeSeriesTooltipRow,\n} from \"../../types/timeSeries.js\";\n\nimport { FILL, WRAPPER } from \"../../styles/seriesChart.js\";\nimport { TOOLTIP } from \"../../styles/shared.js\";\nimport { useChartTheme } from \"../../hooks/useChartTheme.js\";\nimport { useWheelZoom } from \"../../hooks/useWheelZoom.js\";\nimport { RibbonPrimitive } from \"../../primitives/RibbonPrimitive.js\";\nimport { TimeRangePrimitive } from \"../../primitives/TimeRangePrimitive.js\";\nimport { patchSquareCanvasLabels } from \"../../utils/canvas.utils.js\";\nimport { withAlpha } from \"../../utils/color.utils.js\";\nimport { deepMerge } from \"../../utils/merge.utils.js\";\nimport { editorialChartOptions } from \"../../utils/editorial.utils.js\";\nimport { ordinalLabel } from \"../../utils/ordinal.utils.js\";\nimport { chartOptionsFromTheme, defaultTheme } from \"../../utils/theme.utils.js\";\nimport {\n defaultTimeLabel,\n ribbonSamples,\n seriesRows,\n seriesTime,\n} from \"../../utils/timeSeries.utils.js\";\nimport { toUnixSeconds } from \"../../utils/time.utils.js\";\nimport { placeTip } from \"../../utils/tooltip.utils.js\";\n\nconst STROKE = {\n solid: LineStyle.Solid,\n dotted: LineStyle.Dotted,\n dashed: LineStyle.Dashed,\n} as const;\n\nconst DEFINITION = {\n line: LineSeries,\n area: AreaSeries,\n histogram: HistogramSeries,\n} as const;\n\nconst NO_CATEGORIES: readonly string[] = [];\nconst NO_RIBBONS: NonNullable<TimeSeriesChartProps[\"ribbons\"]> = [];\nconst NO_RANGES: NonNullable<TimeSeriesChartProps[\"ranges\"]> = [];\nconst NO_GUIDES: NonNullable<TimeSeriesChartProps[\"guides\"]> = [];\nconst NO_MARKERS: NonNullable<TimeSeriesChartProps[\"markers\"]> = [];\n\nconst TIP: CSSProperties = {\n ...TOOLTIP,\n minWidth: 140,\n padding: \"8px 10px\",\n borderRadius: 0,\n fontSize: 12,\n lineHeight: 1.4,\n};\n\ninterface TipState {\n label: string;\n rows: TimeSeriesTooltipRow[];\n x: number;\n y: number;\n time: number;\n}\n\nfunction scaleOf(series: TimeSeriesSpec): TimeSeriesScale {\n return series.priceScale ?? \"right\";\n}\n\nfunction seriesColor(\n spec: TimeSeriesSpec,\n index: number,\n categorical: readonly string[],\n): string {\n return spec.color ?? categorical[index % Math.max(1, categorical.length)] ?? \"#191919\";\n}\n\nexport function TimeSeriesChart({\n series,\n ribbons = NO_RIBBONS,\n ranges = NO_RANGES,\n guides = NO_GUIDES,\n markers = NO_MARKERS,\n onPointClick,\n height = 340,\n className,\n ariaLabel = \"Time series chart\",\n profile = \"editorial\",\n axis = \"time\",\n categories,\n timeVisible = false,\n formatTime,\n formatValue,\n extraTooltipRows,\n renderTooltip,\n chartOptions,\n theme,\n unstyled,\n}: TimeSeriesChartProps) {\n const container = useRef<HTMLDivElement>(null);\n const resolved = useChartTheme({ theme, unstyled });\n const [chart, setChart] = useState<IChartApi | null>(null);\n const [tip, setTip] = useState<TipState | null>(null);\n const callbacks = useRef({\n formatTime,\n formatValue,\n extraTooltipRows,\n renderTooltip,\n onPointClick,\n });\n callbacks.current = {\n formatTime,\n formatValue,\n extraTooltipRows,\n renderTooltip,\n onPointClick,\n };\n const editorial = profile === \"editorial\";\n const labels = axis === \"ordinal\" ? (categories ?? NO_CATEGORIES) : null;\n const look = resolved ?? defaultTheme;\n\n useEffect(() => {\n const element = container.current;\n\n if (!element || !editorial) return;\n\n return patchSquareCanvasLabels(element);\n }, [editorial]);\n\n useEffect(() => {\n const element = container.current;\n\n if (!element) return;\n\n const palette = look.palette;\n const categorical = palette.categorical;\n const left = series.some((item) => scaleOf(item) === \"left\") ||\n ribbons.some((item) => item.priceScale === \"left\");\n const right =\n series.length === 0 ||\n series.some((item) => scaleOf(item) === \"right\") ||\n ribbons.some((item) => (item.priceScale ?? \"right\") === \"right\");\n const formatTick = (time: Time) => {\n const unix = typeof time === \"number\" ? time : toUnixSeconds(time as never);\n\n if (unix === null) return \"\";\n if (labels) return ordinalLabel(unix, labels);\n\n return callbacks.current.formatTime?.(unix) ?? defaultTimeLabel(unix);\n };\n const base = editorial\n ? editorialChartOptions(look, {\n height,\n timeVisible,\n leftPriceScale: left,\n rightPriceScale: right,\n tickMarkFormatter: formatTick,\n timeFormatter: formatTick,\n })\n : deepMerge(chartOptionsFromTheme(look), {\n height,\n crosshair: { mode: CrosshairMode.Magnet },\n handleScale: { mouseWheel: false },\n handleScroll: { mouseWheel: false },\n leftPriceScale: { visible: left },\n rightPriceScale: { visible: right },\n timeScale: {\n timeVisible,\n tickMarkFormatter: formatTick,\n },\n localization: { timeFormatter: formatTick },\n });\n const api = createChart(element, deepMerge({ autoSize: true }, base, chartOptions));\n const hosts = new Map<TimeSeriesScale, ISeriesApi<SeriesType>>();\n const painted = series.map((spec, index) => {\n const color = seriesColor(spec, index, categorical);\n const kind: TimeSeriesKind = spec.kind ?? \"line\";\n const width = (spec.lineWidth ?? (kind === \"line\" ? 2 : 1)) as LineWidth;\n const common = {\n priceScaleId: scaleOf(spec),\n priceLineVisible: false,\n lastValueVisible: spec.lastValueVisible ?? false,\n };\n const options =\n kind === \"area\"\n ? {\n ...common,\n lineColor: color,\n lineWidth: width,\n lineStyle: STROKE[spec.lineStyle ?? \"solid\"],\n topColor: withAlpha(color, 0.2) ?? color,\n bottomColor: withAlpha(color, 0) ?? color,\n }\n : kind === \"histogram\"\n ? { ...common, color }\n : {\n ...common,\n color,\n lineWidth: width,\n lineStyle: STROKE[spec.lineStyle ?? \"solid\"],\n crosshairMarkerVisible: true,\n };\n const apiSeries = api.addSeries(DEFINITION[kind], options);\n const rows = seriesRows(spec.data, labels);\n\n apiSeries.setData(rows);\n hosts.set(scaleOf(spec), apiSeries);\n\n const marks = markers.flatMap((marker) => {\n if (marker.seriesId !== spec.id) return [];\n\n const time = seriesTime(marker.time, labels);\n\n return time === null\n ? []\n : [\n {\n time,\n position: marker.position ?? \"inBar\",\n shape: marker.shape ?? \"circle\",\n color: marker.color ?? color,\n text: marker.text,\n } satisfies SeriesMarker<Time>,\n ];\n });\n\n if (marks.length > 0) createSeriesMarkers(apiSeries, marks);\n\n return { spec, color, rows, apiSeries };\n });\n\n for (const ribbon of ribbons) {\n const side = ribbon.priceScale ?? \"right\";\n const host = hosts.get(side) ?? painted[0]?.apiSeries;\n\n if (!host) continue;\n\n const color = ribbon.color ?? categorical[0] ?? palette.down;\n\n host.attachPrimitive(\n new RibbonPrimitive({\n points: ribbonSamples(ribbon.upper, ribbon.lower, labels),\n color,\n opacity: ribbon.opacity,\n }),\n );\n }\n\n const rangeHost = painted[0]?.apiSeries;\n\n if (rangeHost && ranges.length > 0) {\n rangeHost.attachPrimitive(\n new TimeRangePrimitive({\n items: ranges.map((range) => ({\n from: range.from,\n to: range.to,\n key: range.id,\n label: range.label,\n color: range.fill,\n })),\n style: (key) => {\n const range = ranges.find((item) => item.id === key);\n const hatch = range?.hatch;\n\n return {\n fill: range?.fill,\n hatch:\n hatch === false\n ? false\n : {\n color: hatch ?? range?.fill ?? palette.down,\n spacing: 8,\n width: 1,\n opacity: 0.45,\n },\n };\n },\n }),\n );\n }\n\n const guideValues = new Map<ISeriesApi<SeriesType>, number[]>();\n\n for (const guide of guides) {\n const host = hosts.get(guide.scale ?? \"right\") ?? painted[0]?.apiSeries;\n\n if (!host) continue;\n\n host.createPriceLine({\n price: guide.value,\n color: guide.color ?? palette.down,\n lineWidth: 1,\n lineStyle: LineStyle.Dashed,\n axisLabelVisible: Boolean(guide.label),\n title: guide.label ?? \"\",\n });\n\n if (!Number.isFinite(guide.value)) continue;\n\n const values = guideValues.get(host) ?? [];\n\n values.push(guide.value);\n guideValues.set(host, values);\n }\n\n for (const [host, values] of guideValues) {\n host.applyOptions({\n autoscaleInfoProvider: ((original) => {\n const info = original();\n\n if (!info?.priceRange) return info;\n\n return {\n ...info,\n priceRange: {\n minValue: Math.min(info.priceRange.minValue, ...values),\n maxValue: Math.max(info.priceRange.maxValue, ...values),\n },\n };\n }) satisfies AutoscaleInfoProvider,\n });\n }\n\n api.timeScale().fitContent();\n\n const onMove = (param: { time?: Time; point?: { x: number; y: number } }) => {\n const unix = typeof param.time === \"number\" ? param.time : null;\n const point = param.point;\n\n if (unix === null || !point) {\n setTip(null);\n return;\n }\n\n const rows: TimeSeriesTooltipRow[] = painted.flatMap(({ spec, color, rows: data }) => {\n if (spec.includeInTooltip === false) return [];\n\n const hit = data.find((item) => item.time === unix);\n\n if (!hit) return [];\n\n return [\n {\n label: spec.name,\n value: callbacks.current.formatValue?.(spec.id, hit.value) ?? String(hit.value),\n color,\n swatch: spec.kind === \"histogram\" ? \"bar\" as const : \"line\" as const,\n },\n ];\n });\n const extra = callbacks.current.extraTooltipRows?.(unix) ?? [];\n const label = labels\n ? ordinalLabel(unix, labels)\n : (callbacks.current.formatTime?.(unix) ?? defaultTimeLabel(unix));\n\n setTip({\n label,\n rows: [...rows, ...extra],\n x: point.x,\n y: point.y,\n time: unix,\n });\n };\n\n const onClick = (param: { time?: Time }) => {\n const handler = callbacks.current.onPointClick;\n const unix = typeof param.time === \"number\" ? param.time : null;\n\n if (!handler || unix === null) return;\n\n const points = painted.flatMap(({ spec, rows: data }) => {\n const hit = data.find((item) => item.time === unix);\n\n return hit ? [{ seriesId: spec.id, value: hit.value }] : [];\n });\n\n if (points.length > 0) handler({ time: unix, points });\n };\n\n api.subscribeCrosshairMove(onMove);\n api.subscribeClick(onClick);\n setChart(api);\n\n return () => {\n setChart(null);\n setTip(null);\n api.unsubscribeCrosshairMove(onMove);\n api.unsubscribeClick(onClick);\n api.remove();\n };\n }, [\n series,\n ribbons,\n ranges,\n guides,\n markers,\n resolved,\n height,\n editorial,\n labels,\n timeVisible,\n chartOptions,\n look,\n ]);\n\n useWheelZoom(\n chart ? ({ chart, series: null as never } satisfies ChartInstance<SeriesType>) : null,\n container,\n !editorial,\n );\n\n const box = container.current?.getBoundingClientRect();\n const placed = tip\n ? placeTip([tip.x, tip.y], 12, [180, 56], [box?.width || height, box?.height || height])\n : null;\n\n return (\n <div\n className={className}\n data-profile={profile}\n data-axis={axis}\n style={{ ...WRAPPER, height }}\n >\n <div ref={container} style={FILL} role=\"img\" aria-label={ariaLabel} />\n {tip && placed && (\n <div\n data-part=\"tooltip\"\n style={{\n ...TIP,\n left: placed[0],\n top: placed[1],\n background: resolved?.palette.background ?? \"#fff\",\n color: resolved?.palette.text ?? \"#191919\",\n border: `1px solid ${resolved?.palette.border ?? \"#2B2B43\"}`,\n }}\n >\n <div data-part=\"tooltip-time\">{tip.label}</div>\n {callbacks.current.renderTooltip\n ? callbacks.current.renderTooltip(tip.rows, {\n time: tip.time,\n x: tip.x,\n y: tip.y,\n })\n : tip.rows.map((row) => (\n <div key={`${row.label}:${row.value}`} data-part=\"tooltip-row\">\n <span\n data-part=\"swatch\"\n data-swatch={row.swatch}\n style={{\n display: \"inline-block\",\n width: 8,\n height: row.swatch === \"bar\" ? 8 : 2,\n marginRight: 6,\n background: row.color,\n }}\n />\n <span>{row.label}</span> <span>{row.value}</span>\n </div>\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAOA,SAASe,EAAO,GAAgC,GAA8B;CAC5E,IAAMC,IAAIC,EAAU,oBAAoBC,CAAgB,GAClDC,IAAOH,MAAM,OAAO,OAAOC,EAAU,iBAAiBD,CAAC;CAE7D,OAAOG,MAAS,OAAO,OAAO,OAAOA,CAAI;AAC3C;AAEA,SAAgBC,EACd,GACA,GACe;CACf,IAAMC,IAAQJ,EAAU,iBAAiBE,CAAoB;CAE7D,IAAIE,MAAU,MAAM,OAAOA;CAE3B,IAAMC,IAAUL,EAAU,YAAYE,GAAsB,EAAI;CAEhE,IAAIG,MAAY,MAAM,OAAO;CAE7B,IAAMC,IAAO,KAAK,IAAI,GAAGD,IAAU,CAAC,GAC9BE,IAAWT,EAAOE,GAAWM,CAAI,GACjCE,IAAYV,EAAOE,GAAWM,IAAO,CAAC,GACtCG,IAAQT,EAAU,oBAAoBM,CAAe,GACrDI,IAASV,EAAU,oBAAqBM,IAAO,CAAa;CAWlE,OAREC,MAAa,QACbC,MAAc,QACdC,MAAU,QACVC,MAAW,QACX,EAAEF,IAAYD,KAEP,OAGPE,KAAUP,IAAOK,MAAaC,IAAYD,MAAcG,IAASD;AAErE;AAEA,SAAgBE,EACd,GACA,GACA,GACyB;CACzB,IAAMC,KAAW,MAAiB;EAChC,IAAMX,IAAQD,EAAU,YAAYE,GAAsB,EAAI;EAE9D,OAAOD,MAAU,OAAO,OAAO,OAAOA,CAAK;CAC7C,GACMY,IAAQD,EAAQE,CAAI,GACpBC,IAAOH,EAAQI,CAAE;CAEvB,IAAIH,MAAU,QAAQE,MAAS,MAAM,OAAO;CAE5C,IAAME,IAAYnB,EAAOE,GAAWa,CAAK,GACnCK,IAAWpB,EAAOE,GAAWe,CAAI;CAEvC,IAAIE,MAAc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