@widgetic/canvas 0.5.40 → 0.5.41

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 (120) hide show
  1. package/README.md +7 -3
  2. package/dist/canvas/DomCanvas.svelte +4 -0
  3. package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
  4. package/dist/canvas/autosaveScheduler.js +89 -37
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +19 -7
  8. package/dist/canvas/chromeLayout.js +18 -17
  9. package/dist/canvas/eventScope.js +14 -10
  10. package/dist/canvas/host/CanvasHost.d.ts +6 -0
  11. package/dist/canvas/host/CanvasHost.js +1556 -1267
  12. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  13. package/dist/canvas/host/CanvasHostApi.js +25 -4
  14. package/dist/canvas/host/browserServices.js +116 -65
  15. package/dist/canvas/host/conversion.js +170 -82
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/pageEvents.js +4 -4
  18. package/dist/canvas/host/screenRects.js +31 -28
  19. package/dist/canvas/host/strokeSnap.js +143 -88
  20. package/dist/canvas/openMarks.js +2 -2
  21. package/dist/canvas/outsideClickDeselect.js +7 -6
  22. package/dist/canvas/panZoomPosition.js +2 -2
  23. package/dist/canvas/preferredTextFont.js +25 -13
  24. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  25. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  26. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  27. package/dist/canvas/toolbarPosition.js +2 -2
  28. package/dist/canvas/ui/CanvasHint.svelte +16 -3
  29. package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
  30. package/dist/canvas/ui/CanvasToolbar.svelte +7 -7
  31. package/dist/canvas/ui/ToolButton.svelte +11 -3
  32. package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
  33. package/dist/canvas/ui/colorModel.js +32 -21
  34. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  35. package/dist/canvas/ui/floatingCard.js +18 -18
  36. package/dist/canvas/ui/floatingLayer.js +6 -5
  37. package/dist/canvas/ui/keyHints.js +11 -9
  38. package/dist/canvas/ui/popoverSide.js +3 -2
  39. package/dist/canvas/ui/selectionTraits.js +40 -34
  40. package/dist/canvas/ui/sizeLabelVisibility.d.ts +1 -1
  41. package/dist/canvas/ui/sizeLabelVisibility.js +1 -1
  42. package/dist/canvas/view/SelectionOverlay.svelte +33 -14
  43. package/dist/canvas/view/erasingMarks.js +7 -7
  44. package/dist/canvas/view/geometry.d.ts +14 -4
  45. package/dist/canvas/view/geometry.js +103 -77
  46. package/dist/components/preferenceStorage.js +2 -2
  47. package/dist/engine/EngineCore.d.ts +4 -1
  48. package/dist/engine/EngineCore.js +801 -695
  49. package/dist/engine/codec/canvasDocument.js +173 -173
  50. package/dist/engine/codec/hostReadableKeys.js +1 -1
  51. package/dist/engine/core/arrange.js +38 -26
  52. package/dist/engine/core/arrow.d.ts +10 -3
  53. package/dist/engine/core/arrow.js +96 -75
  54. package/dist/engine/core/arrowBinding.d.ts +69 -0
  55. package/dist/engine/core/arrowBinding.js +344 -0
  56. package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
  57. package/dist/engine/core/arrowBindingRecords.js +141 -0
  58. package/dist/engine/core/brush.js +94 -67
  59. package/dist/engine/core/defaults.js +51 -90
  60. package/dist/engine/core/freehand.js +163 -147
  61. package/dist/engine/core/geometry.js +54 -47
  62. package/dist/engine/core/history.js +50 -33
  63. package/dist/engine/core/hitTest.d.ts +3 -0
  64. package/dist/engine/core/hitTest.js +83 -69
  65. package/dist/engine/core/matrix.js +20 -18
  66. package/dist/engine/core/pathData.js +210 -183
  67. package/dist/engine/core/rotationReset.js +6 -5
  68. package/dist/engine/core/scene.d.ts +3 -0
  69. package/dist/engine/core/scene.js +192 -129
  70. package/dist/engine/core/scribble.js +84 -59
  71. package/dist/engine/core/shapePaths.js +15 -12
  72. package/dist/engine/core/shapeTools.js +63 -72
  73. package/dist/engine/core/snapping.js +117 -65
  74. package/dist/engine/core/style.js +64 -31
  75. package/dist/engine/core/transform.js +94 -83
  76. package/dist/engine/core/types.d.ts +29 -0
  77. package/dist/engine/core/types.js +4 -4
  78. package/dist/engine/core/viewport.js +36 -23
  79. package/dist/engine/input/PointerController.js +476 -447
  80. package/dist/engine/input/arrowHandles.js +12 -12
  81. package/dist/engine/input/gestures.d.ts +12 -1
  82. package/dist/engine/input/gestures.js +342 -251
  83. package/dist/engine/input/hoverCursor.js +1 -1
  84. package/dist/engine/input/keyboard.d.ts +9 -1
  85. package/dist/engine/input/keyboard.js +46 -27
  86. package/dist/engine/input/selectionHandles.js +50 -45
  87. package/dist/engine/input/types.js +1 -1
  88. package/dist/engine/render/rasterize.js +158 -86
  89. package/dist/engine/state.d.ts +6 -1
  90. package/dist/engine/state.js +17 -5
  91. package/dist/engine/text/layoutText.js +62 -43
  92. package/dist/engine/text/textMetrics.js +10 -8
  93. package/dist/engine/widgets.js +137 -101
  94. package/dist/fonts/interFont.js +68 -17
  95. package/dist/fonts/workspaceFonts.js +90 -32
  96. package/dist/i18n/labels.js +4 -4
  97. package/dist/i18n/language.js +4 -4
  98. package/dist/i18n/messages.js +1 -1
  99. package/dist/i18n/shortcuts.d.ts +12 -0
  100. package/dist/i18n/shortcuts.js +32 -18
  101. package/dist/settings/workspaceToolSettings.js +48 -32
  102. package/dist/tools/components/catalog.d.ts +11 -0
  103. package/dist/tools/components/catalog.js +270 -0
  104. package/dist/tools/components/grouping.d.ts +9 -0
  105. package/dist/tools/components/grouping.js +33 -0
  106. package/dist/tools/definitions.d.ts +19 -0
  107. package/dist/tools/definitions.js +147 -0
  108. package/dist/tools/executors.d.ts +7 -0
  109. package/dist/tools/executors.js +324 -0
  110. package/dist/tools/hostAdapter.d.ts +14 -0
  111. package/dist/tools/hostAdapter.js +40 -0
  112. package/dist/tools/index.d.ts +6 -0
  113. package/dist/tools/index.js +6 -0
  114. package/dist/tools/sceneSummary.d.ts +24 -0
  115. package/dist/tools/sceneSummary.js +170 -0
  116. package/dist/tools/sketchIntent.d.ts +17 -0
  117. package/dist/tools/sketchIntent.js +166 -0
  118. package/dist/tools/types.d.ts +54 -0
  119. package/dist/tools/types.js +11 -0
  120. package/package.json +7 -2
