@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
@@ -3,36 +3,33 @@ 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,
12
+ bounds,
14
13
  assets: options.assets,
15
14
  fontFamilies: options.fontFamilies,
16
- getScene: function () {
15
+ getScene() {
17
16
  return engine.state.scene;
18
17
  },
19
- createId: function (prefix) {
20
- return createObjectId(prefix !== null && prefix !== void 0 ? prefix : 'sketch');
18
+ createId(prefix) {
19
+ return createObjectId(prefix ?? 'sketch');
21
20
  },
22
- commitScene: function (next) {
23
- var _a;
24
- engine.applyScene(next, (_a = options.commitMode) !== null && _a !== void 0 ? _a : 'push');
21
+ commitScene(next) {
22
+ engine.applyScene(next, options.commitMode ?? 'push');
25
23
  }
26
24
  };
27
25
  }
28
26
  /** Run several tool calls as a single undo step on the engine. */
29
27
  export function runCanvasToolBatch(host, run, engine) {
30
28
  // When backed by engine, defer commit until batch ends.
31
- var engineHost = host;
32
29
  if (engine) {
33
- var snapshot = engine.state.scene;
30
+ const snapshot = engine.state.scene;
34
31
  run();
35
- var finalScene = host.getScene();
32
+ const finalScene = host.getScene();
36
33
  if (finalScene !== snapshot) {
37
34
  engine.applyScene(finalScene, 'push');
38
35
  }
@@ -1,29 +1,19 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
1
  import { boundsOfObjects, findObject, indexScene, shapeBounds } from '../engine/core/scene.js';
11
2
  import { isBoxedObject } from '../engine/core/types.js';
12
- var DEFAULT_BOUNDS = { width: 1200, height: 800 };
13
- export var SCENE_SUMMARY_MAX_ELEMENTS = 48;
3
+ const DEFAULT_BOUNDS = { width: 1200, height: 800 };
4
+ export const SCENE_SUMMARY_MAX_ELEMENTS = 48;
14
5
  /** The longest label a summary carries (the assistant request schema accepts 256, and the model needs far fewer). */
15
- var SCENE_LABEL_MAX_CHARS = 80;
6
+ const SCENE_LABEL_MAX_CHARS = 80;
16
7
  /** A label cut to the length a summary carries, so a long text never makes a request the gateway refuses. */
17
8
  function shortenLabel(text) {
18
- return text.length > SCENE_LABEL_MAX_CHARS ? "".concat(text.slice(0, SCENE_LABEL_MAX_CHARS - 3), "...") : text;
9
+ return text.length > SCENE_LABEL_MAX_CHARS ? `${text.slice(0, SCENE_LABEL_MAX_CHARS - 3)}...` : text;
19
10
  }
20
11
  export function labelOfObject(object) {
21
- var _a, _b;
22
12
  if (object.type === 'text') {
23
13
  return shortenLabel(object.text.trim());
24
14
  }
25
15
  if (object.type === 'widget')
26
- return (_a = object.widgetName) !== null && _a !== void 0 ? _a : 'widget';
16
+ return object.widgetName ?? 'widget';
27
17
  if (object.type === 'group')
28
18
  return 'group';
29
19
  if (object.type === 'path' && object.arrow)
@@ -35,12 +25,11 @@ export function labelOfObject(object) {
35
25
  if (object.type === 'ellipse')
36
26
  return 'ellipse';
37
27
  if (object.type === 'image')
38
- return (_b = object.fileName) !== null && _b !== void 0 ? _b : 'image';
28
+ return object.fileName ?? 'image';
39
29
  return object.type;
40
30
  }
41
31
  function groupLabelFromMembers(groupId, scene) {
42
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
43
- var object = scene_1[_i];
32
+ for (const object of scene) {
44
33
  if (object.parentId === groupId && object.type === 'text') {
45
34
  // Cut like the label of a loose text: a component's first text can be a whole paragraph.
46
35
  return shortenLabel(object.text.trim()) || 'group';
@@ -67,31 +56,30 @@ function elementPriority(element) {
67
56
  return 3;
68
57
  }
69
58
  function compareElements(a, b) {
70
- var pa = elementPriority(a);
71
- var pb = elementPriority(b);
59
+ const pa = elementPriority(a);
60
+ const pb = elementPriority(b);
72
61
  if (pa !== pb)
73
62
  return pa - pb;
74
- var areaA = a.bbox.width * a.bbox.height;
75
- var areaB = b.bbox.width * b.bbox.height;
63
+ const areaA = a.bbox.width * a.bbox.height;
64
+ const areaB = b.bbox.width * b.bbox.height;
76
65
  if (areaA !== areaB)
77
66
  return areaB - areaA;
78
67
  return a.zIndex - b.zIndex;
79
68
  }
80
- export function summarizeScene(scene, bounds) {
81
- if (bounds === void 0) { bounds = DEFAULT_BOUNDS; }
82
- var elements = [];
83
- scene.forEach(function (object, zIndex) {
69
+ export function summarizeScene(scene, bounds = DEFAULT_BOUNDS) {
70
+ const elements = [];
71
+ scene.forEach((object, zIndex) => {
84
72
  if (object.type === 'group') {
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)
73
+ const memberIds = scene.filter((member) => member.parentId === object.id).map((member) => member.id);
74
+ const bbox = boundsOfObjects(scene, memberIds);
75
+ if (!bbox)
88
76
  return;
89
77
  elements.push({
90
78
  id: object.id,
91
79
  kind: 'group',
92
80
  label: groupLabelFromMembers(object.id, scene),
93
- bbox: bbox_1,
94
- zIndex: zIndex,
81
+ bbox,
82
+ zIndex,
95
83
  parentId: object.parentId
96
84
  });
97
85
  return;
@@ -100,69 +88,67 @@ export function summarizeScene(scene, bounds) {
100
88
  return;
101
89
  if (!isBoxedObject(object))
102
90
  return;
103
- var bbox = shapeBounds(object);
91
+ const bbox = shapeBounds(object);
104
92
  elements.push({
105
93
  id: object.id,
106
94
  kind: kindOfObject(object),
107
95
  label: labelOfObject(object),
108
- bbox: bbox,
109
- zIndex: zIndex,
96
+ bbox,
97
+ zIndex,
110
98
  parentId: object.parentId
111
99
  });
112
100
  });
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;
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;
117
105
  return {
118
- bounds: bounds,
106
+ bounds,
119
107
  elements: limited,
120
- totalCount: totalCount,
121
- truncated: truncated,
122
- truncationNote: truncated ? "Showing ".concat(SCENE_SUMMARY_MAX_ELEMENTS, " of ").concat(totalCount, " top-level elements.") : undefined
108
+ totalCount,
109
+ truncated,
110
+ truncationNote: truncated ? `Showing ${SCENE_SUMMARY_MAX_ELEMENTS} of ${totalCount} top-level elements.` : undefined
123
111
  };
124
112
  }
125
113
  export function findByLabel(scene, needle) {
126
- var lower = needle.toLowerCase();
127
- for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
128
- var object = scene_2[_i];
114
+ const lower = needle.toLowerCase();
115
+ for (const object of scene) {
129
116
  if (object.type === 'group') {
130
- var label = groupLabelFromMembers(object.id, scene).toLowerCase();
117
+ const label = groupLabelFromMembers(object.id, scene).toLowerCase();
131
118
  if (label.includes(lower))
132
119
  return object.id;
133
120
  }
134
121
  if (object.type === 'text') {
135
- var label = object.text.toLowerCase();
122
+ const label = object.text.toLowerCase();
136
123
  if (label.includes(lower))
137
124
  return object.id;
138
125
  }
139
126
  }
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();
127
+ for (const object of scene) {
128
+ const label = labelOfObject(object).toLowerCase();
143
129
  if (label.includes(lower))
144
130
  return object.id;
145
131
  }
146
132
  return null;
147
133
  }
148
134
  export function centerOf(id, scene) {
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)
135
+ const object = findObject(scene, id);
136
+ if (object?.type === 'group') {
137
+ const bbox = boundsOfObjects(scene, [id]);
138
+ if (!bbox)
153
139
  return null;
154
- return { x: bbox_2.x + bbox_2.width / 2, y: bbox_2.y + bbox_2.height / 2 };
140
+ return { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
155
141
  }
156
142
  if (!object || !isBoxedObject(object))
157
143
  return null;
158
- var bbox = shapeBounds(object);
144
+ const bbox = shapeBounds(object);
159
145
  return { x: bbox.x + bbox.width / 2, y: bbox.y + bbox.height / 2 };
160
146
  }
161
147
  export function sceneIndexMap(scene) {
162
148
  return indexScene(scene);
163
149
  }
164
150
  export function bboxIntersects(a, b) {
165
- var pad = 2;
151
+ const pad = 2;
166
152
  return (a.x + a.width > b.x + pad &&
167
153
  b.x + b.width > a.x + pad &&
168
154
  a.y + a.height > b.y + pad &&
@@ -4,26 +4,18 @@
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() {
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');
7
+ function standalone(...alternatives) {
8
+ return new RegExp(`(?:^|[^\\p{L}\\p{N}_])(?:${alternatives.join('|')})(?![\\p{L}\\p{N}_])`, 'iu');
13
9
  }
14
10
  /** A pattern for a phrase of a writing system that puts no spaces between words (Chinese, Japanese): found anywhere. */
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');
11
+ function anywhere(...alternatives) {
12
+ return new RegExp(`(?:${alternatives.join('|')})`, 'iu');
21
13
  }
22
14
  /**
23
15
  * Words that say the author wants something drawn on the canvas. Only words that mean drawing: a request to create
24
16
  * something ("make a quiz", "I need a video player") is a widget, and goes to the code generator.
25
17
  */
26
- var SKETCH_PATTERNS = [
18
+ const SKETCH_PATTERNS = [
27
19
  /\bdraw\b/i,
28
20
  /\bsketch\b/i,
29
21
  /\bwireframe\b/i,
@@ -58,7 +50,7 @@ var SKETCH_PATTERNS = [
58
50
  * Words that say the author wants code, a build or a publish. They win over a drawing word: "draw it, then publish it"
59
51
  * is a request for the widget.
60
52
  */
61
- var CODEGEN_PATTERNS = [
53
+ const CODEGEN_PATTERNS = [
62
54
  /\bbuild\b/i,
63
55
  /\bgenerate\b/i,
64
56
  /\bcode\b/i,
@@ -84,7 +76,7 @@ var CODEGEN_PATTERNS = [
84
76
  standalone('zbuduj', 'wygeneruj', 'kod', 'opublikuj', 'zaimplementuj'),
85
77
  standalone('bouw', 'genereer', 'publiceer', 'implementeer')
86
78
  ];
87
- export var SKETCH_INTENT_COUNTER_EXAMPLES = [
79
+ export const SKETCH_INTENT_COUNTER_EXAMPLES = [
88
80
  'build me a countdown widget',
89
81
  'make the button blue in the widget',
90
82
  'generate the react code for this',
@@ -96,7 +88,7 @@ export var SKETCH_INTENT_COUNTER_EXAMPLES = [
96
88
  * Free-text requests that draw, in the languages the router knows. Every one must route to the sketch assistant
97
89
  * (the creator's tests and the gateway's mirror hold the same list).
98
90
  */
99
- export var SKETCH_FREE_TEXT_EXAMPLES = [
91
+ export const SKETCH_FREE_TEXT_EXAMPLES = [
100
92
  'Sketch a pricing page with three plans and a call to action under each',
101
93
  'wireframe a dashboard with a sidebar and four stat cards',
102
94
  'can you draw three circles in a row and connect them with arrows',
@@ -128,7 +120,7 @@ export var SKETCH_FREE_TEXT_EXAMPLES = [
128
120
  * Requests that are not for a drawing, with the verdict each gets. Creating something ("make", "create", "I need") is a
129
121
  * widget, so most of them are `unknown` and go to the code generator by default; the ones that name code are `generate`.
130
122
  */
131
- export var SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
123
+ export const SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
132
124
  ['a video player with a playlist', 'unknown'],
133
125
  ['create a countdown timer with a start button', 'unknown'],
134
126
  ['I want a quiz about world capitals', 'unknown'],
@@ -149,16 +141,16 @@ export var SKETCH_FREE_TEXT_COUNTER_EXAMPLES = [
149
141
  * Lightweight sketch-vs-codegen classifier for the creator chat (gateway mirrors this in tests).
150
142
  */
151
143
  export function classifySketchIntent(message) {
152
- var text = message.trim();
144
+ const text = message.trim();
153
145
  if (!text)
154
146
  return 'unknown';
155
- if (CODEGEN_PATTERNS.some(function (pattern) { return pattern.test(text); }))
147
+ if (CODEGEN_PATTERNS.some((pattern) => pattern.test(text)))
156
148
  return 'generate';
157
- if (SKETCH_PATTERNS.some(function (pattern) { return pattern.test(text); }))
149
+ if (SKETCH_PATTERNS.some((pattern) => pattern.test(text)))
158
150
  return 'sketch';
159
151
  return 'unknown';
160
152
  }
161
- export var SKETCH_ACCEPTANCE_PROMPTS = [
153
+ export const SKETCH_ACCEPTANCE_PROMPTS = [
162
154
  'draw a video player for me',
163
155
  'move the navigation outside the video thumbnail',
164
156
  'delete all sketches',
@@ -7,27 +7,25 @@
7
7
  */
8
8
  import { isFontFamilyName } from '../engine/codec/canvasDocument.js';
9
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;
10
+ const HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
11
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; }
12
+ export function readColorArgument(value, name, allowTransparent = false) {
14
13
  if (value === undefined || value === null || value === '')
15
14
  return { ok: true, value: undefined };
16
- var text = typeof value === 'string' ? value.trim() : '';
15
+ const text = typeof value === 'string' ? value.trim() : '';
17
16
  if (HEX_COLOR_PATTERN.test(text))
18
17
  return { ok: true, value: text.toLowerCase() };
19
18
  if (allowTransparent && text.toLowerCase() === 'transparent')
20
19
  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), ".") };
20
+ return { ok: false, error: `${name} must be a hex colour such as #1a2b3c${allowTransparent ? ' or "transparent"' : ''}, not ${JSON.stringify(value)}.` };
22
21
  }
23
22
  /** The first family of a CSS font list, without quotes, lower-cased: how two spellings of one family are compared. */
24
23
  function familyKey(family) {
25
- var _a;
26
- var first = (_a = family.split(',')[0]) !== null && _a !== void 0 ? _a : '';
24
+ const first = family.split(',')[0] ?? '';
27
25
  return first.trim().replace(/^["']|["']$/g, '').toLowerCase();
28
26
  }
29
27
  /** How many families a refusal lists (the model needs a few to choose from, not a hundred). */
30
- var FONT_LIST_IN_REFUSAL = 24;
28
+ const FONT_LIST_IN_REFUSAL = 24;
31
29
  /**
32
30
  * 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
31
  * 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
@@ -36,39 +34,39 @@ var FONT_LIST_IN_REFUSAL = 24;
36
34
  export function readFontFamilyArgument(value, known) {
37
35
  if (value === undefined || value === null || value === '')
38
36
  return { ok: true, value: undefined };
39
- var text = typeof value === 'string' ? value.trim() : '';
37
+ const text = typeof value === 'string' ? value.trim() : '';
40
38
  if (text === '' || !isFontFamilyName(text))
41
- return { ok: false, error: "fontFamily must be a font family name, not ".concat(JSON.stringify(value), ".") };
39
+ return { ok: false, error: `fontFamily must be a font family name, not ${JSON.stringify(value)}.` };
42
40
  if (!known || known.length === 0)
43
41
  return { ok: true, value: text };
44
- var wanted = familyKey(text);
45
- var match = known.find(function (family) { return familyKey(family) === wanted; });
42
+ const wanted = familyKey(text);
43
+ const match = known.find((family) => familyKey(family) === wanted);
46
44
  if (match)
47
45
  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 ? ', …' : '', ".") };
46
+ const listed = known.slice(0, FONT_LIST_IN_REFUSAL).join(', ');
47
+ return { ok: false, error: `The font "${text}" is not on this canvas. Use one of: ${listed}${known.length > FONT_LIST_IN_REFUSAL ? ', …' : ''}.` };
50
48
  }
51
49
  /** A number inside a range, or absent. Anything else is refused. */
52
50
  export function readNumberArgument(value, name, minimum, maximum) {
53
51
  if (value === undefined || value === null || value === '')
54
52
  return { ok: true, value: undefined };
55
- var number = typeof value === 'number' ? value : Number(value);
53
+ const number = typeof value === 'number' ? value : Number(value);
56
54
  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), ".") };
55
+ return { ok: false, error: `${name} must be a number from ${minimum} to ${maximum}, not ${JSON.stringify(value)}.` };
58
56
  }
59
57
  return { ok: true, value: number };
60
58
  }
61
59
  /** 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;
60
+ export const ASSET_DEFAULT_SIDE = 96;
63
61
  /**
64
62
  * 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
63
  * 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
64
  */
67
65
  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;
66
+ const known = typeof asset.width === 'number' && typeof asset.height === 'number' && asset.width > 0 && asset.height > 0;
67
+ const aspect = known ? asset.width / asset.height : 1;
68
+ let finalWidth;
69
+ let finalHeight;
72
70
  if (width !== undefined && height !== undefined) {
73
71
  finalWidth = width;
74
72
  finalHeight = height;
@@ -1,4 +1,4 @@
1
- export var CANVAS_TOOL_NAMES = [
1
+ export const CANVAS_TOOL_NAMES = [
2
2
  'get_canvas',
3
3
  'draw_ui_component',
4
4
  'add_shape',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/canvas",
3
- "version": "0.5.45",
3
+ "version": "0.5.47",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -56,10 +56,10 @@
56
56
  "dev": "concurrently -n app,pkg -c blue,green \"npm run dev-sv -- --port 5181\" \"npm run package:watch\"",
57
57
  "dev-sv": "NODE_ENV=development vite dev",
58
58
  "build": "vite build && npm run package",
59
- "package": "NODE_ENV=production svelte-package",
59
+ "package": "svelte-kit sync && NODE_ENV=production svelte-package",
60
60
  "publish-to-npm": "node ../dev-tools/bin/publish-package.mjs",
61
61
  "package:watch": "NODE_ENV=development svelte-package --watch",
62
- "test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\" \"tests/engine/*.test.mjs\" \"tests/host/*.test.mjs\" \"tests/view/*.test.mjs\" \"tests/ui/*.test.mjs\" \"tests/tools/*.test.mjs\"",
62
+ "test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\" \"tests/engine/*.test.mjs\" \"tests/host/*.test.mjs\" \"tests/settings/*.test.mjs\" \"tests/view/*.test.mjs\" \"tests/ui/*.test.mjs\" \"tests/tools/*.test.mjs\"",
63
63
  "preview": "vite preview",
64
64
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
65
65
  "check:peers": "check-design-system-peers ..",
@@ -99,7 +99,7 @@
99
99
  "@tiptap/extension-underline": "^2.9.1",
100
100
  "@tiptap/pm": "^2.9.1",
101
101
  "@tiptap/starter-kit": "^2.9.1",
102
- "@widgetic/design-system": "^0.5.36",
102
+ "@widgetic/design-system": "^0.5.42",
103
103
  "@widgetic/dev-tools": "^0.3.0",
104
104
  "eslint": "^9.18.0",
105
105
  "eslint-config-prettier": "^10.0.1",
@@ -143,7 +143,7 @@
143
143
  "url": "https://gitlab.com/widgeticai/Frontend/canvas.git"
144
144
  },
145
145
  "peerDependencies": {
146
- "@widgetic/design-system": ">=0.5.36",
146
+ "@widgetic/design-system": ">=0.5.41",
147
147
  "svelte": "^5.0.0"
148
148
  }
149
149
  }