@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
@@ -8,17 +8,6 @@
8
8
  * A handle is dragged in the frame's own (unrotated) space, so a turned shape resizes along its own edges.
9
9
  * The edge opposite the handle (or the centre, with Alt) stays where it is in the world.
10
10
  */
11
- var __assign = (this && this.__assign) || function () {
12
- __assign = Object.assign || function(t) {
13
- for (var s, i = 1, n = arguments.length; i < n; i++) {
14
- s = arguments[i];
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
16
- t[p] = s[p];
17
- }
18
- return t;
19
- };
20
- return __assign.apply(this, arguments);
21
- };
22
11
  import { isArrow, transformArrow } from './arrow.js';
23
12
  import { isBrushStroke, reshapeBrushStroke } from './brush.js';
24
13
  import { rotatedBoxBounds, unionRects, worldToBoxLocal, clampNumber } from './geometry.js';
@@ -26,7 +15,7 @@ import { applyMatrixToPoint, boxToWorldMatrix, degreesToRadians, normalizeDegree
26
15
  import { parsePathData, scalePathCommands, mirrorPathCommands, serializePathData } from './pathData.js';
27
16
  import { regeneratedPathCommands } from './shapePaths.js';
28
17
  import { MIN_OBJECT_SIZE } from './types.js';
29
- var HANDLE_DIRECTIONS = {
18
+ const HANDLE_DIRECTIONS = {
30
19
  nw: { x: -1, y: -1 },
31
20
  n: { x: 0, y: -1 },
32
21
  ne: { x: 1, y: -1 },
@@ -44,11 +33,11 @@ export function selectionFrameOf(shapes) {
44
33
  if (shapes.length === 0)
45
34
  return null;
46
35
  if (shapes.length === 1) {
47
- var shape = shapes[0];
36
+ const [shape] = shapes;
48
37
  return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
49
38
  }
50
- var union = unionRects(shapes.map(function (shape) { return rotatedBoxBounds(shape); }));
51
- return union ? __assign(__assign({}, union), { rotation: 0 }) : null;
39
+ const union = unionRects(shapes.map((shape) => rotatedBoxBounds(shape)));
40
+ return union ? { ...union, rotation: 0 } : null;
52
41
  }
53
42
  /** The centre of a frame in the world. */
54
43
  export function frameCenter(frame) {
@@ -58,31 +47,29 @@ export function frameCenter(frame) {
58
47
  * The frame that results from dragging `handle` to a world point.
59
48
  * `frame` is the frame when the drag began (not the one the last pointer move produced).
60
49
  */
61
- export function computeResizedFrame(frame, handle, pointerWorld, options) {
62
- var _a;
63
- if (options === void 0) { options = {}; }
64
- var minimumSize = (_a = options.minimumSize) !== null && _a !== void 0 ? _a : MIN_OBJECT_SIZE;
65
- var direction = HANDLE_DIRECTIONS[handle];
66
- var local = worldToBoxLocal(frame, pointerWorld);
50
+ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
51
+ const minimumSize = options.minimumSize ?? MIN_OBJECT_SIZE;
52
+ const direction = HANDLE_DIRECTIONS[handle];
53
+ const local = worldToBoxLocal(frame, pointerWorld);
67
54
  if (!local)
68
- return __assign(__assign({}, frame), { flipX: false, flipY: false });
69
- var width = frame.width, height = frame.height;
55
+ return { ...frame, flipX: false, flipY: false };
56
+ const { width, height } = frame;
70
57
  // How far the handle's edge is from the anchor (the opposite edge, or the centre), signed: negative means
71
58
  // the pointer has crossed the anchor.
72
- var extentX = direction.x === 0
59
+ const extentX = direction.x === 0
73
60
  ? width
74
61
  : options.fromCenter
75
62
  ? (local.x - width / 2) * direction.x * 2
76
63
  : (local.x - (direction.x > 0 ? 0 : width)) * direction.x;
77
- var extentY = direction.y === 0
64
+ const extentY = direction.y === 0
78
65
  ? height
79
66
  : options.fromCenter
80
67
  ? (local.y - height / 2) * direction.y * 2
81
68
  : (local.y - (direction.y > 0 ? 0 : height)) * direction.y;
82
- var signedWidth = extentX;
83
- var signedHeight = extentY;
69
+ let signedWidth = extentX;
70
+ let signedHeight = extentY;
84
71
  if (options.keepAspect && width > 0 && height > 0) {
85
- var scale = void 0;
72
+ let scale;
86
73
  if (direction.x !== 0 && direction.y !== 0) {
87
74
  scale = Math.max(Math.abs(extentX) / width, Math.abs(extentY) / height);
88
75
  }
@@ -92,14 +79,14 @@ export function computeResizedFrame(frame, handle, pointerWorld, options) {
92
79
  else {
93
80
  scale = Math.abs(extentY) / height;
94
81
  }
95
- var smallestScale = minimumSize / Math.min(width, height);
82
+ const smallestScale = minimumSize / Math.min(width, height);
96
83
  if (!options.allowFlip || scale < smallestScale)
97
84
  scale = Math.max(scale, smallestScale);
98
85
  signedWidth = (direction.x === 0 || extentX >= 0 ? 1 : -1) * width * scale;
99
86
  signedHeight = (direction.y === 0 || extentY >= 0 ? 1 : -1) * height * scale;
100
87
  }
101
- var flipX = false;
102
- var flipY = false;
88
+ let flipX = false;
89
+ let flipY = false;
103
90
  if (signedWidth < 0) {
104
91
  if (options.allowFlip)
105
92
  flipX = true;
@@ -112,22 +99,22 @@ export function computeResizedFrame(frame, handle, pointerWorld, options) {
112
99
  else
113
100
  signedHeight = minimumSize;
114
101
  }
115
- var newWidth = Math.max(minimumSize, Math.abs(signedWidth));
116
- var newHeight = Math.max(minimumSize, Math.abs(signedHeight));
102
+ const newWidth = Math.max(minimumSize, Math.abs(signedWidth));
103
+ const newHeight = Math.max(minimumSize, Math.abs(signedHeight));
117
104
  // The centre of the new box in the frame's own space: half an extent from the anchor, towards the handle.
118
- var anchorX = direction.x > 0 ? 0 : width;
119
- var anchorY = direction.y > 0 ? 0 : height;
120
- var centerLocalX = direction.x === 0 || options.fromCenter ? width / 2 : anchorX + (direction.x * (flipX ? -newWidth : newWidth)) / 2;
121
- var centerLocalY = direction.y === 0 || options.fromCenter ? height / 2 : anchorY + (direction.y * (flipY ? -newHeight : newHeight)) / 2;
122
- var centerWorld = applyMatrixToPoint(boxToWorldMatrix(frame), { x: centerLocalX, y: centerLocalY });
105
+ const anchorX = direction.x > 0 ? 0 : width;
106
+ const anchorY = direction.y > 0 ? 0 : height;
107
+ const centerLocalX = direction.x === 0 || options.fromCenter ? width / 2 : anchorX + (direction.x * (flipX ? -newWidth : newWidth)) / 2;
108
+ const centerLocalY = direction.y === 0 || options.fromCenter ? height / 2 : anchorY + (direction.y * (flipY ? -newHeight : newHeight)) / 2;
109
+ const centerWorld = applyMatrixToPoint(boxToWorldMatrix(frame), { x: centerLocalX, y: centerLocalY });
123
110
  return {
124
111
  x: centerWorld.x - newWidth / 2,
125
112
  y: centerWorld.y - newHeight / 2,
126
113
  width: newWidth,
127
114
  height: newHeight,
128
115
  rotation: frame.rotation,
129
- flipX: flipX,
130
- flipY: flipY
116
+ flipX,
117
+ flipY
131
118
  };
132
119
  }
133
120
  /**
@@ -137,21 +124,18 @@ export function computeResizedFrame(frame, handle, pointerWorld, options) {
137
124
  * is drawn again (its head keeps its size), text keeps its font size when it is resized from a side
138
125
  * (wrapping) and scales it from a corner.
139
126
  */
140
- export function resizeShapeToBox(shape, box, flip, textScale) {
141
- var _a;
142
- if (flip === void 0) { flip = { flipX: false, flipY: false }; }
143
- if (textScale === void 0) { textScale = null; }
144
- var width = Math.max(MIN_OBJECT_SIZE, box.width);
145
- var height = Math.max(MIN_OBJECT_SIZE, box.height);
146
- var rotation = (_a = box.rotation) !== null && _a !== void 0 ? _a : shape.rotation;
147
- var base = __assign(__assign({}, shape), { x: box.x, y: box.y, width: width, height: height, rotation: rotation });
127
+ export function resizeShapeToBox(shape, box, flip = { flipX: false, flipY: false }, textScale = null) {
128
+ const width = Math.max(MIN_OBJECT_SIZE, box.width);
129
+ const height = Math.max(MIN_OBJECT_SIZE, box.height);
130
+ const rotation = box.rotation ?? shape.rotation;
131
+ const base = { ...shape, x: box.x, y: box.y, width, height, rotation };
148
132
  switch (shape.type) {
149
133
  case 'path': {
150
134
  if (isArrow(shape)) {
151
135
  // The points of the arrow go where the box goes (mirrored by a flip), and the arrow is drawn again from them.
152
- var mapPoint = function (point) {
153
- var unitX = shape.width > 0 ? (point.x - shape.x) / shape.width : 0.5;
154
- var unitY = shape.height > 0 ? (point.y - shape.y) / shape.height : 0.5;
136
+ const mapPoint = (point) => {
137
+ let unitX = shape.width > 0 ? (point.x - shape.x) / shape.width : 0.5;
138
+ let unitY = shape.height > 0 ? (point.y - shape.y) / shape.height : 0.5;
155
139
  if (flip.flipX)
156
140
  unitX = 1 - unitX;
157
141
  if (flip.flipY)
@@ -161,35 +145,35 @@ export function resizeShapeToBox(shape, box, flip, textScale) {
161
145
  return transformArrow(shape, mapPoint);
162
146
  }
163
147
  // A flip toggles the mirror the shape already has.
164
- var flipX = shape.flipX !== flip.flipX;
165
- var flipY = shape.flipY !== flip.flipY;
148
+ const flipX = shape.flipX !== flip.flipX;
149
+ const flipY = shape.flipY !== flip.flipY;
166
150
  if (isBrushStroke(shape)) {
167
151
  // The line goes where the box goes (and is mirrored by this flip); the brush stays as wide as it was.
168
- var reshaped = reshapeBrushStroke(shape, { width: width, height: height, flipX: flip.flipX, flipY: flip.flipY });
169
- return __assign(__assign({}, base), { d: reshaped.d, ink: reshaped.ink, flipX: flipX, flipY: flipY });
152
+ const reshaped = reshapeBrushStroke(shape, { width, height, flipX: flip.flipX, flipY: flip.flipY });
153
+ return { ...base, d: reshaped.d, ink: reshaped.ink, flipX, flipY };
170
154
  }
171
- var regenerated = regeneratedPathCommands(shape, width, height);
172
- var commands = void 0;
155
+ const regenerated = regeneratedPathCommands(shape, width, height);
156
+ let commands;
173
157
  if (regenerated) {
174
158
  // Rebuilt from its key, so the mirror the shape had is applied again.
175
159
  commands = mirrorPathCommands(regenerated, width, height, flipX, flipY);
176
160
  }
177
161
  else {
178
162
  // Scaled from the path it has, which already holds the earlier mirrors: only this flip is applied.
179
- var scaleX = shape.width > 0 ? width / shape.width : 1;
180
- var scaleY = shape.height > 0 ? height / shape.height : 1;
163
+ const scaleX = shape.width > 0 ? width / shape.width : 1;
164
+ const scaleY = shape.height > 0 ? height / shape.height : 1;
181
165
  commands = mirrorPathCommands(scalePathCommands(parsePathData(shape.d), scaleX, scaleY), width, height, flip.flipX, flip.flipY);
182
166
  }
183
- return __assign(__assign({}, base), { d: serializePathData(commands), flipX: flipX, flipY: flipY });
167
+ return { ...base, d: serializePathData(commands), flipX, flipY };
184
168
  }
185
169
  case 'text': {
186
- var text = shape;
170
+ const text = shape;
187
171
  if (textScale !== null && textScale > 0) {
188
172
  // A corner drag scales the letters with the box.
189
- return __assign(__assign({}, base), { fontSize: clampNumber(text.fontSize * textScale, 4, 600) });
173
+ return { ...base, fontSize: clampNumber(text.fontSize * textScale, 4, 600) };
190
174
  }
191
175
  // A side drag only sets the width the text wraps at.
192
- return __assign(__assign({}, base), { autoWidth: false });
176
+ return { ...base, autoWidth: false };
193
177
  }
194
178
  default:
195
179
  return base;
@@ -202,38 +186,38 @@ export function resizeShapeToBox(shape, box, flip, textScale) {
202
186
  */
203
187
  export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
204
188
  if (shapes.length === 1) {
205
- var shape = shapes[0];
206
- var cornerTextScale = shape.type === 'text' && isCornerHandle && startFrame.width > 0 ? resized.width / startFrame.width : null;
189
+ const [shape] = shapes;
190
+ const cornerTextScale = shape.type === 'text' && isCornerHandle && startFrame.width > 0 ? resized.width / startFrame.width : null;
207
191
  return [
208
192
  resizeShapeToBox(shape, resized, { flipX: resized.flipX, flipY: resized.flipY }, cornerTextScale)
209
193
  ];
210
194
  }
211
- var scaleX = startFrame.width > 0 ? resized.width / startFrame.width : 1;
212
- var scaleY = startFrame.height > 0 ? resized.height / startFrame.height : 1;
213
- var mapPoint = function (point) {
214
- var unitX = startFrame.width > 0 ? (point.x - startFrame.x) / startFrame.width : 0.5;
215
- var unitY = startFrame.height > 0 ? (point.y - startFrame.y) / startFrame.height : 0.5;
195
+ const scaleX = startFrame.width > 0 ? resized.width / startFrame.width : 1;
196
+ const scaleY = startFrame.height > 0 ? resized.height / startFrame.height : 1;
197
+ const mapPoint = (point) => {
198
+ let unitX = startFrame.width > 0 ? (point.x - startFrame.x) / startFrame.width : 0.5;
199
+ let unitY = startFrame.height > 0 ? (point.y - startFrame.y) / startFrame.height : 0.5;
216
200
  if (resized.flipX)
217
201
  unitX = 1 - unitX;
218
202
  if (resized.flipY)
219
203
  unitY = 1 - unitY;
220
204
  return { x: resized.x + unitX * resized.width, y: resized.y + unitY * resized.height };
221
205
  };
222
- return shapes.map(function (shape) {
223
- var radians = degreesToRadians(shape.rotation);
224
- var cosine = Math.cos(radians);
225
- var sine = Math.sin(radians);
206
+ return shapes.map((shape) => {
207
+ const radians = degreesToRadians(shape.rotation);
208
+ const cosine = Math.cos(radians);
209
+ const sine = Math.sin(radians);
226
210
  // The shape's own axes are stretched by the frame; the lengths along them give its new size.
227
- var widthFactor = Math.hypot(scaleX * cosine, scaleY * sine);
228
- var heightFactor = Math.hypot(scaleX * sine, scaleY * cosine);
229
- var newWidth = Math.max(MIN_OBJECT_SIZE, shape.width * widthFactor);
230
- var newHeight = Math.max(MIN_OBJECT_SIZE, shape.height * heightFactor);
231
- var center = mapPoint({ x: shape.x + shape.width / 2, y: shape.y + shape.height / 2 });
211
+ const widthFactor = Math.hypot(scaleX * cosine, scaleY * sine);
212
+ const heightFactor = Math.hypot(scaleX * sine, scaleY * cosine);
213
+ const newWidth = Math.max(MIN_OBJECT_SIZE, shape.width * widthFactor);
214
+ const newHeight = Math.max(MIN_OBJECT_SIZE, shape.height * heightFactor);
215
+ const center = mapPoint({ x: shape.x + shape.width / 2, y: shape.y + shape.height / 2 });
232
216
  // A mirrored shape turns the other way.
233
- var mirrors = (resized.flipX ? 1 : 0) + (resized.flipY ? 1 : 0);
234
- var rotation = mirrors % 2 === 1 ? normalizeDegrees(-shape.rotation) : shape.rotation;
235
- var box = { x: center.x - newWidth / 2, y: center.y - newHeight / 2, width: newWidth, height: newHeight, rotation: rotation };
236
- var textScale = shape.type === 'text' ? (widthFactor + heightFactor) / 2 : null;
217
+ const mirrors = (resized.flipX ? 1 : 0) + (resized.flipY ? 1 : 0);
218
+ const rotation = mirrors % 2 === 1 ? normalizeDegrees(-shape.rotation) : shape.rotation;
219
+ const box = { x: center.x - newWidth / 2, y: center.y - newHeight / 2, width: newWidth, height: newHeight, rotation };
220
+ const textScale = shape.type === 'text' ? (widthFactor + heightFactor) / 2 : null;
237
221
  return resizeShapeToBox(shape, box, { flipX: resized.flipX, flipY: resized.flipY }, textScale);
238
222
  });
239
223
  }
@@ -242,21 +226,26 @@ export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
242
226
  * turn (it is always upright): its points go round the point and it is drawn again between them.
243
227
  */
244
228
  export function rotateShapesAbout(shapes, pivot, deltaDegrees) {
245
- var radians = degreesToRadians(deltaDegrees);
246
- var cosine = Math.cos(radians);
247
- var sine = Math.sin(radians);
248
- return shapes.map(function (shape) {
229
+ const radians = degreesToRadians(deltaDegrees);
230
+ const cosine = Math.cos(radians);
231
+ const sine = Math.sin(radians);
232
+ return shapes.map((shape) => {
249
233
  if (isArrow(shape)) {
250
- return transformArrow(shape, function (point) { return ({
234
+ return transformArrow(shape, (point) => ({
251
235
  x: pivot.x + (point.x - pivot.x) * cosine - (point.y - pivot.y) * sine,
252
236
  y: pivot.y + (point.x - pivot.x) * sine + (point.y - pivot.y) * cosine
253
- }); });
237
+ }));
254
238
  }
255
- var centerX = shape.x + shape.width / 2 - pivot.x;
256
- var centerY = shape.y + shape.height / 2 - pivot.y;
257
- var rotatedX = pivot.x + centerX * cosine - centerY * sine;
258
- var rotatedY = pivot.y + centerX * sine + centerY * cosine;
259
- return __assign(__assign({}, shape), { x: rotatedX - shape.width / 2, y: rotatedY - shape.height / 2, rotation: normalizeDegrees(shape.rotation + deltaDegrees) });
239
+ const centerX = shape.x + shape.width / 2 - pivot.x;
240
+ const centerY = shape.y + shape.height / 2 - pivot.y;
241
+ const rotatedX = pivot.x + centerX * cosine - centerY * sine;
242
+ const rotatedY = pivot.y + centerX * sine + centerY * cosine;
243
+ return {
244
+ ...shape,
245
+ x: rotatedX - shape.width / 2,
246
+ y: rotatedY - shape.height / 2,
247
+ rotation: normalizeDegrees(shape.rotation + deltaDegrees)
248
+ };
260
249
  });
261
250
  }
262
251
  /** The angle, in degrees, of the line from `center` to `point` (0 is to the right, growing clockwise on screen). */
@@ -17,10 +17,10 @@
17
17
  * Nothing here knows about the DOM, Svelte or the host, so the same records run in Node tests.
18
18
  */
19
19
  /** The version of the saved format. A file of any other version (the previous canvas wrote version 1, a string, `1.0`) is not read: there is no converter. */
20
- export var CANVAS_DOCUMENT_VERSION = 2;
21
- export var MIN_OBJECT_SIZE = 1;
22
- export var MIN_ZOOM = 0.05;
23
- export var MAX_ZOOM = 8;
20
+ export const CANVAS_DOCUMENT_VERSION = 2;
21
+ export const MIN_OBJECT_SIZE = 1;
22
+ export const MIN_ZOOM = 0.05;
23
+ export const MAX_ZOOM = 8;
24
24
  /** True for the objects that carry a box (so not for a group). */
25
25
  export function isBoxedObject(object) {
26
26
  return object.type !== 'group';
@@ -5,22 +5,11 @@
5
5
  * `viewport.x` and `viewport.y` are where the world origin lands on the board element, in CSS pixels, and
6
6
  * `viewport.zoom` is the scale (1 is 100%). The world layer is drawn with `translate(x, y) scale(zoom)`.
7
7
  */
8
- var __assign = (this && this.__assign) || function () {
9
- __assign = Object.assign || function(t) {
10
- for (var s, i = 1, n = arguments.length; i < n; i++) {
11
- s = arguments[i];
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13
- t[p] = s[p];
14
- }
15
- return t;
16
- };
17
- return __assign.apply(this, arguments);
18
- };
19
8
  import { clampNumber } from './geometry.js';
20
9
  import { MAX_ZOOM, MIN_ZOOM } from './types.js';
21
- export var INITIAL_VIEWPORT = { x: 0, y: 0, zoom: 1 };
10
+ export const INITIAL_VIEWPORT = { x: 0, y: 0, zoom: 1 };
22
11
  /** The zoom levels the zoom buttons and the menu step through. */
23
- export var ZOOM_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
12
+ export const ZOOM_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
24
13
  export function clampZoom(zoom) {
25
14
  if (!Number.isFinite(zoom))
26
15
  return 1;
@@ -45,21 +34,21 @@ export function visibleWorldRect(viewport, viewSize) {
45
34
  }
46
35
  /** Changes the zoom and keeps the world point under `screenPoint` where it is (what the wheel and pinch do). */
47
36
  export function zoomAtPoint(viewport, screenPoint, nextZoom) {
48
- var zoom = clampZoom(nextZoom);
49
- var worldPoint = screenToWorld(viewport, screenPoint);
50
- return { x: screenPoint.x - worldPoint.x * zoom, y: screenPoint.y - worldPoint.y * zoom, zoom: zoom };
37
+ const zoom = clampZoom(nextZoom);
38
+ const worldPoint = screenToWorld(viewport, screenPoint);
39
+ return { x: screenPoint.x - worldPoint.x * zoom, y: screenPoint.y - worldPoint.y * zoom, zoom };
51
40
  }
52
41
  export function panViewport(viewport, deltaX, deltaY) {
53
- return __assign(__assign({}, viewport), { x: viewport.x + deltaX, y: viewport.y + deltaY });
42
+ return { ...viewport, x: viewport.x + deltaX, y: viewport.y + deltaY };
54
43
  }
55
44
  /** The next step above (direction 1) or below (-1) the current zoom, or the same zoom at the end of the ladder. */
56
45
  export function nextZoomStep(zoom, direction) {
57
- var tolerance = 1e-6;
46
+ const tolerance = 1e-6;
58
47
  if (direction === 1) {
59
- var step = ZOOM_STEPS.find(function (candidate) { return candidate > zoom + tolerance; });
60
- return step !== null && step !== void 0 ? step : ZOOM_STEPS[ZOOM_STEPS.length - 1];
48
+ const step = ZOOM_STEPS.find((candidate) => candidate > zoom + tolerance);
49
+ return step ?? ZOOM_STEPS[ZOOM_STEPS.length - 1];
61
50
  }
62
- for (var index = ZOOM_STEPS.length - 1; index >= 0; index -= 1) {
51
+ for (let index = ZOOM_STEPS.length - 1; index >= 0; index -= 1) {
63
52
  if (ZOOM_STEPS[index] < zoom - tolerance)
64
53
  return ZOOM_STEPS[index];
65
54
  }
@@ -69,29 +58,27 @@ export function nextZoomStep(zoom, direction) {
69
58
  * The view that shows a rectangle of the world, centred, with room around it.
70
59
  * Never zooms in past `maxZoom` (a single small shape is not blown up to fill the board).
71
60
  */
72
- export function fitViewportToRect(rect, viewSize, padding, maxZoom) {
73
- if (padding === void 0) { padding = 48; }
74
- if (maxZoom === void 0) { maxZoom = 1; }
61
+ export function fitViewportToRect(rect, viewSize, padding = 48, maxZoom = 1) {
75
62
  if (viewSize.width <= 0 || viewSize.height <= 0)
76
63
  return INITIAL_VIEWPORT;
77
- var availableWidth = Math.max(1, viewSize.width - padding * 2);
78
- var availableHeight = Math.max(1, viewSize.height - padding * 2);
79
- var zoom = clampZoom(Math.min(maxZoom, rect.width > 0 ? availableWidth / rect.width : maxZoom, rect.height > 0 ? availableHeight / rect.height : maxZoom));
80
- var centerX = rect.x + rect.width / 2;
81
- var centerY = rect.y + rect.height / 2;
82
- return { x: viewSize.width / 2 - centerX * zoom, y: viewSize.height / 2 - centerY * zoom, zoom: zoom };
64
+ const availableWidth = Math.max(1, viewSize.width - padding * 2);
65
+ const availableHeight = Math.max(1, viewSize.height - padding * 2);
66
+ const zoom = clampZoom(Math.min(maxZoom, rect.width > 0 ? availableWidth / rect.width : maxZoom, rect.height > 0 ? availableHeight / rect.height : maxZoom));
67
+ const centerX = rect.x + rect.width / 2;
68
+ const centerY = rect.y + rect.height / 2;
69
+ return { x: viewSize.width / 2 - centerX * zoom, y: viewSize.height / 2 - centerY * zoom, zoom };
83
70
  }
84
71
  /** The CSS transform of the world layer. */
85
72
  export function viewportToCssTransform(viewport) {
86
- return "translate(".concat(Number(viewport.x.toFixed(3)), "px, ").concat(Number(viewport.y.toFixed(3)), "px) scale(").concat(Number(viewport.zoom.toFixed(5)), ")");
73
+ return `translate(${Number(viewport.x.toFixed(3))}px, ${Number(viewport.y.toFixed(3))}px) scale(${Number(viewport.zoom.toFixed(5))})`;
87
74
  }
88
75
  /** A viewport read from untrusted data: anything that is not a finite number falls back to the default. */
89
76
  export function sanitizeViewport(value) {
90
77
  if (!value || typeof value !== 'object')
91
78
  return INITIAL_VIEWPORT;
92
- var candidate = value;
93
- var x = typeof candidate.x === 'number' && Number.isFinite(candidate.x) ? candidate.x : 0;
94
- var y = typeof candidate.y === 'number' && Number.isFinite(candidate.y) ? candidate.y : 0;
95
- var zoom = typeof candidate.zoom === 'number' ? clampZoom(candidate.zoom) : 1;
96
- return { x: x, y: y, zoom: zoom };
79
+ const candidate = value;
80
+ const x = typeof candidate.x === 'number' && Number.isFinite(candidate.x) ? candidate.x : 0;
81
+ const y = typeof candidate.y === 'number' && Number.isFinite(candidate.y) ? candidate.y : 0;
82
+ const zoom = typeof candidate.zoom === 'number' ? clampZoom(candidate.zoom) : 1;
83
+ return { x, y, zoom };
97
84
  }