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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

mimshwright
Copy link
Contributor

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

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.

1 participant