@@ -8,6 +8,17 @@
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
+ };
11
22
  import { isArrow, transformArrow } from './arrow.js';
12
23
  import { isBrushStroke, reshapeBrushStroke } from './brush.js';
13
24
  import { rotatedBoxBounds, unionRects, worldToBoxLocal, clampNumber } from './geometry.js';
@@ -15,7 +26,7 @@ import { applyMatrixToPoint, boxToWorldMatrix, degreesToRadians, normalizeDegree
15
26
  import { parsePathData, scalePathCommands, mirrorPathCommands, serializePathData } from './pathData.js';
16
27
  import { regeneratedPathCommands } from './shapePaths.js';
17
28
  import { MIN_OBJECT_SIZE } from './types.js';
18
- const HANDLE_DIRECTIONS = {
29
+ var HANDLE_DIRECTIONS = {
19
30
  nw: { x: -1, y: -1 },
20
31
  n: { x: 0, y: -1 },
21
32
  ne: { x: 1, y: -1 },
@@ -33,11 +44,11 @@ export function selectionFrameOf(shapes) {
33
44
  if (shapes.length === 0)
34
45
  return null;
35
46
  if (shapes.length === 1) {
36
- const [shape] = shapes;
47
+ var shape = shapes[0];
37
48
  return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
38
49
  }
39
- const union = unionRects(shapes.map((shape) => rotatedBoxBounds(shape)));
40
- return union ? { ...union, rotation: 0 } : null;
50
+ var union = unionRects(shapes.map(function (shape) { return rotatedBoxBounds(shape); }));
51
+ return union ? __assign(__assign({}, union), { rotation: 0 }) : null;
41
52
  }
42
53
  /** The centre of a frame in the world. */
43
54
  export function frameCenter(frame) {
@@ -47,29 +58,31 @@ export function frameCenter(frame) {
47
58
  * The frame that results from dragging `handle` to a world point.
48
59
  * `frame` is the frame when the drag began (not the one the last pointer move produced).
49
60
  */
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);
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);
54
67
  if (!local)
55
- return { ...frame, flipX: false, flipY: false };
56
- const { width, height } = frame;
68
+ return __assign(__assign({}, frame), { flipX: false, flipY: false });
69
+ var width = frame.width, height = frame.height;
57
70
  // How far the handle's edge is from the anchor (the opposite edge, or the centre), signed: negative means
58
71
  // the pointer has crossed the anchor.
59
- const extentX = direction.x === 0
72
+ var extentX = direction.x === 0
60
73
  ? width
61
74
  : options.fromCenter
62
75
  ? (local.x - width / 2) * direction.x * 2
63
76
  : (local.x - (direction.x > 0 ? 0 : width)) * direction.x;
64
- const extentY = direction.y === 0
77
+ var extentY = direction.y === 0
65
78
  ? height
66
79
  : options.fromCenter
67
80
  ? (local.y - height / 2) * direction.y * 2
68
81
  : (local.y - (direction.y > 0 ? 0 : height)) * direction.y;
69
- let signedWidth = extentX;
70
- let signedHeight = extentY;
82
+ var signedWidth = extentX;
83
+ var signedHeight = extentY;
71
84
  if (options.keepAspect && width > 0 && height > 0) {
72
- let scale;
85
+ var scale = void 0;
73
86
  if (direction.x !== 0 && direction.y !== 0) {
74
87
  scale = Math.max(Math.abs(extentX) / width, Math.abs(extentY) / height);
75
88
  }
@@ -79,14 +92,14 @@ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
79
92
  else {
80
93
  scale = Math.abs(extentY) / height;
81
94
  }
82
- const smallestScale = minimumSize / Math.min(width, height);
95
+ var smallestScale = minimumSize / Math.min(width, height);
83
96
  if (!options.allowFlip || scale < smallestScale)
84
97
  scale = Math.max(scale, smallestScale);
85
98
  signedWidth = (direction.x === 0 || extentX >= 0 ? 1 : -1) * width * scale;
86
99
  signedHeight = (direction.y === 0 || extentY >= 0 ? 1 : -1) * height * scale;
87
100
  }
88
- let flipX = false;
89
- let flipY = false;
101
+ var flipX = false;
102
+ var flipY = false;
90
103
  if (signedWidth < 0) {
91
104
  if (options.allowFlip)
92
105
  flipX = true;
@@ -99,22 +112,22 @@ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
99
112
  else
100
113
  signedHeight = minimumSize;
101
114
  }
102
- const newWidth = Math.max(minimumSize, Math.abs(signedWidth));
103
- const newHeight = Math.max(minimumSize, Math.abs(signedHeight));
115
+ var newWidth = Math.max(minimumSize, Math.abs(signedWidth));
116
+ var newHeight = Math.max(minimumSize, Math.abs(signedHeight));
104
117
  // The centre of the new box in the frame's own space: half an extent from the anchor, towards the handle.
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 });
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 });
110
123
  return {
111
124
  x: centerWorld.x - newWidth / 2,
112
125
  y: centerWorld.y - newHeight / 2,
113
126
  width: newWidth,
114
127
  height: newHeight,
115
128
  rotation: frame.rotation,
116
- flipX,
117
- flipY
129
+ flipX: flipX,
130
+ flipY: flipY
118
131
  };
