@lightblues/jig 0.1.3 → 0.1.5

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.
Files changed (43) hide show
  1. package/README.md +2 -0
  2. package/dist/canvas/artifact/assets/katex.css +1 -0
  3. package/dist/canvas/artifact/assets/manifest.json +13 -0
  4. package/dist/canvas/artifact/assets/runtime.js +382 -0
  5. package/dist/canvas/artifact/css.d.ts +29 -0
  6. package/dist/canvas/artifact/css.js +159 -0
  7. package/dist/canvas/artifact/entry.d.ts +1 -0
  8. package/dist/canvas/artifact/entry.js +10 -0
  9. package/dist/canvas/artifact/icons.d.ts +13 -0
  10. package/dist/canvas/artifact/icons.js +67 -0
  11. package/dist/canvas/artifact/icons.json +1 -0
  12. package/dist/canvas/artifact/index.d.ts +54 -0
  13. package/dist/canvas/artifact/index.js +111 -0
  14. package/dist/canvas/artifact/instructions.d.ts +2 -0
  15. package/dist/canvas/artifact/instructions.js +16 -0
  16. package/dist/canvas/artifact/kit.d.ts +32 -0
  17. package/dist/canvas/artifact/kit.js +88 -0
  18. package/dist/canvas/artifact/modules.d.ts +3 -0
  19. package/dist/canvas/artifact/modules.js +33 -0
  20. package/dist/canvas/artifact/names.d.ts +6 -0
  21. package/dist/canvas/artifact/names.js +30 -0
  22. package/dist/canvas/artifact/ui.d.ts +76 -0
  23. package/dist/canvas/artifact/ui.js +156 -0
  24. package/dist/canvas/build.d.ts +14 -0
  25. package/dist/canvas/build.js +27 -0
  26. package/dist/canvas/compile.d.ts +8 -0
  27. package/dist/canvas/compile.js +19 -4
  28. package/dist/canvas/kit/blocks.d.ts +118 -0
  29. package/dist/canvas/kit/blocks.js +276 -0
  30. package/dist/canvas/kit/charts.d.ts +66 -0
  31. package/dist/canvas/kit/charts.js +319 -0
  32. package/dist/canvas/kit/context.d.ts +33 -0
  33. package/dist/canvas/kit/context.js +38 -0
  34. package/dist/canvas/kit/index.d.ts +25 -0
  35. package/dist/canvas/kit/index.js +44 -0
  36. package/dist/canvas/kit/theme.d.ts +88 -0
  37. package/dist/canvas/kit/theme.js +63 -0
  38. package/dist/canvas/kit/ui.d.ts +55 -0
  39. package/dist/canvas/kit/ui.js +100 -0
  40. package/dist/canvas/runtime.d.ts +6 -1
  41. package/dist/canvas/runtime.js +4 -3
  42. package/dist/markdown/mermaid.js +8 -4
  43. package/package.json +34 -2
