@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
  * 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 const HOVER_SHAPE_CURSOR = 'pointer';
6
+ export var 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
  */
@@ -24,13 +24,25 @@ export interface KeyInput {
24
24
  }
25
25
  /** A tool that has a letter. The frame and video tools are gone with the objects they made. */
26
26
  export type ToolShortcut = 'select' | 'erase' | 'draw' | 'pan' | 'arrow' | 'rect' | 'triangle' | 'ellipse' | 'text' | 'image';
27
- /** The letter of each tool (the same letters the hints and the list of shortcuts show). */
27
+ /**
28
+ * The letter of each tool (the same letters the hints and the list of shortcuts show).
29
+ *
30
+ * `G` is left out on purpose: it hides the alignment guides while it is held (see `routeKeyDown`), so no tool may take it. The
31
+ * triangle has `Y`.
32
+ */
28
33
  export declare const TOOL_LETTERS: Readonly<Record<string, ToolShortcut>>;
34
+ /**
35
+ * 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
36
+ * 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
37
+ * is open, since the board's own keys are not answered inside a menu.
38
+ */
39
+ export declare function shapeShortcutOf(input: Pick<KeyInput, 'key' | 'altKey' | 'metaKey' | 'ctrlKey'>): ToolShortcut | null;
29
40
  /**
30
41
  * The number of each tool of the drawing bar, in the order the bar lists them (select, draw, erase, arrow, text): the
31
42
  * digits 1 to 5 choose them, besides their letters. A digit is the one the person types (`key`), on the number row or on the
32
- * 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
33
- * list of shortcuts show these same numbers (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
43
+ * numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The numbers are the
44
+ * second way to choose a tool: the hints and the list of shortcuts show the letters only, but the toolbar buttons name these
45
+ * numbers in `aria-keyshortcuts` (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
34
46
  */
35
47
  export declare const TOOL_DIGITS: Readonly<Record<string, ToolShortcut>>;
36
48
  /** What the shell does that the engine does not: the things outside the board. */
@@ -47,6 +59,13 @@ export interface KeyboardActions {
47
59
  afterCopy(): void;
48
60
  /** The person pressed Space to pan: the shell shows the grid while it is held. */
49
61
  spacePanChanged?(held: boolean): void;
62
+ /** The person pressed G (`held`) or let it go: the alignment guides are off while it is held. Told once for the press, for the shell's log. */
63
+ guidesSuppressedChanged?(held: boolean): void;
64
+ /**
65
+ * A key that would change what a gesture works on was taken and left unanswered on purpose, because the pointer is drawing or
66
+ * dragging something (`gesture` is the kind of gesture). Told once for a press, not for the repeats of a held key, for the shell's log.
67
+ */
68
+ keyIgnoredDuringGesture?(key: string, gesture: string): void;
50
69
  }
51
70
  export interface KeyboardHost {
52
71
  engine: EngineCore;
@@ -8,26 +8,48 @@
8
8
  * of each tool, and the number of each tool of the drawing bar); they live here, apart from the DOM, so each one is
9
9
  * tested with a plain record.
10
10
  */
