@widgetic/canvas 0.5.45 → 0.5.47

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 (137) hide show
  1. package/README.md +3 -2
  2. package/dist/canvas/DomCanvas.svelte +1 -2
  3. package/dist/canvas/autosaveScheduler.js +37 -89
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +7 -19
  7. package/dist/canvas/chromeLayout.js +19 -21
  8. package/dist/canvas/eventScope.js +10 -14
  9. package/dist/canvas/host/CanvasHost.d.ts +6 -5
  10. package/dist/canvas/host/CanvasHost.js +1664 -1861
  11. package/dist/canvas/host/CanvasHostApi.js +4 -19
  12. package/dist/canvas/host/boardFiles.js +35 -51
  13. package/dist/canvas/host/browserServices.js +108 -196
  14. package/dist/canvas/host/conversion.js +82 -170
  15. package/dist/canvas/host/hostObject.js +7 -7
  16. package/dist/canvas/host/nearCards.js +18 -21
  17. package/dist/canvas/host/pageEvents.js +5 -5
  18. package/dist/canvas/host/pauseCollector.d.ts +18 -0
  19. package/dist/canvas/host/pauseCollector.js +45 -0
  20. package/dist/canvas/host/pictureSaves.js +9 -11
  21. package/dist/canvas/host/screenRects.js +28 -31
  22. package/dist/canvas/host/storedPictures.js +149 -243
  23. package/dist/canvas/host/strokeSnap.js +88 -143
  24. package/dist/canvas/index.d.ts +1 -1
  25. package/dist/canvas/openMarks.js +2 -2
  26. package/dist/canvas/outsideClickDeselect.js +6 -7
  27. package/dist/canvas/panZoomPosition.js +2 -2
  28. package/dist/canvas/preferredTextFont.js +13 -25
  29. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  30. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  31. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  32. package/dist/canvas/toolbarPosition.js +2 -2
  33. package/dist/canvas/types.d.ts +7 -1
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
  35. package/dist/canvas/ui/CanvasHint.svelte +10 -9
  36. package/dist/canvas/ui/SelectionPanel.svelte +14 -12
  37. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
  38. package/dist/canvas/ui/ShapesMenu.svelte +6 -4
  39. package/dist/canvas/ui/ToolButton.svelte +7 -6
  40. package/dist/canvas/ui/colorModel.js +21 -32
  41. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  42. package/dist/canvas/ui/floatingCard.d.ts +28 -8
  43. package/dist/canvas/ui/floatingCard.js +48 -28
  44. package/dist/canvas/ui/floatingLayer.js +5 -6
  45. package/dist/canvas/ui/keyHints.js +9 -11
  46. package/dist/canvas/ui/popoverSide.js +2 -3
  47. package/dist/canvas/ui/selectionTraits.d.ts +8 -4
  48. package/dist/canvas/ui/selectionTraits.js +44 -58
  49. package/dist/canvas/view/CanvasStage.svelte +1 -1
  50. package/dist/canvas/view/SelectionOverlay.svelte +2 -2
  51. package/dist/canvas/view/erasingMarks.js +7 -7
  52. package/dist/canvas/view/geometry.d.ts +1 -1
  53. package/dist/canvas/view/geometry.js +72 -91
  54. package/dist/canvas/view/liftedScene.js +24 -36
  55. package/dist/canvas/view/mountedScene.js +76 -79
  56. package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
  57. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
  58. package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
  59. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
  60. package/dist/components/boardLoaderDelay.d.ts +39 -0
  61. package/dist/components/boardLoaderDelay.js +71 -0
  62. package/dist/components/input-controls/ColorIC.svelte +1 -1
  63. package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
  64. package/dist/components/preferenceStorage.js +2 -2
  65. package/dist/engine/EngineCore.d.ts +42 -10
  66. package/dist/engine/EngineCore.js +843 -916
  67. package/dist/engine/codec/canvasDocument.js +192 -155
  68. package/dist/engine/codec/hostReadableKeys.js +1 -1
  69. package/dist/engine/core/arrange.js +26 -38
  70. package/dist/engine/core/arrow.js +79 -92
  71. package/dist/engine/core/arrowBinding.js +98 -116
  72. package/dist/engine/core/arrowBindingRecords.js +23 -38
  73. package/dist/engine/core/brush.d.ts +24 -0
  74. package/dist/engine/core/brush.js +223 -103
  75. package/dist/engine/core/cameraMove.js +39 -51
  76. package/dist/engine/core/defaults.js +92 -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.js +38 -55
  80. package/dist/engine/core/hitTest.js +68 -81
  81. package/dist/engine/core/matrix.js +18 -20
  82. package/dist/engine/core/pathData.js +183 -210
  83. package/dist/engine/core/rotationReset.js +5 -6
  84. package/dist/engine/core/scene.js +160 -224
  85. package/dist/engine/core/scribble.js +59 -84
  86. package/dist/engine/core/shapePaths.js +12 -15
  87. package/dist/engine/core/shapeTools.d.ts +23 -18
  88. package/dist/engine/core/shapeTools.js +104 -67
  89. package/dist/engine/core/snapping.js +65 -117
  90. package/dist/engine/core/style.d.ts +18 -2
  91. package/dist/engine/core/style.js +79 -80
  92. package/dist/engine/core/styleMemory.d.ts +88 -0
  93. package/dist/engine/core/styleMemory.js +189 -0
  94. package/dist/engine/core/transform.js +84 -95
  95. package/dist/engine/core/types.js +4 -4
  96. package/dist/engine/core/viewport.js +23 -36
  97. package/dist/engine/input/PointerController.js +513 -526
  98. package/dist/engine/input/arrowHandles.js +12 -12
  99. package/dist/engine/input/gestures.d.ts +8 -3
  100. package/dist/engine/input/gestures.js +378 -346
  101. package/dist/engine/input/hoverCursor.js +1 -1
  102. package/dist/engine/input/keyboard.js +42 -41
  103. package/dist/engine/input/selectionHandles.js +45 -50
  104. package/dist/engine/input/types.js +1 -1
  105. package/dist/engine/render/rasterize.js +86 -158
  106. package/dist/engine/state.js +6 -17
  107. package/dist/engine/text/layoutText.js +43 -62
  108. package/dist/engine/text/textMetrics.js +8 -10
  109. package/dist/engine/widgets.js +101 -137
  110. package/dist/fonts/interFont.js +30 -83
  111. package/dist/fonts/workspaceFonts.js +33 -92
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.js +4 -4
  114. package/dist/i18n/messages.js +1 -1
  115. package/dist/i18n/shortcuts.js +14 -14
  116. package/dist/index.d.ts +1 -1
  117. package/dist/poster/boardPlacement.d.ts +4 -1
  118. package/dist/poster/boardPlacement.js +34 -33
  119. package/dist/poster/boardPoster.js +58 -83
  120. package/dist/poster/paintBoardPoster.js +16 -39
  121. package/dist/poster/posterPictures.js +27 -43
  122. package/dist/settings/rememberedStyles.d.ts +22 -0
  123. package/dist/settings/rememberedStyles.js +47 -0
  124. package/dist/settings/rememberedTool.d.ts +50 -0
  125. package/dist/settings/rememberedTool.js +68 -0
  126. package/dist/settings/workspaceToolSettings.d.ts +25 -0
  127. package/dist/settings/workspaceToolSettings.js +38 -48
  128. package/dist/tools/components/catalog.js +64 -74
  129. package/dist/tools/components/grouping.js +6 -28
  130. package/dist/tools/definitions.js +5 -5
  131. package/dist/tools/executors.js +137 -169
  132. package/dist/tools/hostAdapter.js +10 -13
  133. package/dist/tools/sceneSummary.js +43 -57
  134. package/dist/tools/sketchIntent.js +13 -21
  135. package/dist/tools/styleArguments.js +19 -21
  136. package/dist/tools/types.js +1 -1
  137. package/package.json +5 -5
