velo-plot 1.12.0 → 1.19.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.
Files changed (153) hide show
  1. package/README.md +14 -0
  2. package/dist/{index.core-xiNcuFfJ.js → ChartCore-DQ691eXH.js} +1807 -1287
  3. package/dist/ChartCore-DQ691eXH.js.map +1 -0
  4. package/dist/assets/downsample.worker-C70QJ04y.js +2 -0
  5. package/dist/assets/downsample.worker-C70QJ04y.js.map +1 -0
  6. package/dist/assets/indicator.worker-bv0zC4EX.js +2 -0
  7. package/dist/assets/indicator.worker-bv0zC4EX.js.map +1 -0
  8. package/dist/core/OverlayRenderer.d.ts +2 -0
  9. package/dist/core/chart/ChartAlerts.d.ts +42 -0
  10. package/dist/core/chart/ChartCore.d.ts +20 -1
  11. package/dist/core/chart/ChartRenderLoop.d.ts +4 -2
  12. package/dist/core/chart/ChartRenderer.d.ts +3 -2
  13. package/dist/core/chart/candlestickMarkers.d.ts +23 -0
  14. package/dist/core/chart/exporter/SVGExporter.d.ts +7 -2
  15. package/dist/core/chart/heikinAshi.d.ts +10 -0
  16. package/dist/core/chart/series/types.d.ts +2 -2
  17. package/dist/core/chart/types.d.ts +9 -0
  18. package/dist/core/indicator/addIndicator.d.ts +36 -0
  19. package/dist/core/indicator/index.d.ts +2 -0
  20. package/dist/core/indicator/indicatorPresets.d.ts +37 -0
  21. package/dist/core/render/pixelSnap.d.ts +8 -0
  22. package/dist/core/series/Series.d.ts +3 -0
  23. package/dist/core/stacked/index.d.ts +3 -1
  24. package/dist/core/stacked/paneResize.d.ts +15 -18
  25. package/dist/core/stacked/stackExport.d.ts +18 -0
  26. package/dist/core/stacked/types.d.ts +42 -5
  27. package/dist/core/time/TimeScale.d.ts +31 -0
  28. package/dist/createStackedChart-BPooTQ9z.js +1164 -0
  29. package/dist/createStackedChart-BPooTQ9z.js.map +1 -0
  30. package/dist/gpu/adapter/gpuRenderer.d.ts +21 -0
  31. package/dist/gpu/backends/webgpu/WebGPUBackend.d.ts +2 -1
  32. package/dist/gpuRenderer-BpaMYz-k.js +1848 -0
  33. package/dist/gpuRenderer-BpaMYz-k.js.map +1 -0
  34. package/dist/index-CUGS98p4.js +277 -0
  35. package/dist/index-CUGS98p4.js.map +1 -0
  36. package/dist/index-D7dTq6VB.js +503 -0
  37. package/dist/index-D7dTq6VB.js.map +1 -0
  38. package/dist/{index-Ce2JgkH_.js → index-DoYxf1cV.js} +86 -43
  39. package/dist/{index-Ce2JgkH_.js.map → index-DoYxf1cV.js.map} +1 -1
  40. package/dist/index.core-BtGFYMOu.js +167 -0
  41. package/dist/index.core-BtGFYMOu.js.map +1 -0
  42. package/dist/index.d.ts +12 -4
  43. package/dist/indicators--eJGmVox.js +302 -0
  44. package/dist/indicators--eJGmVox.js.map +1 -0
  45. package/dist/math-Ddm2EZjj.js +85 -0
  46. package/dist/math-Ddm2EZjj.js.map +1 -0
  47. package/dist/plugins/analysis.js +543 -818
  48. package/dist/plugins/analysis.js.map +1 -1
  49. package/dist/plugins/anomaly-detection.d.ts +1 -0
  50. package/dist/plugins/anomaly-detection.js +221 -0
  51. package/dist/plugins/anomaly-detection.js.map +1 -0
  52. package/dist/plugins/broken-axis.d.ts +3 -0
  53. package/dist/plugins/broken-axis.js +262 -0
  54. package/dist/plugins/broken-axis.js.map +1 -0
  55. package/dist/plugins/caching.d.ts +3 -0
  56. package/dist/plugins/caching.js +187 -0
  57. package/dist/plugins/caching.js.map +1 -0
  58. package/dist/plugins/data-transform.d.ts +3 -0
  59. package/dist/plugins/data-transform.js +146 -0
  60. package/dist/plugins/data-transform.js.map +1 -0
  61. package/dist/plugins/debug.js +12 -11
  62. package/dist/plugins/debug.js.map +1 -1
  63. package/dist/plugins/drawing-tools/index.d.ts +16 -0
  64. package/dist/plugins/forecasting.d.ts +1 -0
  65. package/dist/plugins/forecasting.js +236 -0
  66. package/dist/plugins/forecasting.js.map +1 -0
  67. package/dist/plugins/gpu.js +202 -1895
  68. package/dist/plugins/gpu.js.map +1 -1
  69. package/dist/plugins/index.d.ts +2 -0
  70. package/dist/plugins/keyboard/index.d.ts +1 -7
  71. package/dist/plugins/keyboard.js +1 -1
  72. package/dist/plugins/latex.d.ts +1 -0
  73. package/dist/plugins/latex.js +454 -0
  74. package/dist/plugins/latex.js.map +1 -0
  75. package/dist/plugins/lazy-load/types.d.ts +7 -0
  76. package/dist/plugins/lazy-load.d.ts +3 -0
  77. package/dist/plugins/lazy-load.js +212 -0
  78. package/dist/plugins/lazy-load.js.map +1 -0
  79. package/dist/plugins/ml-integration.d.ts +3 -0
  80. package/dist/plugins/ml-integration.js +355 -0
  81. package/dist/plugins/ml-integration.js.map +1 -0
  82. package/dist/plugins/offscreen.d.ts +3 -0
  83. package/dist/plugins/offscreen.js +169 -0
  84. package/dist/plugins/offscreen.js.map +1 -0
  85. package/dist/plugins/pattern-recognition.d.ts +3 -0
  86. package/dist/plugins/pattern-recognition.js +690 -0
  87. package/dist/plugins/pattern-recognition.js.map +1 -0
  88. package/dist/plugins/radar.d.ts +3 -0
  89. package/dist/plugins/radar.js +103 -0
  90. package/dist/plugins/radar.js.map +1 -0
  91. package/dist/plugins/regression.d.ts +3 -0
  92. package/dist/plugins/regression.js +634 -0
  93. package/dist/plugins/regression.js.map +1 -0
  94. package/dist/plugins/replay/index.d.ts +19 -0
  95. package/dist/plugins/roi.d.ts +1 -0
  96. package/dist/plugins/roi.js +223 -0
  97. package/dist/plugins/roi.js.map +1 -0
  98. package/dist/plugins/snapshot/types.d.ts +1 -1
  99. package/dist/plugins/snapshot.d.ts +3 -0
  100. package/dist/plugins/snapshot.js +90 -0
  101. package/dist/plugins/snapshot.js.map +1 -0
  102. package/dist/plugins/sync/index.d.ts +2 -1
  103. package/dist/plugins/sync.js +13 -269
  104. package/dist/plugins/sync.js.map +1 -1
  105. package/dist/plugins/video-recorder.d.ts +3 -0
  106. package/dist/plugins/video-recorder.js +104 -0
  107. package/dist/plugins/video-recorder.js.map +1 -0
  108. package/dist/plugins/virtualization/types.d.ts +12 -0
  109. package/dist/plugins/virtualization.d.ts +3 -0
  110. package/dist/plugins/virtualization.js +6 -0
  111. package/dist/plugins/virtualization.js.map +1 -0
  112. package/dist/pool-15HMCNv8.js +88 -0
  113. package/dist/pool-15HMCNv8.js.map +1 -0
  114. package/dist/react.d.ts +1 -0
  115. package/dist/react.js +31 -0
  116. package/dist/react.js.map +1 -0
  117. package/dist/renderer/CandlestickRenderer.d.ts +1 -1
  118. package/dist/renderer/ChartSeriesRenderer.d.ts +6 -0
  119. package/dist/renderer/GpuChartRenderer.d.ts +23 -0
  120. package/dist/renderer/index.d.ts +3 -0
  121. package/dist/renderer/spike/WebGLGridSpike.d.ts +40 -0
  122. package/dist/testing/baselines/v1.15.0.json.d.ts +51 -0
  123. package/dist/testing/gridSpikeBenchmark.d.ts +49 -0
  124. package/dist/testing/index.d.ts +5 -0
  125. package/dist/testing/rendererBenchmark.d.ts +13 -0
  126. package/dist/testing/stage1BrowserBench.d.ts +42 -0
  127. package/dist/types.d.ts +21 -1
  128. package/dist/utils-BK5UUXxj.js +172 -0
  129. package/dist/utils-BK5UUXxj.js.map +1 -0
  130. package/dist/velo-plot.full.js +1382 -5932
  131. package/dist/velo-plot.full.js.map +1 -1
  132. package/dist/velo-plot.js +26 -25
  133. package/dist/velo-plot.js.map +1 -1
  134. package/dist/workers/downsample.d.ts +38 -0
  135. package/dist/workers/downsampleAsync.d.ts +6 -0
  136. package/dist/workers/indicator.worker.d.ts +32 -0
  137. package/dist/workers/indicatorsAsync.d.ts +26 -0
  138. package/dist/workers/pool.d.ts +36 -0
  139. package/package.json +19 -2
  140. package/dist/core/OverlayRenderer.test.d.ts +0 -1
  141. package/dist/core/chart/ChartScaling.test.d.ts +0 -1
  142. package/dist/core/chart/NavigationUtils.test.d.ts +0 -1
  143. package/dist/core/format/axisFormat.test.d.ts +0 -1
  144. package/dist/core/indicator/buildIndicatorSeries.test.d.ts +0 -1
  145. package/dist/core/series/SeriesBounds.test.d.ts +0 -1
  146. package/dist/core/stacked/createStackedChart.test.d.ts +0 -1
  147. package/dist/core/stacked/paneAxis.test.d.ts +0 -1
  148. package/dist/core/stacked/paneResize.test.d.ts +0 -1
  149. package/dist/core/sync/index.test.d.ts +0 -1
  150. package/dist/index.core-xiNcuFfJ.js.map +0 -1
  151. package/dist/plugins/tools/tooltip/format.test.d.ts +0 -1
  152. package/dist/utils-Dbro9-qM.js +0 -254
  153. package/dist/utils-Dbro9-qM.js.map +0 -1
