@aiaiai-pt/design-system 0.61.1 → 0.62.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/components/EChart.svelte
CHANGED
|
@@ -170,6 +170,26 @@
|
|
|
170
170
|
/** @type {import('echarts/core').EChartsType | undefined} */
|
|
171
171
|
let _chart = $state();
|
|
172
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Resolve CSS Color 4/5 values (e.g. `color-mix(...)`, `oklch(...)`,
|
|
175
|
+
* space-separated `rgb(... / ...)`) into ZRender-safe `rgb()`/`rgba()` via a
|
|
176
|
+
* transient DOM probe. Simple `#hex` and comma `rgb()`/`rgba()` pass straight
|
|
177
|
+
* through without touching the DOM.
|
|
178
|
+
*/
|
|
179
|
+
const ZRENDER_SAFE_COLOR = /^(?:#[0-9a-f]{3,8}|rgba?\(\s*[0-9.]+\s*,\s*[0-9.]+\s*,\s*[0-9.]+(?:\s*,\s*[0-9.]+)?\s*\))$/i;
|
|
180
|
+
|
|
181
|
+
function resolveColor(el, raw) {
|
|
182
|
+
if (!raw || ZRENDER_SAFE_COLOR.test(raw)) return raw;
|
|
183
|
+
if (typeof document === "undefined") return raw;
|
|
184
|
+
const probe = document.createElement("span");
|
|
185
|
+
probe.style.display = "none";
|
|
186
|
+
probe.style.color = raw;
|
|
187
|
+
el.appendChild(probe);
|
|
188
|
+
const resolved = getComputedStyle(probe).color.trim();
|
|
189
|
+
probe.remove();
|
|
190
|
+
return resolved || raw;
|
|
191
|
+
}
|
|
192
|
+
|
|
173
193
|
/** Build the ECharts option from current data + the container's tokens. */
|
|
174
194
|
function buildOption() {
|
|
175
195
|
const el = container;
|
|
@@ -177,7 +197,7 @@
|
|
|
177
197
|
const cs = getComputedStyle(el);
|
|
178
198
|
const token = (name, fallback) => {
|
|
179
199
|
const v = cs.getPropertyValue(name).trim();
|
|
180
|
-
return v || fallback;
|
|
200
|
+
return resolveColor(el, v || fallback);
|
|
181
201
|
};
|
|
182
202
|
return buildChartOption(chartData, {
|
|
183
203
|
tokens: {
|
|
@@ -351,6 +371,10 @@
|
|
|
351
371
|
font-weight: 600;
|
|
352
372
|
}
|
|
353
373
|
|
|
374
|
+
.echart-table thead th:not(:first-child) {
|
|
375
|
+
text-align: end;
|
|
376
|
+
}
|
|
377
|
+
|
|
354
378
|
.echart-table tr[data-band] {
|
|
355
379
|
background: var(--chart-band-bg);
|
|
356
380
|
}
|
|
@@ -361,12 +385,12 @@
|
|
|
361
385
|
}
|
|
362
386
|
.echart-table tbody th {
|
|
363
387
|
font-weight: 400;
|
|
364
|
-
color: var(--color-text
|
|
388
|
+
color: var(--color-text);
|
|
365
389
|
}
|
|
366
390
|
|
|
367
391
|
.echart-table td {
|
|
368
392
|
text-align: end;
|
|
369
393
|
font-variant-numeric: tabular-nums;
|
|
370
|
-
color: var(--color-text
|
|
394
|
+
color: var(--color-text);
|
|
371
395
|
}
|
|
372
396
|
</style>
|
|
@@ -66,6 +66,21 @@
|
|
|
66
66
|
/** @type {string} — label for the "next" nav button */
|
|
67
67
|
nextLabel = 'NEXT',
|
|
68
68
|
|
|
69
|
+
/* Host-language text (atelier#2674): the summary and the navigation's
|
|
70
|
+
accessible names. Each count arrives already formatted. */
|
|
71
|
+
/** @type {(total: string) => string} — cursor-mode summary */
|
|
72
|
+
totalLabel = (total) => `${total} total`,
|
|
73
|
+
/** @type {(start: string, end: string, total: string) => string} — offset-mode range */
|
|
74
|
+
rangeLabel = (start, end, total) => `${start}–${end} of ${total}`,
|
|
75
|
+
/** @type {string} — accessible name of the page-size control */
|
|
76
|
+
rowsPerPageLabel = 'Rows per page',
|
|
77
|
+
/** @type {string} — accessible name of the previous-page button */
|
|
78
|
+
previousPageLabel = 'Previous page',
|
|
79
|
+
/** @type {string} — accessible name of the next-page button */
|
|
80
|
+
nextPageLabel = 'Next page',
|
|
81
|
+
/** @type {string | undefined} — BCP 47 locale the counts are formatted in */
|
|
82
|
+
locale = undefined,
|
|
83
|
+
|
|
69
84
|
/** @type {string} */
|
|
70
85
|
class: className = '',
|
|
71
86
|
...rest
|
|
@@ -87,13 +102,17 @@
|
|
|
87
102
|
total_items === undefined
|
|
88
103
|
? ''
|
|
89
104
|
: mode === 'cursor'
|
|
90
|
-
?
|
|
105
|
+
? totalLabel(total_items.toLocaleString(locale))
|
|
91
106
|
: (() => {
|
|
92
107
|
const start = (current_page - 1) * page_size + 1;
|
|
93
108
|
const end = Math.min(current_page * page_size, total_items);
|
|
94
109
|
return start > total_items
|
|
95
|
-
?
|
|
96
|
-
:
|
|
110
|
+
? totalLabel(total_items.toLocaleString(locale))
|
|
111
|
+
: rangeLabel(
|
|
112
|
+
start.toLocaleString(locale),
|
|
113
|
+
end.toLocaleString(locale),
|
|
114
|
+
total_items.toLocaleString(locale)
|
|
115
|
+
);
|
|
97
116
|
})()
|
|
98
117
|
);
|
|
99
118
|
|
|
@@ -138,7 +157,7 @@
|
|
|
138
157
|
value={page_size_value}
|
|
139
158
|
options={page_size_options}
|
|
140
159
|
onchange={(val) => on_page_size_change?.(Number(val))}
|
|
141
|
-
aria-label=
|
|
160
|
+
aria-label={rowsPerPageLabel}
|
|
142
161
|
/>
|
|
143
162
|
</div>
|
|
144
163
|
{/if}
|
|
@@ -150,15 +169,15 @@
|
|
|
150
169
|
<span class="pagination-spacer" aria-hidden="true"></span>
|
|
151
170
|
|
|
152
171
|
{#if mode === 'cursor'}
|
|
153
|
-
<button class="pagination-nav" disabled={!has_prev} onclick={on_prev} aria-label=
|
|
172
|
+
<button class="pagination-nav" disabled={!has_prev} onclick={on_prev} aria-label={previousPageLabel}>
|
|
154
173
|
{@render chevronLeft()}<span>{prevLabel}</span>
|
|
155
174
|
</button>
|
|
156
|
-
<button class="pagination-nav" disabled={!has_next} onclick={on_next} aria-label=
|
|
175
|
+
<button class="pagination-nav" disabled={!has_next} onclick={on_next} aria-label={nextPageLabel}>
|
|
157
176
|
<span>{nextLabel}</span>{@render chevronRight()}
|
|
158
177
|
</button>
|
|
159
178
|
|
|
160
179
|
{:else}
|
|
161
|
-
<button class="pagination-nav" disabled={current_page <= 1} onclick={() => on_page_change?.(current_page - 1)} aria-label=
|
|
180
|
+
<button class="pagination-nav" disabled={current_page <= 1} onclick={() => on_page_change?.(current_page - 1)} aria-label={previousPageLabel}>
|
|
162
181
|
{@render chevronLeft()}<span>{prevLabel}</span>
|
|
163
182
|
</button>
|
|
164
183
|
|
|
@@ -181,7 +200,7 @@
|
|
|
181
200
|
{/each}
|
|
182
201
|
</div>
|
|
183
202
|
|
|
184
|
-
<button class="pagination-nav" disabled={current_page >= (total_pages ?? current_page)} onclick={() => on_page_change?.(current_page + 1)} aria-label=
|
|
203
|
+
<button class="pagination-nav" disabled={current_page >= (total_pages ?? current_page)} onclick={() => on_page_change?.(current_page + 1)} aria-label={nextPageLabel}>
|
|
185
204
|
<span>{nextLabel}</span>{@render chevronRight()}
|
|
186
205
|
</button>
|
|
187
206
|
{/if}
|
|
@@ -46,6 +46,12 @@ declare const Pagination: import("svelte").Component<{
|
|
|
46
46
|
on_page_size_change?: any;
|
|
47
47
|
prevLabel?: string;
|
|
48
48
|
nextLabel?: string;
|
|
49
|
+
totalLabel?: Function;
|
|
50
|
+
rangeLabel?: Function;
|
|
51
|
+
rowsPerPageLabel?: string;
|
|
52
|
+
previousPageLabel?: string;
|
|
53
|
+
nextPageLabel?: string;
|
|
54
|
+
locale?: any;
|
|
49
55
|
class?: string;
|
|
50
56
|
} & Record<string, any>, {}, "">;
|
|
51
57
|
type $$ComponentProps = {
|
|
@@ -63,5 +69,11 @@ type $$ComponentProps = {
|
|
|
63
69
|
on_page_size_change?: any;
|
|
64
70
|
prevLabel?: string;
|
|
65
71
|
nextLabel?: string;
|
|
72
|
+
totalLabel?: Function;
|
|
73
|
+
rangeLabel?: Function;
|
|
74
|
+
rowsPerPageLabel?: string;
|
|
75
|
+
previousPageLabel?: string;
|
|
76
|
+
nextPageLabel?: string;
|
|
77
|
+
locale?: any;
|
|
66
78
|
class?: string;
|
|
67
79
|
} & Record<string, any>;
|
|
@@ -59,10 +59,21 @@ export interface BuildChartOptionOpts {
|
|
|
59
59
|
/** The same, for the secondary value axis. */
|
|
60
60
|
ySecondaryCeiling?: number;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Apply an alpha multiplier to a CSS colour and emit ZRender-safe `rgb()` /
|
|
64
|
+
* `rgba()` syntax.
|
|
65
|
+
*
|
|
66
|
+
* Why NOT `color-mix(in srgb, ...)`: Canvas 2D draws `color-mix(...)` at rest,
|
|
67
|
+
* but ECharts 6 / ZRender computes hover (`emphasis`) colours in JS via
|
|
68
|
+
* `zrender/lib/tool/color.lift()`, whose parser only accepts `#hex`, `rgb()`,
|
|
69
|
+
* `rgba()`, `hsl()`, and named CSS colours. Passing `color-mix(...)` makes
|
|
70
|
+
* `lift()` return `undefined`, turning hovered bars/slices invisible.
|
|
71
|
+
*/
|
|
72
|
+
export declare function withAlpha(color: string, alpha: number): string;
|
|
62
73
|
/**
|
|
63
74
|
* Per-series / per-slice colour: an alpha ramp off the accent so N series stay
|
|
64
|
-
* distinguishable AND on-theme without a hardcoded palette.
|
|
65
|
-
*
|
|
75
|
+
* distinguishable AND on-theme without a hardcoded palette. Emits ZRender-safe
|
|
76
|
+
* `rgb()`/`rgba()` so ECharts emphasis (`color.lift`) works on hover.
|
|
66
77
|
*/
|
|
67
78
|
export declare function seriesColor(accent: string, i: number): string;
|
|
68
79
|
/** A muted series: the secondary text colour, light enough to sit behind the accent. */
|
|
@@ -80,14 +80,78 @@ function makeFmt(locale: string): (value: number) => string {
|
|
|
80
80
|
return (value: number) => nf.format(value);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Parse a CSS hex (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`) or `rgb()`/`rgba()`
|
|
85
|
+
* string (comma or CSS Color 4 space/slash syntax) into `[r, g, b, a]`, or null
|
|
86
|
+
* if unrecognised.
|
|
87
|
+
*/
|
|
88
|
+
function parseRgb(color: string): [number, number, number, number] | null {
|
|
89
|
+
const s = color.trim();
|
|
90
|
+
if (s.startsWith("#")) {
|
|
91
|
+
const hex = s.slice(1);
|
|
92
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
93
|
+
const r = parseInt(hex[0] + hex[0], 16);
|
|
94
|
+
const g = parseInt(hex[1] + hex[1], 16);
|
|
95
|
+
const b = parseInt(hex[2] + hex[2], 16);
|
|
96
|
+
const a = hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1;
|
|
97
|
+
if ([r, g, b, a].every(Number.isFinite)) return [r, g, b, a];
|
|
98
|
+
} else if (hex.length === 6 || hex.length === 8) {
|
|
99
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
100
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
101
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
102
|
+
const a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
|
|
103
|
+
if ([r, g, b, a].every(Number.isFinite)) return [r, g, b, a];
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const m = s.match(
|
|
109
|
+
/^rgba?\(\s*([0-9.]+)\s*[,\s]\s*([0-9.]+)\s*[,\s]\s*([0-9.]+)(?:\s*[,/]\s*([0-9.]+%?))?\s*\)$/i,
|
|
110
|
+
);
|
|
111
|
+
if (!m) return null;
|
|
112
|
+
const r = Math.round(Number(m[1]));
|
|
113
|
+
const g = Math.round(Number(m[2]));
|
|
114
|
+
const b = Math.round(Number(m[3]));
|
|
115
|
+
let a = 1;
|
|
116
|
+
if (m[4] !== undefined) {
|
|
117
|
+
a = m[4].endsWith("%") ? parseFloat(m[4]) / 100 : Number(m[4]);
|
|
118
|
+
}
|
|
119
|
+
if (![r, g, b, a].every(Number.isFinite)) return null;
|
|
120
|
+
return [
|
|
121
|
+
Math.min(255, Math.max(0, r)),
|
|
122
|
+
Math.min(255, Math.max(0, g)),
|
|
123
|
+
Math.min(255, Math.max(0, b)),
|
|
124
|
+
Math.min(1, Math.max(0, a)),
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Apply an alpha multiplier to a CSS colour and emit ZRender-safe `rgb()` /
|
|
130
|
+
* `rgba()` syntax.
|
|
131
|
+
*
|
|
132
|
+
* Why NOT `color-mix(in srgb, ...)`: Canvas 2D draws `color-mix(...)` at rest,
|
|
133
|
+
* but ECharts 6 / ZRender computes hover (`emphasis`) colours in JS via
|
|
134
|
+
* `zrender/lib/tool/color.lift()`, whose parser only accepts `#hex`, `rgb()`,
|
|
135
|
+
* `rgba()`, `hsl()`, and named CSS colours. Passing `color-mix(...)` makes
|
|
136
|
+
* `lift()` return `undefined`, turning hovered bars/slices invisible.
|
|
137
|
+
*/
|
|
138
|
+
export function withAlpha(color: string, alpha: number): string {
|
|
139
|
+
const clamped = Math.min(1, Math.max(0, alpha));
|
|
140
|
+
const parsed = parseRgb(color);
|
|
141
|
+
if (!parsed) return color.trim();
|
|
142
|
+
const [r, g, b, baseA] = parsed;
|
|
143
|
+
const outA = Math.round(baseA * clamped * 1000) / 1000;
|
|
144
|
+
return outA >= 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${outA})`;
|
|
145
|
+
}
|
|
146
|
+
|
|
83
147
|
/**
|
|
84
148
|
* Per-series / per-slice colour: an alpha ramp off the accent so N series stay
|
|
85
|
-
* distinguishable AND on-theme without a hardcoded palette.
|
|
86
|
-
*
|
|
149
|
+
* distinguishable AND on-theme without a hardcoded palette. Emits ZRender-safe
|
|
150
|
+
* `rgb()`/`rgba()` so ECharts emphasis (`color.lift`) works on hover.
|
|
87
151
|
*/
|
|
88
152
|
export function seriesColor(accent: string, i: number): string {
|
|
89
153
|
const alpha = Math.max(0.35, 1 - i * 0.15);
|
|
90
|
-
return
|
|
154
|
+
return withAlpha(accent, alpha);
|
|
91
155
|
}
|
|
92
156
|
|
|
93
157
|
/** True when the chart should render as a pie/donut (single-measure mode). */
|
|
@@ -140,7 +204,7 @@ function buildPieOption(
|
|
|
140
204
|
|
|
141
205
|
/** A muted series: the secondary text colour, light enough to sit behind the accent. */
|
|
142
206
|
export function mutedColor(textSecondary: string): string {
|
|
143
|
-
return
|
|
207
|
+
return withAlpha(textSecondary, 0.35);
|
|
144
208
|
}
|
|
145
209
|
|
|
146
210
|
/** Map one shaped series → its ECharts series object. `i` counts accent series only. */
|
|
@@ -213,8 +277,7 @@ function bandArea(
|
|
|
213
277
|
return {
|
|
214
278
|
silent: true,
|
|
215
279
|
itemStyle: {
|
|
216
|
-
color:
|
|
217
|
-
tokens.band || `color-mix(in srgb, ${tokens.accent} 16%, transparent)`,
|
|
280
|
+
color: tokens.band || withAlpha(tokens.accent, 0.16),
|
|
218
281
|
},
|
|
219
282
|
label: {
|
|
220
283
|
show: Boolean(band.label),
|
|
@@ -303,7 +366,10 @@ function buildCartesianOption(
|
|
|
303
366
|
tooltip: {
|
|
304
367
|
...tooltipChrome(tokens),
|
|
305
368
|
trigger: "axis",
|
|
306
|
-
axisPointer: {
|
|
369
|
+
axisPointer: {
|
|
370
|
+
type: "shadow",
|
|
371
|
+
shadowStyle: { color: withAlpha(tokens.textSecondary, 0.08) },
|
|
372
|
+
},
|
|
307
373
|
formatter: (
|
|
308
374
|
ps: Array<{
|
|
309
375
|
axisValueLabel?: string;
|