@@ -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
- var _a, _b;
25
- if (options === void 0) { options = {}; }
26
- var groupId = (_a = options.groupId) !== null && _a !== void 0 ? _a : createObjectId('gp');
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: groupId,
31
- objects: __spreadArray([createGroupObject({ id: groupId, parentId: parentId })], withParents, true)
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 var CANVAS_TOOL_DEFINITIONS = [
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(function (tool) { return ({
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(function (tool) { return ({
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
  }
@@ -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, createImageObject, createPathObject, createRectObject, createTextObject } from '../engine/core/defaults.js';
22
2
  import { readImageAddress, readLibraryFileAddress } from '../engine/codec/canvasDocument.js';
23
3
  import { buildArrow } from '../engine/core/arrow.js';
@@ -28,22 +8,20 @@ import { drawUiComponent, makeArrowBetween } from './components/catalog.js';
28
8
  import { centerOf, findByLabel, kindOfObject, labelOfObject, summarizeScene } from './sceneSummary.js';
29
9
  import { assetSizeFor, readColorArgument, readFontFamilyArgument, readNumberArgument } from './styleArguments.js';
30
10
  function groupLabelForName(groupId, scene) {
31
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
32
- var object = scene_1[_i];
11
+ for (const object of scene) {
33
12
  if (object.parentId === groupId && object.type === 'text')
34
13
  return object.text.trim();
35
14
  }
36
15
  return 'group';
37
16
  }
38
17
  function fail(code, error) {
39
- return { ok: false, error: error, code: code };
18
+ return { ok: false, error, code };
40
19
  }
41
- function ok(message, extra) {
42
- if (extra === void 0) { extra = {}; }
43
- return __assign({ ok: true, message: message }, extra);
20
+ function ok(message, extra = {}) {
21
+ return { ok: true, message, ...extra };
44
22
  }
45
23
  function clampInBounds(host, x, y, width, height) {
46
- var pad = 8;
24
+ const pad = 8;
47
25
  return (x >= -pad &&
48
26
  y >= -pad &&
49
27
  x + width <= host.bounds.width + pad &&
@@ -52,216 +30,215 @@ function clampInBounds(host, x, y, width, height) {
52
30
  height > 0);
53
31
  }
54
32
  function addToScene(host, objects) {
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; }) };
33
+ const withIds = objects.map((object) => ({ ...object, id: object.id ?? host.createId(kindOfObject(object)) }));
34
+ const scene = normalizeScene([...host.getScene(), ...withIds]);
35
+ return { scene, ids: withIds.map((object) => object.id) };
58
36
  }
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 });
37
+ const executors = {
38
+ get_canvas(host) {
39
+ const summary = summarizeScene(host.getScene(), host.bounds);
40
+ return ok(`Canvas has ${summary.elements.length} elements.`, { summary });
63
41
  },
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;
42
+ draw_ui_component(host, args) {
43
+ const component = String(args.component ?? '');
44
+ const x = Number(args.x);
45
+ const y = Number(args.y);
46
+ const width = Number(args.width ?? 360);
47
+ const height = Number(args.height ?? 240);
48
+ const label = typeof args.label === 'string' ? args.label : undefined;
72
49
  if (!Number.isFinite(x) || !Number.isFinite(y))
73
50
  return fail('invalid_args', 'x and y are required numbers.');
74
- var placement = drawUiComponent(component, x, y, width, height, label);
75
- var _d = addToScene(host, placement.objects), scene = _d.scene, ids = _d.ids;
51
+ const placement = drawUiComponent(component, x, y, width, height, label);
52
+ const { scene, ids } = addToScene(host, placement.objects);
76
53
  // The check is on what the component really covers (a button is 48 px high whatever height was asked for, a video
77
54
  // player has its title above y and a navigation strip below the thumbnail), not on the size that was passed: a
78
55
  // request with no size would otherwise be judged as 360 x 240, and a button near the bottom would be refused.
79
- var covered = boundsOfObjects(scene, ids);
56
+ const covered = boundsOfObjects(scene, ids);
80
57
  if (!covered || !clampInBounds(host, covered.x, covered.y, covered.width, covered.height)) {
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
+ const area = covered
59
+ ? ` 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)}.`
83
60
  : '';
84
- return fail('bounds', "Component would sit outside the canvas.".concat(area));
61
+ return fail('bounds', `Component would sit outside the canvas.${area}`);
85
62
  }
86
63
  host.commitScene(scene);
87
- return ok("Drew ".concat(component, " (").concat(placement.rootLabel, ")."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
64
+ return ok(`Drew ${component} (${placement.rootLabel}).`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
88
65
  },
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);
66
+ add_shape(host, args) {
67
+ const shape = String(args.shape ?? 'rectangle');
68
+ const x = Number(args.x);
69
+ const y = Number(args.y);
70
+ const width = Number(args.width);
71
+ const height = Number(args.height);
96
72
  if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height)) {
97
73
  return fail('invalid_args', 'x, y, width and height are required.');
98
74
  }
99
75
  if (!clampInBounds(host, x, y, width, height))
100
76
  return fail('bounds', 'Shape is outside the canvas.');
101
77
  // 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);
78
+ const fill = readColorArgument(args.fill, 'fill', true);
103
79
  if (!fill.ok)
104
80
  return fail('invalid_args', fill.error);
105
- var stroke = readColorArgument(args.stroke, 'stroke');
81
+ const stroke = readColorArgument(args.stroke, 'stroke');
106
82
  if (!stroke.ok)
107
83
  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;
84
+ const paint = { ...(fill.value !== undefined ? { fill: fill.value } : {}), ...(stroke.value !== undefined ? { stroke: stroke.value } : {}) };
85
+ let object;
86
+ const label = typeof args.label === 'string' ? args.label : undefined;
111
87
  if (shape === 'ellipse') {
112
- object = createEllipseObject(__assign({ x: x, y: y, width: width, height: height }, paint));
88
+ object = createEllipseObject({ x, y, width, height, ...paint });
113
89
  }
114
90
  else if (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));
91
+ const path = `M ${width / 2} 0 L ${width} ${height / 2} L ${width / 2} ${height} L 0 ${height / 2} Z`;
92
+ object = createPathObject({ x, y, width, height, d: path, shape: 'diamond', ...paint });
117
93
  }
118
94
  else {
119
- object = createRectObject(__assign({ x: x, y: y, width: width, height: height, roundness: shape === 'rounded' ? 16 : 0 }, paint));
95
+ object = createRectObject({ x, y, width, height, roundness: shape === 'rounded' ? 16 : 0, ...paint });
120
96
  }
121
- var objects = [object];
97
+ const objects = [object];
122
98
  if (label) {
123
99
  objects.push(createTextObject({ x: x + 4, y: y + 4, text: label, fontSize: 12, autoWidth: true }));
124
100
  }
125
- var _b = addToScene(host, objects), scene = _b.scene, ids = _b.ids;
101
+ const { scene, ids } = addToScene(host, objects);
126
102
  host.commitScene(scene);
127
- return ok("Added ".concat(shape, "."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
103
+ return ok(`Added ${shape}.`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
128
104
  },
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);
105
+ add_text(host, args) {
106
+ const text = String(args.text ?? '').trim();
107
+ const x = Number(args.x);
108
+ const y = Number(args.y);
134
109
  if (!text)
135
110
  return fail('invalid_args', 'text is required.');
136
111
  if (!Number.isFinite(x) || !Number.isFinite(y))
137
112
  return fail('invalid_args', 'x and y are required.');
138
- var width = Number((_b = args.width) !== null && _b !== void 0 ? _b : 200);
113
+ const width = Number(args.width ?? 200);
139
114
  // 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);
115
+ const fontFamily = readFontFamilyArgument(args.fontFamily, host.fontFamilies);
141
116
  if (!fontFamily.ok)
142
117
  return fail('invalid_args', fontFamily.error);
143
- var color = readColorArgument(args.color, 'color');
118
+ const color = readColorArgument(args.color, 'color');
144
119
  if (!color.ok)
145
120
  return fail('invalid_args', color.error);
146
- var fontSize = readNumberArgument(args.fontSize, 'fontSize', 8, 200);
121
+ const fontSize = readNumberArgument(args.fontSize, 'fontSize', 8, 200);
147
122
  if (!fontSize.ok)
148
123
  return fail('invalid_args', fontSize.error);
149
124
  if (args.fontWeight !== undefined && args.fontWeight !== 'normal' && args.fontWeight !== 'bold') {
150
125
  return fail('invalid_args', 'fontWeight must be "normal" or "bold".');
151
126
  }
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));
127
+ const look = {
128
+ ...(fontFamily.value !== undefined ? { fontFamily: fontFamily.value } : {}),
129
+ ...(color.value !== undefined ? { color: color.value } : {}),
130
+ ...(fontSize.value !== undefined ? { fontSize: fontSize.value, height: Math.ceil(fontSize.value * 1.2) } : {}),
131
+ ...(args.fontWeight === 'bold' ? { fontWeight: 'bold' } : {})
132
+ };
133
+ const object = createTextObject({ x, y, width, text, autoWidth: width <= 40, ...look });
154
134
  if (!clampInBounds(host, x, y, object.width, object.height))
155
135
  return fail('bounds', 'Text is outside the canvas.');
156
- var _c = addToScene(host, [object]), scene = _c.scene, ids = _c.ids;
136
+ const { scene, ids } = addToScene(host, [object]);
157
137
  host.commitScene(scene);
158
138
  return ok('Added text.', { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
159
139
  },
160
- add_asset: function (host, args) {
161
- var _a, _b;
162
- var assetId = typeof args.assetId === 'string' ? args.assetId.trim() : '';
140
+ add_asset(host, args) {
141
+ const assetId = typeof args.assetId === 'string' ? args.assetId.trim() : '';
163
142
  if (!assetId)
164
143
  return fail('invalid_args', 'assetId is required.');
165
- var assets = (_a = host.assets) !== null && _a !== void 0 ? _a : [];
144
+ const assets = host.assets ?? [];
166
145
  if (assets.length === 0) {
167
146
  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
147
  }
169
- var asset = assets.find(function (candidate) { return candidate.id === assetId; });
148
+ const asset = assets.find((candidate) => candidate.id === assetId);
170
149
  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 ? ', …' : '', "."));
150
+ const listed = assets.slice(0, 24).map((candidate) => candidate.id).join(', ');
151
+ return fail('not_found', `Unknown assetId "${assetId}". Use one of: ${listed}${assets.length > 24 ? ', …' : ''}.`);
173
152
  }
174
- var x = Number(args.x);
175
- var y = Number(args.y);
153
+ const x = Number(args.x);
154
+ const y = Number(args.y);
176
155
  if (!Number.isFinite(x) || !Number.isFinite(y))
177
156
  return fail('invalid_args', 'x and y are required.');
178
- var width = readNumberArgument(args.width, 'width', 8, 2000);
157
+ const width = readNumberArgument(args.width, 'width', 8, 2000);
179
158
  if (!width.ok)
180
159
  return fail('invalid_args', width.error);
181
- var height = readNumberArgument(args.height, 'height', 8, 2000);
160
+ const height = readNumberArgument(args.height, 'height', 8, 2000);
182
161
  if (!height.ok)
183
162
  return fail('invalid_args', height.error);
184
163
  // 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);
164
+ const src = readImageAddress(asset.src);
186
165
  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);
166
+ return fail('invalid_args', `Asset "${asset.id}" has no picture the canvas can draw.`);
167
+ const size = assetSizeFor(asset, width.value, height.value);
189
168
  if (!clampInBounds(host, x, y, size.width, size.height))
190
169
  return fail('bounds', 'Asset would sit outside the canvas.');
191
- var object = createImageObject({
192
- x: x,
193
- y: y,
170
+ const object = createImageObject({
171
+ x,
172
+ y,
194
173
  width: size.width,
195
174
  height: size.height,
196
- src: src,
175
+ src,
197
176
  fileName: asset.name.slice(0, 300),
198
177
  // 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,
178
+ libraryFileId: asset.libraryFileId ?? null,
200
179
  libraryFileUrl: readLibraryFileAddress(asset.libraryFileUrl),
201
180
  naturalWidth: asset.width && asset.width > 0 ? asset.width : size.width,
202
181
  naturalHeight: asset.height && asset.height > 0 ? asset.height : size.height
203
182
  });
204
- var _c = addToScene(host, [object]), scene = _c.scene, ids = _c.ids;
183
+ const { scene, ids } = addToScene(host, [object]);
205
184
  host.commitScene(scene);
206
- return ok("Placed ".concat(asset.name, "."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
185
+ return ok(`Placed ${asset.name}.`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
207
186
  },
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();
187
+ add_arrow(host, args) {
188
+ let fromX = Number(args.fromX);
189
+ let fromY = Number(args.fromY);
190
+ let toX = Number(args.toX);
191
+ let toY = Number(args.toY);
192
+ const scene = host.getScene();
214
193
  if (typeof args.fromId === 'string') {
215
- var center = centerOf(args.fromId, scene);
194
+ const center = centerOf(args.fromId, scene);
216
195
  if (!center)
217
- return fail('not_found', "fromId ".concat(args.fromId, " not found."));
196
+ return fail('not_found', `fromId ${args.fromId} not found.`);
218
197
  fromX = center.x;
219
198
  fromY = center.y;
220
199
  }
221
200
  if (typeof args.toId === 'string') {
222
- var center = centerOf(args.toId, scene);
201
+ const center = centerOf(args.toId, scene);
223
202
  if (!center)
224
- return fail('not_found', "toId ".concat(args.toId, " not found."));
203
+ return fail('not_found', `toId ${args.toId} not found.`);
225
204
  toX = center.x;
226
205
  toY = center.y;
227
206
  }
228
207
  if (![fromX, fromY, toX, toY].every(Number.isFinite))
229
208
  return fail('invalid_args', 'Need from/to points or ids.');
230
- var objects = [makeArrowBetween(fromX, fromY, toX, toY)];
209
+ const objects = [makeArrowBetween(fromX, fromY, toX, toY)];
231
210
  if (typeof args.label === 'string' && args.label.trim()) {
232
211
  objects.push(createTextObject({ x: (fromX + toX) / 2, y: (fromY + toY) / 2 - 16, text: args.label.trim(), fontSize: 12, autoWidth: true }));
233
212
  }
234
- var added = addToScene(host, objects);
213
+ const added = addToScene(host, objects);
235
214
  host.commitScene(added.scene);
236
215
  return ok('Added arrow.', { createdIds: added.ids, summary: summarizeScene(added.scene, host.bounds) });
237
216
  },
238
- move_elements: function (host, args) {
239
- var _a, _b;
240
- var ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
217
+ move_elements(host, args) {
218
+ const ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
241
219
  if (ids.length === 0)
242
220
  return fail('invalid_args', 'ids required.');
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];
221
+ let scene = host.getScene();
222
+ const index = indexScene(scene);
223
+ for (const id of ids) {
247
224
  if (!index.has(id))
248
- return fail('not_found', "Element ".concat(id, " not found."));
225
+ return fail('not_found', `Element ${id} not found.`);
249
226
  }
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);
227
+ const dx = Number(args.dx ?? 0);
228
+ const dy = Number(args.dy ?? 0);
252
229
  if ((Number.isFinite(args.x) || Number.isFinite(args.y)) && ids.length > 0) {
253
- var first = findObject(scene, ids[0]);
230
+ const first = findObject(scene, ids[0]);
254
231
  if (!first)
255
232
  return fail('not_found', 'First id not movable.');
256
- var bbox = first.type === 'group'
233
+ const bbox = first.type === 'group'
257
234
  ? boundsOfObjects(scene, [first.id])
258
235
  : isBoxedObject(first)
259
236
  ? shapeBounds(first)
260
237
  : null;
261
238
  if (!bbox)
262
239
  return fail('not_found', 'First id not movable.');
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;
240
+ const targetDx = Number.isFinite(args.x) ? Number(args.x) - bbox.x : 0;
241
+ const targetDy = Number.isFinite(args.y) ? Number(args.y) - bbox.y : 0;
265
242
  scene = translateObjects(scene, ids, targetDx, targetDy);
266
243
  }
267
244
  else if (dx !== 0 || dy !== 0) {
@@ -271,36 +248,35 @@ var executors = {
271
248
  return fail('invalid_args', 'Provide dx/dy or x/y.');
272
249
  }
273
250
  host.commitScene(scene);
274
- return ok("Moved ".concat(ids.length, " element(s)."), { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
251
+ return ok(`Moved ${ids.length} element(s).`, { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
275
252
  },
276
- delete_elements: function (host, args) {
277
- var ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
253
+ delete_elements(host, args) {
254
+ const ids = Array.isArray(args.ids) ? args.ids.map(String) : [];
278
255
  if (ids.length === 0)
279
256
  return fail('invalid_args', 'ids required.');
280
- var scene = host.getScene();
257
+ let scene = host.getScene();
281
258
  if (ids.length === 1 && ids[0] === 'all') {
282
259
  scene = [];
283
260
  }
284
261
  else {
285
- var missing = ids.filter(function (id) { return !findObject(scene, id); });
262
+ const missing = ids.filter((id) => !findObject(scene, id));
286
263
  if (missing.length > 0)
287
- return fail('not_found', "Unknown ids: ".concat(missing.join(', ')));
264
+ return fail('not_found', `Unknown ids: ${missing.join(', ')}`);
288
265
  scene = removeObjects(scene, ids);
289
266
  }
290
267
  host.commitScene(scene);
291
268
  return ok('Deleted elements.', { affectedIds: ids, summary: summarizeScene(scene, host.bounds) });
292
269
  },
293
- clear_canvas: function (host) {
294
- var scene = [];
270
+ clear_canvas(host) {
271
+ const scene = [];
295
272
  host.commitScene(scene);
296
273
  return ok('Canvas cleared.', { summary: summarizeScene(scene, host.bounds) });
297
274
  },
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];
275
+ name_components_with_arrows(host, args) {
276
+ const prefix = typeof args.prefix === 'string' ? args.prefix.trim() : '';
277
+ const sceneBefore = host.getScene();
278
+ const additions = [];
279
+ for (const object of sceneBefore) {
304
280
  if (object.parentId !== null)
305
281
  continue;
306
282
  if (object.type === 'text')
@@ -309,19 +285,19 @@ var executors = {
309
285
  continue;
310
286
  if (!isBoxedObject(object) && object.type !== 'group')
311
287
  continue;
312
- var name = "".concat(prefix ? "".concat(prefix, " ") : '').concat(object.type === 'group' ? groupLabelForName(object.id, sceneBefore) : labelOfObject(object)).trim();
313
- var bbox = object.type === 'group'
288
+ const name = `${prefix ? `${prefix} ` : ''}${object.type === 'group' ? groupLabelForName(object.id, sceneBefore) : labelOfObject(object)}`.trim();
289
+ const bbox = object.type === 'group'
314
290
  ? boundsOfObjects(sceneBefore, [object.id])
315
291
  : isBoxedObject(object)
316
292
  ? shapeBounds(object)
317
293
  : null;
318
294
  if (!bbox)
319
295
  continue;
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 });
296
+ const labelX = bbox.x - 8;
297
+ const labelY = bbox.y - 28;
298
+ const label = createTextObject({ x: labelX, y: labelY, text: name, fontSize: 12, autoWidth: true });
323
299
  additions.push(label);
324
- var geometry = buildArrow({ x: labelX + 40, y: labelY + 10 }, { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 }, 0, 2);
300
+ const geometry = buildArrow({ x: labelX + 40, y: labelY + 10 }, { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 }, 0, 2);
325
301
  additions.push(createPathObject({
326
302
  x: geometry.box.x,
327
303
  y: geometry.box.y,
@@ -335,15 +311,15 @@ var executors = {
335
311
  fill: 'transparent'
336
312
  }));
337
313
  }
338
- var _a = addToScene(host, additions), scene = _a.scene, ids = _a.ids;
314
+ const { scene, ids } = addToScene(host, additions);
339
315
  host.commitScene(scene);
340
- return ok("Named ".concat(additions.length / 2, " components."), { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
316
+ return ok(`Named ${additions.length / 2} components.`, { createdIds: ids, summary: summarizeScene(scene, host.bounds) });
341
317
  }
342
318
  };
343
319
  export function executeCanvasTool(host, name, args) {
344
- var run = executors[name];
320
+ const run = executors[name];
345
321
  if (!run)
346
- return fail('invalid_args', "Unknown tool ".concat(name, "."));
322
+ return fail('invalid_args', `Unknown tool ${name}.`);
347
323
  try {
348
324
  return run(host, args);
349
325
  }
@@ -353,42 +329,34 @@ export function executeCanvasTool(host, name, args) {
353
329
  }
354
330
  /** Navigation wireframe group (label "Navigation"). */
355
331
  export function findNavigationId(scene) {
356
- for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
357
- var object = scene_2[_i];
332
+ for (const object of scene) {
358
333
  if (object.type === 'text' && object.text.trim().toLowerCase() === 'navigation' && object.parentId) {
359
334
  return object.parentId;
360
335
  }
361
336
  }
362
- var direct = findByLabel(scene, 'navigation');
337
+ const direct = findByLabel(scene, 'navigation');
363
338
  if (direct) {
364
- var object = findObject(scene, direct);
365
- if ((object === null || object === void 0 ? void 0 : object.type) === 'group')
339
+ const object = findObject(scene, direct);
340
+ if (object?.type === 'group')
366
341
  return direct;
367
- if (object === null || object === void 0 ? void 0 : object.parentId)
342
+ if (object?.parentId)
368
343
  return object.parentId;
369
344
  }
370
345
  return findByLabel(scene, 'nav');
371
346
  }
372
347
  export function findVideoThumbnailBounds(scene) {
373
- var _loop_1 = function (object) {
348
+ for (const object of scene) {
374
349
  if (object.type === 'text' && object.text.toLowerCase() === 'thumbnail') {
375
- var frame = scene.find(function (candidate) { return candidate.parentId === object.parentId || candidate.type === 'rect'; });
350
+ const frame = scene.find((candidate) => candidate.parentId === object.parentId || candidate.type === 'rect');
376
351
  if (frame && isBoxedObject(frame))
377
- return { value: shapeBounds(frame) };
352
+ return shapeBounds(frame);
378
353
  }
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;
385
354
  }
386
- var screen = scene.find(function (object) { return object.type === 'rect' && object.fill === '#f3f4f6' && object.parentId !== null; });
355
+ const screen = scene.find((object) => object.type === 'rect' && object.fill === '#f3f4f6' && object.parentId !== null);
387
356
  return screen && isBoxedObject(screen) ? shapeBounds(screen) : null;
388
357
  }
389
358
  export function findVideoPlayerRoot(scene) {
390
- for (var _i = 0, scene_4 = scene; _i < scene_4.length; _i++) {
391
- var object = scene_4[_i];
359
+ for (const object of scene) {
392
360
  if (object.type === 'text' && object.text.toLowerCase().includes('video player'))
393
361
  return object.id;
394
362
  }