@widgetic/canvas 0.5.39 → 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 (134) hide show
  1. package/README.md +7 -3
  2. package/dist/canvas/DomCanvas.svelte +7 -3
  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.d.ts +2 -0
  9. package/dist/canvas/chromeLayout.js +31 -17
  10. package/dist/canvas/eventScope.js +14 -10
  11. package/dist/canvas/host/CanvasHost.d.ts +6 -0
  12. package/dist/canvas/host/CanvasHost.js +1556 -1255
  13. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  14. package/dist/canvas/host/CanvasHostApi.js +25 -4
  15. package/dist/canvas/host/browserServices.js +116 -65
  16. package/dist/canvas/host/conversion.js +170 -82
  17. package/dist/canvas/host/hostObject.js +7 -7
  18. package/dist/canvas/host/pageEvents.js +4 -4
  19. package/dist/canvas/host/screenRects.js +31 -28
  20. package/dist/canvas/host/strokeSnap.js +143 -88
  21. package/dist/canvas/openMarks.js +2 -2
  22. package/dist/canvas/outsideClickDeselect.js +7 -6
  23. package/dist/canvas/panZoomPosition.js +2 -2
  24. package/dist/canvas/preferredTextFont.js +25 -13
  25. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  26. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  27. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  28. package/dist/canvas/toolbarPosition.js +2 -2
  29. package/dist/canvas/ui/CanvasContextMenu.svelte +69 -39
  30. package/dist/canvas/ui/CanvasHint.svelte +17 -4
  31. package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
  32. package/dist/canvas/ui/CanvasToolbar.svelte +27 -10
  33. package/dist/canvas/ui/ColorField.svelte +1 -1
  34. package/dist/canvas/ui/SelectionPanel.svelte +24 -20
  35. package/dist/canvas/ui/ShapesMenu.svelte +0 -2
  36. package/dist/canvas/ui/ToolButton.svelte +11 -3
  37. package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
  38. package/dist/canvas/ui/WidgetActions.svelte +1 -1
  39. package/dist/canvas/ui/ZoomControl.svelte +39 -4
  40. package/dist/canvas/ui/ZoomControl.svelte.d.ts +2 -2
  41. package/dist/canvas/ui/colorModel.js +32 -21
  42. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  43. package/dist/canvas/ui/floatingCard.d.ts +7 -5
  44. package/dist/canvas/ui/floatingCard.js +23 -21
  45. package/dist/canvas/ui/floatingLayer.js +6 -5
  46. package/dist/canvas/ui/keyHints.d.ts +5 -0
  47. package/dist/canvas/ui/keyHints.js +23 -7
  48. package/dist/canvas/ui/popoverSide.js +3 -2
  49. package/dist/canvas/ui/selectionTraits.js +40 -34
  50. package/dist/canvas/ui/sizeLabelVisibility.d.ts +5 -2
  51. package/dist/canvas/ui/sizeLabelVisibility.js +7 -6
  52. package/dist/canvas/ui/widgetSelectionPanel.d.ts +6 -0
  53. package/dist/canvas/ui/widgetSelectionPanel.js +9 -0
  54. package/dist/canvas/view/ObjectView.svelte +2 -1
  55. package/dist/canvas/view/SelectionOverlay.svelte +34 -14
  56. package/dist/canvas/view/erasingMarks.js +7 -7
  57. package/dist/canvas/view/geometry.d.ts +14 -4
  58. package/dist/canvas/view/geometry.js +103 -77
  59. package/dist/components/preferenceStorage.js +2 -2
  60. package/dist/engine/EngineCore.d.ts +4 -1
  61. package/dist/engine/EngineCore.js +801 -695
  62. package/dist/engine/codec/canvasDocument.js +173 -173
  63. package/dist/engine/codec/hostReadableKeys.js +1 -1
  64. package/dist/engine/core/arrange.js +38 -26
  65. package/dist/engine/core/arrow.d.ts +10 -3
  66. package/dist/engine/core/arrow.js +96 -75
  67. package/dist/engine/core/arrowBinding.d.ts +69 -0
  68. package/dist/engine/core/arrowBinding.js +344 -0
  69. package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
  70. package/dist/engine/core/arrowBindingRecords.js +141 -0
  71. package/dist/engine/core/brush.js +94 -67
  72. package/dist/engine/core/defaults.js +51 -90
  73. package/dist/engine/core/freehand.js +163 -147
  74. package/dist/engine/core/geometry.js +54 -47
  75. package/dist/engine/core/history.js +50 -33
  76. package/dist/engine/core/hitTest.d.ts +3 -0
  77. package/dist/engine/core/hitTest.js +83 -69
  78. package/dist/engine/core/matrix.js +20 -18
  79. package/dist/engine/core/pathData.js +210 -183
  80. package/dist/engine/core/rotationReset.js +6 -5
  81. package/dist/engine/core/scene.d.ts +3 -0
  82. package/dist/engine/core/scene.js +192 -129
  83. package/dist/engine/core/scribble.js +84 -59
  84. package/dist/engine/core/shapePaths.js +15 -12
  85. package/dist/engine/core/shapeTools.js +63 -72
  86. package/dist/engine/core/snapping.js +117 -65
  87. package/dist/engine/core/style.js +64 -31
  88. package/dist/engine/core/transform.js +94 -83
  89. package/dist/engine/core/types.d.ts +29 -0
  90. package/dist/engine/core/types.js +4 -4
  91. package/dist/engine/core/viewport.js +36 -23
  92. package/dist/engine/input/PointerController.js +476 -447
  93. package/dist/engine/input/arrowHandles.js +12 -12
  94. package/dist/engine/input/gestures.d.ts +12 -1
  95. package/dist/engine/input/gestures.js +342 -251
  96. package/dist/engine/input/hoverCursor.js +1 -1
  97. package/dist/engine/input/keyboard.d.ts +9 -1
  98. package/dist/engine/input/keyboard.js +46 -27
  99. package/dist/engine/input/selectionHandles.js +50 -45
  100. package/dist/engine/input/types.js +1 -1
  101. package/dist/engine/render/rasterize.js +158 -86
  102. package/dist/engine/state.d.ts +6 -1
  103. package/dist/engine/state.js +17 -5
  104. package/dist/engine/text/layoutText.js +62 -43
  105. package/dist/engine/text/textMetrics.js +10 -8
  106. package/dist/engine/widgets.js +137 -101
  107. package/dist/fonts/interFont.js +68 -17
  108. package/dist/fonts/workspaceFonts.js +90 -32
  109. package/dist/i18n/labels.js +6 -5
  110. package/dist/i18n/language.js +4 -4
  111. package/dist/i18n/messages.d.ts +6 -6
  112. package/dist/i18n/messages.js +7 -7
  113. package/dist/i18n/shortcuts.d.ts +12 -0
  114. package/dist/i18n/shortcuts.js +32 -18
  115. package/dist/settings/workspaceToolSettings.js +48 -32
  116. package/dist/tools/components/catalog.d.ts +11 -0
  117. package/dist/tools/components/catalog.js +270 -0
  118. package/dist/tools/components/grouping.d.ts +9 -0
  119. package/dist/tools/components/grouping.js +33 -0
  120. package/dist/tools/definitions.d.ts +19 -0
  121. package/dist/tools/definitions.js +147 -0
  122. package/dist/tools/executors.d.ts +7 -0
  123. package/dist/tools/executors.js +324 -0
  124. package/dist/tools/hostAdapter.d.ts +14 -0
  125. package/dist/tools/hostAdapter.js +40 -0
  126. package/dist/tools/index.d.ts +6 -0
  127. package/dist/tools/index.js +6 -0
  128. package/dist/tools/sceneSummary.d.ts +24 -0
  129. package/dist/tools/sceneSummary.js +170 -0
  130. package/dist/tools/sketchIntent.d.ts +17 -0
  131. package/dist/tools/sketchIntent.js +166 -0
  132. package/dist/tools/types.d.ts +54 -0
  133. package/dist/tools/types.js +11 -0
  134. package/package.json +7 -2
