js-draw 1.21.3 → 1.23.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +104 -76
- 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.d.ts +1 -3
- package/dist/cjs/Editor.js +38 -26
- package/dist/cjs/EventDispatcher.js +1 -1
- package/dist/cjs/Pointer.js +3 -3
- package/dist/cjs/SVGLoader/SVGLoader.js +15 -6
- package/dist/cjs/UndoRedoHistory.js +1 -1
- package/dist/cjs/Viewport.d.ts +1 -1
- package/dist/cjs/Viewport.js +5 -3
- 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 +2 -2
- package/dist/cjs/components/AbstractComponent.js +4 -4
- 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.d.ts +30 -7
- package/dist/cjs/image/EditorImage.js +43 -22
- 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.d.ts +2 -25
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +6 -28
- package/dist/cjs/rendering/renderers/DummyRenderer.js +1 -1
- package/dist/cjs/rendering/renderers/SVGRenderer.js +39 -21
- 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.d.ts +19 -0
- package/dist/cjs/toolbar/AbstractToolbar.js +26 -11
- package/dist/cjs/toolbar/EdgeToolbar.js +11 -15
- package/dist/cjs/toolbar/IconProvider.d.ts +5 -1
- package/dist/cjs/toolbar/IconProvider.js +117 -149
- package/dist/cjs/toolbar/localization.js +5 -5
- 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.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/BaseWidget.js +8 -8
- 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 +18 -13
- package/dist/cjs/tools/PasteHandler.js +8 -2
- package/dist/cjs/tools/Pen.d.ts +13 -0
- package/dist/cjs/tools/Pen.js +30 -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/lib.d.ts +1 -0
- package/dist/cjs/tools/lib.js +3 -1
- 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/cloneElementWithStyles.js +1 -1
- package/dist/cjs/util/createElement.d.ts +62 -0
- package/dist/cjs/util/createElement.js +53 -0
- 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.d.ts +1 -3
- package/dist/mjs/Editor.mjs +39 -27
- package/dist/mjs/EventDispatcher.mjs +1 -1
- package/dist/mjs/Pointer.mjs +3 -3
- package/dist/mjs/SVGLoader/SVGLoader.mjs +16 -7
- package/dist/mjs/UndoRedoHistory.mjs +1 -1
- package/dist/mjs/Viewport.d.ts +1 -1
- package/dist/mjs/Viewport.mjs +5 -3
- 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 +2 -2
- package/dist/mjs/components/AbstractComponent.mjs +4 -4
- 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.d.ts +30 -7
- package/dist/mjs/image/EditorImage.mjs +43 -22
- 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.d.ts +2 -25
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +6 -28
- package/dist/mjs/rendering/renderers/DummyRenderer.mjs +1 -1
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +40 -22
- 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.d.ts +19 -0
- package/dist/mjs/toolbar/AbstractToolbar.mjs +26 -11
- package/dist/mjs/toolbar/EdgeToolbar.mjs +11 -15
- package/dist/mjs/toolbar/IconProvider.d.ts +5 -1
- package/dist/mjs/toolbar/IconProvider.mjs +117 -149
- package/dist/mjs/toolbar/localization.mjs +5 -5
- 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.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +9 -9
- 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 +19 -14
- package/dist/mjs/tools/PasteHandler.mjs +8 -2
- package/dist/mjs/tools/Pen.d.ts +13 -0
- package/dist/mjs/tools/Pen.mjs +31 -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/lib.d.ts +1 -0
- package/dist/mjs/tools/lib.mjs +1 -0
- 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/cloneElementWithStyles.mjs +1 -1
- package/dist/mjs/util/createElement.d.ts +62 -0
- package/dist/mjs/util/createElement.mjs +47 -0
- 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
@@ -22,7 +22,7 @@ export default class FindTool extends BaseTool {
|
|
22
22
|
}
|
23
23
|
getMatches(searchFor) {
|
24
24
|
const lowerSearchFor = searchFor.toLocaleLowerCase();
|
25
|
-
const matchingComponents = this.editor.image.getAllElements().filter(component => {
|
25
|
+
const matchingComponents = this.editor.image.getAllElements().filter((component) => {
|
26
26
|
let text = '';
|
27
27
|
if (component instanceof TextComponent) {
|
28
28
|
text = component.getText();
|
@@ -37,7 +37,7 @@ export default class FindTool extends BaseTool {
|
|
37
37
|
const hasSameCaseMatch = text.indexOf(searchFor) !== -1;
|
38
38
|
return hasLowercaseMatch || hasSameCaseMatch;
|
39
39
|
});
|
40
|
-
return matchingComponents.map(match => match.getBBox());
|
40
|
+
return matchingComponents.map((match) => match.getBBox());
|
41
41
|
}
|
42
42
|
focusCurrentMatch() {
|
43
43
|
const matches = this.getMatches(this.searchInput.value);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { InputEvtType, isPointerEvt } from '../../inputEvents.mjs';
|
2
2
|
import InputMapper from './InputMapper.mjs';
|
3
|
-
import StationaryPenDetector, { defaultStationaryDetectionConfig } from '../util/StationaryPenDetector.mjs';
|
3
|
+
import StationaryPenDetector, { defaultStationaryDetectionConfig, } from '../util/StationaryPenDetector.mjs';
|
4
4
|
import { PointerDevice } from '../../Pointer.mjs';
|
5
5
|
export default class ContextMenuRecognizer extends InputMapper {
|
6
6
|
constructor() {
|
@@ -15,9 +15,7 @@ export default class ContextMenuRecognizer extends InputMapper {
|
|
15
15
|
* one such device.
|
16
16
|
*/
|
17
17
|
canMakeLongPressMenuEvent(event) {
|
18
|
-
const allowedDevices = [
|
19
|
-
PointerDevice.Touch,
|
20
|
-
];
|
18
|
+
const allowedDevices = [PointerDevice.Touch];
|
21
19
|
return event.allPointers.length === 1 && allowedDevices.includes(event.current.device);
|
22
20
|
}
|
23
21
|
onEvent(event) {
|
@@ -19,7 +19,7 @@ class InputMapper {
|
|
19
19
|
}
|
20
20
|
// @internal
|
21
21
|
setEmitListener(listener) {
|
22
|
-
if (listener && typeof
|
22
|
+
if (listener && typeof listener === 'object') {
|
23
23
|
__classPrivateFieldSet(this, _InputMapper_listener, (event) => {
|
24
24
|
return listener.onEvent(event) ?? false;
|
25
25
|
}, "f");
|
@@ -42,7 +42,7 @@ class InputPipeline extends InputMapper {
|
|
42
42
|
__classPrivateFieldGet(this, _InputPipeline_tail, "f").setEmitListener(mapper);
|
43
43
|
__classPrivateFieldSet(this, _InputPipeline_tail, mapper, "f");
|
44
44
|
}
|
45
|
-
__classPrivateFieldGet(this, _InputPipeline_tail, "f").setEmitListener(event => this.emit(event));
|
45
|
+
__classPrivateFieldGet(this, _InputPipeline_tail, "f").setEmitListener((event) => this.emit(event));
|
46
46
|
}
|
47
47
|
}
|
48
48
|
_InputPipeline_head = new WeakMap(), _InputPipeline_tail = new WeakMap();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { InputEvtType, isPointerEvt } from '../../inputEvents.mjs';
|
1
|
+
import { InputEvtType, isPointerEvt, } from '../../inputEvents.mjs';
|
2
2
|
import InputMapper from './InputMapper.mjs';
|
3
3
|
import { Vec2 } from '@js-draw/math';
|
4
4
|
import untilNextAnimationFrame from '../../util/untilNextAnimationFrame.mjs';
|
@@ -48,10 +48,14 @@ class StylusInputStabilizer {
|
|
48
48
|
const springForce = toTarget.times(this.options.springConstant);
|
49
49
|
const gravityAccel = 10;
|
50
50
|
const normalForceMagnitude = this.options.mass * gravityAccel;
|
51
|
-
const frictionForce = this.velocity
|
52
|
-
|
51
|
+
const frictionForce = this.velocity
|
52
|
+
.normalizedOrZero()
|
53
|
+
.times(-this.options.frictionCoefficient * normalForceMagnitude);
|
54
|
+
const acceleration = springForce.plus(frictionForce).times(1 / this.options.mass);
|
53
55
|
const decayFactor = this.options.velocityDecayFactor;
|
54
|
-
const springVelocity = this.velocity
|
56
|
+
const springVelocity = this.velocity
|
57
|
+
.times(1 - decayFactor)
|
58
|
+
.plus(acceleration.times(deltaTimeMs / 1000));
|
55
59
|
// An alternate velocity that goes directly towards the target.
|
56
60
|
const toTargetVelocity = toTarget.normalizedOrZero().times(springVelocity.length());
|
57
61
|
return toTargetVelocity.lerp(springVelocity, this.options.inertiaFraction);
|
@@ -117,7 +121,9 @@ export default class InputStabilizer extends InputMapper {
|
|
117
121
|
this.lastPointerEvent = event;
|
118
122
|
}
|
119
123
|
// Only apply smoothing if there is a single pointer.
|
120
|
-
if (event.kind === InputEvtType.GestureCancelEvt ||
|
124
|
+
if (event.kind === InputEvtType.GestureCancelEvt ||
|
125
|
+
event.allPointers.length > 1 ||
|
126
|
+
this.stabilizer === null) {
|
121
127
|
return this.emit(event);
|
122
128
|
}
|
123
129
|
this.stabilizer.setTarget(event.current.screenPos);
|
@@ -161,7 +167,8 @@ export default class InputStabilizer extends InputMapper {
|
|
161
167
|
}
|
162
168
|
}
|
163
169
|
const handled = this.mapPointerEvent(event);
|
164
|
-
if (event.kind === InputEvtType.PointerUpEvt ||
|
170
|
+
if (event.kind === InputEvtType.PointerUpEvt ||
|
171
|
+
event.kind === InputEvtType.GestureCancelEvt) {
|
165
172
|
this.stabilizer?.cancel();
|
166
173
|
this.stabilizer = null;
|
167
174
|
}
|
@@ -48,18 +48,21 @@ export default class StrokeKeyboardControl extends InputMapper {
|
|
48
48
|
}
|
49
49
|
onEvent(event) {
|
50
50
|
const shortcuts = this.shortcuts;
|
51
|
-
if (event.kind === InputEvtType.PointerDownEvt ||
|
51
|
+
if (event.kind === InputEvtType.PointerDownEvt ||
|
52
|
+
event.kind === InputEvtType.PointerMoveEvt ||
|
53
|
+
event.kind === InputEvtType.PointerUpEvt) {
|
52
54
|
if (event.kind === InputEvtType.PointerDownEvt) {
|
53
55
|
this.startPointCanvas = event.current.canvasPos;
|
54
56
|
}
|
55
57
|
event = this.mapPointerEvent(event);
|
56
58
|
}
|
57
59
|
let handled = this.emit(event);
|
58
|
-
if (
|
59
|
-
|
60
|
+
if (
|
61
|
+
// Always check keyUpEvents (in case we handled the corresponding keyDown event)
|
62
|
+
event.kind === InputEvtType.KeyUpEvent ||
|
60
63
|
// Only handle key press events if another tool isn't handling it. We don't want
|
61
64
|
// snap to grid/angle lock to conflict with selection/another tool's shortcuts.
|
62
|
-
|
65
|
+
(!handled && event.kind === InputEvtType.KeyPressEvent)) {
|
63
66
|
const isKeyPress = event.kind === InputEvtType.KeyPressEvent;
|
64
67
|
if (shortcuts.matchesShortcut(snapToGridKeyboardShortcutId, event)) {
|
65
68
|
this.snapToGridEnabled = isKeyPress;
|
@@ -54,7 +54,7 @@ export default class PanZoom extends BaseTool {
|
|
54
54
|
canReceiveInputInReadOnlyEditor(): boolean;
|
55
55
|
computePinchData(p1: Pointer, p2: Pointer): PinchData;
|
56
56
|
private allPointersAreOfType;
|
57
|
-
onPointerDown({ allPointers: pointers, current: currentPointer }: PointerEvt): boolean;
|
57
|
+
onPointerDown({ allPointers: pointers, current: currentPointer, }: PointerEvt): boolean;
|
58
58
|
private updateVelocity;
|
59
59
|
private getCenterDelta;
|
60
60
|
private toSnappedRotationDelta;
|
@@ -4,7 +4,7 @@ import { EditorEventType } from '../types.mjs';
|
|
4
4
|
import untilNextAnimationFrame from '../util/untilNextAnimationFrame.mjs';
|
5
5
|
import { Viewport } from '../Viewport.mjs';
|
6
6
|
import BaseTool from './BaseTool.mjs';
|
7
|
-
import { moveDownKeyboardShortcutId, moveLeftKeyboardShortcutId, moveRightKeyboardShortcutId, moveUpKeyboardShortcutId, rotateClockwiseKeyboardShortcutId, rotateCounterClockwiseKeyboardShortcutId, zoomInKeyboardShortcutId, zoomOutKeyboardShortcutId } from './keybindings.mjs';
|
7
|
+
import { moveDownKeyboardShortcutId, moveLeftKeyboardShortcutId, moveRightKeyboardShortcutId, moveUpKeyboardShortcutId, rotateClockwiseKeyboardShortcutId, rotateCounterClockwiseKeyboardShortcutId, zoomInKeyboardShortcutId, zoomOutKeyboardShortcutId, } from './keybindings.mjs';
|
8
8
|
export var PanZoomMode;
|
9
9
|
(function (PanZoomMode) {
|
10
10
|
/** Touch gestures with a single pointer. Ignores non-touch gestures. */
|
@@ -117,9 +117,9 @@ export default class PanZoom extends BaseTool {
|
|
117
117
|
return { canvasCenter, screenCenter, angle, dist };
|
118
118
|
}
|
119
119
|
allPointersAreOfType(pointers, kind) {
|
120
|
-
return pointers.every(pointer => pointer.device === kind);
|
120
|
+
return pointers.every((pointer) => pointer.device === kind);
|
121
121
|
}
|
122
|
-
onPointerDown({ allPointers: pointers, current: currentPointer }) {
|
122
|
+
onPointerDown({ allPointers: pointers, current: currentPointer, }) {
|
123
123
|
let handlingGesture = false;
|
124
124
|
const inertialScrollerVelocity = this.inertialScroller?.getCurrentVelocity() ?? Vec2.zero;
|
125
125
|
this.inertialScroller?.stop();
|
@@ -141,9 +141,10 @@ export default class PanZoom extends BaseTool {
|
|
141
141
|
this.isRotating = Math.abs(Math.sin(this.initialViewportRotation * 2)) > 1e-3;
|
142
142
|
handlingGesture = true;
|
143
143
|
}
|
144
|
-
else if (pointers.length === 1 &&
|
145
|
-
|
146
|
-
|
144
|
+
else if (pointers.length === 1 &&
|
145
|
+
((this.mode & PanZoomMode.OneFingerTouchGestures && allAreTouch) ||
|
146
|
+
(isRightClick && this.mode & PanZoomMode.RightClickDrags) ||
|
147
|
+
this.mode & PanZoomMode.SinglePointerGestures)) {
|
147
148
|
this.lastScreenCenter = pointers[0].screenPos;
|
148
149
|
this.isScaling = false;
|
149
150
|
handlingGesture = true;
|
@@ -197,7 +198,9 @@ export default class PanZoom extends BaseTool {
|
|
197
198
|
// `snapToMultipleOf`.
|
198
199
|
// Use a smaller snap angle if already rotated (to avoid pinch zoom gestures from
|
199
200
|
// starting rotation).
|
200
|
-
const maxSnapAngle = this.isRotating
|
201
|
+
const maxSnapAngle = this.isRotating
|
202
|
+
? this.afterRotationStartSnapAngle
|
203
|
+
: this.initialRotationSnapAngle;
|
201
204
|
// Snap the rotation
|
202
205
|
if (Math.abs(fullRotation - roundedFullRotation) < maxSnapAngle) {
|
203
206
|
fullRotation = roundedFullRotation;
|
@@ -216,7 +219,7 @@ export default class PanZoom extends BaseTool {
|
|
216
219
|
*/
|
217
220
|
toSnappedScaleFactor(touchDist) {
|
218
221
|
// scaleFactor is applied to the current transformation of the viewport.
|
219
|
-
const newScale = this.initialViewportScale * touchDist / this.startTouchDist;
|
222
|
+
const newScale = (this.initialViewportScale * touchDist) / this.startTouchDist;
|
220
223
|
const currentScale = this.editor.viewport.getScaleFactor();
|
221
224
|
const logNewScale = Math.log(newScale) / Math.log(10);
|
222
225
|
const roundedLogNewScale = Math.round(logNewScale);
|
@@ -295,10 +298,10 @@ export default class PanZoom extends BaseTool {
|
|
295
298
|
this.velocity = Vec2.zero;
|
296
299
|
};
|
297
300
|
const minInertialScrollDt = 30;
|
298
|
-
const shouldInertialScroll = event.current.device === PointerDevice.Touch
|
299
|
-
|
300
|
-
|
301
|
-
|
301
|
+
const shouldInertialScroll = event.current.device === PointerDevice.Touch &&
|
302
|
+
event.allPointers.length === 1 &&
|
303
|
+
this.velocity !== null &&
|
304
|
+
event.current.timeStamp - this.lastPointerDownTimestamp > minInertialScrollDt;
|
302
305
|
if (shouldInertialScroll && this.velocity !== null) {
|
303
306
|
const oldVelocity = this.velocity;
|
304
307
|
// If the user drags the screen, then stops, then lifts the pointer,
|
@@ -424,7 +427,7 @@ export default class PanZoom extends BaseTool {
|
|
424
427
|
translation = translation.times(-1);
|
425
428
|
rotation = rotation * -1;
|
426
429
|
scale = 1 / scale;
|
427
|
-
// Work around an issue that seems to be related to rotation
|
430
|
+
// Work around an issue that seems to be related to rotation matrices losing precision on inversion.
|
428
431
|
// TODO: Figure out why and implement a better solution.
|
429
432
|
if (rotation !== 0) {
|
430
433
|
rotation += 0.0001;
|
@@ -438,7 +441,9 @@ export default class PanZoom extends BaseTool {
|
|
438
441
|
translation = toCanvas.transformVec3(translation);
|
439
442
|
// Rotate/scale about the center of the canvas
|
440
443
|
const transformCenter = this.editor.viewport.visibleRect.center;
|
441
|
-
const transformUpdate = Mat33.scaling2D(scale, transformCenter)
|
444
|
+
const transformUpdate = Mat33.scaling2D(scale, transformCenter)
|
445
|
+
.rightMul(Mat33.zRotation(rotation, transformCenter))
|
446
|
+
.rightMul(Mat33.translation(translation));
|
442
447
|
this.applyAndFinalizeTransform(transformUpdate);
|
443
448
|
return true;
|
444
449
|
}
|
@@ -85,14 +85,20 @@ export default class PasteHandler extends BaseTool {
|
|
85
85
|
}
|
86
86
|
return 0;
|
87
87
|
});
|
88
|
-
const defaultTextStyle = {
|
88
|
+
const defaultTextStyle = {
|
89
|
+
size: 12,
|
90
|
+
fontFamily: 'sans',
|
91
|
+
renderingStyle: { fill: Color4.red },
|
92
|
+
};
|
89
93
|
const pastedTextStyle = textTools[0]?.getTextStyle() ?? defaultTextStyle;
|
90
94
|
// Don't paste text that would be invisible.
|
91
95
|
if (text.trim() === '') {
|
92
96
|
return;
|
93
97
|
}
|
94
98
|
const lines = text.split('\n');
|
95
|
-
await this.addComponentsFromPaste([
|
99
|
+
await this.addComponentsFromPaste([
|
100
|
+
TextComponent.fromLines(lines, Mat33.identity, pastedTextStyle),
|
101
|
+
]);
|
96
102
|
}
|
97
103
|
async doImagePaste(dataURL) {
|
98
104
|
const image = new Image();
|
package/dist/mjs/tools/Pen.d.ts
CHANGED
@@ -11,6 +11,12 @@ export interface PenStyle {
|
|
11
11
|
readonly thickness: number;
|
12
12
|
readonly factory: ComponentBuilderFactory;
|
13
13
|
}
|
14
|
+
/**
|
15
|
+
* A tool that allows drawing shapes and freehand lines.
|
16
|
+
*
|
17
|
+
* To change the type of shape drawn by the pen (e.g. to switch to the rectangle
|
18
|
+
* pen type), see {@link setStrokeFactory}.
|
19
|
+
*/
|
14
20
|
export default class Pen extends BaseTool {
|
15
21
|
private editor;
|
16
22
|
protected builder: ComponentBuilder | null;
|
@@ -42,6 +48,13 @@ export default class Pen extends BaseTool {
|
|
42
48
|
private noteUpdated;
|
43
49
|
setColor(color: Color4): void;
|
44
50
|
setThickness(thickness: number): void;
|
51
|
+
/**
|
52
|
+
* Changes the type of stroke created by the pen. The given `factory` can be one of the built-in
|
53
|
+
* stroke factories (e.g. {@link makeFreehandLineBuilder}) or a custom stroke factory.
|
54
|
+
*
|
55
|
+
* Example:
|
56
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
57
|
+
*/
|
45
58
|
setStrokeFactory(factory: ComponentBuilderFactory): void;
|
46
59
|
setHasStabilization(hasStabilization: boolean): void;
|
47
60
|
setStrokeAutocorrectEnabled(enabled: boolean): void;
|
package/dist/mjs/tools/Pen.mjs
CHANGED
@@ -8,7 +8,13 @@ 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
|
+
/**
|
13
|
+
* A tool that allows drawing shapes and freehand lines.
|
14
|
+
*
|
15
|
+
* To change the type of shape drawn by the pen (e.g. to switch to the rectangle
|
16
|
+
* pen type), see {@link setStrokeFactory}.
|
17
|
+
*/
|
12
18
|
export default class Pen extends BaseTool {
|
13
19
|
constructor(editor, description, style) {
|
14
20
|
super(editor.notifier, description);
|
@@ -29,14 +35,14 @@ export default class Pen extends BaseTool {
|
|
29
35
|
thickness: 4,
|
30
36
|
...style,
|
31
37
|
});
|
32
|
-
this.styleValue.onUpdateAndNow(newValue => {
|
38
|
+
this.styleValue.onUpdateAndNow((newValue) => {
|
33
39
|
this.style = newValue;
|
34
40
|
this.noteUpdated();
|
35
41
|
});
|
36
42
|
}
|
37
43
|
getPressureMultiplier() {
|
38
44
|
const thickness = this.style.thickness;
|
39
|
-
return 1 / this.editor.viewport.getScaleFactor() * thickness;
|
45
|
+
return (1 / this.editor.viewport.getScaleFactor()) * thickness;
|
40
46
|
}
|
41
47
|
// Converts a `pointer` to a `StrokeDataPoint`.
|
42
48
|
toStrokePoint(pointer) {
|
@@ -95,7 +101,7 @@ export default class Pen extends BaseTool {
|
|
95
101
|
this.currentDeviceType = current.device;
|
96
102
|
this.currentPointerId = current.id;
|
97
103
|
if (this.shapeAutocompletionEnabled) {
|
98
|
-
this.stationaryDetector = new StationaryPenDetector(current, defaultStationaryDetectionConfig, pointer => this.autocorrectShape(pointer));
|
104
|
+
this.stationaryDetector = new StationaryPenDetector(current, defaultStationaryDetectionConfig, (pointer) => this.autocorrectShape(pointer));
|
99
105
|
}
|
100
106
|
else {
|
101
107
|
this.stationaryDetector = null;
|
@@ -244,6 +250,13 @@ export default class Pen extends BaseTool {
|
|
244
250
|
});
|
245
251
|
}
|
246
252
|
}
|
253
|
+
/**
|
254
|
+
* Changes the type of stroke created by the pen. The given `factory` can be one of the built-in
|
255
|
+
* stroke factories (e.g. {@link makeFreehandLineBuilder}) or a custom stroke factory.
|
256
|
+
*
|
257
|
+
* Example:
|
258
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
259
|
+
*/
|
247
260
|
setStrokeFactory(factory) {
|
248
261
|
if (factory !== this.style.factory) {
|
249
262
|
this.styleValue.set({
|
@@ -275,10 +288,18 @@ export default class Pen extends BaseTool {
|
|
275
288
|
getStrokeAutocorrectionEnabled() {
|
276
289
|
return this.shapeAutocompletionEnabled;
|
277
290
|
}
|
278
|
-
getThickness() {
|
279
|
-
|
280
|
-
|
281
|
-
|
291
|
+
getThickness() {
|
292
|
+
return this.style.thickness;
|
293
|
+
}
|
294
|
+
getColor() {
|
295
|
+
return this.style.color;
|
296
|
+
}
|
297
|
+
getStrokeFactory() {
|
298
|
+
return this.style.factory;
|
299
|
+
}
|
300
|
+
getStyleValue() {
|
301
|
+
return this.styleValue;
|
302
|
+
}
|
282
303
|
onKeyPress(event) {
|
283
304
|
const shortcuts = this.editor.shortcuts;
|
284
305
|
// Ctrl+Z: End the stroke so that it can be undone/redone.
|
@@ -291,10 +312,10 @@ export default class Pen extends BaseTool {
|
|
291
312
|
}
|
292
313
|
let newThickness;
|
293
314
|
if (shortcuts.matchesShortcut(decreaseSizeKeyboardShortcutId, event)) {
|
294
|
-
newThickness = this.getThickness() * 2 / 3;
|
315
|
+
newThickness = (this.getThickness() * 2) / 3;
|
295
316
|
}
|
296
317
|
else if (shortcuts.matchesShortcut(increaseSizeKeyboardShortcutId, event)) {
|
297
|
-
newThickness = this.getThickness() * 3 / 2;
|
318
|
+
newThickness = (this.getThickness() * 3) / 2;
|
298
319
|
}
|
299
320
|
if (newThickness !== undefined) {
|
300
321
|
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
|
}
|