119
132
  }
120
133
  /**
@@ -124,18 +137,21 @@ export function computeResizedFrame(frame, handle, pointerWorld, options = {}) {
124
137
  * is drawn again (its head keeps its size), text keeps its font size when it is resized from a side
125
138
  * (wrapping) and scales it from a corner.
126
139
  */
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 };
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 });
132
148
  switch (shape.type) {
133
149
  case 'path': {
134
150
  if (isArrow(shape)) {
135
151
  // The points of the arrow go where the box goes (mirrored by a flip), and the arrow is drawn again from them.
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;
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;
139
155
  if (flip.flipX)
140
156
  unitX = 1 - unitX;
141
157
  if (flip.flipY)
@@ -145,35 +161,35 @@ export function resizeShapeToBox(shape, box, flip = { flipX: false, flipY: false
145
161
  return transformArrow(shape, mapPoint);
146
162
  }
147
163
  // A flip toggles the mirror the shape already has.
148
- const flipX = shape.flipX !== flip.flipX;
149
- const flipY = shape.flipY !== flip.flipY;
164
+ var flipX = shape.flipX !== flip.flipX;
165
+ var flipY = shape.flipY !== flip.flipY;
150
166
  if (isBrushStroke(shape)) {
151
167
  // The line goes where the box goes (and is mirrored by this flip); the brush stays as wide as it was.
152
- const reshaped = reshapeBrushStroke(shape, { width, height, flipX: flip.flipX, flipY: flip.flipY });
153
- return { ...base, d: reshaped.d, ink: reshaped.ink, flipX, flipY };
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 });
154
170
  }
155
- const regenerated = regeneratedPathCommands(shape, width, height);
156
- let commands;
171
+ var regenerated = regeneratedPathCommands(shape, width, height);
172
+ var commands = void 0;
157
173
  if (regenerated) {
158
174
  // Rebuilt from its key, so the mirror the shape had is applied again.
159
175
  commands = mirrorPathCommands(regenerated, width, height, flipX, flipY);
160
176
  }
161
177
  else {
162
178
  // Scaled from the path it has, which already holds the earlier mirrors: only this flip is applied.
163
- const scaleX = shape.width > 0 ? width / shape.width : 1;
164
- const scaleY = shape.height > 0 ? height / shape.height : 1;
179
+ var scaleX = shape.width > 0 ? width / shape.width : 1;
180
+ var scaleY = shape.height > 0 ? height / shape.height : 1;
165
181
  commands = mirrorPathCommands(scalePathCommands(parsePathData(shape.d), scaleX, scaleY), width, height, flip.flipX, flip.flipY);
166
182
  }
167
- return { ...base, d: serializePathData(commands), flipX, flipY };
183
+ return __assign(__assign({}, base), { d: serializePathData(commands), flipX: flipX, flipY: flipY });
168
184
  }
169
185
  case 'text': {
170
- const text = shape;
186
+ var text = shape;
171
187
  if (textScale !== null && textScale > 0) {
172
188
  // A corner drag scales the letters with the box.
173
- return { ...base, fontSize: clampNumber(text.fontSize * textScale, 4, 600) };
189
+ return __assign(__assign({}, base), { fontSize: clampNumber(text.fontSize * textScale, 4, 600) });
174
190
  }
175
191
  // A side drag only sets the width the text wraps at.
176
- return { ...base, autoWidth: false };
192
+ return __assign(__assign({}, base), { autoWidth: false });
177
193
  }
178
194
  default:
179
195
  return base;
@@ -186,38 +202,38 @@ export function resizeShapeToBox(shape, box, flip = { flipX: false, flipY: false
186
202
  */
187
203
  export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
188
204
  if (shapes.length === 1) {
189
- const [shape] = shapes;
190
- const cornerTextScale = shape.type === 'text' && isCornerHandle && startFrame.width > 0 ? resized.width / startFrame.width : null;
205
+ var shape = shapes[0];
206
+ var cornerTextScale = shape.type === 'text' && isCornerHandle && startFrame.width > 0 ? resized.width / startFrame.width : null;
191
207
  return [
192
208
  resizeShapeToBox(shape, resized, { flipX: resized.flipX, flipY: resized.flipY }, cornerTextScale)
193
209
  ];
194
210
  }
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;
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;
200
216
  if (resized.flipX)
201
217
  unitX = 1 - unitX;
202
218
  if (resized.flipY)
203
219
  unitY = 1 - unitY;
204
220
  return { x: resized.x + unitX * resized.width, y: resized.y + unitY * resized.height };
205
221
  };
206
- return shapes.map((shape) => {
207
- const radians = degreesToRadians(shape.rotation);
208
- const cosine = Math.cos(radians);
209
- const sine = Math.sin(radians);
222
+ return shapes.map(function (shape) {
223
+ var radians = degreesToRadians(shape.rotation);
224
+ var cosine = Math.cos(radians);
225
+ var sine = Math.sin(radians);
210
226
  // The shape's own axes are stretched by the frame; the lengths along them give its new size.
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 });
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 });
216
232
  // A mirrored shape turns the other way.
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;
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;
221
237
  return resizeShapeToBox(shape, box, { flipX: resized.flipX, flipY: resized.flipY }, textScale);
222
238
  });
