@363045841yyt/klinechart 0.7.0 → 0.7.3-alpha.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 (233) hide show
  1. package/README.md +10 -6
  2. package/dist/components/DrawingStyleToolbar.vue.d.ts +28 -0
  3. package/dist/components/DrawingStyleToolbar.vue.d.ts.map +1 -0
  4. package/dist/{src/components → components}/IndicatorParams.vue.d.ts +3 -3
  5. package/dist/components/IndicatorParams.vue.d.ts.map +1 -0
  6. package/dist/{src/components → components}/IndicatorSelector.vue.d.ts +4 -4
  7. package/dist/components/IndicatorSelector.vue.d.ts.map +1 -0
  8. package/dist/components/KLineChart.vue.d.ts +63 -0
  9. package/dist/components/KLineChart.vue.d.ts.map +1 -0
  10. package/dist/components/KLineTooltip.vue.d.ts +30 -0
  11. package/dist/components/KLineTooltip.vue.d.ts.map +1 -0
  12. package/dist/{src/components → components}/LeftToolbar.vue.d.ts +3 -2
  13. package/dist/components/LeftToolbar.vue.d.ts.map +1 -0
  14. package/dist/components/MarkerTooltip.vue.d.ts +26 -0
  15. package/dist/components/MarkerTooltip.vue.d.ts.map +1 -0
  16. package/dist/components/index.d.ts +8 -0
  17. package/dist/components/index.d.ts.map +1 -0
  18. package/dist/{src/composables → composables}/useFullscreenTeleportTarget.d.ts +1 -0
  19. package/dist/composables/useFullscreenTeleportTarget.d.ts.map +1 -0
  20. package/dist/{src/debug → debug}/canvasProfiler.d.ts +1 -0
  21. package/dist/debug/canvasProfiler.d.ts.map +1 -0
  22. package/dist/index.cjs +2 -49
  23. package/dist/index.d.cts +124 -0
  24. package/dist/index.d.ts +124 -2
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +1470 -16916
  27. package/dist/klinechart.css +1 -1
  28. package/dist/version.d.ts +3 -0
  29. package/dist/version.d.ts.map +1 -0
  30. package/package.json +52 -81
  31. package/src/__tests__/_mockController.ts +192 -0
  32. package/src/__tests__/contract.test.ts +132 -0
  33. package/src/components/DrawingStyleToolbar.vue +199 -0
  34. package/src/components/IndicatorParams.vue +570 -0
  35. package/src/components/IndicatorSelector.vue +1042 -0
  36. package/src/components/KLineChart.vue +1570 -0
  37. package/src/components/KLineTooltip.vue +200 -0
  38. package/src/components/LeftToolbar.vue +844 -0
  39. package/src/components/MarkerTooltip.vue +155 -0
  40. package/src/components/index.ts +7 -0
  41. package/src/composables/useFullscreenTeleportTarget.ts +18 -0
  42. package/src/debug/canvasProfiler.ts +296 -0
  43. package/src/index.ts +402 -0
  44. package/src/version.ts +3 -0
  45. package/LICENSE +0 -21
  46. package/dist/favicon.ico +0 -0
  47. package/dist/mock-stock-data.json +0 -1
  48. package/dist/schema-CzmPW09E.cjs +0 -1
  49. package/dist/schema-DBMGp6Af.js +0 -437
  50. package/dist/src/App.vue.d.ts +0 -4
  51. package/dist/src/api/data/baostock.d.ts +0 -90
  52. package/dist/src/api/data/baostock.integration.test.d.ts +0 -1
  53. package/dist/src/api/data/index.d.ts +0 -26
  54. package/dist/src/api/data/kLine.d.ts +0 -11
  55. package/dist/src/api/data/types.d.ts +0 -33
  56. package/dist/src/api/data/unified.d.ts +0 -37
  57. package/dist/src/components/DrawingStyleToolbar.vue.d.ts +0 -12
  58. package/dist/src/components/KLineChart.vue.d.ts +0 -100
  59. package/dist/src/components/KLineTooltip.vue.d.ts +0 -17
  60. package/dist/src/components/MarkerTooltip.vue.d.ts +0 -13
  61. package/dist/src/components/index.d.ts +0 -2
  62. package/dist/src/config/chartSettings.d.ts +0 -69
  63. package/dist/src/core/chart-store.d.ts +0 -74
  64. package/dist/src/core/chart.d.ts +0 -420
  65. package/dist/src/core/controller/interaction.d.ts +0 -167
  66. package/dist/src/core/controller/markerInteraction.d.ts +0 -28
  67. package/dist/src/core/controller/pinchTracker.d.ts +0 -18
  68. package/dist/src/core/controller/tooltipPosition.d.ts +0 -21
  69. package/dist/src/core/draw/pixelAlign.d.ts +0 -114
  70. package/dist/src/core/drawing/index.d.ts +0 -47
  71. package/dist/src/core/drawing/interaction.d.ts +0 -75
  72. package/dist/src/core/drawing/plugin.d.ts +0 -27
  73. package/dist/src/core/indicators/atrState.d.ts +0 -16
  74. package/dist/src/core/indicators/bollState.d.ts +0 -34
  75. package/dist/src/core/indicators/calculators.d.ts +0 -465
  76. package/dist/src/core/indicators/cciState.d.ts +0 -15
  77. package/dist/src/core/indicators/chaikinVolState.d.ts +0 -18
  78. package/dist/src/core/indicators/cmfState.d.ts +0 -16
  79. package/dist/src/core/indicators/demaState.d.ts +0 -16
  80. package/dist/src/core/indicators/donchianState.d.ts +0 -23
  81. package/dist/src/core/indicators/eneState.d.ts +0 -30
  82. package/dist/src/core/indicators/expmaState.d.ts +0 -30
  83. package/dist/src/core/indicators/fastkState.d.ts +0 -15
  84. package/dist/src/core/indicators/fibState.d.ts +0 -26
  85. package/dist/src/core/indicators/hmaState.d.ts +0 -16
  86. package/dist/src/core/indicators/hvState.d.ts +0 -18
  87. package/dist/src/core/indicators/ichimokuState.d.ts +0 -44
  88. package/dist/src/core/indicators/indicator.worker.d.ts +0 -5
  89. package/dist/src/core/indicators/indicatorRuntime.d.ts +0 -126
  90. package/dist/src/core/indicators/kamaState.d.ts +0 -20
  91. package/dist/src/core/indicators/keltnerState.d.ts +0 -27
  92. package/dist/src/core/indicators/kstState.d.ts +0 -21
  93. package/dist/src/core/indicators/maState.d.ts +0 -26
  94. package/dist/src/core/indicators/macdState.d.ts +0 -58
  95. package/dist/src/core/indicators/mfiState.d.ts +0 -16
  96. package/dist/src/core/indicators/momState.d.ts +0 -15
  97. package/dist/src/core/indicators/obvState.d.ts +0 -14
  98. package/dist/src/core/indicators/parkinsonState.d.ts +0 -18
  99. package/dist/src/core/indicators/pivotState.d.ts +0 -29
  100. package/dist/src/core/indicators/pvtState.d.ts +0 -14
  101. package/dist/src/core/indicators/rocState.d.ts +0 -16
  102. package/dist/src/core/indicators/rsiState.d.ts +0 -39
  103. package/dist/src/core/indicators/sarState.d.ts +0 -26
  104. package/dist/src/core/indicators/scheduler.d.ts +0 -237
  105. package/dist/src/core/indicators/soa.d.ts +0 -115
  106. package/dist/src/core/indicators/stateComposer.d.ts +0 -146
  107. package/dist/src/core/indicators/stochState.d.ts +0 -18
  108. package/dist/src/core/indicators/structureState.d.ts +0 -43
  109. package/dist/src/core/indicators/supertrendState.d.ts +0 -22
  110. package/dist/src/core/indicators/temaState.d.ts +0 -16
  111. package/dist/src/core/indicators/trixState.d.ts +0 -20
  112. package/dist/src/core/indicators/vmaState.d.ts +0 -16
  113. package/dist/src/core/indicators/volumeProfileState.d.ts +0 -34
  114. package/dist/src/core/indicators/vwapState.d.ts +0 -16
  115. package/dist/src/core/indicators/wmaState.d.ts +0 -16
  116. package/dist/src/core/indicators/wmsrState.d.ts +0 -15
  117. package/dist/src/core/indicators/workerProtocol.d.ts +0 -496
  118. package/dist/src/core/indicators/zonesState.d.ts +0 -26
  119. package/dist/src/core/layout/pane.d.ts +0 -103
  120. package/dist/src/core/marker/registry.d.ts +0 -174
  121. package/dist/src/core/paneRenderer.d.ts +0 -45
  122. package/dist/src/core/renderers/Indicator/atr.d.ts +0 -17
  123. package/dist/src/core/renderers/Indicator/boll.d.ts +0 -2
  124. package/dist/src/core/renderers/Indicator/cci.d.ts +0 -21
  125. package/dist/src/core/renderers/Indicator/chaikinVol.d.ts +0 -4
  126. package/dist/src/core/renderers/Indicator/cmf.d.ts +0 -4
  127. package/dist/src/core/renderers/Indicator/dema.d.ts +0 -5
  128. package/dist/src/core/renderers/Indicator/donchian.d.ts +0 -5
  129. package/dist/src/core/renderers/Indicator/ene.d.ts +0 -10
  130. package/dist/src/core/renderers/Indicator/expma.d.ts +0 -2
  131. package/dist/src/core/renderers/Indicator/fastk.d.ts +0 -21
  132. package/dist/src/core/renderers/Indicator/fib.d.ts +0 -4
  133. package/dist/src/core/renderers/Indicator/hma.d.ts +0 -5
  134. package/dist/src/core/renderers/Indicator/hv.d.ts +0 -4
  135. package/dist/src/core/renderers/Indicator/ichimoku.d.ts +0 -5
  136. package/dist/src/core/renderers/Indicator/index.d.ts +0 -59
  137. package/dist/src/core/renderers/Indicator/indicatorData.d.ts +0 -13
  138. package/dist/src/core/renderers/Indicator/kama.d.ts +0 -5
  139. package/dist/src/core/renderers/Indicator/keltner.d.ts +0 -5
  140. package/dist/src/core/renderers/Indicator/kst.d.ts +0 -21
  141. package/dist/src/core/renderers/Indicator/ma.d.ts +0 -3
  142. package/dist/src/core/renderers/Indicator/macd.d.ts +0 -49
  143. package/dist/src/core/renderers/Indicator/macdLegend.d.ts +0 -12
  144. package/dist/src/core/renderers/Indicator/mainIndicatorLegend.d.ts +0 -10
  145. package/dist/src/core/renderers/Indicator/mfi.d.ts +0 -4
  146. package/dist/src/core/renderers/Indicator/mom.d.ts +0 -21
  147. package/dist/src/core/renderers/Indicator/obv.d.ts +0 -4
  148. package/dist/src/core/renderers/Indicator/parkinson.d.ts +0 -4
  149. package/dist/src/core/renderers/Indicator/pivot.d.ts +0 -4
  150. package/dist/src/core/renderers/Indicator/pvt.d.ts +0 -4
  151. package/dist/src/core/renderers/Indicator/roc.d.ts +0 -5
  152. package/dist/src/core/renderers/Indicator/rsi.d.ts +0 -32
  153. package/dist/src/core/renderers/Indicator/sar.d.ts +0 -5
  154. package/dist/src/core/renderers/Indicator/scale/atr_scale.d.ts +0 -11
  155. package/dist/src/core/renderers/Indicator/scale/cci_scale.d.ts +0 -11
  156. package/dist/src/core/renderers/Indicator/scale/fastk_scale.d.ts +0 -11
  157. package/dist/src/core/renderers/Indicator/scale/indicator_scale.d.ts +0 -35
  158. package/dist/src/core/renderers/Indicator/scale/kst_scale.d.ts +0 -11
  159. package/dist/src/core/renderers/Indicator/scale/macd_scale.d.ts +0 -14
  160. package/dist/src/core/renderers/Indicator/scale/mom_scale.d.ts +0 -11
  161. package/dist/src/core/renderers/Indicator/scale/rsi_scale.d.ts +0 -11
  162. package/dist/src/core/renderers/Indicator/scale/stoch_scale.d.ts +0 -11
  163. package/dist/src/core/renderers/Indicator/scale/volume_scale.d.ts +0 -14
  164. package/dist/src/core/renderers/Indicator/scale/wmsr_scale.d.ts +0 -11
  165. package/dist/src/core/renderers/Indicator/stoch.d.ts +0 -21
  166. package/dist/src/core/renderers/Indicator/structure.d.ts +0 -4
  167. package/dist/src/core/renderers/Indicator/subPaneConfig.d.ts +0 -9
  168. package/dist/src/core/renderers/Indicator/supertrend.d.ts +0 -5
  169. package/dist/src/core/renderers/Indicator/tema.d.ts +0 -5
  170. package/dist/src/core/renderers/Indicator/trix.d.ts +0 -5
  171. package/dist/src/core/renderers/Indicator/vma.d.ts +0 -4
  172. package/dist/src/core/renderers/Indicator/volumeProfile.d.ts +0 -4
  173. package/dist/src/core/renderers/Indicator/vwap.d.ts +0 -4
  174. package/dist/src/core/renderers/Indicator/wma.d.ts +0 -5
  175. package/dist/src/core/renderers/Indicator/wmsr.d.ts +0 -21
  176. package/dist/src/core/renderers/Indicator/zones.d.ts +0 -4
  177. package/dist/src/core/renderers/candle.d.ts +0 -20
  178. package/dist/src/core/renderers/crosshair.d.ts +0 -17
  179. package/dist/src/core/renderers/customMarkers.d.ts +0 -6
  180. package/dist/src/core/renderers/extremaMarkers.d.ts +0 -5
  181. package/dist/src/core/renderers/gridLines.d.ts +0 -7
  182. package/dist/src/core/renderers/lastPrice.d.ts +0 -9
  183. package/dist/src/core/renderers/paneTitle.d.ts +0 -40
  184. package/dist/src/core/renderers/subVolume.d.ts +0 -13
  185. package/dist/src/core/renderers/timeAxis.d.ts +0 -14
  186. package/dist/src/core/renderers/webgl/candleSurface.d.ts +0 -80
  187. package/dist/src/core/renderers/webgl/sharedWebGLSurface.d.ts +0 -33
  188. package/dist/src/core/renderers/yAxis.d.ts +0 -14
  189. package/dist/src/core/scale/logFormula.d.ts +0 -66
  190. package/dist/src/core/scale/price.d.ts +0 -11
  191. package/dist/src/core/scale/priceScale.d.ts +0 -87
  192. package/dist/src/core/subPaneManager.d.ts +0 -22
  193. package/dist/src/core/theme/colors.d.ts +0 -243
  194. package/dist/src/core/theme/fonts.d.ts +0 -12
  195. package/dist/src/core/utils/klineConfig.d.ts +0 -28
  196. package/dist/src/core/utils/tickCount.d.ts +0 -8
  197. package/dist/src/core/utils/tickPosition.d.ts +0 -24
  198. package/dist/src/core/utils/zoom.d.ts +0 -30
  199. package/dist/src/core/viewport/viewport.d.ts +0 -31
  200. package/dist/src/index.d.ts +0 -8
  201. package/dist/src/main.d.ts +0 -0
  202. package/dist/src/plugin/ConfigManager.d.ts +0 -31
  203. package/dist/src/plugin/EventBus.d.ts +0 -34
  204. package/dist/src/plugin/HookSystem.d.ts +0 -28
  205. package/dist/src/plugin/PluginHost.d.ts +0 -54
  206. package/dist/src/plugin/PluginRegistry.d.ts +0 -40
  207. package/dist/src/plugin/StateStore.d.ts +0 -37
  208. package/dist/src/plugin/index.d.ts +0 -11
  209. package/dist/src/plugin/rendererPluginManager.d.ts +0 -77
  210. package/dist/src/plugin/stateKeys.d.ts +0 -6
  211. package/dist/src/plugin/types.d.ts +0 -439
  212. package/dist/src/semantic/controller.d.ts +0 -35
  213. package/dist/src/semantic/drawShape.d.ts +0 -14
  214. package/dist/src/semantic/index.d.ts +0 -8
  215. package/dist/src/semantic/types.d.ts +0 -298
  216. package/dist/src/semantic/validator.d.ts +0 -43
  217. package/dist/src/test-setup.d.ts +0 -6
  218. package/dist/src/types/kLine.d.ts +0 -3
  219. package/dist/src/types/price.d.ts +0 -31
  220. package/dist/src/types/volumePrice.d.ts +0 -26
  221. package/dist/src/utils/cache.d.ts +0 -33
  222. package/dist/src/utils/dateFormat.d.ts +0 -83
  223. package/dist/src/utils/http.d.ts +0 -14
  224. package/dist/src/utils/kLineDraw/MA.d.ts +0 -12
  225. package/dist/src/utils/kLineDraw/axis.d.ts +0 -150
  226. package/dist/src/utils/kLineDraw/grid.d.ts +0 -30
  227. package/dist/src/utils/kLineDraw/kLine.d.ts +0 -15
  228. package/dist/src/utils/kline/format.d.ts +0 -14
  229. package/dist/src/utils/kline/viewport.d.ts +0 -10
  230. package/dist/src/utils/logger.d.ts +0 -5
  231. package/dist/src/utils/mock/genRandomPriceData.d.ts +0 -3
  232. package/dist/src/utils/priceToY.d.ts +0 -7
  233. package/dist/src/utils/volumePrice.d.ts +0 -54
