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,904 @@
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
+
});
|
33
|
+
};
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
36
|
+
};
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
38
|
+
exports.Editor = void 0;
|
39
|
+
const EditorImage_1 = __importDefault(require("./EditorImage"));
|
40
|
+
const ToolController_1 = __importDefault(require("./tools/ToolController"));
|
41
|
+
const types_1 = require("./types");
|
42
|
+
const UndoRedoHistory_1 = __importDefault(require("./UndoRedoHistory"));
|
43
|
+
const Viewport_1 = __importDefault(require("./Viewport"));
|
44
|
+
const EventDispatcher_1 = __importDefault(require("./EventDispatcher"));
|
45
|
+
const Vec2_1 = require("./math/Vec2");
|
46
|
+
const Vec3_1 = __importDefault(require("./math/Vec3"));
|
47
|
+
const HTMLToolbar_1 = __importDefault(require("./toolbar/HTMLToolbar"));
|
48
|
+
const Display_1 = __importStar(require("./rendering/Display"));
|
49
|
+
const SVGRenderer_1 = __importDefault(require("./rendering/renderers/SVGRenderer"));
|
50
|
+
const Color4_1 = __importDefault(require("./Color4"));
|
51
|
+
const SVGLoader_1 = __importDefault(require("./SVGLoader"));
|
52
|
+
const Pointer_1 = __importDefault(require("./Pointer"));
|
53
|
+
const Mat33_1 = __importDefault(require("./math/Mat33"));
|
54
|
+
const getLocalizationTable_1 = __importDefault(require("./localizations/getLocalizationTable"));
|
55
|
+
const IconProvider_1 = __importDefault(require("./toolbar/IconProvider"));
|
56
|
+
const rounding_1 = require("./math/rounding");
|
57
|
+
const CanvasRenderer_1 = __importDefault(require("./rendering/renderers/CanvasRenderer"));
|
58
|
+
const untilNextAnimationFrame_1 = __importDefault(require("./util/untilNextAnimationFrame"));
|
59
|
+
const fileToBase64_1 = __importDefault(require("./util/fileToBase64"));
|
60
|
+
const uniteCommands_1 = __importDefault(require("./commands/uniteCommands"));
|
61
|
+
const SelectionTool_1 = __importDefault(require("./tools/SelectionTool/SelectionTool"));
|
62
|
+
const Erase_1 = __importDefault(require("./commands/Erase"));
|
63
|
+
const ImageBackground_1 = __importStar(require("./components/ImageBackground"));
|
64
|
+
const sendPenEvent_1 = __importDefault(require("./testing/sendPenEvent"));
|
65
|
+
/**
|
66
|
+
* The main entrypoint for the full editor.
|
67
|
+
*
|
68
|
+
* @example
|
69
|
+
* To create an editor with a toolbar,
|
70
|
+
* ```
|
71
|
+
* const editor = new Editor(document.body);
|
72
|
+
*
|
73
|
+
* const toolbar = editor.addToolbar();
|
74
|
+
* toolbar.addActionButton('Save', () => {
|
75
|
+
* const saveData = editor.toSVG().outerHTML;
|
76
|
+
* // Do something with saveData...
|
77
|
+
* });
|
78
|
+
* ```
|
79
|
+
*
|
80
|
+
* See also
|
81
|
+
* [`docs/example/example.ts`](https://github.com/personalizedrefrigerator/js-draw/blob/main/docs/example/example.ts#L15).
|
82
|
+
*/
|
83
|
+
class Editor {
|
84
|
+
/**
|
85
|
+
* @example
|
86
|
+
* ```
|
87
|
+
* const container = document.body;
|
88
|
+
*
|
89
|
+
* // Create an editor
|
90
|
+
* const editor = new Editor(container, {
|
91
|
+
* // 2e-10 and 1e12 are the default values for minimum/maximum zoom.
|
92
|
+
* minZoom: 2e-10,
|
93
|
+
* maxZoom: 1e12,
|
94
|
+
* });
|
95
|
+
*
|
96
|
+
* // Add the default toolbar
|
97
|
+
* const toolbar = editor.addToolbar();
|
98
|
+
*
|
99
|
+
* // Add a save button
|
100
|
+
* toolbar.addActionButton({
|
101
|
+
* label: 'Save'
|
102
|
+
* icon: createSaveIcon(),
|
103
|
+
* }, () => {
|
104
|
+
* const saveData = editor.toSVG().outerHTML;
|
105
|
+
* // Do something with saveData
|
106
|
+
* });
|
107
|
+
* ```
|
108
|
+
*/
|
109
|
+
constructor(parent, settings = {}) {
|
110
|
+
var _a, _b, _c, _d, _e;
|
111
|
+
this.eventListenerTargets = [];
|
112
|
+
this.previousAccessibilityAnnouncement = '';
|
113
|
+
this.pointers = {};
|
114
|
+
this.announceUndoCallback = (command) => {
|
115
|
+
this.announceForAccessibility(this.localization.undoAnnouncement(command.description(this, this.localization)));
|
116
|
+
};
|
117
|
+
this.announceRedoCallback = (command) => {
|
118
|
+
this.announceForAccessibility(this.localization.redoAnnouncement(command.description(this, this.localization)));
|
119
|
+
};
|
120
|
+
// Listeners to be called once at the end of the next re-render.
|
121
|
+
this.nextRerenderListeners = [];
|
122
|
+
this.rerenderQueued = false;
|
123
|
+
this.localization = Object.assign(Object.assign({}, (0, getLocalizationTable_1.default)()), settings.localization);
|
124
|
+
// Fill default settings.
|
125
|
+
this.settings = {
|
126
|
+
wheelEventsEnabled: (_a = settings.wheelEventsEnabled) !== null && _a !== void 0 ? _a : true,
|
127
|
+
renderingMode: (_b = settings.renderingMode) !== null && _b !== void 0 ? _b : Display_1.RenderingMode.CanvasRenderer,
|
128
|
+
localization: this.localization,
|
129
|
+
minZoom: (_c = settings.minZoom) !== null && _c !== void 0 ? _c : 2e-10,
|
130
|
+
maxZoom: (_d = settings.maxZoom) !== null && _d !== void 0 ? _d : 1e12,
|
131
|
+
iconProvider: (_e = settings.iconProvider) !== null && _e !== void 0 ? _e : new IconProvider_1.default(),
|
132
|
+
};
|
133
|
+
this.icons = this.settings.iconProvider;
|
134
|
+
this.container = document.createElement('div');
|
135
|
+
this.renderingRegion = document.createElement('div');
|
136
|
+
this.container.appendChild(this.renderingRegion);
|
137
|
+
this.container.className = 'imageEditorContainer';
|
138
|
+
this.loadingWarning = document.createElement('div');
|
139
|
+
this.loadingWarning.classList.add('loadingMessage');
|
140
|
+
this.loadingWarning.ariaLive = 'polite';
|
141
|
+
this.container.appendChild(this.loadingWarning);
|
142
|
+
this.accessibilityControlArea = document.createElement('textarea');
|
143
|
+
this.accessibilityControlArea.setAttribute('placeholder', this.localization.accessibilityInputInstructions);
|
144
|
+
this.accessibilityControlArea.style.opacity = '0';
|
145
|
+
this.accessibilityControlArea.style.width = '0';
|
146
|
+
this.accessibilityControlArea.style.height = '0';
|
147
|
+
this.accessibilityControlArea.style.position = 'absolute';
|
148
|
+
this.accessibilityAnnounceArea = document.createElement('div');
|
149
|
+
this.accessibilityAnnounceArea.setAttribute('aria-live', 'assertive');
|
150
|
+
this.accessibilityAnnounceArea.className = 'accessibilityAnnouncement';
|
151
|
+
this.container.appendChild(this.accessibilityAnnounceArea);
|
152
|
+
this.renderingRegion.style.touchAction = 'none';
|
153
|
+
this.renderingRegion.className = 'imageEditorRenderArea';
|
154
|
+
this.renderingRegion.appendChild(this.accessibilityControlArea);
|
155
|
+
this.renderingRegion.setAttribute('tabIndex', '0');
|
156
|
+
this.renderingRegion.setAttribute('alt', '');
|
157
|
+
this.notifier = new EventDispatcher_1.default();
|
158
|
+
this.viewport = new Viewport_1.default((oldTransform, newTransform) => {
|
159
|
+
this.notifier.dispatch(types_1.EditorEventType.ViewportChanged, {
|
160
|
+
kind: types_1.EditorEventType.ViewportChanged,
|
161
|
+
newTransform,
|
162
|
+
oldTransform,
|
163
|
+
});
|
164
|
+
});
|
165
|
+
this.display = new Display_1.default(this, this.settings.renderingMode, this.renderingRegion);
|
166
|
+
this.image = new EditorImage_1.default();
|
167
|
+
this.history = new UndoRedoHistory_1.default(this, this.announceRedoCallback, this.announceUndoCallback);
|
168
|
+
this.toolController = new ToolController_1.default(this, this.localization);
|
169
|
+
parent.appendChild(this.container);
|
170
|
+
this.viewport.updateScreenSize(Vec2_1.Vec2.of(this.display.width, this.display.height));
|
171
|
+
this.registerListeners();
|
172
|
+
this.queueRerender();
|
173
|
+
this.hideLoadingWarning();
|
174
|
+
// Enforce zoom limits.
|
175
|
+
this.notifier.on(types_1.EditorEventType.ViewportChanged, evt => {
|
176
|
+
if (evt.kind === types_1.EditorEventType.ViewportChanged) {
|
177
|
+
const zoom = evt.newTransform.transformVec3(Vec2_1.Vec2.unitX).length();
|
178
|
+
if (zoom > this.settings.maxZoom || zoom < this.settings.minZoom) {
|
179
|
+
const oldZoom = evt.oldTransform.transformVec3(Vec2_1.Vec2.unitX).length();
|
180
|
+
let resetTransform = Mat33_1.default.identity;
|
181
|
+
if (oldZoom <= this.settings.maxZoom && oldZoom >= this.settings.minZoom) {
|
182
|
+
resetTransform = evt.oldTransform;
|
183
|
+
}
|
184
|
+
this.viewport.resetTransform(resetTransform);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
});
|
188
|
+
}
|
189
|
+
/**
|
190
|
+
* @returns a reference to the editor's container.
|
191
|
+
*
|
192
|
+
* @example
|
193
|
+
* ```
|
194
|
+
* // Set the editor's height to 500px
|
195
|
+
* editor.getRootElement().style.height = '500px';
|
196
|
+
* ```
|
197
|
+
*/
|
198
|
+
getRootElement() {
|
199
|
+
return this.container;
|
200
|
+
}
|
201
|
+
/** @param fractionLoaded - should be a number from 0 to 1, where 1 represents completely loaded. */
|
202
|
+
showLoadingWarning(fractionLoaded) {
|
203
|
+
const loadingPercent = Math.round(fractionLoaded * 100);
|
204
|
+
this.loadingWarning.innerText = this.localization.loading(loadingPercent);
|
205
|
+
this.loadingWarning.style.display = 'block';
|
206
|
+
}
|
207
|
+
hideLoadingWarning() {
|
208
|
+
this.loadingWarning.style.display = 'none';
|
209
|
+
this.announceForAccessibility(this.localization.doneLoading);
|
210
|
+
}
|
211
|
+
/**
|
212
|
+
* Announce `message` for screen readers. If `message` is the same as the previous
|
213
|
+
* message, it is re-announced.
|
214
|
+
*/
|
215
|
+
announceForAccessibility(message) {
|
216
|
+
// Force re-announcing an announcement if announced again.
|
217
|
+
if (message === this.previousAccessibilityAnnouncement) {
|
218
|
+
message = message + '. ';
|
219
|
+
}
|
220
|
+
this.accessibilityAnnounceArea.innerText = message;
|
221
|
+
this.previousAccessibilityAnnouncement = message;
|
222
|
+
}
|
223
|
+
/**
|
224
|
+
* Creates a toolbar. If `defaultLayout` is true, default buttons are used.
|
225
|
+
* @returns a reference to the toolbar.
|
226
|
+
*/
|
227
|
+
addToolbar(defaultLayout = true) {
|
228
|
+
const toolbar = new HTMLToolbar_1.default(this, this.container, this.localization);
|
229
|
+
if (defaultLayout) {
|
230
|
+
toolbar.addDefaults();
|
231
|
+
}
|
232
|
+
return toolbar;
|
233
|
+
}
|
234
|
+
registerListeners() {
|
235
|
+
this.handlePointerEventsFrom(this.renderingRegion);
|
236
|
+
this.handleKeyEventsFrom(this.renderingRegion);
|
237
|
+
this.container.addEventListener('wheel', evt => {
|
238
|
+
let delta = Vec3_1.default.of(evt.deltaX, evt.deltaY, evt.deltaZ);
|
239
|
+
// Process wheel events if the ctrl key is down, even if disabled -- we do want to handle
|
240
|
+
// pinch-zooming.
|
241
|
+
if (!evt.ctrlKey && !evt.metaKey) {
|
242
|
+
if (!this.settings.wheelEventsEnabled) {
|
243
|
+
return;
|
244
|
+
}
|
245
|
+
else if (this.settings.wheelEventsEnabled === 'only-if-focused') {
|
246
|
+
const focusedChild = this.container.querySelector(':focus');
|
247
|
+
if (!focusedChild) {
|
248
|
+
return;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) {
|
253
|
+
delta = delta.times(15);
|
254
|
+
}
|
255
|
+
else if (evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
|
256
|
+
delta = delta.times(100);
|
257
|
+
}
|
258
|
+
if (evt.ctrlKey || evt.metaKey) {
|
259
|
+
delta = Vec3_1.default.of(0, 0, evt.deltaY);
|
260
|
+
}
|
261
|
+
// Ensure that `pos` is relative to `this.container`
|
262
|
+
const bbox = this.container.getBoundingClientRect();
|
263
|
+
const pos = Vec2_1.Vec2.of(evt.clientX, evt.clientY).minus(Vec2_1.Vec2.of(bbox.left, bbox.top));
|
264
|
+
if (this.toolController.dispatchInputEvent({
|
265
|
+
kind: types_1.InputEvtType.WheelEvt,
|
266
|
+
delta,
|
267
|
+
screenPos: pos,
|
268
|
+
})) {
|
269
|
+
evt.preventDefault();
|
270
|
+
return true;
|
271
|
+
}
|
272
|
+
return false;
|
273
|
+
});
|
274
|
+
this.notifier.on(types_1.EditorEventType.DisplayResized, _event => {
|
275
|
+
this.viewport.updateScreenSize(Vec2_1.Vec2.of(this.display.width, this.display.height));
|
276
|
+
this.queueRerender();
|
277
|
+
});
|
278
|
+
const handleResize = () => {
|
279
|
+
this.notifier.dispatch(types_1.EditorEventType.DisplayResized, {
|
280
|
+
kind: types_1.EditorEventType.DisplayResized,
|
281
|
+
newSize: Vec2_1.Vec2.of(this.display.width, this.display.height),
|
282
|
+
});
|
283
|
+
};
|
284
|
+
if ('ResizeObserver' in window) {
|
285
|
+
const resizeObserver = new ResizeObserver(handleResize);
|
286
|
+
resizeObserver.observe(this.container);
|
287
|
+
}
|
288
|
+
else {
|
289
|
+
addEventListener('resize', handleResize);
|
290
|
+
}
|
291
|
+
this.accessibilityControlArea.addEventListener('input', () => {
|
292
|
+
this.accessibilityControlArea.value = '';
|
293
|
+
});
|
294
|
+
document.addEventListener('copy', evt => {
|
295
|
+
if (!this.isEventSink(document.querySelector(':focus'))) {
|
296
|
+
return;
|
297
|
+
}
|
298
|
+
const clipboardData = evt.clipboardData;
|
299
|
+
if (this.toolController.dispatchInputEvent({
|
300
|
+
kind: types_1.InputEvtType.CopyEvent,
|
301
|
+
setData: (mime, data) => {
|
302
|
+
clipboardData === null || clipboardData === void 0 ? void 0 : clipboardData.setData(mime, data);
|
303
|
+
},
|
304
|
+
})) {
|
305
|
+
evt.preventDefault();
|
306
|
+
}
|
307
|
+
});
|
308
|
+
document.addEventListener('paste', evt => {
|
309
|
+
this.handlePaste(evt);
|
310
|
+
});
|
311
|
+
}
|
312
|
+
getPointerList() {
|
313
|
+
const nowTime = (new Date()).getTime();
|
314
|
+
const res = [];
|
315
|
+
for (const id in this.pointers) {
|
316
|
+
const maxUnupdatedTime = 2000; // Maximum time without a pointer update (ms)
|
317
|
+
if (this.pointers[id] && (nowTime - this.pointers[id].timeStamp) < maxUnupdatedTime) {
|
318
|
+
res.push(this.pointers[id]);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
return res;
|
322
|
+
}
|
323
|
+
/**
|
324
|
+
* Dispatches a `PointerEvent` to the editor. The target element for `evt` must have the same top left
|
325
|
+
* as the content of the editor.
|
326
|
+
*/
|
327
|
+
handleHTMLPointerEvent(eventType, evt) {
|
328
|
+
var _a, _b, _c;
|
329
|
+
const eventsRelativeTo = this.renderingRegion;
|
330
|
+
const eventTarget = (_a = evt.target) !== null && _a !== void 0 ? _a : this.renderingRegion;
|
331
|
+
if (eventType === 'pointerdown') {
|
332
|
+
const pointer = Pointer_1.default.ofEvent(evt, true, this.viewport, eventsRelativeTo);
|
333
|
+
this.pointers[pointer.id] = pointer;
|
334
|
+
eventTarget.setPointerCapture(pointer.id);
|
335
|
+
const event = {
|
336
|
+
kind: types_1.InputEvtType.PointerDownEvt,
|
337
|
+
current: pointer,
|
338
|
+
allPointers: this.getPointerList(),
|
339
|
+
};
|
340
|
+
this.toolController.dispatchInputEvent(event);
|
341
|
+
return true;
|
342
|
+
}
|
343
|
+
else if (eventType === 'pointermove') {
|
344
|
+
const pointer = Pointer_1.default.ofEvent(evt, (_c = (_b = this.pointers[evt.pointerId]) === null || _b === void 0 ? void 0 : _b.down) !== null && _c !== void 0 ? _c : false, this.viewport, eventsRelativeTo);
|
345
|
+
if (pointer.down) {
|
346
|
+
const prevData = this.pointers[pointer.id];
|
347
|
+
if (prevData) {
|
348
|
+
const distanceMoved = pointer.screenPos.minus(prevData.screenPos).magnitude();
|
349
|
+
// If the pointer moved less than two pixels, don't send a new event.
|
350
|
+
if (distanceMoved < 2) {
|
351
|
+
return false;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
this.pointers[pointer.id] = pointer;
|
355
|
+
if (this.toolController.dispatchInputEvent({
|
356
|
+
kind: types_1.InputEvtType.PointerMoveEvt,
|
357
|
+
current: pointer,
|
358
|
+
allPointers: this.getPointerList(),
|
359
|
+
})) {
|
360
|
+
evt.preventDefault();
|
361
|
+
}
|
362
|
+
}
|
363
|
+
return true;
|
364
|
+
}
|
365
|
+
else if (eventType === 'pointercancel' || eventType === 'pointerup') {
|
366
|
+
const pointer = Pointer_1.default.ofEvent(evt, false, this.viewport, eventsRelativeTo);
|
367
|
+
if (!this.pointers[pointer.id]) {
|
368
|
+
return false;
|
369
|
+
}
|
370
|
+
this.pointers[pointer.id] = pointer;
|
371
|
+
eventTarget.releasePointerCapture(pointer.id);
|
372
|
+
if (this.toolController.dispatchInputEvent({
|
373
|
+
kind: types_1.InputEvtType.PointerUpEvt,
|
374
|
+
current: pointer,
|
375
|
+
allPointers: this.getPointerList(),
|
376
|
+
})) {
|
377
|
+
evt.preventDefault();
|
378
|
+
}
|
379
|
+
delete this.pointers[pointer.id];
|
380
|
+
return true;
|
381
|
+
}
|
382
|
+
return eventType;
|
383
|
+
}
|
384
|
+
isEventSink(evtTarget) {
|
385
|
+
let currentElem = evtTarget;
|
386
|
+
while (currentElem !== null) {
|
387
|
+
for (const elem of this.eventListenerTargets) {
|
388
|
+
if (elem === currentElem) {
|
389
|
+
return true;
|
390
|
+
}
|
391
|
+
}
|
392
|
+
currentElem = currentElem.parentElement;
|
393
|
+
}
|
394
|
+
return false;
|
395
|
+
}
|
396
|
+
handlePaste(evt) {
|
397
|
+
var _a, _b;
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
399
|
+
const target = (_a = document.querySelector(':focus')) !== null && _a !== void 0 ? _a : evt.target;
|
400
|
+
if (!this.isEventSink(target)) {
|
401
|
+
return;
|
402
|
+
}
|
403
|
+
const clipboardData = (_b = evt.dataTransfer) !== null && _b !== void 0 ? _b : evt.clipboardData;
|
404
|
+
if (!clipboardData) {
|
405
|
+
return;
|
406
|
+
}
|
407
|
+
// Handle SVG files (prefer to PNG/JPEG)
|
408
|
+
for (const file of clipboardData.files) {
|
409
|
+
if (file.type.toLowerCase() === 'image/svg+xml') {
|
410
|
+
const text = yield file.text();
|
411
|
+
if (this.toolController.dispatchInputEvent({
|
412
|
+
kind: types_1.InputEvtType.PasteEvent,
|
413
|
+
mime: file.type,
|
414
|
+
data: text,
|
415
|
+
})) {
|
416
|
+
evt.preventDefault();
|
417
|
+
return;
|
418
|
+
}
|
419
|
+
}
|
420
|
+
}
|
421
|
+
// Handle image files.
|
422
|
+
for (const file of clipboardData.files) {
|
423
|
+
const fileType = file.type.toLowerCase();
|
424
|
+
if (fileType === 'image/png' || fileType === 'image/jpg') {
|
425
|
+
this.showLoadingWarning(0);
|
426
|
+
const onprogress = (evt) => {
|
427
|
+
this.showLoadingWarning(evt.loaded / evt.total);
|
428
|
+
};
|
429
|
+
try {
|
430
|
+
const data = yield (0, fileToBase64_1.default)(file, onprogress);
|
431
|
+
if (data && this.toolController.dispatchInputEvent({
|
432
|
+
kind: types_1.InputEvtType.PasteEvent,
|
433
|
+
mime: fileType,
|
434
|
+
data: data,
|
435
|
+
})) {
|
436
|
+
evt.preventDefault();
|
437
|
+
this.hideLoadingWarning();
|
438
|
+
return;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
catch (e) {
|
442
|
+
console.error('Error reading image:', e);
|
443
|
+
}
|
444
|
+
this.hideLoadingWarning();
|
445
|
+
}
|
446
|
+
}
|
447
|
+
// Supported MIMEs for text data, in order of preference
|
448
|
+
const supportedMIMEs = [
|
449
|
+
'image/svg+xml',
|
450
|
+
'text/plain',
|
451
|
+
];
|
452
|
+
for (const mime of supportedMIMEs) {
|
453
|
+
const data = clipboardData.getData(mime);
|
454
|
+
if (data && this.toolController.dispatchInputEvent({
|
455
|
+
kind: types_1.InputEvtType.PasteEvent,
|
456
|
+
mime,
|
457
|
+
data,
|
458
|
+
})) {
|
459
|
+
evt.preventDefault();
|
460
|
+
return;
|
461
|
+
}
|
462
|
+
}
|
463
|
+
});
|
464
|
+
}
|
465
|
+
/**
|
466
|
+
* Forward pointer events from `elem` to this editor. Such that right-click/right-click drag
|
467
|
+
* events are also forwarded, `elem`'s contextmenu is disabled.
|
468
|
+
*
|
469
|
+
* @example
|
470
|
+
* ```ts
|
471
|
+
* const overlay = document.createElement('div');
|
472
|
+
* editor.createHTMLOverlay(overlay);
|
473
|
+
*
|
474
|
+
* // Send all pointer events that don't have the control key pressed
|
475
|
+
* // to the editor.
|
476
|
+
* editor.handlePointerEventsFrom(overlay, (event) => {
|
477
|
+
* if (event.ctrlKey) {
|
478
|
+
* return false;
|
479
|
+
* }
|
480
|
+
* return true;
|
481
|
+
* });
|
482
|
+
* ```
|
483
|
+
*/
|
484
|
+
handlePointerEventsFrom(elem, filter) {
|
485
|
+
// May be required to prevent text selection on iOS/Safari:
|
486
|
+
// See https://stackoverflow.com/a/70992717/17055750
|
487
|
+
elem.addEventListener('touchstart', evt => evt.preventDefault());
|
488
|
+
elem.addEventListener('contextmenu', evt => {
|
489
|
+
// Don't show a context menu
|
490
|
+
evt.preventDefault();
|
491
|
+
});
|
492
|
+
const eventNames = ['pointerdown', 'pointermove', 'pointerup', 'pointercancel'];
|
493
|
+
for (const eventName of eventNames) {
|
494
|
+
elem.addEventListener(eventName, evt => {
|
495
|
+
if (filter && !filter(eventName, evt)) {
|
496
|
+
return true;
|
497
|
+
}
|
498
|
+
return this.handleHTMLPointerEvent(eventName, evt);
|
499
|
+
});
|
500
|
+
}
|
501
|
+
}
|
502
|
+
/** Adds event listners for keypresses to `elem` and forwards those events to the editor. */
|
503
|
+
handleKeyEventsFrom(elem) {
|
504
|
+
elem.addEventListener('keydown', evt => {
|
505
|
+
if (evt.key === 't' || evt.key === 'T') {
|
506
|
+
evt.preventDefault();
|
507
|
+
this.display.rerenderAsText();
|
508
|
+
}
|
509
|
+
else if (this.toolController.dispatchInputEvent({
|
510
|
+
kind: types_1.InputEvtType.KeyPressEvent,
|
511
|
+
key: evt.key,
|
512
|
+
ctrlKey: evt.ctrlKey || evt.metaKey,
|
513
|
+
altKey: evt.altKey,
|
514
|
+
})) {
|
515
|
+
evt.preventDefault();
|
516
|
+
}
|
517
|
+
else if (evt.key === 'Escape') {
|
518
|
+
this.renderingRegion.blur();
|
519
|
+
}
|
520
|
+
});
|
521
|
+
elem.addEventListener('keyup', evt => {
|
522
|
+
if (this.toolController.dispatchInputEvent({
|
523
|
+
kind: types_1.InputEvtType.KeyUpEvent,
|
524
|
+
key: evt.key,
|
525
|
+
ctrlKey: evt.ctrlKey || evt.metaKey,
|
526
|
+
altKey: evt.altKey,
|
527
|
+
})) {
|
528
|
+
evt.preventDefault();
|
529
|
+
}
|
530
|
+
});
|
531
|
+
// Allow drop.
|
532
|
+
elem.ondragover = evt => {
|
533
|
+
evt.preventDefault();
|
534
|
+
};
|
535
|
+
elem.ondrop = evt => {
|
536
|
+
evt.preventDefault();
|
537
|
+
this.handlePaste(evt);
|
538
|
+
};
|
539
|
+
this.eventListenerTargets.push(elem);
|
540
|
+
}
|
541
|
+
/** `apply` a command. `command` will be announced for accessibility. */
|
542
|
+
dispatch(command, addToHistory = true) {
|
543
|
+
const dispatchResult = this.dispatchNoAnnounce(command, addToHistory);
|
544
|
+
this.announceForAccessibility(command.description(this, this.localization));
|
545
|
+
return dispatchResult;
|
546
|
+
}
|
547
|
+
/**
|
548
|
+
* Dispatches a command without announcing it. By default, does not add to history.
|
549
|
+
* Use this to show finalized commands that don't need to have `announceForAccessibility`
|
550
|
+
* called.
|
551
|
+
*
|
552
|
+
* Prefer `command.apply(editor)` for incomplete commands. `dispatchNoAnnounce` may allow
|
553
|
+
* clients to listen for the application of commands (e.g. `SerializableCommand`s so they can
|
554
|
+
* be sent across the network), while `apply` does not.
|
555
|
+
*
|
556
|
+
* @example
|
557
|
+
* ```
|
558
|
+
* const addToHistory = false;
|
559
|
+
* editor.dispatchNoAnnounce(editor.viewport.zoomTo(someRectangle), addToHistory);
|
560
|
+
* ```
|
561
|
+
*/
|
562
|
+
dispatchNoAnnounce(command, addToHistory = false) {
|
563
|
+
const result = command.apply(this);
|
564
|
+
if (addToHistory) {
|
565
|
+
const apply = false; // Don't double-apply
|
566
|
+
this.history.push(command, apply);
|
567
|
+
}
|
568
|
+
return result;
|
569
|
+
}
|
570
|
+
/**
|
571
|
+
* Apply a large transformation in chunks.
|
572
|
+
* If `apply` is `false`, the commands are unapplied.
|
573
|
+
* Triggers a re-render after each `updateChunkSize`-sized group of commands
|
574
|
+
* has been applied.
|
575
|
+
*/
|
576
|
+
asyncApplyOrUnapplyCommands(commands, apply, updateChunkSize) {
|
577
|
+
return __awaiter(this, void 0, void 0, function* () {
|
578
|
+
console.assert(updateChunkSize > 0);
|
579
|
+
this.display.setDraftMode(true);
|
580
|
+
for (let i = 0; i < commands.length; i += updateChunkSize) {
|
581
|
+
this.showLoadingWarning(i / commands.length);
|
582
|
+
for (let j = i; j < commands.length && j < i + updateChunkSize; j++) {
|
583
|
+
const cmd = commands[j];
|
584
|
+
if (apply) {
|
585
|
+
cmd.apply(this);
|
586
|
+
}
|
587
|
+
else {
|
588
|
+
cmd.unapply(this);
|
589
|
+
}
|
590
|
+
}
|
591
|
+
// Re-render to show progress, but only if we're not done.
|
592
|
+
if (i + updateChunkSize < commands.length) {
|
593
|
+
yield new Promise(resolve => {
|
594
|
+
this.rerender();
|
595
|
+
requestAnimationFrame(resolve);
|
596
|
+
});
|
597
|
+
}
|
598
|
+
}
|
599
|
+
this.display.setDraftMode(false);
|
600
|
+
this.hideLoadingWarning();
|
601
|
+
});
|
602
|
+
}
|
603
|
+
// @see {@link #asyncApplyOrUnapplyCommands }
|
604
|
+
asyncApplyCommands(commands, chunkSize) {
|
605
|
+
return this.asyncApplyOrUnapplyCommands(commands, true, chunkSize);
|
606
|
+
}
|
607
|
+
// If `unapplyInReverseOrder`, commands are reversed before unapplying.
|
608
|
+
// @see {@link #asyncApplyOrUnapplyCommands }
|
609
|
+
asyncUnapplyCommands(commands, chunkSize, unapplyInReverseOrder = false) {
|
610
|
+
if (unapplyInReverseOrder) {
|
611
|
+
commands = [...commands]; // copy
|
612
|
+
commands.reverse();
|
613
|
+
}
|
614
|
+
return this.asyncApplyOrUnapplyCommands(commands, false, chunkSize);
|
615
|
+
}
|
616
|
+
/**
|
617
|
+
* Schedule a re-render for some time in the near future. Does not schedule an additional
|
618
|
+
* re-render if a re-render is already queued.
|
619
|
+
*
|
620
|
+
* @returns a promise that resolves when re-rendering has completed.
|
621
|
+
*/
|
622
|
+
queueRerender() {
|
623
|
+
if (!this.rerenderQueued) {
|
624
|
+
this.rerenderQueued = true;
|
625
|
+
requestAnimationFrame(() => {
|
626
|
+
// If .rerender was called manually, we might not need to
|
627
|
+
// re-render.
|
628
|
+
if (this.rerenderQueued) {
|
629
|
+
this.rerender();
|
630
|
+
this.rerenderQueued = false;
|
631
|
+
}
|
632
|
+
});
|
633
|
+
}
|
634
|
+
return new Promise(resolve => {
|
635
|
+
this.nextRerenderListeners.push(() => resolve());
|
636
|
+
});
|
637
|
+
}
|
638
|
+
// @internal
|
639
|
+
isRerenderQueued() {
|
640
|
+
return this.rerenderQueued;
|
641
|
+
}
|
642
|
+
/**
|
643
|
+
* Re-renders the entire image.
|
644
|
+
*
|
645
|
+
* @see {@link Editor.queueRerender}
|
646
|
+
*/
|
647
|
+
rerender(showImageBounds = true) {
|
648
|
+
this.display.startRerender();
|
649
|
+
// Don't render if the display has zero size.
|
650
|
+
if (this.display.width === 0 || this.display.height === 0) {
|
651
|
+
return;
|
652
|
+
}
|
653
|
+
// Draw a rectangle around the region that will be visible on save
|
654
|
+
const renderer = this.display.getDryInkRenderer();
|
655
|
+
this.image.renderWithCache(renderer, this.display.getCache(), this.viewport);
|
656
|
+
if (showImageBounds) {
|
657
|
+
const exportRectFill = { fill: Color4_1.default.fromHex('#44444455') };
|
658
|
+
const exportRectStrokeWidth = 5 * this.viewport.getSizeOfPixelOnCanvas();
|
659
|
+
renderer.drawRect(this.getImportExportRect(), exportRectStrokeWidth, exportRectFill);
|
660
|
+
}
|
661
|
+
this.rerenderQueued = false;
|
662
|
+
this.nextRerenderListeners.forEach(listener => listener());
|
663
|
+
this.nextRerenderListeners = [];
|
664
|
+
}
|
665
|
+
/**
|
666
|
+
* Draws the given path onto the wet ink renderer. The given path will
|
667
|
+
* be displayed on top of the main image.
|
668
|
+
*
|
669
|
+
* @see {@link Display.getWetInkRenderer} {@link Display.flatten}
|
670
|
+
*/
|
671
|
+
drawWetInk(...path) {
|
672
|
+
for (const part of path) {
|
673
|
+
this.display.getWetInkRenderer().drawPath(part);
|
674
|
+
}
|
675
|
+
}
|
676
|
+
/**
|
677
|
+
* Clears the wet ink display.
|
678
|
+
*
|
679
|
+
* @see {@link Display.getWetInkRenderer}
|
680
|
+
*/
|
681
|
+
clearWetInk() {
|
682
|
+
this.display.getWetInkRenderer().clear();
|
683
|
+
}
|
684
|
+
/**
|
685
|
+
* Focuses the region used for text input/key commands.
|
686
|
+
*/
|
687
|
+
focus() {
|
688
|
+
this.renderingRegion.focus();
|
689
|
+
}
|
690
|
+
/**
|
691
|
+
* Creates an element that will be positioned on top of the dry/wet ink
|
692
|
+
* renderers.
|
693
|
+
*
|
694
|
+
* This is useful for displaying content on top of the rendered content
|
695
|
+
* (e.g. a selection box).
|
696
|
+
*/
|
697
|
+
createHTMLOverlay(overlay) {
|
698
|
+
overlay.classList.add('overlay');
|
699
|
+
this.container.appendChild(overlay);
|
700
|
+
return {
|
701
|
+
remove: () => overlay.remove(),
|
702
|
+
};
|
703
|
+
}
|
704
|
+
addStyleSheet(content) {
|
705
|
+
const styleSheet = document.createElement('style');
|
706
|
+
styleSheet.innerText = content;
|
707
|
+
this.container.appendChild(styleSheet);
|
708
|
+
return styleSheet;
|
709
|
+
}
|
710
|
+
// Dispatch a keyboard event to the currently selected tool.
|
711
|
+
// Intended for unit testing
|
712
|
+
sendKeyboardEvent(eventType, key, ctrlKey = false, altKey = false) {
|
713
|
+
this.toolController.dispatchInputEvent({
|
714
|
+
kind: eventType,
|
715
|
+
key,
|
716
|
+
ctrlKey,
|
717
|
+
altKey,
|
718
|
+
});
|
719
|
+
}
|
720
|
+
/**
|
721
|
+
* Dispatch a pen event to the currently selected tool.
|
722
|
+
* Intended primarially for unit tests.
|
723
|
+
*
|
724
|
+
* @deprecated
|
725
|
+
* @see {@link sendPenEvent} {@link sendTouchEvent}
|
726
|
+
*/
|
727
|
+
sendPenEvent(eventType, point,
|
728
|
+
// @deprecated
|
729
|
+
allPointers) {
|
730
|
+
(0, sendPenEvent_1.default)(this, eventType, point, allPointers);
|
731
|
+
}
|
732
|
+
addAndCenterComponents(components, selectComponents = true) {
|
733
|
+
return __awaiter(this, void 0, void 0, function* () {
|
734
|
+
let bbox = null;
|
735
|
+
for (const component of components) {
|
736
|
+
if (bbox) {
|
737
|
+
bbox = bbox.union(component.getBBox());
|
738
|
+
}
|
739
|
+
else {
|
740
|
+
bbox = component.getBBox();
|
741
|
+
}
|
742
|
+
}
|
743
|
+
if (!bbox) {
|
744
|
+
return;
|
745
|
+
}
|
746
|
+
// Find a transform that scales/moves bbox onto the screen.
|
747
|
+
const visibleRect = this.viewport.visibleRect;
|
748
|
+
const scaleRatioX = visibleRect.width / bbox.width;
|
749
|
+
const scaleRatioY = visibleRect.height / bbox.height;
|
750
|
+
let scaleRatio = scaleRatioX;
|
751
|
+
if (bbox.width * scaleRatio > visibleRect.width || bbox.height * scaleRatio > visibleRect.height) {
|
752
|
+
scaleRatio = scaleRatioY;
|
753
|
+
}
|
754
|
+
scaleRatio *= 2 / 3;
|
755
|
+
scaleRatio = Viewport_1.default.roundScaleRatio(scaleRatio);
|
756
|
+
const transfm = Mat33_1.default.translation(visibleRect.center.minus(bbox.center)).rightMul(Mat33_1.default.scaling2D(scaleRatio, bbox.center));
|
757
|
+
const commands = [];
|
758
|
+
for (const component of components) {
|
759
|
+
// To allow deserialization, we need to add first, then transform.
|
760
|
+
commands.push(EditorImage_1.default.addElement(component));
|
761
|
+
commands.push(component.transformBy(transfm));
|
762
|
+
}
|
763
|
+
const applyChunkSize = 100;
|
764
|
+
yield this.dispatch((0, uniteCommands_1.default)(commands, applyChunkSize), true);
|
765
|
+
if (selectComponents) {
|
766
|
+
for (const selectionTool of this.toolController.getMatchingTools(SelectionTool_1.default)) {
|
767
|
+
selectionTool.setEnabled(true);
|
768
|
+
selectionTool.setSelection(components);
|
769
|
+
}
|
770
|
+
}
|
771
|
+
});
|
772
|
+
}
|
773
|
+
// Get a data URL (e.g. as produced by `HTMLCanvasElement::toDataURL`).
|
774
|
+
// If `format` is not `image/png`, a PNG image URL may still be returned (as in the
|
775
|
+
// case of `HTMLCanvasElement::toDataURL`).
|
776
|
+
//
|
777
|
+
// The export resolution is the same as the size of the drawing canvas.
|
778
|
+
toDataURL(format = 'image/png') {
|
779
|
+
const canvas = document.createElement('canvas');
|
780
|
+
const importExportViewport = this.image.getImportExportViewport();
|
781
|
+
const resolution = importExportViewport.getScreenRectSize();
|
782
|
+
canvas.width = resolution.x;
|
783
|
+
canvas.height = resolution.y;
|
784
|
+
const ctx = canvas.getContext('2d');
|
785
|
+
const renderer = new CanvasRenderer_1.default(ctx, importExportViewport);
|
786
|
+
this.image.renderAll(renderer);
|
787
|
+
const dataURL = canvas.toDataURL(format);
|
788
|
+
return dataURL;
|
789
|
+
}
|
790
|
+
toSVG() {
|
791
|
+
const importExportViewport = this.image.getImportExportViewport().getTemporaryClone();
|
792
|
+
const sanitize = false;
|
793
|
+
const { element: result, renderer } = SVGRenderer_1.default.fromViewport(importExportViewport, sanitize);
|
794
|
+
const origTransform = importExportViewport.canvasToScreenTransform;
|
795
|
+
// Render with (0,0) at (0,0) — we'll handle translation with
|
796
|
+
// the viewBox property.
|
797
|
+
importExportViewport.resetTransform(Mat33_1.default.identity);
|
798
|
+
this.image.renderAll(renderer);
|
799
|
+
importExportViewport.resetTransform(origTransform);
|
800
|
+
// Just show the main region
|
801
|
+
const rect = importExportViewport.visibleRect;
|
802
|
+
result.setAttribute('viewBox', [rect.x, rect.y, rect.w, rect.h].map(part => (0, rounding_1.toRoundedString)(part)).join(' '));
|
803
|
+
result.setAttribute('width', (0, rounding_1.toRoundedString)(rect.w));
|
804
|
+
result.setAttribute('height', (0, rounding_1.toRoundedString)(rect.h));
|
805
|
+
return result;
|
806
|
+
}
|
807
|
+
/**
|
808
|
+
* Load editor data from an `ImageLoader` (e.g. an {@link SVGLoader}).
|
809
|
+
*
|
810
|
+
* @see loadFromSVG
|
811
|
+
*/
|
812
|
+
loadFrom(loader) {
|
813
|
+
return __awaiter(this, void 0, void 0, function* () {
|
814
|
+
this.showLoadingWarning(0);
|
815
|
+
this.display.setDraftMode(true);
|
816
|
+
const originalBackgrounds = this.image.getBackgroundComponents();
|
817
|
+
const eraseBackgroundCommand = new Erase_1.default(originalBackgrounds);
|
818
|
+
yield loader.start((component) => __awaiter(this, void 0, void 0, function* () {
|
819
|
+
yield this.dispatchNoAnnounce(EditorImage_1.default.addElement(component));
|
820
|
+
}), (countProcessed, totalToProcess) => {
|
821
|
+
if (countProcessed % 500 === 0) {
|
822
|
+
this.showLoadingWarning(countProcessed / totalToProcess);
|
823
|
+
this.rerender();
|
824
|
+
return (0, untilNextAnimationFrame_1.default)();
|
825
|
+
}
|
826
|
+
return null;
|
827
|
+
}, (importExportRect) => {
|
828
|
+
this.dispatchNoAnnounce(this.setImportExportRect(importExportRect), false);
|
829
|
+
this.dispatchNoAnnounce(this.viewport.zoomTo(importExportRect), false);
|
830
|
+
});
|
831
|
+
// Ensure that we don't have multiple overlapping BackgroundComponents. Remove
|
832
|
+
// old BackgroundComponents.
|
833
|
+
// Overlapping BackgroundComponents may cause changing the background color to
|
834
|
+
// not work properly.
|
835
|
+
if (this.image.getBackgroundComponents().length !== originalBackgrounds.length) {
|
836
|
+
yield this.dispatchNoAnnounce(eraseBackgroundCommand);
|
837
|
+
}
|
838
|
+
this.hideLoadingWarning();
|
839
|
+
this.display.setDraftMode(false);
|
840
|
+
this.queueRerender();
|
841
|
+
});
|
842
|
+
}
|
843
|
+
getTopmostBackgroundComponent() {
|
844
|
+
let background = null;
|
845
|
+
// Find a background component, if one exists.
|
846
|
+
// Use the last (topmost) background component if there are multiple.
|
847
|
+
for (const component of this.image.getBackgroundComponents()) {
|
848
|
+
if (component instanceof ImageBackground_1.default) {
|
849
|
+
background = component;
|
850
|
+
}
|
851
|
+
}
|
852
|
+
return background;
|
853
|
+
}
|
854
|
+
/**
|
855
|
+
* Set the background color of the image.
|
856
|
+
*/
|
857
|
+
setBackgroundColor(color) {
|
858
|
+
let background = this.getTopmostBackgroundComponent();
|
859
|
+
if (!background) {
|
860
|
+
const backgroundType = color.eq(Color4_1.default.transparent) ? ImageBackground_1.BackgroundType.None : ImageBackground_1.BackgroundType.SolidColor;
|
861
|
+
background = new ImageBackground_1.default(backgroundType, color);
|
862
|
+
return this.image.addElement(background);
|
863
|
+
}
|
864
|
+
else {
|
865
|
+
return background.updateStyle({ color });
|
866
|
+
}
|
867
|
+
}
|
868
|
+
/**
|
869
|
+
* @returns the average of the colors of all background components. Use this to get the current background
|
870
|
+
* color.
|
871
|
+
*/
|
872
|
+
estimateBackgroundColor() {
|
873
|
+
var _a;
|
874
|
+
const backgroundColors = [];
|
875
|
+
for (const component of this.image.getBackgroundComponents()) {
|
876
|
+
if (component instanceof ImageBackground_1.default) {
|
877
|
+
backgroundColors.push((_a = component.getStyle().color) !== null && _a !== void 0 ? _a : Color4_1.default.transparent);
|
878
|
+
}
|
879
|
+
}
|
880
|
+
return Color4_1.default.average(backgroundColors);
|
881
|
+
}
|
882
|
+
// Returns the size of the visible region of the output SVG
|
883
|
+
getImportExportRect() {
|
884
|
+
return this.image.getImportExportViewport().visibleRect;
|
885
|
+
}
|
886
|
+
// Resize the output SVG to match `imageRect`.
|
887
|
+
setImportExportRect(imageRect) {
|
888
|
+
return this.image.setImportExportRect(imageRect);
|
889
|
+
}
|
890
|
+
/**
|
891
|
+
* Alias for loadFrom(SVGLoader.fromString).
|
892
|
+
*
|
893
|
+
* This is particularly useful when accessing a bundled version of the editor,
|
894
|
+
* where `SVGLoader.fromString` is unavailable.
|
895
|
+
*/
|
896
|
+
loadFromSVG(svgData, sanitize = false) {
|
897
|
+
return __awaiter(this, void 0, void 0, function* () {
|
898
|
+
const loader = SVGLoader_1.default.fromString(svgData, sanitize);
|
899
|
+
yield this.loadFrom(loader);
|
900
|
+
});
|
901
|
+
}
|
902
|
+
}
|
903
|
+
exports.Editor = Editor;
|
904
|
+
exports.default = Editor;
|