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

feat: Add experimental onNodeDetected event #457

Merged
merged 3 commits into from
Apr 23, 2023
Merged

feat: Add experimental onNodeDetected event #457

merged 3 commits into from
Apr 23, 2023

Conversation

shuding
Copy link
Member

@shuding shuding commented Apr 23, 2023

Relates to #223 and partially solves it. There're two categories of discoverable nodes: HTML nodes and SVG nodes. The HTML nodes are just the same as the input, which is easier to reason about: we just emit the input nodes with resolved layout and styling information. This can be thought as the "preprocessing step" of the data.

Then, the SVG nodes are a little bit tricky because they're not a 1:1 mapping from the input nodes. For example a <div style={{ boxShadow: '...' }}> might be generated as a collection of SVG nodes including <defs>, <filter> and <rect>.

However, in the future we can still emit structured data for these in a onNodeGenerated event, containing the mapping information via a from field:

<div key="k" id="i" className="c" style={{ boxShadow: '...' }}>

Emits:

onNodeDetected: #0 = { type: 'div', key: 'k', width, height, left, top, props }

And:

onNodeGenerated: {
  from: #0,
  defs: DefNode[],
  elements: SVGElementNode[]
}

It apparently needs more discussion to get the best structured data design. The generated node can be converted to SVG easily but not necessarily (i.e. can be rendered in an imperative way such as canvas too). Then we can get #233 fully supported.

@vercel
Copy link

vercel bot commented Apr 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
satori-playground ✅ Ready (Inspect) Visit Preview Apr 23, 2023 8:28pm

@shuding shuding changed the title feat: Add onNodeDetected event feat: Add experimental onNodeDetected event Apr 23, 2023
@shuding shuding merged commit c1469ee into main Apr 23, 2023
@shuding shuding deleted the shu/03dc branch April 23, 2023 20:30
@github-actions
Copy link

🎉 This PR is included in version 0.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

sahithyandev pushed a commit to sahithyandev/satori that referenced this pull request Apr 26, 2024
Relates to vercel#223 and partially solves it. There're two categories of
discoverable nodes: HTML nodes and SVG nodes. The HTML nodes are just
the same as the input, which is easier to reason about: we just emit the
input nodes with resolved layout and styling information. This can be
thought as the "preprocessing step" of the data.

Then, the SVG nodes are a little bit tricky because they're not a 1:1
mapping from the input nodes. For example a `<div style={{ boxShadow:
'...' }}>` might be generated as a collection of SVG nodes including
`<defs>`, `<filter>` and `<rect>`.

However, in the future we can still emit structured data for these in a
`onNodeGenerated` event, containing the mapping information via a `from`
field:

```html
<div key="k" id="i" className="c" style={{ boxShadow: '...' }}>
```

Emits:

```js
onNodeDetected: #0 = { type: 'div', key: 'k', width, height, left, top, props }
```

And:

```js
onNodeGenerated: {
  from: #0,
  defs: DefNode[],
  elements: SVGElementNode[]
}
```

It apparently needs more discussion to get the best structured data
design. The generated node can be converted to SVG easily but not
necessarily (i.e. can be rendered in an imperative way such as canvas
too). Then we can get vercel#233 fully supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant