@voidable/ui 0.10.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/dist/base.d.ts +6 -0
- package/dist/base.js +2 -2
- package/dist/chunks/{base-BxmMM3B7.js → base-BGrS4eIl.js} +9 -0
- package/dist/chunks/data-BpiiNapL.js +95 -0
- package/dist/chunks/{modal-CgGp_fCs.js → modal-DWGkNdNG.js} +2 -2
- package/dist/chunks/{overlay-hLJ7IQHx.js → overlay-CH7L4N-h.js} +1 -1
- package/dist/chunks/{projection-SnR79EHI.js → projection-oPe6ipjL.js} +1 -1
- package/dist/components/accordion.js +1 -1
- package/dist/components/action-input.js +2 -2
- package/dist/components/alert.d.ts +11 -0
- package/dist/components/alert.js +10 -3
- package/dist/components/avatar.js +2 -2
- package/dist/components/badge.d.ts +8 -2
- package/dist/components/badge.js +1 -4
- package/dist/components/banner.d.ts +9 -0
- package/dist/components/banner.js +10 -3
- package/dist/components/bar-chart.d.ts +21 -7
- package/dist/components/bar-chart.js +65 -43
- package/dist/components/breadcrumbs.js +1 -1
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +40 -2
- package/dist/components/calendar.js +110 -21
- package/dist/components/card.js +1 -1
- package/dist/components/carousel.js +3 -3
- package/dist/components/charts/data.d.ts +72 -0
- package/dist/components/checkbox-group.js +2 -2
- package/dist/components/checkbox.js +2 -2
- package/dist/components/collapsible.js +1 -1
- package/dist/components/color-picker.js +2 -2
- package/dist/components/combobox.js +3 -3
- package/dist/components/compose-input.js +2 -2
- package/dist/components/dialog.js +1 -1
- package/dist/components/divider.js +2 -2
- package/dist/components/donut-chart.d.ts +22 -6
- package/dist/components/donut-chart.js +95 -69
- package/dist/components/drawer.js +1 -1
- package/dist/components/dropdown-menu.js +2 -2
- package/dist/components/editable.js +2 -2
- package/dist/components/error-fallback.js +1 -1
- package/dist/components/field.js +2 -2
- package/dist/components/file-upload.d.ts +20 -5
- package/dist/components/file-upload.js +51 -21
- package/dist/components/gauge.d.ts +32 -8
- package/dist/components/gauge.js +202 -130
- package/dist/components/hamburger.d.ts +12 -1
- package/dist/components/hamburger.js +24 -13
- package/dist/components/hover-card.js +2 -2
- package/dist/components/indicator.js +2 -2
- package/dist/components/input.js +2 -2
- package/dist/components/line-chart.d.ts +22 -7
- package/dist/components/line-chart.js +76 -54
- package/dist/components/list.js +1 -1
- package/dist/components/menu.js +1 -1
- package/dist/components/multiselect.js +3 -3
- package/dist/components/nav-bar.d.ts +9 -0
- package/dist/components/nav-bar.js +16 -3
- package/dist/components/nav-menu.js +1 -1
- package/dist/components/number-input.js +2 -2
- package/dist/components/pagination.js +2 -2
- package/dist/components/panel.js +1 -1
- package/dist/components/pin-input.js +2 -2
- package/dist/components/popover.js +2 -2
- package/dist/components/progress.js +2 -2
- package/dist/components/radio-group.js +2 -2
- package/dist/components/radio.js +2 -2
- package/dist/components/scroll-area.js +2 -2
- package/dist/components/segmented-control.js +1 -1
- package/dist/components/select.js +2 -2
- package/dist/components/sidebar.js +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +2 -2
- package/dist/components/spinner.js +2 -2
- package/dist/components/stat.d.ts +13 -1
- package/dist/components/stat.js +28 -20
- package/dist/components/status-dot.js +1 -1
- package/dist/components/stepper.js +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +4 -0
- package/dist/components/table.js +42 -29
- package/dist/components/tabs.js +1 -1
- package/dist/components/tag.js +2 -2
- package/dist/components/tags-input.js +2 -2
- package/dist/components/textarea.js +2 -2
- package/dist/components/toast.js +1 -1
- package/dist/components/toggle-group.js +1 -1
- package/dist/components/toggle.js +1 -1
- package/dist/components/tooltip.js +2 -2
- package/dist/components.json +15 -13
- package/dist/custom-elements.json +272 -70
- package/dist/dev/types.d.ts +3 -1
- package/dist/dev.js +54 -9
- package/dist/index.js +1 -1
- package/dist/llms.txt +1 -1
- package/dist/reference.md +81 -56
- package/dist/types/elements.d.ts +13 -13
- package/dist/types/react.d.ts +2 -2
- package/dist/types/solid.d.ts +2 -2
- package/dist/types/svelte.d.ts +2 -2
- package/dist/types/vue.d.ts +2 -2
- package/dist/vscode.html-custom-data.json +95 -21
- package/dist/web-types.json +173 -44
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ export declare class VoidElement extends LitElement {
|
|
|
66
66
|
* @internal
|
|
67
67
|
*/
|
|
68
68
|
connectedMoveCallback(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Reports a problem with this element through `@voidable/ui/dev` when it is loaded (a console warning,
|
|
71
|
+
* or a thrown `VoidDevError` in a test suite that asked for that); silent otherwise. Never throws on
|
|
72
|
+
* its own.
|
|
73
|
+
*/
|
|
74
|
+
protected reportDev(kind: string, subject: string, message: string): void;
|
|
69
75
|
protected shouldUpdate(changed: PropertyValues): boolean;
|
|
70
76
|
protected update(changed: PropertyValues): void;
|
|
71
77
|
/**
|
package/dist/base.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as e } from "./chunks/base-
|
|
2
|
-
import { r as t } from "./chunks/projection-
|
|
1
|
+
import { t as e } from "./chunks/base-BGrS4eIl.js";
|
|
2
|
+
import { r as t } from "./chunks/projection-oPe6ipjL.js";
|
|
3
3
|
//#region src/base-entry.ts
|
|
4
4
|
t();
|
|
5
5
|
//#endregion
|
|
@@ -96,6 +96,15 @@ var u = 10, d = 1e3, f = Symbol.for("voidable.dev"), p = Symbol.for("@voidable/u
|
|
|
96
96
|
this.#a === void 0 && (this.#a = this.#f(this), this.#o = this.outerHTML, !this.__voidProjection && this.render !== e.prototype.render && r.current?.create(this)), super.connectedCallback();
|
|
97
97
|
}
|
|
98
98
|
connectedMoveCallback() {}
|
|
99
|
+
reportDev(e, t, n) {
|
|
100
|
+
globalThis[f]?.report?.({
|
|
101
|
+
kind: e,
|
|
102
|
+
tag: this.localName,
|
|
103
|
+
subject: t,
|
|
104
|
+
message: n,
|
|
105
|
+
element: this
|
|
106
|
+
});
|
|
107
|
+
}
|
|
99
108
|
#f(e) {
|
|
100
109
|
if (!e.hasAttributes()) return null;
|
|
101
110
|
let { attrs: t } = l(this), n = e.attributes, r = null;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { html as e, nothing as t } from "lit";
|
|
2
|
+
//#region src/components/charts/data.ts
|
|
3
|
+
function n(e, t, n) {
|
|
4
|
+
if (typeof e != "string") return t.text = null, { value: e ?? n.empty() };
|
|
5
|
+
if (e === t.text) return null;
|
|
6
|
+
if (t.text = e, e.trim() === "") return { value: n.empty() };
|
|
7
|
+
let i;
|
|
8
|
+
try {
|
|
9
|
+
i = JSON.parse(e);
|
|
10
|
+
} catch (t) {
|
|
11
|
+
return n.warn(n.attr, `${n.attr}="${r(e)}" is not valid JSON (${t.message}), so nothing is drawn. Expected ${n.shape}.`), { value: n.empty() };
|
|
12
|
+
}
|
|
13
|
+
let a = n.normalize(i);
|
|
14
|
+
return a === null ? (n.warn(n.attr, `${n.attr}="${r(e)}" does not have the shape the chart takes, so nothing is drawn. Expected ${n.shape}.`), { value: n.empty() }) : { value: a };
|
|
15
|
+
}
|
|
16
|
+
function r(e) {
|
|
17
|
+
return e.length > 60 ? `${e.slice(0, 57)}...` : e;
|
|
18
|
+
}
|
|
19
|
+
var i = (e) => typeof e == "object" && !!e && !Array.isArray(e), a = (e) => Array.isArray(e) ? e : [];
|
|
20
|
+
function o(e) {
|
|
21
|
+
if (!i(e) || e.series !== void 0 && !Array.isArray(e.series)) return null;
|
|
22
|
+
let t = a(e.series).filter(i).map((e) => ({
|
|
23
|
+
...e,
|
|
24
|
+
name: String(e.name ?? ""),
|
|
25
|
+
values: a(e.values)
|
|
26
|
+
}));
|
|
27
|
+
return e.labels === void 0 ? { series: t } : {
|
|
28
|
+
series: t,
|
|
29
|
+
labels: a(e.labels).map(String)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function s(e) {
|
|
33
|
+
return Array.isArray(e) ? e.filter(i).map((e) => ({
|
|
34
|
+
...e,
|
|
35
|
+
name: String(e.name ?? ""),
|
|
36
|
+
value: e.value
|
|
37
|
+
})) : null;
|
|
38
|
+
}
|
|
39
|
+
function c(e) {
|
|
40
|
+
return e.closest("[lang]")?.getAttribute("lang") || void 0;
|
|
41
|
+
}
|
|
42
|
+
function l(e) {
|
|
43
|
+
let t = (t) => {
|
|
44
|
+
try {
|
|
45
|
+
return new Intl.NumberFormat(c(e), t);
|
|
46
|
+
} catch {
|
|
47
|
+
return new Intl.NumberFormat(void 0, t);
|
|
48
|
+
}
|
|
49
|
+
}, n = t({ maximumFractionDigits: 3 }), r = t({
|
|
50
|
+
style: "percent",
|
|
51
|
+
maximumFractionDigits: 1
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
number: (e) => typeof e == "number" && Number.isFinite(e) ? n.format(e) : "–",
|
|
55
|
+
percent: (e) => Number.isFinite(e) ? r.format(e) : "–"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function u(n, r) {
|
|
59
|
+
return r ? e`<table class=${n}>
|
|
60
|
+
<caption>${r.caption}</caption>
|
|
61
|
+
<thead><tr>${r.head.map((t) => e`<th scope="col">${t}</th>`)}</tr></thead>
|
|
62
|
+
<tbody>${r.rows.map((n) => e`<tr>${n.header === void 0 ? t : e`<th scope="row">${n.header}</th>`}${n.cells.map((t) => e`<td>${t}</td>`)}</tr>`)}</tbody>
|
|
63
|
+
</table>` : t;
|
|
64
|
+
}
|
|
65
|
+
function d(e, t, n, r) {
|
|
66
|
+
if (n.length === 0) return null;
|
|
67
|
+
let i = l(e), a = Math.max(...n.map((e) => e.values.length)), o = [];
|
|
68
|
+
for (let e = 0; e < a; e++) o.push({
|
|
69
|
+
header: r[e] ?? String(e + 1),
|
|
70
|
+
cells: n.map((t) => i.number(t.values[e]))
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
caption: t,
|
|
74
|
+
head: ["Label", ...n.map((e) => e.name)],
|
|
75
|
+
rows: o
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function f(e, t, n) {
|
|
79
|
+
if (n.length === 0) return null;
|
|
80
|
+
let r = l(e), i = (e) => Number.isFinite(e) ? e : 0, a = n.reduce((e, t) => e + i(t.value), 0);
|
|
81
|
+
return {
|
|
82
|
+
caption: t,
|
|
83
|
+
head: [
|
|
84
|
+
"Segment",
|
|
85
|
+
"Value",
|
|
86
|
+
"Share"
|
|
87
|
+
],
|
|
88
|
+
rows: n.map((e) => ({
|
|
89
|
+
header: e.name,
|
|
90
|
+
cells: [r.number(e.value), a > 0 ? r.percent(i(e.value) / a) : "–"]
|
|
91
|
+
}))
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { o as a, d as c, s as i, l, u as n, n as o, i as r, f as s, c as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as e } from "./base-
|
|
1
|
+
import { t as e } from "./base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "./decorate-CaYbmmmm.js";
|
|
3
3
|
import { n, r } from "./parts-DI_3VpSy.js";
|
|
4
|
-
import { t as i } from "./overlay-
|
|
4
|
+
import { t as i } from "./overlay-CH7L4N-h.js";
|
|
5
5
|
import { property as a } from "lit/decorators.js";
|
|
6
6
|
//#region src/modal.ts
|
|
7
7
|
var o = class extends e {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
3
|
import { n } from "../chunks/parts-DI_3VpSy.js";
|
|
4
4
|
import { t as r } from "../chunks/disclosure-Bj_49GcC.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
3
|
import { n } from "../chunks/form-control-C0vH6gii.js";
|
|
4
|
-
import { r } from "../chunks/projection-
|
|
4
|
+
import { r } from "../chunks/projection-oPe6ipjL.js";
|
|
5
5
|
import { n as i, t as a } from "../chunks/secret-value-CmTtVkMg.js";
|
|
6
6
|
import { html as o, nothing as s } from "lit";
|
|
7
7
|
import { property as c } from "lit/decorators.js";
|
|
@@ -3,6 +3,9 @@ import { PartsController } from '../parts.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Inline contextual message for form validation feedback, permission warnings, and system status notices.
|
|
5
5
|
*
|
|
6
|
+
* Its role follows the colour: `error` and `warning` are `role="alert"` (announced at once, interrupting), every
|
|
7
|
+
* other colour is `role="status"` (announced politely). A role you write on it is kept.
|
|
8
|
+
*
|
|
6
9
|
* Its text is written as parts: an optional `<void-alert-title>`, the `<void-alert-description>` and an optional
|
|
7
10
|
* `<void-alert-close>`. The parts are never moved. The close part wraps the one control the author writes (a
|
|
8
11
|
* `<button type="button" aria-label="Dismiss">`); pressing it fires `void-close` and, unless that is cancelled, removes the alert (focus inside
|
|
@@ -24,6 +27,14 @@ export declare class VoidAlert extends VoidElement {
|
|
|
24
27
|
variant: 'subtle' | 'filled';
|
|
25
28
|
protected readonly _parts: PartsController;
|
|
26
29
|
connectedCallback(): void;
|
|
30
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
31
|
+
/**
|
|
32
|
+
* `alert` (assertive: it interrupts) only for the urgent colours, `error` and `warning`; every other
|
|
33
|
+
* alert is `status` (polite). A role the author wrote is left alone.
|
|
34
|
+
*/
|
|
35
|
+
private _syncRole;
|
|
36
|
+
/** The role this alert wrote itself, so one the author wrote is told apart from it. */
|
|
37
|
+
private _writtenRole;
|
|
27
38
|
disconnectedCallback(): void;
|
|
28
39
|
private _onClick;
|
|
29
40
|
}
|
package/dist/components/alert.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
3
|
import { n } from "../chunks/parts-DI_3VpSy.js";
|
|
4
4
|
import { n as r, t as i } from "../chunks/dismiss-Drsy_dE5.js";
|
|
@@ -13,7 +13,7 @@ var o = class extends e {
|
|
|
13
13
|
"void-alert-close"
|
|
14
14
|
],
|
|
15
15
|
onChange: () => void 0
|
|
16
|
-
}), this._onClick = (e) => {
|
|
16
|
+
}), this._writtenRole = null, this._onClick = (e) => {
|
|
17
17
|
i(this._parts.one("void-alert-close"), e) && this.dispatchEvent(new CustomEvent("void-close", {
|
|
18
18
|
bubbles: !1,
|
|
19
19
|
cancelable: !0,
|
|
@@ -22,7 +22,14 @@ var o = class extends e {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
connectedCallback() {
|
|
25
|
-
super.connectedCallback(), this.
|
|
25
|
+
super.connectedCallback(), this._syncRole(), this.addEventListener("click", this._onClick);
|
|
26
|
+
}
|
|
27
|
+
updated(e) {
|
|
28
|
+
super.updated(e), e.has("color") && this._syncRole();
|
|
29
|
+
}
|
|
30
|
+
_syncRole() {
|
|
31
|
+
let e = this.getAttribute("role");
|
|
32
|
+
e !== null && e !== this._writtenRole || (this._writtenRole = this.color === "error" || this.color === "warning" ? "alert" : "status", this.setHostAttribute("role", this._writtenRole));
|
|
26
33
|
}
|
|
27
34
|
disconnectedCallback() {
|
|
28
35
|
super.disconnectedCallback(), this.removeEventListener("click", this._onClick);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
|
-
import { r as n } from "../chunks/projection-
|
|
3
|
+
import { r as n } from "../chunks/projection-oPe6ipjL.js";
|
|
4
4
|
import { html as r } from "lit";
|
|
5
5
|
import { property as i } from "lit/decorators.js";
|
|
6
6
|
//#region src/components/avatar.ts
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { VoidElement } from '../base.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Small status chip for issue trackers, tag systems, and categorization UIs where color conveys state at a glance.
|
|
4
|
+
*
|
|
5
|
+
* A badge has no role: it is text beside other text, and a screen reader reads it where it sits. It is not
|
|
6
|
+
* a live region, because a table of status badges would announce every one as it is inserted. For the one
|
|
7
|
+
* badge whose change must be heard (a count that updates while the user works), write `role="status"` on it
|
|
8
|
+
* yourself; the component leaves it alone.
|
|
9
|
+
*/
|
|
3
10
|
export declare class VoidBadge extends VoidElement {
|
|
4
11
|
/**
|
|
5
12
|
* Status colour: `default`, `error`, `warning`, `caution`, `success`, `info`, `notice` or `highlight`.
|
|
@@ -10,7 +17,6 @@ export declare class VoidBadge extends VoidElement {
|
|
|
10
17
|
variant: 'filled' | 'outline';
|
|
11
18
|
/** Size step: `sm`, `md` (default) or `lg`. */
|
|
12
19
|
size: 'sm' | 'md' | 'lg';
|
|
13
|
-
connectedCallback(): void;
|
|
14
20
|
}
|
|
15
21
|
declare global {
|
|
16
22
|
interface HTMLElementTagNameMap {
|
package/dist/components/badge.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
3
|
import { property as n } from "lit/decorators.js";
|
|
4
4
|
//#region src/components/badge.ts
|
|
@@ -6,9 +6,6 @@ var r = class extends e {
|
|
|
6
6
|
constructor(...e) {
|
|
7
7
|
super(...e), this.color = "default", this.variant = "filled", this.size = "md";
|
|
8
8
|
}
|
|
9
|
-
connectedCallback() {
|
|
10
|
-
super.connectedCallback(), this.setHostAttribute("role", "status");
|
|
11
|
-
}
|
|
12
9
|
};
|
|
13
10
|
t([n({
|
|
14
11
|
type: String,
|
|
@@ -3,6 +3,11 @@ import { PartsController } from '../parts.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Full-width site-level announcement for maintenance windows, cookie consent, and promotional messaging.
|
|
5
5
|
*
|
|
6
|
+
* It never has the `banner` role: that is the page header landmark (at most one per page, never inside
|
|
7
|
+
* `<main>`), which an announcement is not. Like the alert it carries an announcement, so its role follows its
|
|
8
|
+
* `color`: `alert` for `error` and `warning`, `status` for the rest. To make it a landmark users can jump to,
|
|
9
|
+
* write `role="region"` and an `aria-label`; the component leaves a role you write alone.
|
|
10
|
+
*
|
|
6
11
|
* Its text is written as parts: an optional `<void-banner-title>`, the `<void-banner-description>`, an optional
|
|
7
12
|
* `<void-banner-actions>` (buttons or links) and an optional `<void-banner-close>`. The parts are never moved. The
|
|
8
13
|
* close part wraps the one control the author writes (a `<void-button aria-label="Dismiss">`); pressing it fires
|
|
@@ -21,6 +26,10 @@ export declare class VoidBanner extends VoidElement {
|
|
|
21
26
|
variant: 'subtle' | 'filled';
|
|
22
27
|
protected readonly _parts: PartsController;
|
|
23
28
|
connectedCallback(): void;
|
|
29
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
30
|
+
/** `alert` for the urgent colours, `status` otherwise; a role the author wrote is left alone. */
|
|
31
|
+
private _syncRole;
|
|
32
|
+
private _writtenRole;
|
|
24
33
|
disconnectedCallback(): void;
|
|
25
34
|
private _onClick;
|
|
26
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
3
|
import { n } from "../chunks/parts-DI_3VpSy.js";
|
|
4
4
|
import { n as r, t as i } from "../chunks/dismiss-Drsy_dE5.js";
|
|
@@ -14,7 +14,7 @@ var o = class extends e {
|
|
|
14
14
|
"void-banner-close"
|
|
15
15
|
],
|
|
16
16
|
onChange: () => void 0
|
|
17
|
-
}), this._onClick = (e) => {
|
|
17
|
+
}), this._writtenRole = null, this._onClick = (e) => {
|
|
18
18
|
i(this._parts.one("void-banner-close"), e) && this.dispatchEvent(new CustomEvent("void-close", {
|
|
19
19
|
bubbles: !1,
|
|
20
20
|
cancelable: !0,
|
|
@@ -23,7 +23,14 @@ var o = class extends e {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
connectedCallback() {
|
|
26
|
-
super.connectedCallback(), this.
|
|
26
|
+
super.connectedCallback(), this._syncRole(), this.addEventListener("click", this._onClick);
|
|
27
|
+
}
|
|
28
|
+
updated(e) {
|
|
29
|
+
super.updated(e), e.has("color") && this._syncRole();
|
|
30
|
+
}
|
|
31
|
+
_syncRole() {
|
|
32
|
+
let e = this.getAttribute("role");
|
|
33
|
+
e !== null && e !== this._writtenRole || (this._writtenRole = this.color === "error" || this.color === "warning" ? "alert" : "status", this.setHostAttribute("role", this._writtenRole));
|
|
27
34
|
}
|
|
28
35
|
disconnectedCallback() {
|
|
29
36
|
super.disconnectedCallback(), this.removeEventListener("click", this._onClick);
|
|
@@ -15,8 +15,10 @@ export interface BarChartData {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Bar chart for comparing categories and series, drawn in SVG with animated bars. Give it `data`
|
|
18
|
-
* (`{ series: [{ name, values }], labels }`)
|
|
19
|
-
*
|
|
18
|
+
* (`{ series: [{ name, values }], labels }`) as the `data` property or as JSON in the `data` attribute, so
|
|
19
|
+
* server-rendered markup draws it with no script; it has no children. The drawing is hidden from assistive
|
|
20
|
+
* technology and a visually hidden data table (captioned with `aria-label`) carries the values instead; add
|
|
21
|
+
* `show-table` to show the table below the chart too.
|
|
20
22
|
*/
|
|
21
23
|
export declare class VoidBarChart extends VoidElement {
|
|
22
24
|
/** Height of the chart in pixels. Defaults to 220. The width fills the container. */
|
|
@@ -29,25 +31,35 @@ export declare class VoidBarChart extends VoidElement {
|
|
|
29
31
|
*/
|
|
30
32
|
variant: 'filled' | 'outline' | 'wireframe';
|
|
31
33
|
/**
|
|
32
|
-
* Accessible name of the chart, such as `Revenue by quarter
|
|
33
|
-
*
|
|
34
|
+
* Accessible name of the chart, such as `Revenue by quarter`; it is also the caption of the data table.
|
|
35
|
+
* Set it: the drawing itself is hidden from assistive technology.
|
|
34
36
|
*/
|
|
35
37
|
ariaLabel: string;
|
|
38
|
+
/**
|
|
39
|
+
* Show the data table (one row per category, one column per series) below the chart. The table is always
|
|
40
|
+
* there for assistive technology; this makes it visible too.
|
|
41
|
+
*/
|
|
42
|
+
showTable: boolean;
|
|
36
43
|
/**
|
|
37
44
|
* Delay in milliseconds between the bars as they animate in, one after another. Without it the theme's
|
|
38
45
|
* `--void-stagger-chart-bars` applies; `stagger="0"` animates them together.
|
|
39
46
|
*/
|
|
40
47
|
stagger: number | null;
|
|
41
48
|
private _data;
|
|
49
|
+
private _source;
|
|
50
|
+
private _entered;
|
|
42
51
|
/**
|
|
43
52
|
* The chart's data: `{ series: [{ name, values, color?, colors? }], labels? }`. `values` are aligned with
|
|
44
53
|
* `labels` (the category names along the axis); `color` colours a whole series and `colors` overrides single
|
|
45
54
|
* bars. Negative values are bars below a zero baseline: the value axis then spans the lowest value as
|
|
46
|
-
* well, and a baseline is drawn at zero.
|
|
47
|
-
* animate to it
|
|
55
|
+
* well, and a baseline is drawn at zero. Give it as a property (assign a new object to update the chart
|
|
56
|
+
* and animate to it) or as JSON in the `data` attribute: `<void-bar-chart data='{"series":[{"name":"Sales","values":[3,5]}],"labels":["Mon","Tue"]}'>`.
|
|
57
|
+
* Invalid JSON draws nothing and is reported by `@voidable/ui/dev`. The property is not reflected to the
|
|
58
|
+
* attribute (the data can be large), and an attribute a server morph leaves unchanged does not animate again.
|
|
59
|
+
* @default { series: [] }
|
|
48
60
|
*/
|
|
49
61
|
get data(): BarChartData;
|
|
50
|
-
set data(
|
|
62
|
+
set data(input: BarChartData);
|
|
51
63
|
private _phase;
|
|
52
64
|
private _display;
|
|
53
65
|
private _targets;
|
|
@@ -63,6 +75,8 @@ export declare class VoidBarChart extends VoidElement {
|
|
|
63
75
|
private _startAnimation;
|
|
64
76
|
private _tick;
|
|
65
77
|
render(): import('lit').TemplateResult<1>;
|
|
78
|
+
/** The data table for assistive technology (and `show-table`), from the data as given, not the animated state. */
|
|
79
|
+
private _table;
|
|
66
80
|
}
|
|
67
81
|
declare global {
|
|
68
82
|
interface HTMLElementTagNameMap {
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
|
-
import { r as n } from "../chunks/projection-
|
|
3
|
+
import { r as n } from "../chunks/projection-oPe6ipjL.js";
|
|
4
4
|
import { n as r, t as i } from "../chunks/scale-_ccSuoYg.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { a, c as o, n as s, o as c, t as l } from "../chunks/data-BpiiNapL.js";
|
|
6
|
+
import { html as u, nothing as d, svg as f } from "lit";
|
|
7
|
+
import { property as p, state as m } from "lit/decorators.js";
|
|
8
|
+
import { guard as h } from "lit/directives/guard.js";
|
|
7
9
|
//#region src/components/bar-chart.ts
|
|
8
10
|
n();
|
|
9
|
-
function
|
|
11
|
+
function g(e) {
|
|
10
12
|
return 1 - (1 - e) ** 3;
|
|
11
13
|
}
|
|
12
|
-
function
|
|
14
|
+
function _(e) {
|
|
13
15
|
return e === 0 ? "0" : Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(e >= 1e4 ? 0 : 1)}k` : Number.isInteger(e) ? String(e) : e.toFixed(1);
|
|
14
16
|
}
|
|
15
|
-
function
|
|
17
|
+
function v(e) {
|
|
16
18
|
return Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(e >= 1e4 ? 0 : 1)}k` : Math.round(e).toString();
|
|
17
19
|
}
|
|
18
|
-
function
|
|
20
|
+
function y(e) {
|
|
19
21
|
if (e <= 0) return 1;
|
|
20
22
|
let t = 10 ** Math.floor(Math.log10(e)), n = e / t;
|
|
21
23
|
return (n <= 1 ? 1 : n <= 2 ? 2 : n <= 5 ? 5 : 10) * t;
|
|
22
24
|
}
|
|
23
|
-
var
|
|
25
|
+
var b = class extends e {
|
|
24
26
|
constructor(...e) {
|
|
25
|
-
super(...e), this.height = 220, this.showValue = !1, this.variant = "filled", this.ariaLabel = "", this.stagger = null, this._data = { series: [] }, this._phase = "pre", this._display = /* @__PURE__ */ new Map(), this._targets = /* @__PURE__ */ new Map(), this._animFrom = /* @__PURE__ */ new Map(), this._animStart = 0, this._animDuration = 0, this._staggerMs = 0, this._rafHandle = 0, this._tick = (e) => {
|
|
27
|
+
super(...e), this.height = 220, this.showValue = !1, this.variant = "filled", this.ariaLabel = "", this.showTable = !1, this.stagger = null, this._data = { series: [] }, this._source = { text: null }, this._entered = !1, this._phase = "pre", this._display = /* @__PURE__ */ new Map(), this._targets = /* @__PURE__ */ new Map(), this._animFrom = /* @__PURE__ */ new Map(), this._animStart = 0, this._animDuration = 0, this._staggerMs = 0, this._rafHandle = 0, this._tick = (e) => {
|
|
26
28
|
let t = e - this._animStart, n = !1;
|
|
27
29
|
for (let [e, r] of this._targets) {
|
|
28
30
|
let [, i] = e.split("-"), a = Number(i) * this._staggerMs, o = a + this._animDuration, s = this._animFrom.get(e) ?? 0;
|
|
@@ -30,7 +32,7 @@ var m = class extends e {
|
|
|
30
32
|
else if (t >= o) this._display.set(e, r);
|
|
31
33
|
else {
|
|
32
34
|
let i = (t - a) / this._animDuration;
|
|
33
|
-
this._display.set(e, s + (r - s) *
|
|
35
|
+
this._display.set(e, s + (r - s) * g(i)), n = !0;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
this.requestUpdate(), n ? this._rafHandle = requestAnimationFrame(this._tick) : this._phase = "idle";
|
|
@@ -40,8 +42,16 @@ var m = class extends e {
|
|
|
40
42
|
return this._data;
|
|
41
43
|
}
|
|
42
44
|
set data(e) {
|
|
43
|
-
let t =
|
|
44
|
-
|
|
45
|
+
let t = c(e, this._source, {
|
|
46
|
+
attr: "data",
|
|
47
|
+
shape: "{\"series\":[{\"name\":\"Sales\",\"values\":[3,5]}],\"labels\":[\"Mon\",\"Tue\"]}",
|
|
48
|
+
empty: () => ({ series: [] }),
|
|
49
|
+
normalize: a,
|
|
50
|
+
warn: (e, t) => this.reportDev("invalid-data", e, t)
|
|
51
|
+
});
|
|
52
|
+
if (!t) return;
|
|
53
|
+
let n = new Map(this._display);
|
|
54
|
+
this._data = t.value, this._refreshTargets(), this.requestUpdate(), this._entered && this.updateComplete.then(() => this._startAnimation(n));
|
|
45
55
|
}
|
|
46
56
|
_key(e, t) {
|
|
47
57
|
return `${e}-${t}`;
|
|
@@ -52,8 +62,8 @@ var m = class extends e {
|
|
|
52
62
|
});
|
|
53
63
|
}
|
|
54
64
|
connectedCallback() {
|
|
55
|
-
super.connectedCallback(), this.setHostAttribute("role", "
|
|
56
|
-
this._startAnimation(/* @__PURE__ */ new Map());
|
|
65
|
+
super.connectedCallback(), this.setHostAttribute("role", "figure"), this._refreshTargets(), requestAnimationFrame(() => {
|
|
66
|
+
this._entered = !0, this._startAnimation(/* @__PURE__ */ new Map());
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
disconnectedCallback() {
|
|
@@ -70,42 +80,41 @@ var m = class extends e {
|
|
|
70
80
|
}
|
|
71
81
|
render() {
|
|
72
82
|
let { series: e, labels: t = [] } = this._data;
|
|
73
|
-
if (e.length === 0) return
|
|
74
|
-
let n = this.height - 16 - 32,
|
|
75
|
-
return
|
|
83
|
+
if (e.length === 0) return u`<svg viewBox="0 0 600 ${this.height}" aria-hidden="true"></svg>`;
|
|
84
|
+
let n = this.height - 16 - 32, a = Math.max(...e.map((e) => e.values.length)), o = e.flatMap((e) => e.values).filter(Number.isFinite), s = Math.max(...o, 0), c = Math.min(...o, 0), l = c < 0 ? -y(-c * 1.1) : 0, p = new r([l, s > 0 || l === 0 ? y(s * 1.1) || 1 : 0], [16 + n, 16]), m = p.scale(0), h = new i(a, [40, 584], .2), g = p.ticks(5);
|
|
85
|
+
return u`
|
|
76
86
|
<svg
|
|
77
87
|
viewBox="0 0 600 ${this.height}"
|
|
78
88
|
preserveAspectRatio="none"
|
|
79
|
-
|
|
80
|
-
aria-label=${this.ariaLabel || "Bar chart"}
|
|
89
|
+
aria-hidden="true"
|
|
81
90
|
data-phase=${this._phase}
|
|
82
91
|
>
|
|
83
92
|
<g class="void-bar-chart-grid">
|
|
84
|
-
${
|
|
85
|
-
let t =
|
|
86
|
-
return
|
|
93
|
+
${g.map((e) => {
|
|
94
|
+
let t = p.scale(e);
|
|
95
|
+
return f`<line x1=${40} x2=${584} y1=${t} y2=${t}></line>`;
|
|
87
96
|
})}
|
|
88
97
|
</g>
|
|
89
98
|
|
|
90
|
-
${
|
|
99
|
+
${l < 0 ? f`<line class="void-bar-chart-baseline" x1=${40} x2=${584} y1=${m} y2=${m}></line>` : d}
|
|
91
100
|
|
|
92
101
|
<g class="void-bar-chart-y-axis">
|
|
93
|
-
${
|
|
102
|
+
${g.map((e) => f`<text x=${32} y=${p.scale(e)} dy="0.32em" text-anchor="end">${_(e)}</text>`)}
|
|
94
103
|
</g>
|
|
95
104
|
|
|
96
105
|
${e.map((t, n) => {
|
|
97
|
-
let r = t.color ?? `var(--void-chart-series-${n % 6 + 1})`, i =
|
|
98
|
-
return
|
|
106
|
+
let r = t.color ?? `var(--void-chart-series-${n % 6 + 1})`, i = h.bandwidth / e.length;
|
|
107
|
+
return f`
|
|
99
108
|
<g class="void-bar-chart-series" style="--series-color: ${r}">
|
|
100
109
|
${t.values.map((e, r) => {
|
|
101
|
-
let a = this._display.get(this._key(n, r)) ?? 0,
|
|
102
|
-
return
|
|
110
|
+
let a = this._display.get(this._key(n, r)) ?? 0, o = h.scale(r) + i * n, s = p.scale(a), c = Math.min(s, m), l = Math.abs(m - s), u = t.colors?.[r];
|
|
111
|
+
return f`<rect
|
|
103
112
|
class="void-bar-chart-bar"
|
|
104
|
-
x=${
|
|
105
|
-
y=${
|
|
113
|
+
x=${o}
|
|
114
|
+
y=${c}
|
|
106
115
|
width=${i - 2}
|
|
107
|
-
height=${
|
|
108
|
-
style=${
|
|
116
|
+
height=${l}
|
|
117
|
+
style=${u ? `--series-color: ${u}` : d}
|
|
109
118
|
></rect>`;
|
|
110
119
|
})}
|
|
111
120
|
</g>
|
|
@@ -113,31 +122,44 @@ var m = class extends e {
|
|
|
113
122
|
})}
|
|
114
123
|
|
|
115
124
|
${this.showValue ? e.map((t, n) => {
|
|
116
|
-
let r =
|
|
117
|
-
return
|
|
125
|
+
let r = h.bandwidth / e.length;
|
|
126
|
+
return f`
|
|
118
127
|
<g class="void-bar-chart-values">
|
|
119
128
|
${t.values.map((e, t) => {
|
|
120
|
-
let i = this._display.get(this._key(n, t)) ?? 0, a =
|
|
121
|
-
return
|
|
129
|
+
let i = this._display.get(this._key(n, t)) ?? 0, a = h.scale(t) + r * n + (r - 2) / 2, o = p.scale(i);
|
|
130
|
+
return f`<text x=${a} y=${i < 0 ? o + 14 : o - 6} text-anchor="middle">${v(i)}</text>`;
|
|
122
131
|
})}
|
|
123
132
|
</g>
|
|
124
133
|
`;
|
|
125
|
-
}) :
|
|
134
|
+
}) : d}
|
|
126
135
|
|
|
127
136
|
<g class="void-bar-chart-x-axis">
|
|
128
|
-
${t.slice(0,
|
|
137
|
+
${t.slice(0, a).map((e, t) => f`<text x=${h.scale(t) + h.bandwidth / 2} y=${16 + n + 18} text-anchor="middle">${e}</text>`)}
|
|
129
138
|
</g>
|
|
130
139
|
</svg>
|
|
140
|
+
${this._table()}
|
|
131
141
|
`;
|
|
132
142
|
}
|
|
143
|
+
_table() {
|
|
144
|
+
let e = this._data, t = this.ariaLabel || "Bar chart";
|
|
145
|
+
return h([
|
|
146
|
+
e,
|
|
147
|
+
t,
|
|
148
|
+
l(this)
|
|
149
|
+
], () => s("void-bar-chart-table", o(this, t, e.series, e.labels ?? [])));
|
|
150
|
+
}
|
|
133
151
|
};
|
|
134
|
-
t([
|
|
152
|
+
t([p({
|
|
135
153
|
type: Number,
|
|
136
154
|
reflect: !0
|
|
137
|
-
})],
|
|
155
|
+
})], b.prototype, "height", void 0), t([p({
|
|
138
156
|
type: Boolean,
|
|
139
157
|
attribute: "show-value",
|
|
140
158
|
reflect: !0
|
|
141
|
-
})],
|
|
159
|
+
})], b.prototype, "showValue", void 0), t([p({ reflect: !0 })], b.prototype, "variant", void 0), t([p({ attribute: "aria-label" })], b.prototype, "ariaLabel", void 0), t([p({
|
|
160
|
+
type: Boolean,
|
|
161
|
+
attribute: "show-table",
|
|
162
|
+
reflect: !0
|
|
163
|
+
})], b.prototype, "showTable", void 0), t([p({ type: Number })], b.prototype, "stagger", void 0), t([p({ attribute: "data" })], b.prototype, "data", null), t([m()], b.prototype, "_phase", void 0), customElements.get("void-bar-chart") || customElements.define("void-bar-chart", b);
|
|
142
164
|
//#endregion
|
|
143
|
-
export {
|
|
165
|
+
export { b as VoidBarChart };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "../chunks/base-
|
|
1
|
+
import { t as e } from "../chunks/base-BGrS4eIl.js";
|
|
2
2
|
import { t } from "../chunks/decorate-CaYbmmmm.js";
|
|
3
3
|
import { t as n } from "../chunks/keyboard-activation-CV0m4hkn.js";
|
|
4
4
|
import { i as r, r as i } from "../chunks/form-control-C0vH6gii.js";
|