@widgetic/canvas 0.5.44 → 0.5.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/canvas/DomCanvas.svelte +52 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +68 -1
  10. package/dist/canvas/host/CanvasHost.js +1901 -1407
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +28 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +1 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  35. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  36. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  37. package/dist/canvas/ui/SelectionPanel.svelte +78 -17
  38. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  39. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  40. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  41. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  42. package/dist/canvas/ui/ToolButton.svelte +34 -55
  43. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  44. package/dist/canvas/ui/colorModel.js +32 -21
  45. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  46. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  47. package/dist/canvas/ui/floatingCard.js +43 -21
  48. package/dist/canvas/ui/floatingLayer.js +6 -5
  49. package/dist/canvas/ui/icons.d.ts +1 -1
  50. package/dist/canvas/ui/icons.js +1 -1
  51. package/dist/canvas/ui/keyHints.js +11 -9
  52. package/dist/canvas/ui/popoverSide.js +3 -2
  53. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  54. package/dist/canvas/ui/selectionTraits.js +66 -35
  55. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  56. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  57. package/dist/canvas/view/CanvasStage.svelte +7 -2
  58. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  59. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  60. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  61. package/dist/canvas/view/erasingMarks.js +7 -7
  62. package/dist/canvas/view/geometry.d.ts +1 -1
  63. package/dist/canvas/view/geometry.js +90 -71
  64. package/dist/canvas/view/liftedScene.js +36 -24
  65. package/dist/canvas/view/mountedScene.js +79 -76
  66. package/dist/components/CanvasBoardPoster.svelte +206 -0
  67. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  68. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  69. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  70. package/dist/components/index.d.ts +7 -0
  71. package/dist/components/index.js +8 -0
  72. package/dist/components/preferenceStorage.js +2 -2
  73. package/dist/engine/EngineCore.d.ts +37 -2
  74. package/dist/engine/EngineCore.js +946 -768
  75. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  76. package/dist/engine/codec/canvasDocument.js +172 -186
  77. package/dist/engine/codec/hostReadableKeys.js +1 -1
  78. package/dist/engine/core/arrange.js +38 -26
  79. package/dist/engine/core/arrow.d.ts +18 -8
  80. package/dist/engine/core/arrow.js +109 -84
  81. package/dist/engine/core/arrowBinding.d.ts +1 -1
  82. package/dist/engine/core/arrowBinding.js +126 -101
  83. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  84. package/dist/engine/core/arrowBindingRecords.js +48 -29
  85. package/dist/engine/core/brush.d.ts +8 -0
  86. package/dist/engine/core/brush.js +98 -78
  87. package/dist/engine/core/cameraMove.d.ts +6 -0
  88. package/dist/engine/core/cameraMove.js +56 -38
  89. package/dist/engine/core/defaults.js +51 -90
  90. package/dist/engine/core/freehand.js +163 -147
  91. package/dist/engine/core/geometry.js +54 -47
  92. package/dist/engine/core/history.js +55 -38
  93. package/dist/engine/core/hitTest.js +81 -68
  94. package/dist/engine/core/matrix.js +20 -18
  95. package/dist/engine/core/pathData.js +210 -183
  96. package/dist/engine/core/rotationReset.js +6 -5
  97. package/dist/engine/core/scene.d.ts +22 -0
  98. package/dist/engine/core/scene.js +288 -139
  99. package/dist/engine/core/scribble.js +84 -59
  100. package/dist/engine/core/shapePaths.js +15 -12
  101. package/dist/engine/core/shapeTools.js +63 -72
  102. package/dist/engine/core/snapping.js +117 -65
  103. package/dist/engine/core/style.d.ts +10 -0
  104. package/dist/engine/core/style.js +82 -33
  105. package/dist/engine/core/transform.d.ts +6 -0
  106. package/dist/engine/core/transform.js +103 -83
  107. package/dist/engine/core/types.d.ts +7 -0
  108. package/dist/engine/core/types.js +4 -4
  109. package/dist/engine/core/viewport.js +36 -23
  110. package/dist/engine/input/PointerController.d.ts +15 -1
  111. package/dist/engine/input/PointerController.js +547 -476
  112. package/dist/engine/input/arrowHandles.js +12 -12
  113. package/dist/engine/input/gestures.d.ts +3 -1
  114. package/dist/engine/input/gestures.js +340 -266
  115. package/dist/engine/input/hoverCursor.js +1 -1
  116. package/dist/engine/input/keyboard.d.ts +22 -3
  117. package/dist/engine/input/keyboard.js +131 -32
  118. package/dist/engine/input/selectionHandles.js +50 -45
  119. package/dist/engine/input/types.d.ts +7 -0
  120. package/dist/engine/input/types.js +1 -1
  121. package/dist/engine/render/rasterize.js +158 -86
  122. package/dist/engine/state.d.ts +18 -0
  123. package/dist/engine/state.js +25 -4
  124. package/dist/engine/text/layoutText.js +62 -43
  125. package/dist/engine/text/textMetrics.js +10 -8
  126. package/dist/engine/widgets.js +137 -101
  127. package/dist/fonts/interFont.js +83 -30
  128. package/dist/fonts/workspaceFonts.d.ts +6 -0
  129. package/dist/fonts/workspaceFonts.js +108 -34
  130. package/dist/i18n/labels.js +4 -4
  131. package/dist/i18n/language.d.ts +3 -3
  132. package/dist/i18n/language.js +4 -4
  133. package/dist/i18n/messages.d.ts +6 -0
  134. package/dist/i18n/messages.js +7 -1
  135. package/dist/i18n/shortcuts.d.ts +6 -4
  136. package/dist/i18n/shortcuts.js +30 -26
  137. package/dist/index.d.ts +1 -0
  138. package/dist/poster/boardPlacement.d.ts +80 -0
  139. package/dist/poster/boardPlacement.js +140 -0
  140. package/dist/poster/boardPoster.d.ts +80 -0
  141. package/dist/poster/boardPoster.js +251 -0
  142. package/dist/poster/paintBoardPoster.d.ts +49 -0
  143. package/dist/poster/paintBoardPoster.js +112 -0
  144. package/dist/poster/posterPictures.d.ts +32 -0
  145. package/dist/poster/posterPictures.js +138 -0
  146. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  147. package/dist/settings/workspaceToolSettings.js +58 -34
  148. package/dist/tools/components/catalog.js +74 -64
  149. package/dist/tools/components/grouping.js +28 -6
  150. package/dist/tools/definitions.js +31 -9
  151. package/dist/tools/executors.js +214 -106
  152. package/dist/tools/hostAdapter.d.ts +5 -1
  153. package/dist/tools/hostAdapter.js +15 -11
  154. package/dist/tools/sceneSummary.js +57 -43
  155. package/dist/tools/sketchIntent.js +21 -13
  156. package/dist/tools/styleArguments.d.ts +35 -0
  157. package/dist/tools/styleArguments.js +93 -0
  158. package/dist/tools/types.d.ts +26 -1
  159. package/dist/tools/types.js +2 -1
  160. package/package.json +1 -1
