js-draw 1.21.3 → 1.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +103 -75
- package/build-config.json +2 -2
- package/dist/Editor.css +29 -16
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.js +36 -22
- package/dist/cjs/EventDispatcher.js +1 -1
- package/dist/cjs/Pointer.js +3 -3
- package/dist/cjs/SVGLoader/SVGLoader.js +13 -6
- package/dist/cjs/UndoRedoHistory.js +1 -1
- package/dist/cjs/Viewport.js +4 -2
- package/dist/cjs/commands/Command.js +7 -5
- package/dist/cjs/commands/Duplicate.js +2 -2
- package/dist/cjs/commands/Erase.js +3 -4
- package/dist/cjs/commands/invertCommand.js +4 -4
- package/dist/cjs/commands/lib.d.ts +1 -1
- package/dist/cjs/commands/uniteCommands.js +4 -4
- package/dist/cjs/components/AbstractComponent.d.ts +1 -1
- package/dist/cjs/components/AbstractComponent.js +3 -3
- package/dist/cjs/components/BackgroundComponent.js +8 -6
- package/dist/cjs/components/ImageComponent.js +12 -5
- package/dist/cjs/components/RestylableComponent.js +1 -1
- package/dist/cjs/components/SVGGlobalAttributesObject.js +1 -2
- package/dist/cjs/components/Stroke.js +37 -24
- package/dist/cjs/components/TextComponent.js +13 -10
- package/dist/cjs/components/UnknownSVGObject.js +2 -3
- package/dist/cjs/components/builders/ArrowBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/ArrowBuilder.js +9 -3
- package/dist/cjs/components/builders/CircleBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/CircleBuilder.js +11 -4
- package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/FreehandLineBuilder.js +10 -4
- package/dist/cjs/components/builders/LineBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/LineBuilder.js +8 -4
- package/dist/cjs/components/builders/PolylineBuilder.d.ts +4 -1
- package/dist/cjs/components/builders/PolylineBuilder.js +9 -5
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +16 -10
- package/dist/cjs/components/builders/RectangleBuilder.d.ts +12 -0
- package/dist/cjs/components/builders/RectangleBuilder.js +17 -3
- package/dist/cjs/components/builders/autocorrect/makeShapeFitAutocorrect.js +5 -8
- package/dist/cjs/components/builders/autocorrect/makeSnapToGridAutocorrect.js +1 -1
- package/dist/cjs/components/builders/lib.d.ts +7 -0
- package/dist/cjs/components/builders/lib.js +18 -0
- package/dist/cjs/components/lib.d.ts +1 -4
- package/dist/cjs/components/lib.js +2 -9
- package/dist/cjs/components/util/StrokeSmoother.js +5 -6
- package/dist/cjs/dialogs/makeAboutDialog.js +1 -1
- package/dist/cjs/dialogs/makeMessageDialog.js +2 -2
- package/dist/cjs/image/EditorImage.js +13 -15
- package/dist/cjs/image/export/editorImageToSVG.js +1 -1
- package/dist/cjs/inputEvents.js +3 -3
- package/dist/cjs/lib.d.ts +2 -2
- package/dist/cjs/localizations/de.js +2 -2
- package/dist/cjs/localizations/es.js +7 -3
- package/dist/cjs/rendering/Display.js +7 -3
- package/dist/cjs/rendering/RenderablePathSpec.js +26 -11
- package/dist/cjs/rendering/RenderingStyle.js +22 -15
- package/dist/cjs/rendering/TextRenderingStyle.js +1 -1
- package/dist/cjs/rendering/caching/CacheRecord.js +1 -1
- package/dist/cjs/rendering/caching/CacheRecordManager.js +1 -1
- package/dist/cjs/rendering/caching/RenderingCache.js +1 -1
- package/dist/cjs/rendering/caching/RenderingCacheNode.js +26 -15
- package/dist/cjs/rendering/caching/testUtils.js +2 -2
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +3 -1
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +4 -3
- package/dist/cjs/rendering/renderers/DummyRenderer.js +1 -1
- package/dist/cjs/rendering/renderers/SVGRenderer.js +37 -19
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +13 -15
- package/dist/cjs/shortcuts/KeyBinding.js +6 -12
- package/dist/cjs/shortcuts/KeyboardShortcutManager.js +2 -2
- package/dist/cjs/testing/createEditor.js +6 -1
- package/dist/cjs/testing/findNodeWithText.d.ts +4 -1
- package/dist/cjs/testing/findNodeWithText.js +12 -3
- package/dist/cjs/testing/getUniquePointerId.js +1 -1
- package/dist/cjs/testing/sendHtmlSwipe.js +7 -3
- package/dist/cjs/testing/sendPenEvent.js +1 -3
- package/dist/cjs/testing/sendTouchEvent.js +1 -4
- package/dist/cjs/testing/startPinchGesture.js +3 -1
- package/dist/cjs/toolbar/AbstractToolbar.js +7 -11
- package/dist/cjs/toolbar/EdgeToolbar.js +11 -15
- package/dist/cjs/toolbar/IconProvider.js +5 -3
- package/dist/cjs/toolbar/localization.js +3 -3
- package/dist/cjs/toolbar/utils/HelpDisplay.js +8 -6
- package/dist/cjs/toolbar/utils/makeDraggable.js +4 -7
- package/dist/cjs/toolbar/widgets/BaseToolWidget.js +3 -2
- package/dist/cjs/toolbar/widgets/BaseWidget.js +7 -7
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +2 -2
- package/dist/cjs/toolbar/widgets/EraserToolWidget.js +5 -3
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +8 -6
- package/dist/cjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.js +9 -10
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +22 -13
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +2 -2
- package/dist/cjs/toolbar/widgets/TextToolWidget.js +5 -5
- package/dist/cjs/toolbar/widgets/components/makeFileInput.js +7 -7
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +5 -5
- package/dist/cjs/toolbar/widgets/components/makeSnappedList.js +9 -5
- package/dist/cjs/toolbar/widgets/keybindings.js +2 -2
- package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.js +6 -6
- package/dist/cjs/tools/BaseTool.js +5 -3
- package/dist/cjs/tools/Eraser.js +25 -20
- package/dist/cjs/tools/FindTool.js +2 -2
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.js +1 -3
- package/dist/cjs/tools/InputFilter/InputMapper.js +1 -1
- package/dist/cjs/tools/InputFilter/InputPipeline.js +1 -1
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +12 -5
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +7 -4
- package/dist/cjs/tools/PanZoom.d.ts +1 -1
- package/dist/cjs/tools/PanZoom.js +17 -12
- package/dist/cjs/tools/PasteHandler.js +8 -2
- package/dist/cjs/tools/Pen.js +17 -9
- package/dist/cjs/tools/ScrollbarTool.js +8 -7
- package/dist/cjs/tools/SelectionTool/Selection.js +16 -12
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +5 -2
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +3 -1
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +25 -16
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.js +1 -1
- package/dist/cjs/tools/SelectionTool/TransformMode.js +6 -7
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.js +23 -2
- package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.js +29 -20
- package/dist/cjs/tools/SoundUITool.js +5 -3
- package/dist/cjs/tools/TextTool.js +8 -6
- package/dist/cjs/tools/ToolController.js +16 -10
- package/dist/cjs/tools/localization.d.ts +2 -0
- package/dist/cjs/tools/localization.js +3 -1
- package/dist/cjs/tools/util/StationaryPenDetector.js +3 -3
- package/dist/cjs/tools/util/createMenuOverlay.js +2 -2
- package/dist/cjs/util/ClipboardHandler.d.ts +1 -1
- package/dist/cjs/util/ClipboardHandler.js +19 -18
- package/dist/cjs/util/ReactiveValue.js +16 -12
- package/dist/cjs/util/adjustEditorThemeForContrast.js +6 -2
- package/dist/cjs/util/guessKeyCodeFromKey.js +1 -1
- package/dist/cjs/util/listenForKeyboardEventsFrom.js +8 -6
- package/dist/cjs/util/waitForAll.js +3 -3
- package/dist/cjs/util/waitForImageLoaded.js +3 -3
- package/dist/cjs/util/waitForTimeout.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.mjs +37 -23
- package/dist/mjs/EventDispatcher.mjs +1 -1
- package/dist/mjs/Pointer.mjs +3 -3
- package/dist/mjs/SVGLoader/SVGLoader.mjs +14 -7
- package/dist/mjs/UndoRedoHistory.mjs +1 -1
- package/dist/mjs/Viewport.mjs +4 -2
- package/dist/mjs/commands/Command.mjs +7 -5
- package/dist/mjs/commands/Duplicate.mjs +2 -2
- package/dist/mjs/commands/Erase.mjs +3 -4
- package/dist/mjs/commands/invertCommand.mjs +4 -4
- package/dist/mjs/commands/lib.d.ts +1 -1
- package/dist/mjs/commands/lib.mjs +1 -1
- package/dist/mjs/commands/uniteCommands.mjs +4 -4
- package/dist/mjs/components/AbstractComponent.d.ts +1 -1
- package/dist/mjs/components/AbstractComponent.mjs +3 -3
- package/dist/mjs/components/BackgroundComponent.mjs +10 -8
- package/dist/mjs/components/ImageComponent.mjs +12 -5
- package/dist/mjs/components/RestylableComponent.mjs +2 -2
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +1 -2
- package/dist/mjs/components/Stroke.mjs +40 -27
- package/dist/mjs/components/TextComponent.mjs +15 -12
- package/dist/mjs/components/UnknownSVGObject.mjs +2 -3
- package/dist/mjs/components/builders/ArrowBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/ArrowBuilder.mjs +9 -3
- package/dist/mjs/components/builders/CircleBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/CircleBuilder.mjs +11 -4
- package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/FreehandLineBuilder.mjs +10 -4
- package/dist/mjs/components/builders/LineBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/LineBuilder.mjs +8 -4
- package/dist/mjs/components/builders/PolylineBuilder.d.ts +4 -1
- package/dist/mjs/components/builders/PolylineBuilder.mjs +10 -6
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +17 -11
- package/dist/mjs/components/builders/RectangleBuilder.d.ts +12 -0
- package/dist/mjs/components/builders/RectangleBuilder.mjs +17 -3
- package/dist/mjs/components/builders/autocorrect/makeShapeFitAutocorrect.mjs +5 -8
- package/dist/mjs/components/builders/autocorrect/makeSnapToGridAutocorrect.mjs +1 -1
- package/dist/mjs/components/builders/lib.d.ts +7 -0
- package/dist/mjs/components/builders/lib.mjs +7 -0
- package/dist/mjs/components/lib.d.ts +1 -4
- package/dist/mjs/components/lib.mjs +2 -5
- package/dist/mjs/components/util/StrokeSmoother.mjs +5 -6
- package/dist/mjs/dialogs/makeAboutDialog.mjs +1 -1
- package/dist/mjs/dialogs/makeMessageDialog.mjs +2 -2
- package/dist/mjs/image/EditorImage.mjs +13 -15
- package/dist/mjs/image/export/editorImageToSVG.mjs +1 -1
- package/dist/mjs/inputEvents.mjs +3 -3
- package/dist/mjs/lib.d.ts +2 -2
- package/dist/mjs/lib.mjs +2 -2
- package/dist/mjs/localization.mjs +2 -2
- package/dist/mjs/localizations/de.mjs +2 -2
- package/dist/mjs/localizations/es.mjs +7 -3
- package/dist/mjs/rendering/Display.mjs +7 -3
- package/dist/mjs/rendering/RenderablePathSpec.mjs +26 -11
- package/dist/mjs/rendering/RenderingStyle.mjs +22 -15
- package/dist/mjs/rendering/TextRenderingStyle.mjs +1 -1
- package/dist/mjs/rendering/caching/CacheRecord.mjs +1 -1
- package/dist/mjs/rendering/caching/CacheRecordManager.mjs +1 -1
- package/dist/mjs/rendering/caching/RenderingCache.mjs +1 -1
- package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +26 -15
- package/dist/mjs/rendering/caching/testUtils.mjs +2 -2
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +3 -1
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +4 -3
- package/dist/mjs/rendering/renderers/DummyRenderer.mjs +1 -1
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +38 -20
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +13 -15
- package/dist/mjs/shortcuts/KeyBinding.mjs +6 -12
- package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +2 -2
- package/dist/mjs/testing/createEditor.mjs +6 -1
- package/dist/mjs/testing/findNodeWithText.d.ts +4 -1
- package/dist/mjs/testing/findNodeWithText.mjs +12 -3
- package/dist/mjs/testing/getUniquePointerId.mjs +1 -1
- package/dist/mjs/testing/sendHtmlSwipe.mjs +7 -3
- package/dist/mjs/testing/sendPenEvent.mjs +1 -3
- package/dist/mjs/testing/sendTouchEvent.mjs +1 -4
- package/dist/mjs/testing/startPinchGesture.mjs +3 -1
- package/dist/mjs/toolbar/AbstractToolbar.mjs +7 -11
- package/dist/mjs/toolbar/EdgeToolbar.mjs +11 -15
- package/dist/mjs/toolbar/IconProvider.mjs +5 -3
- package/dist/mjs/toolbar/localization.mjs +3 -3
- package/dist/mjs/toolbar/utils/HelpDisplay.mjs +8 -6
- package/dist/mjs/toolbar/utils/makeDraggable.mjs +4 -7
- package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +3 -2
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +8 -8
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +2 -2
- package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +5 -3
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +8 -6
- package/dist/mjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.mjs +9 -10
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +23 -14
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +2 -2
- package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +5 -5
- package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +7 -7
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +5 -5
- package/dist/mjs/toolbar/widgets/components/makeSnappedList.mjs +9 -5
- package/dist/mjs/toolbar/widgets/keybindings.mjs +2 -2
- package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.mjs +6 -6
- package/dist/mjs/tools/BaseTool.mjs +6 -4
- package/dist/mjs/tools/Eraser.mjs +25 -20
- package/dist/mjs/tools/FindTool.mjs +2 -2
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.mjs +2 -4
- package/dist/mjs/tools/InputFilter/InputMapper.mjs +1 -1
- package/dist/mjs/tools/InputFilter/InputPipeline.mjs +1 -1
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +13 -6
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +7 -4
- package/dist/mjs/tools/PanZoom.d.ts +1 -1
- package/dist/mjs/tools/PanZoom.mjs +18 -13
- package/dist/mjs/tools/PasteHandler.mjs +8 -2
- package/dist/mjs/tools/Pen.mjs +18 -10
- package/dist/mjs/tools/ScrollbarTool.mjs +8 -7
- package/dist/mjs/tools/SelectionTool/Selection.mjs +16 -12
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +5 -2
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +3 -1
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +26 -17
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.mjs +1 -1
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +6 -7
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.mjs +23 -2
- package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.mjs +29 -20
- package/dist/mjs/tools/SoundUITool.mjs +5 -3
- package/dist/mjs/tools/TextTool.mjs +8 -6
- package/dist/mjs/tools/ToolController.mjs +16 -10
- package/dist/mjs/tools/localization.d.ts +2 -0
- package/dist/mjs/tools/localization.mjs +3 -1
- package/dist/mjs/tools/util/StationaryPenDetector.mjs +3 -3
- package/dist/mjs/tools/util/createMenuOverlay.mjs +2 -2
- package/dist/mjs/util/ClipboardHandler.d.ts +1 -1
- package/dist/mjs/util/ClipboardHandler.mjs +19 -18
- package/dist/mjs/util/ReactiveValue.mjs +16 -12
- package/dist/mjs/util/adjustEditorThemeForContrast.mjs +6 -2
- package/dist/mjs/util/guessKeyCodeFromKey.mjs +1 -1
- package/dist/mjs/util/listenForKeyboardEventsFrom.mjs +8 -6
- package/dist/mjs/util/waitForAll.mjs +3 -3
- package/dist/mjs/util/waitForImageLoaded.mjs +3 -3
- package/dist/mjs/util/waitForTimeout.mjs +1 -1
- package/dist/mjs/version.mjs +1 -1
- package/package.json +88 -88
- package/src/Coloris.css +6 -6
- package/src/Editor.scss +7 -5
- package/src/dialogs/dialogs.scss +3 -4
- package/src/dialogs/makeAboutDialog.scss +2 -2
- package/src/dialogs/makeMessageDialog.scss +11 -7
- package/src/styles.js +1 -1
- package/src/toolbar/AbstractToolbar.scss +20 -12
- package/src/toolbar/DropdownToolbar.scss +5 -4
- package/src/toolbar/EdgeToolbar.scss +65 -31
- package/src/toolbar/toolbar.scss +5 -5
- package/src/toolbar/utils/HelpDisplay.scss +48 -25
- package/src/toolbar/utils/labelVisibleOnHover.scss +39 -16
- package/src/toolbar/widgets/DocumentPropertiesWidget.scss +0 -1
- package/src/toolbar/widgets/HandToolWidget.scss +0 -1
- package/src/toolbar/widgets/InsertImageWidget/InsertImageWidget.scss +2 -3
- package/src/toolbar/widgets/OverflowWidget.css +1 -2
- package/src/toolbar/widgets/PenToolWidget.scss +0 -2
- package/src/toolbar/widgets/SelectionToolWidget.scss +1 -2
- package/src/toolbar/widgets/components/components.scss +6 -6
- package/src/toolbar/widgets/components/makeColorInput.scss +0 -2
- package/src/toolbar/widgets/components/makeFileInput.scss +5 -7
- package/src/toolbar/widgets/components/makeGridSelector.scss +6 -9
- package/src/toolbar/widgets/components/makeSnappedList.scss +3 -4
- package/src/toolbar/widgets/components/makeThicknessSlider.scss +1 -2
- package/src/toolbar/widgets/widgets.scss +7 -7
- package/src/tools/FindTool.css +1 -2
- package/src/tools/ScrollbarTool.scss +9 -5
- package/src/tools/SelectionTool/SelectionTool.scss +15 -7
- package/src/tools/SelectionTool/util/makeClipboardErrorHandlers.scss +1 -2
- package/src/tools/SoundUITool.scss +4 -4
- package/src/tools/tools.scss +5 -6
- package/src/tools/util/createMenuOverlay.scss +10 -4
- package/tsconfig.json +1 -3
- package/typedoc.json +1 -1
package/dist/mjs/tools/Pen.mjs
CHANGED
@@ -8,7 +8,7 @@ import { undoKeyboardShortcutId } from './keybindings.mjs';
|
|
8
8
|
import { decreaseSizeKeyboardShortcutId, increaseSizeKeyboardShortcutId } from './keybindings.mjs';
|
9
9
|
import InputStabilizer from './InputFilter/InputStabilizer.mjs';
|
10
10
|
import { ReactiveValue } from '../util/ReactiveValue.mjs';
|
11
|
-
import StationaryPenDetector, { defaultStationaryDetectionConfig } from './util/StationaryPenDetector.mjs';
|
11
|
+
import StationaryPenDetector, { defaultStationaryDetectionConfig, } from './util/StationaryPenDetector.mjs';
|
12
12
|
export default class Pen extends BaseTool {
|
13
13
|
constructor(editor, description, style) {
|
14
14
|
super(editor.notifier, description);
|
@@ -29,14 +29,14 @@ export default class Pen extends BaseTool {
|
|
29
29
|
thickness: 4,
|
30
30
|
...style,
|
31
31
|
});
|
32
|
-
this.styleValue.onUpdateAndNow(newValue => {
|
32
|
+
this.styleValue.onUpdateAndNow((newValue) => {
|
33
33
|
this.style = newValue;
|
34
34
|
this.noteUpdated();
|
35
35
|
});
|
36
36
|
}
|
37
37
|
getPressureMultiplier() {
|
38
38
|
const thickness = this.style.thickness;
|
39
|
-
return 1 / this.editor.viewport.getScaleFactor() * thickness;
|
39
|
+
return (1 / this.editor.viewport.getScaleFactor()) * thickness;
|
40
40
|
}
|
41
41
|
// Converts a `pointer` to a `StrokeDataPoint`.
|
42
42
|
toStrokePoint(pointer) {
|
@@ -95,7 +95,7 @@ export default class Pen extends BaseTool {
|
|
95
95
|
this.currentDeviceType = current.device;
|
96
96
|
this.currentPointerId = current.id;
|
97
97
|
if (this.shapeAutocompletionEnabled) {
|
98
|
-
this.stationaryDetector = new StationaryPenDetector(current, defaultStationaryDetectionConfig, pointer => this.autocorrectShape(pointer));
|
98
|
+
this.stationaryDetector = new StationaryPenDetector(current, defaultStationaryDetectionConfig, (pointer) => this.autocorrectShape(pointer));
|
99
99
|
}
|
100
100
|
else {
|
101
101
|
this.stationaryDetector = null;
|
@@ -275,10 +275,18 @@ export default class Pen extends BaseTool {
|
|
275
275
|
getStrokeAutocorrectionEnabled() {
|
276
276
|
return this.shapeAutocompletionEnabled;
|
277
277
|
}
|
278
|
-
getThickness() {
|
279
|
-
|
280
|
-
|
281
|
-
|
278
|
+
getThickness() {
|
279
|
+
return this.style.thickness;
|
280
|
+
}
|
281
|
+
getColor() {
|
282
|
+
return this.style.color;
|
283
|
+
}
|
284
|
+
getStrokeFactory() {
|
285
|
+
return this.style.factory;
|
286
|
+
}
|
287
|
+
getStyleValue() {
|
288
|
+
return this.styleValue;
|
289
|
+
}
|
282
290
|
onKeyPress(event) {
|
283
291
|
const shortcuts = this.editor.shortcuts;
|
284
292
|
// Ctrl+Z: End the stroke so that it can be undone/redone.
|
@@ -291,10 +299,10 @@ export default class Pen extends BaseTool {
|
|
291
299
|
}
|
292
300
|
let newThickness;
|
293
301
|
if (shortcuts.matchesShortcut(decreaseSizeKeyboardShortcutId, event)) {
|
294
|
-
newThickness = this.getThickness() * 2 / 3;
|
302
|
+
newThickness = (this.getThickness() * 2) / 3;
|
295
303
|
}
|
296
304
|
else if (shortcuts.matchesShortcut(increaseSizeKeyboardShortcutId, event)) {
|
297
|
-
newThickness = this.getThickness() * 3 / 2;
|
305
|
+
newThickness = (this.getThickness() * 3) / 2;
|
298
306
|
}
|
299
307
|
if (newThickness !== undefined) {
|
300
308
|
newThickness = Math.min(Math.max(1, newThickness), 256);
|
@@ -22,13 +22,13 @@ export default class ScrollbarTool extends BaseTool {
|
|
22
22
|
this.scrollbarOverlay.replaceChildren(this.verticalScrollbar, this.horizontalScrollbar);
|
23
23
|
let overlay = null;
|
24
24
|
let viewportListener = null;
|
25
|
-
this.enabledValue().onUpdateAndNow(enabled => {
|
25
|
+
this.enabledValue().onUpdateAndNow((enabled) => {
|
26
26
|
overlay?.remove();
|
27
27
|
viewportListener?.remove();
|
28
28
|
viewportListener = null;
|
29
29
|
overlay = null;
|
30
30
|
if (enabled) {
|
31
|
-
viewportListener = editor.notifier.on(EditorEventType.ViewportChanged, _event => {
|
31
|
+
viewportListener = editor.notifier.on(EditorEventType.ViewportChanged, (_event) => {
|
32
32
|
this.updateScrollbars();
|
33
33
|
});
|
34
34
|
this.updateScrollbars();
|
@@ -40,16 +40,17 @@ export default class ScrollbarTool extends BaseTool {
|
|
40
40
|
const viewport = this.editor.viewport;
|
41
41
|
const screenSize = viewport.getScreenRectSize();
|
42
42
|
const screenRect = new Rect2(0, 0, screenSize.x, screenSize.y);
|
43
|
-
const imageRect = this.editor
|
43
|
+
const imageRect = this.editor
|
44
|
+
.getImportExportRect()
|
44
45
|
// The scrollbars are positioned in screen coordinates, so the exportRect also needs
|
45
46
|
// to be in screen coordinates
|
46
47
|
.transformedBoundingBox(viewport.canvasToScreenTransform)
|
47
48
|
// If the screenRect is outside of the exportRect, expand the image rectangle
|
48
49
|
.union(screenRect);
|
49
|
-
const scrollbarWidth = screenRect.width / imageRect.width * screenSize.x;
|
50
|
-
const scrollbarHeight = screenRect.height / imageRect.height * screenSize.y;
|
51
|
-
const scrollbarX = (screenRect.x - imageRect.x) / imageRect.width *
|
52
|
-
const scrollbarY = (screenRect.y - imageRect.y) / imageRect.height *
|
50
|
+
const scrollbarWidth = (screenRect.width / imageRect.width) * screenSize.x;
|
51
|
+
const scrollbarHeight = (screenRect.height / imageRect.height) * screenSize.y;
|
52
|
+
const scrollbarX = ((screenRect.x - imageRect.x) / imageRect.width) * screenSize.x;
|
53
|
+
const scrollbarY = ((screenRect.y - imageRect.y) / imageRect.height) * screenSize.y;
|
53
54
|
this.horizontalScrollbar.style.width = `${scrollbarWidth}px`;
|
54
55
|
this.verticalScrollbar.style.height = `${scrollbarHeight}px`;
|
55
56
|
this.horizontalScrollbar.style.marginLeft = `${scrollbarX}px`;
|
@@ -147,7 +147,7 @@ class Selection {
|
|
147
147
|
const selectedBottommostZIndex = this.selectedElems[0].getZIndex();
|
148
148
|
const visibleObjects = this.editor.image.getElementsIntersectingRegion(this.region);
|
149
149
|
const topMostVisibleZIndex = visibleObjects[visibleObjects.length - 1]?.getZIndex() ?? selectedBottommostZIndex;
|
150
|
-
const deltaZIndex =
|
150
|
+
const deltaZIndex = topMostVisibleZIndex + 1 - selectedBottommostZIndex;
|
151
151
|
return deltaZIndex;
|
152
152
|
}
|
153
153
|
// Applies the current transformation to the selection
|
@@ -177,7 +177,7 @@ class Selection {
|
|
177
177
|
const targetHighestZIndex = lowestVisibleZIndex - 1;
|
178
178
|
const deltaZIndex = targetHighestZIndex - highestSelectedZIndex;
|
179
179
|
if (deltaZIndex !== 0) {
|
180
|
-
const commands = this.selectedElems.map(elem => {
|
180
|
+
const commands = this.selectedElems.map((elem) => {
|
181
181
|
return elem.setZIndex(elem.getZIndex() + deltaZIndex);
|
182
182
|
});
|
183
183
|
return uniteCommands(commands, updateChunkSize);
|
@@ -218,7 +218,9 @@ class Selection {
|
|
218
218
|
// Only select one item if the rectangle was very small.
|
219
219
|
singleItemSelectionMode = true;
|
220
220
|
}
|
221
|
-
this.selectedElems = this.editor.image
|
221
|
+
this.selectedElems = this.editor.image
|
222
|
+
.getElementsIntersectingRegion(this.region)
|
223
|
+
.filter((elem) => {
|
222
224
|
return elem.intersectsRect(this.region) && elem.isSelectable();
|
223
225
|
});
|
224
226
|
if (singleItemSelectionMode && this.selectedElems.length > 0) {
|
@@ -276,7 +278,7 @@ class Selection {
|
|
276
278
|
this.backgroundElem.style.marginTop = `${screenRegion.topLeft.y}px`;
|
277
279
|
this.backgroundElem.style.width = `${screenRegion.width}px`;
|
278
280
|
this.backgroundElem.style.height = `${screenRegion.height}px`;
|
279
|
-
const rotationDeg = this.screenRegionRotation * 180 / Math.PI;
|
281
|
+
const rotationDeg = (this.screenRegionRotation * 180) / Math.PI;
|
280
282
|
this.backgroundElem.style.transform = `rotate(${rotationDeg}deg)`;
|
281
283
|
this.backgroundElem.style.transformOrigin = 'center';
|
282
284
|
// If closer to perpendicular, apply different CSS
|
@@ -343,7 +345,7 @@ class Selection {
|
|
343
345
|
}
|
344
346
|
removeDeletedElemsFromSelection() {
|
345
347
|
// Remove any deleted elements from the selection.
|
346
|
-
this.selectedElems = this.selectedElems.filter(elem => {
|
348
|
+
this.selectedElems = this.selectedElems.filter((elem) => {
|
347
349
|
const hasParent = !!this.editor.image.findParent(elem);
|
348
350
|
// If we removed the element and haven't added it back yet, don't remove it
|
349
351
|
// from the selection.
|
@@ -504,7 +506,7 @@ class Selection {
|
|
504
506
|
this.addRemoveSelectionFromImage(true);
|
505
507
|
this.originalRegion = bbox;
|
506
508
|
this.selectionTightBoundingBox = bbox;
|
507
|
-
this.selectedElems = objects.filter(object => object.isSelectable());
|
509
|
+
this.selectedElems = objects.filter((object) => object.isSelectable());
|
508
510
|
// Enforce increasing z-index invariant
|
509
511
|
this.selectedElems.sort((a, b) => a.getZIndex() - b.getZIndex());
|
510
512
|
this.padRegion();
|
@@ -519,7 +521,7 @@ _a = Selection;
|
|
519
521
|
SerializableCommand.register('selection-tool-transform', (json, _editor) => {
|
520
522
|
// The selection box is lost when serializing/deserializing. No need to store box rotation
|
521
523
|
const fullTransform = new Mat33(...json.transform);
|
522
|
-
const elemIds =
|
524
|
+
const elemIds = json.elems ?? [];
|
523
525
|
const deltaZIndex = parseInt(json.deltaZIndex ?? 0);
|
524
526
|
return new _a.ApplyTransformationCommand(null, elemIds, fullTransform, deltaZIndex);
|
525
527
|
});
|
@@ -542,8 +544,8 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand {
|
|
542
544
|
this.selectedElemIds = selectedElems;
|
543
545
|
}
|
544
546
|
else {
|
545
|
-
this.selectedElemIds = selectedElems.map(elem => elem.getId());
|
546
|
-
this.transformCommands = selectedElems.map(elem => {
|
547
|
+
this.selectedElemIds = selectedElems.map((elem) => elem.getId());
|
548
|
+
this.transformCommands = selectedElems.map((elem) => {
|
547
549
|
return elem.setZIndexAndTransformBy(this.fullTransform, elem.getZIndex() + deltaZIndex);
|
548
550
|
});
|
549
551
|
}
|
@@ -552,7 +554,8 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand {
|
|
552
554
|
if (this.transformCommands) {
|
553
555
|
return;
|
554
556
|
}
|
555
|
-
this.transformCommands = this.selectedElemIds
|
557
|
+
this.transformCommands = this.selectedElemIds
|
558
|
+
.map((id) => {
|
556
559
|
const elem = editor.image.lookupElement(id);
|
557
560
|
if (!elem) {
|
558
561
|
// There may be valid reasons for an element lookup to fail:
|
@@ -570,9 +573,10 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand {
|
|
570
573
|
originalZIndex = elem.getZIndex() - this.deltaZIndex;
|
571
574
|
}
|
572
575
|
return elem.setZIndexAndTransformBy(this.fullTransform, targetZIndex, originalZIndex);
|
573
|
-
})
|
576
|
+
})
|
577
|
+
.filter(
|
574
578
|
// Remove all null commands
|
575
|
-
command => command !== null);
|
579
|
+
(command) => command !== null);
|
576
580
|
}
|
577
581
|
async apply(editor) {
|
578
582
|
this.resolveToElems(editor, false);
|
@@ -65,7 +65,9 @@ export default class SelectionHandle {
|
|
65
65
|
* Removes this element from its container. Should only be called
|
66
66
|
* after {@link addTo}.
|
67
67
|
*/
|
68
|
-
remove() {
|
68
|
+
remove() {
|
69
|
+
this.element.remove();
|
70
|
+
}
|
69
71
|
/**
|
70
72
|
* Returns this handle's bounding box relative to the top left of the
|
71
73
|
* selection box.
|
@@ -73,7 +75,8 @@ export default class SelectionHandle {
|
|
73
75
|
getBBoxParentCoords() {
|
74
76
|
const parentRect = this.parent.getScreenRegion();
|
75
77
|
const size = Vec2.of(handleSize, handleSize);
|
76
|
-
const topLeft = parentRect.size
|
78
|
+
const topLeft = parentRect.size
|
79
|
+
.scale(this.parentSide)
|
77
80
|
// Center
|
78
81
|
.minus(size.times(1 / 2));
|
79
82
|
return new Rect2(topLeft.x, topLeft.y, size.x, size.y);
|
@@ -39,7 +39,9 @@ export default class SelectionMenuShortcut {
|
|
39
39
|
addTo(container) {
|
40
40
|
container.appendChild(this.element);
|
41
41
|
}
|
42
|
-
remove() {
|
42
|
+
remove() {
|
43
|
+
this.element.remove();
|
44
|
+
}
|
43
45
|
getElementScreenSize() {
|
44
46
|
return Vec2.of(this.element.clientWidth, this.element.clientHeight);
|
45
47
|
}
|
@@ -6,7 +6,7 @@ import CanvasRenderer from '../../rendering/renderers/CanvasRenderer.mjs';
|
|
6
6
|
import SVGRenderer from '../../rendering/renderers/SVGRenderer.mjs';
|
7
7
|
import Selection from './Selection.mjs';
|
8
8
|
import TextComponent from '../../components/TextComponent.mjs';
|
9
|
-
import { duplicateSelectionShortcut, translateLeftSelectionShortcutId, translateRightSelectionShortcutId, selectAllKeyboardShortcut, sendToBackSelectionShortcut, snapToGridKeyboardShortcutId, translateDownSelectionShortcutId, translateUpSelectionShortcutId, rotateClockwiseSelectionShortcutId, rotateCounterClockwiseSelectionShortcutId, stretchXSelectionShortcutId, shrinkXSelectionShortcutId, shrinkYSelectionShortcutId, stretchYSelectionShortcutId, stretchXYSelectionShortcutId, shrinkXYSelectionShortcutId } from '../keybindings.mjs';
|
9
|
+
import { duplicateSelectionShortcut, translateLeftSelectionShortcutId, translateRightSelectionShortcutId, selectAllKeyboardShortcut, sendToBackSelectionShortcut, snapToGridKeyboardShortcutId, translateDownSelectionShortcutId, translateUpSelectionShortcutId, rotateClockwiseSelectionShortcutId, rotateCounterClockwiseSelectionShortcutId, stretchXSelectionShortcutId, shrinkXSelectionShortcutId, shrinkYSelectionShortcutId, stretchYSelectionShortcutId, stretchXYSelectionShortcutId, shrinkXYSelectionShortcutId, } from '../keybindings.mjs';
|
10
10
|
import ToPointerAutoscroller from './ToPointerAutoscroller.mjs';
|
11
11
|
import showSelectionContextMenu from './util/showSelectionContextMenu.mjs';
|
12
12
|
export const cssPrefix = 'selection-tool-';
|
@@ -47,7 +47,7 @@ export default class SelectionTool extends BaseTool {
|
|
47
47
|
editor.createHTMLOverlay(this.handleOverlay);
|
48
48
|
this.handleOverlay.style.display = 'none';
|
49
49
|
this.handleOverlay.classList.add('handleOverlay');
|
50
|
-
editor.notifier.on(EditorEventType.ViewportChanged, _data => {
|
50
|
+
editor.notifier.on(EditorEventType.ViewportChanged, (_data) => {
|
51
51
|
// The selection box could be using the wet ink display if its transformation
|
52
52
|
// hasn't been finalized yet. Clear before updating the UI.
|
53
53
|
this.editor.clearWetInk();
|
@@ -82,7 +82,9 @@ export default class SelectionTool extends BaseTool {
|
|
82
82
|
this.selectionBox.finalizeTransform();
|
83
83
|
}
|
84
84
|
onContextMenu(event) {
|
85
|
-
const canShowSelectionMenu = this.selectionBox
|
85
|
+
const canShowSelectionMenu = this.selectionBox
|
86
|
+
?.getScreenRegion()
|
87
|
+
?.containsPoint(event.screenPos);
|
86
88
|
void this.showContextMenu(event.canvasPos, canShowSelectionMenu);
|
87
89
|
return true;
|
88
90
|
}
|
@@ -196,8 +198,8 @@ export default class SelectionTool extends BaseTool {
|
|
196
198
|
onSelectionUpdated() {
|
197
199
|
const selectedItemCount = this.selectionBox?.getSelectedItemCount() ?? 0;
|
198
200
|
const selectedObjects = this.selectionBox?.getSelectedObjects() ?? [];
|
199
|
-
const hasDifferentSelection = this.lastSelectedObjects.length !== selectedItemCount
|
200
|
-
|
201
|
+
const hasDifferentSelection = this.lastSelectedObjects.length !== selectedItemCount ||
|
202
|
+
selectedObjects.some((obj, i) => this.lastSelectedObjects[i] !== obj);
|
201
203
|
if (hasDifferentSelection) {
|
202
204
|
this.lastSelectedObjects = selectedObjects;
|
203
205
|
// Note that the selection has changed
|
@@ -234,8 +236,9 @@ export default class SelectionTool extends BaseTool {
|
|
234
236
|
this.snapToGrid = true;
|
235
237
|
return true;
|
236
238
|
}
|
237
|
-
if (this.selectionBox &&
|
238
|
-
|
239
|
+
if (this.selectionBox &&
|
240
|
+
(shortcucts.matchesShortcut(duplicateSelectionShortcut, event) ||
|
241
|
+
shortcucts.matchesShortcut(sendToBackSelectionShortcut, event))) {
|
239
242
|
// Handle duplication on key up — we don't want to accidentally duplicate
|
240
243
|
// many times.
|
241
244
|
return true;
|
@@ -298,11 +301,11 @@ export default class SelectionTool extends BaseTool {
|
|
298
301
|
xScaleSteps += 1;
|
299
302
|
yScaleSteps += 1;
|
300
303
|
}
|
301
|
-
let handled = xTranslateSteps !== 0
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
304
|
+
let handled = xTranslateSteps !== 0 ||
|
305
|
+
yTranslateSteps !== 0 ||
|
306
|
+
rotationSteps !== 0 ||
|
307
|
+
xScaleSteps !== 0 ||
|
308
|
+
yScaleSteps !== 0;
|
306
309
|
if (!this.selectionBox) {
|
307
310
|
handled = false;
|
308
311
|
}
|
@@ -313,9 +316,13 @@ export default class SelectionTool extends BaseTool {
|
|
313
316
|
const region = this.selectionBox.region;
|
314
317
|
const scaleFactor = Vec2.of(scaleStepSize ** xScaleSteps, scaleStepSize ** yScaleSteps);
|
315
318
|
const rotationMat = Mat33.zRotation(rotationSteps * rotateStepSize);
|
316
|
-
const roundedRotationMatrix = rotationMat.mapEntries(component => Viewport.roundScaleRatio(component));
|
319
|
+
const roundedRotationMatrix = rotationMat.mapEntries((component) => Viewport.roundScaleRatio(component));
|
317
320
|
const regionCenter = this.editor.viewport.roundPoint(region.center);
|
318
|
-
const transform = Mat33.scaling2D(scaleFactor, this.editor.viewport.roundPoint(region.topLeft))
|
321
|
+
const transform = Mat33.scaling2D(scaleFactor, this.editor.viewport.roundPoint(region.topLeft))
|
322
|
+
.rightMul(Mat33.translation(regionCenter)
|
323
|
+
.rightMul(roundedRotationMatrix)
|
324
|
+
.rightMul(Mat33.translation(regionCenter.times(-1))))
|
325
|
+
.rightMul(Mat33.translation(this.editor.viewport.roundPoint(Vec2.of(xTranslateSteps, yTranslateSteps).times(translateStepSize))));
|
319
326
|
const oldTransform = this.selectionBox.getTransform();
|
320
327
|
this.selectionBox.setTransform(oldTransform.rightMul(transform));
|
321
328
|
this.selectionBox.scrollTo();
|
@@ -341,7 +348,7 @@ export default class SelectionTool extends BaseTool {
|
|
341
348
|
}
|
342
349
|
if (this.selectionBox && shortcucts.matchesShortcut(duplicateSelectionShortcut, evt)) {
|
343
350
|
// Finalize duplicating the selection
|
344
|
-
this.selectionBox.duplicateSelectedObjects().then(command => {
|
351
|
+
this.selectionBox.duplicateSelectedObjects().then((command) => {
|
345
352
|
this.editor.dispatch(command);
|
346
353
|
});
|
347
354
|
return true;
|
@@ -386,7 +393,9 @@ export default class SelectionTool extends BaseTool {
|
|
386
393
|
return false;
|
387
394
|
}
|
388
395
|
const exportViewport = new Viewport(() => { });
|
389
|
-
const selectionScreenSize = this.selectionBox
|
396
|
+
const selectionScreenSize = this.selectionBox
|
397
|
+
.getScreenRegion()
|
398
|
+
.size.times(this.editor.display.getDevicePixelRatio());
|
390
399
|
// Update the viewport to have screen size roughly equal to the size of the selection box
|
391
400
|
let scaleFactor = selectionScreenSize.maximumEntryMagnitude() / (bbox.size.maximumEntryMagnitude() || 1);
|
392
401
|
// Round to a nearby power of two
|
@@ -455,7 +464,7 @@ export default class SelectionTool extends BaseTool {
|
|
455
464
|
// Select the given `objects`. Any non-selectable objects in `objects` are ignored.
|
456
465
|
setSelection(objects) {
|
457
466
|
// Only select selectable objects.
|
458
|
-
objects = objects.filter(obj => obj.isSelectable());
|
467
|
+
objects = objects.filter((obj) => obj.isSelectable());
|
459
468
|
// Sort by z-index
|
460
469
|
objects.sort((a, b) => a.getZIndex() - b.getZIndex());
|
461
470
|
// Remove duplicates
|
@@ -63,7 +63,7 @@ export default class ToPointerAutoscroller {
|
|
63
63
|
const currentTime = performance.now();
|
64
64
|
const deltaTimeMs = currentTime - lastUpdateTime;
|
65
65
|
const scrollDirection = this.getScrollForPoint(this.targetPoint);
|
66
|
-
const screenScrollAmount = scrollDirection.times(this.scrollRate * deltaTimeMs / 1000);
|
66
|
+
const screenScrollAmount = scrollDirection.times((this.scrollRate * deltaTimeMs) / 1000);
|
67
67
|
this.scrollByCanvasDelta(this.viewport.screenToCanvasTransform.transformVec3(screenScrollAmount));
|
68
68
|
lastUpdateTime = currentTime;
|
69
69
|
await untilNextAnimationFrame();
|
@@ -75,7 +75,7 @@ export class ResizeTransformer {
|
|
75
75
|
}
|
76
76
|
// Round: If this isn't done, scaling can create numbers with long decimal representations.
|
77
77
|
// long decimal representations => large file sizes.
|
78
|
-
scale = scale.map(component => Viewport.roundScaleRatio(component, 2));
|
78
|
+
scale = scale.map((component) => Viewport.roundScaleRatio(component, 2));
|
79
79
|
if (scale.x !== 0 && scale.y !== 0) {
|
80
80
|
const origin = this.editor.viewport.roundPoint(this.transformOrigin);
|
81
81
|
this.selection.setTransform(Mat33.scaling2D(scale, origin));
|
@@ -116,9 +116,8 @@ export class RotateTransformer {
|
|
116
116
|
// Transform in canvas space
|
117
117
|
const canvasSelCenter = this.editor.viewport.roundPoint(this.selection.preTransformRegion.center);
|
118
118
|
const unrounded = Mat33.zRotation(angle);
|
119
|
-
const roundedRotationTransform = unrounded.mapEntries(entry => Viewport.roundScaleRatio(entry));
|
120
|
-
const fullRoundedTransform = Mat33
|
121
|
-
.translation(canvasSelCenter)
|
119
|
+
const roundedRotationTransform = unrounded.mapEntries((entry) => Viewport.roundScaleRatio(entry));
|
120
|
+
const fullRoundedTransform = Mat33.translation(canvasSelCenter)
|
122
121
|
.rightMul(roundedRotationTransform)
|
123
122
|
.rightMul(Mat33.translation(canvasSelCenter.times(-1)));
|
124
123
|
this.selection.setTransform(fullRoundedTransform);
|
@@ -136,9 +135,9 @@ export class RotateTransformer {
|
|
136
135
|
const clickThresholdDist = 10;
|
137
136
|
const clickThresholdTime = 0.4; // s
|
138
137
|
const dragTimeSeconds = (performance.now() - this.startTime) / 1000;
|
139
|
-
if (dragTimeSeconds < clickThresholdTime
|
140
|
-
|
141
|
-
|
138
|
+
if (dragTimeSeconds < clickThresholdTime &&
|
139
|
+
this.maximumDistFromStart < clickThresholdDist &&
|
140
|
+
this.targetRotation === 0) {
|
142
141
|
this.setRotationTo(-Math.PI / 2);
|
143
142
|
}
|
144
143
|
return this.selection.finalizeTransform();
|
@@ -4,7 +4,7 @@ const makeClipboardErrorHandlers = (editor) => {
|
|
4
4
|
const makeErrorDialog = (error) => {
|
5
5
|
const dialog = makeMessageDialog(editor, {
|
6
6
|
title: editor.localization.copyPasteError__heading,
|
7
|
-
classNames: ['clipboard-error-dialog']
|
7
|
+
classNames: ['clipboard-error-dialog'],
|
8
8
|
});
|
9
9
|
dialog.appendChild(document.createTextNode(editor.localization.copyPasteError__description));
|
10
10
|
const errorDetailsElement = document.createElement('details');
|
@@ -17,7 +17,26 @@ const makeClipboardErrorHandlers = (editor) => {
|
|
17
17
|
};
|
18
18
|
return {
|
19
19
|
async onCopyError(error) {
|
20
|
-
makeErrorDialog(error);
|
20
|
+
const dialog = makeErrorDialog(error);
|
21
|
+
const textboxLabel = document.createElement('label');
|
22
|
+
textboxLabel.textContent = editor.localization.copyPasteError__copyRetry;
|
23
|
+
const copyTextbox = document.createElement('textarea');
|
24
|
+
textboxLabel.appendChild(copyTextbox);
|
25
|
+
const retryHandler = new ClipboardHandler(editor);
|
26
|
+
const handleCopy = (event) => {
|
27
|
+
event.preventDefault();
|
28
|
+
// Use .then to ensure that .copy runs within the event handler.
|
29
|
+
// Copy can fail if certain logic is run async.
|
30
|
+
return retryHandler.copy(event).then(() => {
|
31
|
+
dialog.close();
|
32
|
+
});
|
33
|
+
};
|
34
|
+
copyTextbox.oncopy = handleCopy;
|
35
|
+
copyTextbox.ondragstart = handleCopy;
|
36
|
+
copyTextbox.value = editor.localization.copyPasteError__copyMe;
|
37
|
+
dialog.appendChild(textboxLabel);
|
38
|
+
copyTextbox.select();
|
39
|
+
document.execCommand('copy');
|
21
40
|
},
|
22
41
|
onPasteError(error) {
|
23
42
|
const dialog = makeErrorDialog(error);
|
@@ -39,6 +58,8 @@ const makeClipboardErrorHandlers = (editor) => {
|
|
39
58
|
pasteTextbox.onpaste = handlePaste;
|
40
59
|
pasteTextbox.ondrop = handlePaste;
|
41
60
|
dialog.appendChild(textboxLabel);
|
61
|
+
pasteTextbox.focus();
|
62
|
+
document.execCommand('paste');
|
42
63
|
},
|
43
64
|
};
|
44
65
|
};
|
@@ -4,35 +4,44 @@ import makeClipboardErrorHandlers from './makeClipboardErrorHandlers.mjs';
|
|
4
4
|
const showSelectionContextMenu = async (selectionBox, editor, canvasAnchor, preferSelectionMenu, clearSelection) => {
|
5
5
|
const localization = editor.localization;
|
6
6
|
const showSelectionMenu = selectionBox?.getSelectedItemCount() && preferSelectionMenu;
|
7
|
-
const noSelectionMenu = [
|
7
|
+
const noSelectionMenu = [
|
8
|
+
{
|
8
9
|
text: localization.selectionMenu__paste,
|
9
10
|
icon: () => editor.icons.makePasteIcon(),
|
10
11
|
key: () => {
|
11
12
|
const clipboardHandler = new ClipboardHandler(editor, makeClipboardErrorHandlers(editor));
|
12
13
|
void clipboardHandler.paste();
|
13
14
|
},
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
},
|
16
|
+
];
|
17
|
+
const onActivated = await createMenuOverlay(editor, canvasAnchor, showSelectionMenu
|
18
|
+
? [
|
19
|
+
{
|
20
|
+
text: localization.selectionMenu__duplicate,
|
21
|
+
icon: () => editor.icons.makeDuplicateSelectionIcon(),
|
22
|
+
key: async () => {
|
23
|
+
await editor.dispatch(await selectionBox.duplicateSelectedObjects());
|
24
|
+
},
|
20
25
|
},
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
{
|
27
|
+
text: localization.selectionMenu__delete,
|
28
|
+
icon: () => editor.icons.makeDeleteSelectionIcon(),
|
29
|
+
key: async () => {
|
30
|
+
await editor.dispatch(selectionBox.deleteSelectedObjects());
|
31
|
+
clearSelection();
|
32
|
+
},
|
27
33
|
},
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
{
|
35
|
+
text: localization.selectionMenu__copyToClipboard,
|
36
|
+
icon: () => editor.icons.makeCopyIcon(),
|
37
|
+
key: () => {
|
38
|
+
const clipboardHandler = new ClipboardHandler(editor, makeClipboardErrorHandlers(editor));
|
39
|
+
void clipboardHandler.copy();
|
40
|
+
},
|
34
41
|
},
|
35
|
-
|
42
|
+
...noSelectionMenu,
|
43
|
+
]
|
44
|
+
: noSelectionMenu);
|
36
45
|
onActivated?.();
|
37
46
|
};
|
38
47
|
export default showSelectionContextMenu;
|
@@ -53,12 +53,12 @@ class SoundFeedback {
|
|
53
53
|
setColor(color) {
|
54
54
|
const hsv = color.asHSV();
|
55
55
|
// Choose frequencies that roughly correspond to hue, saturation, and value.
|
56
|
-
const hueFrequency =
|
56
|
+
const hueFrequency = -Math.cos(hsv.x / 2) * 220 + 440;
|
57
57
|
const saturationFrequency = hsv.y * 440 + 220;
|
58
58
|
const valueFrequency = (hsv.z + 0.1) * 440;
|
59
59
|
// Sigmoid with maximum 0.25 * alpha.
|
60
60
|
// Louder for greater value.
|
61
|
-
const gain = 0.25 * Math.min(1, color.a) / (1 + Math.exp(-(hsv.z - 0.5) * 3));
|
61
|
+
const gain = (0.25 * Math.min(1, color.a)) / (1 + Math.exp(-(hsv.z - 0.5) * 3));
|
62
62
|
this.colorOscHue.frequency.setValueAtTime(hueFrequency, this.ctx.currentTime);
|
63
63
|
this.colorOscSaturation.frequency.setValueAtTime(saturationFrequency, this.ctx.currentTime);
|
64
64
|
this.colorOscValue.frequency.setValueAtTime(valueFrequency, this.ctx.currentTime);
|
@@ -150,7 +150,9 @@ export default class SoundUITool extends BaseTool {
|
|
150
150
|
onPointerMove({ current }) {
|
151
151
|
this.soundFeedback?.setColor(this.editor.display.getColorAt(current.screenPos) ?? Color4.black);
|
152
152
|
const pointerMotionLine = new LineSegment2(this.lastPointerPos, current.canvasPos);
|
153
|
-
const collisions = this.editor.image
|
153
|
+
const collisions = this.editor.image
|
154
|
+
.getElementsIntersectingRegion(pointerMotionLine.bbox)
|
155
|
+
.filter((component) => component.intersects(pointerMotionLine));
|
154
156
|
this.lastPointerPos = current.canvasPos;
|
155
157
|
if (collisions.length > 0) {
|
156
158
|
this.soundFeedback?.announceBoundaryCross(collisions.length);
|
@@ -76,7 +76,7 @@ export default class TextTool extends BaseTool {
|
|
76
76
|
return measurement.fontBoundingBoxAscent ?? measurement.actualBoundingBoxAscent;
|
77
77
|
}
|
78
78
|
// Estimate
|
79
|
-
return style.size * 2 / 3;
|
79
|
+
return (style.size * 2) / 3;
|
80
80
|
}
|
81
81
|
// Take input from this' textInputElem and add it to the EditorImage.
|
82
82
|
// If [removeInput], the HTML input element is removed. Otherwise, its value
|
@@ -95,7 +95,10 @@ export default class TextTool extends BaseTool {
|
|
95
95
|
if (content === '') {
|
96
96
|
return;
|
97
97
|
}
|
98
|
-
const textTransform = Mat33.translation(this.textTargetPosition)
|
98
|
+
const textTransform = Mat33.translation(this.textTargetPosition)
|
99
|
+
.rightMul(this.getTextScaleMatrix())
|
100
|
+
.rightMul(Mat33.scaling2D(this.editor.viewport.getSizeOfPixelOnCanvas()))
|
101
|
+
.rightMul(Mat33.zRotation(this.textRotation));
|
99
102
|
const textComponent = TextComponent.fromLines(content.split('\n'), textTransform, this.textStyle);
|
100
103
|
const action = EditorImage.addElement(textComponent);
|
101
104
|
if (this.removeExistingCommand) {
|
@@ -139,8 +142,7 @@ export default class TextTool extends BaseTool {
|
|
139
142
|
const vertAdjust = ascent;
|
140
143
|
const rotation = this.textRotation + viewport.getRotationAngle();
|
141
144
|
const scale = this.getTextScaleMatrix();
|
142
|
-
this.textInputElem.style.transform =
|
143
|
-
`${scale.toCSSMatrix()} rotate(${rotation * 180 / Math.PI}deg) translate(0, ${-vertAdjust}px)`;
|
145
|
+
this.textInputElem.style.transform = `${scale.toCSSMatrix()} rotate(${(rotation * 180) / Math.PI}deg) translate(0, ${-vertAdjust}px)`;
|
144
146
|
this.textInputElem.style.transformOrigin = 'top left';
|
145
147
|
// Match the line height of default rendered text.
|
146
148
|
const lineHeight = Math.floor(this.textStyle.size);
|
@@ -208,11 +210,11 @@ export default class TextTool extends BaseTool {
|
|
208
210
|
const halfTestRegionSize = Vec2.of(2.5, 2.5).times(this.editor.viewport.getSizeOfPixelOnCanvas());
|
209
211
|
const testRegion = Rect2.fromCorners(canvasPos.minus(halfTestRegionSize), canvasPos.plus(halfTestRegionSize));
|
210
212
|
const targetNodes = this.editor.image.getElementsIntersectingRegion(testRegion);
|
211
|
-
let targetTextNodes = targetNodes.filter(node => node instanceof TextComponent);
|
213
|
+
let targetTextNodes = targetNodes.filter((node) => node instanceof TextComponent);
|
212
214
|
// Don't try to edit text nodes that contain the viewport (this allows us
|
213
215
|
// to zoom in on text nodes and add text on top of them.)
|
214
216
|
const visibleRect = this.editor.viewport.visibleRect;
|
215
|
-
targetTextNodes = targetTextNodes.filter(node => !node.getBBox().containsRect(visibleRect));
|
217
|
+
targetTextNodes = targetTextNodes.filter((node) => !node.getBBox().containsRect(visibleRect));
|
216
218
|
// End any TextNodes we're currently editing.
|
217
219
|
this.flushInput();
|
218
220
|
if (targetTextNodes.length > 0) {
|