@asanchez-sa/abby 0.4.0 → 0.5.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.
@@ -1,278 +0,0 @@
1
- "use client";
2
- import { cn } from "../../../utilities/cn/index.js";
3
- import { ChartGrid, ChartXAxis, ChartYAxis } from "./axes.js";
4
- import { ChartTooltip, useChartTooltip } from "./points.js";
5
- import { labelIndices, plotScale, rowId, valueFormatter } from "./scale.js";
6
- import { ChartTable } from "./table.js";
7
- import { defaultTexts } from "./types.js";
8
- import { c } from "react/compiler-runtime";
9
- import { useState } from "react";
10
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
- // src/components/chart/parts/frame.tsx
12
- /**
13
- * Whether the app was built for production. A bundler replaces
14
- * `process.env.NODE_ENV` with a string; where nothing does and `process`
15
- * doesn't exist (a browser loading the module as is), reading it throws and
16
- * the chart counts as in development. Read once, never during render.
17
- */
18
- const production = (() => {
19
- try {
20
- return process.env.NODE_ENV === "production";
21
- } catch {
22
- return false;
23
- }
24
- })();
25
- /** The width of an element in px, kept up to date as it resizes. */
26
- function useWidth() {
27
- const $ = c(4);
28
- const [width, setWidth] = useState(0);
29
- let t0;
30
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31
- t0 = () => (node) => {
32
- if (!node) return;
33
- setWidth(node.getBoundingClientRect().width);
34
- if (typeof ResizeObserver === "undefined") return;
35
- const observer = new ResizeObserver(() => setWidth(node.getBoundingClientRect().width));
36
- observer.observe(node);
37
- return () => observer.disconnect();
38
- };
39
- $[0] = t0;
40
- } else t0 = $[0];
41
- const [ref] = useState(t0);
42
- let t1;
43
- if ($[1] !== ref || $[2] !== width) {
44
- t1 = {
45
- width,
46
- ref
47
- };
48
- $[1] = ref;
49
- $[2] = width;
50
- $[3] = t1;
51
- } else t1 = $[3];
52
- return t1;
53
- }
54
- function ChartFrame(t0) {
55
- const $ = c(45);
56
- let children;
57
- let className;
58
- let data;
59
- let domain;
60
- let format;
61
- let highlight;
62
- let locale;
63
- let max;
64
- let name;
65
- let series;
66
- let t1;
67
- let t10;
68
- let t11;
69
- let t12;
70
- let t13;
71
- let t2;
72
- let t3;
73
- let t4;
74
- let t5;
75
- let t6;
76
- let t7;
77
- let t8;
78
- let t9;
79
- if ($[0] !== t0) {
80
- ({data, series, highlight, height: t1, yAxis: t2, xAxis: t3, grid: t4, format, locale, maxLabels: t5, labels: t6, max, empty: t7, categoryHeader: t8, missing: t9, totalHeader: t10, stack: t11, room: t12, bottom: t13, domain, className, children, ...name} = t0);
81
- $[0] = t0;
82
- $[1] = children;
83
- $[2] = className;
84
- $[3] = data;
85
- $[4] = domain;
86
- $[5] = format;
87
- $[6] = highlight;
88
- $[7] = locale;
89
- $[8] = max;
90
- $[9] = name;
91
- $[10] = series;
92
- $[11] = t1;
93
- $[12] = t10;
94
- $[13] = t11;
95
- $[14] = t12;
96
- $[15] = t13;
97
- $[16] = t2;
98
- $[17] = t3;
99
- $[18] = t4;
100
- $[19] = t5;
101
- $[20] = t6;
102
- $[21] = t7;
103
- $[22] = t8;
104
- $[23] = t9;
105
- } else {
106
- children = $[1];
107
- className = $[2];
108
- data = $[3];
109
- domain = $[4];
110
- format = $[5];
111
- highlight = $[6];
112
- locale = $[7];
113
- max = $[8];
114
- name = $[9];
115
- series = $[10];
116
- t1 = $[11];
117
- t10 = $[12];
118
- t11 = $[13];
119
- t12 = $[14];
120
- t13 = $[15];
121
- t2 = $[16];
122
- t3 = $[17];
123
- t4 = $[18];
124
- t5 = $[19];
125
- t6 = $[20];
126
- t7 = $[21];
127
- t8 = $[22];
128
- t9 = $[23];
129
- }
130
- const height = t1 === void 0 ? 96 : t1;
131
- const yAxis = t2 === void 0 ? true : t2;
132
- const xAxis = t3 === void 0 ? true : t3;
133
- const grid = t4 === void 0 ? true : t4;
134
- const maxLabels = t5 === void 0 ? 8 : t5;
135
- const labels = t6 === void 0 ? "auto" : t6;
136
- const empty = t7 === void 0 ? defaultTexts.empty : t7;
137
- const categoryHeader = t8 === void 0 ? defaultTexts.categoryHeader : t8;
138
- const missing = t9 === void 0 ? defaultTexts.missing : t9;
139
- const totalHeader = t10 === void 0 ? defaultTexts.totalHeader : t10;
140
- const stack = t11 === void 0 ? false : t11;
141
- const room = t12 === void 0 ? 0 : t12;
142
- const bottom = t13 === void 0 ? 0 : t13;
143
- if (!production && !name["aria-label"] && !name["aria-labelledby"]) throw new Error("A chart needs a name: pass aria-label or aria-labelledby");
144
- const tooltip = useChartTooltip();
145
- const plot = plotScale(data, series, height, max, {
146
- stack,
147
- room,
148
- bottom,
149
- domain
150
- });
151
- const { width, ref } = useWidth();
152
- const text = valueFormatter(locale, format);
153
- const show = (value) => text(value, missing);
154
- const highlighted = highlight === void 0 ? -1 : data.findIndex((row) => rowId(row) === highlight);
155
- const shown = labels === "ends" ? Array.from(/* @__PURE__ */ new Set([
156
- 0,
157
- data.length - 1,
158
- ...highlighted >= 0 ? [highlighted] : []
159
- ])).sort(_temp) : labelIndices(data.length, maxLabels, highlighted);
160
- const t14 = name["aria-label"];
161
- const t15 = name["aria-labelledby"];
162
- let t16;
163
- if ($[24] !== t14 || $[25] !== t15) {
164
- t16 = {
165
- "aria-label": t14,
166
- "aria-labelledby": t15
167
- };
168
- $[24] = t14;
169
- $[25] = t15;
170
- $[26] = t16;
171
- } else t16 = $[26];
172
- const labelled = t16;
173
- const t17 = "group";
174
- const t18 = "chart";
175
- let t19;
176
- if ($[27] !== className) {
177
- t19 = cn("flex w-full min-w-0 flex-col gap-1.5", className);
178
- $[27] = className;
179
- $[28] = t19;
180
- } else t19 = $[28];
181
- const t20 = data.length === 0 ? /* @__PURE__ */ jsx("div", {
182
- "data-slot": "chart-empty",
183
- className: "flex items-center justify-center text-sm text-muted-foreground",
184
- style: { height },
185
- children: empty
186
- }) : /* @__PURE__ */ jsxs("div", {
187
- className: "grid grid-cols-[auto_minmax(0,1fr)]",
188
- children: [
189
- yAxis ? /* @__PURE__ */ jsx(ChartYAxis, {
190
- plot,
191
- format: (value_0) => text(value_0, "")
192
- }) : /* @__PURE__ */ jsx("div", {}),
193
- /* @__PURE__ */ jsxs("svg", {
194
- ref,
195
- "data-slot": "chart-plot",
196
- width: "100%",
197
- height,
198
- className: "block overflow-visible",
199
- children: [grid ? /* @__PURE__ */ jsx(ChartGrid, { plot }) : /* @__PURE__ */ jsx("line", {
200
- "aria-hidden": "true",
201
- x1: "0",
202
- x2: "100%",
203
- y1: plot.baseline + .5,
204
- y2: plot.baseline + .5,
205
- className: "stroke-border",
206
- shapeRendering: "crispEdges"
207
- }), children({
208
- plot,
209
- tooltip,
210
- text: show,
211
- highlighted,
212
- width
213
- })]
214
- }),
215
- xAxis ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {}), /* @__PURE__ */ jsx(ChartXAxis, {
216
- labels: data.map(_temp2),
217
- count: data.length,
218
- shown,
219
- highlighted
220
- })] }) : null
221
- ]
222
- });
223
- const t21 = stack ? totalHeader : void 0;
224
- let t22;
225
- if ($[29] !== categoryHeader || $[30] !== data || $[31] !== labelled || $[32] !== missing || $[33] !== series || $[34] !== t21 || $[35] !== text) {
226
- t22 = /* @__PURE__ */ jsx(ChartTable, {
227
- rows: data,
228
- series,
229
- categoryHeader,
230
- missing,
231
- format: text,
232
- name: labelled,
233
- totalHeader: t21
234
- });
235
- $[29] = categoryHeader;
236
- $[30] = data;
237
- $[31] = labelled;
238
- $[32] = missing;
239
- $[33] = series;
240
- $[34] = t21;
241
- $[35] = text;
242
- $[36] = t22;
243
- } else t22 = $[36];
244
- let t23;
245
- if ($[37] !== tooltip) {
246
- t23 = /* @__PURE__ */ jsx(ChartTooltip, { controller: tooltip });
247
- $[37] = tooltip;
248
- $[38] = t23;
249
- } else t23 = $[38];
250
- let t24;
251
- if ($[39] !== labelled || $[40] !== t19 || $[41] !== t20 || $[42] !== t22 || $[43] !== t23) {
252
- t24 = /* @__PURE__ */ jsxs("div", {
253
- role: t17,
254
- "data-slot": t18,
255
- className: t19,
256
- ...labelled,
257
- children: [
258
- t20,
259
- t22,
260
- t23
261
- ]
262
- });
263
- $[39] = labelled;
264
- $[40] = t19;
265
- $[41] = t20;
266
- $[42] = t22;
267
- $[43] = t23;
268
- $[44] = t24;
269
- } else t24 = $[44];
270
- return t24;
271
- }
272
- function _temp2(row_0) {
273
- return row_0.label;
274
- }
275
- function _temp(a, b) {
276
- return a - b;
277
- }
278
- export { ChartFrame };
@@ -1 +0,0 @@
1
- import { ReactNode } from "react";
@@ -1,139 +0,0 @@
1
- "use client";
2
- import { Tooltip as Tooltip$1, TooltipContent as TooltipContent$1 } from "../../tooltip/tooltip.js";
3
- import { cn } from "../../../utilities/cn/index.js";
4
- import { c } from "react/compiler-runtime";
5
- import { useState } from "react";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- import { TooltipTrigger, createTooltipController } from "@ui-sdk/react/tooltip";
8
- // src/components/chart/parts/points.tsx
9
- /** The controller of the chart's one tooltip. */
10
- function useChartTooltip() {
11
- const [tooltip] = useState(_temp);
12
- return tooltip;
13
- }
14
- /**
15
- * The chart has one tab stop: the active point takes `tabIndex` 0 and the
16
- * others -1. Arrows, Home and End move focus to another point; focusing one
17
- * (by click too) makes it the active. The chart isn't mirrored right to left
18
- * (a time axis keeps its direction), so the arrows follow the screen there
19
- * too: ArrowRight goes to the point on the right.
20
- */
21
- function _temp() {
22
- return createTooltipController();
23
- }
24
- function useRovingPoints(count) {
25
- const $ = c(3);
26
- const [chosen, setChosen] = useState(0);
27
- const active = Math.min(chosen, Math.max(0, count - 1));
28
- let t0;
29
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30
- t0 = function onKeyDown(event) {
31
- const points = Array.from(event.currentTarget.querySelectorAll("[data-chart-point]"));
32
- const current = points.indexOf(event.target);
33
- if (current < 0 || points.length === 0) return;
34
- const next = event.key === "ArrowRight" ? current + 1 : event.key === "ArrowLeft" ? current - 1 : event.key === "Home" ? 0 : event.key === "End" ? points.length - 1 : null;
35
- if (next === null) return;
36
- event.preventDefault();
37
- points[Math.min(points.length - 1, Math.max(0, next))]?.focus();
38
- };
39
- $[0] = t0;
40
- } else t0 = $[0];
41
- const onKeyDown = t0;
42
- let t1;
43
- if ($[1] !== active) {
44
- t1 = {
45
- active,
46
- setChosen,
47
- onKeyDown
48
- };
49
- $[1] = active;
50
- $[2] = t1;
51
- } else t1 = $[2];
52
- return t1;
53
- }
54
- /**
55
- * The transparent area of one mark that takes the pointer and the focus. The
56
- * mark is drawn under it, so a bar of zero height can still be reached. It is
57
- * an image for a screen reader, named "category: value".
58
- */
59
- function ChartPoint(t0) {
60
- const $ = c(14);
61
- const { controller, index, active, onActivate, label, x, width, height } = t0;
62
- let t1;
63
- if ($[0] !== height || $[1] !== width || $[2] !== x) {
64
- t1 = /* @__PURE__ */ jsx("rect", {
65
- x,
66
- y: 0,
67
- width,
68
- height,
69
- strokeWidth: 1
70
- });
71
- $[0] = height;
72
- $[1] = width;
73
- $[2] = x;
74
- $[3] = t1;
75
- } else t1 = $[3];
76
- const t2 = index === active ? 0 : -1;
77
- let t3;
78
- if ($[4] !== index || $[5] !== onActivate) {
79
- t3 = () => onActivate(index);
80
- $[4] = index;
81
- $[5] = onActivate;
82
- $[6] = t3;
83
- } else t3 = $[6];
84
- let t4;
85
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
86
- t4 = cn("cursor-default fill-transparent outline-none transition-colors hover:fill-accent focus-visible:fill-accent motion-reduce:transition-none", "focus-visible:stroke-(--focus-ring,var(--ring))");
87
- $[7] = t4;
88
- } else t4 = $[7];
89
- let t5;
90
- if ($[8] !== controller || $[9] !== label || $[10] !== t1 || $[11] !== t2 || $[12] !== t3) {
91
- t5 = /* @__PURE__ */ jsx(TooltipTrigger, {
92
- controller,
93
- payload: label,
94
- render: t1,
95
- role: "img",
96
- "aria-label": label,
97
- tabIndex: t2,
98
- "data-chart-point": "",
99
- "data-agent-hidden": "",
100
- onFocus: t3,
101
- className: t4
102
- });
103
- $[8] = controller;
104
- $[9] = label;
105
- $[10] = t1;
106
- $[11] = t2;
107
- $[12] = t3;
108
- $[13] = t5;
109
- } else t5 = $[13];
110
- return t5;
111
- }
112
- /** The one tooltip, showing the payload of the point that opened it. */
113
- function ChartTooltip(t0) {
114
- const $ = c(4);
115
- const { controller, children } = t0;
116
- let t1;
117
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
118
- t1 = /* @__PURE__ */ jsx(TooltipContent$1, {
119
- "data-agent-hidden": "",
120
- children: _temp2
121
- });
122
- $[0] = t1;
123
- } else t1 = $[0];
124
- let t2;
125
- if ($[1] !== children || $[2] !== controller) {
126
- t2 = /* @__PURE__ */ jsxs(Tooltip$1, {
127
- controller,
128
- children: [t1, children]
129
- });
130
- $[1] = children;
131
- $[2] = controller;
132
- $[3] = t2;
133
- } else t2 = $[3];
134
- return t2;
135
- }
136
- function _temp2(state) {
137
- return state.payload ?? "";
138
- }
139
- export { ChartPoint, ChartTooltip, useChartTooltip, useRovingPoints };