@joniguerini/lume 0.0.0-stage → 1.9.1
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 +25 -0
- package/README.md +62 -2
- package/base.css +165 -0
- package/bin/lumeui.mjs +163 -0
- package/components/alert.css +156 -0
- package/components/banner.css +98 -0
- package/components/button.css +291 -0
- package/components/calendar.css +532 -0
- package/components/carousel.css +175 -0
- package/components/chart.css +813 -0
- package/components/chat.css +670 -0
- package/components/checkbox.css +212 -0
- package/components/chip.css +224 -0
- package/components/code.css +36 -0
- package/components/color-picker.css +192 -0
- package/components/command.css +148 -0
- package/components/content.css +211 -0
- package/components/editor.css +174 -0
- package/components/feedback.css +320 -0
- package/components/filters.css +103 -0
- package/components/form.css +455 -0
- package/components/image-viewer.css +237 -0
- package/components/layers.css +138 -0
- package/components/link.css +87 -0
- package/components/loading.css +260 -0
- package/components/menu.css +180 -0
- package/components/modal.css +209 -0
- package/components/navigation.css +507 -0
- package/components/notifications.css +186 -0
- package/components/number-field.css +52 -0
- package/components/otp.css +119 -0
- package/components/panel.css +208 -0
- package/components/picker.css +207 -0
- package/components/rating.css +143 -0
- package/components/resizable.css +173 -0
- package/components/scrollbar.css +110 -0
- package/components/select.css +477 -0
- package/components/shell.css +837 -0
- package/components/slider.css +189 -0
- package/components/sortable.css +287 -0
- package/components/surfaces.css +182 -0
- package/components/switch.css +115 -0
- package/components/table.css +228 -0
- package/components/tabs.css +190 -0
- package/components/tags.css +83 -0
- package/components/toast.css +164 -0
- package/components/toolbar.css +80 -0
- package/components/upload.css +181 -0
- package/ds.css +48 -0
- package/fonts/Geist-LICENSE.txt +92 -0
- package/fonts/Geist-Variable.woff2 +0 -0
- package/fonts/GeistSerif-Regular.woff2 +0 -0
- package/fonts/JetBrainsMono-LICENSE.txt +93 -0
- package/fonts/JetBrainsMono-Variable.woff2 +0 -0
- package/fonts.css +29 -0
- package/icons/icons.d.ts +5 -0
- package/icons/icons.js +266 -0
- package/js/back-to-top.d.ts +2 -0
- package/js/back-to-top.js +62 -0
- package/js/banner.js +87 -0
- package/js/calendar.d.ts +3 -0
- package/js/calendar.js +472 -0
- package/js/carousel.d.ts +2 -0
- package/js/carousel.js +258 -0
- package/js/charts/bar.js +361 -0
- package/js/charts/core.js +604 -0
- package/js/charts/donut.js +206 -0
- package/js/charts/figures.js +97 -0
- package/js/charts/heatmap.js +410 -0
- package/js/charts/line.js +268 -0
- package/js/charts/scatter.js +211 -0
- package/js/charts.d.ts +12 -0
- package/js/charts.js +27 -0
- package/js/code-block.d.ts +3 -0
- package/js/code-block.js +32 -0
- package/js/color-picker.d.ts +4 -0
- package/js/color-picker.js +448 -0
- package/js/command-palette.js +233 -0
- package/js/composer.js +573 -0
- package/js/context-menu.d.ts +2 -0
- package/js/context-menu.js +154 -0
- package/js/date-picker.d.ts +2 -0
- package/js/date-picker.js +430 -0
- package/js/drawer.js +48 -0
- package/js/editor.d.ts +5 -0
- package/js/editor.js +615 -0
- package/js/field-support.js +77 -0
- package/js/file-upload.d.ts +2 -0
- package/js/file-upload.js +230 -0
- package/js/filters.js +266 -0
- package/js/form.d.ts +2 -0
- package/js/form.js +409 -0
- package/js/i18n.d.ts +14 -0
- package/js/i18n.js +83 -0
- package/js/image-viewer.d.ts +4 -0
- package/js/image-viewer.js +275 -0
- package/js/menu.d.ts +4 -0
- package/js/menu.js +237 -0
- package/js/messages.js +908 -0
- package/js/modal.d.ts +7 -0
- package/js/modal.js +183 -0
- package/js/notifications.d.ts +4 -0
- package/js/notifications.js +204 -0
- package/js/number-field.d.ts +2 -0
- package/js/number-field.js +175 -0
- package/js/otp-field.d.ts +2 -0
- package/js/otp-field.js +107 -0
- package/js/pagination.d.ts +3 -0
- package/js/pagination.js +143 -0
- package/js/popover.d.ts +2 -0
- package/js/popover.js +155 -0
- package/js/progress-ring.js +48 -0
- package/js/rating.d.ts +3 -0
- package/js/rating.js +130 -0
- package/js/resizable.d.ts +2 -0
- package/js/resizable.js +311 -0
- package/js/scrollbar.d.ts +2 -0
- package/js/scrollbar.js +273 -0
- package/js/segmented.js +60 -0
- package/js/select.d.ts +3 -0
- package/js/select.js +784 -0
- package/js/shell.d.ts +6 -0
- package/js/shell.js +373 -0
- package/js/slider.d.ts +2 -0
- package/js/slider.js +89 -0
- package/js/sortable.d.ts +5 -0
- package/js/sortable.js +463 -0
- package/js/stepper.d.ts +2 -0
- package/js/stepper.js +72 -0
- package/js/tabs.js +99 -0
- package/js/tag-field.d.ts +2 -0
- package/js/tag-field.js +177 -0
- package/js/theme.d.ts +9 -0
- package/js/theme.js +114 -0
- package/js/time-picker.d.ts +2 -0
- package/js/time-picker.js +279 -0
- package/js/toast.d.ts +17 -0
- package/js/toast.js +171 -0
- package/js/toolbar.d.ts +2 -0
- package/js/toolbar.js +107 -0
- package/js/tooltip.d.ts +2 -0
- package/js/tooltip.js +208 -0
- package/js/tree.d.ts +2 -0
- package/js/tree.js +168 -0
- package/lume.css +11574 -0
- package/lume.d.ts +104 -0
- package/lume.js +67 -0
- package/package.json +66 -4
- package/react/Alert.d.ts +24 -0
- package/react/Alert.js +21 -0
- package/react/AppShell.d.ts +67 -0
- package/react/AppShell.js +94 -0
- package/react/Avatar.d.ts +39 -0
- package/react/Avatar.js +40 -0
- package/react/Badge.d.ts +17 -0
- package/react/Badge.js +10 -0
- package/react/Button.d.ts +32 -0
- package/react/Button.js +17 -0
- package/react/Calendar.d.ts +48 -0
- package/react/Calendar.js +67 -0
- package/react/Carousel.d.ts +30 -0
- package/react/Carousel.js +38 -0
- package/react/Charts.d.ts +186 -0
- package/react/Charts.js +58 -0
- package/react/Chip.d.ts +34 -0
- package/react/Chip.js +26 -0
- package/react/Choice.d.ts +72 -0
- package/react/Choice.js +51 -0
- package/react/ColorPicker.d.ts +43 -0
- package/react/ColorPicker.js +73 -0
- package/react/Content.d.ts +58 -0
- package/react/Content.js +42 -0
- package/react/Controls.d.ts +97 -0
- package/react/Controls.js +118 -0
- package/react/Editor.d.ts +28 -0
- package/react/Editor.js +57 -0
- package/react/Field.d.ts +90 -0
- package/react/Field.js +65 -0
- package/react/Form.d.ts +36 -0
- package/react/Form.js +45 -0
- package/react/Icon.d.ts +13 -0
- package/react/Icon.js +8 -0
- package/react/IconButton.d.ts +19 -0
- package/react/IconButton.js +12 -0
- package/react/ImageViewer.d.ts +20 -0
- package/react/ImageViewer.js +22 -0
- package/react/InlineAction.d.ts +15 -0
- package/react/InlineAction.js +12 -0
- package/react/Layers.d.ts +118 -0
- package/react/Layers.js +115 -0
- package/react/Link.d.ts +32 -0
- package/react/Link.js +26 -0
- package/react/Loading.d.ts +67 -0
- package/react/Loading.js +49 -0
- package/react/Navigation.d.ts +181 -0
- package/react/Navigation.js +197 -0
- package/react/Notices.d.ts +43 -0
- package/react/Notices.js +89 -0
- package/react/Panel.d.ts +57 -0
- package/react/Panel.js +33 -0
- package/react/Pickers.d.ts +83 -0
- package/react/Pickers.js +70 -0
- package/react/Rating.d.ts +39 -0
- package/react/Rating.js +41 -0
- package/react/Resizable.d.ts +44 -0
- package/react/Resizable.js +30 -0
- package/react/Select.d.ts +53 -0
- package/react/Select.js +79 -0
- package/react/Sortable.d.ts +52 -0
- package/react/Sortable.js +113 -0
- package/react/Table.d.ts +60 -0
- package/react/Table.js +34 -0
- package/react/Toolbar.d.ts +45 -0
- package/react/Toolbar.js +45 -0
- package/react/cx.d.ts +2 -0
- package/react/cx.js +5 -0
- package/react/icon-names.d.ts +1 -0
- package/react/icon-names.js +2 -0
- package/react/index.d.ts +42 -0
- package/react/index.js +52 -0
- package/react/useController.d.ts +8 -0
- package/react/useController.js +16 -0
- package/react/useLocale.d.ts +5 -0
- package/react/useLocale.js +15 -0
- package/tokens.css +739 -0
- package/tokens.js +4911 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lume — dispersão e bolhas.
|
|
3
|
+
*
|
|
4
|
+
* createScatterChart(host, {
|
|
5
|
+
* series: [{ name, color?, points: [{ x, y, size?, label? }] }], até 3 séries (todas as cores se tocam)
|
|
6
|
+
* x: { label, format, zero: false, reference, referenceLabel },
|
|
7
|
+
* y: { label, format, zero: false, reference, referenceLabel },
|
|
8
|
+
* size: { label, format, range: [4, 18] }, com `size` nos pontos, vira bolhas
|
|
9
|
+
* height, title, subtitle, label, card, table,
|
|
10
|
+
* }) → { update(options), setLoading(bool), destroy(), el }
|
|
11
|
+
*
|
|
12
|
+
* Pontos de 8 px com anel de 2 px da cor da superfície; o hover acha o ponto mais próximo
|
|
13
|
+
* (até 24 px), então ninguém precisa acertar o centro.
|
|
14
|
+
*/
|
|
15
|
+
import { createFrame, paint, formatter, axisFormatter, niceTicks, linear, textWidth, tag, escapeHtml, yAxis, xAxis, round, FONTS } from './core.js';
|
|
16
|
+
import { msg } from '../i18n.js';
|
|
17
|
+
|
|
18
|
+
const HIT = 24;
|
|
19
|
+
let warned = false;
|
|
20
|
+
|
|
21
|
+
export function createScatterChart(host, input) {
|
|
22
|
+
let source = input;
|
|
23
|
+
let o = normalize(source);
|
|
24
|
+
const hidden = new Set();
|
|
25
|
+
const frame = createFrame(host, o, { kind: 'scatter' });
|
|
26
|
+
let geo = null;
|
|
27
|
+
|
|
28
|
+
function normalize(opts) {
|
|
29
|
+
const series = (opts.series ?? []).map((s, i) => ({ ...s, index: i, paint: paint(s.color, i), points: (s.points ?? []).filter((p) => Number.isFinite(+p.x) && Number.isFinite(+p.y)) }));
|
|
30
|
+
if (series.length > 3 && !warned) {
|
|
31
|
+
warned = true;
|
|
32
|
+
console.warn(`[Lume] ${msg('chart.scatterTooManySeries')}`);
|
|
33
|
+
}
|
|
34
|
+
return { height: 320, x: {}, y: {}, ...opts, series };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const visible = () => o.series.filter((s) => !hidden.has(s.index));
|
|
38
|
+
|
|
39
|
+
function legend() {
|
|
40
|
+
if (o.series.length < 2) return frame.setLegend([]);
|
|
41
|
+
frame.setLegend(
|
|
42
|
+
o.series.map((s) => ({ name: s.name, color: s.paint, mark: 'dot', hidden: hidden.has(s.index) })),
|
|
43
|
+
(i) => {
|
|
44
|
+
if (hidden.has(i)) hidden.delete(i);
|
|
45
|
+
else if (visible().length > 1) hidden.add(i);
|
|
46
|
+
legend();
|
|
47
|
+
render();
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function render() {
|
|
53
|
+
const W = frame.width;
|
|
54
|
+
if (!W) return;
|
|
55
|
+
const vs = visible();
|
|
56
|
+
const pts = vs.flatMap((s) => s.points.map((p) => ({ ...p, x: +p.x, y: +p.y, s })));
|
|
57
|
+
if (!pts.length) {
|
|
58
|
+
geo = null;
|
|
59
|
+
frame.empty();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const fx = formatter(o.x.format);
|
|
63
|
+
const fy = formatter(o.y.format);
|
|
64
|
+
const ax = axisFormatter(o.x.format, o.x.axisFormat);
|
|
65
|
+
const ay = axisFormatter(o.y.format, o.y.axisFormat);
|
|
66
|
+
const bubbles = pts.some((p) => p.size != null);
|
|
67
|
+
const [r0, r1] = o.size?.range ?? [4, 18];
|
|
68
|
+
const sizes = pts.map((p) => +p.size || 0);
|
|
69
|
+
const smax = Math.max(...sizes, 1);
|
|
70
|
+
let rMax = r1;
|
|
71
|
+
const radius = (p) => (bubbles ? r0 + (rMax - r0) * Math.sqrt((+p.size || 0) / smax) : 4);
|
|
72
|
+
|
|
73
|
+
const ext = (key, axis) => {
|
|
74
|
+
const vals = pts.map((p) => p[key]);
|
|
75
|
+
if (axis.reference != null) vals.push(axis.reference);
|
|
76
|
+
let lo = Math.min(...vals);
|
|
77
|
+
let hi = Math.max(...vals);
|
|
78
|
+
if (axis.zero) {
|
|
79
|
+
lo = Math.min(0, lo);
|
|
80
|
+
hi = Math.max(0, hi);
|
|
81
|
+
}
|
|
82
|
+
const pad = (hi - lo || 1) * 0.04;
|
|
83
|
+
return [axis.zero && lo >= 0 ? lo : lo - pad, hi + pad];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const H = o.height;
|
|
87
|
+
const top = o.y.label ? 26 : 12;
|
|
88
|
+
const bottom = o.x.label ? 48 : 28;
|
|
89
|
+
const plotH = Math.max(60, H - top - bottom);
|
|
90
|
+
const yt = niceTicks(...ext('y', o.y), Math.max(2, Math.round(plotH / 56)));
|
|
91
|
+
const left = Math.ceil(Math.max(...yt.ticks.map((t) => textWidth(ay(t))))) + 14;
|
|
92
|
+
const right = 16;
|
|
93
|
+
const plotW = Math.max(60, W - left - right);
|
|
94
|
+
// Em telas estreitas as bolhas encolhem junto, para a nuvem não virar uma mancha.
|
|
95
|
+
rMax = Math.max(r0 + 4, Math.min(r1, plotW / 22));
|
|
96
|
+
const xt = niceTicks(...ext('x', o.x), Math.max(2, Math.round(plotW / 90)));
|
|
97
|
+
const x = linear(xt.min, xt.max, left, left + plotW);
|
|
98
|
+
const y = linear(yt.min, yt.max, top + plotH, top);
|
|
99
|
+
|
|
100
|
+
let svg = yAxis({ ticks: yt.ticks, y, left, right: left + plotW, format: ay, baseline: yt.min });
|
|
101
|
+
svg += xAxis({ ticks: xt.ticks, x, top, bottom: top + plotH, format: ax, baseline: xt.min });
|
|
102
|
+
if (o.y.label) svg += tag('text', { x: left - 14, y: 10, class: 'ds-chart__axis-label' }, escapeHtml(o.y.label));
|
|
103
|
+
if (o.x.label) svg += tag('text', { x: left + plotW, y: H - 6, class: 'ds-chart__axis-label', 'text-anchor': 'end' }, escapeHtml(o.x.label));
|
|
104
|
+
|
|
105
|
+
// referências (mediana, meta): tracejado = limite, nunca grade
|
|
106
|
+
if (o.x.reference != null) {
|
|
107
|
+
const px = round(Math.round(x(o.x.reference)) + 0.5, 1);
|
|
108
|
+
svg += tag('line', { x1: px, x2: px, y1: top, y2: top + plotH, class: 'ds-chart__target' });
|
|
109
|
+
if (o.x.referenceLabel) svg += tag('text', { x: px + 6, y: top + 12, class: 'ds-chart__target-label' }, escapeHtml(o.x.referenceLabel));
|
|
110
|
+
}
|
|
111
|
+
if (o.y.reference != null) {
|
|
112
|
+
const py = round(Math.round(y(o.y.reference)) + 0.5, 1);
|
|
113
|
+
svg += tag('line', { x1: left, x2: left + plotW, y1: py, y2: py, class: 'ds-chart__target' });
|
|
114
|
+
if (o.y.referenceLabel) svg += tag('text', { x: left + plotW - 4, y: py - 7, class: 'ds-chart__target-label', 'text-anchor': 'end' }, escapeHtml(o.y.referenceLabel));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const placed = pts.map((p, i) => ({ ...p, i, px: x(p.x), py: y(p.y), r: radius(p) }));
|
|
118
|
+
// maiores atrás, para as pequenas não sumirem
|
|
119
|
+
const drawOrder = [...placed].sort((a, b) => b.r - a.r);
|
|
120
|
+
svg += drawOrder
|
|
121
|
+
.map((p) => tag('circle', { cx: round(p.px), cy: round(p.py), r: round(p.r), class: `ds-chart__dot${bubbles ? ' ds-chart__dot--bubble' : ''}`, 'data-i': p.i, style: `--c:${p.s.paint};--d:${Math.min(p.i, 40) * 10}ms` }))
|
|
122
|
+
.join('');
|
|
123
|
+
// rótulos seletivos: só nos pontos marcados com `label`
|
|
124
|
+
svg += placed
|
|
125
|
+
.filter((p) => p.label && p.showLabel !== false)
|
|
126
|
+
.map((p) => {
|
|
127
|
+
const w = textWidth(p.label, FONTS.label);
|
|
128
|
+
const toLeft = p.px + p.r + 6 + w > left + plotW;
|
|
129
|
+
return tag('text', { x: toLeft ? p.px - p.r - 6 : p.px + p.r + 6, y: p.py, class: 'ds-chart__label', 'text-anchor': toLeft ? 'end' : 'start', 'dominant-baseline': 'middle' }, escapeHtml(p.label));
|
|
130
|
+
})
|
|
131
|
+
.join('');
|
|
132
|
+
svg += tag('circle', { class: 'ds-chart__point-ring', 'data-ring': '', cx: 0, cy: 0, r: 0 });
|
|
133
|
+
|
|
134
|
+
frame.plot.innerHTML = `<svg class="ds-chart__svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" aria-hidden="true">${svg}</svg>`;
|
|
135
|
+
const byX = [...placed].sort((a, b) => a.px - b.px || a.py - b.py);
|
|
136
|
+
geo = { placed, byX, fx, fy };
|
|
137
|
+
|
|
138
|
+
const fs = formatter(o.size?.format);
|
|
139
|
+
frame.setTable({
|
|
140
|
+
columns: [{ label: o.pointLabel ?? msg('chart.point') }, ...(o.series.length > 1 ? [{ label: msg('chart.series') }] : []), { label: o.x.label ?? 'x', num: true }, { label: o.y.label ?? 'y', num: true }, ...(bubbles ? [{ label: o.size?.label ?? 'Tamanho', num: true }] : [])],
|
|
141
|
+
rows: o.series.flatMap((s) =>
|
|
142
|
+
s.points.map((p, k) => [p.label ?? `${s.name ?? msg('chart.point')} ${k + 1}`, ...(o.series.length > 1 ? [s.name ?? ''] : []), fx(+p.x), fy(+p.y), ...(bubbles ? [p.size == null ? '—' : fs(+p.size)] : [])]),
|
|
143
|
+
),
|
|
144
|
+
});
|
|
145
|
+
frame.refresh();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
frame.interact({
|
|
149
|
+
count: () => (geo ? geo.byX.length : 0),
|
|
150
|
+
hit(px, py) {
|
|
151
|
+
if (!geo) return null;
|
|
152
|
+
let best = null;
|
|
153
|
+
let bestD = Infinity;
|
|
154
|
+
geo.byX.forEach((p, k) => {
|
|
155
|
+
const d = Math.hypot(p.px - px, p.py - py) - (p.r - 4);
|
|
156
|
+
if (d < bestD) {
|
|
157
|
+
bestD = d;
|
|
158
|
+
best = k;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return bestD <= HIT ? best : null;
|
|
162
|
+
},
|
|
163
|
+
anchor: (k) => ({ x: geo.byX[k].px, y: geo.byX[k].py - geo.byX[k].r }),
|
|
164
|
+
highlight(k) {
|
|
165
|
+
const ring = frame.plot.querySelector('[data-ring]');
|
|
166
|
+
if (!ring) return;
|
|
167
|
+
frame.plot.querySelectorAll('.ds-chart__dot[data-active]').forEach((el) => el.removeAttribute('data-active'));
|
|
168
|
+
if (k == null || !geo) return ring.setAttribute('r', 0);
|
|
169
|
+
const p = geo.byX[k];
|
|
170
|
+
ring.setAttribute('cx', round(p.px));
|
|
171
|
+
ring.setAttribute('cy', round(p.py));
|
|
172
|
+
ring.setAttribute('r', round(p.r + 4));
|
|
173
|
+
ring.style.setProperty('--c', p.s.paint);
|
|
174
|
+
frame.plot.querySelector(`.ds-chart__dot[data-i="${p.i}"]`)?.setAttribute('data-active', '');
|
|
175
|
+
},
|
|
176
|
+
describe(k) {
|
|
177
|
+
const p = geo.byX[k];
|
|
178
|
+
const rows = [
|
|
179
|
+
{ value: geo.fx(p.x), name: o.x.label ?? 'x' },
|
|
180
|
+
{ value: geo.fy(p.y), name: o.y.label ?? 'y' },
|
|
181
|
+
];
|
|
182
|
+
if (p.size != null) rows.push({ value: formatter(o.size?.format)(+p.size), name: o.size?.label ?? 'Tamanho' });
|
|
183
|
+
return { title: p.label ?? p.s.name ?? msg('chart.point'), rows, note: p.label && o.series.length > 1 ? p.s.name : undefined };
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
function summary() {
|
|
188
|
+
const n = o.series.reduce((a, s) => a + s.points.length, 0);
|
|
189
|
+
return msg('chart.summaryScatter', o.title ?? o.label ?? msg('chart.chart'), n);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
frame.setLabel(summary());
|
|
193
|
+
frame.onResize(render);
|
|
194
|
+
legend();
|
|
195
|
+
render();
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
el: frame.figure,
|
|
199
|
+
update(next) {
|
|
200
|
+
source = { ...source, ...next };
|
|
201
|
+
o = normalize(source);
|
|
202
|
+
[...hidden].forEach((i) => i >= o.series.length && hidden.delete(i));
|
|
203
|
+
frame.setHead(o);
|
|
204
|
+
frame.setLabel(summary());
|
|
205
|
+
legend();
|
|
206
|
+
render();
|
|
207
|
+
},
|
|
208
|
+
setLoading: frame.setLoading,
|
|
209
|
+
destroy: frame.destroy,
|
|
210
|
+
};
|
|
211
|
+
}
|
package/js/charts.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
type Chart = { update(options: any): void; setLoading(on: boolean): void; destroy(): void; el: HTMLElement };
|
|
3
|
+
export declare function createBarChart(host: HTMLElement, options: any): Chart;
|
|
4
|
+
export declare function createLineChart(host: HTMLElement, options: any): Chart;
|
|
5
|
+
export declare function createDonutChart(host: HTMLElement, options: any): Chart;
|
|
6
|
+
export declare function createHeatmap(host: HTMLElement, options: any): Chart;
|
|
7
|
+
export declare function createCalendarHeatmap(host: HTMLElement, options: any): Chart;
|
|
8
|
+
export declare function createScatterChart(host: HTMLElement, options: any): Chart;
|
|
9
|
+
export declare function sparklineHtml(values: number[], options?: Record<string, unknown>): string;
|
|
10
|
+
export declare function statTileHtml(options: Record<string, unknown>): string;
|
|
11
|
+
export declare function meterHtml(options: Record<string, unknown>): string;
|
|
12
|
+
export declare function chartFormatter(format?: unknown): (value: number) => string;
|
package/js/charts.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lume — gráficos.
|
|
3
|
+
*
|
|
4
|
+
* import { createBarChart, createLineChart, createDonutChart, createHeatmap, createCalendarHeatmap, createScatterChart,
|
|
5
|
+
* sparklineHtml, statTileHtml, meterHtml } from './ds/js/charts.js';
|
|
6
|
+
*
|
|
7
|
+
* const chart = createBarChart(document.querySelector('#vendas'), {
|
|
8
|
+
* title: 'Vendas por mês',
|
|
9
|
+
* categories: ['Jan', 'Fev', 'Mar'],
|
|
10
|
+
* series: [{ name: 'Loja', values: [120, 180, 150] }],
|
|
11
|
+
* format: 'currency',
|
|
12
|
+
* });
|
|
13
|
+
* chart.update({ series: [...] }); // mesma API em todos
|
|
14
|
+
* chart.destroy();
|
|
15
|
+
*
|
|
16
|
+
* Todo gráfico desenha em SVG puro, segue o tema (cores são tokens), tem tooltip no hover e no
|
|
17
|
+
* teclado (setas), legenda que esconde séries sem repintar as outras e uma vista em tabela.
|
|
18
|
+
*/
|
|
19
|
+
export { createBarChart } from './charts/bar.js';
|
|
20
|
+
export { createLineChart } from './charts/line.js';
|
|
21
|
+
export { createDonutChart } from './charts/donut.js';
|
|
22
|
+
export { createHeatmap, createCalendarHeatmap } from './charts/heatmap.js';
|
|
23
|
+
export { createScatterChart } from './charts/scatter.js';
|
|
24
|
+
export { sparklineHtml, statTileHtml, meterHtml } from './charts/figures.js';
|
|
25
|
+
import { formatter as chartFormatter } from './charts/core.js';
|
|
26
|
+
|
|
27
|
+
export { chartFormatter };
|
package/js/code-block.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bloco de código com botão de copiar.
|
|
3
|
+
*
|
|
4
|
+
* <div class="ds-code-block">
|
|
5
|
+
* <pre class="ds-code"><code>npm run build</code></pre>
|
|
6
|
+
* <button type="button" class="ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted ds-code-block__copy" data-code-copy aria-label="Copiar código"></button>
|
|
7
|
+
* </div>
|
|
8
|
+
*
|
|
9
|
+
* const stop = mountCodeBlocks(document); // liga todos os botões [data-code-copy] dentro do elemento
|
|
10
|
+
*
|
|
11
|
+
* codeBlockHtml(codigo) devolve esse HTML pronto, com o código já escapado e o nome do botão no idioma atual.
|
|
12
|
+
* Ao copiar, um aviso confirma; o texto do código não é repetido no aviso.
|
|
13
|
+
*/
|
|
14
|
+
import { icon } from '../icons/icons.js';
|
|
15
|
+
import { msg } from './i18n.js';
|
|
16
|
+
import { copyText } from './toast.js';
|
|
17
|
+
|
|
18
|
+
const escape = (s) => String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
19
|
+
|
|
20
|
+
export const codeBlockHtml = (code, { small = false } = {}) => `<div class="ds-code-block">
|
|
21
|
+
<pre class="ds-code${small ? ' ds-code--sm' : ''}"><code>${escape(code)}</code></pre>
|
|
22
|
+
<button type="button" class="ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted ds-code-block__copy" data-code-copy aria-label="${escape(msg('code.copy'))}" data-ds-tooltip="${escape(msg('code.copy'))}">${icon('copy', { size: 16 })}</button>
|
|
23
|
+
</div>`;
|
|
24
|
+
|
|
25
|
+
export function mountCodeBlocks(root = document) {
|
|
26
|
+
const onClick = (event) => {
|
|
27
|
+
const btn = event.target.closest('[data-code-copy]');
|
|
28
|
+
if (btn) copyText(btn.closest('.ds-code-block').querySelector('code').textContent, msg('code.copied'), { echo: false });
|
|
29
|
+
};
|
|
30
|
+
root.addEventListener('click', onClick);
|
|
31
|
+
return () => root.removeEventListener('click', onClick);
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
export declare function parseHex(text: string): string | null;
|
|
3
|
+
export declare function createColorPicker(root: HTMLElement, options?: Record<string, unknown>): { value: string; setValue(value: string | null): void; setSwatches(list: unknown[]): void; focus(): void; destroy(): void };
|
|
4
|
+
export declare function createColorField(input: HTMLInputElement, options?: Record<string, unknown>): { value: string | null; setValue(value: string | null): void; open(): void; close(): void; destroy(): void };
|