223
239
  }
@@ -226,26 +242,21 @@ export function applyFrameResize(shapes, startFrame, resized, isCornerHandle) {
226
242
  * turn (it is always upright): its points go round the point and it is drawn again between them.
227
243
  */
228
244
  export function rotateShapesAbout(shapes, pivot, deltaDegrees) {
229
- const radians = degreesToRadians(deltaDegrees);
230
- const cosine = Math.cos(radians);
231
- const sine = Math.sin(radians);
232
- return shapes.map((shape) => {
245
+ var radians = degreesToRadians(deltaDegrees);
246
+ var cosine = Math.cos(radians);
247
+ var sine = Math.sin(radians);
248
+ return shapes.map(function (shape) {
233
249
  if (isArrow(shape)) {
234
- return transformArrow(shape, (point) => ({
250
+ return transformArrow(shape, function (point) { return ({
235
251
  x: pivot.x + (point.x - pivot.x) * cosine - (point.y - pivot.y) * sine,
236
252
  y: pivot.y + (point.x - pivot.x) * sine + (point.y - pivot.y) * cosine
237
- }));
253
+ }); });
238
254
  }
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
- };
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) });
249
260
  });
250
261
  }
251
262
  /** The angle, in degrees, of the line from `center` to `point` (0 is to the right, growing clockwise on screen). */
