js-draw 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -0
- package/dist/cjs/src/Color4.d.ts +69 -0
- package/dist/cjs/src/Color4.js +264 -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 +475 -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 +43 -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 +75 -0
- package/dist/cjs/src/components/Stroke.js +225 -0
- package/dist/cjs/src/components/TextComponent.d.ts +75 -0
- package/dist/cjs/src/components/TextComponent.js +280 -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 +13 -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 +64 -0
- package/dist/cjs/src/lib.js +93 -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 +7 -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/SoundUITool.d.ts +24 -0
- package/dist/cjs/src/tools/SoundUITool.js +164 -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 +192 -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 +17 -0
- package/dist/cjs/src/tools/lib.js +38 -0
- package/dist/cjs/src/tools/localization.d.ts +31 -0
- package/dist/cjs/src/tools/localization.js +33 -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 +69 -0
- package/dist/mjs/src/Color4.mjs +257 -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 +445 -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 +43 -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 +75 -0
- package/dist/mjs/src/components/Stroke.mjs +219 -0
- package/dist/mjs/src/components/TextComponent.d.ts +75 -0
- package/dist/mjs/src/components/TextComponent.mjs +274 -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 +13 -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 +64 -0
- package/dist/mjs/src/lib.mjs +64 -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 +7 -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/SoundUITool.d.ts +24 -0
- package/dist/mjs/src/tools/SoundUITool.mjs +158 -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 +163 -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 +17 -0
- package/dist/mjs/src/tools/lib.mjs +17 -0
- package/dist/mjs/src/tools/localization.d.ts +31 -0
- package/dist/mjs/src/tools/localization.mjs +30 -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 +6 -4
- package/src/Editor.css +86 -0
- package/src/styles.js +7 -0
- package/src/toolbar/toolbar.css +213 -0
- package/src/toolbar/widgets/InsertImageWidget.css +44 -0
- package/src/toolbar/widgets/OverflowWidget.css +27 -0
- package/src/tools/FindTool.css +7 -0
- package/src/tools/SelectionTool/SelectionTool.css +23 -0
- package/src/tools/SoundUITool.css +15 -0
- package/src/tools/tools.css +4 -0
@@ -0,0 +1,88 @@
|
|
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.isRestylableComponent = exports.createRestyleComponentCommand = void 0;
|
7
|
+
const Color4_1 = __importDefault(require("../Color4"));
|
8
|
+
const SerializableCommand_1 = __importDefault(require("../commands/SerializableCommand"));
|
9
|
+
const UnresolvedCommand_1 = __importDefault(require("../commands/UnresolvedCommand"));
|
10
|
+
const TextRenderingStyle_1 = require("../rendering/TextRenderingStyle");
|
11
|
+
const serializeComponentStyle = (style) => {
|
12
|
+
const result = {};
|
13
|
+
if (style.color) {
|
14
|
+
result.color = style.color.toHexString();
|
15
|
+
}
|
16
|
+
if (style.textStyle) {
|
17
|
+
result.textStyle = (0, TextRenderingStyle_1.textStyleToJSON)(style.textStyle);
|
18
|
+
}
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
const deserializeComponentStyle = (json) => {
|
22
|
+
const color = json.color ? Color4_1.default.fromHex(json.color) : undefined;
|
23
|
+
const textStyle = json.textStyle ? (0, TextRenderingStyle_1.textStyleFromJSON)(json.textStyle) : undefined;
|
24
|
+
return {
|
25
|
+
color,
|
26
|
+
textStyle,
|
27
|
+
};
|
28
|
+
};
|
29
|
+
// For internal use by Components implementing `updateStyle`:
|
30
|
+
const createRestyleComponentCommand = (initialStyle, newStyle, component) => {
|
31
|
+
return new DefaultRestyleComponentCommand(initialStyle, newStyle, component.getId(), component);
|
32
|
+
};
|
33
|
+
exports.createRestyleComponentCommand = createRestyleComponentCommand;
|
34
|
+
// Returns true if `component` is a `RestylableComponent`.
|
35
|
+
const isRestylableComponent = (component) => {
|
36
|
+
const hasMethods = 'getStyle' in component && 'updateStyle' in component && 'forceStyle' in component;
|
37
|
+
if (!hasMethods) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
if (!('isRestylableComponent' in component) || !component['isRestylableComponent']) {
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
return true;
|
44
|
+
};
|
45
|
+
exports.isRestylableComponent = isRestylableComponent;
|
46
|
+
const defaultRestyleComponentCommandId = 'default-restyle-element';
|
47
|
+
class DefaultRestyleComponentCommand extends UnresolvedCommand_1.default {
|
48
|
+
constructor(originalStyle, newStyle, componentID, component) {
|
49
|
+
super(defaultRestyleComponentCommandId, componentID, component);
|
50
|
+
this.originalStyle = originalStyle;
|
51
|
+
this.newStyle = newStyle;
|
52
|
+
}
|
53
|
+
getComponent(editor) {
|
54
|
+
this.resolveComponent(editor.image);
|
55
|
+
const component = this.component;
|
56
|
+
if (!component || !component['forceStyle'] || !component['updateStyle']) {
|
57
|
+
throw new Error('this.component is missing forceStyle and/or updateStyle methods!');
|
58
|
+
}
|
59
|
+
return component;
|
60
|
+
}
|
61
|
+
apply(editor) {
|
62
|
+
this.getComponent(editor).forceStyle(this.newStyle, editor);
|
63
|
+
}
|
64
|
+
unapply(editor) {
|
65
|
+
this.getComponent(editor).forceStyle(this.originalStyle, editor);
|
66
|
+
}
|
67
|
+
description(editor, localizationTable) {
|
68
|
+
return localizationTable.restyledElement(this.getComponent(editor).description(localizationTable));
|
69
|
+
}
|
70
|
+
serializeToJSON() {
|
71
|
+
return {
|
72
|
+
id: this.componentID,
|
73
|
+
originalStyle: serializeComponentStyle(this.originalStyle),
|
74
|
+
newStyle: serializeComponentStyle(this.newStyle),
|
75
|
+
};
|
76
|
+
}
|
77
|
+
}
|
78
|
+
(() => {
|
79
|
+
SerializableCommand_1.default.register(defaultRestyleComponentCommandId, (json, _editor) => {
|
80
|
+
const origStyle = deserializeComponentStyle(json.originalStyle);
|
81
|
+
const newStyle = deserializeComponentStyle(json.newStyle);
|
82
|
+
const id = json.id;
|
83
|
+
if (typeof json.id !== 'string') {
|
84
|
+
throw new Error(`json.id is of type ${(typeof json.id)}, not string.`);
|
85
|
+
}
|
86
|
+
return new DefaultRestyleComponentCommand(origStyle, newStyle, id);
|
87
|
+
});
|
88
|
+
})();
|
@@ -0,0 +1,21 @@
|
|
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
|
+
type GlobalAttrsList = Array<[string, string | null]>;
|
8
|
+
export default class SVGGlobalAttributesObject extends AbstractComponent {
|
9
|
+
private readonly attrs;
|
10
|
+
protected contentBBox: Rect2;
|
11
|
+
constructor(attrs: GlobalAttrsList);
|
12
|
+
render(canvas: AbstractRenderer, _visibleRect?: Rect2): void;
|
13
|
+
intersects(_lineSegment: LineSegment2): boolean;
|
14
|
+
protected applyTransformation(_affineTransfm: Mat33): void;
|
15
|
+
isSelectable(): boolean;
|
16
|
+
protected createClone(): SVGGlobalAttributesObject;
|
17
|
+
description(localization: ImageComponentLocalization): string;
|
18
|
+
protected serializeToJSON(): string | null;
|
19
|
+
static deserializeFromString(data: string): AbstractComponent;
|
20
|
+
}
|
21
|
+
export {};
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
//
|
3
|
+
// Used by `SVGLoader`s to store unrecognised global attributes
|
4
|
+
// (e.g. unrecognised XML namespace declarations).
|
5
|
+
// @internal
|
6
|
+
// @packageDocumentation
|
7
|
+
//
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
const Rect2_1 = __importDefault(require("../math/Rect2"));
|
13
|
+
const SVGRenderer_1 = __importDefault(require("../rendering/renderers/SVGRenderer"));
|
14
|
+
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
15
|
+
const componentKind = 'svg-global-attributes';
|
16
|
+
// Stores global SVG attributes (e.g. namespace identifiers.)
|
17
|
+
class SVGGlobalAttributesObject extends AbstractComponent_1.default {
|
18
|
+
constructor(attrs) {
|
19
|
+
super(componentKind);
|
20
|
+
this.attrs = attrs;
|
21
|
+
this.contentBBox = Rect2_1.default.empty;
|
22
|
+
}
|
23
|
+
render(canvas, _visibleRect) {
|
24
|
+
if (!(canvas instanceof SVGRenderer_1.default)) {
|
25
|
+
// Don't draw unrenderable objects if we can't
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
for (const [attr, value] of this.attrs) {
|
29
|
+
canvas.setRootSVGAttribute(attr, value);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
intersects(_lineSegment) {
|
33
|
+
return false;
|
34
|
+
}
|
35
|
+
applyTransformation(_affineTransfm) {
|
36
|
+
}
|
37
|
+
isSelectable() {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
createClone() {
|
41
|
+
return new SVGGlobalAttributesObject(this.attrs);
|
42
|
+
}
|
43
|
+
description(localization) {
|
44
|
+
return localization.svgObject;
|
45
|
+
}
|
46
|
+
serializeToJSON() {
|
47
|
+
return JSON.stringify(this.attrs);
|
48
|
+
}
|
49
|
+
static deserializeFromString(data) {
|
50
|
+
const json = JSON.parse(data);
|
51
|
+
const attrs = [];
|
52
|
+
const numericAndSpaceContentExp = /^[ \t\n0-9.-eE]+$/;
|
53
|
+
// Don't deserialize all attributes, just those that should be safe.
|
54
|
+
for (const [key, val] of json) {
|
55
|
+
if (key === 'viewBox' || key === 'width' || key === 'height') {
|
56
|
+
if (val && numericAndSpaceContentExp.exec(val)) {
|
57
|
+
attrs.push([key, val]);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return new SVGGlobalAttributesObject(attrs);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
exports.default = SVGGlobalAttributesObject;
|
65
|
+
AbstractComponent_1.default.registerComponent(componentKind, SVGGlobalAttributesObject.deserializeFromString);
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import SerializableCommand from '../commands/SerializableCommand';
|
2
|
+
import LineSegment2 from '../math/LineSegment2';
|
3
|
+
import Mat33 from '../math/Mat33';
|
4
|
+
import Path from '../math/Path';
|
5
|
+
import Rect2 from '../math/Rect2';
|
6
|
+
import Editor from '../Editor';
|
7
|
+
import AbstractRenderer, { RenderablePathSpec } from '../rendering/renderers/AbstractRenderer';
|
8
|
+
import AbstractComponent from './AbstractComponent';
|
9
|
+
import { ImageComponentLocalization } from './localization';
|
10
|
+
import RestyleableComponent, { ComponentStyle } from './RestylableComponent';
|
11
|
+
/**
|
12
|
+
* Represents an {@link AbstractComponent} made up of one or more {@link Path}s.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* For some {@link Editor} editor and `Stroke` stroke,
|
16
|
+
*
|
17
|
+
* **Restyling**:
|
18
|
+
* ```ts
|
19
|
+
* editor.dispatch(stroke.updateStyle({ color: Color4.red }));
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* **Transforming**:
|
23
|
+
* ```ts
|
24
|
+
* editor.dispatch(stroke.transformBy(Mat33.translation(Vec2.of(10, 0))));
|
25
|
+
* ```
|
26
|
+
*/
|
27
|
+
export default class Stroke extends AbstractComponent implements RestyleableComponent {
|
28
|
+
private parts;
|
29
|
+
protected contentBBox: Rect2;
|
30
|
+
readonly isRestylableComponent: true;
|
31
|
+
private approximateRenderingTime;
|
32
|
+
/**
|
33
|
+
* Creates a `Stroke` from the given `parts`. All parts should have the
|
34
|
+
* same color.
|
35
|
+
*
|
36
|
+
* @example
|
37
|
+
* ```ts
|
38
|
+
* // A path that starts at (1,1), moves to the right by (2, 0),
|
39
|
+
* // then moves down and right by (3, 3)
|
40
|
+
* const path = Path.fromString('m1,1 2,0 3,3');
|
41
|
+
*
|
42
|
+
* const stroke = new Stroke([
|
43
|
+
* // Fill with red
|
44
|
+
* path.toRenderable({ fill: Color4.red })
|
45
|
+
* ]);
|
46
|
+
* ```
|
47
|
+
*/
|
48
|
+
constructor(parts: RenderablePathSpec[]);
|
49
|
+
getStyle(): ComponentStyle;
|
50
|
+
updateStyle(style: ComponentStyle): SerializableCommand;
|
51
|
+
forceStyle(style: ComponentStyle, editor: Editor | null): void;
|
52
|
+
intersects(line: LineSegment2): boolean;
|
53
|
+
render(canvas: AbstractRenderer, visibleRect?: Rect2): void;
|
54
|
+
getProportionalRenderingTime(): number;
|
55
|
+
private bboxForPart;
|
56
|
+
protected applyTransformation(affineTransfm: Mat33): void;
|
57
|
+
/**
|
58
|
+
* @returns the {@link Path.union} of all paths that make up this stroke.
|
59
|
+
*/
|
60
|
+
getPath(): Path;
|
61
|
+
description(localization: ImageComponentLocalization): string;
|
62
|
+
protected createClone(): AbstractComponent;
|
63
|
+
protected serializeToJSON(): {
|
64
|
+
style: {
|
65
|
+
fill: string;
|
66
|
+
stroke: {
|
67
|
+
color: string;
|
68
|
+
width: number;
|
69
|
+
} | undefined;
|
70
|
+
};
|
71
|
+
path: string;
|
72
|
+
}[];
|
73
|
+
/** @internal */
|
74
|
+
static deserializeFromJSON(json: any): Stroke;
|
75
|
+
}
|
@@ -0,0 +1,225 @@
|
|
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 Path_1 = __importDefault(require("../math/Path"));
|
7
|
+
const Rect2_1 = __importDefault(require("../math/Rect2"));
|
8
|
+
const RenderingStyle_1 = require("../rendering/RenderingStyle");
|
9
|
+
const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
|
10
|
+
const RestylableComponent_1 = require("./RestylableComponent");
|
11
|
+
/**
|
12
|
+
* Represents an {@link AbstractComponent} made up of one or more {@link Path}s.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* For some {@link Editor} editor and `Stroke` stroke,
|
16
|
+
*
|
17
|
+
* **Restyling**:
|
18
|
+
* ```ts
|
19
|
+
* editor.dispatch(stroke.updateStyle({ color: Color4.red }));
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* **Transforming**:
|
23
|
+
* ```ts
|
24
|
+
* editor.dispatch(stroke.transformBy(Mat33.translation(Vec2.of(10, 0))));
|
25
|
+
* ```
|
26
|
+
*/
|
27
|
+
class Stroke extends AbstractComponent_1.default {
|
28
|
+
/**
|
29
|
+
* Creates a `Stroke` from the given `parts`. All parts should have the
|
30
|
+
* same color.
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* ```ts
|
34
|
+
* // A path that starts at (1,1), moves to the right by (2, 0),
|
35
|
+
* // then moves down and right by (3, 3)
|
36
|
+
* const path = Path.fromString('m1,1 2,0 3,3');
|
37
|
+
*
|
38
|
+
* const stroke = new Stroke([
|
39
|
+
* // Fill with red
|
40
|
+
* path.toRenderable({ fill: Color4.red })
|
41
|
+
* ]);
|
42
|
+
* ```
|
43
|
+
*/
|
44
|
+
constructor(parts) {
|
45
|
+
var _a;
|
46
|
+
super('stroke');
|
47
|
+
// @internal
|
48
|
+
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
49
|
+
this.isRestylableComponent = true;
|
50
|
+
this.approximateRenderingTime = 0;
|
51
|
+
this.parts = [];
|
52
|
+
for (const section of parts) {
|
53
|
+
const path = Path_1.default.fromRenderable(section);
|
54
|
+
const pathBBox = this.bboxForPart(path.bbox, section.style);
|
55
|
+
if (!this.contentBBox) {
|
56
|
+
this.contentBBox = pathBBox;
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
this.contentBBox = this.contentBBox.union(pathBBox);
|
60
|
+
}
|
61
|
+
this.parts.push({
|
62
|
+
path,
|
63
|
+
// To implement RenderablePathSpec
|
64
|
+
startPoint: path.startPoint,
|
65
|
+
style: section.style,
|
66
|
+
commands: path.parts,
|
67
|
+
});
|
68
|
+
this.approximateRenderingTime += path.parts.length;
|
69
|
+
}
|
70
|
+
(_a = this.contentBBox) !== null && _a !== void 0 ? _a : (this.contentBBox = Rect2_1.default.empty);
|
71
|
+
}
|
72
|
+
getStyle() {
|
73
|
+
if (this.parts.length === 0) {
|
74
|
+
return {};
|
75
|
+
}
|
76
|
+
const firstPart = this.parts[0];
|
77
|
+
if (firstPart.style.stroke === undefined
|
78
|
+
|| firstPart.style.stroke.width === 0) {
|
79
|
+
return {
|
80
|
+
color: firstPart.style.fill,
|
81
|
+
};
|
82
|
+
}
|
83
|
+
return {
|
84
|
+
color: firstPart.style.stroke.color,
|
85
|
+
};
|
86
|
+
}
|
87
|
+
updateStyle(style) {
|
88
|
+
return (0, RestylableComponent_1.createRestyleComponentCommand)(this.getStyle(), style, this);
|
89
|
+
}
|
90
|
+
forceStyle(style, editor) {
|
91
|
+
if (!style.color) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
this.parts = this.parts.map((part) => {
|
95
|
+
const newStyle = Object.assign(Object.assign({}, part.style), { stroke: part.style.stroke ? Object.assign({}, part.style.stroke) : undefined });
|
96
|
+
// Change the stroke color if a stroked shape. Else,
|
97
|
+
// change the fill.
|
98
|
+
if (newStyle.stroke && newStyle.stroke.width > 0) {
|
99
|
+
newStyle.stroke.color = style.color;
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
newStyle.fill = style.color;
|
103
|
+
}
|
104
|
+
return {
|
105
|
+
path: part.path,
|
106
|
+
startPoint: part.startPoint,
|
107
|
+
commands: part.commands,
|
108
|
+
style: newStyle,
|
109
|
+
};
|
110
|
+
});
|
111
|
+
if (editor) {
|
112
|
+
editor.image.queueRerenderOf(this);
|
113
|
+
editor.queueRerender();
|
114
|
+
}
|
115
|
+
}
|
116
|
+
intersects(line) {
|
117
|
+
for (const part of this.parts) {
|
118
|
+
if (part.path.intersection(line).length > 0) {
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
return false;
|
123
|
+
}
|
124
|
+
render(canvas, visibleRect) {
|
125
|
+
var _a, _b;
|
126
|
+
canvas.startObject(this.getBBox());
|
127
|
+
for (const part of this.parts) {
|
128
|
+
const bbox = this.bboxForPart(part.path.bbox, part.style);
|
129
|
+
if (visibleRect) {
|
130
|
+
if (!bbox.intersects(visibleRect)) {
|
131
|
+
continue;
|
132
|
+
}
|
133
|
+
const muchBiggerThanVisible = bbox.size.x > visibleRect.size.x * 2 || bbox.size.y > visibleRect.size.y * 2;
|
134
|
+
if (muchBiggerThanVisible && !part.path.roughlyIntersects(visibleRect, (_b = (_a = part.style.stroke) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0)) {
|
135
|
+
continue;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
canvas.drawPath(part);
|
139
|
+
}
|
140
|
+
canvas.endObject(this.getLoadSaveData());
|
141
|
+
}
|
142
|
+
getProportionalRenderingTime() {
|
143
|
+
return this.approximateRenderingTime;
|
144
|
+
}
|
145
|
+
// Grows the bounding box for a given stroke part based on that part's style.
|
146
|
+
bboxForPart(origBBox, style) {
|
147
|
+
if (!style.stroke) {
|
148
|
+
return origBBox;
|
149
|
+
}
|
150
|
+
return origBBox.grownBy(style.stroke.width / 2);
|
151
|
+
}
|
152
|
+
applyTransformation(affineTransfm) {
|
153
|
+
this.contentBBox = Rect2_1.default.empty;
|
154
|
+
let isFirstPart = true;
|
155
|
+
// Update each part
|
156
|
+
this.parts = this.parts.map((part) => {
|
157
|
+
const newPath = part.path.transformedBy(affineTransfm);
|
158
|
+
const newStyle = Object.assign(Object.assign({}, part.style), { stroke: part.style.stroke ? Object.assign({}, part.style.stroke) : undefined });
|
159
|
+
// Approximate the scale factor.
|
160
|
+
if (newStyle.stroke) {
|
161
|
+
const scaleFactor = affineTransfm.getScaleFactor();
|
162
|
+
newStyle.stroke.width *= scaleFactor;
|
163
|
+
}
|
164
|
+
const newBBox = this.bboxForPart(newPath.bbox, newStyle);
|
165
|
+
if (isFirstPart) {
|
166
|
+
this.contentBBox = newBBox;
|
167
|
+
isFirstPart = false;
|
168
|
+
}
|
169
|
+
else {
|
170
|
+
this.contentBBox = this.contentBBox.union(newBBox);
|
171
|
+
}
|
172
|
+
return {
|
173
|
+
path: newPath,
|
174
|
+
startPoint: newPath.startPoint,
|
175
|
+
commands: newPath.parts,
|
176
|
+
style: newStyle,
|
177
|
+
};
|
178
|
+
});
|
179
|
+
}
|
180
|
+
/**
|
181
|
+
* @returns the {@link Path.union} of all paths that make up this stroke.
|
182
|
+
*/
|
183
|
+
getPath() {
|
184
|
+
let result = null;
|
185
|
+
for (const part of this.parts) {
|
186
|
+
if (result) {
|
187
|
+
result = result.union(part.path);
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
result !== null && result !== void 0 ? result : (result = part.path);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
return result !== null && result !== void 0 ? result : Path_1.default.empty;
|
194
|
+
}
|
195
|
+
description(localization) {
|
196
|
+
return localization.stroke;
|
197
|
+
}
|
198
|
+
createClone() {
|
199
|
+
return new Stroke(this.parts);
|
200
|
+
}
|
201
|
+
serializeToJSON() {
|
202
|
+
return this.parts.map(part => {
|
203
|
+
return {
|
204
|
+
style: (0, RenderingStyle_1.styleToJSON)(part.style),
|
205
|
+
path: part.path.serialize(),
|
206
|
+
};
|
207
|
+
});
|
208
|
+
}
|
209
|
+
/** @internal */
|
210
|
+
static deserializeFromJSON(json) {
|
211
|
+
if (typeof json === 'string') {
|
212
|
+
json = JSON.parse(json);
|
213
|
+
}
|
214
|
+
if (typeof json !== 'object' || typeof json.length !== 'number') {
|
215
|
+
throw new Error(`${json} is missing required field, parts, or parts is of the wrong type.`);
|
216
|
+
}
|
217
|
+
const pathSpec = json.map((part) => {
|
218
|
+
const style = (0, RenderingStyle_1.styleFromJSON)(part.style);
|
219
|
+
return Path_1.default.fromString(part.path).toRenderable(style);
|
220
|
+
});
|
221
|
+
return new Stroke(pathSpec);
|
222
|
+
}
|
223
|
+
}
|
224
|
+
exports.default = Stroke;
|
225
|
+
AbstractComponent_1.default.registerComponent('stroke', Stroke.deserializeFromJSON);
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import SerializableCommand from '../commands/SerializableCommand';
|
2
|
+
import LineSegment2 from '../math/LineSegment2';
|
3
|
+
import Mat33 from '../math/Mat33';
|
4
|
+
import Rect2 from '../math/Rect2';
|
5
|
+
import Editor from '../Editor';
|
6
|
+
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
7
|
+
import { TextRenderingStyle } from '../rendering/TextRenderingStyle';
|
8
|
+
import AbstractComponent from './AbstractComponent';
|
9
|
+
import { ImageComponentLocalization } from './localization';
|
10
|
+
import RestyleableComponent, { ComponentStyle } from './RestylableComponent';
|
11
|
+
/**
|
12
|
+
* Displays text.
|
13
|
+
*/
|
14
|
+
export default class TextComponent extends AbstractComponent implements RestyleableComponent {
|
15
|
+
protected readonly textObjects: Array<string | TextComponent>;
|
16
|
+
private transform;
|
17
|
+
private style;
|
18
|
+
protected contentBBox: Rect2;
|
19
|
+
readonly isRestylableComponent: true;
|
20
|
+
/**
|
21
|
+
* Creates a new text object from a list of component text or child TextComponents.
|
22
|
+
*
|
23
|
+
* @see {@link fromLines}
|
24
|
+
*/
|
25
|
+
constructor(textObjects: Array<string | TextComponent>, transform: Mat33, style: TextRenderingStyle);
|
26
|
+
static applyTextStyles(ctx: CanvasRenderingContext2D, style: TextRenderingStyle): void;
|
27
|
+
private static textMeasuringCtx;
|
28
|
+
private static estimateTextDimens;
|
29
|
+
private static getTextDimens;
|
30
|
+
private computeBBoxOfPart;
|
31
|
+
private recomputeBBox;
|
32
|
+
private renderInternal;
|
33
|
+
render(canvas: AbstractRenderer, _visibleRect?: Rect2): void;
|
34
|
+
getProportionalRenderingTime(): number;
|
35
|
+
intersects(lineSegment: LineSegment2): boolean;
|
36
|
+
getStyle(): ComponentStyle;
|
37
|
+
updateStyle(style: ComponentStyle): SerializableCommand;
|
38
|
+
forceStyle(style: ComponentStyle, editor: Editor | null): void;
|
39
|
+
getTextStyle(): {
|
40
|
+
renderingStyle: {
|
41
|
+
fill: import("../Color4").default;
|
42
|
+
stroke: {
|
43
|
+
color: import("../Color4").default;
|
44
|
+
width: number;
|
45
|
+
} | undefined;
|
46
|
+
};
|
47
|
+
size: number;
|
48
|
+
fontFamily: string;
|
49
|
+
fontWeight?: string | undefined;
|
50
|
+
fontVariant?: string | undefined;
|
51
|
+
};
|
52
|
+
getBaselinePos(): import("../lib").Vec3;
|
53
|
+
getTransform(): Mat33;
|
54
|
+
protected applyTransformation(affineTransfm: Mat33): void;
|
55
|
+
protected createClone(): AbstractComponent;
|
56
|
+
getText(): string;
|
57
|
+
description(localizationTable: ImageComponentLocalization): string;
|
58
|
+
protected serializeToJSON(): Record<string, any>;
|
59
|
+
static deserializeFromString(json: any): TextComponent;
|
60
|
+
/**
|
61
|
+
* Creates a `TextComponent` from `lines`.
|
62
|
+
*
|
63
|
+
* @example
|
64
|
+
* ```ts
|
65
|
+
* const textStyle = {
|
66
|
+
* size: 12,
|
67
|
+
* fontFamily: 'serif',
|
68
|
+
* renderingStyle: { fill: Color4.black },
|
69
|
+
* };
|
70
|
+
*
|
71
|
+
* const text = TextComponent.fromLines('foo\nbar'.split('\n'), Mat33.identity, textStyle);
|
72
|
+
* ```
|
73
|
+
*/
|
74
|
+
static fromLines(lines: string[], transform: Mat33, style: TextRenderingStyle): AbstractComponent;
|
75
|
+
}
|