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
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Vec2, Rect2, Mat33, Color4 } from '@js-draw/math';
|
2
|
-
import { cloneTextStyle, textStyleFromJSON, textStyleToJSON } from '../rendering/TextRenderingStyle.mjs';
|
2
|
+
import { cloneTextStyle, textStyleFromJSON, textStyleToJSON, } from '../rendering/TextRenderingStyle.mjs';
|
3
3
|
import AbstractComponent from './AbstractComponent.mjs';
|
4
|
-
import { createRestyleComponentCommand } from './RestylableComponent.mjs';
|
4
|
+
import { createRestyleComponentCommand, } from './RestylableComponent.mjs';
|
5
5
|
const componentTypeId = 'text';
|
6
6
|
export var TextTransformMode;
|
7
7
|
(function (TextTransformMode) {
|
@@ -15,7 +15,9 @@ export var TextTransformMode;
|
|
15
15
|
TextTransformMode[TextTransformMode["RELATIVE_Y_ABSOLUTE_X"] = 3] = "RELATIVE_Y_ABSOLUTE_X";
|
16
16
|
})(TextTransformMode || (TextTransformMode = {}));
|
17
17
|
const defaultTextStyle = {
|
18
|
-
fontFamily: 'sans',
|
18
|
+
fontFamily: 'sans',
|
19
|
+
size: 12,
|
20
|
+
renderingStyle: { fill: Color4.purple },
|
19
21
|
};
|
20
22
|
/**
|
21
23
|
* Displays text.
|
@@ -76,7 +78,7 @@ class TextComponent extends AbstractComponent {
|
|
76
78
|
this.recomputeBBox();
|
77
79
|
// If this has no direct children, choose a style representative of this' content
|
78
80
|
// (useful for estimating the style of the TextComponent).
|
79
|
-
const hasDirectContent = textObjects.some(obj => typeof obj === 'string');
|
81
|
+
const hasDirectContent = textObjects.some((obj) => typeof obj === 'string');
|
80
82
|
if (!hasDirectContent && textObjects.length > 0) {
|
81
83
|
this.style = textObjects[0].getTextStyle();
|
82
84
|
}
|
@@ -90,7 +92,7 @@ class TextComponent extends AbstractComponent {
|
|
90
92
|
style.fontStyle ?? '',
|
91
93
|
style.fontWeight ?? '',
|
92
94
|
(style.size ?? 12) + 'px',
|
93
|
-
`${fontFamily}
|
95
|
+
`${fontFamily}`,
|
94
96
|
].join(' ');
|
95
97
|
// TODO: Support RTL
|
96
98
|
ctx.textAlign = 'left';
|
@@ -101,7 +103,7 @@ class TextComponent extends AbstractComponent {
|
|
101
103
|
const heightEst = style.size;
|
102
104
|
// Text is drawn with (0, 0) as its baseline. As such, the majority of the text's height should
|
103
105
|
// be above (0, 0).
|
104
|
-
return new Rect2(0, -heightEst * 2 / 3, widthEst, heightEst);
|
106
|
+
return new Rect2(0, (-heightEst * 2) / 3, widthEst, heightEst);
|
105
107
|
}
|
106
108
|
// Returns a set of TextMetrics for the given text, if a canvas is available.
|
107
109
|
static getTextMetrics(text, style) {
|
@@ -181,7 +183,7 @@ class TextComponent extends AbstractComponent {
|
|
181
183
|
const textBBox = TextComponent.getTextDimens(subObject, this.style);
|
182
184
|
// TODO: Use a better intersection check. Perhaps draw the text onto a CanvasElement and
|
183
185
|
// use pixel-testing to check for intersection with its contour.
|
184
|
-
if (textBBox.getEdges().some(edge => transformedLine.intersection(edge) !== null)) {
|
186
|
+
if (textBBox.getEdges().some((edge) => transformedLine.intersection(edge) !== null)) {
|
185
187
|
return true;
|
186
188
|
}
|
187
189
|
}
|
@@ -249,7 +251,7 @@ class TextComponent extends AbstractComponent {
|
|
249
251
|
this.recomputeBBox();
|
250
252
|
}
|
251
253
|
createClone() {
|
252
|
-
const clonedTextObjects = this.textObjects.map(obj => {
|
254
|
+
const clonedTextObjects = this.textObjects.map((obj) => {
|
253
255
|
if (typeof obj === 'string') {
|
254
256
|
return obj;
|
255
257
|
}
|
@@ -277,7 +279,7 @@ class TextComponent extends AbstractComponent {
|
|
277
279
|
// Do not rely on the output of `serializeToJSON` taking any particular format.
|
278
280
|
serializeToJSON() {
|
279
281
|
const serializableStyle = textStyleToJSON(this.style);
|
280
|
-
const serializedTextObjects = this.textObjects.map(text => {
|
282
|
+
const serializedTextObjects = this.textObjects.map((text) => {
|
281
283
|
if (typeof text === 'string') {
|
282
284
|
return {
|
283
285
|
text,
|
@@ -363,7 +365,7 @@ TextComponent.TextCursor = class {
|
|
363
365
|
let elementTransform = Mat33.identity;
|
364
366
|
let elemInternalTransform = Mat33.identity;
|
365
367
|
let textSize;
|
366
|
-
if (typeof
|
368
|
+
if (typeof elem === 'string') {
|
367
369
|
textSize = TextComponent.getTextDimens(elem, this.parentStyle);
|
368
370
|
}
|
369
371
|
else {
|
@@ -372,12 +374,13 @@ TextComponent.TextCursor = class {
|
|
372
374
|
elemInternalTransform = elem.transform;
|
373
375
|
textSize = elem.getBBox();
|
374
376
|
}
|
375
|
-
const positioning = typeof
|
377
|
+
const positioning = typeof elem === 'string' ? TextTransformMode.RELATIVE_XY : elem.transformMode;
|
376
378
|
if (positioning === TextTransformMode.RELATIVE_XY) {
|
377
379
|
// Position relative to the previous element's transform.
|
378
380
|
elementTransform = this.transform.rightMul(elementTransform);
|
379
381
|
}
|
380
|
-
else if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y ||
|
382
|
+
else if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y ||
|
383
|
+
positioning === TextTransformMode.RELATIVE_Y_ABSOLUTE_X) {
|
381
384
|
// Zero the absolute component of this.transform's translation
|
382
385
|
const transform = this.transform.mapEntries((component, [row, col]) => {
|
383
386
|
if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y) {
|
@@ -23,10 +23,9 @@ export default class UnknownSVGObject extends AbstractComponent {
|
|
23
23
|
canvas.endObject(this.getLoadSaveData());
|
24
24
|
}
|
25
25
|
intersects(lineSegment) {
|
26
|
-
return this.contentBBox.getEdges().some(edge => edge.intersection(lineSegment) !== null);
|
27
|
-
}
|
28
|
-
applyTransformation(_affineTransfm) {
|
26
|
+
return this.contentBBox.getEdges().some((edge) => edge.intersection(lineSegment) !== null);
|
29
27
|
}
|
28
|
+
applyTransformation(_affineTransfm) { }
|
30
29
|
isSelectable() {
|
31
30
|
return false;
|
32
31
|
}
|
@@ -4,6 +4,12 @@ import { StrokeDataPoint } from '../../types';
|
|
4
4
|
import Viewport from '../../Viewport';
|
5
5
|
import AbstractComponent from '../AbstractComponent';
|
6
6
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
7
|
+
/**
|
8
|
+
* Creates a stroke builder that generates arrows circles.
|
9
|
+
*
|
10
|
+
* Example:
|
11
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
12
|
+
*/
|
7
13
|
export declare const makeArrowBuilder: ComponentBuilderFactory;
|
8
14
|
export default class ArrowBuilder implements ComponentBuilder {
|
9
15
|
private readonly startPoint;
|
@@ -1,6 +1,12 @@
|
|
1
1
|
import { Path, PathCommandType } from '@js-draw/math';
|
2
2
|
import Stroke from '../Stroke.mjs';
|
3
3
|
import makeSnapToGridAutocorrect from './autocorrect/makeSnapToGridAutocorrect.mjs';
|
4
|
+
/**
|
5
|
+
* Creates a stroke builder that generates arrows circles.
|
6
|
+
*
|
7
|
+
* Example:
|
8
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
9
|
+
*/
|
4
10
|
export const makeArrowBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
|
5
11
|
return new ArrowBuilder(initialPoint, viewport);
|
6
12
|
});
|
@@ -63,15 +69,15 @@ export default class ArrowBuilder {
|
|
63
69
|
point: arrowTipBase.minus(scaledBaseNormal),
|
64
70
|
},
|
65
71
|
// Round all points in the arrow (to remove unnecessary decimal places)
|
66
|
-
]).mapPoints(point => this.viewport.roundPoint(point));
|
72
|
+
]).mapPoints((point) => this.viewport.roundPoint(point));
|
67
73
|
const preview = new Stroke([
|
68
74
|
{
|
69
75
|
startPoint: path.startPoint,
|
70
76
|
commands: path.parts,
|
71
77
|
style: {
|
72
78
|
fill: this.startPoint.color,
|
73
|
-
}
|
74
|
-
}
|
79
|
+
},
|
80
|
+
},
|
75
81
|
]);
|
76
82
|
return preview;
|
77
83
|
}
|
@@ -1,2 +1,8 @@
|
|
1
1
|
import { ComponentBuilderFactory } from './types';
|
2
|
+
/**
|
3
|
+
* Creates a stroke builder that generates outlined circles.
|
4
|
+
*
|
5
|
+
* Example:
|
6
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
7
|
+
*/
|
2
8
|
export declare const makeOutlinedCircleBuilder: ComponentBuilderFactory;
|
@@ -3,6 +3,12 @@ import { pathToRenderable } from '../../rendering/RenderablePathSpec.mjs';
|
|
3
3
|
import Viewport from '../../Viewport.mjs';
|
4
4
|
import Stroke from '../Stroke.mjs';
|
5
5
|
import makeSnapToGridAutocorrect from './autocorrect/makeSnapToGridAutocorrect.mjs';
|
6
|
+
/**
|
7
|
+
* Creates a stroke builder that generates outlined circles.
|
8
|
+
*
|
9
|
+
* Example:
|
10
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
11
|
+
*/
|
6
12
|
export const makeOutlinedCircleBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
|
7
13
|
return new CircleBuilder(initialPoint, viewport);
|
8
14
|
});
|
@@ -20,7 +26,7 @@ class CircleBuilder {
|
|
20
26
|
buildPreview() {
|
21
27
|
const pathCommands = [];
|
22
28
|
const numDivisions = 6;
|
23
|
-
const stepSize = Math.PI * 2 / numDivisions;
|
29
|
+
const stepSize = (Math.PI * 2) / numDivisions;
|
24
30
|
// Round the stroke width so that when exported it doesn't have unnecessary trailing decimals.
|
25
31
|
const strokeWidth = Viewport.roundPoint(this.endPoint.width, 5 / this.viewport.getScaleFactor());
|
26
32
|
const center = this.startPoint.pos.lerp(this.endPoint.pos, 0.5);
|
@@ -32,7 +38,9 @@ class CircleBuilder {
|
|
32
38
|
// controlPointRadiusScale is selected to make the circles appear circular and
|
33
39
|
// **does** depend on stepSize.
|
34
40
|
const controlPointRadiusScale = 1.141;
|
35
|
-
const controlPoint = Vec2.of(Math.cos(t - stepSize / 2), -Math.sin(t - stepSize / 2))
|
41
|
+
const controlPoint = Vec2.of(Math.cos(t - stepSize / 2), -Math.sin(t - stepSize / 2))
|
42
|
+
.times(radius * controlPointRadiusScale)
|
43
|
+
.plus(center);
|
36
44
|
pathCommands.push({
|
37
45
|
kind: PathCommandType.QuadraticBezierTo,
|
38
46
|
controlPoint,
|
@@ -43,8 +51,7 @@ class CircleBuilder {
|
|
43
51
|
kind: PathCommandType.LineTo,
|
44
52
|
point: startPoint,
|
45
53
|
});
|
46
|
-
const path = new Path(startPoint, pathCommands)
|
47
|
-
.mapPoints(point => this.viewport.roundPoint(point));
|
54
|
+
const path = new Path(startPoint, pathCommands).mapPoints((point) => this.viewport.roundPoint(point));
|
48
55
|
const preview = new Stroke([
|
49
56
|
pathToRenderable(path, {
|
50
57
|
fill: Color4.transparent,
|
@@ -6,6 +6,12 @@ import Viewport from '../../Viewport';
|
|
6
6
|
import { StrokeDataPoint } from '../../types';
|
7
7
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
8
8
|
import RenderingStyle from '../../rendering/RenderingStyle';
|
9
|
+
/**
|
10
|
+
* Creates a stroke builder that draws freehand lines.
|
11
|
+
*
|
12
|
+
* Example:
|
13
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
14
|
+
*/
|
9
15
|
export declare const makeFreehandLineBuilder: ComponentBuilderFactory;
|
10
16
|
export default class FreehandLineBuilder implements ComponentBuilder {
|
11
17
|
private startPoint;
|
@@ -3,6 +3,12 @@ import Stroke from '../Stroke.mjs';
|
|
3
3
|
import Viewport from '../../Viewport.mjs';
|
4
4
|
import { StrokeSmoother } from '../util/StrokeSmoother.mjs';
|
5
5
|
import makeShapeFitAutocorrect from './autocorrect/makeShapeFitAutocorrect.mjs';
|
6
|
+
/**
|
7
|
+
* Creates a stroke builder that draws freehand lines.
|
8
|
+
*
|
9
|
+
* Example:
|
10
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
11
|
+
*/
|
6
12
|
export const makeFreehandLineBuilder = makeShapeFitAutocorrect((initialPoint, viewport) => {
|
7
13
|
// Don't smooth if input is more than ± 3 pixels from the true curve, do smooth if
|
8
14
|
// less than ±1 px from the curve.
|
@@ -32,7 +38,7 @@ export default class FreehandLineBuilder {
|
|
32
38
|
stroke: {
|
33
39
|
color: this.startPoint.color,
|
34
40
|
width: this.roundDistance(this.averageWidth),
|
35
|
-
}
|
41
|
+
},
|
36
42
|
};
|
37
43
|
}
|
38
44
|
previewCurrentPath() {
|
@@ -129,7 +135,7 @@ export default class FreehandLineBuilder {
|
|
129
135
|
kind: PathCommandType.QuadraticBezierTo,
|
130
136
|
controlPoint: center.plus(Vec2.of(width, -width)),
|
131
137
|
endPoint: center.plus(Vec2.of(width, 0)),
|
132
|
-
}
|
138
|
+
},
|
133
139
|
];
|
134
140
|
}
|
135
141
|
const result = [];
|
@@ -157,7 +163,7 @@ export default class FreehandLineBuilder {
|
|
157
163
|
this.curveFitter.addPoint(newPoint);
|
158
164
|
this.widthAverageNumSamples++;
|
159
165
|
this.averageWidth =
|
160
|
-
this.averageWidth * (this.widthAverageNumSamples - 1) / this.widthAverageNumSamples
|
161
|
-
|
166
|
+
(this.averageWidth * (this.widthAverageNumSamples - 1)) / this.widthAverageNumSamples +
|
167
|
+
newPoint.width / this.widthAverageNumSamples;
|
162
168
|
}
|
163
169
|
}
|
@@ -4,6 +4,12 @@ import { StrokeDataPoint } from '../../types';
|
|
4
4
|
import Viewport from '../../Viewport';
|
5
5
|
import AbstractComponent from '../AbstractComponent';
|
6
6
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
7
|
+
/**
|
8
|
+
* Creates a stroke builder that generates filled lines.
|
9
|
+
*
|
10
|
+
* Example:
|
11
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
12
|
+
*/
|
7
13
|
export declare const makeLineBuilder: ComponentBuilderFactory;
|
8
14
|
export default class LineBuilder implements ComponentBuilder {
|
9
15
|
private readonly startPoint;
|
@@ -2,6 +2,12 @@ import { Path, PathCommandType } from '@js-draw/math';
|
|
2
2
|
import { pathToRenderable } from '../../rendering/RenderablePathSpec.mjs';
|
3
3
|
import Stroke from '../Stroke.mjs';
|
4
4
|
import makeSnapToGridAutocorrect from './autocorrect/makeSnapToGridAutocorrect.mjs';
|
5
|
+
/**
|
6
|
+
* Creates a stroke builder that generates filled lines.
|
7
|
+
*
|
8
|
+
* Example:
|
9
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
10
|
+
*/
|
5
11
|
export const makeLineBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
|
6
12
|
return new LineBuilder(initialPoint, viewport);
|
7
13
|
});
|
@@ -42,10 +48,8 @@ export default class LineBuilder {
|
|
42
48
|
kind: PathCommandType.LineTo,
|
43
49
|
point: startPoint.minus(scaledStartNormal),
|
44
50
|
},
|
45
|
-
]).mapPoints(point => this.viewport.roundPoint(point));
|
46
|
-
const preview = new Stroke([
|
47
|
-
pathToRenderable(path, { fill: this.startPoint.color })
|
48
|
-
]);
|
51
|
+
]).mapPoints((point) => this.viewport.roundPoint(point));
|
52
|
+
const preview = new Stroke([pathToRenderable(path, { fill: this.startPoint.color })]);
|
49
53
|
return preview;
|
50
54
|
}
|
51
55
|
build() {
|
@@ -7,8 +7,11 @@ import { StrokeDataPoint } from '../../types';
|
|
7
7
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
8
8
|
import RenderingStyle from '../../rendering/RenderingStyle';
|
9
9
|
/**
|
10
|
-
* Creates
|
10
|
+
* Creates a freehand line builder that creates strokes from line segments
|
11
|
+
* rather than Bézier curves.
|
11
12
|
*
|
13
|
+
* Example:
|
14
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
12
15
|
*/
|
13
16
|
export declare const makePolylineBuilder: ComponentBuilderFactory;
|
14
17
|
export default class PolylineBuilder implements ComponentBuilder {
|
@@ -1,10 +1,13 @@
|
|
1
|
-
import { Rect2, Color4, PathCommandType, Vec2, LineSegment2 } from '@js-draw/math';
|
1
|
+
import { Rect2, Color4, PathCommandType, Vec2, LineSegment2, } from '@js-draw/math';
|
2
2
|
import Stroke from '../Stroke.mjs';
|
3
3
|
import Viewport from '../../Viewport.mjs';
|
4
4
|
import makeShapeFitAutocorrect from './autocorrect/makeShapeFitAutocorrect.mjs';
|
5
5
|
/**
|
6
|
-
* Creates
|
6
|
+
* Creates a freehand line builder that creates strokes from line segments
|
7
|
+
* rather than Bézier curves.
|
7
8
|
*
|
9
|
+
* Example:
|
10
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
8
11
|
*/
|
9
12
|
export const makePolylineBuilder = makeShapeFitAutocorrect((initialPoint, viewport) => {
|
10
13
|
// Fit to a value slightly smaller than the pixel size. A larger value can
|
@@ -42,7 +45,7 @@ export default class PolylineBuilder {
|
|
42
45
|
stroke: {
|
43
46
|
color: this.startPoint.color,
|
44
47
|
width: this.roundDistance(this.averageWidth),
|
45
|
-
}
|
48
|
+
},
|
46
49
|
};
|
47
50
|
}
|
48
51
|
previewCurrentPath() {
|
@@ -96,12 +99,13 @@ export default class PolylineBuilder {
|
|
96
99
|
addPoint(newPoint) {
|
97
100
|
this.widthAverageNumSamples++;
|
98
101
|
this.averageWidth =
|
99
|
-
this.averageWidth * (this.widthAverageNumSamples - 1) / this.widthAverageNumSamples
|
100
|
-
|
102
|
+
(this.averageWidth * (this.widthAverageNumSamples - 1)) / this.widthAverageNumSamples +
|
103
|
+
newPoint.width / this.widthAverageNumSamples;
|
101
104
|
const roundedPoint = this.roundPoint(newPoint.pos);
|
102
105
|
if (!roundedPoint.eq(this.lastPoint)) {
|
103
106
|
// If almost exactly in the same line as the previous
|
104
|
-
if (this.lastLineSegment &&
|
107
|
+
if (this.lastLineSegment &&
|
108
|
+
this.lastLineSegment.direction.dot(roundedPoint.minus(this.lastPoint).normalized()) > 0.997) {
|
105
109
|
this.parts.pop();
|
106
110
|
this.lastPoint = this.lastLineSegment.p1;
|
107
111
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Vec2, Rect2, PathCommandType, QuadraticBezier } from '@js-draw/math';
|
1
|
+
import { Vec2, Rect2, PathCommandType, QuadraticBezier, } from '@js-draw/math';
|
2
2
|
import Stroke from '../Stroke.mjs';
|
3
3
|
import Viewport from '../../Viewport.mjs';
|
4
4
|
import { StrokeSmoother } from '../util/StrokeSmoother.mjs';
|
@@ -30,7 +30,7 @@ export default class PressureSensitiveFreehandLineBuilder {
|
|
30
30
|
this.parts = [];
|
31
31
|
this.upperSegments = [];
|
32
32
|
this.lowerSegments = [];
|
33
|
-
this.curveFitter = new StrokeSmoother(startPoint, minFitAllowed, maxFitAllowed, curve => this.addCurve(curve));
|
33
|
+
this.curveFitter = new StrokeSmoother(startPoint, minFitAllowed, maxFitAllowed, (curve) => this.addCurve(curve));
|
34
34
|
this.curveStartWidth = startPoint.width;
|
35
35
|
this.bbox = new Rect2(this.startPoint.pos.x, this.startPoint.pos.y, 0, 0);
|
36
36
|
}
|
@@ -64,7 +64,8 @@ export default class PressureSensitiveFreehandLineBuilder {
|
|
64
64
|
}
|
65
65
|
let startPoint;
|
66
66
|
const lastLowerSegment = lowerPath[lowerPath.length - 1];
|
67
|
-
if (lastLowerSegment.kind === PathCommandType.LineTo ||
|
67
|
+
if (lastLowerSegment.kind === PathCommandType.LineTo ||
|
68
|
+
lastLowerSegment.kind === PathCommandType.MoveTo) {
|
68
69
|
startPoint = lastLowerSegment.point;
|
69
70
|
}
|
70
71
|
else {
|
@@ -163,11 +164,11 @@ export default class PressureSensitiveFreehandLineBuilder {
|
|
163
164
|
// where the next stroke and the previous stroke are in different directions.
|
164
165
|
//
|
165
166
|
// Are the exit/enter directions of the previous and current curves in different enough directions?
|
166
|
-
if (getEnterDirection(upperCurve).dot(getExitDirection(this.lastUpperBezier)) < 0.35
|
167
|
-
|
167
|
+
if (getEnterDirection(upperCurve).dot(getExitDirection(this.lastUpperBezier)) < 0.35 ||
|
168
|
+
getEnterDirection(lowerCurve).dot(getExitDirection(this.lastLowerBezier)) < 0.35 ||
|
168
169
|
// Also handle if the curves exit/enter directions differ
|
169
|
-
|
170
|
-
|
170
|
+
getEnterDirection(upperCurve).dot(getExitDirection(upperCurve)) < 0 ||
|
171
|
+
getEnterDirection(lowerCurve).dot(getExitDirection(lowerCurve)) < 0) {
|
171
172
|
return true;
|
172
173
|
}
|
173
174
|
// Check whether the lower curve intersects the other wall:
|
@@ -274,8 +275,9 @@ export default class PressureSensitiveFreehandLineBuilder {
|
|
274
275
|
// Approximate the normal at the location of the control point
|
275
276
|
const projectionT = bezier.nearestPointTo(controlPoint).parameterValue;
|
276
277
|
const halfVecT = projectionT;
|
277
|
-
const halfVec = bezier
|
278
|
-
|
278
|
+
const halfVec = bezier
|
279
|
+
.normal(halfVecT)
|
280
|
+
.times((curve.startWidth / 2) * halfVecT + (curve.endWidth / 2) * (1 - halfVecT));
|
279
281
|
// Each starts at startPt ± startVec
|
280
282
|
const lowerCurveStartPoint = this.roundPoint(startPt.plus(startVec));
|
281
283
|
const lowerCurveControlPoint = this.roundPoint(controlPoint.plus(halfVec));
|
@@ -318,8 +320,12 @@ export default class PressureSensitiveFreehandLineBuilder {
|
|
318
320
|
const upperCurve = new QuadraticBezier(upperCurveStartPoint, upperCurveControlPoint, upperCurveEndPoint);
|
319
321
|
const lowerCurve = new QuadraticBezier(lowerCurveStartPoint, lowerCurveControlPoint, lowerCurveEndPoint);
|
320
322
|
return {
|
321
|
-
upperCurveCommand,
|
322
|
-
|
323
|
+
upperCurveCommand,
|
324
|
+
upperToLowerConnector,
|
325
|
+
lowerToUpperConnector,
|
326
|
+
lowerCurveCommand,
|
327
|
+
upperCurve,
|
328
|
+
lowerCurve,
|
323
329
|
nextCurveStartConnector,
|
324
330
|
};
|
325
331
|
}
|
@@ -4,7 +4,19 @@ import { StrokeDataPoint } from '../../types';
|
|
4
4
|
import Viewport from '../../Viewport';
|
5
5
|
import AbstractComponent from '../AbstractComponent';
|
6
6
|
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
7
|
+
/**
|
8
|
+
* Creates filled rectangles with sharp corners.
|
9
|
+
*
|
10
|
+
* Example:
|
11
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
12
|
+
*/
|
7
13
|
export declare const makeFilledRectangleBuilder: ComponentBuilderFactory;
|
14
|
+
/**
|
15
|
+
* Creates outlined rectangles with sharp corners.
|
16
|
+
*
|
17
|
+
* Example:
|
18
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
19
|
+
*/
|
8
20
|
export declare const makeOutlinedRectangleBuilder: ComponentBuilderFactory;
|
9
21
|
export default class RectangleBuilder implements ComponentBuilder {
|
10
22
|
private readonly startPoint;
|
@@ -2,9 +2,21 @@ import { Mat33, Rect2, Path } from '@js-draw/math';
|
|
2
2
|
import { pathToRenderable } from '../../rendering/RenderablePathSpec.mjs';
|
3
3
|
import Stroke from '../Stroke.mjs';
|
4
4
|
import makeSnapToGridAutocorrect from './autocorrect/makeSnapToGridAutocorrect.mjs';
|
5
|
+
/**
|
6
|
+
* Creates filled rectangles with sharp corners.
|
7
|
+
*
|
8
|
+
* Example:
|
9
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
10
|
+
*/
|
5
11
|
export const makeFilledRectangleBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
|
6
12
|
return new RectangleBuilder(initialPoint, true, viewport);
|
7
13
|
});
|
14
|
+
/**
|
15
|
+
* Creates outlined rectangles with sharp corners.
|
16
|
+
*
|
17
|
+
* Example:
|
18
|
+
* [[include:doc-pages/inline-examples/changing-pen-types.md]]
|
19
|
+
*/
|
8
20
|
export const makeOutlinedRectangleBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
|
9
21
|
return new RectangleBuilder(initialPoint, false, viewport);
|
10
22
|
});
|
@@ -28,12 +40,14 @@ export default class RectangleBuilder {
|
|
28
40
|
const startPoint = rotationMat.inverse().transformVec2(this.startPoint.pos);
|
29
41
|
const endPoint = rotationMat.inverse().transformVec2(this.endPoint.pos);
|
30
42
|
const rect = Rect2.fromCorners(startPoint, endPoint);
|
31
|
-
const path = Path.fromRect(rect, this.filled ? null : this.endPoint.width)
|
43
|
+
const path = Path.fromRect(rect, this.filled ? null : this.endPoint.width)
|
44
|
+
.transformedBy(
|
32
45
|
// Rotate the canvas rectangle so that its rotation matches the screen
|
33
|
-
rotationMat)
|
46
|
+
rotationMat)
|
47
|
+
.mapPoints((point) => this.viewport.roundPoint(point));
|
34
48
|
const preview = new Stroke([
|
35
49
|
pathToRenderable(path, {
|
36
|
-
fill: this.endPoint.color
|
50
|
+
fill: this.endPoint.color,
|
37
51
|
}),
|
38
52
|
]);
|
39
53
|
return preview;
|
@@ -6,14 +6,11 @@ const makeShapeFitAutocorrect = (sourceFactory) => {
|
|
6
6
|
};
|
7
7
|
export default makeShapeFitAutocorrect;
|
8
8
|
const makeLineTemplate = (startPoint, points, _bbox) => {
|
9
|
-
const templatePoints = [
|
10
|
-
|
11
|
-
points[points.length - 1],
|
12
|
-
];
|
13
|
-
return { points: templatePoints, };
|
9
|
+
const templatePoints = [startPoint, points[points.length - 1]];
|
10
|
+
return { points: templatePoints };
|
14
11
|
};
|
15
12
|
const makeRectangleTemplate = (_startPoint, _points, bbox) => {
|
16
|
-
return { points: [...bbox.corners, bbox.corners[0]]
|
13
|
+
return { points: [...bbox.corners, bbox.corners[0]] };
|
17
14
|
};
|
18
15
|
class ShapeFitBuilder {
|
19
16
|
constructor(sourceFactory, startPoint, viewport) {
|
@@ -39,10 +36,10 @@ class ShapeFitBuilder {
|
|
39
36
|
async autocorrectShape() {
|
40
37
|
// Use screen points so that autocorrected shapes rotate with the screen.
|
41
38
|
const startPoint = this.viewport.canvasToScreen(this.startPoint.pos);
|
42
|
-
const points = this.points.map(point => this.viewport.canvasToScreen(point.pos));
|
39
|
+
const points = this.points.map((point) => this.viewport.canvasToScreen(point.pos));
|
43
40
|
const bbox = Rect2.bboxOf(points);
|
44
41
|
const snappedStartPoint = this.viewport.canvasToScreen(this.viewport.snapToGrid(this.startPoint.pos));
|
45
|
-
const snappedPoints = this.points.map(point => this.viewport.canvasToScreen(this.viewport.snapToGrid(point.pos)));
|
42
|
+
const snappedPoints = this.points.map((point) => this.viewport.canvasToScreen(this.viewport.snapToGrid(point.pos)));
|
46
43
|
const snappedBBox = Rect2.bboxOf(snappedPoints);
|
47
44
|
// Only fit larger shapes
|
48
45
|
if (bbox.maxDimension < 32) {
|
@@ -35,7 +35,7 @@ class SnapToGridAutocompleteBuilder {
|
|
35
35
|
// Use screen points so that snapped shapes rotate with the screen.
|
36
36
|
const startPoint = snapToGrid(this.startPoint);
|
37
37
|
const builder = this.sourceFactory(startPoint, this.viewport);
|
38
|
-
const points = this.points.map(point => snapToGrid(point));
|
38
|
+
const points = this.points.map((point) => snapToGrid(point));
|
39
39
|
for (const point of points) {
|
40
40
|
builder.addPoint(point);
|
41
41
|
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export { makeFreehandLineBuilder } from './FreehandLineBuilder';
|
2
|
+
export { makePolylineBuilder } from './PolylineBuilder';
|
3
|
+
export { makePressureSensitiveFreehandLineBuilder } from './PressureSensitiveFreehandLineBuilder';
|
4
|
+
export { makeOutlinedCircleBuilder } from './CircleBuilder';
|
5
|
+
export { makeArrowBuilder } from './ArrowBuilder';
|
6
|
+
export { makeLineBuilder } from './LineBuilder';
|
7
|
+
export { makeFilledRectangleBuilder, makeOutlinedRectangleBuilder } from './RectangleBuilder';
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export { makeFreehandLineBuilder } from './FreehandLineBuilder.mjs';
|
2
|
+
export { makePolylineBuilder } from './PolylineBuilder.mjs';
|
3
|
+
export { makePressureSensitiveFreehandLineBuilder } from './PressureSensitiveFreehandLineBuilder.mjs';
|
4
|
+
export { makeOutlinedCircleBuilder } from './CircleBuilder.mjs';
|
5
|
+
export { makeArrowBuilder } from './ArrowBuilder.mjs';
|
6
|
+
export { makeLineBuilder } from './LineBuilder.mjs';
|
7
|
+
export { makeFilledRectangleBuilder, makeOutlinedRectangleBuilder } from './RectangleBuilder.mjs';
|
@@ -1,8 +1,5 @@
|
|
1
1
|
export * from './builders/types';
|
2
|
-
export
|
3
|
-
export { makePolylineBuilder } from './builders/PolylineBuilder';
|
4
|
-
export { makePressureSensitiveFreehandLineBuilder } from './builders/PressureSensitiveFreehandLineBuilder';
|
5
|
-
export { makeOutlinedCircleBuilder } from './builders/CircleBuilder';
|
2
|
+
export * from './builders/lib';
|
6
3
|
export { default as StrokeSmoother, Curve as StrokeSmootherCurve } from './util/StrokeSmoother';
|
7
4
|
export * from './AbstractComponent';
|
8
5
|
export { default as AbstractComponent } from './AbstractComponent';
|
@@ -1,15 +1,12 @@
|
|
1
1
|
export * from './builders/types.mjs';
|
2
|
-
export
|
3
|
-
export { makePolylineBuilder } from './builders/PolylineBuilder.mjs';
|
4
|
-
export { makePressureSensitiveFreehandLineBuilder } from './builders/PressureSensitiveFreehandLineBuilder.mjs';
|
5
|
-
export { makeOutlinedCircleBuilder } from './builders/CircleBuilder.mjs';
|
2
|
+
export * from './builders/lib.mjs';
|
6
3
|
export { default as StrokeSmoother } from './util/StrokeSmoother.mjs';
|
7
4
|
export * from './AbstractComponent.mjs';
|
8
5
|
export { default as AbstractComponent } from './AbstractComponent.mjs';
|
9
6
|
import Stroke from './Stroke.mjs';
|
10
7
|
import TextComponent from './TextComponent.mjs';
|
11
8
|
import ImageComponent from './ImageComponent.mjs';
|
12
|
-
import { createRestyleComponentCommand, isRestylableComponent } from './RestylableComponent.mjs';
|
9
|
+
import { createRestyleComponentCommand, isRestylableComponent, } from './RestylableComponent.mjs';
|
13
10
|
import BackgroundComponent, { BackgroundType } from './BackgroundComponent.mjs';
|
14
11
|
export { Stroke, createRestyleComponentCommand, isRestylableComponent, TextComponent,
|
15
12
|
/** @deprecated use {@link TextComponent} */
|
@@ -53,9 +53,7 @@ export class StrokeSmoother {
|
|
53
53
|
console.assert(this.lastExitingVec.magnitude() !== 0, 'lastExitingVec has zero length!');
|
54
54
|
// Use the last two points to start a new curve (the last point isn't used
|
55
55
|
// in the current curve and we want connected curves to share end points)
|
56
|
-
this.buffer = [
|
57
|
-
this.buffer[this.buffer.length - 2], lastPoint,
|
58
|
-
];
|
56
|
+
this.buffer = [this.buffer[this.buffer.length - 2], lastPoint];
|
59
57
|
this.currentCurve = null;
|
60
58
|
this.isFirstSegment = false;
|
61
59
|
}
|
@@ -96,8 +94,7 @@ export class StrokeSmoother {
|
|
96
94
|
return;
|
97
95
|
}
|
98
96
|
const threshold = Math.min(this.lastPoint.width, newPoint.width) / 3;
|
99
|
-
const shouldSnapToInitial = this.startPoint.pos.distanceTo(newPoint.pos) < threshold
|
100
|
-
&& this.isFirstSegment;
|
97
|
+
const shouldSnapToInitial = this.startPoint.pos.distanceTo(newPoint.pos) < threshold && this.isFirstSegment;
|
101
98
|
// Snap to the starting point if the stroke is contained within a small ball centered
|
102
99
|
// at the starting point.
|
103
100
|
// This allows us to create a circle/dot at the start of the stroke.
|
@@ -150,7 +147,9 @@ export class StrokeSmoother {
|
|
150
147
|
const startEndDist = segmentEnd.distanceTo(segmentStart);
|
151
148
|
const maxControlPointDist = maxRelativeLength * startEndDist;
|
152
149
|
// Exit in cases where we would divide by zero
|
153
|
-
if (maxControlPointDist === 0 ||
|
150
|
+
if (maxControlPointDist === 0 ||
|
151
|
+
exitingVec.magnitude() === 0 ||
|
152
|
+
!isFinite(exitingVec.magnitude())) {
|
154
153
|
return;
|
155
154
|
}
|
156
155
|
console.assert(isFinite(enteringVec.magnitude()), 'Pre-normalized enteringVec has NaN or ∞ magnitude!');
|
@@ -8,7 +8,7 @@ const makeAboutDialog = (editor, entries) => {
|
|
8
8
|
const container = document.createElement(entry.minimized ? 'details' : 'div');
|
9
9
|
container.classList.add('about-entry');
|
10
10
|
const header = document.createElement(entry.minimized ? 'summary' : 'h2');
|
11
|
-
if (typeof
|
11
|
+
if (typeof entry.heading === 'string') {
|
12
12
|
header.innerText = entry.heading;
|
13
13
|
}
|
14
14
|
else {
|
@@ -15,7 +15,7 @@ const makeAboutDialog = (editor, options) => {
|
|
15
15
|
const scrollRegion = document.createElement('div');
|
16
16
|
scrollRegion.classList.add('scroll');
|
17
17
|
// Allow scrolling in the scrollable container -- don't forward wheel events.
|
18
|
-
scrollRegion.onwheel = evt => evt.stopPropagation();
|
18
|
+
scrollRegion.onwheel = (evt) => evt.stopPropagation();
|
19
19
|
contentWrapper.replaceChildren(heading, scrollRegion, closeButton);
|
20
20
|
dialog.replaceChildren(contentWrapper);
|
21
21
|
overlay.replaceChildren(dialog);
|
@@ -27,7 +27,7 @@ const makeAboutDialog = (editor, options) => {
|
|
27
27
|
dialog.close();
|
28
28
|
};
|
29
29
|
const addCloseListeners = () => {
|
30
|
-
dialog.addEventListener('pointerdown', event => {
|
30
|
+
dialog.addEventListener('pointerdown', (event) => {
|
31
31
|
if (event.target === dialog) {
|
32
32
|
void closeDialog();
|
33
33
|
}
|