Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Vectors to SVG, take 2 #152

Merged
merged 12 commits into from
Jan 15, 2025
Merged

Conversation

mimshwright
Copy link
Contributor

@mimshwright mimshwright commented Jan 1, 2025

Hi @bernaferrari

I've done another pass on this. There are probably a few things that should be fixed before merging but I wanted to show you. I'm interested in getting your feedback on this since you have a lot more experience with this than I do.

Here's a summary...

  1. the conversion to alt nodes adds a bit of metadata to the AltNode.
  2. It checks whether the nodes can be flattened. We define some types to look for (e.g. "VECTOR") then we check the nodes and all the child nodes, grandchildren etc. If a node is made up entirely of flattenable nodes or groups that contain only flattenable nodes, it can be flattened.
  3. It adds a reference to the original node that was converted.
  4. There is a place to store the SVG string generated.
  5. In the conversion to code for HTML and Tailwind, the nodes are checked to see if they can be compressed. If so, we use exportAsync() to flatten the node. It gets stored in the svg prop so it doesn't get run more than once.
  6. SVG gets wrapped in a div

Known issues:

  • - There is no loading state for the asynchronous functions
  • - Seems like there are issues with positioning when there are multiple SVG groups generated. The SVGs probably need to be wrapped in a div with position: absolute
  • - In the case that you have a bunch of vectors and down in the tree is a text field, exportAsync will be run more than once. Each vector or group that can be flattened will be but the entire thing can't be flattened as one. That seems like a reasonable risk to me though. see examples below:

Without Text:
Screenshot 2025-01-01 at 23 13 04

With Text:
Screenshot 2025-01-01 at 23 13 46

@mimshwright
Copy link
Contributor Author

mimshwright commented Jan 8, 2025

I've added some changes to how the SVG wrapper works. Now it seems to be positioning elements more reliably.

My extreme example with hundreds of deeply nested nodes is still not completely right and i'm not sure what exactly is causing the problem. Probably something to do with nested groups not being positioned inside correctly or in other words, in the case that a group contains SVG objects that are absolutely positioned, and there are subgroups next to them, the subgroups should use position absolute rather than relative. It may also have to do with nested transformations where the rotations are being applied incorrectly. Need to test more.

Screenshot 2025-01-08 at 11 13 51 This looks right image This is closer but shapes are scattered around incorrectly.

Update

I found the issue. It is related to rotations on / within groups. #155

@mimshwright
Copy link
Contributor Author

@bernaferrari I think this is working pretty well. Did you get a chance to look at it?

@bernaferrari
Copy link
Owner

Oh, sorry. Weekend I was traveling and yesterday my flight got delayed by 12h. Will review later today.

@mimshwright
Copy link
Contributor Author

Don't worry! You can do it when you have time. Just curious if you had any feedback.

@bernaferrari
Copy link
Owner

Vector feels small compared to everything else that you changed. Good and interesting changes!

@bernaferrari
Copy link
Owner

You know the next step is downloading a zip with all the images/svgs, either as a raw html project or nextjs project? I'm waiting for the next PR.. 😝

@bernaferrari bernaferrari merged commit 3f64849 into bernaferrari:main Jan 15, 2025
1 check passed
@bernaferrari
Copy link
Owner

Also, if you want I can take a shot into the AST feature

@mimshwright mimshwright deleted the svg branch January 15, 2025 10:28
@mimshwright
Copy link
Contributor Author

@bernaferrari
My interest in this project lies mostly with the HTML exporter. That's what I'm going to be using it for, so that's why I'm focusing most of my work.
I do want to work on some way of exporting images. I think it would either do it by embedding them as Base64 or SVG or by exporting them as a zip. My instinct is to do the Zip as a separate step from the code export. But I don't think I'd try to incorporate Next.js or anything else

@bernaferrari
Copy link
Owner

There is almost no difference from raw html with zip to nextjs, so you can do whatever you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants