@widgetic/canvas 0.5.41 → 0.5.43
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 +1 -0
- package/dist/canvas/DomCanvas.svelte +49 -20
- package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.d.ts +14 -3
- package/dist/canvas/chromeLayout.js +30 -20
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +47 -5
- package/dist/canvas/host/CanvasHost.js +1481 -1566
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/browserServices.js +65 -116
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.d.ts +33 -0
- package/dist/canvas/host/nearCards.js +78 -0
- package/dist/canvas/host/pageEvents.d.ts +16 -4
- package/dist/canvas/host/pageEvents.js +17 -8
- package/dist/canvas/host/pictureSaves.d.ts +33 -0
- package/dist/canvas/host/pictureSaves.js +42 -0
- package/dist/canvas/host/screenRects.d.ts +5 -0
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.d.ts +88 -0
- package/dist/canvas/host/storedPictures.js +288 -0
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/index.js +1 -1
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
- package/dist/canvas/shapes/shapeImageStore.js +10 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.d.ts +2 -2
- package/dist/canvas/toolbarPosition.js +4 -4
- package/dist/canvas/ui/SelectionPanel.svelte +28 -5
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
- package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
- package/dist/canvas/ui/ToolButton.svelte +8 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +2 -2
- package/dist/canvas/ui/floatingCard.js +20 -20
- package/dist/canvas/ui/floatingLayer.d.ts +13 -2
- package/dist/canvas/ui/floatingLayer.js +18 -7
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/CanvasStage.svelte +101 -67
- package/dist/canvas/view/LeftToRightScope.svelte +21 -0
- package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
- package/dist/canvas/view/ObjectView.svelte +15 -10
- package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/canvas/view/liftedScene.d.ts +31 -0
- package/dist/canvas/view/liftedScene.js +146 -0
- package/dist/canvas/view/mountedScene.d.ts +71 -0
- package/dist/canvas/view/mountedScene.js +363 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +15 -1
- package/dist/engine/EngineCore.js +724 -797
- package/dist/engine/codec/canvasDocument.d.ts +5 -0
- package/dist/engine/codec/canvasDocument.js +212 -149
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +76 -89
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +67 -94
- package/dist/engine/core/defaults.js +90 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.d.ts +6 -0
- package/dist/engine/core/history.js +49 -50
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.d.ts +10 -0
- package/dist/engine/core/scene.js +153 -187
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +31 -64
- package/dist/engine/core/transform.js +83 -94
- package/dist/engine/core/types.d.ts +8 -2
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +467 -474
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +265 -309
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +27 -30
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.d.ts +20 -0
- package/dist/engine/state.js +5 -15
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.d.ts +10 -1
- package/dist/fonts/interFont.js +47 -75
- package/dist/fonts/workspaceFonts.js +32 -90
- 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 +8 -1
- package/dist/i18n/messages.js +10 -2
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/settings/workspaceToolSettings.js +32 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +105 -141
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/types.js +1 -1
- package/package.json +1 -1
- package/dist/canvas/ui/SelectorBar.svelte +0 -84
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
package/dist/tools/executors.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
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
1
|
import { createEllipseObject, createPathObject, createRectObject, createTextObject } from '../engine/core/defaults.js';
|
|
22
2
|
import { buildArrow } from '../engine/core/arrow.js';
|
|
23
3
|
import { serializePathData } from '../engine/core/pathData.js';
|
|
@@ -26,22 +6,20 @@ import { isBoxedObject } from '../engine/core/types.js';
|
|
|
26
6
|
import { drawUiComponent, makeArrowBetween } from './components/catalog.js';
|
|
27
7
|
import { centerOf, findByLabel, kindOfObject, labelOfObject, summarizeScene } from './sceneSummary.js';
|
|
28
8
|
function groupLabelForName(groupId, scene) {
|
|
29
|
-
for (
|
|
30
|
-
var object = scene_1[_i];
|
|
9
|
+
for (const object of scene) {
|
|
31
10
|
if (object.parentId === groupId && object.type === 'text')
|
|
32
11
|
return object.text.trim();
|
|
33
12
|
}
|
|
34
13
|
return 'group';
|
|
35
14
|
}
|
|
36
15
|
function fail(code, error) {
|
|
37
|
-
return { ok: false, error
|
|
16
|
+
return { ok: false, error, code };
|
|
38
17
|
}
|
|
39
|
-
function ok(message, extra) {
|
|
40
|
-
|
|
41
|
-
return __assign({ ok: true, message: message }, extra);
|
|
18
|
+
function ok(message, extra = {}) {
|
|
19
|
+
return { ok: true, message, ...extra };
|
|
42
20
|
}
|
|
43
21
|
function clampInBounds(host, x, y, width, height) {
|
|
44
|
-
|
|
22
|
+
const pad = 8;
|
|
45
23
|
return (x >= -pad &&
|
|
46
24
|
y >= -pad &&
|
|
47
25
|
x + width <= host.bounds.width + pad &&
|
|
@@ -50,146 +28,141 @@ function clampInBounds(host, x, y, width, height) {
|
|
|
50
28
|
height > 0);
|
|
51
29
|
}
|
|
52
30
|
function addToScene(host, objects) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return { scene
|
|
31
|
+
const withIds = objects.map((object) => ({ ...object, id: object.id ?? host.createId(kindOfObject(object)) }));
|
|
32
|
+
const scene = normalizeScene([...host.getScene(), ...withIds]);
|
|
33
|
+
return { scene, ids: withIds.map((object) => object.id) };
|
|
56
34
|
}
|
|
57
|
-
|
|
58
|
-
get_canvas
|
|
59
|
-
|
|
60
|
-
return ok(
|
|
35
|
+
const executors = {
|
|
36
|
+
get_canvas(host) {
|
|
37
|
+
const summary = summarizeScene(host.getScene(), host.bounds);
|
|
38
|
+
return ok(`Canvas has ${summary.elements.length} elements.`, { summary });
|
|
61
39
|
},
|
|
62
|
-
draw_ui_component
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var label = typeof args.label === 'string' ? args.label : undefined;
|
|
40
|
+
draw_ui_component(host, args) {
|
|
41
|
+
const component = String(args.component ?? '');
|
|
42
|
+
const x = Number(args.x);
|
|
43
|
+
const y = Number(args.y);
|
|
44
|
+
const width = Number(args.width ?? 360);
|
|
45
|
+
const height = Number(args.height ?? 240);
|
|
46
|
+
const label = typeof args.label === 'string' ? args.label : undefined;
|
|
70
47
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
71
48
|
return fail('invalid_args', 'x and y are required numbers.');
|
|
72
|
-
|
|
73
|
-
|
|
49
|
+
const placement = drawUiComponent(component, x, y, width, height, label);
|
|
50
|
+
const { scene, ids } = addToScene(host, placement.objects);
|
|
74
51
|
// The check is on what the component really covers (a button is 48 px high whatever height was asked for, a video
|
|
75
52
|
// player has its title above y and a navigation strip below the thumbnail), not on the size that was passed: a
|
|
76
53
|
// request with no size would otherwise be judged as 360 x 240, and a button near the bottom would be refused.
|
|
77
|
-
|
|
54
|
+
const covered = boundsOfObjects(scene, ids);
|
|
78
55
|
if (!covered || !clampInBounds(host, covered.x, covered.y, covered.width, covered.height)) {
|
|
79
|
-
|
|
80
|
-
?
|
|
56
|
+
const area = covered
|
|
57
|
+
? ` It would cover x ${Math.round(covered.x)} to ${Math.round(covered.x + covered.width)} and y ${Math.round(covered.y)} to ${Math.round(covered.y + covered.height)}, and the canvas is ${Math.round(host.bounds.width)} x ${Math.round(host.bounds.height)}.`
|
|
81
58
|
: '';
|
|
82
|
-
return fail('bounds',
|
|
59
|
+
return fail('bounds', `Component would sit outside the canvas.${area}`);
|
|
83
60
|
}
|
|
84
61
|
host.commitScene(scene);
|
|
85
|
-
return ok(
|
|
62
|
+
return ok(`Drew ${component} (${placement.rootLabel}).`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
86
63
|
},
|
|
87
|
-
add_shape
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var height = Number(args.height);
|
|
64
|
+
add_shape(host, args) {
|
|
65
|
+
const shape = String(args.shape ?? 'rectangle');
|
|
66
|
+
const x = Number(args.x);
|
|
67
|
+
const y = Number(args.y);
|
|
68
|
+
const width = Number(args.width);
|
|
69
|
+
const height = Number(args.height);
|
|
94
70
|
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
95
71
|
return fail('invalid_args', 'x, y, width and height are required.');
|
|
96
72
|
}
|
|
97
73
|
if (!clampInBounds(host, x, y, width, height))
|
|
98
74
|
return fail('bounds', 'Shape is outside the canvas.');
|
|
99
|
-
|
|
100
|
-
|
|
75
|
+
let object;
|
|
76
|
+
const label = typeof args.label === 'string' ? args.label : undefined;
|
|
101
77
|
if (shape === 'ellipse') {
|
|
102
|
-
object = createEllipseObject({ x
|
|
78
|
+
object = createEllipseObject({ x, y, width, height });
|
|
103
79
|
}
|
|
104
80
|
else if (shape === 'diamond') {
|
|
105
|
-
|
|
106
|
-
object = createPathObject({ x
|
|
81
|
+
const path = `M ${width / 2} 0 L ${width} ${height / 2} L ${width / 2} ${height} L 0 ${height / 2} Z`;
|
|
82
|
+
object = createPathObject({ x, y, width, height, d: path, shape: 'diamond' });
|
|
107
83
|
}
|
|
108
84
|
else {
|
|
109
|
-
object = createRectObject({ x
|
|
85
|
+
object = createRectObject({ x, y, width, height, roundness: shape === 'rounded' ? 16 : 0 });
|
|
110
86
|
}
|
|
111
|
-
|
|
87
|
+
const objects = [object];
|
|
112
88
|
if (label) {
|
|
113
89
|
objects.push(createTextObject({ x: x + 4, y: y + 4, text: label, fontSize: 12, autoWidth: true }));
|
|
114
90
|
}
|
|
115
|
-
|
|
91
|
+
const { scene, ids } = addToScene(host, objects);
|
|
116
92
|
host.commitScene(scene);
|
|
117
|
-
return ok(
|
|
93
|
+
return ok(`Added ${shape}.`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
118
94
|
},
|
|
119
|
-
add_text
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var y = Number(args.y);
|
|
95
|
+
add_text(host, args) {
|
|
96
|
+
const text = String(args.text ?? '').trim();
|
|
97
|
+
const x = Number(args.x);
|
|
98
|
+
const y = Number(args.y);
|
|
124
99
|
if (!text)
|
|
125
100
|
return fail('invalid_args', 'text is required.');
|
|
126
101
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
127
102
|
return fail('invalid_args', 'x and y are required.');
|
|
128
|
-
|
|
129
|
-
|
|
103
|
+
const width = Number(args.width ?? 200);
|
|
104
|
+
const object = createTextObject({ x, y, width, text, autoWidth: width <= 40 });
|
|
130
105
|
if (!clampInBounds(host, x, y, object.width, object.height))
|
|
131
106
|
return fail('bounds', 'Text is outside the canvas.');
|
|
132
|
-
|
|
107
|
+
const { scene, ids } = addToScene(host, [object]);
|
|
133
108
|
host.commitScene(scene);
|
|
134
109
|
return ok('Added text.', { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
135
110
|
},
|
|
136
|
-
add_arrow
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
add_arrow(host, args) {
|
|
112
|
+
let fromX = Number(args.fromX);
|
|
113
|
+
let fromY = Number(args.fromY);
|
|
114
|
+
let toX = Number(args.toX);
|
|
115
|
+
let toY = Number(args.toY);
|
|
116
|
+
const scene = host.getScene();
|
|
142
117
|
if (typeof args.fromId === 'string') {
|
|
143
|
-
|
|
118
|
+
const center = centerOf(args.fromId, scene);
|
|
144
119
|
if (!center)
|
|
145
|
-
return fail('not_found',
|
|
120
|
+
return fail('not_found', `fromId ${args.fromId} not found.`);
|
|
146
121
|
fromX = center.x;
|
|
147
122
|
fromY = center.y;
|
|
148
123
|
}
|
|
149
124
|
if (typeof args.toId === 'string') {
|
|
150
|
-
|
|
125
|
+
const center = centerOf(args.toId, scene);
|
|
151
126
|
if (!center)
|
|
152
|
-
return fail('not_found',
|
|
127
|
+
return fail('not_found', `toId ${args.toId} not found.`);
|
|
153
128
|
toX = center.x;
|
|
154
129
|
toY = center.y;
|
|
155
130
|
}
|
|
156
131
|
if (![fromX, fromY, toX, toY].every(Number.isFinite))
|
|
157
132
|
return fail('invalid_args', 'Need from/to points or ids.');
|
|
158
|
-
|
|
133
|
+
const objects = [makeArrowBetween(fromX, fromY, toX, toY)];
|
|
159
134
|
if (typeof args.label === 'string' && args.label.trim()) {
|
|
160
135
|
objects.push(createTextObject({ x: (fromX + toX) / 2, y: (fromY + toY) / 2 - 16, text: args.label.trim(), fontSize: 12, autoWidth: true }));
|
|
161
136
|
}
|
|
162
|
-
|
|
137
|
+
const added = addToScene(host, objects);
|
|
163
138
|
host.commitScene(added.scene);
|
|
164
139
|
return ok('Added arrow.', { createdIds: added.ids, summary: summarizeScene(added.scene, host.bounds) });
|
|
165
140
|
},
|
|
166
|
-
move_elements
|
|
167
|
-
|
|
168
|
-
var ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
|
|
141
|
+
move_elements(host, args) {
|
|
142
|
+
const ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
|
|
169
143
|
if (ids.length === 0)
|
|
170
144
|
return fail('invalid_args', 'ids required.');
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
for (
|
|
174
|
-
var id = ids_1[_i];
|
|
145
|
+
let scene = host.getScene();
|
|
146
|
+
const index = indexScene(scene);
|
|
147
|
+
for (const id of ids) {
|
|
175
148
|
if (!index.has(id))
|
|
176
|
-
return fail('not_found',
|
|
149
|
+
return fail('not_found', `Element ${id} not found.`);
|
|
177
150
|
}
|
|
178
|
-
|
|
179
|
-
|
|
151
|
+
const dx = Number(args.dx ?? 0);
|
|
152
|
+
const dy = Number(args.dy ?? 0);
|
|
180
153
|
if ((Number.isFinite(args.x) || Number.isFinite(args.y)) && ids.length > 0) {
|
|
181
|
-
|
|
154
|
+
const first = findObject(scene, ids[0]);
|
|
182
155
|
if (!first)
|
|
183
156
|
return fail('not_found', 'First id not movable.');
|
|
184
|
-
|
|
157
|
+
const bbox = first.type === 'group'
|
|
185
158
|
? boundsOfObjects(scene, [first.id])
|
|
186
159
|
: isBoxedObject(first)
|
|
187
160
|
? shapeBounds(first)
|
|
188
161
|
: null;
|
|
189
162
|
if (!bbox)
|
|
190
163
|
return fail('not_found', 'First id not movable.');
|
|
191
|
-
|
|
192
|
-
|
|
164
|
+
const targetDx = Number.isFinite(args.x) ? Number(args.x) - bbox.x : 0;
|
|
165
|
+
const targetDy = Number.isFinite(args.y) ? Number(args.y) - bbox.y : 0;
|
|
193
166
|
scene = translateObjects(scene, ids, targetDx, targetDy);
|
|
194
167
|
}
|
|
195
168
|
else if (dx !== 0 || dy !== 0) {
|
|
@@ -199,36 +172,35 @@ var executors = {
|
|
|
199
172
|
return fail('invalid_args', 'Provide dx/dy or x/y.');
|
|
200
173
|
}
|
|
201
174
|
host.commitScene(scene);
|
|
202
|
-
return ok(
|
|
175
|
+
return ok(`Moved ${ids.length} element(s).`, { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
203
176
|
},
|
|
204
|
-
delete_elements
|
|
205
|
-
|
|
177
|
+
delete_elements(host, args) {
|
|
178
|
+
const ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
|
|
206
179
|
if (ids.length === 0)
|
|
207
180
|
return fail('invalid_args', 'ids required.');
|
|
208
|
-
|
|
181
|
+
let scene = host.getScene();
|
|
209
182
|
if (ids.length === 1 && ids[0] === 'all') {
|
|
210
183
|
scene = [];
|
|
211
184
|
}
|
|
212
185
|
else {
|
|
213
|
-
|
|
186
|
+
const missing = ids.filter((id) => !findObject(scene, id));
|
|
214
187
|
if (missing.length > 0)
|
|
215
|
-
return fail('not_found',
|
|
188
|
+
return fail('not_found', `Unknown ids: ${missing.join(', ')}`);
|
|
216
189
|
scene = removeObjects(scene, ids);
|
|
217
190
|
}
|
|
218
191
|
host.commitScene(scene);
|
|
219
192
|
return ok('Deleted elements.', { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
220
193
|
},
|
|
221
|
-
clear_canvas
|
|
222
|
-
|
|
194
|
+
clear_canvas(host) {
|
|
195
|
+
const scene = [];
|
|
223
196
|
host.commitScene(scene);
|
|
224
197
|
return ok('Canvas cleared.', { summary: summarizeScene(scene, host.bounds) });
|
|
225
198
|
},
|
|
226
|
-
name_components_with_arrows
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
for (
|
|
231
|
-
var object = sceneBefore_1[_i];
|
|
199
|
+
name_components_with_arrows(host, args) {
|
|
200
|
+
const prefix = typeof args.prefix === 'string' ? args.prefix.trim() : '';
|
|
201
|
+
const sceneBefore = host.getScene();
|
|
202
|
+
const additions = [];
|
|
203
|
+
for (const object of sceneBefore) {
|
|
232
204
|
if (object.parentId !== null)
|
|
233
205
|
continue;
|
|
234
206
|
if (object.type === 'text')
|
|
@@ -237,19 +209,19 @@ var executors = {
|
|
|
237
209
|
continue;
|
|
238
210
|
if (!isBoxedObject(object) && object.type !== 'group')
|
|
239
211
|
continue;
|
|
240
|
-
|
|
241
|
-
|
|
212
|
+
const name = `${prefix ? `${prefix} ` : ''}${object.type === 'group' ? groupLabelForName(object.id, sceneBefore) : labelOfObject(object)}`.trim();
|
|
213
|
+
const bbox = object.type === 'group'
|
|
242
214
|
? boundsOfObjects(sceneBefore, [object.id])
|
|
243
215
|
: isBoxedObject(object)
|
|
244
216
|
? shapeBounds(object)
|
|
245
217
|
: null;
|
|
246
218
|
if (!bbox)
|
|
247
219
|
continue;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
220
|
+
const labelX = bbox.x - 8;
|
|
221
|
+
const labelY = bbox.y - 28;
|
|
222
|
+
const label = createTextObject({ x: labelX, y: labelY, text: name, fontSize: 12, autoWidth: true });
|
|
251
223
|
additions.push(label);
|
|
252
|
-
|
|
224
|
+
const geometry = buildArrow({ x: labelX + 40, y: labelY + 10 }, { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 }, 0, 2);
|
|
253
225
|
additions.push(createPathObject({
|
|
254
226
|
x: geometry.box.x,
|
|
255
227
|
y: geometry.box.y,
|
|
@@ -263,15 +235,15 @@ var executors = {
|
|
|
263
235
|
fill: 'transparent'
|
|
264
236
|
}));
|
|
265
237
|
}
|
|
266
|
-
|
|
238
|
+
const { scene, ids } = addToScene(host, additions);
|
|
267
239
|
host.commitScene(scene);
|
|
268
|
-
return ok(
|
|
240
|
+
return ok(`Named ${additions.length / 2} components.`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
|
|
269
241
|
}
|
|
270
242
|
};
|
|
271
243
|
export function executeCanvasTool(host, name, args) {
|
|
272
|
-
|
|
244
|
+
const run = executors[name];
|
|
273
245
|
if (!run)
|
|
274
|
-
return fail('invalid_args',
|
|
246
|
+
return fail('invalid_args', `Unknown tool ${name}.`);
|
|
275
247
|
try {
|
|
276
248
|
return run(host, args);
|
|
277
249
|
}
|
|
@@ -281,42 +253,34 @@ export function executeCanvasTool(host, name, args) {
|
|
|
281
253
|
}
|
|
282
254
|
/** Navigation wireframe group (label "Navigation"). */
|
|
283
255
|
export function findNavigationId(scene) {
|
|
284
|
-
for (
|
|
285
|
-
var object = scene_2[_i];
|
|
256
|
+
for (const object of scene) {
|
|
286
257
|
if (object.type === 'text' && object.text.trim().toLowerCase() === 'navigation' && object.parentId) {
|
|
287
258
|
return object.parentId;
|
|
288
259
|
}
|
|
289
260
|
}
|
|
290
|
-
|
|
261
|
+
const direct = findByLabel(scene, 'navigation');
|
|
291
262
|
if (direct) {
|
|
292
|
-
|
|
293
|
-
if (
|
|
263
|
+
const object = findObject(scene, direct);
|
|
264
|
+
if (object?.type === 'group')
|
|
294
265
|
return direct;
|
|
295
|
-
if (object
|
|
266
|
+
if (object?.parentId)
|
|
296
267
|
return object.parentId;
|
|
297
268
|
}
|
|
298
269
|
return findByLabel(scene, 'nav');
|
|
299
270
|
}
|
|
300
271
|
export function findVideoThumbnailBounds(scene) {
|
|
301
|
-
|
|
272
|
+
for (const object of scene) {
|
|
302
273
|
if (object.type === 'text' && object.text.toLowerCase() === 'thumbnail') {
|
|
303
|
-
|
|
274
|
+
const frame = scene.find((candidate) => candidate.parentId === object.parentId || candidate.type === 'rect');
|
|
304
275
|
if (frame && isBoxedObject(frame))
|
|
305
|
-
return
|
|
276
|
+
return shapeBounds(frame);
|
|
306
277
|
}
|
|
307
|
-
};
|
|
308
|
-
for (var _i = 0, scene_3 = scene; _i < scene_3.length; _i++) {
|
|
309
|
-
var object = scene_3[_i];
|
|
310
|
-
var state_1 = _loop_1(object);
|
|
311
|
-
if (typeof state_1 === "object")
|
|
312
|
-
return state_1.value;
|
|
313
278
|
}
|
|
314
|
-
|
|
279
|
+
const screen = scene.find((object) => object.type === 'rect' && object.fill === '#f3f4f6' && object.parentId !== null);
|
|
315
280
|
return screen && isBoxedObject(screen) ? shapeBounds(screen) : null;
|
|
316
281
|
}
|
|
317
282
|
export function findVideoPlayerRoot(scene) {
|
|
318
|
-
for (
|
|
319
|
-
var object = scene_4[_i];
|
|
283
|
+
for (const object of scene) {
|
|
320
284
|
if (object.type === 'text' && object.text.toLowerCase().includes('video player'))
|
|
321
285
|
return object.id;
|
|
322
286
|
}
|
|
@@ -3,34 +3,32 @@ import { createObjectId } from '../engine/core/defaults.js';
|
|
|
3
3
|
* Adapts EngineCore to CanvasToolHost: one `commit()` per assistant turn.
|
|
4
4
|
*/
|
|
5
5
|
export function createCanvasToolHostFromEngine(options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var bounds = (_a = options.bounds) !== null && _a !== void 0 ? _a : {
|
|
6
|
+
const { engine } = options;
|
|
7
|
+
const bounds = options.bounds ?? {
|
|
9
8
|
width: engine.state.viewSize.width || 1200,
|
|
10
9
|
height: engine.state.viewSize.height || 800
|
|
11
10
|
};
|
|
12
11
|
return {
|
|
13
|
-
bounds
|
|
14
|
-
getScene
|
|
12
|
+
bounds,
|
|
13
|
+
getScene() {
|
|
15
14
|
return engine.state.scene;
|
|
16
15
|
},
|
|
17
|
-
createId
|
|
18
|
-
return createObjectId(prefix
|
|
16
|
+
createId(prefix) {
|
|
17
|
+
return createObjectId(prefix ?? 'sketch');
|
|
19
18
|
},
|
|
20
|
-
commitScene
|
|
21
|
-
|
|
22
|
-
engine.applyScene(next, (_a = options.commitMode) !== null && _a !== void 0 ? _a : 'push');
|
|
19
|
+
commitScene(next) {
|
|
20
|
+
engine.applyScene(next, options.commitMode ?? 'push');
|
|
23
21
|
}
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
24
|
/** Run several tool calls as a single undo step on the engine. */
|
|
27
25
|
export function runCanvasToolBatch(host, run, engine) {
|
|
28
26
|
// When backed by engine, defer commit until batch ends.
|
|
29
|
-
|
|
27
|
+
const engineHost = host;
|
|
30
28
|
if (engine) {
|
|
31
|
-
|
|
29
|
+
const snapshot = engine.state.scene;
|
|
32
30
|
run();
|
|
33
|
-
|
|
31
|
+
const finalScene = host.getScene();
|
|
34
32
|
if (finalScene !== snapshot) {
|
|
35
33
|
engine.applyScene(finalScene, 'push');
|
|
36
34
|
}
|