Skip to content

Commit

Permalink
fix: getDefaultStyle nodeName not being converted to lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Apr 15, 2023
1 parent 86518ff commit c3d5c92
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/copy-css-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ignoredStyle = [
'all', // svg: all
'd', // svg: d
'content', // Safari shows pseudoelements if content is set
'-webkit-text-fill-color',
]

export function copyCssStyles<T extends HTMLElement | SVGElement>(
Expand All @@ -17,7 +18,7 @@ export function copyCssStyles<T extends HTMLElement | SVGElement>(
context: Context,
) {
const cloneStyle = clone.style
const defaultStyle = getDefaultStyle(node.tagName, null, context)
const defaultStyle = getDefaultStyle(node.nodeName, null, context)

cloneStyle.transitionProperty = 'none'

Expand Down
3 changes: 2 additions & 1 deletion src/copy-pseudo-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Context } from './context'
const ignoredStyles = [
'content',
'-webkit-locale',
'-webkit-text-fill-color',
]

const pseudoClasses = [
Expand Down Expand Up @@ -40,7 +41,7 @@ export function copyPseudoClass<T extends HTMLElement | SVGElement>(
const content = style.getPropertyValue('content')
if (!content || content === 'none') return
const klasses = [uuid()]
const defaultStyle = getDefaultStyle('DIV', pseudoClass, context)
const defaultStyle = getDefaultStyle(node.nodeName, pseudoClass, context)
const cloneStyle = [
`content: '${ content.replace(/'|"/g, '') }';`,
]
Expand Down
7 changes: 4 additions & 3 deletions src/get-default-style.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { uuid } from './utils'
import type { Context } from './context'

export function getDefaultStyle(tagName: string, pseudoElement: string | null, context: Context) {
export function getDefaultStyle(nodeName: string, pseudoElement: string | null, context: Context) {
nodeName = nodeName.toLowerCase()
const { defaultComputedStyles, ownerDocument } = context
const key = `${ tagName }${ pseudoElement ?? '' }`
const key = `${ nodeName }${ pseudoElement ?? '' }`
if (defaultComputedStyles.has(key)) return defaultComputedStyles.get(key)!
let sandbox = context.sandbox
if (!sandbox) {
Expand All @@ -23,7 +24,7 @@ export function getDefaultStyle(tagName: string, pseudoElement: string | null, c
const sandboxWindow = sandbox.contentWindow
if (!sandboxWindow) return {}
const sandboxDocument = sandboxWindow.document
const el = sandboxDocument.createElement(tagName)
const el = sandboxDocument.createElement(nodeName)
sandboxDocument.body.appendChild(el)
// Ensure that there is some content, so properties like margin are applied
el.textContent = ' '
Expand Down

1 comment on commit c3d5c92

@vercel
Copy link

@vercel vercel bot commented on c3d5c92 Apr 15, 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-qq15725.vercel.app
modern-screenshot-git-main-qq15725.vercel.app
modern-screenshot.vercel.app

Please sign in to comment.