@widgetic/canvas 0.5.43 → 0.5.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/canvas/DomCanvas.svelte +56 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -28
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +87 -2
  10. package/dist/canvas/host/CanvasHost.js +1948 -1394
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +32 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +2 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/types.d.ts +17 -0
  35. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  36. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  37. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  38. package/dist/canvas/ui/ColorField.svelte +7 -2
  39. package/dist/canvas/ui/SelectionPanel.svelte +105 -42
  40. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  41. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  42. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  43. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  44. package/dist/canvas/ui/ToolButton.svelte +35 -54
  45. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  46. package/dist/canvas/ui/colorModel.js +32 -21
  47. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  48. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  49. package/dist/canvas/ui/floatingCard.js +43 -21
  50. package/dist/canvas/ui/floatingLayer.js +6 -5
  51. package/dist/canvas/ui/icons.d.ts +1 -1
  52. package/dist/canvas/ui/icons.js +1 -1
  53. package/dist/canvas/ui/keyHints.js +11 -9
  54. package/dist/canvas/ui/popoverSide.js +3 -2
  55. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  56. package/dist/canvas/ui/selectionTraits.js +66 -35
  57. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  58. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  59. package/dist/canvas/view/CanvasStage.svelte +7 -2
  60. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  61. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  62. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  63. package/dist/canvas/view/erasingMarks.js +7 -7
  64. package/dist/canvas/view/geometry.d.ts +1 -1
  65. package/dist/canvas/view/geometry.js +90 -71
  66. package/dist/canvas/view/liftedScene.js +36 -24
  67. package/dist/canvas/view/mountedScene.js +79 -76
  68. package/dist/components/CanvasBoardPoster.svelte +206 -0
  69. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  70. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  71. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  72. package/dist/components/index.d.ts +7 -0
  73. package/dist/components/index.js +8 -0
  74. package/dist/components/preferenceStorage.js +2 -2
  75. package/dist/engine/EngineCore.d.ts +111 -2
  76. package/dist/engine/EngineCore.js +1013 -707
  77. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  78. package/dist/engine/codec/canvasDocument.js +172 -186
  79. package/dist/engine/codec/hostReadableKeys.js +1 -1
  80. package/dist/engine/core/arrange.js +38 -26
  81. package/dist/engine/core/arrow.d.ts +18 -8
  82. package/dist/engine/core/arrow.js +109 -84
  83. package/dist/engine/core/arrowBinding.d.ts +1 -1
  84. package/dist/engine/core/arrowBinding.js +126 -101
  85. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  86. package/dist/engine/core/arrowBindingRecords.js +48 -29
  87. package/dist/engine/core/brush.d.ts +8 -0
  88. package/dist/engine/core/brush.js +98 -78
  89. package/dist/engine/core/cameraMove.d.ts +73 -0
  90. package/dist/engine/core/cameraMove.js +172 -0
  91. package/dist/engine/core/defaults.js +51 -90
  92. package/dist/engine/core/freehand.js +163 -147
  93. package/dist/engine/core/geometry.js +54 -47
  94. package/dist/engine/core/history.js +55 -38
  95. package/dist/engine/core/hitTest.js +81 -68
  96. package/dist/engine/core/matrix.js +20 -18
  97. package/dist/engine/core/pathData.js +210 -183
  98. package/dist/engine/core/rotationReset.js +6 -5
  99. package/dist/engine/core/scene.d.ts +22 -0
  100. package/dist/engine/core/scene.js +288 -139
  101. package/dist/engine/core/scribble.js +84 -59
  102. package/dist/engine/core/shapePaths.js +15 -12
  103. package/dist/engine/core/shapeTools.js +63 -72
  104. package/dist/engine/core/snapping.js +117 -65
  105. package/dist/engine/core/style.d.ts +10 -0
  106. package/dist/engine/core/style.js +82 -33
  107. package/dist/engine/core/transform.d.ts +6 -0
  108. package/dist/engine/core/transform.js +103 -83
  109. package/dist/engine/core/types.d.ts +7 -0
  110. package/dist/engine/core/types.js +4 -4
  111. package/dist/engine/core/viewport.js +36 -23
  112. package/dist/engine/input/PointerController.d.ts +15 -1
  113. package/dist/engine/input/PointerController.js +549 -466
  114. package/dist/engine/input/arrowHandles.js +12 -12
  115. package/dist/engine/input/gestures.d.ts +3 -1
  116. package/dist/engine/input/gestures.js +340 -266
  117. package/dist/engine/input/hoverCursor.js +1 -1
  118. package/dist/engine/input/keyboard.d.ts +22 -3
  119. package/dist/engine/input/keyboard.js +131 -32
  120. package/dist/engine/input/selectionHandles.js +50 -45
  121. package/dist/engine/input/types.d.ts +7 -0
  122. package/dist/engine/input/types.js +1 -1
  123. package/dist/engine/render/rasterize.js +158 -86
  124. package/dist/engine/state.d.ts +18 -0
  125. package/dist/engine/state.js +25 -4
  126. package/dist/engine/text/layoutText.js +62 -43
  127. package/dist/engine/text/textMetrics.js +10 -8
  128. package/dist/engine/widgets.js +137 -101
  129. package/dist/fonts/interFont.js +83 -30
  130. package/dist/fonts/workspaceFonts.d.ts +6 -0
  131. package/dist/fonts/workspaceFonts.js +108 -34
  132. package/dist/i18n/labels.js +4 -4
  133. package/dist/i18n/language.d.ts +3 -3
  134. package/dist/i18n/language.js +4 -4
  135. package/dist/i18n/messages.d.ts +6 -0
  136. package/dist/i18n/messages.js +7 -1
  137. package/dist/i18n/shortcuts.d.ts +6 -4
  138. package/dist/i18n/shortcuts.js +30 -26
  139. package/dist/index.d.ts +2 -1
  140. package/dist/poster/boardPlacement.d.ts +80 -0
  141. package/dist/poster/boardPlacement.js +140 -0
  142. package/dist/poster/boardPoster.d.ts +80 -0
  143. package/dist/poster/boardPoster.js +251 -0
  144. package/dist/poster/paintBoardPoster.d.ts +49 -0
  145. package/dist/poster/paintBoardPoster.js +112 -0
  146. package/dist/poster/posterPictures.d.ts +32 -0
  147. package/dist/poster/posterPictures.js +138 -0
  148. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  149. package/dist/settings/workspaceToolSettings.js +58 -34
  150. package/dist/tools/components/catalog.js +74 -64
  151. package/dist/tools/components/grouping.js +28 -6
  152. package/dist/tools/definitions.js +31 -9
  153. package/dist/tools/executors.js +214 -106
  154. package/dist/tools/hostAdapter.d.ts +5 -1
  155. package/dist/tools/hostAdapter.js +15 -11
  156. package/dist/tools/sceneSummary.js +57 -43
  157. package/dist/tools/sketchIntent.js +21 -13
  158. package/dist/tools/styleArguments.d.ts +35 -0
  159. package/dist/tools/styleArguments.js +93 -0
  160. package/dist/tools/types.d.ts +26 -1
  161. package/dist/tools/types.js +2 -1
  162. package/package.json +1 -1
