@widgetic/canvas 0.5.41 → 0.5.42

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 (85) hide show
  1. package/dist/canvas/autosaveScheduler.js +37 -89
  2. package/dist/canvas/boardFrame.js +1 -1
  3. package/dist/canvas/boardSurface.js +1 -1
  4. package/dist/canvas/canvasLogger.js +7 -19
  5. package/dist/canvas/chromeLayout.js +17 -18
  6. package/dist/canvas/eventScope.js +10 -14
  7. package/dist/canvas/host/CanvasHost.js +1286 -1536
  8. package/dist/canvas/host/CanvasHostApi.js +4 -19
  9. package/dist/canvas/host/browserServices.js +65 -116
  10. package/dist/canvas/host/conversion.js +82 -170
  11. package/dist/canvas/host/hostObject.js +7 -7
  12. package/dist/canvas/host/pageEvents.js +4 -4
  13. package/dist/canvas/host/screenRects.js +28 -31
  14. package/dist/canvas/host/strokeSnap.js +88 -143
  15. package/dist/canvas/openMarks.js +2 -2
  16. package/dist/canvas/outsideClickDeselect.js +6 -7
  17. package/dist/canvas/panZoomPosition.js +2 -2
  18. package/dist/canvas/preferredTextFont.js +13 -25
  19. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  20. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  21. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  22. package/dist/canvas/toolbarPosition.js +2 -2
  23. package/dist/canvas/ui/colorModel.js +21 -32
  24. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  25. package/dist/canvas/ui/floatingCard.js +18 -18
  26. package/dist/canvas/ui/floatingLayer.js +5 -6
  27. package/dist/canvas/ui/keyHints.js +9 -11
  28. package/dist/canvas/ui/popoverSide.js +2 -3
  29. package/dist/canvas/ui/selectionTraits.js +34 -40
  30. package/dist/canvas/view/erasingMarks.js +7 -7
  31. package/dist/canvas/view/geometry.js +71 -90
  32. package/dist/components/preferenceStorage.js +2 -2
  33. package/dist/engine/EngineCore.js +696 -795
  34. package/dist/engine/codec/canvasDocument.js +183 -147
  35. package/dist/engine/codec/hostReadableKeys.js +1 -1
  36. package/dist/engine/core/arrange.js +26 -38
  37. package/dist/engine/core/arrow.js +76 -89
  38. package/dist/engine/core/arrowBinding.js +98 -116
  39. package/dist/engine/core/arrowBindingRecords.js +23 -38
  40. package/dist/engine/core/brush.js +67 -94
  41. package/dist/engine/core/defaults.js +90 -51
  42. package/dist/engine/core/freehand.js +147 -163
  43. package/dist/engine/core/geometry.js +47 -54
  44. package/dist/engine/core/history.js +33 -50
  45. package/dist/engine/core/hitTest.js +68 -81
  46. package/dist/engine/core/matrix.js +18 -20
  47. package/dist/engine/core/pathData.js +183 -210
  48. package/dist/engine/core/rotationReset.js +5 -6
  49. package/dist/engine/core/scene.js +129 -187
  50. package/dist/engine/core/scribble.js +59 -84
  51. package/dist/engine/core/shapePaths.js +12 -15
  52. package/dist/engine/core/shapeTools.js +72 -63
  53. package/dist/engine/core/snapping.js +65 -117
  54. package/dist/engine/core/style.js +31 -64
  55. package/dist/engine/core/transform.js +83 -94
  56. package/dist/engine/core/types.js +4 -4
  57. package/dist/engine/core/viewport.js +23 -36
  58. package/dist/engine/input/PointerController.js +467 -474
  59. package/dist/engine/input/arrowHandles.js +12 -12
  60. package/dist/engine/input/gestures.js +262 -308
  61. package/dist/engine/input/hoverCursor.js +1 -1
  62. package/dist/engine/input/keyboard.js +27 -30
  63. package/dist/engine/input/selectionHandles.js +45 -50
  64. package/dist/engine/input/types.js +1 -1
  65. package/dist/engine/render/rasterize.js +86 -158
  66. package/dist/engine/state.js +4 -15
  67. package/dist/engine/text/layoutText.js +43 -62
  68. package/dist/engine/text/textMetrics.js +8 -10
  69. package/dist/engine/widgets.js +101 -137
  70. package/dist/fonts/interFont.js +17 -68
  71. package/dist/fonts/workspaceFonts.js +32 -90
  72. package/dist/i18n/labels.js +4 -4
  73. package/dist/i18n/language.js +4 -4
  74. package/dist/i18n/messages.js +1 -1
  75. package/dist/i18n/shortcuts.js +14 -14
  76. package/dist/settings/workspaceToolSettings.js +32 -48
  77. package/dist/tools/components/catalog.js +64 -74
  78. package/dist/tools/components/grouping.js +6 -28
  79. package/dist/tools/definitions.js +5 -5
  80. package/dist/tools/executors.js +105 -141
  81. package/dist/tools/hostAdapter.js +11 -13
  82. package/dist/tools/sceneSummary.js +43 -57
  83. package/dist/tools/sketchIntent.js +13 -21
  84. package/dist/tools/types.js +1 -1
  85. package/package.json +1 -1
@@ -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',
@@ -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.41",
3
+ "version": "0.5.42",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",