@@ -0,0 +1,690 @@
1
+ function C(s) {
2
+ const e = [], n = [];
3
+ for (let t = 1; t < s.length - 1; t++) {
4
+ const o = s[t - 1], i = s[t], g = s[t + 1];
5
+ i.y > o.y && i.y > g.y ? e.push({ ...i, type: "peak" }) : i.y < o.y && i.y < g.y && n.push({ ...i, type: "valley" });
6
+ }
7
+ return { peaks: e, valleys: n };
8
+ }
9
+ function I(s, e) {
10
+ return (e.y - s.y) / (e.x - s.x);
11
+ }
12
+ function T(s) {
13
+ const e = s.map((g) => g.y), n = s.map((g) => g.x), t = Math.max(...e) - Math.min(...e), o = Math.max(...n) - Math.min(...n), i = I(s[0], s[s.length - 1]);
14
+ return {
15
+ height: t,
16
+ width: o,
17
+ slope: i,
18
+ volumeProfile: {
19
+ increasing: 0.4,
20
+ // Mock values
21
+ decreasing: 0.3,
22
+ neutral: 0.3
23
+ },
24
+ breakoutTarget: Math.max(...e) + t * 0.8,
25
+ stopLoss: Math.min(...e) - t * 0.2
26
+ };
27
+ }
28
+ function D(s) {
29
+ if (s.length < 5)
30
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for head-shoulders pattern"] };
31
+ const { peaks: e, valleys: n } = C(s);
32
+ if (e.length < 3 || n.length < 2)
33
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
34
+ const t = e[0], o = e[1], i = e[2], g = n[0], u = n[1], p = o.y > t.y && o.y > i.y, y = Math.abs(t.y - i.y) / t.y < 0.1, k = g.y < t.y && u.y < i.y;
35
+ if (!p || !y || !k)
36
+ return {
37
+ valid: !1,
38
+ confidence: 0,
39
+ segments: [],
40
+ keyPoints: [],
41
+ errors: ["Invalid head-shoulders structure"]
42
+ };
43
+ const x = [
44
+ { start: t, end: g, type: "resistance", strength: 0.8 },
45
+ { start: g, end: o, type: "support", strength: 0.7 },
46
+ { start: o, end: u, type: "resistance", strength: 0.8 },
47
+ { start: u, end: i, type: "support", strength: 0.7 }
48
+ ], b = [t, g, o, u, i], M = T(s), a = 1 - Math.abs(t.y - i.y) / o.y, l = 1 - Math.abs(g.y - u.y) / o.y;
49
+ return {
50
+ valid: !0,
51
+ confidence: (a + l) / 2,
52
+ segments: x,
53
+ keyPoints: b,
54
+ measurements: M
55
+ };
56
+ }
57
+ function q(s) {
58
+ if (s.length < 4)
59
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for double top"] };
60
+ const { peaks: e, valleys: n } = C(s);
61
+ if (e.length < 2 || n.length < 1)
62
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
63
+ const t = e[0], o = e[1], i = n[0], g = Math.abs(t.y - o.y) / t.y < 0.05, u = i.y < t.y && i.y < o.y, p = (t.y - i.y) / t.y > 0.1;
64
+ if (!g || !u || !p)
65
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Invalid double top structure"] };
66
+ const y = [
67
+ { start: t, end: i, type: "resistance", strength: 0.9 },
68
+ { start: i, end: o, type: "support", strength: 0.8 },
69
+ { start: t, end: o, type: "resistance", strength: 0.9 }
70
+ ], k = [t, i, o], x = T(s), b = 1 - Math.abs(t.y - o.y) / t.y, M = (t.y - i.y) / t.y;
71
+ return {
72
+ valid: !0,
73
+ confidence: (b + Math.min(M * 2, 1)) / 2,
74
+ segments: y,
75
+ keyPoints: k,
76
+ measurements: x
77
+ };
78
+ }
79
+ function E(s) {
80
+ if (s.length < 4)
81
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for double bottom"] };
82
+ const { peaks: e, valleys: n } = C(s);
83
+ if (n.length < 2 || e.length < 1)
84
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
85
+ const t = n[0], o = n[1], i = e[0], g = Math.abs(t.y - o.y) / t.y < 0.05, u = i.y > t.y && i.y > o.y, p = (i.y - t.y) / t.y > 0.1;
86
+ if (!g || !u || !p)
87
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Invalid double bottom structure"] };
88
+ const y = [
89
+ { start: t, end: i, type: "support", strength: 0.9 },
90
+ { start: i, end: o, type: "resistance", strength: 0.8 },
91
+ { start: t, end: o, type: "support", strength: 0.9 }
92
+ ], k = [t, i, o], x = T(s), b = 1 - Math.abs(t.y - o.y) / t.y, M = (i.y - t.y) / t.y;
93
+ return {
94
+ valid: !0,
95
+ confidence: (b + Math.min(M * 2, 1)) / 2,
96
+ segments: y,
97
+ keyPoints: k,
98
+ measurements: x
99
+ };
100
+ }
101
+ function _(s) {
102
+ if (s.length < 4)
103
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points for ascending triangle"] };
104
+ const e = s.map((a) => a.y), n = Math.max(...e), t = s.filter((a) => Math.abs(a.y - n) / n < 0.02);
105
+ if (t.length < 2)
106
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient resistance points"] };
107
+ const o = s.filter((a, l) => l === 0 || a.y < s[l - 1].y);
108
+ if (o.length < 2)
109
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient low points"] };
110
+ const i = o[0], g = o[o.length - 1], u = I(i, g);
111
+ if (u <= 0)
112
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Support not ascending"] };
113
+ const p = [
114
+ { start: t[0], end: t[t.length - 1], type: "resistance", strength: 0.8 },
115
+ { start: i, end: g, type: "support", strength: 0.7 }
116
+ ], y = [...t.slice(0, 2), i, g], k = T(s), x = 1 - Math.abs(t[0].y - t[t.length - 1].y) / n, b = Math.min(u / 0.01, 1);
117
+ return {
118
+ valid: !0,
119
+ confidence: (x + b) / 2,
120
+ segments: p,
121
+ keyPoints: y,
122
+ measurements: k
123
+ };
124
+ }
125
+ const B = {
126
+ "head-shoulders": {
127
+ id: "head-shoulders",
128
+ type: "head-shoulders",
129
+ name: "Head and Shoulders",
130
+ description: "Bearish reversal pattern with three peaks",
131
+ minPoints: 5,
132
+ maxPoints: 7,
133
+ validator: D
134
+ },
135
+ "inverse-head-shoulders": {
136
+ id: "inverse-head-shoulders",
137
+ type: "inverse-head-shoulders",
138
+ name: "Inverse Head and Shoulders",
139
+ description: "Bullish reversal pattern with three valleys",
140
+ minPoints: 5,
141
+ maxPoints: 7,
142
+ validator: (s) => {
143
+ const e = s.map((t) => ({ ...t, y: -t.y }));
144
+ return D(e);
145
+ }
146
+ },
147
+ "double-top": {
148
+ id: "double-top",
149
+ type: "double-top",
150
+ name: "Double Top",
151
+ description: "Bearish reversal pattern with two equal peaks",
152
+ minPoints: 4,
153
+ maxPoints: 6,
154
+ validator: q
155
+ },
156
+ "double-bottom": {
157
+ id: "double-bottom",
158
+ type: "double-bottom",
159
+ name: "Double Bottom",
160
+ description: "Bullish reversal pattern with two equal valleys",
161
+ minPoints: 4,
162
+ maxPoints: 6,
163
+ validator: E
164
+ },
165
+ "triple-top": {
166
+ id: "triple-top",
167
+ type: "triple-top",
168
+ name: "Triple Top",
169
+ description: "Bearish reversal pattern with three equal peaks",
170
+ minPoints: 5,
171
+ maxPoints: 7,
172
+ validator: (s) => {
173
+ if (s.length < 5)
174
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
175
+ const { peaks: e } = C(s);
176
+ if (e.length < 3)
177
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Need at least 3 peaks"] };
178
+ const n = e[0].y, t = e[1].y, o = e[2].y, i = 0.05;
179
+ if (!(Math.abs(n - t) / n < i && Math.abs(t - o) / t < i))
180
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Peaks not equal"] };
181
+ const u = [
182
+ { start: e[0], end: e[1], type: "resistance", strength: 0.8 },
183
+ { start: e[1], end: e[2], type: "resistance", strength: 0.8 }
184
+ ], p = [e[0], e[1], e[2]], y = T(s);
185
+ return {
186
+ valid: !0,
187
+ confidence: 0.8,
188
+ segments: u,
189
+ keyPoints: p,
190
+ measurements: y
191
+ };
192
+ }
193
+ },
194
+ "triple-bottom": {
195
+ id: "triple-bottom",
196
+ type: "triple-bottom",
197
+ name: "Triple Bottom",
198
+ description: "Bullish reversal pattern with three equal valleys",
199
+ minPoints: 5,
200
+ maxPoints: 7,
201
+ validator: (s) => {
202
+ const e = s.map((n) => ({ ...n, y: -n.y }));
203
+ return B["triple-top"].validator(e);
204
+ }
205
+ },
206
+ "ascending-triangle": {
207
+ id: "ascending-triangle",
208
+ type: "ascending-triangle",
209
+ name: "Ascending Triangle",
210
+ description: "Continuation pattern with horizontal resistance and ascending support",
211
+ minPoints: 4,
212
+ maxPoints: 8,
213
+ validator: _
214
+ },
215
+ "descending-triangle": {
216
+ id: "descending-triangle",
217
+ type: "descending-triangle",
218
+ name: "Descending Triangle",
219
+ description: "Continuation pattern with horizontal support and descending resistance",
220
+ minPoints: 4,
221
+ maxPoints: 8,
222
+ validator: (s) => {
223
+ const e = s.map((t) => ({ ...t, y: -t.y }));
224
+ return _(e);
225
+ }
226
+ },
227
+ "symmetrical-triangle": {
228
+ id: "symmetrical-triangle",
229
+ type: "symmetrical-triangle",
230
+ name: "Symmetrical Triangle",
231
+ description: "Continuation pattern with converging support and resistance",
232
+ minPoints: 4,
233
+ maxPoints: 8,
234
+ validator: (s) => {
235
+ if (s.length < 4)
236
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
237
+ const e = s.slice(0, Math.floor(s.length / 2)), n = s.slice(Math.floor(s.length / 2)), t = I(e[0], e[e.length - 1]), o = I(n[0], n[n.length - 1]);
238
+ if (!(t > 0 && o < 0 || t < 0 && o > 0))
239
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Lines not converging"] };
240
+ const g = [
241
+ { start: e[0], end: e[e.length - 1], type: "trendline", strength: 0.7 },
242
+ { start: n[0], end: n[n.length - 1], type: "trendline", strength: 0.7 }
243
+ ], u = [e[0], e[e.length - 1], n[0], n[n.length - 1]], p = T(s);
244
+ return {
245
+ valid: !0,
246
+ confidence: 0.7,
247
+ segments: g,
248
+ keyPoints: u,
249
+ measurements: p
250
+ };
251
+ }
252
+ },
253
+ "rising-wedge": {
254
+ id: "rising-wedge",
255
+ type: "rising-wedge",
256
+ name: "Rising Wedge",
257
+ description: "Bearish reversal pattern with two converging upward lines",
258
+ minPoints: 4,
259
+ maxPoints: 8,
260
+ validator: (s) => {
261
+ if (s.length < 4)
262
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
263
+ const { peaks: e, valleys: n } = C(s);
264
+ if (e.length < 2 || n.length < 2)
265
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient peaks/valleys"] };
266
+ const t = I(e[0], e[e.length - 1]), o = I(n[0], n[n.length - 1]);
267
+ if (!(t > 0 && o > 0 && o > t))
268
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Not a rising wedge pattern"] };
269
+ const g = [
270
+ { start: e[0], end: e[e.length - 1], type: "resistance", strength: 0.8 },
271
+ { start: n[0], end: n[n.length - 1], type: "support", strength: 0.8 }
272
+ ], u = [e[0], e[e.length - 1], n[0], n[n.length - 1]], p = T(s);
273
+ return {
274
+ valid: !0,
275
+ confidence: 0.75,
276
+ segments: g,
277
+ keyPoints: u,
278
+ measurements: p
279
+ };
280
+ }
281
+ },
282
+ "falling-wedge": {
283
+ id: "falling-wedge",
284
+ type: "falling-wedge",
285
+ name: "Falling Wedge",
286
+ description: "Bullish reversal pattern with two converging downward lines",
287
+ minPoints: 4,
288
+ maxPoints: 8,
289
+ validator: (s) => {
290
+ const e = s.map((t) => ({ ...t, y: -t.y }));
291
+ return B["rising-wedge"].validator(e);
292
+ }
293
+ },
294
+ rectangle: {
295
+ id: "rectangle",
296
+ type: "rectangle",
297
+ name: "Rectangle",
298
+ description: "Continuation pattern with horizontal support and resistance",
299
+ minPoints: 4,
300
+ maxPoints: 10,
301
+ validator: (s) => {
302
+ if (s.length < 4)
303
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
304
+ const e = s.map((y) => y.y), n = Math.max(...e), t = Math.min(...e), o = s.filter((y) => Math.abs(y.y - n) / n < 0.05), i = s.filter((y) => Math.abs(y.y - t) / t < 0.05);
305
+ if (o.length < 2 || i.length < 2)
306
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient horizontal lines"] };
307
+ const g = [
308
+ { start: o[0], end: o[o.length - 1], type: "resistance", strength: 0.9 },
309
+ { start: i[0], end: i[i.length - 1], type: "support", strength: 0.9 }
310
+ ], u = [o[0], o[o.length - 1], i[0], i[i.length - 1]], p = T(s);
311
+ return {
312
+ valid: !0,
313
+ confidence: 0.8,
314
+ segments: g,
315
+ keyPoints: u,
316
+ measurements: p
317
+ };
318
+ }
319
+ },
320
+ flag: {
321
+ id: "flag",
322
+ type: "flag",
323
+ name: "Flag",
324
+ description: "Short-term continuation pattern after strong move",
325
+ minPoints: 3,
326
+ maxPoints: 6,
327
+ validator: (s) => {
328
+ if (s.length < 3)
329
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
330
+ const e = I(s[0], s[s.length - 1]);
331
+ if (!(Math.abs(e) < 0.01))
332
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Not horizontal enough"] };
333
+ const t = [
334
+ { start: s[0], end: s[s.length - 1], type: "trendline", strength: 0.6 }
335
+ ], o = [s[0], s[s.length - 1]], i = T(s);
336
+ return {
337
+ valid: !0,
338
+ confidence: 0.6,
339
+ segments: t,
340
+ keyPoints: o,
341
+ measurements: i
342
+ };
343
+ }
344
+ },
345
+ pennant: {
346
+ id: "pennant",
347
+ type: "pennant",
348
+ name: "Pennant",
349
+ description: "Short-term continuation pattern with converging lines",
350
+ minPoints: 3,
351
+ maxPoints: 5,
352
+ validator: (s) => B["symmetrical-triangle"].validator(s)
353
+ },
354
+ custom: {
355
+ id: "custom",
356
+ type: "custom",
357
+ name: "Custom Pattern",
358
+ description: "User-defined pattern",
359
+ minPoints: 3,
360
+ validator: (s) => ({ valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Custom pattern not implemented"] })
361
+ }
362
+ }, L = {
363
+ name: "pattern-recognition",
364
+ version: "1.0.0",
365
+ description: "Technical pattern recognition for financial and scientific data",
366
+ author: "Sci Plot Team",
367
+ provides: ["patterns", "technical-analysis", "chart-patterns"]
368
+ }, V = {
369
+ defaultParameters: {
370
+ minConfidence: 0.7,
371
+ maxPatterns: 10,
372
+ patternTypes: ["head-shoulders", "double-top", "double-bottom", "ascending-triangle", "descending-triangle"],
373
+ sensitivity: 0.5,
374
+ minPatternSize: 5,
375
+ maxPatternSize: 50,
376
+ overlapTolerance: 0.3,
377
+ enableVolumeConfirmation: !1,
378
+ enableTrendConfirmation: !0
379
+ },
380
+ customPatterns: [],
381
+ enableRealtime: !1,
382
+ debounceTime: 500,
383
+ maxStoredPatterns: 100,
384
+ visualization: {
385
+ showPatterns: !0,
386
+ showLabels: !0,
387
+ showTargets: !0,
388
+ colorScheme: {
389
+ "head-shoulders": "#ff6b6b",
390
+ "inverse-head-shoulders": "#4ecdc4",
391
+ "double-top": "#ff9f43",
392
+ "double-bottom": "#00d2d3",
393
+ "triple-top": "#ff6b6b",
394
+ "triple-bottom": "#4ecdc4",
395
+ "ascending-triangle": "#45b7d1",
396
+ "descending-triangle": "#f39c12",
397
+ "symmetrical-triangle": "#9b59b6",
398
+ "rising-wedge": "#e74c3c",
399
+ "falling-wedge": "#27ae60",
400
+ rectangle: "#34495e",
401
+ flag: "#f1c40f",
402
+ pennant: "#e67e22",
403
+ custom: "#95a5a6"
404
+ },
405
+ opacity: 0.7,
406
+ lineWidth: 2
407
+ },
408
+ notifications: {
409
+ enableAlerts: !1,
410
+ minAlertConfidence: 0.8,
411
+ alertTypes: ["head-shoulders", "double-top", "double-bottom"]
412
+ }
413
+ };
414
+ function F(s = {}) {
415
+ const e = { ...V, ...s };
416
+ let n = null;
417
+ const t = /* @__PURE__ */ new Map(), o = new Map(Object.entries(B)), i = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
418
+ async function u(a, l, d) {
419
+ const r = { ...e.defaultParameters, ...d }, f = performance.now(), c = [], m = {}, h = p(l, r.sensitivity);
420
+ for (const v of r.patternTypes) {
421
+ const w = o.get(v);
422
+ if (w) {
423
+ for (let z = r.minPatternSize; z <= Math.min(h.length, r.maxPatternSize); z++) {
424
+ const $ = h.slice(Math.max(0, z - r.maxPatternSize), z);
425
+ if ($.length < w.minPoints || w.maxPoints && $.length > w.maxPoints) continue;
426
+ const R = w.validator($);
427
+ if (R.valid && R.confidence >= r.minConfidence) {
428
+ const A = {
429
+ pattern: w,
430
+ confidence: R.confidence,
431
+ location: {
432
+ startIndex: Math.max(0, z - r.maxPatternSize),
433
+ endIndex: z,
434
+ startPoint: $[0],
435
+ endPoint: $[$.length - 1]
436
+ },
437
+ validation: R,
438
+ timestamp: Date.now(),
439
+ seriesId: a
440
+ };
441
+ if (!y(A, c, r.overlapTolerance) && (c.push(A), m[v] = (m[v] || 0) + 1, c.length >= r.maxPatterns))
442
+ break;
443
+ }
444
+ }
445
+ if (c.length >= r.maxPatterns)
446
+ break;
447
+ }
448
+ }
449
+ c.sort((v, w) => w.confidence - v.confidence), t.set(a, c);
450
+ const P = performance.now() - f;
451
+ for (const v of c)
452
+ v.confidence >= e.notifications.minAlertConfidence && e.notifications.alertTypes.includes(v.pattern.type) && (n == null || n.events.emit("pattern:detected", {
453
+ match: v,
454
+ seriesId: a,
455
+ timestamp: Date.now()
456
+ }));
457
+ const S = {
458
+ matches: c,
459
+ summary: {
460
+ totalPatterns: c.length,
461
+ patternsByType: m,
462
+ averageConfidence: c.length > 0 ? c.reduce((v, w) => v + w.confidence, 0) / c.length : 0,
463
+ detectionTime: P
464
+ },
465
+ processedPoints: h.length,
466
+ parameters: r
467
+ };
468
+ return n == null || n.log.info(`Pattern detection completed for ${a}: ${c.length} patterns found`), S;
469
+ }
470
+ function p(a, l) {
471
+ return a.filter((d, r) => {
472
+ if (r === 0 || r === a.length - 1) return !0;
473
+ const f = a[r - 1];
474
+ return Math.abs(d.y - f.y) / f.y >= l * 0.01;
475
+ });
476
+ }
477
+ function y(a, l, d) {
478
+ for (const r of l) {
479
+ const f = Math.max(a.location.startIndex, r.location.startIndex), m = Math.min(a.location.endIndex, r.location.endIndex) - f, h = a.location.endIndex - a.location.startIndex, P = r.location.endIndex - r.location.startIndex;
480
+ if (m / Math.min(h, P) > d)
481
+ return !0;
482
+ }
483
+ return !1;
484
+ }
485
+ function k(a) {
486
+ const l = {
487
+ id: a.id,
488
+ type: "custom",
489
+ name: a.name,
490
+ minPoints: a.pointSequence.length,
491
+ maxPoints: a.pointSequence.length,
492
+ validator: (d) => x(d, a)
493
+ };
494
+ o.set("custom", l), n == null || n.log.info(`Custom pattern registered: ${a.id}`);
495
+ }
496
+ function x(a, l) {
497
+ if (a.length < l.pointSequence.length)
498
+ return { valid: !1, confidence: 0, segments: [], keyPoints: [], errors: ["Insufficient points"] };
499
+ let d = 1;
500
+ const r = [];
501
+ for (let f = 0; f < l.pointSequence.length; f++) {
502
+ const c = l.pointSequence[f], m = a[f];
503
+ if (c.constraints) {
504
+ const h = c.constraints;
505
+ if (h.higherThanPrevious && f > 0 && m.y <= a[f - 1].y && (d *= 0.8, r.push(`Point ${f} not higher than previous`)), h.lowerThanPrevious && f > 0 && m.y >= a[f - 1].y && (d *= 0.8, r.push(`Point ${f} not lower than previous`)), h.withinRange) {
506
+ const [P, S] = h.withinRange;
507
+ (m.y < P || m.y > S) && (d *= 0.7, r.push(`Point ${f} not within range [${P}, ${S}]`));
508
+ }
509
+ }
510
+ }
511
+ return {
512
+ valid: d >= 0.5,
513
+ confidence: d,
514
+ segments: [],
515
+ keyPoints: a,
516
+ errors: r.length > 0 ? r : void 0
517
+ };
518
+ }
519
+ const b = {
520
+ detectPatterns: u,
521
+ registerCustomPattern: k,
522
+ getRegisteredPatterns() {
523
+ return Array.from(o.values());
524
+ },
525
+ getPatternMatches(a) {
526
+ return t.get(a) || [];
527
+ },
528
+ clearPatternMatches(a) {
529
+ t.delete(a), n == null || n.log.info(`Pattern matches cleared for series: ${a}`);
530
+ },
531
+ enableRealtimeDetection(a, l) {
532
+ i.add(a);
533
+ const d = n == null ? void 0 : n.chart;
534
+ if (d) {
535
+ const r = d.getSeries(a);
536
+ if (r) {
537
+ const f = r.getData();
538
+ if (f && f.x.length > 0) {
539
+ const c = Array.from(f.x).map((m, h) => ({
540
+ x: m,
541
+ y: f.y[h]
542
+ }));
543
+ u(a, c, l);
544
+ }
545
+ }
546
+ }
547
+ n == null || n.log.info(`Real-time pattern detection enabled for series: ${a}`);
548
+ },
549
+ disableRealtimeDetection(a) {
550
+ i.delete(a);
551
+ const l = g.get(a);
552
+ l && (clearTimeout(l), g.delete(a)), n == null || n.log.info(`Real-time pattern detection disabled for series: ${a}`);
553
+ },
554
+ getStatistics(a) {
555
+ if (a) {
556
+ const l = t.get(a) || [], d = {};
557
+ for (const r of l)
558
+ d[r.pattern.type] = (d[r.pattern.type] || 0) + 1;
559
+ return {
560
+ totalDetections: l.length,
561
+ patternsByType: d,
562
+ averageConfidence: l.length > 0 ? l.reduce((r, f) => r + f.confidence, 0) / l.length : 0,
563
+ detectionRate: l.length / 100
564
+ };
565
+ } else {
566
+ let l = 0;
567
+ const d = {}, r = [];
568
+ for (const f of t.values()) {
569
+ l += f.length, r.push(...f.map((c) => c.confidence));
570
+ for (const c of f)
571
+ d[c.pattern.type] = (d[c.pattern.type] || 0) + 1;
572
+ }
573
+ return {
574
+ totalDetections: l,
575
+ patternsByType: d,
576
+ averageConfidence: r.length > 0 ? r.reduce((f, c) => f + c, 0) / r.length : 0,
577
+ detectionRate: l / 100
578
+ };
579
+ }
580
+ },
581
+ updateConfig: (a) => {
582
+ Object.assign(e, a);
583
+ },
584
+ getConfig: () => ({ ...e }),
585
+ visualizePatterns(a, l) {
586
+ const d = n == null ? void 0 : n.chart;
587
+ if (!d) return;
588
+ const r = t.get(a) || [], f = l ? r.filter((c) => l.includes(c.pattern.type)) : r;
589
+ b.hidePatterns(a);
590
+ for (const c of f) {
591
+ const m = e.visualization.colorScheme[c.pattern.type] || "#666666";
592
+ for (const h of c.validation.segments) {
593
+ const P = `${a}_pattern_${c.pattern.id}_${c.location.startIndex}`;
594
+ d.addSeries({
595
+ id: P,
596
+ type: "line",
597
+ data: {
598
+ x: new Float32Array([h.start.x, h.end.x]),
599
+ y: new Float32Array([h.start.y, h.end.y])
600
+ },
601
+ style: {
602
+ color: m,
603
+ width: e.visualization.lineWidth,
604
+ opacity: e.visualization.opacity,
605
+ lineDash: [5, 5]
606
+ }
607
+ });
608
+ }
609
+ if (e.visualization.showLabels) {
610
+ const h = `${a}_label_${c.pattern.id}_${c.location.startIndex}`, P = (c.location.startPoint.x + c.location.endPoint.x) / 2, S = (c.location.startPoint.y + c.location.endPoint.y) / 2;
611
+ d.addAnnotation({
612
+ id: h,
613
+ type: "text",
614
+ text: c.pattern.name,
615
+ x: P,
616
+ y: S,
617
+ style: {
618
+ color: m,
619
+ fontSize: 12,
620
+ backgroundColor: "rgba(255, 255, 255, 0.8)"
621
+ }
622
+ });
623
+ }
624
+ }
625
+ },
626
+ hidePatterns(a) {
627
+ const l = n == null ? void 0 : n.chart;
628
+ if (!l) return;
629
+ const d = t.get(a) || [];
630
+ for (const r of d) {
631
+ for (let c = 0; c < r.validation.segments.length; c++) {
632
+ const m = `${a}_pattern_${r.pattern.id}_${r.location.startIndex}`;
633
+ l.getSeries(m) && l.removeSeries(m);
634
+ }
635
+ const f = `${a}_label_${r.pattern.id}_${r.location.startIndex}`;
636
+ l.getAnnotation(f) && l.removeAnnotation(f);
637
+ }
638
+ }
639
+ };
640
+ function M(a, l) {
641
+ if (!e.enableRealtime) return;
642
+ const { seriesId: d } = l;
643
+ if (i.has(d)) {
644
+ const r = g.get(d);
645
+ r && clearTimeout(r);
646
+ const f = setTimeout(() => {
647
+ const c = a.chart;
648
+ if (c) {
649
+ const m = c.getSeries(d);
650
+ if (m) {
651
+ const h = m.getData();
652
+ if (h && h.x.length > 0) {
653
+ const P = Array.from(h.x).map((S, v) => ({
654
+ x: S,
655
+ y: h.y[v]
656
+ }));
657
+ u(d, P), e.visualization.showPatterns && b.visualizePatterns(d);
658
+ }
659
+ }
660
+ }
661
+ }, e.debounceTime);
662
+ g.set(d, f);
663
+ }
664
+ }
665
+ return {
666
+ manifest: L,
667
+ onInit(a) {
668
+ if (n = a, e.customPatterns)
669
+ for (const l of e.customPatterns)
670
+ k(l);
671
+ n.log.info(`Pattern Recognition plugin initialized with ${o.size} patterns`);
672
+ },
673
+ onConfigChange(a, l) {
674
+ },
675
+ onBeforeRender(a, l) {
676
+ },
677
+ onDataUpdate: M,
678
+ onDestroy(a) {
679
+ for (const l of g.values())
680
+ clearTimeout(l);
681
+ g.clear(), t.clear(), i.clear(), o.clear();
682
+ },
683
+ api: b
684
+ };
685
+ }
686
+ export {
687
+ F as PluginPatternRecognition,
688
+ F as default
689
+ };
690
+ //# sourceMappingURL=pattern-recognition.js.map