@@ -5,7 +5,7 @@
5
5
  in the middle of a selection that is stretched or turned, and the arrow of a text's corner while it is dragged.
6
6
 
7
7
  Figma "Selection Box": a 1.5 px ring outline, 8 px handles (background fill, 1.5 px ring border, 2 px corners) and a size
8
- label of inverse colours under the frame. It is drawn in the board's pixels rather than inside the world layer, so a line
8
+ label of inverse colours in the middle of the frame. It is drawn in the board's pixels rather than inside the world layer, so a line
9
9
  and a handle are the same size at every zoom. The engine finds the handles itself (selectionHandles.ts), so on the board
10
10
  nothing here takes the pointer.
11
11
 
@@ -15,7 +15,10 @@
15
15
 
16
16
  One selected arrow has no frame at all (the way tldraw shows one): its own thin outline, a round handle on each end and one in
17
17
  the middle that bends it. No corners, no turning dot, no size: an arrow is a line from here to there, and it points where its
18
- ends are. A handle grows under the pointer and while it is dragged.
18
+ ends are. A handle grows under the pointer and while it is dragged. The handle of an end that is tied to a shape is filled.
19
+
20
+ While an arrow is drawn or an end of it is dragged over a shape, the shape it would be tied to is outlined and a dot rests where
21
+ the end would stay: on the edge, or in the middle of the shape. The Arrow tool shows the same over a shape before anything is pressed.
19
22
 
20
23
  It is mounted twice when the page lays live widgets over the board. The board's copy draws everything but the frame of a
21
24
  selected widget card; the copy in the page's own layer (`layer="above-widgets"`) draws only that frame, above the live
@@ -34,6 +37,7 @@
34
37
  import type { CanvasHost } from '../host/CanvasHost.js';
35
38
  import { shouldShowRestingSizeLabel } from '../ui/sizeLabelVisibility.js';
36
39
  import {
40
+ arrowBindMarkOf,
37
41
  arrowOutlinePlacement,
38
42
  cssCursor,
39
43
  formatReadout,
@@ -98,14 +102,17 @@
98
102
  const arrow = singleArrowOf(host.engine.selectedShapes(), state.selectedIds);
99
103
  if (!arrow) return null;
100
104
  const positions = arrowHandlePositions(arrow, state.viewport);
101
- const handles: { id: ArrowHandleId; point: Point }[] = [
102
- { id: 'start', point: positions.start },
103
- { id: 'end', point: positions.end }
105
+ const handles: { id: ArrowHandleId; point: Point; bound: boolean }[] = [
106
+ { id: 'start', point: positions.start, bound: !!arrow.arrow.startBinding },
107
+ { id: 'end', point: positions.end, bound: !!arrow.arrow.endBinding }
104
108
  ];
105
- if (bendHandleAvailable(positions)) handles.push({ id: 'bend', point: positions.bend });
109
+ if (bendHandleAvailable(positions)) handles.push({ id: 'bend', point: positions.bend, bound: false });
106
110
  return { arrow, handles };
107
111
  });
