@metamask-previews/advanced-chart-core 0.0.0-preview-e58fe0640 → 0.0.0-preview-238cb7063

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (321) hide show
  1. package/dist/core/bootstrap.cjs +185 -0
  2. package/dist/core/bootstrap.cjs.map +1 -0
  3. package/dist/core/bootstrap.d.cts +10 -0
  4. package/dist/core/bootstrap.d.cts.map +1 -0
  5. package/dist/core/bootstrap.d.mts +10 -0
  6. package/dist/core/bootstrap.d.mts.map +1 -0
  7. package/dist/core/bootstrap.mjs +181 -0
  8. package/dist/core/bootstrap.mjs.map +1 -0
  9. package/dist/core/bridge.cjs +115 -0
  10. package/dist/core/bridge.cjs.map +1 -0
  11. package/dist/core/bridge.d.cts +37 -0
  12. package/dist/core/bridge.d.cts.map +1 -0
  13. package/dist/core/bridge.d.mts +37 -0
  14. package/dist/core/bridge.d.mts.map +1 -0
  15. package/dist/core/bridge.mjs +108 -0
  16. package/dist/core/bridge.mjs.map +1 -0
  17. package/dist/core/dataLifecycle.cjs +52 -0
  18. package/dist/core/dataLifecycle.cjs.map +1 -0
  19. package/dist/core/dataLifecycle.d.cts +8 -0
  20. package/dist/core/dataLifecycle.d.cts.map +1 -0
  21. package/dist/core/dataLifecycle.d.mts +8 -0
  22. package/dist/core/dataLifecycle.d.mts.map +1 -0
  23. package/dist/core/dataLifecycle.mjs +46 -0
  24. package/dist/core/dataLifecycle.mjs.map +1 -0
  25. package/dist/core/loadLibrary.cjs +63 -0
  26. package/dist/core/loadLibrary.cjs.map +1 -0
  27. package/dist/core/loadLibrary.d.cts +16 -0
  28. package/dist/core/loadLibrary.d.cts.map +1 -0
  29. package/dist/core/loadLibrary.d.mts +16 -0
  30. package/dist/core/loadLibrary.d.mts.map +1 -0
  31. package/dist/core/loadLibrary.mjs +58 -0
  32. package/dist/core/loadLibrary.mjs.map +1 -0
  33. package/dist/core/resolution.cjs +58 -0
  34. package/dist/core/resolution.cjs.map +1 -0
  35. package/dist/core/resolution.d.cts +15 -0
  36. package/dist/core/resolution.d.cts.map +1 -0
  37. package/dist/core/resolution.d.mts +15 -0
  38. package/dist/core/resolution.d.mts.map +1 -0
  39. package/dist/core/resolution.mjs +54 -0
  40. package/dist/core/resolution.mjs.map +1 -0
  41. package/dist/core/state.cjs +343 -0
  42. package/dist/core/state.cjs.map +1 -0
  43. package/dist/core/state.d.cts +67 -0
  44. package/dist/core/state.d.cts.map +1 -0
  45. package/dist/core/state.d.mts +67 -0
  46. package/dist/core/state.d.mts.map +1 -0
  47. package/dist/core/state.mjs +283 -0
  48. package/dist/core/state.mjs.map +1 -0
  49. package/dist/core/timeUtils.cjs +72 -0
  50. package/dist/core/timeUtils.cjs.map +1 -0
  51. package/dist/core/timeUtils.d.cts +32 -0
  52. package/dist/core/timeUtils.d.cts.map +1 -0
  53. package/dist/core/timeUtils.d.mts +32 -0
  54. package/dist/core/timeUtils.d.mts.map +1 -0
  55. package/dist/core/timeUtils.mjs +66 -0
  56. package/dist/core/timeUtils.mjs.map +1 -0
  57. package/dist/core/timezone.cjs +135 -0
  58. package/dist/core/timezone.cjs.map +1 -0
  59. package/dist/core/timezone.d.cts +16 -0
  60. package/dist/core/timezone.d.cts.map +1 -0
  61. package/dist/core/timezone.d.mts +16 -0
  62. package/dist/core/timezone.d.mts.map +1 -0
  63. package/dist/core/timezone.mjs +131 -0
  64. package/dist/core/timezone.mjs.map +1 -0
  65. package/dist/core/types.cjs +20 -0
  66. package/dist/core/types.cjs.map +1 -0
  67. package/dist/core/types.d.cts +323 -0
  68. package/dist/core/types.d.cts.map +1 -0
  69. package/dist/core/types.d.mts +323 -0
  70. package/dist/core/types.d.mts.map +1 -0
  71. package/dist/core/types.mjs +17 -0
  72. package/dist/core/types.mjs.map +1 -0
  73. package/dist/features/indicators/index.cjs +183 -0
  74. package/dist/features/indicators/index.cjs.map +1 -0
  75. package/dist/features/indicators/index.d.cts +6 -0
  76. package/dist/features/indicators/index.d.cts.map +1 -0
  77. package/dist/features/indicators/index.d.mts +6 -0
  78. package/dist/features/indicators/index.d.mts.map +1 -0
  79. package/dist/features/indicators/index.mjs +177 -0
  80. package/dist/features/indicators/index.mjs.map +1 -0
  81. package/dist/features/indicators/legend.cjs +575 -0
  82. package/dist/features/indicators/legend.cjs.map +1 -0
  83. package/dist/features/indicators/legend.d.cts +40 -0
  84. package/dist/features/indicators/legend.d.cts.map +1 -0
  85. package/dist/features/indicators/legend.d.mts +40 -0
  86. package/dist/features/indicators/legend.d.mts.map +1 -0
  87. package/dist/features/indicators/legend.mjs +564 -0
  88. package/dist/features/indicators/legend.mjs.map +1 -0
  89. package/dist/features/indicators/resize.cjs +34 -0
  90. package/dist/features/indicators/resize.cjs.map +1 -0
  91. package/dist/features/indicators/resize.d.cts +2 -0
  92. package/dist/features/indicators/resize.d.cts.map +1 -0
  93. package/dist/features/indicators/resize.d.mts +2 -0
  94. package/dist/features/indicators/resize.d.mts.map +1 -0
  95. package/dist/features/indicators/resize.mjs +30 -0
  96. package/dist/features/indicators/resize.mjs.map +1 -0
  97. package/dist/features/indicators/studies.cjs +147 -0
  98. package/dist/features/indicators/studies.cjs.map +1 -0
  99. package/dist/features/indicators/studies.d.cts +36 -0
  100. package/dist/features/indicators/studies.d.cts.map +1 -0
  101. package/dist/features/indicators/studies.d.mts +36 -0
  102. package/dist/features/indicators/studies.d.mts.map +1 -0
  103. package/dist/features/indicators/studies.mjs +140 -0
  104. package/dist/features/indicators/studies.mjs.map +1 -0
  105. package/dist/features/indicators/subPane.cjs +78 -0
  106. package/dist/features/indicators/subPane.cjs.map +1 -0
  107. package/dist/features/indicators/subPane.d.cts +6 -0
  108. package/dist/features/indicators/subPane.d.cts.map +1 -0
  109. package/dist/features/indicators/subPane.d.mts +6 -0
  110. package/dist/features/indicators/subPane.d.mts.map +1 -0
  111. package/dist/features/indicators/subPane.mjs +72 -0
  112. package/dist/features/indicators/subPane.mjs.map +1 -0
  113. package/dist/features/volume/index.cjs +145 -0
  114. package/dist/features/volume/index.cjs.map +1 -0
  115. package/dist/features/volume/index.d.cts +4 -0
  116. package/dist/features/volume/index.d.cts.map +1 -0
  117. package/dist/features/volume/index.d.mts +4 -0
  118. package/dist/features/volume/index.d.mts.map +1 -0
  119. package/dist/features/volume/index.mjs +140 -0
  120. package/dist/features/volume/index.mjs.map +1 -0
  121. package/dist/index.cjs +20 -0
  122. package/dist/index.cjs.map +1 -0
  123. package/dist/index.d.cts +2 -0
  124. package/dist/index.d.cts.map +1 -0
  125. package/dist/index.d.mts +2 -0
  126. package/dist/index.d.mts.map +1 -0
  127. package/dist/index.mjs +18 -0
  128. package/dist/index.mjs.map +1 -0
  129. package/dist/interaction/crosshair.cjs +147 -0
  130. package/dist/interaction/crosshair.cjs.map +1 -0
  131. package/dist/interaction/crosshair.d.cts +21 -0
  132. package/dist/interaction/crosshair.d.cts.map +1 -0
  133. package/dist/interaction/crosshair.d.mts +21 -0
  134. package/dist/interaction/crosshair.d.mts.map +1 -0
  135. package/dist/interaction/crosshair.mjs +141 -0
  136. package/dist/interaction/crosshair.mjs.map +1 -0
  137. package/dist/interaction/visibleRange.cjs +102 -0
  138. package/dist/interaction/visibleRange.cjs.map +1 -0
  139. package/dist/interaction/visibleRange.d.cts +11 -0
  140. package/dist/interaction/visibleRange.d.cts.map +1 -0
  141. package/dist/interaction/visibleRange.d.mts +11 -0
  142. package/dist/interaction/visibleRange.d.mts.map +1 -0
  143. package/dist/interaction/visibleRange.mjs +97 -0
  144. package/dist/interaction/visibleRange.mjs.map +1 -0
  145. package/dist/messages/contract.cjs +27 -0
  146. package/dist/messages/contract.cjs.map +1 -0
  147. package/dist/messages/contract.d.cts +262 -0
  148. package/dist/messages/contract.d.cts.map +1 -0
  149. package/dist/messages/contract.d.mts +262 -0
  150. package/dist/messages/contract.d.mts.map +1 -0
  151. package/dist/messages/contract.mjs +26 -0
  152. package/dist/messages/contract.mjs.map +1 -0
  153. package/dist/messages/handler.cjs +54 -0
  154. package/dist/messages/handler.cjs.map +1 -0
  155. package/dist/messages/handler.d.cts +25 -0
  156. package/dist/messages/handler.d.cts.map +1 -0
  157. package/dist/messages/handler.d.mts +25 -0
  158. package/dist/messages/handler.d.mts.map +1 -0
  159. package/dist/messages/handler.mjs +48 -0
  160. package/dist/messages/handler.mjs.map +1 -0
  161. package/dist/overlays/focusTime/index.cjs +161 -0
  162. package/dist/overlays/focusTime/index.cjs.map +1 -0
  163. package/dist/overlays/focusTime/index.d.cts +6 -0
  164. package/dist/overlays/focusTime/index.d.cts.map +1 -0
  165. package/dist/overlays/focusTime/index.d.mts +6 -0
  166. package/dist/overlays/focusTime/index.d.mts.map +1 -0
  167. package/dist/overlays/focusTime/index.mjs +155 -0
  168. package/dist/overlays/focusTime/index.mjs.map +1 -0
  169. package/dist/overlays/positionLines/index.cjs +188 -0
  170. package/dist/overlays/positionLines/index.cjs.map +1 -0
  171. package/dist/overlays/positionLines/index.d.cts +4 -0
  172. package/dist/overlays/positionLines/index.d.cts.map +1 -0
  173. package/dist/overlays/positionLines/index.d.mts +4 -0
  174. package/dist/overlays/positionLines/index.d.mts.map +1 -0
  175. package/dist/overlays/positionLines/index.mjs +183 -0
  176. package/dist/overlays/positionLines/index.mjs.map +1 -0
  177. package/dist/overlays/positionLines/state.cjs +35 -0
  178. package/dist/overlays/positionLines/state.cjs.map +1 -0
  179. package/dist/overlays/positionLines/state.d.cts +8 -0
  180. package/dist/overlays/positionLines/state.d.cts.map +1 -0
  181. package/dist/overlays/positionLines/state.d.mts +8 -0
  182. package/dist/overlays/positionLines/state.d.mts.map +1 -0
  183. package/dist/overlays/positionLines/state.mjs +26 -0
  184. package/dist/overlays/positionLines/state.mjs.map +1 -0
  185. package/dist/overlays/socialLeaderboard/index.cjs +229 -0
  186. package/dist/overlays/socialLeaderboard/index.cjs.map +1 -0
  187. package/dist/overlays/socialLeaderboard/index.d.cts +48 -0
  188. package/dist/overlays/socialLeaderboard/index.d.cts.map +1 -0
  189. package/dist/overlays/socialLeaderboard/index.d.mts +48 -0
  190. package/dist/overlays/socialLeaderboard/index.d.mts.map +1 -0
  191. package/dist/overlays/socialLeaderboard/index.mjs +222 -0
  192. package/dist/overlays/socialLeaderboard/index.mjs.map +1 -0
  193. package/dist/overlays/tradeMarkers/animation.cjs +123 -0
  194. package/dist/overlays/tradeMarkers/animation.cjs.map +1 -0
  195. package/dist/overlays/tradeMarkers/animation.d.cts +5 -0
  196. package/dist/overlays/tradeMarkers/animation.d.cts.map +1 -0
  197. package/dist/overlays/tradeMarkers/animation.d.mts +5 -0
  198. package/dist/overlays/tradeMarkers/animation.d.mts.map +1 -0
  199. package/dist/overlays/tradeMarkers/animation.mjs +118 -0
  200. package/dist/overlays/tradeMarkers/animation.mjs.map +1 -0
  201. package/dist/overlays/tradeMarkers/index.cjs +334 -0
  202. package/dist/overlays/tradeMarkers/index.cjs.map +1 -0
  203. package/dist/overlays/tradeMarkers/index.d.cts +35 -0
  204. package/dist/overlays/tradeMarkers/index.d.cts.map +1 -0
  205. package/dist/overlays/tradeMarkers/index.d.mts +35 -0
  206. package/dist/overlays/tradeMarkers/index.d.mts.map +1 -0
  207. package/dist/overlays/tradeMarkers/index.mjs +324 -0
  208. package/dist/overlays/tradeMarkers/index.mjs.map +1 -0
  209. package/dist/overlays/tradeMarkers/markerHitTest.cjs +337 -0
  210. package/dist/overlays/tradeMarkers/markerHitTest.cjs.map +1 -0
  211. package/dist/overlays/tradeMarkers/markerHitTest.d.cts +15 -0
  212. package/dist/overlays/tradeMarkers/markerHitTest.d.cts.map +1 -0
  213. package/dist/overlays/tradeMarkers/markerHitTest.d.mts +15 -0
  214. package/dist/overlays/tradeMarkers/markerHitTest.d.mts.map +1 -0
  215. package/dist/overlays/tradeMarkers/markerHitTest.mjs +331 -0
  216. package/dist/overlays/tradeMarkers/markerHitTest.mjs.map +1 -0
  217. package/dist/overlays/tradeMarkers/state.cjs +75 -0
  218. package/dist/overlays/tradeMarkers/state.cjs.map +1 -0
  219. package/dist/overlays/tradeMarkers/state.d.cts +20 -0
  220. package/dist/overlays/tradeMarkers/state.d.cts.map +1 -0
  221. package/dist/overlays/tradeMarkers/state.d.mts +20 -0
  222. package/dist/overlays/tradeMarkers/state.d.mts.map +1 -0
  223. package/dist/overlays/tradeMarkers/state.mjs +60 -0
  224. package/dist/overlays/tradeMarkers/state.mjs.map +1 -0
  225. package/dist/pagination/priceApi.cjs +102 -0
  226. package/dist/pagination/priceApi.cjs.map +1 -0
  227. package/dist/pagination/priceApi.d.cts +43 -0
  228. package/dist/pagination/priceApi.d.cts.map +1 -0
  229. package/dist/pagination/priceApi.d.mts +43 -0
  230. package/dist/pagination/priceApi.d.mts.map +1 -0
  231. package/dist/pagination/priceApi.mjs +97 -0
  232. package/dist/pagination/priceApi.mjs.map +1 -0
  233. package/dist/pagination/rnBacked.cjs +108 -0
  234. package/dist/pagination/rnBacked.cjs.map +1 -0
  235. package/dist/pagination/rnBacked.d.cts +15 -0
  236. package/dist/pagination/rnBacked.d.cts.map +1 -0
  237. package/dist/pagination/rnBacked.d.mts +15 -0
  238. package/dist/pagination/rnBacked.d.mts.map +1 -0
  239. package/dist/pagination/rnBacked.mjs +100 -0
  240. package/dist/pagination/rnBacked.mjs.map +1 -0
  241. package/dist/widget/chartType.cjs +39 -0
  242. package/dist/widget/chartType.cjs.map +1 -0
  243. package/dist/widget/chartType.d.cts +4 -0
  244. package/dist/widget/chartType.d.cts.map +1 -0
  245. package/dist/widget/chartType.d.mts +4 -0
  246. package/dist/widget/chartType.d.mts.map +1 -0
  247. package/dist/widget/chartType.mjs +34 -0
  248. package/dist/widget/chartType.mjs.map +1 -0
  249. package/dist/widget/datafeed.cjs +228 -0
  250. package/dist/widget/datafeed.cjs.map +1 -0
  251. package/dist/widget/datafeed.d.cts +22 -0
  252. package/dist/widget/datafeed.d.cts.map +1 -0
  253. package/dist/widget/datafeed.d.mts +22 -0
  254. package/dist/widget/datafeed.d.mts.map +1 -0
  255. package/dist/widget/datafeed.mjs +223 -0
  256. package/dist/widget/datafeed.mjs.map +1 -0
  257. package/dist/widget/externalLinkBridge.cjs +134 -0
  258. package/dist/widget/externalLinkBridge.cjs.map +1 -0
  259. package/dist/widget/externalLinkBridge.d.cts +14 -0
  260. package/dist/widget/externalLinkBridge.d.cts.map +1 -0
  261. package/dist/widget/externalLinkBridge.d.mts +14 -0
  262. package/dist/widget/externalLinkBridge.d.mts.map +1 -0
  263. package/dist/widget/externalLinkBridge.mjs +127 -0
  264. package/dist/widget/externalLinkBridge.mjs.map +1 -0
  265. package/dist/widget/initChart.cjs +242 -0
  266. package/dist/widget/initChart.cjs.map +1 -0
  267. package/dist/widget/initChart.d.cts +53 -0
  268. package/dist/widget/initChart.d.cts.map +1 -0
  269. package/dist/widget/initChart.d.mts +53 -0
  270. package/dist/widget/initChart.d.mts.map +1 -0
  271. package/dist/widget/initChart.mjs +235 -0
  272. package/dist/widget/initChart.mjs.map +1 -0
  273. package/dist/widget/ohlcvIngestion.cjs +240 -0
  274. package/dist/widget/ohlcvIngestion.cjs.map +1 -0
  275. package/dist/widget/ohlcvIngestion.d.cts +16 -0
  276. package/dist/widget/ohlcvIngestion.d.cts.map +1 -0
  277. package/dist/widget/ohlcvIngestion.d.mts +16 -0
  278. package/dist/widget/ohlcvIngestion.d.mts.map +1 -0
  279. package/dist/widget/ohlcvIngestion.mjs +233 -0
  280. package/dist/widget/ohlcvIngestion.mjs.map +1 -0
  281. package/dist/widget/priceFormatter.cjs +142 -0
  282. package/dist/widget/priceFormatter.cjs.map +1 -0
  283. package/dist/widget/priceFormatter.d.cts +38 -0
  284. package/dist/widget/priceFormatter.d.cts.map +1 -0
  285. package/dist/widget/priceFormatter.d.mts +38 -0
  286. package/dist/widget/priceFormatter.d.mts.map +1 -0
  287. package/dist/widget/priceFormatter.mjs +134 -0
  288. package/dist/widget/priceFormatter.mjs.map +1 -0
  289. package/dist/widget/scaleLayout.cjs +89 -0
  290. package/dist/widget/scaleLayout.cjs.map +1 -0
  291. package/dist/widget/scaleLayout.d.cts +9 -0
  292. package/dist/widget/scaleLayout.d.cts.map +1 -0
  293. package/dist/widget/scaleLayout.d.mts +9 -0
  294. package/dist/widget/scaleLayout.d.mts.map +1 -0
  295. package/dist/widget/scaleLayout.mjs +85 -0
  296. package/dist/widget/scaleLayout.mjs.map +1 -0
  297. package/dist/widget/theme.cjs +286 -0
  298. package/dist/widget/theme.cjs.map +1 -0
  299. package/dist/widget/theme.d.cts +99 -0
  300. package/dist/widget/theme.d.cts.map +1 -0
  301. package/dist/widget/theme.d.mts +99 -0
  302. package/dist/widget/theme.d.mts.map +1 -0
  303. package/dist/widget/theme.mjs +270 -0
  304. package/dist/widget/theme.mjs.map +1 -0
  305. package/dist/widget/tvDomHelpers.cjs +65 -0
  306. package/dist/widget/tvDomHelpers.cjs.map +1 -0
  307. package/dist/widget/tvDomHelpers.d.cts +19 -0
  308. package/dist/widget/tvDomHelpers.d.cts.map +1 -0
  309. package/dist/widget/tvDomHelpers.d.mts +19 -0
  310. package/dist/widget/tvDomHelpers.d.mts.map +1 -0
  311. package/dist/widget/tvDomHelpers.mjs +60 -0
  312. package/dist/widget/tvDomHelpers.mjs.map +1 -0
  313. package/dist/widget/visualOverrides.cjs +63 -0
  314. package/dist/widget/visualOverrides.cjs.map +1 -0
  315. package/dist/widget/visualOverrides.d.cts +27 -0
  316. package/dist/widget/visualOverrides.d.cts.map +1 -0
  317. package/dist/widget/visualOverrides.d.mts +27 -0
  318. package/dist/widget/visualOverrides.d.mts.map +1 -0
  319. package/dist/widget/visualOverrides.mjs +58 -0
  320. package/dist/widget/visualOverrides.mjs.map +1 -0
  321. package/package.json +3 -1
