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
@@ -1,252 +0,0 @@
|
|
1
|
-
import LineSegment2 from '../math/LineSegment2';
|
2
|
-
import Mat33 from '../math/Mat33';
|
3
|
-
import Rect2 from '../math/Rect2';
|
4
|
-
import { Vec2 } from '../math/Vec2';
|
5
|
-
import { cloneTextStyle, textStyleFromJSON, textStyleToJSON } from '../rendering/TextRenderingStyle';
|
6
|
-
import AbstractComponent from './AbstractComponent';
|
7
|
-
import { createRestyleComponentCommand } from './RestylableComponent';
|
8
|
-
const componentTypeId = 'text';
|
9
|
-
export default class TextComponent extends AbstractComponent {
|
10
|
-
constructor(textObjects, transform, style) {
|
11
|
-
super(componentTypeId);
|
12
|
-
this.textObjects = textObjects;
|
13
|
-
this.transform = transform;
|
14
|
-
this.style = style;
|
15
|
-
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
16
|
-
this.isRestylableComponent = true;
|
17
|
-
this.recomputeBBox();
|
18
|
-
// If this has no direct children, choose a style representative of this' content
|
19
|
-
// (useful for estimating the style of the TextComponent).
|
20
|
-
const hasDirectContent = textObjects.some(obj => typeof obj === 'string');
|
21
|
-
if (!hasDirectContent && textObjects.length > 0) {
|
22
|
-
this.style = textObjects[0].getTextStyle();
|
23
|
-
}
|
24
|
-
}
|
25
|
-
static applyTextStyles(ctx, style) {
|
26
|
-
var _a, _b;
|
27
|
-
// Quote the font family if necessary.
|
28
|
-
const fontFamily = style.fontFamily.match(/\s/) ? style.fontFamily.replace(/["]/g, '\\"') : style.fontFamily;
|
29
|
-
ctx.font = [
|
30
|
-
((_a = style.size) !== null && _a !== void 0 ? _a : 12) + 'px',
|
31
|
-
(_b = style.fontWeight) !== null && _b !== void 0 ? _b : '',
|
32
|
-
`${fontFamily}`,
|
33
|
-
style.fontWeight
|
34
|
-
].join(' ');
|
35
|
-
ctx.textAlign = 'left';
|
36
|
-
}
|
37
|
-
// Roughly estimate the bounding box of `text`. Use if no CanvasRenderingContext2D is available.
|
38
|
-
static estimateTextDimens(text, style) {
|
39
|
-
const widthEst = text.length * style.size;
|
40
|
-
const heightEst = style.size;
|
41
|
-
// Text is drawn with (0, 0) as its baseline. As such, the majority of the text's height should
|
42
|
-
// be above (0, 0).
|
43
|
-
return new Rect2(0, -heightEst * 2 / 3, widthEst, heightEst);
|
44
|
-
}
|
45
|
-
// Returns the bounding box of `text`. This is approximate if no Canvas is available.
|
46
|
-
static getTextDimens(text, style) {
|
47
|
-
var _a, _b;
|
48
|
-
(_a = TextComponent.textMeasuringCtx) !== null && _a !== void 0 ? _a : (TextComponent.textMeasuringCtx = (_b = document.createElement('canvas').getContext('2d')) !== null && _b !== void 0 ? _b : null);
|
49
|
-
if (!TextComponent.textMeasuringCtx) {
|
50
|
-
return this.estimateTextDimens(text, style);
|
51
|
-
}
|
52
|
-
const ctx = TextComponent.textMeasuringCtx;
|
53
|
-
TextComponent.applyTextStyles(ctx, style);
|
54
|
-
const measure = ctx.measureText(text);
|
55
|
-
// Text is drawn with (0,0) at the bottom left of the baseline.
|
56
|
-
const textY = -measure.actualBoundingBoxAscent;
|
57
|
-
const textHeight = measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent;
|
58
|
-
return new Rect2(0, textY, measure.width, textHeight);
|
59
|
-
}
|
60
|
-
computeBBoxOfPart(part) {
|
61
|
-
if (typeof part === 'string') {
|
62
|
-
const textBBox = TextComponent.getTextDimens(part, this.style);
|
63
|
-
return textBBox.transformedBoundingBox(this.transform);
|
64
|
-
}
|
65
|
-
else {
|
66
|
-
const bbox = part.contentBBox.transformedBoundingBox(this.transform);
|
67
|
-
return bbox;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
recomputeBBox() {
|
71
|
-
let bbox = null;
|
72
|
-
for (const textObject of this.textObjects) {
|
73
|
-
const currentBBox = this.computeBBoxOfPart(textObject);
|
74
|
-
bbox !== null && bbox !== void 0 ? bbox : (bbox = currentBBox);
|
75
|
-
bbox = bbox.union(currentBBox);
|
76
|
-
}
|
77
|
-
this.contentBBox = bbox !== null && bbox !== void 0 ? bbox : Rect2.empty;
|
78
|
-
}
|
79
|
-
renderInternal(canvas) {
|
80
|
-
const cursor = this.transform;
|
81
|
-
for (const textObject of this.textObjects) {
|
82
|
-
if (typeof textObject === 'string') {
|
83
|
-
canvas.drawText(textObject, cursor, this.style);
|
84
|
-
}
|
85
|
-
else {
|
86
|
-
canvas.pushTransform(cursor);
|
87
|
-
textObject.renderInternal(canvas);
|
88
|
-
canvas.popTransform();
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
render(canvas, _visibleRect) {
|
93
|
-
canvas.startObject(this.contentBBox);
|
94
|
-
this.renderInternal(canvas);
|
95
|
-
canvas.endObject(this.getLoadSaveData());
|
96
|
-
}
|
97
|
-
getProportionalRenderingTime() {
|
98
|
-
return this.textObjects.length;
|
99
|
-
}
|
100
|
-
intersects(lineSegment) {
|
101
|
-
// Convert canvas space to internal space.
|
102
|
-
const invTransform = this.transform.inverse();
|
103
|
-
const p1InThisSpace = invTransform.transformVec2(lineSegment.p1);
|
104
|
-
const p2InThisSpace = invTransform.transformVec2(lineSegment.p2);
|
105
|
-
lineSegment = new LineSegment2(p1InThisSpace, p2InThisSpace);
|
106
|
-
for (const subObject of this.textObjects) {
|
107
|
-
if (typeof subObject === 'string') {
|
108
|
-
const textBBox = TextComponent.getTextDimens(subObject, this.style);
|
109
|
-
// TODO: Use a better intersection check. Perhaps draw the text onto a CanvasElement and
|
110
|
-
// use pixel-testing to check for intersection with its contour.
|
111
|
-
if (textBBox.getEdges().some(edge => lineSegment.intersection(edge) !== null)) {
|
112
|
-
return true;
|
113
|
-
}
|
114
|
-
}
|
115
|
-
else {
|
116
|
-
if (subObject.intersects(lineSegment)) {
|
117
|
-
return true;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
return false;
|
122
|
-
}
|
123
|
-
getStyle() {
|
124
|
-
return {
|
125
|
-
color: this.style.renderingStyle.fill,
|
126
|
-
// Make a copy
|
127
|
-
textStyle: Object.assign(Object.assign({}, this.style), { renderingStyle: Object.assign({}, this.style.renderingStyle) }),
|
128
|
-
};
|
129
|
-
}
|
130
|
-
updateStyle(style) {
|
131
|
-
return createRestyleComponentCommand(this.getStyle(), style, this);
|
132
|
-
}
|
133
|
-
forceStyle(style, editor) {
|
134
|
-
if (style.textStyle) {
|
135
|
-
this.style = cloneTextStyle(style.textStyle);
|
136
|
-
}
|
137
|
-
else if (style.color) {
|
138
|
-
this.style = Object.assign(Object.assign({}, this.style), { renderingStyle: Object.assign(Object.assign({}, this.style.renderingStyle), { fill: style.color }) });
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
return;
|
142
|
-
}
|
143
|
-
for (const child of this.textObjects) {
|
144
|
-
if (child instanceof TextComponent) {
|
145
|
-
child.forceStyle(style, editor);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
if (editor) {
|
149
|
-
editor.image.queueRerenderOf(this);
|
150
|
-
editor.queueRerender();
|
151
|
-
}
|
152
|
-
}
|
153
|
-
// See this.getStyle
|
154
|
-
getTextStyle() {
|
155
|
-
return cloneTextStyle(this.style);
|
156
|
-
}
|
157
|
-
getBaselinePos() {
|
158
|
-
return this.transform.transformVec2(Vec2.zero);
|
159
|
-
}
|
160
|
-
getTransform() {
|
161
|
-
return this.transform;
|
162
|
-
}
|
163
|
-
applyTransformation(affineTransfm) {
|
164
|
-
this.transform = affineTransfm.rightMul(this.transform);
|
165
|
-
this.recomputeBBox();
|
166
|
-
}
|
167
|
-
createClone() {
|
168
|
-
const clonedTextObjects = this.textObjects.map(obj => {
|
169
|
-
if (typeof obj === 'string') {
|
170
|
-
return obj;
|
171
|
-
}
|
172
|
-
else {
|
173
|
-
return obj.createClone();
|
174
|
-
}
|
175
|
-
});
|
176
|
-
return new TextComponent(clonedTextObjects, this.transform, this.style);
|
177
|
-
}
|
178
|
-
getText() {
|
179
|
-
const result = [];
|
180
|
-
for (const textObject of this.textObjects) {
|
181
|
-
if (typeof textObject === 'string') {
|
182
|
-
result.push(textObject);
|
183
|
-
}
|
184
|
-
else {
|
185
|
-
result.push(textObject.getText());
|
186
|
-
}
|
187
|
-
}
|
188
|
-
return result.join('\n');
|
189
|
-
}
|
190
|
-
description(localizationTable) {
|
191
|
-
return localizationTable.text(this.getText());
|
192
|
-
}
|
193
|
-
// Do not rely on the output of `serializeToJSON` taking any particular format.
|
194
|
-
serializeToJSON() {
|
195
|
-
const serializableStyle = textStyleToJSON(this.style);
|
196
|
-
const serializedTextObjects = this.textObjects.map(text => {
|
197
|
-
if (typeof text === 'string') {
|
198
|
-
return {
|
199
|
-
text,
|
200
|
-
};
|
201
|
-
}
|
202
|
-
else {
|
203
|
-
return {
|
204
|
-
json: text.serializeToJSON(),
|
205
|
-
};
|
206
|
-
}
|
207
|
-
});
|
208
|
-
return {
|
209
|
-
textObjects: serializedTextObjects,
|
210
|
-
transform: this.transform.toArray(),
|
211
|
-
style: serializableStyle,
|
212
|
-
};
|
213
|
-
}
|
214
|
-
// @internal
|
215
|
-
static deserializeFromString(json) {
|
216
|
-
if (typeof json === 'string') {
|
217
|
-
json = JSON.parse(json);
|
218
|
-
}
|
219
|
-
const style = textStyleFromJSON(json.style);
|
220
|
-
const textObjects = json.textObjects.map((data) => {
|
221
|
-
var _a;
|
222
|
-
if (((_a = data.text) !== null && _a !== void 0 ? _a : null) !== null) {
|
223
|
-
return data.text;
|
224
|
-
}
|
225
|
-
return TextComponent.deserializeFromString(data.json);
|
226
|
-
});
|
227
|
-
json.transform = json.transform.filter((elem) => typeof elem === 'number');
|
228
|
-
if (json.transform.length !== 9) {
|
229
|
-
throw new Error(`Unable to deserialize transform, ${json.transform}.`);
|
230
|
-
}
|
231
|
-
const transformData = json.transform;
|
232
|
-
const transform = new Mat33(...transformData);
|
233
|
-
return new TextComponent(textObjects, transform, style);
|
234
|
-
}
|
235
|
-
static fromLines(lines, transform, style) {
|
236
|
-
let lastComponent = null;
|
237
|
-
const components = [];
|
238
|
-
for (const line of lines) {
|
239
|
-
let position = Vec2.zero;
|
240
|
-
if (lastComponent) {
|
241
|
-
const lineMargin = Math.floor(style.size);
|
242
|
-
position = lastComponent.getBBox().bottomLeft.plus(Vec2.unitY.times(lineMargin));
|
243
|
-
}
|
244
|
-
const component = new TextComponent([line], Mat33.translation(position), style);
|
245
|
-
components.push(component);
|
246
|
-
lastComponent = component;
|
247
|
-
}
|
248
|
-
return new TextComponent(components, transform, style);
|
249
|
-
}
|
250
|
-
}
|
251
|
-
TextComponent.textMeasuringCtx = null;
|
252
|
-
AbstractComponent.registerComponent(componentTypeId, (data) => TextComponent.deserializeFromString(data));
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import LineSegment2 from '../math/LineSegment2';
|
2
|
-
import Mat33 from '../math/Mat33';
|
3
|
-
import Rect2 from '../math/Rect2';
|
4
|
-
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
5
|
-
import AbstractComponent from './AbstractComponent';
|
6
|
-
import { ImageComponentLocalization } from './localization';
|
7
|
-
export default class UnknownSVGObject extends AbstractComponent {
|
8
|
-
private svgObject;
|
9
|
-
protected contentBBox: Rect2;
|
10
|
-
constructor(svgObject: SVGElement);
|
11
|
-
render(canvas: AbstractRenderer, _visibleRect?: Rect2): void;
|
12
|
-
intersects(lineSegment: LineSegment2): boolean;
|
13
|
-
protected applyTransformation(_affineTransfm: Mat33): void;
|
14
|
-
isSelectable(): boolean;
|
15
|
-
protected createClone(): AbstractComponent;
|
16
|
-
description(localization: ImageComponentLocalization): string;
|
17
|
-
protected serializeToJSON(): string | null;
|
18
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Stores objects loaded from an SVG that aren't recognised by the editor.
|
3
|
-
// @internal
|
4
|
-
// @packageDocumentation
|
5
|
-
//
|
6
|
-
import Rect2 from '../math/Rect2';
|
7
|
-
import SVGRenderer from '../rendering/renderers/SVGRenderer';
|
8
|
-
import AbstractComponent from './AbstractComponent';
|
9
|
-
const componentId = 'unknown-svg-object';
|
10
|
-
export default class UnknownSVGObject extends AbstractComponent {
|
11
|
-
constructor(svgObject) {
|
12
|
-
super(componentId);
|
13
|
-
this.svgObject = svgObject;
|
14
|
-
this.contentBBox = Rect2.of(svgObject.getBoundingClientRect());
|
15
|
-
}
|
16
|
-
render(canvas, _visibleRect) {
|
17
|
-
if (!(canvas instanceof SVGRenderer)) {
|
18
|
-
// Don't draw unrenderable objects if we can't
|
19
|
-
return;
|
20
|
-
}
|
21
|
-
canvas.drawSVGElem(this.svgObject);
|
22
|
-
}
|
23
|
-
intersects(lineSegment) {
|
24
|
-
return this.contentBBox.getEdges().some(edge => edge.intersection(lineSegment) !== null);
|
25
|
-
}
|
26
|
-
applyTransformation(_affineTransfm) {
|
27
|
-
}
|
28
|
-
isSelectable() {
|
29
|
-
return false;
|
30
|
-
}
|
31
|
-
createClone() {
|
32
|
-
return new UnknownSVGObject(this.svgObject.cloneNode(true));
|
33
|
-
}
|
34
|
-
description(localization) {
|
35
|
-
return localization.svgObject;
|
36
|
-
}
|
37
|
-
serializeToJSON() {
|
38
|
-
return JSON.stringify({
|
39
|
-
html: this.svgObject.outerHTML,
|
40
|
-
});
|
41
|
-
}
|
42
|
-
}
|
43
|
-
// null: Do not deserialize UnknownSVGObjects.
|
44
|
-
AbstractComponent.registerComponent(componentId, null);
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import Rect2 from '../../math/Rect2';
|
2
|
-
import AbstractRenderer from '../../rendering/renderers/AbstractRenderer';
|
3
|
-
import { StrokeDataPoint } from '../../types';
|
4
|
-
import Viewport from '../../Viewport';
|
5
|
-
import AbstractComponent from '../AbstractComponent';
|
6
|
-
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
7
|
-
export declare const makeArrowBuilder: ComponentBuilderFactory;
|
8
|
-
export default class ArrowBuilder implements ComponentBuilder {
|
9
|
-
private readonly startPoint;
|
10
|
-
private readonly viewport;
|
11
|
-
private endPoint;
|
12
|
-
constructor(startPoint: StrokeDataPoint, viewport: Viewport);
|
13
|
-
private getLineWidth;
|
14
|
-
getBBox(): Rect2;
|
15
|
-
private buildPreview;
|
16
|
-
build(): AbstractComponent;
|
17
|
-
preview(renderer: AbstractRenderer): void;
|
18
|
-
addPoint(point: StrokeDataPoint): void;
|
19
|
-
}
|
@@ -1,86 +0,0 @@
|
|
1
|
-
import Path, { PathCommandType } from '../../math/Path';
|
2
|
-
import Stroke from '../Stroke';
|
3
|
-
export const makeArrowBuilder = (initialPoint, viewport) => {
|
4
|
-
return new ArrowBuilder(initialPoint, viewport);
|
5
|
-
};
|
6
|
-
export default class ArrowBuilder {
|
7
|
-
constructor(startPoint, viewport) {
|
8
|
-
this.startPoint = startPoint;
|
9
|
-
this.viewport = viewport;
|
10
|
-
this.endPoint = startPoint;
|
11
|
-
}
|
12
|
-
getLineWidth() {
|
13
|
-
return Math.max(this.endPoint.width, this.startPoint.width);
|
14
|
-
}
|
15
|
-
getBBox() {
|
16
|
-
const preview = this.buildPreview();
|
17
|
-
return preview.getBBox();
|
18
|
-
}
|
19
|
-
buildPreview() {
|
20
|
-
const lineStartPoint = this.startPoint.pos;
|
21
|
-
const endPoint = this.endPoint.pos;
|
22
|
-
const toEnd = endPoint.minus(lineStartPoint).normalized();
|
23
|
-
const arrowLength = endPoint.minus(lineStartPoint).length();
|
24
|
-
// Ensure that the arrow tip is smaller than the arrow.
|
25
|
-
const arrowTipSize = Math.min(this.getLineWidth(), arrowLength / 2);
|
26
|
-
const startSize = this.startPoint.width / 2;
|
27
|
-
const endSize = this.endPoint.width / 2;
|
28
|
-
const arrowTipBase = endPoint.minus(toEnd.times(arrowTipSize));
|
29
|
-
// Scaled normal vectors.
|
30
|
-
const lineNormal = toEnd.orthog();
|
31
|
-
const scaledStartNormal = lineNormal.times(startSize);
|
32
|
-
const scaledBaseNormal = lineNormal.times(endSize);
|
33
|
-
const path = new Path(arrowTipBase.minus(scaledBaseNormal), [
|
34
|
-
// Stem
|
35
|
-
{
|
36
|
-
kind: PathCommandType.LineTo,
|
37
|
-
point: lineStartPoint.minus(scaledStartNormal),
|
38
|
-
},
|
39
|
-
{
|
40
|
-
kind: PathCommandType.LineTo,
|
41
|
-
point: lineStartPoint.plus(scaledStartNormal),
|
42
|
-
},
|
43
|
-
{
|
44
|
-
kind: PathCommandType.LineTo,
|
45
|
-
point: arrowTipBase.plus(scaledBaseNormal),
|
46
|
-
},
|
47
|
-
// Head
|
48
|
-
{
|
49
|
-
kind: PathCommandType.LineTo,
|
50
|
-
point: arrowTipBase.plus(lineNormal.times(arrowTipSize).plus(scaledBaseNormal)),
|
51
|
-
},
|
52
|
-
{
|
53
|
-
kind: PathCommandType.LineTo,
|
54
|
-
point: endPoint.plus(toEnd.times(endSize)),
|
55
|
-
},
|
56
|
-
{
|
57
|
-
kind: PathCommandType.LineTo,
|
58
|
-
point: arrowTipBase.plus(lineNormal.times(-arrowTipSize).minus(scaledBaseNormal)),
|
59
|
-
},
|
60
|
-
{
|
61
|
-
kind: PathCommandType.LineTo,
|
62
|
-
point: arrowTipBase.minus(scaledBaseNormal),
|
63
|
-
},
|
64
|
-
// Round all points in the arrow (to remove unnecessary decimal places)
|
65
|
-
]).mapPoints(point => this.viewport.roundPoint(point));
|
66
|
-
const preview = new Stroke([
|
67
|
-
{
|
68
|
-
startPoint: path.startPoint,
|
69
|
-
commands: path.parts,
|
70
|
-
style: {
|
71
|
-
fill: this.startPoint.color,
|
72
|
-
}
|
73
|
-
}
|
74
|
-
]);
|
75
|
-
return preview;
|
76
|
-
}
|
77
|
-
build() {
|
78
|
-
return this.buildPreview();
|
79
|
-
}
|
80
|
-
preview(renderer) {
|
81
|
-
this.buildPreview().render(renderer);
|
82
|
-
}
|
83
|
-
addPoint(point) {
|
84
|
-
this.endPoint = point;
|
85
|
-
}
|
86
|
-
}
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import AbstractRenderer, { RenderablePathSpec } from '../../rendering/renderers/AbstractRenderer';
|
2
|
-
import Rect2 from '../../math/Rect2';
|
3
|
-
import Stroke from '../Stroke';
|
4
|
-
import Viewport from '../../Viewport';
|
5
|
-
import { StrokeDataPoint } from '../../types';
|
6
|
-
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
7
|
-
import RenderingStyle from '../../rendering/RenderingStyle';
|
8
|
-
export declare const makeFreehandLineBuilder: ComponentBuilderFactory;
|
9
|
-
export default class FreehandLineBuilder implements ComponentBuilder {
|
10
|
-
private startPoint;
|
11
|
-
private minFitAllowed;
|
12
|
-
private viewport;
|
13
|
-
private isFirstSegment;
|
14
|
-
private parts;
|
15
|
-
private curveFitter;
|
16
|
-
private bbox;
|
17
|
-
private averageWidth;
|
18
|
-
private widthAverageNumSamples;
|
19
|
-
constructor(startPoint: StrokeDataPoint, minFitAllowed: number, maxFitAllowed: number, viewport: Viewport);
|
20
|
-
getBBox(): Rect2;
|
21
|
-
protected getRenderingStyle(): RenderingStyle;
|
22
|
-
protected previewCurrentPath(): RenderablePathSpec | null;
|
23
|
-
protected previewFullPath(): RenderablePathSpec[] | null;
|
24
|
-
private previewStroke;
|
25
|
-
preview(renderer: AbstractRenderer): void;
|
26
|
-
build(): Stroke;
|
27
|
-
private getMinFit;
|
28
|
-
private roundPoint;
|
29
|
-
private roundDistance;
|
30
|
-
private curveToPathCommands;
|
31
|
-
private addCurve;
|
32
|
-
addPoint(newPoint: StrokeDataPoint): void;
|
33
|
-
}
|
@@ -1,165 +0,0 @@
|
|
1
|
-
import { Vec2 } from '../../math/Vec2';
|
2
|
-
import Rect2 from '../../math/Rect2';
|
3
|
-
import { PathCommandType } from '../../math/Path';
|
4
|
-
import Stroke from '../Stroke';
|
5
|
-
import Viewport from '../../Viewport';
|
6
|
-
import { StrokeSmoother } from '../util/StrokeSmoother';
|
7
|
-
import Color4 from '../../Color4';
|
8
|
-
export const makeFreehandLineBuilder = (initialPoint, viewport) => {
|
9
|
-
// Don't smooth if input is more than ± 3 pixels from the true curve, do smooth if
|
10
|
-
// less than ±1 px from the curve.
|
11
|
-
const maxSmoothingDist = viewport.getSizeOfPixelOnCanvas() * 3;
|
12
|
-
const minSmoothingDist = viewport.getSizeOfPixelOnCanvas();
|
13
|
-
return new FreehandLineBuilder(initialPoint, minSmoothingDist, maxSmoothingDist, viewport);
|
14
|
-
};
|
15
|
-
// Handles stroke smoothing and creates Strokes from user/stylus input.
|
16
|
-
export default class FreehandLineBuilder {
|
17
|
-
constructor(startPoint, minFitAllowed, maxFitAllowed, viewport) {
|
18
|
-
this.startPoint = startPoint;
|
19
|
-
this.minFitAllowed = minFitAllowed;
|
20
|
-
this.viewport = viewport;
|
21
|
-
this.isFirstSegment = true;
|
22
|
-
this.parts = [];
|
23
|
-
this.widthAverageNumSamples = 1;
|
24
|
-
this.curveFitter = new StrokeSmoother(startPoint, minFitAllowed, maxFitAllowed, (curve) => this.addCurve(curve));
|
25
|
-
this.averageWidth = startPoint.width;
|
26
|
-
this.bbox = new Rect2(this.startPoint.pos.x, this.startPoint.pos.y, 0, 0);
|
27
|
-
}
|
28
|
-
getBBox() {
|
29
|
-
return this.bbox;
|
30
|
-
}
|
31
|
-
getRenderingStyle() {
|
32
|
-
return {
|
33
|
-
fill: Color4.transparent,
|
34
|
-
stroke: {
|
35
|
-
color: this.startPoint.color,
|
36
|
-
width: this.roundDistance(this.averageWidth),
|
37
|
-
}
|
38
|
-
};
|
39
|
-
}
|
40
|
-
previewCurrentPath() {
|
41
|
-
const path = this.parts.slice();
|
42
|
-
const commands = [...path, ...this.curveToPathCommands(this.curveFitter.preview())];
|
43
|
-
const startPoint = this.startPoint.pos;
|
44
|
-
return {
|
45
|
-
startPoint,
|
46
|
-
commands,
|
47
|
-
style: this.getRenderingStyle(),
|
48
|
-
};
|
49
|
-
}
|
50
|
-
previewFullPath() {
|
51
|
-
const preview = this.previewCurrentPath();
|
52
|
-
if (preview) {
|
53
|
-
return [preview];
|
54
|
-
}
|
55
|
-
return null;
|
56
|
-
}
|
57
|
-
previewStroke() {
|
58
|
-
const pathPreview = this.previewFullPath();
|
59
|
-
if (pathPreview) {
|
60
|
-
return new Stroke(pathPreview);
|
61
|
-
}
|
62
|
-
return null;
|
63
|
-
}
|
64
|
-
preview(renderer) {
|
65
|
-
const paths = this.previewFullPath();
|
66
|
-
if (paths) {
|
67
|
-
const approxBBox = this.viewport.visibleRect;
|
68
|
-
renderer.startObject(approxBBox);
|
69
|
-
for (const path of paths) {
|
70
|
-
renderer.drawPath(path);
|
71
|
-
}
|
72
|
-
renderer.endObject();
|
73
|
-
}
|
74
|
-
}
|
75
|
-
build() {
|
76
|
-
this.curveFitter.finalizeCurrentCurve();
|
77
|
-
return this.previewStroke();
|
78
|
-
}
|
79
|
-
getMinFit() {
|
80
|
-
let minFit = Math.min(this.minFitAllowed, this.averageWidth / 3);
|
81
|
-
if (minFit < 1e-10) {
|
82
|
-
minFit = this.minFitAllowed;
|
83
|
-
}
|
84
|
-
return minFit;
|
85
|
-
}
|
86
|
-
roundPoint(point) {
|
87
|
-
const minFit = this.getMinFit();
|
88
|
-
return Viewport.roundPoint(point, minFit);
|
89
|
-
}
|
90
|
-
roundDistance(dist) {
|
91
|
-
const minFit = this.getMinFit();
|
92
|
-
return Viewport.roundPoint(dist, minFit);
|
93
|
-
}
|
94
|
-
curveToPathCommands(curve) {
|
95
|
-
// Case where no points have been added
|
96
|
-
if (!curve) {
|
97
|
-
// Don't create a circle around the initial point if the stroke has more than one point.
|
98
|
-
if (!this.isFirstSegment) {
|
99
|
-
return [];
|
100
|
-
}
|
101
|
-
// Make the circle small -- because of the stroke style, we'll be drawing a stroke around it.
|
102
|
-
const width = Viewport.roundPoint(this.averageWidth / 10, Math.min(this.minFitAllowed, this.averageWidth / 10));
|
103
|
-
const center = this.roundPoint(this.startPoint.pos);
|
104
|
-
// Start on the right, cycle clockwise:
|
105
|
-
// |
|
106
|
-
// ----- ←
|
107
|
-
// |
|
108
|
-
// Draw a circle-ish shape around the start point
|
109
|
-
return [
|
110
|
-
{
|
111
|
-
kind: PathCommandType.QuadraticBezierTo,
|
112
|
-
controlPoint: center.plus(Vec2.of(width, width)),
|
113
|
-
// Bottom of the circle
|
114
|
-
// |
|
115
|
-
// -----
|
116
|
-
// |
|
117
|
-
// ↑
|
118
|
-
endPoint: center.plus(Vec2.of(0, width)),
|
119
|
-
},
|
120
|
-
{
|
121
|
-
kind: PathCommandType.QuadraticBezierTo,
|
122
|
-
controlPoint: center.plus(Vec2.of(-width, width)),
|
123
|
-
endPoint: center.plus(Vec2.of(-width, 0)),
|
124
|
-
},
|
125
|
-
{
|
126
|
-
kind: PathCommandType.QuadraticBezierTo,
|
127
|
-
controlPoint: center.plus(Vec2.of(-width, -width)),
|
128
|
-
endPoint: center.plus(Vec2.of(0, -width)),
|
129
|
-
},
|
130
|
-
{
|
131
|
-
kind: PathCommandType.QuadraticBezierTo,
|
132
|
-
controlPoint: center.plus(Vec2.of(width, -width)),
|
133
|
-
endPoint: center.plus(Vec2.of(width, 0)),
|
134
|
-
}
|
135
|
-
];
|
136
|
-
}
|
137
|
-
const result = [];
|
138
|
-
if (this.isFirstSegment) {
|
139
|
-
result.push({
|
140
|
-
kind: PathCommandType.MoveTo,
|
141
|
-
point: this.roundPoint(curve.startPoint),
|
142
|
-
});
|
143
|
-
}
|
144
|
-
result.push({
|
145
|
-
kind: PathCommandType.QuadraticBezierTo,
|
146
|
-
controlPoint: this.roundPoint(curve.controlPoint),
|
147
|
-
endPoint: this.roundPoint(curve.endPoint),
|
148
|
-
});
|
149
|
-
return result;
|
150
|
-
}
|
151
|
-
addCurve(curve) {
|
152
|
-
const parts = this.curveToPathCommands(curve);
|
153
|
-
this.parts.push(...parts);
|
154
|
-
if (this.isFirstSegment) {
|
155
|
-
this.isFirstSegment = false;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
addPoint(newPoint) {
|
159
|
-
this.curveFitter.addPoint(newPoint);
|
160
|
-
this.widthAverageNumSamples++;
|
161
|
-
this.averageWidth =
|
162
|
-
this.averageWidth * (this.widthAverageNumSamples - 1) / this.widthAverageNumSamples
|
163
|
-
+ newPoint.width / this.widthAverageNumSamples;
|
164
|
-
}
|
165
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import Rect2 from '../../math/Rect2';
|
2
|
-
import AbstractRenderer from '../../rendering/renderers/AbstractRenderer';
|
3
|
-
import { StrokeDataPoint } from '../../types';
|
4
|
-
import Viewport from '../../Viewport';
|
5
|
-
import AbstractComponent from '../AbstractComponent';
|
6
|
-
import { ComponentBuilder, ComponentBuilderFactory } from './types';
|
7
|
-
export declare const makeLineBuilder: ComponentBuilderFactory;
|
8
|
-
export default class LineBuilder implements ComponentBuilder {
|
9
|
-
private readonly startPoint;
|
10
|
-
private readonly viewport;
|
11
|
-
private endPoint;
|
12
|
-
constructor(startPoint: StrokeDataPoint, viewport: Viewport);
|
13
|
-
getBBox(): Rect2;
|
14
|
-
private buildPreview;
|
15
|
-
build(): AbstractComponent;
|
16
|
-
preview(renderer: AbstractRenderer): void;
|
17
|
-
addPoint(point: StrokeDataPoint): void;
|
18
|
-
}
|