@widgetic/canvas 0.5.41 → 0.5.43

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 (131) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +49 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
  4. package/dist/canvas/autosaveScheduler.js +37 -89
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +7 -19
  8. package/dist/canvas/chromeLayout.d.ts +14 -3
  9. package/dist/canvas/chromeLayout.js +30 -20
  10. package/dist/canvas/eventScope.js +10 -14
  11. package/dist/canvas/host/CanvasHost.d.ts +47 -5
  12. package/dist/canvas/host/CanvasHost.js +1481 -1566
  13. package/dist/canvas/host/CanvasHostApi.js +4 -19
  14. package/dist/canvas/host/browserServices.js +65 -116
  15. package/dist/canvas/host/conversion.js +82 -170
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/nearCards.d.ts +33 -0
  18. package/dist/canvas/host/nearCards.js +78 -0
  19. package/dist/canvas/host/pageEvents.d.ts +16 -4
  20. package/dist/canvas/host/pageEvents.js +17 -8
  21. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  22. package/dist/canvas/host/pictureSaves.js +42 -0
  23. package/dist/canvas/host/screenRects.d.ts +5 -0
  24. package/dist/canvas/host/screenRects.js +28 -31
  25. package/dist/canvas/host/storedPictures.d.ts +88 -0
  26. package/dist/canvas/host/storedPictures.js +288 -0
  27. package/dist/canvas/host/strokeSnap.js +88 -143
  28. package/dist/canvas/index.d.ts +1 -1
  29. package/dist/canvas/index.js +1 -1
  30. package/dist/canvas/openMarks.js +2 -2
  31. package/dist/canvas/outsideClickDeselect.js +6 -7
  32. package/dist/canvas/panZoomPosition.js +2 -2
  33. package/dist/canvas/preferredTextFont.js +13 -25
  34. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  35. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  36. package/dist/canvas/shapes/shapeImageStore.js +10 -3
  37. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  38. package/dist/canvas/toolbarPosition.d.ts +2 -2
  39. package/dist/canvas/toolbarPosition.js +4 -4
  40. package/dist/canvas/ui/SelectionPanel.svelte +28 -5
  41. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  42. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  43. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  44. package/dist/canvas/ui/ToolButton.svelte +8 -2
  45. package/dist/canvas/ui/colorModel.js +21 -32
  46. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  47. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  48. package/dist/canvas/ui/floatingCard.js +20 -20
  49. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  50. package/dist/canvas/ui/floatingLayer.js +18 -7
  51. package/dist/canvas/ui/keyHints.js +9 -11
  52. package/dist/canvas/ui/popoverSide.js +2 -3
  53. package/dist/canvas/ui/selectionTraits.js +34 -40
  54. package/dist/canvas/view/CanvasStage.svelte +101 -67
  55. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  56. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  57. package/dist/canvas/view/ObjectView.svelte +15 -10
  58. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  59. package/dist/canvas/view/erasingMarks.js +7 -7
  60. package/dist/canvas/view/geometry.js +71 -90
  61. package/dist/canvas/view/liftedScene.d.ts +31 -0
  62. package/dist/canvas/view/liftedScene.js +146 -0
  63. package/dist/canvas/view/mountedScene.d.ts +71 -0
  64. package/dist/canvas/view/mountedScene.js +363 -0
  65. package/dist/components/preferenceStorage.js +2 -2
  66. package/dist/engine/EngineCore.d.ts +15 -1
  67. package/dist/engine/EngineCore.js +724 -797
  68. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  69. package/dist/engine/codec/canvasDocument.js +212 -149
  70. package/dist/engine/codec/hostReadableKeys.js +1 -1
  71. package/dist/engine/core/arrange.js +26 -38
  72. package/dist/engine/core/arrow.js +76 -89
  73. package/dist/engine/core/arrowBinding.js +98 -116
  74. package/dist/engine/core/arrowBindingRecords.js +23 -38
  75. package/dist/engine/core/brush.js +67 -94
  76. package/dist/engine/core/defaults.js +90 -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.d.ts +6 -0
  80. package/dist/engine/core/history.js +49 -50
  81. package/dist/engine/core/hitTest.js +68 -81
  82. package/dist/engine/core/matrix.js +18 -20
  83. package/dist/engine/core/pathData.js +183 -210
  84. package/dist/engine/core/rotationReset.js +5 -6
  85. package/dist/engine/core/scene.d.ts +10 -0
  86. package/dist/engine/core/scene.js +153 -187
  87. package/dist/engine/core/scribble.js +59 -84
  88. package/dist/engine/core/shapePaths.js +12 -15
  89. package/dist/engine/core/shapeTools.js +72 -63
  90. package/dist/engine/core/snapping.js +65 -117
  91. package/dist/engine/core/style.js +31 -64
  92. package/dist/engine/core/transform.js +83 -94
  93. package/dist/engine/core/types.d.ts +8 -2
  94. package/dist/engine/core/types.js +4 -4
  95. package/dist/engine/core/viewport.js +23 -36
  96. package/dist/engine/input/PointerController.js +467 -474
  97. package/dist/engine/input/arrowHandles.js +12 -12
  98. package/dist/engine/input/gestures.js +265 -309
  99. package/dist/engine/input/hoverCursor.js +1 -1
  100. package/dist/engine/input/keyboard.js +27 -30
  101. package/dist/engine/input/selectionHandles.js +45 -50
  102. package/dist/engine/input/types.js +1 -1
  103. package/dist/engine/render/rasterize.js +86 -158
  104. package/dist/engine/state.d.ts +20 -0
  105. package/dist/engine/state.js +5 -15
  106. package/dist/engine/text/layoutText.js +43 -62
  107. package/dist/engine/text/textMetrics.js +8 -10
  108. package/dist/engine/widgets.js +101 -137
  109. package/dist/fonts/interFont.d.ts +10 -1
  110. package/dist/fonts/interFont.js +47 -75
  111. package/dist/fonts/workspaceFonts.js +32 -90
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.d.ts +3 -3
  114. package/dist/i18n/language.js +4 -4
  115. package/dist/i18n/messages.d.ts +8 -1
  116. package/dist/i18n/messages.js +10 -2
  117. package/dist/i18n/shortcuts.js +14 -14
  118. package/dist/index.d.ts +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/settings/workspaceToolSettings.js +32 -48
  121. package/dist/tools/components/catalog.js +64 -74
  122. package/dist/tools/components/grouping.js +6 -28
  123. package/dist/tools/definitions.js +5 -5
  124. package/dist/tools/executors.js +105 -141
  125. package/dist/tools/hostAdapter.js +11 -13
  126. package/dist/tools/sceneSummary.js +43 -57
  127. package/dist/tools/sketchIntent.js +13 -21
  128. package/dist/tools/types.js +1 -1
  129. package/package.json +1 -1
  130. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  131. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -3,7 +3,7 @@