@@ -99,6 +99,35 @@ export interface ArrowSpec {
99
99
  readonly start: Point;
100
100
  readonly end: Point;
101
101
  readonly bend: number;
102
+ /** What the start is tied to: set only while it is tied, so a free arrow has neither key. */
103
+ readonly startBinding?: ArrowBinding;
104
+ /** What the end (the head) is tied to: set only while it is tied. */
105
+ readonly endBinding?: ArrowBinding;
106
+ }
107
+ /**
108
+ * What one end of an arrow is tied to (the way tldraw ties its arrows): the end follows the shape when it is moved, stretched, turned
109
+ * or, for a text, when it grows. Either the end aims at the middle of the shape and rests where the line to the other end meets
110
+ * its outline (`center`), or it rests on one point of the outline (`edge`), given as a fraction of the shape's own box (0 to 1 across,
111
+ * 0 to 1 down, before the shape is turned) so that the point goes where the shape goes.
112
+ */
113
+ export type ArrowBinding = {
114
+ readonly targetId: ObjectId;
115
+ readonly kind: 'center';
116
+ } | {
117
+ readonly targetId: ObjectId;
118
+ readonly kind: 'edge';
119
+ readonly anchor: Point;
120
+ };
121
+ /** Which end of an arrow: the tail it starts from, or the end with the head. */
122
+ export type ArrowEnd = 'start' | 'end';
123
+ /**
124
+ * What the board shows while an end of an arrow is dragged over a shape it would be tied to if it were let go now: the shape, and
125
+ * the point (in the world) where the end would rest: a point of its outline for `edge`, its middle for `center`.
126
+ */
127
+ export interface ArrowBindHint {
128
+ readonly targetId: ObjectId;
129
+ readonly kind: ArrowBinding['kind'];
130
+ readonly point: Point;
102
131
  }
