@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
@@ -9,45 +9,93 @@
9
9
  * Nothing here touches `document` or `window`: the browser's canvas, image loader and `Path2D` are handed in as
10
10
  * services, so the drawing order and the geometry are tested in Node with a recording context.
11
11
  */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
12
57
  import { boxToWorldMatrix } from '../core/matrix.js';
13
58
  import { strokeDashArray } from '../core/defaults.js';
14
59
  import { shapeVisualBounds } from '../core/scene.js';
15
60
  import { unionRects } from '../core/geometry.js';
16
61
  import { fontShorthand, layoutTextObject, lineBoxHeight, textDirection } from '../text/layoutText.js';
17
- export const DEFAULT_RASTER_SCALE = 2;
18
- export const DEFAULT_RASTER_MAX_PIXELS = 16_000_000;
19
- export const DEFAULT_RASTER_MAX_SIDE = 8192;
62
+ export var DEFAULT_RASTER_SCALE = 2;
63
+ export var DEFAULT_RASTER_MAX_PIXELS = 16000000;
64
+ export var DEFAULT_RASTER_MAX_SIDE = 8192;
20
65
  /** The addresses of the pictures a set of shapes needs: images and the screenshots of widget cards. */
21
66
  export function imageSourcesOf(shapes) {
22
- const sources = new Set();
23
- for (const shape of shapes) {
67
+ var sources = new Set();
68
+ for (var _i = 0, shapes_1 = shapes; _i < shapes_1.length; _i++) {
69
+ var shape = shapes_1[_i];
24
70
  if (shape.type === 'image' && shape.src)
25
71
  sources.add(shape.src);
26
72
  if (shape.type === 'widget' && shape.thumbnail)
27
73
  sources.add(shape.thumbnail);
28
74
  }
29
- return [...sources];
75
+ return __spreadArray([], sources, true);
30
76
  }
31
77
  /** The rectangle every shape fits in, strokes included. Null when there is no shape or it has no size. */
32
78
  export function rasterBoundsOf(shapes) {
33
- const bounds = unionRects(shapes.map(shapeVisualBounds));
79
+ var bounds = unionRects(shapes.map(shapeVisualBounds));
34
80
  if (!bounds || !(bounds.width > 0) || !(bounds.height > 0))
35
81
  return null;
36
82
  return bounds;
37
83
  }
38
84
  /** The scale a picture of these bounds is drawn at: the one asked for, lowered until it fits the limits. */
39
- export function rasterScaleFor(bounds, options = {}) {
40
- const requested = options.scale ?? DEFAULT_RASTER_SCALE;
41
- const maxPixels = options.maxPixels ?? DEFAULT_RASTER_MAX_PIXELS;
42
- const maxSide = options.maxSide ?? DEFAULT_RASTER_MAX_SIDE;
43
- const area = Math.max(1, bounds.width * bounds.height);
44
- const longest = Math.max(1, bounds.width, bounds.height);
45
- const byArea = Math.sqrt(maxPixels / area);
46
- const bySide = maxSide / longest;
85
+ export function rasterScaleFor(bounds, options) {
86
+ var _a, _b, _c;
87
+ if (options === void 0) { options = {}; }
88
+ var requested = (_a = options.scale) !== null && _a !== void 0 ? _a : DEFAULT_RASTER_SCALE;
89
+ var maxPixels = (_b = options.maxPixels) !== null && _b !== void 0 ? _b : DEFAULT_RASTER_MAX_PIXELS;
90
+ var maxSide = (_c = options.maxSide) !== null && _c !== void 0 ? _c : DEFAULT_RASTER_MAX_SIDE;
91
+ var area = Math.max(1, bounds.width * bounds.height);
92
+ var longest = Math.max(1, bounds.width, bounds.height);
93
+ var byArea = Math.sqrt(maxPixels / area);
94
+ var bySide = maxSide / longest;
47
95
  return Math.max(0.01, Math.min(requested, byArea, bySide));
48
96
  }
49
97
  function roundedRectPath(context, width, height, radius) {
50
- const clamped = Math.max(0, Math.min(radius, width / 2, height / 2));
98
+ var clamped = Math.max(0, Math.min(radius, width / 2, height / 2));
51
99
  context.beginPath();
52
100
  if (clamped <= 0) {
53
101
  context.rect(0, 0, width, height);
@@ -73,8 +121,8 @@ function applyStroke(context, shape) {
73
121
  return false;
74
122
  context.strokeStyle = shape.stroke;
75
123
  context.lineWidth = shape.strokeWidth;
76
- const dash = strokeDashArray(shape.strokeStyle, shape.strokeWidth);
77
- context.setLineDash(dash ?? []);
124
+ var dash = strokeDashArray(shape.strokeStyle, shape.strokeWidth);
125
+ context.setLineDash(dash !== null && dash !== void 0 ? dash : []);
78
126
  // A dotted line is zero-length dashes; only a round cap turns each into a dot.
79
127
  if (shape.strokeStyle === 'dotted')
80
128
  context.lineCap = 'round';
@@ -82,7 +130,7 @@ function applyStroke(context, shape) {
82
130
  }
83
131
  function paintFillAndStroke(context, shape, fillPath) {
84
132
  if (shape.fill !== 'transparent' && shape.fillOpacity > 0) {
85
- const before = context.globalAlpha;
133
+ var before = context.globalAlpha;
86
134
  context.globalAlpha = before * Math.max(0, Math.min(1, shape.fillOpacity));
87
135
  context.fillStyle = shape.fill;
88
136
  if (fillPath)
@@ -99,11 +147,11 @@ function paintFillAndStroke(context, shape, fillPath) {
99
147
  }
100
148
  }
101
149
  function fontMetricsOf(context, size) {
102
- const measured = context.measureText('Hg');
103
- const ascent = measured.fontBoundingBoxAscent;
104
- const descent = measured.fontBoundingBoxDescent;
150
+ var measured = context.measureText('Hg');
151
+ var ascent = measured.fontBoundingBoxAscent;
152
+ var descent = measured.fontBoundingBoxDescent;
105
153
  if (typeof ascent === 'number' && typeof descent === 'number' && ascent + descent > 0)
106
- return { ascent, descent };
154
+ return { ascent: ascent, descent: descent };
107
155
  return { ascent: size * 0.8, descent: size * 0.2 };
108
156
  }
109
157
  function paintText(context, shape, deps) {
@@ -113,27 +161,27 @@ function paintText(context, shape, deps) {
113
161
  }
114
162
  if (shape.text === '')
115
163
  return;
116
- const layout = layoutTextObject(shape, deps.measureText);
164
+ var layout = layoutTextObject(shape, deps.measureText);
117
165
  context.font = fontShorthand(shape);
118
166
  context.fillStyle = shape.color;
119
167
  context.textBaseline = 'alphabetic';
120
168
  context.textAlign = 'left';
121
169
  // The text reads the way the board shows it: by the direction of its first letter (a line is placed from its left edge).
122
170
  context.direction = textDirection(shape.text);
123
- const lineHeight = lineBoxHeight(shape);
124
- const { ascent, descent } = fontMetricsOf(context, shape.fontSize);
125
- const innerWidth = shape.width - shape.padding * 2;
126
- for (let index = 0; index < layout.lines.length; index += 1) {
127
- const line = layout.lines[index];
171
+ var lineHeight = lineBoxHeight(shape);
172
+ var _a = fontMetricsOf(context, shape.fontSize), ascent = _a.ascent, descent = _a.descent;
173
+ var innerWidth = shape.width - shape.padding * 2;
174
+ for (var index = 0; index < layout.lines.length; index += 1) {
175
+ var line = layout.lines[index];
128
176
  if (line === '')
129
177
  continue;
130
- const lineWidth = deps.measureText(line, fontShorthand(shape));
131
- let left = shape.padding;
178
+ var lineWidth = deps.measureText(line, fontShorthand(shape));
179
+ var left = shape.padding;
132
180
  if (shape.align === 'center')
133
181
  left = shape.padding + (innerWidth - lineWidth) / 2;
134
182
  else if (shape.align === 'right')
135
183
  left = shape.padding + (innerWidth - lineWidth);
136
- const baseline = shape.padding + index * lineHeight + (lineHeight - (ascent + descent)) / 2 + ascent;
184
+ var baseline = shape.padding + index * lineHeight + (lineHeight - (ascent + descent)) / 2 + ascent;
137
185
  context.fillText(line, left, baseline);
138
186
  if (shape.underline) {
139
187
  context.fillRect(left, baseline + Math.max(1, shape.fontSize * 0.08), lineWidth, Math.max(1, shape.fontSize / 15));
@@ -141,7 +189,7 @@ function paintText(context, shape, deps) {
141
189
  }
142
190
  }
143
191
  function paintWidget(context, shape, deps) {
144
- const picture = deps.imageFor(shape.thumbnail);
192
+ var picture = deps.imageFor(shape.thumbnail);
145
193
  roundedRectPath(context, shape.width, shape.height, 8);
146
194
  context.fillStyle = '#ffffff';
147
195
  context.fill();
@@ -157,14 +205,14 @@ function paintWidget(context, shape, deps) {
157
205
  context.setLineDash([6, 4]);
158
206
  context.stroke();
159
207
  context.setLineDash([]);
160
- const name = shape.widgetName || deps.widgetFallbackName || '';
208
+ var name = shape.widgetName || deps.widgetFallbackName || '';
161
209
  if (name === '')
162
210
  return;
163
211
  context.fillStyle = '#1e293b';
164
212
  context.textAlign = 'center';
165
213
  context.textBaseline = 'middle';
166
- const size = Math.max(11, Math.min(18, shape.width * 0.06));
167
- context.font = `600 ${size}px system-ui, sans-serif`;
214
+ var size = Math.max(11, Math.min(18, shape.width * 0.06));
215
+ context.font = "600 ".concat(size, "px system-ui, sans-serif");
168
216
  context.fillText(name, shape.width / 2, shape.height / 2);
169
217
  }
170
218
  /**
@@ -176,7 +224,7 @@ export function paintShape(context, shape, deps) {
176
224
  return;
177
225
  context.save();
178
226
  try {
179
- const matrix = boxToWorldMatrix(shape);
227
+ var matrix = boxToWorldMatrix(shape);
180
228
  context.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
181
229
  context.globalAlpha = context.globalAlpha * Math.max(0, Math.min(1, shape.opacity));
182
230
  switch (shape.type) {
@@ -202,7 +250,7 @@ export function paintShape(context, shape, deps) {
202
250
  break;
203
251
  }
204
252
  case 'image': {
205
- const picture = deps.imageFor(shape.src);
253
+ var picture = deps.imageFor(shape.src);
206
254
  if (picture)
207
255
  context.drawImage(picture, 0, 0, shape.width, shape.height);
208
256
  break;
@@ -222,52 +270,76 @@ export function paintShape(context, shape, deps) {
222
270
  * string when there is nothing to draw, the canvas cannot be made, or the browser refuses to export it (a picture
223
271
  * from another site without CORS taints the canvas).
224
272
  */
225
- export async function renderShapesToDataUrl(shapes, services, options = {}) {
226
- const bounds = rasterBoundsOf(shapes);
227
- if (!bounds)
228
- return '';
229
- const padding = Math.max(0, options.padding ?? 0);
230
- // Whole world units on every side, so the crop never cuts the last pixel of a stroke.
231
- const left = Math.floor(bounds.x - padding);
232
- const top = Math.floor(bounds.y - padding);
233
- const right = Math.ceil(bounds.x + bounds.width + padding);
234
- const bottom = Math.ceil(bounds.y + bounds.height + padding);
235
- const area = { x: left, y: top, width: Math.max(1, right - left), height: Math.max(1, bottom - top) };
236
- const scale = rasterScaleFor(area, options);
237
- const pixelWidth = Math.max(1, Math.ceil(area.width * scale));
238
- const pixelHeight = Math.max(1, Math.ceil(area.height * scale));
239
- const canvas = services.createCanvas(pixelWidth, pixelHeight);
240
- const context = canvas?.getContext('2d') ?? null;
241
- if (!canvas || !context)
242
- return '';
243
- const loaded = new Map();
244
- await Promise.all(imageSourcesOf(shapes).map(async (source) => {
245
- try {
246
- const picture = await services.loadImage(source);
247
- if (picture)
248
- loaded.set(source, picture);
249
- }
250
- catch {
251
- // A picture that cannot be loaded is left out of the sketch instead of failing the whole capture.
252
- }
253
- }));
254
- try {
255
- if (options.background) {
256
- context.fillStyle = options.background;
257
- context.fillRect(0, 0, pixelWidth, pixelHeight);
258
- }
259
- context.setTransform(scale, 0, 0, scale, -area.x * scale, -area.y * scale);
260
- const deps = {
261
- createPath: services.createPath,
262
- imageFor: (source) => (source ? (loaded.get(source) ?? null) : null),
263
- measureText: services.measureText,
264
- widgetFallbackName: options.widgetFallbackName
265
- };
266
- for (const shape of shapes)
267
- paintShape(context, shape, deps);
268
- return canvas.toDataURL('image/png');
269
- }
270
- catch {
271
- return '';
272
- }
273
+ export function renderShapesToDataUrl(shapes_2, services_1) {
274
+ return __awaiter(this, arguments, Promise, function (shapes, services, options) {
275
+ var bounds, padding, left, top, right, bottom, area, scale, pixelWidth, pixelHeight, canvas, context, loaded, deps, _i, shapes_3, shape;
276
+ var _this = this;
277
+ var _a, _b;
278
+ if (options === void 0) { options = {}; }
279
+ return __generator(this, function (_c) {
280
+ switch (_c.label) {
281
+ case 0:
282
+ bounds = rasterBoundsOf(shapes);
283
+ if (!bounds)
284
+ return [2 /*return*/, ''];
285
+ padding = Math.max(0, (_a = options.padding) !== null && _a !== void 0 ? _a : 0);
286
+ left = Math.floor(bounds.x - padding);
287
+ top = Math.floor(bounds.y - padding);
288
+ right = Math.ceil(bounds.x + bounds.width + padding);
289
+ bottom = Math.ceil(bounds.y + bounds.height + padding);
290
+ area = { x: left, y: top, width: Math.max(1, right - left), height: Math.max(1, bottom - top) };
291
+ scale = rasterScaleFor(area, options);
292
+ pixelWidth = Math.max(1, Math.ceil(area.width * scale));
293
+ pixelHeight = Math.max(1, Math.ceil(area.height * scale));
294
+ canvas = services.createCanvas(pixelWidth, pixelHeight);
295
+ context = (_b = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d')) !== null && _b !== void 0 ? _b : null;
296
+ if (!canvas || !context)
297
+ return [2 /*return*/, ''];
298
+ loaded = new Map();
299
+ return [4 /*yield*/, Promise.all(imageSourcesOf(shapes).map(function (source) { return __awaiter(_this, void 0, void 0, function () {
300
+ var picture, _a;
301
+ return __generator(this, function (_b) {
302
+ switch (_b.label) {
303
+ case 0:
304
+ _b.trys.push([0, 2, , 3]);
305
+ return [4 /*yield*/, services.loadImage(source)];
306
+ case 1:
307
+ picture = _b.sent();
308
+ if (picture)
309
+ loaded.set(source, picture);
310
+ return [3 /*break*/, 3];
311
+ case 2:
312
+ _a = _b.sent();
313
+ return [3 /*break*/, 3];
314
+ case 3: return [2 /*return*/];
315
+ }
316
+ });
317
+ }); }))];
318
+ case 1:
319
+ _c.sent();
320
+ try {
321
+ if (options.background) {
322
+ context.fillStyle = options.background;
323
+ context.fillRect(0, 0, pixelWidth, pixelHeight);
324
+ }
325
+ context.setTransform(scale, 0, 0, scale, -area.x * scale, -area.y * scale);
326
+ deps = {
327
+ createPath: services.createPath,
328
+ imageFor: function (source) { var _a; return (source ? ((_a = loaded.get(source)) !== null && _a !== void 0 ? _a : null) : null); },
329
+ measureText: services.measureText,
330
+ widgetFallbackName: options.widgetFallbackName
331
+ };
332
+ for (_i = 0, shapes_3 = shapes; _i < shapes_3.length; _i++) {
333
+ shape = shapes_3[_i];
334
+ paintShape(context, shape, deps);
335
+ }
336
+ return [2 /*return*/, canvas.toDataURL('image/png')];
337
+ }
338
+ catch (_d) {
339
+ return [2 /*return*/, ''];
340
+ }
341
+ return [2 /*return*/];
342
+ }
343
+ });
344
+ });
273
345
  }
@@ -11,6 +11,22 @@ import type { ArrowBindHint, ObjectId, Rect, SceneObject, Size, Viewport } from
11
11
  export type ToolId = 'select' | 'draw' | 'rect' | 'rounded-rect' | 'ellipse' | 'circle' | 'triangle' | 'arrow' | 'library-shape' | 'text' | 'erase' | 'pan';
12
12
  /** The tools that drag a shape out. */
13
13
  export type ShapeToolId = 'rect' | 'rounded-rect' | 'ellipse' | 'circle' | 'triangle' | 'arrow' | 'library-shape';
14
+ /**
15
+ * How the Draw tool draws, set before a line is drawn: the lines drawn from then on have this colour, this width and this opacity.
16
+ * A line that is already on the board keeps what it has (the settings panel changes it while it is selected).
17
+ */
18
+ export interface PenStyle {
19
+ /** The colour of the line. */
20
+ color: string;
21
+ /** The width of the line, as the Width control of the panel shows it. */
22
+ width: number;
23
+ /** How much of the board shows through the whole line, from 0 to 1: 1 is solid. */
24
+ opacity: number;
25
+ }
26
+ /** The least opaque the pen may be made: a line that cannot be seen is not a pen anyone means to choose, and a drawn line would look like nothing happened. */
27
+ export declare const MIN_PEN_OPACITY = 0.05;
28
+ /** The pen of a board that was not given another: the colour and the width the Draw tool has always drawn with, fully solid. */
29
+ export declare const DEFAULT_PEN_STYLE: PenStyle;
14
30
  export declare const SHAPE_TOOLS: readonly ToolId[];
15
31
  /** A widget card whose widget the host is still working on. Not saved. */
16
32
  export type PendingWidgetState = 'duplicating' | 'linking' | 'converting';
@@ -123,6 +139,8 @@ export interface EngineState {
123
139
  libraryShapeKey: string | null;
124
140
  /** Keep the tool after a shape has been placed (otherwise the tool goes back to Select). */
125
141
  stickyTool: boolean;
142
+ /** How the Draw tool draws the next line (see `PenStyle`). Not part of the saved board: it is the person's setting. */
143
+ penStyle: PenStyle;
126
144
  /** The CSS cursor of the board. */
127
145
  cursor: string;
128
146
  overlay: EngineOverlay;
@@ -3,10 +3,30 @@
3
3
  * is, what is half-drawn. One immutable snapshot, replaced on every change, so a view can hold on to a slice of
4
4
  * it (the scene, the selection, the viewport) and redraw only when that slice is a different object.
5
5
  */
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
17
+ import { SHAPE_STYLE_DEFAULTS } from './core/defaults.js';
6
18
  import { INITIAL_VIEWPORT } from './core/viewport.js';
7
- export const SHAPE_TOOLS = ['rect', 'rounded-rect', 'ellipse', 'circle', 'triangle', 'arrow', 'library-shape'];
8
- export const DEFAULT_WIDGET_RUNTIME = Object.freeze({ hiddenImage: false, orphaned: false, bodyDragAllowed: false });
9
- export const EMPTY_OVERLAY = Object.freeze({
19
+ /** The least opaque the pen may be made: a line that cannot be seen is not a pen anyone means to choose, and a drawn line would look like nothing happened. */
20
+ export var MIN_PEN_OPACITY = 0.05;
21
+ /** The pen of a board that was not given another: the colour and the width the Draw tool has always drawn with, fully solid. */
22
+ export var DEFAULT_PEN_STYLE = Object.freeze({
23
+ color: SHAPE_STYLE_DEFAULTS.inkStroke,
24
+ width: SHAPE_STYLE_DEFAULTS.inkStrokeWidth,
25
+ opacity: 1
26
+ });
27
+ export var SHAPE_TOOLS = ['rect', 'rounded-rect', 'ellipse', 'circle', 'triangle', 'arrow', 'library-shape'];
28
+ export var DEFAULT_WIDGET_RUNTIME = Object.freeze({ hiddenImage: false, orphaned: false, bodyDragAllowed: false });
29
+ export var EMPTY_OVERLAY = Object.freeze({
10
30
  marquee: null,
11
31
  marqueeHover: Object.freeze([]),
12
32
  guides: Object.freeze([]),
@@ -27,11 +47,12 @@ export function createInitialState() {
27
47
  hoverId: null,
28
48
  rotationDotHovered: false,
29
49
  arrowHandleHovered: null,
30
- viewport: { ...INITIAL_VIEWPORT },
50
+ viewport: __assign({}, INITIAL_VIEWPORT),
31
51
  viewSize: { width: 0, height: 0 },
32
52
  tool: 'select',
33
53
  libraryShapeKey: null,
34
54
  stickyTool: false,
55
+ penStyle: DEFAULT_PEN_STYLE,
35
56
  cursor: 'default',
36
57
  overlay: EMPTY_OVERLAY,
37
58
  scribble: null,
@@ -6,24 +6,35 @@
6
6
  * same measuring function. The board draws the lines this returns (each on a line of its own, never wrapped by the
7
7
  * browser), and the sketch the AI is shown is drawn from the same lines, so what is on the screen is what is sent.
8
8
  */
9
+ var __assign = (this && this.__assign) || function () {
10
+ __assign = Object.assign || function(t) {
11
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
12
+ s = arguments[i];
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
14
+ t[p] = s[p];
15
+ }
16
+ return t;
17
+ };
18
+ return __assign.apply(this, arguments);
19
+ };
9
20
  import { TEXT_DEFAULTS } from '../core/defaults.js';
10
21
  import { textLineExtent } from './textMetrics.js';
11
22
  /** Room so the last letter and the caret stay on the line; more than this reads as padding. */
12
- export const TEXT_FIT_SLACK = 4;
23
+ export var TEXT_FIT_SLACK = 4;
13
24
  /** Extra width for italic slant and serif overhang beyond what `measureText` returns. */
14
25
  export function textFitHorizontalSlack(style) {
15
- const overhang = Math.ceil(style.fontSize * 0.08);
16
- const italic = style.fontStyle === 'italic' ? Math.ceil(style.fontSize * 0.2) : 0;
26
+ var overhang = Math.ceil(style.fontSize * 0.08);
27
+ var italic = style.fontStyle === 'italic' ? Math.ceil(style.fontSize * 0.2) : 0;
17
28
  return TEXT_FIT_SLACK + overhang + italic;
18
29
  }
19
30
  /** The CSS `font` shorthand of a text object. */
20
31
  export function fontShorthand(style) {
21
- const parts = [];
32
+ var parts = [];
22
33
  if (style.fontStyle === 'italic')
23
34
  parts.push('italic');
24
35
  if (style.fontWeight === 'bold')
25
36
  parts.push('bold');
26
- parts.push(`${style.fontSize}px`);
37
+ parts.push("".concat(style.fontSize, "px"));
27
38
  parts.push(style.fontFamily);
28
39
  return parts.join(' ');
29
40
  }
@@ -33,16 +44,17 @@ export function lineBoxHeight(style) {
33
44
  }
34
45
  export { textLineExtent } from './textMetrics.js';
35
46
  /** A letter of a script that is written from right to left. Digits, signs and marks have no direction of their own. */
36
- const RIGHT_TO_LEFT_LETTER = /(?=\p{L})[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Mandaic}\p{Script=Adlam}]/u;
47
+ var RIGHT_TO_LEFT_LETTER = /(?=\p{L})[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Samaritan}\p{Script=Mandaic}\p{Script=Adlam}]/u;
37
48
  /** A letter of any script. */
38
- const ANY_LETTER = /\p{L}/u;
49
+ var ANY_LETTER = /\p{L}/u;
39
50
  /**
40
51
  * The direction a text is written in: the one of its first letter. This is what the browser's `dir="auto"` does, so the
41
52
  * board (a drawing that is `ltr` on every screen), the field a text is typed in and the sketch that is drawn for the AI
42
53
  * all place the same text the same way. A text with no letter (digits, signs, nothing) reads left to right.
43
54
  */
44
55
  export function textDirection(text) {
45
- for (const character of text) {
56
+ for (var _i = 0, text_1 = text; _i < text_1.length; _i++) {
57
+ var character = text_1[_i];
46
58
  if (RIGHT_TO_LEFT_LETTER.test(character))
47
59
  return 'rtl';
48
60
  if (ANY_LETTER.test(character))
@@ -50,23 +62,24 @@ export function textDirection(text) {
50
62
  }
51
63
  return 'ltr';
52
64
  }
53
- let segmenter;
65
+ var segmenter;
54
66
  /** The letters of a word as a person counts them (an emoji with a modifier is one), when the platform can tell. */
55
67
  function graphemes(word) {
56
68
  if (segmenter === undefined) {
57
- const Segmenter = Intl.Segmenter;
69
+ var Segmenter = Intl.Segmenter;
58
70
  segmenter = Segmenter ? new Segmenter(undefined, { granularity: 'grapheme' }) : null;
59
71
  }
60
72
  if (!segmenter)
61
73
  return Array.from(word);
62
- return Array.from(segmenter.segment(word), (part) => part.segment);
74
+ return Array.from(segmenter.segment(word), function (part) { return part.segment; });
63
75
  }
64
76
  /** Cuts a word that is wider than a line into pieces that each fit (at least one letter each). */
65
77
  function breakLongWord(word, maxWidth, font, measure) {
66
- const pieces = [];
67
- let current = '';
68
- for (const letter of graphemes(word)) {
69
- const candidate = current + letter;
78
+ var pieces = [];
79
+ var current = '';
80
+ for (var _i = 0, _a = graphemes(word); _i < _a.length; _i++) {
81
+ var letter = _a[_i];
82
+ var candidate = current + letter;
70
83
  if (current !== '' && measure(candidate, font) > maxWidth) {
71
84
  pieces.push(current);
72
85
  current = letter;
@@ -81,16 +94,18 @@ function breakLongWord(word, maxWidth, font, measure) {
81
94
  }
82
95
  /** Wraps one paragraph (no line breaks in it) into lines no wider than `maxWidth`, breaking at spaces. */
83
96
  function wrapParagraph(paragraph, maxWidth, font, measure) {
97
+ var _a, _b;
84
98
  if (paragraph === '')
85
99
  return [''];
86
100
  if (measure(paragraph, font) <= maxWidth)
87
101
  return [paragraph];
88
- const lines = [];
89
- let line = '';
102
+ var lines = [];
103
+ var line = '';
90
104
  // Words keep the spaces that follow them, so a line that ends in a space still measures like the browser's.
91
- const words = paragraph.match(/\S+\s*|\s+/g) ?? [paragraph];
92
- for (const word of words) {
93
- const candidate = line + word;
105
+ var words = (_a = paragraph.match(/\S+\s*|\s+/g)) !== null && _a !== void 0 ? _a : [paragraph];
106
+ for (var _i = 0, words_1 = words; _i < words_1.length; _i++) {
107
+ var word = words_1[_i];
108
+ var candidate = line + word;
94
109
  if (measure(candidate.trimEnd(), font) <= maxWidth) {
95
110
  line = candidate;
96
111
  continue;
@@ -103,11 +118,11 @@ function wrapParagraph(paragraph, maxWidth, font, measure) {
103
118
  line = word;
104
119
  }
105
120
  else {
106
- const bareWord = word.trimEnd();
107
- const pieces = breakLongWord(bareWord, maxWidth, font, measure);
108
- lines.push(...pieces.slice(0, -1));
121
+ var bareWord = word.trimEnd();
122
+ var pieces = breakLongWord(bareWord, maxWidth, font, measure);
123
+ lines.push.apply(lines, pieces.slice(0, -1));
109
124
  // The last piece keeps the spaces that followed the word, so the next word is not glued to it
110
- line = (pieces[pieces.length - 1] ?? '') + word.slice(bareWord.length);
125
+ line = ((_b = pieces[pieces.length - 1]) !== null && _b !== void 0 ? _b : '') + word.slice(bareWord.length);
111
126
  }
112
127
  }
113
128
  if (line !== '')
@@ -119,30 +134,32 @@ function wrapParagraph(paragraph, maxWidth, font, measure) {
119
134
  * `fixedWidth` is the width of the box when the text wraps; null lets the box be as wide as the longest line.
120
135
  */
121
136
  export function layoutText(text, style, fixedWidth, measure) {
122
- const font = fontShorthand(style);
123
- const padding = style.padding;
124
- const paragraphs = text.split('\n');
125
- let lines;
137
+ var font = fontShorthand(style);
138
+ var padding = style.padding;
139
+ var paragraphs = text.split('\n');
140
+ var lines;
126
141
  if (fixedWidth === null) {
127
142
  lines = paragraphs;
128
143
  }
129
144
  else {
130
- const maxWidth = Math.max(1, fixedWidth - padding * 2);
131
- lines = paragraphs.flatMap((paragraph) => wrapParagraph(paragraph, maxWidth, font, measure));
145
+ var maxWidth_1 = Math.max(1, fixedWidth - padding * 2);
146
+ lines = paragraphs.flatMap(function (paragraph) { return wrapParagraph(paragraph, maxWidth_1, font, measure); });
132
147
  }
133
- let contentWidth = 0;
134
- for (const line of lines)
148
+ var contentWidth = 0;
149
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
150
+ var line = lines_1[_i];
135
151
  contentWidth = Math.max(contentWidth, measure(line, font));
136
- const height = Math.ceil(lines.length * textLineExtent(style) + padding * 2);
137
- let width = fixedWidth === null
152
+ }
153
+ var height = Math.ceil(lines.length * textLineExtent(style) + padding * 2);
154
+ var width = fixedWidth === null
138
155
  ? Math.max(TEXT_DEFAULTS.minimumWidth, Math.ceil(contentWidth + padding * 2 + textFitHorizontalSlack(style)))
139
156
  : fixedWidth;
140
157
  if (fixedWidth === null && text === '') {
141
- const standIn = TEXT_DEFAULTS.emptyTextMeasureStandIn;
142
- const standInWidth = measure(standIn, font);
158
+ var standIn = TEXT_DEFAULTS.emptyTextMeasureStandIn;
159
+ var standInWidth = measure(standIn, font);
143
160
  width = Math.max(width, Math.ceil(standInWidth + padding * 2 + textFitHorizontalSlack(style)));
144
161
  }
145
- return { lines, contentWidth, width, height };
162
+ return { lines: lines, contentWidth: contentWidth, width: width, height: height };
146
163
  }
147
164
  /** The layout of a text object as it stands. */
148
165
  export function layoutTextObject(shape, measure) {
@@ -153,16 +170,18 @@ export function layoutTextObject(shape, measure) {
153
170
  * The same object comes back when nothing changes, so an unchanged text is not redrawn.
154
171
  */
155
172
  export function fitTextObject(shape, measure) {
156
- const layout = layoutTextObject(shape, measure);
157
- const width = shape.autoWidth ? layout.width : shape.width;
173
+ var layout = layoutTextObject(shape, measure);
174
+ var width = shape.autoWidth ? layout.width : shape.width;
158
175
  if (width === shape.width && layout.height === shape.height)
159
176
  return shape;
160
- return { ...shape, width, height: layout.height };
177
+ return __assign(__assign({}, shape), { width: width, height: layout.height });
161
178
  }
162
179
  /** A measuring function that needs no browser: every letter is `advance` times the font size wide. For tests and Node. */
163
- export function createFixedAdvanceMeasure(advance = 0.5) {
164
- return (text, font) => {
165
- const size = /(\d+(?:\.\d+)?)px/.exec(font)?.[1];
180
+ export function createFixedAdvanceMeasure(advance) {
181
+ if (advance === void 0) { advance = 0.5; }
182
+ return function (text, font) {
183
+ var _a;
184
+ var size = (_a = /(\d+(?:\.\d+)?)px/.exec(font)) === null || _a === void 0 ? void 0 : _a[1];
166
185
  return Array.from(text).length * advance * (size ? Number(size) : 16);
167
186
  };
168
187
  }