js-draw 0.17.3 → 0.18.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/.github/workflows/firebase-hosting-merge.yml +2 -0
- package/.github/workflows/firebase-hosting-pull-request.yml +2 -0
- package/.github/workflows/github-pages.yml +2 -0
- package/CHANGELOG.md +10 -1
- package/README.md +17 -8
- package/build_tools/postDist.ts +71 -0
- package/dist/bundle.js +9 -1
- package/dist/cjs/build_tools/BundledFile.js +163 -0
- package/dist/cjs/build_tools/buildTranslationTemplate.js +119 -0
- package/dist/cjs/build_tools/bundle.js +10 -0
- package/dist/cjs/build_tools/postDist.js +72 -0
- package/dist/{src → cjs/src}/Color4.d.ts +1 -0
- package/dist/cjs/src/Color4.js +197 -0
- package/dist/{src → cjs/src}/Editor.d.ts +57 -1
- package/dist/cjs/src/Editor.js +904 -0
- package/dist/{src → cjs/src}/EditorImage.d.ts +4 -2
- package/dist/cjs/src/EditorImage.js +486 -0
- package/dist/cjs/src/EventDispatcher.js +57 -0
- package/dist/cjs/src/Pointer.js +84 -0
- package/dist/{src → cjs/src}/SVGLoader.d.ts +4 -0
- package/dist/cjs/src/SVGLoader.js +472 -0
- package/dist/cjs/src/UndoRedoHistory.js +93 -0
- package/dist/cjs/src/Viewport.js +264 -0
- package/dist/cjs/src/bundle/bundled.js +24 -0
- package/dist/cjs/src/commands/Command.js +34 -0
- package/dist/cjs/src/commands/Duplicate.js +39 -0
- package/dist/cjs/src/commands/Erase.js +63 -0
- package/dist/cjs/src/commands/SerializableCommand.js +42 -0
- package/dist/cjs/src/commands/UnresolvedCommand.js +28 -0
- package/dist/cjs/src/commands/invertCommand.js +49 -0
- package/dist/cjs/src/commands/lib.js +18 -0
- package/dist/cjs/src/commands/localization.js +24 -0
- package/dist/cjs/src/commands/uniteCommands.js +121 -0
- package/dist/cjs/src/components/AbstractComponent.js +258 -0
- package/dist/cjs/src/components/ImageBackground.js +146 -0
- package/dist/cjs/src/components/ImageComponent.js +152 -0
- package/dist/cjs/src/components/RestylableComponent.js +88 -0
- package/dist/cjs/src/components/SVGGlobalAttributesObject.js +65 -0
- package/dist/cjs/src/components/Stroke.js +191 -0
- package/dist/cjs/src/components/TextComponent.js +258 -0
- package/dist/cjs/src/components/UnknownSVGObject.js +50 -0
- package/dist/cjs/src/components/builders/ArrowBuilder.js +117 -0
- package/dist/cjs/src/components/builders/FreehandLineBuilder.js +173 -0
- package/dist/cjs/src/components/builders/LineBuilder.js +89 -0
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.js +347 -0
- package/dist/cjs/src/components/builders/RectangleBuilder.js +59 -0
- package/dist/cjs/src/components/builders/types.js +2 -0
- package/dist/cjs/src/components/lib.js +43 -0
- package/dist/cjs/src/components/localization.js +13 -0
- package/dist/cjs/src/components/util/StrokeSmoother.js +217 -0
- package/dist/cjs/src/components/util/describeComponentList.js +16 -0
- package/dist/{src → cjs/src}/lib.d.ts +2 -1
- package/dist/cjs/src/lib.js +63 -0
- package/dist/cjs/src/localization.js +13 -0
- package/dist/cjs/src/localizations/de.js +6 -0
- package/dist/cjs/src/localizations/en.js +6 -0
- package/dist/cjs/src/localizations/es.js +20 -0
- package/dist/cjs/src/localizations/getLocalizationTable.js +50 -0
- package/dist/cjs/src/math/LineSegment2.js +131 -0
- package/dist/cjs/src/math/Mat33.js +332 -0
- package/dist/cjs/src/math/Path.js +655 -0
- package/dist/cjs/src/math/Rect2.js +234 -0
- package/dist/cjs/src/math/Triangle.js +22 -0
- package/dist/cjs/src/math/Vec2.js +19 -0
- package/dist/cjs/src/math/Vec3.js +177 -0
- package/dist/cjs/src/math/lib.js +18 -0
- package/dist/cjs/src/math/rounding.js +135 -0
- package/dist/cjs/src/rendering/Display.js +214 -0
- package/dist/cjs/src/rendering/RenderingStyle.js +48 -0
- package/dist/cjs/src/rendering/TextRenderingStyle.js +29 -0
- package/dist/cjs/src/rendering/caching/CacheRecord.js +61 -0
- package/dist/cjs/src/rendering/caching/CacheRecordManager.js +50 -0
- package/dist/cjs/src/rendering/caching/RenderingCache.js +51 -0
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.js +326 -0
- package/dist/cjs/src/rendering/caching/testUtils.js +27 -0
- package/dist/cjs/src/rendering/caching/types.js +2 -0
- package/dist/{src → cjs/src}/rendering/lib.d.ts +2 -0
- package/dist/cjs/src/rendering/lib.js +16 -0
- package/dist/cjs/src/rendering/localization.js +12 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.js +170 -0
- package/dist/{src → cjs/src}/rendering/renderers/CanvasRenderer.d.ts +25 -0
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +236 -0
- package/dist/cjs/src/rendering/renderers/DummyRenderer.js +112 -0
- package/dist/{src → cjs/src}/rendering/renderers/SVGRenderer.d.ts +15 -0
- package/dist/cjs/src/rendering/renderers/SVGRenderer.js +311 -0
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.js +63 -0
- package/dist/cjs/src/testing/beforeEachFile.js +12 -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.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.js +383 -0
- package/dist/cjs/src/toolbar/IconProvider.js +660 -0
- package/dist/cjs/src/toolbar/lib.js +24 -0
- package/dist/cjs/src/toolbar/localization.js +51 -0
- package/dist/cjs/src/toolbar/makeColorInput.js +120 -0
- package/dist/cjs/src/toolbar/types.js +2 -0
- package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.js +31 -0
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.js +50 -0
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +313 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +126 -0
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.js +63 -0
- package/dist/cjs/src/toolbar/widgets/HandToolWidget.js +201 -0
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.js +176 -0
- package/dist/cjs/src/toolbar/widgets/OverflowWidget.js +77 -0
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +226 -0
- package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.js +153 -0
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.js +115 -0
- package/dist/cjs/src/toolbar/widgets/lib.js +26 -0
- package/dist/cjs/src/tools/BaseTool.js +66 -0
- package/dist/cjs/src/tools/Eraser.js +112 -0
- package/dist/cjs/src/tools/FindTool.js +121 -0
- package/dist/cjs/src/tools/PanZoom.js +421 -0
- package/dist/cjs/src/tools/PasteHandler.js +99 -0
- package/dist/cjs/src/tools/Pen.js +179 -0
- package/dist/cjs/src/tools/PipetteTool.js +45 -0
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.js +28 -0
- package/dist/cjs/src/tools/SelectionTool/Selection.js +488 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionHandle.js +85 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.js +405 -0
- package/dist/cjs/src/tools/SelectionTool/TransformMode.js +107 -0
- package/dist/cjs/src/tools/SelectionTool/types.js +14 -0
- package/dist/cjs/src/tools/TextTool.js +262 -0
- package/dist/cjs/src/tools/ToolController.js +187 -0
- package/dist/cjs/src/tools/ToolEnabledGroup.js +14 -0
- package/dist/cjs/src/tools/ToolSwitcherShortcut.js +38 -0
- package/dist/cjs/src/tools/ToolbarShortcutHandler.js +29 -0
- package/dist/cjs/src/tools/UndoRedoShortcut.js +28 -0
- package/dist/cjs/src/tools/lib.js +36 -0
- package/dist/cjs/src/tools/localization.js +30 -0
- package/dist/cjs/src/types.js +38 -0
- package/dist/cjs/src/util/assertions.js +51 -0
- package/dist/cjs/src/util/fileToBase64.js +15 -0
- package/dist/cjs/src/util/untilNextAnimationFrame.js +9 -0
- package/dist/cjs/src/util/waitForTimeout.js +9 -0
- package/dist/mjs/build_tools/BundledFile.d.ts +13 -0
- package/dist/{build_tools/buildTranslationTemplate.js → mjs/build_tools/buildTranslationTemplate.mjs} +1 -1
- package/dist/{build_tools/bundle.js → mjs/build_tools/bundle.mjs} +1 -1
- package/dist/mjs/build_tools/postDist.d.ts +1 -0
- package/dist/mjs/build_tools/postDist.mjs +67 -0
- package/dist/mjs/src/Color4.d.ts +61 -0
- package/dist/{src/Color4.js → mjs/src/Color4.mjs} +1 -0
- package/dist/mjs/src/Editor.d.ts +308 -0
- package/dist/{src/Editor.js → mjs/src/Editor.mjs} +86 -49
- package/dist/mjs/src/EditorImage.d.ts +97 -0
- package/dist/{src/EditorImage.js → mjs/src/EditorImage.mjs} +12 -10
- package/dist/mjs/src/EventDispatcher.d.ts +30 -0
- package/dist/mjs/src/Pointer.d.ts +24 -0
- package/dist/{src/Pointer.js → mjs/src/Pointer.mjs} +1 -1
- package/dist/mjs/src/SVGLoader.d.ts +48 -0
- package/dist/{src/SVGLoader.js → mjs/src/SVGLoader.mjs} +15 -11
- package/dist/mjs/src/UndoRedoHistory.d.ts +19 -0
- package/dist/{src/UndoRedoHistory.js → mjs/src/UndoRedoHistory.mjs} +1 -1
- package/dist/mjs/src/Viewport.d.ts +71 -0
- package/dist/{src/Viewport.js → mjs/src/Viewport.mjs} +5 -5
- package/dist/mjs/src/bundle/bundled.d.ts +4 -0
- package/dist/{src/bundle/bundled.js → mjs/src/bundle/bundled.mjs} +2 -2
- package/dist/mjs/src/commands/Command.d.ts +16 -0
- package/dist/mjs/src/commands/Duplicate.d.ts +14 -0
- package/dist/{src/commands/Duplicate.js → mjs/src/commands/Duplicate.mjs} +3 -3
- package/dist/mjs/src/commands/Erase.d.ts +14 -0
- package/dist/{src/commands/Erase.js → mjs/src/commands/Erase.mjs} +3 -3
- package/dist/mjs/src/commands/SerializableCommand.d.ts +12 -0
- package/dist/{src/commands/SerializableCommand.js → mjs/src/commands/SerializableCommand.mjs} +1 -1
- package/dist/mjs/src/commands/UnresolvedCommand.d.ts +14 -0
- package/dist/{src/commands/UnresolvedCommand.js → mjs/src/commands/UnresolvedCommand.mjs} +1 -1
- package/dist/mjs/src/commands/invertCommand.d.ts +4 -0
- package/dist/{src/commands/invertCommand.js → mjs/src/commands/invertCommand.mjs} +2 -2
- package/dist/mjs/src/commands/lib.mjs +7 -0
- package/dist/mjs/src/commands/localization.d.ts +23 -0
- package/dist/mjs/src/commands/uniteCommands.d.ts +4 -0
- package/dist/{src/commands/uniteCommands.js → mjs/src/commands/uniteCommands.mjs} +2 -2
- package/dist/mjs/src/components/AbstractComponent.d.ts +73 -0
- package/dist/{src/components/AbstractComponent.js → mjs/src/components/AbstractComponent.mjs} +4 -4
- package/dist/mjs/src/components/ImageBackground.d.ts +42 -0
- package/dist/{src/components/ImageBackground.js → mjs/src/components/ImageBackground.mjs} +5 -5
- package/dist/mjs/src/components/ImageComponent.d.ts +31 -0
- package/dist/{src/components/ImageComponent.js → mjs/src/components/ImageComponent.mjs} +3 -3
- package/dist/mjs/src/components/RestylableComponent.d.ts +24 -0
- package/dist/{src/components/RestylableComponent.js → mjs/src/components/RestylableComponent.mjs} +4 -4
- package/dist/mjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/{src/components/SVGGlobalAttributesObject.js → mjs/src/components/SVGGlobalAttributesObject.mjs} +3 -3
- package/dist/mjs/src/components/Stroke.d.ts +40 -0
- package/dist/{src/components/Stroke.js → mjs/src/components/Stroke.mjs} +5 -5
- package/dist/mjs/src/components/TextComponent.d.ts +53 -0
- package/dist/{src/components/TextComponent.js → mjs/src/components/TextComponent.mjs} +7 -7
- package/dist/mjs/src/components/UnknownSVGObject.d.ts +18 -0
- package/dist/{src/components/UnknownSVGObject.js → mjs/src/components/UnknownSVGObject.mjs} +3 -3
- package/dist/mjs/src/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/{src/components/builders/ArrowBuilder.js → mjs/src/components/builders/ArrowBuilder.mjs} +2 -2
- package/dist/mjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/{src/components/builders/FreehandLineBuilder.js → mjs/src/components/builders/FreehandLineBuilder.mjs} +7 -7
- package/dist/mjs/src/components/builders/LineBuilder.d.ts +18 -0
- package/dist/{src/components/builders/LineBuilder.js → mjs/src/components/builders/LineBuilder.mjs} +2 -2
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/{src/components/builders/PressureSensitiveFreehandLineBuilder.js → mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.mjs} +6 -6
- package/dist/mjs/src/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/{src/components/builders/RectangleBuilder.js → mjs/src/components/builders/RectangleBuilder.mjs} +4 -4
- package/dist/mjs/src/components/builders/types.d.ts +12 -0
- package/dist/mjs/src/components/builders/types.mjs +1 -0
- package/dist/{src/components/lib.js → mjs/src/components/lib.d.ts} +3 -3
- package/dist/mjs/src/components/lib.mjs +12 -0
- package/dist/mjs/src/components/localization.d.ts +11 -0
- package/dist/mjs/src/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/{src/components/util/StrokeSmoother.js → mjs/src/components/util/StrokeSmoother.mjs} +3 -3
- package/dist/mjs/src/components/util/describeComponentList.d.ts +4 -0
- package/dist/{src/lib.js → mjs/src/lib.d.ts} +4 -3
- package/dist/mjs/src/lib.mjs +34 -0
- package/dist/mjs/src/localization.d.ts +14 -0
- package/dist/{src/localization.js → mjs/src/localization.mjs} +5 -5
- package/dist/mjs/src/localizations/de.d.ts +3 -0
- package/dist/{src/localizations/de.js → mjs/src/localizations/de.mjs} +1 -1
- package/dist/mjs/src/localizations/en.d.ts +3 -0
- package/dist/{src/localizations/en.js → mjs/src/localizations/en.mjs} +1 -1
- package/dist/mjs/src/localizations/es.d.ts +3 -0
- package/dist/{src/localizations/es.js → mjs/src/localizations/es.mjs} +1 -1
- package/dist/mjs/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/{src/localizations/getLocalizationTable.js → mjs/src/localizations/getLocalizationTable.mjs} +4 -4
- package/dist/mjs/src/math/LineSegment2.d.ts +24 -0
- package/dist/{src/math/LineSegment2.js → mjs/src/math/LineSegment2.mjs} +2 -2
- package/dist/mjs/src/math/Mat33.d.ts +118 -0
- package/dist/{src/math/Mat33.js → mjs/src/math/Mat33.mjs} +2 -2
- package/dist/mjs/src/math/Path.d.ts +71 -0
- package/dist/{src/math/Path.js → mjs/src/math/Path.mjs} +5 -5
- package/dist/mjs/src/math/Rect2.d.ts +52 -0
- package/dist/{src/math/Rect2.js → mjs/src/math/Rect2.mjs} +2 -2
- package/dist/mjs/src/math/Triangle.d.ts +11 -0
- package/dist/mjs/src/math/Vec2.d.ts +13 -0
- package/dist/{src/math/Vec2.js → mjs/src/math/Vec2.mjs} +1 -1
- package/dist/mjs/src/math/Vec3.d.ts +106 -0
- package/dist/mjs/src/math/lib.mjs +7 -0
- package/dist/mjs/src/math/rounding.d.ts +4 -0
- package/dist/mjs/src/rendering/Display.d.ts +75 -0
- package/dist/{src/rendering/Display.js → mjs/src/rendering/Display.mjs} +7 -7
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +31 -0
- package/dist/{src/rendering/RenderingStyle.js → mjs/src/rendering/RenderingStyle.mjs} +1 -1
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +36 -0
- package/dist/{src/rendering/TextRenderingStyle.js → mjs/src/rendering/TextRenderingStyle.mjs} +1 -1
- package/dist/mjs/src/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/{src/rendering/caching/CacheRecord.js → mjs/src/rendering/caching/CacheRecord.mjs} +1 -1
- package/dist/mjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/{src/rendering/caching/CacheRecordManager.js → mjs/src/rendering/caching/CacheRecordManager.mjs} +1 -1
- package/dist/mjs/src/rendering/caching/RenderingCache.d.ts +11 -0
- package/dist/{src/rendering/caching/RenderingCache.js → mjs/src/rendering/caching/RenderingCache.mjs} +3 -3
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/{src/rendering/caching/RenderingCacheNode.js → mjs/src/rendering/caching/RenderingCacheNode.mjs} +3 -3
- package/dist/mjs/src/rendering/caching/testUtils.d.ts +9 -0
- package/dist/{src/rendering/caching/testUtils.js → mjs/src/rendering/caching/testUtils.mjs} +4 -4
- package/dist/mjs/src/rendering/caching/types.d.ts +19 -0
- package/dist/mjs/src/rendering/caching/types.mjs +1 -0
- package/dist/{src/rendering/lib.js → mjs/src/rendering/lib.d.ts} +2 -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/renderers/AbstractRenderer.d.ts +68 -0
- package/dist/{src/rendering/renderers/AbstractRenderer.js → mjs/src/rendering/renderers/AbstractRenderer.mjs} +3 -3
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/{src/rendering/renderers/CanvasRenderer.js → mjs/src/rendering/renderers/CanvasRenderer.mjs} +32 -5
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/{src/rendering/renderers/DummyRenderer.js → mjs/src/rendering/renderers/DummyRenderer.mjs} +2 -2
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/{src/rendering/renderers/SVGRenderer.js → mjs/src/rendering/renderers/SVGRenderer.mjs} +33 -7
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/{src/rendering/renderers/TextOnlyRenderer.js → mjs/src/rendering/renderers/TextOnlyRenderer.mjs} +2 -2
- package/dist/mjs/src/testing/beforeEachFile.d.ts +1 -0
- package/dist/{src/testing/beforeEachFile.js → mjs/src/testing/beforeEachFile.mjs} +1 -1
- package/dist/mjs/src/testing/createEditor.d.ts +4 -0
- package/dist/{src/testing/createEditor.js → mjs/src/testing/createEditor.mjs} +2 -2
- 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/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/{src/toolbar/HTMLToolbar.js → mjs/src/toolbar/HTMLToolbar.mjs} +17 -17
- package/dist/mjs/src/toolbar/IconProvider.d.ts +62 -0
- package/dist/{src/toolbar/IconProvider.js → mjs/src/toolbar/IconProvider.mjs} +4 -4
- package/dist/mjs/src/toolbar/lib.mjs +3 -0
- package/dist/mjs/src/toolbar/localization.d.ts +49 -0
- package/dist/mjs/src/toolbar/makeColorInput.d.ts +6 -0
- package/dist/{src/toolbar/makeColorInput.js → mjs/src/toolbar/makeColorInput.mjs} +3 -3
- 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/{src/toolbar/widgets/ActionButtonWidget.js → mjs/src/toolbar/widgets/ActionButtonWidget.mjs} +1 -1
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
- package/dist/{src/toolbar/widgets/BaseToolWidget.js → mjs/src/toolbar/widgets/BaseToolWidget.mjs} +2 -2
- package/dist/mjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
- package/dist/{src/toolbar/widgets/BaseWidget.js → mjs/src/toolbar/widgets/BaseWidget.mjs} +3 -3
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
- package/dist/{src/toolbar/widgets/DocumentPropertiesWidget.js → mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs} +9 -7
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
- package/dist/{src/toolbar/widgets/EraserToolWidget.js → mjs/src/toolbar/widgets/EraserToolWidget.mjs} +3 -3
- package/dist/mjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
- package/dist/{src/toolbar/widgets/HandToolWidget.js → mjs/src/toolbar/widgets/HandToolWidget.mjs} +7 -7
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
- package/dist/{src/toolbar/widgets/InsertImageWidget.js → mjs/src/toolbar/widgets/InsertImageWidget.mjs} +8 -8
- package/dist/mjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
- package/dist/{src/toolbar/widgets/OverflowWidget.js → mjs/src/toolbar/widgets/OverflowWidget.mjs} +1 -1
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
- package/dist/{src/toolbar/widgets/PenToolWidget.js → mjs/src/toolbar/widgets/PenToolWidget.mjs} +11 -10
- package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
- package/dist/{src/toolbar/widgets/SelectionToolWidget.js → mjs/src/toolbar/widgets/SelectionToolWidget.mjs} +8 -8
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
- package/dist/{src/toolbar/widgets/TextToolWidget.js → mjs/src/toolbar/widgets/TextToolWidget.mjs} +9 -6
- package/dist/mjs/src/toolbar/widgets/lib.mjs +10 -0
- package/dist/mjs/src/tools/BaseTool.d.ts +22 -0
- package/dist/{src/tools/BaseTool.js → mjs/src/tools/BaseTool.mjs} +1 -1
- package/dist/mjs/src/tools/Eraser.d.ts +23 -0
- package/dist/{src/tools/Eraser.js → mjs/src/tools/Eraser.mjs} +8 -8
- package/dist/mjs/src/tools/FindTool.d.ts +21 -0
- package/dist/{src/tools/FindTool.js → mjs/src/tools/FindTool.mjs} +2 -2
- package/dist/mjs/src/tools/PanZoom.d.ts +52 -0
- package/dist/{src/tools/PanZoom.js → mjs/src/tools/PanZoom.mjs} +8 -8
- package/dist/mjs/src/tools/PasteHandler.d.ts +23 -0
- package/dist/{src/tools/PasteHandler.js → mjs/src/tools/PasteHandler.mjs} +7 -7
- package/dist/mjs/src/tools/Pen.d.ts +39 -0
- package/dist/{src/tools/Pen.js → mjs/src/tools/Pen.mjs} +5 -5
- package/dist/mjs/src/tools/PipetteTool.d.ts +18 -0
- package/dist/{src/tools/PipetteTool.js → mjs/src/tools/PipetteTool.mjs} +1 -1
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/{src/tools/SelectionTool/SelectAllShortcutHandler.js → mjs/src/tools/SelectionTool/SelectAllShortcutHandler.mjs} +2 -2
- package/dist/mjs/src/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/{src/tools/SelectionTool/Selection.js → mjs/src/tools/SelectionTool/Selection.mjs} +12 -12
- package/dist/mjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
- package/dist/{src/tools/SelectionTool/SelectionHandle.js → mjs/src/tools/SelectionTool/SelectionHandle.mjs} +3 -3
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
- package/dist/{src/tools/SelectionTool/SelectionTool.js → mjs/src/tools/SelectionTool/SelectionTool.mjs} +13 -14
- package/dist/mjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
- package/dist/{src/tools/SelectionTool/TransformMode.js → mjs/src/tools/SelectionTool/TransformMode.mjs} +4 -4
- package/dist/mjs/src/tools/SelectionTool/types.d.ts +9 -0
- package/dist/mjs/src/tools/TextTool.d.ts +33 -0
- package/dist/{src/tools/TextTool.js → mjs/src/tools/TextTool.mjs} +11 -11
- package/dist/mjs/src/tools/ToolController.d.ts +18 -0
- package/dist/{src/tools/ToolController.js → mjs/src/tools/ToolController.mjs} +16 -16
- package/dist/mjs/src/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/mjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/{src/tools/ToolSwitcherShortcut.js → mjs/src/tools/ToolSwitcherShortcut.mjs} +1 -1
- package/dist/mjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/{src/tools/ToolbarShortcutHandler.js → mjs/src/tools/ToolbarShortcutHandler.mjs} +1 -1
- package/dist/mjs/src/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/{src/tools/UndoRedoShortcut.js → mjs/src/tools/UndoRedoShortcut.mjs} +1 -1
- package/dist/{src/tools/lib.js → mjs/src/tools/lib.d.ts} +1 -1
- package/dist/mjs/src/tools/lib.mjs +16 -0
- package/dist/mjs/src/tools/localization.d.ts +28 -0
- package/dist/mjs/src/types.d.ts +151 -0
- package/dist/mjs/src/util/assertions.d.ts +23 -0
- package/dist/mjs/src/util/fileToBase64.d.ts +3 -0
- package/dist/mjs/src/util/untilNextAnimationFrame.d.ts +3 -0
- package/dist/mjs/src/util/waitForTimeout.d.ts +2 -0
- package/package.json +34 -33
- package/src/Color4.ts +2 -0
- package/src/Editor.ts +62 -28
- package/src/EditorImage.ts +4 -2
- package/src/SVGLoader.ts +4 -0
- package/src/lib.ts +2 -1
- package/src/rendering/lib.ts +2 -0
- package/src/rendering/renderers/CanvasRenderer.ts +27 -0
- package/src/rendering/renderers/SVGRenderer.ts +32 -1
- package/src/testing/lib.ts +3 -0
- package/src/testing/sendPenEvent.ts +31 -0
- package/src/testing/sendTouchEvent.ts +36 -1
- package/src/toolbar/toolbar.css +5 -0
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +4 -2
- package/src/toolbar/widgets/PenToolWidget.ts +1 -0
- package/src/toolbar/widgets/TextToolWidget.ts +4 -1
- package/src/tools/Eraser.test.ts +11 -10
- package/src/tools/PanZoom.test.ts +1 -1
- package/src/tools/Pen.test.ts +63 -62
- package/src/tools/SelectionTool/SelectionTool.test.ts +15 -14
- package/src/tools/SelectionTool/SelectionTool.ts +5 -7
- package/tsconfig.json +3 -2
- package/tsconfig.mjs.json +9 -0
- package/dist/src/testing/sendTouchEvent.d.ts +0 -6
- package/dist/src/testing/sendTouchEvent.js +0 -26
- /package/dist/{build_tools → cjs/build_tools}/BundledFile.d.ts +0 -0
- /package/dist/{build_tools → cjs/build_tools}/buildTranslationTemplate.d.ts +0 -0
- /package/dist/{build_tools → cjs/build_tools}/bundle.d.ts +0 -0
- /package/dist/{src/components/builders/types.js → cjs/build_tools/postDist.d.ts} +0 -0
- /package/dist/{src → cjs/src}/EventDispatcher.d.ts +0 -0
- /package/dist/{src → cjs/src}/Pointer.d.ts +0 -0
- /package/dist/{src → cjs/src}/UndoRedoHistory.d.ts +0 -0
- /package/dist/{src → cjs/src}/Viewport.d.ts +0 -0
- /package/dist/{src → cjs/src}/bundle/bundled.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/Command.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/Duplicate.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/Erase.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/SerializableCommand.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/UnresolvedCommand.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/invertCommand.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/lib.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/localization.d.ts +0 -0
- /package/dist/{src → cjs/src}/commands/uniteCommands.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/AbstractComponent.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/ImageBackground.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/ImageComponent.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/RestylableComponent.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/SVGGlobalAttributesObject.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/Stroke.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/TextComponent.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/UnknownSVGObject.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/builders/ArrowBuilder.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/builders/FreehandLineBuilder.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/builders/LineBuilder.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/builders/RectangleBuilder.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/builders/types.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/lib.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/localization.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/util/StrokeSmoother.d.ts +0 -0
- /package/dist/{src → cjs/src}/components/util/describeComponentList.d.ts +0 -0
- /package/dist/{src → cjs/src}/localization.d.ts +0 -0
- /package/dist/{src → cjs/src}/localizations/de.d.ts +0 -0
- /package/dist/{src → cjs/src}/localizations/en.d.ts +0 -0
- /package/dist/{src → cjs/src}/localizations/es.d.ts +0 -0
- /package/dist/{src → cjs/src}/localizations/getLocalizationTable.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/LineSegment2.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/Mat33.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/Path.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/Rect2.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/Triangle.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/Vec2.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/Vec3.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/lib.d.ts +0 -0
- /package/dist/{src → cjs/src}/math/rounding.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/Display.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/RenderingStyle.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/TextRenderingStyle.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/caching/CacheRecord.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/caching/CacheRecordManager.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/caching/RenderingCache.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/caching/RenderingCacheNode.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/caching/testUtils.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/caching/types.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/localization.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/renderers/AbstractRenderer.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/renderers/DummyRenderer.d.ts +0 -0
- /package/dist/{src → cjs/src}/rendering/renderers/TextOnlyRenderer.d.ts +0 -0
- /package/dist/{src → cjs/src}/testing/beforeEachFile.d.ts +0 -0
- /package/dist/{src → cjs/src}/testing/createEditor.d.ts +0 -0
- /package/dist/{src → cjs/src}/testing/loadExpectExtensions.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/HTMLToolbar.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/IconProvider.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/lib.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/localization.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/makeColorInput.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/types.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/ActionButtonWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/BaseToolWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/BaseWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/DocumentPropertiesWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/EraserToolWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/HandToolWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/InsertImageWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/OverflowWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/PenToolWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/SelectionToolWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/TextToolWidget.d.ts +0 -0
- /package/dist/{src → cjs/src}/toolbar/widgets/lib.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/BaseTool.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/Eraser.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/FindTool.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/PanZoom.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/PasteHandler.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/Pen.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/PipetteTool.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/SelectionTool/Selection.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/SelectionTool/SelectionHandle.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/SelectionTool/SelectionTool.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/SelectionTool/TransformMode.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/SelectionTool/types.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/TextTool.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/ToolController.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/ToolEnabledGroup.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/ToolSwitcherShortcut.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/ToolbarShortcutHandler.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/UndoRedoShortcut.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/lib.d.ts +0 -0
- /package/dist/{src → cjs/src}/tools/localization.d.ts +0 -0
- /package/dist/{src → cjs/src}/types.d.ts +0 -0
- /package/dist/{src → cjs/src}/util/assertions.d.ts +0 -0
- /package/dist/{src → cjs/src}/util/fileToBase64.d.ts +0 -0
- /package/dist/{src → cjs/src}/util/untilNextAnimationFrame.d.ts +0 -0
- /package/dist/{src → cjs/src}/util/waitForTimeout.d.ts +0 -0
- /package/dist/{build_tools/BundledFile.js → mjs/build_tools/BundledFile.mjs} +0 -0
- /package/dist/{src/rendering/caching/types.js → mjs/build_tools/buildTranslationTemplate.d.ts} +0 -0
- /package/dist/{src/toolbar/types.js → mjs/build_tools/bundle.d.ts} +0 -0
- /package/dist/{src/EventDispatcher.js → mjs/src/EventDispatcher.mjs} +0 -0
- /package/dist/{src/commands/Command.js → mjs/src/commands/Command.mjs} +0 -0
- /package/dist/{src/commands/lib.js → mjs/src/commands/lib.d.ts} +0 -0
- /package/dist/{src/commands/localization.js → mjs/src/commands/localization.mjs} +0 -0
- /package/dist/{src/components/localization.js → mjs/src/components/localization.mjs} +0 -0
- /package/dist/{src/components/util/describeComponentList.js → mjs/src/components/util/describeComponentList.mjs} +0 -0
- /package/dist/{src/math/Triangle.js → mjs/src/math/Triangle.mjs} +0 -0
- /package/dist/{src/math/Vec3.js → mjs/src/math/Vec3.mjs} +0 -0
- /package/dist/{src/math/lib.js → mjs/src/math/lib.d.ts} +0 -0
- /package/dist/{src/math/rounding.js → mjs/src/math/rounding.mjs} +0 -0
- /package/dist/{src/rendering/localization.js → mjs/src/rendering/localization.mjs} +0 -0
- /package/dist/{src/testing/loadExpectExtensions.js → mjs/src/testing/loadExpectExtensions.mjs} +0 -0
- /package/dist/{src/toolbar/lib.js → mjs/src/toolbar/lib.d.ts} +0 -0
- /package/dist/{src/toolbar/localization.js → mjs/src/toolbar/localization.mjs} +0 -0
- /package/dist/{src/toolbar/widgets/lib.js → mjs/src/toolbar/widgets/lib.d.ts} +0 -0
- /package/dist/{src/tools/SelectionTool/types.js → mjs/src/tools/SelectionTool/types.mjs} +0 -0
- /package/dist/{src/tools/ToolEnabledGroup.js → mjs/src/tools/ToolEnabledGroup.mjs} +0 -0
- /package/dist/{src/tools/localization.js → mjs/src/tools/localization.mjs} +0 -0
- /package/dist/{src/types.js → mjs/src/types.mjs} +0 -0
- /package/dist/{src/util/assertions.js → mjs/src/util/assertions.mjs} +0 -0
- /package/dist/{src/util/fileToBase64.js → mjs/src/util/fileToBase64.mjs} +0 -0
- /package/dist/{src/util/untilNextAnimationFrame.js → mjs/src/util/untilNextAnimationFrame.mjs} +0 -0
- /package/dist/{src/util/waitForTimeout.js → mjs/src/util/waitForTimeout.mjs} +0 -0
@@ -26,8 +26,10 @@ export default class EditorImage {
|
|
26
26
|
/** @internal */
|
27
27
|
renderWithCache(screenRenderer: AbstractRenderer, cache: RenderingCache, viewport: Viewport): void;
|
28
28
|
/**
|
29
|
-
* Renders all nodes visible from `viewport` (or all nodes if `viewport = null`)
|
30
|
-
*
|
29
|
+
* Renders all nodes visible from `viewport` (or all nodes if `viewport = null`).
|
30
|
+
*
|
31
|
+
* `viewport` is used to improve rendering performance. If given, it must match
|
32
|
+
* the viewport used by the `renderer` (if any).
|
31
33
|
*/
|
32
34
|
render(renderer: AbstractRenderer, viewport: Viewport | null): void;
|
33
35
|
/** Renders all nodes, even ones not within the viewport. @internal */
|
@@ -0,0 +1,486 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
var _a, _b, _c;
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
exports.ImageNode = exports.EditorImageEventType = exports.sortLeavesByZIndex = void 0;
|
8
|
+
const Viewport_1 = __importDefault(require("./Viewport"));
|
9
|
+
const AbstractComponent_1 = __importDefault(require("./components/AbstractComponent"));
|
10
|
+
const Rect2_1 = __importDefault(require("./math/Rect2"));
|
11
|
+
const SerializableCommand_1 = __importDefault(require("./commands/SerializableCommand"));
|
12
|
+
const EventDispatcher_1 = __importDefault(require("./EventDispatcher"));
|
13
|
+
const Vec2_1 = require("./math/Vec2");
|
14
|
+
const Mat33_1 = __importDefault(require("./math/Mat33"));
|
15
|
+
const assertions_1 = require("./util/assertions");
|
16
|
+
// @internal Sort by z-index, low to high
|
17
|
+
const sortLeavesByZIndex = (leaves) => {
|
18
|
+
leaves.sort((a, b) => a.getContent().getZIndex() - b.getContent().getZIndex());
|
19
|
+
};
|
20
|
+
exports.sortLeavesByZIndex = sortLeavesByZIndex;
|
21
|
+
var EditorImageEventType;
|
22
|
+
(function (EditorImageEventType) {
|
23
|
+
EditorImageEventType[EditorImageEventType["ExportViewportChanged"] = 0] = "ExportViewportChanged";
|
24
|
+
})(EditorImageEventType = exports.EditorImageEventType || (exports.EditorImageEventType = {}));
|
25
|
+
// Handles lookup/storage of elements in the image
|
26
|
+
class EditorImage {
|
27
|
+
// @internal
|
28
|
+
constructor() {
|
29
|
+
this.root = new ImageNode();
|
30
|
+
this.background = new ImageNode();
|
31
|
+
this.componentsById = {};
|
32
|
+
this.notifier = new EventDispatcher_1.default();
|
33
|
+
this.importExportViewport = new Viewport_1.default(() => {
|
34
|
+
this.notifier.dispatch(EditorImageEventType.ExportViewportChanged, {
|
35
|
+
image: this,
|
36
|
+
});
|
37
|
+
});
|
38
|
+
// Default to a 500x500 image
|
39
|
+
this.importExportViewport.updateScreenSize(Vec2_1.Vec2.of(500, 500));
|
40
|
+
}
|
41
|
+
// Returns all components that make up the background of this image. These
|
42
|
+
// components are rendered below all other components.
|
43
|
+
getBackgroundComponents() {
|
44
|
+
const result = [];
|
45
|
+
const leaves = this.background.getLeaves();
|
46
|
+
(0, exports.sortLeavesByZIndex)(leaves);
|
47
|
+
for (const leaf of leaves) {
|
48
|
+
const content = leaf.getContent();
|
49
|
+
if (content) {
|
50
|
+
result.push(content);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return result;
|
54
|
+
}
|
55
|
+
// Returns the parent of the given element, if it exists.
|
56
|
+
findParent(elem) {
|
57
|
+
var _b;
|
58
|
+
return (_b = this.background.getChildWithContent(elem)) !== null && _b !== void 0 ? _b : this.root.getChildWithContent(elem);
|
59
|
+
}
|
60
|
+
// Forces a re-render of `elem` when the image is next re-rendered as a whole.
|
61
|
+
// Does nothing if `elem` is not in this.
|
62
|
+
queueRerenderOf(elem) {
|
63
|
+
// TODO: Make more efficient (e.g. increase IDs of all parents,
|
64
|
+
// make cache take into account last modified time instead of IDs, etc.)
|
65
|
+
const parent = this.findParent(elem);
|
66
|
+
if (parent) {
|
67
|
+
parent.remove();
|
68
|
+
this.addElementDirectly(elem);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
/** @internal */
|
72
|
+
renderWithCache(screenRenderer, cache, viewport) {
|
73
|
+
this.background.render(screenRenderer, viewport.visibleRect);
|
74
|
+
cache.render(screenRenderer, this.root, viewport);
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* Renders all nodes visible from `viewport` (or all nodes if `viewport = null`).
|
78
|
+
*
|
79
|
+
* `viewport` is used to improve rendering performance. If given, it must match
|
80
|
+
* the viewport used by the `renderer` (if any).
|
81
|
+
*/
|
82
|
+
render(renderer, viewport) {
|
83
|
+
this.background.render(renderer, viewport === null || viewport === void 0 ? void 0 : viewport.visibleRect);
|
84
|
+
this.root.render(renderer, viewport === null || viewport === void 0 ? void 0 : viewport.visibleRect);
|
85
|
+
}
|
86
|
+
/** Renders all nodes, even ones not within the viewport. @internal */
|
87
|
+
renderAll(renderer) {
|
88
|
+
this.render(renderer, null);
|
89
|
+
}
|
90
|
+
/** @returns all elements in the image, sorted by z-index. This can be slow for large images. */
|
91
|
+
getAllElements() {
|
92
|
+
const leaves = this.root.getLeaves();
|
93
|
+
(0, exports.sortLeavesByZIndex)(leaves);
|
94
|
+
return leaves.map(leaf => leaf.getContent());
|
95
|
+
}
|
96
|
+
/** @returns a list of `AbstractComponent`s intersecting `region`, sorted by z-index. */
|
97
|
+
getElementsIntersectingRegion(region) {
|
98
|
+
const leaves = this.root.getLeavesIntersectingRegion(region);
|
99
|
+
(0, exports.sortLeavesByZIndex)(leaves);
|
100
|
+
return leaves.map(leaf => leaf.getContent());
|
101
|
+
}
|
102
|
+
/** @internal */
|
103
|
+
onDestroyElement(elem) {
|
104
|
+
delete this.componentsById[elem.getId()];
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
* @returns the AbstractComponent with `id`, if it exists.
|
108
|
+
*
|
109
|
+
* @see {@link AbstractComponent.getId}
|
110
|
+
*/
|
111
|
+
lookupElement(id) {
|
112
|
+
var _b;
|
113
|
+
return (_b = this.componentsById[id]) !== null && _b !== void 0 ? _b : null;
|
114
|
+
}
|
115
|
+
addElementDirectly(elem) {
|
116
|
+
elem.onAddToImage(this);
|
117
|
+
this.componentsById[elem.getId()] = elem;
|
118
|
+
// If a background component, add to the background. Else,
|
119
|
+
// add to the normal component tree.
|
120
|
+
const parentTree = elem.isBackground() ? this.background : this.root;
|
121
|
+
return parentTree.addLeaf(elem);
|
122
|
+
}
|
123
|
+
removeElementDirectly(element) {
|
124
|
+
const container = this.findParent(element);
|
125
|
+
container === null || container === void 0 ? void 0 : container.remove();
|
126
|
+
if (container) {
|
127
|
+
this.onDestroyElement(element);
|
128
|
+
return true;
|
129
|
+
}
|
130
|
+
return false;
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* Returns a command that adds the given element to the `EditorImage`.
|
134
|
+
* If `applyByFlattening` is true, the content of the wet ink renderer is
|
135
|
+
* rendered onto the main rendering canvas instead of doing a full re-render.
|
136
|
+
*
|
137
|
+
* @see {@link Display.flatten}
|
138
|
+
*/
|
139
|
+
static addElement(elem, applyByFlattening = false) {
|
140
|
+
return new EditorImage.AddElementCommand(elem, applyByFlattening);
|
141
|
+
}
|
142
|
+
/** @see EditorImage.addElement */
|
143
|
+
addElement(elem, applyByFlattening) {
|
144
|
+
return EditorImage.addElement(elem, applyByFlattening);
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* @returns a `Viewport` for rendering the image when importing/exporting.
|
148
|
+
*/
|
149
|
+
getImportExportViewport() {
|
150
|
+
return this.importExportViewport;
|
151
|
+
}
|
152
|
+
setImportExportRect(imageRect) {
|
153
|
+
const importExportViewport = this.getImportExportViewport();
|
154
|
+
const origSize = importExportViewport.visibleRect.size;
|
155
|
+
const origTransform = importExportViewport.canvasToScreenTransform;
|
156
|
+
return new EditorImage.SetImportExportRectCommand(origSize, origTransform, imageRect);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
exports.default = EditorImage;
|
160
|
+
_a = EditorImage;
|
161
|
+
// A Command that can access private [EditorImage] functionality
|
162
|
+
EditorImage.AddElementCommand = (_b = class extends SerializableCommand_1.default {
|
163
|
+
// If [applyByFlattening], then the rendered content of this element
|
164
|
+
// is present on the display's wet ink canvas. As such, no re-render is necessary
|
165
|
+
// the first time this command is applied (the surfaces are joined instead).
|
166
|
+
constructor(element, applyByFlattening = false) {
|
167
|
+
super('add-element');
|
168
|
+
this.element = element;
|
169
|
+
this.applyByFlattening = applyByFlattening;
|
170
|
+
this.serializedElem = null;
|
171
|
+
// FIXME: The serialized version of this command may be inaccurate if this is
|
172
|
+
// serialized when this command is not on the top of the undo stack.
|
173
|
+
//
|
174
|
+
// Caching the element's serialized data leads to additional memory usage *and*
|
175
|
+
// sometimes incorrect behavior in collaborative editing.
|
176
|
+
this.serializedElem = null;
|
177
|
+
if (isNaN(element.getBBox().area)) {
|
178
|
+
throw new Error('Elements in the image cannot have NaN bounding boxes');
|
179
|
+
}
|
180
|
+
}
|
181
|
+
apply(editor) {
|
182
|
+
editor.image.addElementDirectly(this.element);
|
183
|
+
if (!this.applyByFlattening) {
|
184
|
+
editor.queueRerender();
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
this.applyByFlattening = false;
|
188
|
+
editor.display.flatten();
|
189
|
+
}
|
190
|
+
}
|
191
|
+
unapply(editor) {
|
192
|
+
editor.image.removeElementDirectly(this.element);
|
193
|
+
editor.queueRerender();
|
194
|
+
}
|
195
|
+
description(_editor, localization) {
|
196
|
+
return localization.addElementAction(this.element.description(localization));
|
197
|
+
}
|
198
|
+
serializeToJSON() {
|
199
|
+
var _b;
|
200
|
+
return {
|
201
|
+
elemData: (_b = this.serializedElem) !== null && _b !== void 0 ? _b : this.element.serialize(),
|
202
|
+
};
|
203
|
+
}
|
204
|
+
},
|
205
|
+
(() => {
|
206
|
+
SerializableCommand_1.default.register('add-element', (json, editor) => {
|
207
|
+
const id = json.elemData.id;
|
208
|
+
const foundElem = editor.image.lookupElement(id);
|
209
|
+
const elem = foundElem !== null && foundElem !== void 0 ? foundElem : AbstractComponent_1.default.deserialize(json.elemData);
|
210
|
+
const result = new EditorImage.AddElementCommand(elem);
|
211
|
+
result.serializedElem = json.elemData;
|
212
|
+
return result;
|
213
|
+
});
|
214
|
+
})(),
|
215
|
+
_b);
|
216
|
+
// Handles resizing the background import/export region of the image.
|
217
|
+
EditorImage.SetImportExportRectCommand = (_c = class extends SerializableCommand_1.default {
|
218
|
+
constructor(originalSize, originalTransform, finalRect) {
|
219
|
+
super(EditorImage.SetImportExportRectCommand.commandId);
|
220
|
+
this.originalSize = originalSize;
|
221
|
+
this.originalTransform = originalTransform;
|
222
|
+
this.finalRect = finalRect;
|
223
|
+
}
|
224
|
+
apply(editor) {
|
225
|
+
const viewport = editor.image.getImportExportViewport();
|
226
|
+
viewport.updateScreenSize(this.finalRect.size);
|
227
|
+
viewport.resetTransform(Mat33_1.default.translation(this.finalRect.topLeft.times(-1)));
|
228
|
+
editor.queueRerender();
|
229
|
+
}
|
230
|
+
unapply(editor) {
|
231
|
+
const viewport = editor.image.getImportExportViewport();
|
232
|
+
viewport.updateScreenSize(this.originalSize);
|
233
|
+
viewport.resetTransform(this.originalTransform);
|
234
|
+
editor.queueRerender();
|
235
|
+
}
|
236
|
+
description(_editor, localization) {
|
237
|
+
return localization.resizeOutputCommand(this.finalRect);
|
238
|
+
}
|
239
|
+
serializeToJSON() {
|
240
|
+
return {
|
241
|
+
originalSize: this.originalSize.xy,
|
242
|
+
originalTransform: this.originalTransform.toArray(),
|
243
|
+
newRegion: {
|
244
|
+
x: this.finalRect.x,
|
245
|
+
y: this.finalRect.y,
|
246
|
+
w: this.finalRect.w,
|
247
|
+
h: this.finalRect.h,
|
248
|
+
},
|
249
|
+
};
|
250
|
+
}
|
251
|
+
},
|
252
|
+
_c.commandId = 'set-import-export-rect',
|
253
|
+
(() => {
|
254
|
+
const commandId = _c.commandId;
|
255
|
+
SerializableCommand_1.default.register(commandId, (json, _editor) => {
|
256
|
+
(0, assertions_1.assertIsNumber)(json.originalSize.x);
|
257
|
+
(0, assertions_1.assertIsNumber)(json.originalSize.y);
|
258
|
+
(0, assertions_1.assertIsNumberArray)(json.originalTransform);
|
259
|
+
(0, assertions_1.assertIsNumberArray)([
|
260
|
+
json.newRegion.x,
|
261
|
+
json.newRegion.y,
|
262
|
+
json.newRegion.w,
|
263
|
+
json.newRegion.h,
|
264
|
+
]);
|
265
|
+
const originalSize = Vec2_1.Vec2.ofXY(json.originalSize);
|
266
|
+
const originalTransform = new Mat33_1.default(...json.originalTransform);
|
267
|
+
const finalRect = new Rect2_1.default(json.newRegion.x, json.newRegion.y, json.newRegion.w, json.newRegion.h);
|
268
|
+
return new EditorImage.SetImportExportRectCommand(originalSize, originalTransform, finalRect);
|
269
|
+
});
|
270
|
+
})(),
|
271
|
+
_c);
|
272
|
+
/** Part of the Editor's image. @internal */
|
273
|
+
class ImageNode {
|
274
|
+
constructor(parent = null) {
|
275
|
+
this.parent = parent;
|
276
|
+
this.targetChildCount = 30;
|
277
|
+
this.children = [];
|
278
|
+
this.bbox = Rect2_1.default.empty;
|
279
|
+
this.content = null;
|
280
|
+
this.id = ImageNode.idCounter++;
|
281
|
+
}
|
282
|
+
getId() {
|
283
|
+
return this.id;
|
284
|
+
}
|
285
|
+
onContentChange() {
|
286
|
+
this.id = ImageNode.idCounter++;
|
287
|
+
}
|
288
|
+
getContent() {
|
289
|
+
return this.content;
|
290
|
+
}
|
291
|
+
getParent() {
|
292
|
+
return this.parent;
|
293
|
+
}
|
294
|
+
getChildrenIntersectingRegion(region) {
|
295
|
+
return this.children.filter(child => {
|
296
|
+
return child.getBBox().intersects(region);
|
297
|
+
});
|
298
|
+
}
|
299
|
+
getChildrenOrSelfIntersectingRegion(region) {
|
300
|
+
if (this.content) {
|
301
|
+
return [this];
|
302
|
+
}
|
303
|
+
return this.getChildrenIntersectingRegion(region);
|
304
|
+
}
|
305
|
+
// Returns a list of `ImageNode`s with content (and thus no children).
|
306
|
+
getLeavesIntersectingRegion(region, isTooSmall) {
|
307
|
+
const result = [];
|
308
|
+
let current;
|
309
|
+
const workList = [];
|
310
|
+
workList.push(this);
|
311
|
+
const toNext = () => {
|
312
|
+
current = undefined;
|
313
|
+
const next = workList.pop();
|
314
|
+
if (next && !(isTooSmall === null || isTooSmall === void 0 ? void 0 : isTooSmall(next.bbox))) {
|
315
|
+
current = next;
|
316
|
+
if (current.content !== null && current.getBBox().intersection(region)) {
|
317
|
+
result.push(current);
|
318
|
+
}
|
319
|
+
workList.push(...current.getChildrenIntersectingRegion(region));
|
320
|
+
}
|
321
|
+
};
|
322
|
+
while (workList.length > 0) {
|
323
|
+
toNext();
|
324
|
+
}
|
325
|
+
return result;
|
326
|
+
}
|
327
|
+
// Returns the child of this with the target content or `null` if no
|
328
|
+
// such child exists.
|
329
|
+
getChildWithContent(target) {
|
330
|
+
const candidates = this.getLeavesIntersectingRegion(target.getBBox());
|
331
|
+
for (const candidate of candidates) {
|
332
|
+
if (candidate.getContent() === target) {
|
333
|
+
return candidate;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
return null;
|
337
|
+
}
|
338
|
+
// Returns a list of leaves with this as an ancestor.
|
339
|
+
// Like getLeavesInRegion, but does not check whether ancestors are in a given rectangle
|
340
|
+
getLeaves() {
|
341
|
+
if (this.content) {
|
342
|
+
return [this];
|
343
|
+
}
|
344
|
+
const result = [];
|
345
|
+
for (const child of this.children) {
|
346
|
+
result.push(...child.getLeaves());
|
347
|
+
}
|
348
|
+
return result;
|
349
|
+
}
|
350
|
+
addLeaf(leaf) {
|
351
|
+
this.onContentChange();
|
352
|
+
if (this.content === null && this.children.length === 0) {
|
353
|
+
this.content = leaf;
|
354
|
+
this.recomputeBBox(true);
|
355
|
+
return this;
|
356
|
+
}
|
357
|
+
if (this.content !== null) {
|
358
|
+
console.assert(this.children.length === 0);
|
359
|
+
const contentNode = new ImageNode(this);
|
360
|
+
contentNode.content = this.content;
|
361
|
+
this.content = null;
|
362
|
+
this.children.push(contentNode);
|
363
|
+
contentNode.recomputeBBox(false);
|
364
|
+
}
|
365
|
+
// If this node is contained within the leaf, make this and the leaf
|
366
|
+
// share a parent.
|
367
|
+
const leafBBox = leaf.getBBox();
|
368
|
+
if (leafBBox.containsRect(this.getBBox())) {
|
369
|
+
const nodeForNewLeaf = new ImageNode(this);
|
370
|
+
if (this.children.length < this.targetChildCount) {
|
371
|
+
this.children.push(nodeForNewLeaf);
|
372
|
+
}
|
373
|
+
else {
|
374
|
+
const nodeForChildren = new ImageNode(this);
|
375
|
+
nodeForChildren.children = this.children;
|
376
|
+
this.children = [nodeForNewLeaf, nodeForChildren];
|
377
|
+
nodeForChildren.recomputeBBox(true);
|
378
|
+
nodeForChildren.updateParents();
|
379
|
+
}
|
380
|
+
return nodeForNewLeaf.addLeaf(leaf);
|
381
|
+
}
|
382
|
+
const containingNodes = this.children.filter(child => child.getBBox().containsRect(leafBBox));
|
383
|
+
// Does the leaf already fit within one of the children?
|
384
|
+
if (containingNodes.length > 0 && this.children.length >= this.targetChildCount) {
|
385
|
+
// Sort the containers in ascending order by area
|
386
|
+
containingNodes.sort((a, b) => a.getBBox().area - b.getBBox().area);
|
387
|
+
// Choose the smallest child that contains the new element.
|
388
|
+
const result = containingNodes[0].addLeaf(leaf);
|
389
|
+
result.rebalance();
|
390
|
+
return result;
|
391
|
+
}
|
392
|
+
const newNode = new ImageNode(this);
|
393
|
+
this.children.push(newNode);
|
394
|
+
newNode.content = leaf;
|
395
|
+
newNode.recomputeBBox(true);
|
396
|
+
return newNode;
|
397
|
+
}
|
398
|
+
getBBox() {
|
399
|
+
return this.bbox;
|
400
|
+
}
|
401
|
+
// Recomputes this' bounding box. If [bubbleUp], also recompute
|
402
|
+
// this' ancestors bounding boxes. This also re-computes this' bounding box
|
403
|
+
// in the z-direction (z-indicies).
|
404
|
+
recomputeBBox(bubbleUp) {
|
405
|
+
var _b;
|
406
|
+
const oldBBox = this.bbox;
|
407
|
+
if (this.content !== null) {
|
408
|
+
this.bbox = this.content.getBBox();
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
this.bbox = Rect2_1.default.union(...this.children.map(child => child.getBBox()));
|
412
|
+
}
|
413
|
+
if (bubbleUp && !oldBBox.eq(this.bbox)) {
|
414
|
+
(_b = this.parent) === null || _b === void 0 ? void 0 : _b.recomputeBBox(true);
|
415
|
+
}
|
416
|
+
}
|
417
|
+
updateParents(recursive = false) {
|
418
|
+
for (const child of this.children) {
|
419
|
+
child.parent = this;
|
420
|
+
if (recursive) {
|
421
|
+
child.updateParents(recursive);
|
422
|
+
}
|
423
|
+
}
|
424
|
+
}
|
425
|
+
rebalance() {
|
426
|
+
// If the current node is its parent's only child,
|
427
|
+
if (this.parent && this.parent.children.length === 1) {
|
428
|
+
console.assert(this.parent.content === null);
|
429
|
+
console.assert(this.parent.children[0] === this);
|
430
|
+
// Remove this' parent, if this' parent isn't the root.
|
431
|
+
const oldParent = this.parent;
|
432
|
+
if (oldParent.parent !== null) {
|
433
|
+
oldParent.children = [];
|
434
|
+
this.parent = oldParent.parent;
|
435
|
+
this.parent.children.push(this);
|
436
|
+
oldParent.parent = null;
|
437
|
+
this.parent.recomputeBBox(false);
|
438
|
+
}
|
439
|
+
else if (this.content === null) {
|
440
|
+
// Remove this and transfer this' children to the parent.
|
441
|
+
this.parent.children = this.children;
|
442
|
+
this.parent.updateParents();
|
443
|
+
this.parent = null;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
}
|
447
|
+
// Remove this node and all of its children
|
448
|
+
remove() {
|
449
|
+
var _b;
|
450
|
+
(_b = this.content) === null || _b === void 0 ? void 0 : _b.onRemoveFromImage();
|
451
|
+
if (!this.parent) {
|
452
|
+
this.content = null;
|
453
|
+
this.children = [];
|
454
|
+
return;
|
455
|
+
}
|
456
|
+
const oldChildCount = this.parent.children.length;
|
457
|
+
this.parent.children = this.parent.children.filter(node => {
|
458
|
+
return node !== this;
|
459
|
+
});
|
460
|
+
console.assert(this.parent.children.length === oldChildCount - 1, `${oldChildCount - 1} ≠ ${this.parent.children.length} after removing all nodes equal to ${this}. Nodes should only be removed once.`);
|
461
|
+
this.parent.children.forEach(child => {
|
462
|
+
child.rebalance();
|
463
|
+
});
|
464
|
+
this.parent.recomputeBBox(true);
|
465
|
+
// Invalidate/disconnect this.
|
466
|
+
this.content = null;
|
467
|
+
this.parent = null;
|
468
|
+
this.children = [];
|
469
|
+
}
|
470
|
+
render(renderer, visibleRect) {
|
471
|
+
let leaves;
|
472
|
+
if (visibleRect) {
|
473
|
+
leaves = this.getLeavesIntersectingRegion(visibleRect, rect => renderer.isTooSmallToRender(rect));
|
474
|
+
}
|
475
|
+
else {
|
476
|
+
leaves = this.getLeaves();
|
477
|
+
}
|
478
|
+
(0, exports.sortLeavesByZIndex)(leaves);
|
479
|
+
for (const leaf of leaves) {
|
480
|
+
// Leaves by definition have content
|
481
|
+
leaf.getContent().render(renderer, visibleRect);
|
482
|
+
}
|
483
|
+
}
|
484
|
+
}
|
485
|
+
exports.ImageNode = ImageNode;
|
486
|
+
ImageNode.idCounter = 0;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* Handles notifying listeners of events.
|
4
|
+
*
|
5
|
+
* `EventKeyType` is used to distinguish events (e.g. a `ClickEvent` vs a `TouchEvent`)
|
6
|
+
* while `EventMessageType` is the type of the data sent with an event (can be `void`).
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* ```
|
10
|
+
* const dispatcher = new EventDispatcher<'event1'|'event2'|'event3', void>();
|
11
|
+
* dispatcher.on('event1', () => {
|
12
|
+
* console.log('Event 1 triggered.');
|
13
|
+
* });
|
14
|
+
* dispatcher.dispatch('event1');
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* @packageDocumentation
|
18
|
+
*/
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
20
|
+
// { @inheritDoc EventDispatcher! }
|
21
|
+
class EventDispatcher {
|
22
|
+
constructor() {
|
23
|
+
this.listeners = {};
|
24
|
+
}
|
25
|
+
dispatch(eventName, event) {
|
26
|
+
const listenerList = this.listeners[eventName];
|
27
|
+
if (listenerList) {
|
28
|
+
for (let i = 0; i < listenerList.length; i++) {
|
29
|
+
listenerList[i](event);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
on(eventName, callback) {
|
34
|
+
if (!this.listeners[eventName])
|
35
|
+
this.listeners[eventName] = [];
|
36
|
+
this.listeners[eventName].push(callback);
|
37
|
+
return {
|
38
|
+
// Retuns false if the listener has already been removed, true otherwise.
|
39
|
+
remove: () => {
|
40
|
+
const originalListeners = this.listeners[eventName];
|
41
|
+
this.off(eventName, callback);
|
42
|
+
return originalListeners.length !== this.listeners[eventName].length;
|
43
|
+
},
|
44
|
+
};
|
45
|
+
}
|
46
|
+
/** Removes an event listener. This is equivalent to calling `.remove()` on the object returned by `.on`. */
|
47
|
+
off(eventName, callback) {
|
48
|
+
const listeners = this.listeners[eventName];
|
49
|
+
if (!listeners)
|
50
|
+
return;
|
51
|
+
// Replace the current list of listeners with a new, shortened list.
|
52
|
+
// This allows any iterators over this.listeners to continue iterating
|
53
|
+
// without skipping elements.
|
54
|
+
this.listeners[eventName] = listeners.filter(otherCallback => otherCallback !== callback);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
exports.default = EventDispatcher;
|
@@ -0,0 +1,84 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PointerDevice = void 0;
|
4
|
+
const Vec2_1 = require("./math/Vec2");
|
5
|
+
var PointerDevice;
|
6
|
+
(function (PointerDevice) {
|
7
|
+
PointerDevice[PointerDevice["Pen"] = 0] = "Pen";
|
8
|
+
PointerDevice[PointerDevice["Eraser"] = 1] = "Eraser";
|
9
|
+
PointerDevice[PointerDevice["Touch"] = 2] = "Touch";
|
10
|
+
PointerDevice[PointerDevice["PrimaryButtonMouse"] = 3] = "PrimaryButtonMouse";
|
11
|
+
PointerDevice[PointerDevice["RightButtonMouse"] = 4] = "RightButtonMouse";
|
12
|
+
PointerDevice[PointerDevice["Other"] = 5] = "Other";
|
13
|
+
})(PointerDevice = exports.PointerDevice || (exports.PointerDevice = {}));
|
14
|
+
// Provides a snapshot containing information about a pointer. A Pointer
|
15
|
+
// object is immutable — it will not be updated when the pointer's information changes.
|
16
|
+
class Pointer {
|
17
|
+
constructor(
|
18
|
+
// The (x, y) position of the pointer relative to the top-left corner
|
19
|
+
// of the visible canvas.
|
20
|
+
screenPos,
|
21
|
+
// Position of the pointer relative to the top left corner of the drawing
|
22
|
+
// surface.
|
23
|
+
canvasPos, pressure, isPrimary, down, device,
|
24
|
+
// Unique ID for the pointer
|
25
|
+
id,
|
26
|
+
// Numeric timestamp (milliseconds, as from `(new Date).getTime()`)
|
27
|
+
timeStamp) {
|
28
|
+
this.screenPos = screenPos;
|
29
|
+
this.canvasPos = canvasPos;
|
30
|
+
this.pressure = pressure;
|
31
|
+
this.isPrimary = isPrimary;
|
32
|
+
this.down = down;
|
33
|
+
this.device = device;
|
34
|
+
this.id = id;
|
35
|
+
this.timeStamp = timeStamp;
|
36
|
+
}
|
37
|
+
// Snaps this pointer to the nearest grid point (rounds the coordinates of this
|
38
|
+
// pointer based on the current zoom). Returns a new Pointer and does not modify
|
39
|
+
// this.
|
40
|
+
snappedToGrid(viewport) {
|
41
|
+
const snappedCanvasPos = viewport.snapToGrid(this.canvasPos);
|
42
|
+
const snappedScreenPos = viewport.canvasToScreen(snappedCanvasPos);
|
43
|
+
return new Pointer(snappedScreenPos, snappedCanvasPos, this.pressure, this.isPrimary, this.down, this.device, this.id, this.timeStamp);
|
44
|
+
}
|
45
|
+
// Creates a Pointer from a DOM event. If `relativeTo` is given, (0, 0) in screen coordinates is
|
46
|
+
// considered the top left of `relativeTo`.
|
47
|
+
static ofEvent(evt, isDown, viewport, relativeTo) {
|
48
|
+
var _a, _b;
|
49
|
+
let screenPos = Vec2_1.Vec2.of(evt.clientX, evt.clientY);
|
50
|
+
if (relativeTo) {
|
51
|
+
const bbox = relativeTo.getBoundingClientRect();
|
52
|
+
screenPos = screenPos.minus(Vec2_1.Vec2.of(bbox.left, bbox.top));
|
53
|
+
}
|
54
|
+
const pointerTypeToDevice = {
|
55
|
+
'mouse': PointerDevice.PrimaryButtonMouse,
|
56
|
+
'pen': PointerDevice.Pen,
|
57
|
+
'touch': PointerDevice.Touch,
|
58
|
+
};
|
59
|
+
let device = (_a = pointerTypeToDevice[evt.pointerType]) !== null && _a !== void 0 ? _a : PointerDevice.Other;
|
60
|
+
const eraserButtonMask = 0x20;
|
61
|
+
if (device === PointerDevice.Pen && (evt.buttons & eraserButtonMask) !== 0) {
|
62
|
+
device = PointerDevice.Eraser;
|
63
|
+
}
|
64
|
+
const timeStamp = (new Date()).getTime();
|
65
|
+
const canvasPos = viewport.roundPoint(viewport.screenToCanvas(screenPos));
|
66
|
+
if (device === PointerDevice.PrimaryButtonMouse) {
|
67
|
+
if (evt.buttons & 0x2) {
|
68
|
+
device = PointerDevice.RightButtonMouse;
|
69
|
+
}
|
70
|
+
else if (!(evt.buttons & 0x1)) {
|
71
|
+
device = PointerDevice.Other;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return new Pointer(screenPos, canvasPos, (_b = evt.pressure) !== null && _b !== void 0 ? _b : null, evt.isPrimary, isDown, device, evt.pointerId, timeStamp);
|
75
|
+
}
|
76
|
+
// Create a new Pointer from a point on the canvas.
|
77
|
+
// Intended for unit tests.
|
78
|
+
static ofCanvasPoint(canvasPos, isDown, viewport, id = 0, device = PointerDevice.Pen, isPrimary = true, pressure = null) {
|
79
|
+
const screenPos = viewport.canvasToScreen(canvasPos);
|
80
|
+
const timeStamp = (new Date()).getTime();
|
81
|
+
return new Pointer(screenPos, canvasPos, pressure, isPrimary, isDown, device, id, timeStamp);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
exports.default = Pointer;
|
@@ -36,6 +36,10 @@ export default class SVGLoader implements ImageLoader {
|
|
36
36
|
private getSourceAttrs;
|
37
37
|
start(onAddComponent: ComponentAddedListener, onProgress: OnProgressListener, onDetermineExportRect?: OnDetermineExportRectListener | null): Promise<void>;
|
38
38
|
/**
|
39
|
+
* Create an `SVGLoader` from the content of an SVG image. SVGs are loaded within a sandboxed
|
40
|
+
* iframe with `sandbox="allow-same-origin"`
|
41
|
+
* [thereby disabling JavaScript](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox).
|
42
|
+
*
|
39
43
|
* @see {@link Editor.loadFrom}
|
40
44
|
* @param text - Textual representation of the SVG (e.g. `<svg viewbox='...'>...</svg>`).
|
41
45
|
* @param sanitize - if `true`, don't store unknown attributes.
|