@tradecanvas/vue 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +140 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TradeCanvas Contributors
|
|
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/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @tradecanvas/vue
|
|
2
|
+
|
|
3
|
+
Vue 3 component for [`@tradecanvas/chart`](https://www.npmjs.com/package/@tradecanvas/chart) — reactive props, template ref, zero boilerplate.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tradecanvas/vue @tradecanvas/chart
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`vue` (>= 3.3) is a peer dependency.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```vue
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import { TradeCanvas } from '@tradecanvas/vue'
|
|
18
|
+
import type { Chart } from '@tradecanvas/chart'
|
|
19
|
+
|
|
20
|
+
function onReady(chart: Chart) {
|
|
21
|
+
// full charting API
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div style="height: 500px">
|
|
27
|
+
<TradeCanvas
|
|
28
|
+
symbol="BTCUSDT"
|
|
29
|
+
timeframe="5m"
|
|
30
|
+
theme="dark"
|
|
31
|
+
:indicators="['rsi', 'macd']"
|
|
32
|
+
@ready="onReady"
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Streams live Binance data by default. Pass `:data="bars"` for static OHLC, or `:adapter="..."` for any feed.
|
|
39
|
+
|
|
40
|
+
## Props & events
|
|
41
|
+
|
|
42
|
+
Props: `symbol`, `timeframe`, `theme`, `chartType`, `indicators`, `data`, `adapter`, `historyLimit`, `features`, `autoScale`, `signalMarkers`, `signalMarkerStyle`, `tradeZones`, `tradeZoneStyle`, `watermarkText`.
|
|
43
|
+
|
|
44
|
+
Events: `@ready="(chart) => …"`, `@crosshairMove="(payload) => …"`.
|
|
45
|
+
|
|
46
|
+
## Imperative access
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { ref } from 'vue'
|
|
51
|
+
const el = ref()
|
|
52
|
+
// el.value.getChart() · el.value.screenshot('chart.png')
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<TradeCanvas ref="el" symbol="BTCUSDT" />
|
|
57
|
+
</template>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Reach the underlying `Chart` (drawings, trading, execution adapters, plugins, resizable panes) via `@ready` or the template ref's `getChart()`. See the [main docs](https://github.com/bonguynvan/tradecanvas).
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`),t=require(`@tradecanvas/chart`);var n=(0,e.defineComponent)({__name:`TradeCanvas`,props:{symbol:{default:`BTCUSDT`},timeframe:{default:`5m`},theme:{default:`dark`},chartType:{default:`candlestick`},indicators:{default:()=>[]},data:{},adapter:{},historyLimit:{default:500},features:{},autoScale:{type:Boolean,default:!0},signalMarkers:{},signalMarkerStyle:{},tradeZones:{},tradeZoneStyle:{},watermarkText:{}},emits:[`ready`,`crosshairMove`],setup(n,{expose:r,emit:i}){let a=n,o=i;function s(e){return e===`dark`?t.DARK_THEME:e===`light`?t.LIGHT_THEME:e}let c=(0,e.ref)(),l=null,u=new Map;function d(){return l}function f(e){l?.screenshot(e)}function p(){return l?.screenshotDataURL()??null}return r({getChart:d,screenshot:f,screenshotDataURL:p}),(0,e.onMounted)(()=>{if(c.value){if(l=new t.Chart(c.value,{chartType:a.chartType,theme:s(a.theme),autoScale:a.autoScale,rightMargin:5,crosshair:{mode:`magnet`},watermark:a.watermarkText?{text:a.watermarkText,fontSize:48,color:`rgba(255,255,255,0.03)`}:void 0,features:{drawings:!0,drawingMagnet:!0,drawingUndoRedo:!0,indicators:!0,trading:!0,volume:!0,legend:!0,crosshair:!0,keyboard:!0,screenshot:!0,alerts:!0,barCountdown:!0,logScale:!0,watermark:!0,...a.features}}),a.data)l.setData(a.data);else{let e=a.adapter??new t.BinanceAdapter;l.connect({adapter:e,symbol:a.symbol,timeframe:a.timeframe,historyLimit:a.historyLimit})}for(let e of a.indicators){let t=l.addIndicator(e);t&&u.set(e,t)}a.signalMarkers&&l.setSignalMarkers(a.signalMarkers),a.signalMarkerStyle&&l.setSignalMarkerStyle(a.signalMarkerStyle),a.tradeZones&&l.setTradeZones(a.tradeZones),a.tradeZoneStyle&&l.setTradeZoneStyle(a.tradeZoneStyle),o(`ready`,l)}}),(0,e.onUnmounted)(()=>{l&&=(l.disconnectStream(),l.destroy(),null)}),(0,e.watch)(()=>[a.symbol,a.timeframe],([e,n])=>{if(!l||a.data)return;l.disconnectStream();let r=a.adapter??new t.BinanceAdapter;l.connect({adapter:r,symbol:e,timeframe:n,historyLimit:a.historyLimit}),a.watermarkText&&l.setWatermark(a.watermarkText)}),(0,e.watch)(()=>a.theme,e=>{l?.setTheme(s(e))}),(0,e.watch)(()=>a.chartType,e=>{l?.setChartType(e)}),(0,e.watch)(()=>a.data,e=>{e&&l?.setData(e)},{deep:!0}),(0,e.watch)(()=>a.indicators,e=>{if(!l)return;let t=new Set(e);for(let[e,n]of u)t.has(e)||(l.removeIndicator(n),u.delete(e));for(let t of e)if(!u.has(t)){let e=l.addIndicator(t);e&&u.set(t,e)}},{deep:!0}),(0,e.watch)(()=>a.signalMarkers,e=>{e&&l?.setSignalMarkers(e)},{deep:!0}),(0,e.watch)(()=>a.signalMarkerStyle,e=>{e&&l?.setSignalMarkerStyle(e)},{deep:!0}),(0,e.watch)(()=>a.tradeZones,e=>{e&&l?.setTradeZones(e)},{deep:!0}),(0,e.watch)(()=>a.tradeZoneStyle,e=>{e&&l?.setTradeZoneStyle(e)},{deep:!0}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`containerEl`,ref:c,style:{width:`100%`,height:`100%`}},null,512))}});exports.TradeCanvas=n;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/TradeCanvas.vue","../src/TradeCanvas.vue"],"sourcesContent":["<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n","<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n"],"mappings":"2iBAyBA,IAAM,EAAQ,EA6BR,EAAO,EAKb,SAAS,EAAa,EAAwC,CAG5D,OAFI,IAAU,OAAe,EAAA,WACzB,IAAU,QAAgB,EAAA,YACvB,EAGT,IAAM,GAAA,EAAA,EAAA,MAAmC,CACrC,EAAsB,KACpB,EAAe,IAAI,IAEzB,SAAS,GAAyB,CAChC,OAAO,EAGT,SAAS,EAAW,EAAyB,CAC3C,GAAO,WAAW,EAAS,CAG7B,SAAS,GAAmC,CAC1C,OAAO,GAAO,mBAAmB,EAAI,YAGvC,EAAa,CAAE,WAAU,aAAY,oBAAmB,CAAC,EAEzD,EAAA,EAAA,eAAgB,CACT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AAJ,IAAI,EAAe,MAAO,CAAA,MAAA,OAAA,OAAA,OAAiC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Chart } from '@tradecanvas/chart';
|
|
2
|
+
import { ChartType } from '@tradecanvas/chart';
|
|
3
|
+
import { ComponentOptionsMixin } from 'vue';
|
|
4
|
+
import { ComponentProvideOptions } from 'vue';
|
|
5
|
+
import { DataAdapter } from '@tradecanvas/chart';
|
|
6
|
+
import { DefineComponent } from 'vue';
|
|
7
|
+
import { FeaturesConfig } from '@tradecanvas/chart';
|
|
8
|
+
import { OHLCBar } from '@tradecanvas/chart';
|
|
9
|
+
import { PublicProps } from 'vue';
|
|
10
|
+
import { SignalMarker } from '@tradecanvas/chart';
|
|
11
|
+
import { SignalMarkerStyle } from '@tradecanvas/chart';
|
|
12
|
+
import { Theme } from '@tradecanvas/chart';
|
|
13
|
+
import { TimeFrame } from '@tradecanvas/chart';
|
|
14
|
+
import { TradeZone } from '@tradecanvas/chart';
|
|
15
|
+
import { TradeZoneStyle } from '@tradecanvas/chart';
|
|
16
|
+
|
|
17
|
+
declare type __VLS_Props = {
|
|
18
|
+
symbol?: string;
|
|
19
|
+
timeframe?: TimeFrame;
|
|
20
|
+
theme?: 'dark' | 'light' | Theme;
|
|
21
|
+
chartType?: ChartType;
|
|
22
|
+
indicators?: string[];
|
|
23
|
+
data?: OHLCBar[];
|
|
24
|
+
adapter?: DataAdapter;
|
|
25
|
+
historyLimit?: number;
|
|
26
|
+
features?: FeaturesConfig;
|
|
27
|
+
autoScale?: boolean;
|
|
28
|
+
signalMarkers?: SignalMarker[];
|
|
29
|
+
signalMarkerStyle?: SignalMarkerStyle;
|
|
30
|
+
tradeZones?: TradeZone[];
|
|
31
|
+
tradeZoneStyle?: TradeZoneStyle;
|
|
32
|
+
watermarkText?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
declare function getChart(): Chart | null;
|
|
36
|
+
|
|
37
|
+
declare function screenshot(filename?: string): void;
|
|
38
|
+
|
|
39
|
+
declare function screenshotDataURL(): string | null;
|
|
40
|
+
|
|
41
|
+
export declare const TradeCanvas: DefineComponent<__VLS_Props, {
|
|
42
|
+
getChart: typeof getChart;
|
|
43
|
+
screenshot: typeof screenshot;
|
|
44
|
+
screenshotDataURL: typeof screenshotDataURL;
|
|
45
|
+
}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
46
|
+
ready: (chart: Chart) => any;
|
|
47
|
+
crosshairMove: (payload: unknown) => any;
|
|
48
|
+
}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
49
|
+
onReady?: ((chart: Chart) => any) | undefined;
|
|
50
|
+
onCrosshairMove?: ((payload: unknown) => any) | undefined;
|
|
51
|
+
}>, {
|
|
52
|
+
symbol: string;
|
|
53
|
+
timeframe: TimeFrame;
|
|
54
|
+
theme: "dark" | "light" | Theme;
|
|
55
|
+
chartType: ChartType;
|
|
56
|
+
indicators: string[];
|
|
57
|
+
historyLimit: number;
|
|
58
|
+
autoScale: boolean;
|
|
59
|
+
}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
60
|
+
containerEl: HTMLDivElement;
|
|
61
|
+
}, HTMLDivElement>;
|
|
62
|
+
|
|
63
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createElementBlock as e, defineComponent as t, onMounted as n, onUnmounted as r, openBlock as i, ref as a, watch as o } from "vue";
|
|
2
|
+
import { BinanceAdapter as s, Chart as c, DARK_THEME as l, LIGHT_THEME as u } from "@tradecanvas/chart";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/TradeCanvas.vue
|
|
5
|
+
var d = /* @__PURE__ */ t({
|
|
6
|
+
__name: "TradeCanvas",
|
|
7
|
+
props: {
|
|
8
|
+
symbol: { default: "BTCUSDT" },
|
|
9
|
+
timeframe: { default: "5m" },
|
|
10
|
+
theme: { default: "dark" },
|
|
11
|
+
chartType: { default: "candlestick" },
|
|
12
|
+
indicators: { default: () => [] },
|
|
13
|
+
data: {},
|
|
14
|
+
adapter: {},
|
|
15
|
+
historyLimit: { default: 500 },
|
|
16
|
+
features: {},
|
|
17
|
+
autoScale: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: !0
|
|
20
|
+
},
|
|
21
|
+
signalMarkers: {},
|
|
22
|
+
signalMarkerStyle: {},
|
|
23
|
+
tradeZones: {},
|
|
24
|
+
tradeZoneStyle: {},
|
|
25
|
+
watermarkText: {}
|
|
26
|
+
},
|
|
27
|
+
emits: ["ready", "crosshairMove"],
|
|
28
|
+
setup(t, { expose: d, emit: f }) {
|
|
29
|
+
let p = t, m = f;
|
|
30
|
+
function h(e) {
|
|
31
|
+
return e === "dark" ? l : e === "light" ? u : e;
|
|
32
|
+
}
|
|
33
|
+
let g = a(), _ = null, v = /* @__PURE__ */ new Map();
|
|
34
|
+
function y() {
|
|
35
|
+
return _;
|
|
36
|
+
}
|
|
37
|
+
function b(e) {
|
|
38
|
+
_?.screenshot(e);
|
|
39
|
+
}
|
|
40
|
+
function x() {
|
|
41
|
+
return _?.screenshotDataURL() ?? null;
|
|
42
|
+
}
|
|
43
|
+
return d({
|
|
44
|
+
getChart: y,
|
|
45
|
+
screenshot: b,
|
|
46
|
+
screenshotDataURL: x
|
|
47
|
+
}), n(() => {
|
|
48
|
+
if (g.value) {
|
|
49
|
+
if (_ = new c(g.value, {
|
|
50
|
+
chartType: p.chartType,
|
|
51
|
+
theme: h(p.theme),
|
|
52
|
+
autoScale: p.autoScale,
|
|
53
|
+
rightMargin: 5,
|
|
54
|
+
crosshair: { mode: "magnet" },
|
|
55
|
+
watermark: p.watermarkText ? {
|
|
56
|
+
text: p.watermarkText,
|
|
57
|
+
fontSize: 48,
|
|
58
|
+
color: "rgba(255,255,255,0.03)"
|
|
59
|
+
} : void 0,
|
|
60
|
+
features: {
|
|
61
|
+
drawings: !0,
|
|
62
|
+
drawingMagnet: !0,
|
|
63
|
+
drawingUndoRedo: !0,
|
|
64
|
+
indicators: !0,
|
|
65
|
+
trading: !0,
|
|
66
|
+
volume: !0,
|
|
67
|
+
legend: !0,
|
|
68
|
+
crosshair: !0,
|
|
69
|
+
keyboard: !0,
|
|
70
|
+
screenshot: !0,
|
|
71
|
+
alerts: !0,
|
|
72
|
+
barCountdown: !0,
|
|
73
|
+
logScale: !0,
|
|
74
|
+
watermark: !0,
|
|
75
|
+
...p.features
|
|
76
|
+
}
|
|
77
|
+
}), p.data) _.setData(p.data);
|
|
78
|
+
else {
|
|
79
|
+
let e = p.adapter ?? new s();
|
|
80
|
+
_.connect({
|
|
81
|
+
adapter: e,
|
|
82
|
+
symbol: p.symbol,
|
|
83
|
+
timeframe: p.timeframe,
|
|
84
|
+
historyLimit: p.historyLimit
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
for (let e of p.indicators) {
|
|
88
|
+
let t = _.addIndicator(e);
|
|
89
|
+
t && v.set(e, t);
|
|
90
|
+
}
|
|
91
|
+
p.signalMarkers && _.setSignalMarkers(p.signalMarkers), p.signalMarkerStyle && _.setSignalMarkerStyle(p.signalMarkerStyle), p.tradeZones && _.setTradeZones(p.tradeZones), p.tradeZoneStyle && _.setTradeZoneStyle(p.tradeZoneStyle), m("ready", _);
|
|
92
|
+
}
|
|
93
|
+
}), r(() => {
|
|
94
|
+
_ &&= (_.disconnectStream(), _.destroy(), null);
|
|
95
|
+
}), o(() => [p.symbol, p.timeframe], ([e, t]) => {
|
|
96
|
+
if (!_ || p.data) return;
|
|
97
|
+
_.disconnectStream();
|
|
98
|
+
let n = p.adapter ?? new s();
|
|
99
|
+
_.connect({
|
|
100
|
+
adapter: n,
|
|
101
|
+
symbol: e,
|
|
102
|
+
timeframe: t,
|
|
103
|
+
historyLimit: p.historyLimit
|
|
104
|
+
}), p.watermarkText && _.setWatermark(p.watermarkText);
|
|
105
|
+
}), o(() => p.theme, (e) => {
|
|
106
|
+
_?.setTheme(h(e));
|
|
107
|
+
}), o(() => p.chartType, (e) => {
|
|
108
|
+
_?.setChartType(e);
|
|
109
|
+
}), o(() => p.data, (e) => {
|
|
110
|
+
e && _?.setData(e);
|
|
111
|
+
}, { deep: !0 }), o(() => p.indicators, (e) => {
|
|
112
|
+
if (!_) return;
|
|
113
|
+
let t = new Set(e);
|
|
114
|
+
for (let [e, n] of v) t.has(e) || (_.removeIndicator(n), v.delete(e));
|
|
115
|
+
for (let t of e) if (!v.has(t)) {
|
|
116
|
+
let e = _.addIndicator(t);
|
|
117
|
+
e && v.set(t, e);
|
|
118
|
+
}
|
|
119
|
+
}, { deep: !0 }), o(() => p.signalMarkers, (e) => {
|
|
120
|
+
e && _?.setSignalMarkers(e);
|
|
121
|
+
}, { deep: !0 }), o(() => p.signalMarkerStyle, (e) => {
|
|
122
|
+
e && _?.setSignalMarkerStyle(e);
|
|
123
|
+
}, { deep: !0 }), o(() => p.tradeZones, (e) => {
|
|
124
|
+
e && _?.setTradeZones(e);
|
|
125
|
+
}, { deep: !0 }), o(() => p.tradeZoneStyle, (e) => {
|
|
126
|
+
e && _?.setTradeZoneStyle(e);
|
|
127
|
+
}, { deep: !0 }), (t, n) => (i(), e("div", {
|
|
128
|
+
ref_key: "containerEl",
|
|
129
|
+
ref: g,
|
|
130
|
+
style: {
|
|
131
|
+
width: "100%",
|
|
132
|
+
height: "100%"
|
|
133
|
+
}
|
|
134
|
+
}, null, 512));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
//#endregion
|
|
138
|
+
export { d as TradeCanvas };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/TradeCanvas.vue","../src/TradeCanvas.vue"],"sourcesContent":["<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n","<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,IAAM,IAAQ,GA6BR,IAAO;EAKb,SAAS,EAAa,GAAwC;AAG5D,UAFI,MAAU,SAAe,IACzB,MAAU,UAAgB,IACvB;;EAGT,IAAM,IAAc,GAAqB,EACrC,IAAsB,MACpB,oBAAe,IAAI,KAAqB;EAE9C,SAAS,IAAyB;AAChC,UAAO;;EAGT,SAAS,EAAW,GAAyB;AAC3C,MAAO,WAAW,EAAS;;EAG7B,SAAS,IAAmC;AAC1C,UAAO,GAAO,mBAAmB,IAAI;;SAGvC,EAAa;GAAE;GAAU;GAAY;GAAmB,CAAC,EAEzD,QAAgB;AACT,SAAY,OA8BjB;QA5BA,IAAQ,IAAI,EAAM,EAAY,OAAO;KACnC,WAAW,EAAM;KACjB,OAAO,EAAa,EAAM,MAAM;KAChC,WAAW,EAAM;KACjB,aAAa;KACb,WAAW,EAAE,MAAM,UAAU;KAC7B,WAAW,EAAM,gBACb;MAAE,MAAM,EAAM;MAAe,UAAU;MAAI,OAAO;MAA0B,GAC5E,KAAA;KACJ,UAAU;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AI,EAClE,QAAY,EAAM,OAAO,MAAM;AAAE,GAAI,KAAG,GAAO,QAAQ,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EAE7E,QACQ,EAAM,aACX,MAAkB;AACjB,OAAI,CAAC,EAAO;GACZ,IAAM,IAAU,IAAI,IAAI,EAAc;AACtC,QAAK,IAAM,CAAC,GAAM,MAAe,EAC/B,CAAK,EAAQ,IAAI,EAAK,KACpB,EAAM,gBAAgB,EAAW,EACjC,EAAa,OAAO,EAAK;AAG7B,QAAK,IAAM,KAAQ,EACjB,KAAI,CAAC,EAAa,IAAI,EAAK,EAAE;IAC3B,IAAM,IAAa,EAAM,aAAa,EAAK;AAC3C,IAAI,KAAY,EAAa,IAAI,GAAM,EAAW;;KAIxD,EAAE,MAAM,IAAM,CACf,EAED,QAAY,EAAM,gBAAgB,MAAM;AAAE,GAAI,KAAG,GAAO,iBAAiB,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EAC/F,QAAY,EAAM,oBAAoB,MAAM;AAAE,GAAI,KAAG,GAAO,qBAAqB,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EACvG,QAAY,EAAM,aAAa,MAAM;AAAE,GAAI,KAAG,GAAO,cAAc,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EACzF,QAAY,EAAM,iBAAiB,MAAM;AAAE,GAAI,KAAG,GAAO,kBAAkB,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,kBAtL/F,EAAoE,OAAA;YAA3D;GAAJ,KAAI;GAAe,OAAO;IAAA,OAAA;IAAA,QAAA;IAAiC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tradecanvas/vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vue 3 component for @tradecanvas/chart — reactive props, template ref, zero boilerplate.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/bonguynvan/tradecanvas.git",
|
|
10
|
+
"directory": "packages/vue"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"keywords": [
|
|
14
|
+
"trading",
|
|
15
|
+
"chart",
|
|
16
|
+
"vue",
|
|
17
|
+
"vue3",
|
|
18
|
+
"candlestick",
|
|
19
|
+
"canvas",
|
|
20
|
+
"technical-analysis"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@tradecanvas/chart": "1.0.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"vue": ">=3.3.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
|
44
|
+
"@vue/test-utils": "^2.4.6",
|
|
45
|
+
"jsdom": "^25.0.1",
|
|
46
|
+
"vitest": "^2.1.8",
|
|
47
|
+
"vue": "^3.5.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "vite build",
|
|
51
|
+
"dev": "vite build --watch",
|
|
52
|
+
"clean": "rm -rf dist",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|