@widgetic/canvas 0.5.45 → 0.5.46
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 -1
- 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.js +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -2
- package/dist/canvas/host/CanvasHost.js +1615 -1847
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +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.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +21 -21
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +35 -41
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +9 -2
- package/dist/engine/EngineCore.js +798 -907
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +84 -96
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- 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.js +160 -224
- 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 +32 -65
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +267 -310
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +35 -39
- 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.js +6 -17
- 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.js +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/poster/boardPlacement.js +28 -30
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +8 -0
- package/dist/settings/workspaceToolSettings.js +35 -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 +137 -169
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +2 -2
|
@@ -38,6 +38,14 @@ export interface WorkspaceToolSettingsV1 {
|
|
|
38
38
|
width?: number;
|
|
39
39
|
opacity?: number;
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The tool the person last had chosen on the toolbar, so a board opened again (a refresh included) starts with it and not always with
|
|
43
|
+
* the pencil (see `rememberedTool.ts`, which says which tools are kept). Left out until a tool is chosen. The id is checked when it
|
|
44
|
+
* is read: a value that is not a tool of the toolbar is the same as none.
|
|
45
|
+
*/
|
|
46
|
+
tool?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
};
|
|
41
49
|
}
|
|
42
50
|
export interface WorkspaceToolSettingsScope {
|
|
43
51
|
workspaceId: string;
|
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Last-used tool settings per workspace (item B16). Debounced writes, flush on pagehide.
|
|
3
3
|
*/
|
|
4
|
-
var __assign = (this && this.__assign) || function () {
|
|
5
|
-
__assign = Object.assign || function(t) {
|
|
6
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
-
s = arguments[i];
|
|
8
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
-
t[p] = s[p];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
return __assign.apply(this, arguments);
|
|
14
|
-
};
|
|
15
4
|
import { getCanvasPreferenceStorage } from '../components/preferenceStorage.js';
|
|
16
|
-
export
|
|
17
|
-
export
|
|
5
|
+
export const WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION = 1;
|
|
6
|
+
export const WORKSPACE_TOOL_SETTINGS_KEY_PREFIX = 'widgetic-canvas:workspace-tool-settings:v1:';
|
|
18
7
|
function storageKey(scope) {
|
|
19
|
-
|
|
20
|
-
return
|
|
8
|
+
const userPart = scope.userId ? `:${scope.userId}` : '';
|
|
9
|
+
return `${WORKSPACE_TOOL_SETTINGS_KEY_PREFIX}${scope.workspaceId}${userPart}`;
|
|
21
10
|
}
|
|
22
11
|
function adapterFromPreferenceStorage() {
|
|
23
|
-
|
|
12
|
+
const storage = getCanvasPreferenceStorage();
|
|
24
13
|
return {
|
|
25
|
-
load
|
|
26
|
-
var _a;
|
|
14
|
+
load(key) {
|
|
27
15
|
try {
|
|
28
|
-
return
|
|
16
|
+
return storage?.getItem(key) ?? null;
|
|
29
17
|
}
|
|
30
|
-
catch
|
|
18
|
+
catch {
|
|
31
19
|
return null;
|
|
32
20
|
}
|
|
33
21
|
},
|
|
34
|
-
save
|
|
22
|
+
save(key, value) {
|
|
35
23
|
try {
|
|
36
|
-
storage
|
|
24
|
+
storage?.setItem(key, value);
|
|
37
25
|
}
|
|
38
|
-
catch
|
|
26
|
+
catch {
|
|
39
27
|
// quota / private mode
|
|
40
28
|
}
|
|
41
29
|
}
|
|
@@ -45,53 +33,53 @@ export function parseWorkspaceToolSettings(raw) {
|
|
|
45
33
|
if (!raw)
|
|
46
34
|
return null;
|
|
47
35
|
try {
|
|
48
|
-
|
|
49
|
-
if (
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (parsed?.v !== WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION)
|
|
50
38
|
return null;
|
|
51
39
|
return parsed;
|
|
52
40
|
}
|
|
53
|
-
catch
|
|
41
|
+
catch {
|
|
54
42
|
return null;
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
|
-
export function loadWorkspaceToolSettings(scope, adapter) {
|
|
58
|
-
if (adapter === void 0) { adapter = adapterFromPreferenceStorage(); }
|
|
45
|
+
export function loadWorkspaceToolSettings(scope, adapter = adapterFromPreferenceStorage()) {
|
|
59
46
|
return parseWorkspaceToolSettings(adapter.load(storageKey(scope)));
|
|
60
47
|
}
|
|
61
|
-
/** The settings with a patch laid over them: each part (text, paint, arrow, pen) keeps what the patch does not say. */
|
|
48
|
+
/** The settings with a patch laid over them: each part (text, paint, arrow, pen, tool) keeps what the patch does not say. */
|
|
62
49
|
function mergeSettings(current, patch) {
|
|
63
|
-
|
|
50
|
+
const merged = {
|
|
64
51
|
v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION,
|
|
65
|
-
text:
|
|
66
|
-
paint:
|
|
67
|
-
arrow:
|
|
52
|
+
text: { ...current.text, ...patch.text },
|
|
53
|
+
paint: { ...current.paint, ...patch.paint },
|
|
54
|
+
arrow: { ...current.arrow, ...patch.arrow }
|
|
68
55
|
};
|
|
69
56
|
// The pen is written only when there is one: settings of a person who never touched it hold none.
|
|
70
57
|
if (current.pen || patch.pen)
|
|
71
|
-
merged.pen =
|
|
58
|
+
merged.pen = { ...current.pen, ...patch.pen };
|
|
59
|
+
// The tool is written only when one was chosen, for the same reason.
|
|
60
|
+
if (current.tool || patch.tool)
|
|
61
|
+
merged.tool = { ...current.tool, ...patch.tool };
|
|
72
62
|
return merged;
|
|
73
63
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export function saveWorkspaceToolSettingsDebounced(scope, patch, adapter) {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
if (adapter === void 0) { adapter = adapterFromPreferenceStorage(); }
|
|
64
|
+
let pending = null;
|
|
65
|
+
let debounceTimer;
|
|
66
|
+
export function saveWorkspaceToolSettingsDebounced(scope, patch, adapter = adapterFromPreferenceStorage()) {
|
|
79
67
|
// A change that waits for its write (see the delay below) is part of the settings already: the next change is laid over it, and not
|
|
80
68
|
// over what the storage still holds, so two changes made within the delay are both kept. A change that waits for another workspace
|
|
81
69
|
// is written first, and is not lost to this one.
|
|
82
70
|
if (pending && storageKey(pending.scope) !== storageKey(scope))
|
|
83
71
|
flushWorkspaceToolSettingsPending();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
pending = { scope
|
|
72
|
+
const current = pending?.value ?? loadWorkspaceToolSettings(scope, adapter) ?? { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
|
|
73
|
+
const merged = mergeSettings(current, patch);
|
|
74
|
+
pending = { scope, value: merged, adapter };
|
|
87
75
|
if (debounceTimer !== undefined)
|
|
88
76
|
clearTimeout(debounceTimer);
|
|
89
|
-
debounceTimer = setTimeout(
|
|
77
|
+
debounceTimer = setTimeout(() => flushWorkspaceToolSettingsPending(), 400);
|
|
90
78
|
}
|
|
91
79
|
export function flushWorkspaceToolSettingsPending() {
|
|
92
80
|
if (!pending)
|
|
93
81
|
return;
|
|
94
|
-
|
|
82
|
+
const { scope, value, adapter } = pending;
|
|
95
83
|
pending = null;
|
|
96
84
|
if (debounceTimer !== undefined) {
|
|
97
85
|
clearTimeout(debounceTimer);
|
|
@@ -100,15 +88,14 @@ export function flushWorkspaceToolSettingsPending() {
|
|
|
100
88
|
try {
|
|
101
89
|
adapter.save(storageKey(scope), JSON.stringify(value));
|
|
102
90
|
}
|
|
103
|
-
catch
|
|
91
|
+
catch {
|
|
104
92
|
// ignored
|
|
105
93
|
}
|
|
106
94
|
}
|
|
107
95
|
/** Merges a patch into settings without debounce (tests). */
|
|
108
96
|
export function saveWorkspaceToolSettingsNow(scope, patch, adapter) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var merged = mergeSettings(current, patch);
|
|
97
|
+
const current = loadWorkspaceToolSettings(scope, adapter) ?? { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
|
|
98
|
+
const merged = mergeSettings(current, patch);
|
|
112
99
|
adapter.save(storageKey(scope), JSON.stringify(merged));
|
|
113
100
|
return merged;
|
|
114
101
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
1
|
import { createPathObject, createRectObject, createTextObject } from '../../engine/core/defaults.js';
|
|
11
2
|
import { buildArrow } from '../../engine/core/arrow.js';
|
|
12
3
|
import { serializePathData } from '../../engine/core/pathData.js';
|
|
@@ -14,27 +5,27 @@ import { packGroup } from './grouping.js';
|
|
|
14
5
|
function snap(value) {
|
|
15
6
|
return Math.round(value / 8) * 8;
|
|
16
7
|
}
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const STROKE = '#9ca3af';
|
|
9
|
+
const STROKE_WIDTH = 2;
|
|
19
10
|
export function drawUiComponent(kind, x, y, width, height, label) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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));
|
|
25
16
|
switch (kind) {
|
|
26
17
|
case 'video_player': {
|
|
27
|
-
|
|
18
|
+
const title = createTextObject({
|
|
28
19
|
x: px,
|
|
29
20
|
y: py - 28,
|
|
30
|
-
text:
|
|
21
|
+
text: label?.trim() || 'Video player',
|
|
31
22
|
fontSize: 14,
|
|
32
23
|
fontWeight: 'bold',
|
|
33
24
|
autoWidth: true
|
|
34
25
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const thumbW = w;
|
|
27
|
+
const thumbH = snap(thumbW * (9 / 16));
|
|
28
|
+
const frame = createRectObject({
|
|
38
29
|
x: px,
|
|
39
30
|
y: py,
|
|
40
31
|
width: thumbW,
|
|
@@ -43,7 +34,7 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
43
34
|
stroke: STROKE,
|
|
44
35
|
strokeWidth: STROKE_WIDTH
|
|
45
36
|
});
|
|
46
|
-
|
|
37
|
+
const screen = createRectObject({
|
|
47
38
|
x: px + 12,
|
|
48
39
|
y: py + 12,
|
|
49
40
|
width: thumbW - 24,
|
|
@@ -53,15 +44,15 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
53
44
|
stroke: 'transparent',
|
|
54
45
|
strokeWidth: 0
|
|
55
46
|
});
|
|
56
|
-
|
|
47
|
+
const screenLabel = createTextObject({
|
|
57
48
|
x: px + 16,
|
|
58
49
|
y: py + 4,
|
|
59
50
|
text: 'Thumbnail',
|
|
60
51
|
fontSize: 11,
|
|
61
52
|
autoWidth: true
|
|
62
53
|
});
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
const playSize = 56;
|
|
55
|
+
const play = createRectObject({
|
|
65
56
|
x: px + thumbW / 2 - playSize / 2,
|
|
66
57
|
y: py + thumbH / 2 - playSize / 2,
|
|
67
58
|
width: playSize,
|
|
@@ -71,8 +62,8 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
71
62
|
stroke: '#d1d5db',
|
|
72
63
|
strokeWidth: 1
|
|
73
64
|
});
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
const screenGroup = packGroup([frame, screen, play, screenLabel], {});
|
|
66
|
+
const navBar = createRectObject({
|
|
76
67
|
x: px,
|
|
77
68
|
y: py + thumbH + 16,
|
|
78
69
|
width: thumbW,
|
|
@@ -82,8 +73,8 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
82
73
|
stroke: STROKE,
|
|
83
74
|
strokeWidth: STROKE_WIDTH
|
|
84
75
|
});
|
|
85
|
-
|
|
86
|
-
for (
|
|
76
|
+
const navThumbs = [];
|
|
77
|
+
for (let i = 0; i < 5; i++) {
|
|
87
78
|
navThumbs.push(createRectObject({
|
|
88
79
|
x: px + 16 + i * 56,
|
|
89
80
|
y: py + thumbH + 32,
|
|
@@ -95,7 +86,7 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
95
86
|
strokeWidth: 0
|
|
96
87
|
}));
|
|
97
88
|
}
|
|
98
|
-
|
|
89
|
+
const navTitle = createTextObject({
|
|
99
90
|
x: px,
|
|
100
91
|
y: py + thumbH + 4,
|
|
101
92
|
text: 'Navigation',
|
|
@@ -103,16 +94,16 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
103
94
|
fontWeight: 'bold',
|
|
104
95
|
autoWidth: true
|
|
105
96
|
});
|
|
106
|
-
|
|
107
|
-
objects.push
|
|
97
|
+
const navGroup = packGroup([navBar, navTitle, ...navThumbs], {});
|
|
98
|
+
objects.push(title, ...screenGroup.objects, ...navGroup.objects);
|
|
108
99
|
return {
|
|
109
|
-
objects
|
|
100
|
+
objects,
|
|
110
101
|
rootLabel: 'Video player',
|
|
111
102
|
highlightIds: [navGroup.groupId]
|
|
112
103
|
};
|
|
113
104
|
}
|
|
114
105
|
case 'navigation_bar': {
|
|
115
|
-
|
|
106
|
+
const bar = createRectObject({
|
|
116
107
|
x: px,
|
|
117
108
|
y: py + 20,
|
|
118
109
|
width: w,
|
|
@@ -122,32 +113,32 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
122
113
|
strokeWidth: STROKE_WIDTH,
|
|
123
114
|
fill: '#f9fafb'
|
|
124
115
|
});
|
|
125
|
-
|
|
116
|
+
const title = createTextObject({
|
|
126
117
|
x: px,
|
|
127
118
|
y: py,
|
|
128
|
-
text:
|
|
119
|
+
text: label?.trim() || 'Navigation bar',
|
|
129
120
|
fontSize: 12,
|
|
130
121
|
fontWeight: 'bold',
|
|
131
122
|
autoWidth: true
|
|
132
123
|
});
|
|
133
|
-
|
|
134
|
-
for (
|
|
124
|
+
const tabs = [];
|
|
125
|
+
for (let i = 0; i < 4; i++) {
|
|
135
126
|
tabs.push(createTextObject({
|
|
136
127
|
x: px + 16 + i * 96,
|
|
137
128
|
y: py + 36,
|
|
138
|
-
text:
|
|
129
|
+
text: `Nav ${i + 1}`,
|
|
139
130
|
fontSize: 14,
|
|
140
131
|
autoWidth: true
|
|
141
132
|
}));
|
|
142
133
|
}
|
|
143
|
-
|
|
144
|
-
objects.push
|
|
145
|
-
return { objects
|
|
134
|
+
const packed = packGroup([bar, ...tabs], {});
|
|
135
|
+
objects.push(title, ...packed.objects);
|
|
136
|
+
return { objects, rootLabel: label?.trim() || 'Navigation bar' };
|
|
146
137
|
}
|
|
147
138
|
case 'button': {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
const btnH = snap(Math.max(44, Math.min(48, h)));
|
|
140
|
+
const btnW = snap(Math.max(128, w));
|
|
141
|
+
const btn = createRectObject({
|
|
151
142
|
x: px,
|
|
152
143
|
y: py + 22,
|
|
153
144
|
width: btnW,
|
|
@@ -157,14 +148,14 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
157
148
|
stroke: STROKE,
|
|
158
149
|
strokeWidth: STROKE_WIDTH
|
|
159
150
|
});
|
|
160
|
-
|
|
151
|
+
const caption = createTextObject({
|
|
161
152
|
x: px + 16,
|
|
162
153
|
y: py + 34,
|
|
163
|
-
text: label
|
|
154
|
+
text: label ?? 'Button',
|
|
164
155
|
fontSize: 15,
|
|
165
156
|
autoWidth: true
|
|
166
157
|
});
|
|
167
|
-
|
|
158
|
+
const title = createTextObject({
|
|
168
159
|
x: px,
|
|
169
160
|
y: py,
|
|
170
161
|
text: 'Button',
|
|
@@ -172,13 +163,13 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
172
163
|
color: '#6b7280',
|
|
173
164
|
autoWidth: true
|
|
174
165
|
});
|
|
175
|
-
|
|
176
|
-
objects.push
|
|
177
|
-
return { objects
|
|
166
|
+
const packed = packGroup([btn, caption], {});
|
|
167
|
+
objects.push(title, ...packed.objects);
|
|
168
|
+
return { objects, rootLabel: label ?? 'Button' };
|
|
178
169
|
}
|
|
179
170
|
case 'card': {
|
|
180
|
-
|
|
181
|
-
|
|
171
|
+
const cardH = snap(Math.max(160, h));
|
|
172
|
+
const card = createRectObject({
|
|
182
173
|
x: px,
|
|
183
174
|
y: py + 24,
|
|
184
175
|
width: w,
|
|
@@ -188,15 +179,15 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
188
179
|
strokeWidth: STROKE_WIDTH,
|
|
189
180
|
fill: '#ffffff'
|
|
190
181
|
});
|
|
191
|
-
|
|
182
|
+
const heading = createTextObject({
|
|
192
183
|
x: px + 16,
|
|
193
184
|
y: py + 40,
|
|
194
|
-
text: label
|
|
185
|
+
text: label ?? 'Card title',
|
|
195
186
|
fontSize: 18,
|
|
196
187
|
fontWeight: 'bold',
|
|
197
188
|
autoWidth: true
|
|
198
189
|
});
|
|
199
|
-
|
|
190
|
+
const body = createRectObject({
|
|
200
191
|
x: px + 16,
|
|
201
192
|
y: py + 72,
|
|
202
193
|
width: w - 32,
|
|
@@ -206,15 +197,15 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
206
197
|
stroke: 'transparent',
|
|
207
198
|
strokeWidth: 0
|
|
208
199
|
});
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
objects.push
|
|
212
|
-
return { objects
|
|
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' };
|
|
213
204
|
}
|
|
214
205
|
case 'form': {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
for (
|
|
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++) {
|
|
218
209
|
fields.push(createRectObject({
|
|
219
210
|
x: px,
|
|
220
211
|
y: py + 32 + i * 48,
|
|
@@ -226,12 +217,12 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
226
217
|
fill: '#fff'
|
|
227
218
|
}));
|
|
228
219
|
}
|
|
229
|
-
|
|
230
|
-
objects.push
|
|
231
|
-
return { objects
|
|
220
|
+
const packed = packGroup(fields, {});
|
|
221
|
+
objects.push(title, ...packed.objects);
|
|
222
|
+
return { objects, rootLabel: label ?? 'Form' };
|
|
232
223
|
}
|
|
233
224
|
default: {
|
|
234
|
-
|
|
225
|
+
const box = createRectObject({
|
|
235
226
|
x: px,
|
|
236
227
|
y: py + 20,
|
|
237
228
|
width: w,
|
|
@@ -240,21 +231,20 @@ export function drawUiComponent(kind, x, y, width, height, label) {
|
|
|
240
231
|
stroke: STROKE,
|
|
241
232
|
strokeWidth: STROKE_WIDTH
|
|
242
233
|
});
|
|
243
|
-
|
|
234
|
+
const title = createTextObject({
|
|
244
235
|
x: px,
|
|
245
236
|
y: py,
|
|
246
|
-
text: label
|
|
237
|
+
text: label ?? kind.replace(/_/g, ' '),
|
|
247
238
|
fontSize: 14,
|
|
248
239
|
autoWidth: true
|
|
249
240
|
});
|
|
250
241
|
objects.push(title, box);
|
|
251
|
-
return { objects
|
|
242
|
+
return { objects, rootLabel: label ?? kind };
|
|
252
243
|
}
|
|
253
244
|
}
|
|
254
245
|
}
|
|
255
|
-
export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth) {
|
|
256
|
-
|
|
257
|
-
var geometry = buildArrow({ x: fromX, y: fromY }, { x: toX, y: toY }, 0, strokeWidth);
|
|
246
|
+
export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth = 2) {
|
|
247
|
+
const geometry = buildArrow({ x: fromX, y: fromY }, { x: toX, y: toY }, 0, strokeWidth);
|
|
258
248
|
return createPathObject({
|
|
259
249
|
x: geometry.box.x,
|
|
260
250
|
y: geometry.box.y,
|
|
@@ -264,7 +254,7 @@ export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth) {
|
|
|
264
254
|
shape: 'arrow',
|
|
265
255
|
arrow: geometry.spec,
|
|
266
256
|
stroke: '#111827',
|
|
267
|
-
strokeWidth
|
|
257
|
+
strokeWidth,
|
|
268
258
|
fill: 'transparent'
|
|
269
259
|
});
|
|
270
260
|
}
|
|
@@ -1,33 +1,11 @@
|
|
|
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 { createGroupObject, createObjectId } from '../../engine/core/defaults.js';
|
|
22
2
|
/** Insert a group and its members in list order (group before members). */
|
|
23
|
-
export function packGroup(members, options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var parentId = (_b = options.parentId) !== null && _b !== void 0 ? _b : null;
|
|
28
|
-
var withParents = members.map(function (object) { return (__assign(__assign({}, object), { parentId: groupId })); });
|
|
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 }));
|
|
29
7
|
return {
|
|
30
|
-
groupId
|
|
31
|
-
objects:
|
|
8
|
+
groupId,
|
|
9
|
+
objects: [createGroupObject({ id: groupId, parentId }), ...withParents]
|
|
32
10
|
};
|
|
33
11
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CANVAS_TOOL_NAMES } from './types.js';
|
|
2
|
-
export
|
|
2
|
+
export const 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.',
|
|
@@ -150,20 +150,20 @@ export function isCanvasToolName(name) {
|
|
|
150
150
|
}
|
|
151
151
|
/** OpenAI / MCP-style tool list for the gateway LLM loop. */
|
|
152
152
|
export function toOpenAiTools() {
|
|
153
|
-
return CANVAS_TOOL_DEFINITIONS.map(
|
|
153
|
+
return CANVAS_TOOL_DEFINITIONS.map((tool) => ({
|
|
154
154
|
type: 'function',
|
|
155
155
|
function: {
|
|
156
156
|
name: tool.name,
|
|
157
157
|
description: tool.description,
|
|
158
158
|
parameters: tool.parameters
|
|
159
159
|
}
|
|
160
|
-
})
|
|
160
|
+
}));
|
|
161
161
|
}
|
|
162
162
|
/** MCP tool catalogue (names + inputSchema only). */
|
|
163
163
|
export function toMcpTools() {
|
|
164
|
-
return CANVAS_TOOL_DEFINITIONS.map(
|
|
164
|
+
return CANVAS_TOOL_DEFINITIONS.map((tool) => ({
|
|
165
165
|
name: tool.name,
|
|
166
166
|
description: tool.description,
|
|
167
167
|
inputSchema: tool.parameters
|
|
168
|
-
})
|
|
168
|
+
}));
|
|
169
169
|
}
|