@widgetic/canvas 0.5.40 → 0.5.42
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 +7 -3
- package/dist/canvas/DomCanvas.svelte +4 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
- package/dist/canvas/host/CanvasHost.d.ts +6 -0
- package/dist/canvas/host/CanvasHost.js +39 -0
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +7 -1
- package/dist/canvas/ui/CanvasHint.svelte +16 -3
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
- package/dist/canvas/ui/CanvasToolbar.svelte +7 -7
- package/dist/canvas/ui/ToolButton.svelte +11 -3
- package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +1 -1
- package/dist/canvas/ui/sizeLabelVisibility.js +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +33 -14
- package/dist/canvas/view/geometry.d.ts +14 -4
- package/dist/canvas/view/geometry.js +14 -7
- package/dist/engine/EngineCore.d.ts +4 -1
- package/dist/engine/EngineCore.js +11 -4
- package/dist/engine/codec/canvasDocument.js +42 -6
- package/dist/engine/core/arrow.d.ts +10 -3
- package/dist/engine/core/arrow.js +10 -2
- package/dist/engine/core/arrowBinding.d.ts +69 -0
- package/dist/engine/core/arrowBinding.js +326 -0
- package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
- package/dist/engine/core/arrowBindingRecords.js +126 -0
- package/dist/engine/core/hitTest.d.ts +3 -0
- package/dist/engine/core/hitTest.js +2 -1
- package/dist/engine/core/scene.d.ts +3 -0
- package/dist/engine/core/scene.js +7 -2
- package/dist/engine/core/types.d.ts +29 -0
- package/dist/engine/input/PointerController.js +23 -1
- package/dist/engine/input/gestures.d.ts +12 -1
- package/dist/engine/input/gestures.js +56 -11
- package/dist/engine/input/keyboard.d.ts +9 -1
- package/dist/engine/input/keyboard.js +18 -2
- package/dist/engine/state.d.ts +6 -1
- package/dist/engine/state.js +2 -1
- package/dist/i18n/shortcuts.d.ts +12 -0
- package/dist/i18n/shortcuts.js +19 -5
- package/dist/tools/components/catalog.d.ts +11 -0
- package/dist/tools/components/catalog.js +260 -0
- package/dist/tools/components/grouping.d.ts +9 -0
- package/dist/tools/components/grouping.js +11 -0
- package/dist/tools/definitions.d.ts +19 -0
- package/dist/tools/definitions.js +147 -0
- package/dist/tools/executors.d.ts +7 -0
- package/dist/tools/executors.js +288 -0
- package/dist/tools/hostAdapter.d.ts +14 -0
- package/dist/tools/hostAdapter.js +38 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/sceneSummary.d.ts +24 -0
- package/dist/tools/sceneSummary.js +156 -0
- package/dist/tools/sketchIntent.d.ts +17 -0
- package/dist/tools/sketchIntent.js +158 -0
- package/dist/tools/types.d.ts +54 -0
- package/dist/tools/types.js +11 -0
- package/package.json +7 -2
package/dist/i18n/shortcuts.js
CHANGED
|
@@ -14,6 +14,18 @@ export const TOOL_KEYS = {
|
|
|
14
14
|
text: 'T',
|
|
15
15
|
image: 'I'
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* The number that also chooses each tool of the drawing bar: the place of its button on the bar, counted from the start of it.
|
|
19
|
+
* The hints and the list of keyboard shortcuts show it beside the letter. A digit is the same on every keyboard, so it is not a
|
|
20
|
+
* message either. The engine's table (`TOOL_DIGITS`) is the one that answers the key; a test holds the two together.
|
|
21
|
+
*/
|
|
22
|
+
export const TOOL_DIGIT_KEYS = {
|
|
23
|
+
select: '1',
|
|
24
|
+
draw: '2',
|
|
25
|
+
erase: '3',
|
|
26
|
+
arrow: '4',
|
|
27
|
+
text: '5'
|
|
28
|
+
};
|
|
17
29
|
const named = (name) => ({ name });
|
|
18
30
|
const cap = (text) => ({ cap: text });
|
|
19
31
|
const PLUS = null;
|
|
@@ -25,15 +37,17 @@ export const SHORTCUT_GROUPS = [
|
|
|
25
37
|
{
|
|
26
38
|
title: 'canvas.shortcuts.groupTools',
|
|
27
39
|
shortcuts: [
|
|
28
|
-
|
|
40
|
+
// The five tools of the drawing bar show two key caps next to each other (the letter, then the number), like the four
|
|
41
|
+
// arrow keys of "move" below: either key does it.
|
|
42
|
+
{ keys: [cap(TOOL_KEYS.select), cap(TOOL_DIGIT_KEYS.select)], label: 'canvas.tool.select' },
|
|
29
43
|
{ keys: [cap(TOOL_KEYS.hand)], label: 'canvas.tool.hand' },
|
|
30
|
-
{ keys: [cap(TOOL_KEYS.erase)], label: 'canvas.tool.erase' },
|
|
31
|
-
{ keys: [cap(TOOL_KEYS.draw)], label: 'canvas.tool.draw' },
|
|
32
|
-
{ keys: [cap(TOOL_KEYS.arrow)], label: 'canvas.tool.arrow' },
|
|
44
|
+
{ keys: [cap(TOOL_KEYS.erase), cap(TOOL_DIGIT_KEYS.erase)], label: 'canvas.tool.erase' },
|
|
45
|
+
{ keys: [cap(TOOL_KEYS.draw), cap(TOOL_DIGIT_KEYS.draw)], label: 'canvas.tool.draw' },
|
|
46
|
+
{ keys: [cap(TOOL_KEYS.arrow), cap(TOOL_DIGIT_KEYS.arrow)], label: 'canvas.tool.arrow' },
|
|
33
47
|
{ keys: [cap(TOOL_KEYS.rectangle)], label: 'canvas.tool.rectangle' },
|
|
34
48
|
{ keys: [cap(TOOL_KEYS.triangle)], label: 'canvas.tool.triangle' },
|
|
35
49
|
{ keys: [cap(TOOL_KEYS.ellipse)], label: 'canvas.tool.ellipse' },
|
|
36
|
-
{ keys: [cap(TOOL_KEYS.text)], label: 'canvas.tool.text' },
|
|
50
|
+
{ keys: [cap(TOOL_KEYS.text), cap(TOOL_DIGIT_KEYS.text)], label: 'canvas.tool.text' },
|
|
37
51
|
{ keys: [cap(TOOL_KEYS.image)], label: 'canvas.tool.image' }
|
|
38
52
|
]
|
|
39
53
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SceneObject } from '../../engine/core/types.js';
|
|
2
|
+
import type { ObjectId } from '../../engine/core/types.js';
|
|
3
|
+
import type { UiComponentKind } from '../types.js';
|
|
4
|
+
export interface ComponentPlacement {
|
|
5
|
+
objects: SceneObject[];
|
|
6
|
+
rootLabel: string;
|
|
7
|
+
/** Ids the assistant should target (e.g. navigation group). */
|
|
8
|
+
highlightIds?: ObjectId[];
|
|
9
|
+
}
|
|
10
|
+
export declare function drawUiComponent(kind: UiComponentKind, x: number, y: number, width: number, height: number, label?: string): ComponentPlacement;
|
|
11
|
+
export declare function makeArrowBetween(fromX: number, fromY: number, toX: number, toY: number, strokeWidth?: number): SceneObject;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { createPathObject, createRectObject, createTextObject } from '../../engine/core/defaults.js';
|
|
2
|
+
import { buildArrow } from '../../engine/core/arrow.js';
|
|
3
|
+
import { serializePathData } from '../../engine/core/pathData.js';
|
|
4
|
+
import { packGroup } from './grouping.js';
|
|
5
|
+
function snap(value) {
|
|
6
|
+
return Math.round(value / 8) * 8;
|
|
7
|
+
}
|
|
8
|
+
const STROKE = '#9ca3af';
|
|
9
|
+
const STROKE_WIDTH = 2;
|
|
10
|
+
export function drawUiComponent(kind, x, y, width, height, label) {
|
|
11
|
+
const objects = [];
|
|
12
|
+
const px = snap(x);
|
|
13
|
+
const py = snap(y);
|
|
14
|
+
const w = snap(Math.max(160, width));
|
|
15
|
+
const h = snap(Math.max(120, height));
|
|
16
|
+
switch (kind) {
|
|
17
|
+
case 'video_player': {
|
|
18
|
+
const title = createTextObject({
|
|
19
|
+
x: px,
|
|
20
|
+
y: py - 28,
|
|
21
|
+
text: label?.trim() || 'Video player',
|
|
22
|
+
fontSize: 14,
|
|
23
|
+
fontWeight: 'bold',
|
|
24
|
+
autoWidth: true
|
|
25
|
+
});
|
|
26
|
+
const thumbW = w;
|
|
27
|
+
const thumbH = snap(thumbW * (9 / 16));
|
|
28
|
+
const frame = createRectObject({
|
|
29
|
+
x: px,
|
|
30
|
+
y: py,
|
|
31
|
+
width: thumbW,
|
|
32
|
+
height: thumbH,
|
|
33
|
+
roundness: 10,
|
|
34
|
+
stroke: STROKE,
|
|
35
|
+
strokeWidth: STROKE_WIDTH
|
|
36
|
+
});
|
|
37
|
+
const screen = createRectObject({
|
|
38
|
+
x: px + 12,
|
|
39
|
+
y: py + 12,
|
|
40
|
+
width: thumbW - 24,
|
|
41
|
+
height: thumbH - 24,
|
|
42
|
+
roundness: 8,
|
|
43
|
+
fill: '#f3f4f6',
|
|
44
|
+
stroke: 'transparent',
|
|
45
|
+
strokeWidth: 0
|
|
46
|
+
});
|
|
47
|
+
const screenLabel = createTextObject({
|
|
48
|
+
x: px + 16,
|
|
49
|
+
y: py + 4,
|
|
50
|
+
text: 'Thumbnail',
|
|
51
|
+
fontSize: 11,
|
|
52
|
+
autoWidth: true
|
|
53
|
+
});
|
|
54
|
+
const playSize = 56;
|
|
55
|
+
const play = createRectObject({
|
|
56
|
+
x: px + thumbW / 2 - playSize / 2,
|
|
57
|
+
y: py + thumbH / 2 - playSize / 2,
|
|
58
|
+
width: playSize,
|
|
59
|
+
height: playSize,
|
|
60
|
+
roundness: 100,
|
|
61
|
+
fill: '#e5e7eb',
|
|
62
|
+
stroke: '#d1d5db',
|
|
63
|
+
strokeWidth: 1
|
|
64
|
+
});
|
|
65
|
+
const screenGroup = packGroup([frame, screen, play, screenLabel], {});
|
|
66
|
+
const navBar = createRectObject({
|
|
67
|
+
x: px,
|
|
68
|
+
y: py + thumbH + 16,
|
|
69
|
+
width: thumbW,
|
|
70
|
+
height: 40,
|
|
71
|
+
roundness: 8,
|
|
72
|
+
fill: '#f9fafb',
|
|
73
|
+
stroke: STROKE,
|
|
74
|
+
strokeWidth: STROKE_WIDTH
|
|
75
|
+
});
|
|
76
|
+
const navThumbs = [];
|
|
77
|
+
for (let i = 0; i < 5; i++) {
|
|
78
|
+
navThumbs.push(createRectObject({
|
|
79
|
+
x: px + 16 + i * 56,
|
|
80
|
+
y: py + thumbH + 32,
|
|
81
|
+
width: 40,
|
|
82
|
+
height: 8,
|
|
83
|
+
roundness: 4,
|
|
84
|
+
fill: '#d1d5db',
|
|
85
|
+
stroke: 'transparent',
|
|
86
|
+
strokeWidth: 0
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
const navTitle = createTextObject({
|
|
90
|
+
x: px,
|
|
91
|
+
y: py + thumbH + 4,
|
|
92
|
+
text: 'Navigation',
|
|
93
|
+
fontSize: 12,
|
|
94
|
+
fontWeight: 'bold',
|
|
95
|
+
autoWidth: true
|
|
96
|
+
});
|
|
97
|
+
const navGroup = packGroup([navBar, navTitle, ...navThumbs], {});
|
|
98
|
+
objects.push(title, ...screenGroup.objects, ...navGroup.objects);
|
|
99
|
+
return {
|
|
100
|
+
objects,
|
|
101
|
+
rootLabel: 'Video player',
|
|
102
|
+
highlightIds: [navGroup.groupId]
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
case 'navigation_bar': {
|
|
106
|
+
const bar = createRectObject({
|
|
107
|
+
x: px,
|
|
108
|
+
y: py + 20,
|
|
109
|
+
width: w,
|
|
110
|
+
height: snap(Math.min(48, h)),
|
|
111
|
+
roundness: 8,
|
|
112
|
+
stroke: STROKE,
|
|
113
|
+
strokeWidth: STROKE_WIDTH,
|
|
114
|
+
fill: '#f9fafb'
|
|
115
|
+
});
|
|
116
|
+
const title = createTextObject({
|
|
117
|
+
x: px,
|
|
118
|
+
y: py,
|
|
119
|
+
text: label?.trim() || 'Navigation bar',
|
|
120
|
+
fontSize: 12,
|
|
121
|
+
fontWeight: 'bold',
|
|
122
|
+
autoWidth: true
|
|
123
|
+
});
|
|
124
|
+
const tabs = [];
|
|
125
|
+
for (let i = 0; i < 4; i++) {
|
|
126
|
+
tabs.push(createTextObject({
|
|
127
|
+
x: px + 16 + i * 96,
|
|
128
|
+
y: py + 36,
|
|
129
|
+
text: `Nav ${i + 1}`,
|
|
130
|
+
fontSize: 14,
|
|
131
|
+
autoWidth: true
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
const packed = packGroup([bar, ...tabs], {});
|
|
135
|
+
objects.push(title, ...packed.objects);
|
|
136
|
+
return { objects, rootLabel: label?.trim() || 'Navigation bar' };
|
|
137
|
+
}
|
|
138
|
+
case 'button': {
|
|
139
|
+
const btnH = snap(Math.max(44, Math.min(48, h)));
|
|
140
|
+
const btnW = snap(Math.max(128, w));
|
|
141
|
+
const btn = createRectObject({
|
|
142
|
+
x: px,
|
|
143
|
+
y: py + 22,
|
|
144
|
+
width: btnW,
|
|
145
|
+
height: btnH,
|
|
146
|
+
roundness: 8,
|
|
147
|
+
fill: '#f9fafb',
|
|
148
|
+
stroke: STROKE,
|
|
149
|
+
strokeWidth: STROKE_WIDTH
|
|
150
|
+
});
|
|
151
|
+
const caption = createTextObject({
|
|
152
|
+
x: px + 16,
|
|
153
|
+
y: py + 34,
|
|
154
|
+
text: label ?? 'Button',
|
|
155
|
+
fontSize: 15,
|
|
156
|
+
autoWidth: true
|
|
157
|
+
});
|
|
158
|
+
const title = createTextObject({
|
|
159
|
+
x: px,
|
|
160
|
+
y: py,
|
|
161
|
+
text: 'Button',
|
|
162
|
+
fontSize: 11,
|
|
163
|
+
color: '#6b7280',
|
|
164
|
+
autoWidth: true
|
|
165
|
+
});
|
|
166
|
+
const packed = packGroup([btn, caption], {});
|
|
167
|
+
objects.push(title, ...packed.objects);
|
|
168
|
+
return { objects, rootLabel: label ?? 'Button' };
|
|
169
|
+
}
|
|
170
|
+
case 'card': {
|
|
171
|
+
const cardH = snap(Math.max(160, h));
|
|
172
|
+
const card = createRectObject({
|
|
173
|
+
x: px,
|
|
174
|
+
y: py + 24,
|
|
175
|
+
width: w,
|
|
176
|
+
height: cardH,
|
|
177
|
+
roundness: 12,
|
|
178
|
+
stroke: STROKE,
|
|
179
|
+
strokeWidth: STROKE_WIDTH,
|
|
180
|
+
fill: '#ffffff'
|
|
181
|
+
});
|
|
182
|
+
const heading = createTextObject({
|
|
183
|
+
x: px + 16,
|
|
184
|
+
y: py + 40,
|
|
185
|
+
text: label ?? 'Card title',
|
|
186
|
+
fontSize: 18,
|
|
187
|
+
fontWeight: 'bold',
|
|
188
|
+
autoWidth: true
|
|
189
|
+
});
|
|
190
|
+
const body = createRectObject({
|
|
191
|
+
x: px + 16,
|
|
192
|
+
y: py + 72,
|
|
193
|
+
width: w - 32,
|
|
194
|
+
height: Math.max(48, cardH - 96),
|
|
195
|
+
roundness: 6,
|
|
196
|
+
fill: '#f3f4f6',
|
|
197
|
+
stroke: 'transparent',
|
|
198
|
+
strokeWidth: 0
|
|
199
|
+
});
|
|
200
|
+
const title = createTextObject({ x: px, y: py, text: 'Card', fontSize: 11, color: '#6b7280', autoWidth: true });
|
|
201
|
+
const packed = packGroup([card, heading, body], {});
|
|
202
|
+
objects.push(title, ...packed.objects);
|
|
203
|
+
return { objects, rootLabel: label ?? 'Card' };
|
|
204
|
+
}
|
|
205
|
+
case 'form': {
|
|
206
|
+
const title = createTextObject({ x: px, y: py, text: label ?? 'Form', fontSize: 12, fontWeight: 'bold', autoWidth: true });
|
|
207
|
+
const fields = [];
|
|
208
|
+
for (let i = 0; i < 3; i++) {
|
|
209
|
+
fields.push(createRectObject({
|
|
210
|
+
x: px,
|
|
211
|
+
y: py + 32 + i * 48,
|
|
212
|
+
width: w,
|
|
213
|
+
height: 36,
|
|
214
|
+
roundness: 6,
|
|
215
|
+
stroke: STROKE,
|
|
216
|
+
strokeWidth: 1,
|
|
217
|
+
fill: '#fff'
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
const packed = packGroup(fields, {});
|
|
221
|
+
objects.push(title, ...packed.objects);
|
|
222
|
+
return { objects, rootLabel: label ?? 'Form' };
|
|
223
|
+
}
|
|
224
|
+
default: {
|
|
225
|
+
const box = createRectObject({
|
|
226
|
+
x: px,
|
|
227
|
+
y: py + 20,
|
|
228
|
+
width: w,
|
|
229
|
+
height: h,
|
|
230
|
+
roundness: 8,
|
|
231
|
+
stroke: STROKE,
|
|
232
|
+
strokeWidth: STROKE_WIDTH
|
|
233
|
+
});
|
|
234
|
+
const title = createTextObject({
|
|
235
|
+
x: px,
|
|
236
|
+
y: py,
|
|
237
|
+
text: label ?? kind.replace(/_/g, ' '),
|
|
238
|
+
fontSize: 14,
|
|
239
|
+
autoWidth: true
|
|
240
|
+
});
|
|
241
|
+
objects.push(title, box);
|
|
242
|
+
return { objects, rootLabel: label ?? kind };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth = 2) {
|
|
247
|
+
const geometry = buildArrow({ x: fromX, y: fromY }, { x: toX, y: toY }, 0, strokeWidth);
|
|
248
|
+
return createPathObject({
|
|
249
|
+
x: geometry.box.x,
|
|
250
|
+
y: geometry.box.y,
|
|
251
|
+
width: geometry.box.width,
|
|
252
|
+
height: geometry.box.height,
|
|
253
|
+
d: serializePathData(geometry.commands),
|
|
254
|
+
shape: 'arrow',
|
|
255
|
+
arrow: geometry.spec,
|
|
256
|
+
stroke: '#111827',
|
|
257
|
+
strokeWidth,
|
|
258
|
+
fill: 'transparent'
|
|
259
|
+
});
|
|
260
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ObjectId, SceneObject } from '../../engine/core/types.js';
|
|
2
|
+
/** Insert a group and its members in list order (group before members). */
|
|
3
|
+
export declare function packGroup(members: SceneObject[], options?: {
|
|
4
|
+
groupId?: ObjectId;
|
|
5
|
+
parentId?: ObjectId | null;
|
|
6
|
+
}): {
|
|
7
|
+
groupId: ObjectId;
|
|
8
|
+
objects: SceneObject[];
|
|
9
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createGroupObject, createObjectId } from '../../engine/core/defaults.js';
|
|
2
|
+
/** Insert a group and its members in list order (group before members). */
|
|
3
|
+
export function packGroup(members, options = {}) {
|
|
4
|
+
const groupId = options.groupId ?? createObjectId('gp');
|
|
5
|
+
const parentId = options.parentId ?? null;
|
|
6
|
+
const withParents = members.map((object) => ({ ...object, parentId: groupId }));
|
|
7
|
+
return {
|
|
8
|
+
groupId,
|
|
9
|
+
objects: [createGroupObject({ id: groupId, parentId }), ...withParents]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CanvasToolDefinition } from './types.js';
|
|
2
|
+
import { CANVAS_TOOL_NAMES } from './types.js';
|
|
3
|
+
export declare const CANVAS_TOOL_DEFINITIONS: CanvasToolDefinition[];
|
|
4
|
+
export declare function isCanvasToolName(name: string): name is (typeof CANVAS_TOOL_NAMES)[number];
|
|
5
|
+
/** OpenAI / MCP-style tool list for the gateway LLM loop. */
|
|
6
|
+
export declare function toOpenAiTools(): Array<{
|
|
7
|
+
type: 'function';
|
|
8
|
+
function: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
parameters: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
/** MCP tool catalogue (names + inputSchema only). */
|
|
15
|
+
export declare function toMcpTools(): Array<{
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
inputSchema: Record<string, unknown>;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { CANVAS_TOOL_NAMES } from './types.js';
|
|
2
|
+
export const CANVAS_TOOL_DEFINITIONS = [
|
|
3
|
+
{
|
|
4
|
+
name: 'get_canvas',
|
|
5
|
+
description: 'Read a compact summary of everything on the canvas: element ids, kinds, text labels, bounding boxes and z-order.',
|
|
6
|
+
parameters: {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {},
|
|
9
|
+
additionalProperties: false
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'draw_ui_component',
|
|
14
|
+
description: 'Draw a wireframe UI component from the catalogue as grouped primitives. Use for video players, nav bars, cards, buttons, forms, tables, carousels, modals.',
|
|
15
|
+
parameters: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
required: ['component', 'x', 'y'],
|
|
18
|
+
properties: {
|
|
19
|
+
component: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
enum: ['video_player', 'navigation_bar', 'card', 'button', 'form', 'table', 'carousel', 'modal']
|
|
22
|
+
},
|
|
23
|
+
x: { type: 'number' },
|
|
24
|
+
y: { type: 'number' },
|
|
25
|
+
width: { type: 'number', minimum: 40, maximum: 2000 },
|
|
26
|
+
height: { type: 'number', minimum: 40, maximum: 2000 },
|
|
27
|
+
label: { type: 'string', maxLength: 120 }
|
|
28
|
+
},
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'add_shape',
|
|
34
|
+
description: 'Add a primitive rectangle, rounded rectangle, ellipse, or diamond.',
|
|
35
|
+
parameters: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
required: ['shape', 'x', 'y', 'width', 'height'],
|
|
38
|
+
properties: {
|
|
39
|
+
shape: { type: 'string', enum: ['rectangle', 'rounded', 'ellipse', 'diamond'] },
|
|
40
|
+
x: { type: 'number' },
|
|
41
|
+
y: { type: 'number' },
|
|
42
|
+
width: { type: 'number', minimum: 4, maximum: 4000 },
|
|
43
|
+
height: { type: 'number', minimum: 4, maximum: 4000 },
|
|
44
|
+
label: { type: 'string', maxLength: 200 }
|
|
45
|
+
},
|
|
46
|
+
additionalProperties: false
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'add_text',
|
|
51
|
+
description: 'Place a text label on the canvas.',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
required: ['text', 'x', 'y'],
|
|
55
|
+
properties: {
|
|
56
|
+
text: { type: 'string', minLength: 1, maxLength: 500 },
|
|
57
|
+
x: { type: 'number' },
|
|
58
|
+
y: { type: 'number' },
|
|
59
|
+
width: { type: 'number', minimum: 20, maximum: 2000 }
|
|
60
|
+
},
|
|
61
|
+
additionalProperties: false
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'add_arrow',
|
|
66
|
+
description: 'Draw an arrow from a start point or element to an end point or element.',
|
|
67
|
+
parameters: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
fromId: { type: 'string' },
|
|
71
|
+
toId: { type: 'string' },
|
|
72
|
+
fromX: { type: 'number' },
|
|
73
|
+
fromY: { type: 'number' },
|
|
74
|
+
toX: { type: 'number' },
|
|
75
|
+
toY: { type: 'number' },
|
|
76
|
+
label: { type: 'string', maxLength: 120 }
|
|
77
|
+
},
|
|
78
|
+
additionalProperties: false
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'move_elements',
|
|
83
|
+
description: 'Move elements by id. Use dx/dy for a relative move, or x/y to set the top-left of the first id.',
|
|
84
|
+
parameters: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
required: ['ids'],
|
|
87
|
+
properties: {
|
|
88
|
+
ids: { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 50 },
|
|
89
|
+
dx: { type: 'number' },
|
|
90
|
+
dy: { type: 'number' },
|
|
91
|
+
x: { type: 'number' },
|
|
92
|
+
y: { type: 'number' }
|
|
93
|
+
},
|
|
94
|
+
additionalProperties: false
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'delete_elements',
|
|
99
|
+
description: 'Delete elements by id, or pass ids ["all"] to remove every sketch object.',
|
|
100
|
+
parameters: {
|
|
101
|
+
type: 'object',
|
|
102
|
+
required: ['ids'],
|
|
103
|
+
properties: {
|
|
104
|
+
ids: { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 500 }
|
|
105
|
+
},
|
|
106
|
+
additionalProperties: false
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'clear_canvas',
|
|
111
|
+
description: 'Remove every object from the canvas.',
|
|
112
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false }
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'name_components_with_arrows',
|
|
116
|
+
description: 'For each non-text shape, add a readable name label and an arrow pointing at it.',
|
|
117
|
+
parameters: {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
prefix: { type: 'string', maxLength: 40 }
|
|
121
|
+
},
|
|
122
|
+
additionalProperties: false
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
export function isCanvasToolName(name) {
|
|
127
|
+
return CANVAS_TOOL_NAMES.includes(name);
|
|
128
|
+
}
|
|
129
|
+
/** OpenAI / MCP-style tool list for the gateway LLM loop. */
|
|
130
|
+
export function toOpenAiTools() {
|
|
131
|
+
return CANVAS_TOOL_DEFINITIONS.map((tool) => ({
|
|
132
|
+
type: 'function',
|
|
133
|
+
function: {
|
|
134
|
+
name: tool.name,
|
|
135
|
+
description: tool.description,
|
|
136
|
+
parameters: tool.parameters
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
/** MCP tool catalogue (names + inputSchema only). */
|
|
141
|
+
export function toMcpTools() {
|
|
142
|
+
return CANVAS_TOOL_DEFINITIONS.map((tool) => ({
|
|
143
|
+
name: tool.name,
|
|
144
|
+
description: tool.description,
|
|
145
|
+
inputSchema: tool.parameters
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ObjectId } from '../engine/core/types.js';
|
|
2
|
+
import type { CanvasToolHost, CanvasToolName, ToolResult } from './types.js';
|
|
3
|
+
export declare function executeCanvasTool(host: CanvasToolHost, name: CanvasToolName, args: Record<string, unknown>): ToolResult;
|
|
4
|
+
/** Navigation wireframe group (label "Navigation"). */
|
|
5
|
+
export declare function findNavigationId(scene: ReturnType<CanvasToolHost['getScene']>): ObjectId | null;
|
|
6
|
+
export declare function findVideoThumbnailBounds(scene: ReturnType<CanvasToolHost['getScene']>): import("../engine/core/types.js").Rect | null;
|
|
7
|
+
export declare function findVideoPlayerRoot(scene: ReturnType<CanvasToolHost['getScene']>): ObjectId | null;
|