@@ -0,0 +1,40 @@
1
+ import type { LegendOverlayConfig, StudyId, TVActiveChart } from "../../core/types.cjs";
2
+ /**
3
+ * Called once on chart-ready to set up the DOM container.
4
+ *
5
+ * @param config - The legend overlay configuration, or undefined.
6
+ */
7
+ export declare function setupLegendOverlay(config: LegendOverlayConfig | undefined): void;
8
+ /**
9
+ * Subscribes to the widget's `panes_height_changed` event so the overlay
10
+ * max-width is recomputed whenever a pane resize (e.g. after adding MACD
11
+ * or RSI) shifts the price-axis boundary.
12
+ *
13
+ * @param widget - The TradingView widget (subset used here).
14
+ * @param widget.subscribe - Subscribes to the `panes_height_changed` event.
15
+ * @param widget.activeChart - Returns the active chart.
16
+ */
17
+ export declare function attachLegendResizeListener(widget: {
18
+ subscribe(event: 'panes_height_changed', handler: () => void): void;
19
+ activeChart(): TVActiveChart;
20
+ }): void;
21
+ export declare function refreshStudyLegendFromExport(): void;
22
+ /**
23
+ * Used by indicator handlers to request a legend rebuild after a study has
24
+ * been added/removed. Two rAFs to wait for TV's internal layout pass.
25
+ */
26
+ export declare function scheduleLegendRefresh(): void;
27
+ /**
28
+ * Subscribes to a study's onDataLoaded event so the legend refreshes once
29
+ * the study's calculation finishes. Falls back to immediate refresh when
30
+ * the subscription API isn't available.
31
+ *
32
+ * @param chart - The active TradingView chart.
33
+ * @param studyId - The id of the study to subscribe to.
34
+ */
35
+ export declare function subscribeStudyDataLoaded(chart: TVActiveChart, studyId: StudyId): void;
36
+ export declare function removeSubPaneOverlay(name: string): void;
37
+ export declare function updateLegendOverlayLayout(): void;
38
+ /** Test-only: clear all module-local state between cases. */
39
+ export declare function _resetLegendForTests(): void;
40
+ //# sourceMappingURL=legend.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legend.d.cts","sourceRoot":"","sources":["../../../src/features/indicators/legend.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,OAAO,EACP,aAAa,EAEd,6BAA4B;AAoB7B;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,mBAAmB,GAAG,SAAS,GACtC,IAAI,CAQN;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,SAAS,CAAC,KAAK,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACpE,WAAW,IAAI,aAAa,CAAC;CAC9B,GAAG,IAAI,CAYP;AAkUD,wBAAgB,4BAA4B,IAAI,IAAI,CA0CnD;AA2ED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,OAAO,GACf,IAAI,CAaN;AA4CD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAMvD;AAyCD,wBAAgB,yBAAyB,IAAI,IAAI,CAqBhD;AAED,6DAA6D;AAC7D,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C"}
@@ -0,0 +1,40 @@
1
+ import type { LegendOverlayConfig, StudyId, TVActiveChart } from "../../core/types.mjs";
2
+ /**
3
+ * Called once on chart-ready to set up the DOM container.
4
+ *
5
+ * @param config - The legend overlay configuration, or undefined.
6
+ */
7
+ export declare function setupLegendOverlay(config: LegendOverlayConfig | undefined): void;
8
+ /**
9
+ * Subscribes to the widget's `panes_height_changed` event so the overlay
10
+ * max-width is recomputed whenever a pane resize (e.g. after adding MACD
11
+ * or RSI) shifts the price-axis boundary.
12
+ *
13
+ * @param widget - The TradingView widget (subset used here).
14
+ * @param widget.subscribe - Subscribes to the `panes_height_changed` event.
15
+ * @param widget.activeChart - Returns the active chart.
16
+ */
17
+ export declare function attachLegendResizeListener(widget: {
18
+ subscribe(event: 'panes_height_changed', handler: () => void): void;
19
+ activeChart(): TVActiveChart;
20
+ }): void;
21
+ export declare function refreshStudyLegendFromExport(): void;
22
+ /**
23
+ * Used by indicator handlers to request a legend rebuild after a study has
24
+ * been added/removed. Two rAFs to wait for TV's internal layout pass.
25
+ */
26
+ export declare function scheduleLegendRefresh(): void;
27
+ /**
28
+ * Subscribes to a study's onDataLoaded event so the legend refreshes once
29
+ * the study's calculation finishes. Falls back to immediate refresh when
30
+ * the subscription API isn't available.
31
+ *
32
+ * @param chart - The active TradingView chart.
33
+ * @param studyId - The id of the study to subscribe to.
34
+ */
35
+ export declare function subscribeStudyDataLoaded(chart: TVActiveChart, studyId: StudyId): void;
36
+ export declare function removeSubPaneOverlay(name: string): void;
37
+ export declare function updateLegendOverlayLayout(): void;
38
+ /** Test-only: clear all module-local state between cases. */
39
+ export declare function _resetLegendForTests(): void;
40
+ //# sourceMappingURL=legend.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legend.d.mts","sourceRoot":"","sources":["../../../src/features/indicators/legend.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,OAAO,EACP,aAAa,EAEd,6BAA4B;AAoB7B;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,mBAAmB,GAAG,SAAS,GACtC,IAAI,CAQN;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,SAAS,CAAC,KAAK,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACpE,WAAW,IAAI,aAAa,CAAC;CAC9B,GAAG,IAAI,CAYP;AAkUD,wBAAgB,4BAA4B,IAAI,IAAI,CA0CnD;AA2ED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,OAAO,GACf,IAAI,CAaN;AA4CD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAMvD;AAyCD,wBAAgB,yBAAyB,IAAI,IAAI,CAqBhD;AAED,6DAA6D;AAC7D,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C"}
@@ -0,0 +1,564 @@
1
+ // DOM legend overlay for active indicator studies.
2
+ //
3
+ // Ported from chartLogic.js: createStudyLegendOverlay (~4365),
4
+ // refreshStudyLegendFromExport (~4644), buildLegendHTML (~4497),
5
+ // updateLegendOverlayLayout (~4401), legend retry/timeout machinery
6
+ // (~4630-4785), getMainPriceAxisLeftRelativeTo (~1472).
7
+ //
8
+ // The overlay is a `<div id="study-legend-overlay">` injected into
9
+ // #tv_chart_container that holds one `.legend-pill` per active indicator.
10
+ // Theme-aware text colors are computed from CONFIG.theme; per-plot colors
11
+ // come from the legend config supplied by RN.
12
+ //
13
+ // `LEGEND_RENDERED` is posted to RN once the overlay has settled (either
14
+ // real values returned by chart.exportData() or after the retry timeout).
15
+ import { postToRN } from "../../core/bridge.mjs";
16
+ import { doesLegendOwnLayoutSettle, getActiveStudies, getLegendStudyOrder, getMaStudies, getTheme, getVolumeStudyId, getWidget, isChartReady, setLegendOwnsLayoutSettle } from "../../core/state.mjs";
17
+ import { eachChartDocument } from "../../widget/tvDomHelpers.mjs";
18
+ const OVERLAY_ID = 'study-legend-overlay';
19
+ const OVERLAY_LEFT_PX = 8;
20
+ const MAX_RETRIES = 10;
21
+ const RETRY_DELAY_MS = 100;
22
+ const RENDER_TIMEOUT_MS = 3000;
23
+ let exportGeneration = 0;
24
+ let retryCount = 0;
25
+ let timeoutId = null;
26
+ let legendOverlayEnabled = false;
27
+ /** Typed legend config from RN — the single source of truth for legend rendering. */
28
+ let legendConfig;
29
+ /** Sub-pane overlay elements keyed by indicator name. */
30
+ const subPaneOverlays = new Map();
31
+ // ----- Lifecycle ---------------------------------------------------------
32
+ /**
33
+ * Called once on chart-ready to set up the DOM container.
34
+ *
35
+ * @param config - The legend overlay configuration, or undefined.
36
+ */
37
+ export function setupLegendOverlay(config) {
38
+ legendOverlayEnabled = Boolean(config?.enabled);
39
+ legendConfig = config?.config;
40
+ if (!legendOverlayEnabled) {
41
+ return;
42
+ }
43
+ createOverlayElement();
44
+ injectHideLegendButtonsCSS();
45
+ }
46
+ /**
47
+ * Subscribes to the widget's `panes_height_changed` event so the overlay
48
+ * max-width is recomputed whenever a pane resize (e.g. after adding MACD
49
+ * or RSI) shifts the price-axis boundary.
50
+ *
51
+ * @param widget - The TradingView widget (subset used here).
52
+ * @param widget.subscribe - Subscribes to the `panes_height_changed` event.
53
+ * @param widget.activeChart - Returns the active chart.
54
+ */
55
+ export function attachLegendResizeListener(widget) {
56
+ try {
57
+ widget.subscribe('panes_height_changed', () => {
58
+ const el = document.getElementById(OVERLAY_ID);
59
+ if (el) {
60
+ updateLegendOverlayLayout();
61
+ }
62
+ repositionSubPaneOverlays(widget.activeChart());
63
+ });
64
+ }
65
+ catch {
66
+ // TV may throw if subscribe isn't ready; safe to ignore.
67
+ }
68
+ }
69
+ function createOverlayElement() {
70
+ const existing = document.getElementById(OVERLAY_ID);
71
+ if (existing) {
72
+ existing.remove();
73
+ }
74
+ const container = document.getElementById('tv_chart_container');
75
+ if (!container) {
76
+ return;
77
+ }
78
+ const div = document.createElement('div');
79
+ div.id = OVERLAY_ID;
80
+ div.style.cssText =
81
+ `position:absolute;top:1px;left:${OVERLAY_LEFT_PX}px;z-index:5;` +
82
+ `pointer-events:none;display:flex;flex-wrap:wrap;align-items:flex-start;` +
83
+ `column-gap:8px;row-gap:2px;`;
84
+ container.style.position = 'relative';
85
+ container.appendChild(div);
86
+ }
87
+ function injectHideLegendButtonsCSS() {
88
+ const styleId = 'mm-hide-legend-buttons';
89
+ if (document.getElementById(styleId)) {
90
+ return;
91
+ }
92
+ let targetDoc = document;
93
+ eachChartDocument((doc) => {
94
+ if (targetDoc === document && doc !== document) {
95
+ targetDoc = doc;
96
+ }
97
+ });
98
+ const style = targetDoc.createElement('style');
99
+ style.id = styleId;
100
+ style.textContent =
101
+ '.chart-controls-bar .apply-common-tooltip,' +
102
+ '.legendElement .showHide,' +
103
+ '.legendElement button[data-name="legend-show-hide-action"],' +
104
+ '.legendElement button[data-name="legend-settings-action"],' +
105
+ '.legendElement button[data-name="legend-delete-action"],' +
106
+ '.legendElement .buttons-wrapper,' +
107
+ '.legendElement .buttonsWrapper{display:none!important;}';
108
+ targetDoc.head.appendChild(style);
109
+ }
110
+ // ----- Legend rebuild ---------------------------------------------------
111
+ /**
112
+ * Returns the per-indicator legend config supplied by RN via legendOverlay.config.
113
+ * Consumers must pass their own config — there is no built-in fallback.
114
+ *
115
+ * @returns The per-indicator legend config map (empty when unset).
116
+ */
117
+ function getPresetMap() {
118
+ return legendConfig ?? {};
119
+ }
120
+ function getLegendAltColor() {
121
+ const theme = getTheme();
122
+ return (theme?.legendTextColor ??
123
+ theme?.textAlternativeColor ??
124
+ theme?.textColor ??
125
+ 'rgb(133,136,152)');
126
+ }
127
+ function isEmptyValue(value) {
128
+ return !value || value === '' || value === 'n/a' || value === '∅';
129
+ }
130
+ function plotValue(indicatorConfig, plotCfg, plotIndex, values) {
131
+ if (indicatorConfig.useIndex && plotIndex < values.length) {
132
+ return values[plotIndex].value;
133
+ }
134
+ const match = values.find((candidate) => candidate.title === plotCfg.tvTitle);
135
+ return match?.value ?? '';
136
+ }
137
+ function wrapPill(innerHtml, color) {
138
+ const style = color ? ` style="color:${color};"` : '';
139
+ return `<span class="legend-pill"${style}>${innerHtml}</span>`;
140
+ }
141
+ function buildHTML(entries) {
142
+ const altColor = getLegendAltColor();
143
+ const presets = getPresetMap();
144
+ const successColor = getTheme()?.successColor ?? 'rgb(38,166,154)';
145
+ const pills = [];
146
+ for (const entry of entries) {
147
+ const indicatorConfig = presets[entry.name];
148
+ if (!indicatorConfig) {
149
+ continue;
150
+ }
151
+ if (indicatorConfig.isMA) {
152
+ const ma = indicatorConfig.plots[0];
153
+ const value = plotValue(indicatorConfig, ma, 0, entry.values);
154
+ if (isEmptyValue(value)) {
155
+ continue;
156
+ }
157
+ pills.push(wrapPill(`${ma.label} ${value}`, ma.color ?? undefined));
158
+ continue;
159
+ }
160
+ if (indicatorConfig.combineInOnePill) {
161
+ const labelColor = indicatorConfig.plots[0].color ?? successColor;
162
+ let inner = `<span style="color:${labelColor}">${indicatorConfig.title ?? indicatorConfig.plots[0].label}</span>`;
163
+ let hasValues = false;
164
+ indicatorConfig.plots.forEach((plot, idx) => {
165
+ const value = plotValue(indicatorConfig, plot, idx, entry.values);
166
+ if (isEmptyValue(value)) {
167
+ return;
168
+ }
169
+ hasValues = true;
170
+ inner +=
171
+ `<span style="color:${labelColor}">&nbsp;${plot.label}</span>` +
172
+ `<span style="color:${altColor}">&nbsp;${value}</span>`;
173
+ });
174
+ if (hasValues) {
175
+ pills.push(wrapPill(inner));
176
+ }
177
+ continue;
178
+ }
179
+ indicatorConfig.plots.forEach((plot, idx) => {
180
+ const value = plotValue(indicatorConfig, plot, idx, entry.values);
181
+ if (isEmptyValue(value)) {
182
+ return;
183
+ }
184
+ const color = plot.color ?? successColor;
185
+ const inner = `<span style="color:${color}">${plot.label}</span>` +
186
+ `<span style="color:${altColor}">&nbsp;${value}</span>`;
187
+ pills.push(wrapPill(inner));
188
+ });
189
+ }
190
+ return pills.join('');
191
+ }
192
+ // ----- Refresh from chart.exportData() ----------------------------------
193
+ function collectStudyIdMap() {
194
+ const map = {};
195
+ for (const [name, id] of getActiveStudies().entries()) {
196
+ map[String(id)] = name;
197
+ }
198
+ for (const [name, id] of getMaStudies().entries()) {
199
+ map[String(id)] = name;
200
+ }
201
+ const vol = getVolumeStudyId();
202
+ if (vol) {
203
+ map[String(vol)] = 'Volume';
204
+ }
205
+ return map;
206
+ }
207
+ function buildOrderedEntries(byStudy) {
208
+ const result = [];
209
+ for (const [name, studyId] of getLegendStudyOrder().entries()) {
210
+ const sid = String(studyId);
211
+ const values = byStudy[sid];
212
+ if (values) {
213
+ result.push({ name, values });
214
+ }
215
+ }
216
+ return result;
217
+ }
218
+ function formatLegendValue(value) {
219
+ if (!Number.isFinite(value)) {
220
+ return '';
221
+ }
222
+ const abs = Math.abs(value);
223
+ if (abs >= 1e9) {
224
+ return `${(value / 1e9).toFixed(2)}B`;
225
+ }
226
+ if (abs >= 1e6) {
227
+ return `${(value / 1e6).toFixed(2)}M`;
228
+ }
229
+ if (abs >= 1e4) {
230
+ return `${(value / 1e3).toFixed(1)}K`;
231
+ }
232
+ if (abs >= 1000) {
233
+ return value.toFixed(2);
234
+ }
235
+ if (abs >= 1) {
236
+ return value.toFixed(2);
237
+ }
238
+ if (abs >= 0.01) {
239
+ return value.toFixed(4);
240
+ }
241
+ return value.toPrecision(4);
242
+ }
243
+ function hasAnyEmpty(entries) {
244
+ for (const entry of entries) {
245
+ for (const value of entry.values) {
246
+ if (isEmptyValue(value.value)) {
247
+ return true;
248
+ }
249
+ }
250
+ }
251
+ return false;
252
+ }
253
+ function notifyLegendRendered() {
254
+ requestAnimationFrame(() => {
255
+ requestAnimationFrame(() => {
256
+ postToRN('LEGEND_RENDERED', {});
257
+ if (doesLegendOwnLayoutSettle()) {
258
+ setLegendOwnsLayoutSettle(false);
259
+ postToRN('CHART_LAYOUT_SETTLED', {});
260
+ }
261
+ });
262
+ });
263
+ }
264
+ function clearTimer() {
265
+ if (timeoutId !== null) {
266
+ clearTimeout(timeoutId);
267
+ timeoutId = null;
268
+ }
269
+ }
270
+ function startTimeout(gen) {
271
+ clearTimer();
272
+ timeoutId = setTimeout(() => {
273
+ if (gen !== exportGeneration) {
274
+ return;
275
+ }
276
+ retryCount = 0;
277
+ clearTimer();
278
+ notifyLegendRendered();
279
+ }, RENDER_TIMEOUT_MS);
280
+ }
281
+ function scheduleRetry(gen) {
282
+ if (retryCount >= MAX_RETRIES) {
283
+ retryCount = 0;
284
+ clearTimer();
285
+ notifyLegendRendered();
286
+ return;
287
+ }
288
+ retryCount += 1;
289
+ setTimeout(() => {
290
+ if (gen === exportGeneration) {
291
+ refreshStudyLegendFromExport();
292
+ }
293
+ }, RETRY_DELAY_MS);
294
+ }
295
+ function renderOverlay(entries) {
296
+ const presets = getPresetMap();
297
+ const widget = getWidget();
298
+ const chart = widget?.activeChart();
299
+ const activeStudies = getActiveStudies();
300
+ const mainEntries = [];
301
+ const subPaneEntries = [];
302
+ for (const entry of entries) {
303
+ const preset = presets[entry.name];
304
+ if (preset?.subPaneLegend && chart) {
305
+ const studyId = activeStudies.get(entry.name);
306
+ const study = studyId ? chart.getStudyById(studyId) : null;
307
+ const paneIdx = study?.paneIndex?.();
308
+ if (paneIdx !== undefined && paneIdx > 0) {
309
+ subPaneEntries.push({ name: entry.name, paneIdx, entry });
310
+ continue;
311
+ }
312
+ }
313
+ mainEntries.push(entry);
314
+ }
315
+ const mainOverlay = document.getElementById(OVERLAY_ID);
316
+ if (mainOverlay) {
317
+ mainOverlay.innerHTML = buildHTML(mainEntries);
318
+ }
319
+ const activeNames = new Set(subPaneEntries.map((subPane) => subPane.name));
320
+ for (const name of subPaneOverlays.keys()) {
321
+ if (!activeNames.has(name)) {
322
+ removeSubPaneOverlay(name);
323
+ }
324
+ }
325
+ for (const { name, paneIdx, entry } of subPaneEntries) {
326
+ const overlay = ensureSubPaneOverlay(name, paneIdx, chart ?? undefined);
327
+ if (overlay) {
328
+ overlay.innerHTML = buildHTML([entry]);
329
+ }
330
+ }
331
+ updateLegendOverlayLayout();
332
+ if (chart) {
333
+ repositionSubPaneOverlays(chart);
334
+ }
335
+ }
336
+ export function refreshStudyLegendFromExport() {
337
+ if (!legendOverlayEnabled) {
338
+ return;
339
+ }
340
+ const widget = getWidget();
341
+ if (!widget || !isChartReady()) {
342
+ return;
343
+ }
344
+ const overlay = document.getElementById(OVERLAY_ID);
345
+ if (!overlay) {
346
+ return;
347
+ }
348
+ const studyIdMap = collectStudyIdMap();
349
+ const studyIds = Object.keys(studyIdMap);
350
+ if (studyIds.length === 0) {
351
+ overlay.innerHTML = '';
352
+ removeAllSubPaneOverlays();
353
+ retryCount = 0;
354
+ clearTimer();
355
+ return;
356
+ }
357
+ exportGeneration += 1;
358
+ const gen = exportGeneration;
359
+ if (retryCount === 0) {
360
+ startTimeout(gen);
361
+ }
362
+ const chart = widget.activeChart();
363
+ chart
364
+ .exportData({
365
+ includeSeries: false,
366
+ includedStudies: studyIds,
367
+ })
368
+ .then((data) => {
369
+ if (gen === exportGeneration) {
370
+ handleExportData(data, gen);
371
+ }
372
+ return undefined;
373
+ })
374
+ .catch(() => scheduleRetry(gen));
375
+ }
376
+ function isValidExportData(data) {
377
+ return Boolean(data?.schema && data.data && data.data.length > 0);
378
+ }
379
+ function resolveDisplayValue(rawVal, colIndex, displayedData) {
380
+ let displayVal = rawVal !== undefined && !Number.isNaN(rawVal)
381
+ ? formatLegendValue(rawVal)
382
+ : '';
383
+ if (displayedData && displayedData.length > 0) {
384
+ const dispRow = displayedData.at(-1);
385
+ if (dispRow?.[colIndex]) {
386
+ displayVal = dispRow[colIndex];
387
+ }
388
+ }
389
+ return displayVal;
390
+ }
391
+ function buildStudyMap(data, lastRow) {
392
+ const byStudy = {};
393
+ for (let index = 0; index < data.schema.length; index++) {
394
+ const field = data.schema[index];
395
+ if (field.type === 'time' || field.type === 'userTime') {
396
+ continue;
397
+ }
398
+ const sid = field.sourceId ? String(field.sourceId) : '';
399
+ if (!sid) {
400
+ continue;
401
+ }
402
+ if (!byStudy[sid]) {
403
+ byStudy[sid] = [];
404
+ }
405
+ const displayVal = resolveDisplayValue(lastRow[index], index, data.displayedData);
406
+ byStudy[sid].push({ title: field.plotTitle ?? '', value: displayVal });
407
+ }
408
+ return byStudy;
409
+ }
410
+ function handleExportData(data, gen) {
411
+ if (!isValidExportData(data)) {
412
+ scheduleRetry(gen);
413
+ return;
414
+ }
415
+ const lastRow = data.data.at(-1);
416
+ if (!lastRow) {
417
+ scheduleRetry(gen);
418
+ return;
419
+ }
420
+ const byStudy = buildStudyMap(data, lastRow);
421
+ const entries = buildOrderedEntries(byStudy);
422
+ if (hasAnyEmpty(entries) && retryCount < MAX_RETRIES) {
423
+ scheduleRetry(gen);
424
+ return;
425
+ }
426
+ retryCount = 0;
427
+ renderOverlay(entries);
428
+ clearTimer();
429
+ notifyLegendRendered();
430
+ }
431
+ /**
432
+ * Used by indicator handlers to request a legend rebuild after a study has
433
+ * been added/removed. Two rAFs to wait for TV's internal layout pass.
434
+ */
435
+ export function scheduleLegendRefresh() {
436
+ requestAnimationFrame(() => {
437
+ requestAnimationFrame(() => refreshStudyLegendFromExport());
438
+ });
439
+ }
440
+ /**
441
+ * Subscribes to a study's onDataLoaded event so the legend refreshes once
442
+ * the study's calculation finishes. Falls back to immediate refresh when
443
+ * the subscription API isn't available.
444
+ *
445
+ * @param chart - The active TradingView chart.
446
+ * @param studyId - The id of the study to subscribe to.
447
+ */
448
+ export function subscribeStudyDataLoaded(chart, studyId) {
449
+ try {
450
+ const study = chart.getStudyById(studyId);
451
+ if (study?.onDataLoaded) {
452
+ study.onDataLoaded().subscribe(null, () => {
453
+ scheduleLegendRefresh();
454
+ });
455
+ return;
456
+ }
457
+ }
458
+ catch {
459
+ // Fallthrough to direct refresh.
460
+ }
461
+ scheduleLegendRefresh();
462
+ }
463
+ // ----- Sub-pane overlay management ----------------------------------------
464
+ function subPaneOverlayId(name) {
465
+ return `${OVERLAY_ID}-pane-${name}`;
466
+ }
467
+ function getSubPaneTopPx(paneIndex, chart) {
468
+ const heights = chart.getAllPanesHeight();
469
+ let top = 0;
470
+ for (let i = 0; i < paneIndex && i < heights.length; i++) {
471
+ top += heights[i];
472
+ }
473
+ return top + 4;
474
+ }
475
+ function ensureSubPaneOverlay(name, paneIndex, chart) {
476
+ const existing = subPaneOverlays.get(name);
477
+ if (existing && document.contains(existing)) {
478
+ return existing;
479
+ }
480
+ const container = document.getElementById('tv_chart_container');
481
+ if (!container) {
482
+ return null;
483
+ }
484
+ const div = document.createElement('div');
485
+ div.id = subPaneOverlayId(name);
486
+ const topPx = chart ? getSubPaneTopPx(paneIndex, chart) : 0;
487
+ div.style.cssText =
488
+ `position:absolute;top:${topPx}px;left:${OVERLAY_LEFT_PX}px;z-index:5;` +
489
+ `pointer-events:none;display:flex;flex-wrap:wrap;align-items:flex-start;` +
490
+ `column-gap:8px;row-gap:2px;`;
491
+ container.appendChild(div);
492
+ subPaneOverlays.set(name, div);
493
+ return div;
494
+ }
495
+ export function removeSubPaneOverlay(name) {
496
+ const el = subPaneOverlays.get(name);
497
+ if (el) {
498
+ el.remove();
499
+ subPaneOverlays.delete(name);
500
+ }
501
+ }
502
+ function removeAllSubPaneOverlays() {
503
+ for (const el of subPaneOverlays.values()) {
504
+ el.remove();
505
+ }
506
+ subPaneOverlays.clear();
507
+ }
508
+ function repositionSubPaneOverlays(chart) {
509
+ const activeStudies = getActiveStudies();
510
+ for (const [name, el] of subPaneOverlays) {
511
+ const studyId = activeStudies.get(name);
512
+ const study = studyId ? chart.getStudyById(studyId) : null;
513
+ const paneIdx = study?.paneIndex?.();
514
+ if (paneIdx !== undefined && paneIdx > 0) {
515
+ el.style.top = `${getSubPaneTopPx(paneIdx, chart)}px`;
516
+ }
517
+ }
518
+ }
519
+ // ----- Layout ------------------------------------------------------------
520
+ const FALLBACK_SCALE_WIDTH = 48;
521
+ const SCALE_GAP = 4;
522
+ function getPriceScaleWidth() {
523
+ const widget = getWidget();
524
+ if (!widget) {
525
+ return FALLBACK_SCALE_WIDTH;
526
+ }
527
+ const chart = widget.activeChart();
528
+ const panes = chart.getPanes?.();
529
+ if (!panes || panes.length === 0) {
530
+ return FALLBACK_SCALE_WIDTH;
531
+ }
532
+ const scales = panes[0].getRightPriceScales?.();
533
+ const width = scales?.[0]?.width?.();
534
+ return width && width > 0 ? width : FALLBACK_SCALE_WIDTH;
535
+ }
536
+ export function updateLegendOverlayLayout() {
537
+ const container = document.getElementById('tv_chart_container');
538
+ if (!container) {
539
+ return;
540
+ }
541
+ const containerWidth = container.clientWidth;
542
+ if (containerWidth <= 0) {
543
+ return;
544
+ }
545
+ const scaleWidth = getPriceScaleWidth();
546
+ const maxWidth = `${containerWidth - OVERLAY_LEFT_PX - scaleWidth - SCALE_GAP}px`;
547
+ const overlay = document.getElementById(OVERLAY_ID);
548
+ if (overlay) {
549
+ overlay.style.maxWidth = maxWidth;
550
+ }
551
+ for (const el of subPaneOverlays.values()) {
552
+ el.style.maxWidth = maxWidth;
553
+ }
554
+ }
555
+ /** Test-only: clear all module-local state between cases. */
556
+ export function _resetLegendForTests() {
557
+ exportGeneration = 0;
558
+ retryCount = 0;
559
+ clearTimer();
560
+ legendOverlayEnabled = false;
561
+ legendConfig = undefined;
562
+ removeAllSubPaneOverlays();
563
+ }
564
+ //# sourceMappingURL=legend.mjs.map