js-draw 0.17.4 → 0.18.1
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/CHANGELOG.md +8 -0
- package/dist/bundle.js +9 -1
- package/package.json +35 -33
- package/tsconfig.json +3 -2
- package/tsconfig.mjs.json +9 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -34
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/ISSUE_TEMPLATE/translation.yml +0 -902
- package/.github/pull_request_template.md +0 -15
- package/.github/workflows/firebase-hosting-merge.yml +0 -32
- package/.github/workflows/firebase-hosting-pull-request.yml +0 -32
- package/.github/workflows/github-pages.yml +0 -56
- package/.husky/pre-commit +0 -4
- package/build_tools/BundledFile.ts +0 -167
- package/build_tools/buildTranslationTemplate.ts +0 -121
- package/build_tools/bundle.ts +0 -11
- package/dist/build_tools/BundledFile.d.ts +0 -13
- package/dist/build_tools/BundledFile.js +0 -157
- package/dist/build_tools/buildTranslationTemplate.d.ts +0 -1
- package/dist/build_tools/buildTranslationTemplate.js +0 -94
- package/dist/build_tools/bundle.d.ts +0 -1
- package/dist/build_tools/bundle.js +0 -5
- package/dist/src/Color4.d.ts +0 -60
- package/dist/src/Color4.js +0 -192
- package/dist/src/Editor.d.ts +0 -308
- package/dist/src/Editor.js +0 -874
- package/dist/src/EditorImage.d.ts +0 -97
- package/dist/src/EditorImage.js +0 -477
- package/dist/src/EventDispatcher.d.ts +0 -30
- package/dist/src/EventDispatcher.js +0 -54
- package/dist/src/Pointer.d.ts +0 -24
- package/dist/src/Pointer.js +0 -80
- package/dist/src/SVGLoader.d.ts +0 -48
- package/dist/src/SVGLoader.js +0 -442
- package/dist/src/UndoRedoHistory.d.ts +0 -19
- package/dist/src/UndoRedoHistory.js +0 -91
- package/dist/src/Viewport.d.ts +0 -71
- package/dist/src/Viewport.js +0 -256
- package/dist/src/bundle/bundled.d.ts +0 -4
- package/dist/src/bundle/bundled.js +0 -5
- package/dist/src/commands/Command.d.ts +0 -16
- package/dist/src/commands/Command.js +0 -30
- package/dist/src/commands/Duplicate.d.ts +0 -14
- package/dist/src/commands/Duplicate.js +0 -33
- package/dist/src/commands/Erase.d.ts +0 -14
- package/dist/src/commands/Erase.js +0 -57
- package/dist/src/commands/SerializableCommand.d.ts +0 -12
- package/dist/src/commands/SerializableCommand.js +0 -36
- package/dist/src/commands/UnresolvedCommand.d.ts +0 -14
- package/dist/src/commands/UnresolvedCommand.js +0 -22
- package/dist/src/commands/invertCommand.d.ts +0 -4
- package/dist/src/commands/invertCommand.js +0 -44
- package/dist/src/commands/lib.d.ts +0 -7
- package/dist/src/commands/lib.js +0 -7
- package/dist/src/commands/localization.d.ts +0 -23
- package/dist/src/commands/localization.js +0 -21
- package/dist/src/commands/uniteCommands.d.ts +0 -4
- package/dist/src/commands/uniteCommands.js +0 -116
- package/dist/src/components/AbstractComponent.d.ts +0 -73
- package/dist/src/components/AbstractComponent.js +0 -252
- package/dist/src/components/ImageBackground.d.ts +0 -42
- package/dist/src/components/ImageBackground.js +0 -139
- package/dist/src/components/ImageComponent.d.ts +0 -31
- package/dist/src/components/ImageComponent.js +0 -146
- package/dist/src/components/RestylableComponent.d.ts +0 -24
- package/dist/src/components/RestylableComponent.js +0 -80
- package/dist/src/components/SVGGlobalAttributesObject.d.ts +0 -21
- package/dist/src/components/SVGGlobalAttributesObject.js +0 -59
- package/dist/src/components/Stroke.d.ts +0 -40
- package/dist/src/components/Stroke.js +0 -185
- package/dist/src/components/TextComponent.d.ts +0 -53
- package/dist/src/components/TextComponent.js +0 -252
- package/dist/src/components/UnknownSVGObject.d.ts +0 -18
- package/dist/src/components/UnknownSVGObject.js +0 -44
- package/dist/src/components/builders/ArrowBuilder.d.ts +0 -19
- package/dist/src/components/builders/ArrowBuilder.js +0 -86
- package/dist/src/components/builders/FreehandLineBuilder.d.ts +0 -33
- package/dist/src/components/builders/FreehandLineBuilder.js +0 -165
- package/dist/src/components/builders/LineBuilder.d.ts +0 -18
- package/dist/src/components/builders/LineBuilder.js +0 -58
- package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +0 -36
- package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.js +0 -339
- package/dist/src/components/builders/RectangleBuilder.d.ts +0 -20
- package/dist/src/components/builders/RectangleBuilder.js +0 -50
- package/dist/src/components/builders/types.d.ts +0 -12
- package/dist/src/components/builders/types.js +0 -1
- package/dist/src/components/lib.d.ts +0 -12
- package/dist/src/components/lib.js +0 -12
- package/dist/src/components/localization.d.ts +0 -11
- package/dist/src/components/localization.js +0 -10
- package/dist/src/components/util/StrokeSmoother.d.ts +0 -35
- package/dist/src/components/util/StrokeSmoother.js +0 -210
- package/dist/src/components/util/describeComponentList.d.ts +0 -4
- package/dist/src/components/util/describeComponentList.js +0 -14
- package/dist/src/lib.d.ts +0 -34
- package/dist/src/lib.js +0 -34
- package/dist/src/localization.d.ts +0 -14
- package/dist/src/localization.js +0 -10
- package/dist/src/localizations/de.d.ts +0 -3
- package/dist/src/localizations/de.js +0 -4
- package/dist/src/localizations/en.d.ts +0 -3
- package/dist/src/localizations/en.js +0 -4
- package/dist/src/localizations/es.d.ts +0 -3
- package/dist/src/localizations/es.js +0 -18
- package/dist/src/localizations/getLocalizationTable.d.ts +0 -3
- package/dist/src/localizations/getLocalizationTable.js +0 -45
- package/dist/src/math/LineSegment2.d.ts +0 -24
- package/dist/src/math/LineSegment2.js +0 -125
- package/dist/src/math/Mat33.d.ts +0 -118
- package/dist/src/math/Mat33.js +0 -326
- package/dist/src/math/Path.d.ts +0 -71
- package/dist/src/math/Path.js +0 -648
- package/dist/src/math/Rect2.d.ts +0 -52
- package/dist/src/math/Rect2.js +0 -228
- package/dist/src/math/Triangle.d.ts +0 -11
- package/dist/src/math/Triangle.js +0 -19
- package/dist/src/math/Vec2.d.ts +0 -13
- package/dist/src/math/Vec2.js +0 -13
- package/dist/src/math/Vec3.d.ts +0 -106
- package/dist/src/math/Vec3.js +0 -174
- package/dist/src/math/lib.d.ts +0 -7
- package/dist/src/math/lib.js +0 -7
- package/dist/src/math/rounding.d.ts +0 -4
- package/dist/src/math/rounding.js +0 -128
- package/dist/src/rendering/Display.d.ts +0 -75
- package/dist/src/rendering/Display.js +0 -207
- package/dist/src/rendering/RenderingStyle.d.ts +0 -31
- package/dist/src/rendering/RenderingStyle.js +0 -38
- package/dist/src/rendering/TextRenderingStyle.d.ts +0 -36
- package/dist/src/rendering/TextRenderingStyle.js +0 -23
- package/dist/src/rendering/caching/CacheRecord.d.ts +0 -20
- package/dist/src/rendering/caching/CacheRecord.js +0 -55
- package/dist/src/rendering/caching/CacheRecordManager.d.ts +0 -12
- package/dist/src/rendering/caching/CacheRecordManager.js +0 -43
- package/dist/src/rendering/caching/RenderingCache.d.ts +0 -11
- package/dist/src/rendering/caching/RenderingCache.js +0 -45
- package/dist/src/rendering/caching/RenderingCacheNode.d.ts +0 -29
- package/dist/src/rendering/caching/RenderingCacheNode.js +0 -320
- package/dist/src/rendering/caching/testUtils.d.ts +0 -9
- package/dist/src/rendering/caching/testUtils.js +0 -20
- package/dist/src/rendering/caching/types.d.ts +0 -19
- package/dist/src/rendering/caching/types.js +0 -1
- package/dist/src/rendering/lib.d.ts +0 -5
- package/dist/src/rendering/lib.js +0 -5
- package/dist/src/rendering/localization.d.ts +0 -10
- package/dist/src/rendering/localization.js +0 -9
- package/dist/src/rendering/renderers/AbstractRenderer.d.ts +0 -68
- package/dist/src/rendering/renderers/AbstractRenderer.js +0 -144
- package/dist/src/rendering/renderers/CanvasRenderer.d.ts +0 -63
- package/dist/src/rendering/renderers/CanvasRenderer.js +0 -230
- package/dist/src/rendering/renderers/DummyRenderer.d.ts +0 -35
- package/dist/src/rendering/renderers/DummyRenderer.js +0 -106
- package/dist/src/rendering/renderers/SVGRenderer.d.ts +0 -57
- package/dist/src/rendering/renderers/SVGRenderer.js +0 -304
- package/dist/src/rendering/renderers/TextOnlyRenderer.d.ts +0 -29
- package/dist/src/rendering/renderers/TextOnlyRenderer.js +0 -57
- package/dist/src/testing/beforeEachFile.d.ts +0 -1
- package/dist/src/testing/beforeEachFile.js +0 -7
- package/dist/src/testing/createEditor.d.ts +0 -4
- package/dist/src/testing/createEditor.js +0 -9
- package/dist/src/testing/lib.d.ts +0 -2
- package/dist/src/testing/lib.js +0 -2
- package/dist/src/testing/loadExpectExtensions.d.ts +0 -2
- package/dist/src/testing/loadExpectExtensions.js +0 -24
- package/dist/src/testing/sendPenEvent.d.ts +0 -12
- package/dist/src/testing/sendPenEvent.js +0 -19
- package/dist/src/testing/sendTouchEvent.d.ts +0 -42
- package/dist/src/testing/sendTouchEvent.js +0 -62
- package/dist/src/toolbar/HTMLToolbar.d.ts +0 -103
- package/dist/src/toolbar/HTMLToolbar.js +0 -376
- package/dist/src/toolbar/IconProvider.d.ts +0 -62
- package/dist/src/toolbar/IconProvider.js +0 -654
- package/dist/src/toolbar/lib.d.ts +0 -3
- package/dist/src/toolbar/lib.js +0 -3
- package/dist/src/toolbar/localization.d.ts +0 -49
- package/dist/src/toolbar/localization.js +0 -48
- package/dist/src/toolbar/makeColorInput.d.ts +0 -6
- package/dist/src/toolbar/makeColorInput.js +0 -113
- package/dist/src/toolbar/types.d.ts +0 -4
- package/dist/src/toolbar/types.js +0 -1
- package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +0 -15
- package/dist/src/toolbar/widgets/ActionButtonWidget.js +0 -25
- package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +0 -11
- package/dist/src/toolbar/widgets/BaseToolWidget.js +0 -44
- package/dist/src/toolbar/widgets/BaseWidget.d.ts +0 -72
- package/dist/src/toolbar/widgets/BaseWidget.js +0 -307
- package/dist/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +0 -18
- package/dist/src/toolbar/widgets/DocumentPropertiesWidget.js +0 -120
- package/dist/src/toolbar/widgets/EraserToolWidget.d.ts +0 -17
- package/dist/src/toolbar/widgets/EraserToolWidget.js +0 -57
- package/dist/src/toolbar/widgets/HandToolWidget.d.ts +0 -17
- package/dist/src/toolbar/widgets/HandToolWidget.js +0 -172
- package/dist/src/toolbar/widgets/InsertImageWidget.d.ts +0 -19
- package/dist/src/toolbar/widgets/InsertImageWidget.js +0 -170
- package/dist/src/toolbar/widgets/OverflowWidget.d.ts +0 -25
- package/dist/src/toolbar/widgets/OverflowWidget.js +0 -71
- package/dist/src/toolbar/widgets/PenToolWidget.d.ts +0 -27
- package/dist/src/toolbar/widgets/PenToolWidget.js +0 -220
- package/dist/src/toolbar/widgets/SelectionToolWidget.d.ts +0 -13
- package/dist/src/toolbar/widgets/SelectionToolWidget.js +0 -147
- package/dist/src/toolbar/widgets/TextToolWidget.d.ts +0 -16
- package/dist/src/toolbar/widgets/TextToolWidget.js +0 -109
- package/dist/src/toolbar/widgets/lib.d.ts +0 -10
- package/dist/src/toolbar/widgets/lib.js +0 -10
- package/dist/src/tools/BaseTool.d.ts +0 -22
- package/dist/src/tools/BaseTool.js +0 -63
- package/dist/src/tools/Eraser.d.ts +0 -23
- package/dist/src/tools/Eraser.js +0 -106
- package/dist/src/tools/FindTool.d.ts +0 -21
- package/dist/src/tools/FindTool.js +0 -114
- package/dist/src/tools/PanZoom.d.ts +0 -52
- package/dist/src/tools/PanZoom.js +0 -414
- package/dist/src/tools/PasteHandler.d.ts +0 -23
- package/dist/src/tools/PasteHandler.js +0 -93
- package/dist/src/tools/Pen.d.ts +0 -39
- package/dist/src/tools/Pen.js +0 -173
- package/dist/src/tools/PipetteTool.d.ts +0 -18
- package/dist/src/tools/PipetteTool.js +0 -39
- package/dist/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -8
- package/dist/src/tools/SelectionTool/SelectAllShortcutHandler.js +0 -22
- package/dist/src/tools/SelectionTool/Selection.d.ts +0 -64
- package/dist/src/tools/SelectionTool/Selection.js +0 -459
- package/dist/src/tools/SelectionTool/SelectionHandle.d.ts +0 -38
- package/dist/src/tools/SelectionTool/SelectionHandle.js +0 -81
- package/dist/src/tools/SelectionTool/SelectionTool.d.ts +0 -36
- package/dist/src/tools/SelectionTool/SelectionTool.js +0 -398
- package/dist/src/tools/SelectionTool/TransformMode.d.ts +0 -34
- package/dist/src/tools/SelectionTool/TransformMode.js +0 -98
- package/dist/src/tools/SelectionTool/types.d.ts +0 -9
- package/dist/src/tools/SelectionTool/types.js +0 -11
- package/dist/src/tools/TextTool.d.ts +0 -33
- package/dist/src/tools/TextTool.js +0 -256
- package/dist/src/tools/ToolController.d.ts +0 -18
- package/dist/src/tools/ToolController.js +0 -158
- package/dist/src/tools/ToolEnabledGroup.d.ts +0 -6
- package/dist/src/tools/ToolEnabledGroup.js +0 -11
- package/dist/src/tools/ToolSwitcherShortcut.d.ts +0 -16
- package/dist/src/tools/ToolSwitcherShortcut.js +0 -32
- package/dist/src/tools/ToolbarShortcutHandler.d.ts +0 -12
- package/dist/src/tools/ToolbarShortcutHandler.js +0 -23
- package/dist/src/tools/UndoRedoShortcut.d.ts +0 -8
- package/dist/src/tools/UndoRedoShortcut.js +0 -22
- package/dist/src/tools/lib.d.ts +0 -16
- package/dist/src/tools/lib.js +0 -16
- package/dist/src/tools/localization.d.ts +0 -28
- package/dist/src/tools/localization.js +0 -27
- package/dist/src/types.d.ts +0 -151
- package/dist/src/types.js +0 -35
- package/dist/src/util/assertions.d.ts +0 -23
- package/dist/src/util/assertions.js +0 -45
- package/dist/src/util/fileToBase64.d.ts +0 -3
- package/dist/src/util/fileToBase64.js +0 -13
- package/dist/src/util/untilNextAnimationFrame.d.ts +0 -3
- package/dist/src/util/untilNextAnimationFrame.js +0 -7
- package/dist/src/util/waitForTimeout.d.ts +0 -2
- package/dist/src/util/waitForTimeout.js +0 -7
- package/src/Color4.test.ts +0 -40
- package/src/Color4.ts +0 -234
- package/src/Editor.css +0 -86
- package/src/Editor.loadFrom.test.ts +0 -24
- package/src/Editor.toSVG.test.ts +0 -111
- package/src/Editor.ts +0 -1122
- 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 -71
- package/src/Pointer.ts +0 -127
- package/src/SVGLoader.test.ts +0 -114
- package/src/SVGLoader.ts +0 -511
- package/src/UndoRedoHistory.test.ts +0 -33
- package/src/UndoRedoHistory.ts +0 -102
- package/src/Viewport.ts +0 -319
- package/src/bundle/bundled.ts +0 -7
- package/src/commands/Command.ts +0 -45
- package/src/commands/Duplicate.ts +0 -48
- package/src/commands/Erase.ts +0 -74
- package/src/commands/SerializableCommand.ts +0 -49
- package/src/commands/UnresolvedCommand.ts +0 -37
- package/src/commands/invertCommand.ts +0 -51
- 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 -135
- package/src/components/AbstractComponent.transformBy.test.ts +0 -22
- package/src/components/AbstractComponent.ts +0 -364
- package/src/components/ImageBackground.test.ts +0 -35
- package/src/components/ImageBackground.ts +0 -176
- package/src/components/ImageComponent.ts +0 -171
- package/src/components/RestylableComponent.ts +0 -142
- package/src/components/SVGGlobalAttributesObject.ts +0 -81
- package/src/components/Stroke.test.ts +0 -139
- package/src/components/Stroke.ts +0 -245
- package/src/components/TextComponent.test.ts +0 -99
- package/src/components/TextComponent.ts +0 -315
- 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/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 -25
- package/src/components/localization.ts +0 -22
- package/src/components/util/StrokeSmoother.ts +0 -293
- package/src/components/util/describeComponentList.ts +0 -18
- package/src/lib.ts +0 -37
- package/src/localization.ts +0 -34
- package/src/localizations/de.ts +0 -98
- 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 -55
- package/src/math/LineSegment2.test.ts +0 -99
- package/src/math/LineSegment2.ts +0 -160
- package/src/math/Mat33.test.ts +0 -244
- package/src/math/Mat33.ts +0 -437
- package/src/math/Path.fromString.test.ts +0 -223
- package/src/math/Path.test.ts +0 -198
- package/src/math/Path.toString.test.ts +0 -77
- package/src/math/Path.ts +0 -790
- package/src/math/Rect2.test.ts +0 -204
- package/src/math/Rect2.ts +0 -315
- package/src/math/Triangle.ts +0 -29
- package/src/math/Vec2.test.ts +0 -30
- package/src/math/Vec2.ts +0 -18
- 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/rounding.test.ts +0 -65
- package/src/math/rounding.ts +0 -156
- package/src/rendering/Display.ts +0 -249
- package/src/rendering/RenderingStyle.test.ts +0 -68
- package/src/rendering/RenderingStyle.ts +0 -55
- package/src/rendering/TextRenderingStyle.ts +0 -45
- 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 -6
- package/src/rendering/localization.ts +0 -20
- package/src/rendering/renderers/AbstractRenderer.ts +0 -222
- package/src/rendering/renderers/CanvasRenderer.ts +0 -296
- package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
- package/src/rendering/renderers/DummyRenderer.ts +0 -136
- package/src/rendering/renderers/SVGRenderer.ts +0 -354
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
- package/src/styles.js +0 -7
- package/src/testing/beforeEachFile.ts +0 -8
- package/src/testing/createEditor.ts +0 -11
- package/src/testing/global.d.ts +0 -17
- package/src/testing/lib.ts +0 -3
- package/src/testing/loadExpectExtensions.ts +0 -25
- package/src/testing/sendPenEvent.ts +0 -31
- package/src/testing/sendTouchEvent.ts +0 -78
- package/src/toolbar/HTMLToolbar.ts +0 -492
- package/src/toolbar/IconProvider.ts +0 -736
- package/src/toolbar/lib.ts +0 -4
- package/src/toolbar/localization.ts +0 -106
- package/src/toolbar/makeColorInput.ts +0 -145
- package/src/toolbar/toolbar.css +0 -213
- package/src/toolbar/types.ts +0 -5
- package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
- package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
- package/src/toolbar/widgets/BaseWidget.ts +0 -377
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
- 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.css +0 -27
- package/src/toolbar/widgets/OverflowWidget.ts +0 -92
- package/src/toolbar/widgets/PenToolWidget.ts +0 -288
- package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
- package/src/toolbar/widgets/TextToolWidget.ts +0 -145
- package/src/toolbar/widgets/lib.ts +0 -13
- package/src/tools/BaseTool.ts +0 -76
- package/src/tools/Eraser.test.ts +0 -103
- package/src/tools/Eraser.ts +0 -139
- package/src/tools/FindTool.css +0 -7
- package/src/tools/FindTool.ts +0 -152
- package/src/tools/PanZoom.test.ts +0 -310
- package/src/tools/PanZoom.ts +0 -520
- package/src/tools/PasteHandler.ts +0 -95
- package/src/tools/Pen.test.ts +0 -194
- package/src/tools/Pen.ts +0 -226
- package/src/tools/PipetteTool.ts +0 -55
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
- package/src/tools/SelectionTool/Selection.ts +0 -607
- package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
- package/src/tools/SelectionTool/SelectionTool.css +0 -23
- package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
- package/src/tools/SelectionTool/SelectionTool.ts +0 -480
- package/src/tools/SelectionTool/TransformMode.ts +0 -114
- package/src/tools/SelectionTool/types.ts +0 -11
- package/src/tools/TextTool.ts +0 -326
- package/src/tools/ToolController.ts +0 -178
- package/src/tools/ToolEnabledGroup.ts +0 -14
- package/src/tools/ToolSwitcherShortcut.ts +0 -39
- package/src/tools/ToolbarShortcutHandler.ts +0 -34
- package/src/tools/UndoRedoShortcut.test.ts +0 -56
- package/src/tools/UndoRedoShortcut.ts +0 -25
- package/src/tools/lib.ts +0 -21
- package/src/tools/localization.ts +0 -66
- package/src/types.ts +0 -234
- package/src/util/assertions.ts +0 -55
- package/src/util/fileToBase64.ts +0 -18
- package/src/util/untilNextAnimationFrame.ts +0 -9
- package/src/util/waitForTimeout.ts +0 -9
package/dist/src/Viewport.d.ts
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
import Command from './commands/Command';
|
2
|
-
import Mat33 from './math/Mat33';
|
3
|
-
import Rect2 from './math/Rect2';
|
4
|
-
import { Point2, Vec2 } from './math/Vec2';
|
5
|
-
import Vec3 from './math/Vec3';
|
6
|
-
import { StrokeDataPoint } from './types';
|
7
|
-
type PointDataType<T extends Point2 | StrokeDataPoint | number> = T extends Point2 ? Point2 : number;
|
8
|
-
export declare abstract class ViewportTransform extends Command {
|
9
|
-
abstract readonly transform: Mat33;
|
10
|
-
}
|
11
|
-
type TransformChangeCallback = (oldTransform: Mat33, newTransform: Mat33) => void;
|
12
|
-
export declare class Viewport {
|
13
|
-
private onTransformChangeCallback;
|
14
|
-
private static ViewportTransform;
|
15
|
-
private transform;
|
16
|
-
private inverseTransform;
|
17
|
-
private screenRect;
|
18
|
-
constructor(onTransformChangeCallback: TransformChangeCallback);
|
19
|
-
/**
|
20
|
-
* @returns a temporary copy of `this` that does not notify when modified. This is
|
21
|
-
* useful when rendering with a temporarily different viewport.
|
22
|
-
*/
|
23
|
-
getTemporaryClone(): Viewport;
|
24
|
-
updateScreenSize(screenSize: Vec2): void;
|
25
|
-
/** Get the screen's visible region transformed into canvas space. */
|
26
|
-
get visibleRect(): Rect2;
|
27
|
-
/** @returns the given point, but in canvas coordinates */
|
28
|
-
screenToCanvas(screenPoint: Point2): Point2;
|
29
|
-
/** @returns the given point transformed into screen coordinates. */
|
30
|
-
canvasToScreen(canvasPoint: Point2): Point2;
|
31
|
-
/** @returns a command that transforms the canvas by `transform`. */
|
32
|
-
static transformBy(transform: Mat33): ViewportTransform;
|
33
|
-
/**
|
34
|
-
* Updates the transformation directly. Using `transformBy` is preferred.
|
35
|
-
* @param newTransform - should map from canvas coordinates to screen coordinates.
|
36
|
-
*/
|
37
|
-
resetTransform(newTransform?: Mat33): void;
|
38
|
-
get screenToCanvasTransform(): Mat33;
|
39
|
-
get canvasToScreenTransform(): Mat33;
|
40
|
-
/** @returns the size of the visible region in pixels. */
|
41
|
-
getScreenRectSize(): Vec2;
|
42
|
-
/** Alias for `getScreenRectSize`. @deprecated */
|
43
|
-
getResolution(): Vec3;
|
44
|
-
/** @returns the amount a vector on the canvas is scaled to become a vector on the screen. */
|
45
|
-
getScaleFactor(): number;
|
46
|
-
/**
|
47
|
-
* @returns `getScaleFactor()` rounded to the nearest power of 10.
|
48
|
-
* For example, if `getScaleFactor()` returns 101, `getScaleFactorToNearestPowerOfTen()`
|
49
|
-
* should return `100` because `100` is the nearest power of 10 to 101.
|
50
|
-
*/
|
51
|
-
getScaleFactorToNearestPowerOfTen(): number;
|
52
|
-
private getScaleFactorToNearestPowerOf;
|
53
|
-
snapToGrid(canvasPos: Point2): Vec3;
|
54
|
-
/** Returns the size of one screen pixel in canvas units. */
|
55
|
-
getSizeOfPixelOnCanvas(): number;
|
56
|
-
/**
|
57
|
-
* @returns the angle of the canvas in radians.
|
58
|
-
* This is the angle by which the canvas is rotated relative to the screen.
|
59
|
-
*/
|
60
|
-
getRotationAngle(): number;
|
61
|
-
/**
|
62
|
-
* Rounds the given `point` to a multiple of 10 such that it is within `tolerance` of
|
63
|
-
* its original location. This is useful for preparing data for base-10 conversion.
|
64
|
-
*/
|
65
|
-
static roundPoint<T extends Point2 | number>(point: T, tolerance: number): PointDataType<T>;
|
66
|
-
roundPoint(point: Point2): Point2;
|
67
|
-
static roundScaleRatio(scaleRatio: number, roundAmount?: number): number;
|
68
|
-
computeZoomToTransform(toMakeVisible: Rect2, allowZoomIn?: boolean, allowZoomOut?: boolean): Mat33;
|
69
|
-
zoomTo(toMakeVisible: Rect2, allowZoomIn?: boolean, allowZoomOut?: boolean): Command;
|
70
|
-
}
|
71
|
-
export default Viewport;
|
package/dist/src/Viewport.js
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
6
|
-
};
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
|
-
};
|
12
|
-
var _inverseTransform, _a;
|
13
|
-
import Command from './commands/Command';
|
14
|
-
import Mat33 from './math/Mat33';
|
15
|
-
import Rect2 from './math/Rect2';
|
16
|
-
import { Vec2 } from './math/Vec2';
|
17
|
-
import Vec3 from './math/Vec3';
|
18
|
-
export class ViewportTransform extends Command {
|
19
|
-
}
|
20
|
-
export class Viewport {
|
21
|
-
// @internal
|
22
|
-
constructor(onTransformChangeCallback) {
|
23
|
-
this.onTransformChangeCallback = onTransformChangeCallback;
|
24
|
-
this.resetTransform(Mat33.identity);
|
25
|
-
this.screenRect = Rect2.empty;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* @returns a temporary copy of `this` that does not notify when modified. This is
|
29
|
-
* useful when rendering with a temporarily different viewport.
|
30
|
-
*/
|
31
|
-
getTemporaryClone() {
|
32
|
-
const result = new Viewport(() => { });
|
33
|
-
result.transform = this.transform;
|
34
|
-
result.inverseTransform = this.inverseTransform;
|
35
|
-
result.screenRect = this.screenRect;
|
36
|
-
return result;
|
37
|
-
}
|
38
|
-
// @internal
|
39
|
-
updateScreenSize(screenSize) {
|
40
|
-
this.screenRect = this.screenRect.resizedTo(screenSize);
|
41
|
-
}
|
42
|
-
/** Get the screen's visible region transformed into canvas space. */
|
43
|
-
get visibleRect() {
|
44
|
-
return this.screenRect.transformedBoundingBox(this.inverseTransform);
|
45
|
-
}
|
46
|
-
/** @returns the given point, but in canvas coordinates */
|
47
|
-
screenToCanvas(screenPoint) {
|
48
|
-
return this.inverseTransform.transformVec2(screenPoint);
|
49
|
-
}
|
50
|
-
/** @returns the given point transformed into screen coordinates. */
|
51
|
-
canvasToScreen(canvasPoint) {
|
52
|
-
return this.transform.transformVec2(canvasPoint);
|
53
|
-
}
|
54
|
-
/** @returns a command that transforms the canvas by `transform`. */
|
55
|
-
static transformBy(transform) {
|
56
|
-
return new Viewport.ViewportTransform(transform);
|
57
|
-
}
|
58
|
-
/**
|
59
|
-
* Updates the transformation directly. Using `transformBy` is preferred.
|
60
|
-
* @param newTransform - should map from canvas coordinates to screen coordinates.
|
61
|
-
*/
|
62
|
-
resetTransform(newTransform = Mat33.identity) {
|
63
|
-
var _a;
|
64
|
-
const oldTransform = this.transform;
|
65
|
-
this.transform = newTransform;
|
66
|
-
this.inverseTransform = newTransform.inverse();
|
67
|
-
(_a = this.onTransformChangeCallback) === null || _a === void 0 ? void 0 : _a.call(this, oldTransform, newTransform);
|
68
|
-
}
|
69
|
-
get screenToCanvasTransform() {
|
70
|
-
return this.inverseTransform;
|
71
|
-
}
|
72
|
-
get canvasToScreenTransform() {
|
73
|
-
return this.transform;
|
74
|
-
}
|
75
|
-
/** @returns the size of the visible region in pixels. */
|
76
|
-
getScreenRectSize() {
|
77
|
-
return this.screenRect.size;
|
78
|
-
}
|
79
|
-
/** Alias for `getScreenRectSize`. @deprecated */
|
80
|
-
getResolution() {
|
81
|
-
return this.getScreenRectSize();
|
82
|
-
}
|
83
|
-
/** @returns the amount a vector on the canvas is scaled to become a vector on the screen. */
|
84
|
-
getScaleFactor() {
|
85
|
-
// Use transformVec3 to avoid translating the vector
|
86
|
-
return this.transform.transformVec3(Vec3.unitX).magnitude();
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* @returns `getScaleFactor()` rounded to the nearest power of 10.
|
90
|
-
* For example, if `getScaleFactor()` returns 101, `getScaleFactorToNearestPowerOfTen()`
|
91
|
-
* should return `100` because `100` is the nearest power of 10 to 101.
|
92
|
-
*/
|
93
|
-
getScaleFactorToNearestPowerOfTen() {
|
94
|
-
return this.getScaleFactorToNearestPowerOf(10);
|
95
|
-
}
|
96
|
-
getScaleFactorToNearestPowerOf(powerOf) {
|
97
|
-
const scaleFactor = this.getScaleFactor();
|
98
|
-
return Math.pow(powerOf, Math.round(Math.log(scaleFactor) / Math.log(powerOf)));
|
99
|
-
}
|
100
|
-
snapToGrid(canvasPos) {
|
101
|
-
const snapCoordinate = (coordinate) => {
|
102
|
-
const scaleFactor = this.getScaleFactorToNearestPowerOf(2);
|
103
|
-
const roundFactor = scaleFactor / 50;
|
104
|
-
const snapped = Math.round(coordinate * roundFactor) / roundFactor;
|
105
|
-
return snapped;
|
106
|
-
};
|
107
|
-
const snappedCanvasPos = Vec2.of(snapCoordinate(canvasPos.x), snapCoordinate(canvasPos.y));
|
108
|
-
return snappedCanvasPos;
|
109
|
-
}
|
110
|
-
/** Returns the size of one screen pixel in canvas units. */
|
111
|
-
getSizeOfPixelOnCanvas() {
|
112
|
-
return 1 / this.getScaleFactor();
|
113
|
-
}
|
114
|
-
/**
|
115
|
-
* @returns the angle of the canvas in radians.
|
116
|
-
* This is the angle by which the canvas is rotated relative to the screen.
|
117
|
-
*/
|
118
|
-
getRotationAngle() {
|
119
|
-
return this.transform.transformVec3(Vec3.unitX).angle();
|
120
|
-
}
|
121
|
-
// The separate function type definition seems necessary here.
|
122
|
-
// See https://stackoverflow.com/a/58163623/17055750.
|
123
|
-
// eslint-disable-next-line no-dupe-class-members
|
124
|
-
static roundPoint(point, tolerance) {
|
125
|
-
const scaleFactor = Math.pow(10, Math.floor(Math.log10(tolerance)));
|
126
|
-
const roundComponent = (component) => {
|
127
|
-
return Math.round(component / scaleFactor) * scaleFactor;
|
128
|
-
};
|
129
|
-
if (typeof point === 'number') {
|
130
|
-
return roundComponent(point);
|
131
|
-
}
|
132
|
-
return point.map(roundComponent);
|
133
|
-
}
|
134
|
-
// Round a point with a tolerance of ±1 screen unit.
|
135
|
-
roundPoint(point) {
|
136
|
-
return Viewport.roundPoint(point, 1 / this.getScaleFactor());
|
137
|
-
}
|
138
|
-
// `roundAmount`: An integer >= 0, larger numbers cause less rounding. Smaller numbers cause more
|
139
|
-
// (as such `roundAmount = 0` does the most rounding).
|
140
|
-
static roundScaleRatio(scaleRatio, roundAmount = 1) {
|
141
|
-
if (Math.abs(scaleRatio) <= 1e-12) {
|
142
|
-
return 0;
|
143
|
-
}
|
144
|
-
// Represent as k 10ⁿ for some n, k ∈ ℤ.
|
145
|
-
const decimalComponent = Math.pow(10, Math.floor(Math.log10(Math.abs(scaleRatio))));
|
146
|
-
const roundAmountFactor = Math.pow(2, roundAmount);
|
147
|
-
scaleRatio = Math.round(scaleRatio / decimalComponent * roundAmountFactor) / roundAmountFactor * decimalComponent;
|
148
|
-
return scaleRatio;
|
149
|
-
}
|
150
|
-
// Computes and returns an affine transformation that makes `toMakeVisible` visible and roughly centered on the screen.
|
151
|
-
computeZoomToTransform(toMakeVisible, allowZoomIn = true, allowZoomOut = true) {
|
152
|
-
let transform = Mat33.identity;
|
153
|
-
if (toMakeVisible.w === 0 || toMakeVisible.h === 0) {
|
154
|
-
throw new Error(`${toMakeVisible.toString()} rectangle is empty! Cannot zoom to!`);
|
155
|
-
}
|
156
|
-
if (isNaN(toMakeVisible.size.magnitude())) {
|
157
|
-
throw new Error(`${toMakeVisible.toString()} rectangle has NaN size! Cannot zoom to!`);
|
158
|
-
}
|
159
|
-
// Try to move the selection within the center 4/5ths of the viewport.
|
160
|
-
const recomputeTargetRect = () => {
|
161
|
-
// transform transforms objects on the canvas. As such, we need to invert it
|
162
|
-
// to transform the viewport.
|
163
|
-
const visibleRect = this.visibleRect.transformedBoundingBox(transform.inverse());
|
164
|
-
return visibleRect.transformedBoundingBox(Mat33.scaling2D(4 / 5, visibleRect.center));
|
165
|
-
};
|
166
|
-
let targetRect = recomputeTargetRect();
|
167
|
-
const largerThanTarget = targetRect.w < toMakeVisible.w || targetRect.h < toMakeVisible.h;
|
168
|
-
// Ensure that toMakeVisible is at least 1/3rd of the visible region.
|
169
|
-
const muchSmallerThanTarget = toMakeVisible.maxDimension / targetRect.maxDimension < 1 / 3;
|
170
|
-
if ((largerThanTarget && allowZoomOut) || (muchSmallerThanTarget && allowZoomIn)) {
|
171
|
-
const multiplier = Math.max(toMakeVisible.w / targetRect.w, toMakeVisible.h / targetRect.h);
|
172
|
-
const visibleRectTransform = Mat33.scaling2D(multiplier, targetRect.topLeft);
|
173
|
-
const viewportContentTransform = visibleRectTransform.inverse();
|
174
|
-
transform = transform.rightMul(viewportContentTransform);
|
175
|
-
}
|
176
|
-
targetRect = recomputeTargetRect();
|
177
|
-
// Ensure that the center of the region is visible
|
178
|
-
if (!targetRect.containsRect(toMakeVisible)) {
|
179
|
-
// target position - current position
|
180
|
-
const translation = toMakeVisible.center.minus(targetRect.center);
|
181
|
-
const visibleRectTransform = Mat33.translation(translation);
|
182
|
-
const viewportContentTransform = visibleRectTransform.inverse();
|
183
|
-
transform = transform.rightMul(viewportContentTransform);
|
184
|
-
}
|
185
|
-
if (!transform.invertable()) {
|
186
|
-
console.warn('Unable to zoom to ', toMakeVisible, '! Computed transform', transform, 'is singular.');
|
187
|
-
transform = Mat33.identity;
|
188
|
-
}
|
189
|
-
return transform;
|
190
|
-
}
|
191
|
-
// Returns a Command that transforms the view such that [rect] is visible, and perhaps
|
192
|
-
// centered in the viewport.
|
193
|
-
// Returns null if no transformation is necessary
|
194
|
-
//
|
195
|
-
// @see {@link computeZoomToTransform}
|
196
|
-
zoomTo(toMakeVisible, allowZoomIn = true, allowZoomOut = true) {
|
197
|
-
const transform = this.computeZoomToTransform(toMakeVisible, allowZoomIn, allowZoomOut);
|
198
|
-
return new Viewport.ViewportTransform(transform);
|
199
|
-
}
|
200
|
-
}
|
201
|
-
// Command that translates/scales the viewport.
|
202
|
-
Viewport.ViewportTransform = (_a = class extends ViewportTransform {
|
203
|
-
constructor(transform) {
|
204
|
-
super();
|
205
|
-
this.transform = transform;
|
206
|
-
_inverseTransform.set(this, void 0);
|
207
|
-
__classPrivateFieldSet(this, _inverseTransform, transform.inverse(), "f");
|
208
|
-
}
|
209
|
-
apply(editor) {
|
210
|
-
const viewport = editor.viewport;
|
211
|
-
viewport.resetTransform(viewport.transform.rightMul(this.transform));
|
212
|
-
editor.queueRerender();
|
213
|
-
}
|
214
|
-
unapply(editor) {
|
215
|
-
const viewport = editor.viewport;
|
216
|
-
viewport.resetTransform(viewport.transform.rightMul(__classPrivateFieldGet(this, _inverseTransform, "f")));
|
217
|
-
editor.queueRerender();
|
218
|
-
}
|
219
|
-
description(editor, localizationTable) {
|
220
|
-
const result = [];
|
221
|
-
// Describe the transformation's affect on the viewport (note that transformation transforms
|
222
|
-
// the **elements** within the viewport). Assumes the transformation only does rotation/scale/translation.
|
223
|
-
const origVec = editor.viewport.visibleRect.center;
|
224
|
-
const linearTransformedVec = this.transform.transformVec3(Vec2.unitX);
|
225
|
-
const affineTransformedVec = this.transform.transformVec2(origVec);
|
226
|
-
const scale = linearTransformedVec.magnitude();
|
227
|
-
const rotation = 180 / Math.PI * linearTransformedVec.angle();
|
228
|
-
const translation = affineTransformedVec.minus(origVec);
|
229
|
-
if (scale > 1.2) {
|
230
|
-
result.push(localizationTable.zoomedIn);
|
231
|
-
}
|
232
|
-
else if (scale < 0.8) {
|
233
|
-
result.push(localizationTable.zoomedOut);
|
234
|
-
}
|
235
|
-
if (Math.floor(Math.abs(rotation)) > 0) {
|
236
|
-
result.push(localizationTable.rotatedBy(Math.round(rotation)));
|
237
|
-
}
|
238
|
-
const minTranslation = 1e-4;
|
239
|
-
if (translation.x > minTranslation) {
|
240
|
-
result.push(localizationTable.movedLeft);
|
241
|
-
}
|
242
|
-
else if (translation.x < -minTranslation) {
|
243
|
-
result.push(localizationTable.movedRight);
|
244
|
-
}
|
245
|
-
if (translation.y < -minTranslation) {
|
246
|
-
result.push(localizationTable.movedDown);
|
247
|
-
}
|
248
|
-
else if (translation.y > minTranslation) {
|
249
|
-
result.push(localizationTable.movedUp);
|
250
|
-
}
|
251
|
-
return result.join('; ');
|
252
|
-
}
|
253
|
-
},
|
254
|
-
_inverseTransform = new WeakMap(),
|
255
|
-
_a);
|
256
|
-
export default Viewport;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import Editor from '../Editor';
|
2
|
-
import { EditorLocalization } from '../localization';
|
3
|
-
export declare abstract class Command {
|
4
|
-
abstract apply(editor: Editor): Promise<void> | void;
|
5
|
-
abstract unapply(editor: Editor): Promise<void> | void;
|
6
|
-
onDrop(_editor: Editor): void;
|
7
|
-
abstract description(editor: Editor, localizationTable: EditorLocalization): string;
|
8
|
-
static union(a: Command, b: Command): Command;
|
9
|
-
static readonly empty: {
|
10
|
-
description(_editor: Editor, _localizationTable: EditorLocalization): string;
|
11
|
-
apply(_editor: Editor): void;
|
12
|
-
unapply(_editor: Editor): void;
|
13
|
-
onDrop(_editor: Editor): void;
|
14
|
-
};
|
15
|
-
}
|
16
|
-
export default Command;
|
@@ -1,30 +0,0 @@
|
|
1
|
-
export class Command {
|
2
|
-
// Called when the command is being deleted
|
3
|
-
onDrop(_editor) { }
|
4
|
-
static union(a, b) {
|
5
|
-
return new class extends Command {
|
6
|
-
apply(editor) {
|
7
|
-
a.apply(editor);
|
8
|
-
b.apply(editor);
|
9
|
-
}
|
10
|
-
unapply(editor) {
|
11
|
-
b.unapply(editor);
|
12
|
-
a.unapply(editor);
|
13
|
-
}
|
14
|
-
description(editor, localizationTable) {
|
15
|
-
const aDescription = a.description(editor, localizationTable);
|
16
|
-
const bDescription = b.description(editor, localizationTable);
|
17
|
-
if (aDescription === bDescription) {
|
18
|
-
return aDescription;
|
19
|
-
}
|
20
|
-
return `${aDescription}, ${bDescription}`;
|
21
|
-
}
|
22
|
-
};
|
23
|
-
}
|
24
|
-
}
|
25
|
-
Command.empty = new class extends Command {
|
26
|
-
description(_editor, _localizationTable) { return ''; }
|
27
|
-
apply(_editor) { }
|
28
|
-
unapply(_editor) { }
|
29
|
-
};
|
30
|
-
export default Command;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import AbstractComponent from '../components/AbstractComponent';
|
2
|
-
import Editor from '../Editor';
|
3
|
-
import { EditorLocalization } from '../localization';
|
4
|
-
import SerializableCommand from './SerializableCommand';
|
5
|
-
export default class Duplicate extends SerializableCommand {
|
6
|
-
private toDuplicate;
|
7
|
-
private duplicates;
|
8
|
-
private reverse;
|
9
|
-
constructor(toDuplicate: AbstractComponent[]);
|
10
|
-
apply(editor: Editor): void;
|
11
|
-
unapply(editor: Editor): void;
|
12
|
-
description(_editor: Editor, localizationTable: EditorLocalization): string;
|
13
|
-
protected serializeToJSON(): string[];
|
14
|
-
}
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import describeComponentList from '../components/util/describeComponentList';
|
2
|
-
import Erase from './Erase';
|
3
|
-
import SerializableCommand from './SerializableCommand';
|
4
|
-
export default class Duplicate extends SerializableCommand {
|
5
|
-
constructor(toDuplicate) {
|
6
|
-
super('duplicate');
|
7
|
-
this.toDuplicate = toDuplicate;
|
8
|
-
this.duplicates = toDuplicate.map(elem => elem.clone());
|
9
|
-
this.reverse = new Erase(this.duplicates);
|
10
|
-
}
|
11
|
-
apply(editor) {
|
12
|
-
this.reverse.unapply(editor);
|
13
|
-
}
|
14
|
-
unapply(editor) {
|
15
|
-
this.reverse.apply(editor);
|
16
|
-
}
|
17
|
-
description(_editor, localizationTable) {
|
18
|
-
var _a;
|
19
|
-
if (this.duplicates.length === 0) {
|
20
|
-
return localizationTable.duplicatedNoElements;
|
21
|
-
}
|
22
|
-
return localizationTable.duplicateAction((_a = describeComponentList(localizationTable, this.duplicates)) !== null && _a !== void 0 ? _a : localizationTable.elements, this.duplicates.length);
|
23
|
-
}
|
24
|
-
serializeToJSON() {
|
25
|
-
return this.toDuplicate.map(elem => elem.getId());
|
26
|
-
}
|
27
|
-
}
|
28
|
-
(() => {
|
29
|
-
SerializableCommand.register('duplicate', (json, editor) => {
|
30
|
-
const elems = json.map((id) => editor.image.lookupElement(id));
|
31
|
-
return new Duplicate(elems);
|
32
|
-
});
|
33
|
-
})();
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import AbstractComponent from '../components/AbstractComponent';
|
2
|
-
import Editor from '../Editor';
|
3
|
-
import { EditorLocalization } from '../localization';
|
4
|
-
import SerializableCommand from './SerializableCommand';
|
5
|
-
export default class Erase extends SerializableCommand {
|
6
|
-
private toRemove;
|
7
|
-
private applied;
|
8
|
-
constructor(toRemove: AbstractComponent[]);
|
9
|
-
apply(editor: Editor): void;
|
10
|
-
unapply(editor: Editor): void;
|
11
|
-
onDrop(editor: Editor): void;
|
12
|
-
description(_editor: Editor, localizationTable: EditorLocalization): string;
|
13
|
-
protected serializeToJSON(): string[];
|
14
|
-
}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import describeComponentList from '../components/util/describeComponentList';
|
2
|
-
import EditorImage from '../EditorImage';
|
3
|
-
import SerializableCommand from './SerializableCommand';
|
4
|
-
export default class Erase extends SerializableCommand {
|
5
|
-
constructor(toRemove) {
|
6
|
-
super('erase');
|
7
|
-
// Clone the list
|
8
|
-
this.toRemove = toRemove.map(elem => elem);
|
9
|
-
this.applied = false;
|
10
|
-
}
|
11
|
-
apply(editor) {
|
12
|
-
for (const part of this.toRemove) {
|
13
|
-
const parent = editor.image.findParent(part);
|
14
|
-
if (parent) {
|
15
|
-
parent.remove();
|
16
|
-
}
|
17
|
-
}
|
18
|
-
this.applied = true;
|
19
|
-
editor.queueRerender();
|
20
|
-
}
|
21
|
-
unapply(editor) {
|
22
|
-
for (const part of this.toRemove) {
|
23
|
-
if (!editor.image.findParent(part)) {
|
24
|
-
EditorImage.addElement(part).apply(editor);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
this.applied = false;
|
28
|
-
editor.queueRerender();
|
29
|
-
}
|
30
|
-
onDrop(editor) {
|
31
|
-
if (this.applied) {
|
32
|
-
for (const part of this.toRemove) {
|
33
|
-
editor.image.onDestroyElement(part);
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
description(_editor, localizationTable) {
|
38
|
-
var _a;
|
39
|
-
if (this.toRemove.length === 0) {
|
40
|
-
return localizationTable.erasedNoElements;
|
41
|
-
}
|
42
|
-
const description = (_a = describeComponentList(localizationTable, this.toRemove)) !== null && _a !== void 0 ? _a : localizationTable.elements;
|
43
|
-
return localizationTable.eraseAction(description, this.toRemove.length);
|
44
|
-
}
|
45
|
-
serializeToJSON() {
|
46
|
-
const elemIds = this.toRemove.map(elem => elem.getId());
|
47
|
-
return elemIds;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
(() => {
|
51
|
-
SerializableCommand.register('erase', (json, editor) => {
|
52
|
-
const elems = json
|
53
|
-
.map((elemId) => editor.image.lookupElement(elemId))
|
54
|
-
.filter((elem) => elem !== null);
|
55
|
-
return new Erase(elems);
|
56
|
-
});
|
57
|
-
})();
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import Editor from '../Editor';
|
2
|
-
import Command from './Command';
|
3
|
-
export type DeserializationCallback = (data: Record<string, any> | any[], editor: Editor) => SerializableCommand;
|
4
|
-
export default abstract class SerializableCommand extends Command {
|
5
|
-
private commandTypeId;
|
6
|
-
constructor(commandTypeId: string);
|
7
|
-
protected abstract serializeToJSON(): string | Record<string, any> | any[];
|
8
|
-
private static deserializationCallbacks;
|
9
|
-
serialize(): Record<string | symbol, any>;
|
10
|
-
static deserialize(data: string | Record<string, any>, editor: Editor): SerializableCommand;
|
11
|
-
static register(commandTypeId: string, deserialize: DeserializationCallback): void;
|
12
|
-
}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
import Command from './Command';
|
2
|
-
export default class SerializableCommand extends Command {
|
3
|
-
constructor(commandTypeId) {
|
4
|
-
super();
|
5
|
-
this.commandTypeId = commandTypeId;
|
6
|
-
if (!(commandTypeId in SerializableCommand.deserializationCallbacks)) {
|
7
|
-
throw new Error(`Command ${commandTypeId} must have a registered deserialization callback. To do this, call SerializableCommand.register.`);
|
8
|
-
}
|
9
|
-
}
|
10
|
-
// Convert this command to an object that can be passed to `JSON.stringify`.
|
11
|
-
//
|
12
|
-
// Do not rely on the stability of the optupt of this function — it can change
|
13
|
-
// form without a major version increase.
|
14
|
-
serialize() {
|
15
|
-
return {
|
16
|
-
data: this.serializeToJSON(),
|
17
|
-
commandType: this.commandTypeId,
|
18
|
-
};
|
19
|
-
}
|
20
|
-
// Convert a `string` containing JSON data (or the output of `JSON.parse`) into a
|
21
|
-
// `Command`.
|
22
|
-
static deserialize(data, editor) {
|
23
|
-
const json = typeof data === 'string' ? JSON.parse(data) : data;
|
24
|
-
const commandType = json.commandType;
|
25
|
-
if (!(commandType in SerializableCommand.deserializationCallbacks)) {
|
26
|
-
throw new Error(`Unrecognised command type ${commandType}!`);
|
27
|
-
}
|
28
|
-
return SerializableCommand.deserializationCallbacks[commandType](json.data, editor);
|
29
|
-
}
|
30
|
-
// Register a deserialization callback. This must be called at least once for every subclass of
|
31
|
-
// `SerializableCommand`.
|
32
|
-
static register(commandTypeId, deserialize) {
|
33
|
-
SerializableCommand.deserializationCallbacks[commandTypeId] = deserialize;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
SerializableCommand.deserializationCallbacks = {};
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import EditorImage from '../EditorImage';
|
2
|
-
import AbstractComponent from '../components/AbstractComponent';
|
3
|
-
import SerializableCommand from './SerializableCommand';
|
4
|
-
export type ResolveFromComponentCallback = () => SerializableCommand;
|
5
|
-
/**
|
6
|
-
* A command that requires a component that may or may not be present in the editor when
|
7
|
-
* the command is created.
|
8
|
-
*/
|
9
|
-
export default abstract class UnresolvedSerializableCommand extends SerializableCommand {
|
10
|
-
protected component: AbstractComponent | null;
|
11
|
-
protected readonly componentID: string;
|
12
|
-
protected constructor(commandId: string, componentID: string, component?: AbstractComponent);
|
13
|
-
protected resolveComponent(image: EditorImage): void;
|
14
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import SerializableCommand from './SerializableCommand';
|
2
|
-
/**
|
3
|
-
* A command that requires a component that may or may not be present in the editor when
|
4
|
-
* the command is created.
|
5
|
-
*/
|
6
|
-
export default class UnresolvedSerializableCommand extends SerializableCommand {
|
7
|
-
constructor(commandId, componentID, component) {
|
8
|
-
super(commandId);
|
9
|
-
this.component = component !== null && component !== void 0 ? component : null;
|
10
|
-
this.componentID = componentID;
|
11
|
-
}
|
12
|
-
resolveComponent(image) {
|
13
|
-
if (this.component) {
|
14
|
-
return;
|
15
|
-
}
|
16
|
-
const component = image.lookupElement(this.componentID);
|
17
|
-
if (!component) {
|
18
|
-
throw new Error(`Unable to resolve component with ID ${this.componentID}`);
|
19
|
-
}
|
20
|
-
this.component = component;
|
21
|
-
}
|
22
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import Command from './Command';
|
2
|
-
import SerializableCommand from './SerializableCommand';
|
3
|
-
// Returns a command that does the opposite of the given command --- `result.apply()` calls
|
4
|
-
// `command.unapply()` and `result.unapply()` calls `command.apply()`.
|
5
|
-
const invertCommand = (command) => {
|
6
|
-
if (command instanceof SerializableCommand) {
|
7
|
-
// SerializableCommand that does the inverse of [command]
|
8
|
-
return new class extends SerializableCommand {
|
9
|
-
serializeToJSON() {
|
10
|
-
return command.serialize();
|
11
|
-
}
|
12
|
-
apply(editor) {
|
13
|
-
command.unapply(editor);
|
14
|
-
}
|
15
|
-
unapply(editor) {
|
16
|
-
command.unapply(editor);
|
17
|
-
}
|
18
|
-
description(editor, localizationTable) {
|
19
|
-
return localizationTable.inverseOf(command.description(editor, localizationTable));
|
20
|
-
}
|
21
|
-
}('inverse');
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
// Command that does the inverse of [command].
|
25
|
-
const result = new class extends Command {
|
26
|
-
apply(editor) {
|
27
|
-
command.unapply(editor);
|
28
|
-
}
|
29
|
-
unapply(editor) {
|
30
|
-
command.apply(editor);
|
31
|
-
}
|
32
|
-
description(editor, localizationTable) {
|
33
|
-
return localizationTable.inverseOf(command.description(editor, localizationTable));
|
34
|
-
}
|
35
|
-
};
|
36
|
-
// We know that T does not extend SerializableCommand, and thus returning a Command
|
37
|
-
// is appropriate.
|
38
|
-
return result;
|
39
|
-
}
|
40
|
-
};
|
41
|
-
SerializableCommand.register('inverse', (data, editor) => {
|
42
|
-
return invertCommand(SerializableCommand.deserialize(data, editor));
|
43
|
-
});
|
44
|
-
export default invertCommand;
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import Command from './Command';
|
2
|
-
import Duplicate from './Duplicate';
|
3
|
-
import Erase from './Erase';
|
4
|
-
import invertCommand from './invertCommand';
|
5
|
-
import SerializableCommand from './SerializableCommand';
|
6
|
-
import uniteCommands from './uniteCommands';
|
7
|
-
export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands, };
|