js-draw 1.21.2 → 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.d.ts +61 -0
- package/dist/cjs/tools/BaseTool.js +181 -0
- package/dist/cjs/tools/Eraser.d.ts +60 -0
- package/dist/cjs/tools/Eraser.js +304 -0
- package/dist/cjs/tools/Eraser.test.d.ts +1 -0
- package/dist/cjs/tools/FindTool.d.ts +21 -0
- package/dist/cjs/tools/FindTool.js +137 -0
- package/dist/cjs/tools/FindTool.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.d.ts +17 -0
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.js +103 -0
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
- package/dist/cjs/tools/InputFilter/FunctionMapper.js +21 -0
- package/dist/cjs/tools/InputFilter/InputMapper.d.ts +23 -0
- package/dist/cjs/tools/InputFilter/InputMapper.js +38 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.d.ts +15 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.js +54 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +188 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +87 -0
- package/dist/cjs/tools/PanZoom.d.ts +125 -0
- package/dist/cjs/tools/PanZoom.js +522 -0
- package/dist/cjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/cjs/tools/PasteHandler.d.ts +23 -0
- package/dist/cjs/tools/PasteHandler.js +115 -0
- package/dist/cjs/tools/Pen.d.ts +54 -0
- package/dist/cjs/tools/Pen.js +343 -0
- package/dist/cjs/tools/Pen.test.d.ts +1 -0
- package/dist/cjs/tools/PipetteTool.d.ts +28 -0
- package/dist/cjs/tools/PipetteTool.js +69 -0
- package/dist/cjs/tools/ScrollbarTool.d.ts +18 -0
- package/dist/cjs/tools/ScrollbarTool.js +86 -0
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +9 -0
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +32 -0
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +72 -0
- package/dist/cjs/tools/SelectionTool/Selection.js +638 -0
- package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +62 -0
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +144 -0
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.d.ts +32 -0
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +88 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +42 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +509 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +1 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.d.ts +23 -0
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.js +83 -0
- package/dist/cjs/tools/SelectionTool/TransformMode.d.ts +42 -0
- package/dist/cjs/tools/SelectionTool/TransformMode.js +154 -0
- package/dist/cjs/tools/SelectionTool/keybindings.d.ts +15 -0
- package/dist/cjs/tools/SelectionTool/keybindings.js +38 -0
- package/dist/cjs/tools/SelectionTool/types.d.ts +35 -0
- package/dist/cjs/tools/SelectionTool/types.js +14 -0
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.d.ts +6 -0
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.js +71 -0
- package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.d.ts +5 -0
- package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.js +52 -0
- package/dist/cjs/tools/SoundUITool.d.ts +26 -0
- package/dist/cjs/tools/SoundUITool.js +173 -0
- package/dist/cjs/tools/TextTool.d.ts +36 -0
- package/dist/cjs/tools/TextTool.js +287 -0
- package/dist/cjs/tools/TextTool.test.d.ts +1 -0
- package/dist/cjs/tools/ToolController.d.ts +73 -0
- package/dist/cjs/tools/ToolController.js +310 -0
- package/dist/cjs/tools/ToolController.test.d.ts +1 -0
- package/dist/cjs/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/cjs/tools/ToolEnabledGroup.js +13 -0
- package/dist/cjs/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/cjs/tools/ToolSwitcherShortcut.js +40 -0
- package/dist/cjs/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/cjs/tools/ToolbarShortcutHandler.js +34 -0
- package/dist/cjs/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/cjs/tools/UndoRedoShortcut.js +27 -0
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/cjs/tools/keybindings.d.ts +16 -0
- package/dist/cjs/tools/keybindings.js +58 -0
- package/dist/cjs/tools/lib.d.ts +14 -0
- package/dist/cjs/tools/lib.js +36 -0
- package/dist/cjs/tools/localization.d.ts +45 -0
- package/dist/cjs/tools/localization.js +47 -0
- package/dist/cjs/tools/util/StationaryPenDetector.d.ts +25 -0
- package/dist/cjs/tools/util/StationaryPenDetector.js +107 -0
- package/dist/cjs/tools/util/createMenuOverlay.d.ts +10 -0
- package/dist/cjs/tools/util/createMenuOverlay.js +126 -0
- package/dist/cjs/tools/util/createMenuOverlay.test.d.ts +1 -0
- 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.d.ts +61 -0
- package/dist/mjs/tools/BaseTool.mjs +179 -0
- package/dist/mjs/tools/Eraser.d.ts +60 -0
- package/dist/mjs/tools/Eraser.mjs +297 -0
- package/dist/mjs/tools/Eraser.test.d.ts +1 -0
- package/dist/mjs/tools/FindTool.d.ts +21 -0
- package/dist/mjs/tools/FindTool.mjs +131 -0
- package/dist/mjs/tools/FindTool.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.d.ts +17 -0
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.mjs +74 -0
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
- package/dist/mjs/tools/InputFilter/FunctionMapper.mjs +15 -0
- package/dist/mjs/tools/InputFilter/InputMapper.d.ts +23 -0
- package/dist/mjs/tools/InputFilter/InputMapper.mjs +36 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.d.ts +15 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.mjs +49 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +182 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +81 -0
- package/dist/mjs/tools/PanZoom.d.ts +125 -0
- package/dist/mjs/tools/PanZoom.mjs +515 -0
- package/dist/mjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/mjs/tools/PasteHandler.d.ts +23 -0
- package/dist/mjs/tools/PasteHandler.mjs +109 -0
- package/dist/mjs/tools/Pen.d.ts +54 -0
- package/dist/mjs/tools/Pen.mjs +314 -0
- package/dist/mjs/tools/Pen.test.d.ts +1 -0
- package/dist/mjs/tools/PipetteTool.d.ts +28 -0
- package/dist/mjs/tools/PipetteTool.mjs +63 -0
- package/dist/mjs/tools/ScrollbarTool.d.ts +18 -0
- package/dist/mjs/tools/ScrollbarTool.mjs +80 -0
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +9 -0
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +26 -0
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +72 -0
- package/dist/mjs/tools/SelectionTool/Selection.mjs +610 -0
- package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +62 -0
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +140 -0
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.d.ts +32 -0
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +85 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +42 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +502 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +1 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.d.ts +23 -0
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.mjs +77 -0
- package/dist/mjs/tools/SelectionTool/TransformMode.d.ts +42 -0
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +145 -0
- package/dist/mjs/tools/SelectionTool/keybindings.d.ts +15 -0
- package/dist/mjs/tools/SelectionTool/keybindings.mjs +32 -0
- package/dist/mjs/tools/SelectionTool/types.d.ts +35 -0
- package/dist/mjs/tools/SelectionTool/types.mjs +11 -0
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.d.ts +6 -0
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.mjs +66 -0
- package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.d.ts +5 -0
- package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.mjs +47 -0
- package/dist/mjs/tools/SoundUITool.d.ts +26 -0
- package/dist/mjs/tools/SoundUITool.mjs +167 -0
- package/dist/mjs/tools/TextTool.d.ts +36 -0
- package/dist/mjs/tools/TextTool.mjs +281 -0
- package/dist/mjs/tools/TextTool.test.d.ts +1 -0
- package/dist/mjs/tools/ToolController.d.ts +73 -0
- package/dist/mjs/tools/ToolController.mjs +281 -0
- package/dist/mjs/tools/ToolController.test.d.ts +1 -0
- package/dist/mjs/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/mjs/tools/ToolEnabledGroup.mjs +10 -0
- package/dist/mjs/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/mjs/tools/ToolSwitcherShortcut.mjs +34 -0
- package/dist/mjs/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/mjs/tools/ToolbarShortcutHandler.mjs +28 -0
- package/dist/mjs/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/mjs/tools/UndoRedoShortcut.mjs +21 -0
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/mjs/tools/keybindings.d.ts +16 -0
- package/dist/mjs/tools/keybindings.mjs +38 -0
- package/dist/mjs/tools/lib.d.ts +14 -0
- package/dist/mjs/tools/lib.mjs +14 -0
- package/dist/mjs/tools/localization.d.ts +45 -0
- package/dist/mjs/tools/localization.mjs +44 -0
- package/dist/mjs/tools/util/StationaryPenDetector.d.ts +25 -0
- package/dist/mjs/tools/util/StationaryPenDetector.mjs +103 -0
- package/dist/mjs/tools/util/createMenuOverlay.d.ts +10 -0
- package/dist/mjs/tools/util/createMenuOverlay.mjs +121 -0
- package/dist/mjs/tools/util/createMenuOverlay.test.d.ts +1 -0
- 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 +6 -0
- package/src/tools/ScrollbarTool.scss +61 -0
- package/src/tools/SelectionTool/SelectionTool.scss +173 -0
- package/src/tools/SelectionTool/util/makeClipboardErrorHandlers.scss +14 -0
- package/src/tools/SoundUITool.scss +22 -0
- package/src/tools/tools.scss +5 -0
- package/src/tools/util/createMenuOverlay.scss +73 -0
- package/tsconfig.json +1 -3
- package/typedoc.json +1 -1
@@ -0,0 +1,179 @@
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
6
|
+
};
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
|
+
};
|
12
|
+
var _BaseTool_enabled, _BaseTool_group, _BaseTool_inputMapper, _BaseTool_readOnlyEditorChangeListener;
|
13
|
+
import { EditorEventType } from '../types.mjs';
|
14
|
+
import { InputEvtType, } from '../inputEvents.mjs';
|
15
|
+
import { ReactiveValue } from '../util/ReactiveValue.mjs';
|
16
|
+
class BaseTool {
|
17
|
+
constructor(notifier, description) {
|
18
|
+
this.notifier = notifier;
|
19
|
+
this.description = description;
|
20
|
+
_BaseTool_enabled.set(this, void 0);
|
21
|
+
_BaseTool_group.set(this, null);
|
22
|
+
_BaseTool_inputMapper.set(this, null);
|
23
|
+
_BaseTool_readOnlyEditorChangeListener.set(this, null);
|
24
|
+
__classPrivateFieldSet(this, _BaseTool_enabled, ReactiveValue.fromInitialValue(true), "f");
|
25
|
+
__classPrivateFieldGet(this, _BaseTool_enabled, "f").onUpdate((enabled) => {
|
26
|
+
// Ensure that at most one tool in the group is enabled.
|
27
|
+
if (enabled) {
|
28
|
+
__classPrivateFieldGet(this, _BaseTool_group, "f")?.notifyEnabled(this);
|
29
|
+
this.notifier.dispatch(EditorEventType.ToolEnabled, {
|
30
|
+
kind: EditorEventType.ToolEnabled,
|
31
|
+
tool: this,
|
32
|
+
});
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
this.notifier.dispatch(EditorEventType.ToolDisabled, {
|
36
|
+
kind: EditorEventType.ToolDisabled,
|
37
|
+
tool: this,
|
38
|
+
});
|
39
|
+
}
|
40
|
+
});
|
41
|
+
}
|
42
|
+
/** Override this to allow this tool to be enabled in a read-only editor */
|
43
|
+
canReceiveInputInReadOnlyEditor() {
|
44
|
+
return false;
|
45
|
+
}
|
46
|
+
setInputMapper(mapper) {
|
47
|
+
__classPrivateFieldSet(this, _BaseTool_inputMapper, mapper, "f");
|
48
|
+
if (mapper) {
|
49
|
+
mapper.setEmitListener((event) => this.dispatchEventToCallback(event));
|
50
|
+
}
|
51
|
+
}
|
52
|
+
getInputMapper() {
|
53
|
+
return __classPrivateFieldGet(this, _BaseTool_inputMapper, "f");
|
54
|
+
}
|
55
|
+
dispatchEventToCallback(event) {
|
56
|
+
let exhaustivenessCheck;
|
57
|
+
switch (event.kind) {
|
58
|
+
case InputEvtType.PointerDownEvt:
|
59
|
+
return this.onPointerDown(event);
|
60
|
+
case InputEvtType.PointerMoveEvt:
|
61
|
+
this.onPointerMove(event);
|
62
|
+
break;
|
63
|
+
case InputEvtType.PointerUpEvt:
|
64
|
+
return this.onPointerUp(event) ?? false;
|
65
|
+
case InputEvtType.GestureCancelEvt:
|
66
|
+
this.onGestureCancel(event);
|
67
|
+
break;
|
68
|
+
case InputEvtType.WheelEvt:
|
69
|
+
return this.onWheel(event);
|
70
|
+
case InputEvtType.KeyPressEvent:
|
71
|
+
return this.onKeyPress(event);
|
72
|
+
case InputEvtType.KeyUpEvent:
|
73
|
+
return this.onKeyUp(event);
|
74
|
+
case InputEvtType.CopyEvent:
|
75
|
+
return this.onCopy(event);
|
76
|
+
case InputEvtType.PasteEvent:
|
77
|
+
return this.onPaste(event);
|
78
|
+
case InputEvtType.ContextMenu:
|
79
|
+
return this.onContextMenu(event);
|
80
|
+
default:
|
81
|
+
exhaustivenessCheck = event;
|
82
|
+
return exhaustivenessCheck;
|
83
|
+
}
|
84
|
+
return true;
|
85
|
+
}
|
86
|
+
// @internal
|
87
|
+
onEvent(event) {
|
88
|
+
if (__classPrivateFieldGet(this, _BaseTool_inputMapper, "f")) {
|
89
|
+
return __classPrivateFieldGet(this, _BaseTool_inputMapper, "f").onEvent(event);
|
90
|
+
}
|
91
|
+
return this.dispatchEventToCallback(event);
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* Returns true iff the tool handled the event and thus should receive additional
|
95
|
+
* events.
|
96
|
+
*/
|
97
|
+
onPointerDown(_event) {
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
onPointerMove(_event) { }
|
101
|
+
/**
|
102
|
+
* Returns true iff there are additional pointers down and the tool should
|
103
|
+
* remain active to handle the additional events.
|
104
|
+
*
|
105
|
+
* For most purposes, this should return `false` or nothing.
|
106
|
+
*/
|
107
|
+
onPointerUp(_event) { }
|
108
|
+
onGestureCancel(_event) { }
|
109
|
+
onWheel(_event) {
|
110
|
+
return false;
|
111
|
+
}
|
112
|
+
onCopy(_event) {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
onPaste(_event) {
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
onKeyPress(_event) {
|
119
|
+
return false;
|
120
|
+
}
|
121
|
+
onKeyUp(_event) {
|
122
|
+
return false;
|
123
|
+
}
|
124
|
+
onContextMenu(_event) {
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
/**
|
128
|
+
* Return true if, while this tool is active, `_event` can be delivered to
|
129
|
+
* another tool that is higher priority than this.
|
130
|
+
* @internal May be renamed
|
131
|
+
*/
|
132
|
+
eventCanBeDeliveredToNonActiveTool(_event) {
|
133
|
+
return true;
|
134
|
+
}
|
135
|
+
setEnabled(enabled) {
|
136
|
+
__classPrivateFieldGet(this, _BaseTool_enabled, "f").set(enabled);
|
137
|
+
}
|
138
|
+
isEnabled() {
|
139
|
+
return __classPrivateFieldGet(this, _BaseTool_enabled, "f").get();
|
140
|
+
}
|
141
|
+
/**
|
142
|
+
* Returns a {@link ReactiveValue} that updates based on whether this tool is
|
143
|
+
* enabled.
|
144
|
+
*
|
145
|
+
* @example
|
146
|
+
* ```ts
|
147
|
+
* const tool = new SomeTool();
|
148
|
+
*
|
149
|
+
* // Watch for changes in enabled status
|
150
|
+
* tool.enabledValue().onUpdate(enabled => doSomething(enabled));
|
151
|
+
* ```
|
152
|
+
*/
|
153
|
+
enabledValue() {
|
154
|
+
return __classPrivateFieldGet(this, _BaseTool_enabled, "f");
|
155
|
+
}
|
156
|
+
// Connect this tool to a set of other tools, ensuring that at most one
|
157
|
+
// of the tools in the group is enabled.
|
158
|
+
setToolGroup(group) {
|
159
|
+
if (this.isEnabled()) {
|
160
|
+
group.notifyEnabled(this);
|
161
|
+
}
|
162
|
+
__classPrivateFieldSet(this, _BaseTool_group, group, "f");
|
163
|
+
}
|
164
|
+
getToolGroup() {
|
165
|
+
if (__classPrivateFieldGet(this, _BaseTool_group, "f")) {
|
166
|
+
return __classPrivateFieldGet(this, _BaseTool_group, "f");
|
167
|
+
}
|
168
|
+
return null;
|
169
|
+
}
|
170
|
+
// Called when the tool is removed/when the editor is destroyed.
|
171
|
+
// Subclasses that override this method **must call super.onDestroy()**.
|
172
|
+
onDestroy() {
|
173
|
+
__classPrivateFieldGet(this, _BaseTool_readOnlyEditorChangeListener, "f")?.remove();
|
174
|
+
__classPrivateFieldSet(this, _BaseTool_readOnlyEditorChangeListener, null, "f");
|
175
|
+
__classPrivateFieldSet(this, _BaseTool_group, null, "f");
|
176
|
+
}
|
177
|
+
}
|
178
|
+
_BaseTool_enabled = new WeakMap(), _BaseTool_group = new WeakMap(), _BaseTool_inputMapper = new WeakMap(), _BaseTool_readOnlyEditorChangeListener = new WeakMap();
|
179
|
+
export default BaseTool;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { GestureCancelEvt, KeyPressEvent, PointerEvt } from '../inputEvents';
|
2
|
+
import BaseTool from './BaseTool';
|
3
|
+
import Editor from '../Editor';
|
4
|
+
import { MutableReactiveValue } from '../util/ReactiveValue';
|
5
|
+
export declare enum EraserMode {
|
6
|
+
PartialStroke = "partial-stroke",
|
7
|
+
FullStroke = "full-stroke"
|
8
|
+
}
|
9
|
+
export interface InitialEraserOptions {
|
10
|
+
thickness?: number;
|
11
|
+
mode?: EraserMode;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* A tool that allows a user to erase parts of an image.
|
15
|
+
*/
|
16
|
+
export default class Eraser extends BaseTool {
|
17
|
+
private editor;
|
18
|
+
private lastPoint;
|
19
|
+
private isFirstEraseEvt;
|
20
|
+
private thickness;
|
21
|
+
private thicknessValue;
|
22
|
+
private modeValue;
|
23
|
+
private toRemove;
|
24
|
+
private toAdd;
|
25
|
+
private eraseCommands;
|
26
|
+
private addCommands;
|
27
|
+
constructor(editor: Editor, description: string, options?: InitialEraserOptions);
|
28
|
+
/**
|
29
|
+
* @returns a tool that briefly enables the eraser when a physical eraser is used.
|
30
|
+
* This tool should be added to the tool list after the primary tools.
|
31
|
+
*/
|
32
|
+
makeEraserSwitcherTool(): BaseTool;
|
33
|
+
private clearPreview;
|
34
|
+
private getSizeOnCanvas;
|
35
|
+
private drawPreviewAt;
|
36
|
+
/**
|
37
|
+
* @returns the eraser rectangle in canvas coordinates.
|
38
|
+
*
|
39
|
+
* For now, all erasers are rectangles or points.
|
40
|
+
*/
|
41
|
+
private getEraserRect;
|
42
|
+
/** Erases in a line from the last point to the current. */
|
43
|
+
private eraseTo;
|
44
|
+
onPointerDown(event: PointerEvt): boolean;
|
45
|
+
onPointerMove(event: PointerEvt): void;
|
46
|
+
onPointerUp(event: PointerEvt): void;
|
47
|
+
onGestureCancel(_event: GestureCancelEvt): void;
|
48
|
+
onKeyPress(event: KeyPressEvent): boolean;
|
49
|
+
/** Returns the side-length of the tip of this eraser. */
|
50
|
+
getThickness(): number;
|
51
|
+
/** Sets the side-length of this' tip. */
|
52
|
+
setThickness(thickness: number): void;
|
53
|
+
/**
|
54
|
+
* Returns a {@link MutableReactiveValue} that can be used to watch
|
55
|
+
* this tool's thickness.
|
56
|
+
*/
|
57
|
+
getThicknessValue(): MutableReactiveValue<number>;
|
58
|
+
/** @returns An object that allows switching between a full stroke and a partial stroke eraser. */
|
59
|
+
getModeValue(): MutableReactiveValue<EraserMode>;
|
60
|
+
}
|
@@ -0,0 +1,297 @@
|
|
1
|
+
import { EditorEventType } from '../types.mjs';
|
2
|
+
import BaseTool from './BaseTool.mjs';
|
3
|
+
import { Vec2, LineSegment2, Color4, Rect2, Path } from '@js-draw/math';
|
4
|
+
import Erase from '../commands/Erase.mjs';
|
5
|
+
import { PointerDevice } from '../Pointer.mjs';
|
6
|
+
import { decreaseSizeKeyboardShortcutId, increaseSizeKeyboardShortcutId } from './keybindings.mjs';
|
7
|
+
import { ReactiveValue } from '../util/ReactiveValue.mjs';
|
8
|
+
import EditorImage from '../image/EditorImage.mjs';
|
9
|
+
import uniteCommands from '../commands/uniteCommands.mjs';
|
10
|
+
import { pathToRenderable } from '../rendering/RenderablePathSpec.mjs';
|
11
|
+
export var EraserMode;
|
12
|
+
(function (EraserMode) {
|
13
|
+
EraserMode["PartialStroke"] = "partial-stroke";
|
14
|
+
EraserMode["FullStroke"] = "full-stroke";
|
15
|
+
})(EraserMode || (EraserMode = {}));
|
16
|
+
/** Handles switching from other primary tools to the eraser and back */
|
17
|
+
class EraserSwitcher extends BaseTool {
|
18
|
+
constructor(editor, eraser) {
|
19
|
+
super(editor.notifier, editor.localization.changeTool);
|
20
|
+
this.editor = editor;
|
21
|
+
this.eraser = eraser;
|
22
|
+
}
|
23
|
+
onPointerDown(event) {
|
24
|
+
if (event.allPointers.length === 1 && event.current.device === PointerDevice.Eraser) {
|
25
|
+
const toolController = this.editor.toolController;
|
26
|
+
const enabledPrimaryTools = toolController
|
27
|
+
.getPrimaryTools()
|
28
|
+
.filter((tool) => tool.isEnabled());
|
29
|
+
if (enabledPrimaryTools.length) {
|
30
|
+
this.previousEnabledTool = enabledPrimaryTools[0];
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
this.previousEnabledTool = null;
|
34
|
+
}
|
35
|
+
this.previousEraserEnabledState = this.eraser.isEnabled();
|
36
|
+
this.eraser.setEnabled(true);
|
37
|
+
if (this.eraser.onPointerDown(event)) {
|
38
|
+
return true;
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
this.restoreOriginalTool();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return false;
|
45
|
+
}
|
46
|
+
onPointerMove(event) {
|
47
|
+
this.eraser.onPointerMove(event);
|
48
|
+
}
|
49
|
+
restoreOriginalTool() {
|
50
|
+
this.eraser.setEnabled(this.previousEraserEnabledState);
|
51
|
+
if (this.previousEnabledTool) {
|
52
|
+
this.previousEnabledTool.setEnabled(true);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
onPointerUp(event) {
|
56
|
+
this.eraser.onPointerUp(event);
|
57
|
+
this.restoreOriginalTool();
|
58
|
+
}
|
59
|
+
onGestureCancel(event) {
|
60
|
+
this.eraser.onGestureCancel(event);
|
61
|
+
this.restoreOriginalTool();
|
62
|
+
}
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* A tool that allows a user to erase parts of an image.
|
66
|
+
*/
|
67
|
+
export default class Eraser extends BaseTool {
|
68
|
+
constructor(editor, description, options) {
|
69
|
+
super(editor.notifier, description);
|
70
|
+
this.editor = editor;
|
71
|
+
this.lastPoint = null;
|
72
|
+
this.isFirstEraseEvt = true;
|
73
|
+
this.toAdd = new Set();
|
74
|
+
// Commands that each remove one element
|
75
|
+
this.eraseCommands = [];
|
76
|
+
this.addCommands = [];
|
77
|
+
this.thickness = options?.thickness ?? 10;
|
78
|
+
this.thicknessValue = ReactiveValue.fromInitialValue(this.thickness);
|
79
|
+
this.thicknessValue.onUpdate((value) => {
|
80
|
+
this.thickness = value;
|
81
|
+
this.editor.notifier.dispatch(EditorEventType.ToolUpdated, {
|
82
|
+
kind: EditorEventType.ToolUpdated,
|
83
|
+
tool: this,
|
84
|
+
});
|
85
|
+
});
|
86
|
+
this.modeValue = ReactiveValue.fromInitialValue(options?.mode ?? EraserMode.FullStroke);
|
87
|
+
this.modeValue.onUpdate((_value) => {
|
88
|
+
this.editor.notifier.dispatch(EditorEventType.ToolUpdated, {
|
89
|
+
kind: EditorEventType.ToolUpdated,
|
90
|
+
tool: this,
|
91
|
+
});
|
92
|
+
});
|
93
|
+
}
|
94
|
+
/**
|
95
|
+
* @returns a tool that briefly enables the eraser when a physical eraser is used.
|
96
|
+
* This tool should be added to the tool list after the primary tools.
|
97
|
+
*/
|
98
|
+
makeEraserSwitcherTool() {
|
99
|
+
return new EraserSwitcher(this.editor, this);
|
100
|
+
}
|
101
|
+
clearPreview() {
|
102
|
+
this.editor.clearWetInk();
|
103
|
+
}
|
104
|
+
getSizeOnCanvas() {
|
105
|
+
return this.thickness / this.editor.viewport.getScaleFactor();
|
106
|
+
}
|
107
|
+
drawPreviewAt(point) {
|
108
|
+
this.clearPreview();
|
109
|
+
const size = this.getSizeOnCanvas();
|
110
|
+
const renderer = this.editor.display.getWetInkRenderer();
|
111
|
+
const rect = this.getEraserRect(point);
|
112
|
+
const rect2 = this.getEraserRect(this.lastPoint ?? point);
|
113
|
+
const fill = {
|
114
|
+
fill: Color4.transparent,
|
115
|
+
stroke: { width: size / 10, color: Color4.gray },
|
116
|
+
};
|
117
|
+
renderer.drawPath(pathToRenderable(Path.fromConvexHullOf([...rect.corners, ...rect2.corners]), fill));
|
118
|
+
}
|
119
|
+
/**
|
120
|
+
* @returns the eraser rectangle in canvas coordinates.
|
121
|
+
*
|
122
|
+
* For now, all erasers are rectangles or points.
|
123
|
+
*/
|
124
|
+
getEraserRect(centerPoint) {
|
125
|
+
const size = this.getSizeOnCanvas();
|
126
|
+
const halfSize = Vec2.of(size / 2, size / 2);
|
127
|
+
return Rect2.fromCorners(centerPoint.minus(halfSize), centerPoint.plus(halfSize));
|
128
|
+
}
|
129
|
+
/** Erases in a line from the last point to the current. */
|
130
|
+
eraseTo(currentPoint) {
|
131
|
+
if (!this.isFirstEraseEvt && currentPoint.distanceTo(this.lastPoint) === 0) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
this.isFirstEraseEvt = false;
|
135
|
+
// Currently only objects within eraserRect or that intersect a straight line
|
136
|
+
// from the center of the current rect to the previous are erased. TODO: Erase
|
137
|
+
// all objects as if there were pointerMove events between the two points.
|
138
|
+
const eraserRect = this.getEraserRect(currentPoint);
|
139
|
+
const line = new LineSegment2(this.lastPoint, currentPoint);
|
140
|
+
const region = Rect2.union(line.bbox, eraserRect);
|
141
|
+
const intersectingElems = this.editor.image
|
142
|
+
.getElementsIntersectingRegion(region)
|
143
|
+
.filter((component) => {
|
144
|
+
return component.intersects(line) || component.intersectsRect(eraserRect);
|
145
|
+
});
|
146
|
+
// Only erase components that could be selected (and thus interacted with)
|
147
|
+
// by the user.
|
148
|
+
const eraseableElems = intersectingElems.filter((elem) => elem.isSelectable());
|
149
|
+
if (this.modeValue.get() === EraserMode.FullStroke) {
|
150
|
+
// Remove any intersecting elements.
|
151
|
+
this.toRemove.push(...eraseableElems);
|
152
|
+
// Create new Erase commands for the now-to-be-erased elements and apply them.
|
153
|
+
const newPartialCommands = eraseableElems.map((elem) => new Erase([elem]));
|
154
|
+
newPartialCommands.forEach((cmd) => cmd.apply(this.editor));
|
155
|
+
this.eraseCommands.push(...newPartialCommands);
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
const toErase = [];
|
159
|
+
const toAdd = [];
|
160
|
+
for (const targetElem of eraseableElems) {
|
161
|
+
toErase.push(targetElem);
|
162
|
+
// Completely delete items that can't be divided.
|
163
|
+
if (!targetElem.withRegionErased) {
|
164
|
+
continue;
|
165
|
+
}
|
166
|
+
// Completely delete items that are completely or almost completely
|
167
|
+
// contained within the eraser.
|
168
|
+
const grownRect = eraserRect.grownBy(eraserRect.maxDimension / 3);
|
169
|
+
if (grownRect.containsRect(targetElem.getExactBBox())) {
|
170
|
+
continue;
|
171
|
+
}
|
172
|
+
// Join the current and previous rectangles so that points between events are also
|
173
|
+
// erased.
|
174
|
+
const erasePath = Path.fromConvexHullOf([
|
175
|
+
...eraserRect.corners,
|
176
|
+
...this.getEraserRect(this.lastPoint ?? currentPoint).corners,
|
177
|
+
].map((p) => this.editor.viewport.roundPoint(p)));
|
178
|
+
toAdd.push(...targetElem.withRegionErased(erasePath, this.editor.viewport));
|
179
|
+
}
|
180
|
+
const eraseCommand = new Erase(toErase);
|
181
|
+
const newAddCommands = toAdd.map((elem) => EditorImage.addElement(elem));
|
182
|
+
eraseCommand.apply(this.editor);
|
183
|
+
newAddCommands.forEach((command) => command.apply(this.editor));
|
184
|
+
const finalToErase = [];
|
185
|
+
for (const item of toErase) {
|
186
|
+
if (this.toAdd.has(item)) {
|
187
|
+
this.toAdd.delete(item);
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
finalToErase.push(item);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
this.toRemove.push(...finalToErase);
|
194
|
+
for (const item of toAdd) {
|
195
|
+
this.toAdd.add(item);
|
196
|
+
}
|
197
|
+
this.eraseCommands.push(new Erase(finalToErase));
|
198
|
+
this.addCommands.push(...newAddCommands);
|
199
|
+
}
|
200
|
+
this.drawPreviewAt(currentPoint);
|
201
|
+
this.lastPoint = currentPoint;
|
202
|
+
}
|
203
|
+
onPointerDown(event) {
|
204
|
+
if (event.allPointers.length === 1 || event.current.device === PointerDevice.Eraser) {
|
205
|
+
this.lastPoint = event.current.canvasPos;
|
206
|
+
this.toRemove = [];
|
207
|
+
this.toAdd.clear();
|
208
|
+
this.isFirstEraseEvt = true;
|
209
|
+
this.drawPreviewAt(event.current.canvasPos);
|
210
|
+
return true;
|
211
|
+
}
|
212
|
+
return false;
|
213
|
+
}
|
214
|
+
onPointerMove(event) {
|
215
|
+
const currentPoint = event.current.canvasPos;
|
216
|
+
this.eraseTo(currentPoint);
|
217
|
+
}
|
218
|
+
onPointerUp(event) {
|
219
|
+
this.eraseTo(event.current.canvasPos);
|
220
|
+
const commands = [];
|
221
|
+
if (this.addCommands.length > 0) {
|
222
|
+
this.addCommands.forEach((cmd) => cmd.unapply(this.editor));
|
223
|
+
// Remove items from toAdd that are also present in toRemove -- adding, then
|
224
|
+
// removing these does nothing, and can break undo/redo.
|
225
|
+
for (const item of this.toAdd) {
|
226
|
+
if (this.toRemove.includes(item)) {
|
227
|
+
this.toAdd.delete(item);
|
228
|
+
this.toRemove = this.toRemove.filter((other) => other !== item);
|
229
|
+
}
|
230
|
+
}
|
231
|
+
for (const item of this.toRemove) {
|
232
|
+
if (this.toAdd.has(item)) {
|
233
|
+
this.toAdd.delete(item);
|
234
|
+
this.toRemove = this.toRemove.filter((other) => other !== item);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
commands.push(...[...this.toAdd].map((a) => EditorImage.addElement(a)));
|
238
|
+
this.addCommands = [];
|
239
|
+
}
|
240
|
+
if (this.eraseCommands.length > 0) {
|
241
|
+
// Undo commands for each individual component and unite into a single command.
|
242
|
+
this.eraseCommands.forEach((cmd) => cmd.unapply(this.editor));
|
243
|
+
this.eraseCommands = [];
|
244
|
+
const command = new Erase(this.toRemove);
|
245
|
+
commands.push(command);
|
246
|
+
}
|
247
|
+
if (commands.length === 1) {
|
248
|
+
this.editor.dispatch(commands[0]); // dispatch: Makes undo-able.
|
249
|
+
}
|
250
|
+
else {
|
251
|
+
this.editor.dispatch(uniteCommands(commands));
|
252
|
+
}
|
253
|
+
this.clearPreview();
|
254
|
+
}
|
255
|
+
onGestureCancel(_event) {
|
256
|
+
this.addCommands.forEach((cmd) => cmd.unapply(this.editor));
|
257
|
+
this.eraseCommands.forEach((cmd) => cmd.unapply(this.editor));
|
258
|
+
this.eraseCommands = [];
|
259
|
+
this.addCommands = [];
|
260
|
+
this.clearPreview();
|
261
|
+
}
|
262
|
+
onKeyPress(event) {
|
263
|
+
const shortcuts = this.editor.shortcuts;
|
264
|
+
let newThickness;
|
265
|
+
if (shortcuts.matchesShortcut(decreaseSizeKeyboardShortcutId, event)) {
|
266
|
+
newThickness = (this.getThickness() * 2) / 3;
|
267
|
+
}
|
268
|
+
else if (shortcuts.matchesShortcut(increaseSizeKeyboardShortcutId, event)) {
|
269
|
+
newThickness = (this.getThickness() * 3) / 2;
|
270
|
+
}
|
271
|
+
if (newThickness !== undefined) {
|
272
|
+
newThickness = Math.min(Math.max(1, newThickness), 200);
|
273
|
+
this.setThickness(newThickness);
|
274
|
+
return true;
|
275
|
+
}
|
276
|
+
return false;
|
277
|
+
}
|
278
|
+
/** Returns the side-length of the tip of this eraser. */
|
279
|
+
getThickness() {
|
280
|
+
return this.thickness;
|
281
|
+
}
|
282
|
+
/** Sets the side-length of this' tip. */
|
283
|
+
setThickness(thickness) {
|
284
|
+
this.thicknessValue.set(thickness);
|
285
|
+
}
|
286
|
+
/**
|
287
|
+
* Returns a {@link MutableReactiveValue} that can be used to watch
|
288
|
+
* this tool's thickness.
|
289
|
+
*/
|
290
|
+
getThicknessValue() {
|
291
|
+
return this.thicknessValue;
|
292
|
+
}
|
293
|
+
/** @returns An object that allows switching between a full stroke and a partial stroke eraser. */
|
294
|
+
getModeValue() {
|
295
|
+
return this.modeValue;
|
296
|
+
}
|
297
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import Editor from '../Editor';
|
2
|
+
import { KeyPressEvent } from '../inputEvents';
|
3
|
+
import BaseTool from './BaseTool';
|
4
|
+
export default class FindTool extends BaseTool {
|
5
|
+
private editor;
|
6
|
+
private overlay;
|
7
|
+
private searchInput;
|
8
|
+
private currentMatchIdx;
|
9
|
+
constructor(editor: Editor);
|
10
|
+
canReceiveInputInReadOnlyEditor(): boolean;
|
11
|
+
private getMatches;
|
12
|
+
private focusCurrentMatch;
|
13
|
+
private toNextMatch;
|
14
|
+
private toPrevMatch;
|
15
|
+
private fillOverlay;
|
16
|
+
private isVisible;
|
17
|
+
private setVisible;
|
18
|
+
private toggleVisible;
|
19
|
+
onKeyPress(event: KeyPressEvent): boolean;
|
20
|
+
setEnabled(enabled: boolean): void;
|
21
|
+
}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
// Displays a find dialog that allows the user to search for and focus text.
|
2
|
+
//
|
3
|
+
// @packageDocumentation
|
4
|
+
import TextComponent from '../components/TextComponent.mjs';
|
5
|
+
import ImageComponent from '../components/ImageComponent.mjs';
|
6
|
+
import BaseTool from './BaseTool.mjs';
|
7
|
+
import { toggleFindVisibleShortcutId } from './keybindings.mjs';
|
8
|
+
const cssPrefix = 'find-tool';
|
9
|
+
export default class FindTool extends BaseTool {
|
10
|
+
constructor(editor) {
|
11
|
+
super(editor.notifier, editor.localization.findLabel);
|
12
|
+
this.editor = editor;
|
13
|
+
this.currentMatchIdx = 0;
|
14
|
+
this.overlay = document.createElement('div');
|
15
|
+
this.fillOverlay();
|
16
|
+
editor.createHTMLOverlay(this.overlay);
|
17
|
+
this.overlay.style.display = 'none';
|
18
|
+
this.overlay.classList.add(`${cssPrefix}-overlay`);
|
19
|
+
}
|
20
|
+
canReceiveInputInReadOnlyEditor() {
|
21
|
+
return true;
|
22
|
+
}
|
23
|
+
getMatches(searchFor) {
|
24
|
+
const lowerSearchFor = searchFor.toLocaleLowerCase();
|
25
|
+
const matchingComponents = this.editor.image.getAllElements().filter((component) => {
|
26
|
+
let text = '';
|
27
|
+
if (component instanceof TextComponent) {
|
28
|
+
text = component.getText();
|
29
|
+
}
|
30
|
+
else if (component instanceof ImageComponent) {
|
31
|
+
text = component.getAltText() ?? '';
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
const hasLowercaseMatch = text.toLocaleLowerCase().indexOf(lowerSearchFor) !== -1;
|
37
|
+
const hasSameCaseMatch = text.indexOf(searchFor) !== -1;
|
38
|
+
return hasLowercaseMatch || hasSameCaseMatch;
|
39
|
+
});
|
40
|
+
return matchingComponents.map((match) => match.getBBox());
|
41
|
+
}
|
42
|
+
focusCurrentMatch() {
|
43
|
+
const matches = this.getMatches(this.searchInput.value);
|
44
|
+
let matchIdx = this.currentMatchIdx % matches.length;
|
45
|
+
if (matchIdx < 0) {
|
46
|
+
matchIdx = matches.length + matchIdx;
|
47
|
+
}
|
48
|
+
if (matchIdx < matches.length) {
|
49
|
+
const undoable = false;
|
50
|
+
void this.editor.dispatch(this.editor.viewport.zoomTo(matches[matchIdx], true, true), undoable);
|
51
|
+
this.editor.announceForAccessibility(this.editor.localization.focusedFoundText(matchIdx + 1, matches.length));
|
52
|
+
}
|
53
|
+
}
|
54
|
+
toNextMatch() {
|
55
|
+
this.currentMatchIdx++;
|
56
|
+
this.focusCurrentMatch();
|
57
|
+
}
|
58
|
+
toPrevMatch() {
|
59
|
+
this.currentMatchIdx--;
|
60
|
+
this.focusCurrentMatch();
|
61
|
+
}
|
62
|
+
fillOverlay() {
|
63
|
+
const label = document.createElement('label');
|
64
|
+
this.searchInput = document.createElement('input');
|
65
|
+
const nextBtn = document.createElement('button');
|
66
|
+
const closeBtn = document.createElement('button');
|
67
|
+
// Math.random() ensures that the ID is unique (to allow us to refer to it
|
68
|
+
// with an htmlFor).
|
69
|
+
this.searchInput.setAttribute('id', `${cssPrefix}-searchInput-${Math.random()}`);
|
70
|
+
label.htmlFor = this.searchInput.getAttribute('id');
|
71
|
+
label.innerText = this.editor.localization.findLabel;
|
72
|
+
nextBtn.innerText = this.editor.localization.toNextMatch;
|
73
|
+
closeBtn.innerText = this.editor.localization.closeDialog;
|
74
|
+
this.searchInput.onkeydown = (ev) => {
|
75
|
+
if (ev.key === 'Enter') {
|
76
|
+
if (ev.shiftKey) {
|
77
|
+
this.toPrevMatch();
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
this.toNextMatch();
|
81
|
+
}
|
82
|
+
}
|
83
|
+
else if (ev.key === 'Escape') {
|
84
|
+
this.setVisible(false);
|
85
|
+
}
|
86
|
+
else if (this.editor.shortcuts.matchesShortcut(toggleFindVisibleShortcutId, ev)) {
|
87
|
+
ev.preventDefault();
|
88
|
+
this.toggleVisible();
|
89
|
+
}
|
90
|
+
};
|
91
|
+
nextBtn.onclick = () => {
|
92
|
+
this.toNextMatch();
|
93
|
+
};
|
94
|
+
closeBtn.onclick = () => {
|
95
|
+
this.setVisible(false);
|
96
|
+
};
|
97
|
+
this.overlay.replaceChildren(label, this.searchInput, nextBtn, closeBtn);
|
98
|
+
}
|
99
|
+
isVisible() {
|
100
|
+
return this.overlay.style.display !== 'none';
|
101
|
+
}
|
102
|
+
setVisible(visible) {
|
103
|
+
if (visible !== this.isVisible()) {
|
104
|
+
this.overlay.style.display = visible ? 'block' : 'none';
|
105
|
+
if (visible) {
|
106
|
+
this.searchInput.focus();
|
107
|
+
this.editor.announceForAccessibility(this.editor.localization.findDialogShown);
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
this.editor.focus();
|
111
|
+
this.editor.announceForAccessibility(this.editor.localization.findDialogHidden);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
toggleVisible() {
|
116
|
+
this.setVisible(!this.isVisible());
|
117
|
+
}
|
118
|
+
onKeyPress(event) {
|
119
|
+
if (this.editor.shortcuts.matchesShortcut(toggleFindVisibleShortcutId, event)) {
|
120
|
+
this.toggleVisible();
|
121
|
+
return true;
|
122
|
+
}
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
setEnabled(enabled) {
|
126
|
+
super.setEnabled(enabled);
|
127
|
+
if (this.isEnabled()) {
|
128
|
+
this.setVisible(false);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|