@widgetic/canvas 0.5.45 → 0.5.47

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 (137) hide show
  1. package/README.md +3 -2
  2. package/dist/canvas/DomCanvas.svelte +1 -2
  3. package/dist/canvas/autosaveScheduler.js +37 -89
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +7 -19
  7. package/dist/canvas/chromeLayout.js +19 -21
  8. package/dist/canvas/eventScope.js +10 -14
  9. package/dist/canvas/host/CanvasHost.d.ts +6 -5
  10. package/dist/canvas/host/CanvasHost.js +1664 -1861
  11. package/dist/canvas/host/CanvasHostApi.js +4 -19
  12. package/dist/canvas/host/boardFiles.js +35 -51
  13. package/dist/canvas/host/browserServices.js +108 -196
  14. package/dist/canvas/host/conversion.js +82 -170
  15. package/dist/canvas/host/hostObject.js +7 -7
  16. package/dist/canvas/host/nearCards.js +18 -21
  17. package/dist/canvas/host/pageEvents.js +5 -5
  18. package/dist/canvas/host/pauseCollector.d.ts +18 -0
  19. package/dist/canvas/host/pauseCollector.js +45 -0
  20. package/dist/canvas/host/pictureSaves.js +9 -11
  21. package/dist/canvas/host/screenRects.js +28 -31
  22. package/dist/canvas/host/storedPictures.js +149 -243
  23. package/dist/canvas/host/strokeSnap.js +88 -143
  24. package/dist/canvas/index.d.ts +1 -1
  25. package/dist/canvas/openMarks.js +2 -2
  26. package/dist/canvas/outsideClickDeselect.js +6 -7
  27. package/dist/canvas/panZoomPosition.js +2 -2
  28. package/dist/canvas/preferredTextFont.js +13 -25
  29. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  30. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  31. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  32. package/dist/canvas/toolbarPosition.js +2 -2
  33. package/dist/canvas/types.d.ts +7 -1
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
  35. package/dist/canvas/ui/CanvasHint.svelte +10 -9
  36. package/dist/canvas/ui/SelectionPanel.svelte +14 -12
  37. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
  38. package/dist/canvas/ui/ShapesMenu.svelte +6 -4
  39. package/dist/canvas/ui/ToolButton.svelte +7 -6
  40. package/dist/canvas/ui/colorModel.js +21 -32
  41. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  42. package/dist/canvas/ui/floatingCard.d.ts +28 -8
  43. package/dist/canvas/ui/floatingCard.js +48 -28
  44. package/dist/canvas/ui/floatingLayer.js +5 -6
  45. package/dist/canvas/ui/keyHints.js +9 -11
  46. package/dist/canvas/ui/popoverSide.js +2 -3
  47. package/dist/canvas/ui/selectionTraits.d.ts +8 -4
  48. package/dist/canvas/ui/selectionTraits.js +44 -58
  49. package/dist/canvas/view/CanvasStage.svelte +1 -1
  50. package/dist/canvas/view/SelectionOverlay.svelte +2 -2
  51. package/dist/canvas/view/erasingMarks.js +7 -7
  52. package/dist/canvas/view/geometry.d.ts +1 -1
  53. package/dist/canvas/view/geometry.js +72 -91
  54. package/dist/canvas/view/liftedScene.js +24 -36
  55. package/dist/canvas/view/mountedScene.js +76 -79
  56. package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
  57. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
  58. package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
  59. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
  60. package/dist/components/boardLoaderDelay.d.ts +39 -0
  61. package/dist/components/boardLoaderDelay.js +71 -0
  62. package/dist/components/input-controls/ColorIC.svelte +1 -1
  63. package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
  64. package/dist/components/preferenceStorage.js +2 -2
  65. package/dist/engine/EngineCore.d.ts +42 -10
  66. package/dist/engine/EngineCore.js +843 -916
  67. package/dist/engine/codec/canvasDocument.js +192 -155
  68. package/dist/engine/codec/hostReadableKeys.js +1 -1
  69. package/dist/engine/core/arrange.js +26 -38
  70. package/dist/engine/core/arrow.js +79 -92
  71. package/dist/engine/core/arrowBinding.js +98 -116
  72. package/dist/engine/core/arrowBindingRecords.js +23 -38
  73. package/dist/engine/core/brush.d.ts +24 -0
  74. package/dist/engine/core/brush.js +223 -103
  75. package/dist/engine/core/cameraMove.js +39 -51
  76. package/dist/engine/core/defaults.js +92 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.js +38 -55
  80. package/dist/engine/core/hitTest.js +68 -81
  81. package/dist/engine/core/matrix.js +18 -20
  82. package/dist/engine/core/pathData.js +183 -210
  83. package/dist/engine/core/rotationReset.js +5 -6
  84. package/dist/engine/core/scene.js +160 -224
  85. package/dist/engine/core/scribble.js +59 -84
  86. package/dist/engine/core/shapePaths.js +12 -15
  87. package/dist/engine/core/shapeTools.d.ts +23 -18
  88. package/dist/engine/core/shapeTools.js +104 -67
  89. package/dist/engine/core/snapping.js +65 -117
  90. package/dist/engine/core/style.d.ts +18 -2
  91. package/dist/engine/core/style.js +79 -80
  92. package/dist/engine/core/styleMemory.d.ts +88 -0
  93. package/dist/engine/core/styleMemory.js +189 -0
  94. package/dist/engine/core/transform.js +84 -95
  95. package/dist/engine/core/types.js +4 -4
  96. package/dist/engine/core/viewport.js +23 -36
  97. package/dist/engine/input/PointerController.js +513 -526
  98. package/dist/engine/input/arrowHandles.js +12 -12
  99. package/dist/engine/input/gestures.d.ts +8 -3
  100. package/dist/engine/input/gestures.js +378 -346
  101. package/dist/engine/input/hoverCursor.js +1 -1
  102. package/dist/engine/input/keyboard.js +42 -41
  103. package/dist/engine/input/selectionHandles.js +45 -50
  104. package/dist/engine/input/types.js +1 -1
  105. package/dist/engine/render/rasterize.js +86 -158
  106. package/dist/engine/state.js +6 -17
  107. package/dist/engine/text/layoutText.js +43 -62
  108. package/dist/engine/text/textMetrics.js +8 -10
  109. package/dist/engine/widgets.js +101 -137
  110. package/dist/fonts/interFont.js +30 -83
  111. package/dist/fonts/workspaceFonts.js +33 -92
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.js +4 -4
  114. package/dist/i18n/messages.js +1 -1
  115. package/dist/i18n/shortcuts.js +14 -14
  116. package/dist/index.d.ts +1 -1
  117. package/dist/poster/boardPlacement.d.ts +4 -1
  118. package/dist/poster/boardPlacement.js +34 -33
  119. package/dist/poster/boardPoster.js +58 -83
  120. package/dist/poster/paintBoardPoster.js +16 -39
  121. package/dist/poster/posterPictures.js +27 -43
  122. package/dist/settings/rememberedStyles.d.ts +22 -0
  123. package/dist/settings/rememberedStyles.js +47 -0
  124. package/dist/settings/rememberedTool.d.ts +50 -0
  125. package/dist/settings/rememberedTool.js +68 -0
  126. package/dist/settings/workspaceToolSettings.d.ts +25 -0
  127. package/dist/settings/workspaceToolSettings.js +38 -48
  128. package/dist/tools/components/catalog.js +64 -74
  129. package/dist/tools/components/grouping.js +6 -28
  130. package/dist/tools/definitions.js +5 -5
  131. package/dist/tools/executors.js +137 -169
  132. package/dist/tools/hostAdapter.js +10 -13
  133. package/dist/tools/sceneSummary.js +43 -57
  134. package/dist/tools/sketchIntent.js +13 -21
  135. package/dist/tools/styleArguments.js +19 -21
  136. package/dist/tools/types.js +1 -1
  137. package/package.json +5 -5
