js-draw 1.14.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. package/dist/Editor.css +288 -1
  2. package/dist/bundle.js +2 -2
  3. package/dist/bundledStyles.js +1 -1
  4. package/dist/cjs/Editor.js +5 -0
  5. package/dist/cjs/components/util/StrokeSmoother.js +11 -4
  6. package/dist/cjs/rendering/caching/CacheRecordManager.js +1 -1
  7. package/dist/cjs/rendering/renderers/CanvasRenderer.js +1 -1
  8. package/dist/cjs/testing/sendHtmlSwipe.d.ts +4 -0
  9. package/dist/cjs/testing/sendHtmlSwipe.js +14 -0
  10. package/dist/cjs/toolbar/EdgeToolbar.d.ts +1 -0
  11. package/dist/cjs/toolbar/EdgeToolbar.js +30 -110
  12. package/dist/cjs/toolbar/IconProvider.d.ts +1 -0
  13. package/dist/cjs/toolbar/IconProvider.js +27 -0
  14. package/dist/cjs/toolbar/localization.d.ts +28 -1
  15. package/dist/cjs/toolbar/localization.js +30 -1
  16. package/dist/cjs/toolbar/utils/HelpDisplay.d.ts +37 -0
  17. package/dist/cjs/toolbar/utils/HelpDisplay.js +442 -0
  18. package/dist/cjs/toolbar/utils/HelpDisplay.test.d.ts +1 -0
  19. package/dist/cjs/toolbar/utils/localization.d.ts +9 -0
  20. package/dist/cjs/toolbar/utils/localization.js +11 -0
  21. package/dist/cjs/toolbar/utils/makeDraggable.d.ts +16 -0
  22. package/dist/cjs/toolbar/utils/makeDraggable.js +130 -0
  23. package/dist/cjs/toolbar/widgets/ActionButtonWidget.d.ts +7 -0
  24. package/dist/cjs/toolbar/widgets/ActionButtonWidget.js +14 -2
  25. package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +8 -1
  26. package/dist/cjs/toolbar/widgets/BaseWidget.js +25 -3
  27. package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.d.ts +3 -1
  28. package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +19 -4
  29. package/dist/cjs/toolbar/widgets/HandToolWidget.d.ts +3 -1
  30. package/dist/cjs/toolbar/widgets/HandToolWidget.js +19 -7
  31. package/dist/cjs/toolbar/widgets/InsertImageWidget.js +1 -0
  32. package/dist/cjs/toolbar/widgets/PenToolWidget.d.ts +4 -2
  33. package/dist/cjs/toolbar/widgets/PenToolWidget.js +27 -8
  34. package/dist/cjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
  35. package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +19 -5
  36. package/dist/cjs/toolbar/widgets/components/makeColorInput.d.ts +2 -0
  37. package/dist/cjs/toolbar/widgets/components/makeColorInput.js +17 -7
  38. package/dist/cjs/toolbar/widgets/components/makeGridSelector.d.ts +6 -0
  39. package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +3 -0
  40. package/dist/cjs/tools/FindTool.js +18 -5
  41. package/dist/cjs/tools/PanZoom.d.ts +8 -2
  42. package/dist/cjs/tools/PanZoom.js +29 -10
  43. package/dist/cjs/tools/SelectionTool/Selection.js +16 -2
  44. package/dist/cjs/util/addLongPressOrHoverCssClasses.d.ts +3 -1
  45. package/dist/cjs/util/addLongPressOrHoverCssClasses.js +2 -1
  46. package/dist/cjs/util/cloneElementWithStyles.d.ts +6 -0
  47. package/dist/cjs/util/cloneElementWithStyles.js +32 -0
  48. package/dist/cjs/version.js +1 -1
  49. package/dist/mjs/Editor.mjs +5 -0
  50. package/dist/mjs/components/util/StrokeSmoother.mjs +11 -4
  51. package/dist/mjs/rendering/caching/CacheRecordManager.mjs +1 -1
  52. package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +1 -1
  53. package/dist/mjs/testing/sendHtmlSwipe.d.ts +4 -0
  54. package/dist/mjs/testing/sendHtmlSwipe.mjs +12 -0
  55. package/dist/mjs/toolbar/EdgeToolbar.d.ts +1 -0
  56. package/dist/mjs/toolbar/EdgeToolbar.mjs +30 -110
  57. package/dist/mjs/toolbar/IconProvider.d.ts +1 -0
  58. package/dist/mjs/toolbar/IconProvider.mjs +27 -0
  59. package/dist/mjs/toolbar/localization.d.ts +28 -1
  60. package/dist/mjs/toolbar/localization.mjs +30 -1
  61. package/dist/mjs/toolbar/utils/HelpDisplay.d.ts +37 -0
  62. package/dist/mjs/toolbar/utils/HelpDisplay.mjs +437 -0
  63. package/dist/mjs/toolbar/utils/HelpDisplay.test.d.ts +1 -0
  64. package/dist/mjs/toolbar/utils/localization.d.ts +9 -0
  65. package/dist/mjs/toolbar/utils/localization.mjs +8 -0
  66. package/dist/mjs/toolbar/utils/makeDraggable.d.ts +16 -0
  67. package/dist/mjs/toolbar/utils/makeDraggable.mjs +128 -0
  68. package/dist/mjs/toolbar/widgets/ActionButtonWidget.d.ts +7 -0
  69. package/dist/mjs/toolbar/widgets/ActionButtonWidget.mjs +14 -2
  70. package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +8 -1
  71. package/dist/mjs/toolbar/widgets/BaseWidget.mjs +25 -3
  72. package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.d.ts +3 -1
  73. package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +19 -4
  74. package/dist/mjs/toolbar/widgets/HandToolWidget.d.ts +3 -1
  75. package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +19 -7
  76. package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +1 -0
  77. package/dist/mjs/toolbar/widgets/PenToolWidget.d.ts +4 -2
  78. package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +27 -8
  79. package/dist/mjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
  80. package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +19 -5
  81. package/dist/mjs/toolbar/widgets/components/makeColorInput.d.ts +2 -0
  82. package/dist/mjs/toolbar/widgets/components/makeColorInput.mjs +17 -7
  83. package/dist/mjs/toolbar/widgets/components/makeGridSelector.d.ts +6 -0
  84. package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +3 -0
  85. package/dist/mjs/tools/FindTool.mjs +18 -5
  86. package/dist/mjs/tools/PanZoom.d.ts +8 -2
  87. package/dist/mjs/tools/PanZoom.mjs +29 -10
  88. package/dist/mjs/tools/SelectionTool/Selection.mjs +16 -2
  89. package/dist/mjs/util/addLongPressOrHoverCssClasses.d.ts +3 -1
  90. package/dist/mjs/util/addLongPressOrHoverCssClasses.mjs +2 -1
  91. package/dist/mjs/util/cloneElementWithStyles.d.ts +6 -0
  92. package/dist/mjs/util/cloneElementWithStyles.mjs +30 -0
  93. package/dist/mjs/version.mjs +1 -1
  94. package/package.json +3 -3
  95. package/src/toolbar/EdgeToolbar.scss +23 -2
  96. package/src/toolbar/toolbar.scss +2 -0
  97. package/src/toolbar/utils/HelpDisplay.scss +315 -0
  98. package/src/toolbar/widgets/components/makeColorInput.scss +7 -0
  99. package/src/tools/SelectionTool/SelectionTool.scss +4 -0
@@ -18,7 +18,7 @@ const makeFormatMenu = (editor, selectionTool, localizationTable) => {
18
18
  container.classList.add('selection-format-menu', `${constants_1.toolbarCSSPrefix}spacedList`, `${constants_1.toolbarCSSPrefix}indentedList`);
19
19
  const colorRow = document.createElement('div');
20
20
  const colorLabel = document.createElement('label');
21
- const { input: colorInput, container: colorInputContainer, setValue: setColorInputValue } = (0, makeColorInput_1.default)(editor, color => {
21
+ const colorInputControl = (0, makeColorInput_1.default)(editor, color => {
22
22
  const selection = selectionTool.getSelection();
23
23
  if (selection) {
24
24
  const updateStyleCommands = [];
@@ -31,6 +31,7 @@ const makeFormatMenu = (editor, selectionTool, localizationTable) => {
31
31
  editor.dispatch(unitedCommand);
32
32
  }
33
33
  });
34
+ const { input: colorInput, container: colorInputContainer } = colorInputControl;
34
35
  colorLabel.innerText = localizationTable.colorLabel;
35
36
  const update = () => {
36
37
  const selection = selectionTool.getSelection();
@@ -46,12 +47,12 @@ const makeFormatMenu = (editor, selectionTool, localizationTable) => {
46
47
  }
47
48
  }
48
49
  }
49
- setColorInputValue(math_1.Color4.average(colors));
50
+ colorInputControl.setValue(math_1.Color4.average(colors));
50
51
  }
51
52
  else {
52
53
  colorInput.disabled = true;
53
54
  container.classList.add('disabled');
54
- setColorInputValue(math_1.Color4.transparent);
55
+ colorInputControl.setValue(math_1.Color4.transparent);
55
56
  }
56
57
  };
57
58
  colorRow.replaceChildren(colorLabel, colorInputContainer);
@@ -61,6 +62,10 @@ const makeFormatMenu = (editor, selectionTool, localizationTable) => {
61
62
  parent.appendChild(container);
62
63
  },
63
64
  update,
65
+ registerHelpText: (helpDisplay) => {
66
+ helpDisplay.registerTextHelpForElement(colorRow, localizationTable.selectionDropdown__changeColorHelpText);
67
+ colorInputControl.registerWithHelpTextDisplay(helpDisplay);
68
+ },
64
69
  };
