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