@aparte/plugin-cards 0.0.0-stage → 0.29.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/LICENSE +21 -0
- package/README.md +148 -2
- package/dist/carousel-CPy-0JGN.js +63 -0
- package/dist/carousel-CPy-0JGN.js.map +1 -0
- package/dist/controls-BVX2u7sK.js +62 -0
- package/dist/controls-BVX2u7sK.js.map +1 -0
- package/dist/format-CchcJRum.js +720 -0
- package/dist/format-CchcJRum.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/items/icons.d.ts +12 -0
- package/dist/items/icons.d.ts.map +1 -0
- package/dist/items/index.d.ts +100 -0
- package/dist/items/index.d.ts.map +1 -0
- package/dist/items.js +698 -0
- package/dist/items.js.map +1 -0
- package/dist/kit/carousel.d.ts +17 -0
- package/dist/kit/carousel.d.ts.map +1 -0
- package/dist/kit/controls.d.ts +51 -0
- package/dist/kit/controls.d.ts.map +1 -0
- package/dist/kit/define.d.ts +194 -0
- package/dist/kit/define.d.ts.map +1 -0
- package/dist/kit/dom.d.ts +40 -0
- package/dist/kit/dom.d.ts.map +1 -0
- package/dist/kit/format.d.ts +49 -0
- package/dist/kit/format.d.ts.map +1 -0
- package/dist/kit/rating.d.ts +19 -0
- package/dist/kit/rating.d.ts.map +1 -0
- package/dist/kit/sparkline.d.ts +19 -0
- package/dist/kit/sparkline.d.ts.map +1 -0
- package/dist/kit/strings.d.ts +139 -0
- package/dist/kit/strings.d.ts.map +1 -0
- package/dist/link/icons.d.ts +16 -0
- package/dist/link/icons.d.ts.map +1 -0
- package/dist/link/index.d.ts +98 -0
- package/dist/link/index.d.ts.map +1 -0
- package/dist/link.js +387 -0
- package/dist/link.js.map +1 -0
- package/dist/media/icons.d.ts +28 -0
- package/dist/media/icons.d.ts.map +1 -0
- package/dist/media/index.d.ts +107 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media.js +610 -0
- package/dist/media.js.map +1 -0
- package/dist/order/icons.d.ts +49 -0
- package/dist/order/icons.d.ts.map +1 -0
- package/dist/order/index.d.ts +204 -0
- package/dist/order/index.d.ts.map +1 -0
- package/dist/order.js +1843 -0
- package/dist/order.js.map +1 -0
- package/dist/place/icons.d.ts +18 -0
- package/dist/place/icons.d.ts.map +1 -0
- package/dist/place/index.d.ts +207 -0
- package/dist/place/index.d.ts.map +1 -0
- package/dist/place.js +1456 -0
- package/dist/place.js.map +1 -0
- package/dist/plan/icons.d.ts +25 -0
- package/dist/plan/icons.d.ts.map +1 -0
- package/dist/plan/index.d.ts +153 -0
- package/dist/plan/index.d.ts.map +1 -0
- package/dist/plan.js +1191 -0
- package/dist/plan.js.map +1 -0
- package/dist/product/icons.d.ts +16 -0
- package/dist/product/icons.d.ts.map +1 -0
- package/dist/product/index.d.ts +133 -0
- package/dist/product/index.d.ts.map +1 -0
- package/dist/product.js +1245 -0
- package/dist/product.js.map +1 -0
- package/dist/rating-B8Mdx_b_.js +35 -0
- package/dist/rating-B8Mdx_b_.js.map +1 -0
- package/dist/score/icons.d.ts +35 -0
- package/dist/score/icons.d.ts.map +1 -0
- package/dist/score/index.d.ts +185 -0
- package/dist/score/index.d.ts.map +1 -0
- package/dist/score.js +1843 -0
- package/dist/score.js.map +1 -0
- package/dist/sparkline-C-cA9obz.js +56 -0
- package/dist/sparkline-C-cA9obz.js.map +1 -0
- package/dist/stats/icons.d.ts +19 -0
- package/dist/stats/icons.d.ts.map +1 -0
- package/dist/stats/index.d.ts +137 -0
- package/dist/stats/index.d.ts.map +1 -0
- package/dist/stats.js +1085 -0
- package/dist/stats.js.map +1 -0
- package/dist/stock/chart.d.ts +135 -0
- package/dist/stock/chart.d.ts.map +1 -0
- package/dist/stock/icons.d.ts +15 -0
- package/dist/stock/icons.d.ts.map +1 -0
- package/dist/stock/index.d.ts +195 -0
- package/dist/stock/index.d.ts.map +1 -0
- package/dist/stock.js +1013 -0
- package/dist/stock.js.map +1 -0
- package/dist/weather/conditions.d.ts +25 -0
- package/dist/weather/conditions.d.ts.map +1 -0
- package/dist/weather/icons.d.ts +12 -0
- package/dist/weather/icons.d.ts.map +1 -0
- package/dist/weather/index.d.ts +146 -0
- package/dist/weather/index.d.ts.map +1 -0
- package/dist/weather.js +1162 -0
- package/dist/weather.js.map +1 -0
- package/package.json +137 -3
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aparte/plugin-cards/stats — a tool's key figures, drawn as a card.
|
|
3
|
+
*
|
|
4
|
+
* import { setupStatsCard } from '@aparte/plugin-cards/stats';
|
|
5
|
+
*
|
|
6
|
+
* setupStatsCard({
|
|
7
|
+
* tool: 'get_sales_summary',
|
|
8
|
+
* map: (result) => ({ title: 'Sales this week', items: result.kpis }),
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* Three variants of one card: `tiles` (a grid of KPI tiles — label, big number, the change
|
|
12
|
+
* as a pill, a sparkline under it), `list` (a fact sheet: one row per figure, the value
|
|
13
|
+
* at the end, for five to twelve facts) and `hero` (the first figure large over a wide
|
|
14
|
+
* chart, the others as a row of small ones beneath).
|
|
15
|
+
*
|
|
16
|
+
* Your tool keeps its own fields: `readStats` reads a list of figures, one figure, a
|
|
17
|
+
* `{ title, items }` envelope, or a plain record — `{ Revenue: 12000, Orders: 340 }` — as
|
|
18
|
+
* label → value pairs; and the usual spellings of each field (`name` for `label`, `amount`
|
|
19
|
+
* or `count` for `value`, `delta` for `change`, `history` for `trend`). `map` covers the rest.
|
|
20
|
+
* A record's `currency` and `unit` are how its figures are written, never figures: the
|
|
21
|
+
* currency goes to the keys that name money (`revenue`, `avgOrderValue`, `mrr` — not
|
|
22
|
+
* `orders`, nor `refundRate`), the unit to the others, and a figure's own always wins.
|
|
23
|
+
*
|
|
24
|
+
* **How a change is read.** A change is a percentage unless `changeFormat: 'absolute'`
|
|
25
|
+
* says it is in the figure's own unit. A percentage given as a number follows one rule:
|
|
26
|
+
* at most 1 in size it is a ratio (`0.12` → +12 %), above that it is already in percent
|
|
27
|
+
* (`12` → +12 %). So `1` is +100 %; write `"1%"` — a string with its sign is never
|
|
28
|
+
* ambiguous — or use `changePercent`, which is always in percent, for one per cent.
|
|
29
|
+
* A `percent` figure's value follows the same rule.
|
|
30
|
+
*/
|
|
31
|
+
import type { AparteConfig } from '@aparte/core';
|
|
32
|
+
import { type CardSetupOptions } from '../kit/define.js';
|
|
33
|
+
import { STAT_ICONS } from './icons.js';
|
|
34
|
+
export type StatsVariant = 'tiles' | 'list' | 'hero';
|
|
35
|
+
/** How a figure's value is written. */
|
|
36
|
+
export type StatFormat = 'number' | 'percent' | 'currency' | 'compact' | 'duration' | 'text';
|
|
37
|
+
/** The glyphs a figure may wear beside its label. */
|
|
38
|
+
export type StatIcon = keyof typeof STAT_ICONS;
|
|
39
|
+
/**
|
|
40
|
+
* One figure as `map` returns it. Only `label` and `value` are needed; every other field
|
|
41
|
+
* adds a line when it is there and nothing when it is not.
|
|
42
|
+
*/
|
|
43
|
+
export interface StatInput {
|
|
44
|
+
label: string;
|
|
45
|
+
/** A number, or a short text (`"Gold"`, `"4.8/5"`). `"12%"` is read as a percentage. */
|
|
46
|
+
value: number | string;
|
|
47
|
+
/**
|
|
48
|
+
* `number` (the default), `percent` (see the rule above), `currency` (with `currency`),
|
|
49
|
+
* `compact` (`12K`, `1.2M`), `duration` (seconds → `1 hr 20 min`) or `text`.
|
|
50
|
+
*/
|
|
51
|
+
format?: StatFormat;
|
|
52
|
+
/** An ISO 4217 code (`EUR`) or a usual symbol (`€`); alone, it makes the figure a sum. */
|
|
53
|
+
currency?: string;
|
|
54
|
+
/** An `Intl` unit (`kilometer`, `megabyte`, `kilometer-per-hour`), or any text, appended. */
|
|
55
|
+
unit?: string;
|
|
56
|
+
/** Decimals shown, 0–6. */
|
|
57
|
+
digits?: number;
|
|
58
|
+
/** The change: a percentage (the rule above) or, with `changeFormat: 'absolute'`, in the figure's unit. */
|
|
59
|
+
change?: number | string;
|
|
60
|
+
changeFormat?: 'percent' | 'absolute';
|
|
61
|
+
/** What the change compares with: "vs last week". */
|
|
62
|
+
changeLabel?: string;
|
|
63
|
+
/** Which way is good — it colours the change green or red, and says which to a screen reader. Without it the change is neutral. */
|
|
64
|
+
good?: 'up' | 'down';
|
|
65
|
+
/** Past values, oldest first, for the sparkline. */
|
|
66
|
+
trend?: number[];
|
|
67
|
+
/** One short line under the figure. */
|
|
68
|
+
hint?: string;
|
|
69
|
+
icon?: StatIcon;
|
|
70
|
+
}
|
|
71
|
+
/** What `map` returns: figures with a heading, a list of them, one figure, or a record of label → value. */
|
|
72
|
+
export type StatsInput = {
|
|
73
|
+
title?: string;
|
|
74
|
+
subtitle?: string;
|
|
75
|
+
items: StatInput[];
|
|
76
|
+
footnote?: string;
|
|
77
|
+
updatedAt?: string | number | Date;
|
|
78
|
+
} | StatInput[] | StatInput | Record<string, number | string>;
|
|
79
|
+
/** One figure as the card draws it, once read. */
|
|
80
|
+
export interface Stat {
|
|
81
|
+
label: string;
|
|
82
|
+
/** A number in the scale it is drawn in (a `percent` figure's is a ratio), or — for `text` — a text drawn as given. */
|
|
83
|
+
value: number | string;
|
|
84
|
+
/** `text` exactly when `value` is a string; never `currency` without a currency. */
|
|
85
|
+
format: StatFormat;
|
|
86
|
+
/** An ISO 4217 code. */
|
|
87
|
+
currency?: string;
|
|
88
|
+
unit?: string;
|
|
89
|
+
digits?: number;
|
|
90
|
+
/** A ratio for a `percent` change; in the value's own scale for an `absolute` one. */
|
|
91
|
+
change?: number;
|
|
92
|
+
changeFormat: 'percent' | 'absolute';
|
|
93
|
+
changeLabel?: string;
|
|
94
|
+
good?: 'up' | 'down';
|
|
95
|
+
/** Two points at least, finite. */
|
|
96
|
+
trend?: number[];
|
|
97
|
+
hint?: string;
|
|
98
|
+
icon?: StatIcon;
|
|
99
|
+
}
|
|
100
|
+
/** The data as the card draws it. */
|
|
101
|
+
export interface StatsData {
|
|
102
|
+
title?: string;
|
|
103
|
+
subtitle?: string;
|
|
104
|
+
items: Stat[];
|
|
105
|
+
footnote?: string;
|
|
106
|
+
updatedAt?: Date;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `key` as a label when a record gave it: `conversionRate` → "Conversion rate",
|
|
110
|
+
* `avg_order_value` → "Avg order value". A key already written for people — with a space,
|
|
111
|
+
* or a single word in capitals like `MRR` — is kept as it is.
|
|
112
|
+
*/
|
|
113
|
+
export declare function humanizeKey(key: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* The card's data from the loose shape `map` returns — a `{ title, items }` envelope (also
|
|
116
|
+
* `stats`, `metrics`, `kpis`, `figures`), a list of figures, one figure, or a record of
|
|
117
|
+
* label → value pairs (`{ Revenue: 12000 }`, or `{ Revenue: { value: 12000, change: 0.1 } }`)
|
|
118
|
+
* — or `null` when not one figure has a label and a value. At most twelve are kept.
|
|
119
|
+
*/
|
|
120
|
+
export declare function readStats(raw: unknown): StatsData | null;
|
|
121
|
+
/** The figure's value as drawn: its number in its format, or its text. */
|
|
122
|
+
export declare function statValue(config: AparteConfig, stat: Stat): string;
|
|
123
|
+
/** The change as drawn, signed: `+12%`, `−3.5%`, or `+€1,200` for an absolute one. */
|
|
124
|
+
export declare function statChange(config: AparteConfig, stat: Stat): string | undefined;
|
|
125
|
+
export declare const statsCard: {
|
|
126
|
+
name: string;
|
|
127
|
+
variants: readonly StatsVariant[];
|
|
128
|
+
setup: (options?: CardSetupOptions<StatsData, StatsVariant>) => () => void;
|
|
129
|
+
segment: (raw: unknown, options?: {
|
|
130
|
+
id?: string;
|
|
131
|
+
variant?: StatsVariant | undefined;
|
|
132
|
+
config?: AparteConfig;
|
|
133
|
+
}) => import("../index.js").AparteCardSegment;
|
|
134
|
+
};
|
|
135
|
+
/** Draw a tool's key figures as this card — returns the function that stops it. */
|
|
136
|
+
export declare function setupStatsCard(options?: CardSetupOptions<StatsData, StatsVariant>): () => void;
|
|
137
|
+
//# sourceMapping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