@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,156 @@
1
+ // The shadcn/ui subset tier-B canvases import as `@/components/ui/*` (J009; the eval's `eval/kit/runtime/shadcn.tsx`,
2
+ // new-york style, Tailwind v4 class strings as shadcn ships them, Radix primitives as shadcn uses them). Bundled only
3
+ // into the artifact `runtime.js`; the page's CSS for these classes is generated on the server (`compileArtifact`),
4
+ // which reads the class strings out of this file, so keep every class in a string literal.
5
+ import { createElement, forwardRef, useMemo } from 'react';
6
+ import { clsx } from 'clsx';
7
+ import { twMerge } from 'tailwind-merge';
8
+ import { cva } from 'class-variance-authority';
9
+ import { Slot } from '@radix-ui/react-slot';
10
+ import * as TabsP from '@radix-ui/react-tabs';
11
+ import * as SelectP from '@radix-ui/react-select';
12
+ import * as SliderP from '@radix-ui/react-slider';
13
+ import * as SwitchP from '@radix-ui/react-switch';
14
+ import * as CheckboxP from '@radix-ui/react-checkbox';
15
+ import * as ProgressP from '@radix-ui/react-progress';
16
+ import * as SeparatorP from '@radix-ui/react-separator';
17
+ import * as LabelP from '@radix-ui/react-label';
18
+ import * as AccordionP from '@radix-ui/react-accordion';
19
+ import Check from 'lucide-react/icons/check';
20
+ import ChevronDown from 'lucide-react/icons/chevron-down';
21
+ // Loosely typed: shadcn passes `data-slot` and other attributes Radix's prop types do not list.
22
+ const h = createElement;
23
+ export function cn(...inputs) {
24
+ return twMerge(clsx(inputs));
25
+ }
26
+ function div(base, slot) {
27
+ const C = forwardRef(({ className, ...p }, ref) => h('div', { ref, 'data-slot': slot, className: cn(base, className), ...p }));
28
+ C.displayName = slot;
29
+ return C;
30
+ }
31
+ /** A plain element with shadcn's classes; `className` merges. */
32
+ function el(tag, base, slot) {
33
+ const C = forwardRef(({ className, ...p }, ref) => h(tag, { ref, 'data-slot': slot, className: cn(base, className), ...p }));
34
+ C.displayName = slot;
35
+ return C;
36
+ }
37
+ /** A Radix part with shadcn's classes. */
38
+ function part(Comp, base, slot) {
39
+ const C = forwardRef(({ className, ...p }, ref) => h(Comp, { ref, 'data-slot': slot, className: cn(base, className), ...p }));
40
+ C.displayName = slot;
41
+ return C;
42
+ }
43
+ // card
44
+ export const Card = div('bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm', 'card');
45
+ export const CardHeader = div('grid auto-rows-min items-start gap-1.5 px-6', 'card-header');
46
+ export const CardTitle = div('leading-none font-semibold', 'card-title');
47
+ export const CardDescription = div('text-muted-foreground text-sm', 'card-description');
48
+ export const CardContent = div('px-6', 'card-content');
49
+ export const CardFooter = div('flex items-center px-6', 'card-footer');
50
+ export const CardAction = div('col-start-2 row-span-2 row-start-1 self-start justify-self-end', 'card-action');
51
+ // button
52
+ export const buttonVariants = cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:border-ring cursor-pointer", {
53
+ variants: {
54
+ variant: {
55
+ default: 'bg-primary text-primary-foreground shadow-xs hover:bg-primary/90',
56
+ destructive: 'bg-destructive text-white shadow-xs hover:bg-destructive/90',
57
+ outline: 'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground',
58
+ secondary: 'bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80',
59
+ ghost: 'hover:bg-accent hover:text-accent-foreground',
60
+ link: 'text-primary underline-offset-4 hover:underline',
61
+ },
62
+ size: { default: 'h-9 px-4 py-2', sm: 'h-8 rounded-md gap-1.5 px-3', lg: 'h-10 rounded-md px-6', icon: 'size-9', 'icon-sm': 'size-8', 'icon-lg': 'size-10' },
63
+ },
64
+ defaultVariants: { variant: 'default', size: 'default' },
65
+ });
66
+ export const Button = forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => h(asChild ? Slot : 'button', { ref, 'data-slot': 'button', className: cn(buttonVariants({ variant, size, className })), ...props }));
67
+ Button.displayName = 'Button';
68
+ // badge
69
+ export const badgeVariants = cva('inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none overflow-hidden', {
70
+ variants: {
71
+ variant: {
72
+ default: 'border-transparent bg-primary text-primary-foreground',
73
+ secondary: 'border-transparent bg-secondary text-secondary-foreground',
74
+ destructive: 'border-transparent bg-destructive text-white',
75
+ outline: 'text-foreground',
76
+ },
77
+ },
78
+ defaultVariants: { variant: 'default' },
79
+ });
80
+ export const Badge = forwardRef(({ className, variant, asChild = false, ...props }, ref) => h(asChild ? Slot : 'span', { ref, 'data-slot': 'badge', className: cn(badgeVariants({ variant }), className), ...props }));
81
+ Badge.displayName = 'Badge';
82
+ // table
83
+ export const Table = forwardRef(({ className, ...p }, ref) => h('div', { 'data-slot': 'table-container', className: 'relative w-full overflow-x-auto' }, h('table', { ref, 'data-slot': 'table', className: cn('w-full caption-bottom text-sm', className), ...p })));
84
+ Table.displayName = 'Table';
85
+ export const TableHeader = el('thead', '[&_tr]:border-b', 'table-header');
86
+ export const TableBody = el('tbody', '[&_tr:last-child]:border-0', 'table-body');
87
+ export const TableFooter = el('tfoot', 'bg-muted/50 border-t font-medium [&>tr]:last:border-b-0', 'table-footer');
88
+ export const TableRow = el('tr', 'hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors', 'table-row');
89
+ export const TableHead = el('th', 'text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0', 'table-head');
90
+ export const TableCell = el('td', 'p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0', 'table-cell');
91
+ export const TableCaption = el('caption', 'text-muted-foreground mt-4 text-sm', 'table-caption');
92
+ // tabs
93
+ export const Tabs = part(TabsP.Root, 'flex flex-col gap-2', 'tabs');
94
+ export const TabsList = part(TabsP.List, 'bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]', 'tabs-list');
95
+ export const TabsTrigger = part(TabsP.Trigger, "data-[state=active]:bg-background data-[state=active]:shadow-sm text-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 cursor-pointer", 'tabs-trigger');
96
+ export const TabsContent = part(TabsP.Content, 'flex-1 outline-none', 'tabs-content');
97
+ // input, label
98
+ export const Input = forwardRef(({ className, type, ...p }, ref) => h('input', { ref, type, 'data-slot': 'input', className: cn('file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]', className), ...p }));
99
+ Input.displayName = 'Input';
100
+ export const Textarea = forwardRef(({ className, ...p }, ref) => h('textarea', { ref, 'data-slot': 'textarea', className: cn('border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm', className), ...p }));
101
+ Textarea.displayName = 'Textarea';
102
+ export const Label = part(LabelP.Root, 'flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50', 'label');
103
+ // select
104
+ export const Select = SelectP.Root;
105
+ export const SelectGroup = SelectP.Group;
106
+ export const SelectValue = SelectP.Value;
107
+ export const SelectTrigger = forwardRef(({ className, children, size = 'default', ...p }, ref) => h(SelectP.Trigger, { ref, 'data-slot': 'select-trigger', 'data-size': size, className: cn("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 cursor-pointer", className), ...p }, children, h(SelectP.Icon, { asChild: true }, h(ChevronDown, { className: 'size-4 opacity-50' }))));
108
+ SelectTrigger.displayName = 'SelectTrigger';
109
+ export function SelectContent({ className, children, position = 'popper', ...p }) {
110
+ return h(SelectP.Portal, null, h(SelectP.Content, {
111
+ 'data-slot': 'select-content', position,
112
+ className: cn('bg-popover text-popover-foreground relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md', position === 'popper' && 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1', className),
113
+ ...p,
114
+ }, h(SelectP.Viewport, { className: cn('p-1', position === 'popper' && 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1') }, children)));
115
+ }
116
+ export const SelectItem = forwardRef(({ className, children, ...p }, ref) => h(SelectP.Item, { ref, 'data-slot': 'select-item', className: cn("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), ...p }, h('span', { className: 'absolute right-2 flex size-3.5 items-center justify-center' }, h(SelectP.ItemIndicator, null, h(Check, { className: 'size-4' }))), h(SelectP.ItemText, null, children)));
117
+ SelectItem.displayName = 'SelectItem';
118
+ export const SelectLabel = part(SelectP.Label, 'text-muted-foreground px-2 py-1.5 text-xs', 'select-label');
119
+ export const SelectSeparator = part(SelectP.Separator, 'bg-border pointer-events-none -mx-1 my-1 h-px', 'select-separator');
120
+ // slider
121
+ export const Slider = forwardRef(({ className, defaultValue, value, min = 0, max = 100, ...p }, ref) => {
122
+ // Models often pass a number where Radix wants an array; accept both.
123
+ const v = typeof value === 'number' ? [value] : value;
124
+ const d = typeof defaultValue === 'number' ? [defaultValue] : defaultValue;
125
+ const values = useMemo(() => (Array.isArray(v) ? v : Array.isArray(d) ? d : [min, max]), [v, d, min, max]);
126
+ return h(SliderP.Root, { ref, 'data-slot': 'slider', defaultValue: d, value: v, min, max, className: cn('relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col', className), ...p }, h(SliderP.Track, { 'data-slot': 'slider-track', className: 'bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5' }, h(SliderP.Range, { 'data-slot': 'slider-range', className: 'bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full' })), ...values.map((_, i) => h(SliderP.Thumb, { key: i, 'data-slot': 'slider-thumb', className: 'border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50' })));
127
+ });
128
+ Slider.displayName = 'Slider';
129
+ // switch, checkbox, progress, separator
130
+ export const Switch = forwardRef(({ className, ...p }, ref) => h(SwitchP.Root, { ref, 'data-slot': 'switch', className: cn('peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer', className), ...p }, h(SwitchP.Thumb, { 'data-slot': 'switch-thumb', className: 'bg-background pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0' })));
131
+ Switch.displayName = 'Switch';
132
+ export const Checkbox = forwardRef(({ className, ...p }, ref) => h(CheckboxP.Root, { ref, 'data-slot': 'checkbox', className: cn('peer border-input data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer', className), ...p }, h(CheckboxP.Indicator, { 'data-slot': 'checkbox-indicator', className: 'flex items-center justify-center text-current transition-none' }, h(Check, { className: 'size-3.5' }))));
133
+ Checkbox.displayName = 'Checkbox';
134
+ export const Progress = forwardRef(({ className, value, ...p }, ref) => {
135
+ const v = Math.max(0, Math.min(100, Number(value) || 0));
136
+ return h(ProgressP.Root, { ref, 'data-slot': 'progress', value: v, className: cn('bg-primary/20 relative h-2 w-full overflow-hidden rounded-full', className), ...p }, h(ProgressP.Indicator, { 'data-slot': 'progress-indicator', className: 'bg-primary h-full w-full flex-1 transition-all', style: { transform: `translateX(-${100 - v}%)` } }));
137
+ });
138
+ Progress.displayName = 'Progress';
139
+ export const Separator = forwardRef(({ className, orientation = 'horizontal', decorative = true, ...p }, ref) => h(SeparatorP.Root, { ref, 'data-slot': 'separator', decorative, orientation, className: cn('bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px', className), ...p }));
140
+ Separator.displayName = 'Separator';
141
+ // alert
142
+ const alertVariants = cva('relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current', {
143
+ variants: { variant: { default: 'bg-card text-card-foreground', destructive: 'text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90' } },
144
+ defaultVariants: { variant: 'default' },
145
+ });
146
+ export const Alert = forwardRef(({ className, variant, ...p }, ref) => h('div', { ref, 'data-slot': 'alert', role: 'alert', className: cn(alertVariants({ variant }), className), ...p }));
147
+ Alert.displayName = 'Alert';
148
+ export const AlertTitle = div('col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight', 'alert-title');
149
+ export const AlertDescription = div('text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed', 'alert-description');
150
+ // accordion
151
+ export const Accordion = AccordionP.Root;
152
+ export const AccordionItem = part(AccordionP.Item, 'border-b last:border-b-0', 'accordion-item');
153
+ export const AccordionTrigger = forwardRef(({ className, children, ...p }, ref) => h(AccordionP.Header, { className: 'flex' }, h(AccordionP.Trigger, { ref, 'data-slot': 'accordion-trigger', className: cn('focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180 cursor-pointer', className), ...p }, children, h(ChevronDown, { className: 'text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200' }))));
154
+ AccordionTrigger.displayName = 'AccordionTrigger';
155
+ export const AccordionContent = forwardRef(({ className, children, ...p }, ref) => h(AccordionP.Content, { ref, 'data-slot': 'accordion-content', className: 'overflow-hidden text-sm', ...p }, h('div', { className: cn('pt-0 pb-4', className) }, children)));
156
+ AccordionContent.displayName = 'AccordionContent';
@@ -23,3 +23,17 @@ export interface BuiltRuntime {
23
23
  exports: string[];
24
24
  }
25
25
  export declare function buildRuntime(options: BuildRuntimeOptions): Promise<BuiltRuntime>;
26
+ export interface BuildArtifactOptions {
27
+ /** Write here as well as returning the code. Default none. */
28
+ outFile?: string;
29
+ /** Default true. */
30
+ minify?: boolean;
31
+ target?: string[];
32
+ }
33
+ /**
34
+ * The prebuilt tier-B runtime (J009's artifact kit): React, react-dom, recharts, the shadcn subset, KaTeX and the state
35
+ * bridge, with `artifact/modules.ts`'s module map. Bundled from `artifact/entry` next to this file, so it works from the
36
+ * source tree and from `dist/`. `scripts/build-artifact.ts` writes it with the KaTeX stylesheet into
37
+ * `dist/canvas/artifact/assets/`; a host serves the files and never builds it.
38
+ */
39
+ export declare function buildArtifactRuntime(options?: BuildArtifactOptions): Promise<BuiltRuntime>;
@@ -52,3 +52,30 @@ export async function buildRuntime(options) {
52
52
  exports: [...new Set([...RUNTIME_NAMES, ...names])].sort(),
53
53
  };
54
54
  }
55
+ /**
56
+ * The prebuilt tier-B runtime (J009's artifact kit): React, react-dom, recharts, the shadcn subset, KaTeX and the state
57
+ * bridge, with `artifact/modules.ts`'s module map. Bundled from `artifact/entry` next to this file, so it works from the
58
+ * source tree and from `dist/`. `scripts/build-artifact.ts` writes it with the KaTeX stylesheet into
59
+ * `dist/canvas/artifact/assets/`; a host serves the files and never builds it.
60
+ */
61
+ export async function buildArtifactRuntime(options = {}) {
62
+ const esbuild = (await import('esbuild'));
63
+ const r = await esbuild.build({
64
+ entryPoints: [sibling('artifact/entry')],
65
+ bundle: true,
66
+ write: false,
67
+ minify: options.minify ?? true,
68
+ format: 'iife',
69
+ platform: 'browser',
70
+ target: options.target ?? ['es2020'],
71
+ define: { 'process.env.NODE_ENV': '"production"' },
72
+ legalComments: 'none',
73
+ logLevel: 'silent',
74
+ });
75
+ const code = r.outputFiles[0].text;
76
+ if (options.outFile) {
77
+ await mkdir(path.dirname(options.outFile), { recursive: true });
78
+ await writeFile(options.outFile, code);
79
+ }
80
+ return { code, hash: createHash('sha256').update(code).digest('hex').slice(0, 12), bytes: Buffer.byteLength(code), exports: [] };
81
+ }
@@ -9,6 +9,14 @@ export interface CompileCanvasOptions {
9
9
  exports?: readonly string[];
10
10
  /** Source cap in UTF-8 bytes. Default 100 KB. */
11
11
  maxBytes?: number;
12
+ /**
13
+ * Names per module, for a kit of several modules (the artifact kit: `react`, `recharts`, `@/components/ui/card` …).
14
+ * When given, the allowed modules are its keys (`modules` is ignored) and each import is checked against its own
15
+ * module's names; `exports` is ignored.
16
+ */
17
+ moduleExports?: Readonly<Record<string, readonly string[] | ReadonlySet<string>>>;
18
+ /** Called for each value import that passed the check: `(module, importedName)`. */
19
+ onImport?: (module: string, name: string) => void;
12
20
  }
13
21
  /** A compile failure: `message` names the line and shows it, ready to return to the model as a tool error. */
14
22
  export declare class CanvasCompileError extends Error {
@@ -38,8 +38,16 @@ export function compileCanvas(source, options = {}) {
38
38
  const bytes = new TextEncoder().encode(source).length;
39
39
  if (bytes > max)
40
40
  throw new CanvasCompileError(`canvas is ${bytes} bytes; the limit is ${max}`);
41
- const modules = new Set(options.modules ?? CANVAS_MODULES);
42
- const known = options.exports ? new Set(options.exports) : null;
41
+ const perModule = options.moduleExports;
42
+ const modules = new Set(perModule ? Object.keys(perModule) : options.modules ?? CANVAS_MODULES);
43
+ const known = options.exports && !perModule ? new Set(options.exports) : null;
44
+ const knownIn = (from) => {
45
+ if (!perModule)
46
+ return known;
47
+ const names = perModule[from];
48
+ return names instanceof Set ? names : new Set(names);
49
+ };
50
+ const imports = [];
43
51
  const shown = [...modules].map((m) => JSON.stringify(m)).join(' or ');
44
52
  let tokens;
45
53
  try {
@@ -151,10 +159,14 @@ export function compileCanvas(source, options = {}) {
151
159
  const from = stringValue(j + 1);
152
160
  if (!modules.has(from))
153
161
  fail(i, `a canvas may import only from ${shown}; found ${JSON.stringify(from)}`);
154
- if (!isType && known)
162
+ const names_ = knownIn(from);
163
+ if (!isType && names_)
155
164
  for (const n of names)
156
- if (!known.has(n.name))
165
+ if (!names_.has(n.name))
157
166
  fail(i, `${JSON.stringify(from)} does not export ${n.name}`);
167
+ if (!isType)
168
+ for (const n of names)
169
+ imports.push([from, n.name]);
158
170
  if (tokens[j + 2]?.type === tt._with || (tokens[j + 2]?.type === tt.name && text(j + 2) === 'assert'))
159
171
  fail(i, 'import attributes are not allowed');
160
172
  return j + 1;
@@ -186,6 +198,9 @@ export function compileCanvas(source, options = {}) {
186
198
  }
187
199
  if (!/\bexports\.\s*default\s*=/.test(code))
188
200
  throw new CanvasCompileError('canvas must `export default` a component');
201
+ if (options.onImport)
202
+ for (const [from, name] of imports)
203
+ options.onImport(from, name);
189
204
  return code;
190
205
  }
191
206
  /** `x.require` and `{ require: 1 }` name a property, not the binding. (`{ require }` shorthand is the binding.) */
@@ -0,0 +1,118 @@
1
+ import type { BlockResult, BlockSpec } from '../../markdown/blocks.ts';
2
+ export type Tone = 'success' | 'danger' | 'warning' | 'info' | 'neutral';
3
+ export type Align = 'left' | 'center' | 'right';
4
+ export type Cell = string | number | boolean | null;
5
+ export type TableBlock = {
6
+ title?: string;
7
+ headers: string[];
8
+ /** Each row has at most `headers.length` cells; a shorter row is padded with `null`. */
9
+ rows: Cell[][];
10
+ /** Per column; a column left out is right-aligned when all its cells are numbers, else left. */
11
+ align?: (Align | null)[];
12
+ /** Per row: a coloured dot before the first cell. */
13
+ tone?: (Tone | null)[];
14
+ /** Markdown in YAML; HTML (inline, safe rules) after `renderDocument`. */
15
+ caption?: string;
16
+ };
17
+ export type StatItem = {
18
+ value: string | number;
19
+ label: string;
20
+ tone?: Tone;
21
+ detail?: string;
22
+ };
23
+ export type StatsBlock = {
24
+ title?: string;
25
+ items: StatItem[];
26
+ };
27
+ export type ChartSeries = {
28
+ name: string;
29
+ data: number[];
30
+ tone?: Tone;
31
+ };
32
+ export type ReferenceLine = {
33
+ value: number;
34
+ label?: string;
35
+ tone?: Tone;
36
+ };
37
+ type ChartCommon = {
38
+ title?: string;
39
+ caption?: string;
40
+ height?: number;
41
+ };
42
+ type AxisChart = ChartCommon & {
43
+ categories: string[];
44
+ series: ChartSeries[];
45
+ valuePrefix?: string;
46
+ valueSuffix?: string;
47
+ beginAtZero?: boolean;
48
+ yMin?: number;
49
+ yMax?: number;
50
+ referenceLines?: ReferenceLine[];
51
+ showValues?: boolean;
52
+ };
53
+ export type BarChartBlock = AxisChart & {
54
+ type: 'bar';
55
+ stacked?: boolean;
56
+ horizontal?: boolean;
57
+ normalized?: boolean;
58
+ };
59
+ export type LineChartBlock = AxisChart & {
60
+ type: 'line';
61
+ fill?: boolean;
62
+ };
63
+ export type PieChartBlock = ChartCommon & {
64
+ type: 'pie';
65
+ data: {
66
+ label: string;
67
+ value: number;
68
+ tone?: Tone;
69
+ }[];
70
+ donut?: boolean;
71
+ };
72
+ export type ChartBlock = BarChartBlock | LineChartBlock | PieChartBlock;
73
+ export type CalloutBlock = {
74
+ tone?: Tone;
75
+ title?: string; /** Markdown in YAML; HTML after `renderDocument`. */
76
+ body?: string;
77
+ };
78
+ /** Size limits of the four blocks. Over a limit, the block is invalid (the 0.1.0 fallback: source + errors). */
79
+ export declare const KIT_BLOCK_LIMITS: {
80
+ readonly title: 200;
81
+ readonly caption: 500;
82
+ readonly columns: 12;
83
+ readonly header: 80;
84
+ readonly rows: 200;
85
+ readonly cell: 500;
86
+ readonly stats: 12;
87
+ readonly statValue: 40;
88
+ readonly statLabel: 80;
89
+ readonly statDetail: 160;
90
+ readonly categories: 100;
91
+ readonly category: 60;
92
+ readonly series: 8;
93
+ readonly seriesName: 60;
94
+ readonly slices: 20;
95
+ readonly referenceLines: 5;
96
+ readonly affix: 8;
97
+ readonly minHeight: 120;
98
+ readonly maxHeight: 480;
99
+ readonly calloutBody: 4000;
100
+ };
101
+ export declare function parseTable(raw: unknown): BlockResult<TableBlock>;
102
+ export declare function parseStats(raw: unknown): BlockResult<StatsBlock>;
103
+ export declare function parseChart(raw: unknown): BlockResult<ChartBlock>;
104
+ export declare function parseCallout(raw: unknown): BlockResult<CalloutBlock>;
105
+ export type KitBlockName = 'table' | 'stats' | 'chart' | 'callout';
106
+ /**
107
+ * The four specs, to spread into `createMarkdown({ yaml, blocks: { ...kitBlocks, ...yours } })`. Markdown fields:
108
+ * `table.caption`, `chart.caption` (inline), `callout.body`.
109
+ */
110
+ export declare const kitBlocks: {
111
+ table: BlockSpec<TableBlock>;
112
+ stats: BlockSpec<StatsBlock>;
113
+ chart: BlockSpec<ChartBlock>;
114
+ callout: BlockSpec<CalloutBlock>;
115
+ };
116
+ /** Text for a host's system prompt: when and how to write the four blocks. Append your own blocks' text after it. */
117
+ export declare const KIT_BLOCKS_INSTRUCTIONS: string;
118
+ export {};