js-draw 0.18.1 → 0.18.2
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 +3 -0
- package/dist/cjs/src/Color4.d.ts +61 -0
- package/dist/cjs/src/Color4.js +197 -0
- package/dist/cjs/src/Editor.d.ts +308 -0
- package/dist/cjs/src/Editor.js +904 -0
- package/dist/cjs/src/EditorImage.d.ts +97 -0
- package/dist/cjs/src/EditorImage.js +486 -0
- package/dist/cjs/src/EventDispatcher.d.ts +30 -0
- package/dist/cjs/src/EventDispatcher.js +57 -0
- package/dist/cjs/src/Pointer.d.ts +24 -0
- package/dist/cjs/src/Pointer.js +84 -0
- package/dist/cjs/src/SVGLoader.d.ts +48 -0
- package/dist/cjs/src/SVGLoader.js +472 -0
- package/dist/cjs/src/UndoRedoHistory.d.ts +19 -0
- package/dist/cjs/src/UndoRedoHistory.js +93 -0
- package/dist/cjs/src/Viewport.d.ts +71 -0
- package/dist/cjs/src/Viewport.js +264 -0
- package/dist/cjs/src/bundle/bundled.d.ts +4 -0
- package/dist/cjs/src/bundle/bundled.js +24 -0
- package/dist/cjs/src/commands/Command.d.ts +16 -0
- package/dist/cjs/src/commands/Command.js +34 -0
- package/dist/cjs/src/commands/Duplicate.d.ts +14 -0
- package/dist/cjs/src/commands/Duplicate.js +39 -0
- package/dist/cjs/src/commands/Erase.d.ts +14 -0
- package/dist/cjs/src/commands/Erase.js +63 -0
- package/dist/cjs/src/commands/SerializableCommand.d.ts +12 -0
- package/dist/cjs/src/commands/SerializableCommand.js +42 -0
- package/dist/cjs/src/commands/UnresolvedCommand.d.ts +14 -0
- package/dist/cjs/src/commands/UnresolvedCommand.js +28 -0
- package/dist/cjs/src/commands/invertCommand.d.ts +4 -0
- package/dist/cjs/src/commands/invertCommand.js +49 -0
- package/dist/cjs/src/commands/lib.d.ts +7 -0
- package/dist/cjs/src/commands/lib.js +18 -0
- package/dist/cjs/src/commands/localization.d.ts +23 -0
- package/dist/cjs/src/commands/localization.js +24 -0
- package/dist/cjs/src/commands/uniteCommands.d.ts +4 -0
- package/dist/cjs/src/commands/uniteCommands.js +121 -0
- package/dist/cjs/src/components/AbstractComponent.d.ts +73 -0
- package/dist/cjs/src/components/AbstractComponent.js +258 -0
- package/dist/cjs/src/components/ImageBackground.d.ts +42 -0
- package/dist/cjs/src/components/ImageBackground.js +146 -0
- package/dist/cjs/src/components/ImageComponent.d.ts +31 -0
- package/dist/cjs/src/components/ImageComponent.js +152 -0
- package/dist/cjs/src/components/RestylableComponent.d.ts +24 -0
- package/dist/cjs/src/components/RestylableComponent.js +88 -0
- package/dist/cjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/cjs/src/components/SVGGlobalAttributesObject.js +65 -0
- package/dist/cjs/src/components/Stroke.d.ts +40 -0
- package/dist/cjs/src/components/Stroke.js +191 -0
- package/dist/cjs/src/components/TextComponent.d.ts +53 -0
- package/dist/cjs/src/components/TextComponent.js +258 -0
- package/dist/cjs/src/components/UnknownSVGObject.d.ts +18 -0
- package/dist/cjs/src/components/UnknownSVGObject.js +50 -0
- package/dist/cjs/src/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/cjs/src/components/builders/ArrowBuilder.js +117 -0
- package/dist/cjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/cjs/src/components/builders/FreehandLineBuilder.js +173 -0
- package/dist/cjs/src/components/builders/LineBuilder.d.ts +18 -0
- package/dist/cjs/src/components/builders/LineBuilder.js +89 -0
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.js +347 -0
- package/dist/cjs/src/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/cjs/src/components/builders/RectangleBuilder.js +59 -0
- package/dist/cjs/src/components/builders/types.d.ts +12 -0
- package/dist/cjs/src/components/builders/types.js +2 -0
- package/dist/cjs/src/components/lib.d.ts +12 -0
- package/dist/cjs/src/components/lib.js +43 -0
- package/dist/cjs/src/components/localization.d.ts +11 -0
- package/dist/cjs/src/components/localization.js +13 -0
- package/dist/cjs/src/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/cjs/src/components/util/StrokeSmoother.js +217 -0
- package/dist/cjs/src/components/util/describeComponentList.d.ts +4 -0
- package/dist/cjs/src/components/util/describeComponentList.js +16 -0
- package/dist/cjs/src/lib.d.ts +34 -0
- package/dist/cjs/src/lib.js +63 -0
- package/dist/cjs/src/localization.d.ts +14 -0
- package/dist/cjs/src/localization.js +13 -0
- package/dist/cjs/src/localizations/de.d.ts +3 -0
- package/dist/cjs/src/localizations/de.js +6 -0
- package/dist/cjs/src/localizations/en.d.ts +3 -0
- package/dist/cjs/src/localizations/en.js +6 -0
- package/dist/cjs/src/localizations/es.d.ts +3 -0
- package/dist/cjs/src/localizations/es.js +20 -0
- package/dist/cjs/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/cjs/src/localizations/getLocalizationTable.js +50 -0
- package/dist/cjs/src/math/LineSegment2.d.ts +24 -0
- package/dist/cjs/src/math/LineSegment2.js +131 -0
- package/dist/cjs/src/math/Mat33.d.ts +118 -0
- package/dist/cjs/src/math/Mat33.js +332 -0
- package/dist/cjs/src/math/Path.d.ts +71 -0
- package/dist/cjs/src/math/Path.js +655 -0
- package/dist/cjs/src/math/Rect2.d.ts +52 -0
- package/dist/cjs/src/math/Rect2.js +234 -0
- package/dist/cjs/src/math/Triangle.d.ts +11 -0
- package/dist/cjs/src/math/Triangle.js +22 -0
- package/dist/cjs/src/math/Vec2.d.ts +13 -0
- package/dist/cjs/src/math/Vec2.js +19 -0
- package/dist/cjs/src/math/Vec3.d.ts +106 -0
- package/dist/cjs/src/math/Vec3.js +177 -0
- package/dist/cjs/src/math/lib.d.ts +7 -0
- package/dist/cjs/src/math/lib.js +18 -0
- package/dist/cjs/src/math/rounding.d.ts +4 -0
- package/dist/cjs/src/math/rounding.js +135 -0
- package/dist/cjs/src/rendering/Display.d.ts +75 -0
- package/dist/cjs/src/rendering/Display.js +214 -0
- package/dist/cjs/src/rendering/RenderingStyle.d.ts +31 -0
- package/dist/cjs/src/rendering/RenderingStyle.js +48 -0
- package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +36 -0
- package/dist/cjs/src/rendering/TextRenderingStyle.js +29 -0
- package/dist/cjs/src/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/cjs/src/rendering/caching/CacheRecord.js +61 -0
- package/dist/cjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/cjs/src/rendering/caching/CacheRecordManager.js +50 -0
- package/dist/cjs/src/rendering/caching/RenderingCache.d.ts +11 -0
- package/dist/cjs/src/rendering/caching/RenderingCache.js +51 -0
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.js +326 -0
- package/dist/cjs/src/rendering/caching/testUtils.d.ts +9 -0
- package/dist/cjs/src/rendering/caching/testUtils.js +27 -0
- package/dist/cjs/src/rendering/caching/types.d.ts +19 -0
- package/dist/cjs/src/rendering/caching/types.js +2 -0
- package/dist/cjs/src/rendering/lib.d.ts +5 -0
- package/dist/cjs/src/rendering/lib.js +17 -0
- package/dist/cjs/src/rendering/localization.d.ts +10 -0
- package/dist/cjs/src/rendering/localization.js +12 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +68 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.js +170 -0
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +236 -0
- package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/cjs/src/rendering/renderers/DummyRenderer.js +112 -0
- package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/cjs/src/rendering/renderers/SVGRenderer.js +311 -0
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.js +63 -0
- package/dist/cjs/src/testing/beforeEachFile.d.ts +1 -0
- package/dist/cjs/src/testing/beforeEachFile.js +12 -0
- package/dist/cjs/src/testing/createEditor.d.ts +4 -0
- package/dist/cjs/src/testing/createEditor.js +14 -0
- package/dist/cjs/src/testing/lib.d.ts +2 -0
- package/dist/cjs/src/testing/lib.js +10 -0
- package/dist/cjs/src/testing/loadExpectExtensions.d.ts +2 -0
- package/dist/cjs/src/testing/loadExpectExtensions.js +28 -0
- package/dist/cjs/src/testing/sendPenEvent.d.ts +12 -0
- package/dist/cjs/src/testing/sendPenEvent.js +24 -0
- package/dist/cjs/src/testing/sendTouchEvent.d.ts +42 -0
- package/dist/cjs/src/testing/sendTouchEvent.js +87 -0
- package/dist/cjs/src/toolbar/HTMLToolbar.d.ts +103 -0
- package/dist/cjs/src/toolbar/HTMLToolbar.js +383 -0
- package/dist/cjs/src/toolbar/IconProvider.d.ts +62 -0
- package/dist/cjs/src/toolbar/IconProvider.js +660 -0
- package/dist/cjs/src/toolbar/lib.d.ts +3 -0
- package/dist/cjs/src/toolbar/lib.js +24 -0
- package/dist/cjs/src/toolbar/localization.d.ts +49 -0
- package/dist/cjs/src/toolbar/localization.js +51 -0
- package/dist/cjs/src/toolbar/makeColorInput.d.ts +6 -0
- package/dist/cjs/src/toolbar/makeColorInput.js +120 -0
- package/dist/cjs/src/toolbar/types.d.ts +4 -0
- package/dist/cjs/src/toolbar/types.js +2 -0
- package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.d.ts +15 -0
- package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.js +31 -0
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.js +50 -0
- package/dist/cjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +313 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +126 -0
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.js +63 -0
- package/dist/cjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
- package/dist/cjs/src/toolbar/widgets/HandToolWidget.js +201 -0
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.js +176 -0
- package/dist/cjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
- package/dist/cjs/src/toolbar/widgets/OverflowWidget.js +77 -0
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +226 -0
- package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
- package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.js +153 -0
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.js +115 -0
- package/dist/cjs/src/toolbar/widgets/lib.d.ts +10 -0
- package/dist/cjs/src/toolbar/widgets/lib.js +26 -0
- package/dist/cjs/src/tools/BaseTool.d.ts +22 -0
- package/dist/cjs/src/tools/BaseTool.js +66 -0
- package/dist/cjs/src/tools/Eraser.d.ts +23 -0
- package/dist/cjs/src/tools/Eraser.js +112 -0
- package/dist/cjs/src/tools/FindTool.d.ts +21 -0
- package/dist/cjs/src/tools/FindTool.js +121 -0
- package/dist/cjs/src/tools/PanZoom.d.ts +52 -0
- package/dist/cjs/src/tools/PanZoom.js +421 -0
- package/dist/cjs/src/tools/PasteHandler.d.ts +23 -0
- package/dist/cjs/src/tools/PasteHandler.js +99 -0
- package/dist/cjs/src/tools/Pen.d.ts +39 -0
- package/dist/cjs/src/tools/Pen.js +179 -0
- package/dist/cjs/src/tools/PipetteTool.d.ts +18 -0
- package/dist/cjs/src/tools/PipetteTool.js +45 -0
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.js +28 -0
- package/dist/cjs/src/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/cjs/src/tools/SelectionTool/Selection.js +488 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionHandle.js +85 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.js +405 -0
- package/dist/cjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
- package/dist/cjs/src/tools/SelectionTool/TransformMode.js +107 -0
- package/dist/cjs/src/tools/SelectionTool/types.d.ts +9 -0
- package/dist/cjs/src/tools/SelectionTool/types.js +14 -0
- package/dist/cjs/src/tools/TextTool.d.ts +33 -0
- package/dist/cjs/src/tools/TextTool.js +262 -0
- package/dist/cjs/src/tools/ToolController.d.ts +18 -0
- package/dist/cjs/src/tools/ToolController.js +187 -0
- package/dist/cjs/src/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/cjs/src/tools/ToolEnabledGroup.js +14 -0
- package/dist/cjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/cjs/src/tools/ToolSwitcherShortcut.js +38 -0
- package/dist/cjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/cjs/src/tools/ToolbarShortcutHandler.js +29 -0
- package/dist/cjs/src/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/cjs/src/tools/UndoRedoShortcut.js +28 -0
- package/dist/cjs/src/tools/lib.d.ts +16 -0
- package/dist/cjs/src/tools/lib.js +36 -0
- package/dist/cjs/src/tools/localization.d.ts +28 -0
- package/dist/cjs/src/tools/localization.js +30 -0
- package/dist/cjs/src/types.d.ts +151 -0
- package/dist/cjs/src/types.js +38 -0
- package/dist/cjs/src/util/assertions.d.ts +23 -0
- package/dist/cjs/src/util/assertions.js +51 -0
- package/dist/cjs/src/util/fileToBase64.d.ts +3 -0
- package/dist/cjs/src/util/fileToBase64.js +15 -0
- package/dist/cjs/src/util/untilNextAnimationFrame.d.ts +3 -0
- package/dist/cjs/src/util/untilNextAnimationFrame.js +9 -0
- package/dist/cjs/src/util/waitForTimeout.d.ts +2 -0
- package/dist/cjs/src/util/waitForTimeout.js +9 -0
- package/dist/mjs/src/Color4.d.ts +61 -0
- package/dist/mjs/src/Color4.mjs +193 -0
- package/dist/mjs/src/Editor.d.ts +308 -0
- package/dist/mjs/src/Editor.mjs +874 -0
- package/dist/mjs/src/EditorImage.d.ts +97 -0
- package/dist/mjs/src/EditorImage.mjs +477 -0
- package/dist/mjs/src/EventDispatcher.d.ts +30 -0
- package/dist/mjs/src/EventDispatcher.mjs +54 -0
- package/dist/mjs/src/Pointer.d.ts +24 -0
- package/dist/mjs/src/Pointer.mjs +80 -0
- package/dist/mjs/src/SVGLoader.d.ts +48 -0
- package/dist/mjs/src/SVGLoader.mjs +442 -0
- package/dist/mjs/src/UndoRedoHistory.d.ts +19 -0
- package/dist/mjs/src/UndoRedoHistory.mjs +91 -0
- package/dist/mjs/src/Viewport.d.ts +71 -0
- package/dist/mjs/src/Viewport.mjs +256 -0
- package/dist/mjs/src/bundle/bundled.d.ts +4 -0
- package/dist/mjs/src/bundle/bundled.mjs +5 -0
- package/dist/mjs/src/commands/Command.d.ts +16 -0
- package/dist/mjs/src/commands/Command.mjs +30 -0
- package/dist/mjs/src/commands/Duplicate.d.ts +14 -0
- package/dist/mjs/src/commands/Duplicate.mjs +33 -0
- package/dist/mjs/src/commands/Erase.d.ts +14 -0
- package/dist/mjs/src/commands/Erase.mjs +57 -0
- package/dist/mjs/src/commands/SerializableCommand.d.ts +12 -0
- package/dist/mjs/src/commands/SerializableCommand.mjs +36 -0
- package/dist/mjs/src/commands/UnresolvedCommand.d.ts +14 -0
- package/dist/mjs/src/commands/UnresolvedCommand.mjs +22 -0
- package/dist/mjs/src/commands/invertCommand.d.ts +4 -0
- package/dist/mjs/src/commands/invertCommand.mjs +44 -0
- package/dist/mjs/src/commands/lib.d.ts +7 -0
- package/dist/mjs/src/commands/lib.mjs +7 -0
- package/dist/mjs/src/commands/localization.d.ts +23 -0
- package/dist/mjs/src/commands/localization.mjs +21 -0
- package/dist/mjs/src/commands/uniteCommands.d.ts +4 -0
- package/dist/mjs/src/commands/uniteCommands.mjs +116 -0
- package/dist/mjs/src/components/AbstractComponent.d.ts +73 -0
- package/dist/mjs/src/components/AbstractComponent.mjs +252 -0
- package/dist/mjs/src/components/ImageBackground.d.ts +42 -0
- package/dist/mjs/src/components/ImageBackground.mjs +139 -0
- package/dist/mjs/src/components/ImageComponent.d.ts +31 -0
- package/dist/mjs/src/components/ImageComponent.mjs +146 -0
- package/dist/mjs/src/components/RestylableComponent.d.ts +24 -0
- package/dist/mjs/src/components/RestylableComponent.mjs +80 -0
- package/dist/mjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/mjs/src/components/SVGGlobalAttributesObject.mjs +59 -0
- package/dist/mjs/src/components/Stroke.d.ts +40 -0
- package/dist/mjs/src/components/Stroke.mjs +185 -0
- package/dist/mjs/src/components/TextComponent.d.ts +53 -0
- package/dist/mjs/src/components/TextComponent.mjs +252 -0
- package/dist/mjs/src/components/UnknownSVGObject.d.ts +18 -0
- package/dist/mjs/src/components/UnknownSVGObject.mjs +44 -0
- package/dist/mjs/src/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/mjs/src/components/builders/ArrowBuilder.mjs +86 -0
- package/dist/mjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/mjs/src/components/builders/FreehandLineBuilder.mjs +165 -0
- package/dist/mjs/src/components/builders/LineBuilder.d.ts +18 -0
- package/dist/mjs/src/components/builders/LineBuilder.mjs +58 -0
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.mjs +339 -0
- package/dist/mjs/src/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/mjs/src/components/builders/RectangleBuilder.mjs +50 -0
- package/dist/mjs/src/components/builders/types.d.ts +12 -0
- package/dist/mjs/src/components/builders/types.mjs +1 -0
- package/dist/mjs/src/components/lib.d.ts +12 -0
- package/dist/mjs/src/components/lib.mjs +12 -0
- package/dist/mjs/src/components/localization.d.ts +11 -0
- package/dist/mjs/src/components/localization.mjs +10 -0
- package/dist/mjs/src/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/mjs/src/components/util/StrokeSmoother.mjs +210 -0
- package/dist/mjs/src/components/util/describeComponentList.d.ts +4 -0
- package/dist/mjs/src/components/util/describeComponentList.mjs +14 -0
- package/dist/mjs/src/lib.d.ts +34 -0
- package/dist/mjs/src/lib.mjs +34 -0
- package/dist/mjs/src/localization.d.ts +14 -0
- package/dist/mjs/src/localization.mjs +10 -0
- package/dist/mjs/src/localizations/de.d.ts +3 -0
- package/dist/mjs/src/localizations/de.mjs +4 -0
- package/dist/mjs/src/localizations/en.d.ts +3 -0
- package/dist/mjs/src/localizations/en.mjs +4 -0
- package/dist/mjs/src/localizations/es.d.ts +3 -0
- package/dist/mjs/src/localizations/es.mjs +18 -0
- package/dist/mjs/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/mjs/src/localizations/getLocalizationTable.mjs +45 -0
- package/dist/mjs/src/math/LineSegment2.d.ts +24 -0
- package/dist/mjs/src/math/LineSegment2.mjs +125 -0
- package/dist/mjs/src/math/Mat33.d.ts +118 -0
- package/dist/mjs/src/math/Mat33.mjs +326 -0
- package/dist/mjs/src/math/Path.d.ts +71 -0
- package/dist/mjs/src/math/Path.mjs +648 -0
- package/dist/mjs/src/math/Rect2.d.ts +52 -0
- package/dist/mjs/src/math/Rect2.mjs +228 -0
- package/dist/mjs/src/math/Triangle.d.ts +11 -0
- package/dist/mjs/src/math/Triangle.mjs +19 -0
- package/dist/mjs/src/math/Vec2.d.ts +13 -0
- package/dist/mjs/src/math/Vec2.mjs +13 -0
- package/dist/mjs/src/math/Vec3.d.ts +106 -0
- package/dist/mjs/src/math/Vec3.mjs +174 -0
- package/dist/mjs/src/math/lib.d.ts +7 -0
- package/dist/mjs/src/math/lib.mjs +7 -0
- package/dist/mjs/src/math/rounding.d.ts +4 -0
- package/dist/mjs/src/math/rounding.mjs +128 -0
- package/dist/mjs/src/rendering/Display.d.ts +75 -0
- package/dist/mjs/src/rendering/Display.mjs +207 -0
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +31 -0
- package/dist/mjs/src/rendering/RenderingStyle.mjs +38 -0
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +36 -0
- package/dist/mjs/src/rendering/TextRenderingStyle.mjs +23 -0
- package/dist/mjs/src/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/mjs/src/rendering/caching/CacheRecord.mjs +55 -0
- package/dist/mjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/mjs/src/rendering/caching/CacheRecordManager.mjs +43 -0
- package/dist/mjs/src/rendering/caching/RenderingCache.d.ts +11 -0
- package/dist/mjs/src/rendering/caching/RenderingCache.mjs +45 -0
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.mjs +320 -0
- package/dist/mjs/src/rendering/caching/testUtils.d.ts +9 -0
- package/dist/mjs/src/rendering/caching/testUtils.mjs +20 -0
- package/dist/mjs/src/rendering/caching/types.d.ts +19 -0
- package/dist/mjs/src/rendering/caching/types.mjs +1 -0
- package/dist/mjs/src/rendering/lib.d.ts +5 -0
- package/dist/mjs/src/rendering/lib.mjs +5 -0
- package/dist/mjs/src/rendering/localization.d.ts +10 -0
- package/dist/mjs/src/rendering/localization.mjs +9 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +68 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.mjs +144 -0
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.mjs +230 -0
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/mjs/src/rendering/renderers/DummyRenderer.mjs +106 -0
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/mjs/src/rendering/renderers/SVGRenderer.mjs +304 -0
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.mjs +57 -0
- package/dist/mjs/src/testing/beforeEachFile.d.ts +1 -0
- package/dist/mjs/src/testing/beforeEachFile.mjs +7 -0
- package/dist/mjs/src/testing/createEditor.d.ts +4 -0
- package/dist/mjs/src/testing/createEditor.mjs +9 -0
- package/dist/mjs/src/testing/lib.d.ts +2 -0
- package/dist/mjs/src/testing/lib.mjs +2 -0
- package/dist/mjs/src/testing/loadExpectExtensions.d.ts +2 -0
- package/dist/mjs/src/testing/loadExpectExtensions.mjs +24 -0
- package/dist/mjs/src/testing/sendPenEvent.d.ts +12 -0
- package/dist/mjs/src/testing/sendPenEvent.mjs +19 -0
- package/dist/mjs/src/testing/sendTouchEvent.d.ts +42 -0
- package/dist/mjs/src/testing/sendTouchEvent.mjs +62 -0
- package/dist/mjs/src/toolbar/HTMLToolbar.d.ts +103 -0
- package/dist/mjs/src/toolbar/HTMLToolbar.mjs +376 -0
- package/dist/mjs/src/toolbar/IconProvider.d.ts +62 -0
- package/dist/mjs/src/toolbar/IconProvider.mjs +654 -0
- package/dist/mjs/src/toolbar/lib.d.ts +3 -0
- package/dist/mjs/src/toolbar/lib.mjs +3 -0
- package/dist/mjs/src/toolbar/localization.d.ts +49 -0
- package/dist/mjs/src/toolbar/localization.mjs +48 -0
- package/dist/mjs/src/toolbar/makeColorInput.d.ts +6 -0
- package/dist/mjs/src/toolbar/makeColorInput.mjs +113 -0
- package/dist/mjs/src/toolbar/types.d.ts +4 -0
- package/dist/mjs/src/toolbar/types.mjs +1 -0
- package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.d.ts +15 -0
- package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.mjs +25 -0
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.mjs +44 -0
- package/dist/mjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +307 -0
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +120 -0
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.mjs +57 -0
- package/dist/mjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
- package/dist/mjs/src/toolbar/widgets/HandToolWidget.mjs +172 -0
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.mjs +170 -0
- package/dist/mjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
- package/dist/mjs/src/toolbar/widgets/OverflowWidget.mjs +71 -0
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +220 -0
- package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
- package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.mjs +147 -0
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.mjs +109 -0
- package/dist/mjs/src/toolbar/widgets/lib.d.ts +10 -0
- package/dist/mjs/src/toolbar/widgets/lib.mjs +10 -0
- package/dist/mjs/src/tools/BaseTool.d.ts +22 -0
- package/dist/mjs/src/tools/BaseTool.mjs +63 -0
- package/dist/mjs/src/tools/Eraser.d.ts +23 -0
- package/dist/mjs/src/tools/Eraser.mjs +106 -0
- package/dist/mjs/src/tools/FindTool.d.ts +21 -0
- package/dist/mjs/src/tools/FindTool.mjs +114 -0
- package/dist/mjs/src/tools/PanZoom.d.ts +52 -0
- package/dist/mjs/src/tools/PanZoom.mjs +414 -0
- package/dist/mjs/src/tools/PasteHandler.d.ts +23 -0
- package/dist/mjs/src/tools/PasteHandler.mjs +93 -0
- package/dist/mjs/src/tools/Pen.d.ts +39 -0
- package/dist/mjs/src/tools/Pen.mjs +173 -0
- package/dist/mjs/src/tools/PipetteTool.d.ts +18 -0
- package/dist/mjs/src/tools/PipetteTool.mjs +39 -0
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.mjs +22 -0
- package/dist/mjs/src/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/mjs/src/tools/SelectionTool/Selection.mjs +459 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionHandle.mjs +81 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.mjs +398 -0
- package/dist/mjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
- package/dist/mjs/src/tools/SelectionTool/TransformMode.mjs +98 -0
- package/dist/mjs/src/tools/SelectionTool/types.d.ts +9 -0
- package/dist/mjs/src/tools/SelectionTool/types.mjs +11 -0
- package/dist/mjs/src/tools/TextTool.d.ts +33 -0
- package/dist/mjs/src/tools/TextTool.mjs +256 -0
- package/dist/mjs/src/tools/ToolController.d.ts +18 -0
- package/dist/mjs/src/tools/ToolController.mjs +158 -0
- package/dist/mjs/src/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/mjs/src/tools/ToolEnabledGroup.mjs +11 -0
- package/dist/mjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/mjs/src/tools/ToolSwitcherShortcut.mjs +32 -0
- package/dist/mjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/mjs/src/tools/ToolbarShortcutHandler.mjs +23 -0
- package/dist/mjs/src/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/mjs/src/tools/UndoRedoShortcut.mjs +22 -0
- package/dist/mjs/src/tools/lib.d.ts +16 -0
- package/dist/mjs/src/tools/lib.mjs +16 -0
- package/dist/mjs/src/tools/localization.d.ts +28 -0
- package/dist/mjs/src/tools/localization.mjs +27 -0
- package/dist/mjs/src/types.d.ts +151 -0
- package/dist/mjs/src/types.mjs +35 -0
- package/dist/mjs/src/util/assertions.d.ts +23 -0
- package/dist/mjs/src/util/assertions.mjs +45 -0
- package/dist/mjs/src/util/fileToBase64.d.ts +3 -0
- package/dist/mjs/src/util/fileToBase64.mjs +13 -0
- package/dist/mjs/src/util/untilNextAnimationFrame.d.ts +3 -0
- package/dist/mjs/src/util/untilNextAnimationFrame.mjs +7 -0
- package/dist/mjs/src/util/waitForTimeout.d.ts +2 -0
- package/dist/mjs/src/util/waitForTimeout.mjs +7 -0
- package/package.json +1 -1
- package/src/Color4.test.ts +40 -0
- package/src/Color4.ts +236 -0
- package/src/Editor.css +86 -0
- package/src/Editor.loadFrom.test.ts +24 -0
- package/src/Editor.toSVG.test.ts +111 -0
- package/src/Editor.ts +1122 -0
- package/src/EditorImage.test.ts +120 -0
- package/src/EditorImage.ts +603 -0
- package/src/EventDispatcher.test.ts +123 -0
- package/src/EventDispatcher.ts +71 -0
- package/src/Pointer.ts +127 -0
- package/src/SVGLoader.test.ts +114 -0
- package/src/SVGLoader.ts +511 -0
- package/src/UndoRedoHistory.test.ts +33 -0
- package/src/UndoRedoHistory.ts +102 -0
- package/src/Viewport.ts +319 -0
- package/src/bundle/bundled.ts +7 -0
- package/src/commands/Command.ts +45 -0
- package/src/commands/Duplicate.ts +48 -0
- package/src/commands/Erase.ts +74 -0
- package/src/commands/SerializableCommand.ts +49 -0
- package/src/commands/UnresolvedCommand.ts +37 -0
- package/src/commands/invertCommand.ts +51 -0
- package/src/commands/lib.ts +16 -0
- package/src/commands/localization.ts +47 -0
- package/src/commands/uniteCommands.test.ts +23 -0
- package/src/commands/uniteCommands.ts +135 -0
- package/src/components/AbstractComponent.transformBy.test.ts +22 -0
- package/src/components/AbstractComponent.ts +364 -0
- package/src/components/ImageBackground.test.ts +35 -0
- package/src/components/ImageBackground.ts +176 -0
- package/src/components/ImageComponent.ts +171 -0
- package/src/components/RestylableComponent.ts +142 -0
- package/src/components/SVGGlobalAttributesObject.ts +81 -0
- package/src/components/Stroke.test.ts +139 -0
- package/src/components/Stroke.ts +245 -0
- package/src/components/TextComponent.test.ts +99 -0
- package/src/components/TextComponent.ts +315 -0
- package/src/components/UnknownSVGObject.test.ts +10 -0
- package/src/components/UnknownSVGObject.ts +60 -0
- package/src/components/builders/ArrowBuilder.ts +107 -0
- package/src/components/builders/FreehandLineBuilder.ts +212 -0
- package/src/components/builders/LineBuilder.ts +77 -0
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +454 -0
- package/src/components/builders/RectangleBuilder.ts +74 -0
- package/src/components/builders/types.ts +15 -0
- package/src/components/lib.ts +25 -0
- package/src/components/localization.ts +22 -0
- package/src/components/util/StrokeSmoother.ts +293 -0
- package/src/components/util/describeComponentList.ts +18 -0
- package/src/lib.ts +37 -0
- package/src/localization.ts +34 -0
- package/src/localizations/de.ts +98 -0
- package/src/localizations/en.ts +8 -0
- package/src/localizations/es.ts +74 -0
- package/src/localizations/getLocalizationTable.test.ts +27 -0
- package/src/localizations/getLocalizationTable.ts +55 -0
- package/src/math/LineSegment2.test.ts +99 -0
- package/src/math/LineSegment2.ts +160 -0
- package/src/math/Mat33.test.ts +244 -0
- package/src/math/Mat33.ts +437 -0
- package/src/math/Path.fromString.test.ts +223 -0
- package/src/math/Path.test.ts +198 -0
- package/src/math/Path.toString.test.ts +77 -0
- package/src/math/Path.ts +790 -0
- package/src/math/Rect2.test.ts +204 -0
- package/src/math/Rect2.ts +315 -0
- package/src/math/Triangle.ts +29 -0
- package/src/math/Vec2.test.ts +30 -0
- package/src/math/Vec2.ts +18 -0
- package/src/math/Vec3.test.ts +44 -0
- package/src/math/Vec3.ts +218 -0
- package/src/math/lib.ts +15 -0
- package/src/math/rounding.test.ts +65 -0
- package/src/math/rounding.ts +156 -0
- package/src/rendering/Display.ts +249 -0
- package/src/rendering/RenderingStyle.test.ts +68 -0
- package/src/rendering/RenderingStyle.ts +55 -0
- package/src/rendering/TextRenderingStyle.ts +45 -0
- package/src/rendering/caching/CacheRecord.test.ts +49 -0
- package/src/rendering/caching/CacheRecord.ts +77 -0
- package/src/rendering/caching/CacheRecordManager.ts +71 -0
- package/src/rendering/caching/RenderingCache.test.ts +44 -0
- package/src/rendering/caching/RenderingCache.ts +66 -0
- package/src/rendering/caching/RenderingCacheNode.ts +405 -0
- package/src/rendering/caching/testUtils.ts +35 -0
- package/src/rendering/caching/types.ts +34 -0
- package/src/rendering/lib.ts +6 -0
- package/src/rendering/localization.ts +20 -0
- package/src/rendering/renderers/AbstractRenderer.ts +222 -0
- package/src/rendering/renderers/CanvasRenderer.ts +296 -0
- package/src/rendering/renderers/DummyRenderer.test.ts +42 -0
- package/src/rendering/renderers/DummyRenderer.ts +136 -0
- package/src/rendering/renderers/SVGRenderer.ts +354 -0
- package/src/rendering/renderers/TextOnlyRenderer.ts +70 -0
- package/src/styles.js +7 -0
- package/src/testing/beforeEachFile.ts +8 -0
- package/src/testing/createEditor.ts +11 -0
- package/src/testing/global.d.ts +17 -0
- package/src/testing/lib.ts +3 -0
- package/src/testing/loadExpectExtensions.ts +25 -0
- package/src/testing/sendPenEvent.ts +31 -0
- package/src/testing/sendTouchEvent.ts +78 -0
- package/src/toolbar/HTMLToolbar.ts +492 -0
- package/src/toolbar/IconProvider.ts +736 -0
- package/src/toolbar/lib.ts +4 -0
- package/src/toolbar/localization.ts +106 -0
- package/src/toolbar/makeColorInput.ts +145 -0
- package/src/toolbar/toolbar.css +213 -0
- package/src/toolbar/types.ts +5 -0
- package/src/toolbar/widgets/ActionButtonWidget.ts +39 -0
- package/src/toolbar/widgets/BaseToolWidget.ts +56 -0
- package/src/toolbar/widgets/BaseWidget.ts +377 -0
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +167 -0
- package/src/toolbar/widgets/EraserToolWidget.ts +85 -0
- package/src/toolbar/widgets/HandToolWidget.ts +250 -0
- package/src/toolbar/widgets/InsertImageWidget.css +44 -0
- package/src/toolbar/widgets/InsertImageWidget.ts +223 -0
- package/src/toolbar/widgets/OverflowWidget.css +27 -0
- package/src/toolbar/widgets/OverflowWidget.ts +92 -0
- package/src/toolbar/widgets/PenToolWidget.ts +288 -0
- package/src/toolbar/widgets/SelectionToolWidget.ts +190 -0
- package/src/toolbar/widgets/TextToolWidget.ts +145 -0
- package/src/toolbar/widgets/lib.ts +13 -0
- package/src/tools/BaseTool.ts +76 -0
- package/src/tools/Eraser.test.ts +103 -0
- package/src/tools/Eraser.ts +139 -0
- package/src/tools/FindTool.css +7 -0
- package/src/tools/FindTool.ts +152 -0
- package/src/tools/PanZoom.test.ts +310 -0
- package/src/tools/PanZoom.ts +520 -0
- package/src/tools/PasteHandler.ts +95 -0
- package/src/tools/Pen.test.ts +194 -0
- package/src/tools/Pen.ts +226 -0
- package/src/tools/PipetteTool.ts +55 -0
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +28 -0
- package/src/tools/SelectionTool/Selection.ts +607 -0
- package/src/tools/SelectionTool/SelectionHandle.ts +108 -0
- package/src/tools/SelectionTool/SelectionTool.css +23 -0
- package/src/tools/SelectionTool/SelectionTool.test.ts +261 -0
- package/src/tools/SelectionTool/SelectionTool.ts +480 -0
- package/src/tools/SelectionTool/TransformMode.ts +114 -0
- package/src/tools/SelectionTool/types.ts +11 -0
- package/src/tools/TextTool.ts +326 -0
- package/src/tools/ToolController.ts +178 -0
- package/src/tools/ToolEnabledGroup.ts +14 -0
- package/src/tools/ToolSwitcherShortcut.ts +39 -0
- package/src/tools/ToolbarShortcutHandler.ts +34 -0
- package/src/tools/UndoRedoShortcut.test.ts +56 -0
- package/src/tools/UndoRedoShortcut.ts +25 -0
- package/src/tools/lib.ts +21 -0
- package/src/tools/localization.ts +66 -0
- package/src/types.ts +234 -0
- package/src/util/assertions.ts +55 -0
- package/src/util/fileToBase64.ts +18 -0
- package/src/util/untilNextAnimationFrame.ts +9 -0
- package/src/util/waitForTimeout.ts +9 -0
@@ -0,0 +1,258 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const LineSegment2_1 = __importDefault(require("../math/LineSegment2"));
|
7
|
+
const Mat33_1 = __importDefault(require("../math/Mat33"));
|
8
|
+
const Rect2_1 = __importDefault(require("../math/Rect2"));
|
9
|
+
const Vec2_1 = require("../math/Vec2");
|
10
|
+
const TextRenderingStyle_1 = require("../rendering/TextRenderingStyle");
|
11
|
+
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
12
|
+
const RestylableComponent_1 = require("./RestylableComponent");
|
13
|
+
const componentTypeId = 'text';
|
14
|
+
class TextComponent extends AbstractComponent_1.default {
|
15
|
+
constructor(textObjects, transform, style) {
|
16
|
+
super(componentTypeId);
|
17
|
+
this.textObjects = textObjects;
|
18
|
+
this.transform = transform;
|
19
|
+
this.style = style;
|
20
|
+
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
21
|
+
this.isRestylableComponent = true;
|
22
|
+
this.recomputeBBox();
|
23
|
+
// If this has no direct children, choose a style representative of this' content
|
24
|
+
// (useful for estimating the style of the TextComponent).
|
25
|
+
const hasDirectContent = textObjects.some(obj => typeof obj === 'string');
|
26
|
+
if (!hasDirectContent && textObjects.length > 0) {
|
27
|
+
this.style = textObjects[0].getTextStyle();
|
28
|
+
}
|
29
|
+
}
|
30
|
+
static applyTextStyles(ctx, style) {
|
31
|
+
var _a, _b;
|
32
|
+
// Quote the font family if necessary.
|
33
|
+
const fontFamily = style.fontFamily.match(/\s/) ? style.fontFamily.replace(/["]/g, '\\"') : style.fontFamily;
|
34
|
+
ctx.font = [
|
35
|
+
((_a = style.size) !== null && _a !== void 0 ? _a : 12) + 'px',
|
36
|
+
(_b = style.fontWeight) !== null && _b !== void 0 ? _b : '',
|
37
|
+
`${fontFamily}`,
|
38
|
+
style.fontWeight
|
39
|
+
].join(' ');
|
40
|
+
ctx.textAlign = 'left';
|
41
|
+
}
|
42
|
+
// Roughly estimate the bounding box of `text`. Use if no CanvasRenderingContext2D is available.
|
43
|
+
static estimateTextDimens(text, style) {
|
44
|
+
const widthEst = text.length * style.size;
|
45
|
+
const heightEst = style.size;
|
46
|
+
// Text is drawn with (0, 0) as its baseline. As such, the majority of the text's height should
|
47
|
+
// be above (0, 0).
|
48
|
+
return new Rect2_1.default(0, -heightEst * 2 / 3, widthEst, heightEst);
|
49
|
+
}
|
50
|
+
// Returns the bounding box of `text`. This is approximate if no Canvas is available.
|
51
|
+
static getTextDimens(text, style) {
|
52
|
+
var _a, _b;
|
53
|
+
(_a = TextComponent.textMeasuringCtx) !== null && _a !== void 0 ? _a : (TextComponent.textMeasuringCtx = (_b = document.createElement('canvas').getContext('2d')) !== null && _b !== void 0 ? _b : null);
|
54
|
+
if (!TextComponent.textMeasuringCtx) {
|
55
|
+
return this.estimateTextDimens(text, style);
|
56
|
+
}
|
57
|
+
const ctx = TextComponent.textMeasuringCtx;
|
58
|
+
TextComponent.applyTextStyles(ctx, style);
|
59
|
+
const measure = ctx.measureText(text);
|
60
|
+
// Text is drawn with (0,0) at the bottom left of the baseline.
|
61
|
+
const textY = -measure.actualBoundingBoxAscent;
|
62
|
+
const textHeight = measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent;
|
63
|
+
return new Rect2_1.default(0, textY, measure.width, textHeight);
|
64
|
+
}
|
65
|
+
computeBBoxOfPart(part) {
|
66
|
+
if (typeof part === 'string') {
|
67
|
+
const textBBox = TextComponent.getTextDimens(part, this.style);
|
68
|
+
return textBBox.transformedBoundingBox(this.transform);
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
const bbox = part.contentBBox.transformedBoundingBox(this.transform);
|
72
|
+
return bbox;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
recomputeBBox() {
|
76
|
+
let bbox = null;
|
77
|
+
for (const textObject of this.textObjects) {
|
78
|
+
const currentBBox = this.computeBBoxOfPart(textObject);
|
79
|
+
bbox !== null && bbox !== void 0 ? bbox : (bbox = currentBBox);
|
80
|
+
bbox = bbox.union(currentBBox);
|
81
|
+
}
|
82
|
+
this.contentBBox = bbox !== null && bbox !== void 0 ? bbox : Rect2_1.default.empty;
|
83
|
+
}
|
84
|
+
renderInternal(canvas) {
|
85
|
+
const cursor = this.transform;
|
86
|
+
for (const textObject of this.textObjects) {
|
87
|
+
if (typeof textObject === 'string') {
|
88
|
+
canvas.drawText(textObject, cursor, this.style);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
canvas.pushTransform(cursor);
|
92
|
+
textObject.renderInternal(canvas);
|
93
|
+
canvas.popTransform();
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
render(canvas, _visibleRect) {
|
98
|
+
canvas.startObject(this.contentBBox);
|
99
|
+
this.renderInternal(canvas);
|
100
|
+
canvas.endObject(this.getLoadSaveData());
|
101
|
+
}
|
102
|
+
getProportionalRenderingTime() {
|
103
|
+
return this.textObjects.length;
|
104
|
+
}
|
105
|
+
intersects(lineSegment) {
|
106
|
+
// Convert canvas space to internal space.
|
107
|
+
const invTransform = this.transform.inverse();
|
108
|
+
const p1InThisSpace = invTransform.transformVec2(lineSegment.p1);
|
109
|
+
const p2InThisSpace = invTransform.transformVec2(lineSegment.p2);
|
110
|
+
lineSegment = new LineSegment2_1.default(p1InThisSpace, p2InThisSpace);
|
111
|
+
for (const subObject of this.textObjects) {
|
112
|
+
if (typeof subObject === 'string') {
|
113
|
+
const textBBox = TextComponent.getTextDimens(subObject, this.style);
|
114
|
+
// TODO: Use a better intersection check. Perhaps draw the text onto a CanvasElement and
|
115
|
+
// use pixel-testing to check for intersection with its contour.
|
116
|
+
if (textBBox.getEdges().some(edge => lineSegment.intersection(edge) !== null)) {
|
117
|
+
return true;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
if (subObject.intersects(lineSegment)) {
|
122
|
+
return true;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
return false;
|
127
|
+
}
|
128
|
+
getStyle() {
|
129
|
+
return {
|
130
|
+
color: this.style.renderingStyle.fill,
|
131
|
+
// Make a copy
|
132
|
+
textStyle: Object.assign(Object.assign({}, this.style), { renderingStyle: Object.assign({}, this.style.renderingStyle) }),
|
133
|
+
};
|
134
|
+
}
|
135
|
+
updateStyle(style) {
|
136
|
+
return (0, RestylableComponent_1.createRestyleComponentCommand)(this.getStyle(), style, this);
|
137
|
+
}
|
138
|
+
forceStyle(style, editor) {
|
139
|
+
if (style.textStyle) {
|
140
|
+
this.style = (0, TextRenderingStyle_1.cloneTextStyle)(style.textStyle);
|
141
|
+
}
|
142
|
+
else if (style.color) {
|
143
|
+
this.style = Object.assign(Object.assign({}, this.style), { renderingStyle: Object.assign(Object.assign({}, this.style.renderingStyle), { fill: style.color }) });
|
144
|
+
}
|
145
|
+
else {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
for (const child of this.textObjects) {
|
149
|
+
if (child instanceof TextComponent) {
|
150
|
+
child.forceStyle(style, editor);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
if (editor) {
|
154
|
+
editor.image.queueRerenderOf(this);
|
155
|
+
editor.queueRerender();
|
156
|
+
}
|
157
|
+
}
|
158
|
+
// See this.getStyle
|
159
|
+
getTextStyle() {
|
160
|
+
return (0, TextRenderingStyle_1.cloneTextStyle)(this.style);
|
161
|
+
}
|
162
|
+
getBaselinePos() {
|
163
|
+
return this.transform.transformVec2(Vec2_1.Vec2.zero);
|
164
|
+
}
|
165
|
+
getTransform() {
|
166
|
+
return this.transform;
|
167
|
+
}
|
168
|
+
applyTransformation(affineTransfm) {
|
169
|
+
this.transform = affineTransfm.rightMul(this.transform);
|
170
|
+
this.recomputeBBox();
|
171
|
+
}
|
172
|
+
createClone() {
|
173
|
+
const clonedTextObjects = this.textObjects.map(obj => {
|
174
|
+
if (typeof obj === 'string') {
|
175
|
+
return obj;
|
176
|
+
}
|
177
|
+
else {
|
178
|
+
return obj.createClone();
|
179
|
+
}
|
180
|
+
});
|
181
|
+
return new TextComponent(clonedTextObjects, this.transform, this.style);
|
182
|
+
}
|
183
|
+
getText() {
|
184
|
+
const result = [];
|
185
|
+
for (const textObject of this.textObjects) {
|
186
|
+
if (typeof textObject === 'string') {
|
187
|
+
result.push(textObject);
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
result.push(textObject.getText());
|
191
|
+
}
|
192
|
+
}
|
193
|
+
return result.join('\n');
|
194
|
+
}
|
195
|
+
description(localizationTable) {
|
196
|
+
return localizationTable.text(this.getText());
|
197
|
+
}
|
198
|
+
// Do not rely on the output of `serializeToJSON` taking any particular format.
|
199
|
+
serializeToJSON() {
|
200
|
+
const serializableStyle = (0, TextRenderingStyle_1.textStyleToJSON)(this.style);
|
201
|
+
const serializedTextObjects = this.textObjects.map(text => {
|
202
|
+
if (typeof text === 'string') {
|
203
|
+
return {
|
204
|
+
text,
|
205
|
+
};
|
206
|
+
}
|
207
|
+
else {
|
208
|
+
return {
|
209
|
+
json: text.serializeToJSON(),
|
210
|
+
};
|
211
|
+
}
|
212
|
+
});
|
213
|
+
return {
|
214
|
+
textObjects: serializedTextObjects,
|
215
|
+
transform: this.transform.toArray(),
|
216
|
+
style: serializableStyle,
|
217
|
+
};
|
218
|
+
}
|
219
|
+
// @internal
|
220
|
+
static deserializeFromString(json) {
|
221
|
+
if (typeof json === 'string') {
|
222
|
+
json = JSON.parse(json);
|
223
|
+
}
|
224
|
+
const style = (0, TextRenderingStyle_1.textStyleFromJSON)(json.style);
|
225
|
+
const textObjects = json.textObjects.map((data) => {
|
226
|
+
var _a;
|
227
|
+
if (((_a = data.text) !== null && _a !== void 0 ? _a : null) !== null) {
|
228
|
+
return data.text;
|
229
|
+
}
|
230
|
+
return TextComponent.deserializeFromString(data.json);
|
231
|
+
});
|
232
|
+
json.transform = json.transform.filter((elem) => typeof elem === 'number');
|
233
|
+
if (json.transform.length !== 9) {
|
234
|
+
throw new Error(`Unable to deserialize transform, ${json.transform}.`);
|
235
|
+
}
|
236
|
+
const transformData = json.transform;
|
237
|
+
const transform = new Mat33_1.default(...transformData);
|
238
|
+
return new TextComponent(textObjects, transform, style);
|
239
|
+
}
|
240
|
+
static fromLines(lines, transform, style) {
|
241
|
+
let lastComponent = null;
|
242
|
+
const components = [];
|
243
|
+
for (const line of lines) {
|
244
|
+
let position = Vec2_1.Vec2.zero;
|
245
|
+
if (lastComponent) {
|
246
|
+
const lineMargin = Math.floor(style.size);
|
247
|
+
position = lastComponent.getBBox().bottomLeft.plus(Vec2_1.Vec2.unitY.times(lineMargin));
|
248
|
+
}
|
249
|
+
const component = new TextComponent([line], Mat33_1.default.translation(position), style);
|
250
|
+
components.push(component);
|
251
|
+
lastComponent = component;
|
252
|
+
}
|
253
|
+
return new TextComponent(components, transform, style);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
exports.default = TextComponent;
|
257
|
+
TextComponent.textMeasuringCtx = null;
|
258
|
+
AbstractComponent_1.default.registerComponent(componentTypeId, (data) => TextComponent.deserializeFromString(data));
|
@@ -0,0 +1,18 @@
|
|
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
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
//
|
3
|
+
// Stores objects loaded from an SVG that aren't recognised by the editor.
|
4
|
+
// @internal
|
5
|
+
// @packageDocumentation
|
6
|
+
//
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
9
|
+
};
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
+
const Rect2_1 = __importDefault(require("../math/Rect2"));
|
12
|
+
const SVGRenderer_1 = __importDefault(require("../rendering/renderers/SVGRenderer"));
|
13
|
+
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
14
|
+
const componentId = 'unknown-svg-object';
|
15
|
+
class UnknownSVGObject extends AbstractComponent_1.default {
|
16
|
+
constructor(svgObject) {
|
17
|
+
super(componentId);
|
18
|
+
this.svgObject = svgObject;
|
19
|
+
this.contentBBox = Rect2_1.default.of(svgObject.getBoundingClientRect());
|
20
|
+
}
|
21
|
+
render(canvas, _visibleRect) {
|
22
|
+
if (!(canvas instanceof SVGRenderer_1.default)) {
|
23
|
+
// Don't draw unrenderable objects if we can't
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
canvas.drawSVGElem(this.svgObject);
|
27
|
+
}
|
28
|
+
intersects(lineSegment) {
|
29
|
+
return this.contentBBox.getEdges().some(edge => edge.intersection(lineSegment) !== null);
|
30
|
+
}
|
31
|
+
applyTransformation(_affineTransfm) {
|
32
|
+
}
|
33
|
+
isSelectable() {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
createClone() {
|
37
|
+
return new UnknownSVGObject(this.svgObject.cloneNode(true));
|
38
|
+
}
|
39
|
+
description(localization) {
|
40
|
+
return localization.svgObject;
|
41
|
+
}
|
42
|
+
serializeToJSON() {
|
43
|
+
return JSON.stringify({
|
44
|
+
html: this.svgObject.outerHTML,
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
exports.default = UnknownSVGObject;
|
49
|
+
// null: Do not deserialize UnknownSVGObjects.
|
50
|
+
AbstractComponent_1.default.registerComponent(componentId, null);
|
@@ -0,0 +1,19 @@
|
|
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
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.makeArrowBuilder = void 0;
|
30
|
+
const Path_1 = __importStar(require("../../math/Path"));
|
31
|
+
const Stroke_1 = __importDefault(require("../Stroke"));
|
32
|
+
const makeArrowBuilder = (initialPoint, viewport) => {
|
33
|
+
return new ArrowBuilder(initialPoint, viewport);
|
34
|
+
};
|
35
|
+
exports.makeArrowBuilder = makeArrowBuilder;
|
36
|
+
class ArrowBuilder {
|
37
|
+
constructor(startPoint, viewport) {
|
38
|
+
this.startPoint = startPoint;
|
39
|
+
this.viewport = viewport;
|
40
|
+
this.endPoint = startPoint;
|
41
|
+
}
|
42
|
+
getLineWidth() {
|
43
|
+
return Math.max(this.endPoint.width, this.startPoint.width);
|
44
|
+
}
|
45
|
+
getBBox() {
|
46
|
+
const preview = this.buildPreview();
|
47
|
+
return preview.getBBox();
|
48
|
+
}
|
49
|
+
buildPreview() {
|
50
|
+
const lineStartPoint = this.startPoint.pos;
|
51
|
+
const endPoint = this.endPoint.pos;
|
52
|
+
const toEnd = endPoint.minus(lineStartPoint).normalized();
|
53
|
+
const arrowLength = endPoint.minus(lineStartPoint).length();
|
54
|
+
// Ensure that the arrow tip is smaller than the arrow.
|
55
|
+
const arrowTipSize = Math.min(this.getLineWidth(), arrowLength / 2);
|
56
|
+
const startSize = this.startPoint.width / 2;
|
57
|
+
const endSize = this.endPoint.width / 2;
|
58
|
+
const arrowTipBase = endPoint.minus(toEnd.times(arrowTipSize));
|
59
|
+
// Scaled normal vectors.
|
60
|
+
const lineNormal = toEnd.orthog();
|
61
|
+
const scaledStartNormal = lineNormal.times(startSize);
|
62
|
+
const scaledBaseNormal = lineNormal.times(endSize);
|
63
|
+
const path = new Path_1.default(arrowTipBase.minus(scaledBaseNormal), [
|
64
|
+
// Stem
|
65
|
+
{
|
66
|
+
kind: Path_1.PathCommandType.LineTo,
|
67
|
+
point: lineStartPoint.minus(scaledStartNormal),
|
68
|
+
},
|
69
|
+
{
|
70
|
+
kind: Path_1.PathCommandType.LineTo,
|
71
|
+
point: lineStartPoint.plus(scaledStartNormal),
|
72
|
+
},
|
73
|
+
{
|
74
|
+
kind: Path_1.PathCommandType.LineTo,
|
75
|
+
point: arrowTipBase.plus(scaledBaseNormal),
|
76
|
+
},
|
77
|
+
// Head
|
78
|
+
{
|
79
|
+
kind: Path_1.PathCommandType.LineTo,
|
80
|
+
point: arrowTipBase.plus(lineNormal.times(arrowTipSize).plus(scaledBaseNormal)),
|
81
|
+
},
|
82
|
+
{
|
83
|
+
kind: Path_1.PathCommandType.LineTo,
|
84
|
+
point: endPoint.plus(toEnd.times(endSize)),
|
85
|
+
},
|
86
|
+
{
|
87
|
+
kind: Path_1.PathCommandType.LineTo,
|
88
|
+
point: arrowTipBase.plus(lineNormal.times(-arrowTipSize).minus(scaledBaseNormal)),
|
89
|
+
},
|
90
|
+
{
|
91
|
+
kind: Path_1.PathCommandType.LineTo,
|
92
|
+
point: arrowTipBase.minus(scaledBaseNormal),
|
93
|
+
},
|
94
|
+
// Round all points in the arrow (to remove unnecessary decimal places)
|
95
|
+
]).mapPoints(point => this.viewport.roundPoint(point));
|
96
|
+
const preview = new Stroke_1.default([
|
97
|
+
{
|
98
|
+
startPoint: path.startPoint,
|
99
|
+
commands: path.parts,
|
100
|
+
style: {
|
101
|
+
fill: this.startPoint.color,
|
102
|
+
}
|
103
|
+
}
|
104
|
+
]);
|
105
|
+
return preview;
|
106
|
+
}
|
107
|
+
build() {
|
108
|
+
return this.buildPreview();
|
109
|
+
}
|
110
|
+
preview(renderer) {
|
111
|
+
this.buildPreview().render(renderer);
|
112
|
+
}
|
113
|
+
addPoint(point) {
|
114
|
+
this.endPoint = point;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
exports.default = ArrowBuilder;
|
@@ -0,0 +1,33 @@
|
|
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
|
+
}
|
@@ -0,0 +1,173 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.makeFreehandLineBuilder = void 0;
|
7
|
+
const Vec2_1 = require("../../math/Vec2");
|
8
|
+
const Rect2_1 = __importDefault(require("../../math/Rect2"));
|
9
|
+
const Path_1 = require("../../math/Path");
|
10
|
+
const Stroke_1 = __importDefault(require("../Stroke"));
|
11
|
+
const Viewport_1 = __importDefault(require("../../Viewport"));
|
12
|
+
const StrokeSmoother_1 = require("../util/StrokeSmoother");
|
13
|
+
const Color4_1 = __importDefault(require("../../Color4"));
|
14
|
+
const makeFreehandLineBuilder = (initialPoint, viewport) => {
|
15
|
+
// Don't smooth if input is more than ± 3 pixels from the true curve, do smooth if
|
16
|
+
// less than ±1 px from the curve.
|
17
|
+
const maxSmoothingDist = viewport.getSizeOfPixelOnCanvas() * 3;
|
18
|
+
const minSmoothingDist = viewport.getSizeOfPixelOnCanvas();
|
19
|
+
return new FreehandLineBuilder(initialPoint, minSmoothingDist, maxSmoothingDist, viewport);
|
20
|
+
};
|
21
|
+
exports.makeFreehandLineBuilder = makeFreehandLineBuilder;
|
22
|
+
// Handles stroke smoothing and creates Strokes from user/stylus input.
|
23
|
+
class FreehandLineBuilder {
|
24
|
+
constructor(startPoint, minFitAllowed, maxFitAllowed, viewport) {
|
25
|
+
this.startPoint = startPoint;
|
26
|
+
this.minFitAllowed = minFitAllowed;
|
27
|
+
this.viewport = viewport;
|
28
|
+
this.isFirstSegment = true;
|
29
|
+
this.parts = [];
|
30
|
+
this.widthAverageNumSamples = 1;
|
31
|
+
this.curveFitter = new StrokeSmoother_1.StrokeSmoother(startPoint, minFitAllowed, maxFitAllowed, (curve) => this.addCurve(curve));
|
32
|
+
this.averageWidth = startPoint.width;
|
33
|
+
this.bbox = new Rect2_1.default(this.startPoint.pos.x, this.startPoint.pos.y, 0, 0);
|
34
|
+
}
|
35
|
+
getBBox() {
|
36
|
+
return this.bbox;
|
37
|
+
}
|
38
|
+
getRenderingStyle() {
|
39
|
+
return {
|
40
|
+
fill: Color4_1.default.transparent,
|
41
|
+
stroke: {
|
42
|
+
color: this.startPoint.color,
|
43
|
+
width: this.roundDistance(this.averageWidth),
|
44
|
+
}
|
45
|
+
};
|
46
|
+
}
|
47
|
+
previewCurrentPath() {
|
48
|
+
const path = this.parts.slice();
|
49
|
+
const commands = [...path, ...this.curveToPathCommands(this.curveFitter.preview())];
|
50
|
+
const startPoint = this.startPoint.pos;
|
51
|
+
return {
|
52
|
+
startPoint,
|
53
|
+
commands,
|
54
|
+
style: this.getRenderingStyle(),
|
55
|
+
};
|
56
|
+
}
|
57
|
+
previewFullPath() {
|
58
|
+
const preview = this.previewCurrentPath();
|
59
|
+
if (preview) {
|
60
|
+
return [preview];
|
61
|
+
}
|
62
|
+
return null;
|
63
|
+
}
|
64
|
+
previewStroke() {
|
65
|
+
const pathPreview = this.previewFullPath();
|
66
|
+
if (pathPreview) {
|
67
|
+
return new Stroke_1.default(pathPreview);
|
68
|
+
}
|
69
|
+
return null;
|
70
|
+
}
|
71
|
+
preview(renderer) {
|
72
|
+
const paths = this.previewFullPath();
|
73
|
+
if (paths) {
|
74
|
+
const approxBBox = this.viewport.visibleRect;
|
75
|
+
renderer.startObject(approxBBox);
|
76
|
+
for (const path of paths) {
|
77
|
+
renderer.drawPath(path);
|
78
|
+
}
|
79
|
+
renderer.endObject();
|
80
|
+
}
|
81
|
+
}
|
82
|
+
build() {
|
83
|
+
this.curveFitter.finalizeCurrentCurve();
|
84
|
+
return this.previewStroke();
|
85
|
+
}
|
86
|
+
getMinFit() {
|
87
|
+
let minFit = Math.min(this.minFitAllowed, this.averageWidth / 3);
|
88
|
+
if (minFit < 1e-10) {
|
89
|
+
minFit = this.minFitAllowed;
|
90
|
+
}
|
91
|
+
return minFit;
|
92
|
+
}
|
93
|
+
roundPoint(point) {
|
94
|
+
const minFit = this.getMinFit();
|
95
|
+
return Viewport_1.default.roundPoint(point, minFit);
|
96
|
+
}
|
97
|
+
roundDistance(dist) {
|
98
|
+
const minFit = this.getMinFit();
|
99
|
+
return Viewport_1.default.roundPoint(dist, minFit);
|
100
|
+
}
|
101
|
+
curveToPathCommands(curve) {
|
102
|
+
// Case where no points have been added
|
103
|
+
if (!curve) {
|
104
|
+
// Don't create a circle around the initial point if the stroke has more than one point.
|
105
|
+
if (!this.isFirstSegment) {
|
106
|
+
return [];
|
107
|
+
}
|
108
|
+
// Make the circle small -- because of the stroke style, we'll be drawing a stroke around it.
|
109
|
+
const width = Viewport_1.default.roundPoint(this.averageWidth / 10, Math.min(this.minFitAllowed, this.averageWidth / 10));
|
110
|
+
const center = this.roundPoint(this.startPoint.pos);
|
111
|
+
// Start on the right, cycle clockwise:
|
112
|
+
// |
|
113
|
+
// ----- ←
|
114
|
+
// |
|
115
|
+
// Draw a circle-ish shape around the start point
|
116
|
+
return [
|
117
|
+
{
|
118
|
+
kind: Path_1.PathCommandType.QuadraticBezierTo,
|
119
|
+
controlPoint: center.plus(Vec2_1.Vec2.of(width, width)),
|
120
|
+
// Bottom of the circle
|
121
|
+
// |
|
122
|
+
// -----
|
123
|
+
// |
|
124
|
+
// ↑
|
125
|
+
endPoint: center.plus(Vec2_1.Vec2.of(0, width)),
|
126
|
+
},
|
127
|
+
{
|
128
|
+
kind: Path_1.PathCommandType.QuadraticBezierTo,
|
129
|
+
controlPoint: center.plus(Vec2_1.Vec2.of(-width, width)),
|
130
|
+
endPoint: center.plus(Vec2_1.Vec2.of(-width, 0)),
|
131
|
+
},
|
132
|
+
{
|
133
|
+
kind: Path_1.PathCommandType.QuadraticBezierTo,
|
134
|
+
controlPoint: center.plus(Vec2_1.Vec2.of(-width, -width)),
|
135
|
+
endPoint: center.plus(Vec2_1.Vec2.of(0, -width)),
|
136
|
+
},
|
137
|
+
{
|
138
|
+
kind: Path_1.PathCommandType.QuadraticBezierTo,
|
139
|
+
controlPoint: center.plus(Vec2_1.Vec2.of(width, -width)),
|
140
|
+
endPoint: center.plus(Vec2_1.Vec2.of(width, 0)),
|
141
|
+
}
|
142
|
+
];
|
143
|
+
}
|
144
|
+
const result = [];
|
145
|
+
if (this.isFirstSegment) {
|
146
|
+
result.push({
|
147
|
+
kind: Path_1.PathCommandType.MoveTo,
|
148
|
+
point: this.roundPoint(curve.startPoint),
|
149
|
+
});
|
150
|
+
}
|
151
|
+
result.push({
|
152
|
+
kind: Path_1.PathCommandType.QuadraticBezierTo,
|
153
|
+
controlPoint: this.roundPoint(curve.controlPoint),
|
154
|
+
endPoint: this.roundPoint(curve.endPoint),
|
155
|
+
});
|
156
|
+
return result;
|
157
|
+
}
|
158
|
+
addCurve(curve) {
|
159
|
+
const parts = this.curveToPathCommands(curve);
|
160
|
+
this.parts.push(...parts);
|
161
|
+
if (this.isFirstSegment) {
|
162
|
+
this.isFirstSegment = false;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
addPoint(newPoint) {
|
166
|
+
this.curveFitter.addPoint(newPoint);
|
167
|
+
this.widthAverageNumSamples++;
|
168
|
+
this.averageWidth =
|
169
|
+
this.averageWidth * (this.widthAverageNumSamples - 1) / this.widthAverageNumSamples
|
170
|
+
+ newPoint.width / this.widthAverageNumSamples;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
exports.default = FreehandLineBuilder;
|