3
3
  * Pure function so Node can test the owner's hover rules (item 19).
4
4
  */
5
5
  /** The CSS cursor keyword for hovering a canvas object (pointing hand, not an open grab). */
6
- export var HOVER_SHAPE_CURSOR = 'pointer';
6
+ export const HOVER_SHAPE_CURSOR = 'pointer';
7
7
  /**
8
8
  * Resolves the board cursor from hover state. Dragging and panning are handled elsewhere; this is idle hover only.
9
9
  */
@@ -9,7 +9,7 @@
9
9
  * tested with a plain record.
10
10
  */
11
11
  /** The letter of each tool (the same letters the hints and the list of shortcuts show). */
12
- export var TOOL_LETTERS = Object.freeze({
12
+ export const TOOL_LETTERS = Object.freeze({
13
13
  V: 'select',
14
14
  E: 'erase',
15
15
  D: 'draw',
@@ -27,7 +27,7 @@ export var TOOL_LETTERS = Object.freeze({
27
27
  * numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The hints and the
28
28
  * list of shortcuts show these same numbers (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
29
29
  */
30
- export var TOOL_DIGITS = Object.freeze({
30
+ export const TOOL_DIGITS = Object.freeze({
31
31
  '1': 'select',
32
32
  '2': 'draw',
33
33
  '3': 'erase',
@@ -35,21 +35,21 @@ export var TOOL_DIGITS = Object.freeze({
35
35
  '5': 'text'
36
36
  });
37
37
  /** The tools that belong to the drawing bar: they are hidden, and so are their letters, when the host turns that bar off. */
38
- var DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
39
- var ARROW_STEPS = Object.freeze({
38
+ const DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
39
+ const ARROW_STEPS = Object.freeze({
40
40
  ArrowUp: [0, -1],
41
41
  ArrowDown: [0, 1],
42
42
  ArrowLeft: [-1, 0],
43
43
  ArrowRight: [1, 0]
44
44
  });
45
45
  /** The nudge of an arrow key, and of an arrow key with Shift, in world units. */
46
- export var NUDGE_DISTANCE = 1;
47
- export var NUDGE_DISTANCE_WITH_SHIFT = 10;
46
+ export const NUDGE_DISTANCE = 1;
47
+ export const NUDGE_DISTANCE_WITH_SHIFT = 10;
48
48
  /** Keys the browser zooms the page with: kept from doing so whatever layout the person has. */
49
49
  export function isBrowserZoomKey(input) {
50
50
  if (!(input.ctrlKey || input.metaKey))
51
51
  return false;
52
- var key = input.key, code = input.code;
52
+ const { key, code } = input;
53
53
  return (key === '=' ||
54
54
  key === '+' ||
55
55
  key === '-' ||
@@ -70,7 +70,7 @@ function selectionExists(engine) {
70
70
  }
71
71
  /** Escape: leaves whatever is going on, one level at a time. */
72
72
  function handleEscape(host) {
73
- var engine = host.engine, controller = host.controller, actions = host.actions;
73
+ const { engine, controller, actions } = host;
74
74
  if (actions.closePanels())
75
75
  return true;
76
76
  if (controller.cancelGesture())
@@ -95,11 +95,11 @@ function handleEscape(host) {
95
95
  }
96
96
  /** Ctrl or Cmd with a key. Returns undefined when the combination is not one of the board's. */
97
97
  function handleShortcut(input, host) {
98
- var engine = host.engine, controller = host.controller, actions = host.actions;
99
- var key = input.key;
100
- var lowerKey = key.length === 1 ? key.toLowerCase() : key;
101
- var editingText = !!engine.state.editingTextId;
102
- var typing = host.typingInField || editingText;
98
+ const { engine, controller, actions } = host;
99
+ const key = input.key;
100
+ const lowerKey = key.length === 1 ? key.toLowerCase() : key;
101
+ const editingText = !!engine.state.editingTextId;
102
+ const typing = host.typingInField || editingText;
103
103
  // The save and the zoom work wherever the focus is.
104
104
  if (lowerKey === 's') {
105
105
  actions.save();
@@ -172,7 +172,7 @@ function handleShortcut(input, host) {
172
172
  // What a drag is doing is not a step yet: the history waits for the release.
173
173
  if (controller.gestureKind)
174
174
  return true;
175
- var redo = input.code === 'KeyY' || input.shiftKey;
175
+ const redo = input.code === 'KeyY' || input.shiftKey;
176
176
  if (redo)
177
177
  engine.redo();
178
178
  else
@@ -187,13 +187,13 @@ function handleShortcut(input, host) {
187
187
  * The bare brackets keep moving one step, as they always did on this board.
188
188
  */
189
189
  function handleLayerKey(input, host) {
190
- var engine = host.engine;
191
- var forward = input.code === 'BracketRight';
190
+ const { engine } = host;
191
+ const forward = input.code === 'BracketRight';
192
192
  if (host.typingInField || engine.state.editingTextId)
193
193
  return false;
194
194
  if (!selectionExists(engine))
195
195
  return false;
196
- var toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
196
+ const toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
197
197
  engine.reorderSelection(forward ? (toEnd ? 'front' : 'forward') : toEnd ? 'back' : 'backward');
198
198
  return true;
199
199
  }
@@ -206,9 +206,8 @@ export function toolIsAvailable(tool, tools) {
206
206
  * does not also scroll, zoom or select the page.
207
207
  */
208
208
  export function routeKeyDown(input, host) {
209
- var _a, _b;
210
- var engine = host.engine, controller = host.controller, actions = host.actions;
211
- var key = input.key;
209
+ const { engine, controller, actions } = host;
210
+ const key = input.key;
212
211
  if (key === 'Escape')
213
212
  return handleEscape(host);
214
213
  // The keys that only change what a gesture does while it runs are not answered here: the shell tells the controller.
@@ -217,11 +216,11 @@ export function routeKeyDown(input, host) {
217
216
  if (input.code === 'BracketRight' || input.code === 'BracketLeft')
218
217
  return handleLayerKey(input, host);
219
218
  if (input.ctrlKey || input.metaKey) {
220
- var answered = handleShortcut(input, host);
219
+ const answered = handleShortcut(input, host);
221
220
  // A combination that is not ours (Ctrl+R, Ctrl+P) is the browser's.
222
221
  return answered === true;
223
222
  }
224
- var editingText = !!engine.state.editingTextId;
223
+ const editingText = !!engine.state.editingTextId;
225
224
  if (host.typingInField || editingText)
226
225
  return false;
227
226
  if (input.code === 'Space') {
@@ -231,7 +230,7 @@ export function routeKeyDown(input, host) {
231
230
  if (engine.state.tool === 'pan')
232
231
  return false;
233
232
  controller.setSpaceHeld(true);
234
- (_a = actions.spacePanChanged) === null || _a === void 0 ? void 0 : _a.call(actions, true);
233
+ actions.spacePanChanged?.(true);
235
234
  return true;
236
235
  }
237
236
  if (key === 'Delete' || key === 'Backspace') {
@@ -240,13 +239,13 @@ export function routeKeyDown(input, host) {
240
239
  void engine.deleteSelection();
241
240
  return true;
242
241
  }
243
- var step = ARROW_STEPS[key];
242
+ const step = ARROW_STEPS[key];
244
243
  if (step) {
245
244
  if (host.selectorHintOpen)
246
245
  return false;
247
246
  if (!selectionExists(engine))
248
247
  return false;
249
- var distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
248
+ const distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
250
249
  engine.nudgeSelection(step[0] * distance, step[1] * distance);
251
250
  return true;
252
251
  }
@@ -258,7 +257,7 @@ export function routeKeyDown(input, host) {
258
257
  return false;
259
258
  // A letter chooses its tool, and so does the number of a tool of the drawing bar. This point is only reached when the person is
260
259
  // not typing (a field of the page, or a text on the board: both returned above), so a digit written into a text stays a digit.
261
- var tool = key.length === 1 ? ((_b = TOOL_LETTERS[key.toUpperCase()]) !== null && _b !== void 0 ? _b : TOOL_DIGITS[key]) : undefined;
260
+ const tool = key.length === 1 ? (TOOL_LETTERS[key.toUpperCase()] ?? TOOL_DIGITS[key]) : undefined;
262
261
  if (tool && toolIsAvailable(tool, host.tools)) {
263
262
  actions.chooseTool(tool);
264
263
  return true;
@@ -267,17 +266,15 @@ export function routeKeyDown(input, host) {
267
266
  }
268
267
  /** A key was released. Returns whether the board used it. */
269
268
  export function routeKeyUp(input, host) {
270
- var _a, _b;
271
269
  if (input.code === 'Space') {
272
270
  host.controller.setSpaceHeld(false);
273
- (_b = (_a = host.actions).spacePanChanged) === null || _b === void 0 ? void 0 : _b.call(_a, false);
271
+ host.actions.spacePanChanged?.(false);
274
272
  return true;
275
273
  }
276
274
  return false;
277
275
  }
278
276
  /** The window lost the focus: nothing is held any more. */
279
277
  export function releaseHeldKeys(host) {
280
- var _a, _b;
281
278
  host.controller.setSpaceHeld(false);
282
- (_b = (_a = host.actions).spacePanChanged) === null || _b === void 0 ? void 0 : _b.call(_a, false);
279
+ host.actions.spacePanChanged?.(false);
283
280
  }
@@ -13,29 +13,29 @@
13
13
  import { degreesToRadians } from '../core/matrix.js';
14
14
  import { handleDirection } from '../core/transform.js';
15
15
  import { worldToScreen } from '../core/viewport.js';
16
- var MOUSE_METRICS = { cornerReach: 10, edgeReach: 13, rotateZone: 22, dotReach: 18 };
17
- var TOUCH_METRICS = { cornerReach: 22, edgeReach: 20, rotateZone: 40, dotReach: 24 };
16
+ const MOUSE_METRICS = { cornerReach: 10, edgeReach: 13, rotateZone: 22, dotReach: 18 };
17
+ const TOUCH_METRICS = { cornerReach: 22, edgeReach: 20, rotateZone: 40, dotReach: 24 };
18
18
  export function handleMetricsFor(pointerType) {
19
19
  return pointerType === 'touch' ? TOUCH_METRICS : MOUSE_METRICS;
20
20
  }
21
21
  /** When false, only the dot under the frame turns the selection (corner zones stay in code but do not hit). */
22
- export var ENABLE_CORNER_ROTATE_ZONES = false;
22
+ export const ENABLE_CORNER_ROTATE_ZONES = false;
23
23
  /** How far under the bottom edge of the frame the turning dot rests, to its middle: half an edge handle, 4 px of air, half the grown dot. */
24
- export var ROTATION_DOT_OFFSET = 21;
24
+ export const ROTATION_DOT_OFFSET = 21;
25
25
  /** The turning dot while nobody is near it: a small handle. */
26
- export var ROTATION_DOT_REST_SIZE = 8;
26
+ export const ROTATION_DOT_REST_SIZE = 8;
27
27
  /** The turning dot under the pointer, and while it turns the selection. */
28
- export var ROTATION_DOT_ACTIVE_SIZE = 24;
28
+ export const ROTATION_DOT_ACTIVE_SIZE = 24;
29
29
  /** A selection thinner than this (screen pixels) has no edge handles: they would cover it, and it could not be moved. */
30
- export var MIN_EDGE_HANDLE_PIXELS = 16;
31
- export var ALL_HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
32
- export var CORNER_HANDLES = ['nw', 'ne', 'se', 'sw'];
30
+ export const MIN_EDGE_HANDLE_PIXELS = 16;
31
+ export const ALL_HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
32
+ export const CORNER_HANDLES = ['nw', 'ne', 'se', 'sw'];
33
33
  /** A text has no top or bottom handle: its height is its lines, so only the corners (which scale the letters) and the sides (which set the width) do anything. */
34
- export var TEXT_HANDLES = ['nw', 'ne', 'se', 'sw', 'e', 'w'];
34
+ export const TEXT_HANDLES = ['nw', 'ne', 'se', 'sw', 'e', 'w'];
35
35
  /** Which handles a selection shows, before its size is looked at (`handleAvailability` does that). */
36
36
  export function visibleHandles(shapes) {
37
37
  if (shapes.length === 1) {
38
- var only = shapes[0];
38
+ const only = shapes[0];
39
39
  if ((only.type === 'path' || only.type === 'ellipse') && only.aspectLocked)
40
40
  return CORNER_HANDLES;
41
41
  if (only.type === 'text')
@@ -44,14 +44,14 @@ export function visibleHandles(shapes) {
44
44
  return ALL_HANDLES;
45
45
  }
46
46
  /** What a selection with nothing special offers. */
47
- export var FULL_AVAILABILITY = Object.freeze({ handles: ALL_HANDLES, canRotate: true });
47
+ export const FULL_AVAILABILITY = Object.freeze({ handles: ALL_HANDLES, canRotate: true });
48
48
  /**
49
49
  * Whether the person can turn a selection. Not when a text is in it, alone, among other shapes, or inside a group: a text
50
50
  * is read upright, so it has no turning dot under its frame and no turning zone outside its corners (the owner's call, 8 Nov
51
51
  * 2026). A text that was saved turned stays as it was saved; nothing here turns it, and nothing turns it back.
52
52
  */
53
53
  export function canRotateSelection(shapes) {
54
- return !shapes.some(function (shape) { return shape.type === 'text'; });
54
+ return !shapes.some((shape) => shape.type === 'text');
55
55
  }
56
56
  /**
57
57
  * The handles of a selection. A widget card is plainer while the page's advanced tools are off (its four corners, no
@@ -59,19 +59,17 @@ export function canRotateSelection(shapes) {
59
59
  * (`canRotateSelection`). A selection that is thinner than `MIN_EDGE_HANDLE_PIXELS` on the screen (`screenSize`) keeps its
60
60
  * corners only.
61
61
  */
62
- export function handleAvailability(shapes, plainCards, screenSize) {
63
- if (plainCards === void 0) { plainCards = false; }
62
+ export function handleAvailability(shapes, plainCards = false, screenSize) {
64
63
  if (plainCards && shapes.length === 1 && shapes[0].type === 'widget')
65
64
  return { handles: CORNER_HANDLES, canRotate: false };
66
- var handles = visibleHandles(shapes);
65
+ let handles = visibleHandles(shapes);
67
66
  if (screenSize && Math.min(screenSize.width, screenSize.height) < MIN_EDGE_HANDLE_PIXELS) {
68
67
  handles = handles.filter(isCornerHandle);
69
68
  }
70
- return { handles: handles, canRotate: canRotateSelection(shapes) };
69
+ return { handles, canRotate: canRotateSelection(shapes) };
71
70
  }
72
71
  /** The handles of a selection whose frame stands on the board at this zoom: `handleAvailability` with the frame's size on the screen. */
73
- export function availableHandles(shapes, frame, viewport, plainCards) {
74
- if (plainCards === void 0) { plainCards = false; }
72
+ export function availableHandles(shapes, frame, viewport, plainCards = false) {
75
73
  return handleAvailability(shapes, plainCards, { width: frame.width * viewport.zoom, height: frame.height * viewport.zoom });
76
74
  }
77
75
  /** Whether a handle sits on a corner of the frame. */
@@ -80,10 +78,10 @@ export function isCornerHandle(handle) {
80
78
  }
81
79
  /** A point of the screen in the frame's own space: pixels from its centre, with the frame's turn undone. */
82
80
  function toFrameSpace(frame, viewport, screenPoint) {
83
- var center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
84
- var radians = -degreesToRadians(frame.rotation);
85
- var deltaX = screenPoint.x - center.x;
86
- var deltaY = screenPoint.y - center.y;
81
+ const center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
82
+ const radians = -degreesToRadians(frame.rotation);
83
+ const deltaX = screenPoint.x - center.x;
84
+ const deltaY = screenPoint.y - center.y;
87
85
  return {
88
86
  local: {
89
87
  x: deltaX * Math.cos(radians) - deltaY * Math.sin(radians),
@@ -107,41 +105,39 @@ function innerReach(reach, shortSide) {
107
105
  * The turning dot comes first (it is drawn above the others), then the corners, then the edges, and last the zone just
108
106
  * outside a corner. Nothing is taken for a selection that offers no turning.
109
107
  */
110
- export function hitSelectionHandle(frame, viewport, screenPoint, metrics, available) {
111
- if (available === void 0) { available = FULL_AVAILABILITY; }
112
- var _a = toFrameSpace(frame, viewport, screenPoint), local = _a.local, halfWidth = _a.halfWidth, halfHeight = _a.halfHeight;
113
- var handles = available.handles, canRotate = available.canRotate;
114
- var shortSide = Math.min(halfWidth, halfHeight) * 2;
108
+ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, available = FULL_AVAILABILITY) {
109
+ const { local, halfWidth, halfHeight } = toFrameSpace(frame, viewport, screenPoint);
110
+ const { handles, canRotate } = available;
111
+ const shortSide = Math.min(halfWidth, halfHeight) * 2;
115
112
  // The dot under the bottom edge.
116
113
  if (canRotate && Math.abs(local.x) <= metrics.dotReach && Math.abs(local.y - (halfHeight + ROTATION_DOT_OFFSET)) <= metrics.dotReach) {
117
114
  return { type: 'rotate', source: 'dot' };
118
115
  }
119
116
  // The corners: a square that reaches `cornerReach` outside the frame and a little into it. The nearest one wins where squares meet.
120
- var cornerInner = innerReach(metrics.cornerReach, shortSide);
121
- var nearest = null;
122
- for (var _i = 0, handles_1 = handles; _i < handles_1.length; _i++) {
123
- var handle = handles_1[_i];
117
+ const cornerInner = innerReach(metrics.cornerReach, shortSide);
118
+ let nearest = null;
119
+ for (const handle of handles) {
124
120
  if (!isCornerHandle(handle))
125
121
  continue;
126
- var direction = handleDirection(handle);
127
- var offsetX = local.x - direction.x * halfWidth;
128
- var offsetY = local.y - direction.y * halfHeight;
122
+ const direction = handleDirection(handle);
123
+ const offsetX = local.x - direction.x * halfWidth;
124
+ const offsetY = local.y - direction.y * halfHeight;
129
125
  // Positive is out of the frame, on the side the corner points to.
130
- var outwardX = offsetX * direction.x;
131
- var outwardY = offsetY * direction.y;
126
+ const outwardX = offsetX * direction.x;
127
+ const outwardY = offsetY * direction.y;
132
128
  if (outwardX > metrics.cornerReach || outwardX < -cornerInner || outwardY > metrics.cornerReach || outwardY < -cornerInner)
133
129
  continue;
134
- var distance = Math.hypot(offsetX, offsetY);
130
+ const distance = Math.hypot(offsetX, offsetY);
135
131
  if (!nearest || distance < nearest.distance)
136
- nearest = { handle: handle, distance: distance };
132
+ nearest = { handle, distance };
137
133
  }
138
134
  if (nearest)
139
135
  return { type: 'resize', handle: nearest.handle };
140
136
  // The edges: a strip along the whole edge, between the corners.
141
- var edgeInner = innerReach(metrics.edgeReach, shortSide);
142
- var onEdge = function (outward) { return outward <= metrics.edgeReach && outward >= -edgeInner; };
143
- var withinWidth = Math.abs(local.x) <= halfWidth;
144
- var withinHeight = Math.abs(local.y) <= halfHeight;
137
+ const edgeInner = innerReach(metrics.edgeReach, shortSide);
138
+ const onEdge = (outward) => outward <= metrics.edgeReach && outward >= -edgeInner;
139
+ const withinWidth = Math.abs(local.x) <= halfWidth;
140
+ const withinHeight = Math.abs(local.y) <= halfHeight;
145
141
  if (withinWidth && handles.includes('n') && onEdge(-(local.y + halfHeight)))
146
142
  return { type: 'resize', handle: 'n' };
147
143
  if (withinWidth && handles.includes('s') && onEdge(local.y - halfHeight))
@@ -152,9 +148,8 @@ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, availa
152
148
  return { type: 'resize', handle: 'e' };
153
149
  // Just outside a corner the selection turns (optional: the dot below the frame is the main control).
154
150
  if (ENABLE_CORNER_ROTATE_ZONES && canRotate && (!withinWidth || !withinHeight)) {
155
- for (var _b = 0, CORNER_HANDLES_1 = CORNER_HANDLES; _b < CORNER_HANDLES_1.length; _b++) {
156
- var handle = CORNER_HANDLES_1[_b];
157
- var direction = handleDirection(handle);
151
+ for (const handle of CORNER_HANDLES) {
152
+ const direction = handleDirection(handle);
158
153
  if (Math.hypot(local.x - direction.x * halfWidth, local.y - direction.y * halfHeight) <= metrics.rotateZone) {
159
154
  return { type: 'rotate', source: 'corner' };
160
155
  }
@@ -164,11 +159,11 @@ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, availa
164
159
  }
165
160
  /** The CSS cursor of a resize handle on a frame turned by `rotation` degrees. */
166
161
  export function cursorForHandle(handle, rotation) {
167
- var direction = handleDirection(handle);
168
- var angle = ((Math.atan2(direction.y, direction.x) * 180) / Math.PI + rotation + 360 * 4) % 180;
162
+ const direction = handleDirection(handle);
163
+ const angle = ((Math.atan2(direction.y, direction.x) * 180) / Math.PI + rotation + 360 * 4) % 180;
169
164
  // 0: along x, 45: down-right, 90: along y, 135: down-left, measured on a screen where y grows downward.
170
- var step = Math.round(angle / 45) % 4;
165
+ const step = Math.round(angle / 45) % 4;
171
166
  return ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'][step];
172
167
  }
173
168
  /** The name the board maps to its turning cursor: there is no CSS keyword for it. */
174
- export var ROTATE_CURSOR = 'rotate';
169
+ export const ROTATE_CURSOR = 'rotate';
@@ -2,4 +2,4 @@
2
2
  * What the input layer exchanges with the shell: plain records, so the whole gesture logic runs in Node tests with
3
3
  * simulated pointers and no browser.
4
4
  */
5
- export var NO_MODIFIERS = Object.freeze({ shiftKey: false, altKey: false, metaKey: false, ctrlKey: false });
5
+ export const NO_MODIFIERS = Object.freeze({ shiftKey: false, altKey: false, metaKey: false, ctrlKey: false });