@lucasromero/matrix-ui 0.9.0 → 0.11.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/CHANGELOG.md +21 -0
- package/README.md +1 -0
- package/dist/components/AreaChart/AreaChart.d.ts +3 -0
- package/dist/components/AreaChart/AreaChart.js +14 -0
- package/dist/components/AreaChart/index.d.ts +1 -0
- package/dist/components/BarChart/BarChart.d.ts +3 -0
- package/dist/components/BarChart/BarChart.js +134 -0
- package/dist/components/BarChart/index.d.ts +1 -0
- package/dist/components/Chart/ChartAxes.d.ts +2 -0
- package/dist/components/Chart/ChartAxes.js +28 -0
- package/dist/components/Chart/ChartFrame.d.ts +7 -0
- package/dist/components/Chart/ChartFrame.js +108 -0
- package/dist/components/Chart/ChartPatterns.d.ts +3 -0
- package/dist/components/Chart/ChartPatterns.js +27 -0
- package/dist/components/Chart/ChartPlot.d.ts +2 -0
- package/dist/components/Chart/ChartPlot.js +101 -0
- package/dist/components/Chart/LinearChart.d.ts +3 -0
- package/dist/components/Chart/LinearChart.js +133 -0
- package/dist/components/Chart/RadialChart.d.ts +20 -0
- package/dist/components/Chart/RadialChart.js +112 -0
- package/dist/components/Chart/index.module.js +38 -0
- package/dist/components/Chart/math.d.ts +19 -0
- package/dist/components/Chart/math.js +82 -0
- package/dist/components/Chart/useChartSize.d.ts +3 -0
- package/dist/components/Chart/useChartSize.js +24 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +2 -0
- package/dist/components/CodeBlock/CodeBlock.js +37 -29
- package/dist/components/CodeBlock/HighlightedCode.d.ts +7 -0
- package/dist/components/CodeBlock/HighlightedCode.js +26 -0
- package/dist/components/CodeBlock/highlight.d.ts +2 -0
- package/dist/components/CodeBlock/highlight.js +104 -0
- package/dist/components/CodeBlock/index.module.js +23 -3
- package/dist/components/DonutChart/DonutChart.d.ts +19 -0
- package/dist/components/DonutChart/DonutChart.js +12 -0
- package/dist/components/DonutChart/index.d.ts +1 -0
- package/dist/components/LineChart/LineChart.d.ts +3 -0
- package/dist/components/LineChart/LineChart.js +14 -0
- package/dist/components/LineChart/index.d.ts +1 -0
- package/dist/components/PieChart/PieChart.d.ts +17 -0
- package/dist/components/PieChart/PieChart.js +12 -0
- package/dist/components/PieChart/index.d.ts +1 -0
- package/dist/components/Sparkline/Sparkline.d.ts +7 -0
- package/dist/components/Sparkline/Sparkline.js +56 -0
- package/dist/components/Sparkline/index.d.ts +1 -0
- package/dist/components/Sparkline/index.module.js +9 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +66 -60
- package/dist/styles.css +1 -1
- package/dist/types/areaChartType.d.ts +5 -0
- package/dist/types/barChartType.d.ts +8 -0
- package/dist/types/chartType.d.ts +156 -0
- package/dist/types/codeBlockType.d.ts +20 -0
- package/dist/types/donutChartType.d.ts +6 -0
- package/dist/types/index.d.ts +8 -1
- package/dist/types/lineChartType.d.ts +5 -0
- package/dist/types/pieChartType.d.ts +2 -0
- package/dist/types/sparklineType.d.ts +14 -0
- package/package.json +3 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ChartFrame as e } from "./ChartFrame.js";
|
|
3
|
+
import { ChartPlot as t } from "./ChartPlot.js";
|
|
4
|
+
import { formatNumber as n, seriesColor as r, slicePath as i, toNumber as a } from "./math.js";
|
|
5
|
+
import o from "./index.module.js";
|
|
6
|
+
import { forwardRef as s, useId as c } from "react";
|
|
7
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
8
|
+
// src/components/Chart/RadialChart.tsx
|
|
9
|
+
var d = (e) => `${Math.round(e * 1e3) / 10}%`, f = s(({ data: s, label: f, innerRatio: p, center: m, height: h = 240, formatValue: g = n, formatShare: _ = d, categoryLabel: v = "Category", valueLabel: y = "Value", shareLabel: b = "Share", showLegend: x = !0, keyboardHint: S = "Use the arrow keys to read each value.", ...C }, w) => {
|
|
10
|
+
let T = c(), E = s.flatMap((e, t) => {
|
|
11
|
+
let n = a(e.value), i = e.color ?? t + 1;
|
|
12
|
+
return n !== null && n > 0 ? [{
|
|
13
|
+
label: e.label,
|
|
14
|
+
value: n,
|
|
15
|
+
slot: i,
|
|
16
|
+
color: r(i)
|
|
17
|
+
}] : [];
|
|
18
|
+
}), D = E.reduce((e, { value: t }) => e + t, 0), O = E.map((e, t) => {
|
|
19
|
+
let n = E.slice(0, t).reduce((e, { value: t }) => e + t, 0);
|
|
20
|
+
return {
|
|
21
|
+
...e,
|
|
22
|
+
share: e.value / D,
|
|
23
|
+
start: n / D,
|
|
24
|
+
end: (n + e.value) / D
|
|
25
|
+
};
|
|
26
|
+
}), k = (e) => {
|
|
27
|
+
let t = Math.max(1, Math.min(e.width, h) / 2 - 6);
|
|
28
|
+
return {
|
|
29
|
+
radius: t,
|
|
30
|
+
middle: {
|
|
31
|
+
x: e.width / 2,
|
|
32
|
+
y: h / 2
|
|
33
|
+
},
|
|
34
|
+
inner: t * p
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ l(e, {
|
|
38
|
+
...C,
|
|
39
|
+
ref: w,
|
|
40
|
+
label: f,
|
|
41
|
+
patternId: T,
|
|
42
|
+
isEmpty: O.length === 0,
|
|
43
|
+
legend: x ? O.map((e) => ({
|
|
44
|
+
label: e.label,
|
|
45
|
+
color: e.color,
|
|
46
|
+
slot: e.slot,
|
|
47
|
+
mark: "fill",
|
|
48
|
+
value: _(e.share)
|
|
49
|
+
})) : [],
|
|
50
|
+
table: {
|
|
51
|
+
headers: [
|
|
52
|
+
v,
|
|
53
|
+
y,
|
|
54
|
+
b
|
|
55
|
+
],
|
|
56
|
+
rows: O.map((e) => [
|
|
57
|
+
e.label,
|
|
58
|
+
g(e.value),
|
|
59
|
+
_(e.share)
|
|
60
|
+
])
|
|
61
|
+
},
|
|
62
|
+
children: /* @__PURE__ */ l(t, {
|
|
63
|
+
label: f,
|
|
64
|
+
height: h,
|
|
65
|
+
hint: S,
|
|
66
|
+
count: O.length,
|
|
67
|
+
patternId: T,
|
|
68
|
+
findIndex: ({ x: e, y: t }, n) => {
|
|
69
|
+
let { radius: r, middle: i, inner: a } = k(n), o = Math.hypot(e - i.x, t - i.y);
|
|
70
|
+
if (o > r || o < a) return null;
|
|
71
|
+
let s = (Math.atan2(t - i.y, e - i.x) / (2 * Math.PI) + .25 + 1) % 1, c = O.findIndex(({ start: e, end: t }) => s >= e && s < t);
|
|
72
|
+
return c === -1 ? null : c;
|
|
73
|
+
},
|
|
74
|
+
getAnchor: (e, t) => {
|
|
75
|
+
let { radius: n, middle: r, inner: i } = k(t), { start: a, end: o } = O[e], s = (a + o) / 2 * 2 * Math.PI - Math.PI / 2, c = (n + i) / 2;
|
|
76
|
+
return {
|
|
77
|
+
x: r.x + c * Math.cos(s),
|
|
78
|
+
y: Math.min(Math.max(0, r.y + c * Math.sin(s) - t.fontSize * 1.5), Math.max(0, h - t.fontSize * 4))
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
getTooltip: (e) => {
|
|
82
|
+
let t = O[e];
|
|
83
|
+
return { rows: [{
|
|
84
|
+
label: `${t.label}, ${_(t.share)}`,
|
|
85
|
+
value: g(t.value),
|
|
86
|
+
color: t.color
|
|
87
|
+
}] };
|
|
88
|
+
},
|
|
89
|
+
overlay: m ? /* @__PURE__ */ l("div", {
|
|
90
|
+
className: o.center,
|
|
91
|
+
children: m
|
|
92
|
+
}) : void 0,
|
|
93
|
+
render: (e, t) => {
|
|
94
|
+
let { radius: n, middle: r, inner: a } = k(e);
|
|
95
|
+
return O.map((e, s) => {
|
|
96
|
+
let c = i(r, a, s === t ? n + 4 : n, e.start, e.end);
|
|
97
|
+
return /* @__PURE__ */ u("g", { children: [/* @__PURE__ */ l("path", {
|
|
98
|
+
className: o.slice,
|
|
99
|
+
style: { fill: e.color },
|
|
100
|
+
d: c
|
|
101
|
+
}), /* @__PURE__ */ l("path", {
|
|
102
|
+
className: o.pattern,
|
|
103
|
+
fill: `url(#${T}-${(e.slot - 1) % 8 + 1})`,
|
|
104
|
+
d: c
|
|
105
|
+
})] }, s);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
f.displayName = "RadialChart";
|
|
112
|
+
export { f as RadialChart };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/components/Chart/index.module.scss
|
|
2
|
+
var e = "matrix-chart-chart", t = "matrix-chart-caption", n = "matrix-chart-label", r = "matrix-chart-hiddenCaption", i = "matrix-chart-hiddenTable", a = "matrix-chart-empty", o = "matrix-chart-legend", s = "matrix-chart-legendItem", c = "matrix-chart-legendValue", l = "matrix-chart-swatch", u = "matrix-chart-plotArea", d = "matrix-chart-plot", f = "matrix-chart-svg", p = "matrix-chart-grid", m = "matrix-chart-baseline", h = "matrix-chart-crosshair", g = "matrix-chart-tick", _ = "matrix-chart-line", v = "matrix-chart-marker", y = "matrix-chart-area", b = "matrix-chart-stackedArea", x = "matrix-chart-band", S = "matrix-chart-slice", C = "matrix-chart-pattern", w = "matrix-chart-withPatterns", T = "matrix-chart-patternLine", E = "matrix-chart-patternDot", D = "matrix-chart-tooltip", O = "matrix-chart-tooltipTitle", k = "matrix-chart-tooltipRow", A = "matrix-chart-tooltipKey", j = "matrix-chart-tooltipValue", M = "matrix-chart-center", N = "matrix-chart-table", P = {
|
|
3
|
+
chart: e,
|
|
4
|
+
caption: t,
|
|
5
|
+
label: n,
|
|
6
|
+
hiddenCaption: r,
|
|
7
|
+
hiddenTable: i,
|
|
8
|
+
empty: a,
|
|
9
|
+
legend: o,
|
|
10
|
+
legendItem: s,
|
|
11
|
+
legendValue: c,
|
|
12
|
+
swatch: l,
|
|
13
|
+
plotArea: u,
|
|
14
|
+
plot: d,
|
|
15
|
+
svg: f,
|
|
16
|
+
grid: p,
|
|
17
|
+
baseline: m,
|
|
18
|
+
crosshair: h,
|
|
19
|
+
tick: g,
|
|
20
|
+
line: _,
|
|
21
|
+
marker: v,
|
|
22
|
+
area: y,
|
|
23
|
+
stackedArea: b,
|
|
24
|
+
band: x,
|
|
25
|
+
slice: S,
|
|
26
|
+
pattern: C,
|
|
27
|
+
withPatterns: w,
|
|
28
|
+
patternLine: T,
|
|
29
|
+
patternDot: E,
|
|
30
|
+
tooltip: D,
|
|
31
|
+
tooltipTitle: O,
|
|
32
|
+
tooltipRow: k,
|
|
33
|
+
tooltipKey: A,
|
|
34
|
+
tooltipValue: j,
|
|
35
|
+
center: M,
|
|
36
|
+
table: N
|
|
37
|
+
};
|
|
38
|
+
export { y as area, x as band, m as baseline, t as caption, M as center, e as chart, h as crosshair, P as default, a as empty, p as grid, r as hiddenCaption, i as hiddenTable, n as label, o as legend, s as legendItem, c as legendValue, _ as line, v as marker, C as pattern, E as patternDot, T as patternLine, d as plot, u as plotArea, S as slice, b as stackedArea, f as svg, l as swatch, N as table, g as tick, D as tooltip, A as tooltipKey, k as tooltipRow, O as tooltipTitle, j as tooltipValue, w as withPatterns };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ChartPoint, ChartScale, ChartSeries, ChartSeriesValues } from "../../types/chartType.js";
|
|
2
|
+
export declare const formatNumber: (value: number) => string;
|
|
3
|
+
export declare const formatTicks: (scale: ChartScale) => (value: number) => string;
|
|
4
|
+
export declare const toNumber: (value: unknown) => number | null;
|
|
5
|
+
export declare const seriesColor: (slot: number) => string;
|
|
6
|
+
export declare const readSeries: <Row extends object>(data: readonly Row[], series: readonly ChartSeries<Row>[]) => ChartSeriesValues[];
|
|
7
|
+
export declare const createScale: (low: number, high: number) => ChartScale;
|
|
8
|
+
export declare const scaleRatio: (value: number, scale: ChartScale) => number;
|
|
9
|
+
export declare const stackSeries: (series: ChartSeriesValues[], count: number) => {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
}[][];
|
|
13
|
+
export declare const linePath: (points: ChartPoint[]) => string;
|
|
14
|
+
export declare const splitAtGaps: (points: (ChartPoint | null)[]) => ChartPoint[][];
|
|
15
|
+
export declare const markerPath: (slot: number, x: number, y: number, radius: number) => string;
|
|
16
|
+
export declare const barPath: (x: number, y: number, width: number, height: number, roundedSide: "top" | "bottom" | "left" | "right" | "none") => string;
|
|
17
|
+
export declare const slicePath: (center: ChartPoint, innerRadius: number, outerRadius: number, start: number, end: number) => string;
|
|
18
|
+
export declare const textWidth: (text: string, fontSize: number) => number;
|
|
19
|
+
export declare const fitText: (text: string, width: number, fontSize: number) => string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/components/Chart/math.ts
|
|
2
|
+
var e = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }), t = new Intl.NumberFormat("en-US", {
|
|
3
|
+
notation: "compact",
|
|
4
|
+
maximumFractionDigits: 1
|
|
5
|
+
}), n = (t) => e.format(t), r = (e) => Math.max(Math.abs(e.min), Math.abs(e.max)) >= 1e4 ? (e) => t.format(e) : n, i = (e) => typeof e == "number" && Number.isFinite(e) ? e : null, a = (e) => e <= 8 ? `var(--matrix-chart-color-${e})` : "var(--matrix-color-text-subtle)", o = (e, t) => t.map(({ key: t, label: n, color: r }, o) => {
|
|
6
|
+
let s = r ?? o + 1;
|
|
7
|
+
return {
|
|
8
|
+
label: n,
|
|
9
|
+
slot: s,
|
|
10
|
+
color: a(s),
|
|
11
|
+
values: e.map((e) => i(e[t]))
|
|
12
|
+
};
|
|
13
|
+
}), s = (e, t) => {
|
|
14
|
+
let n = e === t ? Math.min(e, 0) : e, r = e === t ? t > 0 ? t : n + 1 : t, i = (r - n) / 4, a = 10 ** Math.floor(Math.log10(i)), o = a * ([
|
|
15
|
+
1,
|
|
16
|
+
2,
|
|
17
|
+
2.5,
|
|
18
|
+
5
|
|
19
|
+
].find((e) => e * a >= i) ?? 10), s = Math.floor(n / o), c = Math.ceil(r / o), l = Array.from({ length: c - s + 1 }, (e, t) => Number(((s + t) * o).toPrecision(12)));
|
|
20
|
+
return {
|
|
21
|
+
min: l[0],
|
|
22
|
+
max: l[l.length - 1],
|
|
23
|
+
ticks: l
|
|
24
|
+
};
|
|
25
|
+
}, c = (e, t) => (e - t.min) / (t.max - t.min), l = (e, t) => {
|
|
26
|
+
let n = Array.from({ length: t }, () => 0), r = Array.from({ length: t }, () => 0);
|
|
27
|
+
return e.map(({ values: e }) => e.map((e, t) => {
|
|
28
|
+
let i = e ?? 0, a = i < 0 ? r : n, o = a[t];
|
|
29
|
+
return a[t] += i, {
|
|
30
|
+
start: o,
|
|
31
|
+
end: a[t]
|
|
32
|
+
};
|
|
33
|
+
}));
|
|
34
|
+
}, u = (e) => e.map(({ x: e, y: t }, n) => `${n === 0 ? "M" : "L"}${e},${t}`).join(""), d = (e) => e.reduce((e, t) => (t ? e[e.length - 1].push(t) : e[e.length - 1].length > 0 && e.push([]), e), [[]]).filter((e) => e.length > 0), f = (e, t, n, r, i) => `${u(Array.from({ length: r }, (a, o) => {
|
|
35
|
+
let s = i + o * 2 * Math.PI / r;
|
|
36
|
+
return {
|
|
37
|
+
x: e + n * Math.cos(s),
|
|
38
|
+
y: t + n * Math.sin(s)
|
|
39
|
+
};
|
|
40
|
+
}))}Z`, p = (e, t, n, r) => {
|
|
41
|
+
let i = -Math.PI / 2;
|
|
42
|
+
switch ((e - 1) % 8) {
|
|
43
|
+
case 1: return f(t, n, r * 1.2, 4, Math.PI / 4);
|
|
44
|
+
case 2: return f(t, n, r * 1.3, 3, i);
|
|
45
|
+
case 3: return f(t, n, r * 1.25, 4, i);
|
|
46
|
+
case 4: return f(t, n, r * 1.3, 3, -i);
|
|
47
|
+
case 5: return f(t, n, r * 1.15, 5, i);
|
|
48
|
+
case 6: return f(t, n, r * 1.15, 6, i);
|
|
49
|
+
case 7: return f(t, n, r * 1.15, 5, -i);
|
|
50
|
+
default: return `M${t - r},${n}a${r},${r} 0 1,0 ${r * 2},0a${r},${r} 0 1,0 ${-r * 2},0Z`;
|
|
51
|
+
}
|
|
52
|
+
}, m = (e, t, n, r, i) => {
|
|
53
|
+
let a = Math.min(4, n / 2, r / 2), o = (...e) => e.includes(i) ? a : 0, s = o("top", "left"), c = o("top", "right"), l = o("bottom", "right"), u = o("bottom", "left"), d = (e, t, n) => e > 0 ? `a${e},${e} 0 0,1 ${t * e},${n * e}` : "";
|
|
54
|
+
return [
|
|
55
|
+
`M${e + s},${t}`,
|
|
56
|
+
`H${e + n - c}`,
|
|
57
|
+
d(c, 1, 1),
|
|
58
|
+
`V${t + r - l}`,
|
|
59
|
+
d(l, -1, 1),
|
|
60
|
+
`H${e + u}`,
|
|
61
|
+
d(u, -1, -1),
|
|
62
|
+
`V${t + s}`,
|
|
63
|
+
d(s, 1, -1),
|
|
64
|
+
"Z"
|
|
65
|
+
].join("");
|
|
66
|
+
}, h = (e, t, n, r, i) => {
|
|
67
|
+
let a = (t, n) => {
|
|
68
|
+
let r = n * 2 * Math.PI - Math.PI / 2;
|
|
69
|
+
return `${e.x + t * Math.cos(r)},${e.y + t * Math.sin(r)}`;
|
|
70
|
+
};
|
|
71
|
+
if (i - r > .9999) {
|
|
72
|
+
let e = (e, t) => `M${a(e, 0)}A${e},${e} 0 1,${t} ${a(e, .5)}A${e},${e} 0 1,${t} ${a(e, 0)}Z`;
|
|
73
|
+
return e(n, 1) + (t > 0 ? e(t, 0) : "");
|
|
74
|
+
}
|
|
75
|
+
let o = +(i - r > .5), s = `M${a(n, r)}A${n},${n} 0 ${o},1 ${a(n, i)}`;
|
|
76
|
+
return t > 0 ? `${s}L${a(t, i)}A${t},${t} 0 ${o},0 ${a(t, r)}Z` : `${s}L${e.x},${e.y}Z`;
|
|
77
|
+
}, g = (e, t) => e.length * t * .58, _ = (e, t, n) => {
|
|
78
|
+
if (g(e, n) <= t) return e;
|
|
79
|
+
let r = Math.max(1, Math.floor(t / (n * .58)) - 1);
|
|
80
|
+
return `${e.slice(0, r).trimEnd()}…`;
|
|
81
|
+
};
|
|
82
|
+
export { m as barPath, s as createScale, _ as fitText, n as formatNumber, r as formatTicks, u as linePath, p as markerPath, o as readSeries, c as scaleRatio, a as seriesColor, h as slicePath, d as splitAtGaps, l as stackSeries, g as textWidth, i as toNumber };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect as e, useLayoutEffect as t, useState as n } from "react";
|
|
3
|
+
// src/components/Chart/useChartSize.ts
|
|
4
|
+
var r = typeof window > "u" ? e : t, i = (e) => {
|
|
5
|
+
let [t, i] = n({
|
|
6
|
+
width: 600,
|
|
7
|
+
fontSize: 13
|
|
8
|
+
});
|
|
9
|
+
return r(() => {
|
|
10
|
+
let t = e.current;
|
|
11
|
+
if (!t) return;
|
|
12
|
+
let n = () => {
|
|
13
|
+
let e = Math.round(t.getBoundingClientRect().width), n = Number.parseFloat(getComputedStyle(t).fontSize) || 13;
|
|
14
|
+
e !== 0 && i((t) => t.width === e && t.fontSize === n ? t : {
|
|
15
|
+
width: e,
|
|
16
|
+
fontSize: n
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
if (n(), typeof ResizeObserver > "u") return;
|
|
20
|
+
let r = new ResizeObserver(n);
|
|
21
|
+
return r.observe(t), () => r.disconnect();
|
|
22
|
+
}, [e]), t;
|
|
23
|
+
};
|
|
24
|
+
export { i as useChartSize };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const CodeBlock: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLDivElement>, "children" | "title"> & {
|
|
2
2
|
code: string;
|
|
3
3
|
title?: string;
|
|
4
|
+
language?: import("../../index.js").CodeBlockLanguage;
|
|
5
|
+
codeColor?: import("../../index.js").CodeBlockColor;
|
|
4
6
|
copyLabel?: string;
|
|
5
7
|
copyButtonLabel?: string;
|
|
6
8
|
copiedMessage?: string;
|
|
@@ -1,47 +1,55 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Button as e } from "../Button/Button.js";
|
|
3
3
|
import { Text as t } from "../Text/Text.js";
|
|
4
|
-
import n from "./
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
4
|
+
import { HighlightedCode as n } from "./HighlightedCode.js";
|
|
5
|
+
import r from "./index.module.js";
|
|
6
|
+
import { forwardRef as i, useState as a } from "react";
|
|
7
|
+
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
7
8
|
// src/components/CodeBlock/CodeBlock.tsx
|
|
8
|
-
var
|
|
9
|
-
let [
|
|
9
|
+
var c = i(({ code: i, title: c, language: l, codeColor: u = "vscode", copyLabel: d = "Copy", copyButtonLabel: f = c ? `${d} ${c}` : `${d} code`, copiedMessage: p = "Copied", copyFailedMessage: m = "Copy failed", className: h, ...g }, _) => {
|
|
10
|
+
let [v, y] = a("idle"), b = async () => {
|
|
10
11
|
try {
|
|
11
|
-
await navigator.clipboard.writeText(
|
|
12
|
+
await navigator.clipboard.writeText(i), y("copied");
|
|
12
13
|
} catch {
|
|
13
|
-
|
|
14
|
+
y("failed");
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
|
-
return /* @__PURE__ */
|
|
17
|
-
...
|
|
18
|
-
ref:
|
|
19
|
-
className: [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
return /* @__PURE__ */ s("div", {
|
|
18
|
+
...g,
|
|
19
|
+
ref: _,
|
|
20
|
+
className: [
|
|
21
|
+
r.codeBlock,
|
|
22
|
+
l && r[u],
|
|
23
|
+
h
|
|
24
|
+
].filter(Boolean).join(" "),
|
|
25
|
+
children: [/* @__PURE__ */ s("div", {
|
|
26
|
+
className: r.header,
|
|
27
|
+
children: [c && /* @__PURE__ */ o(t, {
|
|
23
28
|
variant: "label",
|
|
24
|
-
children:
|
|
25
|
-
}), /* @__PURE__ */
|
|
26
|
-
className:
|
|
27
|
-
children: [/* @__PURE__ */
|
|
29
|
+
children: c
|
|
30
|
+
}), /* @__PURE__ */ s("div", {
|
|
31
|
+
className: r.actions,
|
|
32
|
+
children: [/* @__PURE__ */ s("span", {
|
|
28
33
|
role: "status",
|
|
29
|
-
className:
|
|
30
|
-
children: [
|
|
31
|
-
}), /* @__PURE__ */
|
|
34
|
+
className: r.status,
|
|
35
|
+
children: [v === "copied" && p, v === "failed" && m]
|
|
36
|
+
}), /* @__PURE__ */ o(e, {
|
|
32
37
|
variant: "ghost",
|
|
33
38
|
size: "small",
|
|
34
|
-
onClick:
|
|
35
|
-
"aria-label":
|
|
36
|
-
children:
|
|
39
|
+
onClick: b,
|
|
40
|
+
"aria-label": f,
|
|
41
|
+
children: d
|
|
37
42
|
})]
|
|
38
43
|
})]
|
|
39
|
-
}), /* @__PURE__ */
|
|
40
|
-
className:
|
|
44
|
+
}), /* @__PURE__ */ o("pre", {
|
|
45
|
+
className: r.code,
|
|
41
46
|
tabIndex: 0,
|
|
42
|
-
children: /* @__PURE__ */
|
|
47
|
+
children: /* @__PURE__ */ o("code", { children: l ? /* @__PURE__ */ o(n, {
|
|
48
|
+
code: i.trimEnd(),
|
|
49
|
+
language: l
|
|
50
|
+
}) : i.trimEnd() })
|
|
43
51
|
})]
|
|
44
52
|
});
|
|
45
53
|
});
|
|
46
|
-
|
|
47
|
-
export {
|
|
54
|
+
c.displayName = "CodeBlock";
|
|
55
|
+
export { c as CodeBlock };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CodeBlockLanguage } from "../../types/codeBlockType.js";
|
|
2
|
+
type HighlightedCodeProps = {
|
|
3
|
+
code: string;
|
|
4
|
+
language: CodeBlockLanguage;
|
|
5
|
+
};
|
|
6
|
+
export declare function HighlightedCode({ code, language }: HighlightedCodeProps): import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import e from "./index.module.js";
|
|
3
|
+
import { useMemo as t, useSyncExternalStore as n } from "react";
|
|
4
|
+
import { Fragment as r, jsx as i } from "react/jsx-runtime";
|
|
5
|
+
// src/components/CodeBlock/HighlightedCode.tsx
|
|
6
|
+
var a = null, o = /* @__PURE__ */ new Set(), s = async () => {
|
|
7
|
+
try {
|
|
8
|
+
a = (await import("./highlight.js")).highlight, o.forEach((e) => e());
|
|
9
|
+
} catch {
|
|
10
|
+
a = null;
|
|
11
|
+
}
|
|
12
|
+
}, c = (e) => (o.add(e), a || s(), () => {
|
|
13
|
+
o.delete(e);
|
|
14
|
+
});
|
|
15
|
+
function l({ code: o, language: s }) {
|
|
16
|
+
let l = n(c, () => a, () => null), u = t(() => l?.(o, s), [
|
|
17
|
+
l,
|
|
18
|
+
o,
|
|
19
|
+
s
|
|
20
|
+
]);
|
|
21
|
+
return u ? /* @__PURE__ */ i(r, { children: u.map(({ text: t, role: n }, r) => n ? /* @__PURE__ */ i("span", {
|
|
22
|
+
className: e[n],
|
|
23
|
+
children: t
|
|
24
|
+
}, r) : t) }) : /* @__PURE__ */ i(r, { children: o });
|
|
25
|
+
}
|
|
26
|
+
export { l as HighlightedCode };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Prism as e, normalizeTokens as t } from "prism-react-renderer";
|
|
2
|
+
// src/components/CodeBlock/highlight.ts
|
|
3
|
+
var n = {
|
|
4
|
+
comment: "comment",
|
|
5
|
+
prolog: "comment",
|
|
6
|
+
doctype: "comment",
|
|
7
|
+
cdata: "comment",
|
|
8
|
+
keyword: "keyword",
|
|
9
|
+
boolean: "keyword",
|
|
10
|
+
atrule: "keyword",
|
|
11
|
+
important: "keyword",
|
|
12
|
+
string: "string",
|
|
13
|
+
char: "string",
|
|
14
|
+
regex: "string",
|
|
15
|
+
url: "string",
|
|
16
|
+
"attr-value": "string",
|
|
17
|
+
number: "number",
|
|
18
|
+
unit: "number",
|
|
19
|
+
hexcode: "number",
|
|
20
|
+
function: "function",
|
|
21
|
+
"class-name": "type",
|
|
22
|
+
"maybe-class-name": "type",
|
|
23
|
+
builtin: "type",
|
|
24
|
+
property: "property",
|
|
25
|
+
variable: "property",
|
|
26
|
+
constant: "property",
|
|
27
|
+
key: "property",
|
|
28
|
+
tag: "tag",
|
|
29
|
+
selector: "tag",
|
|
30
|
+
"attr-name": "attribute",
|
|
31
|
+
"property-access": "variable",
|
|
32
|
+
punctuation: null,
|
|
33
|
+
operator: null,
|
|
34
|
+
interpolation: null,
|
|
35
|
+
spread: null,
|
|
36
|
+
script: null,
|
|
37
|
+
plain: null
|
|
38
|
+
}, r = new Set("import export from default return if else for while do switch case break continue try catch finally throw await yield".split(" ")), i = [
|
|
39
|
+
"bracket1",
|
|
40
|
+
"bracket2",
|
|
41
|
+
"bracket3"
|
|
42
|
+
], a = (e, t) => {
|
|
43
|
+
if (e.includes("plain-text")) return null;
|
|
44
|
+
if (e.includes("attr-value") && (t === "\"" || t === "'")) return "string";
|
|
45
|
+
if (e.includes("interpolation-punctuation") || e.includes("arrow")) return "keyword";
|
|
46
|
+
if (e.includes("tag") && /^[</>]+$/.test(t)) return "delimiter";
|
|
47
|
+
let i = [...e].reverse().find((e) => Object.hasOwn(n, e)), a = i ? n[i] : null;
|
|
48
|
+
return a === "keyword" && r.has(t) ? "control" : a;
|
|
49
|
+
}, o = {
|
|
50
|
+
pattern: /([\p{L}_$][\p{L}\p{N}_$]*)/u,
|
|
51
|
+
role: "variable"
|
|
52
|
+
}, s = {
|
|
53
|
+
js: o,
|
|
54
|
+
jsx: o,
|
|
55
|
+
ts: o,
|
|
56
|
+
tsx: o,
|
|
57
|
+
css: {
|
|
58
|
+
pattern: /([a-z][\w-]*)/i,
|
|
59
|
+
role: "string"
|
|
60
|
+
}
|
|
61
|
+
}, c = (e, t) => {
|
|
62
|
+
let n = s[t];
|
|
63
|
+
return n ? e.split(n.pattern).map((e, t) => ({
|
|
64
|
+
text: e,
|
|
65
|
+
role: t % 2 == 1 ? n.role : null
|
|
66
|
+
})).filter((e) => e.text !== "") : [{
|
|
67
|
+
text: e,
|
|
68
|
+
role: null
|
|
69
|
+
}];
|
|
70
|
+
}, l = (e) => {
|
|
71
|
+
let t = 0;
|
|
72
|
+
return e.map((e) => {
|
|
73
|
+
if (e.role !== null || !/^[()[\]{}]$/.test(e.text)) return e;
|
|
74
|
+
/[)\]}]/.test(e.text) && (t = Math.max(0, t - 1));
|
|
75
|
+
let n = i[t % i.length];
|
|
76
|
+
return /[([{]/.test(e.text) && (t += 1), {
|
|
77
|
+
...e,
|
|
78
|
+
role: n
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}, u = (n, r) => {
|
|
82
|
+
let i = e.languages[r];
|
|
83
|
+
if (!i) return [{
|
|
84
|
+
text: n,
|
|
85
|
+
role: null
|
|
86
|
+
}];
|
|
87
|
+
let o = {
|
|
88
|
+
code: n,
|
|
89
|
+
grammar: i,
|
|
90
|
+
language: r,
|
|
91
|
+
tokens: e.tokenize(n, i)
|
|
92
|
+
};
|
|
93
|
+
return e.hooks.run("after-tokenize", o), l(t(o.tokens).flatMap((e, t) => [...t > 0 ? [{
|
|
94
|
+
text: "\n",
|
|
95
|
+
role: null
|
|
96
|
+
}] : [], ...e.filter((e) => !e.empty && e.content !== "").flatMap(({ types: e, content: t }) => {
|
|
97
|
+
let n = a(e, t);
|
|
98
|
+
return n === null && !e.includes("plain-text") ? c(t, r) : [{
|
|
99
|
+
text: t,
|
|
100
|
+
role: n
|
|
101
|
+
}];
|
|
102
|
+
})]));
|
|
103
|
+
};
|
|
104
|
+
export { u as highlight };
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
// src/components/CodeBlock/index.module.scss
|
|
2
|
-
var e = "matrix-codeblock-codeBlock", t = "matrix-codeblock-header", n = "matrix-codeblock-actions", r = "matrix-codeblock-status", i = "matrix-codeblock-code", a = {
|
|
2
|
+
var e = "matrix-codeblock-codeBlock", t = "matrix-codeblock-header", n = "matrix-codeblock-actions", r = "matrix-codeblock-status", i = "matrix-codeblock-code", a = "matrix-codeblock-vscode", o = "matrix-codeblock-github", s = "matrix-codeblock-one", c = "matrix-codeblock-dracula", l = "matrix-codeblock-solarized", u = "matrix-codeblock-comment", d = "matrix-codeblock-keyword", f = "matrix-codeblock-control", p = "matrix-codeblock-string", m = "matrix-codeblock-number", h = "matrix-codeblock-type", g = "matrix-codeblock-property", _ = "matrix-codeblock-tag", v = "matrix-codeblock-attribute", y = "matrix-codeblock-variable", b = "matrix-codeblock-delimiter", x = "matrix-codeblock-bracket1", S = "matrix-codeblock-bracket2", C = "matrix-codeblock-bracket3", w = {
|
|
3
3
|
codeBlock: e,
|
|
4
4
|
header: t,
|
|
5
5
|
actions: n,
|
|
6
6
|
status: r,
|
|
7
|
-
code: i
|
|
7
|
+
code: i,
|
|
8
|
+
vscode: a,
|
|
9
|
+
github: o,
|
|
10
|
+
one: s,
|
|
11
|
+
dracula: c,
|
|
12
|
+
solarized: l,
|
|
13
|
+
comment: u,
|
|
14
|
+
keyword: d,
|
|
15
|
+
control: f,
|
|
16
|
+
string: p,
|
|
17
|
+
number: m,
|
|
18
|
+
function: "matrix-codeblock-function",
|
|
19
|
+
type: h,
|
|
20
|
+
property: g,
|
|
21
|
+
tag: _,
|
|
22
|
+
attribute: v,
|
|
23
|
+
variable: y,
|
|
24
|
+
delimiter: b,
|
|
25
|
+
bracket1: x,
|
|
26
|
+
bracket2: S,
|
|
27
|
+
bracket3: C
|
|
8
28
|
};
|
|
9
|
-
export { n as actions, i as code, e as codeBlock,
|
|
29
|
+
export { n as actions, v as attribute, x as bracket1, S as bracket2, C as bracket3, i as code, e as codeBlock, u as comment, f as control, w as default, b as delimiter, c as dracula, o as github, t as header, d as keyword, m as number, s as one, g as property, l as solarized, r as status, p as string, _ as tag, h as type, y as variable, a as vscode };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const DonutChart: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLElement>, "children"> & {
|
|
2
|
+
label: string;
|
|
3
|
+
hideLabel?: boolean;
|
|
4
|
+
height?: number;
|
|
5
|
+
formatValue?: (value: number) => string;
|
|
6
|
+
showTable?: boolean;
|
|
7
|
+
categoryLabel?: string;
|
|
8
|
+
patterns?: boolean;
|
|
9
|
+
emptyMessage?: import("react").ReactNode;
|
|
10
|
+
keyboardHint?: string;
|
|
11
|
+
} & {
|
|
12
|
+
data: readonly import("../../index.js").ChartSlice[];
|
|
13
|
+
valueLabel?: string;
|
|
14
|
+
shareLabel?: string;
|
|
15
|
+
formatShare?: (share: number) => string;
|
|
16
|
+
showLegend?: boolean;
|
|
17
|
+
} & {
|
|
18
|
+
center?: import("react").ReactNode;
|
|
19
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { RadialChart as e } from "../Chart/RadialChart.js";
|
|
3
|
+
import { forwardRef as t } from "react";
|
|
4
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
5
|
+
// src/components/DonutChart/DonutChart.tsx
|
|
6
|
+
var r = t((t, r) => /* @__PURE__ */ n(e, {
|
|
7
|
+
...t,
|
|
8
|
+
ref: r,
|
|
9
|
+
innerRatio: .62
|
|
10
|
+
}));
|
|
11
|
+
r.displayName = "DonutChart";
|
|
12
|
+
export { r as DonutChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DonutChart } from "./DonutChart.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { LinearChart as e } from "../Chart/LinearChart.js";
|
|
3
|
+
import { forwardRef as t } from "react";
|
|
4
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
5
|
+
var r = t(({ includeZero: t = !0, ...r }, i) => /* @__PURE__ */ n(e, {
|
|
6
|
+
...r,
|
|
7
|
+
ref: i,
|
|
8
|
+
kind: "line",
|
|
9
|
+
includeZero: t,
|
|
10
|
+
stacked: !1
|
|
11
|
+
}));
|
|
12
|
+
r.displayName = "LineChart";
|
|
13
|
+
var i = r;
|
|
14
|
+
export { i as LineChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LineChart } from "./LineChart.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const PieChart: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLElement>, "children"> & {
|
|
2
|
+
label: string;
|
|
3
|
+
hideLabel?: boolean;
|
|
4
|
+
height?: number;
|
|
5
|
+
formatValue?: (value: number) => string;
|
|
6
|
+
showTable?: boolean;
|
|
7
|
+
categoryLabel?: string;
|
|
8
|
+
patterns?: boolean;
|
|
9
|
+
emptyMessage?: import("react").ReactNode;
|
|
10
|
+
keyboardHint?: string;
|
|
11
|
+
} & {
|
|
12
|
+
data: readonly import("../../index.js").ChartSlice[];
|
|
13
|
+
valueLabel?: string;
|
|
14
|
+
shareLabel?: string;
|
|
15
|
+
formatShare?: (share: number) => string;
|
|
16
|
+
showLegend?: boolean;
|
|
17
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { RadialChart as e } from "../Chart/RadialChart.js";
|
|
3
|
+
import { forwardRef as t } from "react";
|
|
4
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
5
|
+
// src/components/PieChart/PieChart.tsx
|
|
6
|
+
var r = t((t, r) => /* @__PURE__ */ n(e, {
|
|
7
|
+
...t,
|
|
8
|
+
ref: r,
|
|
9
|
+
innerRatio: 0
|
|
10
|
+
}));
|
|
11
|
+
r.displayName = "PieChart";
|
|
12
|
+
export { r as PieChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PieChart } from "./PieChart.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const Sparkline: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLSpanElement>, "children" | "color"> & {
|
|
2
|
+
data: readonly number[];
|
|
3
|
+
label: string;
|
|
4
|
+
color?: import("../../index.js").ChartColor;
|
|
5
|
+
area?: boolean;
|
|
6
|
+
height?: number;
|
|
7
|
+
} & import("react").RefAttributes<HTMLSpanElement>>;
|