js-draw 0.25.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -20
- package/build-config.json +22 -21
- package/dist/Editor.css +1281 -0
- package/dist/bundle.js +3 -3
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.d.ts +91 -12
- package/dist/cjs/Editor.js +619 -590
- package/dist/cjs/EditorImage.d.ts +5 -2
- package/dist/cjs/EditorImage.js +258 -297
- package/dist/cjs/EventDispatcher.js +17 -19
- package/dist/cjs/Pointer.d.ts +3 -1
- package/dist/cjs/Pointer.js +41 -44
- package/dist/cjs/SVGLoader.d.ts +7 -1
- package/dist/cjs/SVGLoader.js +373 -474
- package/dist/cjs/UndoRedoHistory.js +28 -40
- package/dist/cjs/Viewport.d.ts +1 -4
- package/dist/cjs/Viewport.js +150 -193
- package/dist/cjs/bundle/bundled.js +4 -1
- package/dist/cjs/commands/Command.js +22 -49
- package/dist/cjs/commands/Duplicate.js +28 -44
- package/dist/cjs/commands/Erase.js +36 -54
- package/dist/cjs/commands/SerializableCommand.js +20 -35
- package/dist/cjs/commands/UnresolvedCommand.js +14 -29
- package/dist/cjs/commands/invertCommand.js +29 -51
- package/dist/cjs/commands/lib.js +9 -6
- package/dist/cjs/commands/localization.d.ts +1 -1
- package/dist/cjs/commands/localization.js +9 -9
- package/dist/cjs/commands/uniteCommands.js +57 -87
- package/dist/cjs/components/AbstractComponent.d.ts +11 -3
- package/dist/cjs/components/AbstractComponent.js +141 -169
- package/dist/cjs/components/BackgroundComponent.d.ts +3 -6
- package/dist/cjs/components/BackgroundComponent.js +124 -149
- package/dist/cjs/components/ImageComponent.d.ts +3 -5
- package/dist/cjs/components/ImageComponent.js +95 -175
- package/dist/cjs/components/RestylableComponent.d.ts +1 -1
- package/dist/cjs/components/RestylableComponent.js +41 -56
- package/dist/cjs/components/SVGGlobalAttributesObject.d.ts +1 -3
- package/dist/cjs/components/SVGGlobalAttributesObject.js +34 -51
- package/dist/cjs/components/Stroke.d.ts +4 -6
- package/dist/cjs/components/Stroke.js +95 -121
- package/dist/cjs/components/TextComponent.d.ts +2 -4
- package/dist/cjs/components/TextComponent.js +189 -234
- package/dist/cjs/components/UnknownSVGObject.d.ts +1 -3
- package/dist/cjs/components/UnknownSVGObject.js +30 -43
- package/dist/cjs/components/builders/ArrowBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/ArrowBuilder.js +43 -42
- package/dist/cjs/components/builders/CircleBuilder.js +43 -43
- package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +3 -2
- package/dist/cjs/components/builders/FreehandLineBuilder.js +73 -86
- package/dist/cjs/components/builders/LineBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/LineBuilder.js +38 -36
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +131 -139
- package/dist/cjs/components/builders/RectangleBuilder.d.ts +1 -1
- package/dist/cjs/components/builders/RectangleBuilder.js +31 -31
- package/dist/cjs/components/builders/types.d.ts +1 -1
- package/dist/cjs/components/lib.d.ts +3 -1
- package/dist/cjs/components/lib.js +10 -7
- package/dist/cjs/components/localization.js +4 -4
- package/dist/cjs/components/util/StrokeSmoother.d.ts +1 -2
- package/dist/cjs/components/util/StrokeSmoother.js +67 -72
- package/dist/cjs/components/util/describeComponentList.d.ts +1 -1
- package/dist/cjs/components/util/describeComponentList.js +4 -5
- package/dist/cjs/dialogs/makeAboutDialog.d.ts +15 -0
- package/dist/cjs/dialogs/makeAboutDialog.js +54 -0
- package/dist/cjs/inputEvents.d.ts +84 -0
- package/dist/cjs/inputEvents.js +40 -0
- package/dist/cjs/lib.d.ts +29 -13
- package/dist/cjs/lib.js +38 -23
- package/dist/cjs/localization.js +19 -18
- package/dist/cjs/localizations/de.js +117 -13
- package/dist/cjs/localizations/en.js +4 -13
- package/dist/cjs/localizations/es.js +62 -23
- package/dist/cjs/localizations/getLocalizationTable.js +15 -13
- package/dist/cjs/rendering/Display.d.ts +1 -2
- package/dist/cjs/rendering/Display.js +70 -83
- package/dist/cjs/rendering/RenderablePathSpec.d.ts +15 -0
- package/dist/cjs/rendering/RenderablePathSpec.js +70 -0
- package/dist/cjs/rendering/RenderingStyle.d.ts +4 -4
- package/dist/cjs/rendering/RenderingStyle.js +18 -28
- package/dist/cjs/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/cjs/rendering/TextRenderingStyle.js +13 -18
- package/dist/cjs/rendering/caching/CacheRecord.d.ts +1 -2
- package/dist/cjs/rendering/caching/CacheRecord.js +20 -22
- package/dist/cjs/rendering/caching/CacheRecordManager.d.ts +1 -1
- package/dist/cjs/rendering/caching/CacheRecordManager.js +17 -15
- package/dist/cjs/rendering/caching/RenderingCache.js +19 -19
- package/dist/cjs/rendering/caching/RenderingCacheNode.d.ts +1 -1
- package/dist/cjs/rendering/caching/RenderingCacheNode.js +98 -118
- package/dist/cjs/rendering/caching/testUtils.js +24 -23
- package/dist/cjs/rendering/caching/types.d.ts +3 -3
- package/dist/cjs/rendering/lib.js +8 -5
- package/dist/cjs/rendering/localization.js +5 -5
- package/dist/cjs/rendering/renderers/AbstractRenderer.d.ts +2 -11
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +53 -57
- package/dist/cjs/rendering/renderers/CanvasRenderer.d.ts +3 -5
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +91 -106
- package/dist/cjs/rendering/renderers/DummyRenderer.d.ts +1 -4
- package/dist/cjs/rendering/renderers/DummyRenderer.js +56 -76
- package/dist/cjs/rendering/renderers/SVGRenderer.d.ts +5 -5
- package/dist/cjs/rendering/renderers/SVGRenderer.js +194 -176
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.d.ts +1 -3
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +47 -72
- package/dist/cjs/shortcuts/KeyBinding.d.ts +5 -0
- package/dist/cjs/shortcuts/KeyBinding.js +94 -70
- package/dist/cjs/shortcuts/KeyboardShortcutManager.d.ts +1 -1
- package/dist/cjs/shortcuts/KeyboardShortcutManager.js +36 -45
- package/dist/cjs/shortcuts/lib.js +5 -2
- package/dist/cjs/testing/createEditor.js +7 -4
- package/dist/cjs/testing/getUniquePointerId.js +4 -5
- package/dist/cjs/testing/lib.js +5 -2
- package/dist/cjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/cjs/testing/sendPenEvent.js +10 -7
- package/dist/cjs/testing/sendTouchEvent.d.ts +2 -2
- package/dist/cjs/testing/sendTouchEvent.js +34 -16
- package/dist/cjs/toolbar/AbstractToolbar.d.ts +166 -0
- package/dist/cjs/toolbar/AbstractToolbar.js +410 -0
- package/dist/cjs/toolbar/DropdownToolbar.d.ts +43 -0
- package/dist/cjs/toolbar/DropdownToolbar.js +176 -0
- package/dist/cjs/toolbar/EdgeToolbar.d.ts +47 -0
- package/dist/cjs/toolbar/EdgeToolbar.js +422 -0
- package/dist/cjs/toolbar/IconProvider.d.ts +54 -30
- package/dist/cjs/toolbar/IconProvider.js +652 -224
- package/dist/cjs/toolbar/constants.d.ts +1 -0
- package/dist/cjs/toolbar/constants.js +4 -0
- package/dist/cjs/toolbar/lib.d.ts +4 -2
- package/dist/cjs/toolbar/lib.js +10 -3
- package/dist/cjs/toolbar/localization.d.ts +9 -2
- package/dist/cjs/toolbar/localization.js +26 -19
- package/dist/cjs/toolbar/types.d.ts +7 -0
- package/dist/cjs/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/ActionButtonWidget.js +23 -39
- package/dist/cjs/toolbar/widgets/BaseToolWidget.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/BaseToolWidget.js +35 -37
- package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +60 -5
- package/dist/cjs/toolbar/widgets/BaseWidget.js +232 -177
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +130 -117
- package/dist/cjs/toolbar/widgets/EraserToolWidget.d.ts +1 -3
- package/dist/cjs/toolbar/widgets/EraserToolWidget.js +45 -73
- package/dist/cjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +126 -141
- package/dist/cjs/toolbar/widgets/InsertImageWidget.d.ts +9 -7
- package/dist/cjs/toolbar/widgets/InsertImageWidget.js +147 -212
- package/dist/cjs/toolbar/widgets/OverflowWidget.js +33 -61
- package/dist/cjs/toolbar/widgets/PenToolWidget.d.ts +8 -1
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +162 -234
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +105 -177
- package/dist/cjs/toolbar/widgets/TextToolWidget.js +64 -87
- package/dist/cjs/toolbar/widgets/components/makeColorInput.d.ts +10 -0
- package/dist/cjs/toolbar/{makeColorInput.js → widgets/components/makeColorInput.js} +57 -34
- package/dist/cjs/toolbar/widgets/components/makeFileInput.d.ts +12 -0
- package/dist/cjs/toolbar/widgets/components/makeFileInput.js +111 -0
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.d.ts +24 -0
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +127 -0
- package/dist/cjs/toolbar/widgets/components/makeSeparator.d.ts +7 -0
- package/dist/cjs/toolbar/widgets/components/makeSeparator.js +16 -0
- package/dist/cjs/toolbar/widgets/components/makeThicknessSlider.d.ts +8 -0
- package/dist/cjs/toolbar/widgets/components/makeThicknessSlider.js +47 -0
- package/dist/cjs/toolbar/widgets/keybindings.js +8 -5
- package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.d.ts +21 -0
- package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.js +199 -0
- package/dist/cjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.d.ts +14 -0
- package/dist/cjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.js +60 -0
- package/dist/cjs/toolbar/widgets/layout/types.d.ts +63 -0
- package/dist/cjs/toolbar/widgets/layout/types.js +2 -0
- package/dist/cjs/toolbar/widgets/lib.d.ts +1 -1
- package/dist/cjs/toolbar/widgets/lib.js +15 -11
- package/dist/cjs/tools/BaseTool.d.ts +28 -9
- package/dist/cjs/tools/BaseTool.js +128 -51
- package/dist/cjs/tools/Eraser.d.ts +8 -1
- package/dist/cjs/tools/Eraser.js +82 -92
- package/dist/cjs/tools/FindTool.d.ts +1 -1
- package/dist/cjs/tools/FindTool.js +61 -77
- package/dist/cjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
- package/dist/cjs/tools/InputFilter/FunctionMapper.js +21 -0
- package/dist/cjs/tools/InputFilter/InputMapper.d.ts +23 -0
- package/dist/cjs/tools/InputFilter/InputMapper.js +38 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.d.ts +15 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.js +54 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +181 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +84 -0
- package/dist/cjs/tools/PanZoom.d.ts +4 -2
- package/dist/cjs/tools/PanZoom.js +186 -248
- package/dist/cjs/tools/PasteHandler.d.ts +1 -1
- package/dist/cjs/tools/PasteHandler.js +49 -148
- package/dist/cjs/tools/Pen.d.ts +12 -11
- package/dist/cjs/tools/Pen.js +123 -158
- package/dist/cjs/tools/PipetteTool.d.ts +11 -2
- package/dist/cjs/tools/PipetteTool.js +51 -48
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +1 -1
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +15 -30
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +5 -5
- package/dist/cjs/tools/SelectionTool/Selection.js +308 -415
- package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +15 -5
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +63 -37
- package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +4 -4
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +164 -187
- package/dist/cjs/tools/SelectionTool/TransformMode.d.ts +1 -1
- package/dist/cjs/tools/SelectionTool/TransformMode.js +65 -66
- package/dist/cjs/tools/SoundUITool.d.ts +2 -1
- package/dist/cjs/tools/SoundUITool.js +70 -84
- package/dist/cjs/tools/TextTool.d.ts +5 -3
- package/dist/cjs/tools/TextTool.js +169 -173
- package/dist/cjs/tools/ToolController.d.ts +16 -2
- package/dist/cjs/tools/ToolController.js +124 -100
- package/dist/cjs/tools/ToolEnabledGroup.js +6 -9
- package/dist/cjs/tools/ToolSwitcherShortcut.d.ts +1 -1
- package/dist/cjs/tools/ToolSwitcherShortcut.js +16 -32
- package/dist/cjs/tools/ToolbarShortcutHandler.d.ts +1 -1
- package/dist/cjs/tools/ToolbarShortcutHandler.js +17 -33
- package/dist/cjs/tools/UndoRedoShortcut.d.ts +1 -1
- package/dist/cjs/tools/UndoRedoShortcut.js +12 -27
- package/dist/cjs/tools/keybindings.js +21 -18
- package/dist/cjs/tools/lib.js +17 -14
- package/dist/cjs/tools/localization.d.ts +2 -1
- package/dist/cjs/tools/localization.js +8 -7
- package/dist/cjs/types.d.ts +22 -80
- package/dist/cjs/types.js +8 -16
- package/dist/cjs/util/ReactiveValue.d.ts +65 -0
- package/dist/cjs/util/ReactiveValue.js +166 -0
- package/dist/cjs/util/assertions.js +5 -8
- package/dist/cjs/util/fileToBase64.js +6 -6
- package/dist/cjs/util/guessKeyCodeFromKey.d.ts +9 -0
- package/dist/cjs/util/guessKeyCodeFromKey.js +32 -0
- package/dist/cjs/util/listPrefixMatch.d.ts +6 -0
- package/dist/cjs/util/listPrefixMatch.js +17 -0
- package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.d.ts +2 -0
- package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.js +17 -0
- package/dist/cjs/util/untilNextAnimationFrame.js +3 -3
- package/dist/cjs/util/waitForAll.js +3 -3
- package/dist/cjs/util/waitForTimeout.js +3 -3
- package/dist/cjs/version.d.ts +4 -0
- package/dist/cjs/version.js +5 -0
- package/dist/mjs/Editor.d.ts +91 -12
- package/dist/mjs/Editor.mjs +565 -563
- package/dist/mjs/EditorImage.d.ts +5 -2
- package/dist/mjs/EditorImage.mjs +248 -291
- package/dist/mjs/EventDispatcher.mjs +17 -20
- package/dist/mjs/Pointer.d.ts +3 -1
- package/dist/mjs/Pointer.mjs +40 -44
- package/dist/mjs/SVGLoader.d.ts +7 -1
- package/dist/mjs/SVGLoader.mjs +338 -466
- package/dist/mjs/UndoRedoHistory.mjs +27 -39
- package/dist/mjs/Viewport.d.ts +1 -4
- package/dist/mjs/Viewport.mjs +139 -187
- package/dist/mjs/commands/Command.mjs +21 -49
- package/dist/mjs/commands/Duplicate.mjs +22 -41
- package/dist/mjs/commands/Erase.mjs +30 -51
- package/dist/mjs/commands/SerializableCommand.mjs +16 -34
- package/dist/mjs/commands/UnresolvedCommand.mjs +10 -29
- package/dist/mjs/commands/invertCommand.mjs +24 -49
- package/dist/mjs/commands/localization.d.ts +1 -1
- package/dist/mjs/commands/localization.mjs +10 -10
- package/dist/mjs/commands/uniteCommands.mjs +52 -85
- package/dist/mjs/components/AbstractComponent.d.ts +11 -3
- package/dist/mjs/components/AbstractComponent.mjs +135 -166
- package/dist/mjs/components/BackgroundComponent.d.ts +3 -6
- package/dist/mjs/components/BackgroundComponent.mjs +107 -136
- package/dist/mjs/components/ImageComponent.d.ts +3 -5
- package/dist/mjs/components/ImageComponent.mjs +90 -174
- package/dist/mjs/components/RestylableComponent.d.ts +1 -1
- package/dist/mjs/components/RestylableComponent.mjs +35 -53
- package/dist/mjs/components/SVGGlobalAttributesObject.d.ts +1 -3
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +29 -50
- package/dist/mjs/components/Stroke.d.ts +4 -6
- package/dist/mjs/components/Stroke.mjs +89 -119
- package/dist/mjs/components/TextComponent.d.ts +2 -4
- package/dist/mjs/components/TextComponent.mjs +180 -228
- package/dist/mjs/components/UnknownSVGObject.d.ts +1 -3
- package/dist/mjs/components/UnknownSVGObject.mjs +26 -43
- package/dist/mjs/components/builders/ArrowBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/ArrowBuilder.mjs +32 -35
- package/dist/mjs/components/builders/CircleBuilder.mjs +35 -38
- package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +3 -2
- package/dist/mjs/components/builders/FreehandLineBuilder.mjs +52 -69
- package/dist/mjs/components/builders/LineBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/LineBuilder.mjs +30 -32
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +103 -115
- package/dist/mjs/components/builders/RectangleBuilder.d.ts +1 -1
- package/dist/mjs/components/builders/RectangleBuilder.mjs +27 -31
- package/dist/mjs/components/builders/types.d.ts +1 -1
- package/dist/mjs/components/lib.d.ts +3 -1
- package/dist/mjs/components/lib.mjs +1 -1
- package/dist/mjs/components/localization.mjs +5 -5
- package/dist/mjs/components/util/StrokeSmoother.d.ts +1 -2
- package/dist/mjs/components/util/StrokeSmoother.mjs +63 -69
- package/dist/mjs/components/util/describeComponentList.d.ts +1 -1
- package/dist/mjs/components/util/describeComponentList.mjs +4 -5
- package/dist/mjs/dialogs/makeAboutDialog.d.ts +15 -0
- package/dist/mjs/dialogs/makeAboutDialog.mjs +52 -0
- package/dist/mjs/inputEvents.d.ts +84 -0
- package/dist/mjs/inputEvents.mjs +34 -0
- package/dist/mjs/lib.d.ts +29 -13
- package/dist/mjs/lib.mjs +30 -13
- package/dist/mjs/localization.mjs +14 -13
- package/dist/mjs/localizations/de.mjs +116 -12
- package/dist/mjs/localizations/en.mjs +3 -12
- package/dist/mjs/localizations/es.mjs +61 -22
- package/dist/mjs/localizations/getLocalizationTable.mjs +12 -13
- package/dist/mjs/rendering/Display.d.ts +1 -2
- package/dist/mjs/rendering/Display.mjs +62 -79
- package/dist/mjs/rendering/RenderablePathSpec.d.ts +15 -0
- package/dist/mjs/rendering/RenderablePathSpec.mjs +64 -0
- package/dist/mjs/rendering/RenderingStyle.d.ts +4 -4
- package/dist/mjs/rendering/RenderingStyle.mjs +16 -26
- package/dist/mjs/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/mjs/rendering/TextRenderingStyle.mjs +12 -17
- package/dist/mjs/rendering/caching/CacheRecord.d.ts +1 -2
- package/dist/mjs/rendering/caching/CacheRecord.mjs +20 -23
- package/dist/mjs/rendering/caching/CacheRecordManager.d.ts +1 -1
- package/dist/mjs/rendering/caching/CacheRecordManager.mjs +13 -15
- package/dist/mjs/rendering/caching/RenderingCache.mjs +13 -17
- package/dist/mjs/rendering/caching/RenderingCacheNode.d.ts +1 -1
- package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +94 -115
- package/dist/mjs/rendering/caching/testUtils.mjs +19 -21
- package/dist/mjs/rendering/caching/types.d.ts +3 -3
- package/dist/mjs/rendering/localization.mjs +6 -6
- package/dist/mjs/rendering/renderers/AbstractRenderer.d.ts +2 -11
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +47 -52
- package/dist/mjs/rendering/renderers/CanvasRenderer.d.ts +3 -5
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +84 -103
- package/dist/mjs/rendering/renderers/DummyRenderer.d.ts +1 -4
- package/dist/mjs/rendering/renderers/DummyRenderer.mjs +51 -75
- package/dist/mjs/rendering/renderers/SVGRenderer.d.ts +5 -5
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +185 -171
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.d.ts +1 -3
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +43 -72
- package/dist/mjs/shortcuts/KeyBinding.d.ts +5 -0
- package/dist/mjs/shortcuts/KeyBinding.mjs +94 -71
- package/dist/mjs/shortcuts/KeyboardShortcutManager.d.ts +1 -1
- package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +32 -44
- package/dist/mjs/testing/createEditor.mjs +2 -2
- package/dist/mjs/testing/getUniquePointerId.mjs +4 -5
- package/dist/mjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/mjs/testing/sendPenEvent.mjs +5 -5
- package/dist/mjs/testing/sendTouchEvent.d.ts +2 -2
- package/dist/mjs/testing/sendTouchEvent.mjs +8 -16
- package/dist/mjs/toolbar/AbstractToolbar.d.ts +166 -0
- package/dist/mjs/toolbar/AbstractToolbar.mjs +405 -0
- package/dist/mjs/toolbar/DropdownToolbar.d.ts +43 -0
- package/dist/mjs/toolbar/DropdownToolbar.mjs +168 -0
- package/dist/mjs/toolbar/EdgeToolbar.d.ts +47 -0
- package/dist/mjs/toolbar/EdgeToolbar.mjs +414 -0
- package/dist/mjs/toolbar/IconProvider.d.ts +54 -30
- package/dist/mjs/toolbar/IconProvider.mjs +644 -219
- package/dist/mjs/toolbar/constants.d.ts +1 -0
- package/dist/mjs/toolbar/constants.mjs +1 -0
- package/dist/mjs/toolbar/lib.d.ts +4 -2
- package/dist/mjs/toolbar/lib.mjs +3 -1
- package/dist/mjs/toolbar/localization.d.ts +9 -2
- package/dist/mjs/toolbar/localization.mjs +27 -20
- package/dist/mjs/toolbar/types.d.ts +7 -0
- package/dist/mjs/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/ActionButtonWidget.mjs +19 -39
- package/dist/mjs/toolbar/widgets/BaseToolWidget.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +30 -36
- package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +60 -5
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +227 -176
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +98 -111
- package/dist/mjs/toolbar/widgets/EraserToolWidget.d.ts +1 -3
- package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +41 -73
- package/dist/mjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +94 -136
- package/dist/mjs/toolbar/widgets/InsertImageWidget.d.ts +9 -7
- package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +140 -208
- package/dist/mjs/toolbar/widgets/OverflowWidget.mjs +30 -62
- package/dist/mjs/toolbar/widgets/PenToolWidget.d.ts +8 -1
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +150 -225
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +97 -173
- package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +59 -85
- package/dist/mjs/toolbar/widgets/components/makeColorInput.d.ts +10 -0
- package/dist/mjs/toolbar/{makeColorInput.mjs → widgets/components/makeColorInput.mjs} +53 -33
- package/dist/mjs/toolbar/widgets/components/makeFileInput.d.ts +12 -0
- package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +106 -0
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.d.ts +24 -0
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +122 -0
- package/dist/mjs/toolbar/widgets/components/makeSeparator.d.ts +7 -0
- package/dist/mjs/toolbar/widgets/components/makeSeparator.mjs +14 -0
- package/dist/mjs/toolbar/widgets/components/makeThicknessSlider.d.ts +8 -0
- package/dist/mjs/toolbar/widgets/components/makeThicknessSlider.mjs +45 -0
- package/dist/mjs/toolbar/widgets/keybindings.mjs +5 -5
- package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.d.ts +21 -0
- package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.mjs +193 -0
- package/dist/mjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.d.ts +14 -0
- package/dist/mjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.mjs +57 -0
- package/dist/mjs/toolbar/widgets/layout/types.d.ts +63 -0
- package/dist/mjs/toolbar/widgets/lib.d.ts +1 -1
- package/dist/mjs/toolbar/widgets/lib.mjs +1 -1
- package/dist/mjs/tools/BaseTool.d.ts +28 -9
- package/dist/mjs/tools/BaseTool.mjs +127 -50
- package/dist/mjs/tools/Eraser.d.ts +8 -1
- package/dist/mjs/tools/Eraser.mjs +72 -86
- package/dist/mjs/tools/FindTool.d.ts +1 -1
- package/dist/mjs/tools/FindTool.mjs +55 -75
- package/dist/mjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
- package/dist/mjs/tools/InputFilter/FunctionMapper.mjs +15 -0
- package/dist/mjs/tools/InputFilter/InputMapper.d.ts +23 -0
- package/dist/mjs/tools/InputFilter/InputMapper.mjs +36 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.d.ts +15 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.mjs +49 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +175 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +78 -0
- package/dist/mjs/tools/PanZoom.d.ts +4 -2
- package/dist/mjs/tools/PanZoom.mjs +169 -235
- package/dist/mjs/tools/PasteHandler.d.ts +1 -1
- package/dist/mjs/tools/PasteHandler.mjs +42 -145
- package/dist/mjs/tools/Pen.d.ts +12 -11
- package/dist/mjs/tools/Pen.mjs +115 -154
- package/dist/mjs/tools/PipetteTool.d.ts +11 -2
- package/dist/mjs/tools/PipetteTool.mjs +47 -48
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +1 -1
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +9 -28
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +5 -5
- package/dist/mjs/tools/SelectionTool/Selection.mjs +268 -401
- package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +15 -5
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +62 -37
- package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +4 -4
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +153 -179
- package/dist/mjs/tools/SelectionTool/TransformMode.d.ts +1 -1
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +52 -59
- package/dist/mjs/tools/SoundUITool.d.ts +2 -1
- package/dist/mjs/tools/SoundUITool.mjs +66 -84
- package/dist/mjs/tools/TextTool.d.ts +5 -3
- package/dist/mjs/tools/TextTool.mjs +155 -163
- package/dist/mjs/tools/ToolController.d.ts +16 -2
- package/dist/mjs/tools/ToolController.mjs +81 -84
- package/dist/mjs/tools/ToolEnabledGroup.mjs +6 -10
- package/dist/mjs/tools/ToolSwitcherShortcut.d.ts +1 -1
- package/dist/mjs/tools/ToolSwitcherShortcut.mjs +12 -32
- package/dist/mjs/tools/ToolbarShortcutHandler.d.ts +1 -1
- package/dist/mjs/tools/ToolbarShortcutHandler.mjs +13 -33
- package/dist/mjs/tools/UndoRedoShortcut.d.ts +1 -1
- package/dist/mjs/tools/UndoRedoShortcut.mjs +7 -26
- package/dist/mjs/tools/keybindings.mjs +34 -34
- package/dist/mjs/tools/localization.d.ts +2 -1
- package/dist/mjs/tools/localization.mjs +9 -8
- package/dist/mjs/types.d.ts +22 -80
- package/dist/mjs/types.mjs +7 -15
- package/dist/mjs/util/ReactiveValue.d.ts +65 -0
- package/dist/mjs/util/ReactiveValue.mjs +161 -0
- package/dist/mjs/util/assertions.mjs +5 -8
- package/dist/mjs/util/fileToBase64.mjs +6 -6
- package/dist/mjs/util/guessKeyCodeFromKey.d.ts +9 -0
- package/dist/mjs/util/guessKeyCodeFromKey.mjs +30 -0
- package/dist/mjs/util/listPrefixMatch.d.ts +6 -0
- package/dist/mjs/util/listPrefixMatch.mjs +15 -0
- package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.d.ts +2 -0
- package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.mjs +15 -0
- package/dist/mjs/util/untilNextAnimationFrame.mjs +3 -3
- package/dist/mjs/util/waitForAll.mjs +3 -3
- package/dist/mjs/util/waitForTimeout.mjs +3 -3
- package/dist/mjs/version.d.ts +4 -0
- package/dist/mjs/version.mjs +3 -0
- package/package.json +11 -22
- package/src/Coloris.css +8 -8
- package/src/Editor.scss +148 -0
- package/src/dialogs/dialogs.scss +36 -0
- package/src/dialogs/makeAboutDialog.scss +41 -0
- package/src/styles.js +1 -1
- package/src/toolbar/{toolbar.css → AbstractToolbar.scss} +47 -85
- package/src/toolbar/DropdownToolbar.scss +46 -0
- package/src/toolbar/EdgeToolbar.scss +511 -0
- package/src/toolbar/toolbar.scss +11 -0
- package/src/toolbar/widgets/DocumentPropertiesWidget.scss +7 -0
- package/src/toolbar/widgets/HandToolWidget.scss +14 -0
- package/src/toolbar/widgets/InsertImageWidget.scss +41 -0
- package/src/toolbar/widgets/PenToolWidget.css +0 -51
- package/src/toolbar/widgets/SelectionToolWidget.scss +6 -0
- package/src/toolbar/widgets/components/components.scss +5 -0
- package/src/toolbar/widgets/components/makeColorInput.scss +82 -0
- package/src/toolbar/widgets/components/makeFileInput.scss +77 -0
- package/src/toolbar/widgets/components/makeGridSelector.scss +60 -0
- package/src/toolbar/widgets/components/makeSeparator.scss +14 -0
- package/src/toolbar/widgets/components/makeThicknessSlider.scss +9 -0
- package/src/tools/FindTool.css +3 -3
- package/src/tools/SelectionTool/SelectionTool.css +23 -11
- package/src/tools/tools.scss +4 -0
- package/tsconfig.json +1 -1
- package/typedoc.json +4 -0
- package/dist/cjs/Color4.d.ts +0 -69
- package/dist/cjs/Color4.js +0 -263
- package/dist/cjs/Editor.loadFrom.test.d.ts +0 -1
- package/dist/cjs/Editor.toSVG.test.d.ts +0 -1
- package/dist/cjs/EditorImage.test.d.ts +0 -1
- package/dist/cjs/EventDispatcher.test.d.ts +0 -1
- package/dist/cjs/SVGLoader.test.d.ts +0 -1
- package/dist/cjs/UndoRedoHistory.test.d.ts +0 -1
- package/dist/cjs/commands/uniteCommands.test.d.ts +0 -1
- package/dist/cjs/components/AbstractComponent.transformBy.test.d.ts +0 -1
- package/dist/cjs/components/BackgroundComponent.test.d.ts +0 -1
- package/dist/cjs/components/Stroke.test.d.ts +0 -1
- package/dist/cjs/components/TextComponent.test.d.ts +0 -1
- package/dist/cjs/components/UnknownSVGObject.test.d.ts +0 -1
- package/dist/cjs/components/builders/FreehandLineBuilder.test.d.ts +0 -1
- package/dist/cjs/localizations/getLocalizationTable.test.d.ts +0 -1
- package/dist/cjs/math/Mat33.d.ts +0 -123
- package/dist/cjs/math/Mat33.js +0 -340
- package/dist/cjs/math/Mat33.test.d.ts +0 -1
- package/dist/cjs/math/Vec2.d.ts +0 -33
- package/dist/cjs/math/Vec2.js +0 -37
- package/dist/cjs/math/Vec2.test.d.ts +0 -1
- package/dist/cjs/math/Vec3.d.ts +0 -106
- package/dist/cjs/math/Vec3.js +0 -183
- package/dist/cjs/math/Vec3.test.d.ts +0 -1
- package/dist/cjs/math/lib.d.ts +0 -7
- package/dist/cjs/math/lib.js +0 -15
- package/dist/cjs/math/polynomial/solveQuadratic.d.ts +0 -9
- package/dist/cjs/math/polynomial/solveQuadratic.js +0 -39
- package/dist/cjs/math/polynomial/solveQuadratic.test.d.ts +0 -1
- package/dist/cjs/math/rounding.d.ts +0 -4
- package/dist/cjs/math/rounding.js +0 -140
- package/dist/cjs/math/rounding.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Abstract2DShape.d.ts +0 -49
- package/dist/cjs/math/shapes/Abstract2DShape.js +0 -42
- package/dist/cjs/math/shapes/BezierJSWrapper.d.ts +0 -36
- package/dist/cjs/math/shapes/BezierJSWrapper.js +0 -109
- package/dist/cjs/math/shapes/CubicBezier.d.ts +0 -17
- package/dist/cjs/math/shapes/CubicBezier.js +0 -50
- package/dist/cjs/math/shapes/LineSegment2.d.ts +0 -70
- package/dist/cjs/math/shapes/LineSegment2.js +0 -204
- package/dist/cjs/math/shapes/LineSegment2.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Path.d.ts +0 -93
- package/dist/cjs/math/shapes/Path.fromString.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Path.js +0 -865
- package/dist/cjs/math/shapes/Path.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Path.toString.test.d.ts +0 -1
- package/dist/cjs/math/shapes/PointShape2D.d.ts +0 -18
- package/dist/cjs/math/shapes/PointShape2D.js +0 -46
- package/dist/cjs/math/shapes/QuadraticBezier.d.ts +0 -34
- package/dist/cjs/math/shapes/QuadraticBezier.js +0 -133
- package/dist/cjs/math/shapes/QuadraticBezier.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Rect2.d.ts +0 -57
- package/dist/cjs/math/shapes/Rect2.js +0 -311
- package/dist/cjs/math/shapes/Rect2.test.d.ts +0 -1
- package/dist/cjs/math/shapes/Triangle.d.ts +0 -46
- package/dist/cjs/math/shapes/Triangle.js +0 -148
- package/dist/cjs/math/shapes/Triangle.test.d.ts +0 -1
- package/dist/cjs/rendering/RenderingStyle.test.d.ts +0 -1
- package/dist/cjs/rendering/caching/CacheRecord.test.d.ts +0 -1
- package/dist/cjs/rendering/caching/RenderingCache.test.d.ts +0 -1
- package/dist/cjs/rendering/renderers/DummyRenderer.test.d.ts +0 -1
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.test.d.ts +0 -1
- package/dist/cjs/shortcuts/KeyBinding.test.d.ts +0 -1
- package/dist/cjs/shortcuts/KeyboardShortcutManager.test.d.ts +0 -1
- package/dist/cjs/toolbar/HTMLToolbar.d.ts +0 -105
- package/dist/cjs/toolbar/HTMLToolbar.js +0 -465
- package/dist/cjs/toolbar/makeColorInput.d.ts +0 -6
- package/dist/cjs/tools/Eraser.test.d.ts +0 -1
- package/dist/cjs/tools/PanZoom.test.d.ts +0 -1
- package/dist/cjs/tools/Pen.test.d.ts +0 -1
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +0 -1
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +0 -1
- package/dist/mjs/Color4.d.ts +0 -69
- package/dist/mjs/Color4.mjs +0 -260
- package/dist/mjs/Color4.test.d.ts +0 -1
- package/dist/mjs/Editor.loadFrom.test.d.ts +0 -1
- package/dist/mjs/Editor.toSVG.test.d.ts +0 -1
- package/dist/mjs/EditorImage.test.d.ts +0 -1
- package/dist/mjs/EventDispatcher.test.d.ts +0 -1
- package/dist/mjs/SVGLoader.test.d.ts +0 -1
- package/dist/mjs/UndoRedoHistory.test.d.ts +0 -1
- package/dist/mjs/commands/uniteCommands.test.d.ts +0 -1
- package/dist/mjs/components/AbstractComponent.transformBy.test.d.ts +0 -1
- package/dist/mjs/components/BackgroundComponent.test.d.ts +0 -1
- package/dist/mjs/components/Stroke.test.d.ts +0 -1
- package/dist/mjs/components/TextComponent.test.d.ts +0 -1
- package/dist/mjs/components/UnknownSVGObject.test.d.ts +0 -1
- package/dist/mjs/components/builders/FreehandLineBuilder.test.d.ts +0 -1
- package/dist/mjs/localizations/getLocalizationTable.test.d.ts +0 -1
- package/dist/mjs/math/Mat33.d.ts +0 -123
- package/dist/mjs/math/Mat33.mjs +0 -338
- package/dist/mjs/math/Mat33.test.d.ts +0 -1
- package/dist/mjs/math/Vec2.d.ts +0 -33
- package/dist/mjs/math/Vec2.mjs +0 -34
- package/dist/mjs/math/Vec2.test.d.ts +0 -1
- package/dist/mjs/math/Vec3.d.ts +0 -106
- package/dist/mjs/math/Vec3.mjs +0 -181
- package/dist/mjs/math/Vec3.test.d.ts +0 -1
- package/dist/mjs/math/lib.d.ts +0 -7
- package/dist/mjs/math/lib.mjs +0 -7
- package/dist/mjs/math/polynomial/solveQuadratic.d.ts +0 -9
- package/dist/mjs/math/polynomial/solveQuadratic.mjs +0 -37
- package/dist/mjs/math/polynomial/solveQuadratic.test.d.ts +0 -1
- package/dist/mjs/math/rounding.d.ts +0 -4
- package/dist/mjs/math/rounding.mjs +0 -133
- package/dist/mjs/math/rounding.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Abstract2DShape.d.ts +0 -49
- package/dist/mjs/math/shapes/Abstract2DShape.mjs +0 -40
- package/dist/mjs/math/shapes/BezierJSWrapper.d.ts +0 -36
- package/dist/mjs/math/shapes/BezierJSWrapper.mjs +0 -107
- package/dist/mjs/math/shapes/CubicBezier.d.ts +0 -17
- package/dist/mjs/math/shapes/CubicBezier.mjs +0 -48
- package/dist/mjs/math/shapes/LineSegment2.d.ts +0 -70
- package/dist/mjs/math/shapes/LineSegment2.mjs +0 -202
- package/dist/mjs/math/shapes/LineSegment2.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Path.d.ts +0 -93
- package/dist/mjs/math/shapes/Path.fromString.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Path.mjs +0 -862
- package/dist/mjs/math/shapes/Path.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Path.toString.test.d.ts +0 -1
- package/dist/mjs/math/shapes/PointShape2D.d.ts +0 -18
- package/dist/mjs/math/shapes/PointShape2D.mjs +0 -44
- package/dist/mjs/math/shapes/QuadraticBezier.d.ts +0 -34
- package/dist/mjs/math/shapes/QuadraticBezier.mjs +0 -131
- package/dist/mjs/math/shapes/QuadraticBezier.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Rect2.d.ts +0 -57
- package/dist/mjs/math/shapes/Rect2.mjs +0 -309
- package/dist/mjs/math/shapes/Rect2.test.d.ts +0 -1
- package/dist/mjs/math/shapes/Triangle.d.ts +0 -46
- package/dist/mjs/math/shapes/Triangle.mjs +0 -146
- package/dist/mjs/math/shapes/Triangle.test.d.ts +0 -1
- package/dist/mjs/rendering/RenderingStyle.test.d.ts +0 -1
- package/dist/mjs/rendering/caching/CacheRecord.test.d.ts +0 -1
- package/dist/mjs/rendering/caching/RenderingCache.test.d.ts +0 -1
- package/dist/mjs/rendering/renderers/DummyRenderer.test.d.ts +0 -1
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.test.d.ts +0 -1
- package/dist/mjs/shortcuts/KeyBinding.test.d.ts +0 -1
- package/dist/mjs/shortcuts/KeyboardShortcutManager.test.d.ts +0 -1
- package/dist/mjs/toolbar/HTMLToolbar.d.ts +0 -105
- package/dist/mjs/toolbar/HTMLToolbar.mjs +0 -462
- package/dist/mjs/toolbar/makeColorInput.d.ts +0 -6
- package/dist/mjs/tools/Eraser.test.d.ts +0 -1
- package/dist/mjs/tools/PanZoom.test.d.ts +0 -1
- package/dist/mjs/tools/Pen.test.d.ts +0 -1
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +0 -1
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +0 -1
- package/dist-test/test_imports/package-lock.json +0 -13
- package/dist-test/test_imports/package.json +0 -12
- package/dist-test/test_imports/test-imports.js +0 -17
- package/dist-test/test_imports/test-require.cjs +0 -19
- package/src/Color4.test.ts +0 -47
- package/src/Color4.ts +0 -304
- package/src/Editor.css +0 -98
- package/src/Editor.loadFrom.test.ts +0 -24
- package/src/Editor.toSVG.test.ts +0 -111
- package/src/Editor.ts +0 -1171
- package/src/EditorImage.test.ts +0 -120
- package/src/EditorImage.ts +0 -603
- package/src/EventDispatcher.test.ts +0 -123
- package/src/EventDispatcher.ts +0 -72
- package/src/Pointer.ts +0 -170
- package/src/SVGLoader.test.ts +0 -114
- package/src/SVGLoader.ts +0 -610
- package/src/UndoRedoHistory.test.ts +0 -33
- package/src/UndoRedoHistory.ts +0 -102
- package/src/Viewport.ts +0 -325
- package/src/bundle/bundled.ts +0 -7
- package/src/commands/Command.ts +0 -45
- package/src/commands/Duplicate.ts +0 -75
- package/src/commands/Erase.ts +0 -94
- package/src/commands/SerializableCommand.ts +0 -49
- package/src/commands/UnresolvedCommand.ts +0 -37
- package/src/commands/invertCommand.ts +0 -58
- package/src/commands/lib.ts +0 -16
- package/src/commands/localization.ts +0 -47
- package/src/commands/uniteCommands.test.ts +0 -23
- package/src/commands/uniteCommands.ts +0 -140
- package/src/components/AbstractComponent.transformBy.test.ts +0 -22
- package/src/components/AbstractComponent.ts +0 -374
- package/src/components/BackgroundComponent.test.ts +0 -45
- package/src/components/BackgroundComponent.ts +0 -353
- package/src/components/ImageComponent.ts +0 -178
- package/src/components/RestylableComponent.ts +0 -161
- package/src/components/SVGGlobalAttributesObject.ts +0 -81
- package/src/components/Stroke.test.ts +0 -139
- package/src/components/Stroke.ts +0 -296
- package/src/components/TextComponent.test.ts +0 -204
- package/src/components/TextComponent.ts +0 -432
- package/src/components/UnknownSVGObject.test.ts +0 -10
- package/src/components/UnknownSVGObject.ts +0 -60
- package/src/components/builders/ArrowBuilder.ts +0 -107
- package/src/components/builders/CircleBuilder.ts +0 -102
- package/src/components/builders/FreehandLineBuilder.test.ts +0 -25
- package/src/components/builders/FreehandLineBuilder.ts +0 -212
- package/src/components/builders/LineBuilder.ts +0 -77
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
- package/src/components/builders/RectangleBuilder.ts +0 -74
- package/src/components/builders/types.ts +0 -15
- package/src/components/lib.ts +0 -31
- package/src/components/localization.ts +0 -24
- package/src/components/util/StrokeSmoother.ts +0 -302
- package/src/components/util/describeComponentList.ts +0 -18
- package/src/lib.ts +0 -69
- package/src/localization.ts +0 -34
- package/src/localizations/de.ts +0 -146
- package/src/localizations/en.ts +0 -8
- package/src/localizations/es.ts +0 -74
- package/src/localizations/getLocalizationTable.test.ts +0 -27
- package/src/localizations/getLocalizationTable.ts +0 -74
- package/src/math/Mat33.test.ts +0 -244
- package/src/math/Mat33.ts +0 -442
- package/src/math/Vec2.test.ts +0 -30
- package/src/math/Vec2.ts +0 -40
- package/src/math/Vec3.test.ts +0 -44
- package/src/math/Vec3.ts +0 -218
- package/src/math/lib.ts +0 -15
- package/src/math/polynomial/solveQuadratic.test.ts +0 -39
- package/src/math/polynomial/solveQuadratic.ts +0 -43
- package/src/math/rounding.test.ts +0 -65
- package/src/math/rounding.ts +0 -156
- package/src/math/shapes/Abstract2DShape.ts +0 -63
- package/src/math/shapes/BezierJSWrapper.ts +0 -93
- package/src/math/shapes/CubicBezier.ts +0 -35
- package/src/math/shapes/LineSegment2.test.ts +0 -99
- package/src/math/shapes/LineSegment2.ts +0 -231
- package/src/math/shapes/Path.fromString.test.ts +0 -223
- package/src/math/shapes/Path.test.ts +0 -309
- package/src/math/shapes/Path.toString.test.ts +0 -77
- package/src/math/shapes/Path.ts +0 -1027
- package/src/math/shapes/PointShape2D.ts +0 -33
- package/src/math/shapes/QuadraticBezier.test.ts +0 -31
- package/src/math/shapes/QuadraticBezier.ts +0 -141
- package/src/math/shapes/Rect2.test.ts +0 -209
- package/src/math/shapes/Rect2.ts +0 -344
- package/src/math/shapes/Triangle.test.ts +0 -61
- package/src/math/shapes/Triangle.ts +0 -139
- package/src/rendering/Display.ts +0 -248
- package/src/rendering/RenderingStyle.test.ts +0 -68
- package/src/rendering/RenderingStyle.ts +0 -55
- package/src/rendering/TextRenderingStyle.ts +0 -55
- package/src/rendering/caching/CacheRecord.test.ts +0 -49
- package/src/rendering/caching/CacheRecord.ts +0 -77
- package/src/rendering/caching/CacheRecordManager.ts +0 -71
- package/src/rendering/caching/RenderingCache.test.ts +0 -44
- package/src/rendering/caching/RenderingCache.ts +0 -66
- package/src/rendering/caching/RenderingCacheNode.ts +0 -405
- package/src/rendering/caching/testUtils.ts +0 -35
- package/src/rendering/caching/types.ts +0 -34
- package/src/rendering/lib.ts +0 -8
- package/src/rendering/localization.ts +0 -20
- package/src/rendering/renderers/AbstractRenderer.ts +0 -242
- package/src/rendering/renderers/CanvasRenderer.ts +0 -307
- package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
- package/src/rendering/renderers/DummyRenderer.ts +0 -145
- package/src/rendering/renderers/SVGRenderer.ts +0 -377
- package/src/rendering/renderers/TextOnlyRenderer.test.ts +0 -34
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -71
- package/src/shortcuts/KeyBinding.test.ts +0 -51
- package/src/shortcuts/KeyBinding.ts +0 -218
- package/src/shortcuts/KeyboardShortcutManager.test.ts +0 -95
- package/src/shortcuts/KeyboardShortcutManager.ts +0 -163
- package/src/shortcuts/lib.ts +0 -3
- package/src/testing/createEditor.ts +0 -11
- package/src/testing/getUniquePointerId.ts +0 -18
- package/src/testing/lib.ts +0 -3
- package/src/testing/sendPenEvent.ts +0 -36
- package/src/testing/sendTouchEvent.ts +0 -71
- package/src/toolbar/HTMLToolbar.ts +0 -567
- package/src/toolbar/IconProvider.ts +0 -805
- package/src/toolbar/lib.ts +0 -4
- package/src/toolbar/localization.ts +0 -114
- package/src/toolbar/makeColorInput.ts +0 -159
- package/src/toolbar/types.ts +0 -5
- package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
- package/src/toolbar/widgets/BaseToolWidget.ts +0 -65
- package/src/toolbar/widgets/BaseWidget.ts +0 -428
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -234
- package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
- package/src/toolbar/widgets/HandToolWidget.ts +0 -250
- package/src/toolbar/widgets/InsertImageWidget.css +0 -44
- package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
- package/src/toolbar/widgets/OverflowWidget.ts +0 -92
- package/src/toolbar/widgets/PenToolWidget.ts +0 -409
- package/src/toolbar/widgets/SelectionToolWidget.ts +0 -197
- package/src/toolbar/widgets/TextToolWidget.ts +0 -145
- package/src/toolbar/widgets/keybindings.ts +0 -21
- package/src/toolbar/widgets/lib.ts +0 -13
- package/src/tools/BaseTool.ts +0 -97
- package/src/tools/Eraser.test.ts +0 -103
- package/src/tools/Eraser.ts +0 -160
- package/src/tools/FindTool.ts +0 -153
- package/src/tools/PanZoom.test.ts +0 -349
- package/src/tools/PanZoom.ts +0 -502
- package/src/tools/PasteHandler.ts +0 -95
- package/src/tools/Pen.test.ts +0 -262
- package/src/tools/Pen.ts +0 -300
- package/src/tools/PipetteTool.ts +0 -55
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -29
- package/src/tools/SelectionTool/Selection.ts +0 -611
- package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
- package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
- package/src/tools/SelectionTool/SelectionTool.ts +0 -496
- package/src/tools/SelectionTool/TransformMode.ts +0 -114
- package/src/tools/SelectionTool/types.ts +0 -11
- package/src/tools/SoundUITool.ts +0 -212
- package/src/tools/TextTool.ts +0 -340
- package/src/tools/ToolController.ts +0 -200
- package/src/tools/ToolEnabledGroup.ts +0 -14
- package/src/tools/ToolSwitcherShortcut.ts +0 -39
- package/src/tools/ToolbarShortcutHandler.ts +0 -39
- package/src/tools/UndoRedoShortcut.test.ts +0 -56
- package/src/tools/UndoRedoShortcut.ts +0 -24
- package/src/tools/keybindings.ts +0 -85
- package/src/tools/lib.ts +0 -22
- package/src/tools/localization.ts +0 -74
- package/src/tools/tools.css +0 -4
- package/src/types.ts +0 -239
- package/src/util/assertions.ts +0 -55
- package/src/util/fileToBase64.ts +0 -18
- package/src/util/untilNextAnimationFrame.ts +0 -9
- package/src/util/waitForAll.ts +0 -18
- package/src/util/waitForTimeout.ts +0 -9
- /package/dist/{cjs/Color4.test.d.ts → mjs/toolbar/widgets/layout/types.mjs} +0 -0
package/dist/cjs/SVGLoader.js
CHANGED
@@ -1,72 +1,53 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
-
function step(op) {
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
-
switch (op[0]) {
|
21
|
-
case 0: case 1: t = op; break;
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
-
default:
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
-
if (t[2]) _.ops.pop();
|
31
|
-
_.trys.pop(); continue;
|
32
|
-
}
|
33
|
-
op = body.call(thisArg, _);
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
36
7
|
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
37
24
|
};
|
38
|
-
var
|
39
|
-
|
40
|
-
if (ar || !(i in from)) {
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
42
|
-
ar[i] = from[i];
|
43
|
-
}
|
44
|
-
}
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
46
27
|
};
|
47
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
48
|
-
exports.svgStyleAttributesDataKey = exports.svgAttributesDataKey = exports.defaultSVGViewRect = void 0;
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
var Path_1 = require("./math/shapes/Path");
|
58
|
-
var Rect2_1 = require("./math/shapes/Rect2");
|
59
|
-
var Vec2_1 = require("./math/Vec2");
|
29
|
+
exports.svgLoaderAttributeContainerID = exports.svgStyleAttributesDataKey = exports.svgAttributesDataKey = exports.defaultSVGViewRect = void 0;
|
30
|
+
const math_1 = require("@js-draw/math");
|
31
|
+
const BackgroundComponent_1 = __importStar(require("./components/BackgroundComponent"));
|
32
|
+
const ImageComponent_1 = __importDefault(require("./components/ImageComponent"));
|
33
|
+
const Stroke_1 = __importDefault(require("./components/Stroke"));
|
34
|
+
const SVGGlobalAttributesObject_1 = __importDefault(require("./components/SVGGlobalAttributesObject"));
|
35
|
+
const TextComponent_1 = __importStar(require("./components/TextComponent"));
|
36
|
+
const UnknownSVGObject_1 = __importDefault(require("./components/UnknownSVGObject"));
|
37
|
+
const RenderablePathSpec_1 = require("./rendering/RenderablePathSpec");
|
60
38
|
// Size of a loaded image if no size is specified.
|
61
|
-
exports.defaultSVGViewRect = new
|
39
|
+
exports.defaultSVGViewRect = new math_1.Rect2(0, 0, 500, 500);
|
62
40
|
// Key to retrieve unrecognised attributes from an AbstractComponent
|
63
41
|
exports.svgAttributesDataKey = 'svgAttrs';
|
42
|
+
// Like {@link svgAttributesDataKey}, but for styles
|
64
43
|
exports.svgStyleAttributesDataKey = 'svgStyleAttrs';
|
65
|
-
|
44
|
+
// Key that specifies the ID of an SVG element that contained a given node when the image
|
45
|
+
// was first loaded.
|
46
|
+
exports.svgLoaderAttributeContainerID = 'svgContainerID';
|
47
|
+
const supportedStrokeFillStyleAttrs = ['stroke', 'fill', 'stroke-width'];
|
66
48
|
// Handles loading images from SVG.
|
67
|
-
|
68
|
-
|
69
|
-
if (storeUnknown === void 0) { storeUnknown = true; }
|
49
|
+
class SVGLoader {
|
50
|
+
constructor(source, onFinish, storeUnknown = true) {
|
70
51
|
this.source = source;
|
71
52
|
this.onFinish = onFinish;
|
72
53
|
this.storeUnknown = storeUnknown;
|
@@ -75,34 +56,35 @@ var SVGLoader = /** @class */ (function () {
|
|
75
56
|
this.onDetermineExportRect = null;
|
76
57
|
this.processedCount = 0;
|
77
58
|
this.totalToProcess = 0;
|
59
|
+
this.containerGroupIDs = [];
|
60
|
+
this.encounteredIDs = [];
|
78
61
|
}
|
79
62
|
// If [computedStyles] is given, it is preferred to directly accessing node's style object.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
var stroke;
|
63
|
+
getStyle(node, computedStyles) {
|
64
|
+
let fill = math_1.Color4.transparent;
|
65
|
+
let stroke;
|
84
66
|
// If possible, use computedStyles (allows property inheritance).
|
85
|
-
|
67
|
+
const fillAttribute = node.getAttribute('fill') ?? computedStyles?.fill ?? node.style.fill;
|
86
68
|
if (fillAttribute) {
|
87
69
|
try {
|
88
|
-
fill =
|
70
|
+
fill = math_1.Color4.fromString(fillAttribute);
|
89
71
|
}
|
90
72
|
catch (e) {
|
91
73
|
console.error('Unknown fill color,', fillAttribute);
|
92
74
|
}
|
93
75
|
}
|
94
|
-
|
95
|
-
|
76
|
+
const strokeAttribute = node.getAttribute('stroke') ?? computedStyles?.stroke ?? node.style.stroke;
|
77
|
+
const strokeWidthAttr = node.getAttribute('stroke-width') ?? computedStyles?.strokeWidth ?? node.style.strokeWidth;
|
96
78
|
if (strokeAttribute && strokeWidthAttr) {
|
97
79
|
try {
|
98
|
-
|
80
|
+
let width = parseFloat(strokeWidthAttr ?? '1');
|
99
81
|
if (!isFinite(width)) {
|
100
82
|
width = 0;
|
101
83
|
}
|
102
|
-
|
84
|
+
const strokeColor = math_1.Color4.fromString(strokeAttribute);
|
103
85
|
if (strokeColor.a > 0) {
|
104
86
|
stroke = {
|
105
|
-
width
|
87
|
+
width,
|
106
88
|
color: strokeColor,
|
107
89
|
};
|
108
90
|
}
|
@@ -111,50 +93,49 @@ var SVGLoader = /** @class */ (function () {
|
|
111
93
|
console.error('Error parsing stroke data:', e);
|
112
94
|
}
|
113
95
|
}
|
114
|
-
|
115
|
-
fill
|
116
|
-
stroke
|
96
|
+
const style = {
|
97
|
+
fill,
|
98
|
+
stroke,
|
117
99
|
};
|
118
100
|
return style;
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
var style = this.getStyle(node);
|
101
|
+
}
|
102
|
+
strokeDataFromElem(node) {
|
103
|
+
const result = [];
|
104
|
+
const pathData = node.getAttribute('d') ?? '';
|
105
|
+
const style = this.getStyle(node);
|
125
106
|
// Break the path into chunks at each moveTo ('M') command:
|
126
|
-
|
127
|
-
|
128
|
-
for (
|
129
|
-
var part = parts_1[_i];
|
107
|
+
const parts = pathData.split('M');
|
108
|
+
let isFirst = true;
|
109
|
+
for (const part of parts) {
|
130
110
|
// Skip effective no-ops -- moveTos without additional commands.
|
131
|
-
|
111
|
+
const isNoOpMoveTo = /^[0-9., \t\n]+$/.exec(part);
|
132
112
|
if (part !== '' && !isNoOpMoveTo) {
|
133
113
|
// We split the path by moveTo commands, so add the 'M' back in
|
134
114
|
// if it was present.
|
135
|
-
|
136
|
-
|
137
|
-
|
115
|
+
const current = !isFirst ? `M${part}` : part;
|
116
|
+
const path = math_1.Path.fromString(current);
|
117
|
+
const spec = (0, RenderablePathSpec_1.pathToRenderable)(path, style);
|
138
118
|
result.push(spec);
|
139
119
|
}
|
140
120
|
isFirst = false;
|
141
121
|
}
|
142
122
|
return result;
|
143
|
-
}
|
144
|
-
|
123
|
+
}
|
124
|
+
attachUnrecognisedAttrs(elem, node, supportedAttrs, supportedStyleAttrs) {
|
145
125
|
if (!this.storeUnknown) {
|
146
126
|
return;
|
147
127
|
}
|
148
|
-
for (
|
149
|
-
var attr = _a[_i];
|
128
|
+
for (const attr of node.getAttributeNames()) {
|
150
129
|
if (supportedAttrs.has(attr) || (attr === 'style' && supportedStyleAttrs)) {
|
151
130
|
continue;
|
152
131
|
}
|
153
132
|
elem.attachLoadSaveData(exports.svgAttributesDataKey, [attr, node.getAttribute(attr)]);
|
154
133
|
}
|
155
134
|
if (supportedStyleAttrs && node.style) {
|
156
|
-
|
157
|
-
|
135
|
+
// Use a for loop instead of an iterator: js-dom seems to not
|
136
|
+
// support using node.style as an iterator.
|
137
|
+
for (let i = 0; i < node.style.length; i++) {
|
138
|
+
const attr = node.style[i];
|
158
139
|
if (attr === '' || !attr) {
|
159
140
|
continue;
|
160
141
|
}
|
@@ -169,165 +150,137 @@ var SVGLoader = /** @class */ (function () {
|
|
169
150
|
});
|
170
151
|
}
|
171
152
|
}
|
172
|
-
}
|
153
|
+
}
|
173
154
|
// Adds a stroke with a single path
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
155
|
+
async addPath(node) {
|
156
|
+
let elem;
|
157
|
+
try {
|
158
|
+
const strokeData = this.strokeDataFromElem(node);
|
159
|
+
elem = new Stroke_1.default(strokeData);
|
160
|
+
this.attachUnrecognisedAttrs(elem, node, new Set([...supportedStrokeFillStyleAttrs, 'd']), new Set(supportedStrokeFillStyleAttrs));
|
161
|
+
}
|
162
|
+
catch (e) {
|
163
|
+
console.error('Invalid path in node', node, '\nError:', e, '\nAdding as an unknown object.');
|
164
|
+
if (this.storeUnknown) {
|
165
|
+
elem = new UnknownSVGObject_1.default(node);
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
await this.addComponent(elem);
|
172
|
+
}
|
173
|
+
async addBackground(node) {
|
174
|
+
// If a grid background,
|
175
|
+
if (node.classList.contains(BackgroundComponent_1.backgroundTypeToClassNameMap[BackgroundComponent_1.BackgroundType.Grid])) {
|
176
|
+
let foregroundStr;
|
177
|
+
let backgroundStr;
|
178
|
+
let gridStrokeWidthStr;
|
179
|
+
// If a group,
|
180
|
+
if (node.tagName.toLowerCase() === 'g') {
|
181
|
+
// We expect exactly two children. One of these is the solid
|
182
|
+
// background of the grid
|
183
|
+
if (node.children.length !== 2) {
|
184
|
+
await this.addUnknownNode(node);
|
185
|
+
return;
|
199
186
|
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
foregroundStr = grid.getAttribute('stroke');
|
225
|
-
gridStrokeWidthStr = grid.getAttribute('stroke-width');
|
226
|
-
return [3 /*break*/, 4];
|
227
|
-
case 3:
|
228
|
-
backgroundStr = node.getAttribute('fill');
|
229
|
-
foregroundStr = node.getAttribute('stroke');
|
230
|
-
gridStrokeWidthStr = node.getAttribute('stroke-width');
|
231
|
-
_g.label = 4;
|
232
|
-
case 4:
|
233
|
-
// Default to a transparent background.
|
234
|
-
backgroundStr !== null && backgroundStr !== void 0 ? backgroundStr : (backgroundStr = Color4_1.default.transparent.toHexString());
|
235
|
-
if (!!foregroundStr) return [3 /*break*/, 6];
|
236
|
-
return [4 /*yield*/, this.addUnknownNode(node)];
|
237
|
-
case 5:
|
238
|
-
_g.sent();
|
239
|
-
return [2 /*return*/];
|
240
|
-
case 6:
|
241
|
-
gridSize = undefined;
|
242
|
-
for (_i = 0, _f = node.classList; _i < _f.length; _i++) {
|
243
|
-
className = _f[_i];
|
244
|
-
if (className.startsWith(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix)) {
|
245
|
-
sizeStr = className.substring(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix.length);
|
246
|
-
gridSize = parseFloat(sizeStr.replace(/p/g, '.'));
|
247
|
-
}
|
248
|
-
}
|
249
|
-
gridStrokeWidth = undefined;
|
250
|
-
if (gridStrokeWidthStr) {
|
251
|
-
gridStrokeWidth = parseFloat(gridStrokeWidthStr);
|
252
|
-
}
|
253
|
-
backgroundColor = Color4_1.default.fromString(backgroundStr);
|
254
|
-
foregroundColor = Color4_1.default.fromString(foregroundStr);
|
255
|
-
// Should the foreground color be determined automatically?
|
256
|
-
if (!node.classList.contains(BackgroundComponent_1.imageBackgroundNonAutomaticSecondaryColorCSSClassName)) {
|
257
|
-
foregroundColor = undefined;
|
258
|
-
}
|
259
|
-
elem = BackgroundComponent_1.default.ofGrid(backgroundColor, gridSize, foregroundColor, gridStrokeWidth);
|
260
|
-
return [4 /*yield*/, ((_a = this.onAddComponent) === null || _a === void 0 ? void 0 : _a.call(this, elem))];
|
261
|
-
case 7:
|
262
|
-
_g.sent();
|
263
|
-
return [3 /*break*/, 12];
|
264
|
-
case 8:
|
265
|
-
if (!(node.tagName.toLowerCase() === 'path')) return [3 /*break*/, 10];
|
266
|
-
fill = Color4_1.default.fromString((_c = (_b = node.getAttribute('fill')) !== null && _b !== void 0 ? _b : node.style.fill) !== null && _c !== void 0 ? _c : 'black');
|
267
|
-
elem = new BackgroundComponent_1.default(BackgroundComponent_1.BackgroundType.SolidColor, fill);
|
268
|
-
return [4 /*yield*/, ((_d = this.onAddComponent) === null || _d === void 0 ? void 0 : _d.call(this, elem))];
|
269
|
-
case 9:
|
270
|
-
_g.sent();
|
271
|
-
return [3 /*break*/, 12];
|
272
|
-
case 10: return [4 /*yield*/, this.addUnknownNode(node)];
|
273
|
-
case 11:
|
274
|
-
_g.sent();
|
275
|
-
_g.label = 12;
|
276
|
-
case 12: return [2 /*return*/];
|
187
|
+
const background = node.children[0];
|
188
|
+
const grid = node.children[1];
|
189
|
+
backgroundStr = background.getAttribute('fill');
|
190
|
+
foregroundStr = grid.getAttribute('stroke');
|
191
|
+
gridStrokeWidthStr = grid.getAttribute('stroke-width');
|
192
|
+
}
|
193
|
+
else {
|
194
|
+
backgroundStr = node.getAttribute('fill');
|
195
|
+
foregroundStr = node.getAttribute('stroke');
|
196
|
+
gridStrokeWidthStr = node.getAttribute('stroke-width');
|
197
|
+
}
|
198
|
+
// Default to a transparent background.
|
199
|
+
backgroundStr ??= math_1.Color4.transparent.toHexString();
|
200
|
+
// A grid must have a foreground color specified.
|
201
|
+
if (!foregroundStr) {
|
202
|
+
await this.addUnknownNode(node);
|
203
|
+
return;
|
204
|
+
}
|
205
|
+
// Extract the grid size from the class name
|
206
|
+
let gridSize = undefined;
|
207
|
+
for (const className of node.classList) {
|
208
|
+
if (className.startsWith(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix)) {
|
209
|
+
const sizeStr = className.substring(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix.length);
|
210
|
+
gridSize = parseFloat(sizeStr.replace(/p/g, '.'));
|
277
211
|
}
|
278
|
-
}
|
279
|
-
|
280
|
-
|
212
|
+
}
|
213
|
+
let gridStrokeWidth = undefined;
|
214
|
+
if (gridStrokeWidthStr) {
|
215
|
+
gridStrokeWidth = parseFloat(gridStrokeWidthStr);
|
216
|
+
}
|
217
|
+
const backgroundColor = math_1.Color4.fromString(backgroundStr);
|
218
|
+
let foregroundColor = math_1.Color4.fromString(foregroundStr);
|
219
|
+
// Should the foreground color be determined automatically?
|
220
|
+
if (!node.classList.contains(BackgroundComponent_1.imageBackgroundNonAutomaticSecondaryColorCSSClassName)) {
|
221
|
+
foregroundColor = undefined;
|
222
|
+
}
|
223
|
+
const elem = BackgroundComponent_1.default.ofGrid(backgroundColor, gridSize, foregroundColor, gridStrokeWidth);
|
224
|
+
await this.addComponent(elem);
|
225
|
+
}
|
226
|
+
// Otherwise, if just a <path/>, it's a solid color background.
|
227
|
+
else if (node.tagName.toLowerCase() === 'path') {
|
228
|
+
const fill = math_1.Color4.fromString(node.getAttribute('fill') ?? node.style.fill ?? 'black');
|
229
|
+
const elem = new BackgroundComponent_1.default(BackgroundComponent_1.BackgroundType.SolidColor, fill);
|
230
|
+
await this.addComponent(elem);
|
231
|
+
}
|
232
|
+
else {
|
233
|
+
await this.addUnknownNode(node);
|
234
|
+
}
|
235
|
+
}
|
281
236
|
// If given, 'supportedAttrs' will have x, y, etc. attributes that were used in computing the transform added to it,
|
282
237
|
// to prevent storing duplicate transform information when saving the component.
|
283
|
-
|
284
|
-
computedStyles
|
285
|
-
|
238
|
+
getTransform(elem, supportedAttrs, computedStyles) {
|
239
|
+
computedStyles ??= window.getComputedStyle(elem);
|
240
|
+
let transformProperty = computedStyles.transform;
|
286
241
|
if (transformProperty === '' || transformProperty === 'none') {
|
287
242
|
transformProperty = elem.style.transform || 'none';
|
288
243
|
}
|
289
244
|
// Prefer the actual .style.transform
|
290
245
|
// to the computed stylesheet -- in some browsers, the computedStyles version
|
291
246
|
// can have lower precision.
|
292
|
-
|
247
|
+
let transform;
|
293
248
|
try {
|
294
|
-
transform =
|
249
|
+
transform = math_1.Mat33.fromCSSMatrix(elem.style.transform);
|
295
250
|
}
|
296
251
|
catch (_e) {
|
297
|
-
transform =
|
252
|
+
transform = math_1.Mat33.fromCSSMatrix(transformProperty);
|
298
253
|
}
|
299
|
-
|
300
|
-
|
254
|
+
const elemX = elem.getAttribute('x');
|
255
|
+
const elemY = elem.getAttribute('y');
|
301
256
|
if (elemX || elemY) {
|
302
|
-
|
303
|
-
|
257
|
+
const x = parseFloat(elemX ?? '0');
|
258
|
+
const y = parseFloat(elemY ?? '0');
|
304
259
|
if (!isNaN(x) && !isNaN(y)) {
|
305
|
-
supportedAttrs
|
306
|
-
transform = transform.rightMul(
|
260
|
+
supportedAttrs?.push('x', 'y');
|
261
|
+
transform = transform.rightMul(math_1.Mat33.translation(math_1.Vec2.of(x, y)));
|
307
262
|
}
|
308
263
|
}
|
309
264
|
return transform;
|
310
|
-
}
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
for (var _i = 0, _b = elem.childNodes; _i < _b.length; _i++) {
|
315
|
-
var child = _b[_i];
|
265
|
+
}
|
266
|
+
makeText(elem) {
|
267
|
+
const contentList = [];
|
268
|
+
for (const child of elem.childNodes) {
|
316
269
|
if (child.nodeType === Node.TEXT_NODE) {
|
317
|
-
contentList.push(
|
270
|
+
contentList.push(child.nodeValue ?? '');
|
318
271
|
}
|
319
272
|
else if (child.nodeType === Node.ELEMENT_NODE) {
|
320
|
-
|
273
|
+
const subElem = child;
|
321
274
|
if (subElem.tagName.toLowerCase() === 'tspan') {
|
322
275
|
// FIXME: tspan's (x, y) components are absolute, not relative to the parent.
|
323
276
|
contentList.push(this.makeText(subElem));
|
324
277
|
}
|
325
278
|
else {
|
326
|
-
throw new Error(
|
279
|
+
throw new Error(`Unrecognized text child element: ${subElem}`);
|
327
280
|
}
|
328
281
|
}
|
329
282
|
else {
|
330
|
-
throw new Error(
|
283
|
+
throw new Error(`Unrecognized text child node: ${child}.`);
|
331
284
|
}
|
332
285
|
}
|
333
286
|
// If no content, the content is an empty string.
|
@@ -335,11 +288,11 @@ var SVGLoader = /** @class */ (function () {
|
|
335
288
|
contentList.push('');
|
336
289
|
}
|
337
290
|
// Compute styles.
|
338
|
-
|
339
|
-
|
291
|
+
const computedStyles = window.getComputedStyle(elem);
|
292
|
+
const fontSizeExp = /^([-0-9.e]+)px/i;
|
340
293
|
// In some environments, computedStyles.fontSize can be increased by the system.
|
341
294
|
// Thus, to prevent text from growing on load/save, prefer .style.fontSize.
|
342
|
-
|
295
|
+
let fontSizeMatch = fontSizeExp.exec(elem.style.fontSize);
|
343
296
|
if (!fontSizeMatch && elem.tagName.toLowerCase() === 'tspan' && elem.parentElement) {
|
344
297
|
// Try to inherit the font size of the parent text element.
|
345
298
|
fontSizeMatch = fontSizeExp.exec(elem.parentElement.style.fontSize);
|
@@ -349,32 +302,33 @@ var SVGLoader = /** @class */ (function () {
|
|
349
302
|
if (!fontSizeMatch) {
|
350
303
|
fontSizeMatch = fontSizeExp.exec(computedStyles.fontSize);
|
351
304
|
}
|
352
|
-
|
305
|
+
const supportedStyleAttrs = [
|
353
306
|
'fontFamily',
|
354
|
-
'transform'
|
355
|
-
|
356
|
-
|
307
|
+
'transform',
|
308
|
+
...supportedStrokeFillStyleAttrs,
|
309
|
+
];
|
310
|
+
let fontSize = 12;
|
357
311
|
if (fontSizeMatch) {
|
358
312
|
supportedStyleAttrs.push('fontSize');
|
359
313
|
fontSize = parseFloat(fontSizeMatch[1]);
|
360
314
|
}
|
361
|
-
|
315
|
+
const style = {
|
362
316
|
size: fontSize,
|
363
317
|
fontFamily: computedStyles.fontFamily || elem.style.fontFamily || 'sans-serif',
|
364
318
|
fontWeight: computedStyles.fontWeight || elem.style.fontWeight || undefined,
|
365
319
|
fontStyle: computedStyles.fontStyle || elem.style.fontStyle || undefined,
|
366
320
|
renderingStyle: this.getStyle(elem, computedStyles),
|
367
321
|
};
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
322
|
+
const supportedAttrs = [];
|
323
|
+
let transform = this.getTransform(elem, supportedAttrs, computedStyles);
|
324
|
+
let transformMode = TextComponent_1.TextTransformMode.ABSOLUTE_XY;
|
325
|
+
const elemDX = elem.getAttribute('dx');
|
372
326
|
if (elemDX) {
|
373
327
|
transformMode = TextComponent_1.TextTransformMode.RELATIVE_X_ABSOLUTE_Y;
|
374
|
-
transform = transform.rightMul(
|
328
|
+
transform = transform.rightMul(math_1.Mat33.translation(math_1.Vec2.of(parseFloat(elemDX), 0)));
|
375
329
|
supportedAttrs.push('dx');
|
376
330
|
}
|
377
|
-
|
331
|
+
const elemDY = elem.getAttribute('dy');
|
378
332
|
if (elemDY) {
|
379
333
|
if (transformMode === TextComponent_1.TextTransformMode.RELATIVE_X_ABSOLUTE_Y) {
|
380
334
|
transformMode = TextComponent_1.TextTransformMode.RELATIVE_XY;
|
@@ -382,249 +336,180 @@ var SVGLoader = /** @class */ (function () {
|
|
382
336
|
else {
|
383
337
|
transformMode = TextComponent_1.TextTransformMode.RELATIVE_Y_ABSOLUTE_X;
|
384
338
|
}
|
385
|
-
transform = transform.rightMul(
|
339
|
+
transform = transform.rightMul(math_1.Mat33.translation(math_1.Vec2.of(0, parseFloat(elemDY))));
|
386
340
|
supportedAttrs.push('dy');
|
387
341
|
}
|
388
|
-
|
342
|
+
const result = new TextComponent_1.default(contentList, transform, style, transformMode);
|
389
343
|
this.attachUnrecognisedAttrs(result, elem, new Set(supportedAttrs), new Set(supportedStyleAttrs));
|
390
344
|
return result;
|
391
|
-
}
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
_b.sent();
|
462
|
-
_b.label = 2;
|
463
|
-
case 2: return [2 /*return*/];
|
464
|
-
}
|
465
|
-
});
|
466
|
-
});
|
467
|
-
};
|
468
|
-
SVGLoader.prototype.updateViewBox = function (node) {
|
469
|
-
var _a;
|
470
|
-
var viewBoxAttr = node.getAttribute('viewBox');
|
345
|
+
}
|
346
|
+
async addText(elem) {
|
347
|
+
try {
|
348
|
+
const textElem = this.makeText(elem);
|
349
|
+
await this.addComponent(textElem);
|
350
|
+
}
|
351
|
+
catch (e) {
|
352
|
+
console.error('Invalid text object in node', elem, '. Continuing.... Error:', e);
|
353
|
+
this.addUnknownNode(elem);
|
354
|
+
}
|
355
|
+
}
|
356
|
+
async addImage(elem) {
|
357
|
+
const image = new Image();
|
358
|
+
image.src = elem.getAttribute('xlink:href') ?? elem.href.baseVal;
|
359
|
+
image.setAttribute('alt', elem.getAttribute('aria-label') ?? '');
|
360
|
+
try {
|
361
|
+
const supportedAttrs = [];
|
362
|
+
const transform = this.getTransform(elem, supportedAttrs);
|
363
|
+
const imageElem = await ImageComponent_1.default.fromImage(image, transform);
|
364
|
+
this.attachUnrecognisedAttrs(imageElem, elem, new Set(supportedAttrs), new Set(['transform']));
|
365
|
+
await this.addComponent(imageElem);
|
366
|
+
}
|
367
|
+
catch (e) {
|
368
|
+
console.error('Error loading image:', e, '. Element: ', elem, '. Continuing...');
|
369
|
+
await this.addUnknownNode(elem);
|
370
|
+
}
|
371
|
+
}
|
372
|
+
async addUnknownNode(node) {
|
373
|
+
if (this.storeUnknown) {
|
374
|
+
const component = new UnknownSVGObject_1.default(node);
|
375
|
+
await this.addComponent(component);
|
376
|
+
}
|
377
|
+
}
|
378
|
+
async startGroup(node) {
|
379
|
+
node = node.cloneNode(false);
|
380
|
+
// Select a unique ID based on the node's ID property (if it exists).
|
381
|
+
// Use `||` and not `??` so that empty string IDs are also replaced.
|
382
|
+
let id = node.id || `id-${this.encounteredIDs.length}`;
|
383
|
+
// Make id unique.
|
384
|
+
let idSuffixCounter = 0;
|
385
|
+
let suffix = '';
|
386
|
+
while (this.encounteredIDs.includes(id + suffix)) {
|
387
|
+
idSuffixCounter++;
|
388
|
+
suffix = '--' + idSuffixCounter;
|
389
|
+
}
|
390
|
+
id += suffix;
|
391
|
+
// Remove all children from the node -- children will be handled separately
|
392
|
+
// (not removing children here could cause duplicates in the result, when rendered).
|
393
|
+
node.replaceChildren();
|
394
|
+
node.id = id;
|
395
|
+
const component = new UnknownSVGObject_1.default(node);
|
396
|
+
this.addComponent(component);
|
397
|
+
// Add to IDs after -- we don't want the <g> element to be marked
|
398
|
+
// as its own container.
|
399
|
+
this.containerGroupIDs.push(node.id);
|
400
|
+
this.encounteredIDs.push(node.id);
|
401
|
+
}
|
402
|
+
// Ends the most recent group started by .startGroup
|
403
|
+
async endGroup() {
|
404
|
+
this.containerGroupIDs.pop();
|
405
|
+
}
|
406
|
+
async addComponent(component) {
|
407
|
+
// Attach the stack of container IDs
|
408
|
+
if (this.containerGroupIDs.length > 0) {
|
409
|
+
component.attachLoadSaveData(exports.svgLoaderAttributeContainerID, [...this.containerGroupIDs]);
|
410
|
+
}
|
411
|
+
await this.onAddComponent?.(component);
|
412
|
+
}
|
413
|
+
updateViewBox(node) {
|
414
|
+
const viewBoxAttr = node.getAttribute('viewBox');
|
471
415
|
if (this.rootViewBox || !viewBoxAttr) {
|
472
416
|
return;
|
473
417
|
}
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
418
|
+
const components = viewBoxAttr.split(/[ \t\n,]+/);
|
419
|
+
const x = parseFloat(components[0]);
|
420
|
+
const y = parseFloat(components[1]);
|
421
|
+
const width = parseFloat(components[2]);
|
422
|
+
const height = parseFloat(components[3]);
|
479
423
|
if (isNaN(x) || isNaN(y) || isNaN(width) || isNaN(height)) {
|
480
|
-
console.warn(
|
424
|
+
console.warn(`node ${node} has an unparsable viewbox. Viewbox: ${viewBoxAttr}. Match: ${components}.`);
|
481
425
|
return;
|
482
426
|
}
|
483
|
-
this.rootViewBox = new
|
484
|
-
|
485
|
-
}
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
427
|
+
this.rootViewBox = new math_1.Rect2(x, y, width, height);
|
428
|
+
this.onDetermineExportRect?.(this.rootViewBox);
|
429
|
+
}
|
430
|
+
async updateSVGAttrs(node) {
|
431
|
+
if (this.storeUnknown) {
|
432
|
+
await this.onAddComponent?.(new SVGGlobalAttributesObject_1.default(this.getSourceAttrs(node)));
|
433
|
+
}
|
434
|
+
}
|
435
|
+
async visit(node) {
|
436
|
+
this.totalToProcess += node.childElementCount;
|
437
|
+
let visitChildren = true;
|
438
|
+
switch (node.tagName.toLowerCase()) {
|
439
|
+
case 'g':
|
440
|
+
if (node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) {
|
441
|
+
await this.addBackground(node);
|
442
|
+
visitChildren = false;
|
498
443
|
}
|
499
|
-
|
500
|
-
|
501
|
-
};
|
502
|
-
SVGLoader.prototype.visit = function (node) {
|
503
|
-
var _a;
|
504
|
-
return __awaiter(this, void 0, void 0, function () {
|
505
|
-
var visitChildren, _b, _i, _c, child;
|
506
|
-
return __generator(this, function (_d) {
|
507
|
-
switch (_d.label) {
|
508
|
-
case 0:
|
509
|
-
this.totalToProcess += node.childElementCount;
|
510
|
-
visitChildren = true;
|
511
|
-
_b = node.tagName.toLowerCase();
|
512
|
-
switch (_b) {
|
513
|
-
case 'g': return [3 /*break*/, 1];
|
514
|
-
case 'path': return [3 /*break*/, 4];
|
515
|
-
case 'text': return [3 /*break*/, 9];
|
516
|
-
case 'image': return [3 /*break*/, 11];
|
517
|
-
case 'svg': return [3 /*break*/, 13];
|
518
|
-
case 'style': return [3 /*break*/, 14];
|
519
|
-
}
|
520
|
-
return [3 /*break*/, 16];
|
521
|
-
case 1:
|
522
|
-
if (!node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) return [3 /*break*/, 3];
|
523
|
-
return [4 /*yield*/, this.addBackground(node)];
|
524
|
-
case 2:
|
525
|
-
_d.sent();
|
526
|
-
visitChildren = false;
|
527
|
-
_d.label = 3;
|
528
|
-
case 3:
|
529
|
-
// Otherwise, continue -- visit the node's children.
|
530
|
-
return [3 /*break*/, 18];
|
531
|
-
case 4:
|
532
|
-
if (!node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) return [3 /*break*/, 6];
|
533
|
-
return [4 /*yield*/, this.addBackground(node)];
|
534
|
-
case 5:
|
535
|
-
_d.sent();
|
536
|
-
return [3 /*break*/, 8];
|
537
|
-
case 6: return [4 /*yield*/, this.addPath(node)];
|
538
|
-
case 7:
|
539
|
-
_d.sent();
|
540
|
-
_d.label = 8;
|
541
|
-
case 8: return [3 /*break*/, 18];
|
542
|
-
case 9: return [4 /*yield*/, this.addText(node)];
|
543
|
-
case 10:
|
544
|
-
_d.sent();
|
545
|
-
visitChildren = false;
|
546
|
-
return [3 /*break*/, 18];
|
547
|
-
case 11: return [4 /*yield*/, this.addImage(node)];
|
548
|
-
case 12:
|
549
|
-
_d.sent();
|
550
|
-
// Images should not have children.
|
551
|
-
visitChildren = false;
|
552
|
-
return [3 /*break*/, 18];
|
553
|
-
case 13:
|
554
|
-
this.updateViewBox(node);
|
555
|
-
this.updateSVGAttrs(node);
|
556
|
-
return [3 /*break*/, 18];
|
557
|
-
case 14: return [4 /*yield*/, this.addUnknownNode(node)];
|
558
|
-
case 15:
|
559
|
-
_d.sent();
|
560
|
-
return [3 /*break*/, 18];
|
561
|
-
case 16:
|
562
|
-
console.warn('Unknown SVG element,', node);
|
563
|
-
if (!(node instanceof SVGElement)) {
|
564
|
-
console.warn('Element', node, 'is not an SVGElement!', this.storeUnknown ? 'Continuing anyway.' : 'Skipping.');
|
565
|
-
}
|
566
|
-
return [4 /*yield*/, this.addUnknownNode(node)];
|
567
|
-
case 17:
|
568
|
-
_d.sent();
|
569
|
-
return [2 /*return*/];
|
570
|
-
case 18:
|
571
|
-
if (!visitChildren) return [3 /*break*/, 22];
|
572
|
-
_i = 0, _c = node.children;
|
573
|
-
_d.label = 19;
|
574
|
-
case 19:
|
575
|
-
if (!(_i < _c.length)) return [3 /*break*/, 22];
|
576
|
-
child = _c[_i];
|
577
|
-
return [4 /*yield*/, this.visit(child)];
|
578
|
-
case 20:
|
579
|
-
_d.sent();
|
580
|
-
_d.label = 21;
|
581
|
-
case 21:
|
582
|
-
_i++;
|
583
|
-
return [3 /*break*/, 19];
|
584
|
-
case 22:
|
585
|
-
this.processedCount++;
|
586
|
-
return [4 /*yield*/, ((_a = this.onProgress) === null || _a === void 0 ? void 0 : _a.call(this, this.processedCount, this.totalToProcess))];
|
587
|
-
case 23:
|
588
|
-
_d.sent();
|
589
|
-
return [2 /*return*/];
|
444
|
+
else {
|
445
|
+
await this.startGroup(node);
|
590
446
|
}
|
591
|
-
|
592
|
-
|
593
|
-
|
447
|
+
// Otherwise, continue -- visit the node's children.
|
448
|
+
break;
|
449
|
+
case 'path':
|
450
|
+
if (node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) {
|
451
|
+
await this.addBackground(node);
|
452
|
+
}
|
453
|
+
else {
|
454
|
+
await this.addPath(node);
|
455
|
+
}
|
456
|
+
break;
|
457
|
+
case 'text':
|
458
|
+
await this.addText(node);
|
459
|
+
visitChildren = false;
|
460
|
+
break;
|
461
|
+
case 'image':
|
462
|
+
await this.addImage(node);
|
463
|
+
// Images should not have children.
|
464
|
+
visitChildren = false;
|
465
|
+
break;
|
466
|
+
case 'svg':
|
467
|
+
this.updateViewBox(node);
|
468
|
+
this.updateSVGAttrs(node);
|
469
|
+
break;
|
470
|
+
case 'style':
|
471
|
+
await this.addUnknownNode(node);
|
472
|
+
break;
|
473
|
+
default:
|
474
|
+
console.warn('Unknown SVG element,', node, node.tagName);
|
475
|
+
if (!(node instanceof SVGElement)) {
|
476
|
+
console.warn('Element', node, 'is not an SVGElement!', this.storeUnknown ? 'Continuing anyway.' : 'Skipping.');
|
477
|
+
}
|
478
|
+
await this.addUnknownNode(node);
|
479
|
+
return;
|
480
|
+
}
|
481
|
+
if (visitChildren) {
|
482
|
+
for (const child of node.children) {
|
483
|
+
await this.visit(child);
|
484
|
+
}
|
485
|
+
if (node.tagName.toLowerCase() === 'g') {
|
486
|
+
await this.endGroup();
|
487
|
+
}
|
488
|
+
}
|
489
|
+
this.processedCount++;
|
490
|
+
await this.onProgress?.(this.processedCount, this.totalToProcess);
|
491
|
+
}
|
594
492
|
// Get SVG element attributes (e.g. xlink=...)
|
595
|
-
|
596
|
-
return node.getAttributeNames().map(
|
493
|
+
getSourceAttrs(node) {
|
494
|
+
return node.getAttributeNames().map(attr => {
|
597
495
|
return [attr, node.getAttribute(attr)];
|
598
496
|
});
|
599
|
-
}
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
return [4 /*yield*/, this.visit(this.source)];
|
616
|
-
case 1:
|
617
|
-
_c.sent();
|
618
|
-
viewBox = this.rootViewBox;
|
619
|
-
if (!viewBox) {
|
620
|
-
(_a = this.onDetermineExportRect) === null || _a === void 0 ? void 0 : _a.call(this, exports.defaultSVGViewRect);
|
621
|
-
}
|
622
|
-
(_b = this.onFinish) === null || _b === void 0 ? void 0 : _b.call(this);
|
623
|
-
return [2 /*return*/];
|
624
|
-
}
|
625
|
-
});
|
626
|
-
});
|
627
|
-
};
|
497
|
+
}
|
498
|
+
async start(onAddComponent, onProgress, onDetermineExportRect = null) {
|
499
|
+
this.onAddComponent = onAddComponent;
|
500
|
+
this.onProgress = onProgress;
|
501
|
+
this.onDetermineExportRect = onDetermineExportRect;
|
502
|
+
// Estimate the number of tags to process.
|
503
|
+
this.totalToProcess = this.source.childElementCount;
|
504
|
+
this.processedCount = 0;
|
505
|
+
this.rootViewBox = null;
|
506
|
+
await this.visit(this.source);
|
507
|
+
const viewBox = this.rootViewBox;
|
508
|
+
if (!viewBox) {
|
509
|
+
this.onDetermineExportRect?.(exports.defaultSVGViewRect);
|
510
|
+
}
|
511
|
+
this.onFinish?.();
|
512
|
+
}
|
628
513
|
/**
|
629
514
|
* Create an `SVGLoader` from the content of an SVG image. SVGs are loaded within a sandboxed
|
630
515
|
* iframe with `sandbox="allow-same-origin"`
|
@@ -634,10 +519,8 @@ var SVGLoader = /** @class */ (function () {
|
|
634
519
|
* @param text - Textual representation of the SVG (e.g. `<svg viewbox='...'>...</svg>`).
|
635
520
|
* @param sanitize - if `true`, don't store unknown attributes.
|
636
521
|
*/
|
637
|
-
|
638
|
-
|
639
|
-
if (sanitize === void 0) { sanitize = false; }
|
640
|
-
var sandbox = document.createElement('iframe');
|
522
|
+
static fromString(text, sanitize = false) {
|
523
|
+
const sandbox = document.createElement('iframe');
|
641
524
|
sandbox.src = 'about:blank';
|
642
525
|
sandbox.setAttribute('sandbox', 'allow-same-origin');
|
643
526
|
sandbox.setAttribute('csp', 'default-src \'about:blank\'');
|
@@ -648,20 +531,36 @@ var SVGLoader = /** @class */ (function () {
|
|
648
531
|
sandbox.remove();
|
649
532
|
throw new Error('SVG loading iframe is not sandboxed.');
|
650
533
|
}
|
651
|
-
|
534
|
+
const sandboxDoc = sandbox.contentWindow?.document ?? sandbox.contentDocument;
|
652
535
|
if (sandboxDoc == null)
|
653
536
|
throw new Error('Unable to open a sandboxed iframe!');
|
654
537
|
sandboxDoc.open();
|
655
|
-
sandboxDoc.write(
|
538
|
+
sandboxDoc.write(`
|
539
|
+
<!DOCTYPE html>
|
540
|
+
<html>
|
541
|
+
<head>
|
542
|
+
<title>SVG Loading Sandbox</title>
|
543
|
+
<meta name='viewport' conent='width=device-width,initial-scale=1.0'/>
|
544
|
+
<meta charset='utf-8'/>
|
545
|
+
</head>
|
546
|
+
<body style='font-size: 12px;'>
|
547
|
+
<script>
|
548
|
+
console.error('JavaScript should not be able to run here!');
|
549
|
+
throw new Error(
|
550
|
+
'The SVG sandbox is broken! Please double-check the sandboxing setting.'
|
551
|
+
);
|
552
|
+
</script>
|
553
|
+
</body>
|
554
|
+
</html>
|
555
|
+
`);
|
656
556
|
sandboxDoc.close();
|
657
|
-
|
557
|
+
const svgElem = sandboxDoc.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
658
558
|
svgElem.innerHTML = text;
|
659
559
|
sandboxDoc.body.appendChild(svgElem);
|
660
|
-
return new SVGLoader(svgElem,
|
560
|
+
return new SVGLoader(svgElem, () => {
|
661
561
|
svgElem.remove();
|
662
562
|
sandbox.remove();
|
663
563
|
}, !sanitize);
|
664
|
-
}
|
665
|
-
|
666
|
-
}());
|
564
|
+
}
|
565
|
+
}
|
667
566
|
exports.default = SVGLoader;
|