Skip to content

Commit

Permalink
fix: skip root margin
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed May 8, 2023
1 parent 60bf91b commit a567b62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/clone-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function cloneNode<T extends Node>(
const cloned = await cloneElement(node, context)
const clonedStyle = cloned.style

copyCssStyles(node, computedStyle, cloned, context)
copyCssStyles(node, computedStyle, cloned, isRoot, context)

if (isRoot) {
applyCssStyleWithOptions(clonedStyle, context)
Expand Down
3 changes: 3 additions & 0 deletions src/copy-css-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function copyCssStyles<T extends HTMLElement | SVGElement>(
node: T,
computedStyle: CSSStyleDeclaration,
cloned: T,
isRoot: boolean,
context: Context,
) {
const clonedStyle = cloned.style
Expand All @@ -23,6 +24,8 @@ export function copyCssStyles<T extends HTMLElement | SVGElement>(
for (const [name, [value, priority]] of Object.entries(diffStyle)) {
if (ignoredStyle.includes(name)) continue

if (isRoot && name.startsWith('margin')) continue

// fix background-clip: text
if (name === 'background-clip' && value === 'text') {
cloned.classList.add('______background-clip--text')
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/css.margin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<style>
#root {
width: 100px;
height: 100px;
background-color: grey;
margin: 30px;
}
</style>
Binary file added test/fixtures/css.margin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit a567b62

@vercel
Copy link

@vercel vercel bot commented on a567b62 May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

modern-screenshot – ./

modern-screenshot.vercel.app
modern-screenshot-git-main-qq15725.vercel.app
modern-screenshot-qq15725.vercel.app

Please sign in to comment.