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,118 @@
|
|
1
|
+
import { Point2, Vec2 } from './Vec2';
|
2
|
+
import Vec3 from './Vec3';
|
3
|
+
export type Mat33Array = [
|
4
|
+
number,
|
5
|
+
number,
|
6
|
+
number,
|
7
|
+
number,
|
8
|
+
number,
|
9
|
+
number,
|
10
|
+
number,
|
11
|
+
number,
|
12
|
+
number
|
13
|
+
];
|
14
|
+
/**
|
15
|
+
* Represents a three dimensional linear transformation or
|
16
|
+
* a two-dimensional affine transformation. (An affine transformation scales/rotates/shears
|
17
|
+
* **and** translates while a linear transformation just scales/rotates/shears).
|
18
|
+
*/
|
19
|
+
export default class Mat33 {
|
20
|
+
readonly a1: number;
|
21
|
+
readonly a2: number;
|
22
|
+
readonly a3: number;
|
23
|
+
readonly b1: number;
|
24
|
+
readonly b2: number;
|
25
|
+
readonly b3: number;
|
26
|
+
readonly c1: number;
|
27
|
+
readonly c2: number;
|
28
|
+
readonly c3: number;
|
29
|
+
private readonly rows;
|
30
|
+
/**
|
31
|
+
* Creates a matrix from inputs in the form,
|
32
|
+
* ```
|
33
|
+
* ⎡ a1 a2 a3 ⎤
|
34
|
+
* ⎢ b1 b2 b3 ⎥
|
35
|
+
* ⎣ c1 c2 c3 ⎦
|
36
|
+
* ```
|
37
|
+
*/
|
38
|
+
constructor(a1: number, a2: number, a3: number, b1: number, b2: number, b3: number, c1: number, c2: number, c3: number);
|
39
|
+
/**
|
40
|
+
* Creates a matrix from the given rows:
|
41
|
+
* ```
|
42
|
+
* ⎡ r1.x r1.y r1.z ⎤
|
43
|
+
* ⎢ r2.x r2.y r2.z ⎥
|
44
|
+
* ⎣ r3.x r3.y r3.z ⎦
|
45
|
+
* ```
|
46
|
+
*/
|
47
|
+
static ofRows(r1: Vec3, r2: Vec3, r3: Vec3): Mat33;
|
48
|
+
static identity: Mat33;
|
49
|
+
/**
|
50
|
+
* Either returns the inverse of this, or, if this matrix is singular/uninvertable,
|
51
|
+
* returns Mat33.identity.
|
52
|
+
*
|
53
|
+
* This may cache the computed inverse and return the cached version instead of recomputing
|
54
|
+
* it.
|
55
|
+
*/
|
56
|
+
inverse(): Mat33;
|
57
|
+
invertable(): boolean;
|
58
|
+
private cachedInverse;
|
59
|
+
private computeInverse;
|
60
|
+
transposed(): Mat33;
|
61
|
+
rightMul(other: Mat33): Mat33;
|
62
|
+
/**
|
63
|
+
* Applies this as an affine transformation to the given vector.
|
64
|
+
* Returns a transformed version of `other`.
|
65
|
+
*/
|
66
|
+
transformVec2(other: Vec2): Vec2;
|
67
|
+
/**
|
68
|
+
* Applies this as a linear transformation to the given vector (doesn't translate).
|
69
|
+
* This is the standard way of transforming vectors in ℝ³.
|
70
|
+
*/
|
71
|
+
transformVec3(other: Vec3): Vec3;
|
72
|
+
/** @returns true iff this is the identity matrix. */
|
73
|
+
isIdentity(): boolean;
|
74
|
+
/** Returns true iff this = other ± fuzz */
|
75
|
+
eq(other: Mat33, fuzz?: number): boolean;
|
76
|
+
toString(): string;
|
77
|
+
/**
|
78
|
+
* ```
|
79
|
+
* result[0] = top left element
|
80
|
+
* result[1] = element at row zero, column 1
|
81
|
+
* ...
|
82
|
+
* ```
|
83
|
+
*/
|
84
|
+
toArray(): Mat33Array;
|
85
|
+
/**
|
86
|
+
* @example
|
87
|
+
* ```
|
88
|
+
* new Mat33(
|
89
|
+
* 1, 2, 3,
|
90
|
+
* 4, 5, 6,
|
91
|
+
* 7, 8, 9,
|
92
|
+
* ).mapEntries(component => component - 1);
|
93
|
+
* // → ⎡ 0, 1, 2 ⎤
|
94
|
+
* // ⎢ 3, 4, 5 ⎥
|
95
|
+
* // ⎣ 6, 7, 8 ⎦
|
96
|
+
* ```
|
97
|
+
*/
|
98
|
+
mapEntries(mapping: (component: number) => number): Mat33;
|
99
|
+
/** Estimate the scale factor of this matrix (based on the first row). */
|
100
|
+
getScaleFactor(): number;
|
101
|
+
/** Constructs a 3x3 translation matrix (for translating `Vec2`s) */
|
102
|
+
static translation(amount: Vec2): Mat33;
|
103
|
+
static zRotation(radians: number, center?: Point2): Mat33;
|
104
|
+
static scaling2D(amount: number | Vec2, center?: Point2): Mat33;
|
105
|
+
/** @see {@link fromCSSMatrix} */
|
106
|
+
toCSSMatrix(): string;
|
107
|
+
/**
|
108
|
+
* Converts a CSS-form `matrix(a, b, c, d, e, f)` to a Mat33.
|
109
|
+
*
|
110
|
+
* Note that such a matrix has the form,
|
111
|
+
* ```
|
112
|
+
* ⎡ a c e ⎤
|
113
|
+
* ⎢ b d f ⎥
|
114
|
+
* ⎣ 0 0 1 ⎦
|
115
|
+
* ```
|
116
|
+
*/
|
117
|
+
static fromCSSMatrix(cssString: string): Mat33;
|
118
|
+
}
|
@@ -0,0 +1,326 @@
|
|
1
|
+
import { Vec2 } from './Vec2.mjs';
|
2
|
+
import Vec3 from './Vec3.mjs';
|
3
|
+
/**
|
4
|
+
* Represents a three dimensional linear transformation or
|
5
|
+
* a two-dimensional affine transformation. (An affine transformation scales/rotates/shears
|
6
|
+
* **and** translates while a linear transformation just scales/rotates/shears).
|
7
|
+
*/
|
8
|
+
export default class Mat33 {
|
9
|
+
/**
|
10
|
+
* Creates a matrix from inputs in the form,
|
11
|
+
* ```
|
12
|
+
* ⎡ a1 a2 a3 ⎤
|
13
|
+
* ⎢ b1 b2 b3 ⎥
|
14
|
+
* ⎣ c1 c2 c3 ⎦
|
15
|
+
* ```
|
16
|
+
*/
|
17
|
+
constructor(a1, a2, a3, b1, b2, b3, c1, c2, c3) {
|
18
|
+
this.a1 = a1;
|
19
|
+
this.a2 = a2;
|
20
|
+
this.a3 = a3;
|
21
|
+
this.b1 = b1;
|
22
|
+
this.b2 = b2;
|
23
|
+
this.b3 = b3;
|
24
|
+
this.c1 = c1;
|
25
|
+
this.c2 = c2;
|
26
|
+
this.c3 = c3;
|
27
|
+
this.cachedInverse = undefined;
|
28
|
+
this.rows = [
|
29
|
+
Vec3.of(a1, a2, a3),
|
30
|
+
Vec3.of(b1, b2, b3),
|
31
|
+
Vec3.of(c1, c2, c3),
|
32
|
+
];
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Creates a matrix from the given rows:
|
36
|
+
* ```
|
37
|
+
* ⎡ r1.x r1.y r1.z ⎤
|
38
|
+
* ⎢ r2.x r2.y r2.z ⎥
|
39
|
+
* ⎣ r3.x r3.y r3.z ⎦
|
40
|
+
* ```
|
41
|
+
*/
|
42
|
+
static ofRows(r1, r2, r3) {
|
43
|
+
return new Mat33(r1.x, r1.y, r1.z, r2.x, r2.y, r2.z, r3.x, r3.y, r3.z);
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Either returns the inverse of this, or, if this matrix is singular/uninvertable,
|
47
|
+
* returns Mat33.identity.
|
48
|
+
*
|
49
|
+
* This may cache the computed inverse and return the cached version instead of recomputing
|
50
|
+
* it.
|
51
|
+
*/
|
52
|
+
inverse() {
|
53
|
+
var _a;
|
54
|
+
return (_a = this.computeInverse()) !== null && _a !== void 0 ? _a : Mat33.identity;
|
55
|
+
}
|
56
|
+
invertable() {
|
57
|
+
return this.computeInverse() !== null;
|
58
|
+
}
|
59
|
+
computeInverse() {
|
60
|
+
if (this.cachedInverse !== undefined) {
|
61
|
+
return this.cachedInverse;
|
62
|
+
}
|
63
|
+
const toIdentity = [
|
64
|
+
this.rows[0],
|
65
|
+
this.rows[1],
|
66
|
+
this.rows[2],
|
67
|
+
];
|
68
|
+
const toResult = [
|
69
|
+
Vec3.unitX,
|
70
|
+
Vec3.unitY,
|
71
|
+
Vec3.unitZ,
|
72
|
+
];
|
73
|
+
// Convert toIdentity to the identity matrix and
|
74
|
+
// toResult to the inverse through elementary row operations
|
75
|
+
for (let cursor = 0; cursor < 3; cursor++) {
|
76
|
+
// Select the [cursor]th diagonal entry
|
77
|
+
let pivot = toIdentity[cursor].at(cursor);
|
78
|
+
// Don't divide by zero (treat very small numbers as zero).
|
79
|
+
const minDivideBy = 1e-10;
|
80
|
+
if (Math.abs(pivot) < minDivideBy) {
|
81
|
+
let swapIndex = -1;
|
82
|
+
// For all other rows,
|
83
|
+
for (let i = 1; i <= 2; i++) {
|
84
|
+
const otherRowIdx = (cursor + i) % 3;
|
85
|
+
if (Math.abs(toIdentity[otherRowIdx].at(cursor)) >= minDivideBy) {
|
86
|
+
swapIndex = otherRowIdx;
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
// Can't swap with another row?
|
91
|
+
if (swapIndex === -1) {
|
92
|
+
this.cachedInverse = null;
|
93
|
+
return null;
|
94
|
+
}
|
95
|
+
const tmpIdentityRow = toIdentity[cursor];
|
96
|
+
const tmpResultRow = toResult[cursor];
|
97
|
+
// Swap!
|
98
|
+
toIdentity[cursor] = toIdentity[swapIndex];
|
99
|
+
toResult[cursor] = toResult[swapIndex];
|
100
|
+
toIdentity[swapIndex] = tmpIdentityRow;
|
101
|
+
toResult[swapIndex] = tmpResultRow;
|
102
|
+
pivot = toIdentity[cursor].at(cursor);
|
103
|
+
}
|
104
|
+
// Make toIdentity[k = cursor] = 1
|
105
|
+
let scale = 1.0 / pivot;
|
106
|
+
toIdentity[cursor] = toIdentity[cursor].times(scale);
|
107
|
+
toResult[cursor] = toResult[cursor].times(scale);
|
108
|
+
const cursorToIdentityRow = toIdentity[cursor];
|
109
|
+
const cursorToResultRow = toResult[cursor];
|
110
|
+
// Make toIdentity[k ≠ cursor] = 0
|
111
|
+
for (let i = 1; i <= 2; i++) {
|
112
|
+
const otherRowIdx = (cursor + i) % 3;
|
113
|
+
scale = -toIdentity[otherRowIdx].at(cursor);
|
114
|
+
toIdentity[otherRowIdx] = toIdentity[otherRowIdx].plus(cursorToIdentityRow.times(scale));
|
115
|
+
toResult[otherRowIdx] = toResult[otherRowIdx].plus(cursorToResultRow.times(scale));
|
116
|
+
}
|
117
|
+
}
|
118
|
+
const inverse = Mat33.ofRows(toResult[0], toResult[1], toResult[2]);
|
119
|
+
this.cachedInverse = inverse;
|
120
|
+
return inverse;
|
121
|
+
}
|
122
|
+
transposed() {
|
123
|
+
return new Mat33(this.a1, this.b1, this.c1, this.a2, this.b2, this.c2, this.a3, this.b3, this.c3);
|
124
|
+
}
|
125
|
+
rightMul(other) {
|
126
|
+
other = other.transposed();
|
127
|
+
const at = (row, col) => {
|
128
|
+
return this.rows[row].dot(other.rows[col]);
|
129
|
+
};
|
130
|
+
return new Mat33(at(0, 0), at(0, 1), at(0, 2), at(1, 0), at(1, 1), at(1, 2), at(2, 0), at(2, 1), at(2, 2));
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* Applies this as an affine transformation to the given vector.
|
134
|
+
* Returns a transformed version of `other`.
|
135
|
+
*/
|
136
|
+
transformVec2(other) {
|
137
|
+
// When transforming a Vec2, we want to use the z transformation
|
138
|
+
// components of this for translation:
|
139
|
+
// ⎡ . . tX ⎤
|
140
|
+
// ⎢ . . tY ⎥
|
141
|
+
// ⎣ 0 0 1 ⎦
|
142
|
+
// For this, we need other's z component to be 1 (so that tX and tY
|
143
|
+
// are scaled by 1):
|
144
|
+
let intermediate = Vec3.of(other.x, other.y, 1);
|
145
|
+
intermediate = this.transformVec3(intermediate);
|
146
|
+
// Drop the z=1 to allow magnitude to work as expected
|
147
|
+
return Vec2.of(intermediate.x, intermediate.y);
|
148
|
+
}
|
149
|
+
/**
|
150
|
+
* Applies this as a linear transformation to the given vector (doesn't translate).
|
151
|
+
* This is the standard way of transforming vectors in ℝ³.
|
152
|
+
*/
|
153
|
+
transformVec3(other) {
|
154
|
+
return Vec3.of(this.rows[0].dot(other), this.rows[1].dot(other), this.rows[2].dot(other));
|
155
|
+
}
|
156
|
+
/** @returns true iff this is the identity matrix. */
|
157
|
+
isIdentity() {
|
158
|
+
if (this === Mat33.identity) {
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
return this.eq(Mat33.identity);
|
162
|
+
}
|
163
|
+
/** Returns true iff this = other ± fuzz */
|
164
|
+
eq(other, fuzz = 0) {
|
165
|
+
for (let i = 0; i < 3; i++) {
|
166
|
+
if (!this.rows[i].eq(other.rows[i], fuzz)) {
|
167
|
+
return false;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
return true;
|
171
|
+
}
|
172
|
+
toString() {
|
173
|
+
let result = '';
|
174
|
+
const maxColumnLens = [0, 0, 0];
|
175
|
+
// Determine the longest item in each column so we can pad the others to that
|
176
|
+
// length.
|
177
|
+
for (const row of this.rows) {
|
178
|
+
for (let i = 0; i < 3; i++) {
|
179
|
+
maxColumnLens[i] = Math.max(maxColumnLens[0], `${row.at(i)}`.length);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
for (let i = 0; i < 3; i++) {
|
183
|
+
if (i === 0) {
|
184
|
+
result += '⎡ ';
|
185
|
+
}
|
186
|
+
else if (i === 1) {
|
187
|
+
result += '⎢ ';
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
result += '⎣ ';
|
191
|
+
}
|
192
|
+
// Add each component of the ith row (after padding it)
|
193
|
+
for (let j = 0; j < 3; j++) {
|
194
|
+
const val = this.rows[i].at(j).toString();
|
195
|
+
let padding = '';
|
196
|
+
for (let i = val.length; i < maxColumnLens[j]; i++) {
|
197
|
+
padding += ' ';
|
198
|
+
}
|
199
|
+
result += val + ', ' + padding;
|
200
|
+
}
|
201
|
+
if (i === 0) {
|
202
|
+
result += ' ⎤';
|
203
|
+
}
|
204
|
+
else if (i === 1) {
|
205
|
+
result += ' ⎥';
|
206
|
+
}
|
207
|
+
else {
|
208
|
+
result += ' ⎦';
|
209
|
+
}
|
210
|
+
result += '\n';
|
211
|
+
}
|
212
|
+
return result.trimEnd();
|
213
|
+
}
|
214
|
+
/**
|
215
|
+
* ```
|
216
|
+
* result[0] = top left element
|
217
|
+
* result[1] = element at row zero, column 1
|
218
|
+
* ...
|
219
|
+
* ```
|
220
|
+
*/
|
221
|
+
toArray() {
|
222
|
+
return [
|
223
|
+
this.a1, this.a2, this.a3,
|
224
|
+
this.b1, this.b2, this.b3,
|
225
|
+
this.c1, this.c2, this.c3,
|
226
|
+
];
|
227
|
+
}
|
228
|
+
/**
|
229
|
+
* @example
|
230
|
+
* ```
|
231
|
+
* new Mat33(
|
232
|
+
* 1, 2, 3,
|
233
|
+
* 4, 5, 6,
|
234
|
+
* 7, 8, 9,
|
235
|
+
* ).mapEntries(component => component - 1);
|
236
|
+
* // → ⎡ 0, 1, 2 ⎤
|
237
|
+
* // ⎢ 3, 4, 5 ⎥
|
238
|
+
* // ⎣ 6, 7, 8 ⎦
|
239
|
+
* ```
|
240
|
+
*/
|
241
|
+
mapEntries(mapping) {
|
242
|
+
return new Mat33(mapping(this.a1), mapping(this.a2), mapping(this.a3), mapping(this.b1), mapping(this.b2), mapping(this.b3), mapping(this.c1), mapping(this.c2), mapping(this.c3));
|
243
|
+
}
|
244
|
+
/** Estimate the scale factor of this matrix (based on the first row). */
|
245
|
+
getScaleFactor() {
|
246
|
+
return Math.hypot(this.a1, this.a2);
|
247
|
+
}
|
248
|
+
/** Constructs a 3x3 translation matrix (for translating `Vec2`s) */
|
249
|
+
static translation(amount) {
|
250
|
+
// When transforming Vec2s by a 3x3 matrix, we give the input
|
251
|
+
// Vec2s z = 1. As such,
|
252
|
+
// outVec2.x = inVec2.x * 1 + inVec2.y * 0 + 1 * amount.x
|
253
|
+
// ...
|
254
|
+
return new Mat33(1, 0, amount.x, 0, 1, amount.y, 0, 0, 1);
|
255
|
+
}
|
256
|
+
static zRotation(radians, center = Vec2.zero) {
|
257
|
+
if (radians === 0) {
|
258
|
+
return Mat33.identity;
|
259
|
+
}
|
260
|
+
const cos = Math.cos(radians);
|
261
|
+
const sin = Math.sin(radians);
|
262
|
+
// Translate everything so that rotation is about the origin
|
263
|
+
let result = Mat33.translation(center);
|
264
|
+
result = result.rightMul(new Mat33(cos, -sin, 0, sin, cos, 0, 0, 0, 1));
|
265
|
+
return result.rightMul(Mat33.translation(center.times(-1)));
|
266
|
+
}
|
267
|
+
static scaling2D(amount, center = Vec2.zero) {
|
268
|
+
let result = Mat33.translation(center);
|
269
|
+
let xAmount, yAmount;
|
270
|
+
if (typeof amount === 'number') {
|
271
|
+
xAmount = amount;
|
272
|
+
yAmount = amount;
|
273
|
+
}
|
274
|
+
else {
|
275
|
+
xAmount = amount.x;
|
276
|
+
yAmount = amount.y;
|
277
|
+
}
|
278
|
+
result = result.rightMul(new Mat33(xAmount, 0, 0, 0, yAmount, 0, 0, 0, 1));
|
279
|
+
// Translate such that [center] goes to (0, 0)
|
280
|
+
return result.rightMul(Mat33.translation(center.times(-1)));
|
281
|
+
}
|
282
|
+
/** @see {@link fromCSSMatrix} */
|
283
|
+
toCSSMatrix() {
|
284
|
+
return `matrix(${this.a1},${this.b1},${this.a2},${this.b2},${this.a3},${this.b3})`;
|
285
|
+
}
|
286
|
+
/**
|
287
|
+
* Converts a CSS-form `matrix(a, b, c, d, e, f)` to a Mat33.
|
288
|
+
*
|
289
|
+
* Note that such a matrix has the form,
|
290
|
+
* ```
|
291
|
+
* ⎡ a c e ⎤
|
292
|
+
* ⎢ b d f ⎥
|
293
|
+
* ⎣ 0 0 1 ⎦
|
294
|
+
* ```
|
295
|
+
*/
|
296
|
+
static fromCSSMatrix(cssString) {
|
297
|
+
if (cssString === '' || cssString === 'none') {
|
298
|
+
return Mat33.identity;
|
299
|
+
}
|
300
|
+
const numberExp = '([-]?\\d*(?:\\.\\d*)?(?:[eE][-]?\\d+)?)';
|
301
|
+
const numberSepExp = '[, \\t\\n]';
|
302
|
+
const regExpSource = `^\\s*matrix\\s*\\(${[
|
303
|
+
// According to MDN, matrix(a,b,c,d,e,f) has form:
|
304
|
+
// ⎡ a c e ⎤
|
305
|
+
// ⎢ b d f ⎥
|
306
|
+
// ⎣ 0 0 1 ⎦
|
307
|
+
numberExp, numberExp, numberExp,
|
308
|
+
numberExp, numberExp, numberExp, // b, d, f
|
309
|
+
].join(`${numberSepExp}+`)}${numberSepExp}*\\)\\s*$`;
|
310
|
+
const matrixExp = new RegExp(regExpSource, 'i');
|
311
|
+
const match = matrixExp.exec(cssString);
|
312
|
+
if (!match) {
|
313
|
+
throw new Error(`Unsupported transformation: ${cssString}`);
|
314
|
+
}
|
315
|
+
const matrixData = match.slice(1).map(entry => parseFloat(entry));
|
316
|
+
const a = matrixData[0];
|
317
|
+
const b = matrixData[1];
|
318
|
+
const c = matrixData[2];
|
319
|
+
const d = matrixData[3];
|
320
|
+
const e = matrixData[4];
|
321
|
+
const f = matrixData[5];
|
322
|
+
const transform = new Mat33(a, c, e, b, d, f, 0, 0, 1);
|
323
|
+
return transform;
|
324
|
+
}
|
325
|
+
}
|
326
|
+
Mat33.identity = new Mat33(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import { Bezier } from 'bezier-js';
|
2
|
+
import { RenderablePathSpec } from '../rendering/renderers/AbstractRenderer';
|
3
|
+
import RenderingStyle from '../rendering/RenderingStyle';
|
4
|
+
import LineSegment2 from './LineSegment2';
|
5
|
+
import Mat33 from './Mat33';
|
6
|
+
import Rect2 from './Rect2';
|
7
|
+
import { Point2 } from './Vec2';
|
8
|
+
export declare enum PathCommandType {
|
9
|
+
LineTo = 0,
|
10
|
+
MoveTo = 1,
|
11
|
+
CubicBezierTo = 2,
|
12
|
+
QuadraticBezierTo = 3
|
13
|
+
}
|
14
|
+
export interface CubicBezierPathCommand {
|
15
|
+
kind: PathCommandType.CubicBezierTo;
|
16
|
+
controlPoint1: Point2;
|
17
|
+
controlPoint2: Point2;
|
18
|
+
endPoint: Point2;
|
19
|
+
}
|
20
|
+
export interface QuadraticBezierPathCommand {
|
21
|
+
kind: PathCommandType.QuadraticBezierTo;
|
22
|
+
controlPoint: Point2;
|
23
|
+
endPoint: Point2;
|
24
|
+
}
|
25
|
+
export interface LinePathCommand {
|
26
|
+
kind: PathCommandType.LineTo;
|
27
|
+
point: Point2;
|
28
|
+
}
|
29
|
+
export interface MoveToPathCommand {
|
30
|
+
kind: PathCommandType.MoveTo;
|
31
|
+
point: Point2;
|
32
|
+
}
|
33
|
+
export type PathCommand = CubicBezierPathCommand | LinePathCommand | QuadraticBezierPathCommand | MoveToPathCommand;
|
34
|
+
interface IntersectionResult {
|
35
|
+
curve: LineSegment2 | Bezier;
|
36
|
+
parameterValue: number;
|
37
|
+
point: Point2;
|
38
|
+
}
|
39
|
+
export default class Path {
|
40
|
+
readonly startPoint: Point2;
|
41
|
+
readonly parts: PathCommand[];
|
42
|
+
readonly bbox: Rect2;
|
43
|
+
constructor(startPoint: Point2, parts: PathCommand[]);
|
44
|
+
private cachedGeometry;
|
45
|
+
get geometry(): Array<LineSegment2 | Bezier>;
|
46
|
+
private cachedPolylineApproximation;
|
47
|
+
polylineApproximation(): LineSegment2[];
|
48
|
+
static computeBBoxForSegment(startPoint: Point2, part: PathCommand): Rect2;
|
49
|
+
intersection(line: LineSegment2): IntersectionResult[];
|
50
|
+
private static mapPathCommand;
|
51
|
+
mapPoints(mapping: (point: Point2) => Point2): Path;
|
52
|
+
transformedBy(affineTransfm: Mat33): Path;
|
53
|
+
union(other: Path | null): Path;
|
54
|
+
private getEndPoint;
|
55
|
+
roughlyIntersects(rect: Rect2, strokeWidth?: number): boolean;
|
56
|
+
closedRoughlyIntersects(rect: Rect2): boolean;
|
57
|
+
static fromRect(rect: Rect2, lineWidth?: number | null): Path;
|
58
|
+
static fromRenderable(renderable: RenderablePathSpec): Path;
|
59
|
+
toRenderable(fill: RenderingStyle): RenderablePathSpec;
|
60
|
+
/**
|
61
|
+
* @returns a Path that, when rendered, looks roughly equivalent to the given path.
|
62
|
+
*/
|
63
|
+
static visualEquivalent(renderablePath: RenderablePathSpec, visibleRect: Rect2): RenderablePathSpec;
|
64
|
+
private cachedStringVersion;
|
65
|
+
toString(useNonAbsCommands?: boolean): string;
|
66
|
+
serialize(): string;
|
67
|
+
static toString(startPoint: Point2, parts: PathCommand[], onlyAbsCommands?: boolean): string;
|
68
|
+
static fromString(pathString: string): Path;
|
69
|
+
static empty: Path;
|
70
|
+
}
|
71
|
+
export {};
|