@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.
Files changed (131) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +49 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
  4. package/dist/canvas/autosaveScheduler.js +37 -89
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +7 -19
  8. package/dist/canvas/chromeLayout.d.ts +14 -3
  9. package/dist/canvas/chromeLayout.js +30 -20
  10. package/dist/canvas/eventScope.js +10 -14
  11. package/dist/canvas/host/CanvasHost.d.ts +47 -5
  12. package/dist/canvas/host/CanvasHost.js +1481 -1566
  13. package/dist/canvas/host/CanvasHostApi.js +4 -19
  14. package/dist/canvas/host/browserServices.js +65 -116
  15. package/dist/canvas/host/conversion.js +82 -170
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/nearCards.d.ts +33 -0
  18. package/dist/canvas/host/nearCards.js +78 -0
  19. package/dist/canvas/host/pageEvents.d.ts +16 -4
  20. package/dist/canvas/host/pageEvents.js +17 -8
  21. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  22. package/dist/canvas/host/pictureSaves.js +42 -0
  23. package/dist/canvas/host/screenRects.d.ts +5 -0
  24. package/dist/canvas/host/screenRects.js +28 -31
  25. package/dist/canvas/host/storedPictures.d.ts +88 -0
  26. package/dist/canvas/host/storedPictures.js +288 -0
  27. package/dist/canvas/host/strokeSnap.js +88 -143
  28. package/dist/canvas/index.d.ts +1 -1
  29. package/dist/canvas/index.js +1 -1
  30. package/dist/canvas/openMarks.js +2 -2
  31. package/dist/canvas/outsideClickDeselect.js +6 -7
  32. package/dist/canvas/panZoomPosition.js +2 -2
  33. package/dist/canvas/preferredTextFont.js +13 -25
  34. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  35. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  36. package/dist/canvas/shapes/shapeImageStore.js +10 -3
  37. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  38. package/dist/canvas/toolbarPosition.d.ts +2 -2
  39. package/dist/canvas/toolbarPosition.js +4 -4
  40. package/dist/canvas/ui/SelectionPanel.svelte +28 -5
  41. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  42. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  43. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  44. package/dist/canvas/ui/ToolButton.svelte +8 -2
  45. package/dist/canvas/ui/colorModel.js +21 -32
  46. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  47. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  48. package/dist/canvas/ui/floatingCard.js +20 -20
  49. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  50. package/dist/canvas/ui/floatingLayer.js +18 -7
  51. package/dist/canvas/ui/keyHints.js +9 -11
  52. package/dist/canvas/ui/popoverSide.js +2 -3
  53. package/dist/canvas/ui/selectionTraits.js +34 -40
  54. package/dist/canvas/view/CanvasStage.svelte +101 -67
  55. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  56. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  57. package/dist/canvas/view/ObjectView.svelte +15 -10
  58. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  59. package/dist/canvas/view/erasingMarks.js +7 -7
  60. package/dist/canvas/view/geometry.js +71 -90
  61. package/dist/canvas/view/liftedScene.d.ts +31 -0
  62. package/dist/canvas/view/liftedScene.js +146 -0
  63. package/dist/canvas/view/mountedScene.d.ts +71 -0
  64. package/dist/canvas/view/mountedScene.js +363 -0
  65. package/dist/components/preferenceStorage.js +2 -2
  66. package/dist/engine/EngineCore.d.ts +15 -1
  67. package/dist/engine/EngineCore.js +724 -797
  68. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  69. package/dist/engine/codec/canvasDocument.js +212 -149
  70. package/dist/engine/codec/hostReadableKeys.js +1 -1
  71. package/dist/engine/core/arrange.js +26 -38
  72. package/dist/engine/core/arrow.js +76 -89
  73. package/dist/engine/core/arrowBinding.js +98 -116
  74. package/dist/engine/core/arrowBindingRecords.js +23 -38
  75. package/dist/engine/core/brush.js +67 -94
  76. package/dist/engine/core/defaults.js +90 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.d.ts +6 -0
  80. package/dist/engine/core/history.js +49 -50
  81. package/dist/engine/core/hitTest.js +68 -81
  82. package/dist/engine/core/matrix.js +18 -20
  83. package/dist/engine/core/pathData.js +183 -210
  84. package/dist/engine/core/rotationReset.js +5 -6
  85. package/dist/engine/core/scene.d.ts +10 -0
  86. package/dist/engine/core/scene.js +153 -187
  87. package/dist/engine/core/scribble.js +59 -84
  88. package/dist/engine/core/shapePaths.js +12 -15
  89. package/dist/engine/core/shapeTools.js +72 -63
  90. package/dist/engine/core/snapping.js +65 -117
  91. package/dist/engine/core/style.js +31 -64
  92. package/dist/engine/core/transform.js +83 -94
  93. package/dist/engine/core/types.d.ts +8 -2
  94. package/dist/engine/core/types.js +4 -4
  95. package/dist/engine/core/viewport.js +23 -36
  96. package/dist/engine/input/PointerController.js +467 -474
  97. package/dist/engine/input/arrowHandles.js +12 -12
  98. package/dist/engine/input/gestures.js +265 -309
  99. package/dist/engine/input/hoverCursor.js +1 -1
  100. package/dist/engine/input/keyboard.js +27 -30
  101. package/dist/engine/input/selectionHandles.js +45 -50
  102. package/dist/engine/input/types.js +1 -1
  103. package/dist/engine/render/rasterize.js +86 -158
  104. package/dist/engine/state.d.ts +20 -0
  105. package/dist/engine/state.js +5 -15
  106. package/dist/engine/text/layoutText.js +43 -62
  107. package/dist/engine/text/textMetrics.js +8 -10
  108. package/dist/engine/widgets.js +101 -137
  109. package/dist/fonts/interFont.d.ts +10 -1
  110. package/dist/fonts/interFont.js +47 -75
  111. package/dist/fonts/workspaceFonts.js +32 -90
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.d.ts +3 -3
  114. package/dist/i18n/language.js +4 -4
  115. package/dist/i18n/messages.d.ts +8 -1
  116. package/dist/i18n/messages.js +10 -2
  117. package/dist/i18n/shortcuts.js +14 -14
  118. package/dist/index.d.ts +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/settings/workspaceToolSettings.js +32 -48
  121. package/dist/tools/components/catalog.js +64 -74
  122. package/dist/tools/components/grouping.js +6 -28
  123. package/dist/tools/definitions.js +5 -5
  124. package/dist/tools/executors.js +105 -141
  125. package/dist/tools/hostAdapter.js +11 -13
  126. package/dist/tools/sceneSummary.js +43 -57
  127. package/dist/tools/sketchIntent.js +13 -21
  128. package/dist/tools/types.js +1 -1
  129. package/package.json +1 -1
  130. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  131. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -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 (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
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: error, code: code };
16
+ return { ok: false, error, code };
38
17
  }