103
132
  /**
104
133
  * Anything drawn as an SVG path: freehand ink, arrows, triangles and the shapes of the library.
@@ -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 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;
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;
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,11 +5,22 @@
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
+ };
8
19
  import { clampNumber } from './geometry.js';
9
20
  import { MAX_ZOOM, MIN_ZOOM } from './types.js';
10
- export const INITIAL_VIEWPORT = { x: 0, y: 0, zoom: 1 };
21
+ export var INITIAL_VIEWPORT = { x: 0, y: 0, zoom: 1 };
11
22
  /** The zoom levels the zoom buttons and the menu step through. */
12
- export const ZOOM_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
23
+ export var ZOOM_STEPS = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
13
24
  export function clampZoom(zoom) {
14
25
  if (!Number.isFinite(zoom))
15
26
  return 1;
@@ -34,21 +45,21 @@ export function visibleWorldRect(viewport, viewSize) {
34
45
  }
35
46
  /** Changes the zoom and keeps the world point under `screenPoint` where it is (what the wheel and pinch do). */
36
47
  export function zoomAtPoint(viewport, screenPoint, nextZoom) {
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 };
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 };
40
51
  }
41
52
  export function panViewport(viewport, deltaX, deltaY) {
42
- return { ...viewport, x: viewport.x + deltaX, y: viewport.y + deltaY };
53
+ return __assign(__assign({}, viewport), { x: viewport.x + deltaX, y: viewport.y + deltaY });
43
54
  }
44
55
  /** The next step above (direction 1) or below (-1) the current zoom, or the same zoom at the end of the ladder. */
45
56
  export function nextZoomStep(zoom, direction) {
46
- const tolerance = 1e-6;
57
+ var tolerance = 1e-6;
47
58
  if (direction === 1) {
48
- const step = ZOOM_STEPS.find((candidate) => candidate > zoom + tolerance);
49
- return step ?? ZOOM_STEPS[ZOOM_STEPS.length - 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];
50
61
  }
51
- for (let index = ZOOM_STEPS.length - 1; index >= 0; index -= 1) {
62
+ for (var index = ZOOM_STEPS.length - 1; index >= 0; index -= 1) {
52
63
  if (ZOOM_STEPS[index] < zoom - tolerance)
53
64
  return ZOOM_STEPS[index];
54
65
  }
@@ -58,27 +69,29 @@ export function nextZoomStep(zoom, direction) {
58
69
  * The view that shows a rectangle of the world, centred, with room around it.
59
70
  * Never zooms in past `maxZoom` (a single small shape is not blown up to fill the board).
60
71
  */
61
- export function fitViewportToRect(rect, viewSize, padding = 48, maxZoom = 1) {
72
+ export function fitViewportToRect(rect, viewSize, padding, maxZoom) {
73
+ if (padding === void 0) { padding = 48; }
74
+ if (maxZoom === void 0) { maxZoom = 1; }
62
75
  if (viewSize.width <= 0 || viewSize.height <= 0)
63
76
  return INITIAL_VIEWPORT;
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 };
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 };
70
83
  }
71
84
  /** The CSS transform of the world layer. */
72
85
  export function viewportToCssTransform(viewport) {
73
- return `translate(${Number(viewport.x.toFixed(3))}px, ${Number(viewport.y.toFixed(3))}px) scale(${Number(viewport.zoom.toFixed(5))})`;
86
+ return "translate(".concat(Number(viewport.x.toFixed(3)), "px, ").concat(Number(viewport.y.toFixed(3)), "px) scale(").concat(Number(viewport.zoom.toFixed(5)), ")");
74
87
  }
75
88
  /** A viewport read from untrusted data: anything that is not a finite number falls back to the default. */
76
89
  export function sanitizeViewport(value) {
77
90
  if (!value || typeof value !== 'object')
78
91
  return INITIAL_VIEWPORT;
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 };
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 };
84
97
  }