Skip to content

Commit

Permalink
fix: a typographic anomaly caused by getComputedStyle getting px valu…
Browse files Browse the repository at this point in the history
…es only to 4-bit precision (close #104)
  • Loading branch information
qq15725 committed Nov 6, 2024
1 parent b6e4fe7 commit ed8d711
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/copy-css-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getDefaultStyle } from './get-default-style'
import { getDiffStyle } from './get-diff-style'
import { IN_CHROME } from './utils'

const px4PrecisionRE = /^\d+\.\d{4}px$/

export function copyCssStyles<T extends HTMLElement | SVGElement>(
node: T,
cloned: T,
Expand Down Expand Up @@ -57,6 +59,10 @@ export function copyCssStyles<T extends HTMLElement | SVGElement>(
}

style.forEach(([value, priority], name) => {
// fix a typographic anomaly caused by getComputedStyle getting px values only to 4-bit precision
if (px4PrecisionRE.test(value)) {
value = `${Number.parseFloat(value) + 0.0001}px`
}
clonedStyle.setProperty(name, value, priority)
})

Expand Down

0 comments on commit ed8d711

Please sign in to comment.