@flesler/cursor-canvas-web 1.0.2 → 1.1.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/README.md +9 -8
- package/dist/cursor-canvas.cjs +1 -1
- package/dist/cursor-canvas.js +702 -746
- package/dist/host-tokens-Cjzmp0z_.cjs +1 -0
- package/dist/host-tokens-Dh2BFFjv.js +412 -0
- package/dist/runtime/index.d.ts +5 -7
- package/dist/runtime.cjs +5 -1
- package/dist/runtime.js +109 -14
- package/package.json +22 -13
- package/src/vendor/canvas/SKILL.md +113 -0
- package/src/vendor/canvas-sdk/callout-tone-icons.d.ts +10 -0
- package/src/vendor/canvas-sdk/canvas-tokens.d.ts +259 -0
- package/src/vendor/canvas-sdk/chart-primitives.d.ts +272 -0
- package/src/vendor/canvas-sdk/collapsible-section.d.ts +66 -0
- package/src/vendor/canvas-sdk/dag-layout.d.ts +101 -0
- package/src/vendor/canvas-sdk/diff-view.d.ts +129 -0
- package/src/vendor/canvas-sdk/form-primitives.d.ts +194 -0
- package/src/vendor/canvas-sdk/hooks.d.ts +173 -0
- package/src/vendor/canvas-sdk/index.d.ts +65 -0
- package/src/vendor/canvas-sdk/internal/canvas-action-dispatch.d.ts +17 -0
- package/src/vendor/canvas-sdk/manifest.json +5 -0
- package/src/vendor/canvas-sdk/swatch.d.ts +39 -0
- package/src/vendor/canvas-sdk/theme.d.ts +107 -0
- package/src/vendor/canvas-sdk/todo-list.d.ts +48 -0
- package/src/vendor/canvas-sdk/ui-primitives.d.ts +569 -0
- package/src/vendor/canvas-sdk/usage-bar.d.ts +55 -0
- package/dist/shim/charts.d.ts +0 -66
- package/dist/shim/cursor-canvas.d.ts +0 -278
- package/dist/shim/dag.d.ts +0 -55
- package/dist/shim/diff.d.ts +0 -23
- package/dist/shim/theme.d.ts +0 -323
- package/dist/shim/todo.d.ts +0 -22
- package/dist/shim/use-tokens.d.ts +0 -6
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart primitives for `cursor/canvas` — multi-series, stacked, and pie charts
|
|
3
|
+
* rendered as pure inline SVG with zero external dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Distilled from the portal-website Highcharts analytics charting layer.
|
|
6
|
+
*/
|
|
7
|
+
import type { CSSProperties, JSX } from "react";
|
|
8
|
+
/**
|
|
9
|
+
* Semantic tone for a chart series or slice. Mirrors the tone vocabulary
|
|
10
|
+
* used by `Stat`, `Callout`, and `Table` `rowTone` so colors match across
|
|
11
|
+
* a canvas — e.g. a `Stat tone="success"` and a `ChartSeries tone="success"`
|
|
12
|
+
* render in the same green. `Pill` does not share this vocabulary.
|
|
13
|
+
*
|
|
14
|
+
* Omit `tone` to let the chart auto-assign a distinct color from the
|
|
15
|
+
* chart palette; supply `tone` only when the value carries semantic
|
|
16
|
+
* meaning that should match other tonal elements on the page.
|
|
17
|
+
*/
|
|
18
|
+
export type ChartTone = "success" | "danger" | "warning" | "info" | "neutral";
|
|
19
|
+
/** A single labeled value, used by `PieChart`. */
|
|
20
|
+
export type ChartDataPoint = {
|
|
21
|
+
label: string;
|
|
22
|
+
/** Non-negative numeric value. */
|
|
23
|
+
value: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A named data series for `BarChart` and `LineChart`.
|
|
27
|
+
* The `data` array aligns by index with the parent component's `categories`.
|
|
28
|
+
* If `tone` is omitted, a color is auto-assigned from the chart palette.
|
|
29
|
+
*/
|
|
30
|
+
export type ChartSeries = {
|
|
31
|
+
name: string;
|
|
32
|
+
/** Values aligned with `categories`. Must be numbers, not numeric strings. */
|
|
33
|
+
data: number[];
|
|
34
|
+
tone?: ChartTone;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A dashed marker line drawn across the plot at a fixed value — for targets,
|
|
38
|
+
* SLOs, budgets, means, or limits. Drawn horizontally on line / vertical-bar
|
|
39
|
+
* charts and vertically on `horizontal` bar charts; either way it marks the
|
|
40
|
+
* value axis and is folded into the auto domain so it stays on-canvas.
|
|
41
|
+
*/
|
|
42
|
+
export type ChartReferenceLine = {
|
|
43
|
+
/** Position on the value axis, in the same units as the series data. */
|
|
44
|
+
value: number;
|
|
45
|
+
/** Short label drawn in a chip at the line's end. */
|
|
46
|
+
label?: string;
|
|
47
|
+
/** Line color. Omit for a muted neutral; set to match other tonal elements. */
|
|
48
|
+
tone?: ChartTone;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Shared value-axis controls (the y-axis, or the x-axis on `horizontal` bar
|
|
52
|
+
* charts). By default the axis starts at zero; override to zoom into a tight
|
|
53
|
+
* range. On stacked / normalized bars these are ignored — those always start
|
|
54
|
+
* at zero.
|
|
55
|
+
*/
|
|
56
|
+
type ValueAxisProps = {
|
|
57
|
+
/**
|
|
58
|
+
* Start the value axis at zero. Defaults to `true`. Set `false` to
|
|
59
|
+
* auto-fit the axis to the data range — useful for tightly-clustered
|
|
60
|
+
* series (e.g. uptime 99.0–99.9%) that a zero baseline would flatten.
|
|
61
|
+
*/
|
|
62
|
+
beginAtZero?: boolean;
|
|
63
|
+
/** Explicit axis minimum. Overrides `beginAtZero`. */
|
|
64
|
+
yMin?: number;
|
|
65
|
+
/** Explicit axis maximum. */
|
|
66
|
+
yMax?: number;
|
|
67
|
+
/** Horizontal marker lines for targets / thresholds / means. */
|
|
68
|
+
referenceLines?: ChartReferenceLine[];
|
|
69
|
+
};
|
|
70
|
+
export type BarChartProps = ValueAxisProps & {
|
|
71
|
+
/** Category labels along the independent axis. */
|
|
72
|
+
categories: string[];
|
|
73
|
+
/** One or more data series. Values align by index with `categories`. */
|
|
74
|
+
series: ChartSeries[];
|
|
75
|
+
height?: number;
|
|
76
|
+
/** Stack series on top of each other instead of grouping side-by-side. */
|
|
77
|
+
stacked?: boolean;
|
|
78
|
+
/** Render horizontal bars instead of vertical columns. */
|
|
79
|
+
horizontal?: boolean;
|
|
80
|
+
/** Show as 100% stacked (implies `stacked`). */
|
|
81
|
+
normalized?: boolean;
|
|
82
|
+
/** Suffix for value labels (e.g. "%", " ms"). */
|
|
83
|
+
valueSuffix?: string;
|
|
84
|
+
/** Prefix for value labels (e.g. "$"). Ignored in `normalized` mode. */
|
|
85
|
+
valuePrefix?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Print each bar's value as a label. Defaults to auto: on for a single
|
|
88
|
+
* series with ≤8 categories, off otherwise. Set `true` to force labels on
|
|
89
|
+
* (e.g. grouped multi-series), or `false` to force them off. No effect on
|
|
90
|
+
* `stacked` / `normalized` charts — use the hover tooltip there.
|
|
91
|
+
*/
|
|
92
|
+
showValues?: boolean;
|
|
93
|
+
style?: CSSProperties;
|
|
94
|
+
};
|
|
95
|
+
export type LineChartProps = ValueAxisProps & {
|
|
96
|
+
categories: string[];
|
|
97
|
+
series: ChartSeries[];
|
|
98
|
+
height?: number;
|
|
99
|
+
/** Fill the area under each line with a soft tint. */
|
|
100
|
+
fill?: boolean;
|
|
101
|
+
/** Suffix for value labels (e.g. "%", " ms"). */
|
|
102
|
+
valueSuffix?: string;
|
|
103
|
+
/** Prefix for value labels (e.g. "$"). */
|
|
104
|
+
valuePrefix?: string;
|
|
105
|
+
/** Print the value next to every data point (≤20 categories). */
|
|
106
|
+
showValues?: boolean;
|
|
107
|
+
/** Draw a vertical guide through the cursor while hovering. Defaults to `true`. */
|
|
108
|
+
showHoverGuide?: boolean;
|
|
109
|
+
style?: CSSProperties;
|
|
110
|
+
};
|
|
111
|
+
export type PieChartProps = {
|
|
112
|
+
data: Array<ChartDataPoint & {
|
|
113
|
+
tone?: ChartTone;
|
|
114
|
+
}>;
|
|
115
|
+
/** Diameter in px. Defaults to 200. */
|
|
116
|
+
size?: number;
|
|
117
|
+
/** Render as a donut with the summed total shown in the hollow center. */
|
|
118
|
+
donut?: boolean;
|
|
119
|
+
style?: CSSProperties;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Multi-series bar/column chart with optional stacking and normalization.
|
|
123
|
+
* Distilled from the portal-website Highcharts analytics charts.
|
|
124
|
+
*
|
|
125
|
+
* Pass `categories` for x-axis labels and one or more `series` whose `data`
|
|
126
|
+
* arrays align by index. With a single series you get simple bars; with
|
|
127
|
+
* multiple series the default is grouped (side-by-side) — set `stacked` for
|
|
128
|
+
* stacked columns or `normalized` for 100%-stacked share-mode.
|
|
129
|
+
*
|
|
130
|
+
* Colors are auto-assigned from the chart palette. With a **single series**,
|
|
131
|
+
* each bar gets a different color by category (so a chart of 5 categories
|
|
132
|
+
* shows 5 colors out of the box). With **multiple series**, each series gets
|
|
133
|
+
* its own color. A legend appears when there are 2+ series.
|
|
134
|
+
*
|
|
135
|
+
* For semantic coloring, pass `tone` on a series — it maps to the same
|
|
136
|
+
* palette entries used by `Stat`, `Pill`, and `Table` so your chart matches
|
|
137
|
+
* tonal elements elsewhere on the page.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```tsx
|
|
141
|
+
* // Simple single-series
|
|
142
|
+
* <BarChart
|
|
143
|
+
* categories={["Mon", "Tue", "Wed"]}
|
|
144
|
+
* series={[{ name: "Requests", data: [120, 90, 150] }]}
|
|
145
|
+
* />
|
|
146
|
+
*
|
|
147
|
+
* // Stacked multi-series (like portal AI commit chart)
|
|
148
|
+
* <BarChart
|
|
149
|
+
* categories={["Mon", "Tue", "Wed"]}
|
|
150
|
+
* series={[
|
|
151
|
+
* { name: "IDE", data: [120, 90, 150] },
|
|
152
|
+
* { name: "CLI", data: [30, 40, 25] },
|
|
153
|
+
* { name: "Cloud", data: [50, 60, 70] },
|
|
154
|
+
* ]}
|
|
155
|
+
* stacked
|
|
156
|
+
* />
|
|
157
|
+
*
|
|
158
|
+
* // Semantic tones — "accepted" renders in the same green as
|
|
159
|
+
* // <Stat tone="success"> elsewhere on the page.
|
|
160
|
+
* <BarChart
|
|
161
|
+
* categories={["Mon", "Tue", "Wed"]}
|
|
162
|
+
* series={[
|
|
163
|
+
* { name: "Accepted", data: [70, 80, 60], tone: "success" },
|
|
164
|
+
* { name: "Rejected", data: [30, 20, 40], tone: "danger" },
|
|
165
|
+
* ]}
|
|
166
|
+
* stacked
|
|
167
|
+
* />
|
|
168
|
+
*
|
|
169
|
+
* // Mark a target with a reference line. Grouped/single bars also accept
|
|
170
|
+
* // `yMin` / `yMax` to frame the axis (stacked bars stay zero-based).
|
|
171
|
+
* <BarChart
|
|
172
|
+
* categories={["Mon", "Tue", "Wed", "Thu", "Fri"]}
|
|
173
|
+
* series={[{ name: "Latency", data: [180, 210, 240, 200, 220] }]}
|
|
174
|
+
* valueSuffix=" ms"
|
|
175
|
+
* referenceLines={[{ value: 200, label: "Budget", tone: "warning" }]}
|
|
176
|
+
* />
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function BarChart({ categories, series, height, stacked, horizontal, normalized, valueSuffix, valuePrefix, showValues, beginAtZero, yMin, yMax, referenceLines, style, }: BarChartProps): JSX.Element;
|
|
180
|
+
/**
|
|
181
|
+
* Multi-series line chart with optional area fill. Distilled from the
|
|
182
|
+
* portal-website Highcharts analytics charts.
|
|
183
|
+
*
|
|
184
|
+
* Each series draws a polyline with dot markers at each data point.
|
|
185
|
+
* Set `fill` to shade the area under every line. Hover over any category
|
|
186
|
+
* column to see a tooltip with all series values and a vertical cursor guide.
|
|
187
|
+
*
|
|
188
|
+
* This is **not** a time-series component — it does not parse dates.
|
|
189
|
+
* Pass pre-formatted date strings as `categories` if plotting over time.
|
|
190
|
+
*
|
|
191
|
+
* Colors are auto-assigned from the chart palette. For semantic coloring,
|
|
192
|
+
* pass `tone` on a series — it maps to the same palette entries used by
|
|
193
|
+
* `Stat`, `Pill`, and `Table`.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* // Single line
|
|
198
|
+
* <LineChart
|
|
199
|
+
* categories={["Jan", "Feb", "Mar", "Apr"]}
|
|
200
|
+
* series={[{ name: "Revenue", data: [100, 140, 120, 180] }]}
|
|
201
|
+
* />
|
|
202
|
+
*
|
|
203
|
+
* // Multi-series with area fill
|
|
204
|
+
* <LineChart
|
|
205
|
+
* categories={["Jan", "Feb", "Mar", "Apr"]}
|
|
206
|
+
* series={[
|
|
207
|
+
* { name: "Accepted", data: [50, 70, 60, 90] },
|
|
208
|
+
* { name: "Suggested", data: [120, 140, 130, 160] },
|
|
209
|
+
* ]}
|
|
210
|
+
* fill
|
|
211
|
+
* />
|
|
212
|
+
*
|
|
213
|
+
* // Semantic tones — "errors" renders in the same red as a
|
|
214
|
+
* // <Stat tone="danger"> or <Callout tone="danger"> elsewhere on the page.
|
|
215
|
+
* <LineChart
|
|
216
|
+
* categories={["00:00", "06:00", "12:00", "18:00"]}
|
|
217
|
+
* series={[
|
|
218
|
+
* { name: "p95 latency", data: [80, 95, 110, 90], tone: "info" },
|
|
219
|
+
* { name: "errors", data: [2, 4, 9, 3], tone: "danger" },
|
|
220
|
+
* ]}
|
|
221
|
+
* />
|
|
222
|
+
*
|
|
223
|
+
* // Zoom into a tight range and mark an SLO. `beginAtZero={false}`
|
|
224
|
+
* // auto-fits the axis; `referenceLines` draws the target.
|
|
225
|
+
* <LineChart
|
|
226
|
+
* categories={["Mon", "Tue", "Wed", "Thu", "Fri"]}
|
|
227
|
+
* series={[{ name: "Uptime", data: [99.91, 99.95, 99.7, 99.99, 99.96] }]}
|
|
228
|
+
* valueSuffix="%"
|
|
229
|
+
* beginAtZero={false}
|
|
230
|
+
* referenceLines={[{ value: 99.9, label: "SLO", tone: "danger" }]}
|
|
231
|
+
* />
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare function LineChart({ categories, series, height, fill, valueSuffix, valuePrefix, showValues, showHoverGuide, beginAtZero, yMin, yMax, referenceLines, style, }: LineChartProps): JSX.Element;
|
|
235
|
+
/**
|
|
236
|
+
* Pie (or donut) chart with hover highlighting. Distilled from the
|
|
237
|
+
* portal-website Highcharts analytics charts.
|
|
238
|
+
*
|
|
239
|
+
* Unlike `BarChart` and `LineChart`, `PieChart` takes a flat `data` array of
|
|
240
|
+
* `{ label, value }` points — each slice is its own category. Colors are
|
|
241
|
+
* auto-assigned from the chart palette; pass `tone` on a point to give a
|
|
242
|
+
* slice a semantic color that matches other tonal elements on the page.
|
|
243
|
+
*
|
|
244
|
+
* Hovering a slice expands it outward and dims the others; hovering a legend
|
|
245
|
+
* item does the same. A tooltip with value and percentage appears below the
|
|
246
|
+
* chart. Set `donut` for a hollow center that shows the summed total.
|
|
247
|
+
*
|
|
248
|
+
* **Do not** use for bar-style comparisons — use `BarChart` instead.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```tsx
|
|
252
|
+
* // Basic pie
|
|
253
|
+
* <PieChart
|
|
254
|
+
* data={[
|
|
255
|
+
* { label: "IDE", value: 120 },
|
|
256
|
+
* { label: "CLI", value: 30 },
|
|
257
|
+
* { label: "Cloud", value: 50 },
|
|
258
|
+
* ]}
|
|
259
|
+
* />
|
|
260
|
+
*
|
|
261
|
+
* // Donut with semantic tones
|
|
262
|
+
* <PieChart
|
|
263
|
+
* data={[
|
|
264
|
+
* { label: "Passing", value: 70, tone: "success" },
|
|
265
|
+
* { label: "Failing", value: 30, tone: "danger" },
|
|
266
|
+
* ]}
|
|
267
|
+
* donut
|
|
268
|
+
* />
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export declare function PieChart({ data, size, donut, style, }: PieChartProps): JSX.Element;
|
|
272
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Borderless disclosure row — chevron + structured header (title, optional
|
|
3
|
+
* leading slot, count, trailing slot) with a body that toggles open. Distilled
|
|
4
|
+
* from baby-glass `ContextTreeRow`'s lightweight list-row chrome (no card
|
|
5
|
+
* border, no background fill).
|
|
6
|
+
*
|
|
7
|
+
* For a bordered surface that collapses, use `<Card collapsible>` instead.
|
|
8
|
+
*/
|
|
9
|
+
import { type CSSProperties, type JSX, type ReactNode } from "react";
|
|
10
|
+
export type CollapsibleSectionProps = {
|
|
11
|
+
/** Plain-text title rendered next to the disclosure chevron. */
|
|
12
|
+
title: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional leading visual (e.g. `<Swatch>`) shown between the chevron and
|
|
15
|
+
* the title.
|
|
16
|
+
*/
|
|
17
|
+
leading?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* Optional small count rendered after the title (e.g. number of children).
|
|
20
|
+
*/
|
|
21
|
+
count?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Optional trailing node, right-aligned (e.g. token readout, badge, button).
|
|
24
|
+
* Rendered with `t.text.tertiary` color hint via the wrapper; the slot can
|
|
25
|
+
* override.
|
|
26
|
+
*/
|
|
27
|
+
trailing?: ReactNode;
|
|
28
|
+
/** Body shown when expanded. */
|
|
29
|
+
children?: ReactNode;
|
|
30
|
+
/** When true, the section starts expanded (uncontrolled). */
|
|
31
|
+
defaultOpen?: boolean;
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Borderless collapsible row with a structured header. Starts closed unless
|
|
36
|
+
* `defaultOpen` is set.
|
|
37
|
+
*
|
|
38
|
+
* Compose with `<Swatch>` in the `leading` slot for a colored category icon,
|
|
39
|
+
* and put a token readout / pill / button in `trailing`. Body content is
|
|
40
|
+
* indented under the row so nested `CollapsibleSection`s read as a tree.
|
|
41
|
+
*
|
|
42
|
+
* For a bordered, card-shaped collapsible surface, use `<Card collapsible>`
|
|
43
|
+
* instead — `CollapsibleSection` has no border or background and is meant to
|
|
44
|
+
* sit in a list of similar rows.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* // Basic
|
|
49
|
+
* <CollapsibleSection title="Conversation">
|
|
50
|
+
* <Text>Messages go here.</Text>
|
|
51
|
+
* </CollapsibleSection>
|
|
52
|
+
*
|
|
53
|
+
* // With a colored category swatch + count + trailing token readout
|
|
54
|
+
* <CollapsibleSection
|
|
55
|
+
* title="Tools"
|
|
56
|
+
* count={4}
|
|
57
|
+
* leading={<Swatch color="purple" />}
|
|
58
|
+
* trailing={<Text size="small" tone="tertiary">12.3k</Text>}
|
|
59
|
+
* >
|
|
60
|
+
* <CollapsibleSection title="Grep">
|
|
61
|
+
* <Text>Search results.</Text>
|
|
62
|
+
* </CollapsibleSection>
|
|
63
|
+
* </CollapsibleSection>
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function CollapsibleSection({ title, leading, count, trailing, children, defaultOpen, style, }: CollapsibleSectionProps): JSX.Element;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure layout math for directed acyclic graphs. Returns positioned node
|
|
3
|
+
* coordinates, edge anchor points, rank bounding boxes, and back-edge flags.
|
|
4
|
+
* Rendering is the caller's responsibility.
|
|
5
|
+
*
|
|
6
|
+
* Handles cycles gracefully: back-edges are detected via DFS, excluded from
|
|
7
|
+
* ranking, and flagged in the output so the caller can render them differently
|
|
8
|
+
* (e.g. dashed arcs).
|
|
9
|
+
*/
|
|
10
|
+
export type DAGLayoutOptions = {
|
|
11
|
+
/** Nodes to lay out. Only `id` is required. */
|
|
12
|
+
nodes: Array<{
|
|
13
|
+
id: string;
|
|
14
|
+
}>;
|
|
15
|
+
/** Directed edges. */
|
|
16
|
+
edges: Array<{
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
}>;
|
|
20
|
+
/** Flow direction. Default `"vertical"` (top-to-bottom). */
|
|
21
|
+
direction?: "vertical" | "horizontal";
|
|
22
|
+
/** Node box width in px. Default 160. */
|
|
23
|
+
nodeWidth?: number;
|
|
24
|
+
/** Node box height in px. Default 40. */
|
|
25
|
+
nodeHeight?: number;
|
|
26
|
+
/** Gap between ranks (layers) in px. Default 64. */
|
|
27
|
+
rankGap?: number;
|
|
28
|
+
/** Gap between sibling nodes in the same rank in px. Default 48. */
|
|
29
|
+
nodeGap?: number;
|
|
30
|
+
/** Padding around the bounding box in px. Default 24. */
|
|
31
|
+
padding?: number;
|
|
32
|
+
};
|
|
33
|
+
export type DAGLayoutNode = {
|
|
34
|
+
id: string;
|
|
35
|
+
/** Left edge of the node box. */
|
|
36
|
+
x: number;
|
|
37
|
+
/** Top edge of the node box. */
|
|
38
|
+
y: number;
|
|
39
|
+
/** Layer index (0 = root). */
|
|
40
|
+
rank: number;
|
|
41
|
+
/** Position within the rank (0-indexed). */
|
|
42
|
+
order: number;
|
|
43
|
+
};
|
|
44
|
+
export type DAGLayoutEdge = {
|
|
45
|
+
from: string;
|
|
46
|
+
to: string;
|
|
47
|
+
/** Suggested source anchor point (center of the outgoing side). */
|
|
48
|
+
sourceX: number;
|
|
49
|
+
sourceY: number;
|
|
50
|
+
/** Suggested target anchor point (center of the incoming side). */
|
|
51
|
+
targetX: number;
|
|
52
|
+
targetY: number;
|
|
53
|
+
/** True when this edge was identified as a back-edge (part of a cycle). */
|
|
54
|
+
isBackEdge: boolean;
|
|
55
|
+
};
|
|
56
|
+
export type DAGLayoutRank = {
|
|
57
|
+
/** Rank index (0 = root). */
|
|
58
|
+
rank: number;
|
|
59
|
+
/** Left edge of the rank bounding box. */
|
|
60
|
+
x: number;
|
|
61
|
+
/** Top edge of the rank bounding box. */
|
|
62
|
+
y: number;
|
|
63
|
+
/** Width of the rank bounding box. */
|
|
64
|
+
width: number;
|
|
65
|
+
/** Height of the rank bounding box. */
|
|
66
|
+
height: number;
|
|
67
|
+
/** Node ids in this rank, in order. */
|
|
68
|
+
nodeIds: string[];
|
|
69
|
+
};
|
|
70
|
+
export type DAGLayoutResult = {
|
|
71
|
+
nodes: DAGLayoutNode[];
|
|
72
|
+
edges: DAGLayoutEdge[];
|
|
73
|
+
/** Bounding box per rank — useful for drawing layer bands. */
|
|
74
|
+
ranks: DAGLayoutRank[];
|
|
75
|
+
/** The direction used for this layout. */
|
|
76
|
+
direction: "vertical" | "horizontal";
|
|
77
|
+
/** Total width of the bounding box. */
|
|
78
|
+
width: number;
|
|
79
|
+
/** Total height of the bounding box. */
|
|
80
|
+
height: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Compute a hierarchical layout for a directed graph.
|
|
84
|
+
*
|
|
85
|
+
* Returns node positions, edge anchor points, rank bounding boxes, and
|
|
86
|
+
* back-edge flags. The caller handles all rendering.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const layout = computeDAGLayout({
|
|
91
|
+
* nodes: [{ id: "a" }, { id: "b" }, { id: "c" }],
|
|
92
|
+
* edges: [{ from: "a", to: "b" }, { from: "b", to: "c" }],
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* // layout.nodes[i].x / .y → position your own SVG/HTML elements
|
|
96
|
+
* // layout.edges[i].sourceX/Y, targetX/Y → draw lines between them
|
|
97
|
+
* // layout.edges[i].isBackEdge → style cycle edges differently
|
|
98
|
+
* // layout.ranks[i] → draw layer bands behind each rank
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function computeDAGLayout(options: DAGLayoutOptions): DAGLayoutResult;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level diff primitives for the canvas SDK.
|
|
3
|
+
*
|
|
4
|
+
* The canvas diff surface is intentionally minimal — two components that
|
|
5
|
+
* compose with the generic `Card` / `CardHeader` / `CardBody` / `Pill` /
|
|
6
|
+
* `Text` primitives to build any diff layout an agent can imagine:
|
|
7
|
+
*
|
|
8
|
+
* - `DiffView` — a monospaced, syntax-highlighted unified diff renderer.
|
|
9
|
+
* Drops into any container (a `Card`, a table cell, a bare layout,
|
|
10
|
+
* nothing at all). No card chrome, no header, no path display. Pass
|
|
11
|
+
* `path` to auto-detect the language for highlighting, or `language`
|
|
12
|
+
* to override.
|
|
13
|
+
*
|
|
14
|
+
* - `DiffStats` — the canonical `+N` green / `-N` red glyph pair. Use
|
|
15
|
+
* it anywhere a small "added/deleted" summary makes sense — in a
|
|
16
|
+
* `CardHeader`'s `trailing` slot, next to a filename in a file tree,
|
|
17
|
+
* inside a status row, etc.
|
|
18
|
+
*
|
|
19
|
+
* For file-level metadata the preferred composition is to use the
|
|
20
|
+
* generic `Card` family:
|
|
21
|
+
*
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <Card collapsible>
|
|
24
|
+
* <CardHeader trailing={<DiffStats additions={5} deletions={2} />}>
|
|
25
|
+
* src/utils.ts
|
|
26
|
+
* </CardHeader>
|
|
27
|
+
* <CardBody style={{ padding: 0 }}>
|
|
28
|
+
* <DiffView path="src/utils.ts" lines={lines} />
|
|
29
|
+
* </CardBody>
|
|
30
|
+
* </Card>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
import type { CSSProperties, JSX } from "react";
|
|
34
|
+
export type DiffStatsProps = {
|
|
35
|
+
additions?: number;
|
|
36
|
+
deletions?: number;
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Inline `+N` / `-N` glyph pair. Green additions, red deletions, with
|
|
41
|
+
* tabular numerals so columns of stats line up. Renders nothing when
|
|
42
|
+
* both counts are zero.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <CardHeader trailing={<DiffStats additions={12} deletions={3} />}>
|
|
47
|
+
* src/utils.ts
|
|
48
|
+
* </CardHeader>
|
|
49
|
+
*
|
|
50
|
+
* <Row gap={8}>
|
|
51
|
+
* <Text>Refactor pass</Text>
|
|
52
|
+
* <DiffStats additions={42} deletions={17} />
|
|
53
|
+
* </Row>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function DiffStats({ additions, deletions, style, }: DiffStatsProps): JSX.Element | null;
|
|
57
|
+
export type DiffLineType = "added" | "removed" | "unchanged";
|
|
58
|
+
export type DiffLineData = {
|
|
59
|
+
type: DiffLineType;
|
|
60
|
+
content: string;
|
|
61
|
+
lineNumber?: number;
|
|
62
|
+
};
|
|
63
|
+
export type DiffViewProps = {
|
|
64
|
+
lines: DiffLineData[];
|
|
65
|
+
/**
|
|
66
|
+
* File path used to infer the syntax-highlighting language from the
|
|
67
|
+
* extension (e.g. `"src/utils.ts"` → `typescript`). The most ergonomic
|
|
68
|
+
* way to enable highlighting — pass the same path you show in the
|
|
69
|
+
* enclosing card header. Unknown extensions silently render as plain
|
|
70
|
+
* text.
|
|
71
|
+
*
|
|
72
|
+
* If both `path` and `language` are provided, `language` wins.
|
|
73
|
+
*/
|
|
74
|
+
path?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Explicit language override for syntax highlighting (e.g.
|
|
77
|
+
* `"typescript"`, `"python"`, `"tsx"`). Use this when no file path is
|
|
78
|
+
* available, when the path's extension is misleading, or when the
|
|
79
|
+
* content is a snippet rather than a real file. Accepts common
|
|
80
|
+
* aliases (`ts`, `py`, `rs`, `md`, etc.). Unknown languages silently
|
|
81
|
+
* fall back to plain text.
|
|
82
|
+
*
|
|
83
|
+
* Highlighting is applied per line, so multi-line constructs (block
|
|
84
|
+
* comments, template literals) may not colorize perfectly across line
|
|
85
|
+
* boundaries. For typical diff-sized inputs this is fine.
|
|
86
|
+
*/
|
|
87
|
+
language?: string;
|
|
88
|
+
/** Show line numbers in the gutter. Default `true`. */
|
|
89
|
+
showLineNumbers?: boolean;
|
|
90
|
+
/** Color line numbers green/red for added/removed lines. Default `true`. */
|
|
91
|
+
coloredLineNumbers?: boolean;
|
|
92
|
+
/** Show a 3px accent strip on the left edge for changed lines. Default `true`. */
|
|
93
|
+
showAccentStrip?: boolean;
|
|
94
|
+
style?: CSSProperties;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Unified diff body renderer with monospaced type, colored line
|
|
98
|
+
* backgrounds, line-number gutter, accent strip, and optional Shiki
|
|
99
|
+
* syntax highlighting.
|
|
100
|
+
*
|
|
101
|
+
* `DiffView` does not provide any surrounding chrome — place it inside
|
|
102
|
+
* a `Card` + `CardBody` (with `padding: 0`) when you want the standard
|
|
103
|
+
* bordered "file diff" look, or drop it anywhere else if you want the
|
|
104
|
+
* bare renderer.
|
|
105
|
+
*
|
|
106
|
+
* Pass `path` to enable syntax highlighting from the file extension.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* <Card>
|
|
111
|
+
* <CardHeader trailing={<DiffStats additions={2} deletions={1} />}>
|
|
112
|
+
* src/utils.ts
|
|
113
|
+
* </CardHeader>
|
|
114
|
+
* <CardBody style={{ padding: 0 }}>
|
|
115
|
+
* <DiffView
|
|
116
|
+
* path="src/utils.ts"
|
|
117
|
+
* lines={[
|
|
118
|
+
* { type: "unchanged", content: "export function add(a: number, b: number): number {", lineNumber: 1 },
|
|
119
|
+
* { type: "removed", content: " return a + b;", lineNumber: 2 },
|
|
120
|
+
* { type: "added", content: " const result = a + b;", lineNumber: 2 },
|
|
121
|
+
* { type: "added", content: " return result;", lineNumber: 3 },
|
|
122
|
+
* { type: "unchanged", content: "}", lineNumber: 4 },
|
|
123
|
+
* ]}
|
|
124
|
+
* />
|
|
125
|
+
* </CardBody>
|
|
126
|
+
* </Card>
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function DiffView({ lines, path, language, showLineNumbers, coloredLineNumbers, showAccentStrip, style, }: DiffViewProps): JSX.Element;
|