39
- function ok(message, extra) {
40
- if (extra === void 0) { extra = {}; }
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
- var pad = 8;
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
- 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)) })); });
54
- var scene = normalizeScene(__spreadArray(__spreadArray([], host.getScene(), true), withIds, true));
55
- return { scene: scene, ids: withIds.map(function (object) { return object.id; }) };
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
- var executors = {
58
- get_canvas: function (host) {
59
- var summary = summarizeScene(host.getScene(), host.bounds);
60
- return ok("Canvas has ".concat(summary.elements.length, " elements."), { summary: summary });
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: function (host, args) {
63
- var _a, _b, _c;
64
- var component = String((_a = args.component) !== null && _a !== void 0 ? _a : '');
65
- var x = Number(args.x);
66
- var y = Number(args.y);
67
- var width = Number((_b = args.width) !== null && _b !== void 0 ? _b : 360);
68
- var height = Number((_c = args.height) !== null && _c !== void 0 ? _c : 240);
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
- var placement = drawUiComponent(component, x, y, width, height, label);
73
- var _d = addToScene(host, placement.objects), scene = _d.scene, ids = _d.ids;
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
- var covered = boundsOfObjects(scene, ids);
54
+ const covered = boundsOfObjects(scene, ids);
78
55
  if (!covered || !clampInBounds(host, covered.x, covered.y, covered.width, covered.height)) {
79
- var area = covered
80
- ? " 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), ".")
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', "Component would sit outside the canvas.".concat(area));
59
+ return fail('bounds', `Component would sit outside the canvas.${area}`);
83
60
  }
84
61
  host.commitScene(scene);
85
- return ok("Drew ".concat(component, " (").concat(placement.rootLabel, ")."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
62
+ return ok(`Drew ${component} (${placement.rootLabel}).`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
86
63
  },
87
- add_shape: function (host, args) {
88
- var _a;
89
- var shape = String((_a = args.shape) !== null && _a !== void 0 ? _a : 'rectangle');
90
- var x = Number(args.x);
91
- var y = Number(args.y);
92
- var width = Number(args.width);
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
- var object;
100
- var label = typeof args.label === 'string' ? args.label : undefined;
75
+ let object;
76
+ const label = typeof args.label === 'string' ? args.label : undefined;
101
77
  if (shape === 'ellipse') {
102
- object = createEllipseObject({ x: x, y: y, width: width, height: height });
78
+ object = createEllipseObject({ x, y, width, height });
103
79
  }
104
80
  else if (shape === 'diamond') {
105
- 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");
106
- object = createPathObject({ x: x, y: y, width: width, height: height, d: path, shape: 'diamond' });
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: x, y: y, width: width, height: height, roundness: shape === 'rounded' ? 16 : 0 });
85
+ object = createRectObject({ x, y, width, height, roundness: shape === 'rounded' ? 16 : 0 });
110
86
  }
111
- var objects = [object];
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
- var _b = addToScene(host, objects), scene = _b.scene, ids = _b.ids;
91
+ const { scene, ids } = addToScene(host, objects);
116
92
  host.commitScene(scene);
117
- return ok("Added ".concat(shape, "."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
93
+ return ok(`Added ${shape}.`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
118
94
  },
119
- add_text: function (host, args) {
120
- var _a, _b;
121
- var text = String((_a = args.text) !== null && _a !== void 0 ? _a : '').trim();
122
- var x = Number(args.x);
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
- var width = Number((_b = args.width) !== null && _b !== void 0 ? _b : 200);
129
- var object = createTextObject({ x: x, y: y, width: width, text: text, autoWidth: width <= 40 });
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
- var _c = addToScene(host, [object]), scene = _c.scene, ids = _c.ids;
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: function (host, args) {
137
- var fromX = Number(args.fromX);
138
- var fromY = Number(args.fromY);
139
- var toX = Number(args.toX);
140
- var toY = Number(args.toY);
141
- var scene = host.getScene();
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
- var center = centerOf(args.fromId, scene);
118
+ const center = centerOf(args.fromId, scene);
144
119
  if (!center)
145
- return fail('not_found', "fromId ".concat(args.fromId, " 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
- var center = centerOf(args.toId, scene);
125
+ const center = centerOf(args.toId, scene);
151
126
  if (!center)
152
- return fail('not_found', "toId ".concat(args.toId, " 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
- var objects = [makeArrowBetween(fromX, fromY, toX, toY)];
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
- var added = addToScene(host, objects);
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: function (host, args) {
167
- var _a, _b;
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
- var scene = host.getScene();
172
- var index = indexScene(scene);
173
- for (var _i = 0, ids_1 = ids; _i < ids_1.length; _i++) {
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', "Element ".concat(id, " not found."));
149
+ return fail('not_found', `Element ${id} not found.`);
177
150
  }
178
- var dx = Number((_a = args.dx) !== null && _a !== void 0 ? _a : 0);
179
- var dy = Number((_b = args.dy) !== null && _b !== void 0 ? _b : 0);
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
- var first = findObject(scene, ids[0]);
154
+ const first = findObject(scene, ids[0]);
182
155
  if (!first)
183
156
  return fail('not_found', 'First id not movable.');
184
- var bbox = first.type === 'group'
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
- var targetDx = Number.isFinite(args.x) ? Number(args.x) - bbox.x : 0;
192
- var targetDy = Number.isFinite(args.y) ? Number(args.y) - bbox.y : 0;
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("Moved ".concat(ids.length, " element(s)."), { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
175
+ return ok(`Moved ${ids.length} element(s).`, { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
203
176
  },
204
- delete_elements: function (host, args) {
205
- var ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
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
- var scene = host.getScene();
181
+ let scene = host.getScene();
209
182
  if (ids.length === 1 && ids[0] === 'all') {
210
183
  scene = [];
211
184
  }
212
185
  else {
213
- var missing = ids.filter(function (id) { return !findObject(scene, id); });
186
+ const missing = ids.filter((id) => !findObject(scene, id));
214
187
  if (missing.length > 0)
215
- return fail('not_found', "Unknown ids: ".concat(missing.join(', ')));
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: function (host) {
222
- var scene = [];
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: function (host, args) {
227
- var prefix = typeof args.prefix === 'string' ? args.prefix.trim() : '';
228
- var sceneBefore = host.getScene();
229
- var additions = [];
230
- for (var _i = 0, sceneBefore_1 = sceneBefore; _i < sceneBefore_1.length; _i++) {
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
- var name = "".concat(prefix ? "".concat(prefix, " ") : '').concat(object.type === 'group' ? groupLabelForName(object.id, sceneBefore) : labelOfObject(object)).trim();
241
- var bbox = object.type === 'group'
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
- var labelX = bbox.x - 8;
249
- var labelY = bbox.y - 28;
250
- var label = createTextObject({ x: labelX, y: labelY, text: name, fontSize: 12, autoWidth: true });
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
- var geometry = buildArrow({ x: labelX + 40, y: labelY + 10 }, { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 }, 0, 2);
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
- var _a = addToScene(host, additions), scene = _a.scene, ids = _a.ids;
238
+ const { scene, ids } = addToScene(host, additions);
267
239
  host.commitScene(scene);
268
- return ok("Named ".concat(additions.length / 2, " components."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
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
- var run = executors[name];
244
+ const run = executors[name];
273
245
  if (!run)
274
- return fail('invalid_args', "Unknown tool ".concat(name, "."));
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 (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
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
- var direct = findByLabel(scene, 'navigation');
261
+ const direct = findByLabel(scene, 'navigation');
291
262
  if (direct) {
292
- var object = findObject(scene, direct);
293
- if ((object === null || object === void 0 ? void 0 : object.type) === 'group')
263
+ const object = findObject(scene, direct);
264
+ if (object?.type === 'group')
294
265
  return direct;
295
- if (object === null || object === void 0 ? void 0 : object.parentId)
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
- var _loop_1 = function (object) {
272
+ for (const object of scene) {
302
273
  if (object.type === 'text' && object.text.toLowerCase() === 'thumbnail') {
303
- var frame = scene.find(function (candidate) { return candidate.parentId === object.parentId || candidate.type === 'rect'; });
274
+ const frame = scene.find((candidate) => candidate.parentId === object.parentId || candidate.type === 'rect');
304
275
  if (frame && isBoxedObject(frame))
305
- return { value: shapeBounds(frame) };
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
- var screen = scene.find(function (object) { return object.type === 'rect' && object.fill === '#f3f4f6' && object.parentId !== null; });
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 (var _i = 0, scene_4 = scene; _i < scene_4.length; _i++) {
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
- var _a;
7
- var engine = options.engine;
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: bounds,
14
- getScene: function () {
12
+ bounds,
13
+ getScene() {
15
14
  return engine.state.scene;
16
15
  },
17
- createId: function (prefix) {
18
- return createObjectId(prefix !== null && prefix !== void 0 ? prefix : 'sketch');
16
+ createId(prefix) {
17
+ return createObjectId(prefix ?? 'sketch');
19
18
  },
20
- commitScene: function (next) {
21
- var _a;
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
- var engineHost = host;
27
+ const engineHost = host;
30
28
  if (engine) {
31
- var snapshot = engine.state.scene;
29
+ const snapshot = engine.state.scene;
32
30
  run();
33
- var finalScene = host.getScene();
31
+ const finalScene = host.getScene();
34
32
  if (finalScene !== snapshot) {
35
33
  engine.applyScene(finalScene, 'push');
36
34
  }