@@ -0,0 +1,33 @@
1
+ import { Component, type CSSProperties, type ErrorInfo, type ReactNode } from 'react';
2
+ import { type KitPalette, type KitTheme, type ThemeKind } from './theme.ts';
3
+ /** The nearest `KitRoot`'s theme; jig's light default outside one. */
4
+ export declare function useKitTheme(): KitTheme;
5
+ export type KitRootProps = {
6
+ /** A theme built with `buildTheme`; wins over `kind` / `palette`. */
7
+ theme?: KitTheme;
8
+ kind?: ThemeKind;
9
+ /** The host's colours (only read when `kind` or the palette object changes: keep it stable, at module level or memoised). */
10
+ palette?: KitPalette;
11
+ children?: ReactNode;
12
+ };
13
+ /**
14
+ * Gives kit components their theme. No page shell, no CSS, no store: wrap the host's `FillSlots` (portals keep the
15
+ * context) or any subtree. Several roots on one page are independent.
16
+ */
17
+ export declare function KitRoot({ theme, kind, palette, children }: KitRootProps): ReactNode;
18
+ export declare function mergeStyle(base: CSSProperties, override?: CSSProperties): CSSProperties;
19
+ /** One block's error stays in its slot. */
20
+ export declare class KitBoundary extends Component<{
21
+ children?: ReactNode;
22
+ }, {
23
+ error: unknown;
24
+ }> {
25
+ state: {
26
+ error: unknown;
27
+ };
28
+ static getDerivedStateFromError(error: unknown): {
29
+ error: unknown;
30
+ };
31
+ componentDidCatch(error: unknown, info: ErrorInfo): void;
32
+ render(): ReactNode;
33
+ }
@@ -0,0 +1,38 @@
1
+ // Tier-A kit: theme context and the per-block shell (provider, error boundary). React only.
2
+ import { Component, createContext, createElement as h, useContext, useMemo } from 'react';
3
+ import { buildTheme } from "./theme.js";
4
+ const LIGHT = buildTheme('light');
5
+ const ThemeContext = createContext(LIGHT);
6
+ /** The nearest `KitRoot`'s theme; jig's light default outside one. */
7
+ export function useKitTheme() {
8
+ return useContext(ThemeContext);
9
+ }
10
+ /**
11
+ * Gives kit components their theme. No page shell, no CSS, no store: wrap the host's `FillSlots` (portals keep the
12
+ * context) or any subtree. Several roots on one page are independent.
13
+ */
14
+ export function KitRoot({ theme, kind = 'light', palette, children }) {
15
+ const built = useMemo(() => theme ?? buildTheme(kind, palette), [theme, kind, palette]);
16
+ return h(ThemeContext.Provider, { value: built }, children);
17
+ }
18
+ export function mergeStyle(base, override) {
19
+ return override ? { ...base, ...override } : base;
20
+ }
21
+ function KitError({ error }) {
22
+ const t = useKitTheme();
23
+ const message = error instanceof Error ? error.message : String(error);
24
+ return h('div', { role: 'alert', className: 'jig-kit-error', style: { padding: '8px 12px', borderRadius: t.radius.md, background: t.fill.tertiary, color: t.tone.danger, fontFamily: t.font.mono, fontSize: 12, lineHeight: '18px', whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' } }, `Could not draw this block: ${message}`);
25
+ }
26
+ /** One block's error stays in its slot. */
27
+ export class KitBoundary extends Component {
28
+ state = { error: null };
29
+ static getDerivedStateFromError(error) {
30
+ return { error };
31
+ }
32
+ componentDidCatch(error, info) {
33
+ console.error('[jig kit]', error, info.componentStack);
34
+ }
35
+ render() {
36
+ return this.state.error == null ? this.props.children : h(KitError, { error: this.state.error });
37
+ }
38
+ }
@@ -0,0 +1,25 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { CalloutBlock, ChartBlock, StatsBlock, TableBlock } from './blocks.ts';
3
+ export { buildTheme, withAlpha, DEFAULT_PALETTES, type KitPalette, type KitTheme, type KitFonts, type ThemeKind, type Tone, type Color, type CategoryPalette } from './theme.ts';
4
+ export { KitRoot, KitBoundary, useKitTheme, mergeStyle, type KitRootProps } from './context.ts';
5
+ export { BlockCard, Callout, Stat, StatGrid, Table, type BlockCardProps, type CalloutProps, type SafeHtml, type StatGridProps, type StatProps, type TableAlign, type TableCell, type TableProps } from './ui.ts';
6
+ export { BarChart, LineChart, PieChart, formatValue, valueAxis, type BarChartProps, type ChartDataPoint, type ChartReferenceLine, type ChartSeries, type LineChartProps, type PieChartProps } from './charts.ts';
7
+ export type { CalloutBlock, ChartBlock, StatsBlock, TableBlock, BarChartBlock, LineChartBlock, PieChartBlock, StatItem, KitBlockName } from './blocks.ts';
8
+ /** Draws a validated `table` block (`caption` arrives as jig-rendered HTML). */
9
+ export declare function TableBlockView({ value }: {
10
+ value: TableBlock;
11
+ }): ReactNode;
12
+ export declare function StatsBlockView({ value }: {
13
+ value: StatsBlock;
14
+ }): ReactNode;
15
+ export declare function ChartBlockView({ value }: {
16
+ value: ChartBlock;
17
+ }): ReactNode;
18
+ export declare function CalloutBlockView({ value }: {
19
+ value: CalloutBlock;
20
+ }): ReactNode;
21
+ /**
22
+ * Renderers of the four blocks for `FillSlots({ registry: { ...kitRegistry, ...yours } })`. Each block is drawn
23
+ * inside its own error boundary; the theme comes from the nearest `KitRoot` (wrap `FillSlots` in one).
24
+ */
25
+ export declare const kitRegistry: Record<'table' | 'stats' | 'chart' | 'callout', (value: any) => ReactNode>;
@@ -0,0 +1,44 @@
1
+ // `@lightblues/jig/canvas/kit`: the tier-A kit (J009), drawn in the host page with the host's React: `Table`,
2
+ // `Stat` / `StatGrid`, `BarChart` / `LineChart` / `PieChart`, `Callout`, the theme (`buildTheme(kind, palette)`,
3
+ // `KitRoot`), and `kitRegistry`, the `FillSlots` renderers of the four blocks whose specs are `kitBlocks`
4
+ // (`@lightblues/jig/canvas/blocks`, React-free). Inline styles only: no CSS to add, none that leaks.
5
+ import { createElement as h } from 'react';
6
+ import { KitBoundary } from "./context.js";
7
+ import { BarChart, LineChart, PieChart } from "./charts.js";
8
+ import { BlockCard, Callout, StatGrid, Table } from "./ui.js";
9
+ export { buildTheme, withAlpha, DEFAULT_PALETTES } from "./theme.js";
10
+ export { KitRoot, KitBoundary, useKitTheme, mergeStyle } from "./context.js";
11
+ export { BlockCard, Callout, Stat, StatGrid, Table } from "./ui.js";
12
+ export { BarChart, LineChart, PieChart, formatValue, valueAxis } from "./charts.js";
13
+ const html = (s) => (s ? { __html: s } : undefined);
14
+ /** Draws a validated `table` block (`caption` arrives as jig-rendered HTML). */
15
+ export function TableBlockView({ value }) {
16
+ return h(BlockCard, { title: value.title, caption: html(value.caption), framed: false }, h(Table, { headers: value.headers, rows: value.rows, align: value.align, rowTone: value.tone, maxHeight: 480 }));
17
+ }
18
+ export function StatsBlockView({ value }) {
19
+ return h(BlockCard, { title: value.title }, h(StatGrid, { items: value.items }));
20
+ }
21
+ export function ChartBlockView({ value }) {
22
+ const chart = value.type === 'pie'
23
+ ? h(PieChart, { data: value.data, donut: value.donut, size: value.height ? Math.min(value.height, 240) : 180 })
24
+ : value.type === 'line'
25
+ ? h(LineChart, { ...axisProps(value), fill: value.fill })
26
+ : h(BarChart, { ...axisProps(value), stacked: value.stacked, horizontal: value.horizontal, normalized: value.normalized });
27
+ return h(BlockCard, { title: value.title, caption: html(value.caption) }, chart);
28
+ }
29
+ function axisProps(v) {
30
+ return { categories: v.categories, series: v.series, height: v.height, valuePrefix: v.valuePrefix, valueSuffix: v.valueSuffix, beginAtZero: v.beginAtZero, yMin: v.yMin, yMax: v.yMax, referenceLines: v.referenceLines, showValues: v.showValues };
31
+ }
32
+ export function CalloutBlockView({ value }) {
33
+ return h(Callout, { tone: value.tone, title: value.title, html: html(value.body) });
34
+ }
35
+ /**
36
+ * Renderers of the four blocks for `FillSlots({ registry: { ...kitRegistry, ...yours } })`. Each block is drawn
37
+ * inside its own error boundary; the theme comes from the nearest `KitRoot` (wrap `FillSlots` in one).
38
+ */
39
+ export const kitRegistry = {
40
+ table: (value) => h(KitBoundary, null, h(TableBlockView, { value })),
41
+ stats: (value) => h(KitBoundary, null, h(StatsBlockView, { value })),
42
+ chart: (value) => h(KitBoundary, null, h(ChartBlockView, { value })),
43
+ callout: (value) => h(KitBoundary, null, h(CalloutBlockView, { value })),
44
+ };
@@ -0,0 +1,88 @@
1
+ export type Color = 'gray' | 'purple' | 'green' | 'yellow' | 'cyan' | 'pink' | 'blue' | 'orange' | 'red';
2
+ export type CategoryPalette = Readonly<Record<Color, string>>;
3
+ export type Tone = 'success' | 'danger' | 'warning' | 'info' | 'neutral';
4
+ export type ThemeKind = 'light' | 'dark';
5
+ /**
6
+ * What a host passes: its own colours, any CSS colour (`#hex`, `rgb()`, `var(--fig-ink)`). Every field is optional;
7
+ * a missing one comes from jig's neutral default for the kind. Fills and strokes are derived from `text`.
8
+ */
9
+ export interface KitPalette {
10
+ /** Page background (chart strokes between slices, label halos). */
11
+ background?: string;
12
+ /** Card background (tables, chart cards). */
13
+ surface?: string;
14
+ text?: string;
15
+ textSecondary?: string;
16
+ textTertiary?: string;
17
+ /** Card borders and table rules. */
18
+ border?: string;
19
+ accent?: string;
20
+ onAccent?: string;
21
+ link?: string;
22
+ tone?: Partial<Record<Tone, string>>;
23
+ category?: Partial<CategoryPalette>;
24
+ /** Series colours in order (at least one). */
25
+ chart?: readonly string[];
26
+ font?: Partial<KitFonts>;
27
+ }
28
+ export interface KitFonts {
29
+ body: string;
30
+ heading: string;
31
+ mono: string;
32
+ }
33
+ export interface KitTheme {
34
+ readonly kind: ThemeKind;
35
+ readonly bg: {
36
+ editor: string;
37
+ elevated: string;
38
+ };
39
+ readonly text: {
40
+ primary: string;
41
+ secondary: string;
42
+ tertiary: string;
43
+ quaternary: string;
44
+ link: string;
45
+ onAccent: string;
46
+ };
47
+ readonly stroke: {
48
+ primary: string;
49
+ secondary: string;
50
+ tertiary: string;
51
+ };
52
+ readonly fill: {
53
+ primary: string;
54
+ secondary: string;
55
+ tertiary: string;
56
+ quaternary: string;
57
+ };
58
+ readonly accent: {
59
+ primary: string;
60
+ };
61
+ readonly tone: Readonly<Record<Tone, string>>;
62
+ readonly category: CategoryPalette;
63
+ readonly chart: {
64
+ readonly sequence: readonly string[];
65
+ };
66
+ readonly radius: {
67
+ readonly sm: number;
68
+ readonly md: number;
69
+ readonly lg: number;
70
+ readonly full: number;
71
+ };
72
+ readonly font: KitFonts;
73
+ }
74
+ type Base = Required<Omit<KitPalette, 'tone' | 'category' | 'chart' | 'font'>> & {
75
+ tone: Record<Tone, string>;
76
+ category: CategoryPalette;
77
+ chart: readonly string[];
78
+ };
79
+ /** jig's default: neutral greys, so a host that passes nothing looks plain, not like another app. */
80
+ export declare const DEFAULT_PALETTES: Readonly<Record<ThemeKind, Base>>;
81
+ /**
82
+ * `color` at `share` (0–1) opacity. `#rgb` / `#rrggbb` become `#rrggbbaa`; any other CSS colour (`var(--x)`, `rgb()`,
83
+ * a name) becomes `color-mix(...)`, so a host colour that is not hex still draws (intake's kit drew nothing then).
84
+ */
85
+ export declare function withAlpha(color: string, share: number): string;
86
+ /** The theme kit components read (`useKitTheme`). Same input, same output: build it once per kind and palette. */
87
+ export declare function buildTheme(kind?: ThemeKind, palette?: KitPalette): KitTheme;
88
+ export {};
@@ -0,0 +1,63 @@
1
+ // Tier-A kit theme (J009): the token shape of intake's Cursor-compatible kit (`tokens.ts`), with the colours a host
2
+ // passes. No React here: `buildTheme` is plain data, so a server can build the same theme.
3
+ const FONTS = {
4
+ body: "system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'PingFang SC', sans-serif",
5
+ heading: "system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'PingFang SC', sans-serif",
6
+ mono: "ui-monospace, 'SF Mono', Menlo, Consolas, monospace",
7
+ };
8
+ /** jig's default: neutral greys, so a host that passes nothing looks plain, not like another app. */
9
+ export const DEFAULT_PALETTES = {
10
+ light: {
11
+ background: '#ffffff', surface: '#ffffff', text: '#1f2328', textSecondary: '#4b535d', textTertiary: '#6a737d', border: '#d8dee4',
12
+ accent: '#2f6fd0', onAccent: '#ffffff', link: '#2f6fd0',
13
+ tone: { success: '#1f7a4a', danger: '#c0362c', warning: '#9a6400', info: '#2f6fd0', neutral: '#6a737d' },
14
+ category: { gray: '#6a737d', purple: '#7650b8', green: '#1f7a4a', yellow: '#9a7400', cyan: '#1d7f86', pink: '#b0457c', blue: '#2f6fd0', orange: '#b85c1e', red: '#c0362c' },
15
+ chart: ['#2e79b5', '#e08a1e', '#1f8a65', '#7b64b8', '#c85898', '#2a9a8a', '#c9a227', '#5a6cc0', '#c06028', '#70b0d8', '#52b896', '#aa98d8'],
16
+ },
17
+ dark: {
18
+ background: '#16181c', surface: '#1e2126', text: '#e6e8eb', textSecondary: '#b4bac2', textTertiary: '#8b939c', border: '#363b42',
19
+ accent: '#6ea8fe', onAccent: '#0b1220', link: '#6ea8fe',
20
+ tone: { success: '#5cc28a', danger: '#f0776b', warning: '#e0b04a', info: '#6ea8fe', neutral: '#8b939c' },
21
+ category: { gray: '#8b939c', purple: '#a98fd6', green: '#5cc28a', yellow: '#d9b441', cyan: '#5fbcbc', pink: '#d98ab0', blue: '#6ea8fe', orange: '#e0935f', red: '#f0776b' },
22
+ chart: ['#5b9bd5', '#f0a040', '#3fb68b', '#9f8ad6', '#e07ab4', '#3fbfae', '#e8c64a', '#8a9ae0', '#e0804a', '#8cc4e8', '#7dcab0', '#c2b4e8'],
23
+ },
24
+ };
25
+ /**
26
+ * `color` at `share` (0–1) opacity. `#rgb` / `#rrggbb` become `#rrggbbaa`; any other CSS colour (`var(--x)`, `rgb()`,
27
+ * a name) becomes `color-mix(...)`, so a host colour that is not hex still draws (intake's kit drew nothing then).
28
+ */
29
+ export function withAlpha(color, share) {
30
+ const s = Math.max(0, Math.min(1, share));
31
+ const c = color.trim();
32
+ const short = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(c);
33
+ const hex = short ? `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}` : /^#[0-9a-f]{6}$/i.test(c) ? c : null;
34
+ if (hex)
35
+ return `${hex}${Math.round(s * 255).toString(16).padStart(2, '0')}`;
36
+ return `color-mix(in srgb, ${c} ${Math.round(s * 1000) / 10}%, transparent)`;
37
+ }
38
+ /** The theme kit components read (`useKitTheme`). Same input, same output: build it once per kind and palette. */
39
+ export function buildTheme(kind = 'light', palette = {}) {
40
+ const d = DEFAULT_PALETTES[kind] ?? DEFAULT_PALETTES.light;
41
+ const text = palette.text ?? d.text;
42
+ const chart = palette.chart?.length ? [...palette.chart] : [...d.chart];
43
+ return {
44
+ kind,
45
+ bg: { editor: palette.background ?? d.background, elevated: palette.surface ?? d.surface },
46
+ text: {
47
+ primary: text,
48
+ secondary: palette.textSecondary ?? d.textSecondary,
49
+ tertiary: palette.textTertiary ?? d.textTertiary,
50
+ quaternary: withAlpha(text, 0.38),
51
+ link: palette.link ?? d.link,
52
+ onAccent: palette.onAccent ?? d.onAccent,
53
+ },
54
+ stroke: { primary: withAlpha(text, 0.3), secondary: withAlpha(text, 0.18), tertiary: palette.border ?? d.border },
55
+ fill: { primary: withAlpha(text, 0.14), secondary: withAlpha(text, 0.09), tertiary: withAlpha(text, 0.055), quaternary: withAlpha(text, 0.035) },
56
+ accent: { primary: palette.accent ?? d.accent },
57
+ tone: { ...d.tone, ...palette.tone },
58
+ category: { ...d.category, ...palette.category },
59
+ chart: { sequence: chart },
60
+ radius: { sm: 4, md: 6, lg: 8, full: 9999 },
61
+ font: { ...FONTS, ...palette.font },
62
+ };
63
+ }
@@ -0,0 +1,55 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ import { type Tone } from './theme.ts';
3
+ export type { Tone } from './theme.ts';
4
+ /** HTML jig rendered from a Markdown field (`md` / `mdInline` of a block spec): safe by construction. */
5
+ export type SafeHtml = {
6
+ __html: string;
7
+ };
8
+ export type BlockCardProps = {
9
+ title?: ReactNode;
10
+ caption?: SafeHtml | ReactNode;
11
+ children?: ReactNode;
12
+ framed?: boolean;
13
+ style?: CSSProperties;
14
+ };
15
+ /** The card around a block: title, body, caption. Never wider than its slot. */
16
+ export declare function BlockCard({ title, caption, children, framed, style }: BlockCardProps): ReactNode;
17
+ export type StatProps = {
18
+ value: ReactNode;
19
+ label: string;
20
+ tone?: Tone;
21
+ detail?: string;
22
+ style?: CSSProperties;
23
+ };
24
+ /** A number and its label. A value too wide for its cell is cut with an ellipsis and shown whole on hover. */
25
+ export declare function Stat({ value, label, tone, detail, style }: StatProps): ReactNode;
26
+ export type StatGridProps = {
27
+ items: StatProps[];
28
+ style?: CSSProperties;
29
+ };
30
+ /** Stats in as many columns as fit (each at least 120 px): four across on a page, two on a phone. */
31
+ export declare function StatGrid({ items, style }: StatGridProps): ReactNode;
32
+ export type CalloutProps = {
33
+ tone?: Tone;
34
+ title?: ReactNode;
35
+ children?: ReactNode; /** Body as jig-rendered HTML (a block's `md` field) instead of children. */
36
+ html?: SafeHtml;
37
+ style?: CSSProperties;
38
+ };
39
+ /** A note with a tone. The body's own Markdown spacing is trimmed (first and last paragraph margins). */
40
+ export declare function Callout({ tone, title, children, html, style }: CalloutProps): ReactNode;
41
+ export type TableAlign = 'left' | 'center' | 'right';
42
+ export type TableCell = string | number | boolean | null | undefined;
43
+ export type TableProps = {
44
+ headers: ReactNode[];
45
+ rows: (TableCell | ReactNode)[][];
46
+ align?: (TableAlign | null | undefined)[];
47
+ rowTone?: (Tone | null | undefined)[];
48
+ striped?: boolean;
49
+ /** Rows taller than this scroll inside, with the header kept on top (px). */
50
+ maxHeight?: number;
51
+ emptyMessage?: ReactNode;
52
+ style?: CSSProperties;
53
+ };
54
+ /** A table that scrolls inside its frame when it is wider than the slot; long text wraps within a cell. */
55
+ export declare function Table({ headers, rows, align, rowTone, striped, maxHeight, emptyMessage, style }: TableProps): ReactNode;
@@ -0,0 +1,100 @@
1
+ // Tier-A kit: Table, Stat / StatGrid, Callout and the block card, from intake's Cursor-compatible kit (`ui.ts`),
2
+ // with inline styles from the theme only (no class names a host's CSS could hit, none it must add).
3
+ import { createElement as h, Fragment } from 'react';
4
+ import { mergeStyle, useKitTheme } from "./context.js";
5
+ import { withAlpha } from "./theme.js";
6
+ /** The card around a block: title, body, caption. Never wider than its slot. */
7
+ export function BlockCard({ title, caption, children, framed = true, style }) {
8
+ const t = useKitTheme();
9
+ const isHtml = caption != null && typeof caption === 'object' && '__html' in caption;
10
+ return h('figure', {
11
+ 'data-jig-kit': '',
12
+ style: mergeStyle({
13
+ boxSizing: 'border-box', margin: '8px 0', minWidth: 0, maxWidth: '100%', display: 'flex', flexDirection: 'column', gap: 8,
14
+ padding: framed ? 12 : 0, border: framed ? `1px solid ${t.stroke.tertiary}` : 0, borderRadius: framed ? t.radius.lg : 0,
15
+ background: framed ? t.bg.elevated : 'transparent', color: t.text.primary, fontFamily: t.font.body, fontSize: 14, lineHeight: '20px',
16
+ }, style),
17
+ }, title == null || title === '' ? null : h('div', { style: { fontFamily: t.font.heading, fontSize: 14, lineHeight: '20px', fontWeight: 600, color: t.text.primary, overflowWrap: 'anywhere' } }, title), children, caption == null || caption === '' ? null : h('figcaption', isHtml
18
+ ? { style: { fontSize: 12, lineHeight: '16px', color: t.text.tertiary, overflowWrap: 'anywhere' }, dangerouslySetInnerHTML: caption }
19
+ : { style: { fontSize: 12, lineHeight: '16px', color: t.text.tertiary, overflowWrap: 'anywhere' } }, isHtml ? undefined : caption));
20
+ }
21
+ /** A number and its label. A value too wide for its cell is cut with an ellipsis and shown whole on hover. */
22
+ export function Stat({ value, label, tone, detail, style }) {
23
+ const t = useKitTheme();
24
+ const text = typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;
25
+ return h('div', { style: mergeStyle({ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 }, style) }, h('div', { title: text, style: { fontFamily: t.font.heading, fontSize: 24, lineHeight: '30px', fontWeight: 620, color: tone ? t.tone[tone] : t.text.primary, fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, value), h('div', { style: { fontSize: 12, lineHeight: '16px', color: t.text.secondary, overflowWrap: 'anywhere' } }, label), detail ? h('div', { style: { fontSize: 12, lineHeight: '16px', color: t.text.tertiary, overflowWrap: 'anywhere' } }, detail) : null);
26
+ }
27
+ /** Stats in as many columns as fit (each at least 120 px): four across on a page, two on a phone. */
28
+ export function StatGrid({ items, style }) {
29
+ return h('div', { style: mergeStyle({ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(min(120px, 100%), 1fr))', gap: '12px 16px', minWidth: 0 }, style) }, items.map((s, i) => h(Stat, { key: i, ...s })));
30
+ }
31
+ const CALLOUT_ICON = {
32
+ info: 'M8 7.2v4M8 4.8h.01',
33
+ success: 'm5.4 8.2 1.8 1.8 3.4-3.6',
34
+ warning: 'M8 6v3M8 11.2h.01',
35
+ danger: 'M8 4.8v4M8 11.2h.01',
36
+ };
37
+ function CalloutIcon({ tone, color }) {
38
+ const ring = tone === 'warning'
39
+ ? h('path', { d: 'M7.13 2.5a1 1 0 0 1 1.74 0l5.5 9.75a1 1 0 0 1-.87 1.5H2.5a1 1 0 0 1-.87-1.5z', stroke: color, strokeWidth: 1.3, strokeLinejoin: 'round' })
40
+ : h('circle', { cx: 8, cy: 8, r: 6, stroke: color, strokeWidth: 1.3 });
41
+ return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, style: { flex: 'none', marginTop: 2 } }, ring, h('path', { d: CALLOUT_ICON[tone], stroke: color, strokeWidth: 1.5, strokeLinecap: 'round', strokeLinejoin: 'round' }));
42
+ }
43
+ /** A note with a tone. The body's own Markdown spacing is trimmed (first and last paragraph margins). */
44
+ export function Callout({ tone = 'info', title, children, html, style }) {
45
+ const t = useKitTheme();
46
+ const color = tone === 'neutral' ? t.text.tertiary : t.tone[tone];
47
+ return h('div', {
48
+ role: 'note', 'data-jig-kit': '',
49
+ style: mergeStyle({ boxSizing: 'border-box', margin: '8px 0', maxWidth: '100%', display: 'flex', gap: 10, alignItems: 'flex-start', padding: '10px 12px', borderRadius: t.radius.md, background: tone === 'neutral' ? t.fill.tertiary : withAlpha(color, 0.1), borderLeft: `3px solid ${color}`, color: t.text.primary, fontFamily: t.font.body, fontSize: 14, lineHeight: '20px' }, style),
50
+ }, tone === 'neutral' ? null : h(CalloutIcon, { tone, color }), h('div', { style: { flex: 1, minWidth: 0, overflowWrap: 'anywhere' } }, title == null || title === '' ? null : h('div', { style: { fontWeight: 650, marginBottom: children == null && !html ? 0 : 2 } }, title), html ? h('div', { className: 'jig-kit-md', style: { minWidth: 0 }, dangerouslySetInnerHTML: html, ref: trimMargins }) : children));
51
+ }
52
+ /** Removes the outer margins of rendered Markdown (a `<p>` inside a callout), without a stylesheet. */
53
+ function trimMargins(el) {
54
+ if (!el)
55
+ return;
56
+ const first = el.firstElementChild;
57
+ const last = el.lastElementChild;
58
+ if (first)
59
+ first.style.marginTop = '0';
60
+ if (last)
61
+ last.style.marginBottom = '0';
62
+ for (const pre of el.querySelectorAll('pre, table, section')) {
63
+ pre.style.overflowX = 'auto';
64
+ pre.style.maxWidth = '100%';
65
+ }
66
+ }
67
+ function toneDot(t, tone) {
68
+ return h('span', { 'aria-hidden': true, style: { display: 'inline-block', width: 6, height: 6, borderRadius: 3, background: t.tone[tone], marginRight: 8, verticalAlign: 'middle' } });
69
+ }
70
+ function showCell(v) {
71
+ if (v === null || v === undefined)
72
+ return '';
73
+ if (typeof v === 'boolean')
74
+ return v ? 'yes' : 'no';
75
+ if (typeof v === 'number')
76
+ return Number.isInteger(v) ? v.toLocaleString('en-US') : String(v);
77
+ return v;
78
+ }
79
+ /** A table that scrolls inside its frame when it is wider than the slot; long text wraps within a cell. */
80
+ export function Table({ headers, rows, align, rowTone, striped, maxHeight, emptyMessage, style }) {
81
+ const t = useKitTheme();
82
+ const numeric = headers.map((_, c) => rows.length > 0 && rows.every((r) => r[c] == null || typeof r[c] === 'number'));
83
+ const alignOf = (c) => align?.[c] ?? (numeric[c] ? 'right' : 'left');
84
+ const cell = (c) => ({ textAlign: alignOf(c), padding: '7px 12px', verticalAlign: 'top', overflowWrap: 'break-word', maxWidth: 360, minWidth: 48 });
85
+ const head = h('thead', null, h('tr', null, headers.map((header, c) => h('th', {
86
+ key: c, scope: 'col',
87
+ style: { ...cell(c), fontSize: 12, lineHeight: '16px', fontWeight: 600, color: t.text.secondary, borderBottom: `1px solid ${t.stroke.tertiary}`, background: t.bg.elevated, position: 'sticky', top: 0, zIndex: 1 },
88
+ }, header))));
89
+ const body = h('tbody', null, rows.length === 0
90
+ ? h('tr', null, h('td', { colSpan: headers.length, style: { padding: '14px 12px', textAlign: 'center', color: t.text.tertiary } }, emptyMessage ?? 'No rows'))
91
+ : rows.map((row, r) => h('tr', { key: r, style: { background: striped && r % 2 === 1 ? t.fill.quaternary : undefined } }, headers.map((_, c) => {
92
+ const tone = c === 0 ? rowTone?.[r] : undefined;
93
+ const v = showCell(row[c]);
94
+ return h('td', { key: c, style: { ...cell(c), borderTop: r === 0 ? 0 : `1px solid ${t.stroke.tertiary}`, fontVariantNumeric: 'tabular-nums' } }, tone ? h(Fragment, null, toneDot(t, tone), v) : v);
95
+ }))));
96
+ return h('div', {
97
+ role: 'region', tabIndex: 0, 'aria-label': 'table',
98
+ style: mergeStyle({ boxSizing: 'border-box', maxWidth: '100%', minWidth: 0, overflow: 'auto', maxHeight, border: `1px solid ${t.stroke.tertiary}`, borderRadius: t.radius.md, background: t.bg.elevated, WebkitOverflowScrolling: 'touch' }, style),
99
+ }, h('table', { style: { width: '100%', borderCollapse: 'separate', borderSpacing: 0, fontSize: 13, lineHeight: '18px', color: t.text.primary } }, head, body));
100
+ }
@@ -18,8 +18,13 @@ export interface CanvasRuntimeOptions {
18
18
  ErrorView?: ComponentType<{
19
19
  error: unknown;
20
20
  }>;
21
+ /**
22
+ * A kit of several modules (the artifact kit: `react`, `recharts`, `@/components/ui/card` …): module name → its
23
+ * exports. When given, `kit` and `modules` are ignored and each import resolves to its own module.
24
+ */
25
+ moduleMap?: Readonly<Record<string, Record<string, unknown>>>;
21
26
  }
22
27
  /** Load the compiled body against the kit and return its default export. Throws what the body throws. */
23
- export declare function loadCanvas(factory: CanvasFactory, kit: Record<string, unknown>, modules: readonly string[]): ComponentType;
28
+ export declare function loadCanvas(factory: CanvasFactory, kit: Record<string, unknown> | Readonly<Record<string, Record<string, unknown>>>, modules: readonly string[] | null): ComponentType;
24
29
  /** Install `window.__jigCanvas.run`. Call once in the runtime entry. */
25
30
  export declare function startCanvasRuntime(options: CanvasRuntimeOptions): void;
@@ -13,11 +13,12 @@ function DefaultError({ error }) {
13
13
  }
14
14
  /** Load the compiled body against the kit and return its default export. Throws what the body throws. */
15
15
  export function loadCanvas(factory, kit, modules) {
16
- const allowed = new Set(modules);
16
+ const map = modules ? null : kit;
17
+ const allowed = new Set(modules ?? Object.keys(map));
17
18
  const module = { exports: {} };
18
19
  const require = (name) => {
19
20
  if (allowed.has(name))
20
- return kit;
21
+ return map ? map[name] : kit;
21
22
  throw new Error(`canvas may import only ${[...allowed].join(' or ')}; found ${JSON.stringify(name)}`);
22
23
  };
23
24
  factory(require, module.exports, module, h, Fragment);
@@ -71,7 +72,7 @@ export function startCanvasRuntime(options) {
71
72
  let body = null;
72
73
  let loadError = null;
73
74
  try {
74
- body = loadCanvas(factory, kit, modules);
75
+ body = options.moduleMap ? loadCanvas(factory, options.moduleMap, null) : loadCanvas(factory, kit, modules);
75
76
  }
76
77
  catch (err) {
77
78
  loadError = err;
@@ -53,11 +53,18 @@ function scrub(root) {
53
53
  export async function drawMermaid(el, source, mermaid, o = {}) {
54
54
  const id = `jig-mmd-${++seq}`;
55
55
  const doc = el.ownerDocument;
56
+ // mermaid's temporary nodes (the drawing root `id` and its wrapper `d<id>`). Removed before the SVG, which keeps the
57
+ // same id, goes into `el`: removing them afterwards took the drawn SVG out of an attached `el` (0.1.4, assay-020).
58
+ const cleanup = () => {
59
+ doc.getElementById(id)?.remove();
60
+ doc.getElementById(`d${id}`)?.remove();
61
+ };
56
62
  try {
57
63
  const mod = typeof mermaid === 'function' ? await mermaid() : mermaid;
58
64
  const m = 'default' in mod && mod.default ? mod.default : mod;
59
65
  m.initialize({ ...o.config, ...MERMAID_CONFIG, secure: [...MERMAID_CONFIG.secure] });
60
66
  const { svg } = await m.render(id, source);
67
+ cleanup();
61
68
  const tpl = doc.createElement('template');
62
69
  tpl.innerHTML = svg; // inert: nothing in a template loads or runs
63
70
  scrub(tpl.content);
@@ -68,6 +75,7 @@ export async function drawMermaid(el, source, mermaid, o = {}) {
68
75
  return true;
69
76
  }
70
77
  catch {
78
+ cleanup();
71
79
  const pre = doc.createElement('pre');
72
80
  pre.className = 'jig-mermaid-error';
73
81
  const code = doc.createElement('code');
@@ -77,8 +85,4 @@ export async function drawMermaid(el, source, mermaid, o = {}) {
77
85
  el.replaceChildren(pre);
78
86
  return false;
79
87
  }
80
- finally {
81
- doc.getElementById(id)?.remove();
82
- doc.getElementById(`d${id}`)?.remove();
83
- }
84
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightblues/jig",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Reusable parts for my apps: agent runtimes (Paseo, pi) that speak AG-UI, a thin thread-following client, one markdown renderer, and more as they prove reusable.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -68,10 +68,22 @@
68
68
  "types": "./dist/canvas/build.d.ts",
69
69
  "default": "./dist/canvas/build.js"
70
70
  },
71
+ "./canvas/kit": {
72
+ "types": "./dist/canvas/kit/index.d.ts",
73
+ "default": "./dist/canvas/kit/index.js"
74
+ },
75
+ "./canvas/blocks": {
76
+ "types": "./dist/canvas/kit/blocks.d.ts",
77
+ "default": "./dist/canvas/kit/blocks.js"
78
+ },
79
+ "./canvas/artifact": {
80
+ "types": "./dist/canvas/artifact/index.d.ts",
81
+ "default": "./dist/canvas/artifact/index.js"
82
+ },
71
83
  "./package.json": "./package.json"
72
84
  },
73
85
  "scripts": {
74
- "build": "tsc -p tsconfig.build.json",
86
+ "build": "tsc -p tsconfig.build.json && node --experimental-strip-types scripts/build-artifact.ts",
75
87
  "typecheck": "tsc -p tsconfig.json --noEmit",
76
88
  "test": "node --test --experimental-strip-types 'test/**/*.test.ts'",
77
89
  "test:contract": "node --test --experimental-strip-types 'test/agent-paseo-contract.ts'",
@@ -83,15 +95,28 @@
83
95
  "@earendil-works/pi-ai": "1.4.0",
84
96
  "@earendil-works/pi-coding-agent": "1.4.0",
85
97
  "@getpaseo/client": "0.17.4",
98
+ "@radix-ui/react-accordion": "1.3.1",
99
+ "@radix-ui/react-checkbox": "1.4.1",
100
+ "@radix-ui/react-label": "2.1.17",
101
+ "@radix-ui/react-progress": "1.2.1",
102
+ "@radix-ui/react-select": "2.4.1",
103
+ "@radix-ui/react-separator": "1.2.0",
104
+ "@radix-ui/react-slider": "1.6.1",
105
+ "@radix-ui/react-slot": "1.5.0",
106
+ "@radix-ui/react-switch": "1.4.1",
107
+ "@radix-ui/react-tabs": "1.2.1",
86
108
  "@types/node": "^24.0.0",
87
109
  "@types/pg": "8.23.1",
88
110
  "@types/react": "19.3.0",
89
111
  "@types/react-dom": "19.3.0",
90
112
  "@types/react-test-renderer": "19.3.1",
113
+ "class-variance-authority": "0.7.1",
114
+ "clsx": "2.1.1",
91
115
  "esbuild": "0.28.2",
92
116
  "happy-dom": "21.0.4",
93
117
  "highlight.js": "11.12.0",
94
118
  "katex": "0.19.1",
119
+ "lucide-react": "1.80.0",
95
120
  "markdown-it": "15.0.3",
96
121
  "markdown-it-cjk-friendly": "3.0.0",
97
122
  "markdown-it-texmath": "1.0.0",
@@ -102,7 +127,10 @@
102
127
  "react": "19.3.1",
103
128
  "react-dom": "19.3.1",
104
129
  "react-test-renderer": "19.3.1",
130
+ "recharts": "3.11.1",
105
131
  "sucrase": "3.35.1",
132
+ "tailwind-merge": "3.7.1",
133
+ "tailwindcss": "4.3.5",
106
134
  "typescript": "^5.9.0",
107
135
  "yaml": "2.9.0",
108
136
  "zod": "4.6.7"
@@ -123,6 +151,7 @@
123
151
  "react": ">=18",
124
152
  "react-dom": ">=18",
125
153
  "sucrase": "~3.35.0",
154
+ "tailwindcss": "^4.3.0",
126
155
  "yaml": "^2.0.0"
127
156
  },
128
157
  "peerDependenciesMeta": {
@@ -171,6 +200,9 @@
171
200
  "sucrase": {
172
201
  "optional": true
173
202
  },
203
+ "tailwindcss": {
204
+ "optional": true
205
+ },
174
206
  "yaml": {
175
207
  "optional": true
176
208
  }