@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
@@ -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
  */
@@ -15,7 +15,7 @@ import { QUICK_CAMERA_MOVE_SCALE } from '../core/cameraMove.js';
15
15
  * `G` is left out on purpose: it hides the alignment guides while it is held (see `routeKeyDown`), so no tool may take it. The
16
16
  * triangle has `Y`.
17
17
  */
18
- export var TOOL_LETTERS = Object.freeze({
18
+ export const TOOL_LETTERS = Object.freeze({
19
19
  V: 'select',
20
20
  E: 'erase',
21
21
  D: 'draw',
@@ -28,7 +28,7 @@ export var TOOL_LETTERS = Object.freeze({
28
28
  I: 'image'
29
29
  });
30
30
  /** The tools that are the shapes of the Shapes menu and have a letter: the menu answers these letters while it is open. */
31
- var SHAPE_SHORTCUTS = new Set(['rect', 'triangle', 'ellipse']);
31
+ const SHAPE_SHORTCUTS = new Set(['rect', 'triangle', 'ellipse']);
32
32
  /**
33
33
  * The shape that a key press chooses by its letter, or null when the key is not a shape's letter (or is a chord: Ctrl, Cmd and Alt
34
34
  * with a letter are the browser's, or the board's own commands, not a tool). The Shapes menu uses it to follow the letters while it
@@ -39,7 +39,7 @@ export function shapeShortcutOf(input) {
39
39
  return null;
40
40
  if (input.key.length !== 1)
41
41
  return null;
42
- var tool = TOOL_LETTERS[input.key.toUpperCase()];
42
+ const tool = TOOL_LETTERS[input.key.toUpperCase()];
43
43
  return tool && SHAPE_SHORTCUTS.has(tool) ? tool : null;
44
44
  }
45
45
  /**
@@ -49,7 +49,7 @@ export function shapeShortcutOf(input) {
49
49
  * second way to choose a tool: the hints and the list of shortcuts show the letters only, but the toolbar buttons name these
50
50
  * numbers in `aria-keyshortcuts` (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
51
51
  */
52
- export var TOOL_DIGITS = Object.freeze({
52
+ export const TOOL_DIGITS = Object.freeze({
53
53
  '1': 'select',
54
54
  '2': 'draw',
55
55
  '3': 'erase',
@@ -57,21 +57,21 @@ export var TOOL_DIGITS = Object.freeze({
57
57
  '5': 'text'
58
58
  });
59
59
  /** The tools that belong to the drawing bar: they are hidden, and so are their letters, when the host turns that bar off. */
60
- var DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
61
- var ARROW_STEPS = Object.freeze({
60
+ const DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
61
+ const ARROW_STEPS = Object.freeze({
62
62
  ArrowUp: [0, -1],
63
63
  ArrowDown: [0, 1],
64
64
  ArrowLeft: [-1, 0],
65
65
  ArrowRight: [1, 0]
66
66
  });
67
67
  /** The nudge of an arrow key, and of an arrow key with Shift, in world units. */
68
- export var NUDGE_DISTANCE = 1;
69
- export var NUDGE_DISTANCE_WITH_SHIFT = 10;
68
+ export const NUDGE_DISTANCE = 1;
69
+ export const NUDGE_DISTANCE_WITH_SHIFT = 10;
70
70
  /** Keys the browser zooms the page with: kept from doing so whatever layout the person has. */
71
71
  export function isBrowserZoomKey(input) {
72
72
  if (!(input.ctrlKey || input.metaKey))
73
73
  return false;
74
- var key = input.key, code = input.code;
74
+ const { key, code } = input;
75
75
  return (key === '=' ||
76
76
  key === '+' ||
77
77
  key === '-' ||
@@ -97,26 +97,30 @@ function selectionExists(engine) {
97
97
  * it either, and the shell is told for its log. What steers the gesture stays: Escape (leaves it), the modifier keys and Space.
98
98
  */
99
99
  function ignoredWhileGesture(input, host) {
100
- var _a, _b;
101
- var gesture = host.controller.gestureKind;
100
+ const gesture = host.controller.gestureKind;
102
101
  if (!gesture)
103
102
  return false;
104
103
  // Told once for the press: a held key repeats, and the repeats are not news.
105
104
  if (!input.repeat)
106
- (_b = (_a = host.actions).keyIgnoredDuringGesture) === null || _b === void 0 ? void 0 : _b.call(_a, input.key, gesture);
105
+ host.actions.keyIgnoredDuringGesture?.(input.key, gesture);
107
106
  return true;
108
107
  }
109
108
  /** Escape: leaves whatever is going on, one level at a time. */
110
109
  function handleEscape(host) {
111
- var engine = host.engine, controller = host.controller, actions = host.actions;
110
+ const { engine, controller, actions } = host;
112
111
  if (actions.closePanels())
113
112
  return true;
114
113
  if (controller.cancelGesture())
115
114
  return true;
116
115
  if (engine.state.editingTextId) {
117
- engine.endTextEdit();
116
+ // Escape says "done writing": the text that was typed stays on the board and stays selected, so that what comes next (a colour,
117
+ // a size, a move) is for it; the next Escape lets go of it. A text that ended empty is not kept, so there is nothing to select.
118
+ const keptTextId = engine.endTextEdit();
118
119
  engine.setTool('select');
119
- engine.clearSelection();
120
+ if (keptTextId === null)
121
+ engine.clearSelection();
122
+ else if (!engine.state.selectedIds.includes(keptTextId))
123
+ engine.select([keptTextId]);
120
124
  return true;
121
125
  }
122
126
  // A field of the page that is not ours keeps its Escape.
@@ -133,11 +137,11 @@ function handleEscape(host) {
133
137
  }
134
138
  /** Ctrl or Cmd with a key. Returns undefined when the combination is not one of the board's. */
135
139
  function handleShortcut(input, host) {
136
- var engine = host.engine, controller = host.controller, actions = host.actions;
137
- var key = input.key;
138
- var lowerKey = key.length === 1 ? key.toLowerCase() : key;
139
- var editingText = !!engine.state.editingTextId;
140
- var typing = host.typingInField || editingText;
140
+ const { engine, controller, actions } = host;
141
+ const key = input.key;
142
+ const lowerKey = key.length === 1 ? key.toLowerCase() : key;
143
+ const editingText = !!engine.state.editingTextId;
144
+ const typing = host.typingInField || editingText;
141
145
  // The save and the zoom work wherever the focus is.
142
146
  if (lowerKey === 's') {
143
147
  actions.save();
@@ -153,7 +157,7 @@ function handleShortcut(input, host) {
153
157
  }
154
158
  // A jump of the view is left for later while something is being drawn or dragged (the world would move under the pointer), except
155
159
  // while the view itself is being panned.
156
- var viewJumpIgnored = function () { return controller.gestureKind !== 'pan' && ignoredWhileGesture(input, host); };
160
+ const viewJumpIgnored = () => controller.gestureKind !== 'pan' && ignoredWhileGesture(input, host);
157
161
  if (key === '0') {
158
162
  if (viewJumpIgnored())
159
163
  return true;
@@ -233,7 +237,7 @@ function handleShortcut(input, host) {
233
237
  // What a drag is doing is not a step yet: the history waits for the release.
234
238
  if (controller.gestureKind)
235
239
  return true;
236
- var redo = input.code === 'KeyY' || input.shiftKey;
240
+ const redo = input.code === 'KeyY' || input.shiftKey;
237
241
  if (redo)
238
242
  engine.redo();
239
243
  else
@@ -248,15 +252,15 @@ function handleShortcut(input, host) {
248
252
  * The bare brackets keep moving one step, as they always did on this board.
249
253
  */
250
254
  function handleLayerKey(input, host) {
251
- var engine = host.engine;
252
- var forward = input.code === 'BracketRight';
255
+ const { engine } = host;
256
+ const forward = input.code === 'BracketRight';
253
257
  if (host.typingInField || engine.state.editingTextId)
254
258
  return false;
255
259
  if (!selectionExists(engine))
256
260
  return false;
257
261
  if (ignoredWhileGesture(input, host))
258
262
  return true;
259
- var toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
263
+ const toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
260
264
  engine.reorderSelection(forward ? (toEnd ? 'front' : 'forward') : toEnd ? 'back' : 'backward');
261
265
  return true;
262
266
  }
@@ -269,9 +273,8 @@ export function toolIsAvailable(tool, tools) {
269
273
  * does not also scroll, zoom or select the page.
270
274
  */
271
275
  export function routeKeyDown(input, host) {
272
- var _a, _b, _c;
273
- var engine = host.engine, controller = host.controller, actions = host.actions;
274
- var key = input.key;
276
+ const { engine, controller, actions } = host;
277
+ const key = input.key;
275
278
  if (key === 'Escape')
276
279
  return handleEscape(host);
277
280
  // The keys that only change what a gesture does while it runs are not answered here: the shell tells the controller.
@@ -280,11 +283,11 @@ export function routeKeyDown(input, host) {
280
283
  if (input.code === 'BracketRight' || input.code === 'BracketLeft')
281
284
  return handleLayerKey(input, host);
282
285
  if (input.ctrlKey || input.metaKey) {
283
- var answered = handleShortcut(input, host);
286
+ const answered = handleShortcut(input, host);
284
287
  // A combination that is not ours (Ctrl+R, Ctrl+P) is the browser's.
285
288
  return answered === true;
286
289
  }
287
- var editingText = !!engine.state.editingTextId;
290
+ const editingText = !!engine.state.editingTextId;
288
291
  if (host.typingInField || editingText)
289
292
  return false;
290
293
  if (input.code === 'Space') {
@@ -294,7 +297,7 @@ export function routeKeyDown(input, host) {
294
297
  if (engine.state.tool === 'pan')
295
298
  return false;
296
299
  controller.setSpaceHeld(true);
297
- (_a = actions.spacePanChanged) === null || _a === void 0 ? void 0 : _a.call(actions, true);
300
+ actions.spacePanChanged?.(true);
298
301
  return true;
299
302
  }
300
303
  // G held: the alignment guides are off for as long as it is down (a drag neither snaps to the other shapes nor shows a guide).
@@ -305,7 +308,7 @@ export function routeKeyDown(input, host) {
305
308
  if (input.repeat)
306
309
  return true;
307
310
  controller.setGuidesSuppressed(true);
308
- (_b = actions.guidesSuppressedChanged) === null || _b === void 0 ? void 0 : _b.call(actions, true);
311
+ actions.guidesSuppressedChanged?.(true);
309
312
  return true;
310
313
  }
311
314
  if (key === 'Delete' || key === 'Backspace') {
@@ -316,7 +319,7 @@ export function routeKeyDown(input, host) {
316
319
  void engine.deleteSelection();
317
320
  return true;
318
321
  }
319
- var step = ARROW_STEPS[key];
322
+ const step = ARROW_STEPS[key];
320
323
  if (step) {
321
324
  if (host.selectorHintOpen)
322
325
  return false;
@@ -324,7 +327,7 @@ export function routeKeyDown(input, host) {
324
327
  return false;
325
328
  if (ignoredWhileGesture(input, host))
326
329
  return true;
327
- var distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
330
+ const distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
328
331
  engine.nudgeSelection(step[0] * distance, step[1] * distance);
329
332
  return true;
330
333
  }
@@ -336,7 +339,7 @@ export function routeKeyDown(input, host) {
336
339
  return false;
337
340
  // 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
338
341
  // 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.
339
- var tool = key.length === 1 ? ((_c = TOOL_LETTERS[key.toUpperCase()]) !== null && _c !== void 0 ? _c : TOOL_DIGITS[key]) : undefined;
342
+ const tool = key.length === 1 ? (TOOL_LETTERS[key.toUpperCase()] ?? TOOL_DIGITS[key]) : undefined;
340
343
  if (tool && toolIsAvailable(tool, host.tools)) {
341
344
  // A held key repeats, and the tool is already the one it chooses (and the image tool would open its file chooser over and
342
345
  // over): only the first press counts. Choosing a tool also clears the selection and the overlay, so a letter pressed while
@@ -353,27 +356,25 @@ export function routeKeyDown(input, host) {
353
356
  }
354
357
  /** A key was released. Returns whether the board used it. */
355
358
  export function routeKeyUp(input, host) {
356
- var _a, _b, _c, _d;
357
359
  if (input.code === 'Space') {
358
360
  host.controller.setSpaceHeld(false);
359
- (_b = (_a = host.actions).spacePanChanged) === null || _b === void 0 ? void 0 : _b.call(_a, false);
361
+ host.actions.spacePanChanged?.(false);
360
362
  return true;
361
363
  }
362
364
  // A G that the board is holding is let go; a G that was typed into a field, and never held by the board, is not the board's.
363
365
  if (input.code === 'KeyG' && host.controller.guidesSuppressed) {
364
366
  host.controller.setGuidesSuppressed(false);
365
- (_d = (_c = host.actions).guidesSuppressedChanged) === null || _d === void 0 ? void 0 : _d.call(_c, false);
367
+ host.actions.guidesSuppressedChanged?.(false);
366
368
  return true;
367
369
  }
368
370
  return false;
369
371
  }
370
372
  /** The window lost the focus: nothing is held any more. */
371
373
  export function releaseHeldKeys(host) {
372
- var _a, _b, _c, _d;
373
374
  host.controller.setSpaceHeld(false);
374
- (_b = (_a = host.actions).spacePanChanged) === null || _b === void 0 ? void 0 : _b.call(_a, false);
375
+ host.actions.spacePanChanged?.(false);
375
376
  if (host.controller.guidesSuppressed) {
376
377
  host.controller.setGuidesSuppressed(false);
377
- (_d = (_c = host.actions).guidesSuppressedChanged) === null || _d === void 0 ? void 0 : _d.call(_c, false);
378
+ host.actions.guidesSuppressedChanged?.(false);
378
379
  }
379
380
  }
@@ -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 });