js-draw 0.25.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -20
- package/build-config.json +22 -21
- package/dist/Editor.css +1281 -0
- package/dist/bundle.js +3 -3
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.d.ts +91 -12
- package/dist/cjs/Editor.js +619 -590
- package/dist/cjs/EditorImage.d.ts +5 -2
- package/dist/cjs/EditorImage.js +258 -297
- package/dist/cjs/EventDispatcher.js +17 -19
- package/dist/cjs/Pointer.d.ts +3 -1
- package/dist/cjs/Pointer.js +41 -44
- package/dist/cjs/SVGLoader.d.ts +7 -1
- package/dist/cjs/SVGLoader.js +373 -474
- package/dist/cjs/UndoRedoHistory.js +28 -40
- package/dist/cjs/Viewport.d.ts +1 -4
- package/dist/cjs/Viewport.js +150 -193
- package/dist/cjs/bundle/bundled.js +4 -1
- package/dist/cjs/commands/Command.js +22 -49
- package/dist/cjs/commands/Duplicate.js +28 -44
- package/dist/cjs/commands/Erase.js +36 -54
- package/dist/cjs/commands/SerializableCommand.js +20 -35
- package/dist/cjs/commands/UnresolvedCommand.js +14 -29
- package/dist/cjs/commands/invertCommand.js +29 -51
- package/dist/cjs/commands/lib.js +9 -6
- package/dist/cjs/commands/localization.d.ts +1 -1
- package/dist/cjs/commands/localization.js +9 -9
- package/dist/cjs/commands/uniteCommands.js +57 -87
- package/dist/cjs/components/AbstractComponent.d.ts +11 -3
- package/dist/cjs/components/AbstractComponent.js +141 -169
- package/dist/cjs/components/BackgroundComponent.d.ts +3 -6
- package/dist/cjs/components/BackgroundComponent.js +124 -149
- package/dist/cjs/components/ImageComponent.d.ts +3 -5
- package/dist/cjs/components/ImageComponent.js +95 -175
- package/dist/cjs/components/RestylableComponent.d.ts +1 -1
- package/dist/cjs/components/RestylableComponent.js +41 -56
- package/dist/cjs/components/SVGGlobalAttributesObject.d.ts +1 -3
- package/dist/cjs/components/SVGGlobalAttributesObject.js +34 -51
- package/dist/cjs/components/Stroke.d.ts +4 -6
- package/dist/cjs/components/Stroke.js +95 -121
- package/dist/cjs/components/TextComponent.d.ts +2 -4
- package/dist/cjs/components/TextComponent.js +189 -234
- package/dist/cjs/components/UnknownSVGObject.d.ts +1 -3
- package/dist/cjs/components/UnknownSVGObject.js +30 -43
- package/dist/cjs/components/builders/ArrowBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/ArrowBuilder.js +43 -42
- package/dist/cjs/components/builders/CircleBuilder.js +43 -43
- package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +3 -2
- package/dist/cjs/components/builders/FreehandLineBuilder.js +73 -86
- package/dist/cjs/components/builders/LineBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/LineBuilder.js +38 -36
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +131 -139
- package/dist/cjs/components/builders/RectangleBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/RectangleBuilder.js +31 -31
- package/dist/cjs/components/builders/types.d.ts +1 -1
- package/dist/cjs/components/lib.d.ts +3 -1
- package/dist/cjs/components/lib.js +10 -7
- package/dist/cjs/components/localization.js +4 -4
- package/dist/cjs/components/util/StrokeSmoother.d.ts +1 -2
- package/dist/cjs/components/util/StrokeSmoother.js +67 -72
- package/dist/cjs/components/util/describeComponentList.d.ts +1 -1
- package/dist/cjs/components/util/describeComponentList.js +4 -5
- package/dist/cjs/dialogs/makeAboutDialog.d.ts +15 -0
- package/dist/cjs/dialogs/makeAboutDialog.js +54 -0
- package/dist/cjs/inputEvents.d.ts +84 -0
- package/dist/cjs/inputEvents.js +40 -0
- package/dist/cjs/lib.d.ts +29 -13
- package/dist/cjs/lib.js +38 -23
- package/dist/cjs/localization.js +19 -18
- package/dist/cjs/localizations/de.js +117 -13
- package/dist/cjs/localizations/en.js +4 -13
- package/dist/cjs/localizations/es.js +62 -23
- package/dist/cjs/localizations/getLocalizationTable.js +15 -13
- package/dist/cjs/rendering/Display.d.ts +1 -2
- package/dist/cjs/rendering/Display.js +70 -83
- package/dist/cjs/rendering/RenderablePathSpec.d.ts +15 -0
- package/dist/cjs/rendering/RenderablePathSpec.js +70 -0
- package/dist/cjs/rendering/RenderingStyle.d.ts +4 -4
- package/dist/cjs/rendering/RenderingStyle.js +18 -28
- package/dist/cjs/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/cjs/rendering/TextRenderingStyle.js +13 -18
- package/dist/cjs/rendering/caching/CacheRecord.d.ts +1 -2
- package/dist/cjs/rendering/caching/CacheRecord.js +20 -22
- package/dist/cjs/rendering/caching/CacheRecordManager.d.ts +1 -1
- package/dist/cjs/rendering/caching/CacheRecordManager.js +17 -15
- package/dist/cjs/rendering/caching/RenderingCache.js +19 -19
- package/dist/cjs/rendering/caching/RenderingCacheNode.d.ts +1 -1
- package/dist/cjs/rendering/caching/RenderingCacheNode.js +98 -118
- package/dist/cjs/rendering/caching/testUtils.js +24 -23
- package/dist/cjs/rendering/caching/types.d.ts +3 -3
- package/dist/cjs/rendering/lib.js +8 -5
- package/dist/cjs/rendering/localization.js +5 -5
- package/dist/cjs/rendering/renderers/AbstractRenderer.d.ts +2 -11
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +53 -57
- package/dist/cjs/rendering/renderers/CanvasRenderer.d.ts +3 -5
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +91 -106
- package/dist/cjs/rendering/renderers/DummyRenderer.d.ts +1 -4
- package/dist/cjs/rendering/renderers/DummyRenderer.js +56 -76
- package/dist/cjs/rendering/renderers/SVGRenderer.d.ts +5 -5
- package/dist/cjs/rendering/renderers/SVGRenderer.js +194 -176
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.d.ts +1 -3
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +47 -72
- package/dist/cjs/shortcuts/KeyBinding.d.ts +5 -0
- package/dist/cjs/shortcuts/KeyBinding.js +94 -70
- package/dist/cjs/shortcuts/KeyboardShortcutManager.d.ts +1 -1
- package/dist/cjs/shortcuts/KeyboardShortcutManager.js +36 -45
- package/dist/cjs/shortcuts/lib.js +5 -2
- package/dist/cjs/testing/createEditor.js +7 -4
- package/dist/cjs/testing/getUniquePointerId.js +4 -5
- package/dist/cjs/testing/lib.js +5 -2
- package/dist/cjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/cjs/testing/sendPenEvent.js +10 -7
- package/dist/cjs/testing/sendTouchEvent.d.ts +2 -2
- package/dist/cjs/testing/sendTouchEvent.js +34 -16
- package/dist/cjs/toolbar/AbstractToolbar.d.ts +166 -0
- package/dist/cjs/toolbar/AbstractToolbar.js +410 -0
- package/dist/cjs/toolbar/DropdownToolbar.d.ts +43 -0
- package/dist/cjs/toolbar/DropdownToolbar.js +176 -0
- package/dist/cjs/toolbar/EdgeToolbar.d.ts +47 -0
- package/dist/cjs/toolbar/EdgeToolbar.js +422 -0
- package/dist/cjs/toolbar/IconProvider.d.ts +54 -30
- package/dist/cjs/toolbar/IconProvider.js +652 -224
- package/dist/cjs/toolbar/constants.d.ts +1 -0
- package/dist/cjs/toolbar/constants.js +4 -0
- package/dist/cjs/toolbar/lib.d.ts +4 -2
- package/dist/cjs/toolbar/lib.js +10 -3
- package/dist/cjs/toolbar/localization.d.ts +9 -2
- package/dist/cjs/toolbar/localization.js +26 -19
- package/dist/cjs/toolbar/types.d.ts +7 -0
- package/dist/cjs/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/ActionButtonWidget.js +23 -39
- package/dist/cjs/toolbar/widgets/BaseToolWidget.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/BaseToolWidget.js +35 -37
- package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +60 -5
- package/dist/cjs/toolbar/widgets/BaseWidget.js +232 -177
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +130 -117
- package/dist/cjs/toolbar/widgets/EraserToolWidget.d.ts +1 -3
- package/dist/cjs/toolbar/widgets/EraserToolWidget.js +45 -73
- package/dist/cjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +126 -141
- package/dist/cjs/toolbar/widgets/InsertImageWidget.d.ts +9 -7
- package/dist/cjs/toolbar/widgets/InsertImageWidget.js +147 -212
- package/dist/cjs/toolbar/widgets/OverflowWidget.js +33 -61
- package/dist/cjs/toolbar/widgets/PenToolWidget.d.ts +8 -1
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +162 -234
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +105 -177
- package/dist/cjs/toolbar/widgets/TextToolWidget.js +64 -87
- package/dist/cjs/toolbar/widgets/components/makeColorInput.d.ts +10 -0
- package/dist/cjs/toolbar/{makeColorInput.js → widgets/components/makeColorInput.js} +57 -34
- package/dist/cjs/toolbar/widgets/components/makeFileInput.d.ts +12 -0
- package/dist/cjs/toolbar/widgets/components/makeFileInput.js +111 -0
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.d.ts +24 -0
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +127 -0
- package/dist/cjs/toolbar/widgets/components/makeSeparator.d.ts +7 -0
- package/dist/cjs/toolbar/widgets/components/makeSeparator.js +16 -0
- package/dist/cjs/toolbar/widgets/components/makeThicknessSlider.d.ts +8 -0
- package/dist/cjs/toolbar/widgets/components/makeThicknessSlider.js +47 -0
- package/dist/cjs/toolbar/widgets/keybindings.js +8 -5
- package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.d.ts +21 -0
- package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.js +199 -0
- package/dist/cjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.d.ts +14 -0
- package/dist/cjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.js +60 -0
- package/dist/cjs/toolbar/widgets/layout/types.d.ts +63 -0
- package/dist/cjs/toolbar/widgets/layout/types.js +2 -0
- package/dist/cjs/toolbar/widgets/lib.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/lib.js +15 -11
- package/dist/cjs/tools/BaseTool.d.ts +28 -9
- package/dist/cjs/tools/BaseTool.js +128 -51
- package/dist/cjs/tools/Eraser.d.ts +8 -1
- package/dist/cjs/tools/Eraser.js +82 -92
- package/dist/cjs/tools/FindTool.d.ts +1 -1
- package/dist/cjs/tools/FindTool.js +61 -77
- 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/InputStabilizer.d.ts +29 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +181 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +84 -0
- package/dist/cjs/tools/PanZoom.d.ts +4 -2
- package/dist/cjs/tools/PanZoom.js +186 -248
- package/dist/cjs/tools/PasteHandler.d.ts +1 -1
- package/dist/cjs/tools/PasteHandler.js +49 -148
- package/dist/cjs/tools/Pen.d.ts +12 -11
- package/dist/cjs/tools/Pen.js +123 -158
- package/dist/cjs/tools/PipetteTool.d.ts +11 -2
- package/dist/cjs/tools/PipetteTool.js +51 -48
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +1 -1
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +15 -30
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +5 -5
- package/dist/cjs/tools/SelectionTool/Selection.js +308 -415
- package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +15 -5
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +63 -37
- package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +4 -4
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +164 -187
- package/dist/cjs/tools/SelectionTool/TransformMode.d.ts +1 -1
- package/dist/cjs/tools/SelectionTool/TransformMode.js +65 -66
- package/dist/cjs/tools/SoundUITool.d.ts +2 -1
- package/dist/cjs/tools/SoundUITool.js +70 -84
- package/dist/cjs/tools/TextTool.d.ts +5 -3
- package/dist/cjs/tools/TextTool.js +169 -173
- package/dist/cjs/tools/ToolController.d.ts +16 -2
- package/dist/cjs/tools/ToolController.js +124 -100
- package/dist/cjs/tools/ToolEnabledGroup.js +6 -9
- package/dist/cjs/tools/ToolSwitcherShortcut.d.ts +1 -1
- package/dist/cjs/tools/ToolSwitcherShortcut.js +16 -32
- package/dist/cjs/tools/ToolbarShortcutHandler.d.ts +1 -1
- package/dist/cjs/tools/ToolbarShortcutHandler.js +17 -33
- package/dist/cjs/tools/UndoRedoShortcut.d.ts +1 -1
- package/dist/cjs/tools/UndoRedoShortcut.js +12 -27
- package/dist/cjs/tools/keybindings.js +21 -18
- package/dist/cjs/tools/lib.js +17 -14
- package/dist/cjs/tools/localization.d.ts +2 -1
- package/dist/cjs/tools/localization.js +8 -7
- package/dist/cjs/types.d.ts +22 -80
- package/dist/cjs/types.js +8 -16
- package/dist/cjs/util/ReactiveValue.d.ts +65 -0
- package/dist/cjs/util/ReactiveValue.js +166 -0
- package/dist/cjs/util/assertions.js +5 -8
- package/dist/cjs/util/fileToBase64.js +6 -6
- package/dist/cjs/util/guessKeyCodeFromKey.d.ts +9 -0
- package/dist/cjs/util/guessKeyCodeFromKey.js +32 -0
- package/dist/cjs/util/listPrefixMatch.d.ts +6 -0
- package/dist/cjs/util/listPrefixMatch.js +17 -0
- package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.d.ts +2 -0
- package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.js +17 -0
- package/dist/cjs/util/untilNextAnimationFrame.js +3 -3
- package/dist/cjs/util/waitForAll.js +3 -3
- package/dist/cjs/util/waitForTimeout.js +3 -3
- package/dist/cjs/version.d.ts +4 -0
- package/dist/cjs/version.js +5 -0
- package/dist/mjs/Editor.d.ts +91 -12
- package/dist/mjs/Editor.mjs +565 -563
- package/dist/mjs/EditorImage.d.ts +5 -2
- package/dist/mjs/EditorImage.mjs +248 -291
- package/dist/mjs/EventDispatcher.mjs +17 -20
- package/dist/mjs/Pointer.d.ts +3 -1
- package/dist/mjs/Pointer.mjs +40 -44
- package/dist/mjs/SVGLoader.d.ts +7 -1
- package/dist/mjs/SVGLoader.mjs +338 -466
- package/dist/mjs/UndoRedoHistory.mjs +27 -39
- package/dist/mjs/Viewport.d.ts +1 -4
- package/dist/mjs/Viewport.mjs +139 -187
- package/dist/mjs/commands/Command.mjs +21 -49
- package/dist/mjs/commands/Duplicate.mjs +22 -41
- package/dist/mjs/commands/Erase.mjs +30 -51
- package/dist/mjs/commands/SerializableCommand.mjs +16 -34
- package/dist/mjs/commands/UnresolvedCommand.mjs +10 -29
- package/dist/mjs/commands/invertCommand.mjs +24 -49
- package/dist/mjs/commands/localization.d.ts +1 -1
- package/dist/mjs/commands/localization.mjs +10 -10
- package/dist/mjs/commands/uniteCommands.mjs +52 -85
- package/dist/mjs/components/AbstractComponent.d.ts +11 -3
- package/dist/mjs/components/AbstractComponent.mjs +135 -166
- package/dist/mjs/components/BackgroundComponent.d.ts +3 -6
- package/dist/mjs/components/BackgroundComponent.mjs +107 -136
- package/dist/mjs/components/ImageComponent.d.ts +3 -5
- package/dist/mjs/components/ImageComponent.mjs +90 -174
- package/dist/mjs/components/RestylableComponent.d.ts +1 -1
- package/dist/mjs/components/RestylableComponent.mjs +35 -53
- package/dist/mjs/components/SVGGlobalAttributesObject.d.ts +1 -3
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +29 -50
- package/dist/mjs/components/Stroke.d.ts +4 -6
- package/dist/mjs/components/Stroke.mjs +89 -119
- package/dist/mjs/components/TextComponent.d.ts +2 -4
- package/dist/mjs/components/TextComponent.mjs +180 -228
- package/dist/mjs/components/UnknownSVGObject.d.ts +1 -3
- package/dist/mjs/components/UnknownSVGObject.mjs +26 -43
- package/dist/mjs/components/builders/ArrowBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/ArrowBuilder.mjs +32 -35
- package/dist/mjs/components/builders/CircleBuilder.mjs +35 -38
- package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +3 -2
- package/dist/mjs/components/builders/FreehandLineBuilder.mjs +52 -69
- package/dist/mjs/components/builders/LineBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/LineBuilder.mjs +30 -32
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +103 -115
- package/dist/mjs/components/builders/RectangleBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/RectangleBuilder.mjs +27 -31
- package/dist/mjs/components/builders/types.d.ts +1 -1
- package/dist/mjs/components/lib.d.ts +3 -1
- package/dist/mjs/components/lib.mjs +1 -1
- package/dist/mjs/components/localization.mjs +5 -5
- package/dist/mjs/components/util/StrokeSmoother.d.ts +1 -2
- package/dist/mjs/components/util/StrokeSmoother.mjs +63 -69
- package/dist/mjs/components/util/describeComponentList.d.ts +1 -1
- package/dist/mjs/components/util/describeComponentList.mjs +4 -5
- package/dist/mjs/dialogs/makeAboutDialog.d.ts +15 -0
- package/dist/mjs/dialogs/makeAboutDialog.mjs +52 -0
- package/dist/mjs/inputEvents.d.ts +84 -0
- package/dist/mjs/inputEvents.mjs +34 -0
- package/dist/mjs/lib.d.ts +29 -13
- package/dist/mjs/lib.mjs +30 -13
- package/dist/mjs/localization.mjs +14 -13
- package/dist/mjs/localizations/de.mjs +116 -12
- package/dist/mjs/localizations/en.mjs +3 -12
- package/dist/mjs/localizations/es.mjs +61 -22
- package/dist/mjs/localizations/getLocalizationTable.mjs +12 -13
- package/dist/mjs/rendering/Display.d.ts +1 -2
- package/dist/mjs/rendering/Display.mjs +62 -79
- package/dist/mjs/rendering/RenderablePathSpec.d.ts +15 -0
- package/dist/mjs/rendering/RenderablePathSpec.mjs +64 -0
- package/dist/mjs/rendering/RenderingStyle.d.ts +4 -4
- package/dist/mjs/rendering/RenderingStyle.mjs +16 -26
- package/dist/mjs/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/mjs/rendering/TextRenderingStyle.mjs +12 -17
- package/dist/mjs/rendering/caching/CacheRecord.d.ts +1 -2
- package/dist/mjs/rendering/caching/CacheRecord.mjs +20 -23
- package/dist/mjs/rendering/caching/CacheRecordManager.d.ts +1 -1
- package/dist/mjs/rendering/caching/CacheRecordManager.mjs +13 -15
- package/dist/mjs/rendering/caching/RenderingCache.mjs +13 -17
- package/dist/mjs/rendering/caching/RenderingCacheNode.d.ts +1 -1
- package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +94 -115
- package/dist/mjs/rendering/caching/testUtils.mjs +19 -21
- package/dist/mjs/rendering/caching/types.d.ts +3 -3
- package/dist/mjs/rendering/localization.mjs +6 -6
- package/dist/mjs/rendering/renderers/AbstractRenderer.d.ts +2 -11
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +47 -52
- package/dist/mjs/rendering/renderers/CanvasRenderer.d.ts +3 -5
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +84 -103
- package/dist/mjs/rendering/renderers/DummyRenderer.d.ts +1 -4
- package/dist/mjs/rendering/renderers/DummyRenderer.mjs +51 -75
- package/dist/mjs/rendering/renderers/SVGRenderer.d.ts +5 -5
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +185 -171
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.d.ts +1 -3
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +43 -72
- package/dist/mjs/shortcuts/KeyBinding.d.ts +5 -0
- package/dist/mjs/shortcuts/KeyBinding.mjs +94 -71
- package/dist/mjs/shortcuts/KeyboardShortcutManager.d.ts +1 -1
- package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +32 -44
- package/dist/mjs/testing/createEditor.mjs +2 -2
- package/dist/mjs/testing/getUniquePointerId.mjs +4 -5
- package/dist/mjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/mjs/testing/sendPenEvent.mjs +5 -5
- package/dist/mjs/testing/sendTouchEvent.d.ts +2 -2
- package/dist/mjs/testing/sendTouchEvent.mjs +8 -16
- package/dist/mjs/toolbar/AbstractToolbar.d.ts +166 -0
- package/dist/mjs/toolbar/AbstractToolbar.mjs +405 -0
- package/dist/mjs/toolbar/DropdownToolbar.d.ts +43 -0
- package/dist/mjs/toolbar/DropdownToolbar.mjs +168 -0
- package/dist/mjs/toolbar/EdgeToolbar.d.ts +47 -0
- package/dist/mjs/toolbar/EdgeToolbar.mjs +414 -0
- package/dist/mjs/toolbar/IconProvider.d.ts +54 -30
- package/dist/mjs/toolbar/IconProvider.mjs +644 -219
- package/dist/mjs/toolbar/constants.d.ts +1 -0
- package/dist/mjs/toolbar/constants.mjs +1 -0
- package/dist/mjs/toolbar/lib.d.ts +4 -2
- package/dist/mjs/toolbar/lib.mjs +3 -1
- package/dist/mjs/toolbar/localization.d.ts +9 -2
- package/dist/mjs/toolbar/localization.mjs +27 -20
- package/dist/mjs/toolbar/types.d.ts +7 -0
- package/dist/mjs/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/ActionButtonWidget.mjs +19 -39
- package/dist/mjs/toolbar/widgets/BaseToolWidget.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +30 -36
- package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +60 -5
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +227 -176
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +98 -111
- package/dist/mjs/toolbar/widgets/EraserToolWidget.d.ts +1 -3
- package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +41 -73
- package/dist/mjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +94 -136
- package/dist/mjs/toolbar/widgets/InsertImageWidget.d.ts +9 -7
- package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +140 -208
- package/dist/mjs/toolbar/widgets/OverflowWidget.mjs +30 -62
- package/dist/mjs/toolbar/widgets/PenToolWidget.d.ts +8 -1
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +150 -225
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +97 -173
- package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +59 -85
- package/dist/mjs/toolbar/widgets/components/makeColorInput.d.ts +10 -0
- package/dist/mjs/toolbar/{makeColorInput.mjs → widgets/components/makeColorInput.mjs} +53 -33
- package/dist/mjs/toolbar/widgets/components/makeFileInput.d.ts +12 -0
- package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +106 -0
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.d.ts +24 -0
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +122 -0
- package/dist/mjs/toolbar/widgets/components/makeSeparator.d.ts +7 -0
- package/dist/mjs/toolbar/widgets/components/makeSeparator.mjs +14 -0
- package/dist/mjs/toolbar/widgets/components/makeThicknessSlider.d.ts +8 -0
- package/dist/mjs/toolbar/widgets/components/makeThicknessSlider.mjs +45 -0
- package/dist/mjs/toolbar/widgets/keybindings.mjs +5 -5
- package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.d.ts +21 -0
- package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.mjs +193 -0
- package/dist/mjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.d.ts +14 -0
- package/dist/mjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.mjs +57 -0
- package/dist/mjs/toolbar/widgets/layout/types.d.ts +63 -0
- package/dist/mjs/toolbar/widgets/lib.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/lib.mjs +1 -1
- package/dist/mjs/tools/BaseTool.d.ts +28 -9
- package/dist/mjs/tools/BaseTool.mjs +127 -50
- package/dist/mjs/tools/Eraser.d.ts +8 -1
- package/dist/mjs/tools/Eraser.mjs +72 -86
- package/dist/mjs/tools/FindTool.d.ts +1 -1
- package/dist/mjs/tools/FindTool.mjs +55 -75
- 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/InputStabilizer.d.ts +29 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +175 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +78 -0
- package/dist/mjs/tools/PanZoom.d.ts +4 -2
- package/dist/mjs/tools/PanZoom.mjs +169 -235
- package/dist/mjs/tools/PasteHandler.d.ts +1 -1
- package/dist/mjs/tools/PasteHandler.mjs +42 -145
- package/dist/mjs/tools/Pen.d.ts +12 -11
- package/dist/mjs/tools/Pen.mjs +115 -154
- package/dist/mjs/tools/PipetteTool.d.ts +11 -2
- package/dist/mjs/tools/PipetteTool.mjs +47 -48
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +1 -1
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +9 -28
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +5 -5
- package/dist/mjs/tools/SelectionTool/Selection.mjs +268 -401
- package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +15 -5
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +62 -37
- package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +4 -4
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +153 -179
- package/dist/mjs/tools/SelectionTool/TransformMode.d.ts +1 -1
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +52 -59
- package/dist/mjs/tools/SoundUITool.d.ts +2 -1
- package/dist/mjs/tools/SoundUITool.mjs +66 -84
- package/dist/mjs/tools/TextTool.d.ts +5 -3
- package/dist/mjs/tools/TextTool.mjs +155 -163
- package/dist/mjs/tools/ToolController.d.ts +16 -2
- package/dist/mjs/tools/ToolController.mjs +81 -84
- package/dist/mjs/tools/ToolEnabledGroup.mjs +6 -10
- package/dist/mjs/tools/ToolSwitcherShortcut.d.ts +1 -1
- package/dist/mjs/tools/ToolSwitcherShortcut.mjs +12 -32
- package/dist/mjs/tools/ToolbarShortcutHandler.d.ts +1 -1
- package/dist/mjs/tools/ToolbarShortcutHandler.mjs +13 -33
- package/dist/mjs/tools/UndoRedoShortcut.d.ts +1 -1
- package/dist/mjs/tools/UndoRedoShortcut.mjs +7 -26
- package/dist/mjs/tools/keybindings.mjs +34 -34
- package/dist/mjs/tools/localization.d.ts +2 -1
- package/dist/mjs/tools/localization.mjs +9 -8
- package/dist/mjs/types.d.ts +22 -80
- package/dist/mjs/types.mjs +7 -15
- package/dist/mjs/util/ReactiveValue.d.ts +65 -0
- package/dist/mjs/util/ReactiveValue.mjs +161 -0
- package/dist/mjs/util/assertions.mjs +5 -8
- package/dist/mjs/util/fileToBase64.mjs +6 -6
- package/dist/mjs/util/guessKeyCodeFromKey.d.ts +9 -0
- package/dist/mjs/util/guessKeyCodeFromKey.mjs +30 -0
- package/dist/mjs/util/listPrefixMatch.d.ts +6 -0
- package/dist/mjs/util/listPrefixMatch.mjs +15 -0
- package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.d.ts +2 -0
- package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.mjs +15 -0
- package/dist/mjs/util/untilNextAnimationFrame.mjs +3 -3
- package/dist/mjs/util/waitForAll.mjs +3 -3
- package/dist/mjs/util/waitForTimeout.mjs +3 -3
- package/dist/mjs/version.d.ts +4 -0
- package/dist/mjs/version.mjs +3 -0
- package/package.json +11 -22
- package/src/Coloris.css +8 -8
- package/src/Editor.scss +148 -0
- package/src/dialogs/dialogs.scss +36 -0
- package/src/dialogs/makeAboutDialog.scss +41 -0
- package/src/styles.js +1 -1
- package/src/toolbar/{toolbar.css → AbstractToolbar.scss} +47 -85
- package/src/toolbar/DropdownToolbar.scss +46 -0
- package/src/toolbar/EdgeToolbar.scss +511 -0
- package/src/toolbar/toolbar.scss +11 -0
- package/src/toolbar/widgets/DocumentPropertiesWidget.scss +7 -0
- package/src/toolbar/widgets/HandToolWidget.scss +14 -0
- package/src/toolbar/widgets/InsertImageWidget.scss +41 -0
- package/src/toolbar/widgets/PenToolWidget.css +0 -51
- package/src/toolbar/widgets/SelectionToolWidget.scss +6 -0
- package/src/toolbar/widgets/components/components.scss +5 -0
- package/src/toolbar/widgets/components/makeColorInput.scss +82 -0
- package/src/toolbar/widgets/components/makeFileInput.scss +77 -0
- package/src/toolbar/widgets/components/makeGridSelector.scss +60 -0
- package/src/toolbar/widgets/components/makeSeparator.scss +14 -0
- package/src/toolbar/widgets/components/makeThicknessSlider.scss +9 -0
- package/src/tools/FindTool.css +3 -3
- package/src/tools/SelectionTool/SelectionTool.css +23 -11
- package/src/tools/tools.scss +4 -0
- package/tsconfig.json +1 -1
- package/typedoc.json +4 -0
- package/dist/cjs/Color4.d.ts +0 -69
- package/dist/cjs/Color4.js +0 -263
- package/dist/cjs/Editor.loadFrom.test.d.ts +0 -1
- package/dist/cjs/Editor.toSVG.test.d.ts +0 -1
- package/dist/cjs/EditorImage.test.d.ts +0 -1
- package/dist/cjs/EventDispatcher.test.d.ts +0 -1
- package/dist/cjs/SVGLoader.test.d.ts +0 -1
- package/dist/cjs/UndoRedoHistory.test.d.ts +0 -1
- package/dist/cjs/commands/uniteCommands.test.d.ts +0 -1
- package/dist/cjs/components/AbstractComponent.transformBy.test.d.ts +0 -1
- package/dist/cjs/components/BackgroundComponent.test.d.ts +0 -1
- package/dist/cjs/components/Stroke.test.d.ts +0 -1
- package/dist/cjs/components/TextComponent.test.d.ts +0 -1
- package/dist/cjs/components/UnknownSVGObject.test.d.ts +0 -1
- package/dist/cjs/components/builders/FreehandLineBuilder.test.d.ts +0 -1
- package/dist/cjs/localizations/getLocalizationTable.test.d.ts +0 -1
- package/dist/cjs/math/Mat33.d.ts +0 -123
- package/dist/cjs/math/Mat33.js +0 -340
- package/dist/cjs/math/Mat33.test.d.ts +0 -1
- package/dist/cjs/math/Vec2.d.ts +0 -33
- package/dist/cjs/math/Vec2.js +0 -37
- package/dist/cjs/math/Vec2.test.d.ts +0 -1
- package/dist/cjs/math/Vec3.d.ts +0 -106
- package/dist/cjs/math/Vec3.js +0 -183
- package/dist/cjs/math/Vec3.test.d.ts +0 -1
- package/dist/cjs/math/lib.d.ts +0 -7
- package/dist/cjs/math/lib.js +0 -15
- package/dist/cjs/math/polynomial/solveQuadratic.d.ts +0 -9
- package/dist/cjs/math/polynomial/solveQuadratic.js +0 -39
- package/dist/cjs/math/polynomial/solveQuadratic.test.d.ts +0 -1
- package/dist/cjs/math/rounding.d.ts +0 -4
- package/dist/cjs/math/rounding.js +0 -140
- package/dist/cjs/math/rounding.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Abstract2DShape.d.ts +0 -49
- package/dist/cjs/math/shapes/Abstract2DShape.js +0 -42
- package/dist/cjs/math/shapes/BezierJSWrapper.d.ts +0 -36
- package/dist/cjs/math/shapes/BezierJSWrapper.js +0 -109
- package/dist/cjs/math/shapes/CubicBezier.d.ts +0 -17
- package/dist/cjs/math/shapes/CubicBezier.js +0 -50
- package/dist/cjs/math/shapes/LineSegment2.d.ts +0 -70
- package/dist/cjs/math/shapes/LineSegment2.js +0 -204
- package/dist/cjs/math/shapes/LineSegment2.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Path.d.ts +0 -93
- package/dist/cjs/math/shapes/Path.fromString.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Path.js +0 -865
- package/dist/cjs/math/shapes/Path.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Path.toString.test.d.ts +0 -1
- package/dist/cjs/math/shapes/PointShape2D.d.ts +0 -18
- package/dist/cjs/math/shapes/PointShape2D.js +0 -46
- package/dist/cjs/math/shapes/QuadraticBezier.d.ts +0 -34
- package/dist/cjs/math/shapes/QuadraticBezier.js +0 -133
- package/dist/cjs/math/shapes/QuadraticBezier.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Rect2.d.ts +0 -57
- package/dist/cjs/math/shapes/Rect2.js +0 -311
- package/dist/cjs/math/shapes/Rect2.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Triangle.d.ts +0 -46
- package/dist/cjs/math/shapes/Triangle.js +0 -148
- package/dist/cjs/math/shapes/Triangle.test.d.ts +0 -1
- package/dist/cjs/rendering/RenderingStyle.test.d.ts +0 -1
- package/dist/cjs/rendering/caching/CacheRecord.test.d.ts +0 -1
- package/dist/cjs/rendering/caching/RenderingCache.test.d.ts +0 -1
- package/dist/cjs/rendering/renderers/DummyRenderer.test.d.ts +0 -1
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.test.d.ts +0 -1
- package/dist/cjs/shortcuts/KeyBinding.test.d.ts +0 -1
- package/dist/cjs/shortcuts/KeyboardShortcutManager.test.d.ts +0 -1
- package/dist/cjs/toolbar/HTMLToolbar.d.ts +0 -105
- package/dist/cjs/toolbar/HTMLToolbar.js +0 -465
- package/dist/cjs/toolbar/makeColorInput.d.ts +0 -6
- package/dist/cjs/tools/Eraser.test.d.ts +0 -1
- package/dist/cjs/tools/PanZoom.test.d.ts +0 -1
- package/dist/cjs/tools/Pen.test.d.ts +0 -1
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +0 -1
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +0 -1
- package/dist/mjs/Color4.d.ts +0 -69
- package/dist/mjs/Color4.mjs +0 -260
- package/dist/mjs/Color4.test.d.ts +0 -1
- package/dist/mjs/Editor.loadFrom.test.d.ts +0 -1
- package/dist/mjs/Editor.toSVG.test.d.ts +0 -1
- package/dist/mjs/EditorImage.test.d.ts +0 -1
- package/dist/mjs/EventDispatcher.test.d.ts +0 -1
- package/dist/mjs/SVGLoader.test.d.ts +0 -1
- package/dist/mjs/UndoRedoHistory.test.d.ts +0 -1
- package/dist/mjs/commands/uniteCommands.test.d.ts +0 -1
- package/dist/mjs/components/AbstractComponent.transformBy.test.d.ts +0 -1
- package/dist/mjs/components/BackgroundComponent.test.d.ts +0 -1
- package/dist/mjs/components/Stroke.test.d.ts +0 -1
- package/dist/mjs/components/TextComponent.test.d.ts +0 -1
- package/dist/mjs/components/UnknownSVGObject.test.d.ts +0 -1
- package/dist/mjs/components/builders/FreehandLineBuilder.test.d.ts +0 -1
- package/dist/mjs/localizations/getLocalizationTable.test.d.ts +0 -1
- package/dist/mjs/math/Mat33.d.ts +0 -123
- package/dist/mjs/math/Mat33.mjs +0 -338
- package/dist/mjs/math/Mat33.test.d.ts +0 -1
- package/dist/mjs/math/Vec2.d.ts +0 -33
- package/dist/mjs/math/Vec2.mjs +0 -34
- package/dist/mjs/math/Vec2.test.d.ts +0 -1
- package/dist/mjs/math/Vec3.d.ts +0 -106
- package/dist/mjs/math/Vec3.mjs +0 -181
- package/dist/mjs/math/Vec3.test.d.ts +0 -1
- package/dist/mjs/math/lib.d.ts +0 -7
- package/dist/mjs/math/lib.mjs +0 -7
- package/dist/mjs/math/polynomial/solveQuadratic.d.ts +0 -9
- package/dist/mjs/math/polynomial/solveQuadratic.mjs +0 -37
- package/dist/mjs/math/polynomial/solveQuadratic.test.d.ts +0 -1
- package/dist/mjs/math/rounding.d.ts +0 -4
- package/dist/mjs/math/rounding.mjs +0 -133
- package/dist/mjs/math/rounding.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Abstract2DShape.d.ts +0 -49
- package/dist/mjs/math/shapes/Abstract2DShape.mjs +0 -40
- package/dist/mjs/math/shapes/BezierJSWrapper.d.ts +0 -36
- package/dist/mjs/math/shapes/BezierJSWrapper.mjs +0 -107
- package/dist/mjs/math/shapes/CubicBezier.d.ts +0 -17
- package/dist/mjs/math/shapes/CubicBezier.mjs +0 -48
- package/dist/mjs/math/shapes/LineSegment2.d.ts +0 -70
- package/dist/mjs/math/shapes/LineSegment2.mjs +0 -202
- package/dist/mjs/math/shapes/LineSegment2.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Path.d.ts +0 -93
- package/dist/mjs/math/shapes/Path.fromString.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Path.mjs +0 -862
- package/dist/mjs/math/shapes/Path.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Path.toString.test.d.ts +0 -1
- package/dist/mjs/math/shapes/PointShape2D.d.ts +0 -18
- package/dist/mjs/math/shapes/PointShape2D.mjs +0 -44
- package/dist/mjs/math/shapes/QuadraticBezier.d.ts +0 -34
- package/dist/mjs/math/shapes/QuadraticBezier.mjs +0 -131
- package/dist/mjs/math/shapes/QuadraticBezier.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Rect2.d.ts +0 -57
- package/dist/mjs/math/shapes/Rect2.mjs +0 -309
- package/dist/mjs/math/shapes/Rect2.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Triangle.d.ts +0 -46
- package/dist/mjs/math/shapes/Triangle.mjs +0 -146
- package/dist/mjs/math/shapes/Triangle.test.d.ts +0 -1
- package/dist/mjs/rendering/RenderingStyle.test.d.ts +0 -1
- package/dist/mjs/rendering/caching/CacheRecord.test.d.ts +0 -1
- package/dist/mjs/rendering/caching/RenderingCache.test.d.ts +0 -1
- package/dist/mjs/rendering/renderers/DummyRenderer.test.d.ts +0 -1
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.test.d.ts +0 -1
- package/dist/mjs/shortcuts/KeyBinding.test.d.ts +0 -1
- package/dist/mjs/shortcuts/KeyboardShortcutManager.test.d.ts +0 -1
- package/dist/mjs/toolbar/HTMLToolbar.d.ts +0 -105
- package/dist/mjs/toolbar/HTMLToolbar.mjs +0 -462
- package/dist/mjs/toolbar/makeColorInput.d.ts +0 -6
- package/dist/mjs/tools/Eraser.test.d.ts +0 -1
- package/dist/mjs/tools/PanZoom.test.d.ts +0 -1
- package/dist/mjs/tools/Pen.test.d.ts +0 -1
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +0 -1
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +0 -1
- package/dist-test/test_imports/package-lock.json +0 -13
- package/dist-test/test_imports/package.json +0 -12
- package/dist-test/test_imports/test-imports.js +0 -17
- package/dist-test/test_imports/test-require.cjs +0 -19
- package/src/Color4.test.ts +0 -47
- package/src/Color4.ts +0 -304
- package/src/Editor.css +0 -98
- package/src/Editor.loadFrom.test.ts +0 -24
- package/src/Editor.toSVG.test.ts +0 -111
- package/src/Editor.ts +0 -1171
- package/src/EditorImage.test.ts +0 -120
- package/src/EditorImage.ts +0 -603
- package/src/EventDispatcher.test.ts +0 -123
- package/src/EventDispatcher.ts +0 -72
- package/src/Pointer.ts +0 -170
- package/src/SVGLoader.test.ts +0 -114
- package/src/SVGLoader.ts +0 -610
- package/src/UndoRedoHistory.test.ts +0 -33
- package/src/UndoRedoHistory.ts +0 -102
- package/src/Viewport.ts +0 -325
- package/src/bundle/bundled.ts +0 -7
- package/src/commands/Command.ts +0 -45
- package/src/commands/Duplicate.ts +0 -75
- package/src/commands/Erase.ts +0 -94
- package/src/commands/SerializableCommand.ts +0 -49
- package/src/commands/UnresolvedCommand.ts +0 -37
- package/src/commands/invertCommand.ts +0 -58
- package/src/commands/lib.ts +0 -16
- package/src/commands/localization.ts +0 -47
- package/src/commands/uniteCommands.test.ts +0 -23
- package/src/commands/uniteCommands.ts +0 -140
- package/src/components/AbstractComponent.transformBy.test.ts +0 -22
- package/src/components/AbstractComponent.ts +0 -374
- package/src/components/BackgroundComponent.test.ts +0 -45
- package/src/components/BackgroundComponent.ts +0 -353
- package/src/components/ImageComponent.ts +0 -178
- package/src/components/RestylableComponent.ts +0 -161
- package/src/components/SVGGlobalAttributesObject.ts +0 -81
- package/src/components/Stroke.test.ts +0 -139
- package/src/components/Stroke.ts +0 -296
- package/src/components/TextComponent.test.ts +0 -204
- package/src/components/TextComponent.ts +0 -432
- package/src/components/UnknownSVGObject.test.ts +0 -10
- package/src/components/UnknownSVGObject.ts +0 -60
- package/src/components/builders/ArrowBuilder.ts +0 -107
- package/src/components/builders/CircleBuilder.ts +0 -102
- package/src/components/builders/FreehandLineBuilder.test.ts +0 -25
- package/src/components/builders/FreehandLineBuilder.ts +0 -212
- package/src/components/builders/LineBuilder.ts +0 -77
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
- package/src/components/builders/RectangleBuilder.ts +0 -74
- package/src/components/builders/types.ts +0 -15
- package/src/components/lib.ts +0 -31
- package/src/components/localization.ts +0 -24
- package/src/components/util/StrokeSmoother.ts +0 -302
- package/src/components/util/describeComponentList.ts +0 -18
- package/src/lib.ts +0 -69
- package/src/localization.ts +0 -34
- package/src/localizations/de.ts +0 -146
- package/src/localizations/en.ts +0 -8
- package/src/localizations/es.ts +0 -74
- package/src/localizations/getLocalizationTable.test.ts +0 -27
- package/src/localizations/getLocalizationTable.ts +0 -74
- package/src/math/Mat33.test.ts +0 -244
- package/src/math/Mat33.ts +0 -442
- package/src/math/Vec2.test.ts +0 -30
- package/src/math/Vec2.ts +0 -40
- package/src/math/Vec3.test.ts +0 -44
- package/src/math/Vec3.ts +0 -218
- package/src/math/lib.ts +0 -15
- package/src/math/polynomial/solveQuadratic.test.ts +0 -39
- package/src/math/polynomial/solveQuadratic.ts +0 -43
- package/src/math/rounding.test.ts +0 -65
- package/src/math/rounding.ts +0 -156
- package/src/math/shapes/Abstract2DShape.ts +0 -63
- package/src/math/shapes/BezierJSWrapper.ts +0 -93
- package/src/math/shapes/CubicBezier.ts +0 -35
- package/src/math/shapes/LineSegment2.test.ts +0 -99
- package/src/math/shapes/LineSegment2.ts +0 -231
- package/src/math/shapes/Path.fromString.test.ts +0 -223
- package/src/math/shapes/Path.test.ts +0 -309
- package/src/math/shapes/Path.toString.test.ts +0 -77
- package/src/math/shapes/Path.ts +0 -1027
- package/src/math/shapes/PointShape2D.ts +0 -33
- package/src/math/shapes/QuadraticBezier.test.ts +0 -31
- package/src/math/shapes/QuadraticBezier.ts +0 -141
- package/src/math/shapes/Rect2.test.ts +0 -209
- package/src/math/shapes/Rect2.ts +0 -344
- package/src/math/shapes/Triangle.test.ts +0 -61
- package/src/math/shapes/Triangle.ts +0 -139
- package/src/rendering/Display.ts +0 -248
- package/src/rendering/RenderingStyle.test.ts +0 -68
- package/src/rendering/RenderingStyle.ts +0 -55
- package/src/rendering/TextRenderingStyle.ts +0 -55
- package/src/rendering/caching/CacheRecord.test.ts +0 -49
- package/src/rendering/caching/CacheRecord.ts +0 -77
- package/src/rendering/caching/CacheRecordManager.ts +0 -71
- package/src/rendering/caching/RenderingCache.test.ts +0 -44
- package/src/rendering/caching/RenderingCache.ts +0 -66
- package/src/rendering/caching/RenderingCacheNode.ts +0 -405
- package/src/rendering/caching/testUtils.ts +0 -35
- package/src/rendering/caching/types.ts +0 -34
- package/src/rendering/lib.ts +0 -8
- package/src/rendering/localization.ts +0 -20
- package/src/rendering/renderers/AbstractRenderer.ts +0 -242
- package/src/rendering/renderers/CanvasRenderer.ts +0 -307
- package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
- package/src/rendering/renderers/DummyRenderer.ts +0 -145
- package/src/rendering/renderers/SVGRenderer.ts +0 -377
- package/src/rendering/renderers/TextOnlyRenderer.test.ts +0 -34
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -71
- package/src/shortcuts/KeyBinding.test.ts +0 -51
- package/src/shortcuts/KeyBinding.ts +0 -218
- package/src/shortcuts/KeyboardShortcutManager.test.ts +0 -95
- package/src/shortcuts/KeyboardShortcutManager.ts +0 -163
- package/src/shortcuts/lib.ts +0 -3
- package/src/testing/createEditor.ts +0 -11
- package/src/testing/getUniquePointerId.ts +0 -18
- package/src/testing/lib.ts +0 -3
- package/src/testing/sendPenEvent.ts +0 -36
- package/src/testing/sendTouchEvent.ts +0 -71
- package/src/toolbar/HTMLToolbar.ts +0 -567
- package/src/toolbar/IconProvider.ts +0 -805
- package/src/toolbar/lib.ts +0 -4
- package/src/toolbar/localization.ts +0 -114
- package/src/toolbar/makeColorInput.ts +0 -159
- package/src/toolbar/types.ts +0 -5
- package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
- package/src/toolbar/widgets/BaseToolWidget.ts +0 -65
- package/src/toolbar/widgets/BaseWidget.ts +0 -428
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -234
- package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
- package/src/toolbar/widgets/HandToolWidget.ts +0 -250
- package/src/toolbar/widgets/InsertImageWidget.css +0 -44
- package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
- package/src/toolbar/widgets/OverflowWidget.ts +0 -92
- package/src/toolbar/widgets/PenToolWidget.ts +0 -409
- package/src/toolbar/widgets/SelectionToolWidget.ts +0 -197
- package/src/toolbar/widgets/TextToolWidget.ts +0 -145
- package/src/toolbar/widgets/keybindings.ts +0 -21
- package/src/toolbar/widgets/lib.ts +0 -13
- package/src/tools/BaseTool.ts +0 -97
- package/src/tools/Eraser.test.ts +0 -103
- package/src/tools/Eraser.ts +0 -160
- package/src/tools/FindTool.ts +0 -153
- package/src/tools/PanZoom.test.ts +0 -349
- package/src/tools/PanZoom.ts +0 -502
- package/src/tools/PasteHandler.ts +0 -95
- package/src/tools/Pen.test.ts +0 -262
- package/src/tools/Pen.ts +0 -300
- package/src/tools/PipetteTool.ts +0 -55
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -29
- package/src/tools/SelectionTool/Selection.ts +0 -611
- package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
- package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
- package/src/tools/SelectionTool/SelectionTool.ts +0 -496
- package/src/tools/SelectionTool/TransformMode.ts +0 -114
- package/src/tools/SelectionTool/types.ts +0 -11
- package/src/tools/SoundUITool.ts +0 -212
- package/src/tools/TextTool.ts +0 -340
- package/src/tools/ToolController.ts +0 -200
- package/src/tools/ToolEnabledGroup.ts +0 -14
- package/src/tools/ToolSwitcherShortcut.ts +0 -39
- package/src/tools/ToolbarShortcutHandler.ts +0 -39
- package/src/tools/UndoRedoShortcut.test.ts +0 -56
- package/src/tools/UndoRedoShortcut.ts +0 -24
- package/src/tools/keybindings.ts +0 -85
- package/src/tools/lib.ts +0 -22
- package/src/tools/localization.ts +0 -74
- package/src/tools/tools.css +0 -4
- package/src/types.ts +0 -239
- package/src/util/assertions.ts +0 -55
- package/src/util/fileToBase64.ts +0 -18
- package/src/util/untilNextAnimationFrame.ts +0 -9
- package/src/util/waitForAll.ts +0 -18
- package/src/util/waitForTimeout.ts +0 -9
- /package/dist/{cjs/Color4.test.d.ts → mjs/toolbar/widgets/layout/types.mjs} +0 -0
@@ -1,204 +0,0 @@
|
|
1
|
-
import Color4 from '../Color4';
|
2
|
-
import EditorImage from '../EditorImage';
|
3
|
-
import Mat33 from '../math/Mat33';
|
4
|
-
import { Vec2 } from '../math/Vec2';
|
5
|
-
import TextRenderingStyle from '../rendering/TextRenderingStyle';
|
6
|
-
import createEditor from '../testing/createEditor';
|
7
|
-
import AbstractComponent from './AbstractComponent';
|
8
|
-
import TextComponent, { TextTransformMode } from './TextComponent';
|
9
|
-
|
10
|
-
|
11
|
-
describe('TextComponent', () => {
|
12
|
-
it('should be serializable', () => {
|
13
|
-
const style: TextRenderingStyle = {
|
14
|
-
size: 12,
|
15
|
-
fontFamily: 'serif',
|
16
|
-
renderingStyle: { fill: Color4.black },
|
17
|
-
};
|
18
|
-
const text = new TextComponent([ 'Foo' ], Mat33.identity, style);
|
19
|
-
const serialized = text.serialize();
|
20
|
-
const deserialized = AbstractComponent.deserialize(serialized) as TextComponent;
|
21
|
-
expect(deserialized.getBBox()).objEq(text.getBBox());
|
22
|
-
expect(deserialized['getText']()).toContain('Foo');
|
23
|
-
});
|
24
|
-
|
25
|
-
it('should be deserializable', () => {
|
26
|
-
const textComponent = TextComponent.deserializeFromString(`{
|
27
|
-
"textObjects": [ { "text": "Foo" } ],
|
28
|
-
"transform": [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ],
|
29
|
-
"style": {
|
30
|
-
"fontFamily": "sans",
|
31
|
-
"size": 10,
|
32
|
-
"renderingStyle": { "fill": "#000" }
|
33
|
-
}
|
34
|
-
}`);
|
35
|
-
|
36
|
-
expect(textComponent.getText()).toBe('Foo');
|
37
|
-
expect(textComponent.getTransform()).objEq(Mat33.identity);
|
38
|
-
expect(textComponent.getStyle().color!).objEq(Color4.black);
|
39
|
-
expect(textComponent.getTextStyle().fontFamily!).toBe('sans');
|
40
|
-
});
|
41
|
-
|
42
|
-
it('should be restylable', () => {
|
43
|
-
const style: TextRenderingStyle = {
|
44
|
-
size: 10,
|
45
|
-
fontFamily: 'sans',
|
46
|
-
renderingStyle: { fill: Color4.red },
|
47
|
-
};
|
48
|
-
const text = new TextComponent([ 'Foo' ], Mat33.identity, style);
|
49
|
-
|
50
|
-
expect(text.getStyle().color).objEq(Color4.red);
|
51
|
-
text.forceStyle({
|
52
|
-
color: Color4.green,
|
53
|
-
}, null);
|
54
|
-
expect(text.getStyle().color).objEq(Color4.green);
|
55
|
-
expect(text.getTextStyle().renderingStyle.fill).objEq(Color4.green);
|
56
|
-
|
57
|
-
const restyleCommand = text.updateStyle({
|
58
|
-
color: Color4.purple,
|
59
|
-
});
|
60
|
-
|
61
|
-
// Should queue a re-render after restyling.
|
62
|
-
const editor = createEditor();
|
63
|
-
EditorImage.addElement(text).apply(editor);
|
64
|
-
|
65
|
-
editor.rerender();
|
66
|
-
expect(editor.isRerenderQueued()).toBe(false);
|
67
|
-
editor.dispatch(restyleCommand);
|
68
|
-
expect(editor.isRerenderQueued()).toBe(true);
|
69
|
-
|
70
|
-
// Undoing should reset to the correct color.
|
71
|
-
expect(text.getStyle().color).objEq(Color4.purple);
|
72
|
-
editor.history.undo();
|
73
|
-
expect(text.getStyle().color).objEq(Color4.green);
|
74
|
-
});
|
75
|
-
|
76
|
-
it('calling forceStyle on the duplicate of a TextComponent should preserve the original\'s style', () => {
|
77
|
-
const originalStyle: TextRenderingStyle = {
|
78
|
-
size: 11,
|
79
|
-
fontFamily: 'sans-serif',
|
80
|
-
renderingStyle: { fill: Color4.purple, },
|
81
|
-
};
|
82
|
-
|
83
|
-
const text1 = new TextComponent([ 'Test' ], Mat33.identity, originalStyle);
|
84
|
-
const text2 = text1.clone() as TextComponent;
|
85
|
-
|
86
|
-
text1.forceStyle({
|
87
|
-
color: Color4.red,
|
88
|
-
}, null);
|
89
|
-
|
90
|
-
expect(text2.getStyle().color).objEq(Color4.purple);
|
91
|
-
expect(text1.getStyle().color).objEq(Color4.red);
|
92
|
-
|
93
|
-
text2.forceStyle({
|
94
|
-
textStyle: originalStyle,
|
95
|
-
}, null);
|
96
|
-
|
97
|
-
expect(text1.getStyle().color).objEq(Color4.red);
|
98
|
-
expect(text2.getTextStyle()).toMatchObject(originalStyle);
|
99
|
-
});
|
100
|
-
|
101
|
-
describe('should position text components relatively or absolutely (bounding box tests)', () => {
|
102
|
-
const baseStyle: TextRenderingStyle = {
|
103
|
-
size: 12,
|
104
|
-
fontFamily: 'sans-serif',
|
105
|
-
renderingStyle: { fill: Color4.red },
|
106
|
-
};
|
107
|
-
|
108
|
-
it('strings should be placed relative to one another', () => {
|
109
|
-
const str1 = 'test';
|
110
|
-
const str2 = 'test2';
|
111
|
-
|
112
|
-
const container = new TextComponent([ str1, str2 ], Mat33.identity, baseStyle);
|
113
|
-
|
114
|
-
// Create separate components for str1 and str2 so we can check their individual bounding boxes
|
115
|
-
const str1Component = new TextComponent([ str1 ], Mat33.identity, baseStyle);
|
116
|
-
const str2Component = new TextComponent([ str2 ], Mat33.identity, baseStyle);
|
117
|
-
|
118
|
-
const widthSum = str1Component.getBBox().width + str2Component.getBBox().width;
|
119
|
-
const maxHeight = Math.max(str1Component.getBBox().height, str2Component.getBBox().height);
|
120
|
-
expect(container.getBBox().size).objEq(Vec2.of(widthSum, maxHeight));
|
121
|
-
});
|
122
|
-
|
123
|
-
it('RELATIVE_X_ABSOLUTE_Y should work (relatively positioned along x, absolutely along y)', () => {
|
124
|
-
const component1 = new TextComponent([ 'test' ], Mat33.identity, baseStyle);
|
125
|
-
|
126
|
-
const componentTranslation = Vec2.of(10, 10);
|
127
|
-
const component2 = new TextComponent(
|
128
|
-
[ 'relatively' ],
|
129
|
-
Mat33.translation(componentTranslation),
|
130
|
-
baseStyle,
|
131
|
-
TextTransformMode.RELATIVE_X_ABSOLUTE_Y
|
132
|
-
);
|
133
|
-
|
134
|
-
const component3 = new TextComponent(
|
135
|
-
[ 'more of a test...' ],
|
136
|
-
Mat33.translation(componentTranslation),
|
137
|
-
baseStyle,
|
138
|
-
TextTransformMode.RELATIVE_X_ABSOLUTE_Y
|
139
|
-
);
|
140
|
-
|
141
|
-
|
142
|
-
const container = new TextComponent([ component1, component2, component3 ], Mat33.identity, baseStyle);
|
143
|
-
const expectedWidth =
|
144
|
-
component1.getBBox().width
|
145
|
-
// x should take the translation from each component into account.
|
146
|
-
+ componentTranslation.x + component2.getBBox().width
|
147
|
-
+ componentTranslation.x + component3.getBBox().width;
|
148
|
-
const expectedHeight = Math.max(
|
149
|
-
component1.getBBox().height,
|
150
|
-
|
151
|
-
// Absolute y: Should *not* take into account both components' y translations
|
152
|
-
componentTranslation.y + component3.getBBox().height
|
153
|
-
);
|
154
|
-
expect(container.getBBox().size).objEq(Vec2.of(expectedWidth, expectedHeight));
|
155
|
-
});
|
156
|
-
|
157
|
-
it('RELATIVE_Y_ABSOLUTE_X should work (relatively positioned along y, absolutely along x)', () => {
|
158
|
-
const firstComponentTranslation = Vec2.of(1000, 1000);
|
159
|
-
const component1 = new TextComponent(
|
160
|
-
[ '...' ],
|
161
|
-
|
162
|
-
// The translation of the first component shouldn't affect the Y size of the bounding box.
|
163
|
-
Mat33.translation(firstComponentTranslation),
|
164
|
-
|
165
|
-
baseStyle);
|
166
|
-
|
167
|
-
const componentTranslation = Vec2.of(10, 20);
|
168
|
-
const component2 = new TextComponent(
|
169
|
-
[ 'Test!' ],
|
170
|
-
Mat33.translation(componentTranslation),
|
171
|
-
baseStyle,
|
172
|
-
TextTransformMode.RELATIVE_Y_ABSOLUTE_X
|
173
|
-
);
|
174
|
-
|
175
|
-
const component3 = new TextComponent(
|
176
|
-
[ 'Even more of a test.' ],
|
177
|
-
Mat33.translation(componentTranslation),
|
178
|
-
baseStyle,
|
179
|
-
TextTransformMode.RELATIVE_Y_ABSOLUTE_X
|
180
|
-
);
|
181
|
-
|
182
|
-
|
183
|
-
const container = new TextComponent([ component1, component2, component3 ], Mat33.identity, baseStyle);
|
184
|
-
const expectedWidth =
|
185
|
-
component1.getBBox().width
|
186
|
-
|
187
|
-
// Space between the start of components 2 and 3 and the start of component 1
|
188
|
-
+ firstComponentTranslation.x - componentTranslation.x;
|
189
|
-
|
190
|
-
const expectedHeight =
|
191
|
-
// Don't include component1.bbox.height: component1 overlaps with component 2 completely in y
|
192
|
-
// similarly, component 2 overlaps completely with component3 in y.
|
193
|
-
//
|
194
|
-
// Note that while relative positioning is relative to the right edge of the baseline of the previous
|
195
|
-
// item (when in left-to-right mode). Thus, x is adjusted automatically by the text width, while
|
196
|
-
// y remains the same (if there is no additional translation).
|
197
|
-
+ componentTranslation.y
|
198
|
-
+ componentTranslation.y
|
199
|
-
+ component3.getBBox().height;
|
200
|
-
|
201
|
-
expect(container.getBBox().size).objEq(Vec2.of(expectedWidth, expectedHeight));
|
202
|
-
});
|
203
|
-
});
|
204
|
-
});
|
@@ -1,432 +0,0 @@
|
|
1
|
-
import SerializableCommand from '../commands/SerializableCommand';
|
2
|
-
import LineSegment2 from '../math/shapes/LineSegment2';
|
3
|
-
import Mat33, { Mat33Array } from '../math/Mat33';
|
4
|
-
import Rect2 from '../math/shapes/Rect2';
|
5
|
-
import Editor from '../Editor';
|
6
|
-
import { Vec2 } from '../math/Vec2';
|
7
|
-
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
8
|
-
import { cloneTextStyle, TextRenderingStyle, textStyleFromJSON, textStyleToJSON } from '../rendering/TextRenderingStyle';
|
9
|
-
import AbstractComponent from './AbstractComponent';
|
10
|
-
import { ImageComponentLocalization } from './localization';
|
11
|
-
import RestyleableComponent, { ComponentStyle, createRestyleComponentCommand } from './RestylableComponent';
|
12
|
-
|
13
|
-
const componentTypeId = 'text';
|
14
|
-
|
15
|
-
export enum TextTransformMode {
|
16
|
-
/** Absolutely positioned in both the X and Y dimensions. */
|
17
|
-
ABSOLUTE_XY,
|
18
|
-
|
19
|
-
/** Relatively positioned in both the X and Y dimensions. */
|
20
|
-
RELATIVE_XY,
|
21
|
-
|
22
|
-
/**Relatively positioned in the X direction, absolutely positioned in the Y direction. */
|
23
|
-
RELATIVE_X_ABSOLUTE_Y,
|
24
|
-
|
25
|
-
/**Relatively positioned in the Y direction, absolutely positioned in the X direction. */
|
26
|
-
RELATIVE_Y_ABSOLUTE_X,
|
27
|
-
}
|
28
|
-
|
29
|
-
type TextElement = TextComponent|string;
|
30
|
-
|
31
|
-
/**
|
32
|
-
* Displays text.
|
33
|
-
*/
|
34
|
-
export default class TextComponent extends AbstractComponent implements RestyleableComponent {
|
35
|
-
protected contentBBox: Rect2;
|
36
|
-
|
37
|
-
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
38
|
-
readonly isRestylableComponent: true = true;
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Creates a new text object from a list of component text or child TextComponents.
|
42
|
-
*
|
43
|
-
* @see {@link fromLines}
|
44
|
-
*/
|
45
|
-
public constructor(
|
46
|
-
protected readonly textObjects: Array<TextElement>,
|
47
|
-
|
48
|
-
// Transformation relative to this component's parent element.
|
49
|
-
private transform: Mat33,
|
50
|
-
private style: TextRenderingStyle,
|
51
|
-
|
52
|
-
// @internal
|
53
|
-
private transformMode: TextTransformMode = TextTransformMode.ABSOLUTE_XY,
|
54
|
-
) {
|
55
|
-
super(componentTypeId);
|
56
|
-
this.recomputeBBox();
|
57
|
-
|
58
|
-
// If this has no direct children, choose a style representative of this' content
|
59
|
-
// (useful for estimating the style of the TextComponent).
|
60
|
-
const hasDirectContent = textObjects.some(obj => typeof obj === 'string');
|
61
|
-
if (!hasDirectContent && textObjects.length > 0) {
|
62
|
-
this.style = (textObjects[0] as TextComponent).getTextStyle();
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
public static applyTextStyles(ctx: CanvasRenderingContext2D, style: TextRenderingStyle) {
|
67
|
-
// Quote the font family if necessary.
|
68
|
-
const fontFamily = style.fontFamily.match(/\s/) ? style.fontFamily.replace(/["]/g, '\\"') : style.fontFamily;
|
69
|
-
|
70
|
-
ctx.font = [
|
71
|
-
style.fontStyle ?? '',
|
72
|
-
style.fontWeight ?? '',
|
73
|
-
(style.size ?? 12) + 'px',
|
74
|
-
`${fontFamily}`
|
75
|
-
].join(' ');
|
76
|
-
|
77
|
-
// TODO: Support RTL
|
78
|
-
ctx.textAlign = 'left';
|
79
|
-
}
|
80
|
-
|
81
|
-
private static textMeasuringCtx: CanvasRenderingContext2D|null = null;
|
82
|
-
|
83
|
-
// Roughly estimate the bounding box of `text`. Use if no CanvasRenderingContext2D is available.
|
84
|
-
private static estimateTextDimens(text: string, style: TextRenderingStyle): Rect2 {
|
85
|
-
const widthEst = text.length * style.size;
|
86
|
-
const heightEst = style.size;
|
87
|
-
|
88
|
-
// Text is drawn with (0, 0) as its baseline. As such, the majority of the text's height should
|
89
|
-
// be above (0, 0).
|
90
|
-
return new Rect2(0, -heightEst * 2/3, widthEst, heightEst);
|
91
|
-
}
|
92
|
-
|
93
|
-
// Returns a set of TextMetrics for the given text, if a canvas is available.
|
94
|
-
private static getTextMetrics(text: string, style: TextRenderingStyle): TextMetrics|null {
|
95
|
-
TextComponent.textMeasuringCtx ??= document.createElement('canvas').getContext('2d') ?? null;
|
96
|
-
if (!TextComponent.textMeasuringCtx) {
|
97
|
-
return null;
|
98
|
-
}
|
99
|
-
|
100
|
-
const ctx = TextComponent.textMeasuringCtx;
|
101
|
-
TextComponent.applyTextStyles(ctx, style);
|
102
|
-
|
103
|
-
return ctx.measureText(text);
|
104
|
-
}
|
105
|
-
|
106
|
-
// Returns the bounding box of `text`. This is approximate if no Canvas is available.
|
107
|
-
private static getTextDimens(text: string, style: TextRenderingStyle): Rect2 {
|
108
|
-
const metrics = this.getTextMetrics(text, style);
|
109
|
-
|
110
|
-
if (!metrics) {
|
111
|
-
return this.estimateTextDimens(text, style);
|
112
|
-
}
|
113
|
-
|
114
|
-
// Text is drawn with (0,0) at the bottom left of the baseline.
|
115
|
-
const textY = -metrics.actualBoundingBoxAscent;
|
116
|
-
const textHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;
|
117
|
-
return new Rect2(0, textY, metrics.width, textHeight);
|
118
|
-
}
|
119
|
-
|
120
|
-
private static getFontHeight(style: TextRenderingStyle): number {
|
121
|
-
return style.size;
|
122
|
-
}
|
123
|
-
|
124
|
-
private computeUntransformedBBoxOfPart(part: TextElement) {
|
125
|
-
if (typeof part === 'string') {
|
126
|
-
return TextComponent.getTextDimens(part, this.style);
|
127
|
-
} else {
|
128
|
-
return part.contentBBox;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
private recomputeBBox() {
|
133
|
-
let bbox: Rect2|null = null;
|
134
|
-
const cursor = new TextComponent.TextCursor(this.transform, this.style);
|
135
|
-
|
136
|
-
for (const textObject of this.textObjects) {
|
137
|
-
const transform = cursor.update(textObject);
|
138
|
-
const currentBBox = this.computeUntransformedBBoxOfPart(textObject).transformedBoundingBox(transform);
|
139
|
-
|
140
|
-
bbox ??= currentBBox;
|
141
|
-
bbox = bbox.union(currentBBox);
|
142
|
-
}
|
143
|
-
|
144
|
-
this.contentBBox = bbox ?? Rect2.empty;
|
145
|
-
}
|
146
|
-
|
147
|
-
private renderInternal(canvas: AbstractRenderer) {
|
148
|
-
const cursor = new TextComponent.TextCursor(this.transform, this.style);
|
149
|
-
|
150
|
-
for (const textObject of this.textObjects) {
|
151
|
-
const transform = cursor.update(textObject);
|
152
|
-
|
153
|
-
if (typeof textObject === 'string') {
|
154
|
-
canvas.drawText(textObject, transform, this.style);
|
155
|
-
} else {
|
156
|
-
canvas.pushTransform(transform);
|
157
|
-
textObject.renderInternal(canvas);
|
158
|
-
canvas.popTransform();
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
public override render(canvas: AbstractRenderer, _visibleRect?: Rect2): void {
|
164
|
-
canvas.startObject(this.contentBBox);
|
165
|
-
this.renderInternal(canvas);
|
166
|
-
canvas.endObject(this.getLoadSaveData());
|
167
|
-
}
|
168
|
-
|
169
|
-
public override getProportionalRenderingTime(): number {
|
170
|
-
return this.textObjects.length;
|
171
|
-
}
|
172
|
-
|
173
|
-
public override intersects(lineSegment: LineSegment2): boolean {
|
174
|
-
const cursor = new TextComponent.TextCursor(this.transform, this.style);
|
175
|
-
|
176
|
-
for (const subObject of this.textObjects) {
|
177
|
-
// Convert canvas space to internal space relative to the current object.
|
178
|
-
const invTransform = cursor.update(subObject).inverse();
|
179
|
-
const transformedLine = lineSegment.transformedBy(invTransform);
|
180
|
-
|
181
|
-
if (typeof subObject === 'string') {
|
182
|
-
const textBBox = TextComponent.getTextDimens(subObject, this.style);
|
183
|
-
|
184
|
-
// TODO: Use a better intersection check. Perhaps draw the text onto a CanvasElement and
|
185
|
-
// use pixel-testing to check for intersection with its contour.
|
186
|
-
if (textBBox.getEdges().some(edge => transformedLine.intersection(edge) !== null)) {
|
187
|
-
return true;
|
188
|
-
}
|
189
|
-
} else {
|
190
|
-
if (subObject.intersects(transformedLine)) {
|
191
|
-
return true;
|
192
|
-
}
|
193
|
-
}
|
194
|
-
}
|
195
|
-
|
196
|
-
return false;
|
197
|
-
}
|
198
|
-
|
199
|
-
public getStyle(): ComponentStyle {
|
200
|
-
return {
|
201
|
-
color: this.style.renderingStyle.fill,
|
202
|
-
|
203
|
-
// Make a copy
|
204
|
-
textStyle: {
|
205
|
-
...this.style,
|
206
|
-
renderingStyle: {
|
207
|
-
...this.style.renderingStyle,
|
208
|
-
},
|
209
|
-
},
|
210
|
-
};
|
211
|
-
}
|
212
|
-
|
213
|
-
public updateStyle(style: ComponentStyle): SerializableCommand {
|
214
|
-
return createRestyleComponentCommand(this.getStyle(), style, this);
|
215
|
-
}
|
216
|
-
|
217
|
-
public forceStyle(style: ComponentStyle, editor: Editor|null): void {
|
218
|
-
if (style.textStyle) {
|
219
|
-
this.style = cloneTextStyle(style.textStyle);
|
220
|
-
} else if (style.color) {
|
221
|
-
this.style = {
|
222
|
-
...this.style,
|
223
|
-
renderingStyle: {
|
224
|
-
...this.style.renderingStyle,
|
225
|
-
fill: style.color,
|
226
|
-
},
|
227
|
-
};
|
228
|
-
} else {
|
229
|
-
return;
|
230
|
-
}
|
231
|
-
|
232
|
-
for (const child of this.textObjects) {
|
233
|
-
if (child instanceof TextComponent) {
|
234
|
-
child.forceStyle(style, editor);
|
235
|
-
}
|
236
|
-
}
|
237
|
-
|
238
|
-
if (editor) {
|
239
|
-
editor.image.queueRerenderOf(this);
|
240
|
-
editor.queueRerender();
|
241
|
-
}
|
242
|
-
}
|
243
|
-
|
244
|
-
// See {@link getStyle}
|
245
|
-
public getTextStyle(): TextRenderingStyle {
|
246
|
-
return cloneTextStyle(this.style);
|
247
|
-
}
|
248
|
-
|
249
|
-
public getBaselinePos() {
|
250
|
-
return this.transform.transformVec2(Vec2.zero);
|
251
|
-
}
|
252
|
-
|
253
|
-
public getTransform(): Mat33 {
|
254
|
-
return this.transform;
|
255
|
-
}
|
256
|
-
|
257
|
-
protected applyTransformation(affineTransfm: Mat33): void {
|
258
|
-
this.transform = affineTransfm.rightMul(this.transform);
|
259
|
-
this.recomputeBBox();
|
260
|
-
}
|
261
|
-
|
262
|
-
protected createClone(): AbstractComponent {
|
263
|
-
const clonedTextObjects = this.textObjects.map(obj => {
|
264
|
-
if (typeof obj === 'string') {
|
265
|
-
return obj;
|
266
|
-
} else {
|
267
|
-
return obj.createClone() as TextComponent;
|
268
|
-
}
|
269
|
-
});
|
270
|
-
return new TextComponent(clonedTextObjects, this.transform, this.style);
|
271
|
-
}
|
272
|
-
|
273
|
-
public getText() {
|
274
|
-
const result: string[] = [];
|
275
|
-
|
276
|
-
for (const textObject of this.textObjects) {
|
277
|
-
if (typeof textObject === 'string') {
|
278
|
-
result.push(textObject);
|
279
|
-
} else {
|
280
|
-
result.push(textObject.getText());
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
return result.join('\n');
|
285
|
-
}
|
286
|
-
|
287
|
-
public description(localizationTable: ImageComponentLocalization): string {
|
288
|
-
return localizationTable.text(this.getText());
|
289
|
-
}
|
290
|
-
|
291
|
-
// Do not rely on the output of `serializeToJSON` taking any particular format.
|
292
|
-
protected serializeToJSON(): Record<string, any> {
|
293
|
-
const serializableStyle = textStyleToJSON(this.style);
|
294
|
-
|
295
|
-
const serializedTextObjects = this.textObjects.map(text => {
|
296
|
-
if (typeof text === 'string') {
|
297
|
-
return {
|
298
|
-
text,
|
299
|
-
};
|
300
|
-
} else {
|
301
|
-
return {
|
302
|
-
json: text.serializeToJSON(),
|
303
|
-
};
|
304
|
-
}
|
305
|
-
});
|
306
|
-
|
307
|
-
return {
|
308
|
-
textObjects: serializedTextObjects,
|
309
|
-
transform: this.transform.toArray(),
|
310
|
-
style: serializableStyle,
|
311
|
-
};
|
312
|
-
}
|
313
|
-
|
314
|
-
// @internal
|
315
|
-
public static deserializeFromString(json: any): TextComponent {
|
316
|
-
if (typeof json === 'string') {
|
317
|
-
json = JSON.parse(json);
|
318
|
-
}
|
319
|
-
|
320
|
-
const style = textStyleFromJSON(json.style);
|
321
|
-
|
322
|
-
const textObjects: Array<TextElement> = json.textObjects.map((data: any) => {
|
323
|
-
if ((data.text ?? null) !== null) {
|
324
|
-
return data.text;
|
325
|
-
}
|
326
|
-
|
327
|
-
return TextComponent.deserializeFromString(data.json);
|
328
|
-
});
|
329
|
-
|
330
|
-
json.transform = json.transform.filter((elem: any) => typeof elem === 'number');
|
331
|
-
if (json.transform.length !== 9) {
|
332
|
-
throw new Error(`Unable to deserialize transform, ${json.transform}.`);
|
333
|
-
}
|
334
|
-
|
335
|
-
const transformData = json.transform as Mat33Array;
|
336
|
-
const transform = new Mat33(...transformData);
|
337
|
-
|
338
|
-
return new TextComponent(textObjects, transform, style);
|
339
|
-
}
|
340
|
-
|
341
|
-
/**
|
342
|
-
* Creates a `TextComponent` from `lines`.
|
343
|
-
*
|
344
|
-
* @example
|
345
|
-
* ```ts
|
346
|
-
* const textStyle = {
|
347
|
-
* size: 12,
|
348
|
-
* fontFamily: 'serif',
|
349
|
-
* renderingStyle: { fill: Color4.black },
|
350
|
-
* };
|
351
|
-
*
|
352
|
-
* const text = TextComponent.fromLines('foo\nbar'.split('\n'), Mat33.identity, textStyle);
|
353
|
-
* ```
|
354
|
-
*/
|
355
|
-
public static fromLines(lines: string[], transform: Mat33, style: TextRenderingStyle): AbstractComponent {
|
356
|
-
let lastComponent: TextComponent|null = null;
|
357
|
-
const components: TextComponent[] = [];
|
358
|
-
|
359
|
-
const lineMargin = Math.round(this.getFontHeight(style));
|
360
|
-
|
361
|
-
let position = Vec2.zero;
|
362
|
-
for (const line of lines) {
|
363
|
-
if (lastComponent) {
|
364
|
-
position = position.plus(Vec2.unitY.times(lineMargin));
|
365
|
-
}
|
366
|
-
|
367
|
-
const component = new TextComponent([ line ], Mat33.translation(position), style);
|
368
|
-
components.push(component);
|
369
|
-
lastComponent = component;
|
370
|
-
}
|
371
|
-
|
372
|
-
return new TextComponent(components, transform, style);
|
373
|
-
}
|
374
|
-
|
375
|
-
private static TextCursor = class {
|
376
|
-
public transform: Mat33 = Mat33.identity;
|
377
|
-
public constructor(
|
378
|
-
private parentTransform: Mat33 = Mat33.identity, private parentStyle: TextRenderingStyle
|
379
|
-
) { }
|
380
|
-
|
381
|
-
/**
|
382
|
-
* Based on previous calls to `update`, returns the transformation of
|
383
|
-
* the given `element` (including the parentTransform given to this cursor's
|
384
|
-
* constructor).
|
385
|
-
*
|
386
|
-
* The result does not take into account
|
387
|
-
*/
|
388
|
-
public update(elem: TextElement) {
|
389
|
-
let elementTransform = Mat33.identity;
|
390
|
-
let elemInternalTransform = Mat33.identity;
|
391
|
-
let textSize;
|
392
|
-
if (typeof(elem) === 'string') {
|
393
|
-
textSize = TextComponent.getTextDimens(elem, this.parentStyle);
|
394
|
-
} else {
|
395
|
-
// TODO: Double-check whether we need to take elem.transform into account here.
|
396
|
-
// elementTransform = elem.transform;
|
397
|
-
elemInternalTransform = elem.transform;
|
398
|
-
textSize = elem.getBBox();
|
399
|
-
}
|
400
|
-
const positioning = typeof(elem) === 'string' ? TextTransformMode.RELATIVE_XY : elem.transformMode;
|
401
|
-
|
402
|
-
if (positioning === TextTransformMode.RELATIVE_XY) {
|
403
|
-
// Position relative to the previous element's transform.
|
404
|
-
elementTransform = this.transform.rightMul(elementTransform);
|
405
|
-
} else if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y || positioning === TextTransformMode.RELATIVE_Y_ABSOLUTE_X) {
|
406
|
-
// Zero the absolute component of this.transform's translation
|
407
|
-
const transform = this.transform.mapEntries((component, [row, col]) => {
|
408
|
-
if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y) {
|
409
|
-
// Zero the y component of this.transform's translation
|
410
|
-
return row === 1 && col === 2 ? 0 : component;
|
411
|
-
} else if (positioning === TextTransformMode.RELATIVE_Y_ABSOLUTE_X) {
|
412
|
-
// Zero the x component of this.transform's translation
|
413
|
-
return row === 0 && col === 2 ? 0 : component;
|
414
|
-
}
|
415
|
-
|
416
|
-
throw new Error('Unreachable');
|
417
|
-
return 0;
|
418
|
-
});
|
419
|
-
|
420
|
-
elementTransform = transform.rightMul(elementTransform);
|
421
|
-
}
|
422
|
-
|
423
|
-
// Update this.transform so that future calls to update return correct values.
|
424
|
-
const endShiftTransform = Mat33.translation(Vec2.of(textSize.width, 0));
|
425
|
-
this.transform = elementTransform.rightMul(elemInternalTransform).rightMul(endShiftTransform);
|
426
|
-
|
427
|
-
return this.parentTransform.rightMul(elementTransform);
|
428
|
-
}
|
429
|
-
};
|
430
|
-
}
|
431
|
-
|
432
|
-
AbstractComponent.registerComponent(componentTypeId, (data: string) => TextComponent.deserializeFromString(data));
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import AbstractComponent from './AbstractComponent';
|
2
|
-
import UnknownSVGObject from './UnknownSVGObject';
|
3
|
-
|
4
|
-
describe('UnknownSVGObject', () => {
|
5
|
-
it('should not be deserializable', () => {
|
6
|
-
const obj = new UnknownSVGObject(document.createElementNS('http://www.w3.org/2000/svg', 'circle'));
|
7
|
-
const serialized = obj.serialize();
|
8
|
-
expect(() => AbstractComponent.deserialize(serialized)).toThrow(/.*cannot be deserialized.*/);
|
9
|
-
});
|
10
|
-
});
|
@@ -1,60 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Stores objects loaded from an SVG that aren't recognised by the editor.
|
3
|
-
// @internal
|
4
|
-
// @packageDocumentation
|
5
|
-
//
|
6
|
-
|
7
|
-
import LineSegment2 from '../math/shapes/LineSegment2';
|
8
|
-
import Mat33 from '../math/Mat33';
|
9
|
-
import Rect2 from '../math/shapes/Rect2';
|
10
|
-
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
11
|
-
import SVGRenderer from '../rendering/renderers/SVGRenderer';
|
12
|
-
import AbstractComponent from './AbstractComponent';
|
13
|
-
import { ImageComponentLocalization } from './localization';
|
14
|
-
|
15
|
-
const componentId = 'unknown-svg-object';
|
16
|
-
export default class UnknownSVGObject extends AbstractComponent {
|
17
|
-
protected contentBBox: Rect2;
|
18
|
-
|
19
|
-
public constructor(private svgObject: SVGElement) {
|
20
|
-
super(componentId);
|
21
|
-
this.contentBBox = Rect2.of(svgObject.getBoundingClientRect());
|
22
|
-
}
|
23
|
-
|
24
|
-
public override render(canvas: AbstractRenderer, _visibleRect?: Rect2): void {
|
25
|
-
if (!(canvas instanceof SVGRenderer)) {
|
26
|
-
// Don't draw unrenderable objects if we can't
|
27
|
-
return;
|
28
|
-
}
|
29
|
-
|
30
|
-
canvas.drawSVGElem(this.svgObject);
|
31
|
-
}
|
32
|
-
|
33
|
-
public override intersects(lineSegment: LineSegment2): boolean {
|
34
|
-
return this.contentBBox.getEdges().some(edge => edge.intersection(lineSegment) !== null);
|
35
|
-
}
|
36
|
-
|
37
|
-
protected applyTransformation(_affineTransfm: Mat33): void {
|
38
|
-
}
|
39
|
-
|
40
|
-
public override isSelectable() {
|
41
|
-
return false;
|
42
|
-
}
|
43
|
-
|
44
|
-
protected createClone(): AbstractComponent {
|
45
|
-
return new UnknownSVGObject(this.svgObject.cloneNode(true) as SVGElement);
|
46
|
-
}
|
47
|
-
|
48
|
-
public description(localization: ImageComponentLocalization): string {
|
49
|
-
return localization.svgObject;
|
50
|
-
}
|
51
|
-
|
52
|
-
protected serializeToJSON(): string | null {
|
53
|
-
return JSON.stringify({
|
54
|
-
html: this.svgObject.outerHTML,
|
55
|
-
});
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
// null: Do not deserialize UnknownSVGObjects.
|
60
|
-
AbstractComponent.registerComponent(componentId, null);
|