js-draw 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -0
- package/dist/cjs/src/Color4.d.ts +69 -0
- package/dist/cjs/src/Color4.js +264 -0
- package/dist/cjs/src/Editor.d.ts +308 -0
- package/dist/cjs/src/Editor.js +904 -0
- package/dist/cjs/src/EditorImage.d.ts +97 -0
- package/dist/cjs/src/EditorImage.js +486 -0
- package/dist/cjs/src/EventDispatcher.d.ts +30 -0
- package/dist/cjs/src/EventDispatcher.js +57 -0
- package/dist/cjs/src/Pointer.d.ts +24 -0
- package/dist/cjs/src/Pointer.js +84 -0
- package/dist/cjs/src/SVGLoader.d.ts +48 -0
- package/dist/cjs/src/SVGLoader.js +475 -0
- package/dist/cjs/src/UndoRedoHistory.d.ts +19 -0
- package/dist/cjs/src/UndoRedoHistory.js +93 -0
- package/dist/cjs/src/Viewport.d.ts +71 -0
- package/dist/cjs/src/Viewport.js +264 -0
- package/dist/cjs/src/bundle/bundled.d.ts +4 -0
- package/dist/cjs/src/bundle/bundled.js +24 -0
- package/dist/cjs/src/commands/Command.d.ts +16 -0
- package/dist/cjs/src/commands/Command.js +34 -0
- package/dist/cjs/src/commands/Duplicate.d.ts +14 -0
- package/dist/cjs/src/commands/Duplicate.js +39 -0
- package/dist/cjs/src/commands/Erase.d.ts +14 -0
- package/dist/cjs/src/commands/Erase.js +63 -0
- package/dist/cjs/src/commands/SerializableCommand.d.ts +12 -0
- package/dist/cjs/src/commands/SerializableCommand.js +42 -0
- package/dist/cjs/src/commands/UnresolvedCommand.d.ts +14 -0
- package/dist/cjs/src/commands/UnresolvedCommand.js +28 -0
- package/dist/cjs/src/commands/invertCommand.d.ts +4 -0
- package/dist/cjs/src/commands/invertCommand.js +49 -0
- package/dist/cjs/src/commands/lib.d.ts +7 -0
- package/dist/cjs/src/commands/lib.js +18 -0
- package/dist/cjs/src/commands/localization.d.ts +23 -0
- package/dist/cjs/src/commands/localization.js +24 -0
- package/dist/cjs/src/commands/uniteCommands.d.ts +4 -0
- package/dist/cjs/src/commands/uniteCommands.js +121 -0
- package/dist/cjs/src/components/AbstractComponent.d.ts +73 -0
- package/dist/cjs/src/components/AbstractComponent.js +258 -0
- package/dist/cjs/src/components/ImageBackground.d.ts +42 -0
- package/dist/cjs/src/components/ImageBackground.js +146 -0
- package/dist/cjs/src/components/ImageComponent.d.ts +31 -0
- package/dist/cjs/src/components/ImageComponent.js +152 -0
- package/dist/cjs/src/components/RestylableComponent.d.ts +43 -0
- package/dist/cjs/src/components/RestylableComponent.js +88 -0
- package/dist/cjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/cjs/src/components/SVGGlobalAttributesObject.js +65 -0
- package/dist/cjs/src/components/Stroke.d.ts +75 -0
- package/dist/cjs/src/components/Stroke.js +225 -0
- package/dist/cjs/src/components/TextComponent.d.ts +75 -0
- package/dist/cjs/src/components/TextComponent.js +280 -0
- package/dist/cjs/src/components/UnknownSVGObject.d.ts +18 -0
- package/dist/cjs/src/components/UnknownSVGObject.js +50 -0
- package/dist/cjs/src/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/cjs/src/components/builders/ArrowBuilder.js +117 -0
- package/dist/cjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/cjs/src/components/builders/FreehandLineBuilder.js +173 -0
- package/dist/cjs/src/components/builders/LineBuilder.d.ts +18 -0
- package/dist/cjs/src/components/builders/LineBuilder.js +89 -0
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.js +347 -0
- package/dist/cjs/src/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/cjs/src/components/builders/RectangleBuilder.js +59 -0
- package/dist/cjs/src/components/builders/types.d.ts +12 -0
- package/dist/cjs/src/components/builders/types.js +2 -0
- package/dist/cjs/src/components/lib.d.ts +13 -0
- package/dist/cjs/src/components/lib.js +43 -0
- package/dist/cjs/src/components/localization.d.ts +11 -0
- package/dist/cjs/src/components/localization.js +13 -0
- package/dist/cjs/src/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/cjs/src/components/util/StrokeSmoother.js +217 -0
- package/dist/cjs/src/components/util/describeComponentList.d.ts +4 -0
- package/dist/cjs/src/components/util/describeComponentList.js +16 -0
- package/dist/cjs/src/lib.d.ts +64 -0
- package/dist/cjs/src/lib.js +93 -0
- package/dist/cjs/src/localization.d.ts +14 -0
- package/dist/cjs/src/localization.js +13 -0
- package/dist/cjs/src/localizations/de.d.ts +3 -0
- package/dist/cjs/src/localizations/de.js +6 -0
- package/dist/cjs/src/localizations/en.d.ts +3 -0
- package/dist/cjs/src/localizations/en.js +6 -0
- package/dist/cjs/src/localizations/es.d.ts +3 -0
- package/dist/cjs/src/localizations/es.js +20 -0
- package/dist/cjs/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/cjs/src/localizations/getLocalizationTable.js +50 -0
- package/dist/cjs/src/math/LineSegment2.d.ts +24 -0
- package/dist/cjs/src/math/LineSegment2.js +131 -0
- package/dist/cjs/src/math/Mat33.d.ts +118 -0
- package/dist/cjs/src/math/Mat33.js +332 -0
- package/dist/cjs/src/math/Path.d.ts +71 -0
- package/dist/cjs/src/math/Path.js +655 -0
- package/dist/cjs/src/math/Rect2.d.ts +52 -0
- package/dist/cjs/src/math/Rect2.js +234 -0
- package/dist/cjs/src/math/Triangle.d.ts +11 -0
- package/dist/cjs/src/math/Triangle.js +22 -0
- package/dist/cjs/src/math/Vec2.d.ts +13 -0
- package/dist/cjs/src/math/Vec2.js +19 -0
- package/dist/cjs/src/math/Vec3.d.ts +106 -0
- package/dist/cjs/src/math/Vec3.js +177 -0
- package/dist/cjs/src/math/lib.d.ts +7 -0
- package/dist/cjs/src/math/lib.js +18 -0
- package/dist/cjs/src/math/rounding.d.ts +4 -0
- package/dist/cjs/src/math/rounding.js +135 -0
- package/dist/cjs/src/rendering/Display.d.ts +75 -0
- package/dist/cjs/src/rendering/Display.js +214 -0
- package/dist/cjs/src/rendering/RenderingStyle.d.ts +31 -0
- package/dist/cjs/src/rendering/RenderingStyle.js +48 -0
- package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +36 -0
- package/dist/cjs/src/rendering/TextRenderingStyle.js +29 -0
- package/dist/cjs/src/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/cjs/src/rendering/caching/CacheRecord.js +61 -0
- package/dist/cjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/cjs/src/rendering/caching/CacheRecordManager.js +50 -0
- package/dist/cjs/src/rendering/caching/RenderingCache.d.ts +11 -0
- package/dist/cjs/src/rendering/caching/RenderingCache.js +51 -0
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.js +326 -0
- package/dist/cjs/src/rendering/caching/testUtils.d.ts +9 -0
- package/dist/cjs/src/rendering/caching/testUtils.js +27 -0
- package/dist/cjs/src/rendering/caching/types.d.ts +19 -0
- package/dist/cjs/src/rendering/caching/types.js +2 -0
- package/dist/cjs/src/rendering/lib.d.ts +7 -0
- package/dist/cjs/src/rendering/lib.js +17 -0
- package/dist/cjs/src/rendering/localization.d.ts +10 -0
- package/dist/cjs/src/rendering/localization.js +12 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +68 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.js +170 -0
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +236 -0
- package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/cjs/src/rendering/renderers/DummyRenderer.js +112 -0
- package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/cjs/src/rendering/renderers/SVGRenderer.js +311 -0
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.js +63 -0
- package/dist/cjs/src/testing/beforeEachFile.d.ts +1 -0
- package/dist/cjs/src/testing/beforeEachFile.js +12 -0
- package/dist/cjs/src/testing/createEditor.d.ts +4 -0
- package/dist/cjs/src/testing/createEditor.js +14 -0
- package/dist/cjs/src/testing/lib.d.ts +2 -0
- package/dist/cjs/src/testing/lib.js +10 -0
- package/dist/cjs/src/testing/loadExpectExtensions.d.ts +2 -0
- package/dist/cjs/src/testing/loadExpectExtensions.js +28 -0
- package/dist/cjs/src/testing/sendPenEvent.d.ts +12 -0
- package/dist/cjs/src/testing/sendPenEvent.js +24 -0
- package/dist/cjs/src/testing/sendTouchEvent.d.ts +42 -0
- package/dist/cjs/src/testing/sendTouchEvent.js +87 -0
- package/dist/cjs/src/toolbar/HTMLToolbar.d.ts +103 -0
- package/dist/cjs/src/toolbar/HTMLToolbar.js +383 -0
- package/dist/cjs/src/toolbar/IconProvider.d.ts +62 -0
- package/dist/cjs/src/toolbar/IconProvider.js +660 -0
- package/dist/cjs/src/toolbar/lib.d.ts +3 -0
- package/dist/cjs/src/toolbar/lib.js +24 -0
- package/dist/cjs/src/toolbar/localization.d.ts +49 -0
- package/dist/cjs/src/toolbar/localization.js +51 -0
- package/dist/cjs/src/toolbar/makeColorInput.d.ts +6 -0
- package/dist/cjs/src/toolbar/makeColorInput.js +120 -0
- package/dist/cjs/src/toolbar/types.d.ts +4 -0
- package/dist/cjs/src/toolbar/types.js +2 -0
- package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.d.ts +15 -0
- package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.js +31 -0
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.js +50 -0
- package/dist/cjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +313 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +126 -0
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.js +63 -0
- package/dist/cjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
- package/dist/cjs/src/toolbar/widgets/HandToolWidget.js +201 -0
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.js +176 -0
- package/dist/cjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
- package/dist/cjs/src/toolbar/widgets/OverflowWidget.js +77 -0
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +226 -0
- package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
- package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.js +153 -0
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.js +115 -0
- package/dist/cjs/src/toolbar/widgets/lib.d.ts +10 -0
- package/dist/cjs/src/toolbar/widgets/lib.js +26 -0
- package/dist/cjs/src/tools/BaseTool.d.ts +22 -0
- package/dist/cjs/src/tools/BaseTool.js +66 -0
- package/dist/cjs/src/tools/Eraser.d.ts +23 -0
- package/dist/cjs/src/tools/Eraser.js +112 -0
- package/dist/cjs/src/tools/FindTool.d.ts +21 -0
- package/dist/cjs/src/tools/FindTool.js +121 -0
- package/dist/cjs/src/tools/PanZoom.d.ts +52 -0
- package/dist/cjs/src/tools/PanZoom.js +421 -0
- package/dist/cjs/src/tools/PasteHandler.d.ts +23 -0
- package/dist/cjs/src/tools/PasteHandler.js +99 -0
- package/dist/cjs/src/tools/Pen.d.ts +39 -0
- package/dist/cjs/src/tools/Pen.js +179 -0
- package/dist/cjs/src/tools/PipetteTool.d.ts +18 -0
- package/dist/cjs/src/tools/PipetteTool.js +45 -0
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.js +28 -0
- package/dist/cjs/src/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/cjs/src/tools/SelectionTool/Selection.js +488 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionHandle.js +85 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.js +405 -0
- package/dist/cjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
- package/dist/cjs/src/tools/SelectionTool/TransformMode.js +107 -0
- package/dist/cjs/src/tools/SelectionTool/types.d.ts +9 -0
- package/dist/cjs/src/tools/SelectionTool/types.js +14 -0
- package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/cjs/src/tools/SoundUITool.js +164 -0
- package/dist/cjs/src/tools/TextTool.d.ts +33 -0
- package/dist/cjs/src/tools/TextTool.js +262 -0
- package/dist/cjs/src/tools/ToolController.d.ts +18 -0
- package/dist/cjs/src/tools/ToolController.js +192 -0
- package/dist/cjs/src/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/cjs/src/tools/ToolEnabledGroup.js +14 -0
- package/dist/cjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/cjs/src/tools/ToolSwitcherShortcut.js +38 -0
- package/dist/cjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/cjs/src/tools/ToolbarShortcutHandler.js +29 -0
- package/dist/cjs/src/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/cjs/src/tools/UndoRedoShortcut.js +28 -0
- package/dist/cjs/src/tools/lib.d.ts +17 -0
- package/dist/cjs/src/tools/lib.js +38 -0
- package/dist/cjs/src/tools/localization.d.ts +31 -0
- package/dist/cjs/src/tools/localization.js +33 -0
- package/dist/cjs/src/types.d.ts +151 -0
- package/dist/cjs/src/types.js +38 -0
- package/dist/cjs/src/util/assertions.d.ts +23 -0
- package/dist/cjs/src/util/assertions.js +51 -0
- package/dist/cjs/src/util/fileToBase64.d.ts +3 -0
- package/dist/cjs/src/util/fileToBase64.js +15 -0
- package/dist/cjs/src/util/untilNextAnimationFrame.d.ts +3 -0
- package/dist/cjs/src/util/untilNextAnimationFrame.js +9 -0
- package/dist/cjs/src/util/waitForTimeout.d.ts +2 -0
- package/dist/cjs/src/util/waitForTimeout.js +9 -0
- package/dist/mjs/src/Color4.d.ts +69 -0
- package/dist/mjs/src/Color4.mjs +257 -0
- package/dist/mjs/src/Editor.d.ts +308 -0
- package/dist/mjs/src/Editor.mjs +874 -0
- package/dist/mjs/src/EditorImage.d.ts +97 -0
- package/dist/mjs/src/EditorImage.mjs +477 -0
- package/dist/mjs/src/EventDispatcher.d.ts +30 -0
- package/dist/mjs/src/EventDispatcher.mjs +54 -0
- package/dist/mjs/src/Pointer.d.ts +24 -0
- package/dist/mjs/src/Pointer.mjs +80 -0
- package/dist/mjs/src/SVGLoader.d.ts +48 -0
- package/dist/mjs/src/SVGLoader.mjs +445 -0
- package/dist/mjs/src/UndoRedoHistory.d.ts +19 -0
- package/dist/mjs/src/UndoRedoHistory.mjs +91 -0
- package/dist/mjs/src/Viewport.d.ts +71 -0
- package/dist/mjs/src/Viewport.mjs +256 -0
- package/dist/mjs/src/bundle/bundled.d.ts +4 -0
- package/dist/mjs/src/bundle/bundled.mjs +5 -0
- package/dist/mjs/src/commands/Command.d.ts +16 -0
- package/dist/mjs/src/commands/Command.mjs +30 -0
- package/dist/mjs/src/commands/Duplicate.d.ts +14 -0
- package/dist/mjs/src/commands/Duplicate.mjs +33 -0
- package/dist/mjs/src/commands/Erase.d.ts +14 -0
- package/dist/mjs/src/commands/Erase.mjs +57 -0
- package/dist/mjs/src/commands/SerializableCommand.d.ts +12 -0
- package/dist/mjs/src/commands/SerializableCommand.mjs +36 -0
- package/dist/mjs/src/commands/UnresolvedCommand.d.ts +14 -0
- package/dist/mjs/src/commands/UnresolvedCommand.mjs +22 -0
- package/dist/mjs/src/commands/invertCommand.d.ts +4 -0
- package/dist/mjs/src/commands/invertCommand.mjs +44 -0
- package/dist/mjs/src/commands/lib.d.ts +7 -0
- package/dist/mjs/src/commands/lib.mjs +7 -0
- package/dist/mjs/src/commands/localization.d.ts +23 -0
- package/dist/mjs/src/commands/localization.mjs +21 -0
- package/dist/mjs/src/commands/uniteCommands.d.ts +4 -0
- package/dist/mjs/src/commands/uniteCommands.mjs +116 -0
- package/dist/mjs/src/components/AbstractComponent.d.ts +73 -0
- package/dist/mjs/src/components/AbstractComponent.mjs +252 -0
- package/dist/mjs/src/components/ImageBackground.d.ts +42 -0
- package/dist/mjs/src/components/ImageBackground.mjs +139 -0
- package/dist/mjs/src/components/ImageComponent.d.ts +31 -0
- package/dist/mjs/src/components/ImageComponent.mjs +146 -0
- package/dist/mjs/src/components/RestylableComponent.d.ts +43 -0
- package/dist/mjs/src/components/RestylableComponent.mjs +80 -0
- package/dist/mjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/mjs/src/components/SVGGlobalAttributesObject.mjs +59 -0
- package/dist/mjs/src/components/Stroke.d.ts +75 -0
- package/dist/mjs/src/components/Stroke.mjs +219 -0
- package/dist/mjs/src/components/TextComponent.d.ts +75 -0
- package/dist/mjs/src/components/TextComponent.mjs +274 -0
- package/dist/mjs/src/components/UnknownSVGObject.d.ts +18 -0
- package/dist/mjs/src/components/UnknownSVGObject.mjs +44 -0
- package/dist/mjs/src/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/mjs/src/components/builders/ArrowBuilder.mjs +86 -0
- package/dist/mjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/mjs/src/components/builders/FreehandLineBuilder.mjs +165 -0
- package/dist/mjs/src/components/builders/LineBuilder.d.ts +18 -0
- package/dist/mjs/src/components/builders/LineBuilder.mjs +58 -0
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.mjs +339 -0
- package/dist/mjs/src/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/mjs/src/components/builders/RectangleBuilder.mjs +50 -0
- package/dist/mjs/src/components/builders/types.d.ts +12 -0
- package/dist/mjs/src/components/builders/types.mjs +1 -0
- package/dist/mjs/src/components/lib.d.ts +13 -0
- package/dist/mjs/src/components/lib.mjs +12 -0
- package/dist/mjs/src/components/localization.d.ts +11 -0
- package/dist/mjs/src/components/localization.mjs +10 -0
- package/dist/mjs/src/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/mjs/src/components/util/StrokeSmoother.mjs +210 -0
- package/dist/mjs/src/components/util/describeComponentList.d.ts +4 -0
- package/dist/mjs/src/components/util/describeComponentList.mjs +14 -0
- package/dist/mjs/src/lib.d.ts +64 -0
- package/dist/mjs/src/lib.mjs +64 -0
- package/dist/mjs/src/localization.d.ts +14 -0
- package/dist/mjs/src/localization.mjs +10 -0
- package/dist/mjs/src/localizations/de.d.ts +3 -0
- package/dist/mjs/src/localizations/de.mjs +4 -0
- package/dist/mjs/src/localizations/en.d.ts +3 -0
- package/dist/mjs/src/localizations/en.mjs +4 -0
- package/dist/mjs/src/localizations/es.d.ts +3 -0
- package/dist/mjs/src/localizations/es.mjs +18 -0
- package/dist/mjs/src/localizations/getLocalizationTable.d.ts +3 -0
- package/dist/mjs/src/localizations/getLocalizationTable.mjs +45 -0
- package/dist/mjs/src/math/LineSegment2.d.ts +24 -0
- package/dist/mjs/src/math/LineSegment2.mjs +125 -0
- package/dist/mjs/src/math/Mat33.d.ts +118 -0
- package/dist/mjs/src/math/Mat33.mjs +326 -0
- package/dist/mjs/src/math/Path.d.ts +71 -0
- package/dist/mjs/src/math/Path.mjs +648 -0
- package/dist/mjs/src/math/Rect2.d.ts +52 -0
- package/dist/mjs/src/math/Rect2.mjs +228 -0
- package/dist/mjs/src/math/Triangle.d.ts +11 -0
- package/dist/mjs/src/math/Triangle.mjs +19 -0
- package/dist/mjs/src/math/Vec2.d.ts +13 -0
- package/dist/mjs/src/math/Vec2.mjs +13 -0
- package/dist/mjs/src/math/Vec3.d.ts +106 -0
- package/dist/mjs/src/math/Vec3.mjs +174 -0
- package/dist/mjs/src/math/lib.d.ts +7 -0
- package/dist/mjs/src/math/lib.mjs +7 -0
- package/dist/mjs/src/math/rounding.d.ts +4 -0
- package/dist/mjs/src/math/rounding.mjs +128 -0
- package/dist/mjs/src/rendering/Display.d.ts +75 -0
- package/dist/mjs/src/rendering/Display.mjs +207 -0
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +31 -0
- package/dist/mjs/src/rendering/RenderingStyle.mjs +38 -0
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +36 -0
- package/dist/mjs/src/rendering/TextRenderingStyle.mjs +23 -0
- package/dist/mjs/src/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/mjs/src/rendering/caching/CacheRecord.mjs +55 -0
- package/dist/mjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/mjs/src/rendering/caching/CacheRecordManager.mjs +43 -0
- package/dist/mjs/src/rendering/caching/RenderingCache.d.ts +11 -0
- package/dist/mjs/src/rendering/caching/RenderingCache.mjs +45 -0
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.mjs +320 -0
- package/dist/mjs/src/rendering/caching/testUtils.d.ts +9 -0
- package/dist/mjs/src/rendering/caching/testUtils.mjs +20 -0
- package/dist/mjs/src/rendering/caching/types.d.ts +19 -0
- package/dist/mjs/src/rendering/caching/types.mjs +1 -0
- package/dist/mjs/src/rendering/lib.d.ts +7 -0
- package/dist/mjs/src/rendering/lib.mjs +5 -0
- package/dist/mjs/src/rendering/localization.d.ts +10 -0
- package/dist/mjs/src/rendering/localization.mjs +9 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +68 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.mjs +144 -0
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.mjs +230 -0
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/mjs/src/rendering/renderers/DummyRenderer.mjs +106 -0
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/mjs/src/rendering/renderers/SVGRenderer.mjs +304 -0
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.mjs +57 -0
- package/dist/mjs/src/testing/beforeEachFile.d.ts +1 -0
- package/dist/mjs/src/testing/beforeEachFile.mjs +7 -0
- package/dist/mjs/src/testing/createEditor.d.ts +4 -0
- package/dist/mjs/src/testing/createEditor.mjs +9 -0
- package/dist/mjs/src/testing/lib.d.ts +2 -0
- package/dist/mjs/src/testing/lib.mjs +2 -0
- package/dist/mjs/src/testing/loadExpectExtensions.d.ts +2 -0
- package/dist/mjs/src/testing/loadExpectExtensions.mjs +24 -0
- package/dist/mjs/src/testing/sendPenEvent.d.ts +12 -0
- package/dist/mjs/src/testing/sendPenEvent.mjs +19 -0
- package/dist/mjs/src/testing/sendTouchEvent.d.ts +42 -0
- package/dist/mjs/src/testing/sendTouchEvent.mjs +62 -0
- package/dist/mjs/src/toolbar/HTMLToolbar.d.ts +103 -0
- package/dist/mjs/src/toolbar/HTMLToolbar.mjs +376 -0
- package/dist/mjs/src/toolbar/IconProvider.d.ts +62 -0
- package/dist/mjs/src/toolbar/IconProvider.mjs +654 -0
- package/dist/mjs/src/toolbar/lib.d.ts +3 -0
- package/dist/mjs/src/toolbar/lib.mjs +3 -0
- package/dist/mjs/src/toolbar/localization.d.ts +49 -0
- package/dist/mjs/src/toolbar/localization.mjs +48 -0
- package/dist/mjs/src/toolbar/makeColorInput.d.ts +6 -0
- package/dist/mjs/src/toolbar/makeColorInput.mjs +113 -0
- package/dist/mjs/src/toolbar/types.d.ts +4 -0
- package/dist/mjs/src/toolbar/types.mjs +1 -0
- package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.d.ts +15 -0
- package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.mjs +25 -0
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.mjs +44 -0
- package/dist/mjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +307 -0
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +120 -0
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.mjs +57 -0
- package/dist/mjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
- package/dist/mjs/src/toolbar/widgets/HandToolWidget.mjs +172 -0
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.mjs +170 -0
- package/dist/mjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
- package/dist/mjs/src/toolbar/widgets/OverflowWidget.mjs +71 -0
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +220 -0
- package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
- package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.mjs +147 -0
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.mjs +109 -0
- package/dist/mjs/src/toolbar/widgets/lib.d.ts +10 -0
- package/dist/mjs/src/toolbar/widgets/lib.mjs +10 -0
- package/dist/mjs/src/tools/BaseTool.d.ts +22 -0
- package/dist/mjs/src/tools/BaseTool.mjs +63 -0
- package/dist/mjs/src/tools/Eraser.d.ts +23 -0
- package/dist/mjs/src/tools/Eraser.mjs +106 -0
- package/dist/mjs/src/tools/FindTool.d.ts +21 -0
- package/dist/mjs/src/tools/FindTool.mjs +114 -0
- package/dist/mjs/src/tools/PanZoom.d.ts +52 -0
- package/dist/mjs/src/tools/PanZoom.mjs +414 -0
- package/dist/mjs/src/tools/PasteHandler.d.ts +23 -0
- package/dist/mjs/src/tools/PasteHandler.mjs +93 -0
- package/dist/mjs/src/tools/Pen.d.ts +39 -0
- package/dist/mjs/src/tools/Pen.mjs +173 -0
- package/dist/mjs/src/tools/PipetteTool.d.ts +18 -0
- package/dist/mjs/src/tools/PipetteTool.mjs +39 -0
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.mjs +22 -0
- package/dist/mjs/src/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/mjs/src/tools/SelectionTool/Selection.mjs +459 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionHandle.mjs +81 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.mjs +398 -0
- package/dist/mjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
- package/dist/mjs/src/tools/SelectionTool/TransformMode.mjs +98 -0
- package/dist/mjs/src/tools/SelectionTool/types.d.ts +9 -0
- package/dist/mjs/src/tools/SelectionTool/types.mjs +11 -0
- package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
- package/dist/mjs/src/tools/TextTool.d.ts +33 -0
- package/dist/mjs/src/tools/TextTool.mjs +256 -0
- package/dist/mjs/src/tools/ToolController.d.ts +18 -0
- package/dist/mjs/src/tools/ToolController.mjs +163 -0
- package/dist/mjs/src/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/mjs/src/tools/ToolEnabledGroup.mjs +11 -0
- package/dist/mjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/mjs/src/tools/ToolSwitcherShortcut.mjs +32 -0
- package/dist/mjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/mjs/src/tools/ToolbarShortcutHandler.mjs +23 -0
- package/dist/mjs/src/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/mjs/src/tools/UndoRedoShortcut.mjs +22 -0
- package/dist/mjs/src/tools/lib.d.ts +17 -0
- package/dist/mjs/src/tools/lib.mjs +17 -0
- package/dist/mjs/src/tools/localization.d.ts +31 -0
- package/dist/mjs/src/tools/localization.mjs +30 -0
- package/dist/mjs/src/types.d.ts +151 -0
- package/dist/mjs/src/types.mjs +35 -0
- package/dist/mjs/src/util/assertions.d.ts +23 -0
- package/dist/mjs/src/util/assertions.mjs +45 -0
- package/dist/mjs/src/util/fileToBase64.d.ts +3 -0
- package/dist/mjs/src/util/fileToBase64.mjs +13 -0
- package/dist/mjs/src/util/untilNextAnimationFrame.d.ts +3 -0
- package/dist/mjs/src/util/untilNextAnimationFrame.mjs +7 -0
- package/dist/mjs/src/util/waitForTimeout.d.ts +2 -0
- package/dist/mjs/src/util/waitForTimeout.mjs +7 -0
- package/package.json +6 -4
- package/src/Editor.css +86 -0
- package/src/styles.js +7 -0
- package/src/toolbar/toolbar.css +213 -0
- package/src/toolbar/widgets/InsertImageWidget.css +44 -0
- package/src/toolbar/widgets/OverflowWidget.css +27 -0
- package/src/tools/FindTool.css +7 -0
- package/src/tools/SelectionTool/SelectionTool.css +23 -0
- package/src/tools/SoundUITool.css +15 -0
- package/src/tools/tools.css +4 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
import Editor from '../Editor';
|
2
|
+
import { ToolbarLocalization } from './localization';
|
3
|
+
import { ActionButtonIcon } from './types';
|
4
|
+
import BaseWidget from './widgets/BaseWidget';
|
5
|
+
export declare const toolbarCSSPrefix = "toolbar-";
|
6
|
+
interface SpacerOptions {
|
7
|
+
grow: number;
|
8
|
+
minSize: string;
|
9
|
+
maxSize: string;
|
10
|
+
}
|
11
|
+
export default class HTMLToolbar {
|
12
|
+
private editor;
|
13
|
+
private localizationTable;
|
14
|
+
private container;
|
15
|
+
private resizeObserver;
|
16
|
+
private listeners;
|
17
|
+
private widgetOrderCounter;
|
18
|
+
private widgetsById;
|
19
|
+
private widgetList;
|
20
|
+
private overflowWidget;
|
21
|
+
private static colorisStarted;
|
22
|
+
private updateColoris;
|
23
|
+
/** @internal */
|
24
|
+
constructor(editor: Editor, parent: HTMLElement, localizationTable?: ToolbarLocalization);
|
25
|
+
setupColorPickers(): void;
|
26
|
+
private reLayoutQueued;
|
27
|
+
private queueReLayout;
|
28
|
+
private reLayout;
|
29
|
+
/**
|
30
|
+
* Adds an `ActionButtonWidget` or `BaseToolWidget`. The widget should not have already have a parent
|
31
|
+
* (i.e. its `addTo` method should not have been called).
|
32
|
+
*
|
33
|
+
* @example
|
34
|
+
* ```ts
|
35
|
+
* const toolbar = editor.addToolbar();
|
36
|
+
* const insertImageWidget = new InsertImageWidget(editor);
|
37
|
+
* toolbar.addWidget(insertImageWidget);
|
38
|
+
* ```
|
39
|
+
*/
|
40
|
+
addWidget(widget: BaseWidget): void;
|
41
|
+
/**
|
42
|
+
* Adds a spacer.
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
* Adding a save button that moves to the very right edge of the toolbar
|
46
|
+
* while keeping the other buttons centered:
|
47
|
+
* ```ts
|
48
|
+
* const toolbar = editor.addToolbar(false);
|
49
|
+
*
|
50
|
+
* toolbar.addSpacer({ grow: 1 });
|
51
|
+
* toolbar.addDefaults();
|
52
|
+
* toolbar.addSpacer({ grow: 1 });
|
53
|
+
*
|
54
|
+
* toolbar.addActionButton({
|
55
|
+
* label: 'Save',
|
56
|
+
* icon: editor.icons.makeSaveIcon(),
|
57
|
+
* }, () => {
|
58
|
+
* saveCallback();
|
59
|
+
* });
|
60
|
+
* ```
|
61
|
+
*/
|
62
|
+
addSpacer(options?: Partial<SpacerOptions>): void;
|
63
|
+
serializeState(): string;
|
64
|
+
/**
|
65
|
+
* Deserialize toolbar widgets from the given state.
|
66
|
+
* Assumes that toolbar widgets are in the same order as when state was serialized.
|
67
|
+
*/
|
68
|
+
deserializeState(state: string): void;
|
69
|
+
/**
|
70
|
+
* Adds an action button with `title` to this toolbar (or to the given `parent` element).
|
71
|
+
*
|
72
|
+
* @return The added button.
|
73
|
+
*/
|
74
|
+
addActionButton(title: string | ActionButtonIcon, command: () => void, mustBeToplevel?: boolean): BaseWidget;
|
75
|
+
addUndoRedoButtons(): void;
|
76
|
+
addDefaultToolWidgets(): void;
|
77
|
+
addDefaultActionButtons(): void;
|
78
|
+
/**
|
79
|
+
* Adds a widget that toggles the overflow menu. Call `addOverflowWidget` to ensure
|
80
|
+
* that this widget is in the correct space (if shown).
|
81
|
+
*
|
82
|
+
* @example
|
83
|
+
* ```ts
|
84
|
+
* toolbar.addDefaultToolWidgets();
|
85
|
+
* toolbar.addOverflowWidget();
|
86
|
+
* toolbar.addDefaultActionButtons();
|
87
|
+
* ```
|
88
|
+
* shows the overflow widget between the default tool widgets and the default action buttons,
|
89
|
+
* if shown.
|
90
|
+
*/
|
91
|
+
addOverflowWidget(): void;
|
92
|
+
/**
|
93
|
+
* Adds both the default tool widgets and action buttons. Equivalent to
|
94
|
+
* ```ts
|
95
|
+
* toolbar.addDefaultToolWidgets();
|
96
|
+
* toolbar.addOverflowWidget();
|
97
|
+
* toolbar.addDefaultActionButtons();
|
98
|
+
* ```
|
99
|
+
*/
|
100
|
+
addDefaults(): void;
|
101
|
+
remove(): void;
|
102
|
+
}
|
103
|
+
export {};
|
@@ -0,0 +1,383 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.toolbarCSSPrefix = void 0;
|
7
|
+
const types_1 = require("../types");
|
8
|
+
const coloris_1 = require("@melloware/coloris");
|
9
|
+
const Color4_1 = __importDefault(require("../Color4"));
|
10
|
+
const localization_1 = require("./localization");
|
11
|
+
const SelectionTool_1 = __importDefault(require("../tools/SelectionTool/SelectionTool"));
|
12
|
+
const PanZoom_1 = __importDefault(require("../tools/PanZoom"));
|
13
|
+
const TextTool_1 = __importDefault(require("../tools/TextTool"));
|
14
|
+
const Eraser_1 = __importDefault(require("../tools/Eraser"));
|
15
|
+
const Pen_1 = __importDefault(require("../tools/Pen"));
|
16
|
+
const PenToolWidget_1 = __importDefault(require("./widgets/PenToolWidget"));
|
17
|
+
const EraserToolWidget_1 = __importDefault(require("./widgets/EraserToolWidget"));
|
18
|
+
const SelectionToolWidget_1 = __importDefault(require("./widgets/SelectionToolWidget"));
|
19
|
+
const TextToolWidget_1 = __importDefault(require("./widgets/TextToolWidget"));
|
20
|
+
const HandToolWidget_1 = __importDefault(require("./widgets/HandToolWidget"));
|
21
|
+
const ActionButtonWidget_1 = __importDefault(require("./widgets/ActionButtonWidget"));
|
22
|
+
const InsertImageWidget_1 = __importDefault(require("./widgets/InsertImageWidget"));
|
23
|
+
const DocumentPropertiesWidget_1 = __importDefault(require("./widgets/DocumentPropertiesWidget"));
|
24
|
+
const OverflowWidget_1 = __importDefault(require("./widgets/OverflowWidget"));
|
25
|
+
exports.toolbarCSSPrefix = 'toolbar-';
|
26
|
+
class HTMLToolbar {
|
27
|
+
/** @internal */
|
28
|
+
constructor(editor, parent, localizationTable = localization_1.defaultToolbarLocalization) {
|
29
|
+
this.editor = editor;
|
30
|
+
this.localizationTable = localizationTable;
|
31
|
+
this.listeners = [];
|
32
|
+
// Flex-order of the next widget to be added.
|
33
|
+
this.widgetOrderCounter = 0;
|
34
|
+
this.widgetsById = {};
|
35
|
+
this.widgetList = [];
|
36
|
+
// Widget to toggle overflow menu.
|
37
|
+
this.overflowWidget = null;
|
38
|
+
this.updateColoris = null;
|
39
|
+
this.reLayoutQueued = false;
|
40
|
+
this.container = document.createElement('div');
|
41
|
+
this.container.classList.add(`${exports.toolbarCSSPrefix}root`);
|
42
|
+
this.container.setAttribute('role', 'toolbar');
|
43
|
+
parent.appendChild(this.container);
|
44
|
+
if (!HTMLToolbar.colorisStarted) {
|
45
|
+
(0, coloris_1.init)();
|
46
|
+
HTMLToolbar.colorisStarted = true;
|
47
|
+
}
|
48
|
+
this.setupColorPickers();
|
49
|
+
if ('ResizeObserver' in window) {
|
50
|
+
this.resizeObserver = new ResizeObserver((_entries) => {
|
51
|
+
this.reLayout();
|
52
|
+
});
|
53
|
+
this.resizeObserver.observe(this.container);
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
console.warn('ResizeObserver not supported. Toolbar will not resize.');
|
57
|
+
}
|
58
|
+
}
|
59
|
+
// @internal
|
60
|
+
setupColorPickers() {
|
61
|
+
// Much of the setup only needs to be done once.
|
62
|
+
if (this.updateColoris) {
|
63
|
+
this.updateColoris();
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
const closePickerOverlay = document.createElement('div');
|
67
|
+
closePickerOverlay.className = `${exports.toolbarCSSPrefix}closeColorPickerOverlay`;
|
68
|
+
this.editor.createHTMLOverlay(closePickerOverlay);
|
69
|
+
const maxSwatchLen = 12;
|
70
|
+
const swatches = [
|
71
|
+
Color4_1.default.red.toHexString(),
|
72
|
+
Color4_1.default.purple.toHexString(),
|
73
|
+
Color4_1.default.blue.toHexString(),
|
74
|
+
Color4_1.default.clay.toHexString(),
|
75
|
+
Color4_1.default.black.toHexString(),
|
76
|
+
Color4_1.default.white.toHexString(),
|
77
|
+
];
|
78
|
+
const presetColorEnd = swatches.length;
|
79
|
+
// (Re)init Coloris -- update the swatches list.
|
80
|
+
const initColoris = () => {
|
81
|
+
(0, coloris_1.coloris)({
|
82
|
+
el: '.coloris_input',
|
83
|
+
format: 'hex',
|
84
|
+
selectInput: false,
|
85
|
+
focusInput: false,
|
86
|
+
themeMode: 'auto',
|
87
|
+
swatches
|
88
|
+
});
|
89
|
+
};
|
90
|
+
initColoris();
|
91
|
+
this.updateColoris = initColoris;
|
92
|
+
const addColorToSwatch = (newColor) => {
|
93
|
+
let alreadyPresent = false;
|
94
|
+
for (const color of swatches) {
|
95
|
+
if (color === newColor) {
|
96
|
+
alreadyPresent = true;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
if (!alreadyPresent) {
|
100
|
+
swatches.push(newColor);
|
101
|
+
if (swatches.length > maxSwatchLen) {
|
102
|
+
swatches.splice(presetColorEnd, 1);
|
103
|
+
}
|
104
|
+
initColoris();
|
105
|
+
}
|
106
|
+
};
|
107
|
+
this.listeners.push(this.editor.notifier.on(types_1.EditorEventType.ColorPickerToggled, event => {
|
108
|
+
if (event.kind !== types_1.EditorEventType.ColorPickerToggled) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
// Show/hide the overlay. Making the overlay visible gives users a surface to click
|
112
|
+
// on that shows/hides the color picker.
|
113
|
+
closePickerOverlay.style.display = event.open ? 'block' : 'none';
|
114
|
+
}));
|
115
|
+
// Add newly-selected colors to the swatch.
|
116
|
+
this.listeners.push(this.editor.notifier.on(types_1.EditorEventType.ColorPickerColorSelected, event => {
|
117
|
+
if (event.kind === types_1.EditorEventType.ColorPickerColorSelected) {
|
118
|
+
addColorToSwatch(event.color.toHexString());
|
119
|
+
}
|
120
|
+
}));
|
121
|
+
}
|
122
|
+
queueReLayout() {
|
123
|
+
if (!this.reLayoutQueued) {
|
124
|
+
this.reLayoutQueued = true;
|
125
|
+
requestAnimationFrame(() => this.reLayout());
|
126
|
+
}
|
127
|
+
}
|
128
|
+
reLayout() {
|
129
|
+
this.reLayoutQueued = false;
|
130
|
+
if (!this.overflowWidget) {
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
const getTotalWidth = (widgetList) => {
|
134
|
+
let totalWidth = 0;
|
135
|
+
for (const widget of widgetList) {
|
136
|
+
if (!widget.isHidden()) {
|
137
|
+
totalWidth += widget.getButtonWidth();
|
138
|
+
}
|
139
|
+
}
|
140
|
+
return totalWidth;
|
141
|
+
};
|
142
|
+
// Returns true if there is enough empty space to move the first child
|
143
|
+
// from the overflow menu to the main menu.
|
144
|
+
const canRemoveFirstChildFromOverflow = (freeSpaceInMainMenu) => {
|
145
|
+
var _a, _b;
|
146
|
+
const overflowChildren = (_b = (_a = this.overflowWidget) === null || _a === void 0 ? void 0 : _a.getChildWidgets()) !== null && _b !== void 0 ? _b : [];
|
147
|
+
if (overflowChildren.length === 0) {
|
148
|
+
return false;
|
149
|
+
}
|
150
|
+
return overflowChildren[0].getButtonWidth() <= freeSpaceInMainMenu;
|
151
|
+
};
|
152
|
+
let overflowWidgetsWidth = getTotalWidth(this.overflowWidget.getChildWidgets());
|
153
|
+
let shownWidgetWidth = getTotalWidth(this.widgetList) - overflowWidgetsWidth;
|
154
|
+
let availableWidth = this.container.clientWidth * 0.87;
|
155
|
+
// If on a device that has enough vertical space, allow
|
156
|
+
// showing two rows of buttons.
|
157
|
+
// TODO: Fix magic numbers
|
158
|
+
if (window.innerHeight > availableWidth * 1.75) {
|
159
|
+
availableWidth *= 1.75;
|
160
|
+
}
|
161
|
+
let updatedChildren = false;
|
162
|
+
// If we can remove at least one child from the overflow menu,
|
163
|
+
if (canRemoveFirstChildFromOverflow(availableWidth - shownWidgetWidth)) {
|
164
|
+
// Move widgets to the main menu.
|
165
|
+
const overflowChildren = this.overflowWidget.clearChildren();
|
166
|
+
for (const child of overflowChildren) {
|
167
|
+
child.addTo(this.container);
|
168
|
+
child.setIsToplevel(true);
|
169
|
+
if (!child.isHidden()) {
|
170
|
+
shownWidgetWidth += child.getButtonWidth();
|
171
|
+
}
|
172
|
+
}
|
173
|
+
overflowWidgetsWidth = 0;
|
174
|
+
updatedChildren = true;
|
175
|
+
}
|
176
|
+
if (shownWidgetWidth >= availableWidth) {
|
177
|
+
// Move widgets to the overflow menu.
|
178
|
+
// Start with the rightmost widget, move to the leftmost
|
179
|
+
for (let i = this.widgetList.length - 1; i >= 0 && shownWidgetWidth >= availableWidth; i--) {
|
180
|
+
const child = this.widgetList[i];
|
181
|
+
if (this.overflowWidget.hasAsChild(child)) {
|
182
|
+
continue;
|
183
|
+
}
|
184
|
+
if (child.canBeInOverflowMenu()) {
|
185
|
+
shownWidgetWidth -= child.getButtonWidth();
|
186
|
+
this.overflowWidget.addToOverflow(child);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
updatedChildren = true;
|
190
|
+
}
|
191
|
+
// Hide/show the overflow widget.
|
192
|
+
this.overflowWidget.setHidden(this.overflowWidget.getChildWidgets().length === 0);
|
193
|
+
if (updatedChildren) {
|
194
|
+
this.setupColorPickers();
|
195
|
+
}
|
196
|
+
}
|
197
|
+
/**
|
198
|
+
* Adds an `ActionButtonWidget` or `BaseToolWidget`. The widget should not have already have a parent
|
199
|
+
* (i.e. its `addTo` method should not have been called).
|
200
|
+
*
|
201
|
+
* @example
|
202
|
+
* ```ts
|
203
|
+
* const toolbar = editor.addToolbar();
|
204
|
+
* const insertImageWidget = new InsertImageWidget(editor);
|
205
|
+
* toolbar.addWidget(insertImageWidget);
|
206
|
+
* ```
|
207
|
+
*/
|
208
|
+
addWidget(widget) {
|
209
|
+
// Prevent name collisions
|
210
|
+
const id = widget.getUniqueIdIn(this.widgetsById);
|
211
|
+
// Add the widget
|
212
|
+
this.widgetsById[id] = widget;
|
213
|
+
this.widgetList.push(widget);
|
214
|
+
// Add HTML elements.
|
215
|
+
const container = widget.addTo(this.container);
|
216
|
+
this.setupColorPickers();
|
217
|
+
// Ensure that the widget gets displayed in the correct
|
218
|
+
// place in the toolbar, even if it's removed and re-added.
|
219
|
+
container.style.order = `${this.widgetOrderCounter++}`;
|
220
|
+
this.queueReLayout();
|
221
|
+
}
|
222
|
+
/**
|
223
|
+
* Adds a spacer.
|
224
|
+
*
|
225
|
+
* @example
|
226
|
+
* Adding a save button that moves to the very right edge of the toolbar
|
227
|
+
* while keeping the other buttons centered:
|
228
|
+
* ```ts
|
229
|
+
* const toolbar = editor.addToolbar(false);
|
230
|
+
*
|
231
|
+
* toolbar.addSpacer({ grow: 1 });
|
232
|
+
* toolbar.addDefaults();
|
233
|
+
* toolbar.addSpacer({ grow: 1 });
|
234
|
+
*
|
235
|
+
* toolbar.addActionButton({
|
236
|
+
* label: 'Save',
|
237
|
+
* icon: editor.icons.makeSaveIcon(),
|
238
|
+
* }, () => {
|
239
|
+
* saveCallback();
|
240
|
+
* });
|
241
|
+
* ```
|
242
|
+
*/
|
243
|
+
addSpacer(options = {}) {
|
244
|
+
const spacer = document.createElement('div');
|
245
|
+
spacer.classList.add(`${exports.toolbarCSSPrefix}spacer`);
|
246
|
+
if (options.grow) {
|
247
|
+
spacer.style.flexGrow = `${options.grow}`;
|
248
|
+
}
|
249
|
+
if (options.minSize) {
|
250
|
+
spacer.style.minWidth = options.minSize;
|
251
|
+
}
|
252
|
+
if (options.maxSize) {
|
253
|
+
spacer.style.maxWidth = options.maxSize;
|
254
|
+
}
|
255
|
+
spacer.style.order = `${this.widgetOrderCounter++}`;
|
256
|
+
this.container.appendChild(spacer);
|
257
|
+
}
|
258
|
+
serializeState() {
|
259
|
+
const result = {};
|
260
|
+
for (const widgetId in this.widgetsById) {
|
261
|
+
result[widgetId] = this.widgetsById[widgetId].serializeState();
|
262
|
+
}
|
263
|
+
return JSON.stringify(result);
|
264
|
+
}
|
265
|
+
/**
|
266
|
+
* Deserialize toolbar widgets from the given state.
|
267
|
+
* Assumes that toolbar widgets are in the same order as when state was serialized.
|
268
|
+
*/
|
269
|
+
deserializeState(state) {
|
270
|
+
const data = JSON.parse(state);
|
271
|
+
for (const widgetId in data) {
|
272
|
+
if (!(widgetId in this.widgetsById)) {
|
273
|
+
console.warn(`Unable to deserialize widget ${widgetId} — no such widget.`);
|
274
|
+
}
|
275
|
+
this.widgetsById[widgetId].deserializeFrom(data[widgetId]);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
/**
|
279
|
+
* Adds an action button with `title` to this toolbar (or to the given `parent` element).
|
280
|
+
*
|
281
|
+
* @return The added button.
|
282
|
+
*/
|
283
|
+
addActionButton(title, command, mustBeToplevel = true) {
|
284
|
+
const titleString = typeof title === 'string' ? title : title.label;
|
285
|
+
const widgetId = 'action-button';
|
286
|
+
const makeIcon = () => {
|
287
|
+
if (typeof title === 'string') {
|
288
|
+
return null;
|
289
|
+
}
|
290
|
+
return title.icon;
|
291
|
+
};
|
292
|
+
const widget = new ActionButtonWidget_1.default(this.editor, widgetId, makeIcon, titleString, command, this.editor.localization, mustBeToplevel);
|
293
|
+
this.addWidget(widget);
|
294
|
+
return widget;
|
295
|
+
}
|
296
|
+
addUndoRedoButtons() {
|
297
|
+
const undoButton = this.addActionButton({
|
298
|
+
label: this.localizationTable.undo,
|
299
|
+
icon: this.editor.icons.makeUndoIcon()
|
300
|
+
}, () => {
|
301
|
+
this.editor.history.undo();
|
302
|
+
});
|
303
|
+
const redoButton = this.addActionButton({
|
304
|
+
label: this.localizationTable.redo,
|
305
|
+
icon: this.editor.icons.makeRedoIcon(),
|
306
|
+
}, () => {
|
307
|
+
this.editor.history.redo();
|
308
|
+
});
|
309
|
+
undoButton.setDisabled(true);
|
310
|
+
redoButton.setDisabled(true);
|
311
|
+
this.editor.notifier.on(types_1.EditorEventType.UndoRedoStackUpdated, event => {
|
312
|
+
if (event.kind !== types_1.EditorEventType.UndoRedoStackUpdated) {
|
313
|
+
throw new Error('Wrong event type!');
|
314
|
+
}
|
315
|
+
undoButton.setDisabled(event.undoStackSize === 0);
|
316
|
+
redoButton.setDisabled(event.redoStackSize === 0);
|
317
|
+
});
|
318
|
+
}
|
319
|
+
addDefaultToolWidgets() {
|
320
|
+
const toolController = this.editor.toolController;
|
321
|
+
for (const tool of toolController.getMatchingTools(Pen_1.default)) {
|
322
|
+
const widget = new PenToolWidget_1.default(this.editor, tool, this.localizationTable);
|
323
|
+
this.addWidget(widget);
|
324
|
+
}
|
325
|
+
for (const tool of toolController.getMatchingTools(Eraser_1.default)) {
|
326
|
+
this.addWidget(new EraserToolWidget_1.default(this.editor, tool, this.localizationTable));
|
327
|
+
}
|
328
|
+
for (const tool of toolController.getMatchingTools(SelectionTool_1.default)) {
|
329
|
+
this.addWidget(new SelectionToolWidget_1.default(this.editor, tool, this.localizationTable));
|
330
|
+
}
|
331
|
+
for (const tool of toolController.getMatchingTools(TextTool_1.default)) {
|
332
|
+
this.addWidget(new TextToolWidget_1.default(this.editor, tool, this.localizationTable));
|
333
|
+
}
|
334
|
+
const panZoomTool = toolController.getMatchingTools(PanZoom_1.default)[0];
|
335
|
+
if (panZoomTool) {
|
336
|
+
this.addWidget(new HandToolWidget_1.default(this.editor, panZoomTool, this.localizationTable));
|
337
|
+
}
|
338
|
+
this.addWidget(new InsertImageWidget_1.default(this.editor, this.localizationTable));
|
339
|
+
}
|
340
|
+
addDefaultActionButtons() {
|
341
|
+
this.addWidget(new DocumentPropertiesWidget_1.default(this.editor, this.localizationTable));
|
342
|
+
this.addUndoRedoButtons();
|
343
|
+
}
|
344
|
+
/**
|
345
|
+
* Adds a widget that toggles the overflow menu. Call `addOverflowWidget` to ensure
|
346
|
+
* that this widget is in the correct space (if shown).
|
347
|
+
*
|
348
|
+
* @example
|
349
|
+
* ```ts
|
350
|
+
* toolbar.addDefaultToolWidgets();
|
351
|
+
* toolbar.addOverflowWidget();
|
352
|
+
* toolbar.addDefaultActionButtons();
|
353
|
+
* ```
|
354
|
+
* shows the overflow widget between the default tool widgets and the default action buttons,
|
355
|
+
* if shown.
|
356
|
+
*/
|
357
|
+
addOverflowWidget() {
|
358
|
+
this.overflowWidget = new OverflowWidget_1.default(this.editor, this.localizationTable);
|
359
|
+
this.addWidget(this.overflowWidget);
|
360
|
+
}
|
361
|
+
/**
|
362
|
+
* Adds both the default tool widgets and action buttons. Equivalent to
|
363
|
+
* ```ts
|
364
|
+
* toolbar.addDefaultToolWidgets();
|
365
|
+
* toolbar.addOverflowWidget();
|
366
|
+
* toolbar.addDefaultActionButtons();
|
367
|
+
* ```
|
368
|
+
*/
|
369
|
+
addDefaults() {
|
370
|
+
this.addDefaultToolWidgets();
|
371
|
+
this.addOverflowWidget();
|
372
|
+
this.addDefaultActionButtons();
|
373
|
+
}
|
374
|
+
remove() {
|
375
|
+
this.container.remove();
|
376
|
+
this.resizeObserver.disconnect();
|
377
|
+
for (const listener of this.listeners) {
|
378
|
+
listener.remove();
|
379
|
+
}
|
380
|
+
}
|
381
|
+
}
|
382
|
+
exports.default = HTMLToolbar;
|
383
|
+
HTMLToolbar.colorisStarted = false;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import Color4 from '../Color4';
|
2
|
+
import { ComponentBuilderFactory } from '../components/builders/types';
|
3
|
+
import TextRenderingStyle from '../rendering/TextRenderingStyle';
|
4
|
+
import Pen from '../tools/Pen';
|
5
|
+
export type IconType = HTMLImageElement | SVGElement;
|
6
|
+
/**
|
7
|
+
* Provides icons that can be used in the toolbar, etc.
|
8
|
+
* Extend this class and override methods to customize icons.
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* ```ts
|
12
|
+
* class CustomIconProvider extends jsdraw.IconProvider {
|
13
|
+
* // Use '☺' instead of the default dropdown symbol.
|
14
|
+
* public makeDropdownIcon() {
|
15
|
+
* const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
16
|
+
* icon.innerHTML = `
|
17
|
+
* <text x='5' y='55' style='fill: var(--icon-color); font-size: 50pt;'>☺</text>
|
18
|
+
* `;
|
19
|
+
* icon.setAttribute('viewBox', '0 0 100 100');
|
20
|
+
* return icon;
|
21
|
+
* }
|
22
|
+
* }
|
23
|
+
*
|
24
|
+
* const icons = new CustomIconProvider();
|
25
|
+
* const editor = new jsdraw.Editor(document.body, {
|
26
|
+
* iconProvider: icons,
|
27
|
+
* });
|
28
|
+
*
|
29
|
+
* // Add a toolbar that uses these icons
|
30
|
+
* editor.addToolbar();
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
export default class IconProvider {
|
34
|
+
makeUndoIcon(): IconType;
|
35
|
+
makeRedoIcon(mirror?: boolean): IconType;
|
36
|
+
makeDropdownIcon(): IconType;
|
37
|
+
makeEraserIcon(eraserSize?: number): IconType;
|
38
|
+
makeSelectionIcon(): IconType;
|
39
|
+
/**
|
40
|
+
* @param pathData - SVG path data (e.g. `m10,10l30,30z`)
|
41
|
+
* @param fill - A valid CSS color (e.g. `var(--icon-color)` or `#f0f`). This can be `none`.
|
42
|
+
*/
|
43
|
+
protected makeIconFromPath(pathData: string, fill?: string, strokeColor?: string, strokeWidth?: string): IconType;
|
44
|
+
makeHandToolIcon(): IconType;
|
45
|
+
makeTouchPanningIcon(): IconType;
|
46
|
+
makeAllDevicePanningIcon(): IconType;
|
47
|
+
makeZoomIcon(): IconType;
|
48
|
+
makeRotationLockIcon(): IconType;
|
49
|
+
makeInsertImageIcon(): IconType;
|
50
|
+
makeTextIcon(textStyle: TextRenderingStyle): IconType;
|
51
|
+
makePenIcon(strokeSize: number, color: string | Color4, rounded?: boolean): IconType;
|
52
|
+
makeIconFromFactory(pen: Pen, factory: ComponentBuilderFactory): IconType;
|
53
|
+
makePipetteIcon(color?: Color4): IconType;
|
54
|
+
makeFormatSelectionIcon(): IconType;
|
55
|
+
makeResizeViewportIcon(): IconType;
|
56
|
+
makeDuplicateSelectionIcon(): IconType;
|
57
|
+
makePasteIcon(): IconType;
|
58
|
+
makeDeleteSelectionIcon(): IconType;
|
59
|
+
makeSaveIcon(): IconType;
|
60
|
+
makeConfigureDocumentIcon(): IconType;
|
61
|
+
makeOverflowIcon(): IconType;
|
62
|
+
}
|