@@ -19,17 +19,6 @@
19
19
  * to; a hollow shape only near its line, as for any click on it) and how (`edge` when the pointer is near the outline, `center` when
20
20
  * it is further in; a line drawn by hand is always `edge`: it has no middle to aim at).
21
21
  */
22
- var __assign = (this && this.__assign) || function () {
23
- __assign = Object.assign || function(t) {
24
- for (var s, i = 1, n = arguments.length; i < n; i++) {
25
- s = arguments[i];
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
27
- t[p] = s[p];
28
- }
29
- return t;
30
- };
31
- return __assign.apply(this, arguments);
32
- };
33
22
  import { arrowPointsInWorld, isArrow, reshapeArrow } from './arrow.js';
34
23
  import { ARROW_ENDS, bindingOfEnd, canBeTiedTo, hasBindings } from './arrowBindingRecords.js';
35
24
  import { isBrushStroke } from './brush.js';
@@ -37,26 +26,26 @@ import { clampNumber, distanceBetween, pointInPolygon, worldToBoxLocal } from '.
37
26
  import { flattenedOutline, shapeContainsPoint } from './hitTest.js';
38
27
  import { applyMatrixToPoint, boxToWorldMatrix } from './matrix.js';
39
28
  /** How far from a shape (screen pixels) the pointer may be and still tie an end to it: the reach a click has on a line. */
40
- export var ARROW_BIND_REACH_PIXELS = 6;
29
+ export const ARROW_BIND_REACH_PIXELS = 6;
41
30
  /** Within this many screen pixels of the outline (inside or outside) an end rests on that point of the outline; further in it aims at the middle. */
42
- export var ARROW_EDGE_BAND_PIXELS = 14;
31
+ export const ARROW_EDGE_BAND_PIXELS = 14;
43
32
  /** The band never takes more than this fraction of the shorter side of the shape, so that a small shape still has a middle to aim at. */
44
- export var ARROW_EDGE_BAND_FRACTION = 0.25;
33
+ export const ARROW_EDGE_BAND_FRACTION = 0.25;
45
34
  /** Two points closer than this (world units) are the same place: an arrow that is there already is not drawn again. */
46
- var SAME_PLACE = 1e-6;
35
+ const SAME_PLACE = 1e-6;
47
36
  /** The straight pieces a quarter of a rounded corner is cut into when the outline of a rounded rectangle is walked. */
48
- var CORNER_STEPS = 8;
37
+ const CORNER_STEPS = 8;
49
38
  /** The radius of the corners of a rectangle with a roundness of 0 to 100 (100 is a pill): the one the board draws (`cornerRadiusOf`). */
