@omem-ai/plugin-sdk 0.0.1 → 0.0.2

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.
@@ -0,0 +1,125 @@
1
+ /**
2
+ * omem's charts and figures, drawn without a framework (docs/v2/interactive-ui.md, “图表的样子”).
3
+ * One drawing for every place that shows a chart: component blocks (blocks.ts, so agents' `show`
4
+ * and plugin pages), and omem's own pages through the thin Vue components in
5
+ * web/src/components/charts/. Feishu cards cannot run this; src/channels/lark-ui.ts builds a VChart
6
+ * spec in the same colours.
7
+ *
8
+ * The look is “countable units”: the unit a reader would count is drawn as a mark of its own.
9
+ * - Columns are ladders of thin rungs, one rung a unit (or a round number of units, said under the
10
+ * chart), every fifth rung heavier; the value is written on top.
11
+ * - Rows are runs of short upright ticks, the value at the end of the run.
12
+ * - A line has a dot per point (hollow on weekends for days), a barcode of one tick per label on its
13
+ * floor, and its highest and last points written beside a larger dot.
14
+ * - An area is a hairline per point from the floor up to an outline, the peak's hairline drawn in.
15
+ * - Shares are a dial of a hundred ticks, one tick a percent, coloured by part, named around the rim.
16
+ * - Figures are large numbers under a small spaced label, with a course drawn the same way.
17
+ * Colour: one series is the blue ramp (`--chart-seq-*`); several are the categorical slots
18
+ * `--chart-1`…`--chart-8`, named on the chart; `--chart-accent` marks the one thing to look at (the
19
+ * highlighted label, a peak, what passes a goal). No frames, no fills behind the marks.
20
+ * Motion: when a chart first comes into view its marks are drawn in once (rungs climb, lines are
21
+ * stroked, hairlines rise, the dial sweeps, numbers count up), about a second, never looping; not at
22
+ * all under `prefers-reduced-motion`, inside `[data-chart-still]`, with `<html data-chart-motion="off">`
23
+ * or after `setChartMotion(false)`. On hover the pointed mark stays and the rest fade.
24
+ * Every chart can be read without colour or pointer: values on the marks, a tooltip that the arrow
25
+ * keys step through, and the numbers as a table (“看数据”).
26
+ *
27
+ * Text goes in through textContent only. Colours are CSS variables only.
28
+ */
29
+ export type ChartSeries = {
30
+ name: string;
31
+ values: number[];
32
+ /** Colour slot (0–7). Defaults to the series' position; give it when a series must keep its colour while others come and go. */
33
+ slot?: number;
34
+ /** Per label: where this series' value at that label is listed (omem's own pages). */
35
+ links?: (string | undefined)[];
36
+ };
37
+ export type ChartSpec = {
38
+ title?: string;
39
+ kind: "bar" | "line" | "area" | "hbar" | "pie";
40
+ labels: string[];
41
+ series: ChartSeries[];
42
+ stack?: boolean;
43
+ goal?: number;
44
+ unit?: string;
45
+ note?: string;
46
+ /** A label to emphasise: its mark in the accent colour with the value written beside it. */
47
+ highlight?: string;
48
+ /** What one mark is, under the title (“一根一天”). */
49
+ caption?: string;
50
+ /** Per label: where its records are listed (a row of a ranking, a day). */
51
+ links?: (string | undefined)[];
52
+ /** hbar only: columns of another unit after the bars, as text. */
53
+ extras?: {
54
+ name: string;
55
+ values: string[];
56
+ links?: (string | undefined)[];
57
+ }[];
58
+ /** The numbers as a table under the chart (default on). */
59
+ table?: boolean;
60
+ };
61
+ /** `good`: which way is good news (up by default); `trend` is read off the change's sign when not given; `spark` is its recent course. */
62
+ export type MetricItem = {
63
+ label: string;
64
+ value: string | number;
65
+ unit?: string;
66
+ change?: string;
67
+ trend?: "up" | "down" | "flat";
68
+ good?: "up" | "down" | "none";
69
+ note?: string;
70
+ spark?: number[];
71
+ /** Where the figure's records are listed (omem's own pages). */
72
+ link?: string;
73
+ /** A longer explanation, shown on hover. */
74
+ hint?: string;
75
+ /** A short word beside the label in a warm pill (“待确认”). */
76
+ tag?: string;
77
+ /** No number yet: this line (“还没取到 · 下次 02:50”) stands where the number would, at its height, instead of a dash. */
78
+ pending?: string;
79
+ };
80
+ /** `even`: every figure the same shape — the label at most two lines, the line under the number one — so a grid of many lines up. */
81
+ export type MetricGroup = {
82
+ title?: string;
83
+ items: MetricItem[];
84
+ note?: string;
85
+ even?: boolean;
86
+ };
87
+ /** `select`: every figure is a button that opens its details (omem's own pages); the page marks the open one with `aria-expanded`. */
88
+ export type MetricsOptions = {
89
+ select?: (index: number) => void;
90
+ };
91
+ export declare function ensureChartStyle(doc: Document): void;
92
+ /** Turn the entrance motion off (or back on) for charts drawn from now on, e.g. for screenshots. */
93
+ export declare function setChartMotion(on: boolean): void;
94
+ /** Every digit of a value (tooltips, the data table). */
95
+ export declare const full: (n: number) => string;
96
+ /** A value where room is short (labels on marks, a dial's total): 1.2万, 3.4亿. */
97
+ export declare function compact(n: number): string;
98
+ /** Seconds read as seconds only when they are few (a duration written on a bar). */
99
+ export declare function withUnit(v: number, unit?: string, short?: boolean): string;
100
+ /**
101
+ * How much one rung (or tick) is worth: one unit while the largest value is small enough to count
102
+ * (at most `most` of them), else the smallest of 1, 2, 5 × 10ⁿ that keeps it to `most`, so the
103
+ * largest mark has about half to all of that many.
104
+ */
105
+ export declare function rungUnit(largest: number, whole: boolean, most?: number): number;
106
+ /** A hundred ticks shared out by value (largest remainder), every part above zero getting at least one. */
107
+ export declare function dialTicks(values: number[], ticks?: number): number[];
108
+ /**
109
+ * A smooth line through the points that never overshoots them (monotone cubic): it does not dip
110
+ * below zero between two zeros or rise above a peak, so the curve shows no value the data lacks.
111
+ */
112
+ export declare function curve(pts: [number, number][]): string;
113
+ /** A series' colour among several: its slot, else its position. */
114
+ export declare const seriesColor: (ser: Pick<ChartSeries, "slot"> | undefined, i: number) => string;
115
+ /**
116
+ * Draw a chart into `el` (replacing what is there) at the width it gets, redrawn when that changes.
117
+ * Returns a function that stops following the width.
118
+ */
119
+ export declare function mountChart(el: HTMLElement, spec: ChartSpec): () => void;
120
+ /** Which way a metric moved: as given, else read off the start of its change (src/agents/ui-blocks.ts, metricTrend). */
121
+ export declare function trendOf(m: Pick<MetricItem, "trend" | "change">): "up" | "down" | "flat" | null;
122
+ /** A recent course drawn like an area: a hairline per value up to a thin line, a dot on the last value. */
123
+ export declare function sparkline(doc: Document, values: number[], label?: string): SVGElement;
124
+ /** A row of figures divided by hairlines: as even as the count allows (up to four in a row), two to a row when narrow. Numbers count up when first seen. */
125
+ export declare function metricsElement(doc: Document, g: MetricGroup, opts?: MetricsOptions): HTMLElement;