js-draw 0.23.1 → 0.24.1
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/README.md +2 -2
- package/build-config.json +23 -0
- package/dist/bundle.js +3 -3
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Color4.js +263 -0
- package/dist/cjs/Editor.d.ts +328 -0
- package/dist/cjs/Editor.js +1058 -0
- package/dist/cjs/EditorImage.d.ts +97 -0
- package/dist/cjs/EditorImage.js +531 -0
- package/dist/cjs/EventDispatcher.d.ts +29 -0
- package/dist/cjs/EventDispatcher.js +58 -0
- package/dist/cjs/Pointer.d.ts +37 -0
- package/dist/cjs/Pointer.js +123 -0
- package/dist/cjs/SVGLoader.d.ts +48 -0
- package/dist/cjs/SVGLoader.js +667 -0
- package/dist/cjs/SVGLoader.test.d.ts +1 -0
- package/dist/cjs/UndoRedoHistory.js +105 -0
- package/dist/cjs/UndoRedoHistory.test.d.ts +1 -0
- package/dist/cjs/Viewport.d.ts +73 -0
- package/dist/cjs/Viewport.js +307 -0
- package/dist/cjs/bundle/bundled.js +21 -0
- package/dist/cjs/commands/Command.js +61 -0
- package/dist/cjs/commands/Duplicate.js +80 -0
- package/dist/cjs/commands/Erase.js +101 -0
- package/dist/cjs/commands/SerializableCommand.js +57 -0
- package/dist/cjs/commands/UnresolvedCommand.js +43 -0
- package/dist/cjs/commands/invertCommand.js +77 -0
- package/dist/cjs/commands/lib.js +15 -0
- package/dist/cjs/commands/localization.d.ts +23 -0
- package/dist/cjs/commands/localization.js +24 -0
- package/dist/cjs/commands/uniteCommands.js +152 -0
- package/dist/cjs/commands/uniteCommands.test.d.ts +1 -0
- package/dist/cjs/components/AbstractComponent.d.ts +85 -0
- package/dist/cjs/components/AbstractComponent.js +300 -0
- package/dist/cjs/components/AbstractComponent.transformBy.test.d.ts +1 -0
- package/dist/cjs/components/BackgroundComponent.d.ts +62 -0
- package/dist/cjs/components/BackgroundComponent.js +311 -0
- package/dist/cjs/components/BackgroundComponent.test.d.ts +1 -0
- package/dist/cjs/components/ImageComponent.d.ts +31 -0
- package/dist/cjs/components/ImageComponent.js +228 -0
- package/dist/cjs/components/RestylableComponent.js +103 -0
- package/dist/cjs/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/cjs/components/SVGGlobalAttributesObject.js +82 -0
- package/dist/cjs/components/Stroke.d.ts +76 -0
- package/dist/cjs/components/Stroke.js +271 -0
- package/dist/cjs/components/Stroke.test.d.ts +1 -0
- package/dist/cjs/components/TextComponent.d.ts +79 -0
- package/dist/cjs/components/TextComponent.js +411 -0
- package/dist/cjs/components/TextComponent.test.d.ts +1 -0
- package/dist/cjs/components/UnknownSVGObject.d.ts +18 -0
- package/dist/cjs/components/UnknownSVGObject.js +65 -0
- package/dist/cjs/components/UnknownSVGObject.test.d.ts +1 -0
- package/dist/cjs/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/cjs/components/builders/ArrowBuilder.js +93 -0
- package/dist/cjs/components/builders/CircleBuilder.d.ts +2 -0
- package/dist/cjs/components/builders/CircleBuilder.js +74 -0
- package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/cjs/components/builders/FreehandLineBuilder.js +183 -0
- package/dist/cjs/components/builders/FreehandLineBuilder.test.d.ts +1 -0
- package/dist/cjs/components/builders/LineBuilder.d.ts +18 -0
- package/dist/cjs/components/builders/LineBuilder.js +65 -0
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +351 -0
- package/dist/cjs/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/cjs/components/builders/RectangleBuilder.js +58 -0
- package/dist/cjs/components/builders/types.d.ts +12 -0
- package/dist/cjs/components/lib.d.ts +14 -0
- package/dist/cjs/components/lib.js +42 -0
- package/dist/cjs/components/localization.js +14 -0
- package/dist/cjs/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/cjs/components/util/StrokeSmoother.js +225 -0
- package/dist/cjs/components/util/describeComponentList.d.ts +4 -0
- package/dist/cjs/components/util/describeComponentList.js +17 -0
- package/dist/cjs/lib.d.ts +66 -0
- package/dist/cjs/lib.js +94 -0
- package/dist/cjs/localization.js +24 -0
- package/dist/cjs/localizations/de.js +17 -0
- package/dist/cjs/localizations/en.js +17 -0
- package/dist/cjs/localizations/es.js +31 -0
- package/dist/cjs/localizations/getLocalizationTable.d.ts +17 -0
- package/dist/cjs/localizations/getLocalizationTable.js +65 -0
- package/dist/cjs/localizations/getLocalizationTable.test.d.ts +1 -0
- package/dist/cjs/math/Mat33.d.ts +123 -0
- package/dist/cjs/math/Mat33.js +340 -0
- package/dist/cjs/math/Mat33.test.d.ts +1 -0
- package/dist/cjs/math/Vec2.js +37 -0
- package/dist/cjs/math/Vec2.test.d.ts +1 -0
- package/dist/cjs/math/Vec3.js +183 -0
- package/dist/cjs/math/Vec3.test.d.ts +1 -0
- package/dist/cjs/math/lib.d.ts +7 -0
- package/dist/cjs/math/lib.js +15 -0
- package/dist/cjs/math/polynomial/solveQuadratic.d.ts +9 -0
- package/dist/cjs/math/polynomial/solveQuadratic.js +39 -0
- package/dist/cjs/math/polynomial/solveQuadratic.test.d.ts +1 -0
- package/dist/cjs/math/rounding.js +140 -0
- package/dist/cjs/math/rounding.test.d.ts +1 -0
- package/dist/cjs/math/shapes/Abstract2DShape.d.ts +49 -0
- package/dist/cjs/math/shapes/Abstract2DShape.js +42 -0
- package/dist/cjs/math/shapes/BezierJSWrapper.d.ts +36 -0
- package/dist/cjs/math/shapes/BezierJSWrapper.js +109 -0
- package/dist/cjs/math/shapes/CubicBezier.d.ts +17 -0
- package/dist/cjs/math/shapes/CubicBezier.js +50 -0
- package/dist/cjs/math/shapes/LineSegment2.d.ts +70 -0
- package/dist/cjs/math/shapes/LineSegment2.js +204 -0
- package/dist/cjs/math/shapes/LineSegment2.test.d.ts +1 -0
- package/dist/cjs/math/shapes/Path.d.ts +93 -0
- package/dist/cjs/math/shapes/Path.fromString.test.d.ts +1 -0
- package/dist/cjs/math/shapes/Path.js +865 -0
- package/dist/cjs/math/shapes/Path.test.d.ts +1 -0
- package/dist/cjs/math/shapes/Path.toString.test.d.ts +1 -0
- package/dist/cjs/math/shapes/PointShape2D.d.ts +18 -0
- package/dist/cjs/math/shapes/PointShape2D.js +46 -0
- package/dist/cjs/math/shapes/QuadraticBezier.d.ts +34 -0
- package/dist/cjs/math/shapes/QuadraticBezier.js +133 -0
- package/dist/cjs/math/shapes/QuadraticBezier.test.d.ts +1 -0
- package/dist/cjs/math/shapes/Rect2.d.ts +57 -0
- package/dist/cjs/math/shapes/Rect2.js +311 -0
- package/dist/cjs/math/shapes/Rect2.test.d.ts +1 -0
- package/dist/cjs/math/shapes/Triangle.d.ts +46 -0
- package/dist/cjs/math/shapes/Triangle.js +148 -0
- package/dist/cjs/math/shapes/Triangle.test.d.ts +1 -0
- package/dist/cjs/rendering/Display.js +222 -0
- package/dist/cjs/rendering/RenderingStyle.d.ts +31 -0
- package/dist/cjs/rendering/RenderingStyle.js +56 -0
- package/dist/cjs/rendering/RenderingStyle.test.d.ts +1 -0
- package/dist/cjs/rendering/TextRenderingStyle.d.ts +43 -0
- package/dist/cjs/rendering/TextRenderingStyle.js +40 -0
- package/dist/cjs/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/cjs/rendering/caching/CacheRecord.js +59 -0
- package/dist/cjs/rendering/caching/CacheRecord.test.d.ts +1 -0
- package/dist/cjs/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/cjs/rendering/caching/CacheRecordManager.js +48 -0
- package/dist/cjs/rendering/caching/RenderingCache.js +50 -0
- package/dist/cjs/rendering/caching/RenderingCache.test.d.ts +1 -0
- package/dist/cjs/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/cjs/rendering/caching/RenderingCacheNode.js +340 -0
- package/dist/cjs/rendering/caching/testUtils.js +34 -0
- package/dist/cjs/rendering/lib.js +14 -0
- package/dist/cjs/rendering/localization.js +12 -0
- package/dist/cjs/rendering/renderers/AbstractRenderer.d.ts +85 -0
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +168 -0
- package/dist/cjs/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +263 -0
- package/dist/cjs/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/cjs/rendering/renderers/DummyRenderer.js +132 -0
- package/dist/cjs/rendering/renderers/DummyRenderer.test.d.ts +1 -0
- package/dist/cjs/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/cjs/rendering/renderers/SVGRenderer.js +355 -0
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +89 -0
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.test.d.ts +1 -0
- package/dist/cjs/shortcuts/KeyBinding.d.ts +46 -0
- package/dist/cjs/shortcuts/KeyBinding.js +157 -0
- package/dist/cjs/shortcuts/KeyBinding.test.d.ts +1 -0
- package/dist/cjs/shortcuts/KeyboardShortcutManager.d.ts +77 -0
- package/dist/cjs/shortcuts/KeyboardShortcutManager.js +148 -0
- package/dist/cjs/shortcuts/KeyboardShortcutManager.test.d.ts +1 -0
- package/dist/cjs/shortcuts/lib.d.ts +2 -0
- package/dist/cjs/shortcuts/lib.js +7 -0
- package/dist/cjs/testing/createEditor.js +11 -0
- package/dist/cjs/testing/lib.js +7 -0
- package/dist/cjs/testing/sendPenEvent.js +21 -0
- package/dist/cjs/testing/sendTouchEvent.js +73 -0
- package/dist/cjs/toolbar/HTMLToolbar.js +465 -0
- package/dist/cjs/toolbar/IconProvider.js +274 -0
- package/dist/cjs/toolbar/lib.js +21 -0
- package/dist/cjs/toolbar/localization.d.ts +52 -0
- package/dist/cjs/toolbar/localization.js +54 -0
- package/dist/cjs/toolbar/makeColorInput.js +125 -0
- package/dist/cjs/toolbar/widgets/ActionButtonWidget.js +47 -0
- package/dist/cjs/toolbar/widgets/BaseToolWidget.js +64 -0
- package/dist/cjs/toolbar/widgets/BaseWidget.js +359 -0
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +196 -0
- package/dist/cjs/toolbar/widgets/EraserToolWidget.js +90 -0
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +211 -0
- package/dist/cjs/toolbar/widgets/InsertImageWidget.js +246 -0
- package/dist/cjs/toolbar/widgets/OverflowWidget.js +103 -0
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +264 -0
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +213 -0
- package/dist/cjs/toolbar/widgets/TextToolWidget.js +142 -0
- package/dist/cjs/toolbar/widgets/keybindings.d.ts +2 -0
- package/dist/cjs/toolbar/widgets/keybindings.js +13 -0
- package/dist/cjs/toolbar/widgets/lib.js +23 -0
- package/dist/cjs/tools/BaseTool.js +67 -0
- package/dist/cjs/tools/Eraser.d.ts +24 -0
- package/dist/cjs/tools/Eraser.js +148 -0
- package/dist/cjs/tools/Eraser.test.d.ts +1 -0
- package/dist/cjs/tools/FindTool.d.ts +20 -0
- package/dist/cjs/tools/FindTool.js +137 -0
- package/dist/cjs/tools/PanZoom.d.ts +52 -0
- package/dist/cjs/tools/PanZoom.js +471 -0
- package/dist/cjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/cjs/tools/PasteHandler.js +179 -0
- package/dist/cjs/tools/Pen.d.ts +41 -0
- package/dist/cjs/tools/Pen.js +238 -0
- package/dist/cjs/tools/Pen.test.d.ts +1 -0
- package/dist/cjs/tools/PipetteTool.js +63 -0
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +44 -0
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/cjs/tools/SelectionTool/Selection.js +602 -0
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +86 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +37 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +441 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/cjs/tools/SelectionTool/TransformMode.js +107 -0
- package/dist/cjs/tools/SelectionTool/types.js +14 -0
- package/dist/cjs/tools/SoundUITool.js +182 -0
- package/dist/cjs/tools/TextTool.d.ts +34 -0
- package/dist/cjs/tools/TextTool.js +284 -0
- package/dist/cjs/tools/ToolController.js +179 -0
- package/dist/cjs/tools/ToolEnabledGroup.js +16 -0
- package/dist/cjs/tools/ToolSwitcherShortcut.js +54 -0
- package/dist/cjs/tools/ToolbarShortcutHandler.js +50 -0
- package/dist/cjs/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/cjs/tools/UndoRedoShortcut.js +42 -0
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/cjs/tools/keybindings.d.ts +17 -0
- package/dist/cjs/tools/keybindings.js +44 -0
- package/dist/cjs/tools/lib.js +35 -0
- package/dist/cjs/tools/localization.js +33 -0
- package/dist/cjs/types.d.ts +154 -0
- package/dist/cjs/types.js +38 -0
- package/dist/cjs/util/assertions.js +54 -0
- package/dist/cjs/util/fileToBase64.js +15 -0
- package/dist/cjs/util/untilNextAnimationFrame.js +9 -0
- package/dist/cjs/util/waitForAll.js +17 -0
- package/dist/cjs/util/waitForTimeout.js +9 -0
- package/dist/mjs/Color4.mjs +260 -0
- package/dist/mjs/Color4.test.d.ts +1 -0
- package/dist/mjs/Editor.d.ts +328 -0
- package/dist/mjs/Editor.loadFrom.test.d.ts +1 -0
- package/dist/mjs/Editor.mjs +1055 -0
- package/dist/mjs/Editor.toSVG.test.d.ts +1 -0
- package/dist/mjs/EditorImage.d.ts +97 -0
- package/dist/mjs/EditorImage.mjs +527 -0
- package/dist/mjs/EditorImage.test.d.ts +1 -0
- package/dist/mjs/EventDispatcher.d.ts +29 -0
- package/dist/mjs/EventDispatcher.mjs +56 -0
- package/dist/mjs/EventDispatcher.test.d.ts +1 -0
- package/dist/mjs/Pointer.d.ts +37 -0
- package/dist/mjs/Pointer.mjs +120 -0
- package/dist/mjs/SVGLoader.d.ts +48 -0
- package/dist/mjs/SVGLoader.mjs +664 -0
- package/dist/mjs/SVGLoader.test.d.ts +1 -0
- package/dist/mjs/UndoRedoHistory.mjs +103 -0
- package/dist/mjs/UndoRedoHistory.test.d.ts +1 -0
- package/dist/mjs/Viewport.d.ts +73 -0
- package/dist/mjs/Viewport.mjs +304 -0
- package/dist/mjs/commands/Command.mjs +58 -0
- package/dist/mjs/commands/Duplicate.mjs +78 -0
- package/dist/mjs/commands/Erase.mjs +99 -0
- package/dist/mjs/commands/SerializableCommand.mjs +55 -0
- package/dist/mjs/commands/UnresolvedCommand.mjs +41 -0
- package/dist/mjs/commands/invertCommand.mjs +75 -0
- package/dist/mjs/commands/localization.d.ts +23 -0
- package/dist/mjs/commands/localization.mjs +21 -0
- package/dist/mjs/commands/uniteCommands.mjs +150 -0
- package/dist/mjs/commands/uniteCommands.test.d.ts +1 -0
- package/dist/mjs/components/AbstractComponent.d.ts +85 -0
- package/dist/mjs/components/AbstractComponent.mjs +298 -0
- package/dist/mjs/components/AbstractComponent.transformBy.test.d.ts +1 -0
- package/dist/mjs/components/BackgroundComponent.d.ts +62 -0
- package/dist/mjs/components/BackgroundComponent.mjs +308 -0
- package/dist/mjs/components/BackgroundComponent.test.d.ts +1 -0
- package/dist/mjs/components/ImageComponent.d.ts +31 -0
- package/dist/mjs/components/ImageComponent.mjs +226 -0
- package/dist/mjs/components/RestylableComponent.mjs +98 -0
- package/dist/mjs/components/SVGGlobalAttributesObject.d.ts +21 -0
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +80 -0
- package/dist/mjs/components/Stroke.d.ts +76 -0
- package/dist/mjs/components/Stroke.mjs +269 -0
- package/dist/mjs/components/Stroke.test.d.ts +1 -0
- package/dist/mjs/components/TextComponent.d.ts +79 -0
- package/dist/mjs/components/TextComponent.mjs +408 -0
- package/dist/mjs/components/TextComponent.test.d.ts +1 -0
- package/dist/mjs/components/UnknownSVGObject.d.ts +18 -0
- package/dist/mjs/components/UnknownSVGObject.mjs +63 -0
- package/dist/mjs/components/UnknownSVGObject.test.d.ts +1 -0
- package/dist/mjs/components/builders/ArrowBuilder.d.ts +19 -0
- package/dist/mjs/components/builders/ArrowBuilder.mjs +89 -0
- package/dist/mjs/components/builders/CircleBuilder.d.ts +2 -0
- package/dist/mjs/components/builders/CircleBuilder.mjs +70 -0
- package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +33 -0
- package/dist/mjs/components/builders/FreehandLineBuilder.mjs +179 -0
- package/dist/mjs/components/builders/FreehandLineBuilder.test.d.ts +1 -0
- package/dist/mjs/components/builders/LineBuilder.d.ts +18 -0
- package/dist/mjs/components/builders/LineBuilder.mjs +61 -0
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +347 -0
- package/dist/mjs/components/builders/RectangleBuilder.d.ts +20 -0
- package/dist/mjs/components/builders/RectangleBuilder.mjs +53 -0
- package/dist/mjs/components/builders/types.d.ts +12 -0
- package/dist/mjs/components/builders/types.mjs +1 -0
- package/dist/mjs/components/lib.d.ts +14 -0
- package/dist/mjs/components/lib.mjs +15 -0
- package/dist/mjs/components/localization.mjs +11 -0
- package/dist/mjs/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/mjs/components/util/StrokeSmoother.mjs +222 -0
- package/dist/mjs/components/util/describeComponentList.d.ts +4 -0
- package/dist/mjs/components/util/describeComponentList.mjs +15 -0
- package/dist/mjs/lib.d.ts +66 -0
- package/dist/mjs/lib.mjs +66 -0
- package/dist/mjs/localization.mjs +21 -0
- package/dist/mjs/localizations/de.mjs +15 -0
- package/dist/mjs/localizations/en.mjs +15 -0
- package/dist/mjs/localizations/es.mjs +29 -0
- package/dist/mjs/localizations/getLocalizationTable.d.ts +17 -0
- package/dist/mjs/localizations/getLocalizationTable.mjs +61 -0
- package/dist/mjs/localizations/getLocalizationTable.test.d.ts +1 -0
- package/dist/mjs/math/Mat33.d.ts +123 -0
- package/dist/mjs/math/Mat33.mjs +338 -0
- package/dist/mjs/math/Mat33.test.d.ts +1 -0
- package/dist/mjs/math/Vec2.mjs +34 -0
- package/dist/mjs/math/Vec2.test.d.ts +1 -0
- package/dist/mjs/math/Vec3.mjs +181 -0
- package/dist/mjs/math/Vec3.test.d.ts +1 -0
- package/dist/mjs/math/lib.d.ts +7 -0
- package/dist/mjs/math/lib.mjs +7 -0
- package/dist/mjs/math/polynomial/solveQuadratic.d.ts +9 -0
- package/dist/mjs/math/polynomial/solveQuadratic.mjs +37 -0
- package/dist/mjs/math/polynomial/solveQuadratic.test.d.ts +1 -0
- package/dist/mjs/math/rounding.mjs +133 -0
- package/dist/mjs/math/rounding.test.d.ts +1 -0
- package/dist/mjs/math/shapes/Abstract2DShape.d.ts +49 -0
- package/dist/mjs/math/shapes/Abstract2DShape.mjs +40 -0
- package/dist/mjs/math/shapes/BezierJSWrapper.d.ts +36 -0
- package/dist/mjs/math/shapes/BezierJSWrapper.mjs +107 -0
- package/dist/mjs/math/shapes/CubicBezier.d.ts +17 -0
- package/dist/mjs/math/shapes/CubicBezier.mjs +48 -0
- package/dist/mjs/math/shapes/LineSegment2.d.ts +70 -0
- package/dist/mjs/math/shapes/LineSegment2.mjs +202 -0
- package/dist/mjs/math/shapes/LineSegment2.test.d.ts +1 -0
- package/dist/mjs/math/shapes/Path.d.ts +93 -0
- package/dist/mjs/math/shapes/Path.fromString.test.d.ts +1 -0
- package/dist/mjs/math/shapes/Path.mjs +862 -0
- package/dist/mjs/math/shapes/Path.test.d.ts +1 -0
- package/dist/mjs/math/shapes/Path.toString.test.d.ts +1 -0
- package/dist/mjs/math/shapes/PointShape2D.d.ts +18 -0
- package/dist/mjs/math/shapes/PointShape2D.mjs +44 -0
- package/dist/mjs/math/shapes/QuadraticBezier.d.ts +34 -0
- package/dist/mjs/math/shapes/QuadraticBezier.mjs +131 -0
- package/dist/mjs/math/shapes/QuadraticBezier.test.d.ts +1 -0
- package/dist/mjs/math/shapes/Rect2.d.ts +57 -0
- package/dist/mjs/math/shapes/Rect2.mjs +309 -0
- package/dist/mjs/math/shapes/Rect2.test.d.ts +1 -0
- package/dist/mjs/math/shapes/Triangle.d.ts +46 -0
- package/dist/mjs/math/shapes/Triangle.mjs +146 -0
- package/dist/mjs/math/shapes/Triangle.test.d.ts +1 -0
- package/dist/mjs/rendering/Display.mjs +219 -0
- package/dist/mjs/rendering/RenderingStyle.d.ts +31 -0
- package/dist/mjs/rendering/RenderingStyle.mjs +49 -0
- package/dist/mjs/rendering/RenderingStyle.test.d.ts +1 -0
- package/dist/mjs/rendering/TextRenderingStyle.d.ts +43 -0
- package/dist/mjs/rendering/TextRenderingStyle.mjs +34 -0
- package/dist/mjs/rendering/caching/CacheRecord.d.ts +20 -0
- package/dist/mjs/rendering/caching/CacheRecord.mjs +57 -0
- package/dist/mjs/rendering/caching/CacheRecord.test.d.ts +1 -0
- package/dist/mjs/rendering/caching/CacheRecordManager.d.ts +12 -0
- package/dist/mjs/rendering/caching/CacheRecordManager.mjs +45 -0
- package/dist/mjs/rendering/caching/RenderingCache.mjs +48 -0
- package/dist/mjs/rendering/caching/RenderingCache.test.d.ts +1 -0
- package/dist/mjs/rendering/caching/RenderingCacheNode.d.ts +29 -0
- package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +338 -0
- package/dist/mjs/rendering/caching/testUtils.mjs +30 -0
- package/dist/mjs/rendering/caching/types.mjs +1 -0
- package/dist/mjs/rendering/localization.mjs +9 -0
- package/dist/mjs/rendering/renderers/AbstractRenderer.d.ts +85 -0
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +166 -0
- package/dist/mjs/rendering/renderers/CanvasRenderer.d.ts +63 -0
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +261 -0
- package/dist/mjs/rendering/renderers/DummyRenderer.d.ts +35 -0
- package/dist/mjs/rendering/renderers/DummyRenderer.mjs +130 -0
- package/dist/mjs/rendering/renderers/DummyRenderer.test.d.ts +1 -0
- package/dist/mjs/rendering/renderers/SVGRenderer.d.ts +57 -0
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +352 -0
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +87 -0
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.test.d.ts +1 -0
- package/dist/mjs/shortcuts/KeyBinding.d.ts +46 -0
- package/dist/mjs/shortcuts/KeyBinding.mjs +155 -0
- package/dist/mjs/shortcuts/KeyBinding.test.d.ts +1 -0
- package/dist/mjs/shortcuts/KeyboardShortcutManager.d.ts +77 -0
- package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +146 -0
- package/dist/mjs/shortcuts/KeyboardShortcutManager.test.d.ts +1 -0
- package/dist/mjs/shortcuts/lib.d.ts +2 -0
- package/dist/mjs/shortcuts/lib.mjs +2 -0
- package/dist/mjs/testing/createEditor.mjs +9 -0
- package/dist/mjs/testing/sendPenEvent.mjs +19 -0
- package/dist/mjs/testing/sendTouchEvent.mjs +71 -0
- package/dist/mjs/toolbar/HTMLToolbar.mjs +462 -0
- package/dist/mjs/toolbar/IconProvider.mjs +272 -0
- package/dist/mjs/toolbar/localization.d.ts +52 -0
- package/dist/mjs/toolbar/localization.mjs +51 -0
- package/dist/mjs/toolbar/makeColorInput.mjs +121 -0
- package/dist/mjs/toolbar/types.mjs +1 -0
- package/dist/mjs/toolbar/widgets/ActionButtonWidget.mjs +45 -0
- package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +62 -0
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +357 -0
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +194 -0
- package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +88 -0
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +209 -0
- package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +244 -0
- package/dist/mjs/toolbar/widgets/OverflowWidget.mjs +101 -0
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +262 -0
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +211 -0
- package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +140 -0
- package/dist/mjs/toolbar/widgets/keybindings.d.ts +2 -0
- package/dist/mjs/toolbar/widgets/keybindings.mjs +10 -0
- package/dist/mjs/tools/BaseTool.mjs +65 -0
- package/dist/mjs/tools/Eraser.d.ts +24 -0
- package/dist/mjs/tools/Eraser.mjs +146 -0
- package/dist/mjs/tools/Eraser.test.d.ts +1 -0
- package/dist/mjs/tools/FindTool.d.ts +20 -0
- package/dist/mjs/tools/FindTool.mjs +135 -0
- package/dist/mjs/tools/PanZoom.d.ts +52 -0
- package/dist/mjs/tools/PanZoom.mjs +468 -0
- package/dist/mjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/mjs/tools/PasteHandler.mjs +177 -0
- package/dist/mjs/tools/Pen.d.ts +41 -0
- package/dist/mjs/tools/Pen.mjs +236 -0
- package/dist/mjs/tools/Pen.test.d.ts +1 -0
- package/dist/mjs/tools/PipetteTool.mjs +61 -0
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +42 -0
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +64 -0
- package/dist/mjs/tools/SelectionTool/Selection.mjs +600 -0
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +83 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +37 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +438 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +104 -0
- package/dist/mjs/tools/SoundUITool.mjs +180 -0
- package/dist/mjs/tools/TextTool.d.ts +34 -0
- package/dist/mjs/tools/TextTool.mjs +282 -0
- package/dist/mjs/tools/ToolController.mjs +177 -0
- package/dist/mjs/tools/ToolEnabledGroup.mjs +14 -0
- package/dist/mjs/tools/ToolSwitcherShortcut.mjs +52 -0
- package/dist/mjs/tools/ToolbarShortcutHandler.mjs +48 -0
- package/dist/mjs/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/mjs/tools/UndoRedoShortcut.mjs +40 -0
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/mjs/tools/keybindings.d.ts +17 -0
- package/dist/mjs/tools/keybindings.mjs +41 -0
- package/dist/mjs/tools/localization.mjs +30 -0
- package/dist/mjs/types.d.ts +154 -0
- package/dist/mjs/util/assertions.mjs +48 -0
- package/dist/mjs/util/fileToBase64.mjs +13 -0
- package/dist/mjs/util/untilNextAnimationFrame.mjs +7 -0
- package/dist/mjs/util/waitForAll.mjs +15 -0
- package/dist/mjs/util/waitForTimeout.mjs +7 -0
- package/dist-test/test_imports/package-lock.json +13 -0
- package/dist-test/test_imports/package.json +12 -0
- package/dist-test/test_imports/test-imports.js +17 -0
- package/dist-test/test_imports/test-require.cjs +19 -0
- package/package.json +99 -124
- package/src/Color4.test.ts +47 -0
- package/src/Color4.ts +304 -0
- package/src/Editor.loadFrom.test.ts +24 -0
- package/src/Editor.toSVG.test.ts +111 -0
- package/src/Editor.ts +1171 -0
- package/src/EditorImage.test.ts +120 -0
- package/src/EditorImage.ts +603 -0
- package/src/EventDispatcher.test.ts +123 -0
- package/src/EventDispatcher.ts +72 -0
- package/src/Pointer.ts +167 -0
- package/src/SVGLoader.test.ts +114 -0
- package/src/SVGLoader.ts +610 -0
- package/src/UndoRedoHistory.test.ts +33 -0
- package/src/UndoRedoHistory.ts +102 -0
- package/src/Viewport.ts +325 -0
- package/src/bundle/bundled.ts +7 -0
- package/src/commands/Command.ts +45 -0
- package/src/commands/Duplicate.ts +75 -0
- package/src/commands/Erase.ts +94 -0
- package/src/commands/SerializableCommand.ts +49 -0
- package/src/commands/UnresolvedCommand.ts +37 -0
- package/src/commands/invertCommand.ts +58 -0
- package/src/commands/lib.ts +16 -0
- package/src/commands/localization.ts +47 -0
- package/src/commands/uniteCommands.test.ts +23 -0
- package/src/commands/uniteCommands.ts +140 -0
- package/src/components/AbstractComponent.transformBy.test.ts +22 -0
- package/src/components/AbstractComponent.ts +374 -0
- package/src/components/BackgroundComponent.test.ts +45 -0
- package/src/components/BackgroundComponent.ts +353 -0
- package/src/components/ImageComponent.ts +178 -0
- package/src/components/RestylableComponent.ts +161 -0
- package/src/components/SVGGlobalAttributesObject.ts +81 -0
- package/src/components/Stroke.test.ts +139 -0
- package/src/components/Stroke.ts +296 -0
- package/src/components/TextComponent.test.ts +204 -0
- package/src/components/TextComponent.ts +432 -0
- package/src/components/UnknownSVGObject.test.ts +10 -0
- package/src/components/UnknownSVGObject.ts +60 -0
- package/src/components/builders/ArrowBuilder.ts +107 -0
- package/src/components/builders/CircleBuilder.ts +102 -0
- package/src/components/builders/FreehandLineBuilder.test.ts +25 -0
- package/src/components/builders/FreehandLineBuilder.ts +212 -0
- package/src/components/builders/LineBuilder.ts +77 -0
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +454 -0
- package/src/components/builders/RectangleBuilder.ts +74 -0
- package/src/components/builders/types.ts +15 -0
- package/src/components/lib.ts +31 -0
- package/src/components/localization.ts +24 -0
- package/src/components/util/StrokeSmoother.ts +302 -0
- package/src/components/util/describeComponentList.ts +18 -0
- package/src/lib.ts +69 -0
- package/src/localization.ts +34 -0
- package/src/localizations/de.ts +146 -0
- package/src/localizations/en.ts +8 -0
- package/src/localizations/es.ts +74 -0
- package/src/localizations/getLocalizationTable.test.ts +27 -0
- package/src/localizations/getLocalizationTable.ts +74 -0
- package/src/math/Mat33.test.ts +244 -0
- package/src/math/Mat33.ts +442 -0
- package/src/math/Vec2.test.ts +30 -0
- package/src/math/Vec2.ts +40 -0
- package/src/math/Vec3.test.ts +44 -0
- package/src/math/Vec3.ts +218 -0
- package/src/math/lib.ts +15 -0
- package/src/math/polynomial/solveQuadratic.test.ts +39 -0
- package/src/math/polynomial/solveQuadratic.ts +43 -0
- package/src/math/rounding.test.ts +65 -0
- package/src/math/rounding.ts +156 -0
- package/src/math/shapes/Abstract2DShape.ts +63 -0
- package/src/math/shapes/BezierJSWrapper.ts +93 -0
- package/src/math/shapes/CubicBezier.ts +35 -0
- package/src/math/shapes/LineSegment2.test.ts +99 -0
- package/src/math/shapes/LineSegment2.ts +231 -0
- package/src/math/shapes/Path.fromString.test.ts +223 -0
- package/src/math/shapes/Path.test.ts +309 -0
- package/src/math/shapes/Path.toString.test.ts +77 -0
- package/src/math/shapes/Path.ts +1027 -0
- package/src/math/shapes/PointShape2D.ts +33 -0
- package/src/math/shapes/QuadraticBezier.test.ts +31 -0
- package/src/math/shapes/QuadraticBezier.ts +141 -0
- package/src/math/shapes/Rect2.test.ts +209 -0
- package/src/math/shapes/Rect2.ts +344 -0
- package/src/math/shapes/Triangle.test.ts +61 -0
- package/src/math/shapes/Triangle.ts +139 -0
- package/src/rendering/Display.ts +248 -0
- package/src/rendering/RenderingStyle.test.ts +68 -0
- package/src/rendering/RenderingStyle.ts +55 -0
- package/src/rendering/TextRenderingStyle.ts +55 -0
- package/src/rendering/caching/CacheRecord.test.ts +49 -0
- package/src/rendering/caching/CacheRecord.ts +77 -0
- package/src/rendering/caching/CacheRecordManager.ts +71 -0
- package/src/rendering/caching/RenderingCache.test.ts +44 -0
- package/src/rendering/caching/RenderingCache.ts +66 -0
- package/src/rendering/caching/RenderingCacheNode.ts +405 -0
- package/src/rendering/caching/testUtils.ts +35 -0
- package/src/rendering/caching/types.ts +34 -0
- package/src/rendering/lib.ts +8 -0
- package/src/rendering/localization.ts +20 -0
- package/src/rendering/renderers/AbstractRenderer.ts +242 -0
- package/src/rendering/renderers/CanvasRenderer.ts +305 -0
- package/src/rendering/renderers/DummyRenderer.test.ts +42 -0
- package/src/rendering/renderers/DummyRenderer.ts +145 -0
- package/src/rendering/renderers/SVGRenderer.ts +374 -0
- package/src/rendering/renderers/TextOnlyRenderer.test.ts +34 -0
- package/src/rendering/renderers/TextOnlyRenderer.ts +71 -0
- package/src/shortcuts/KeyBinding.test.ts +51 -0
- package/src/shortcuts/KeyBinding.ts +218 -0
- package/src/shortcuts/KeyboardShortcutManager.test.ts +95 -0
- package/src/shortcuts/KeyboardShortcutManager.ts +163 -0
- package/src/shortcuts/lib.ts +3 -0
- package/src/testing/createEditor.ts +11 -0
- package/src/testing/lib.ts +3 -0
- package/src/testing/sendPenEvent.ts +31 -0
- package/src/testing/sendTouchEvent.ts +78 -0
- package/src/toolbar/HTMLToolbar.ts +567 -0
- package/src/toolbar/IconProvider.ts +736 -0
- package/src/toolbar/lib.ts +4 -0
- package/src/toolbar/localization.ts +114 -0
- package/src/toolbar/makeColorInput.ts +159 -0
- package/src/toolbar/types.ts +5 -0
- package/src/toolbar/widgets/ActionButtonWidget.ts +39 -0
- package/src/toolbar/widgets/BaseToolWidget.ts +56 -0
- package/src/toolbar/widgets/BaseWidget.ts +428 -0
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +234 -0
- package/src/toolbar/widgets/EraserToolWidget.ts +85 -0
- package/src/toolbar/widgets/HandToolWidget.ts +250 -0
- package/src/toolbar/widgets/InsertImageWidget.ts +223 -0
- package/src/toolbar/widgets/OverflowWidget.ts +92 -0
- package/src/toolbar/widgets/PenToolWidget.ts +297 -0
- package/src/toolbar/widgets/SelectionToolWidget.ts +193 -0
- package/src/toolbar/widgets/TextToolWidget.ts +145 -0
- package/src/toolbar/widgets/keybindings.ts +21 -0
- package/src/toolbar/widgets/lib.ts +13 -0
- package/src/tools/BaseTool.ts +76 -0
- package/src/tools/Eraser.test.ts +103 -0
- package/src/tools/Eraser.ts +160 -0
- package/src/tools/FindTool.ts +153 -0
- package/src/tools/PanZoom.test.ts +349 -0
- package/src/tools/PanZoom.ts +502 -0
- package/src/tools/PasteHandler.ts +95 -0
- package/src/tools/Pen.test.ts +194 -0
- package/src/tools/Pen.ts +262 -0
- package/src/tools/PipetteTool.ts +55 -0
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +29 -0
- package/src/tools/SelectionTool/Selection.ts +611 -0
- package/src/tools/SelectionTool/SelectionHandle.ts +108 -0
- package/src/tools/SelectionTool/SelectionTool.test.ts +261 -0
- package/src/tools/SelectionTool/SelectionTool.ts +496 -0
- package/src/tools/SelectionTool/TransformMode.ts +114 -0
- package/src/tools/SelectionTool/types.ts +11 -0
- package/src/tools/SoundUITool.ts +212 -0
- package/src/tools/TextTool.ts +340 -0
- package/src/tools/ToolController.ts +185 -0
- package/src/tools/ToolEnabledGroup.ts +14 -0
- package/src/tools/ToolSwitcherShortcut.ts +39 -0
- package/src/tools/ToolbarShortcutHandler.ts +39 -0
- package/src/tools/UndoRedoShortcut.test.ts +56 -0
- package/src/tools/UndoRedoShortcut.ts +24 -0
- package/src/tools/keybindings.ts +85 -0
- package/src/tools/lib.ts +22 -0
- package/src/tools/localization.ts +74 -0
- package/src/types.ts +239 -0
- package/src/util/assertions.ts +55 -0
- package/src/util/fileToBase64.ts +18 -0
- package/src/util/untilNextAnimationFrame.ts +9 -0
- package/src/util/waitForAll.ts +18 -0
- package/src/util/waitForTimeout.ts +9 -0
- package/tools/allLocales.js +4 -0
- package/tools/copyREADME.ts +62 -0
- package/tsconfig.json +2 -32
- package/.eslintrc.js +0 -60
- package/.firebaserc +0 -5
- package/CHANGELOG.md +0 -390
- package/CONTRIBUTING.md +0 -75
- package/LICENSE +0 -21
- package/__mocks__/coloris.ts +0 -8
- package/__mocks__/styleMock.js +0 -1
- package/dist/cjs/src/Color4.js +0 -264
- package/dist/cjs/src/Editor.d.ts +0 -309
- package/dist/cjs/src/Editor.js +0 -922
- package/dist/cjs/src/EditorImage.d.ts +0 -97
- package/dist/cjs/src/EditorImage.js +0 -492
- package/dist/cjs/src/EventDispatcher.d.ts +0 -30
- package/dist/cjs/src/EventDispatcher.js +0 -57
- package/dist/cjs/src/Pointer.d.ts +0 -26
- package/dist/cjs/src/Pointer.js +0 -109
- package/dist/cjs/src/SVGLoader.d.ts +0 -48
- package/dist/cjs/src/SVGLoader.js +0 -537
- package/dist/cjs/src/UndoRedoHistory.js +0 -93
- package/dist/cjs/src/Viewport.d.ts +0 -73
- package/dist/cjs/src/Viewport.js +0 -268
- package/dist/cjs/src/bundle/bundled.js +0 -24
- package/dist/cjs/src/commands/Command.js +0 -34
- package/dist/cjs/src/commands/Duplicate.js +0 -65
- package/dist/cjs/src/commands/Erase.js +0 -83
- package/dist/cjs/src/commands/SerializableCommand.js +0 -42
- package/dist/cjs/src/commands/UnresolvedCommand.js +0 -28
- package/dist/cjs/src/commands/invertCommand.js +0 -55
- package/dist/cjs/src/commands/lib.js +0 -18
- package/dist/cjs/src/commands/localization.d.ts +0 -23
- package/dist/cjs/src/commands/localization.js +0 -24
- package/dist/cjs/src/commands/uniteCommands.js +0 -122
- package/dist/cjs/src/components/AbstractComponent.d.ts +0 -85
- package/dist/cjs/src/components/AbstractComponent.js +0 -273
- package/dist/cjs/src/components/BackgroundComponent.d.ts +0 -62
- package/dist/cjs/src/components/BackgroundComponent.js +0 -316
- package/dist/cjs/src/components/ImageComponent.d.ts +0 -31
- package/dist/cjs/src/components/ImageComponent.js +0 -157
- package/dist/cjs/src/components/RestylableComponent.js +0 -88
- package/dist/cjs/src/components/SVGGlobalAttributesObject.d.ts +0 -21
- package/dist/cjs/src/components/SVGGlobalAttributesObject.js +0 -65
- package/dist/cjs/src/components/Stroke.d.ts +0 -76
- package/dist/cjs/src/components/Stroke.js +0 -238
- package/dist/cjs/src/components/TextComponent.d.ts +0 -63
- package/dist/cjs/src/components/TextComponent.js +0 -280
- package/dist/cjs/src/components/UnknownSVGObject.d.ts +0 -18
- package/dist/cjs/src/components/UnknownSVGObject.js +0 -50
- package/dist/cjs/src/components/builders/ArrowBuilder.d.ts +0 -19
- package/dist/cjs/src/components/builders/ArrowBuilder.js +0 -117
- package/dist/cjs/src/components/builders/FreehandLineBuilder.d.ts +0 -33
- package/dist/cjs/src/components/builders/FreehandLineBuilder.js +0 -173
- package/dist/cjs/src/components/builders/LineBuilder.d.ts +0 -18
- package/dist/cjs/src/components/builders/LineBuilder.js +0 -89
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +0 -36
- package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.js +0 -347
- package/dist/cjs/src/components/builders/RectangleBuilder.d.ts +0 -20
- package/dist/cjs/src/components/builders/RectangleBuilder.js +0 -59
- package/dist/cjs/src/components/builders/types.d.ts +0 -12
- package/dist/cjs/src/components/lib.d.ts +0 -13
- package/dist/cjs/src/components/lib.js +0 -43
- package/dist/cjs/src/components/localization.js +0 -14
- package/dist/cjs/src/components/util/StrokeSmoother.d.ts +0 -35
- package/dist/cjs/src/components/util/StrokeSmoother.js +0 -225
- package/dist/cjs/src/components/util/describeComponentList.d.ts +0 -4
- package/dist/cjs/src/components/util/describeComponentList.js +0 -16
- package/dist/cjs/src/lib.d.ts +0 -64
- package/dist/cjs/src/lib.js +0 -93
- package/dist/cjs/src/localization.js +0 -13
- package/dist/cjs/src/localizations/de.js +0 -6
- package/dist/cjs/src/localizations/en.js +0 -6
- package/dist/cjs/src/localizations/es.js +0 -20
- package/dist/cjs/src/localizations/getLocalizationTable.d.ts +0 -3
- package/dist/cjs/src/localizations/getLocalizationTable.js +0 -50
- package/dist/cjs/src/math/LineSegment2.d.ts +0 -26
- package/dist/cjs/src/math/LineSegment2.js +0 -135
- package/dist/cjs/src/math/Mat33.d.ts +0 -118
- package/dist/cjs/src/math/Mat33.js +0 -332
- package/dist/cjs/src/math/Path.d.ts +0 -92
- package/dist/cjs/src/math/Path.js +0 -876
- package/dist/cjs/src/math/Rect2.d.ts +0 -52
- package/dist/cjs/src/math/Rect2.js +0 -235
- package/dist/cjs/src/math/Triangle.d.ts +0 -11
- package/dist/cjs/src/math/Triangle.js +0 -22
- package/dist/cjs/src/math/Vec2.js +0 -39
- package/dist/cjs/src/math/Vec3.js +0 -177
- package/dist/cjs/src/math/lib.d.ts +0 -7
- package/dist/cjs/src/math/lib.js +0 -18
- package/dist/cjs/src/math/polynomial/QuadraticBezier.d.ts +0 -28
- package/dist/cjs/src/math/polynomial/QuadraticBezier.js +0 -114
- package/dist/cjs/src/math/polynomial/solveQuadratic.d.ts +0 -6
- package/dist/cjs/src/math/polynomial/solveQuadratic.js +0 -36
- package/dist/cjs/src/math/rounding.js +0 -135
- package/dist/cjs/src/rendering/Display.js +0 -213
- package/dist/cjs/src/rendering/RenderingStyle.d.ts +0 -31
- package/dist/cjs/src/rendering/RenderingStyle.js +0 -48
- package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +0 -36
- package/dist/cjs/src/rendering/TextRenderingStyle.js +0 -29
- package/dist/cjs/src/rendering/caching/CacheRecord.d.ts +0 -20
- package/dist/cjs/src/rendering/caching/CacheRecord.js +0 -61
- package/dist/cjs/src/rendering/caching/CacheRecordManager.d.ts +0 -12
- package/dist/cjs/src/rendering/caching/CacheRecordManager.js +0 -50
- package/dist/cjs/src/rendering/caching/RenderingCache.js +0 -51
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.d.ts +0 -29
- package/dist/cjs/src/rendering/caching/RenderingCacheNode.js +0 -326
- package/dist/cjs/src/rendering/caching/testUtils.js +0 -27
- package/dist/cjs/src/rendering/lib.js +0 -17
- package/dist/cjs/src/rendering/localization.js +0 -12
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +0 -85
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.js +0 -188
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +0 -63
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +0 -243
- package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +0 -35
- package/dist/cjs/src/rendering/renderers/DummyRenderer.js +0 -112
- package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +0 -57
- package/dist/cjs/src/rendering/renderers/SVGRenderer.js +0 -320
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +0 -29
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.js +0 -63
- package/dist/cjs/src/testing/beforeEachFile.js +0 -12
- package/dist/cjs/src/testing/createEditor.js +0 -14
- package/dist/cjs/src/testing/lib.js +0 -10
- package/dist/cjs/src/testing/loadExpectExtensions.d.ts +0 -2
- package/dist/cjs/src/testing/loadExpectExtensions.js +0 -28
- package/dist/cjs/src/testing/sendPenEvent.js +0 -24
- package/dist/cjs/src/testing/sendTouchEvent.js +0 -87
- package/dist/cjs/src/toolbar/HTMLToolbar.js +0 -449
- package/dist/cjs/src/toolbar/IconProvider.js +0 -660
- package/dist/cjs/src/toolbar/lib.js +0 -24
- package/dist/cjs/src/toolbar/localization.d.ts +0 -51
- package/dist/cjs/src/toolbar/localization.js +0 -53
- package/dist/cjs/src/toolbar/makeColorInput.js +0 -128
- package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.js +0 -31
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.js +0 -49
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +0 -351
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +0 -201
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.js +0 -63
- package/dist/cjs/src/toolbar/widgets/HandToolWidget.js +0 -201
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.js +0 -176
- package/dist/cjs/src/toolbar/widgets/OverflowWidget.js +0 -77
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +0 -226
- package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.js +0 -153
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.js +0 -115
- package/dist/cjs/src/toolbar/widgets/lib.js +0 -26
- package/dist/cjs/src/tools/BaseTool.js +0 -66
- package/dist/cjs/src/tools/Eraser.d.ts +0 -23
- package/dist/cjs/src/tools/Eraser.js +0 -112
- package/dist/cjs/src/tools/FindTool.d.ts +0 -21
- package/dist/cjs/src/tools/FindTool.js +0 -121
- package/dist/cjs/src/tools/PanZoom.d.ts +0 -52
- package/dist/cjs/src/tools/PanZoom.js +0 -421
- package/dist/cjs/src/tools/PasteHandler.js +0 -99
- package/dist/cjs/src/tools/Pen.d.ts +0 -43
- package/dist/cjs/src/tools/Pen.js +0 -202
- package/dist/cjs/src/tools/PipetteTool.js +0 -45
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -8
- package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.js +0 -28
- package/dist/cjs/src/tools/SelectionTool/Selection.d.ts +0 -64
- package/dist/cjs/src/tools/SelectionTool/Selection.js +0 -491
- package/dist/cjs/src/tools/SelectionTool/SelectionHandle.js +0 -85
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.d.ts +0 -37
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.js +0 -413
- package/dist/cjs/src/tools/SelectionTool/TransformMode.js +0 -107
- package/dist/cjs/src/tools/SelectionTool/types.js +0 -14
- package/dist/cjs/src/tools/SoundUITool.js +0 -164
- package/dist/cjs/src/tools/TextTool.d.ts +0 -33
- package/dist/cjs/src/tools/TextTool.js +0 -262
- package/dist/cjs/src/tools/ToolController.js +0 -192
- package/dist/cjs/src/tools/ToolEnabledGroup.js +0 -14
- package/dist/cjs/src/tools/ToolSwitcherShortcut.js +0 -38
- package/dist/cjs/src/tools/ToolbarShortcutHandler.js +0 -29
- package/dist/cjs/src/tools/UndoRedoShortcut.d.ts +0 -8
- package/dist/cjs/src/tools/UndoRedoShortcut.js +0 -28
- package/dist/cjs/src/tools/lib.js +0 -38
- package/dist/cjs/src/tools/localization.js +0 -33
- package/dist/cjs/src/types.d.ts +0 -153
- package/dist/cjs/src/types.js +0 -38
- package/dist/cjs/src/util/assertions.js +0 -51
- package/dist/cjs/src/util/fileToBase64.js +0 -15
- package/dist/cjs/src/util/untilNextAnimationFrame.js +0 -9
- package/dist/cjs/src/util/waitForAll.js +0 -17
- package/dist/cjs/src/util/waitForTimeout.js +0 -9
- package/dist/mjs/src/Color4.mjs +0 -258
- package/dist/mjs/src/Editor.d.ts +0 -309
- package/dist/mjs/src/Editor.mjs +0 -892
- package/dist/mjs/src/EditorImage.d.ts +0 -97
- package/dist/mjs/src/EditorImage.mjs +0 -485
- package/dist/mjs/src/EventDispatcher.d.ts +0 -30
- package/dist/mjs/src/EventDispatcher.mjs +0 -54
- package/dist/mjs/src/Pointer.d.ts +0 -26
- package/dist/mjs/src/Pointer.mjs +0 -105
- package/dist/mjs/src/SVGLoader.d.ts +0 -48
- package/dist/mjs/src/SVGLoader.mjs +0 -507
- package/dist/mjs/src/UndoRedoHistory.mjs +0 -91
- package/dist/mjs/src/Viewport.d.ts +0 -73
- package/dist/mjs/src/Viewport.mjs +0 -261
- package/dist/mjs/src/commands/Command.mjs +0 -31
- package/dist/mjs/src/commands/Duplicate.mjs +0 -59
- package/dist/mjs/src/commands/Erase.mjs +0 -77
- package/dist/mjs/src/commands/SerializableCommand.mjs +0 -37
- package/dist/mjs/src/commands/UnresolvedCommand.mjs +0 -22
- package/dist/mjs/src/commands/invertCommand.mjs +0 -50
- package/dist/mjs/src/commands/localization.d.ts +0 -23
- package/dist/mjs/src/commands/localization.mjs +0 -21
- package/dist/mjs/src/commands/uniteCommands.mjs +0 -117
- package/dist/mjs/src/components/AbstractComponent.d.ts +0 -85
- package/dist/mjs/src/components/AbstractComponent.mjs +0 -268
- package/dist/mjs/src/components/BackgroundComponent.d.ts +0 -62
- package/dist/mjs/src/components/BackgroundComponent.mjs +0 -286
- package/dist/mjs/src/components/ImageComponent.d.ts +0 -31
- package/dist/mjs/src/components/ImageComponent.mjs +0 -151
- package/dist/mjs/src/components/RestylableComponent.mjs +0 -80
- package/dist/mjs/src/components/SVGGlobalAttributesObject.d.ts +0 -21
- package/dist/mjs/src/components/SVGGlobalAttributesObject.mjs +0 -59
- package/dist/mjs/src/components/Stroke.d.ts +0 -76
- package/dist/mjs/src/components/Stroke.mjs +0 -232
- package/dist/mjs/src/components/TextComponent.d.ts +0 -63
- package/dist/mjs/src/components/TextComponent.mjs +0 -275
- package/dist/mjs/src/components/UnknownSVGObject.d.ts +0 -18
- package/dist/mjs/src/components/UnknownSVGObject.mjs +0 -44
- package/dist/mjs/src/components/builders/ArrowBuilder.d.ts +0 -19
- package/dist/mjs/src/components/builders/ArrowBuilder.mjs +0 -86
- package/dist/mjs/src/components/builders/FreehandLineBuilder.d.ts +0 -33
- package/dist/mjs/src/components/builders/FreehandLineBuilder.mjs +0 -165
- package/dist/mjs/src/components/builders/LineBuilder.d.ts +0 -18
- package/dist/mjs/src/components/builders/LineBuilder.mjs +0 -58
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +0 -36
- package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.mjs +0 -339
- package/dist/mjs/src/components/builders/RectangleBuilder.d.ts +0 -20
- package/dist/mjs/src/components/builders/RectangleBuilder.mjs +0 -50
- package/dist/mjs/src/components/builders/types.d.ts +0 -12
- package/dist/mjs/src/components/lib.d.ts +0 -13
- package/dist/mjs/src/components/lib.mjs +0 -14
- package/dist/mjs/src/components/localization.mjs +0 -11
- package/dist/mjs/src/components/util/StrokeSmoother.d.ts +0 -35
- package/dist/mjs/src/components/util/StrokeSmoother.mjs +0 -218
- package/dist/mjs/src/components/util/describeComponentList.d.ts +0 -4
- package/dist/mjs/src/components/util/describeComponentList.mjs +0 -14
- package/dist/mjs/src/lib.d.ts +0 -64
- package/dist/mjs/src/lib.mjs +0 -64
- package/dist/mjs/src/localization.mjs +0 -10
- package/dist/mjs/src/localizations/de.mjs +0 -4
- package/dist/mjs/src/localizations/en.mjs +0 -4
- package/dist/mjs/src/localizations/es.mjs +0 -18
- package/dist/mjs/src/localizations/getLocalizationTable.d.ts +0 -3
- package/dist/mjs/src/localizations/getLocalizationTable.mjs +0 -45
- package/dist/mjs/src/math/LineSegment2.d.ts +0 -26
- package/dist/mjs/src/math/LineSegment2.mjs +0 -129
- package/dist/mjs/src/math/Mat33.d.ts +0 -118
- package/dist/mjs/src/math/Mat33.mjs +0 -327
- package/dist/mjs/src/math/Path.d.ts +0 -92
- package/dist/mjs/src/math/Path.mjs +0 -870
- package/dist/mjs/src/math/Rect2.d.ts +0 -52
- package/dist/mjs/src/math/Rect2.mjs +0 -230
- package/dist/mjs/src/math/Triangle.d.ts +0 -11
- package/dist/mjs/src/math/Triangle.mjs +0 -19
- package/dist/mjs/src/math/Vec2.mjs +0 -33
- package/dist/mjs/src/math/Vec3.mjs +0 -175
- package/dist/mjs/src/math/lib.d.ts +0 -7
- package/dist/mjs/src/math/lib.mjs +0 -7
- package/dist/mjs/src/math/polynomial/QuadraticBezier.d.ts +0 -28
- package/dist/mjs/src/math/polynomial/QuadraticBezier.mjs +0 -108
- package/dist/mjs/src/math/polynomial/solveQuadratic.d.ts +0 -6
- package/dist/mjs/src/math/polynomial/solveQuadratic.mjs +0 -34
- package/dist/mjs/src/math/rounding.mjs +0 -128
- package/dist/mjs/src/rendering/Display.mjs +0 -206
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +0 -31
- package/dist/mjs/src/rendering/RenderingStyle.mjs +0 -38
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +0 -36
- package/dist/mjs/src/rendering/TextRenderingStyle.mjs +0 -23
- package/dist/mjs/src/rendering/caching/CacheRecord.d.ts +0 -20
- package/dist/mjs/src/rendering/caching/CacheRecord.mjs +0 -55
- package/dist/mjs/src/rendering/caching/CacheRecordManager.d.ts +0 -12
- package/dist/mjs/src/rendering/caching/CacheRecordManager.mjs +0 -43
- package/dist/mjs/src/rendering/caching/RenderingCache.mjs +0 -45
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.d.ts +0 -29
- package/dist/mjs/src/rendering/caching/RenderingCacheNode.mjs +0 -320
- package/dist/mjs/src/rendering/caching/testUtils.mjs +0 -20
- package/dist/mjs/src/rendering/localization.mjs +0 -9
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +0 -85
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.mjs +0 -162
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +0 -63
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.mjs +0 -237
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +0 -35
- package/dist/mjs/src/rendering/renderers/DummyRenderer.mjs +0 -106
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +0 -57
- package/dist/mjs/src/rendering/renderers/SVGRenderer.mjs +0 -313
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +0 -29
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.mjs +0 -57
- package/dist/mjs/src/testing/beforeEachFile.mjs +0 -7
- package/dist/mjs/src/testing/createEditor.mjs +0 -9
- package/dist/mjs/src/testing/loadExpectExtensions.d.ts +0 -2
- package/dist/mjs/src/testing/loadExpectExtensions.mjs +0 -24
- package/dist/mjs/src/testing/sendPenEvent.mjs +0 -19
- package/dist/mjs/src/testing/sendTouchEvent.mjs +0 -62
- package/dist/mjs/src/toolbar/HTMLToolbar.mjs +0 -443
- package/dist/mjs/src/toolbar/IconProvider.mjs +0 -654
- package/dist/mjs/src/toolbar/localization.d.ts +0 -51
- package/dist/mjs/src/toolbar/localization.mjs +0 -50
- package/dist/mjs/src/toolbar/makeColorInput.mjs +0 -121
- package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.mjs +0 -25
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.mjs +0 -43
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +0 -345
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +0 -173
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.mjs +0 -58
- package/dist/mjs/src/toolbar/widgets/HandToolWidget.mjs +0 -172
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.mjs +0 -171
- package/dist/mjs/src/toolbar/widgets/OverflowWidget.mjs +0 -71
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +0 -221
- package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.mjs +0 -147
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.mjs +0 -110
- package/dist/mjs/src/tools/BaseTool.mjs +0 -63
- package/dist/mjs/src/tools/Eraser.d.ts +0 -23
- package/dist/mjs/src/tools/Eraser.mjs +0 -106
- package/dist/mjs/src/tools/FindTool.d.ts +0 -21
- package/dist/mjs/src/tools/FindTool.mjs +0 -114
- package/dist/mjs/src/tools/PanZoom.d.ts +0 -52
- package/dist/mjs/src/tools/PanZoom.mjs +0 -414
- package/dist/mjs/src/tools/PasteHandler.mjs +0 -93
- package/dist/mjs/src/tools/Pen.d.ts +0 -43
- package/dist/mjs/src/tools/Pen.mjs +0 -196
- package/dist/mjs/src/tools/PipetteTool.mjs +0 -39
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -8
- package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.mjs +0 -22
- package/dist/mjs/src/tools/SelectionTool/Selection.d.ts +0 -64
- package/dist/mjs/src/tools/SelectionTool/Selection.mjs +0 -463
- package/dist/mjs/src/tools/SelectionTool/SelectionHandle.mjs +0 -81
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.d.ts +0 -37
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.mjs +0 -407
- package/dist/mjs/src/tools/SelectionTool/TransformMode.mjs +0 -98
- package/dist/mjs/src/tools/SoundUITool.mjs +0 -158
- package/dist/mjs/src/tools/TextTool.d.ts +0 -33
- package/dist/mjs/src/tools/TextTool.mjs +0 -256
- package/dist/mjs/src/tools/ToolController.mjs +0 -163
- package/dist/mjs/src/tools/ToolEnabledGroup.mjs +0 -11
- package/dist/mjs/src/tools/ToolSwitcherShortcut.mjs +0 -32
- package/dist/mjs/src/tools/ToolbarShortcutHandler.mjs +0 -23
- package/dist/mjs/src/tools/UndoRedoShortcut.d.ts +0 -8
- package/dist/mjs/src/tools/UndoRedoShortcut.mjs +0 -22
- package/dist/mjs/src/tools/localization.mjs +0 -30
- package/dist/mjs/src/types.d.ts +0 -153
- package/dist/mjs/src/util/assertions.mjs +0 -45
- package/dist/mjs/src/util/fileToBase64.mjs +0 -13
- package/dist/mjs/src/util/untilNextAnimationFrame.mjs +0 -7
- package/dist/mjs/src/util/waitForAll.mjs +0 -15
- package/dist/mjs/src/util/waitForTimeout.mjs +0 -7
- package/firebase.json +0 -16
- package/jest.config.js +0 -29
- package/lint-staged.config.js +0 -6
- package/tsconfig-typedoc.json +0 -7
- package/tsconfig.mjs.json +0 -9
- package/typedoc.json +0 -25
- /package/dist/cjs/{src/Color4.d.ts → Color4.d.ts} +0 -0
- /package/dist/cjs/{src/testing/beforeEachFile.d.ts → Color4.test.d.ts} +0 -0
- /package/dist/{mjs/src/components/builders/types.mjs → cjs/Editor.loadFrom.test.d.ts} +0 -0
- /package/dist/{mjs/src/rendering/caching/types.mjs → cjs/Editor.toSVG.test.d.ts} +0 -0
- /package/dist/{mjs/src/testing/beforeEachFile.d.ts → cjs/EditorImage.test.d.ts} +0 -0
- /package/dist/{mjs/src/toolbar/types.mjs → cjs/EventDispatcher.test.d.ts} +0 -0
- /package/dist/cjs/{src/UndoRedoHistory.d.ts → UndoRedoHistory.d.ts} +0 -0
- /package/dist/cjs/{src/bundle → bundle}/bundled.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/Command.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/Duplicate.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/Erase.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/SerializableCommand.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/UnresolvedCommand.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/invertCommand.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/lib.d.ts +0 -0
- /package/dist/cjs/{src/commands → commands}/uniteCommands.d.ts +0 -0
- /package/dist/cjs/{src/components → components}/RestylableComponent.d.ts +0 -0
- /package/dist/cjs/{src/components → components}/builders/types.js +0 -0
- /package/dist/cjs/{src/components → components}/localization.d.ts +0 -0
- /package/dist/cjs/{src/localization.d.ts → localization.d.ts} +0 -0
- /package/dist/cjs/{src/localizations → localizations}/de.d.ts +0 -0
- /package/dist/cjs/{src/localizations → localizations}/en.d.ts +0 -0
- /package/dist/cjs/{src/localizations → localizations}/es.d.ts +0 -0
- /package/dist/cjs/{src/math → math}/Vec2.d.ts +0 -0
- /package/dist/cjs/{src/math → math}/Vec3.d.ts +0 -0
- /package/dist/cjs/{src/math → math}/rounding.d.ts +0 -0
- /package/dist/cjs/{src/rendering → rendering}/Display.d.ts +0 -0
- /package/dist/cjs/{src/rendering → rendering}/caching/RenderingCache.d.ts +0 -0
- /package/dist/cjs/{src/rendering → rendering}/caching/testUtils.d.ts +0 -0
- /package/dist/cjs/{src/rendering → rendering}/caching/types.d.ts +0 -0
- /package/dist/cjs/{src/rendering → rendering}/caching/types.js +0 -0
- /package/dist/cjs/{src/rendering → rendering}/lib.d.ts +0 -0
- /package/dist/cjs/{src/rendering → rendering}/localization.d.ts +0 -0
- /package/dist/cjs/{src/testing → testing}/createEditor.d.ts +0 -0
- /package/dist/cjs/{src/testing → testing}/lib.d.ts +0 -0
- /package/dist/cjs/{src/testing → testing}/sendPenEvent.d.ts +0 -0
- /package/dist/cjs/{src/testing → testing}/sendTouchEvent.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/HTMLToolbar.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/IconProvider.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/lib.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/makeColorInput.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/types.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/types.js +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/ActionButtonWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/BaseToolWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/BaseWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/DocumentPropertiesWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/EraserToolWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/HandToolWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/InsertImageWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/OverflowWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/PenToolWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/SelectionToolWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/TextToolWidget.d.ts +0 -0
- /package/dist/cjs/{src/toolbar → toolbar}/widgets/lib.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/BaseTool.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/PasteHandler.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/PipetteTool.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/SelectionTool/SelectionHandle.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/SelectionTool/TransformMode.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/SelectionTool/types.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/SoundUITool.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/ToolController.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/ToolEnabledGroup.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/ToolSwitcherShortcut.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/ToolbarShortcutHandler.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/lib.d.ts +0 -0
- /package/dist/cjs/{src/tools → tools}/localization.d.ts +0 -0
- /package/dist/cjs/{src/util → util}/assertions.d.ts +0 -0
- /package/dist/cjs/{src/util → util}/fileToBase64.d.ts +0 -0
- /package/dist/cjs/{src/util → util}/untilNextAnimationFrame.d.ts +0 -0
- /package/dist/cjs/{src/util → util}/waitForAll.d.ts +0 -0
- /package/dist/cjs/{src/util → util}/waitForTimeout.d.ts +0 -0
- /package/dist/mjs/{src/Color4.d.ts → Color4.d.ts} +0 -0
- /package/dist/mjs/{src/UndoRedoHistory.d.ts → UndoRedoHistory.d.ts} +0 -0
- /package/dist/mjs/{src/bundle → bundle}/bundled.d.ts +0 -0
- /package/dist/mjs/{src/bundle → bundle}/bundled.mjs +0 -0
- /package/dist/mjs/{src/commands → commands}/Command.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/Duplicate.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/Erase.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/SerializableCommand.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/UnresolvedCommand.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/invertCommand.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/lib.d.ts +0 -0
- /package/dist/mjs/{src/commands → commands}/lib.mjs +0 -0
- /package/dist/mjs/{src/commands → commands}/uniteCommands.d.ts +0 -0
- /package/dist/mjs/{src/components → components}/RestylableComponent.d.ts +0 -0
- /package/dist/mjs/{src/components → components}/localization.d.ts +0 -0
- /package/dist/mjs/{src/localization.d.ts → localization.d.ts} +0 -0
- /package/dist/mjs/{src/localizations → localizations}/de.d.ts +0 -0
- /package/dist/mjs/{src/localizations → localizations}/en.d.ts +0 -0
- /package/dist/mjs/{src/localizations → localizations}/es.d.ts +0 -0
- /package/dist/mjs/{src/math → math}/Vec2.d.ts +0 -0
- /package/dist/mjs/{src/math → math}/Vec3.d.ts +0 -0
- /package/dist/mjs/{src/math → math}/rounding.d.ts +0 -0
- /package/dist/mjs/{src/rendering → rendering}/Display.d.ts +0 -0
- /package/dist/mjs/{src/rendering → rendering}/caching/RenderingCache.d.ts +0 -0
- /package/dist/mjs/{src/rendering → rendering}/caching/testUtils.d.ts +0 -0
- /package/dist/mjs/{src/rendering → rendering}/caching/types.d.ts +0 -0
- /package/dist/mjs/{src/rendering → rendering}/lib.d.ts +0 -0
- /package/dist/mjs/{src/rendering → rendering}/lib.mjs +0 -0
- /package/dist/mjs/{src/rendering → rendering}/localization.d.ts +0 -0
- /package/dist/mjs/{src/testing → testing}/createEditor.d.ts +0 -0
- /package/dist/mjs/{src/testing → testing}/lib.d.ts +0 -0
- /package/dist/mjs/{src/testing → testing}/lib.mjs +0 -0
- /package/dist/mjs/{src/testing → testing}/sendPenEvent.d.ts +0 -0
- /package/dist/mjs/{src/testing → testing}/sendTouchEvent.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/HTMLToolbar.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/IconProvider.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/lib.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/lib.mjs +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/makeColorInput.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/types.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/ActionButtonWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/BaseToolWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/BaseWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/DocumentPropertiesWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/EraserToolWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/HandToolWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/InsertImageWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/OverflowWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/PenToolWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/SelectionToolWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/TextToolWidget.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/lib.d.ts +0 -0
- /package/dist/mjs/{src/toolbar → toolbar}/widgets/lib.mjs +0 -0
- /package/dist/mjs/{src/tools → tools}/BaseTool.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/PasteHandler.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/PipetteTool.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/SelectionTool/SelectionHandle.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/SelectionTool/TransformMode.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/SelectionTool/types.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/SelectionTool/types.mjs +0 -0
- /package/dist/mjs/{src/tools → tools}/SoundUITool.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/ToolController.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/ToolEnabledGroup.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/ToolSwitcherShortcut.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/ToolbarShortcutHandler.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/lib.d.ts +0 -0
- /package/dist/mjs/{src/tools → tools}/lib.mjs +0 -0
- /package/dist/mjs/{src/tools → tools}/localization.d.ts +0 -0
- /package/dist/mjs/{src/types.mjs → types.mjs} +0 -0
- /package/dist/mjs/{src/util → util}/assertions.d.ts +0 -0
- /package/dist/mjs/{src/util → util}/fileToBase64.d.ts +0 -0
- /package/dist/mjs/{src/util → util}/untilNextAnimationFrame.d.ts +0 -0
- /package/dist/mjs/{src/util → util}/waitForAll.d.ts +0 -0
- /package/dist/mjs/{src/util → util}/waitForTimeout.d.ts +0 -0
@@ -0,0 +1,1027 @@
|
|
1
|
+
import { RenderablePathSpec } from '../../rendering/renderers/AbstractRenderer';
|
2
|
+
import RenderingStyle from '../../rendering/RenderingStyle';
|
3
|
+
import { toRoundedString, toStringOfSamePrecision } from '../rounding';
|
4
|
+
import LineSegment2 from './LineSegment2';
|
5
|
+
import Mat33 from '../Mat33';
|
6
|
+
import Rect2 from './Rect2';
|
7
|
+
import { Point2, Vec2 } from '../Vec2';
|
8
|
+
import Abstract2DShape from './Abstract2DShape';
|
9
|
+
import CubicBezier from './CubicBezier';
|
10
|
+
import QuadraticBezier from './QuadraticBezier';
|
11
|
+
import PointShape2D from './PointShape2D';
|
12
|
+
|
13
|
+
export enum PathCommandType {
|
14
|
+
LineTo,
|
15
|
+
MoveTo,
|
16
|
+
CubicBezierTo,
|
17
|
+
QuadraticBezierTo,
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface CubicBezierPathCommand {
|
21
|
+
kind: PathCommandType.CubicBezierTo;
|
22
|
+
controlPoint1: Point2;
|
23
|
+
controlPoint2: Point2;
|
24
|
+
endPoint: Point2;
|
25
|
+
}
|
26
|
+
|
27
|
+
export interface QuadraticBezierPathCommand {
|
28
|
+
kind: PathCommandType.QuadraticBezierTo;
|
29
|
+
controlPoint: Point2;
|
30
|
+
endPoint: Point2;
|
31
|
+
}
|
32
|
+
|
33
|
+
export interface LinePathCommand {
|
34
|
+
kind: PathCommandType.LineTo;
|
35
|
+
point: Point2;
|
36
|
+
}
|
37
|
+
|
38
|
+
export interface MoveToPathCommand {
|
39
|
+
kind: PathCommandType.MoveTo;
|
40
|
+
point: Point2;
|
41
|
+
}
|
42
|
+
|
43
|
+
export type PathCommand = CubicBezierPathCommand | QuadraticBezierPathCommand | MoveToPathCommand | LinePathCommand;
|
44
|
+
|
45
|
+
interface IntersectionResult {
|
46
|
+
// @internal
|
47
|
+
curve: Abstract2DShape;
|
48
|
+
|
49
|
+
/** @internal @deprecated */
|
50
|
+
parameterValue?: number;
|
51
|
+
|
52
|
+
// Point at which the intersection occured.
|
53
|
+
point: Point2;
|
54
|
+
}
|
55
|
+
|
56
|
+
type GeometryType = Abstract2DShape;
|
57
|
+
type GeometryArrayType = Array<GeometryType>;
|
58
|
+
|
59
|
+
export default class Path {
|
60
|
+
/**
|
61
|
+
* A rough estimate of the bounding box of the path.
|
62
|
+
* A slight overestimate.
|
63
|
+
* See {@link getExactBBox}
|
64
|
+
*/
|
65
|
+
public readonly bbox: Rect2;
|
66
|
+
|
67
|
+
public constructor(public readonly startPoint: Point2, public readonly parts: PathCommand[]) {
|
68
|
+
// Initial bounding box contains one point: the start point.
|
69
|
+
this.bbox = Rect2.bboxOf([startPoint]);
|
70
|
+
|
71
|
+
// Convert into a representation of the geometry (cache for faster intersection
|
72
|
+
// calculation)
|
73
|
+
for (const part of parts) {
|
74
|
+
this.bbox = this.bbox.union(Path.computeBBoxForSegment(startPoint, part));
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
public getExactBBox(): Rect2 {
|
79
|
+
const bboxes: Rect2[] = [];
|
80
|
+
for (const part of this.geometry) {
|
81
|
+
bboxes.push(part.getTightBoundingBox());
|
82
|
+
}
|
83
|
+
|
84
|
+
return Rect2.union(...bboxes);
|
85
|
+
}
|
86
|
+
|
87
|
+
private cachedGeometry: GeometryArrayType|null = null;
|
88
|
+
|
89
|
+
// Lazy-loads and returns this path's geometry
|
90
|
+
public get geometry(): GeometryArrayType {
|
91
|
+
if (this.cachedGeometry) {
|
92
|
+
return this.cachedGeometry;
|
93
|
+
}
|
94
|
+
|
95
|
+
let startPoint = this.startPoint;
|
96
|
+
const geometry: GeometryArrayType = [];
|
97
|
+
|
98
|
+
for (const part of this.parts) {
|
99
|
+
switch (part.kind) {
|
100
|
+
case PathCommandType.CubicBezierTo:
|
101
|
+
geometry.push(
|
102
|
+
new CubicBezier(
|
103
|
+
startPoint, part.controlPoint1, part.controlPoint2, part.endPoint
|
104
|
+
)
|
105
|
+
);
|
106
|
+
startPoint = part.endPoint;
|
107
|
+
break;
|
108
|
+
case PathCommandType.QuadraticBezierTo:
|
109
|
+
geometry.push(
|
110
|
+
new QuadraticBezier(
|
111
|
+
startPoint, part.controlPoint, part.endPoint
|
112
|
+
)
|
113
|
+
);
|
114
|
+
startPoint = part.endPoint;
|
115
|
+
break;
|
116
|
+
case PathCommandType.LineTo:
|
117
|
+
geometry.push(
|
118
|
+
new LineSegment2(startPoint, part.point)
|
119
|
+
);
|
120
|
+
startPoint = part.point;
|
121
|
+
break;
|
122
|
+
case PathCommandType.MoveTo:
|
123
|
+
geometry.push(new PointShape2D(part.point));
|
124
|
+
startPoint = part.point;
|
125
|
+
break;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
this.cachedGeometry = geometry;
|
130
|
+
return this.cachedGeometry;
|
131
|
+
}
|
132
|
+
|
133
|
+
private cachedPolylineApproximation: LineSegment2[]|null = null;
|
134
|
+
|
135
|
+
// Approximates this path with a group of line segments.
|
136
|
+
public polylineApproximation(): LineSegment2[] {
|
137
|
+
if (this.cachedPolylineApproximation) {
|
138
|
+
return this.cachedPolylineApproximation;
|
139
|
+
}
|
140
|
+
|
141
|
+
const points: Point2[] = [];
|
142
|
+
|
143
|
+
for (const part of this.parts) {
|
144
|
+
switch (part.kind) {
|
145
|
+
case PathCommandType.CubicBezierTo:
|
146
|
+
points.push(part.controlPoint1, part.controlPoint2, part.endPoint);
|
147
|
+
break;
|
148
|
+
case PathCommandType.QuadraticBezierTo:
|
149
|
+
points.push(part.controlPoint, part.endPoint);
|
150
|
+
break;
|
151
|
+
case PathCommandType.MoveTo:
|
152
|
+
case PathCommandType.LineTo:
|
153
|
+
points.push(part.point);
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
const result: LineSegment2[] = [];
|
159
|
+
let prevPoint = this.startPoint;
|
160
|
+
for (const point of points) {
|
161
|
+
result.push(new LineSegment2(prevPoint, point));
|
162
|
+
prevPoint = point;
|
163
|
+
}
|
164
|
+
|
165
|
+
return result;
|
166
|
+
}
|
167
|
+
|
168
|
+
public static computeBBoxForSegment(startPoint: Point2, part: PathCommand): Rect2 {
|
169
|
+
const points = [startPoint];
|
170
|
+
let exhaustivenessCheck: never;
|
171
|
+
switch (part.kind) {
|
172
|
+
case PathCommandType.MoveTo:
|
173
|
+
case PathCommandType.LineTo:
|
174
|
+
points.push(part.point);
|
175
|
+
break;
|
176
|
+
case PathCommandType.CubicBezierTo:
|
177
|
+
points.push(part.controlPoint1, part.controlPoint2, part.endPoint);
|
178
|
+
break;
|
179
|
+
case PathCommandType.QuadraticBezierTo:
|
180
|
+
points.push(part.controlPoint, part.endPoint);
|
181
|
+
break;
|
182
|
+
default:
|
183
|
+
exhaustivenessCheck = part;
|
184
|
+
return exhaustivenessCheck;
|
185
|
+
}
|
186
|
+
|
187
|
+
return Rect2.bboxOf(points);
|
188
|
+
}
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Let `S` be a closed path a distance `strokeRadius` from this path.
|
192
|
+
*
|
193
|
+
* @returns Approximate intersections of `line` with `S` using ray marching, starting from
|
194
|
+
* both end points of `line` and each point in `additionalRaymarchStartPoints`.
|
195
|
+
*/
|
196
|
+
private raymarchIntersectionWith(
|
197
|
+
line: LineSegment2, strokeRadius: number, additionalRaymarchStartPoints: Point2[] = []
|
198
|
+
): IntersectionResult[] {
|
199
|
+
// No intersection between bounding boxes: No possible intersection
|
200
|
+
// of the interior.
|
201
|
+
if (!line.bbox.intersects(this.bbox.grownBy(strokeRadius))) {
|
202
|
+
return [];
|
203
|
+
}
|
204
|
+
|
205
|
+
const lineLength = line.length;
|
206
|
+
|
207
|
+
type DistanceFunction = (point: Point2) => number;
|
208
|
+
const partDistFunctionRecords: {
|
209
|
+
part: GeometryType,
|
210
|
+
bbox: Rect2,
|
211
|
+
distFn: DistanceFunction,
|
212
|
+
}[] = [];
|
213
|
+
|
214
|
+
// Determine distance functions for all parts that the given line could possibly intersect with
|
215
|
+
for (const part of this.geometry) {
|
216
|
+
const bbox = part.getTightBoundingBox().grownBy(strokeRadius);
|
217
|
+
if (!bbox.intersects(line.bbox)) {
|
218
|
+
continue;
|
219
|
+
}
|
220
|
+
|
221
|
+
// Signed distance function
|
222
|
+
const partDist: DistanceFunction = (point) => part.signedDistance(point);
|
223
|
+
|
224
|
+
// Part signed distance function (negative result implies `point` is
|
225
|
+
// inside the shape).
|
226
|
+
const partSdf = (point: Point2) => partDist(point) - strokeRadius;
|
227
|
+
|
228
|
+
// If the line can't possibly intersect the part,
|
229
|
+
if (partSdf(line.p1) > lineLength && partSdf(line.p2) > lineLength) {
|
230
|
+
continue;
|
231
|
+
}
|
232
|
+
|
233
|
+
partDistFunctionRecords.push({
|
234
|
+
part,
|
235
|
+
distFn: partDist,
|
236
|
+
bbox,
|
237
|
+
});
|
238
|
+
}
|
239
|
+
|
240
|
+
// If no distance functions, there are no intersections.
|
241
|
+
if (partDistFunctionRecords.length === 0) {
|
242
|
+
return [];
|
243
|
+
}
|
244
|
+
|
245
|
+
// Returns the minimum distance to a part in this stroke, where only parts that the given
|
246
|
+
// line could intersect are considered.
|
247
|
+
const sdf = (point: Point2): [GeometryType|null, number] => {
|
248
|
+
let minDist = Infinity;
|
249
|
+
let minDistPart = null;
|
250
|
+
|
251
|
+
const uncheckedDistFunctions = [];
|
252
|
+
|
253
|
+
// First pass: only curves for which the current point is inside
|
254
|
+
// the bounding box.
|
255
|
+
for (const distFnRecord of partDistFunctionRecords) {
|
256
|
+
const { part, distFn, bbox } = distFnRecord;
|
257
|
+
|
258
|
+
// Check later if the current point isn't in the bounding box.
|
259
|
+
if (!bbox.containsPoint(point)) {
|
260
|
+
uncheckedDistFunctions.push(distFnRecord);
|
261
|
+
continue;
|
262
|
+
}
|
263
|
+
|
264
|
+
const currentDist = distFn(point);
|
265
|
+
|
266
|
+
if (currentDist <= minDist) {
|
267
|
+
minDist = currentDist;
|
268
|
+
minDistPart = part;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
// Second pass: Everything else
|
273
|
+
for (const { part, distFn, bbox } of uncheckedDistFunctions) {
|
274
|
+
// Skip if impossible for the distance to the target to be lesser than
|
275
|
+
// the current minimum.
|
276
|
+
if (!bbox.grownBy(minDist).containsPoint(point)) {
|
277
|
+
continue;
|
278
|
+
}
|
279
|
+
|
280
|
+
const currentDist = distFn(point);
|
281
|
+
|
282
|
+
if (currentDist <= minDist) {
|
283
|
+
minDist = currentDist;
|
284
|
+
minDistPart = part;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
return [ minDistPart, minDist - strokeRadius ];
|
289
|
+
};
|
290
|
+
|
291
|
+
|
292
|
+
// Raymarch:
|
293
|
+
const maxRaymarchSteps = 7;
|
294
|
+
|
295
|
+
// Start raymarching from each of these points. This allows detection of multiple
|
296
|
+
// intersections.
|
297
|
+
const startPoints = [
|
298
|
+
line.p1, ...additionalRaymarchStartPoints, line.p2
|
299
|
+
];
|
300
|
+
|
301
|
+
// Converts a point ON THE LINE to a parameter
|
302
|
+
const pointToParameter = (point: Point2) => {
|
303
|
+
// Because line.direction is a unit vector, this computes the length
|
304
|
+
// of the projection of the vector(line.p1->point) onto line.direction.
|
305
|
+
//
|
306
|
+
// Note that this can be negative if the given point is outside of the given
|
307
|
+
// line segment.
|
308
|
+
return point.minus(line.p1).dot(line.direction);
|
309
|
+
};
|
310
|
+
|
311
|
+
// Sort start points by parameter on the line.
|
312
|
+
// This allows us to determine whether the current value of a parameter
|
313
|
+
// drops down to a value already tested.
|
314
|
+
startPoints.sort((a, b) => {
|
315
|
+
const t_a = pointToParameter(a);
|
316
|
+
const t_b = pointToParameter(b);
|
317
|
+
|
318
|
+
// Sort in increasing order
|
319
|
+
return t_a - t_b;
|
320
|
+
});
|
321
|
+
|
322
|
+
const result: IntersectionResult[] = [];
|
323
|
+
|
324
|
+
const stoppingThreshold = strokeRadius / 1000;
|
325
|
+
|
326
|
+
// Returns the maximum x value explored
|
327
|
+
const raymarchFrom = (
|
328
|
+
startPoint: Point2,
|
329
|
+
|
330
|
+
// Direction to march in (multiplies line.direction)
|
331
|
+
directionMultiplier: -1|1,
|
332
|
+
|
333
|
+
// Terminate if the current point corresponds to a parameter
|
334
|
+
// below this.
|
335
|
+
minimumLineParameter: number,
|
336
|
+
): number|null => {
|
337
|
+
let currentPoint = startPoint;
|
338
|
+
let [lastPart, lastDist] = sdf(currentPoint);
|
339
|
+
let lastParameter = pointToParameter(currentPoint);
|
340
|
+
|
341
|
+
if (lastDist > lineLength) {
|
342
|
+
return lastParameter;
|
343
|
+
}
|
344
|
+
|
345
|
+
const direction = line.direction.times(directionMultiplier);
|
346
|
+
|
347
|
+
for (let i = 0; i < maxRaymarchSteps; i++) {
|
348
|
+
// Step in the direction of the edge of the shape.
|
349
|
+
const step = lastDist;
|
350
|
+
currentPoint = currentPoint.plus(direction.times(step));
|
351
|
+
lastParameter = pointToParameter(currentPoint);
|
352
|
+
|
353
|
+
// If we're below the minimum parameter, stop. We've already tried
|
354
|
+
// this.
|
355
|
+
if (lastParameter <= minimumLineParameter) {
|
356
|
+
return lastParameter;
|
357
|
+
}
|
358
|
+
|
359
|
+
const [currentPart, signedDist] = sdf(currentPoint);
|
360
|
+
|
361
|
+
// Ensure we're stepping in the correct direction.
|
362
|
+
// Note that because we could start with a negative distance and work towards a
|
363
|
+
// positive distance, we need absolute values here.
|
364
|
+
if (Math.abs(signedDist) > Math.abs(lastDist)) {
|
365
|
+
// If not, stop.
|
366
|
+
return null;
|
367
|
+
}
|
368
|
+
|
369
|
+
lastDist = signedDist;
|
370
|
+
lastPart = currentPart;
|
371
|
+
|
372
|
+
// Is the distance close enough that we can stop early?
|
373
|
+
if (Math.abs(lastDist) < stoppingThreshold) {
|
374
|
+
break;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
// Ensure that the point we ended with is on the line.
|
379
|
+
const isOnLineSegment = lastParameter >= 0 && lastParameter <= lineLength;
|
380
|
+
|
381
|
+
if (lastPart && isOnLineSegment && Math.abs(lastDist) < stoppingThreshold) {
|
382
|
+
result.push({
|
383
|
+
point: currentPoint,
|
384
|
+
parameterValue: NaN,
|
385
|
+
curve: lastPart,
|
386
|
+
});
|
387
|
+
}
|
388
|
+
|
389
|
+
return lastParameter;
|
390
|
+
};
|
391
|
+
|
392
|
+
// The maximum value of the line's parameter explored so far (0 corresponds to
|
393
|
+
// line.p1)
|
394
|
+
let maxLineT = 0;
|
395
|
+
|
396
|
+
// Raymarch for each start point.
|
397
|
+
//
|
398
|
+
// Use a for (i from 0 to length) loop because startPoints may be added
|
399
|
+
// during iteration.
|
400
|
+
for (let i = 0; i < startPoints.length; i++) {
|
401
|
+
const startPoint = startPoints[i];
|
402
|
+
|
403
|
+
// Try raymarching in both directions.
|
404
|
+
maxLineT = Math.max(maxLineT, raymarchFrom(startPoint, 1, maxLineT) ?? maxLineT);
|
405
|
+
maxLineT = Math.max(maxLineT, raymarchFrom(startPoint, -1, maxLineT) ?? maxLineT);
|
406
|
+
}
|
407
|
+
|
408
|
+
return result;
|
409
|
+
}
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Returns a list of intersections with this path. If `strokeRadius` is given,
|
413
|
+
* intersections are approximated with the surface `strokeRadius` away from this.
|
414
|
+
*
|
415
|
+
* If `strokeRadius > 0`, the resultant `parameterValue` has no defined value.
|
416
|
+
*/
|
417
|
+
public intersection(line: LineSegment2, strokeRadius?: number): IntersectionResult[] {
|
418
|
+
let result: IntersectionResult[] = [];
|
419
|
+
|
420
|
+
// Is any intersection between shapes within the bounding boxes impossible?
|
421
|
+
if (!line.bbox.intersects(this.bbox.grownBy(strokeRadius ?? 0))) {
|
422
|
+
return [];
|
423
|
+
}
|
424
|
+
|
425
|
+
for (const part of this.geometry) {
|
426
|
+
const intersection = part.intersectsLineSegment(line);
|
427
|
+
|
428
|
+
if (intersection.length > 0) {
|
429
|
+
result.push({
|
430
|
+
curve: part,
|
431
|
+
point: intersection[0],
|
432
|
+
});
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
// If given a non-zero strokeWidth, attempt to raymarch.
|
437
|
+
// Even if raymarching, we need to collect starting points.
|
438
|
+
// We use the above-calculated intersections for this.
|
439
|
+
const doRaymarching = strokeRadius && strokeRadius > 1e-8;
|
440
|
+
if (doRaymarching) {
|
441
|
+
// Starting points for raymarching (in addition to the end points of the line).
|
442
|
+
const startPoints = result.map(intersection => intersection.point);
|
443
|
+
result = this.raymarchIntersectionWith(line, strokeRadius, startPoints);
|
444
|
+
}
|
445
|
+
|
446
|
+
return result;
|
447
|
+
}
|
448
|
+
|
449
|
+
private static mapPathCommand(part: PathCommand, mapping: (point: Point2)=> Point2): PathCommand {
|
450
|
+
switch (part.kind) {
|
451
|
+
case PathCommandType.MoveTo:
|
452
|
+
case PathCommandType.LineTo:
|
453
|
+
return {
|
454
|
+
kind: part.kind,
|
455
|
+
point: mapping(part.point),
|
456
|
+
};
|
457
|
+
break;
|
458
|
+
case PathCommandType.CubicBezierTo:
|
459
|
+
return {
|
460
|
+
kind: part.kind,
|
461
|
+
controlPoint1: mapping(part.controlPoint1),
|
462
|
+
controlPoint2: mapping(part.controlPoint2),
|
463
|
+
endPoint: mapping(part.endPoint),
|
464
|
+
};
|
465
|
+
break;
|
466
|
+
case PathCommandType.QuadraticBezierTo:
|
467
|
+
return {
|
468
|
+
kind: part.kind,
|
469
|
+
controlPoint: mapping(part.controlPoint),
|
470
|
+
endPoint: mapping(part.endPoint),
|
471
|
+
};
|
472
|
+
break;
|
473
|
+
}
|
474
|
+
|
475
|
+
const exhaustivenessCheck: never = part;
|
476
|
+
return exhaustivenessCheck;
|
477
|
+
}
|
478
|
+
|
479
|
+
public mapPoints(mapping: (point: Point2)=>Point2): Path {
|
480
|
+
const startPoint = mapping(this.startPoint);
|
481
|
+
const newParts: PathCommand[] = [];
|
482
|
+
|
483
|
+
for (const part of this.parts) {
|
484
|
+
newParts.push(Path.mapPathCommand(part, mapping));
|
485
|
+
}
|
486
|
+
|
487
|
+
return new Path(startPoint, newParts);
|
488
|
+
}
|
489
|
+
|
490
|
+
public transformedBy(affineTransfm: Mat33): Path {
|
491
|
+
if (affineTransfm.isIdentity()) {
|
492
|
+
return this;
|
493
|
+
}
|
494
|
+
|
495
|
+
return this.mapPoints(point => affineTransfm.transformVec2(point));
|
496
|
+
}
|
497
|
+
|
498
|
+
// Creates a new path by joining [other] to the end of this path
|
499
|
+
public union(other: Path|null): Path {
|
500
|
+
if (!other) {
|
501
|
+
return this;
|
502
|
+
}
|
503
|
+
|
504
|
+
return new Path(this.startPoint, [
|
505
|
+
...this.parts,
|
506
|
+
{
|
507
|
+
kind: PathCommandType.MoveTo,
|
508
|
+
point: other.startPoint,
|
509
|
+
},
|
510
|
+
...other.parts,
|
511
|
+
]);
|
512
|
+
}
|
513
|
+
|
514
|
+
private getEndPoint() {
|
515
|
+
if (this.parts.length === 0) {
|
516
|
+
return this.startPoint;
|
517
|
+
}
|
518
|
+
const lastPart = this.parts[this.parts.length - 1];
|
519
|
+
if (lastPart.kind === PathCommandType.QuadraticBezierTo || lastPart.kind === PathCommandType.CubicBezierTo) {
|
520
|
+
return lastPart.endPoint;
|
521
|
+
} else {
|
522
|
+
return lastPart.point;
|
523
|
+
}
|
524
|
+
}
|
525
|
+
|
526
|
+
public roughlyIntersects(rect: Rect2, strokeWidth: number = 0) {
|
527
|
+
if (this.parts.length === 0) {
|
528
|
+
return rect.containsPoint(this.startPoint);
|
529
|
+
}
|
530
|
+
const isClosed = this.startPoint.eq(this.getEndPoint());
|
531
|
+
|
532
|
+
if (isClosed && strokeWidth === 0) {
|
533
|
+
return this.closedRoughlyIntersects(rect);
|
534
|
+
}
|
535
|
+
|
536
|
+
if (rect.containsRect(this.bbox)) {
|
537
|
+
return true;
|
538
|
+
}
|
539
|
+
|
540
|
+
// Does the rectangle intersect the bounding boxes of any of this' parts?
|
541
|
+
let startPoint = this.startPoint;
|
542
|
+
for (const part of this.parts) {
|
543
|
+
const bbox = Path.computeBBoxForSegment(startPoint, part).grownBy(strokeWidth);
|
544
|
+
|
545
|
+
if (part.kind === PathCommandType.LineTo || part.kind === PathCommandType.MoveTo) {
|
546
|
+
startPoint = part.point;
|
547
|
+
} else {
|
548
|
+
startPoint = part.endPoint;
|
549
|
+
}
|
550
|
+
|
551
|
+
if (rect.intersects(bbox)) {
|
552
|
+
return true;
|
553
|
+
}
|
554
|
+
}
|
555
|
+
|
556
|
+
return false;
|
557
|
+
}
|
558
|
+
|
559
|
+
// Treats this as a closed path and returns true if part of `rect` is roughly within
|
560
|
+
// this path's interior.
|
561
|
+
//
|
562
|
+
// Note: Assumes that this is a closed, non-self-intersecting path.
|
563
|
+
public closedRoughlyIntersects(rect: Rect2): boolean {
|
564
|
+
if (rect.containsRect(this.bbox)) {
|
565
|
+
return true;
|
566
|
+
}
|
567
|
+
|
568
|
+
// Choose a point outside of the path.
|
569
|
+
const startPt = this.bbox.topLeft.minus(Vec2.of(1, 1));
|
570
|
+
const testPts = rect.corners;
|
571
|
+
const polygon = this.polylineApproximation();
|
572
|
+
|
573
|
+
for (const point of testPts) {
|
574
|
+
const testLine = new LineSegment2(point, startPt);
|
575
|
+
|
576
|
+
let intersectionCount = 0;
|
577
|
+
for (const line of polygon) {
|
578
|
+
if (line.intersects(testLine)) {
|
579
|
+
intersectionCount ++;
|
580
|
+
}
|
581
|
+
}
|
582
|
+
|
583
|
+
// Odd? The point is within the polygon!
|
584
|
+
if (intersectionCount % 2 === 1) {
|
585
|
+
return true;
|
586
|
+
}
|
587
|
+
}
|
588
|
+
|
589
|
+
// Grow the rectangle for possible additional precision.
|
590
|
+
const grownRect = rect.grownBy(Math.min(rect.size.x, rect.size.y));
|
591
|
+
const edges = [];
|
592
|
+
for (const subrect of grownRect.divideIntoGrid(4, 4)) {
|
593
|
+
edges.push(...subrect.getEdges());
|
594
|
+
}
|
595
|
+
|
596
|
+
for (const edge of edges) {
|
597
|
+
for (const line of polygon) {
|
598
|
+
if (edge.intersects(line)) {
|
599
|
+
return true;
|
600
|
+
}
|
601
|
+
}
|
602
|
+
}
|
603
|
+
|
604
|
+
// Even? Probably no intersection.
|
605
|
+
return false;
|
606
|
+
}
|
607
|
+
|
608
|
+
// Returns a path that outlines [rect]. If [lineWidth] is not given, the resultant path is
|
609
|
+
// the outline of [rect]. Otherwise, the resultant path represents a line of width [lineWidth]
|
610
|
+
// that traces [rect].
|
611
|
+
public static fromRect(rect: Rect2, lineWidth: number|null = null): Path {
|
612
|
+
const commands: PathCommand[] = [];
|
613
|
+
|
614
|
+
let corners;
|
615
|
+
let startPoint;
|
616
|
+
|
617
|
+
if (lineWidth !== null) {
|
618
|
+
// Vector from the top left corner or bottom right corner to the edge of the
|
619
|
+
// stroked region.
|
620
|
+
const cornerToEdge = Vec2.of(lineWidth, lineWidth).times(0.5);
|
621
|
+
const innerRect = Rect2.fromCorners(
|
622
|
+
rect.topLeft.plus(cornerToEdge),
|
623
|
+
rect.bottomRight.minus(cornerToEdge)
|
624
|
+
);
|
625
|
+
const outerRect = Rect2.fromCorners(
|
626
|
+
rect.topLeft.minus(cornerToEdge),
|
627
|
+
rect.bottomRight.plus(cornerToEdge)
|
628
|
+
);
|
629
|
+
|
630
|
+
corners = [
|
631
|
+
innerRect.corners[3],
|
632
|
+
...innerRect.corners,
|
633
|
+
...outerRect.corners.reverse(),
|
634
|
+
];
|
635
|
+
startPoint = outerRect.corners[3];
|
636
|
+
} else {
|
637
|
+
corners = rect.corners.slice(1);
|
638
|
+
startPoint = rect.corners[0];
|
639
|
+
}
|
640
|
+
|
641
|
+
for (const corner of corners) {
|
642
|
+
commands.push({
|
643
|
+
kind: PathCommandType.LineTo,
|
644
|
+
point: corner,
|
645
|
+
});
|
646
|
+
}
|
647
|
+
|
648
|
+
// Close the shape
|
649
|
+
commands.push({
|
650
|
+
kind: PathCommandType.LineTo,
|
651
|
+
point: startPoint,
|
652
|
+
});
|
653
|
+
|
654
|
+
return new Path(startPoint, commands);
|
655
|
+
}
|
656
|
+
|
657
|
+
public static fromRenderable(renderable: RenderablePathSpec): Path {
|
658
|
+
if (renderable.path) {
|
659
|
+
return renderable.path;
|
660
|
+
}
|
661
|
+
|
662
|
+
return new Path(renderable.startPoint, renderable.commands);
|
663
|
+
}
|
664
|
+
|
665
|
+
public toRenderable(fill: RenderingStyle): RenderablePathSpec {
|
666
|
+
return {
|
667
|
+
startPoint: this.startPoint,
|
668
|
+
style: fill,
|
669
|
+
commands: this.parts,
|
670
|
+
path: this,
|
671
|
+
};
|
672
|
+
}
|
673
|
+
|
674
|
+
/**
|
675
|
+
* @returns a Path that, when rendered, looks roughly equivalent to the given path.
|
676
|
+
*/
|
677
|
+
public static visualEquivalent(renderablePath: RenderablePathSpec, visibleRect: Rect2): RenderablePathSpec {
|
678
|
+
const path = Path.fromRenderable(renderablePath);
|
679
|
+
const strokeWidth = renderablePath.style.stroke?.width ?? 0;
|
680
|
+
const onlyStroked = strokeWidth > 0 && renderablePath.style.fill.a === 0;
|
681
|
+
|
682
|
+
// Scale the expanded rect --- the visual equivalent is only close for huge strokes.
|
683
|
+
const expandedRect = visibleRect.grownBy(strokeWidth)
|
684
|
+
.transformedBoundingBox(Mat33.scaling2D(4, visibleRect.center));
|
685
|
+
|
686
|
+
// TODO: Handle simplifying very small paths.
|
687
|
+
if (expandedRect.containsRect(path.bbox.grownBy(strokeWidth))) {
|
688
|
+
return renderablePath;
|
689
|
+
}
|
690
|
+
const parts: PathCommand[] = [];
|
691
|
+
let startPoint = path.startPoint;
|
692
|
+
|
693
|
+
for (const part of path.parts) {
|
694
|
+
const partBBox = Path.computeBBoxForSegment(startPoint, part).grownBy(strokeWidth);
|
695
|
+
let endPoint;
|
696
|
+
|
697
|
+
if (part.kind === PathCommandType.LineTo || part.kind === PathCommandType.MoveTo) {
|
698
|
+
endPoint = part.point;
|
699
|
+
} else {
|
700
|
+
endPoint = part.endPoint;
|
701
|
+
}
|
702
|
+
|
703
|
+
const intersectsVisible = partBBox.intersects(visibleRect);
|
704
|
+
|
705
|
+
if (intersectsVisible) {
|
706
|
+
// TODO: Can we trim parts of paths that intersect the visible rectangle?
|
707
|
+
parts.push(part);
|
708
|
+
} else if (onlyStroked || part.kind === PathCommandType.MoveTo) {
|
709
|
+
// We're stroking (not filling) and the path doesn't intersect the bounding box.
|
710
|
+
// Don't draw it, but preserve the endpoints.
|
711
|
+
parts.push({
|
712
|
+
kind: PathCommandType.MoveTo,
|
713
|
+
point: endPoint,
|
714
|
+
});
|
715
|
+
}
|
716
|
+
else {
|
717
|
+
// Otherwise, we may be filling. Try to roughly preserve the filled region.
|
718
|
+
parts.push({
|
719
|
+
kind: PathCommandType.LineTo,
|
720
|
+
point: endPoint,
|
721
|
+
});
|
722
|
+
}
|
723
|
+
|
724
|
+
startPoint = endPoint;
|
725
|
+
}
|
726
|
+
|
727
|
+
return new Path(path.startPoint, parts).toRenderable(renderablePath.style);
|
728
|
+
}
|
729
|
+
|
730
|
+
private cachedStringVersion: string|null = null;
|
731
|
+
|
732
|
+
public toString(useNonAbsCommands?: boolean): string {
|
733
|
+
if (this.cachedStringVersion) {
|
734
|
+
return this.cachedStringVersion;
|
735
|
+
}
|
736
|
+
|
737
|
+
if (useNonAbsCommands === undefined) {
|
738
|
+
// Hueristic: Try to determine whether converting absolute to relative commands is worth it.
|
739
|
+
useNonAbsCommands = Math.abs(this.bbox.topLeft.x) > 10 && Math.abs(this.bbox.topLeft.y) > 10;
|
740
|
+
}
|
741
|
+
|
742
|
+
const result = Path.toString(this.startPoint, this.parts, !useNonAbsCommands);
|
743
|
+
this.cachedStringVersion = result;
|
744
|
+
return result;
|
745
|
+
}
|
746
|
+
|
747
|
+
public serialize(): string {
|
748
|
+
return this.toString();
|
749
|
+
}
|
750
|
+
|
751
|
+
// @param onlyAbsCommands - True if we should avoid converting absolute coordinates to relative offsets -- such
|
752
|
+
// conversions can lead to smaller output strings, but also take time.
|
753
|
+
public static toString(startPoint: Point2, parts: PathCommand[], onlyAbsCommands?: boolean): string {
|
754
|
+
const result: string[] = [];
|
755
|
+
|
756
|
+
let prevPoint: Point2|undefined;
|
757
|
+
const addCommand = (command: string, ...points: Point2[]) => {
|
758
|
+
const absoluteCommandParts: string[] = [];
|
759
|
+
const relativeCommandParts: string[] = [];
|
760
|
+
const makeAbsCommand = !prevPoint || onlyAbsCommands;
|
761
|
+
const roundedPrevX = prevPoint ? toRoundedString(prevPoint.x) : '';
|
762
|
+
const roundedPrevY = prevPoint ? toRoundedString(prevPoint.y) : '';
|
763
|
+
|
764
|
+
for (const point of points) {
|
765
|
+
const xComponent = toRoundedString(point.x);
|
766
|
+
const yComponent = toRoundedString(point.y);
|
767
|
+
|
768
|
+
// Relative commands are often shorter as strings than absolute commands.
|
769
|
+
if (!makeAbsCommand) {
|
770
|
+
const xComponentRelative = toStringOfSamePrecision(point.x - prevPoint!.x, xComponent, roundedPrevX, roundedPrevY);
|
771
|
+
const yComponentRelative = toStringOfSamePrecision(point.y - prevPoint!.y, yComponent, roundedPrevX, roundedPrevY);
|
772
|
+
|
773
|
+
// No need for an additional separator if it starts with a '-'
|
774
|
+
if (yComponentRelative.charAt(0) === '-') {
|
775
|
+
relativeCommandParts.push(`${xComponentRelative}${yComponentRelative}`);
|
776
|
+
} else {
|
777
|
+
relativeCommandParts.push(`${xComponentRelative},${yComponentRelative}`);
|
778
|
+
}
|
779
|
+
} else {
|
780
|
+
absoluteCommandParts.push(`${xComponent},${yComponent}`);
|
781
|
+
}
|
782
|
+
}
|
783
|
+
|
784
|
+
let commandString;
|
785
|
+
if (makeAbsCommand) {
|
786
|
+
commandString = `${command}${absoluteCommandParts.join(' ')}`;
|
787
|
+
} else {
|
788
|
+
commandString = `${command.toLowerCase()}${relativeCommandParts.join(' ')}`;
|
789
|
+
}
|
790
|
+
|
791
|
+
// Don't add no-ops.
|
792
|
+
if (commandString === 'l0,0' || commandString === 'm0,0') {
|
793
|
+
return;
|
794
|
+
}
|
795
|
+
result.push(commandString);
|
796
|
+
|
797
|
+
if (points.length > 0) {
|
798
|
+
prevPoint = points[points.length - 1];
|
799
|
+
}
|
800
|
+
};
|
801
|
+
|
802
|
+
// Don't add two moveTos in a row (this can happen if
|
803
|
+
// the start point corresponds to a moveTo _and_ the first command is
|
804
|
+
// also a moveTo)
|
805
|
+
if (parts[0]?.kind !== PathCommandType.MoveTo) {
|
806
|
+
addCommand('M', startPoint);
|
807
|
+
}
|
808
|
+
|
809
|
+
let exhaustivenessCheck: never;
|
810
|
+
for (let i = 0; i < parts.length; i++) {
|
811
|
+
const part = parts[i];
|
812
|
+
|
813
|
+
switch (part.kind) {
|
814
|
+
case PathCommandType.MoveTo:
|
815
|
+
addCommand('M', part.point);
|
816
|
+
break;
|
817
|
+
case PathCommandType.LineTo:
|
818
|
+
addCommand('L', part.point);
|
819
|
+
break;
|
820
|
+
case PathCommandType.CubicBezierTo:
|
821
|
+
addCommand('C', part.controlPoint1, part.controlPoint2, part.endPoint);
|
822
|
+
break;
|
823
|
+
case PathCommandType.QuadraticBezierTo:
|
824
|
+
addCommand('Q', part.controlPoint, part.endPoint);
|
825
|
+
break;
|
826
|
+
default:
|
827
|
+
exhaustivenessCheck = part;
|
828
|
+
return exhaustivenessCheck;
|
829
|
+
}
|
830
|
+
}
|
831
|
+
|
832
|
+
return result.join('');
|
833
|
+
}
|
834
|
+
|
835
|
+
// Create a Path from a SVG path specification.
|
836
|
+
// TODO: Support a larger subset of SVG paths.
|
837
|
+
// TODO: Support `s`,`t` commands shorthands.
|
838
|
+
public static fromString(pathString: string): Path {
|
839
|
+
// See the MDN reference:
|
840
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
|
841
|
+
// and
|
842
|
+
// https://www.w3.org/TR/SVG2/paths.html
|
843
|
+
|
844
|
+
// Remove linebreaks
|
845
|
+
pathString = pathString.split('\n').join(' ');
|
846
|
+
|
847
|
+
let lastPos: Point2 = Vec2.zero;
|
848
|
+
let firstPos: Point2|null = null;
|
849
|
+
let startPos: Point2|null = null;
|
850
|
+
let isFirstCommand: boolean = true;
|
851
|
+
const commands: PathCommand[] = [];
|
852
|
+
|
853
|
+
|
854
|
+
const moveTo = (point: Point2) => {
|
855
|
+
// The first moveTo/lineTo is already handled by the [startPoint] parameter of the Path constructor.
|
856
|
+
if (isFirstCommand) {
|
857
|
+
isFirstCommand = false;
|
858
|
+
return;
|
859
|
+
}
|
860
|
+
|
861
|
+
commands.push({
|
862
|
+
kind: PathCommandType.MoveTo,
|
863
|
+
point,
|
864
|
+
});
|
865
|
+
};
|
866
|
+
const lineTo = (point: Point2) => {
|
867
|
+
if (isFirstCommand) {
|
868
|
+
isFirstCommand = false;
|
869
|
+
return;
|
870
|
+
}
|
871
|
+
|
872
|
+
commands.push({
|
873
|
+
kind: PathCommandType.LineTo,
|
874
|
+
point,
|
875
|
+
});
|
876
|
+
};
|
877
|
+
const cubicBezierTo = (cp1: Point2, cp2: Point2, end: Point2) => {
|
878
|
+
commands.push({
|
879
|
+
kind: PathCommandType.CubicBezierTo,
|
880
|
+
controlPoint1: cp1,
|
881
|
+
controlPoint2: cp2,
|
882
|
+
endPoint: end,
|
883
|
+
});
|
884
|
+
};
|
885
|
+
const quadraticBeierTo = (controlPoint: Point2, endPoint: Point2) => {
|
886
|
+
commands.push({
|
887
|
+
kind: PathCommandType.QuadraticBezierTo,
|
888
|
+
controlPoint,
|
889
|
+
endPoint,
|
890
|
+
});
|
891
|
+
};
|
892
|
+
const commandArgCounts: Record<string, number> = {
|
893
|
+
'm': 1,
|
894
|
+
'l': 1,
|
895
|
+
'c': 3,
|
896
|
+
'q': 2,
|
897
|
+
'z': 0,
|
898
|
+
'h': 1,
|
899
|
+
'v': 1,
|
900
|
+
};
|
901
|
+
|
902
|
+
// Each command: Command character followed by anything that isn't a command character
|
903
|
+
const commandExp = /([MZLHVCSQTA])\s*([^MZLHVCSQTA]*)/ig;
|
904
|
+
let current;
|
905
|
+
while ((current = commandExp.exec(pathString)) !== null) {
|
906
|
+
const argParts = current[2].trim().split(/[^0-9Ee.-]/).filter(
|
907
|
+
part => part.length > 0
|
908
|
+
).reduce((accumualtor: string[], current: string): string[] => {
|
909
|
+
// As of 09/2022, iOS Safari doesn't support support lookbehind in regular
|
910
|
+
// expressions. As such, we need an alternative.
|
911
|
+
// Because '-' can be used as a path separator, unless preceeded by an 'e' (as in 1e-5),
|
912
|
+
// we need special cases:
|
913
|
+
current = current.replace(/([^eE])[-]/g, '$1 -');
|
914
|
+
const parts = current.split(' -');
|
915
|
+
if (parts[0] !== '') {
|
916
|
+
accumualtor.push(parts[0]);
|
917
|
+
}
|
918
|
+
accumualtor.push(...parts.slice(1).map(part => `-${part}`));
|
919
|
+
return accumualtor;
|
920
|
+
}, []);
|
921
|
+
|
922
|
+
let numericArgs = argParts.map(arg => parseFloat(arg));
|
923
|
+
|
924
|
+
let commandChar = current[1].toLowerCase();
|
925
|
+
let uppercaseCommand = current[1] !== commandChar;
|
926
|
+
|
927
|
+
// Convert commands that don't take points into commands that do.
|
928
|
+
if (commandChar === 'v' || commandChar === 'h') {
|
929
|
+
numericArgs = numericArgs.reduce((accumulator: number[], current: number): number[] => {
|
930
|
+
if (commandChar === 'v') {
|
931
|
+
return accumulator.concat(uppercaseCommand ? lastPos.x : 0, current);
|
932
|
+
} else {
|
933
|
+
return accumulator.concat(current, uppercaseCommand ? lastPos.y : 0);
|
934
|
+
}
|
935
|
+
}, []);
|
936
|
+
commandChar = 'l';
|
937
|
+
} else if (commandChar === 'z') {
|
938
|
+
if (firstPos) {
|
939
|
+
numericArgs = [ firstPos.x, firstPos.y ];
|
940
|
+
firstPos = lastPos;
|
941
|
+
} else {
|
942
|
+
continue;
|
943
|
+
}
|
944
|
+
|
945
|
+
// 'z' always acts like an uppercase lineTo(startPos)
|
946
|
+
uppercaseCommand = true;
|
947
|
+
commandChar = 'l';
|
948
|
+
}
|
949
|
+
|
950
|
+
|
951
|
+
const commandArgCount: number = commandArgCounts[commandChar] ?? 0;
|
952
|
+
const allArgs = numericArgs.reduce((
|
953
|
+
accumulator: Point2[], current, index, parts
|
954
|
+
): Point2[] => {
|
955
|
+
if (index % 2 !== 0) {
|
956
|
+
const currentAsFloat = current;
|
957
|
+
const prevAsFloat = parts[index - 1];
|
958
|
+
return accumulator.concat(Vec2.of(prevAsFloat, currentAsFloat));
|
959
|
+
} else {
|
960
|
+
return accumulator;
|
961
|
+
}
|
962
|
+
}, []).map((coordinate, index): Point2 => {
|
963
|
+
// Lowercase commands are relative, uppercase commands use absolute
|
964
|
+
// positioning
|
965
|
+
let newPos;
|
966
|
+
if (uppercaseCommand) {
|
967
|
+
newPos = coordinate;
|
968
|
+
} else {
|
969
|
+
newPos = lastPos.plus(coordinate);
|
970
|
+
}
|
971
|
+
|
972
|
+
if ((index + 1) % commandArgCount === 0) {
|
973
|
+
lastPos = newPos;
|
974
|
+
}
|
975
|
+
|
976
|
+
return newPos;
|
977
|
+
});
|
978
|
+
|
979
|
+
if (allArgs.length % commandArgCount !== 0) {
|
980
|
+
throw new Error([
|
981
|
+
`Incorrect number of arguments: got ${JSON.stringify(allArgs)} with a length of ${allArgs.length} ≠ ${commandArgCount}k, k ∈ ℤ.`,
|
982
|
+
`The number of arguments to ${commandChar} must be a multiple of ${commandArgCount}!`,
|
983
|
+
`Command: ${current[0]}`,
|
984
|
+
].join('\n'));
|
985
|
+
}
|
986
|
+
|
987
|
+
for (let argPos = 0; argPos < allArgs.length; argPos += commandArgCount) {
|
988
|
+
const args = allArgs.slice(argPos, argPos + commandArgCount);
|
989
|
+
|
990
|
+
switch (commandChar.toLowerCase()) {
|
991
|
+
case 'm':
|
992
|
+
if (argPos === 0) {
|
993
|
+
moveTo(args[0]);
|
994
|
+
} else {
|
995
|
+
lineTo(args[0]);
|
996
|
+
}
|
997
|
+
break;
|
998
|
+
case 'l':
|
999
|
+
lineTo(args[0]);
|
1000
|
+
break;
|
1001
|
+
case 'c':
|
1002
|
+
cubicBezierTo(args[0], args[1], args[2]);
|
1003
|
+
break;
|
1004
|
+
case 'q':
|
1005
|
+
quadraticBeierTo(args[0], args[1]);
|
1006
|
+
break;
|
1007
|
+
default:
|
1008
|
+
throw new Error(`Unknown path command ${commandChar}`);
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
isFirstCommand = false;
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
if (allArgs.length > 0) {
|
1015
|
+
firstPos ??= allArgs[0];
|
1016
|
+
startPos ??= firstPos;
|
1017
|
+
lastPos = allArgs[allArgs.length - 1];
|
1018
|
+
}
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
const result = new Path(startPos ?? Vec2.zero, commands);
|
1022
|
+
result.cachedStringVersion = pathString;
|
1023
|
+
return result;
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
public static empty: Path = new Path(Vec2.zero, []);
|
1027
|
+
}
|