zsviczian / obsidian-excalidraw-plugin

A plugin to edit and view Excalidraw drawings in Obsidian
3.68k stars 202 forks source link

BUG: File contents gets DELETED when convert SVG to Excalidraw #1768

Closed MahmadSharaf closed 1 month ago

MahmadSharaf commented 1 month ago

Your environment SYSTEM INFO: Obsidian version: v1.5.12 Installer version: v1.5.12 Operating system: Windows 10 Pro 10.0.22631 Login status: logged in Catalyst license: none Insider build toggle: off Live preview: on Base theme: adapt to system Community theme: AnuPpuccin v1.4.5 Snippets enabled: 10 Restricted mode: off Plugins installed: 51 Plugins enabled: 32 1: Pane Relief v0.5.3 2: Advanced URI v1.40.1 3: QuickAdd v1.8.1 4: Templater v2.2.4 5: Tasks v7.1.0 6: Hotkeys++ v0.2.7 7: Git v2.24.1 8: Auto Link Title v1.5.4 9: Book Search v0.7.3 10: Charts v3.9.0 11: Code Editor Shortcuts v1.14.0 12: Editor Syntax Highlight v0.1.3 13: floating toc v2.4.7 14: LanguageTool Integration v0.3.7 15: Plugin Update Tracker v1.5.2 16: Copy Block Link v1.0.4 17: Natural Language Dates v0.6.2 18: Commander v0.5.1 19: Dataview v0.5.66 20: ExcaliBrain v0.2.15 21: Excalidraw v2.1.7 22: Linter v1.24.0 23: Omnisearch v1.22.2 24: Style Settings v1.0.8 25: S3 Image Uploader v0.2.12 26: Digital Garden v2.56.2 27: Projects v1.17.3 28: Dataedit v0.0.1 29: Note Toolbar v1.6.3 30: Supercharged Links v0.12.1 31: Strange New Worlds v2.1.2 32: Workspaces Plus v0.3.3

RECOMMENDATIONS: Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets. Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.

Describe the bug Converting an SVG to Strokes, crashes the note and deletes its content.

To Reproduce Steps to reproduce the behavior:

  1. Copy a remote url for an SVG
  2. Paste it in an Excalidraw note, old or a new note.
  3. Right-click on the SVG
  4. Click on "Convert SVG to Strokes - with limitations"

Expected behavior The SVG gets converted to an Excalidraw element

Screenshots Here is a video for the bug https://github.com/zsviczian/obsidian-excalidraw-plugin/assets/36701447/dbfb0d16-0723-4e70-ba6e-92e126b0b6ec

And this the SVG used drawing

zsviczian commented 1 month ago

I am able to reproduce. Thanks for sharing the SVG.

zsviczian commented 1 month ago

I'll add better error handling to catch whatever the issue is... however, it seems this SVG has something weird going on. Loading it with https://jakearchibald.github.io/svgomg/ and saving it results in an SVG that I was able to convert into strokes without issues.

https://excalidraw.com/#json=kBFr7EMkHyXXJct7D_uF6,ngxLFMXX8V5VcrVykZZyIA

MahmadSharaf commented 1 month ago

Yeah, it seemed so. I was able to workaround the conversion failure by simplifying the paths in Inkscape and then was able to convert successfully.

The real trouble is that the content of the file that gets deleted. I believe that catching the error is more than enough. Fixing the root cause is not important.

Shall I close it now? or leave it as reminder till fixed?

zsviczian commented 1 month ago

I have added error handling, will be included in 2.1.8.

According to chatGPT the SVG is malformed. The error is thrown by a built-in javascript function when calling it with this transform value: new DOMMatrix("translate(4.252e, -6px)");

The error you're encountering indicates that there's an issue with the syntax of the transformation matrix you're trying to create using the DOMMatrix constructor. The error message specifically states: "Failed to parse 'translate(4.252e, -6px)'."

It seems like the values you're passing to the translate() function are not in the correct format. The translate() function typically takes two parameters: one for the horizontal translation and one for the vertical translation.

In your case, it looks like you're trying to translate horizontally by 4.252e and vertically by -6px. The issue here is with the first parameter, 4.252e, which seems to be missing the unit (like px for pixels) or a numeric value.

To resolve this error, make sure you provide valid numeric values with appropriate units for the translation parameters. For example:

new DOMMatrix("translate(4.252px, -6px)");

Or, if you're using scientific notation for the translation values, ensure they are formatted correctly:

new DOMMatrix("translate(4.252e3px, -6px)");

Adjust the translation values according to your requirements and ensure they follow the correct syntax for the translate() function.