65
70
  };
66
71
  class SelectionToolWidget extends BaseToolWidget_1.default {
@@ -71,16 +76,19 @@ class SelectionToolWidget extends BaseToolWidget_1.default {
71
76
  const resizeButton = new ActionButtonWidget_1.default(editor, 'resize-btn', () => editor.icons.makeResizeImageToSelectionIcon(), this.localizationTable.resizeImageToSelection, () => {
72
77
  this.resizeImageToSelection();
73
78
  }, localization);
79
+ resizeButton.setHelpText(this.localizationTable.selectionDropdown__resizeToHelpText);
74
80
  const deleteButton = new ActionButtonWidget_1.default(editor, 'delete-btn', () => editor.icons.makeDeleteSelectionIcon(), this.localizationTable.deleteSelection, () => {
75
81
  const selection = this.tool.getSelection();
76
82
  this.editor.dispatch(selection.deleteSelectedObjects());
77
83
  this.tool.clearSelection();
78
84
  }, localization);
85
+ deleteButton.setHelpText(this.localizationTable.selectionDropdown__deleteHelpText);
79
86
  const duplicateButton = new ActionButtonWidget_1.default(editor, 'duplicate-btn', () => editor.icons.makeDuplicateSelectionIcon(), this.localizationTable.duplicateSelection, async () => {
80
87
  const selection = this.tool.getSelection();
81
88
  this.editor.dispatch(await selection.duplicateSelectedObjects());
82
89
  this.setDropdownVisible(false);
83
90
  }, localization);
91
+ duplicateButton.setHelpText(this.localizationTable.selectionDropdown__duplicateHelpText);
84
92
  this.addSubWidget(resizeButton);
85
93
  this.addSubWidget(deleteButton);
86
94
  this.addSubWidget(duplicateButton);
@@ -129,8 +137,11 @@ class SelectionToolWidget extends BaseToolWidget_1.default {
129
137
  createIcon() {
130
138
  return this.editor.icons.makeSelectionIcon();
131
139
  }
132
- fillDropdown(dropdown) {
133
- super.fillDropdown(dropdown);
140
+ getHelpText() {
141
+ return this.localizationTable.selectionDropdown__baseHelpText;
142
+ }
143
+ fillDropdown(dropdown, helpDisplay) {
144
+ super.fillDropdown(dropdown, helpDisplay);
134
145
  const controlsContainer = document.createElement('div');
135
146
  controlsContainer.classList.add(`${constants_1.toolbarCSSPrefix}nonbutton-controls-main-list`);
136
147
  dropdown.appendChild(controlsContainer);
@@ -138,6 +149,9 @@ class SelectionToolWidget extends BaseToolWidget_1.default {
138
149
  const formatMenu = makeFormatMenu(this.editor, this.tool, this.localizationTable);
139
150
  formatMenu.addTo(controlsContainer);
140
151
  this.updateFormatMenu = () => formatMenu.update();
152
+ if (helpDisplay) {
153
+ formatMenu.registerHelpText(helpDisplay);
154
+ }
141
155
  formatMenu.update();
142
156
  return true;
143
157
  }
@@ -1,10 +1,12 @@
1
1
  import { Color4 } from '@js-draw/math';
2
2
  import Editor from '../../../Editor';
3
+ import type HelpDisplay from '../../utils/HelpDisplay';
3
4
  type OnColorChangeListener = (color: Color4) => void;
4
5
  export declare const makeColorInput: (editor: Editor, onColorChange: OnColorChangeListener) => {
5
6
  input: HTMLInputElement;
6
7
  container: HTMLSpanElement;
7
8
  setValue: (color: Color4 | string) => void;
8
9
  closePicker: () => void;
10
+ registerWithHelpTextDisplay: (helpDisplay: HelpDisplay) => void;
9
11
  };
10
12
  export default makeColorInput;
@@ -9,13 +9,16 @@ const PipetteTool_1 = __importDefault(require("../../../tools/PipetteTool"));
9
9
  const types_1 = require("../../../types");
10
10
  // Returns [ color input, input container, callback to change the color value ].
11
11
  const makeColorInput = (editor, onColorChange) => {
12
- const colorInputContainer = document.createElement('span');
12
+ const container = document.createElement('span');
13
+ const inputWrapper = document.createElement('span');
13
14
  const colorInput = document.createElement('input');
14
15
  colorInput.type = 'button';
15
16
  colorInput.classList.add('coloris_input');
16
- colorInputContainer.classList.add('color-input-container');
17
- colorInputContainer.appendChild(colorInput);
18
- const pipetteController = addPipetteTool(editor, colorInputContainer, (color) => {
17
+ container.classList.add('color-input-container');
18
+ inputWrapper.classList.add('color-input-wrapper');
19
+ inputWrapper.appendChild(colorInput);
20
+ container.appendChild(inputWrapper);
21
+ const pipetteController = addPipetteTool(editor, container, (color) => {
19
22
  colorInput.value = color.toHexString();
20
23
  onInputEnd();
21
24
  // Update the color preview, if it exists (may be managed by Coloris).
@@ -50,7 +53,7 @@ const makeColorInput = (editor, onColorChange) => {
50
53
  open: true,
51
54
  });
52
55
  pipetteController.cancel();
53
- colorInputContainer.classList.add('picker-open');
56
+ container.classList.add('picker-open');
54
57
  // Focus the Coloris color picker, if it exists.
55
58
  // Don't focus the text input within the color picker, however,
56
59
  // as this displays a keyboard on mobile devices.
@@ -66,7 +69,7 @@ const makeColorInput = (editor, onColorChange) => {
66
69
  onInputEnd();
67
70
  // Restore focus to the input that opened the color picker
68
71
  colorInput.focus();
69
- colorInputContainer.classList.remove('picker-open');
72
+ container.classList.remove('picker-open');
70
73
  };
71
74
  colorInput.addEventListener('close', () => {
72
75
  onClose();
@@ -82,13 +85,17 @@ const makeColorInput = (editor, onColorChange) => {
82
85
  };
83
86
  return {
84
87
  input: colorInput,
85
- container: colorInputContainer,
88
+ container,
86
89
  setValue: setColorInputValue,
87
90
  closePicker: () => {
88
91
  if (isOpen) {
89
92
  onInputEnd();
90
93
  }
91
94
  },
95
+ registerWithHelpTextDisplay: (helpDisplay) => {
96
+ helpDisplay.registerTextHelpForElement(inputWrapper, editor.localization.colorPickerToggleHelpText);
97
+ pipetteController.registerWithHelpTextDisplay(helpDisplay);
98
+ },
92
99
  };
93
100
  };
94
101
  exports.makeColorInput = makeColorInput;
@@ -143,6 +150,9 @@ const addPipetteTool = (editor, container, onColorChange) => {
143
150
  cancel: () => {
144
151
  endColorSelectMode();
145
152
  },
153
+ registerWithHelpTextDisplay: (helpDisplay) => {
154
+ helpDisplay.registerTextHelpForElement(pipetteButton, editor.localization.colorPickerPipetteHelpText);
155
+ },
146
156
  };
147
157
  };
148
158
  exports.default = exports.makeColorInput;
@@ -7,8 +7,14 @@ interface GridSelectChoice<ChoiceIdType> {
7
7
  }
8
8
  interface GridSelector<ChoiceIdType> {
9
9
  value: MutableReactiveValue<ChoiceIdType>;
10
+ /**
11
+ * Connects this grid selector with `other` such that only one item in
12
+ * either this or `other` can be selected at a time.
13
+ */
10
14
  linkWith: (other: GridSelector<ChoiceIdType>) => void;
15
+ /** Re-builds the icons shown in the grid selector. */
11
16
  updateIcons: () => void;
17
+ getRootElement: () => HTMLElement;
12
18
  addTo: (parent: HTMLElement) => void;
13
19
  /** Used internally @internal */
14
20
  _radiogroupName: string;
@@ -136,6 +136,9 @@ labelText, defaultId, choices) => {
136
136
  updateIcons: () => {
137
137
  buttons.forEach(button => button.updateIcon());
138
138
  },
139
+ getRootElement() {
140
+ return outerContainer;
141
+ },
139
142
  addTo: (parent) => {
140
143
  parent.appendChild(outerContainer);
141
144
  },
@@ -7,6 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const TextComponent_1 = __importDefault(require("../components/TextComponent"));
10
+ const ImageComponent_1 = __importDefault(require("../components/ImageComponent"));
10
11
  const BaseTool_1 = __importDefault(require("./BaseTool"));
11
12
  const keybindings_1 = require("./keybindings");
12
13
  const cssPrefix = 'find-tool';
@@ -25,11 +26,23 @@ class FindTool extends BaseTool_1.default {
25
26
  return true;
26
27
  }
27
28
  getMatches(searchFor) {
28
- searchFor = searchFor.toLocaleLowerCase();
29
- const allTextComponents = this.editor.image.getAllElements()
30
- .filter(elem => elem instanceof TextComponent_1.default);
31
- const matches = allTextComponents.filter(text => text.getText().toLocaleLowerCase().indexOf(searchFor) !== -1);
32
- return matches.map(match => match.getBBox());
29
+ const lowerSearchFor = searchFor.toLocaleLowerCase();
30
+ const matchingComponents = this.editor.image.getAllElements().filter(component => {
31
+ let text = '';
32
+ if (component instanceof TextComponent_1.default) {
33
+ text = component.getText();
34
+ }
35
+ else if (component instanceof ImageComponent_1.default) {
36
+ text = component.getAltText() ?? '';
37
+ }
38
+ else {
39
+ return false;
40
+ }
41
+ const hasLowercaseMatch = text.toLocaleLowerCase().indexOf(lowerSearchFor) !== -1;
42
+ const hasSameCaseMatch = text.indexOf(searchFor) !== -1;
43
+ return hasLowercaseMatch || hasSameCaseMatch;
44
+ });
45
+ return matchingComponents.map(match => match.getBBox());
33
46
  }
34
47
  focusCurrentMatch() {
35
48
  const matches = this.getMatches(this.searchInput.value);
@@ -24,13 +24,14 @@ export default class PanZoom extends BaseTool {
24
24
  private readonly initialRotationSnapAngle;
25
25
  private readonly afterRotationStartSnapAngle;
26
26
  private readonly pinchZoomStartThreshold;
27
- private startDist;
28
- private lastDist;
27
+ private startTouchDist;
28
+ private lastTouchDist;
29
29
  private lastScreenCenter;
30
30
  private lastTimestamp;
31
31
  private lastPointerDownTimestamp;
32
32
  private initialTouchAngle;
33
33
  private initialViewportRotation;
34
+ private initialViewportScale;
34
35
  private isScaling;
35
36
  private isRotating;
36
37
  private inertialScroller;
@@ -43,6 +44,11 @@ export default class PanZoom extends BaseTool {
43
44
  private updateVelocity;
44
45
  private getCenterDelta;
45
46
  private toSnappedRotationDelta;
47
+ /**
48
+ * Given a scale update, `scaleFactor`, returns a new scale factor snapped
49
+ * to a power of two (if within some tolerance of that scale).
50
+ */
51
+ private toSnappedScaleFactor;
46
52
  private handleTwoFingerMove;
47
53
  private handleOneFingerMove;
48
54
  onPointerMove({ allPointers }: PointerEvt): void;
@@ -77,9 +77,11 @@ class PanZoom extends BaseTool_1.default {
77
77
  this.initialRotationSnapAngle = 0.22; // radians
78
78
  this.afterRotationStartSnapAngle = 0.07; // radians
79
79
  this.pinchZoomStartThreshold = 1.08; // scale factor
80
+ // Last timestamp at which a pointerdown event was received
80
81
  this.lastPointerDownTimestamp = 0;
81
82
  this.initialTouchAngle = 0;
82
83
  this.initialViewportRotation = 0;
84
+ this.initialViewportScale = 0;
83
85
  // Set to `true` only when scaling has started (if two fingers are down and have moved
84
86
  // far enough).
85
87
  this.isScaling = false;
@@ -119,11 +121,12 @@ class PanZoom extends BaseTool_1.default {
119
121
  const isRightClick = this.allPointersAreOfType(pointers, Pointer_1.PointerDevice.RightButtonMouse);
120
122
  if (allAreTouch && pointers.length === 2 && this.mode & PanZoomMode.TwoFingerTouchGestures) {
121
123
  const { screenCenter, angle, dist } = this.computePinchData(pointers[0], pointers[1]);
122
- this.lastDist = dist;
123
- this.startDist = dist;
124
+ this.lastTouchDist = dist;
125
+ this.startTouchDist = dist;
124
126
  this.lastScreenCenter = screenCenter;
125
127
  this.initialTouchAngle = angle;
126
128
  this.initialViewportRotation = this.editor.viewport.getRotationAngle();
129
+ this.initialViewportScale = this.editor.viewport.getScaleFactor();
127
130
  this.isScaling = false;
128
131
  // We're initially rotated if `initialViewportRotation` isn't near a multiple of pi/2.
129
132
  // In other words, if sin(2 initialViewportRotation) is near zero.
@@ -199,6 +202,22 @@ class PanZoom extends BaseTool_1.default {
199
202
  }
200
203
  return fullRotation - this.editor.viewport.getRotationAngle();
201
204
  }
205
+ /**
206
+ * Given a scale update, `scaleFactor`, returns a new scale factor snapped
207
+ * to a power of two (if within some tolerance of that scale).
208
+ */
209
+ toSnappedScaleFactor(touchDist) {
210
+ // scaleFactor is applied to the current transformation of the viewport.
211
+ const newScale = this.initialViewportScale * touchDist / this.startTouchDist;
212
+ const currentScale = this.editor.viewport.getScaleFactor();
213
+ const logNewScale = Math.log(newScale) / Math.log(10);
214
+ const roundedLogNewScale = Math.round(logNewScale);
215
+ const logTolerance = 0.04;
216
+ if (Math.abs(roundedLogNewScale - logNewScale) < logTolerance) {
217
+ return Math.pow(10, roundedLogNewScale) / currentScale;
218
+ }
219
+ return touchDist / this.lastTouchDist;
220
+ }
202
221
  handleTwoFingerMove(allPointers) {
203
222
  const { screenCenter, canvasCenter, angle, dist } = this.computePinchData(allPointers[0], allPointers[1]);
204
223
  const delta = this.getCenterDelta(screenCenter);
@@ -215,25 +234,25 @@ class PanZoom extends BaseTool_1.default {
215
234
  this.isRotating = true;
216
235
  }
217
236
  this.updateVelocity(screenCenter);
218
- let scaleFactor = 1;
219
- if (this.isScaling) {
220
- scaleFactor = dist / this.lastDist;
221
- }
222
- else {
223
- const initialScaleFactor = dist / this.startDist;
237
+ if (!this.isScaling) {
238
+ const initialScaleFactor = dist / this.startTouchDist;
224
239
  // Only start scaling if scaling done so far exceeds some threshold.
225
240
  const upperBound = this.pinchZoomStartThreshold;
226
241
  const lowerBound = 1 / this.pinchZoomStartThreshold;
227
242
  if (initialScaleFactor > upperBound || initialScaleFactor < lowerBound) {
228
- scaleFactor = initialScaleFactor;
229
243
  this.isScaling = true;
230
244
  }
231
245
  }
246
+ let scaleFactor = 1;
247
+ if (this.isScaling) {
248
+ scaleFactor = this.toSnappedScaleFactor(dist);
249
+ // Don't set lastDist until we start scaling --
250
+ this.lastTouchDist = dist;
251
+ }
232
252
  const transformUpdate = math_1.Mat33.translation(delta)
233
253
  .rightMul(math_1.Mat33.scaling2D(scaleFactor, canvasCenter))
234
254
  .rightMul(math_1.Mat33.zRotation(deltaRotation, canvasCenter));
235
255
  this.lastScreenCenter = screenCenter;
236
- this.lastDist = dist;
237
256
  this.transform = Viewport_1.Viewport.transformBy(this.transform.transform.rightMul(transformUpdate));
238
257
  return transformUpdate;
239
258
  }
@@ -108,6 +108,7 @@ class Selection {
108
108
  for (const handle of this.handles) {
109
109
  handle.addTo(this.backgroundElem);
110
110
  }
111
+ this.updateUI();
111
112
  }
112
113
  // @internal Intended for unit tests
113
114
  getBackgroundElem() {
@@ -313,6 +314,13 @@ class Selection {
313
314
  else {
314
315
  this.innerContainer.classList.remove(perpendicularClassName);
315
316
  }
317
+ // Hide handles when empty
318
+ if (screenRegion.width === 0 && screenRegion.height === 0) {
319
+ this.innerContainer.classList.add('-empty');
320
+ }
321
+ else {
322
+ this.innerContainer.classList.remove('-empty');
323
+ }
316
324
  for (const handle of this.handles) {
317
325
  handle.updatePosition();
318
326
  }
@@ -561,7 +569,11 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand_1.defau
561
569
  this.transformCommands = this.selectedElemIds.map(id => {
562
570
  const elem = editor.image.lookupElement(id);
563
571
  if (!elem) {
564
- throw new Error(`Unable to find element with ID, ${id}.`);
572
+ // There may be valid reasons for an element lookup to fail:
573
+ // For example, if the element was deleted remotely and the remote deletion
574
+ // hasn't been undone.
575
+ console.warn(`Unable to find element with ID, ${id}.`);
576
+ return null;
565
577
  }
566
578
  let originalZIndex = elem.getZIndex();
567
579
  let targetZIndex = elem.getZIndex() + this.deltaZIndex;
@@ -572,7 +584,9 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand_1.defau
572
584
  originalZIndex = elem.getZIndex() - this.deltaZIndex;
573
585
  }
574
586
  return elem.setZIndexAndTransformBy(this.fullTransform, targetZIndex, originalZIndex);
575
- });
587
+ }).filter(// Remove all null commands
588
+ // Remove all null commands
589
+ command => command !== null);
576
590
  }
577
591
  async apply(editor) {
578
592
  this.resolveToElems(editor, false);
@@ -4,7 +4,9 @@
4
4
  *
5
5
  * When no pointers are inside `element`, adds the CSS class `no-long-press-or-hover`.
6
6
  */
7
- declare const addLongPressOrHoverCssClasses: (element: HTMLElement) => {
7
+ declare const addLongPressOrHoverCssClasses: (element: HTMLElement, options?: {
8
+ timeout: number;
9
+ }) => {
8
10
  removeEventListeners: () => void;
9
11
  };
10
12
  export default addLongPressOrHoverCssClasses;
@@ -10,7 +10,7 @@ const listenForLongPressOrHover_1 = __importDefault(require("./listenForLongPres
10
10
  *
11
11
  * When no pointers are inside `element`, adds the CSS class `no-long-press-or-hover`.
12
12
  */
13
- const addLongPressOrHoverCssClasses = (element) => {
13
+ const addLongPressOrHoverCssClasses = (element, options) => {
14
14
  const hasLongPressClass = 'has-long-press-or-hover';
15
15
  const noLongPressClass = 'no-long-press-or-hover';
16
16
  element.classList.add('no-long-press-or-hover');
@@ -23,6 +23,7 @@ const addLongPressOrHoverCssClasses = (element) => {
23
23
  element.classList.add(noLongPressClass);
24
24
  element.classList.remove(hasLongPressClass);
25
25
  },
26
+ longPressTimeout: options?.timeout,
26
27
  });
27
28
  return {
28
29
  removeEventListeners: () => {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Makes a clone of `element` and recursively applies styles from the original to the
3
+ * clone's children.
4
+ */
5
+ declare const cloneElementWithStyles: (element: HTMLElement) => HTMLElement;
6
+ export default cloneElementWithStyles;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Makes a clone of `element` and recursively applies styles from the original to the
5
+ * clone's children.
6
+ */
7
+ const cloneElementWithStyles = (element) => {
8
+ const restyle = (originalElement, clonedElement) => {
9
+ const originalComputedStyle = getComputedStyle(originalElement);
10
+ // jsdom doesn't support iterators in CSSStyleDeclarations. Iterate with
11
+ // an index.
12
+ for (let index = 0; index < originalComputedStyle.length; index++) {
13
+ const propertyName = originalComputedStyle.item(index);
14
+ const propertyValue = originalComputedStyle.getPropertyValue(propertyName);
15
+ clonedElement.style.setProperty(propertyName, propertyValue);
16
+ }
17
+ for (let i = 0; i < originalElement.children.length; i++) {
18
+ const originalChild = originalElement.children.item(i);
19
+ const clonedChild = clonedElement.children.item(i);
20
+ if (originalChild && clonedChild) {
21
+ restyle(originalChild, clonedChild);
22
+ }
23
+ else {
24
+ console.warn('CloneElement: Missing child');
25
+ }
26
+ }
27
+ };
28
+ const elementClone = element.cloneNode(true);
29
+ restyle(element, elementClone);
30
+ return elementClone;
31
+ };
32
+ exports.default = cloneElementWithStyles;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
- number: '1.14.0',
4
+ number: '1.16.0',
5
5
  };
@@ -1198,6 +1198,11 @@ export class Editor {
1198
1198
  '',
1199
1199
  '== Bezier.js ==',
1200
1200
  mitLicenseAttribution('2023 Mike "Pomax" Kamermans'),
1201
+ '',
1202
+ '',
1203
+ '== js-draw ==',
1204
+ mitLicenseAttribution('2023 Henry Heino'),
1205
+ '',
1201
1206
  ].join('\n'),
1202
1207
  minimized: true,
1203
1208
  });
@@ -144,7 +144,7 @@ export class StrokeSmoother {
144
144
  }
145
145
  let exitingVec = this.computeExitingVec();
146
146
  // Find the intersection between the entering vector and the exiting vector
147
- const maxRelativeLength = 2.4;
147
+ const maxRelativeLength = 1.7;
148
148
  const segmentStart = this.buffer[0];
149
149
  const segmentEnd = newPoint.pos;
150
150
  const startEndDist = segmentEnd.minus(segmentStart).magnitude();
@@ -165,11 +165,18 @@ export class StrokeSmoother {
165
165
  if (intersection) {
166
166
  controlPoint = intersection.point;
167
167
  }
168
- // No intersection or the intersection is one of the end points?
169
- if (!controlPoint || segmentStart.eq(controlPoint) || segmentEnd.eq(controlPoint)) {
168
+ // No intersection?
169
+ if (!controlPoint) {
170
+ // Estimate the control point position based on the entering tangent line
171
+ controlPoint = segmentStart
172
+ .lerp(segmentEnd, 0.5)
173
+ .lerp(segmentStart.plus(enteringVec.times(startEndDist)), 0.1);
174
+ }
175
+ // Equal to an endpoint?
176
+ if (segmentStart.eq(controlPoint) || segmentEnd.eq(controlPoint)) {
170
177
  // Position the control point closer to the first -- the connecting
171
178
  // segment will be roughly a line.
172
- controlPoint = segmentStart.plus(enteringVec.times(startEndDist / 4));
179
+ controlPoint = segmentStart.plus(enteringVec.times(startEndDist / 5));
173
180
  }
174
181
  console.assert(!segmentStart.eq(controlPoint, 1e-11), 'Start and control points are equal!');
175
182
  console.assert(!controlPoint.eq(segmentEnd, 1e-11), 'Control and end points are equal!');
@@ -49,7 +49,7 @@ export class CacheRecordManager {
49
49
  numberAllocd++;
50
50
  }
51
51
  }
52
- averageReassignedCount /= Math.max(this.cacheRecords.length, 0);
52
+ averageReassignedCount /= Math.max(this.cacheRecords.length, 1);
53
53
  const debugInfo = [
54
54
  `${this.cacheRecords.length} cache records (max ${this.maxCanvases})`,
55
55
  `${numberAllocd} assigned to screen regions`,
@@ -238,7 +238,7 @@ export default class CanvasRenderer extends AbstractRenderer {
238
238
  // @internal
239
239
  isTooSmallToRender(rect) {
240
240
  // Should we ignore all objects within this object's bbox?
241
- const diagonal = this.getCanvasToScreenTransform().transformVec3(rect.size);
241
+ const diagonal = rect.size.times(this.getCanvasToScreenTransform().getScaleFactor());
242
242
  const bothDimenMinSize = this.minRenderSizeBothDimens;
243
243
  const bothTooSmall = Math.abs(diagonal.x) < bothDimenMinSize && Math.abs(diagonal.y) < bothDimenMinSize;
244
244
  const anyDimenMinSize = this.minRenderSizeAnyDimen;
@@ -0,0 +1,4 @@
1
+ import { Point2 } from '@js-draw/math';
2
+ /** Swipes `element` using HTML pointer events. */
3
+ declare const sendHtmlSwipe: (element: HTMLElement, start: Point2, end: Point2, timeMs?: number) => Promise<void>;
4
+ export default sendHtmlSwipe;
@@ -0,0 +1,12 @@
1
+ /** Swipes `element` using HTML pointer events. */
2
+ const sendHtmlSwipe = async (element, start, end, timeMs = 300) => {
3
+ element.dispatchEvent(new PointerEvent('pointerdown', { isPrimary: true, clientX: start.x, clientY: start.y, }));
4
+ const step = 0.1;
5
+ for (let i = 0; i < 1; i += step) {
6
+ await jest.advanceTimersByTimeAsync(timeMs * step);
7
+ const currentPoint = start.lerp(end, i);
8
+ element.dispatchEvent(new PointerEvent('pointermove', { isPrimary: true, clientX: currentPoint.x, clientY: currentPoint.y, }));
9
+ }
10
+ element.dispatchEvent(new PointerEvent('pointerup', { isPrimary: true, clientX: end.x, clientY: end.y, }));
11
+ };
12
+ export default sendHtmlSwipe;
@@ -44,6 +44,7 @@ export default class EdgeToolbar extends AbstractToolbar {
44
44
  private sidebarVisible;
45
45
  private sidebarY;
46
46
  private sidebarTitle;
47
+ private clearDragListeners;
47
48
  /** @internal */
48
49
  constructor(editor: Editor, parent: HTMLElement, localizationTable: ToolbarLocalization);
49
50
  private listenForVisibilityChanges;