50
39
  function cornerRadius(shape) {
51
40
  return (clampNumber(shape.roundness, 0, 100) / 100) * (Math.min(shape.width, shape.height) / 2);
52
41
  }
53
42
  /** The outline of a rectangle with rounded corners, clockwise on the screen from the left end of its top edge. */
54
43
  function roundedBoxLines(width, height, radius) {
55
- var reach = clampNumber(radius, 0, Math.min(width, height) / 2);
56
- var points = [];
57
- var corner = function (centerX, centerY, startAngle) {
58
- for (var step = 0; step <= CORNER_STEPS; step += 1) {
59
- var angle = startAngle + (step / CORNER_STEPS) * (Math.PI / 2);
44
+ const reach = clampNumber(radius, 0, Math.min(width, height) / 2);
45
+ const points = [];
46
+ const corner = (centerX, centerY, startAngle) => {
47
+ for (let step = 0; step <= CORNER_STEPS; step += 1) {
48
+ const angle = startAngle + (step / CORNER_STEPS) * (Math.PI / 2);
60
49
  points.push({ x: centerX + reach * Math.cos(angle), y: centerY + reach * Math.sin(angle) });
61
50
  }
62
51
  };
@@ -64,44 +53,44 @@ function roundedBoxLines(width, height, radius) {
64
53
  corner(width - reach, reach, Math.PI * 1.5);
65
54
  corner(width - reach, height - reach, 0);
66
55
  corner(reach, height - reach, Math.PI / 2);
67
- return { points: points, closed: true };
56
+ return { points, closed: true };
68
57
  }
69
58
  function outlineOf(shape) {
70
- var width = shape.width, height = shape.height;
59
+ const { width, height } = shape;
71
60
  switch (shape.type) {
72
61
  case 'ellipse':
73
- return { kind: 'ellipse', width: width, height: height };
62
+ return { kind: 'ellipse', width, height };
74
63
  case 'rect': {
75
- var radius = cornerRadius(shape);
76
- return radius > 0.5 ? { kind: 'lines', width: width, height: height, lines: [roundedBoxLines(width, height, radius)] } : { kind: 'box', width: width, height: height };
64
+ const radius = cornerRadius(shape);
65
+ return radius > 0.5 ? { kind: 'lines', width, height, lines: [roundedBoxLines(width, height, radius)] } : { kind: 'box', width, height };
77
66
  }
78
67
  case 'path': {
79
- var lines = flattenedOutline(shape.d).filter(function (outline) { return outline.points.length >= 2; });
80
- return lines.length > 0 ? { kind: 'lines', width: width, height: height, lines: lines } : { kind: 'box', width: width, height: height };
68
+ const lines = flattenedOutline(shape.d).filter((outline) => outline.points.length >= 2);
69
+ return lines.length > 0 ? { kind: 'lines', width, height, lines } : { kind: 'box', width, height };
81
70
  }
82
71
  default:
83
72
  // Text, pictures and widget cards are their box.
84
- return { kind: 'box', width: width, height: height };
73
+ return { kind: 'box', width, height };
85
74
  }
86
75
  }
87
76
  function closestOnSegment(point, first, second) {
88
- var deltaX = second.x - first.x;
89
- var deltaY = second.y - first.y;
90
- var lengthSquared = deltaX * deltaX + deltaY * deltaY;
77
+ const deltaX = second.x - first.x;
78
+ const deltaY = second.y - first.y;
79
+ const lengthSquared = deltaX * deltaX + deltaY * deltaY;
91
80
  if (lengthSquared < 1e-12)
92
81
  return first;
93
- var along = clampNumber(((point.x - first.x) * deltaX + (point.y - first.y) * deltaY) / lengthSquared, 0, 1);
82
+ const along = clampNumber(((point.x - first.x) * deltaX + (point.y - first.y) * deltaY) / lengthSquared, 0, 1);
94
83
  return { x: first.x + along * deltaX, y: first.y + along * deltaY };
95
84
  }
96
85
  /** The point of the outline nearest to a point (both in the coordinates of the box). */
97
86
  function nearestOnOutline(outline, point) {
98
- var width = outline.width, height = outline.height;
87
+ const { width, height } = outline;
99
88
  if (outline.kind === 'box') {
100
89
  if (point.x < 0 || point.x > width || point.y < 0 || point.y > height) {
101
90
  return { x: clampNumber(point.x, 0, width), y: clampNumber(point.y, 0, height) };
102
91
  }
103
92
  // Inside: the nearest of the four sides.
104
- var least = Math.min(point.x, width - point.x, point.y, height - point.y);
93
+ const least = Math.min(point.x, width - point.x, point.y, height - point.y);
105
94
  if (least === point.x)
106
95
  return { x: 0, y: point.y };
107
96
  if (least === width - point.x)
@@ -111,25 +100,24 @@ function nearestOnOutline(outline, point) {
111
100
  return { x: point.x, y: height };
112
101
  }
113
102
  if (outline.kind === 'ellipse') {
114
- var radiusX = Math.max(width / 2, 1e-6);
115
- var radiusY = Math.max(height / 2, 1e-6);
116
- var offsetX = point.x - width / 2;
117
- var offsetY = point.y - height / 2;
118
- var reach = Math.hypot(offsetX / radiusX, offsetY / radiusY);
103
+ const radiusX = Math.max(width / 2, 1e-6);
104
+ const radiusY = Math.max(height / 2, 1e-6);
105
+ const offsetX = point.x - width / 2;
106
+ const offsetY = point.y - height / 2;
107
+ const reach = Math.hypot(offsetX / radiusX, offsetY / radiusY);
119
108
  // The middle has no nearest point: the one at the right will do.
120
109
  if (reach < 1e-9)
121
110
  return { x: width, y: height / 2 };
122
111
  // The point of the ellipse on the line from the middle through the point.
123
112
  return { x: width / 2 + offsetX / reach, y: height / 2 + offsetY / reach };
124
113
  }
125
- var nearest = outline.lines[0].points[0];
126
- var nearestDistance = Infinity;
127
- for (var _i = 0, _a = outline.lines; _i < _a.length; _i++) {
128
- var line = _a[_i];
129
- var last = line.closed ? line.points.length : line.points.length - 1;
130
- for (var index = 0; index < last; index += 1) {
131
- var candidate = closestOnSegment(point, line.points[index], line.points[(index + 1) % line.points.length]);
132
- var distance = distanceBetween(point, candidate);
114
+ let nearest = outline.lines[0].points[0];
115
+ let nearestDistance = Infinity;
116
+ for (const line of outline.lines) {
117
+ const last = line.closed ? line.points.length : line.points.length - 1;
118
+ for (let index = 0; index < last; index += 1) {
119
+ const candidate = closestOnSegment(point, line.points[index], line.points[(index + 1) % line.points.length]);
120
+ const distance = distanceBetween(point, candidate);
133
121
  if (distance < nearestDistance) {
134
122
  nearest = candidate;
135
123
  nearestDistance = distance;
@@ -140,15 +128,15 @@ function nearestOnOutline(outline, point) {
140
128
  }
141
129
  /** Where the segment from `first` to `second` meets the segment from `a` to `b`, as the fraction of the first it is along; null when they do not meet. */
142
130
  function segmentMeeting(first, second, a, b) {
143
- var directionX = second.x - first.x;
144
- var directionY = second.y - first.y;
145
- var edgeX = b.x - a.x;
146
- var edgeY = b.y - a.y;
147
- var denominator = directionX * edgeY - directionY * edgeX;
131
+ const directionX = second.x - first.x;
132
+ const directionY = second.y - first.y;
133
+ const edgeX = b.x - a.x;
134
+ const edgeY = b.y - a.y;
135
+ const denominator = directionX * edgeY - directionY * edgeX;
148
136
  if (Math.abs(denominator) < 1e-12)
149
137
  return null;
150
- var along = ((a.x - first.x) * edgeY - (a.y - first.y) * edgeX) / denominator;
151
- var across = ((a.x - first.x) * directionY - (a.y - first.y) * directionX) / denominator;
138
+ const along = ((a.x - first.x) * edgeY - (a.y - first.y) * edgeX) / denominator;
139
+ const across = ((a.x - first.x) * directionY - (a.y - first.y) * directionX) / denominator;
152
140
  return along >= 0 && along <= 1 && across >= 0 && across <= 1 ? along : null;
153
141
  }
154
142
  /**
@@ -156,27 +144,26 @@ function segmentMeeting(first, second, a, b) {
156
144
  * point is inside the shape, or on it: the line meets nothing then.
157
145
  */
158
146
  function crossingTowardMiddle(outline, from) {
159
- var width = outline.width, height = outline.height;
160
- var middle = { x: width / 2, y: height / 2 };
147
+ const { width, height } = outline;
148
+ const middle = { x: width / 2, y: height / 2 };
161
149
  if (outline.kind === 'lines') {
162
- var nearestAlong = Infinity;
163
- for (var _i = 0, _a = outline.lines; _i < _a.length; _i++) {
164
- var line = _a[_i];
165
- var last = line.closed ? line.points.length : line.points.length - 1;
166
- for (var index = 0; index < last; index += 1) {
167
- var along = segmentMeeting(from, middle, line.points[index], line.points[(index + 1) % line.points.length]);
150
+ let nearestAlong = Infinity;
151
+ for (const line of outline.lines) {
152
+ const last = line.closed ? line.points.length : line.points.length - 1;
153
+ for (let index = 0; index < last; index += 1) {
154
+ const along = segmentMeeting(from, middle, line.points[index], line.points[(index + 1) % line.points.length]);
168
155
  if (along !== null && along < nearestAlong)
169
156
  nearestAlong = along;
170
157
  }
171
158
  }
172
159
  return nearestAlong === Infinity ? null : { x: from.x + (middle.x - from.x) * nearestAlong, y: from.y + (middle.y - from.y) * nearestAlong };
173
160
  }
174
- var radiusX = Math.max(width / 2, 1e-6);
175
- var radiusY = Math.max(height / 2, 1e-6);
176
- var offsetX = (from.x - middle.x) / radiusX;
177
- var offsetY = (from.y - middle.y) / radiusY;
161
+ const radiusX = Math.max(width / 2, 1e-6);
162
+ const radiusY = Math.max(height / 2, 1e-6);
163
+ const offsetX = (from.x - middle.x) / radiusX;
164
+ const offsetY = (from.y - middle.y) / radiusY;
178
165
  // How many times the box (or the ellipse) the point is from the middle: past 1 it is outside.
179
- var reach = outline.kind === 'box' ? Math.max(Math.abs(offsetX), Math.abs(offsetY)) : Math.hypot(offsetX, offsetY);
166
+ const reach = outline.kind === 'box' ? Math.max(Math.abs(offsetX), Math.abs(offsetY)) : Math.hypot(offsetX, offsetY);
180
167
  if (reach <= 1 + 1e-9)
181
168
  return null;
182
169
  return { x: middle.x + (from.x - middle.x) / reach, y: middle.y + (from.y - middle.y) / reach };
@@ -190,7 +177,7 @@ export function centerOfShape(shape) {
190
177
  }
191
178
  /** The point of the outline of a shape that an `edge` tie rests on, in the world. */
192
179
  export function edgePointOf(shape, anchor) {
193
- var local = { x: anchor.x * shape.width, y: anchor.y * shape.height };
180
+ const local = { x: anchor.x * shape.width, y: anchor.y * shape.height };
194
181
  // Put back on the outline: a shape that was rebuilt (a rounded corner, a regenerated path) may have moved it a little.
195
182
  return toWorld(shape, nearestOnOutline(outlineOf(shape), local));
196
183
  }
@@ -199,15 +186,15 @@ export function edgePointOf(shape, anchor) {
199
186
  * from inside the shape (or from the middle), so that it still points at it.
200
187
  */
201
188
  export function centerCrossingOf(shape, aim) {
202
- var local = worldToBoxLocal(shape, aim);
203
- var crossing = local ? crossingTowardMiddle(outlineOf(shape), local) : null;
189
+ const local = worldToBoxLocal(shape, aim);
190
+ const crossing = local ? crossingTowardMiddle(outlineOf(shape), local) : null;
204
191
  return crossing ? toWorld(shape, crossing) : centerOfShape(shape);
205
192
  }
206
193
  /** The shape an arrow's tie holds to, or null when there is none to hold to (it is gone, or an arrow cannot be tied to it). */
207
194
  function targetOf(arrow, binding, lookup) {
208
195
  if (!binding || binding.targetId === arrow.id)
209
196
  return null;
210
- var target = lookup(binding.targetId);
197
+ const target = lookup(binding.targetId);
211
198
  return target && canBeTiedTo(target) ? target : null;
212
199
  }
213
200
  /**
@@ -217,14 +204,13 @@ function targetOf(arrow, binding, lookup) {
217
204
  export function positionBoundArrow(arrow, lookup) {
218
205
  if (!hasBindings(arrow.arrow))
219
206
  return arrow;
220
- var current = arrowPointsInWorld(arrow);
221
- var targets = { start: null, end: null };
222
- var bindings = { start: null, end: null };
223
- var cut = {};
224
- for (var _i = 0, ARROW_ENDS_1 = ARROW_ENDS; _i < ARROW_ENDS_1.length; _i++) {
225
- var end = ARROW_ENDS_1[_i];
226
- var binding = bindingOfEnd(arrow.arrow, end);
227
- var target = targetOf(arrow, binding, lookup);
207
+ const current = arrowPointsInWorld(arrow);
208
+ const targets = { start: null, end: null };
209
+ const bindings = { start: null, end: null };
210
+ const cut = {};
211
+ for (const end of ARROW_ENDS) {
212
+ const binding = bindingOfEnd(arrow.arrow, end);
213
+ const target = targetOf(arrow, binding, lookup);
228
214
  if (binding && target) {
229
215
  bindings[end] = binding;
230
216
  targets[end] = target;
@@ -234,45 +220,42 @@ export function positionBoundArrow(arrow, lookup) {
234
220
  }
235
221
  }
236
222
  // What the line to the far end is drawn to: its place on the outline, the middle of its shape, or its own place when it is free.
237
- var lookedAt = function (end) {
238
- var target = targets[end];
239
- var binding = bindings[end];
223
+ const lookedAt = (end) => {
224
+ const target = targets[end];
225
+ const binding = bindings[end];
240
226
  if (!target || !binding)
241
227
  return current[end];
242
228
  return binding.kind === 'edge' ? edgePointOf(target, binding.anchor) : centerOfShape(target);
243
229
  };
244
- var placed = { start: current.start, end: current.end };
245
- for (var _a = 0, ARROW_ENDS_2 = ARROW_ENDS; _a < ARROW_ENDS_2.length; _a++) {
246
- var end = ARROW_ENDS_2[_a];
247
- var target = targets[end];
248
- var binding = bindings[end];
230
+ const placed = { start: current.start, end: current.end };
231
+ for (const end of ARROW_ENDS) {
232
+ const target = targets[end];
233
+ const binding = bindings[end];
249
234
  if (!target || !binding)
250
235
  continue;
251
236
  placed[end] = binding.kind === 'edge' ? edgePointOf(target, binding.anchor) : centerCrossingOf(target, lookedAt(end === 'start' ? 'end' : 'start'));
252
237
  }
253
- var moved = ARROW_ENDS.some(function (end) { return distanceBetween(placed[end], current[end]) > SAME_PLACE; });
238
+ const moved = ARROW_ENDS.some((end) => distanceBetween(placed[end], current[end]) > SAME_PLACE);
254
239
  if (!moved && Object.keys(cut).length === 0)
255
240
  return arrow;
256
- return reshapeArrow(arrow, __assign({ start: placed.start, end: placed.end }, cut));
241
+ return reshapeArrow(arrow, { start: placed.start, end: placed.end, ...cut });
257
242
  }
258
243
  /**
259
244
  * The scene with every tied arrow where its ties say. The very same array when none has to move (the engine runs this over every
260
245
  * scene it is given, so that it must cost nothing when no arrow is tied, and must not make a change out of nothing).
261
246
  */
262
247
  export function reconcileArrowBindings(scene) {
263
- if (!scene.some(function (object) { return object.type === 'path' && !!object.arrow && hasBindings(object.arrow); }))
248
+ if (!scene.some((object) => object.type === 'path' && !!object.arrow && hasBindings(object.arrow)))
264
249
  return scene;
265
- var index = new Map();
266
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
267
- var object = scene_1[_i];
250
+ const index = new Map();
251
+ for (const object of scene)
268
252
  index.set(object.id, object);
269
- }
270
- var lookup = function (id) { return index.get(id); };
271
- var changed = false;
272
- var next = scene.map(function (object) {
253
+ const lookup = (id) => index.get(id);
254
+ let changed = false;
255
+ const next = scene.map((object) => {
273
256
  if (object.type !== 'path' || !isArrow(object) || !hasBindings(object.arrow))
274
257
  return object;
275
- var placed = positionBoundArrow(object, lookup);
258
+ const placed = positionBoundArrow(object, lookup);
276
259
  if (placed !== object)
277
260
  changed = true;
278
261
  return placed;
@@ -285,7 +268,7 @@ function edgeBandOf(shape, zoom) {
285
268
  }
286
269
  /** Whether a point is inside a shape, a hollow one included (the way a click is not: a click on the empty middle of a frame reaches what lies under it). */
287
270
  function interiorContains(shape, point) {
288
- var local = worldToBoxLocal(shape, point);
271
+ const local = worldToBoxLocal(shape, point);
289
272
  if (!local)
290
273
  return false;
291
274
  switch (shape.type) {
@@ -294,7 +277,7 @@ function interiorContains(shape, point) {
294
277
  case 'ellipse':
295
278
  return Math.hypot((local.x - shape.width / 2) / Math.max(shape.width / 2, 1e-6), (local.y - shape.height / 2) / Math.max(shape.height / 2, 1e-6)) <= 1;
296
279
  case 'path':
297
- return flattenedOutline(shape.d).some(function (outline) { return outline.points.length >= 3 && pointInPolygon(local, outline.points); });
280
+ return flattenedOutline(shape.d).some((outline) => outline.points.length >= 3 && pointInPolygon(local, outline.points));
298
281
  default:
299
282
  return false;
300
283
  }
@@ -307,13 +290,13 @@ function interiorContains(shape, point) {
307
290
  * all), so the end rests on the point of the stroke that is nearest to the pointer and stays at that place of the line.
308
291
  */
309
292
  function tieOnShape(shape, point, zoom) {
310
- var local = worldToBoxLocal(shape, point);
293
+ const local = worldToBoxLocal(shape, point);
311
294
  if (!local)
312
295
  return null;
313
- var nearest = nearestOnOutline(outlineOf(shape), local);
296
+ const nearest = nearestOnOutline(outlineOf(shape), local);
314
297
  if (isBrushStroke(shape) || distanceBetween(local, nearest) <= edgeBandOf(shape, zoom)) {
315
- var anchor = { x: clampNumber(nearest.x / Math.max(shape.width, 1e-6), 0, 1), y: clampNumber(nearest.y / Math.max(shape.height, 1e-6), 0, 1) };
316
- return { binding: { targetId: shape.id, kind: 'edge', anchor: anchor }, hint: { targetId: shape.id, kind: 'edge', point: toWorld(shape, nearest) } };
298
+ const anchor = { x: clampNumber(nearest.x / Math.max(shape.width, 1e-6), 0, 1), y: clampNumber(nearest.y / Math.max(shape.height, 1e-6), 0, 1) };
299
+ return { binding: { targetId: shape.id, kind: 'edge', anchor }, hint: { targetId: shape.id, kind: 'edge', point: toWorld(shape, nearest) } };
317
300
  }
318
301
  return { binding: { targetId: shape.id, kind: 'center' }, hint: { targetId: shape.id, kind: 'center', point: centerOfShape(shape) } };
319
302
  }
@@ -324,26 +307,25 @@ function tieOnShape(shape, point, zoom) {
324
307
  * middle of a hollow shape taken as the shape. Null when the pointer is over nothing of the kind.
325
308
  */
326
309
  export function pickArrowBinding(scene, point, options) {
327
- var _a, _b;
328
- var zoom = Math.max(options.zoom, 1e-6);
329
- var reach = ARROW_BIND_REACH_PIXELS / zoom;
330
- for (var position = scene.length - 1; position >= 0; position -= 1) {
331
- var object = scene[position];
332
- if (!canBeTiedTo(object) || ((_a = options.ignore) === null || _a === void 0 ? void 0 : _a.has(object.id)))
310
+ const zoom = Math.max(options.zoom, 1e-6);
311
+ const reach = ARROW_BIND_REACH_PIXELS / zoom;
312
+ for (let position = scene.length - 1; position >= 0; position -= 1) {
313
+ const object = scene[position];
314
+ if (!canBeTiedTo(object) || options.ignore?.has(object.id))
333
315
  continue;
334
316
  if (!shapeContainsPoint(object, point, reach))
335
317
  continue;
336
- var pick = tieOnShape(object, point, zoom);
318
+ const pick = tieOnShape(object, point, zoom);
337
319
  if (pick)
338
320
  return pick;
339
321
  }
340
- for (var position = scene.length - 1; position >= 0; position -= 1) {
341
- var object = scene[position];
342
- if (!canBeTiedTo(object) || ((_b = options.ignore) === null || _b === void 0 ? void 0 : _b.has(object.id)))
322
+ for (let position = scene.length - 1; position >= 0; position -= 1) {
323
+ const object = scene[position];
324
+ if (!canBeTiedTo(object) || options.ignore?.has(object.id))
343
325
  continue;
344
326
  if (!interiorContains(object, point))
345
327
  continue;
346
- var pick = tieOnShape(object, point, zoom);
328
+ const pick = tieOnShape(object, point, zoom);
347
329
  if (pick)
348
330
  return pick;
349
331
  }
@@ -7,23 +7,11 @@
7
7
  * every function that makes a spec writes `startBinding` and `endBinding` only while they are set, so an arrow that is tied to
8
8
  * nothing is the very same record it was before ties existed.
9
9
  */
10
- var __assign = (this && this.__assign) || function () {
11
- __assign = Object.assign || function(t) {
12
- for (var s, i = 1, n = arguments.length; i < n; i++) {
13
- s = arguments[i];
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
15
- t[p] = s[p];
16
- }
17
- return t;
18
- };
19
- return __assign.apply(this, arguments);
20
- };
21
10
  /** The two ends of an arrow, the tail first. */
22
- export var ARROW_ENDS = Object.freeze(['start', 'end']);
11
+ export const ARROW_ENDS = Object.freeze(['start', 'end']);
23
12
  /** The tie of one end of an arrow, or null while that end is free. */
24
13
  export function bindingOfEnd(spec, end) {
25
- var _a;
26
- return (_a = (end === 'start' ? spec.startBinding : spec.endBinding)) !== null && _a !== void 0 ? _a : null;
14
+ return (end === 'start' ? spec.startBinding : spec.endBinding) ?? null;
27
15
  }
28
16
  /** Whether either end of an arrow is tied. */
29
17
  export function hasBindings(spec) {
@@ -42,12 +30,11 @@ export function sameBinding(first, second) {
42
30
  }
43
31
  /** The spec with its ties changed. The same spec when the change says what it says already. */
44
32
  export function withBindings(spec, change) {
45
- var _a, _b, _c, _d;
46
- var start = 'startBinding' in change ? ((_a = change.startBinding) !== null && _a !== void 0 ? _a : null) : ((_b = spec.startBinding) !== null && _b !== void 0 ? _b : null);
47
- var end = 'endBinding' in change ? ((_c = change.endBinding) !== null && _c !== void 0 ? _c : null) : ((_d = spec.endBinding) !== null && _d !== void 0 ? _d : null);
33
+ const start = 'startBinding' in change ? (change.startBinding ?? null) : (spec.startBinding ?? null);
34
+ const end = 'endBinding' in change ? (change.endBinding ?? null) : (spec.endBinding ?? null);
48
35
  if (sameBinding(start, spec.startBinding) && sameBinding(end, spec.endBinding))
49
36
  return spec;
50
- return __assign(__assign({ start: spec.start, end: spec.end, bend: spec.bend }, (start ? { startBinding: start } : {})), (end ? { endBinding: end } : {}));
37
+ return { start: spec.start, end: spec.end, bend: spec.bend, ...(start ? { startBinding: start } : {}), ...(end ? { endBinding: end } : {}) };
51
38
  }
52
39
  /**
53
40
  * Whether an arrow can be tied to this object: a shape that has an outline, which is not an arrow or a group. A line drawn by hand
@@ -74,17 +61,17 @@ export function arrowSpecOf(object) {
74
61
  }
75
62
  /** The same arrow with its spec replaced, or the very same object when the spec did not change. */
76
63
  function withSpec(object, spec) {
77
- return spec === object.arrow ? object : __assign(__assign({}, object), { arrow: spec });
64
+ return spec === object.arrow ? object : { ...object, arrow: spec };
78
65
  }
79
66
  /**
80
67
  * An arrow that is carried, stretched or turned together with some shapes: the ties to shapes that are not among them are cut (an
81
68
  * arrow that is moved by itself comes off the shapes it was tied to, the way it does in tldraw). The same object when nothing is cut.
82
69
  */
83
70
  export function releaseUnmovedEnds(object, moving) {
84
- var spec = arrowSpecOf(object);
71
+ const spec = arrowSpecOf(object);
85
72
  if (!spec || !hasBindings(spec))
86
73
  return object;
87
- var change = {};
74
+ const change = {};
88
75
  if (spec.startBinding && !moving.has(spec.startBinding.targetId))
89
76
  change.startBinding = null;
90
77
  if (spec.endBinding && !moving.has(spec.endBinding.targetId))
@@ -96,12 +83,12 @@ export function releaseUnmovedEnds(object, moving) {
96
83
  * alone is a free arrow). `idMap` says which id was copied to which.
97
84
  */
98
85
  export function remapEnds(object, idMap) {
99
- var spec = arrowSpecOf(object);
86
+ const spec = arrowSpecOf(object);
100
87
  if (!spec || !hasBindings(spec))
101
88
  return object;
102
- var remap = function (binding) {
103
- var copyId = binding ? idMap.get(binding.targetId) : undefined;
104
- return binding && copyId ? __assign(__assign({}, binding), { targetId: copyId }) : null;
89
+ const remap = (binding) => {
90
+ const copyId = binding ? idMap.get(binding.targetId) : undefined;
91
+ return binding && copyId ? { ...binding, targetId: copyId } : null;
105
92
  };
106
93
  return withSpec(object, withBindings(spec, { startBinding: remap(spec.startBinding), endBinding: remap(spec.endBinding) }));
107
94
  }
@@ -111,32 +98,30 @@ export function remapEnds(object, idMap) {
111
98
  * is cut. The very same array when nothing is cut.
112
99
  */
113
100
  export function dropDanglingBindings(scene) {
114
- if (!scene.some(function (object) {
115
- var spec = arrowSpecOf(object);
101
+ if (!scene.some((object) => {
102
+ const spec = arrowSpecOf(object);
116
103
  return !!spec && hasBindings(spec);
117
104
  })) {
118
105
  return scene;
119
106
  }
120
- var index = new Map();
121
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
122
- var object = scene_1[_i];
107
+ const index = new Map();
108
+ for (const object of scene)
123
109
  index.set(object.id, object);
124
- }
125
- var changed = false;
126
- var next = scene.map(function (object) {
127
- var spec = arrowSpecOf(object);
110
+ let changed = false;
111
+ const next = scene.map((object) => {
112
+ const spec = arrowSpecOf(object);
128
113
  if (!spec || !hasBindings(spec))
129
114
  return object;
130
- var holds = function (binding) {
131
- var target = binding ? index.get(binding.targetId) : undefined;
115
+ const holds = (binding) => {
116
+ const target = binding ? index.get(binding.targetId) : undefined;
132
117
  return !!binding && !!target && target.id !== object.id && canBeTiedTo(target);
133
118
  };
134
- var change = {};
119
+ const change = {};
135
120
  if (spec.startBinding && !holds(spec.startBinding))
136
121
  change.startBinding = null;
137
122
  if (spec.endBinding && !holds(spec.endBinding))
138
123
  change.endBinding = null;
139
- var cut = withSpec(object, withBindings(spec, change));
124
+ const cut = withSpec(object, withBindings(spec, change));
140
125
  if (cut !== object)
141
126
  changed = true;
142
127
  return cut;
@@ -35,6 +35,22 @@ export declare function brushCentreline(shape: BrushPath): Point[];
35
35
  * Always something to draw: a line the outline cannot be made of (one point, or none) is a dot.
36
36
  */
37
37
  export declare function brushOutlineData(ink: BrushInk, strokeWidth: number): string;
38
+ /**
39
+ * The pressure a straight line (Shift) is drawn at when the device reports none (a mouse, a finger): the one a stroke drawn by
40
+ * hand settles at as soon as the hand moves at an ordinary pace. The straight line is then as thick as the lines drawn by hand
41
+ * beside it (a width of 3 is about 3 px on the screen, and not the 6.6 px of a pen pressing at its middle), and as thick at one
42
+ * end as at the other.
43
+ */
44
+ export declare const STRAIGHT_LINE_PRESSURE = 0;
45
+ /** A stretch of a stroke's line held straight (Shift held while drawing): a straight line of one even width between two samples. */
46
+ export interface BrushStraightSpan {
47
+ /** The index of the sample the stretch begins at: where the pointer was when Shift went down. */
48
+ from: number;
49
+ /** The index of the sample the stretch ends at: where the pointer was when Shift went up, or where it is now. */
50
+ to: number;
51
+ /** The pressure (0 to 1) it is drawn at all along; `STRAIGHT_LINE_PRESSURE` when it is not given. */
52
+ pressure?: number;
53
+ }
38
54
  export interface BrushStrokeOptions {
39
55
  createId?: (prefix: string) => ObjectId;
40
56
  /** The colour of the line. */
@@ -53,6 +69,14 @@ export interface BrushStrokeOptions {
53
69
  * the hand even while it is still being drawn (the first and the last sample are the two ends it is drawn between).
54
70
  */
55
71
  steadyPressure?: number;
72
+ /**
73
+ * The stretches of the line held straight (Shift held while drawing), each between two of the samples (by index). A stretch is
74
+ * drawn as an exact straight line of one even width; what lies between the stretches is the hand's, smoothed as ever, and ends
75
+ * on the sample where a stretch begins and begins again where it ends. A line that is a single stretch from its first sample to
76
+ * its last is a straight line like the one `steadyPressure` draws. Stretches that overlap or have no length are left out, and
77
+ * so are all of them when `steadyPressure` is given (it makes the whole line straight).
78
+ */
79
+ straightSpans?: readonly BrushStraightSpan[];
56
80
  }
57
81
  /**
58
82
  * The stroke for the samples of a pointer, in world units: the box of its line, the line itself with its pressure, and the