@@ -3,7 +3,7 @@
3
3
  * rasterizer are built from. Pure functions on plain numbers.
4
4
  */
5
5
  import { boxToWorldMatrix, applyMatrixToPoint, invertMatrix } from './matrix.js';
6
- const EPSILON = 1e-9;
6
+ var EPSILON = 1e-9;
7
7
  export function rectRight(rect) {
8
8
  return rect.x + rect.width;
9
9
  }
@@ -52,11 +52,12 @@ export function inflateRect(rect, amount) {
52
52
  export function unionRects(rects) {
53
53
  if (rects.length === 0)
54
54
  return null;
55
- let left = Infinity;
56
- let top = Infinity;
57
- let right = -Infinity;
58
- let bottom = -Infinity;
59
- for (const rect of rects) {
55
+ var left = Infinity;
56
+ var top = Infinity;
57
+ var right = -Infinity;
58
+ var bottom = -Infinity;
59
+ for (var _i = 0, rects_1 = rects; _i < rects_1.length; _i++) {
60
+ var rect = rects_1[_i];
60
61
  left = Math.min(left, rect.x);
61
62
  top = Math.min(top, rect.y);
62
63
  right = Math.max(right, rect.x + rect.width);
@@ -68,11 +69,12 @@ export function unionRects(rects) {
68
69
  export function boundsOfPoints(points) {
69
70
  if (points.length === 0)
70
71
  return null;
71
- let left = Infinity;
72
- let top = Infinity;
73
- let right = -Infinity;
74
- let bottom = -Infinity;
75
- for (const point of points) {
72
+ var left = Infinity;
73
+ var top = Infinity;
74
+ var right = -Infinity;
75
+ var bottom = -Infinity;
76
+ for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
77
+ var point = points_1[_i];
76
78
  left = Math.min(left, point.x);
77
79
  top = Math.min(top, point.y);
78
80
  right = Math.max(right, point.x);
@@ -82,7 +84,7 @@ export function boundsOfPoints(points) {
82
84
  }
83
85
  /** The four corners of a box in world space, clockwise from the top-left (before rotation). */
84
86
  export function boxCorners(box) {
85
- const matrix = boxToWorldMatrix(box);
87
+ var matrix = boxToWorldMatrix(box);
86
88
  return [
87
89
  applyMatrixToPoint(matrix, { x: 0, y: 0 }),
88
90
  applyMatrixToPoint(matrix, { x: box.width, y: 0 }),
@@ -97,11 +99,12 @@ export function rotatedBoxBounds(box) {
97
99
  return boundsOfPoints(boxCorners(box));
98
100
  }
99
101
  /** Whether a world point is inside a (possibly rotated) box, with `slop` world units of leeway on every side. */
100
- export function pointInBox(box, point, slop = 0) {
101
- const inverse = invertMatrix(boxToWorldMatrix(box));
102
+ export function pointInBox(box, point, slop) {
103
+ if (slop === void 0) { slop = 0; }
104
+ var inverse = invertMatrix(boxToWorldMatrix(box));
102
105
  if (!inverse)
103
106
  return false;
104
- const local = applyMatrixToPoint(inverse, point);
107
+ var local = applyMatrixToPoint(inverse, point);
105
108
  return (local.x >= -slop &&
106
109
  local.x <= box.width + slop &&
107
110
  local.y >= -slop &&
@@ -109,7 +112,7 @@ export function pointInBox(box, point, slop = 0) {
109
112
  }
110
113
  /** A world point in the local space of a box. Null when the box is degenerate. */
111
114
  export function worldToBoxLocal(box, point) {
112
- const inverse = invertMatrix(boxToWorldMatrix(box));
115
+ var inverse = invertMatrix(boxToWorldMatrix(box));
113
116
  return inverse ? applyMatrixToPoint(inverse, point) : null;
114
117
  }
115
118
  export function distanceBetween(first, second) {
@@ -117,13 +120,13 @@ export function distanceBetween(first, second) {
117
120
  }
118
121
  /** The distance from a point to the segment a-b. */
119
122
  export function distanceToSegment(point, a, b) {
120
- const deltaX = b.x - a.x;
121
- const deltaY = b.y - a.y;
122
- const lengthSquared = deltaX * deltaX + deltaY * deltaY;
123
+ var deltaX = b.x - a.x;
124
+ var deltaY = b.y - a.y;
125
+ var lengthSquared = deltaX * deltaX + deltaY * deltaY;
123
126
  if (lengthSquared < EPSILON)
124
127
  return distanceBetween(point, a);
125
- const along = ((point.x - a.x) * deltaX + (point.y - a.y) * deltaY) / lengthSquared;
126
- const clamped = Math.max(0, Math.min(1, along));
128
+ var along = ((point.x - a.x) * deltaX + (point.y - a.y) * deltaY) / lengthSquared;
129
+ var clamped = Math.max(0, Math.min(1, along));
127
130
  return Math.hypot(point.x - (a.x + clamped * deltaX), point.y - (a.y + clamped * deltaY));
128
131
  }
129
132
  /** The distance from a point to a polyline (closed: the last point joins the first). */
@@ -132,10 +135,10 @@ export function distanceToPolyline(point, vertices, closed) {
132
135
  return Infinity;
133
136
  if (vertices.length === 1)
134
137
  return distanceBetween(point, vertices[0]);
135
- let best = Infinity;
136
- const last = closed ? vertices.length : vertices.length - 1;
137
- for (let index = 0; index < last; index += 1) {
138
- const distance = distanceToSegment(point, vertices[index], vertices[(index + 1) % vertices.length]);
138
+ var best = Infinity;
139
+ var last = closed ? vertices.length : vertices.length - 1;
140
+ for (var index = 0; index < last; index += 1) {
141
+ var distance = distanceToSegment(point, vertices[index], vertices[(index + 1) % vertices.length]);
139
142
  if (distance < best)
140
143
  best = distance;
141
144
  }
@@ -143,11 +146,11 @@ export function distanceToPolyline(point, vertices, closed) {
143
146
  }
144
147
  /** Even-odd test: whether the point lies inside the polygon. */
145
148
  export function pointInPolygon(point, vertices) {
146
- let inside = false;
147
- for (let index = 0, previous = vertices.length - 1; index < vertices.length; previous = index, index += 1) {
148
- const current = vertices[index];
149
- const before = vertices[previous];
150
- const crosses = current.y > point.y !== before.y > point.y &&
149
+ var inside = false;
150
+ for (var index = 0, previous = vertices.length - 1; index < vertices.length; previous = index, index += 1) {
151
+ var current = vertices[index];
152
+ var before = vertices[previous];
153
+ var crosses = current.y > point.y !== before.y > point.y &&
151
154
  point.x < ((before.x - current.x) * (point.y - current.y)) / (before.y - current.y) + current.x;
152
155
  if (crosses)
153
156
  inside = !inside;
@@ -156,17 +159,19 @@ export function pointInPolygon(point, vertices) {
156
159
  }
157
160
  /** Whether segment p1-p2 crosses segment p3-p4. */
158
161
  export function segmentsIntersect(p1, p2, p3, p4) {
159
- const orientation = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
160
- const d1 = orientation(p3, p4, p1);
161
- const d2 = orientation(p3, p4, p2);
162
- const d3 = orientation(p1, p2, p3);
163
- const d4 = orientation(p1, p2, p4);
162
+ var orientation = function (a, b, c) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); };
163
+ var d1 = orientation(p3, p4, p1);
164
+ var d2 = orientation(p3, p4, p2);
165
+ var d3 = orientation(p1, p2, p3);
166
+ var d4 = orientation(p1, p2, p4);
164
167
  if (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0)))
165
168
  return true;
166
- const onSegment = (a, b, c) => Math.min(a.x, b.x) - EPSILON <= c.x &&
167
- c.x <= Math.max(a.x, b.x) + EPSILON &&
168
- Math.min(a.y, b.y) - EPSILON <= c.y &&
169
- c.y <= Math.max(a.y, b.y) + EPSILON;
169
+ var onSegment = function (a, b, c) {
170
+ return Math.min(a.x, b.x) - EPSILON <= c.x &&
171
+ c.x <= Math.max(a.x, b.x) + EPSILON &&
172
+ Math.min(a.y, b.y) - EPSILON <= c.y &&
173
+ c.y <= Math.max(a.y, b.y) + EPSILON;
174
+ };
170
175
  if (Math.abs(d1) < EPSILON && onSegment(p3, p4, p1))
171
176
  return true;
172
177
  if (Math.abs(d2) < EPSILON && onSegment(p3, p4, p2))
@@ -182,7 +187,8 @@ export function polygonIntersectsRect(vertices, rect) {
182
187
  if (vertices.length === 0)
183
188
  return false;
184
189
  // Any vertex inside the rectangle.
185
- for (const vertex of vertices) {
190
+ for (var _i = 0, vertices_1 = vertices; _i < vertices_1.length; _i++) {
191
+ var vertex = vertices_1[_i];
186
192
  if (rectContainsPoint(rect, vertex))
187
193
  return true;
188
194
  }
@@ -190,16 +196,16 @@ export function polygonIntersectsRect(vertices, rect) {
190
196
  if (pointInPolygon(rectCenter(rect), vertices))
191
197
  return true;
192
198
  // Any edge crossing any edge of the rectangle.
193
- const rectangleCorners = [
199
+ var rectangleCorners = [
194
200
  { x: rect.x, y: rect.y },
195
201
  { x: rect.x + rect.width, y: rect.y },
196
202
  { x: rect.x + rect.width, y: rect.y + rect.height },
197
203
  { x: rect.x, y: rect.y + rect.height }
198
204
  ];
199
- for (let index = 0; index < vertices.length; index += 1) {
200
- const start = vertices[index];
201
- const end = vertices[(index + 1) % vertices.length];
202
- for (let side = 0; side < 4; side += 1) {
205
+ for (var index = 0; index < vertices.length; index += 1) {
206
+ var start = vertices[index];
207
+ var end = vertices[(index + 1) % vertices.length];
208
+ for (var side = 0; side < 4; side += 1) {
203
209
  if (segmentsIntersect(start, end, rectangleCorners[side], rectangleCorners[(side + 1) % 4]))
204
210
  return true;
205
211
  }
@@ -207,8 +213,9 @@ export function polygonIntersectsRect(vertices, rect) {
207
213
  return false;
208
214
  }
209
215
  /** Rounds to a number of decimals (default 2): for stored geometry, so JSON does not carry noise digits. */
210
- export function roundTo(value, decimals = 2) {
211
- const factor = 10 ** decimals;
216
+ export function roundTo(value, decimals) {
217
+ if (decimals === void 0) { decimals = 2; }
218
+ var factor = Math.pow(10, decimals);
212
219
  return Math.round(value * factor) / factor;
213
220
  }
214
221
  export function clampNumber(value, minimum, maximum) {
@@ -5,35 +5,50 @@
5
5
  * hundred steps costs a hundred arrays of pointers, not a hundred copies of the board. One step is pushed
6
6
  * when a gesture ends (a drag, a resize, a stroke), never while it runs.
7
7
  */
8
- export class HistoryStack {
9
- entries;
10
- cursor = 0;
11
- limit;
12
- isSame;
13
- constructor(initial, options = {}) {
8
+ var HistoryStack = /** @class */ (function () {
9
+ function HistoryStack(initial, options) {
10
+ if (options === void 0) { options = {}; }
11
+ var _a, _b;
12
+ this.cursor = 0;
14
13
  this.entries = [initial];
15
- this.limit = Math.max(2, options.limit ?? 100);
16
- this.isSame = options.isSame ?? Object.is;
17
- }
18
- /** The state the board is in now. */
19
- get current() {
20
- return this.entries[this.cursor];
21
- }
22
- get canUndo() {
23
- return this.cursor > 0;
24
- }
25
- get canRedo() {
26
- return this.cursor < this.entries.length - 1;
27
- }
28
- /** How many states the stack holds (the start included). */
29
- get length() {
30
- return this.entries.length;
14
+ this.limit = Math.max(2, (_a = options.limit) !== null && _a !== void 0 ? _a : 100);
15
+ this.isSame = (_b = options.isSame) !== null && _b !== void 0 ? _b : Object.is;
31
16
  }
17
+ Object.defineProperty(HistoryStack.prototype, "current", {
18
+ /** The state the board is in now. */
19
+ get: function () {
20
+ return this.entries[this.cursor];
21
+ },
22
+ enumerable: false,
23
+ configurable: true
24
+ });
25
+ Object.defineProperty(HistoryStack.prototype, "canUndo", {
26
+ get: function () {
27
+ return this.cursor > 0;
28
+ },
29
+ enumerable: false,
30
+ configurable: true
31
+ });
32
+ Object.defineProperty(HistoryStack.prototype, "canRedo", {
33
+ get: function () {
34
+ return this.cursor < this.entries.length - 1;
35
+ },
36
+ enumerable: false,
37
+ configurable: true
38
+ });
39
+ Object.defineProperty(HistoryStack.prototype, "length", {
40
+ /** How many states the stack holds (the start included). */
41
+ get: function () {
42
+ return this.entries.length;
43
+ },
44
+ enumerable: false,
45
+ configurable: true
46
+ });
32
47
  /**
33
48
  * Adds a step after the current one and forgets the steps that were undone.
34
49
  * Returns false (and records nothing) when the state is the same as the current one.
35
50
  */
36
- push(state) {
51
+ HistoryStack.prototype.push = function (state) {
37
52
  if (this.isSame(this.current, state))
38
53
  return false;
39
54
  this.entries = this.entries.slice(0, this.cursor + 1);
@@ -42,44 +57,46 @@ export class HistoryStack {
42
57
  this.entries.splice(0, this.entries.length - this.limit);
43
58
  this.cursor = this.entries.length - 1;
44
59
  return true;
45
- }
60
+ };
46
61
  /** Goes one step back and returns that state, or null at the start. */
47
- undo() {
62
+ HistoryStack.prototype.undo = function () {
48
63
  if (!this.canUndo)
49
64
  return null;
50
65
  this.cursor -= 1;
51
66
  return this.entries[this.cursor];
52
- }
67
+ };
53
68
  /** Goes one step forward and returns that state, or null at the end. */
54
- redo() {
69
+ HistoryStack.prototype.redo = function () {
55
70
  if (!this.canRedo)
56
71
  return null;
57
72
  this.cursor += 1;
58
73
  return this.entries[this.cursor];
59
- }
74
+ };
60
75
  /** Replaces the current step without adding one (for a change that must not be undone on its own). */
61
- replaceCurrent(state) {
76
+ HistoryStack.prototype.replaceCurrent = function (state) {
62
77
  this.entries[this.cursor] = state;
63
- }
78
+ };
64
79
  /**
65
80
  * Rewrites every step, the past and the future of the cursor too, with no step added (a repair that all of them must have, as
66
81
  * a picture that arrived late: going back to a step from before it came must not take it away). A step that the rewrite
67
82
  * leaves as it is keeps its identity, and a state that is held by two steps is rewritten once.
68
83
  */
69
- mapAll(rewrite) {
70
- const rewritten = new Map();
71
- this.entries = this.entries.map((entry) => {
72
- let result = rewritten.get(entry);
84
+ HistoryStack.prototype.mapAll = function (rewrite) {
85
+ var rewritten = new Map();
86
+ this.entries = this.entries.map(function (entry) {
87
+ var result = rewritten.get(entry);
73
88
  if (result === undefined) {
74
89
  result = rewrite(entry);
75
90
  rewritten.set(entry, result);
76
91
  }
77
92
  return result;
78
93
  });
79
- }
94
+ };
80
95
  /** Forgets everything and starts again from this state (a canvas was loaded). */
81
- reset(state) {
96
+ HistoryStack.prototype.reset = function (state) {
82
97
  this.entries = [state];
83
98
  this.cursor = 0;
84
- }
85
- }
99
+ };
100
+ return HistoryStack;
101
+ }());
102
+ export { HistoryStack };
@@ -16,16 +16,16 @@ import { applyMatrixToPoint, boxToWorldMatrix } from './matrix.js';
16
16
  import { flattenPath, parsePathData } from './pathData.js';
17
17
  import { indexScene, isWithin, topLevelAncestorId } from './scene.js';
18
18
  import { isBoxedObject } from './types.js';
19
- const DEFAULT_TOLERANCE_PIXELS = 5;
20
- const FLATTENED_PATH_CACHE_LIMIT = 400;
19
+ var DEFAULT_TOLERANCE_PIXELS = 5;
20
+ var FLATTENED_PATH_CACHE_LIMIT = 400;
21
21
  /** Flattened outlines by path data, so a hover over a busy board does not parse the same strokes again. */
22
- const flattenedPathCache = new Map();
22
+ var flattenedPathCache = new Map();
23
23
  /** The outline of a path flattened to straight pieces, in the coordinates of its box (the same pieces for as long as the same data is asked for). */
24
24
  export function flattenedOutline(data) {
25
- const cached = flattenedPathCache.get(data);
25
+ var cached = flattenedPathCache.get(data);
26
26
  if (cached)
27
27
  return cached;
28
- const flattened = flattenPath(parsePathData(data));
28
+ var flattened = flattenPath(parsePathData(data));
29
29
  if (flattenedPathCache.size >= FLATTENED_PATH_CACHE_LIMIT)
30
30
  flattenedPathCache.clear();
31
31
  flattenedPathCache.set(data, flattened);
@@ -46,39 +46,41 @@ function halfStroke(shape) {
46
46
  }
47
47
  /** Whether a world point is on a shape (inside it, or near its outline, depending on the kind of shape). */
48
48
  export function shapeContainsPoint(shape, worldPoint, toleranceWorld) {
49
- const reach = toleranceWorld + halfStroke(shape);
49
+ var reach = toleranceWorld + halfStroke(shape);
50
50
  // Cheap rejection first: outside the box grown by the reach, nothing else can say yes. A brush stroke's outline spills past
51
51
  // the box of its line, so the box grows by that as well (the outline itself is the shape: the reach on it stays the tolerance).
52
52
  if (!pointInBox(shape, worldPoint, reach + brushOverflow(shape)))
53
53
  return false;
54
- const local = worldToBoxLocal(shape, worldPoint);
54
+ var local = worldToBoxLocal(shape, worldPoint);
55
55
  if (!local)
56
56
  return false;
57
57
  switch (shape.type) {
58
58
  case 'rect': {
59
59
  if (!isHollow(shape))
60
60
  return true;
61
- const edgeDistance = Math.min(Math.abs(local.x), Math.abs(local.x - shape.width), Math.abs(local.y), Math.abs(local.y - shape.height));
61
+ var edgeDistance = Math.min(Math.abs(local.x), Math.abs(local.x - shape.width), Math.abs(local.y), Math.abs(local.y - shape.height));
62
62
  return edgeDistance <= reach;
63
63
  }
64
64
  case 'ellipse': {
65
- const radiusX = Math.max(0.5, shape.width / 2);
66
- const radiusY = Math.max(0.5, shape.height / 2);
67
- const normalized = Math.hypot((local.x - radiusX) / radiusX, (local.y - radiusY) / radiusY);
68
- const smallestRadius = Math.min(radiusX, radiusY);
65
+ var radiusX = Math.max(0.5, shape.width / 2);
66
+ var radiusY = Math.max(0.5, shape.height / 2);
67
+ var normalized = Math.hypot((local.x - radiusX) / radiusX, (local.y - radiusY) / radiusY);
68
+ var smallestRadius = Math.min(radiusX, radiusY);
69
69
  if (!isHollow(shape))
70
70
  return normalized <= 1 + reach / smallestRadius;
71
71
  return Math.abs(normalized - 1) * smallestRadius <= reach;
72
72
  }
73
73
  case 'path': {
74
- const outlines = flattenedOutline(shape.d);
75
- for (const outline of outlines) {
74
+ var outlines = flattenedOutline(shape.d);
75
+ for (var _i = 0, outlines_1 = outlines; _i < outlines_1.length; _i++) {
76
+ var outline = outlines_1[_i];
76
77
  if (distanceToPolyline(local, outline.points, outline.closed) <= reach)
77
78
  return true;
78
79
  }
79
80
  if (!isHollow(shape)) {
80
81
  // A fill closes an open outline implicitly, so every outline counts as a polygon here.
81
- for (const outline of outlines) {
82
+ for (var _a = 0, outlines_2 = outlines; _a < outlines_2.length; _a++) {
83
+ var outline = outlines_2[_a];
82
84
  if (outline.points.length >= 3 && pointInPolygon(local, outline.points))
83
85
  return true;
84
86
  }
@@ -92,24 +94,26 @@ export function shapeContainsPoint(shape, worldPoint, toleranceWorld) {
92
94
  }
93
95
  /** The unit a person selects when a leaf shape is picked: the group nearest the board, or the entered group's member. */
94
96
  function selectableIdFor(index, leafId, enteredGroupId) {
97
+ var _a;
95
98
  if (!enteredGroupId || !isWithin(index, leafId, enteredGroupId) || leafId === enteredGroupId) {
96
99
  return topLevelAncestorId(index, leafId);
97
100
  }
98
- let current = index.get(leafId);
101
+ var current = index.get(leafId);
99
102
  while (current && current.parentId !== null && current.parentId !== enteredGroupId) {
100
103
  current = index.get(current.parentId);
101
104
  }
102
- return current?.id ?? leafId;
105
+ return (_a = current === null || current === void 0 ? void 0 : current.id) !== null && _a !== void 0 ? _a : leafId;
103
106
  }
104
107
  /** The topmost selectable object under a world point, or null. */
105
108
  export function hitTestPoint(scene, worldPoint, options) {
106
- const index = options.index ?? indexScene(scene);
107
- const toleranceWorld = (options.tolerancePixels ?? DEFAULT_TOLERANCE_PIXELS) / Math.max(options.zoom, 1e-6);
108
- for (let position = scene.length - 1; position >= 0; position -= 1) {
109
- const object = scene[position];
109
+ var _a, _b, _c;
110
+ var index = (_a = options.index) !== null && _a !== void 0 ? _a : indexScene(scene);
111
+ var toleranceWorld = ((_b = options.tolerancePixels) !== null && _b !== void 0 ? _b : DEFAULT_TOLERANCE_PIXELS) / Math.max(options.zoom, 1e-6);
112
+ for (var position = scene.length - 1; position >= 0; position -= 1) {
113
+ var object = scene[position];
110
114
  if (!isBoxedObject(object))
111
115
  continue;
112
- if (options.ignore?.has(object.id))
116
+ if ((_c = options.ignore) === null || _c === void 0 ? void 0 : _c.has(object.id))
113
117
  continue;
114
118
  if (shapeContainsPoint(object, worldPoint, toleranceWorld)) {
115
119
  return selectableIdFor(index, object.id, options.enteredGroupId);
@@ -122,18 +126,20 @@ export function hitTestPoint(scene, worldPoint, options) {
122
126
  * through, one object further down at every click.
123
127
  */
124
128
  export function hitTestStack(scene, worldPoint, options) {
125
- const index = options.index ?? indexScene(scene);
126
- const toleranceWorld = (options.tolerancePixels ?? DEFAULT_TOLERANCE_PIXELS) / Math.max(options.zoom, 1e-6);
127
- const stack = [];
128
- const seen = new Set();
129
- for (const object of scene) {
129
+ var _a, _b, _c;
130
+ var index = (_a = options.index) !== null && _a !== void 0 ? _a : indexScene(scene);
131
+ var toleranceWorld = ((_b = options.tolerancePixels) !== null && _b !== void 0 ? _b : DEFAULT_TOLERANCE_PIXELS) / Math.max(options.zoom, 1e-6);
132
+ var stack = [];
133
+ var seen = new Set();
134
+ for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
135
+ var object = scene_1[_i];
130
136
  if (!isBoxedObject(object))
131
137
  continue;
132
- if (options.ignore?.has(object.id))
138
+ if ((_c = options.ignore) === null || _c === void 0 ? void 0 : _c.has(object.id))
133
139
  continue;
134
140
  if (!shapeContainsPoint(object, worldPoint, toleranceWorld))
135
141
  continue;
136
- const unitId = selectableIdFor(index, object.id, options.enteredGroupId);
142
+ var unitId = selectableIdFor(index, object.id, options.enteredGroupId);
137
143
  // A unit that is hit again by a later member moves up to that member's place in the paint order.
138
144
  if (seen.has(unitId))
139
145
  stack.splice(stack.indexOf(unitId), 1);
@@ -144,12 +150,13 @@ export function hitTestStack(scene, worldPoint, options) {
144
150
  }
145
151
  /** The leaf shape under a world point, ignoring groups (what the eraser removes, what a double-click enters). */
146
152
  export function hitTestLeaf(scene, worldPoint, options) {
147
- const toleranceWorld = (options.tolerancePixels ?? DEFAULT_TOLERANCE_PIXELS) / Math.max(options.zoom, 1e-6);
148
- for (let position = scene.length - 1; position >= 0; position -= 1) {
149
- const object = scene[position];
153
+ var _a, _b;
154
+ var toleranceWorld = ((_a = options.tolerancePixels) !== null && _a !== void 0 ? _a : DEFAULT_TOLERANCE_PIXELS) / Math.max(options.zoom, 1e-6);
155
+ for (var position = scene.length - 1; position >= 0; position -= 1) {
156
+ var object = scene[position];
150
157
  if (!isBoxedObject(object))
151
158
  continue;
152
- if (options.ignore?.has(object.id))
159
+ if ((_b = options.ignore) === null || _b === void 0 ? void 0 : _b.has(object.id))
153
160
  continue;
154
161
  if (shapeContainsPoint(object, worldPoint, toleranceWorld))
155
162
  return object;
@@ -158,31 +165,32 @@ export function hitTestLeaf(scene, worldPoint, options) {
158
165
  }
159
166
  /** Whether a polyline (open or closed) touches a rectangle. */
160
167
  function polylineTouchesRect(points, closed, rect) {
161
- for (const point of points) {
168
+ for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
169
+ var point = points_1[_i];
162
170
  if (rectContainsPoint(rect, point))
163
171
  return true;
164
172
  }
165
- const corners = [
173
+ var corners = [
166
174
  { x: rect.x, y: rect.y },
167
175
  { x: rect.x + rect.width, y: rect.y },
168
176
  { x: rect.x + rect.width, y: rect.y + rect.height },
169
177
  { x: rect.x, y: rect.y + rect.height }
170
178
  ];
171
- const last = closed ? points.length : points.length - 1;
172
- for (let position = 0; position < last; position += 1) {
173
- const start = points[position];
174
- const end = points[(position + 1) % points.length];
175
- for (let side = 0; side < 4; side += 1) {
179
+ var last = closed ? points.length : points.length - 1;
180
+ for (var position = 0; position < last; position += 1) {
181
+ var start = points[position];
182
+ var end = points[(position + 1) % points.length];
183
+ for (var side = 0; side < 4; side += 1) {
176
184
  if (segmentsIntersect(start, end, corners[side], corners[(side + 1) % 4]))
177
185
  return true;
178
186
  }
179
187
  }
180
188
  return false;
181
189
  }
182
- const shapesInTheWorld = new WeakMap();
190
+ var shapesInTheWorld = new WeakMap();
183
191
  function shapeInTheWorld(shape) {
184
- const data = shape.type === 'path' ? shape.d : null;
185
- const cached = shapesInTheWorld.get(shape);
192
+ var data = shape.type === 'path' ? shape.d : null;
193
+ var cached = shapesInTheWorld.get(shape);
186
194
  if (cached &&
187
195
  cached.x === shape.x &&
188
196
  cached.y === shape.y &&
@@ -192,34 +200,35 @@ function shapeInTheWorld(shape) {
192
200
  cached.data === data) {
193
201
  return cached;
194
202
  }
195
- const outlines = [];
196
- let corners = [];
203
+ var outlines = [];
204
+ var corners = [];
197
205
  if (data !== null) {
198
- const matrix = boxToWorldMatrix(shape);
199
- for (const outline of flattenedOutline(data)) {
200
- outlines.push({ points: outline.points.map((point) => applyMatrixToPoint(matrix, point)), closed: outline.closed });
206
+ var matrix_1 = boxToWorldMatrix(shape);
207
+ for (var _i = 0, _a = flattenedOutline(data); _i < _a.length; _i++) {
208
+ var outline = _a[_i];
209
+ outlines.push({ points: outline.points.map(function (point) { return applyMatrixToPoint(matrix_1, point); }), closed: outline.closed });
201
210
  }
202
211
  }
203
212
  else {
204
213
  corners = boxCorners(shape);
205
214
  }
206
- const made = {
215
+ var made = {
207
216
  x: shape.x,
208
217
  y: shape.y,
209
218
  width: shape.width,
210
219
  height: shape.height,
211
220
  rotation: shape.rotation,
212
- data,
213
- corners,
214
- outlines,
215
- bounds: boundsOfPoints(data !== null ? outlines.flatMap((outline) => outline.points) : corners)
221
+ data: data,
222
+ corners: corners,
223
+ outlines: outlines,
224
+ bounds: boundsOfPoints(data !== null ? outlines.flatMap(function (outline) { return outline.points; }) : corners)
216
225
  };
217
226
  shapesInTheWorld.set(shape, made);
218
227
  return made;
219
228
  }
220
229
  // How far a shape must lie from a rectangle, box to box, before nothing of it can touch the rectangle: far more than the slack
221
230
  // the segment tests allow themselves (1e-9), so that the quick answer below never says no where those tests would say yes.
222
- const CLEAR_OF_RECT_MARGIN = 1e-6;
231
+ var CLEAR_OF_RECT_MARGIN = 1e-6;
223
232
  /**
224
233
  * Whether a shape touches a rectangle of the world (by its outline or fill, not only by its box).
225
234
  *
@@ -229,10 +238,10 @@ const CLEAR_OF_RECT_MARGIN = 1e-6;
229
238
  * tested point by point.
230
239
  */
231
240
  export function shapeIntersectsRect(shape, rect) {
232
- const world = shapeInTheWorld(shape);
233
- const bounds = world.bounds;
241
+ var world = shapeInTheWorld(shape);
242
+ var bounds = world.bounds;
234
243
  if (bounds) {
235
- const clear = bounds.x - CLEAR_OF_RECT_MARGIN > rect.x + rect.width ||
244
+ var clear = bounds.x - CLEAR_OF_RECT_MARGIN > rect.x + rect.width ||
236
245
  bounds.x + bounds.width + CLEAR_OF_RECT_MARGIN < rect.x ||
237
246
  bounds.y - CLEAR_OF_RECT_MARGIN > rect.y + rect.height ||
238
247
  bounds.y + bounds.height + CLEAR_OF_RECT_MARGIN < rect.y;
@@ -242,7 +251,8 @@ export function shapeIntersectsRect(shape, rect) {
242
251
  return true;
243
252
  }
244
253
  if (shape.type === 'path') {
245
- for (const outline of world.outlines) {
254
+ for (var _i = 0, _a = world.outlines; _i < _a.length; _i++) {
255
+ var outline = _a[_i];
246
256
  if (polylineTouchesRect(outline.points, outline.closed, rect))
247
257
  return true;
248
258
  if (!isHollow(shape) && outline.points.length >= 3 && pointInPolygon(rectCenter(rect), outline.points))
@@ -258,20 +268,22 @@ export function shapeIntersectsRect(shape, rect) {
258
268
  }
259
269
  /** The selectable objects a marquee takes, each once, in paint order. */
260
270
  export function hitTestRect(scene, rect, options) {
261
- const index = options.index ?? indexScene(scene);
262
- const found = [];
263
- const seen = new Set();
264
- for (const object of scene) {
271
+ var _a, _b;
272
+ var index = (_a = options.index) !== null && _a !== void 0 ? _a : indexScene(scene);
273
+ var found = [];
274
+ var seen = new Set();
275
+ for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
276
+ var object = scene_2[_i];
265
277
  if (!isBoxedObject(object))
266
278
  continue;
267
- if (options.ignore?.has(object.id))
279
+ if ((_b = options.ignore) === null || _b === void 0 ? void 0 : _b.has(object.id))
268
280
  continue;
269
- const taken = options.mode === 'contain'
281
+ var taken = options.mode === 'contain'
270
282
  ? rectContainsRect(rect, rotatedBoxBounds(object))
271
283
  : shapeIntersectsRect(object, rect);
272
284
  if (!taken)
273
285
  continue;
274
- const unitId = selectableIdFor(index, object.id, options.enteredGroupId);
286
+ var unitId = selectableIdFor(index, object.id, options.enteredGroupId);
275
287
  if (!seen.has(unitId)) {
276
288
  seen.add(unitId);
277
289
  found.push(unitId);
@@ -279,11 +291,12 @@ export function hitTestRect(scene, rect, options) {
279
291
  }
280
292
  // A group is taken whole or not at all in `contain` mode: one member left out leaves the group out.
281
293
  if (options.mode === 'contain') {
282
- return found.filter((id) => {
283
- const unit = index.get(id);
294
+ return found.filter(function (id) {
295
+ var unit = index.get(id);
284
296
  if (!unit || unit.type !== 'group')
285
297
  return true;
286
- for (const object of scene) {
298
+ for (var _i = 0, scene_3 = scene; _i < scene_3.length; _i++) {
299
+ var object = scene_3[_i];
287
300
  if (isBoxedObject(object) && isWithin(index, object.id, id) && !rectContainsRect(rect, rotatedBoxBounds(object))) {
288
301
  return false;
289
302
  }