11
- /** The letter of each tool (the same letters the hints and the list of shortcuts show). */
12
- export const TOOL_LETTERS = Object.freeze({
11
+ import { QUICK_CAMERA_MOVE_SCALE } from '../core/cameraMove.js';
12
+ /**
13
+ * The letter of each tool (the same letters the hints and the list of shortcuts show).
14
+ *
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
+ * triangle has `Y`.
17
+ */
18
+ export var TOOL_LETTERS = Object.freeze({
13
19
  V: 'select',
14
20
  E: 'erase',
15
21
  D: 'draw',
16
22
  H: 'pan',
17
23
  A: 'arrow',
18
24
  R: 'rect',
19
- G: 'triangle',
25
+ Y: 'triangle',
20
26
  O: 'ellipse',
21
27
  T: 'text',
22
28
  I: 'image'
23
29
  });
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']);
32
+ /**
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
+ * 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
35
+ * is open, since the board's own keys are not answered inside a menu.
36
+ */
37
+ export function shapeShortcutOf(input) {
38
+ if (input.ctrlKey || input.metaKey || input.altKey)
39
+ return null;
40
+ if (input.key.length !== 1)
41
+ return null;
42
+ var tool = TOOL_LETTERS[input.key.toUpperCase()];
43
+ return tool && SHAPE_SHORTCUTS.has(tool) ? tool : null;
44
+ }
24
45
  /**
25
46
  * The number of each tool of the drawing bar, in the order the bar lists them (select, draw, erase, arrow, text): the
26
47
  * digits 1 to 5 choose them, besides their letters. A digit is the one the person types (`key`), on the number row or on the
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
- * list of shortcuts show these same numbers (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
48
+ * numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The numbers are the
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
+ * numbers in `aria-keyshortcuts` (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
29
51
  */
30
- export const TOOL_DIGITS = Object.freeze({
52
+ export var TOOL_DIGITS = Object.freeze({
31
53
  '1': 'select',
32
54
  '2': 'draw',
33
55
  '3': 'erase',
@@ -35,21 +57,21 @@ export const TOOL_DIGITS = Object.freeze({
35
57
  '5': 'text'
36
58
  });
37
59
  /** The tools that belong to the drawing bar: they are hidden, and so are their letters, when the host turns that bar off. */
38
- const DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
39
- const ARROW_STEPS = Object.freeze({
60
+ var DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
61
+ var ARROW_STEPS = Object.freeze({
40
62
  ArrowUp: [0, -1],
41
63
  ArrowDown: [0, 1],
42
64
  ArrowLeft: [-1, 0],
43
65
  ArrowRight: [1, 0]
44
66
  });
45
67
  /** The nudge of an arrow key, and of an arrow key with Shift, in world units. */
46
- export const NUDGE_DISTANCE = 1;
47
- export const NUDGE_DISTANCE_WITH_SHIFT = 10;
68
+ export var NUDGE_DISTANCE = 1;
69
+ export var NUDGE_DISTANCE_WITH_SHIFT = 10;
48
70
  /** Keys the browser zooms the page with: kept from doing so whatever layout the person has. */
49
71
  export function isBrowserZoomKey(input) {
50
72
  if (!(input.ctrlKey || input.metaKey))
51
73
  return false;
52
- const { key, code } = input;
74
+ var key = input.key, code = input.code;
53
75
  return (key === '=' ||
54
76
  key === '+' ||
55
77
  key === '-' ||
@@ -68,9 +90,25 @@ export function isBrowserZoomKey(input) {
68
90
  function selectionExists(engine) {
69
91
  return engine.state.selectedIds.length > 0;
70
92
  }
93
+ /**
94
+ * Whether a key that would change what a gesture works on is to be left alone, because the pointer is drawing or dragging something.
95
+ * A tool, a delete, a nudge, a layer step, a group or a jump of the view under the gesture would pull the ground from under it (a
96
+ * changed tool even clears the selection and the overlay the gesture draws). The key is still taken, so the browser does nothing with
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
+ */
99
+ function ignoredWhileGesture(input, host) {
100
+ var _a, _b;
101
+ var gesture = host.controller.gestureKind;
102
+ if (!gesture)
103
+ return false;
104
+ // Told once for the press: a held key repeats, and the repeats are not news.
105
+ if (!input.repeat)
106
+ (_b = (_a = host.actions).keyIgnoredDuringGesture) === null || _b === void 0 ? void 0 : _b.call(_a, input.key, gesture);
107
+ return true;
108
+ }
71
109
  /** Escape: leaves whatever is going on, one level at a time. */
72
110
  function handleEscape(host) {
73
- const { engine, controller, actions } = host;
111
+ var engine = host.engine, controller = host.controller, actions = host.actions;
74
112
  if (actions.closePanels())
75
113
  return true;
76
114
  if (controller.cancelGesture())
@@ -95,11 +133,11 @@ function handleEscape(host) {
95
133
  }
96
134
  /** Ctrl or Cmd with a key. Returns undefined when the combination is not one of the board's. */
97
135
  function handleShortcut(input, host) {
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;
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;
103
141
  // The save and the zoom work wherever the focus is.
104
142
  if (lowerKey === 's') {
105
143
  actions.save();
@@ -113,11 +151,24 @@ function handleShortcut(input, host) {
113
151
  engine.zoomStep(-1);
114
152
  return true;
115
153
  }
154
+ // 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
+ // while the view itself is being panned.
156
+ var viewJumpIgnored = function () { return controller.gestureKind !== 'pan' && ignoredWhileGesture(input, host); };
116
157
  if (key === '0') {
117
- engine.zoomReset();
158
+ if (viewJumpIgnored())
159
+ return true;
160
+ // With nothing selected it does what a double click on the empty board does: the view eases back to 100% with the middle of
161
+ // everything that is drawn in the middle of the board. With something selected it keeps resetting the zoom about the middle
162
+ // of the view, so the selection stays where the person was looking at it.
163
+ if (!selectionExists(engine))
164
+ engine.flyToContent({ durationScale: QUICK_CAMERA_MOVE_SCALE });
165
+ else
166
+ engine.zoomReset();
118
167
  return true;
119
168
  }
120
169
  if (key === '9') {
170
+ if (viewJumpIgnored())
171
+ return true;
121
172
  engine.zoomToFit();
122
173
  return true;
123
174
  }
@@ -128,6 +179,8 @@ function handleShortcut(input, host) {
128
179
  case 'a':
129
180
  if (typing)
130
181
  return false;
182
+ if (ignoredWhileGesture(input, host))
183
+ return true;
131
184
  if (engine.state.tool !== 'select')
132
185
  engine.setTool('select');
133
186
  engine.selectAll();
@@ -137,6 +190,8 @@ function handleShortcut(input, host) {
137
190
  return false;
138
191
  if (!selectionExists(engine))
139
192
  return false;
193
+ if (ignoredWhileGesture(input, host))
194
+ return true;
140
195
  if (engine.copySelection())
141
196
  actions.afterCopy();
142
197
  return true;
@@ -145,6 +200,8 @@ function handleShortcut(input, host) {
145
200
  return false;
146
201
  if (!selectionExists(engine))
147
202
  return false;
203
+ if (ignoredWhileGesture(input, host))
204
+ return true;
148
205
  if (engine.cutSelection())
149
206
  actions.afterCopy();
150
207
  return true;
@@ -153,11 +210,15 @@ function handleShortcut(input, host) {
153
210
  return false;
154
211
  if (!selectionExists(engine))
155
212
  return false;
213
+ if (ignoredWhileGesture(input, host))
214
+ return true;
156
215
  engine.duplicateSelection();
157
216
  return true;
158
217
  case 'g':
159
218
  if (typing)
160
219
  return false;
220
+ if (ignoredWhileGesture(input, host))
221
+ return true;
161
222
  if (input.shiftKey)
162
223
  engine.ungroupSelection();
163
224
  else
@@ -172,7 +233,7 @@ function handleShortcut(input, host) {
172
233
  // What a drag is doing is not a step yet: the history waits for the release.
173
234
  if (controller.gestureKind)
174
235
  return true;
175
- const redo = input.code === 'KeyY' || input.shiftKey;
236
+ var redo = input.code === 'KeyY' || input.shiftKey;
176
237
  if (redo)
177
238
  engine.redo();
178
239
  else
@@ -187,13 +248,15 @@ function handleShortcut(input, host) {
187
248
  * The bare brackets keep moving one step, as they always did on this board.
188
249
  */
189
250
  function handleLayerKey(input, host) {
190
- const { engine } = host;
191
- const forward = input.code === 'BracketRight';
251
+ var engine = host.engine;
252
+ var forward = input.code === 'BracketRight';
192
253
  if (host.typingInField || engine.state.editingTextId)
193
254
  return false;
194
255
  if (!selectionExists(engine))
195
256
  return false;
196
- const toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
257
+ if (ignoredWhileGesture(input, host))
258
+ return true;
259
+ var toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
197
260
  engine.reorderSelection(forward ? (toEnd ? 'front' : 'forward') : toEnd ? 'back' : 'backward');
198
261
  return true;
199
262
  }
@@ -206,8 +269,9 @@ export function toolIsAvailable(tool, tools) {
206
269
  * does not also scroll, zoom or select the page.
207
270
  */
208
271
  export function routeKeyDown(input, host) {
209
- const { engine, controller, actions } = host;
210
- const key = input.key;
272
+ var _a, _b, _c;
273
+ var engine = host.engine, controller = host.controller, actions = host.actions;
274
+ var key = input.key;
211
275
  if (key === 'Escape')
212
276
  return handleEscape(host);
213
277
  // The keys that only change what a gesture does while it runs are not answered here: the shell tells the controller.
@@ -216,11 +280,11 @@ export function routeKeyDown(input, host) {
216
280
  if (input.code === 'BracketRight' || input.code === 'BracketLeft')
217
281
  return handleLayerKey(input, host);
218
282
  if (input.ctrlKey || input.metaKey) {
219
- const answered = handleShortcut(input, host);
283
+ var answered = handleShortcut(input, host);
220
284
  // A combination that is not ours (Ctrl+R, Ctrl+P) is the browser's.
221
285
  return answered === true;
222
286
  }
223
- const editingText = !!engine.state.editingTextId;
287
+ var editingText = !!engine.state.editingTextId;
224
288
  if (host.typingInField || editingText)
225
289
  return false;
226
290
  if (input.code === 'Space') {
@@ -230,22 +294,37 @@ export function routeKeyDown(input, host) {
230
294
  if (engine.state.tool === 'pan')
231
295
  return false;
232
296
  controller.setSpaceHeld(true);
233
- actions.spacePanChanged?.(true);
297
+ (_a = actions.spacePanChanged) === null || _a === void 0 ? void 0 : _a.call(actions, true);
298
+ return true;
299
+ }
300
+ // 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).
301
+ // The physical key is read, so Shift (a capital G) and Alt (which types another character on some keyboards) change nothing, and a
302
+ // layout that types another letter on that key still has it. A gesture is not "ignored" here: the key is for the drag itself.
303
+ if (input.code === 'KeyG') {
304
+ // A held key repeats: keep the page still, and change nothing.
305
+ if (input.repeat)
306
+ return true;
307
+ controller.setGuidesSuppressed(true);
308
+ (_b = actions.guidesSuppressedChanged) === null || _b === void 0 ? void 0 : _b.call(actions, true);
234
309
  return true;
235
310
  }
236
311
  if (key === 'Delete' || key === 'Backspace') {
237
312
  if (!selectionExists(engine))
238
313
  return false;
314
+ if (ignoredWhileGesture(input, host))
315
+ return true;
239
316
  void engine.deleteSelection();
240
317
  return true;
241
318
  }
242
- const step = ARROW_STEPS[key];
319
+ var step = ARROW_STEPS[key];
243
320
  if (step) {
244
321
  if (host.selectorHintOpen)
245
322
  return false;
246
323
  if (!selectionExists(engine))
247
324
  return false;
248
- const distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
325
+ if (ignoredWhileGesture(input, host))
326
+ return true;
327
+ var distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
249
328
  engine.nudgeSelection(step[0] * distance, step[1] * distance);
250
329
  return true;
251
330
  }
@@ -257,8 +336,16 @@ export function routeKeyDown(input, host) {
257
336
  return false;
258
337
  // 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
259
338
  // 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.
260
- const tool = key.length === 1 ? (TOOL_LETTERS[key.toUpperCase()] ?? TOOL_DIGITS[key]) : undefined;
339
+ var tool = key.length === 1 ? ((_c = TOOL_LETTERS[key.toUpperCase()]) !== null && _c !== void 0 ? _c : TOOL_DIGITS[key]) : undefined;
261
340
  if (tool && toolIsAvailable(tool, host.tools)) {
341
+ // 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
+ // over): only the first press counts. Choosing a tool also clears the selection and the overlay, so a letter pressed while
343
+ // the pointer is drawing or dragging something must not change the tool under the gesture. Both are taken (the browser does
344
+ // nothing with them) and answered with nothing.
345
+ if (input.repeat)
346
+ return true;
347
+ if (ignoredWhileGesture(input, host))
348
+ return true;
262
349
  actions.chooseTool(tool);
263
350
  return true;
264
351
  }
@@ -266,15 +353,27 @@ export function routeKeyDown(input, host) {
266
353
  }
267
354
  /** A key was released. Returns whether the board used it. */
268
355
  export function routeKeyUp(input, host) {
356
+ var _a, _b, _c, _d;
269
357
  if (input.code === 'Space') {
270
358
  host.controller.setSpaceHeld(false);
271
- host.actions.spacePanChanged?.(false);
359
+ (_b = (_a = host.actions).spacePanChanged) === null || _b === void 0 ? void 0 : _b.call(_a, false);
360
+ return true;
361
+ }
362
+ // 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
+ if (input.code === 'KeyG' && host.controller.guidesSuppressed) {
364
+ host.controller.setGuidesSuppressed(false);
365
+ (_d = (_c = host.actions).guidesSuppressedChanged) === null || _d === void 0 ? void 0 : _d.call(_c, false);
272
366
  return true;
273
367
  }
274
368
  return false;
275
369
  }
276
370
  /** The window lost the focus: nothing is held any more. */
277
371
  export function releaseHeldKeys(host) {
372
+ var _a, _b, _c, _d;
278
373
  host.controller.setSpaceHeld(false);
279
- host.actions.spacePanChanged?.(false);
374
+ (_b = (_a = host.actions).spacePanChanged) === null || _b === void 0 ? void 0 : _b.call(_a, false);
375
+ if (host.controller.guidesSuppressed) {
376
+ host.controller.setGuidesSuppressed(false);
377
+ (_d = (_c = host.actions).guidesSuppressedChanged) === null || _d === void 0 ? void 0 : _d.call(_c, false);
378
+ }
280
379
  }
@@ -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
- const MOUSE_METRICS = { cornerReach: 10, edgeReach: 13, rotateZone: 22, dotReach: 18 };
17
- const TOUCH_METRICS = { cornerReach: 22, edgeReach: 20, rotateZone: 40, dotReach: 24 };
16
+ var MOUSE_METRICS = { cornerReach: 10, edgeReach: 13, rotateZone: 22, dotReach: 18 };
17
+ var 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 const ENABLE_CORNER_ROTATE_ZONES = false;
22
+ export var 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 const ROTATION_DOT_OFFSET = 21;
24
+ export var ROTATION_DOT_OFFSET = 21;
25
25
  /** The turning dot while nobody is near it: a small handle. */
26
- export const ROTATION_DOT_REST_SIZE = 8;
26
+ export var ROTATION_DOT_REST_SIZE = 8;
27
27
  /** The turning dot under the pointer, and while it turns the selection. */
28
- export const ROTATION_DOT_ACTIVE_SIZE = 24;
28
+ export var 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 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'];
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'];
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 const TEXT_HANDLES = ['nw', 'ne', 'se', 'sw', 'e', 'w'];
34
+ export var 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
- const only = shapes[0];
38
+ var 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 const FULL_AVAILABILITY = Object.freeze({ handles: ALL_HANDLES, canRotate: true });
47
+ export var 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((shape) => shape.type === 'text');
54
+ return !shapes.some(function (shape) { return 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,17 +59,19 @@ 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 = false, screenSize) {
62
+ export function handleAvailability(shapes, plainCards, screenSize) {
63
+ if (plainCards === void 0) { plainCards = false; }
63
64
  if (plainCards && shapes.length === 1 && shapes[0].type === 'widget')
64
65
  return { handles: CORNER_HANDLES, canRotate: false };
65
- let handles = visibleHandles(shapes);
66
+ var handles = visibleHandles(shapes);
66
67
  if (screenSize && Math.min(screenSize.width, screenSize.height) < MIN_EDGE_HANDLE_PIXELS) {
67
68
  handles = handles.filter(isCornerHandle);
68
69
  }
69
- return { handles, canRotate: canRotateSelection(shapes) };
70
+ return { handles: handles, canRotate: canRotateSelection(shapes) };
70
71
  }
71
72
  /** The handles of a selection whose frame stands on the board at this zoom: `handleAvailability` with the frame's size on the screen. */
72
- export function availableHandles(shapes, frame, viewport, plainCards = false) {
73
+ export function availableHandles(shapes, frame, viewport, plainCards) {
74
+ if (plainCards === void 0) { plainCards = false; }
73
75
  return handleAvailability(shapes, plainCards, { width: frame.width * viewport.zoom, height: frame.height * viewport.zoom });
74
76
  }
75
77
  /** Whether a handle sits on a corner of the frame. */
@@ -78,10 +80,10 @@ export function isCornerHandle(handle) {
78
80
  }
79
81
  /** A point of the screen in the frame's own space: pixels from its centre, with the frame's turn undone. */
80
82
  function toFrameSpace(frame, viewport, screenPoint) {
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;
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;
85
87
  return {
86
88
  local: {
87
89
  x: deltaX * Math.cos(radians) - deltaY * Math.sin(radians),
@@ -105,39 +107,41 @@ function innerReach(reach, shortSide) {
105
107
  * The turning dot comes first (it is drawn above the others), then the corners, then the edges, and last the zone just
106
108
  * outside a corner. Nothing is taken for a selection that offers no turning.
107
109
  */
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;
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;
112
115
  // The dot under the bottom edge.
113
116
  if (canRotate && Math.abs(local.x) <= metrics.dotReach && Math.abs(local.y - (halfHeight + ROTATION_DOT_OFFSET)) <= metrics.dotReach) {
114
117
  return { type: 'rotate', source: 'dot' };
115
118
  }
116
119
  // The corners: a square that reaches `cornerReach` outside the frame and a little into it. The nearest one wins where squares meet.
117
- const cornerInner = innerReach(metrics.cornerReach, shortSide);
118
- let nearest = null;
119
- for (const handle of handles) {
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];
120
124
  if (!isCornerHandle(handle))
121
125
  continue;
122
- const direction = handleDirection(handle);
123
- const offsetX = local.x - direction.x * halfWidth;
124
- const offsetY = local.y - direction.y * halfHeight;
126
+ var direction = handleDirection(handle);
127
+ var offsetX = local.x - direction.x * halfWidth;
128
+ var offsetY = local.y - direction.y * halfHeight;
125
129
  // Positive is out of the frame, on the side the corner points to.
126
- const outwardX = offsetX * direction.x;
127
- const outwardY = offsetY * direction.y;
130
+ var outwardX = offsetX * direction.x;
131
+ var outwardY = offsetY * direction.y;
128
132
  if (outwardX > metrics.cornerReach || outwardX < -cornerInner || outwardY > metrics.cornerReach || outwardY < -cornerInner)
129
133
  continue;
130
- const distance = Math.hypot(offsetX, offsetY);
134
+ var distance = Math.hypot(offsetX, offsetY);
131
135
  if (!nearest || distance < nearest.distance)
132
- nearest = { handle, distance };
136
+ nearest = { handle: handle, distance: distance };
133
137
  }
134
138
  if (nearest)
135
139
  return { type: 'resize', handle: nearest.handle };
136
140
  // The edges: a strip along the whole edge, between the corners.
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;
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;
141
145
  if (withinWidth && handles.includes('n') && onEdge(-(local.y + halfHeight)))
142
146
  return { type: 'resize', handle: 'n' };
143
147
  if (withinWidth && handles.includes('s') && onEdge(local.y - halfHeight))
@@ -148,8 +152,9 @@ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, availa
148
152
  return { type: 'resize', handle: 'e' };
149
153
  // Just outside a corner the selection turns (optional: the dot below the frame is the main control).
150
154
  if (ENABLE_CORNER_ROTATE_ZONES && canRotate && (!withinWidth || !withinHeight)) {
151
- for (const handle of CORNER_HANDLES) {
152
- const direction = handleDirection(handle);
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);
153
158
  if (Math.hypot(local.x - direction.x * halfWidth, local.y - direction.y * halfHeight) <= metrics.rotateZone) {
154
159
  return { type: 'rotate', source: 'corner' };
155
160
  }
@@ -159,11 +164,11 @@ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, availa
159
164
  }
160
165
  /** The CSS cursor of a resize handle on a frame turned by `rotation` degrees. */
161
166
  export function cursorForHandle(handle, rotation) {
162
- const direction = handleDirection(handle);
163
- const angle = ((Math.atan2(direction.y, direction.x) * 180) / Math.PI + rotation + 360 * 4) % 180;
167
+ var direction = handleDirection(handle);
168
+ var angle = ((Math.atan2(direction.y, direction.x) * 180) / Math.PI + rotation + 360 * 4) % 180;
164
169
  // 0: along x, 45: down-right, 90: along y, 135: down-left, measured on a screen where y grows downward.
165
- const step = Math.round(angle / 45) % 4;
170
+ var step = Math.round(angle / 45) % 4;
166
171
  return ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'][step];
167
172
  }
168
173
  /** The name the board maps to its turning cursor: there is no CSS keyword for it. */
169
- export const ROTATE_CURSOR = 'rotate';
174
+ export var ROTATE_CURSOR = 'rotate';
@@ -55,6 +55,8 @@ export interface Gesture {
55
55
  cancel(): void;
56
56
  /** A modifier key changed while the pointer stayed still (Shift pressed in the middle of a drag). */
57
57
  modifiersChanged?(modifiers: Modifiers, lastInput: PointerInput | null): void;
58
+ /** The key that turns the alignment guides off was pressed or let go while the pointer stayed still (G held in the middle of a drag). */
59
+ guidesSuppressedChanged?(): void;
58
60
  }
59
61
  export interface PointerControllerOptions {
60
62
  /** Whether moving objects snap to the others. Read at every move. */
@@ -79,4 +81,9 @@ export interface PointerControllerOptions {
79
81
  export interface GestureContext {
80
82
  engine: EngineCore;
81
83
  options: PointerControllerOptions;
84
+ /**
85
+ * Whether the person holds the key that turns the alignment guides off (G): a drag then neither snaps to the other shapes nor shows
86
+ * a guide. Read at every step of a drag; a context that leaves it out has the guides on.
87
+ */
88
+ guidesSuppressed?: () => boolean;
82
89
  }
@@ -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 const NO_MODIFIERS = Object.freeze({ shiftKey: false, altKey: false, metaKey: false, ctrlKey: false });
5
+ export var NO_MODIFIERS = Object.freeze({ shiftKey: false, altKey: false, metaKey: false, ctrlKey: false });