108
112
 
113
+ // The shape an arrow end would be tied to, and the place on it: drawn while an arrow is drawn, or an end of it dragged, over a shape.
114
+ const bindMark = $derived(onBoard ? arrowBindMarkOf(state.scene, state.overlay.arrowBind, state.viewport) : null);
115
+
109
116
  const frame = $derived.by(() => {
110
117
  if (!frameVisible || arrowSelection) return null;
111
118
  // The scene and the selection are what the frame is made from: read them so it follows both.
@@ -199,7 +206,8 @@
199
206
  : []
200
207
  );
201
208
 
202
- // The size sits under the frame, at rest and while the frame is stretched, so it does not cover the widget.
209
+ // The size sits in the middle of the frame (the middle of the box round everything selected), where the figure of a stretch
210
+ // sits too. Once the stretch has its figure, that one pill says the size and the label is not drawn a second time on it.
203
211
  const sizeLabel = $derived.by(() => {
204
212
  if (
205
213
  !shouldShowRestingSizeLabel({
@@ -210,19 +218,17 @@
210
218
  ) {
211
219
  return null;
212
220
  }
213
- if (!frame) return null;
221
+ if (!frame || state.overlay.readout) return null;
214
222
  const text = formatReadout({ kind: 'size', width: Math.round(frame.world.width), height: Math.round(frame.world.height) });
215
223
  const at = restingSizeLabelPoint(frame.screen, text);
216
224
  if (!at) return null;
217
225
  return { x: at.x, y: at.y, text };
218
226
  });
219
227
 
228
+ // The figure of a stretch (the size) or of a turn (the angle) stands in the middle of the frame, in both cases.
220
229
  const readoutPoint = $derived.by(() => {
221
230
  if (!frame || !state.overlay.readout) return null;
222
- if (state.overlay.readout.kind === 'size') {
223
- return restingSizeLabelPoint(frame.screen, formatReadout(state.overlay.readout));
224
- }
225
- return { x: frame.screen.centerX, y: frame.screen.centerY };
231
+ return restingSizeLabelPoint(frame.screen, formatReadout(state.overlay.readout));
226
232
  });
227
233
 
228
234
  /** Where one handle sits on the frame, as the percentages of its width and height. */
@@ -288,6 +294,16 @@
288
294
  {@render arrowOutline(hoverArrow, true)}
289
295
  {/if}
290
296
 
297
+ <!-- The shape an arrow end would be tied to (outlined in 2 px, one more than a shape under the pointer) and the place the end would stay. -->
298
+ {#if bindMark}
299
+ <div class="absolute outline outline-2 outline-ring" style={screenFrameStyle(bindMark.frame)} data-canvas-bind-target></div>
300
+ <span
301
+ class="absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-[1.5px] border-background bg-ring"
302
+ style={layerPointStyle(bindMark.point)}
303
+ data-canvas-bind-dot={bindMark.kind}
304
+ ></span>
305
+ {/if}
306
+
291
307
  <!--
292
308
  What the marquee would take, outlined exactly as a unit under the pointer is (the same line of 1 px just outside the edge,
293
309
  the same band round an arrow). The boxes are two paths in the board's pixels, whatever their number; the one of the boxes
@@ -317,10 +333,13 @@
317
333
  ? 'size-3.5 bg-ring'
318
334
  : handle.id === 'bend'
319
335
  ? 'size-2 bg-background'
320
- : 'size-2.5 bg-background'}"
336
+ : handle.bound
337
+ ? 'size-2.5 bg-ring'
338
+ : 'size-2.5 bg-background'}"
321
339
  style={layerPointStyle(handle.point)}
322
340
  data-canvas-arrow-handle={handle.id}
323
341
  data-active={active}
342
+ data-bound={handle.bound}
324
343
  ></span>
325
344
  {/each}
326
345
  {/if}
@@ -337,6 +356,7 @@
337
356
  class="absolute box-border border-[1.5px] {dragging === 'resize' ? 'border-transparent' : 'border-ring'}"
338
357
  style={screenFrameStyle(frame.screen)}
339
358
  data-canvas-frame
359
+ data-canvas-selection-frame
340
360
  data-dragging={dragging}
341
361
  >
342
362
  {#if dragging === 'resize'}
@@ -417,7 +437,7 @@
417
437
  {/if}
418
438
 
419
439
  {#if readoutPoint && readoutText}
420
- <!-- The size of a stretch sits under the frame. The angle of a turn stays in the middle. -->
440
+ <!-- The size of a stretch and the angle of a turn both stand in the middle of the frame. -->
421
441
  <span
422
442
  class="absolute -translate-x-1/2 -translate-y-1/2 whitespace-nowrap rounded-sm bg-inverse px-1.5 py-0.5 text-xs font-medium tabular-nums text-inverse-foreground"
423
443
  style={layerPointStyle(readoutPoint)}
@@ -12,18 +12,18 @@
12
12
  */
13
13
  import { writable } from 'svelte/store';
14
14
  /** The set while nothing is marked: one shared set, so that "nothing marked" is the same value every time. */
15
- export const NOTHING_ERASED = new Set();
15
+ export var NOTHING_ERASED = new Set();
16
16
  export function createErasingMarks() {
17
- const { subscribe, set } = writable(NOTHING_ERASED);
18
- let listSeen = null;
19
- let current = NOTHING_ERASED;
17
+ var _a = writable(NOTHING_ERASED), subscribe = _a.subscribe, set = _a.set;
18
+ var listSeen = null;
19
+ var current = NOTHING_ERASED;
20
20
  return {
21
- subscribe,
22
- take(marked) {
21
+ subscribe: subscribe,
22
+ take: function (marked) {
23
23
  if (marked === listSeen)
24
24
  return;
25
25
  listSeen = marked;
26
- const next = marked.length === 0 ? NOTHING_ERASED : new Set(marked);
26
+ var next = marked.length === 0 ? NOTHING_ERASED : new Set(marked);
27
27
  // A store tells its subscribers of every `set` of an object, equal or not: nothing marked before and nothing now is no news.
28
28
  if (next === current)
29
29
  return;
@@ -6,7 +6,7 @@
6
6
  import type { ArrowObject } from '../../engine/core/arrow.js';
7
7
  import type { Scene } from '../../engine/core/scene.js';
8
8
  import type { SelectionFrame } from '../../engine/core/transform.js';
9
- import type { ObjectId, PaintProps, Point, Rect, SceneObject, ShapeObject, TextObject, Viewport } from '../../engine/core/types.js';
9
+ import type { ArrowBindHint, ObjectId, PaintProps, Point, Rect, SceneObject, ShapeObject, TextObject, Viewport } from '../../engine/core/types.js';
10
10
  import type { Readout } from '../../engine/state.js';
11
11
  /**
12
12
  * The CSS transform that puts a box where it stands in the world layer: its turn about its own middle, then its move.
@@ -93,11 +93,12 @@ export declare function screenFrameStyle(frame: ScreenFrame): string;
93
93
  */
94
94
  export declare function formatReadout(readout: Readout): string;
95
95
  /**
96
- * Where the size label sits at rest: centred under the bottom edge, clear of the frame
97
- * and of the rotation dot (21px under that edge). A label in the middle covers the widget.
96
+ * Where the size label sits: in the middle of the selection (the middle of the frame, whatever its turn, and of the box around
97
+ * all of it when several things are selected), where the figure of a stretch or a turn sits too, so the number is always at
98
+ * the same place and never moves off the thing it measures.
98
99
  */
99
100
  export declare function restingSizeLabelPoint(frame: ScreenFrame, _text: string): Point | null;
100
- /** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the size label goes. */
101
+ /** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the turning dot goes. */
101
102
  export declare function pointBelowFrame(frame: ScreenFrame, distance: number): Point;
102
103
  /**
103
104
  * The outline to draw around a unit (a shape, or a group with all of its members): the shape's own turned box for one
@@ -106,6 +107,15 @@ export declare function pointBelowFrame(frame: ScreenFrame, distance: number): P
106
107
  export declare function outlineOfUnit(scene: Scene, id: ObjectId): (Rect & {
107
108
  rotation: number;
108
109
  }) | null;
110
+ /** What the board shows while an arrow end would be tied to a shape: the shape's box on the screen, and where on the screen the end would rest. */
111
+ export interface ArrowBindMark {
112
+ frame: ScreenFrame;
113
+ point: Point;
114
+ /** `edge`: the end rests on the outline. `center`: the end aims at the middle of the shape. */
115
+ kind: ArrowBindHint['kind'];
116
+ }
117
+ /** The mark for the tie the engine says is in the offing, or null when there is none (or its shape is not on the board any more). */
118
+ export declare function arrowBindMarkOf(scene: Scene, hint: ArrowBindHint | null, viewport: Viewport): ArrowBindMark | null;
109
119
  /**
110
120
  * What is drawn round the units a marquee would take: the box of each shape or group as it stands on the screen, and each
111
121
  * arrow by itself (an arrow is outlined along its line, as it is when the pointer is over it).
@@ -3,6 +3,17 @@
3
3
  * which cursor the board shows. Plain functions of the engine's records and the viewport, free of Svelte and the DOM, so
4
4
  * a view only writes what they return and Node can test them.
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
+ };
6
17
  import { isArrow } from '../../engine/core/arrow.js';
7
18
  import { strokeDashArray } from '../../engine/core/defaults.js';
8
19
  import { boxToWorldMatrix, degreesToRadians, matrixToCss } from '../../engine/core/matrix.js';
@@ -17,23 +28,23 @@ import { fontShorthand } from '../../engine/text/layoutText.js';
17
28
  */
18
29
  export function placementCss(box) {
19
30
  if (!box.rotation)
20
- return `matrix(1, 0, 0, 1, ${Number(box.x.toFixed(5))}, ${Number(box.y.toFixed(5))})`;
31
+ return "matrix(1, 0, 0, 1, ".concat(Number(box.x.toFixed(5)), ", ").concat(Number(box.y.toFixed(5)), ")");
21
32
  return matrixToCss(boxToWorldMatrix(box));
22
33
  }
23
34
  /** The size of an object's box and the corner it turns about: what its style says apart from where it stands. */
24
35
  export function boxSizeCss(box) {
25
- return `left:0;top:0;width:${trim(box.width)}px;height:${trim(box.height)}px;transform-origin:0 0;`;
36
+ return "left:0;top:0;width:".concat(trim(box.width), "px;height:").concat(trim(box.height), "px;transform-origin:0 0;");
26
37
  }
27
38
  /** The CSS that puts an object's box where it belongs in the world layer: its size, and its turn about its own middle. */
28
39
  export function boxStyle(box) {
29
- return `${boxSizeCss(box)}transform:${placementCss(box)};`;
40
+ return "".concat(boxSizeCss(box), "transform:").concat(placementCss(box), ";");
30
41
  }
31
42
  /** What a text's style says apart from its box: the padding, the colours, the font, and how its lines sit in the box. */
32
43
  export function textBoxCss(text) {
33
- return `padding:${text.padding}px;background-color:${text.backgroundColor};color:${text.color};font:${fontShorthand(text)};line-height:${text.lineHeight};text-align:${text.align};${text.underline ? 'text-decoration:underline;' : ''}`;
44
+ return "padding:".concat(text.padding, "px;background-color:").concat(text.backgroundColor, ";color:").concat(text.color, ";font:").concat(fontShorthand(text), ";line-height:").concat(text.lineHeight, ";text-align:").concat(text.align, ";").concat(text.underline ? 'text-decoration:underline;' : '');
34
45
  }
35
46
  /** The fields of a record that say where an object stands; every other field says what it looks like. */
36
- const PLACEMENT_FIELDS = new Set(['x', 'y', 'rotation']);
47
+ var PLACEMENT_FIELDS = new Set(['x', 'y', 'rotation']);
37
48
  /**
38
49
  * True when two records of an object differ only in where they stand (its position and its turn).
39
50
  *
@@ -46,14 +57,14 @@ export function sameLook(first, second) {
46
57
  return true;
47
58
  if (first.type !== second.type)
48
59
  return false;
49
- const before = first;
50
- const after = second;
51
- for (const key in after) {
60
+ var before = first;
61
+ var after = second;
62
+ for (var key in after) {
52
63
  if (!PLACEMENT_FIELDS.has(key) && before[key] !== after[key])
53
64
  return false;
54
65
  }
55
66
  // A field that was dropped is a change too (a record with the same fields never takes this loop further).
56
- for (const key in before) {
67
+ for (var key in before) {
57
68
  if (!PLACEMENT_FIELDS.has(key) && !(key in after))
58
69
  return false;
59
70
  }
@@ -61,8 +72,8 @@ export function sameLook(first, second) {
61
72
  }
62
73
  /** A colour of `transparent` (or a stroke with no width) is "none" in SVG. */
63
74
  export function svgPaintOf(shape) {
64
- const hasStroke = shape.stroke !== 'transparent' && shape.strokeWidth > 0;
65
- const dash = hasStroke ? strokeDashArray(shape.strokeStyle, shape.strokeWidth) : null;
75
+ var hasStroke = shape.stroke !== 'transparent' && shape.strokeWidth > 0;
76
+ var dash = hasStroke ? strokeDashArray(shape.strokeStyle, shape.strokeWidth) : null;
66
77
  return {
67
78
  fill: shape.fill === 'transparent' ? 'none' : shape.fill,
68
79
  fillOpacity: shape.fillOpacity,
@@ -74,10 +85,10 @@ export function svgPaintOf(shape) {
74
85
  };
75
86
  }
76
87
  export function screenFrameOf(frame, viewport) {
77
- const center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
78
- const width = frame.width * viewport.zoom;
79
- const height = frame.height * viewport.zoom;
80
- return { left: center.x - width / 2, top: center.y - height / 2, width, height, rotation: frame.rotation, centerX: center.x, centerY: center.y };
88
+ var center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
89
+ var width = frame.width * viewport.zoom;
90
+ var height = frame.height * viewport.zoom;
91
+ return { left: center.x - width / 2, top: center.y - height / 2, width: width, height: height, rotation: frame.rotation, centerX: center.x, centerY: center.y };
81
92
  }
82
93
  /**
83
94
  * The CSS that places a box in a layer that covers the board, in pixels from the layer's top left corner.
@@ -86,14 +97,15 @@ export function screenFrameOf(frame, viewport) {
86
97
  * a physical distance from the left edge, and is not written with the start of the line.
87
98
  */
88
99
  export function layerBoxStyle(box) {
89
- const size = (box.width === undefined ? '' : `width:${trim(box.width)}px;`) + (box.height === undefined ? '' : `height:${trim(box.height)}px;`);
100
+ var size = (box.width === undefined ? '' : "width:".concat(trim(box.width), "px;")) + (box.height === undefined ? '' : "height:".concat(trim(box.height), "px;"));
90
101
  // rtl-ok: a place on the drawing, measured from the left edge of the layer on every screen
91
- return `left:${trim(box.left)}px;top:${trim(box.top)}px;${size}`;
102
+ return "left:".concat(trim(box.left), "px;top:").concat(trim(box.top), "px;").concat(size);
92
103
  }
93
104
  /** The CSS that puts a box of `width` by `height` (a square when only `width` is given) with its middle on a point of the layer that covers the board. */
94
- export function layerCenteredStyle(center, width, height = width) {
105
+ export function layerCenteredStyle(center, width, height) {
106
+ if (height === void 0) { height = width; }
95
107
  // rtl-ok: a place on the drawing, measured from the left edge of the layer on every screen
96
- return layerBoxStyle({ left: center.x - width / 2, top: center.y - height / 2, width, height });
108
+ return layerBoxStyle({ left: center.x - width / 2, top: center.y - height / 2, width: width, height: height });
97
109
  }
98
110
  /** The CSS that places a point of the layer that covers the board (the corner a label starts from). */
99
111
  export function layerPointStyle(point) {
@@ -104,35 +116,33 @@ export function layerPointStyle(point) {
104
116
  * on the screen, and the scale from the coordinates of its path to pixels.
105
117
  */
106
118
  export function arrowOutlinePlacement(box, viewport) {
107
- const corner = worldToScreen(viewport, { x: box.x, y: box.y });
119
+ var corner = worldToScreen(viewport, { x: box.x, y: box.y });
108
120
  return { style: layerBoxStyle({ left: corner.x, top: corner.y }), scale: viewport.zoom };
109
121
  }
110
122
  /** The CSS that places a screen frame in a layer that covers the board. */
111
123
  export function screenFrameStyle(frame) {
112
- const turn = frame.rotation === 0 ? '' : `transform:rotate(${trim(frame.rotation)}deg);`;
113
- return `${layerBoxStyle(frame)}${turn}`;
124
+ var turn = frame.rotation === 0 ? '' : "transform:rotate(".concat(trim(frame.rotation), "deg);");
125
+ return "".concat(layerBoxStyle(frame)).concat(turn);
114
126
  }
115
127
  /**
116
128
  * What the figure in the middle of a selection says: a size as `450 × 149`, an angle as `35°`. Numbers and signs, no
117
129
  * words, so it needs no translation (the page that shows it sets its direction to left to right, so the order holds).
118
130
  */
119
131
  export function formatReadout(readout) {
120
- return readout.kind === 'size' ? `${readout.width} × ${readout.height}` : `${readout.degrees}°`;
132
+ return readout.kind === 'size' ? "".concat(readout.width, " \u00D7 ").concat(readout.height) : "".concat(readout.degrees, "\u00B0");
121
133
  }
122
- /** Height of the size label (text-xs + vertical padding), so it clears the rotation dot. */
123
- const SIZE_LABEL_HEIGHT = 22;
124
134
  /**
125
- * Where the size label sits at rest: centred under the bottom edge, clear of the frame
126
- * and of the rotation dot (21px under that edge). A label in the middle covers the widget.
135
+ * Where the size label sits: in the middle of the selection (the middle of the frame, whatever its turn, and of the box around
136
+ * all of it when several things are selected), where the figure of a stretch or a turn sits too, so the number is always at
137
+ * the same place and never moves off the thing it measures.
127
138
  */
128
139
  export function restingSizeLabelPoint(frame, _text) {
129
- const belowRotationDot = 21 + 8 + SIZE_LABEL_HEIGHT / 2;
130
- return pointBelowFrame(frame, belowRotationDot);
140
+ return { x: frame.centerX, y: frame.centerY };
131
141
  }
132
- /** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the size label goes. */
142
+ /** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the turning dot goes. */
133
143
  export function pointBelowFrame(frame, distance) {
134
- const radians = degreesToRadians(frame.rotation);
135
- const reach = frame.height / 2 + distance;
144
+ var radians = degreesToRadians(frame.rotation);
145
+ var reach = frame.height / 2 + distance;
136
146
  return { x: frame.centerX - Math.sin(radians) * reach, y: frame.centerY + Math.cos(radians) * reach };
137
147
  }
138
148
  /**
@@ -140,18 +150,27 @@ export function pointBelowFrame(frame, distance) {
140
150
  * shape, the upright rectangle around the members for a group.
141
151
  */
142
152
  export function outlineOfUnit(scene, id) {
143
- const object = scene.find((candidate) => candidate.id === id);
153
+ var object = scene.find(function (candidate) { return candidate.id === id; });
144
154
  if (!object)
145
155
  return null;
146
156
  if (object.type !== 'group') {
147
- const shape = object;
157
+ var shape = object;
148
158
  return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
149
159
  }
150
- const bounds = boundsOfObjects(scene, [id]);
151
- return bounds ? { ...bounds, rotation: 0 } : null;
160
+ var bounds = boundsOfObjects(scene, [id]);
161
+ return bounds ? __assign(__assign({}, bounds), { rotation: 0 }) : null;
162
+ }
163
+ /** The mark for the tie the engine says is in the offing, or null when there is none (or its shape is not on the board any more). */
164
+ export function arrowBindMarkOf(scene, hint, viewport) {
165
+ if (!hint)
166
+ return null;
167
+ var outline = outlineOfUnit(scene, hint.targetId);
168
+ if (!outline)
169
+ return null;
170
+ return { frame: screenFrameOf(outline, viewport), point: worldToScreen(viewport, hint.point), kind: hint.kind };
152
171
  }
153
172
  /** What a marquee that takes nothing draws: the one shared empty answer, so a derived value that holds it stays the same. */
154
- export const NO_MARQUEE_OUTLINES = Object.freeze({ frames: Object.freeze([]), arrows: Object.freeze([]) });
173
+ export var NO_MARQUEE_OUTLINES = Object.freeze({ frames: Object.freeze([]), arrows: Object.freeze([]) });
155
174
  /**
156
175
  * The outlines of the units a marquee would take, in the order given (paint order). One pass over the scene finds the units,
157
176
  * so a marquee over the whole board costs one more pass for every group in it and no more for a shape.
@@ -159,32 +178,34 @@ export const NO_MARQUEE_OUTLINES = Object.freeze({ frames: Object.freeze([]), ar
159
178
  export function marqueeOutlinesOf(scene, ids, viewport) {
160
179
  if (ids.length === 0)
161
180
  return NO_MARQUEE_OUTLINES;
162
- const wanted = new Set(ids);
163
- const found = new Map();
164
- for (const object of scene) {
181
+ var wanted = new Set(ids);
182
+ var found = new Map();
183
+ for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
184
+ var object = scene_1[_i];
165
185
  if (wanted.has(object.id))
166
186
  found.set(object.id, object);
167
187
  }
168
- const frames = [];
169
- const arrows = [];
170
- for (const id of ids) {
171
- const object = found.get(id);
188
+ var frames = [];
189
+ var arrows = [];
190
+ for (var _a = 0, ids_1 = ids; _a < ids_1.length; _a++) {
191
+ var id = ids_1[_a];
192
+ var object = found.get(id);
172
193
  if (!object)
173
194
  continue;
174
195
  if (object.type === 'path' && isArrow(object)) {
175
196
  arrows.push(object);
176
197
  continue;
177
198
  }
178
- const outline = object.type === 'group' ? outlineOfUnit(scene, id) : { x: object.x, y: object.y, width: object.width, height: object.height, rotation: object.rotation };
199
+ var outline = object.type === 'group' ? outlineOfUnit(scene, id) : { x: object.x, y: object.y, width: object.width, height: object.height, rotation: object.rotation };
179
200
  if (outline)
180
- frames.push({ id, frame: screenFrameOf(outline, viewport) });
201
+ frames.push({ id: id, frame: screenFrameOf(outline, viewport) });
181
202
  }
182
- return frames.length === 0 && arrows.length === 0 ? NO_MARQUEE_OUTLINES : { frames, arrows };
203
+ return frames.length === 0 && arrows.length === 0 ? NO_MARQUEE_OUTLINES : { frames: frames, arrows: arrows };
183
204
  }
184
205
  /** What a marquee that takes nothing draws: the one shared empty answer. */
185
- export const NO_OUTLINE_PATHS = Object.freeze({ upright: '', turned: '' });
206
+ export var NO_OUTLINE_PATHS = Object.freeze({ upright: '', turned: '' });
186
207
  /** Half the width of the line, in pixels: the line is centred this far outside the edge, so it covers the pixel just outside it. */
187
- const OUTLINE_HALF_WIDTH = 0.5;
208
+ var OUTLINE_HALF_WIDTH = 0.5;
188
209
  /**
189
210
  * The paths of the outlines of some frames, in the order given.
190
211
  *
@@ -196,41 +217,46 @@ const OUTLINE_HALF_WIDTH = 0.5;
196
217
  export function outlinePathsOf(frames) {
197
218
  if (frames.length === 0)
198
219
  return NO_OUTLINE_PATHS;
199
- let upright = '';
200
- let turned = '';
201
- for (const { frame } of frames) {
220
+ var upright = '';
221
+ var turned = '';
222
+ var _loop_1 = function (frame) {
202
223
  if (!Number.isFinite(frame.left + frame.top + frame.width + frame.height + frame.rotation))
203
- continue;
224
+ return "continue";
204
225
  if (frame.rotation === 0) {
205
- const left = Math.round(frame.left);
206
- const top = Math.round(frame.top);
207
- const reachRight = Math.round(frame.left + frame.width) - left + 2 * OUTLINE_HALF_WIDTH;
208
- const reachDown = Math.round(frame.top + frame.height) - top + 2 * OUTLINE_HALF_WIDTH;
209
- upright += `M${left - OUTLINE_HALF_WIDTH} ${top - OUTLINE_HALF_WIDTH}h${reachRight}v${reachDown}h${-reachRight}z`;
210
- continue;
226
+ var left = Math.round(frame.left);
227
+ var top = Math.round(frame.top);
228
+ var reachRight = Math.round(frame.left + frame.width) - left + 2 * OUTLINE_HALF_WIDTH;
229
+ var reachDown = Math.round(frame.top + frame.height) - top + 2 * OUTLINE_HALF_WIDTH;
230
+ upright += "M".concat(left - OUTLINE_HALF_WIDTH, " ").concat(top - OUTLINE_HALF_WIDTH, "h").concat(reachRight, "v").concat(reachDown, "h").concat(-reachRight, "z");
231
+ return "continue";
211
232
  }
212
- const radians = degreesToRadians(frame.rotation);
213
- const cosine = Math.cos(radians);
214
- const sine = Math.sin(radians);
215
- const halfWidth = frame.width / 2 + OUTLINE_HALF_WIDTH;
216
- const halfHeight = frame.height / 2 + OUTLINE_HALF_WIDTH;
233
+ var radians = degreesToRadians(frame.rotation);
234
+ var cosine = Math.cos(radians);
235
+ var sine = Math.sin(radians);
236
+ var halfWidth = frame.width / 2 + OUTLINE_HALF_WIDTH;
237
+ var halfHeight = frame.height / 2 + OUTLINE_HALF_WIDTH;
217
238
  // The four corners of the box grown by half the width of the line, turned about the middle of the box (clockwise, as CSS turns).
218
- const corners = [
239
+ var corners = [
219
240
  [-halfWidth, -halfHeight],
220
241
  [halfWidth, -halfHeight],
221
242
  [halfWidth, halfHeight],
222
243
  [-halfWidth, halfHeight]
223
244
  ];
224
245
  turned += corners
225
- .map(([cornerX, cornerY], index) => {
226
- const x = frame.centerX + cornerX * cosine - cornerY * sine;
227
- const y = frame.centerY + cornerX * sine + cornerY * cosine;
228
- return `${index === 0 ? 'M' : 'L'}${Math.round(x * 100) / 100} ${Math.round(y * 100) / 100}`;
246
+ .map(function (_a, index) {
247
+ var cornerX = _a[0], cornerY = _a[1];
248
+ var x = frame.centerX + cornerX * cosine - cornerY * sine;
249
+ var y = frame.centerY + cornerX * sine + cornerY * cosine;
250
+ return "".concat(index === 0 ? 'M' : 'L').concat(Math.round(x * 100) / 100, " ").concat(Math.round(y * 100) / 100);
229
251
  })
230
252
  .join('');
231
253
  turned += 'z';
254
+ };
255
+ for (var _i = 0, frames_1 = frames; _i < frames_1.length; _i++) {
256
+ var frame = frames_1[_i].frame;
257
+ _loop_1(frame);
232
258
  }
233
- return upright === '' && turned === '' ? NO_OUTLINE_PATHS : { upright, turned };
259
+ return upright === '' && turned === '' ? NO_OUTLINE_PATHS : { upright: upright, turned: turned };
234
260
  }
235
261
  /** The rectangle around a shape as the board shows it: for a shape that is turned, the box that holds its corners. */
236
262
  export function upright(shape) {
@@ -240,23 +266,23 @@ export function upright(shape) {
240
266
  * The dot grid under the objects (Figma "Dot Grid": a dot every 24 world units, 2 pixels across, the ink colour at 30%).
241
267
  * It moves and scales with the world, and doubles its step while the dots would be closer than 12 pixels.
242
268
  */
243
- export const DOT_GRID_STEP = 24;
244
- const DOT_GRID_MIN_SCREEN_STEP = 12;
269
+ export var DOT_GRID_STEP = 24;
270
+ var DOT_GRID_MIN_SCREEN_STEP = 12;
245
271
  /**
246
272
  * One dot in the middle of a cell, as a gradient: it takes its colour from the page's `foreground` token (a data URL
247
273
  * cannot), stays two pixels across at every zoom, and costs one background layer however large the board is.
248
274
  */
249
- export const DOT_GRID_IMAGE = 'radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 0, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 1px, transparent 1.5px)';
275
+ export var DOT_GRID_IMAGE = 'radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 0, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 1px, transparent 1.5px)';
250
276
  export function dotGridStyle(viewport) {
251
- let step = DOT_GRID_STEP;
277
+ var step = DOT_GRID_STEP;
252
278
  while (step * viewport.zoom < DOT_GRID_MIN_SCREEN_STEP)
253
279
  step *= 2;
254
- const size = step * viewport.zoom;
280
+ var size = step * viewport.zoom;
255
281
  // The cells follow the world origin, and the dot is in the middle of each, as in the design.
256
- return `background-image:${DOT_GRID_IMAGE};background-size:${trim(size)}px ${trim(size)}px;background-position:${trim(viewport.x)}px ${trim(viewport.y)}px;`;
282
+ return "background-image:".concat(DOT_GRID_IMAGE, ";background-size:").concat(trim(size), "px ").concat(trim(size), "px;background-position:").concat(trim(viewport.x), "px ").concat(trim(viewport.y), "px;");
257
283
  }
258
284
  /** The pointer of the board has a name for the turning handle that CSS does not know: it is drawn as a small arc with an arrowhead. */
259
- const ROTATE_CURSOR_CSS = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%230f2010' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 11a8 8 0 1 0-2.3 5.7'/%3E%3Cpath d='M20 4v7h-7'/%3E%3C/svg%3E\") 12 12, grab";
285
+ var ROTATE_CURSOR_CSS = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%230f2010' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 11a8 8 0 1 0-2.3 5.7'/%3E%3Cpath d='M20 4v7h-7'/%3E%3C/svg%3E\") 12 12, grab";
260
286
  /** The CSS `cursor` for what the engine asked the board to show. */
261
287
  export function cssCursor(cursor) {
262
288
  return cursor === ROTATE_CURSOR ? ROTATE_CURSOR_CSS : cursor;
@@ -6,7 +6,7 @@
6
6
  * is written into the page's storage and a browser that several visitors share does not pass one visitor's choices on
7
7
  * to the next. The host does this once, before the canvas is shown.
8
8
  */
9
- let installedStorage = null;
9
+ var installedStorage = null;
10
10
  /** Installs the store the canvas keeps the visitor's choices in; `null` goes back to the browser's `localStorage`. */
11
11
  export function setCanvasPreferenceStorage(storage) {
12
12
  installedStorage = storage;
@@ -18,7 +18,7 @@ export function getCanvasPreferenceStorage() {
18
18
  try {
19
19
  return typeof localStorage === 'undefined' ? null : localStorage;
20
20
  }
21
- catch {
21
+ catch (_a) {
22
22
  // Reading `localStorage` itself throws where the browser blocks storage for the page.
23
23
  return null;
24
24
  }
@@ -118,8 +118,11 @@ export declare class EngineCore {
118
118
  /**
119
119
  * Puts a new scene on the board. `transient` is for the frames of a gesture (nothing is recorded), `push`
120
120
  * records one undo step and tells the host the board changed, `replace` changes the current step.
121
+ *
122
+ * Whatever the change was (a drag, a stretch, a word typed, an undo), the arrows that are tied to shapes are drawn again from
123
+ * where their shapes are now, in the same scene and the same step: nothing else has to know about the ties.
121
124
  */
122
- applyScene(next: Scene, mode?: 'transient' | 'push' | 'replace'): boolean;
125
+ applyScene(requested: Scene, mode?: 'transient' | 'push' | 'replace'): boolean;
123
126
  /**
124
127
  * Puts a scene on the board with no undo step and without telling the host that the board changed: a repair
125
128
  * of what was loaded (a name filled in), not an edit.