@tabler/charts-vue 0.0.0-stage → 0.0.1-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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 The Tabler Authors
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 CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="../../docs/images/logo-white.svg">
4
+ <img src="../../docs/images/logo.svg" alt="Tabler Charts" width="280">
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ # @tabler/charts-vue
9
+
10
+ Vue 3 components and a composable for [`@tabler/charts`](../core). Charts render to SVG on the server (Nuxt included), and the browser takes the markup over without re-creating it.
11
+
12
+ > 🚧 **Pre-release.** Not on npm yet; the API may still change.
13
+
14
+ ```bash
15
+ npm install @tabler/charts @tabler/charts-vue
16
+ ```
17
+
18
+ Requires Vue 3.5 or newer.
19
+
20
+ ## Usage
21
+
22
+ ```vue
23
+ <script setup>
24
+ import { LineChart } from '@tabler/charts-vue'
25
+ import '@tabler/charts/style.css'
26
+
27
+ const data = { labels: ['Mon', 'Tue', 'Wed'], series: [{ name: 'Visitors', values: [3, 5, 4] }] }
28
+ </script>
29
+
30
+ <template>
31
+ <LineChart :data="data" :aspect-ratio="3" locale="en-US" title="Visitors" />
32
+ </template>
33
+ ```
34
+
35
+ There is one component per chart type: `LineChart`, `AreaChart`, `BarChart`, `PieChart`, `DonutChart`, `GaugeChart`, `RadarChart`, `SankeyChart`, `ScatterChart`, `HeatmapChart`, `CandlestickChart` and `Sparkline`. `TablerChart` takes the type as a prop:
36
+
37
+ ```vue
38
+ <TablerChart :type="bar" :data="data" stacked />
39
+ ```
40
+
41
+ ## Props
42
+
43
+ Every chart option is an attribute, in kebab-case or camelCase: `:data`, `title`, `locale`, `:aspect-ratio`, `:legend`, and the type's own options (`stacked`, `curve` …).
44
+
45
+ - `class` and `style` go to the container `<div>`, as usual in Vue.
46
+ - `data` is watched deeply, so changing it in place (`data.series[0].values.push(…)`) updates the chart, and new data animates from the old.
47
+ - For SSR, pass `locale` so the server and browser format numbers the same. Ids come from `useId()`, so hydration lines up.
48
+ - The chart starts from server-rendered markup, also in the browser. Under a strict CSP (`style-src` without `'unsafe-inline'`) its style attributes are reported, then set again on mount; allow `style-src-attr 'unsafe-inline'` to keep the reports out (see the core README).
49
+
50
+ ## Events
51
+
52
+ ```vue
53
+ <BarChart
54
+ :data="data"
55
+ @hover="({ hit }) => (active = hit?.label)"
56
+ @click="({ hit }) => select(hit)"
57
+ @legend-toggle="({ name, hidden }) => {}"
58
+ @render="({ size }) => {}"
59
+ />
60
+ ```
61
+
62
+ ## The `Chart` instance
63
+
64
+ A template ref exposes `chart`, the [`Chart`](../core#the-chart-instance):
65
+
66
+ ```vue
67
+ <script setup>
68
+ import { ref } from 'vue'
69
+ const revenue = ref()
70
+ // revenue.value.chart.toggleSeries('Costs')
71
+ </script>
72
+
73
+ <template>
74
+ <LineChart ref="revenue" :data="data" />
75
+ </template>
76
+ ```
77
+
78
+ ## `useChart()`
79
+
80
+ To render into an element of your own:
81
+
82
+ ```js
83
+ import { ref } from 'vue'
84
+ import { line } from '@tabler/charts'
85
+ import { useChart } from '@tabler/charts-vue'
86
+
87
+ const el = ref(null)
88
+ const chart = useChart(el, () => ({ type: line, data: data.value }))
89
+ ```
90
+
91
+ `useChart()` returns a shallow ref to the chart. It creates the chart once the element is there, follows the config deeply and destroys it with the component. It does not render on the server; use the components for SSR.
92
+
93
+ ## License
94
+
95
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,159 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _tabler_charts = require("@tabler/charts");
3
+ let vue = require("vue");
4
+ //#region src/chart.ts
5
+ const camelize = (key) => key.replace(/-(\w)/g, (_, c) => c.toUpperCase());
6
+ /** Whether two configs have the same values, key by key (not deep). */
7
+ function shallowEqual(a, b) {
8
+ const ka = Object.keys(a);
9
+ if (ka.length !== Object.keys(b).length) return false;
10
+ return ka.every((key) => Object.is(a[key], b[key]));
11
+ }
12
+ /** A Vue `useId()` as a valid SVG id prefix. */
13
+ const idFrom = (vueId) => `tc-${vueId.replace(/[^a-zA-Z0-9]/g, "")}`;
14
+ function setup(fixedType) {
15
+ return (props, { attrs, emit, expose }) => {
16
+ const id = idFrom((0, vue.useId)() ?? "");
17
+ const config = () => {
18
+ const out = {};
19
+ for (const [key, value] of Object.entries(attrs)) {
20
+ if (key === "class" || key === "style" || /^on[A-Z]/.test(key)) continue;
21
+ out[camelize(key)] = (0, vue.toRaw)(value);
22
+ }
23
+ out.data = (0, vue.toRaw)(props.data);
24
+ out.type = fixedType ?? (0, vue.toRaw)(props.type);
25
+ out.id ??= id;
26
+ return out;
27
+ };
28
+ const initial = config();
29
+ const html = (0, vue.inject)(vue.ssrContextKey, null) !== null || (0, vue.getCurrentInstance)()?.vnode.el != null ? (0, _tabler_charts.chartToString)(initial, (0, _tabler_charts.resolveSize)(initial)) : "";
30
+ const element = (0, vue.shallowRef)(null);
31
+ const chart = (0, vue.shallowRef)(null);
32
+ let applied = initial;
33
+ const push = (force) => {
34
+ const next = config();
35
+ if (!chart.value || !force && shallowEqual(applied, next)) return;
36
+ applied = next;
37
+ chart.value.setConfig(next);
38
+ };
39
+ (0, vue.onMounted)(() => {
40
+ const created = new _tabler_charts.Chart(element.value, config());
41
+ applied = created.config;
42
+ for (const name of _tabler_charts.chartEvents) created.on(name, (event) => emit(name, event));
43
+ chart.value = created;
44
+ });
45
+ (0, vue.onUpdated)(() => push(false));
46
+ (0, vue.watch)(() => props.data, () => push(true), { deep: true });
47
+ (0, vue.onActivated)(() => chart.value?.resize());
48
+ (0, vue.onBeforeUnmount)(() => {
49
+ chart.value?.destroy();
50
+ chart.value = null;
51
+ });
52
+ expose({ chart });
53
+ return () => (0, vue.h)("div", {
54
+ ref: element,
55
+ class: ["tc-container", attrs.class],
56
+ ...attrs.style ? { style: attrs.style } : {},
57
+ innerHTML: html
58
+ });
59
+ };
60
+ }
61
+ /**
62
+ * Any chart, with the type as a prop. Renders the SVG on the server and
63
+ * takes it over in the browser. The template ref exposes `chart`.
64
+ *
65
+ * ```vue
66
+ * <TablerChart :type="line" :data="data" :aspect-ratio="3" locale="en-US" @hover="onHover" />
67
+ * ```
68
+ */
69
+ const TablerChart = /* @__PURE__ */ (0, vue.defineComponent)(setup(void 0), {
70
+ name: "TablerChart",
71
+ inheritAttrs: false,
72
+ props: ["type", "data"],
73
+ emits: [..._tabler_charts.chartEvents]
74
+ });
75
+ /** A component for one chart type, e.g. `chartComponent(line, 'LineChart')`. */
76
+ function chartComponent(type, name) {
77
+ return (0, vue.defineComponent)(setup(type), {
78
+ name,
79
+ inheritAttrs: false,
80
+ props: ["data"],
81
+ emits: [..._tabler_charts.chartEvents]
82
+ });
83
+ }
84
+ /**
85
+ * Bind a chart to an element of your own: created when the element is
86
+ * there, updated when the config changes (deeply), destroyed with the
87
+ * component.
88
+ *
89
+ * ```ts
90
+ * const el = ref<HTMLElement | null>(null)
91
+ * const chart = useChart(el, () => ({ type: line, data: data.value }))
92
+ * ```
93
+ */
94
+ function useChart(target, config) {
95
+ const chart = (0, vue.shallowRef)(null);
96
+ const read = () => (0, vue.toRaw)((0, vue.toValue)(config));
97
+ (0, vue.watch)(target, (element) => {
98
+ chart.value?.destroy();
99
+ chart.value = element ? new _tabler_charts.Chart(element, read()) : null;
100
+ }, { flush: "post" });
101
+ (0, vue.onMounted)(() => {
102
+ if (!chart.value && target.value) chart.value = new _tabler_charts.Chart(target.value, read());
103
+ });
104
+ (0, vue.watch)(() => (0, vue.toValue)(config), () => chart.value?.setConfig(read()), { deep: true });
105
+ (0, vue.onActivated)(() => chart.value?.resize());
106
+ (0, vue.onBeforeUnmount)(() => {
107
+ chart.value?.destroy();
108
+ chart.value = null;
109
+ });
110
+ return chart;
111
+ }
112
+ //#endregion
113
+ //#region src/index.ts
114
+ /**
115
+ * `@tabler/charts-vue`: Vue 3 components and a composable for `@tabler/charts`.
116
+ * Charts render on the server (Nuxt included) and the browser takes the SVG
117
+ * over. Import `@tabler/charts/style.css` once in your app.
118
+ *
119
+ * ```vue
120
+ * <script setup>
121
+ * import { LineChart } from '@tabler/charts-vue'
122
+ * import '@tabler/charts/style.css'
123
+ * <\/script>
124
+ *
125
+ * <template>
126
+ * <LineChart :data="data" :aspect-ratio="3" locale="en-US" @hover="onHover" />
127
+ * </template>
128
+ * ```
129
+ */
130
+ const LineChart = /* @__PURE__ */ chartComponent(_tabler_charts.line, "LineChart");
131
+ const AreaChart = /* @__PURE__ */ chartComponent(_tabler_charts.area, "AreaChart");
132
+ const BarChart = /* @__PURE__ */ chartComponent(_tabler_charts.bar, "BarChart");
133
+ const PieChart = /* @__PURE__ */ chartComponent(_tabler_charts.pie, "PieChart");
134
+ const DonutChart = /* @__PURE__ */ chartComponent(_tabler_charts.donut, "DonutChart");
135
+ const ScatterChart = /* @__PURE__ */ chartComponent(_tabler_charts.scatter, "ScatterChart");
136
+ const Sparkline = /* @__PURE__ */ chartComponent(_tabler_charts.sparkline, "Sparkline");
137
+ const GaugeChart = /* @__PURE__ */ chartComponent(_tabler_charts.gauge, "GaugeChart");
138
+ const HeatmapChart = /* @__PURE__ */ chartComponent(_tabler_charts.heatmap, "HeatmapChart");
139
+ const CandlestickChart = /* @__PURE__ */ chartComponent(_tabler_charts.candlestick, "CandlestickChart");
140
+ const RadarChart = /* @__PURE__ */ chartComponent(_tabler_charts.radar, "RadarChart");
141
+ const SankeyChart = /* @__PURE__ */ chartComponent(_tabler_charts.sankey, "SankeyChart");
142
+ //#endregion
143
+ exports.AreaChart = AreaChart;
144
+ exports.BarChart = BarChart;
145
+ exports.CandlestickChart = CandlestickChart;
146
+ exports.DonutChart = DonutChart;
147
+ exports.GaugeChart = GaugeChart;
148
+ exports.HeatmapChart = HeatmapChart;
149
+ exports.LineChart = LineChart;
150
+ exports.PieChart = PieChart;
151
+ exports.RadarChart = RadarChart;
152
+ exports.SankeyChart = SankeyChart;
153
+ exports.ScatterChart = ScatterChart;
154
+ exports.Sparkline = Sparkline;
155
+ exports.TablerChart = TablerChart;
156
+ exports.chartComponent = chartComponent;
157
+ exports.useChart = useChart;
158
+
159
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["useId","toRaw","inject","ssrContextKey","getCurrentInstance","chartToString","resolveSize","shallowRef","Chart","chartEvents","h","defineComponent","toValue","line","area","bar","pie","donut","scatter","sparkline","gauge","heatmap","candlestick","radar","sankey"],"sources":["../src/chart.ts","../src/index.ts"],"sourcesContent":["import {\n Chart,\n type ChartConfig,\n type ChartEvents,\n type ChartType,\n chartEvents,\n chartToString,\n resolveSize,\n} from '@tabler/charts'\nimport {\n type DefineSetupFnComponent,\n defineComponent,\n getCurrentInstance,\n h,\n inject,\n type MaybeRefOrGetter,\n onActivated,\n onBeforeUnmount,\n onMounted,\n onUpdated,\n type Ref,\n type SetupContext,\n type ShallowRef,\n shallowRef,\n ssrContextKey,\n toRaw,\n toValue,\n useId,\n watch,\n} from 'vue'\n\n/** Chart events, emitted as `hover`, `click`, `legend-toggle` and `render`. */\nexport type ChartEmits = {\n hover: (event: ChartEvents['hover']) => void\n click: (event: ChartEvents['click']) => void\n 'legend-toggle': (event: ChartEvents['legend-toggle']) => void\n render: (event: ChartEvents['render']) => void\n}\n\n/**\n * Props of a chart component: the chart config. `class` and `style` go to\n * the container `<div>` as usual in Vue.\n */\nexport type ChartProps<O extends object> = Omit<ChartConfig<O>, 'class'>\n\n/** A chart component with its type fixed, such as `<LineChart>`. */\nexport type ChartComponent<O extends object> = DefineSetupFnComponent<\n Omit<ChartProps<O>, 'type'>,\n ChartEmits\n>\n\nconst camelize = (key: string): string => key.replace(/-(\\w)/g, (_, c: string) => c.toUpperCase())\n\n/** Whether two configs have the same values, key by key (not deep). */\nfunction shallowEqual(a: object, b: object): boolean {\n const ka = Object.keys(a)\n if (ka.length !== Object.keys(b).length) return false\n return ka.every((key) =>\n Object.is((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),\n )\n}\n\n/** A Vue `useId()` as a valid SVG id prefix. */\nconst idFrom = (vueId: string): string => `tc-${vueId.replace(/[^a-zA-Z0-9]/g, '')}`\n\nfunction setup<O extends object>(fixedType: ChartType<O> | undefined) {\n return (props: Record<string, unknown>, { attrs, emit, expose }: SetupContext<ChartEmits>) => {\n // Ids from useId() match between the server and the client, so hydration lines up.\n const id = idFrom(useId() ?? '')\n const config = (): ChartConfig<O> => {\n const out: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(attrs)) {\n // class and style belong to the container; listeners are Vue's.\n if (key === 'class' || key === 'style' || /^on[A-Z]/.test(key)) continue\n out[camelize(key)] = toRaw(value)\n }\n out.data = toRaw(props.data)\n out.type = fixedType ?? toRaw(props.type)\n out.id ??= id\n return out as ChartConfig<O>\n }\n\n // The server-rendered chart; the same string on every render, so Vue never\n // rewrites the container while the chart owns it. Only on the server and when\n // hydrating its markup (the component then already has its element): mounted\n // in the browser alone, the chart is built once, by the Chart.\n const initial = config()\n const server = inject(ssrContextKey, null) !== null || getCurrentInstance()?.vnode.el != null\n const html = server ? chartToString(initial, resolveSize(initial)) : ''\n\n const element = shallowRef<HTMLElement | null>(null)\n const chart = shallowRef<Chart<O> | null>(null)\n let applied = initial\n\n const push = (force: boolean) => {\n const next = config()\n if (!chart.value || (!force && shallowEqual(applied, next))) return\n applied = next\n chart.value.setConfig(next)\n }\n\n onMounted(() => {\n // The chart takes the server-rendered svg over in place.\n const created = new Chart(element.value as HTMLElement, config())\n applied = created.config\n for (const name of chartEvents) {\n created.on(name, (event) => (emit as (name: string, event: unknown) => void)(name, event))\n }\n chart.value = created\n })\n // Other options arrive as attributes: compare them after every update.\n onUpdated(() => push(false))\n // Data is watched deeply, so reactive arrays can be changed in place.\n watch(\n () => props.data,\n () => push(true),\n { deep: true },\n )\n // Back from <KeepAlive>, which kept the container out of the page: observe it again.\n onActivated(() => chart.value?.resize())\n onBeforeUnmount(() => {\n chart.value?.destroy()\n chart.value = null\n })\n\n expose({ chart })\n return () =>\n h('div', {\n ref: element,\n class: ['tc-container', attrs.class],\n ...(attrs.style ? { style: attrs.style } : {}),\n innerHTML: html,\n })\n }\n}\n\n/**\n * Any chart, with the type as a prop. Renders the SVG on the server and\n * takes it over in the browser. The template ref exposes `chart`.\n *\n * ```vue\n * <TablerChart :type=\"line\" :data=\"data\" :aspect-ratio=\"3\" locale=\"en-US\" @hover=\"onHover\" />\n * ```\n */\nexport const TablerChart: DefineSetupFnComponent<\n ChartProps<object>,\n ChartEmits\n> = /* @__PURE__ */ defineComponent(setup(undefined) as never, {\n name: 'TablerChart',\n inheritAttrs: false,\n props: ['type', 'data'],\n emits: [...chartEvents],\n}) as never\n\n/** A component for one chart type, e.g. `chartComponent(line, 'LineChart')`. */\nexport function chartComponent<O extends object>(\n type: ChartType<O>,\n name: string,\n): ChartComponent<O> {\n return defineComponent(setup(type) as never, {\n name,\n inheritAttrs: false,\n props: ['data'],\n emits: [...chartEvents],\n }) as never\n}\n\n/**\n * Bind a chart to an element of your own: created when the element is\n * there, updated when the config changes (deeply), destroyed with the\n * component.\n *\n * ```ts\n * const el = ref<HTMLElement | null>(null)\n * const chart = useChart(el, () => ({ type: line, data: data.value }))\n * ```\n */\nexport function useChart<O extends object>(\n target: Ref<Element | null | undefined>,\n config: MaybeRefOrGetter<ChartConfig<O>>,\n): ShallowRef<Chart<O> | null> {\n const chart = shallowRef<Chart<O> | null>(null)\n const read = () => toRaw(toValue(config))\n watch(\n target,\n (element) => {\n chart.value?.destroy()\n chart.value = element ? new Chart(element, read()) : null\n },\n { flush: 'post' },\n )\n onMounted(() => {\n if (!chart.value && target.value) chart.value = new Chart(target.value, read())\n })\n watch(\n () => toValue(config),\n () => chart.value?.setConfig(read()),\n { deep: true },\n )\n onActivated(() => chart.value?.resize())\n onBeforeUnmount(() => {\n chart.value?.destroy()\n chart.value = null\n })\n return chart\n}\n","/**\n * `@tabler/charts-vue`: Vue 3 components and a composable for `@tabler/charts`.\n * Charts render on the server (Nuxt included) and the browser takes the SVG\n * over. Import `@tabler/charts/style.css` once in your app.\n *\n * ```vue\n * <script setup>\n * import { LineChart } from '@tabler/charts-vue'\n * import '@tabler/charts/style.css'\n * </script>\n *\n * <template>\n * <LineChart :data=\"data\" :aspect-ratio=\"3\" locale=\"en-US\" @hover=\"onHover\" />\n * </template>\n * ```\n */\nimport {\n type AreaOptions,\n area,\n type BarOptions,\n bar,\n type CandlestickOptions,\n candlestick,\n donut,\n type GaugeOptions,\n gauge,\n type HeatmapOptions,\n heatmap,\n type LineOptions,\n line,\n type PieOptions,\n pie,\n type RadarOptions,\n radar,\n type SankeyOptions,\n type ScatterOptions,\n type SparklineOptions,\n sankey,\n scatter,\n sparkline,\n} from '@tabler/charts'\nimport { type ChartComponent, chartComponent } from './chart.ts'\n\nexport type { ChartComponent, ChartEmits, ChartProps } from './chart.ts'\nexport { chartComponent, TablerChart, useChart } from './chart.ts'\n\n// Each component is created by a pure call, so unused ones (and their chart types) tree-shake.\nexport const LineChart: ChartComponent<LineOptions> = /* @__PURE__ */ chartComponent(\n line,\n 'LineChart',\n)\nexport const AreaChart: ChartComponent<AreaOptions> = /* @__PURE__ */ chartComponent(\n area,\n 'AreaChart',\n)\nexport const BarChart: ChartComponent<BarOptions> = /* @__PURE__ */ chartComponent(bar, 'BarChart')\nexport const PieChart: ChartComponent<PieOptions> = /* @__PURE__ */ chartComponent(pie, 'PieChart')\nexport const DonutChart: ChartComponent<PieOptions> = /* @__PURE__ */ chartComponent(\n donut,\n 'DonutChart',\n)\nexport const ScatterChart: ChartComponent<ScatterOptions> = /* @__PURE__ */ chartComponent(\n scatter,\n 'ScatterChart',\n)\nexport const Sparkline: ChartComponent<SparklineOptions> = /* @__PURE__ */ chartComponent(\n sparkline,\n 'Sparkline',\n)\nexport const GaugeChart: ChartComponent<GaugeOptions> = /* @__PURE__ */ chartComponent(\n gauge,\n 'GaugeChart',\n)\nexport const HeatmapChart: ChartComponent<HeatmapOptions> = /* @__PURE__ */ chartComponent(\n heatmap,\n 'HeatmapChart',\n)\nexport const CandlestickChart: ChartComponent<CandlestickOptions> = /* @__PURE__ */ chartComponent(\n candlestick,\n 'CandlestickChart',\n)\nexport const RadarChart: ChartComponent<RadarOptions> = /* @__PURE__ */ chartComponent(\n radar,\n 'RadarChart',\n)\nexport const SankeyChart: ChartComponent<SankeyOptions> = /* @__PURE__ */ chartComponent(\n sankey,\n 'SankeyChart',\n)\n"],"mappings":";;;;AAmDA,MAAM,YAAY,QAAwB,IAAI,QAAQ,WAAW,GAAG,MAAc,EAAE,YAAY,CAAC;;AAGjG,SAAS,aAAa,GAAW,GAAoB;CACnD,MAAM,KAAK,OAA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BACF;AACA,MAAa,aAA2D,+BACtEC,eAAAA,OACA,YACF;AACA,MAAa,cAA6D,+BACxEC,eAAAA,QACA,aACF"}
@@ -0,0 +1,56 @@
1
+ import { AreaOptions, BarOptions, CandlestickOptions, Chart, ChartConfig, ChartEvents, ChartType, GaugeOptions, HeatmapOptions, LineOptions, PieOptions, RadarOptions, SankeyOptions, ScatterOptions, SparklineOptions } from "@tabler/charts";
2
+ import { DefineSetupFnComponent, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
3
+ //#region src/chart.d.ts
4
+ /** Chart events, emitted as `hover`, `click`, `legend-toggle` and `render`. */
5
+ type ChartEmits = {
6
+ hover: (event: ChartEvents["hover"]) => void;
7
+ click: (event: ChartEvents["click"]) => void;
8
+ "legend-toggle": (event: ChartEvents["legend-toggle"]) => void;
9
+ render: (event: ChartEvents["render"]) => void;
10
+ };
11
+ /**
12
+ * Props of a chart component: the chart config. `class` and `style` go to
13
+ * the container `<div>` as usual in Vue.
14
+ */
15
+ type ChartProps<O extends object> = Omit<ChartConfig<O>, "class">;
16
+ /** A chart component with its type fixed, such as `<LineChart>`. */
17
+ type ChartComponent<O extends object> = DefineSetupFnComponent<Omit<ChartProps<O>, "type">, ChartEmits>;
18
+ /**
19
+ * Any chart, with the type as a prop. Renders the SVG on the server and
20
+ * takes it over in the browser. The template ref exposes `chart`.
21
+ *
22
+ * ```vue
23
+ * <TablerChart :type="line" :data="data" :aspect-ratio="3" locale="en-US" @hover="onHover" />
24
+ * ```
25
+ */
26
+ export declare const TablerChart: DefineSetupFnComponent<ChartProps<object>, ChartEmits>;
27
+ /** A component for one chart type, e.g. `chartComponent(line, 'LineChart')`. */
28
+ export declare function chartComponent<O extends object>(type: ChartType<O>, name: string): ChartComponent<O>;
29
+ /**
30
+ * Bind a chart to an element of your own: created when the element is
31
+ * there, updated when the config changes (deeply), destroyed with the
32
+ * component.
33
+ *
34
+ * ```ts
35
+ * const el = ref<HTMLElement | null>(null)
36
+ * const chart = useChart(el, () => ({ type: line, data: data.value }))
37
+ * ```
38
+ */
39
+ export declare function useChart<O extends object>(target: Ref<Element | null | undefined>, config: MaybeRefOrGetter<ChartConfig<O>>): ShallowRef<Chart<O> | null>;
40
+ //#endregion
41
+ //#region src/index.d.ts
42
+ export declare const LineChart: ChartComponent<LineOptions>;
43
+ export declare const AreaChart: ChartComponent<AreaOptions>;
44
+ export declare const BarChart: ChartComponent<BarOptions>;
45
+ export declare const PieChart: ChartComponent<PieOptions>;
46
+ export declare const DonutChart: ChartComponent<PieOptions>;
47
+ export declare const ScatterChart: ChartComponent<ScatterOptions>;
48
+ export declare const Sparkline: ChartComponent<SparklineOptions>;
49
+ export declare const GaugeChart: ChartComponent<GaugeOptions>;
50
+ export declare const HeatmapChart: ChartComponent<HeatmapOptions>;
51
+ export declare const CandlestickChart: ChartComponent<CandlestickOptions>;
52
+ export declare const RadarChart: ChartComponent<RadarOptions>;
53
+ export declare const SankeyChart: ChartComponent<SankeyOptions>;
54
+ //#endregion
55
+ export type { ChartComponent, ChartEmits, ChartProps };
56
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,56 @@
1
+ import { AreaOptions, BarOptions, CandlestickOptions, Chart, ChartConfig, ChartEvents, ChartType, GaugeOptions, HeatmapOptions, LineOptions, PieOptions, RadarOptions, SankeyOptions, ScatterOptions, SparklineOptions } from "@tabler/charts";
2
+ import { DefineSetupFnComponent, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
3
+ //#region src/chart.d.ts
4
+ /** Chart events, emitted as `hover`, `click`, `legend-toggle` and `render`. */
5
+ type ChartEmits = {
6
+ hover: (event: ChartEvents["hover"]) => void;
7
+ click: (event: ChartEvents["click"]) => void;
8
+ "legend-toggle": (event: ChartEvents["legend-toggle"]) => void;
9
+ render: (event: ChartEvents["render"]) => void;
10
+ };
11
+ /**
12
+ * Props of a chart component: the chart config. `class` and `style` go to
13
+ * the container `<div>` as usual in Vue.
14
+ */
15
+ type ChartProps<O extends object> = Omit<ChartConfig<O>, "class">;
16
+ /** A chart component with its type fixed, such as `<LineChart>`. */
17
+ type ChartComponent<O extends object> = DefineSetupFnComponent<Omit<ChartProps<O>, "type">, ChartEmits>;
18
+ /**
19
+ * Any chart, with the type as a prop. Renders the SVG on the server and
20
+ * takes it over in the browser. The template ref exposes `chart`.
21
+ *
22
+ * ```vue
23
+ * <TablerChart :type="line" :data="data" :aspect-ratio="3" locale="en-US" @hover="onHover" />
24
+ * ```
25
+ */
26
+ export declare const TablerChart: DefineSetupFnComponent<ChartProps<object>, ChartEmits>;
27
+ /** A component for one chart type, e.g. `chartComponent(line, 'LineChart')`. */
28
+ export declare function chartComponent<O extends object>(type: ChartType<O>, name: string): ChartComponent<O>;
29
+ /**
30
+ * Bind a chart to an element of your own: created when the element is
31
+ * there, updated when the config changes (deeply), destroyed with the
32
+ * component.
33
+ *
34
+ * ```ts
35
+ * const el = ref<HTMLElement | null>(null)
36
+ * const chart = useChart(el, () => ({ type: line, data: data.value }))
37
+ * ```
38
+ */
39
+ export declare function useChart<O extends object>(target: Ref<Element | null | undefined>, config: MaybeRefOrGetter<ChartConfig<O>>): ShallowRef<Chart<O> | null>;
40
+ //#endregion
41
+ //#region src/index.d.ts
42
+ export declare const LineChart: ChartComponent<LineOptions>;
43
+ export declare const AreaChart: ChartComponent<AreaOptions>;
44
+ export declare const BarChart: ChartComponent<BarOptions>;
45
+ export declare const PieChart: ChartComponent<PieOptions>;
46
+ export declare const DonutChart: ChartComponent<PieOptions>;
47
+ export declare const ScatterChart: ChartComponent<ScatterOptions>;
48
+ export declare const Sparkline: ChartComponent<SparklineOptions>;
49
+ export declare const GaugeChart: ChartComponent<GaugeOptions>;
50
+ export declare const HeatmapChart: ChartComponent<HeatmapOptions>;
51
+ export declare const CandlestickChart: ChartComponent<CandlestickOptions>;
52
+ export declare const RadarChart: ChartComponent<RadarOptions>;
53
+ export declare const SankeyChart: ChartComponent<SankeyOptions>;
54
+ //#endregion
55
+ export type { ChartComponent, ChartEmits, ChartProps };
56
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,144 @@
1
+ import { Chart, area, bar, candlestick, chartEvents, chartToString, donut, gauge, heatmap, line, pie, radar, resolveSize, sankey, scatter, sparkline } from "@tabler/charts";
2
+ import { defineComponent, getCurrentInstance, h, inject, onActivated, onBeforeUnmount, onMounted, onUpdated, shallowRef, ssrContextKey, toRaw, toValue, useId, watch } from "vue";
3
+ //#region src/chart.ts
4
+ const camelize = (key) => key.replace(/-(\w)/g, (_, c) => c.toUpperCase());
5
+ /** Whether two configs have the same values, key by key (not deep). */
6
+ function shallowEqual(a, b) {
7
+ const ka = Object.keys(a);
8
+ if (ka.length !== Object.keys(b).length) return false;
9
+ return ka.every((key) => Object.is(a[key], b[key]));
10
+ }
11
+ /** A Vue `useId()` as a valid SVG id prefix. */
12
+ const idFrom = (vueId) => `tc-${vueId.replace(/[^a-zA-Z0-9]/g, "")}`;
13
+ function setup(fixedType) {
14
+ return (props, { attrs, emit, expose }) => {
15
+ const id = idFrom(useId() ?? "");
16
+ const config = () => {
17
+ const out = {};
18
+ for (const [key, value] of Object.entries(attrs)) {
19
+ if (key === "class" || key === "style" || /^on[A-Z]/.test(key)) continue;
20
+ out[camelize(key)] = toRaw(value);
21
+ }
22
+ out.data = toRaw(props.data);
23
+ out.type = fixedType ?? toRaw(props.type);
24
+ out.id ??= id;
25
+ return out;
26
+ };
27
+ const initial = config();
28
+ const html = inject(ssrContextKey, null) !== null || getCurrentInstance()?.vnode.el != null ? chartToString(initial, resolveSize(initial)) : "";
29
+ const element = shallowRef(null);
30
+ const chart = shallowRef(null);
31
+ let applied = initial;
32
+ const push = (force) => {
33
+ const next = config();
34
+ if (!chart.value || !force && shallowEqual(applied, next)) return;
35
+ applied = next;
36
+ chart.value.setConfig(next);
37
+ };
38
+ onMounted(() => {
39
+ const created = new Chart(element.value, config());
40
+ applied = created.config;
41
+ for (const name of chartEvents) created.on(name, (event) => emit(name, event));
42
+ chart.value = created;
43
+ });
44
+ onUpdated(() => push(false));
45
+ watch(() => props.data, () => push(true), { deep: true });
46
+ onActivated(() => chart.value?.resize());
47
+ onBeforeUnmount(() => {
48
+ chart.value?.destroy();
49
+ chart.value = null;
50
+ });
51
+ expose({ chart });
52
+ return () => h("div", {
53
+ ref: element,
54
+ class: ["tc-container", attrs.class],
55
+ ...attrs.style ? { style: attrs.style } : {},
56
+ innerHTML: html
57
+ });
58
+ };
59
+ }
60
+ /**
61
+ * Any chart, with the type as a prop. Renders the SVG on the server and
62
+ * takes it over in the browser. The template ref exposes `chart`.
63
+ *
64
+ * ```vue
65
+ * <TablerChart :type="line" :data="data" :aspect-ratio="3" locale="en-US" @hover="onHover" />
66
+ * ```
67
+ */
68
+ const TablerChart = /* @__PURE__ */ defineComponent(setup(void 0), {
69
+ name: "TablerChart",
70
+ inheritAttrs: false,
71
+ props: ["type", "data"],
72
+ emits: [...chartEvents]
73
+ });
74
+ /** A component for one chart type, e.g. `chartComponent(line, 'LineChart')`. */
75
+ function chartComponent(type, name) {
76
+ return defineComponent(setup(type), {
77
+ name,
78
+ inheritAttrs: false,
79
+ props: ["data"],
80
+ emits: [...chartEvents]
81
+ });
82
+ }
83
+ /**
84
+ * Bind a chart to an element of your own: created when the element is
85
+ * there, updated when the config changes (deeply), destroyed with the
86
+ * component.
87
+ *
88
+ * ```ts
89
+ * const el = ref<HTMLElement | null>(null)
90
+ * const chart = useChart(el, () => ({ type: line, data: data.value }))
91
+ * ```
92
+ */
93
+ function useChart(target, config) {
94
+ const chart = shallowRef(null);
95
+ const read = () => toRaw(toValue(config));
96
+ watch(target, (element) => {
97
+ chart.value?.destroy();
98
+ chart.value = element ? new Chart(element, read()) : null;
99
+ }, { flush: "post" });
100
+ onMounted(() => {
101
+ if (!chart.value && target.value) chart.value = new Chart(target.value, read());
102
+ });
103
+ watch(() => toValue(config), () => chart.value?.setConfig(read()), { deep: true });
104
+ onActivated(() => chart.value?.resize());
105
+ onBeforeUnmount(() => {
106
+ chart.value?.destroy();
107
+ chart.value = null;
108
+ });
109
+ return chart;
110
+ }
111
+ //#endregion
112
+ //#region src/index.ts
113
+ /**
114
+ * `@tabler/charts-vue`: Vue 3 components and a composable for `@tabler/charts`.
115
+ * Charts render on the server (Nuxt included) and the browser takes the SVG
116
+ * over. Import `@tabler/charts/style.css` once in your app.
117
+ *
118
+ * ```vue
119
+ * <script setup>
120
+ * import { LineChart } from '@tabler/charts-vue'
121
+ * import '@tabler/charts/style.css'
122
+ * <\/script>
123
+ *
124
+ * <template>
125
+ * <LineChart :data="data" :aspect-ratio="3" locale="en-US" @hover="onHover" />
126
+ * </template>
127
+ * ```
128
+ */
129
+ const LineChart = /* @__PURE__ */ chartComponent(line, "LineChart");
130
+ const AreaChart = /* @__PURE__ */ chartComponent(area, "AreaChart");
131
+ const BarChart = /* @__PURE__ */ chartComponent(bar, "BarChart");
132
+ const PieChart = /* @__PURE__ */ chartComponent(pie, "PieChart");
133
+ const DonutChart = /* @__PURE__ */ chartComponent(donut, "DonutChart");
134
+ const ScatterChart = /* @__PURE__ */ chartComponent(scatter, "ScatterChart");
135
+ const Sparkline = /* @__PURE__ */ chartComponent(sparkline, "Sparkline");
136
+ const GaugeChart = /* @__PURE__ */ chartComponent(gauge, "GaugeChart");
137
+ const HeatmapChart = /* @__PURE__ */ chartComponent(heatmap, "HeatmapChart");
138
+ const CandlestickChart = /* @__PURE__ */ chartComponent(candlestick, "CandlestickChart");
139
+ const RadarChart = /* @__PURE__ */ chartComponent(radar, "RadarChart");
140
+ const SankeyChart = /* @__PURE__ */ chartComponent(sankey, "SankeyChart");
141
+ //#endregion
142
+ export { AreaChart, BarChart, CandlestickChart, DonutChart, GaugeChart, HeatmapChart, LineChart, PieChart, RadarChart, SankeyChart, ScatterChart, Sparkline, TablerChart, chartComponent, useChart };
143
+
144
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/chart.ts","../src/index.ts"],"sourcesContent":["import {\n Chart,\n type ChartConfig,\n type ChartEvents,\n type ChartType,\n chartEvents,\n chartToString,\n resolveSize,\n} from '@tabler/charts'\nimport {\n type DefineSetupFnComponent,\n defineComponent,\n getCurrentInstance,\n h,\n inject,\n type MaybeRefOrGetter,\n onActivated,\n onBeforeUnmount,\n onMounted,\n onUpdated,\n type Ref,\n type SetupContext,\n type ShallowRef,\n shallowRef,\n ssrContextKey,\n toRaw,\n toValue,\n useId,\n watch,\n} from 'vue'\n\n/** Chart events, emitted as `hover`, `click`, `legend-toggle` and `render`. */\nexport type ChartEmits = {\n hover: (event: ChartEvents['hover']) => void\n click: (event: ChartEvents['click']) => void\n 'legend-toggle': (event: ChartEvents['legend-toggle']) => void\n render: (event: ChartEvents['render']) => void\n}\n\n/**\n * Props of a chart component: the chart config. `class` and `style` go to\n * the container `<div>` as usual in Vue.\n */\nexport type ChartProps<O extends object> = Omit<ChartConfig<O>, 'class'>\n\n/** A chart component with its type fixed, such as `<LineChart>`. */\nexport type ChartComponent<O extends object> = DefineSetupFnComponent<\n Omit<ChartProps<O>, 'type'>,\n ChartEmits\n>\n\nconst camelize = (key: string): string => key.replace(/-(\\w)/g, (_, c: string) => c.toUpperCase())\n\n/** Whether two configs have the same values, key by key (not deep). */\nfunction shallowEqual(a: object, b: object): boolean {\n const ka = Object.keys(a)\n if (ka.length !== Object.keys(b).length) return false\n return ka.every((key) =>\n Object.is((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),\n )\n}\n\n/** A Vue `useId()` as a valid SVG id prefix. */\nconst idFrom = (vueId: string): string => `tc-${vueId.replace(/[^a-zA-Z0-9]/g, '')}`\n\nfunction setup<O extends object>(fixedType: ChartType<O> | undefined) {\n return (props: Record<string, unknown>, { attrs, emit, expose }: SetupContext<ChartEmits>) => {\n // Ids from useId() match between the server and the client, so hydration lines up.\n const id = idFrom(useId() ?? '')\n const config = (): ChartConfig<O> => {\n const out: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(attrs)) {\n // class and style belong to the container; listeners are Vue's.\n if (key === 'class' || key === 'style' || /^on[A-Z]/.test(key)) continue\n out[camelize(key)] = toRaw(value)\n }\n out.data = toRaw(props.data)\n out.type = fixedType ?? toRaw(props.type)\n out.id ??= id\n return out as ChartConfig<O>\n }\n\n // The server-rendered chart; the same string on every render, so Vue never\n // rewrites the container while the chart owns it. Only on the server and when\n // hydrating its markup (the component then already has its element): mounted\n // in the browser alone, the chart is built once, by the Chart.\n const initial = config()\n const server = inject(ssrContextKey, null) !== null || getCurrentInstance()?.vnode.el != null\n const html = server ? chartToString(initial, resolveSize(initial)) : ''\n\n const element = shallowRef<HTMLElement | null>(null)\n const chart = shallowRef<Chart<O> | null>(null)\n let applied = initial\n\n const push = (force: boolean) => {\n const next = config()\n if (!chart.value || (!force && shallowEqual(applied, next))) return\n applied = next\n chart.value.setConfig(next)\n }\n\n onMounted(() => {\n // The chart takes the server-rendered svg over in place.\n const created = new Chart(element.value as HTMLElement, config())\n applied = created.config\n for (const name of chartEvents) {\n created.on(name, (event) => (emit as (name: string, event: unknown) => void)(name, event))\n }\n chart.value = created\n })\n // Other options arrive as attributes: compare them after every update.\n onUpdated(() => push(false))\n // Data is watched deeply, so reactive arrays can be changed in place.\n watch(\n () => props.data,\n () => push(true),\n { deep: true },\n )\n // Back from <KeepAlive>, which kept the container out of the page: observe it again.\n onActivated(() => chart.value?.resize())\n onBeforeUnmount(() => {\n chart.value?.destroy()\n chart.value = null\n })\n\n expose({ chart })\n return () =>\n h('div', {\n ref: element,\n class: ['tc-container', attrs.class],\n ...(attrs.style ? { style: attrs.style } : {}),\n innerHTML: html,\n })\n }\n}\n\n/**\n * Any chart, with the type as a prop. Renders the SVG on the server and\n * takes it over in the browser. The template ref exposes `chart`.\n *\n * ```vue\n * <TablerChart :type=\"line\" :data=\"data\" :aspect-ratio=\"3\" locale=\"en-US\" @hover=\"onHover\" />\n * ```\n */\nexport const TablerChart: DefineSetupFnComponent<\n ChartProps<object>,\n ChartEmits\n> = /* @__PURE__ */ defineComponent(setup(undefined) as never, {\n name: 'TablerChart',\n inheritAttrs: false,\n props: ['type', 'data'],\n emits: [...chartEvents],\n}) as never\n\n/** A component for one chart type, e.g. `chartComponent(line, 'LineChart')`. */\nexport function chartComponent<O extends object>(\n type: ChartType<O>,\n name: string,\n): ChartComponent<O> {\n return defineComponent(setup(type) as never, {\n name,\n inheritAttrs: false,\n props: ['data'],\n emits: [...chartEvents],\n }) as never\n}\n\n/**\n * Bind a chart to an element of your own: created when the element is\n * there, updated when the config changes (deeply), destroyed with the\n * component.\n *\n * ```ts\n * const el = ref<HTMLElement | null>(null)\n * const chart = useChart(el, () => ({ type: line, data: data.value }))\n * ```\n */\nexport function useChart<O extends object>(\n target: Ref<Element | null | undefined>,\n config: MaybeRefOrGetter<ChartConfig<O>>,\n): ShallowRef<Chart<O> | null> {\n const chart = shallowRef<Chart<O> | null>(null)\n const read = () => toRaw(toValue(config))\n watch(\n target,\n (element) => {\n chart.value?.destroy()\n chart.value = element ? new Chart(element, read()) : null\n },\n { flush: 'post' },\n )\n onMounted(() => {\n if (!chart.value && target.value) chart.value = new Chart(target.value, read())\n })\n watch(\n () => toValue(config),\n () => chart.value?.setConfig(read()),\n { deep: true },\n )\n onActivated(() => chart.value?.resize())\n onBeforeUnmount(() => {\n chart.value?.destroy()\n chart.value = null\n })\n return chart\n}\n","/**\n * `@tabler/charts-vue`: Vue 3 components and a composable for `@tabler/charts`.\n * Charts render on the server (Nuxt included) and the browser takes the SVG\n * over. Import `@tabler/charts/style.css` once in your app.\n *\n * ```vue\n * <script setup>\n * import { LineChart } from '@tabler/charts-vue'\n * import '@tabler/charts/style.css'\n * </script>\n *\n * <template>\n * <LineChart :data=\"data\" :aspect-ratio=\"3\" locale=\"en-US\" @hover=\"onHover\" />\n * </template>\n * ```\n */\nimport {\n type AreaOptions,\n area,\n type BarOptions,\n bar,\n type CandlestickOptions,\n candlestick,\n donut,\n type GaugeOptions,\n gauge,\n type HeatmapOptions,\n heatmap,\n type LineOptions,\n line,\n type PieOptions,\n pie,\n type RadarOptions,\n radar,\n type SankeyOptions,\n type ScatterOptions,\n type SparklineOptions,\n sankey,\n scatter,\n sparkline,\n} from '@tabler/charts'\nimport { type ChartComponent, chartComponent } from './chart.ts'\n\nexport type { ChartComponent, ChartEmits, ChartProps } from './chart.ts'\nexport { chartComponent, TablerChart, useChart } from './chart.ts'\n\n// Each component is created by a pure call, so unused ones (and their chart types) tree-shake.\nexport const LineChart: ChartComponent<LineOptions> = /* @__PURE__ */ chartComponent(\n line,\n 'LineChart',\n)\nexport const AreaChart: ChartComponent<AreaOptions> = /* @__PURE__ */ chartComponent(\n area,\n 'AreaChart',\n)\nexport const BarChart: ChartComponent<BarOptions> = /* @__PURE__ */ chartComponent(bar, 'BarChart')\nexport const PieChart: ChartComponent<PieOptions> = /* @__PURE__ */ chartComponent(pie, 'PieChart')\nexport const DonutChart: ChartComponent<PieOptions> = /* @__PURE__ */ chartComponent(\n donut,\n 'DonutChart',\n)\nexport const ScatterChart: ChartComponent<ScatterOptions> = /* @__PURE__ */ chartComponent(\n scatter,\n 'ScatterChart',\n)\nexport const Sparkline: ChartComponent<SparklineOptions> = /* @__PURE__ */ chartComponent(\n sparkline,\n 'Sparkline',\n)\nexport const GaugeChart: ChartComponent<GaugeOptions> = /* @__PURE__ */ chartComponent(\n gauge,\n 'GaugeChart',\n)\nexport const HeatmapChart: ChartComponent<HeatmapOptions> = /* @__PURE__ */ chartComponent(\n heatmap,\n 'HeatmapChart',\n)\nexport const CandlestickChart: ChartComponent<CandlestickOptions> = /* @__PURE__ */ chartComponent(\n candlestick,\n 'CandlestickChart',\n)\nexport const RadarChart: ChartComponent<RadarOptions> = /* @__PURE__ */ chartComponent(\n radar,\n 'RadarChart',\n)\nexport const SankeyChart: ChartComponent<SankeyOptions> = /* @__PURE__ */ chartComponent(\n sankey,\n 'SankeyChart',\n)\n"],"mappings":";;;AAmDA,MAAM,YAAY,QAAwB,IAAI,QAAQ,WAAW,GAAG,MAAc,EAAE,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AO,UAAU,KAAK,CAAC,GACnC,EAAE,MAAM,KAAK,CACf;CACA,kBAAkB,MAAM,OAAO,OAAO,CAAC;CACvC,sBAAsB;EACpB,MAAM,OAAO,QAAQ;EACrB,MAAM,QAAQ;CAChB,CAAC;CACD,OAAO;AACT;;;;;;;;;;;;;;;;;;;AC9JA,MAAa,YAAyD,+BACpE,MACA,WACF;AACA,MAAa,YAAyD,+BACpE,MACA,WACF;AACA,MAAa,WAAuD,+BAAe,KAAK,UAAU;AAClG,MAAa,WAAuD,+BAAe,KAAK,UAAU;AAClG,MAAa,aAAyD,+BACpE,OACA,YACF;AACA,MAAa,eAA+D,+BAC1E,SACA,cACF;AACA,MAAa,YAA8D,+BACzE,WACA,WACF;AACA,MAAa,aAA2D,+BACtE,OACA,YACF;AACA,MAAa,eAA+D,+BAC1E,SACA,cACF;AACA,MAAa,mBAAuE,+BAClF,aACA,kBACF;AACA,MAAa,aAA2D,+BACtE,OACA,YACF;AACA,MAAa,cAA6D,+BACxE,QACA,aACF"}
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@tabler/charts-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "Vue 3 components and composable for @tabler/charts, with SSR.",
5
+ "keywords": [
6
+ "charts",
7
+ "svg",
8
+ "vue",
9
+ "nuxt",
10
+ "ssr",
11
+ "tabler"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Paweł Kuna",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/tabler/tabler-charts.git",
18
+ "directory": "packages/vue"
19
+ },
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/index.d.cts",
33
+ "default": "./dist/index.cjs"
34
+ }
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "peerDependencies": {
42
+ "@tabler/charts": "^0.0.1-alpha.0",
43
+ "vue": ">=3.5"
44
+ },
45
+ "devDependencies": {
46
+ "@tabler/charts": "^0.0.1-alpha.0",
47
+ "vue": "^3.5.43"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "build": "tsdown",
54
+ "dev": "tsdown --watch",
55
+ "typecheck": "tsc -p .",
56
+ "lint:pkg": "publint && attw --pack . --profile node16"
57
+ }
6
58
  }