@@ -3,32 +3,36 @@ 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
- const { engine } = options;
7
- const bounds = options.bounds ?? {
6
+ var _a;
7
+ var engine = options.engine;
8
+ var bounds = (_a = options.bounds) !== null && _a !== void 0 ? _a : {
8
9
  width: engine.state.viewSize.width || 1200,
9
10
  height: engine.state.viewSize.height || 800
10
11
  };
11
12
  return {
12
- bounds,
13
- getScene() {
13
+ bounds: bounds,
14
+ assets: options.assets,
15
+ fontFamilies: options.fontFamilies,
16
+ getScene: function () {
14
17
  return engine.state.scene;
15
18
  },
16
- createId(prefix) {
17
- return createObjectId(prefix ?? 'sketch');
19
+ createId: function (prefix) {
20
+ return createObjectId(prefix !== null && prefix !== void 0 ? prefix : 'sketch');
18
21
  },
19
- commitScene(next) {
20
- engine.applyScene(next, options.commitMode ?? 'push');
22
+ commitScene: function (next) {
23
+ var _a;
24
+ engine.applyScene(next, (_a = options.commitMode) !== null && _a !== void 0 ? _a : 'push');
21
25
  }
22
26
  };
23
27
  }
24
28
  /** Run several tool calls as a single undo step on the engine. */
25
29
  export function runCanvasToolBatch(host, run, engine) {
26
30
  // When backed by engine, defer commit until batch ends.
27
- const engineHost = host;
31
+ var engineHost = host;
28
32
  if (engine) {
29
- const snapshot = engine.state.scene;
33
+ var snapshot = engine.state.scene;
30
34
  run();
31
- const finalScene = host.getScene();
35
+ var finalScene = host.getScene();
32
36
  if (finalScene !== snapshot) {
33
37
  engine.applyScene(finalScene, 'push');
34
38
  }
@@ -1,19 +1,29 @@
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
+ };
1
10
  import { boundsOfObjects, findObject, indexScene, shapeBounds } from '../engine/core/scene.js';
2
11
  import { isBoxedObject } from '../engine/core/types.js';
3
- const DEFAULT_BOUNDS = { width: 1200, height: 800 };
4
- export const SCENE_SUMMARY_MAX_ELEMENTS = 48;
12
+ var DEFAULT_BOUNDS = { width: 1200, height: 800 };
13
+ export var SCENE_SUMMARY_MAX_ELEMENTS = 48;
5
14
  /** The longest label a summary carries (the assistant request schema accepts 256, and the model needs far fewer). */
6
- const SCENE_LABEL_MAX_CHARS = 80;
15
+ var SCENE_LABEL_MAX_CHARS = 80;
7
16
  /** A label cut to the length a summary carries, so a long text never makes a request the gateway refuses. */
8
17
  function shortenLabel(text) {
9
- return text.length > SCENE_LABEL_MAX_CHARS ? `${text.slice(0, SCENE_LABEL_MAX_CHARS - 3)}...` : text;
18
+ return text.length > SCENE_LABEL_MAX_CHARS ? "".concat(text.slice(0, SCENE_LABEL_MAX_CHARS - 3), "...") : text;
10
19
  }
11
20
  export function labelOfObject(object) {
21
+ var _a, _b;
12
22
  if (object.type === 'text') {
13
23
  return shortenLabel(object.text.trim());
14
24
  }
15
25
  if (object.type === 'widget')
16
- return object.widgetName ?? 'widget';
26
+ return (_a = object.widgetName) !== null && _a !== void 0 ? _a : 'widget';
17
27
  if (object.type === 'group')
18
28
  return 'group';
19
29
  if (object.type === 'path' && object.arrow)
@@ -25,11 +35,12 @@ export function labelOfObject(object) {
25
35
  if (object.type === 'ellipse')
26
36
  return 'ellipse';
27
37
  if (object.type === 'image')
28
- return object.fileName ?? 'image';
38
+ return (_b = object.fileName) !== null && _b !== void 0 ? _b : 'image';
29
39
  return object.type;
30
40
  }
31
41
  function groupLabelFromMembers(groupId, scene) {
32
- for (const object of scene) {
42
+ for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
43
+ var object = scene_1[_i];
33
44
  if (object.parentId === groupId && object.type === 'text') {
34
45
  // Cut like the label of a loose text: a component's first text can be a whole paragraph.
35
46
  return shortenLabel(object.text.trim()) || 'group';
@@ -56,30 +67,31 @@ function elementPriority(element) {
56
67
  return 3;
57
68
  }
58
69
  function compareElements(a, b) {
59
- const pa = elementPriority(a);
60
- const pb = elementPriority(b);
70
+ var pa = elementPriority(a);
71
+ var pb = elementPriority(b);
61
72
  if (pa !== pb)
62
73
  return pa - pb;
63
- const areaA = a.bbox.width * a.bbox.height;
64
- const areaB = b.bbox.width * b.bbox.height;
74
+ var areaA = a.bbox.width * a.bbox.height;
75
+ var areaB = b.bbox.width * b.bbox.height;
65
76
  if (areaA !== areaB)
66
77
  return areaB - areaA;
67
78
  return a.zIndex - b.zIndex;
68
79
  }
69
- export function summarizeScene(scene, bounds = DEFAULT_BOUNDS) {
70
- const elements = [];
71
- scene.forEach((object, zIndex) => {
80
+ export function summarizeScene(scene, bounds) {
81
+ if (bounds === void 0) { bounds = DEFAULT_BOUNDS; }
82
+ var elements = [];
83
+ scene.forEach(function (object, zIndex) {
72
84
  if (object.type === 'group') {
73
- const memberIds = scene.filter((member) => member.parentId === object.id).map((member) => member.id);
74
- const bbox = boundsOfObjects(scene, memberIds);
75
- if (!bbox)
85
+ var memberIds = scene.filter(function (member) { return member.parentId === object.id; }).map(function (member) { return member.id; });
86
+ var bbox_1 = boundsOfObjects(scene, memberIds);
87
+ if (!bbox_1)
76
88
  return;
77
89
  elements.push({
78
90
  id: object.id,
79
91
  kind: 'group',
80
92
  label: groupLabelFromMembers(object.id, scene),
81
- bbox,
82
- zIndex,
93
+ bbox: bbox_1,
94
+ zIndex: zIndex,
83
95
  parentId: object.parentId
84
96
  });
85
97
  return;
@@ -88,67 +100,69 @@ export function summarizeScene(scene, bounds = DEFAULT_BOUNDS) {
88
100
  return;
89
101
  if (!isBoxedObject(object))
90
102
  return;
91
- const bbox = shapeBounds(object);
103
+ var bbox = shapeBounds(object);
92
104
  elements.push({
93
105
  id: object.id,
94
106
  kind: kindOfObject(object),
95
107
  label: labelOfObject(object),
96
- bbox,
97
- zIndex,
108
+ bbox: bbox,
109
+ zIndex: zIndex,
98
110
  parentId: object.parentId
99
111
  });
100
112
  });
101
- const sorted = [...elements].sort(compareElements);
102
- const totalCount = sorted.length;
103
- const truncated = totalCount > SCENE_SUMMARY_MAX_ELEMENTS;
104
- const limited = truncated ? sorted.slice(0, SCENE_SUMMARY_MAX_ELEMENTS) : sorted;
113
+ var sorted = __spreadArray([], elements, true).sort(compareElements);
114
+ var totalCount = sorted.length;
115
+ var truncated = totalCount > SCENE_SUMMARY_MAX_ELEMENTS;
116
+ var limited = truncated ? sorted.slice(0, SCENE_SUMMARY_MAX_ELEMENTS) : sorted;
105
117
  return {
106
- bounds,
118
+ bounds: bounds,
107
119
  elements: limited,
108
- totalCount,
109
- truncated,
110
- truncationNote: truncated ? `Showing ${SCENE_SUMMARY_MAX_ELEMENTS} of ${totalCount} top-level elements.` : undefined
120
+ totalCount: totalCount,
121
+ truncated: truncated,
122
+ truncationNote: truncated ? "Showing ".concat(SCENE_SUMMARY_MAX_ELEMENTS, " of ").concat(totalCount, " top-level elements.") : undefined
111
123
  };
112
124
  }
113
125
  export function findByLabel(scene, needle) {
114
- const lower = needle.toLowerCase();
115
- for (const object of scene) {
126
+ var lower = needle.toLowerCase();
127
+ for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
128
+ var object = scene_2[_i];
116
129
  if (object.type === 'group') {
117
- const label = groupLabelFromMembers(object.id, scene).toLowerCase();
130
+ var label = groupLabelFromMembers(object.id, scene).toLowerCase();
118
131
  if (label.includes(lower))
119
132
  return object.id;
120
133
  }
121
134
  if (object.type === 'text') {
122
- const label = object.text.toLowerCase();
135
+ var label = object.text.toLowerCase();
123
136
  if (label.includes(lower))
124
137
  return object.id;
125
138
  }
126
139
  }
127
- for (const object of scene) {
128
- const label = labelOfObject(object).toLowerCase();
140
+ for (var _a = 0, scene_3 = scene; _a < scene_3.length; _a++) {
141
+ var object = scene_3[_a];
142
+ var label = labelOfObject(object).toLowerCase();
129
143
  if (label.includes(lower))
130
144
  return object.id;
131
145
  }
132
146
  return null;
133
147
  }
134
148
  export function centerOf(id, scene) {
135
- const object = findObject(scene, id);
136
- if (object?.type === 'group') {
137
- const bbox = boundsOfObjects(scene, [id]);
138
- if (!bbox)
149
+ var object = findObject(scene, id);
150
+ if ((object === null || object === void 0 ? void 0 : object.type) === 'group') {
151
+ var bbox_2 = boundsOfObjects(scene, [id]);
152
+ if (!bbox_2)
139
153
  return null;
140
- return { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
154
+ return { x: bbox_2.x + bbox_2.width / 2, y: bbox_2.y + bbox_2.height / 2 };
141
155
  }
142
156
  if (!object || !isBoxedObject(object))
143
157
  return null;
144
- const bbox = shapeBounds(object);
158
+ var bbox = shapeBounds(object);
145
159
  return { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
146
160
  }
147
161
  export function sceneIndexMap(scene) {
148
162
  return indexScene(scene);
149
163
  }
150
164
  export function bboxIntersects(a, b) {
151
- const pad = 2;
165
+ var pad = 2;
152
166
  return (a.x + a.width > b.x + pad &&
153
167
  b.x + b.width > a.x + pad &&
154
168
  a.y + a.height > b.y + pad &&
@@ -4,18 +4,26 @@
4
4
  * every script. It is written without a lookbehind (which older Safari does not have), so it can never stop the module
5
5
  * from loading.
6
6
  */
7
- function standalone(...alternatives) {
8
- return new RegExp(`(?:^|[^\\p{L}\\p{N}_])(?:${alternatives.join('|')})(?![\\p{L}\\p{N}_])`, 'iu');
7
+ function standalone() {
8
+ var alternatives = [];
9
+ for (var _i = 0; _i < arguments.length; _i++) {
10
+ alternatives[_i] = arguments[_i];
11
+ }
12
+ return new RegExp("(?:^|[^\\p{L}\\p{N}_])(?:".concat(alternatives.join('|'), ")(?![\\p{L}\\p{N}_])"), 'iu');
9
13
  }
10
14
  /** A pattern for a phrase of a writing system that puts no spaces between words (Chinese, Japanese): found anywhere. */
11
- function anywhere(...alternatives) {
12
- return new RegExp(`(?:${alternatives.join('|')})`, 'iu');
15
+ function anywhere() {
16
+ var alternatives = [];
17
+ for (var _i = 0; _i < arguments.length; _i++) {
18
+ alternatives[_i] = arguments[_i];
19
+ }
20
+ return new RegExp("(?:".concat(alternatives.join('|'), ")"), 'iu');
13
21
  }
14
22
  /**
15
23
  * Words that say the author wants something drawn on the canvas. Only words that mean drawing: a request to create
16
24
  * something ("make a quiz", "I need a video player") is a widget, and goes to the code generator.
17
25
  */
18
- const SKETCH_PATTERNS = [
26
+ var SKETCH_PATTERNS = [
19
27
  /\bdraw\b/i,
20
28
  /\bsketch\b/i,
21
29
  /\bwireframe\b/i,
@@ -50,7 +58,7 @@ const SKETCH_PATTERNS = [
50
58
  * Words that say the author wants code, a build or a publish. They win over a drawing word: "draw it, then publish it"
51
59
  * is a request for the widget.
52
60
  */
53
- const CODEGEN_PATTERNS = [
61
+ var CODEGEN_PATTERNS = [
54
62
  /\bbuild\b/i,
55
63
  /\bgenerate\b/i,
56
64
  /\bcode\b/i,
@@ -76,7 +84,7 @@ const CODEGEN_PATTERNS = [
76
84
  standalone('zbuduj', 'wygeneruj', 'kod', 'opublikuj', 'zaimplementuj'),
77
85
  standalone('bouw', 'genereer', 'publiceer', 'implementeer')
78
86
  ];
79
- export const SKETCH_INTENT_COUNTER_EXAMPLES = [
87
+ export var SKETCH_INTENT_COUNTER_EXAMPLES = [
80
88
  'build me a countdown widget',
81
89
  'make the button blue in the widget',
82
90
  'generate the react code for this',
@@ -88,7 +96,7 @@ export const SKETCH_INTENT_COUNTER_EXAMPLES = [
88
96
  * Free-text requests that draw, in the languages the router knows. Every one must route to the sketch assistant
89
97
  * (the creator's tests and the gateway's mirror hold the same list).
90
98
  */
91
- export const SKETCH_FREE_TEXT_EXAMPLES = [
99
+ export var SKETCH_FREE_TEXT_EXAMPLES = [
92
100
  'Sketch a pricing page with three plans and a call to action under each',
93
101
  'wireframe a dashboard with a sidebar and four stat cards',
94
102
  'can you draw three circles in a row and connect them with arrows',
@@ -120,7 +128,7 @@ export const SKETCH_FREE_TEXT_EXAMPLES = [
120
128
  * Requests that are not for a drawing, with the verdict each gets. Creating something ("make", "create", "I need") is a
121
129
  * widget, so most of them are `unknown` and go to the code generator by default; the ones that name code are `generate`.
122
130
  */
123
- export const SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
131
+ export var SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
124
132
  ['a video player with a playlist', 'unknown'],
125
133
  ['create a countdown timer with a start button', 'unknown'],
126
134
  ['I want a quiz about world capitals', 'unknown'],
@@ -141,16 +149,16 @@ export const SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
141
149
  * Lightweight sketch-vs-codegen classifier for the creator chat (gateway mirrors this in tests).
142
150
  */
143
151
  export function classifySketchIntent(message) {
144
- const text = message.trim();
152
+ var text = message.trim();
145
153
  if (!text)
146
154
  return 'unknown';
147
- if (CODEGEN_PATTERNS.some((pattern) => pattern.test(text)))
155
+ if (CODEGEN_PATTERNS.some(function (pattern) { return pattern.test(text); }))
148
156
  return 'generate';
149
- if (SKETCH_PATTERNS.some((pattern) => pattern.test(text)))
157
+ if (SKETCH_PATTERNS.some(function (pattern) { return pattern.test(text); }))
150
158
  return 'sketch';
151
159
  return 'unknown';
152
160
  }
153
- export const SKETCH_ACCEPTANCE_PROMPTS = [
161
+ export var SKETCH_ACCEPTANCE_PROMPTS = [
154
162
  'draw a video player for me',
155
163
  'move the navigation outside the video thumbnail',
156
164
  'delete all sketches',
@@ -0,0 +1,35 @@
1
+ /**
2
+ * What the sketch assistant may say about the look of what it draws, checked before anything reaches the board: a colour, a font,
3
+ * a size for a picture. The arguments come from a model, so each one is checked like input from outside: a bad value is refused
4
+ * with a sentence the model can act on (it retries), never silently turned into something else.
5
+ *
6
+ * Plain TypeScript: runs in Node.
7
+ */
8
+ import type { CanvasToolAsset } from './types.js';
9
+ export type ArgumentResult<Value> = {
10
+ ok: true;
11
+ value: Value;
12
+ } | {
13
+ ok: false;
14
+ error: string;
15
+ };
16
+ /** The colour in an argument: a hex colour (and `transparent` when `allowTransparent`). Absent when the model passed nothing. */
17
+ export declare function readColorArgument(value: unknown, name: string, allowTransparent?: boolean): ArgumentResult<string | undefined>;
18
+ /**
19
+ * The font family in an argument, as the canvas knows it. With a list of families (the built-in ones and the brand kit's) the name
20
+ * must be one of them (any spelling of the case); the answer is the family as the list writes it. Without a list any well-formed
21
+ * name is accepted. Absent when the model passed nothing.
22
+ */
23
+ export declare function readFontFamilyArgument(value: unknown, known: readonly string[] | undefined): ArgumentResult<string | undefined>;
24
+ /** A number inside a range, or absent. Anything else is refused. */
25
+ export declare function readNumberArgument(value: unknown, name: string, minimum: number, maximum: number): ArgumentResult<number | undefined>;
26
+ /** The side a picture is given when the assistant does not say how big (an icon is a small thing). */
27
+ export declare const ASSET_DEFAULT_SIDE = 96;
28
+ /**
29
+ * The size a placed picture gets: both sides as asked; one side as asked and the other from the picture's proportions; or, with no
30
+ * size asked, the longer side is `ASSET_DEFAULT_SIDE`. The proportions are the picture's own when it says its size, a square when not.
31
+ */
32
+ export declare function assetSizeFor(asset: Pick<CanvasToolAsset, 'width' | 'height'>, width: number | undefined, height: number | undefined): {
33
+ width: number;
34
+ height: number;
35
+ };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * What the sketch assistant may say about the look of what it draws, checked before anything reaches the board: a colour, a font,
3
+ * a size for a picture. The arguments come from a model, so each one is checked like input from outside: a bad value is refused
4
+ * with a sentence the model can act on (it retries), never silently turned into something else.
5
+ *
6
+ * Plain TypeScript: runs in Node.
7
+ */
8
+ import { isFontFamilyName } from '../engine/codec/canvasDocument.js';
9
+ /** A colour the assistant may pass: a hex colour (the brand kit's colours are hex), or `transparent` where a fill may be. */
10
+ var HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
11
+ /** The colour in an argument: a hex colour (and `transparent` when `allowTransparent`). Absent when the model passed nothing. */
12
+ export function readColorArgument(value, name, allowTransparent) {
13
+ if (allowTransparent === void 0) { allowTransparent = false; }
14
+ if (value === undefined || value === null || value === '')
15
+ return { ok: true, value: undefined };
16
+ var text = typeof value === 'string' ? value.trim() : '';
17
+ if (HEX_COLOR_PATTERN.test(text))
18
+ return { ok: true, value: text.toLowerCase() };
19
+ if (allowTransparent && text.toLowerCase() === 'transparent')
20
+ return { ok: true, value: 'transparent' };
21
+ return { ok: false, error: "".concat(name, " must be a hex colour such as #1a2b3c").concat(allowTransparent ? ' or "transparent"' : '', ", not ").concat(JSON.stringify(value), ".") };
22
+ }
23
+ /** The first family of a CSS font list, without quotes, lower-cased: how two spellings of one family are compared. */
24
+ function familyKey(family) {
25
+ var _a;
26
+ var first = (_a = family.split(',')[0]) !== null && _a !== void 0 ? _a : '';
27
+ return first.trim().replace(/^["']|["']$/g, '').toLowerCase();
28
+ }
29
+ /** How many families a refusal lists (the model needs a few to choose from, not a hundred). */
30
+ var FONT_LIST_IN_REFUSAL = 24;
31
+ /**
32
+ * The font family in an argument, as the canvas knows it. With a list of families (the built-in ones and the brand kit's) the name
33
+ * must be one of them (any spelling of the case); the answer is the family as the list writes it. Without a list any well-formed
34
+ * name is accepted. Absent when the model passed nothing.
35
+ */
36
+ export function readFontFamilyArgument(value, known) {
37
+ if (value === undefined || value === null || value === '')
38
+ return { ok: true, value: undefined };
39
+ var text = typeof value === 'string' ? value.trim() : '';
40
+ if (text === '' || !isFontFamilyName(text))
41
+ return { ok: false, error: "fontFamily must be a font family name, not ".concat(JSON.stringify(value), ".") };
42
+ if (!known || known.length === 0)
43
+ return { ok: true, value: text };
44
+ var wanted = familyKey(text);
45
+ var match = known.find(function (family) { return familyKey(family) === wanted; });
46
+ if (match)
47
+ return { ok: true, value: match };
48
+ var listed = known.slice(0, FONT_LIST_IN_REFUSAL).join(', ');
49
+ return { ok: false, error: "The font \"".concat(text, "\" is not on this canvas. Use one of: ").concat(listed).concat(known.length > FONT_LIST_IN_REFUSAL ? ', …' : '', ".") };
50
+ }
51
+ /** A number inside a range, or absent. Anything else is refused. */
52
+ export function readNumberArgument(value, name, minimum, maximum) {
53
+ if (value === undefined || value === null || value === '')
54
+ return { ok: true, value: undefined };
55
+ var number = typeof value === 'number' ? value : Number(value);
56
+ if (!Number.isFinite(number) || number < minimum || number > maximum) {
57
+ return { ok: false, error: "".concat(name, " must be a number from ").concat(minimum, " to ").concat(maximum, ", not ").concat(JSON.stringify(value), ".") };
58
+ }
59
+ return { ok: true, value: number };
60
+ }
61
+ /** The side a picture is given when the assistant does not say how big (an icon is a small thing). */
62
+ export var ASSET_DEFAULT_SIDE = 96;
63
+ /**
64
+ * The size a placed picture gets: both sides as asked; one side as asked and the other from the picture's proportions; or, with no
65
+ * size asked, the longer side is `ASSET_DEFAULT_SIDE`. The proportions are the picture's own when it says its size, a square when not.
66
+ */
67
+ export function assetSizeFor(asset, width, height) {
68
+ var known = typeof asset.width === 'number' && typeof asset.height === 'number' && asset.width > 0 && asset.height > 0;
69
+ var aspect = known ? asset.width / asset.height : 1;
70
+ var finalWidth;
71
+ var finalHeight;
72
+ if (width !== undefined && height !== undefined) {
73
+ finalWidth = width;
74
+ finalHeight = height;
75
+ }
76
+ else if (width !== undefined) {
77
+ finalWidth = width;
78
+ finalHeight = width / aspect;
79
+ }
80
+ else if (height !== undefined) {
81
+ finalHeight = height;
82
+ finalWidth = height * aspect;
83
+ }
84
+ else if (aspect >= 1) {
85
+ finalWidth = ASSET_DEFAULT_SIDE;
86
+ finalHeight = ASSET_DEFAULT_SIDE / aspect;
87
+ }
88
+ else {
89
+ finalHeight = ASSET_DEFAULT_SIDE;
90
+ finalWidth = ASSET_DEFAULT_SIDE * aspect;
91
+ }
92
+ return { width: Math.max(8, Math.round(finalWidth)), height: Math.max(8, Math.round(finalHeight)) };
93
+ }
@@ -1,6 +1,6 @@
1
1
  import type { ObjectId, Rect } from '../engine/core/types.js';
2
2
  import type { Scene } from '../engine/core/scene.js';
3
- export declare const CANVAS_TOOL_NAMES: readonly ["get_canvas", "draw_ui_component", "add_shape", "add_text", "add_arrow", "move_elements", "delete_elements", "clear_canvas", "name_components_with_arrows"];
3
+ export declare const CANVAS_TOOL_NAMES: readonly ["get_canvas", "draw_ui_component", "add_shape", "add_text", "add_asset", "add_arrow", "move_elements", "delete_elements", "clear_canvas", "name_components_with_arrows"];
4
4
  export type CanvasToolName = (typeof CANVAS_TOOL_NAMES)[number];
5
5
  export interface CanvasBounds {
6
6
  width: number;
@@ -34,8 +34,33 @@ export interface ToolFailure {
34
34
  code: 'invalid_args' | 'not_found' | 'bounds' | 'internal';
35
35
  }
36
36
  export type ToolResult = ToolSuccess | ToolFailure;
37
+ /**
38
+ * A picture the sketch assistant may put on the board by its id: an icon of the brand kit, a file of the person's library. The page
39
+ * builds the list (it knows the brand kit and the library) and the board draws what the assistant names; the assistant is told the
40
+ * ids and names (never the pictures themselves) in its request.
41
+ */
42
+ export interface CanvasToolAsset {
43
+ /** What the assistant calls it in `add_asset { assetId }`. Short and unique in the list. */
44
+ id: string;
45
+ /** A readable name (`logo.svg`, "Cart icon"). The picture keeps it as its file name, so the scene summary shows it. */
46
+ name: string;
47
+ /** Where it comes from: the brand kit's icons, or the person's file library (the File Browser). */
48
+ source: 'brand-icon' | 'library';
49
+ /** What the board draws: an http(s) address, a path of the page, or a `data:image/…` address (an SVG made from markup). */
50
+ src: string;
51
+ /** For a library file: the library's id and address, which the picture keeps (so it is never put in the library again). */
52
+ libraryFileId?: string | null;
53
+ libraryFileUrl?: string | null;
54
+ /** The size of the picture itself, when known, to keep its proportions. */
55
+ width?: number;
56
+ height?: number;
57
+ }
37
58
  export interface CanvasToolHost {
38
59
  readonly bounds: CanvasBounds;
60
+ /** The pictures `add_asset` may place. Missing or empty: the tool says there are none. */
61
+ readonly assets?: readonly CanvasToolAsset[];
62
+ /** The font families `add_text` may use (the built-in ones and the brand kit's). Missing or empty: any well-formed family name. */
63
+ readonly fontFamilies?: readonly string[];
39
64
  getScene(): Scene;
40
65
  /** Apply a new scene as one undo step. */
41
66
  commitScene(next: Scene): void;
@@ -1,8 +1,9 @@
1
- export const CANVAS_TOOL_NAMES = [
1
+ export var CANVAS_TOOL_NAMES = [
2
2
  'get_canvas',
3
3
  'draw_ui_component',
4
4
  'add_shape',
5
5
  'add_text',
6
+ 'add_asset',
6
7
  'add_arrow',
7
8
  'move_elements',
8
9
  'delete_elements',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/canvas",
3
- "version": "0.5.44",
3
+ "version": "0.5.45",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",