@widgetic/canvas 0.5.44 → 0.5.45
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/dist/canvas/DomCanvas.svelte +52 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
- package/dist/canvas/autosaveScheduler.js +89 -37
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +19 -7
- package/dist/canvas/chromeLayout.js +21 -19
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +68 -1
- package/dist/canvas/host/CanvasHost.js +1901 -1407
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +28 -5
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +155 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +211 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +21 -18
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +11 -9
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/storedPictures.js +243 -149
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +7 -6
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +25 -13
- package/dist/canvas/shapes/ShapeLibrary.js +148 -138
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/SelectionPanel.svelte +78 -17
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +34 -55
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +43 -21
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +66 -35
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +90 -71
- package/dist/canvas/view/liftedScene.js +36 -24
- package/dist/canvas/view/mountedScene.js +79 -76
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +37 -2
- package/dist/engine/EngineCore.js +946 -768
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +172 -186
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +109 -84
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +126 -101
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +48 -29
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +98 -78
- package/dist/engine/core/cameraMove.d.ts +6 -0
- package/dist/engine/core/cameraMove.js +56 -38
- package/dist/engine/core/defaults.js +51 -90
- package/dist/engine/core/freehand.js +163 -147
- package/dist/engine/core/geometry.js +54 -47
- package/dist/engine/core/history.js +55 -38
- package/dist/engine/core/hitTest.js +81 -68
- package/dist/engine/core/matrix.js +20 -18
- package/dist/engine/core/pathData.js +210 -183
- package/dist/engine/core/rotationReset.js +6 -5
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +288 -139
- package/dist/engine/core/scribble.js +84 -59
- package/dist/engine/core/shapePaths.js +15 -12
- package/dist/engine/core/shapeTools.js +63 -72
- package/dist/engine/core/snapping.js +117 -65
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +82 -33
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +103 -83
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +547 -476
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +340 -266
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +131 -32
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +25 -4
- package/dist/engine/text/layoutText.js +62 -43
- package/dist/engine/text/textMetrics.js +10 -8
- package/dist/engine/widgets.js +137 -101
- package/dist/fonts/interFont.js +83 -30
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +108 -34
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +7 -1
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +30 -26
- package/dist/index.d.ts +1 -0
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +140 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +251 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +112 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +138 -0
- package/dist/settings/workspaceToolSettings.d.ts +6 -0
- package/dist/settings/workspaceToolSettings.js +58 -34
- package/dist/tools/components/catalog.js +74 -64
- package/dist/tools/components/grouping.js +28 -6
- package/dist/tools/definitions.js +31 -9
- package/dist/tools/executors.js +214 -106
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +15 -11
- package/dist/tools/sceneSummary.js +57 -43
- package/dist/tools/sketchIntent.js +21 -13
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +93 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +2 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CANVAS_TOOL_NAMES } from './types.js';
|
|
2
|
-
export
|
|
2
|
+
export var CANVAS_TOOL_DEFINITIONS = [
|
|
3
3
|
{
|
|
4
4
|
name: 'get_canvas',
|
|
5
5
|
description: 'Read a compact summary of everything on the canvas: element ids, kinds, text labels, bounding boxes and z-order.',
|
|
@@ -31,7 +31,7 @@ export const CANVAS_TOOL_DEFINITIONS = [
|
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
name: 'add_shape',
|
|
34
|
-
description: 'Add a primitive rectangle, rounded rectangle, ellipse, or diamond.',
|
|
34
|
+
description: 'Add a primitive rectangle, rounded rectangle, ellipse, or diamond. Pass fill and stroke (hex colours, for example the brand colours listed in the request context) to colour it.',
|
|
35
35
|
parameters: {
|
|
36
36
|
type: 'object',
|
|
37
37
|
required: ['shape', 'x', 'y', 'width', 'height'],
|
|
@@ -41,14 +41,16 @@ export const CANVAS_TOOL_DEFINITIONS = [
|
|
|
41
41
|
y: { type: 'number' },
|
|
42
42
|
width: { type: 'number', minimum: 4, maximum: 4000 },
|
|
43
43
|
height: { type: 'number', minimum: 4, maximum: 4000 },
|
|
44
|
-
label: { type: 'string', maxLength: 200 }
|
|
44
|
+
label: { type: 'string', maxLength: 200 },
|
|
45
|
+
fill: { type: 'string', maxLength: 9, description: 'Fill colour as a hex colour such as #1a2b3c, or "transparent".' },
|
|
46
|
+
stroke: { type: 'string', maxLength: 9, description: 'Outline colour as a hex colour such as #1a2b3c.' }
|
|
45
47
|
},
|
|
46
48
|
additionalProperties: false
|
|
47
49
|
}
|
|
48
50
|
},
|
|
49
51
|
{
|
|
50
52
|
name: 'add_text',
|
|
51
|
-
description: 'Place a text label on the canvas.',
|
|
53
|
+
description: 'Place a text label on the canvas. Pass fontFamily (one of the brand fonts listed in the request context, or a font the canvas has), color (a hex colour such as a brand colour), fontSize and fontWeight to style it.',
|
|
52
54
|
parameters: {
|
|
53
55
|
type: 'object',
|
|
54
56
|
required: ['text', 'x', 'y'],
|
|
@@ -56,7 +58,27 @@ export const CANVAS_TOOL_DEFINITIONS = [
|
|
|
56
58
|
text: { type: 'string', minLength: 1, maxLength: 500 },
|
|
57
59
|
x: { type: 'number' },
|
|
58
60
|
y: { type: 'number' },
|
|
59
|
-
width: { type: 'number', minimum: 20, maximum: 2000 }
|
|
61
|
+
width: { type: 'number', minimum: 20, maximum: 2000 },
|
|
62
|
+
fontFamily: { type: 'string', maxLength: 80, description: 'A font family name exactly as listed (for example the brand kit fonts).' },
|
|
63
|
+
fontSize: { type: 'number', minimum: 8, maximum: 200 },
|
|
64
|
+
color: { type: 'string', maxLength: 9, description: 'Text colour as a hex colour such as #1a2b3c.' },
|
|
65
|
+
fontWeight: { type: 'string', enum: ['normal', 'bold'] }
|
|
66
|
+
},
|
|
67
|
+
additionalProperties: false
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'add_asset',
|
|
72
|
+
description: 'Place one picture from the assets listed in the request context on the canvas, by its assetId: an SVG icon from the user\'s brand kit or a file from the user\'s file browser. Prefer an asset over drawing a shape whenever one fits (a logo, an icon, a photo the user chose). Never invent an assetId. Pass width and height to size it (the proportions are kept when only one is given).',
|
|
73
|
+
parameters: {
|
|
74
|
+
type: 'object',
|
|
75
|
+
required: ['assetId', 'x', 'y'],
|
|
76
|
+
properties: {
|
|
77
|
+
assetId: { type: 'string', minLength: 1, maxLength: 120 },
|
|
78
|
+
x: { type: 'number' },
|
|
79
|
+
y: { type: 'number' },
|
|
80
|
+
width: { type: 'number', minimum: 8, maximum: 2000 },
|
|
81
|
+
height: { type: 'number', minimum: 8, maximum: 2000 }
|
|
60
82
|
},
|
|
61
83
|
additionalProperties: false
|
|
62
84
|
}
|
|
@@ -128,20 +150,20 @@ export function isCanvasToolName(name) {
|
|
|
128
150
|
}
|
|
129
151
|
/** OpenAI / MCP-style tool list for the gateway LLM loop. */
|
|
130
152
|
export function toOpenAiTools() {
|
|
131
|
-
return CANVAS_TOOL_DEFINITIONS.map((tool)
|
|
153
|
+
return CANVAS_TOOL_DEFINITIONS.map(function (tool) { return ({
|
|
132
154
|
type: 'function',
|
|
133
155
|
function: {
|
|
134
156
|
name: tool.name,
|
|
135
157
|
description: tool.description,
|
|
136
158
|
parameters: tool.parameters
|
|
137
159
|
}
|
|
138
|
-
}));
|
|
160
|
+
}); });
|
|
139
161
|
}
|
|
140
162
|
/** MCP tool catalogue (names + inputSchema only). */
|
|
141
163
|
export function toMcpTools() {
|
|
142
|
-
return CANVAS_TOOL_DEFINITIONS.map((tool)
|
|
164
|
+
return CANVAS_TOOL_DEFINITIONS.map(function (tool) { return ({
|
|
143
165
|
name: tool.name,
|
|
144
166
|
description: tool.description,
|
|
145
167
|
inputSchema: tool.parameters
|
|
146
|
-
}));
|
|
168
|
+
}); });
|
|
147
169
|
}
|
package/dist/tools/executors.js
CHANGED
|
@@ -1,25 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { createEllipseObject, createImageObject, createPathObject, createRectObject, createTextObject } from '../engine/core/defaults.js';
|
|
22
|
+
import { readImageAddress, readLibraryFileAddress } from '../engine/codec/canvasDocument.js';
|
|
2
23
|
import { buildArrow } from '../engine/core/arrow.js';
|
|
3
24
|
import { serializePathData } from '../engine/core/pathData.js';
|
|
4
25
|
import { boundsOfObjects, findObject, indexScene, normalizeScene, removeObjects, shapeBounds, translateObjects } from '../engine/core/scene.js';
|
|
5
26
|
import { isBoxedObject } from '../engine/core/types.js';
|
|
6
27
|
import { drawUiComponent, makeArrowBetween } from './components/catalog.js';
|
|
7
28
|
import { centerOf, findByLabel, kindOfObject, labelOfObject, summarizeScene } from './sceneSummary.js';
|
|
29
|
+
import { assetSizeFor, readColorArgument, readFontFamilyArgument, readNumberArgument } from './styleArguments.js';
|
|
8
30
|
function groupLabelForName(groupId, scene) {
|
|
9
|
-
for (
|
|
31
|
+
for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
|
|
32
|
+
var object = scene_1[_i];
|
|
10
33
|
if (object.parentId === groupId && object.type === 'text')
|
|
11
34
|
return object.text.trim();
|
|
12
35
|
}
|
|
13
36
|
return 'group';
|
|
14
37
|
}
|
|
15
38
|
function fail(code, error) {
|
|
16
|
-
return { ok: false, error, code };
|
|
39
|
+
return { ok: false, error: error, code: code };
|
|
17
40
|
}
|
|
18
|
-
function ok(message, extra
|
|
19
|
-
|
|
41
|
+
function ok(message, extra) {
|
|
42
|
+
if (extra === void 0) { extra = {}; }
|
|
43
|
+
return __assign({ ok: true, message: message }, extra);
|
|
20
44
|
}
|
|
21
45
|
function clampInBounds(host, x, y, width, height) {
|
|
22
|
-
|
|
46
|
+
var pad = 8;
|
|
23
47
|
return (x >= -pad &&
|
|
24
48
|
y >= -pad &&
|
|
25
49
|
x + width <= host.bounds.width + pad &&
|
|
@@ -28,141 +52,216 @@ function clampInBounds(host, x, y, width, height) {
|
|
|
28
52
|
height > 0);
|
|
29
53
|
}
|
|
30
54
|
function addToScene(host, objects) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return { scene, ids: withIds.map((object)
|
|
55
|
+
var withIds = objects.map(function (object) { var _a; return (__assign(__assign({}, object), { id: (_a = object.id) !== null && _a !== void 0 ? _a : host.createId(kindOfObject(object)) })); });
|
|
56
|
+
var scene = normalizeScene(__spreadArray(__spreadArray([], host.getScene(), true), withIds, true));
|
|
57
|
+
return { scene: scene, ids: withIds.map(function (object) { return object.id; }) };
|
|
34
58
|
}
|
|
35
|
-
|
|
36
|
-
get_canvas(host) {
|
|
37
|
-
|
|
38
|
-
return ok(
|
|
59
|
+
var executors = {
|
|
60
|
+
get_canvas: function (host) {
|
|
61
|
+
var summary = summarizeScene(host.getScene(), host.bounds);
|
|
62
|
+
return ok("Canvas has ".concat(summary.elements.length, " elements."), { summary: summary });
|
|
39
63
|
},
|
|
40
|
-
draw_ui_component(host, args) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
draw_ui_component: function (host, args) {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
var component = String((_a = args.component) !== null && _a !== void 0 ? _a : '');
|
|
67
|
+
var x = Number(args.x);
|
|
68
|
+
var y = Number(args.y);
|
|
69
|
+
var width = Number((_b = args.width) !== null && _b !== void 0 ? _b : 360);
|
|
70
|
+
var height = Number((_c = args.height) !== null && _c !== void 0 ? _c : 240);
|
|
71
|
+
var label = typeof args.label === 'string' ? args.label : undefined;
|
|
47
72
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
48
73
|
return fail('invalid_args', 'x and y are required numbers.');
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
var placement = drawUiComponent(component, x, y, width, height, label);
|
|
75
|
+
var _d = addToScene(host, placement.objects), scene = _d.scene, ids = _d.ids;
|
|
51
76
|
// The check is on what the component really covers (a button is 48 px high whatever height was asked for, a video
|
|
52
77
|
// player has its title above y and a navigation strip below the thumbnail), not on the size that was passed: a
|
|
53
78
|
// request with no size would otherwise be judged as 360 x 240, and a button near the bottom would be refused.
|
|
54
|
-
|
|
79
|
+
var covered = boundsOfObjects(scene, ids);
|
|
55
80
|
if (!covered || !clampInBounds(host, covered.x, covered.y, covered.width, covered.height)) {
|
|
56
|
-
|
|
57
|
-
?
|
|
81
|
+
var area = covered
|
|
82
|
+
? " It would cover x ".concat(Math.round(covered.x), " to ").concat(Math.round(covered.x + covered.width), " and y ").concat(Math.round(covered.y), " to ").concat(Math.round(covered.y + covered.height), ", and the canvas is ").concat(Math.round(host.bounds.width), " x ").concat(Math.round(host.bounds.height), ".")
|
|
58
83
|
: '';
|
|
59
|
-
return fail('bounds',
|
|
84
|
+
return fail('bounds', "Component would sit outside the canvas.".concat(area));
|
|
60
85
|
}
|
|
61
86
|
host.commitScene(scene);
|
|
62
|
-
return ok(
|
|
87
|
+
return ok("Drew ".concat(component, " (").concat(placement.rootLabel, ")."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
63
88
|
},
|
|
64
|
-
add_shape(host, args) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
add_shape: function (host, args) {
|
|
90
|
+
var _a;
|
|
91
|
+
var shape = String((_a = args.shape) !== null && _a !== void 0 ? _a : 'rectangle');
|
|
92
|
+
var x = Number(args.x);
|
|
93
|
+
var y = Number(args.y);
|
|
94
|
+
var width = Number(args.width);
|
|
95
|
+
var height = Number(args.height);
|
|
70
96
|
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
71
97
|
return fail('invalid_args', 'x, y, width and height are required.');
|
|
72
98
|
}
|
|
73
99
|
if (!clampInBounds(host, x, y, width, height))
|
|
74
100
|
return fail('bounds', 'Shape is outside the canvas.');
|
|
75
|
-
|
|
76
|
-
|
|
101
|
+
// The brand colours the assistant was told about: a bad colour is refused so the model can say it again.
|
|
102
|
+
var fill = readColorArgument(args.fill, 'fill', true);
|
|
103
|
+
if (!fill.ok)
|
|
104
|
+
return fail('invalid_args', fill.error);
|
|
105
|
+
var stroke = readColorArgument(args.stroke, 'stroke');
|
|
106
|
+
if (!stroke.ok)
|
|
107
|
+
return fail('invalid_args', stroke.error);
|
|
108
|
+
var paint = __assign(__assign({}, (fill.value !== undefined ? { fill: fill.value } : {})), (stroke.value !== undefined ? { stroke: stroke.value } : {}));
|
|
109
|
+
var object;
|
|
110
|
+
var label = typeof args.label === 'string' ? args.label : undefined;
|
|
77
111
|
if (shape === 'ellipse') {
|
|
78
|
-
object = createEllipseObject({ x, y, width, height });
|
|
112
|
+
object = createEllipseObject(__assign({ x: x, y: y, width: width, height: height }, paint));
|
|
79
113
|
}
|
|
80
114
|
else if (shape === 'diamond') {
|
|
81
|
-
|
|
82
|
-
object = createPathObject({ x, y, width, height, d: path, shape: 'diamond' });
|
|
115
|
+
var path = "M ".concat(width / 2, " 0 L ").concat(width, " ").concat(height / 2, " L ").concat(width / 2, " ").concat(height, " L 0 ").concat(height / 2, " Z");
|
|
116
|
+
object = createPathObject(__assign({ x: x, y: y, width: width, height: height, d: path, shape: 'diamond' }, paint));
|
|
83
117
|
}
|
|
84
118
|
else {
|
|
85
|
-
object = createRectObject({ x, y, width, height, roundness: shape === 'rounded' ? 16 : 0 });
|
|
119
|
+
object = createRectObject(__assign({ x: x, y: y, width: width, height: height, roundness: shape === 'rounded' ? 16 : 0 }, paint));
|
|
86
120
|
}
|
|
87
|
-
|
|
121
|
+
var objects = [object];
|
|
88
122
|
if (label) {
|
|
89
123
|
objects.push(createTextObject({ x: x + 4, y: y + 4, text: label, fontSize: 12, autoWidth: true }));
|
|
90
124
|
}
|
|
91
|
-
|
|
125
|
+
var _b = addToScene(host, objects), scene = _b.scene, ids = _b.ids;
|
|
92
126
|
host.commitScene(scene);
|
|
93
|
-
return ok(
|
|
127
|
+
return ok("Added ".concat(shape, "."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
94
128
|
},
|
|
95
|
-
add_text(host, args) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
129
|
+
add_text: function (host, args) {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
var text = String((_a = args.text) !== null && _a !== void 0 ? _a : '').trim();
|
|
132
|
+
var x = Number(args.x);
|
|
133
|
+
var y = Number(args.y);
|
|
99
134
|
if (!text)
|
|
100
135
|
return fail('invalid_args', 'text is required.');
|
|
101
136
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
102
137
|
return fail('invalid_args', 'x and y are required.');
|
|
103
|
-
|
|
104
|
-
|
|
138
|
+
var width = Number((_b = args.width) !== null && _b !== void 0 ? _b : 200);
|
|
139
|
+
// The look: the brand fonts and colours the assistant was told about. Anything the canvas does not have is refused.
|
|
140
|
+
var fontFamily = readFontFamilyArgument(args.fontFamily, host.fontFamilies);
|
|
141
|
+
if (!fontFamily.ok)
|
|
142
|
+
return fail('invalid_args', fontFamily.error);
|
|
143
|
+
var color = readColorArgument(args.color, 'color');
|
|
144
|
+
if (!color.ok)
|
|
145
|
+
return fail('invalid_args', color.error);
|
|
146
|
+
var fontSize = readNumberArgument(args.fontSize, 'fontSize', 8, 200);
|
|
147
|
+
if (!fontSize.ok)
|
|
148
|
+
return fail('invalid_args', fontSize.error);
|
|
149
|
+
if (args.fontWeight !== undefined && args.fontWeight !== 'normal' && args.fontWeight !== 'bold') {
|
|
150
|
+
return fail('invalid_args', 'fontWeight must be "normal" or "bold".');
|
|
151
|
+
}
|
|
152
|
+
var look = __assign(__assign(__assign(__assign({}, (fontFamily.value !== undefined ? { fontFamily: fontFamily.value } : {})), (color.value !== undefined ? { color: color.value } : {})), (fontSize.value !== undefined ? { fontSize: fontSize.value, height: Math.ceil(fontSize.value * 1.2) } : {})), (args.fontWeight === 'bold' ? { fontWeight: 'bold' } : {}));
|
|
153
|
+
var object = createTextObject(__assign({ x: x, y: y, width: width, text: text, autoWidth: width <= 40 }, look));
|
|
105
154
|
if (!clampInBounds(host, x, y, object.width, object.height))
|
|
106
155
|
return fail('bounds', 'Text is outside the canvas.');
|
|
107
|
-
|
|
156
|
+
var _c = addToScene(host, [object]), scene = _c.scene, ids = _c.ids;
|
|
108
157
|
host.commitScene(scene);
|
|
109
158
|
return ok('Added text.', { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
110
159
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
160
|
+
add_asset: function (host, args) {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
var assetId = typeof args.assetId === 'string' ? args.assetId.trim() : '';
|
|
163
|
+
if (!assetId)
|
|
164
|
+
return fail('invalid_args', 'assetId is required.');
|
|
165
|
+
var assets = (_a = host.assets) !== null && _a !== void 0 ? _a : [];
|
|
166
|
+
if (assets.length === 0) {
|
|
167
|
+
return fail('not_found', 'There are no assets to place: this canvas has no brand-kit icons or library files for the assistant. Draw with shapes and text instead.');
|
|
168
|
+
}
|
|
169
|
+
var asset = assets.find(function (candidate) { return candidate.id === assetId; });
|
|
170
|
+
if (!asset) {
|
|
171
|
+
var listed = assets.slice(0, 24).map(function (candidate) { return candidate.id; }).join(', ');
|
|
172
|
+
return fail('not_found', "Unknown assetId \"".concat(assetId, "\". Use one of: ").concat(listed).concat(assets.length > 24 ? ', …' : '', "."));
|
|
173
|
+
}
|
|
174
|
+
var x = Number(args.x);
|
|
175
|
+
var y = Number(args.y);
|
|
176
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
177
|
+
return fail('invalid_args', 'x and y are required.');
|
|
178
|
+
var width = readNumberArgument(args.width, 'width', 8, 2000);
|
|
179
|
+
if (!width.ok)
|
|
180
|
+
return fail('invalid_args', width.error);
|
|
181
|
+
var height = readNumberArgument(args.height, 'height', 8, 2000);
|
|
182
|
+
if (!height.ok)
|
|
183
|
+
return fail('invalid_args', height.error);
|
|
184
|
+
// The page built the asset list, but its pictures are drawn into the board like any other: only a loadable address goes in.
|
|
185
|
+
var src = readImageAddress(asset.src);
|
|
186
|
+
if (!src)
|
|
187
|
+
return fail('invalid_args', "Asset \"".concat(asset.id, "\" has no picture the canvas can draw."));
|
|
188
|
+
var size = assetSizeFor(asset, width.value, height.value);
|
|
189
|
+
if (!clampInBounds(host, x, y, size.width, size.height))
|
|
190
|
+
return fail('bounds', 'Asset would sit outside the canvas.');
|
|
191
|
+
var object = createImageObject({
|
|
192
|
+
x: x,
|
|
193
|
+
y: y,
|
|
194
|
+
width: size.width,
|
|
195
|
+
height: size.height,
|
|
196
|
+
src: src,
|
|
197
|
+
fileName: asset.name.slice(0, 300),
|
|
198
|
+
// A library file keeps the library's id, so the canvas never puts it in the library a second time.
|
|
199
|
+
libraryFileId: (_b = asset.libraryFileId) !== null && _b !== void 0 ? _b : null,
|
|
200
|
+
libraryFileUrl: readLibraryFileAddress(asset.libraryFileUrl),
|
|
201
|
+
naturalWidth: asset.width && asset.width > 0 ? asset.width : size.width,
|
|
202
|
+
naturalHeight: asset.height && asset.height > 0 ? asset.height : size.height
|
|
203
|
+
});
|
|
204
|
+
var _c = addToScene(host, [object]), scene = _c.scene, ids = _c.ids;
|
|
205
|
+
host.commitScene(scene);
|
|
206
|
+
return ok("Placed ".concat(asset.name, "."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
207
|
+
},
|
|
208
|
+
add_arrow: function (host, args) {
|
|
209
|
+
var fromX = Number(args.fromX);
|
|
210
|
+
var fromY = Number(args.fromY);
|
|
211
|
+
var toX = Number(args.toX);
|
|
212
|
+
var toY = Number(args.toY);
|
|
213
|
+
var scene = host.getScene();
|
|
117
214
|
if (typeof args.fromId === 'string') {
|
|
118
|
-
|
|
215
|
+
var center = centerOf(args.fromId, scene);
|
|
119
216
|
if (!center)
|
|
120
|
-
return fail('not_found',
|
|
217
|
+
return fail('not_found', "fromId ".concat(args.fromId, " not found."));
|
|
121
218
|
fromX = center.x;
|
|
122
219
|
fromY = center.y;
|
|
123
220
|
}
|
|
124
221
|
if (typeof args.toId === 'string') {
|
|
125
|
-
|
|
222
|
+
var center = centerOf(args.toId, scene);
|
|
126
223
|
if (!center)
|
|
127
|
-
return fail('not_found',
|
|
224
|
+
return fail('not_found', "toId ".concat(args.toId, " not found."));
|
|
128
225
|
toX = center.x;
|
|
129
226
|
toY = center.y;
|
|
130
227
|
}
|
|
131
228
|
if (![fromX, fromY, toX, toY].every(Number.isFinite))
|
|
132
229
|
return fail('invalid_args', 'Need from/to points or ids.');
|
|
133
|
-
|
|
230
|
+
var objects = [makeArrowBetween(fromX, fromY, toX, toY)];
|
|
134
231
|
if (typeof args.label === 'string' && args.label.trim()) {
|
|
135
232
|
objects.push(createTextObject({ x: (fromX + toX) / 2, y: (fromY + toY) / 2 - 16, text: args.label.trim(), fontSize: 12, autoWidth: true }));
|
|
136
233
|
}
|
|
137
|
-
|
|
234
|
+
var added = addToScene(host, objects);
|
|
138
235
|
host.commitScene(added.scene);
|
|
139
236
|
return ok('Added arrow.', { createdIds: added.ids, summary: summarizeScene(added.scene, host.bounds) });
|
|
140
237
|
},
|
|
141
|
-
move_elements(host, args) {
|
|
142
|
-
|
|
238
|
+
move_elements: function (host, args) {
|
|
239
|
+
var _a, _b;
|
|
240
|
+
var ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
|
|
143
241
|
if (ids.length === 0)
|
|
144
242
|
return fail('invalid_args', 'ids required.');
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
for (
|
|
243
|
+
var scene = host.getScene();
|
|
244
|
+
var index = indexScene(scene);
|
|
245
|
+
for (var _i = 0, ids_1 = ids; _i < ids_1.length; _i++) {
|
|
246
|
+
var id = ids_1[_i];
|
|
148
247
|
if (!index.has(id))
|
|
149
|
-
return fail('not_found',
|
|
248
|
+
return fail('not_found', "Element ".concat(id, " not found."));
|
|
150
249
|
}
|
|
151
|
-
|
|
152
|
-
|
|
250
|
+
var dx = Number((_a = args.dx) !== null && _a !== void 0 ? _a : 0);
|
|
251
|
+
var dy = Number((_b = args.dy) !== null && _b !== void 0 ? _b : 0);
|
|
153
252
|
if ((Number.isFinite(args.x) || Number.isFinite(args.y)) && ids.length > 0) {
|
|
154
|
-
|
|
253
|
+
var first = findObject(scene, ids[0]);
|
|
155
254
|
if (!first)
|
|
156
255
|
return fail('not_found', 'First id not movable.');
|
|
157
|
-
|
|
256
|
+
var bbox = first.type === 'group'
|
|
158
257
|
? boundsOfObjects(scene, [first.id])
|
|
159
258
|
: isBoxedObject(first)
|
|
160
259
|
? shapeBounds(first)
|
|
161
260
|
: null;
|
|
162
261
|
if (!bbox)
|
|
163
262
|
return fail('not_found', 'First id not movable.');
|
|
164
|
-
|
|
165
|
-
|
|
263
|
+
var targetDx = Number.isFinite(args.x) ? Number(args.x) - bbox.x : 0;
|
|
264
|
+
var targetDy = Number.isFinite(args.y) ? Number(args.y) - bbox.y : 0;
|
|
166
265
|
scene = translateObjects(scene, ids, targetDx, targetDy);
|
|
167
266
|
}
|
|
168
267
|
else if (dx !== 0 || dy !== 0) {
|
|
@@ -172,35 +271,36 @@ const executors = {
|
|
|
172
271
|
return fail('invalid_args', 'Provide dx/dy or x/y.');
|
|
173
272
|
}
|
|
174
273
|
host.commitScene(scene);
|
|
175
|
-
return ok(
|
|
274
|
+
return ok("Moved ".concat(ids.length, " element(s)."), { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
176
275
|
},
|
|
177
|
-
delete_elements(host, args) {
|
|
178
|
-
|
|
276
|
+
delete_elements: function (host, args) {
|
|
277
|
+
var ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
|
|
179
278
|
if (ids.length === 0)
|
|
180
279
|
return fail('invalid_args', 'ids required.');
|
|
181
|
-
|
|
280
|
+
var scene = host.getScene();
|
|
182
281
|
if (ids.length === 1 && ids[0] === 'all') {
|
|
183
282
|
scene = [];
|
|
184
283
|
}
|
|
185
284
|
else {
|
|
186
|
-
|
|
285
|
+
var missing = ids.filter(function (id) { return !findObject(scene, id); });
|
|
187
286
|
if (missing.length > 0)
|
|
188
|
-
return fail('not_found',
|
|
287
|
+
return fail('not_found', "Unknown ids: ".concat(missing.join(', ')));
|
|
189
288
|
scene = removeObjects(scene, ids);
|
|
190
289
|
}
|
|
191
290
|
host.commitScene(scene);
|
|
192
291
|
return ok('Deleted elements.', { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
193
292
|
},
|
|
194
|
-
clear_canvas(host) {
|
|
195
|
-
|
|
293
|
+
clear_canvas: function (host) {
|
|
294
|
+
var scene = [];
|
|
196
295
|
host.commitScene(scene);
|
|
197
296
|
return ok('Canvas cleared.', { summary: summarizeScene(scene, host.bounds) });
|
|
198
297
|
},
|
|
199
|
-
name_components_with_arrows(host, args) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (
|
|
298
|
+
name_components_with_arrows: function (host, args) {
|
|
299
|
+
var prefix = typeof args.prefix === 'string' ? args.prefix.trim() : '';
|
|
300
|
+
var sceneBefore = host.getScene();
|
|
301
|
+
var additions = [];
|
|
302
|
+
for (var _i = 0, sceneBefore_1 = sceneBefore; _i < sceneBefore_1.length; _i++) {
|
|
303
|
+
var object = sceneBefore_1[_i];
|
|
204
304
|
if (object.parentId !== null)
|
|
205
305
|
continue;
|
|
206
306
|
if (object.type === 'text')
|
|
@@ -209,19 +309,19 @@ const executors = {
|
|
|
209
309
|
continue;
|
|
210
310
|
if (!isBoxedObject(object) && object.type !== 'group')
|
|
211
311
|
continue;
|
|
212
|
-
|
|
213
|
-
|
|
312
|
+
var name = "".concat(prefix ? "".concat(prefix, " ") : '').concat(object.type === 'group' ? groupLabelForName(object.id, sceneBefore) : labelOfObject(object)).trim();
|
|
313
|
+
var bbox = object.type === 'group'
|
|
214
314
|
? boundsOfObjects(sceneBefore, [object.id])
|
|
215
315
|
: isBoxedObject(object)
|
|
216
316
|
? shapeBounds(object)
|
|
217
317
|
: null;
|
|
218
318
|
if (!bbox)
|
|
219
319
|
continue;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
320
|
+
var labelX = bbox.x - 8;
|
|
321
|
+
var labelY = bbox.y - 28;
|
|
322
|
+
var label = createTextObject({ x: labelX, y: labelY, text: name, fontSize: 12, autoWidth: true });
|
|
223
323
|
additions.push(label);
|
|
224
|
-
|
|
324
|
+
var geometry = buildArrow({ x: labelX + 40, y: labelY + 10 }, { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 }, 0, 2);
|
|
225
325
|
additions.push(createPathObject({
|
|
226
326
|
x: geometry.box.x,
|
|
227
327
|
y: geometry.box.y,
|
|
@@ -235,15 +335,15 @@ const executors = {
|
|
|
235
335
|
fill: 'transparent'
|
|
236
336
|
}));
|
|
237
337
|
}
|
|
238
|
-
|
|
338
|
+
var _a = addToScene(host, additions), scene = _a.scene, ids = _a.ids;
|
|
239
339
|
host.commitScene(scene);
|
|
240
|
-
return ok(
|
|
340
|
+
return ok("Named ".concat(additions.length / 2, " components."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
241
341
|
}
|
|
242
342
|
};
|
|
243
343
|
export function executeCanvasTool(host, name, args) {
|
|
244
|
-
|
|
344
|
+
var run = executors[name];
|
|
245
345
|
if (!run)
|
|
246
|
-
return fail('invalid_args',
|
|
346
|
+
return fail('invalid_args', "Unknown tool ".concat(name, "."));
|
|
247
347
|
try {
|
|
248
348
|
return run(host, args);
|
|
249
349
|
}
|
|
@@ -253,34 +353,42 @@ export function executeCanvasTool(host, name, args) {
|
|
|
253
353
|
}
|
|
254
354
|
/** Navigation wireframe group (label "Navigation"). */
|
|
255
355
|
export function findNavigationId(scene) {
|
|
256
|
-
for (
|
|
356
|
+
for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
|
|
357
|
+
var object = scene_2[_i];
|
|
257
358
|
if (object.type === 'text' && object.text.trim().toLowerCase() === 'navigation' && object.parentId) {
|
|
258
359
|
return object.parentId;
|
|
259
360
|
}
|
|
260
361
|
}
|
|
261
|
-
|
|
362
|
+
var direct = findByLabel(scene, 'navigation');
|
|
262
363
|
if (direct) {
|
|
263
|
-
|
|
264
|
-
if (object
|
|
364
|
+
var object = findObject(scene, direct);
|
|
365
|
+
if ((object === null || object === void 0 ? void 0 : object.type) === 'group')
|
|
265
366
|
return direct;
|
|
266
|
-
if (object
|
|
367
|
+
if (object === null || object === void 0 ? void 0 : object.parentId)
|
|
267
368
|
return object.parentId;
|
|
268
369
|
}
|
|
269
370
|
return findByLabel(scene, 'nav');
|
|
270
371
|
}
|
|
271
372
|
export function findVideoThumbnailBounds(scene) {
|
|
272
|
-
|
|
373
|
+
var _loop_1 = function (object) {
|
|
273
374
|
if (object.type === 'text' && object.text.toLowerCase() === 'thumbnail') {
|
|
274
|
-
|
|
375
|
+
var frame = scene.find(function (candidate) { return candidate.parentId === object.parentId || candidate.type === 'rect'; });
|
|
275
376
|
if (frame && isBoxedObject(frame))
|
|
276
|
-
return shapeBounds(frame);
|
|
377
|
+
return { value: shapeBounds(frame) };
|
|
277
378
|
}
|
|
379
|
+
};
|
|
380
|
+
for (var _i = 0, scene_3 = scene; _i < scene_3.length; _i++) {
|
|
381
|
+
var object = scene_3[_i];
|
|
382
|
+
var state_1 = _loop_1(object);
|
|
383
|
+
if (typeof state_1 === "object")
|
|
384
|
+
return state_1.value;
|
|
278
385
|
}
|
|
279
|
-
|
|
386
|
+
var screen = scene.find(function (object) { return object.type === 'rect' && object.fill === '#f3f4f6' && object.parentId !== null; });
|
|
280
387
|
return screen && isBoxedObject(screen) ? shapeBounds(screen) : null;
|
|
281
388
|
}
|
|
282
389
|
export function findVideoPlayerRoot(scene) {
|
|
283
|
-
for (
|
|
390
|
+
for (var _i = 0, scene_4 = scene; _i < scene_4.length; _i++) {
|
|
391
|
+
var object = scene_4[_i];
|
|
284
392
|
if (object.type === 'text' && object.text.toLowerCase().includes('video player'))
|
|
285
393
|
return object.id;
|
|
286
394
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { EngineCore } from '../engine/EngineCore.js';
|
|
2
|
-
import type { CanvasBounds, CanvasToolHost } from './types.js';
|
|
2
|
+
import type { CanvasBounds, CanvasToolAsset, CanvasToolHost } from './types.js';
|
|
3
3
|
export interface EngineToolHostOptions {
|
|
4
4
|
engine: EngineCore;
|
|
5
5
|
bounds?: CanvasBounds;
|
|
6
6
|
/** When `transient`, scene updates apply without a new undo step until a `push` flush. */
|
|
7
7
|
commitMode?: 'push' | 'transient';
|
|
8
|
+
/** The pictures the assistant may place by id (`add_asset`). */
|
|
9
|
+
assets?: readonly CanvasToolAsset[];
|
|
10
|
+
/** The font families the assistant may use for a text. */
|
|
11
|
+
fontFamilies?: readonly string[];
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Adapts EngineCore to CanvasToolHost: one `commit()` per assistant turn.
|