package/src/index.ts ADDED
@@ -0,0 +1,402 @@
1
+ /**
2
+ * @363045841yyt/klinechart — public API surface.
3
+ *
4
+ * Vue 3 bindings for @363045841yyt/klinechart-core. Bridges core signals to Vue's
5
+ * reactivity via `shallowRef` + `effect` so each adapter owns its own
6
+ * reactivity boundary — no proxy wrapping of immutable signal values.
7
+ *
8
+ * Backward-compatibility contract: `KMapPlugin.install(app)` MUST exist
9
+ * because legacy users of `@363045841yyt/klinechart` consume it.
10
+ */
11
+
12
+ import {
13
+ defineComponent,
14
+ effectScope,
15
+ h,
16
+ onBeforeUnmount,
17
+ onMounted,
18
+ onScopeDispose,
19
+ onUnmounted,
20
+ shallowRef,
21
+ watch,
22
+ type App,
23
+ type PropType,
24
+ type Ref,
25
+ } from 'vue'
26
+ import type { Signal } from '@363045841yyt/klinechart-core/reactivity'
27
+ import type {
28
+ ChartController,
29
+ ChartControllerFactory,
30
+ ChartMountOptions,
31
+ ChartViewport,
32
+ IndicatorInstance,
33
+ InteractionSnapshot,
34
+ KLineData,
35
+ } from '@363045841yyt/klinechart-core'
36
+
37
+ export type {
38
+ ChartController,
39
+ ChartMountOptions,
40
+ ChartViewport,
41
+ } from '@363045841yyt/klinechart-core'
42
+
43
+ // ---------------------------------------------------------------------------
44
+ // SFC components (for consumers using Vite / SFC compiler)
45
+ // ---------------------------------------------------------------------------
46
+
47
+ export {
48
+ DrawingStyleToolbar,
49
+ IndicatorParams,
50
+ IndicatorSelector,
51
+ KLineChartVue,
52
+ KLineTooltip,
53
+ LeftToolbar,
54
+ MarkerTooltip,
55
+ } from './components/index'
56
+
57
+ // ---------------------------------------------------------------------------
58
+ // Controller factory injection
59
+ //
60
+ // The concrete `createChartController` from packages/core/src/controllers/
61
+ // (Phase 1A deliverable) is not yet wired. Adapters and tests inject a
62
+ // factory via `__setControllerFactory` so the public API surface stays stable.
63
+ // ---------------------------------------------------------------------------
64
+
65
+ let controllerFactory: ChartControllerFactory | null = null
66
+
67
+ /**
68
+ * Inject the ChartController factory. Called by:
69
+ * - the core package's bootstrap once `createChartController` is implemented
70
+ * - tests that need a mock controller
71
+ */
72
+ export function __setControllerFactory(
73
+ factory: ChartControllerFactory | null,
74
+ ): void {
75
+ controllerFactory = factory
76
+ }
77
+
78
+ // ---------------------------------------------------------------------------
79
+ // createChart �?imperative mount
80
+ // ---------------------------------------------------------------------------
81
+
82
+ /**
83
+ * Imperative mount API. Returns a controller; caller is responsible for `dispose`.
84
+ *
85
+ * Throws if container is null/undefined (SSR-safe guard).
86
+ */
87
+ export function createChart(opts: ChartMountOptions): ChartController {
88
+ if (opts.container == null) {
89
+ throw new Error(
90
+ '[@363045841yyt/klinechart] createChart: `container` is required and must be a non-null HTMLElement',
91
+ )
92
+ }
93
+ if (controllerFactory === null) {
94
+ throw new Error(
95
+ '[@363045841yyt/klinechart] createChart: no ChartController factory registered. ' +
96
+ 'Call __setControllerFactory(...) before mounting (the core package wires this in production).',
97
+ )
98
+ }
99
+ return controllerFactory(opts)
100
+ }
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // coreSignalToVueRef �?reactivity bridge
104
+ //
105
+ // Subscribe to a core Signal and mirror its value in a shallowRef. Auto-cleanup
106
+ // on component teardown via onScopeDispose (works inside effectScope or SFC).
107
+ // ---------------------------------------------------------------------------
108
+
109
+ /**
110
+ * Bridge a core Signal<T> into a Vue Ref<T> backed by `shallowRef`.
111
+ *
112
+ * We use `shallowRef` (not `ref`) because:
113
+ * - core signal values are treated as immutable; deep proxying is wasteful
114
+ * - `Object.is` short-circuits in the core depend on referential equality,
115
+ * which Vue's deep reactivity would silently break
116
+ *
117
+ * Subscription is torn down via `onScopeDispose`, so this is safe to call
118
+ * inside a Vue component setup, a composable, or a manually-created
119
+ * `effectScope`. Calling it outside any scope still returns a working ref �?
120
+ * the caller is then responsible for unsubscribing.
121
+ */
122
+ export function coreSignalToVueRef<T>(signal: Signal<T>): Ref<T> {
123
+ const ref = shallowRef(signal.peek()) as Ref<T>
124
+ const unsub = signal.subscribe(() => {
125
+ ref.value = signal.peek()
126
+ })
127
+ onScopeDispose(unsub)
128
+ return ref
129
+ }
130
+
131
+ // ---------------------------------------------------------------------------
132
+ // useChart �?composable
133
+ // ---------------------------------------------------------------------------
134
+
135
+ /**
136
+ * Composable. Pass a template ref to the container element.
137
+ *
138
+ * Watches `containerRef` to populate; once it does, calls `createChart`
139
+ * and exposes the controller via a `shallowRef`. Disposes on scope teardown.
140
+ */
141
+ export function useChart(
142
+ containerRef: Ref<HTMLElement | null>,
143
+ opts: Omit<ChartMountOptions, 'container'>,
144
+ ): { chart: Ref<ChartController | null> } {
145
+ const chart = shallowRef<ChartController | null>(null)
146
+
147
+ const mountIfReady = (el: HTMLElement | null): void => {
148
+ if (el == null || chart.value != null) return
149
+ chart.value = createChart({ ...opts, container: el })
150
+ }
151
+
152
+ // Mount synchronously if the ref is already populated (e.g. SFC where the
153
+ // template ref is set before this composable's effect runs).
154
+ mountIfReady(containerRef.value)
155
+
156
+ // Otherwise watch for the ref to populate.
157
+ const stopWatch = watch(
158
+ containerRef,
159
+ (el) => {
160
+ mountIfReady(el)
161
+ },
162
+ { immediate: true, flush: 'post' },
163
+ )
164
+
165
+ const dispose = (): void => {
166
+ stopWatch()
167
+ const ctrl = chart.value
168
+ if (ctrl != null) {
169
+ ctrl.dispose()
170
+ chart.value = null
171
+ }
172
+ }
173
+
174
+ onScopeDispose(dispose)
175
+ // Belt-and-braces: SFC components running outside a manual scope still get
176
+ // unmount cleanup via the component lifecycle hook.
177
+ onBeforeUnmount(dispose)
178
+
179
+ return { chart }
180
+ }
181
+
182
+ // ---------------------------------------------------------------------------
183
+ // useIndicators �?composable
184
+ // ---------------------------------------------------------------------------
185
+
186
+ /**
187
+ * Bridge the Chart's indicators signal into a Vue shallowRef.
188
+ */
189
+ export function useIndicators(controller: ChartController): {
190
+ indicators: Ref<ReadonlyArray<IndicatorInstance>>
191
+ add: ChartController['addIndicator']
192
+ remove: ChartController['removeIndicator']
193
+ updateParams: ChartController['updateIndicatorParams']
194
+ } {
195
+ const indicators = shallowRef(controller.indicators.peek()) as Ref<
196
+ ReadonlyArray<IndicatorInstance>
197
+ >
198
+ const unsub = controller.indicators.subscribe(() => {
199
+ indicators.value = controller.indicators.peek()
200
+ })
201
+ onScopeDispose(unsub)
202
+
203
+ return {
204
+ indicators,
205
+ add: controller.addIndicator.bind(controller),
206
+ remove: controller.removeIndicator.bind(controller),
207
+ updateParams: controller.updateIndicatorParams.bind(controller),
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Bridge the Chart's interactionState signal into a Vue shallowRef.
213
+ */
214
+ export function useInteractionState(
215
+ controller: ChartController,
216
+ ): Ref<InteractionSnapshot> {
217
+ const state = shallowRef(controller.interactionState.peek()) as Ref<InteractionSnapshot>
218
+ const unsub = controller.interactionState.subscribe(() => {
219
+ state.value = controller.interactionState.peek()
220
+ })
221
+ onScopeDispose(unsub)
222
+ return state
223
+ }
224
+
225
+ /**
226
+ * Bridge the Chart's paneRatios signal into a Vue shallowRef.
227
+ */
228
+ export function usePaneRatios(
229
+ controller: ChartController,
230
+ ): Ref<Readonly<Record<string, number>>> {
231
+ const ratios = shallowRef(controller.paneRatios.peek()) as Ref<
232
+ Readonly<Record<string, number>>
233
+ >
234
+ const unsub = controller.paneRatios.subscribe(() => {
235
+ ratios.value = controller.paneRatios.peek()
236
+ })
237
+ onScopeDispose(unsub)
238
+ return ratios
239
+ }
240
+
241
+ /**
242
+ * Bridge the Chart's viewport signal into a Vue shallowRef.
243
+ */
244
+ export function useViewport(
245
+ controller: ChartController,
246
+ ): Ref<ChartViewport> {
247
+ const vp = shallowRef(controller.viewport.peek()) as Ref<ChartViewport>
248
+ const unsub = controller.viewport.subscribe(() => {
249
+ vp.value = controller.viewport.peek()
250
+ })
251
+ onScopeDispose(unsub)
252
+ return vp
253
+ }
254
+
255
+ // ---------------------------------------------------------------------------
256
+ // <KLineChart /> SFC-equivalent component
257
+ //
258
+ // Implemented with defineComponent + render function rather than a `.vue`
259
+ // SFC to keep the package buildable with plain `tsc` (no SFC compiler in
260
+ // the publishable pipeline). Mirrors the legacy KLineChart.vue prop names
261
+ // that downstream consumers depend on.
262
+ // ---------------------------------------------------------------------------
263
+
264
+ export const KLineChart = defineComponent({
265
+ name: 'KLineChart',
266
+ props: {
267
+ data: {
268
+ type: Array as PropType<ReadonlyArray<KLineData>>,
269
+ required: true,
270
+ },
271
+ initialZoomLevel: { type: Number, default: 3 },
272
+ zoomLevels: { type: Number, default: 20 },
273
+ theme: {
274
+ type: String as PropType<'light' | 'dark'>,
275
+ default: 'light',
276
+ },
277
+ /** custom class for the chart container root */
278
+ containerClass: { type: String, default: '' },
279
+ },
280
+ emits: {
281
+ ready: (_controller: ChartController) => true,
282
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
283
+ zoomLevelChange: (_level: number, _kWidth: number) => true,
284
+ },
285
+ setup(props, { emit, expose }) {
286
+ const containerRef = shallowRef<HTMLElement | null>(null)
287
+ const scope = effectScope()
288
+
289
+ const chart = shallowRef<ChartController | null>(null)
290
+
291
+ onMounted(() => {
292
+ const el = containerRef.value
293
+ if (el == null) return
294
+ scope.run(() => {
295
+ chart.value = createChart({
296
+ container: el,
297
+ data: props.data,
298
+ initialZoomLevel: props.initialZoomLevel,
299
+ zoomLevels: props.zoomLevels,
300
+ theme: props.theme,
301
+ })
302
+ if (chart.value != null) {
303
+ emit('ready', chart.value)
304
+ // Bridge viewport changes back out as zoomLevelChange.
305
+ const ctrl = chart.value
306
+ const emitViewport = (): void => {
307
+ const vp = ctrl.viewport.peek()
308
+ emit('zoomLevelChange', vp.zoomLevel, vp.kWidth)
309
+ }
310
+ emitViewport()
311
+ const unsub = ctrl.viewport.subscribe(emitViewport)
312
+ onScopeDispose(unsub)
313
+ }
314
+ })
315
+
316
+ // React to prop changes: data + theme.
317
+ watch(
318
+ () => props.data,
319
+ (next) => {
320
+ chart.value?.setData(next)
321
+ },
322
+ )
323
+ watch(
324
+ () => props.theme,
325
+ (next) => {
326
+ chart.value?.setTheme(next)
327
+ },
328
+ )
329
+ })
330
+
331
+ onUnmounted(() => {
332
+ chart.value?.dispose()
333
+ chart.value = null
334
+ scope.stop()
335
+ })
336
+
337
+ expose({
338
+ getController: (): ChartController | null => chart.value,
339
+ handlePointerEvent: (
340
+ e: PointerEvent,
341
+ drawingController?: Parameters<ChartController['handlePointerEvent']>[1],
342
+ ): boolean => chart.value?.handlePointerEvent(e, drawingController) ?? false,
343
+ handleWheelEvent: (e: WheelEvent): void => chart.value?.handleWheelEvent(e),
344
+ handleScrollEvent: (): void => chart.value?.handleScrollEvent(),
345
+ zoomToLevel: (level: number, anchorX?: number): void =>
346
+ chart.value?.zoomToLevel(level, anchorX),
347
+ zoomIn: (anchorX?: number): void => chart.value?.zoomIn(anchorX),
348
+ zoomOut: (anchorX?: number): void => chart.value?.zoomOut(anchorX),
349
+ addIndicator: (
350
+ definitionId: string,
351
+ role: 'main' | 'sub',
352
+ params?: Record<string, unknown>,
353
+ ): string | null => chart.value?.addIndicator(definitionId, role, params) ?? null,
354
+ removeIndicator: (instanceId: string): boolean =>
355
+ chart.value?.removeIndicator(instanceId) ?? false,
356
+ setTheme: (theme: 'light' | 'dark'): void => chart.value?.setTheme(theme),
357
+ setData: (next: ReadonlyArray<KLineData>): void => chart.value?.setData(next),
358
+ })
359
+
360
+ const setContainerRef = (el: unknown): void => {
361
+ containerRef.value = (el as HTMLElement | null) ?? null
362
+ }
363
+
364
+ return () =>
365
+ h('div', {
366
+ ref: setContainerRef,
367
+ class: ['klinechart-quant-root', props.containerClass]
368
+ .filter(Boolean)
369
+ .join(' '),
370
+ style: { width: '100%', height: '100%' },
371
+ })
372
+ },
373
+ })
374
+
375
+ // ---------------------------------------------------------------------------
376
+ // KMapPlugin �?legacy Vue plugin
377
+ //
378
+ // PRESERVE THIS EXACT SHAPE �?legacy consumers do:
379
+ // import { KMapPlugin } from '@363045841yyt/klinechart'
380
+ // app.use(KMapPlugin)
381
+ // ---------------------------------------------------------------------------
382
+
383
+ export const KMapPlugin = {
384
+ install(app: App): void {
385
+ app.component('KLineChart', KLineChart)
386
+ },
387
+ }
388
+
389
+ // ---------------------------------------------------------------------------
390
+ // Auto-register the production ChartControllerFactory
391
+ //
392
+ // Consumers don't need to call __setControllerFactory manually unless they
393
+ // want to inject a custom backing (e.g. for testing). Contract tests
394
+ // override via __setControllerFactory in their setup and reset to null in
395
+ // afterEach, so this default registration is transparent to them.
396
+ //
397
+ // Importing the factory is side-effect-free at module load �?the engine's
398
+ // DOM access only happens when `createChart(opts)` is actually called.
399
+ // ---------------------------------------------------------------------------
400
+ import { createChartController } from '@363045841yyt/klinechart-core'
401
+ __setControllerFactory(createChartController)
402
+ export { VERSION, CORE_VERSION } from './version'
package/src/version.ts ADDED
@@ -0,0 +1,3 @@
1
+ import pkg from '../package.json'
2
+ export const VERSION = pkg.version
3
+ export { VERSION as CORE_VERSION } from '@363045841yyt/klinechart-core'
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 363045841
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/favicon.ico DELETED
Binary file