Skip to content

Commit

Permalink
avoid creating x,y in a moving tspan if they didn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jfhenon committed Nov 10, 2024
1 parent 3607cc8 commit 023b41b
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions packages/svgcanvas/core/coords.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import {
transformBox,
getTransformList
} from './math.js'
import {
convertToNum
} from './units.js'
import { convertToNum } from './units.js'

let svgCanvas = null

Expand Down Expand Up @@ -187,24 +185,21 @@ export const remapElement = (selected, changes, m) => {
const child = childNodes[i]
if (child.nodeType === 1 && child.tagName === 'tspan') {
const childChanges = {}
const childX = child.getAttribute('x')
const childY = child.getAttribute('y')
if (childX !== null) {
childChanges.x = convertToNum('x', childX)
} else {
// If 'x' is not set, inherit from parent
childChanges.x = changes.x
const hasX = child.hasAttribute('x')
const hasY = child.hasAttribute('y')
if (hasX) {
const childX = convertToNum('x', child.getAttribute('x'))
const childPtX = remap(childX, changes.y).x
childChanges.x = childPtX
}
if (hasY) {
const childY = convertToNum('y', child.getAttribute('y'))
const childPtY = remap(changes.x, childY).y
childChanges.y = childPtY
}
if (childY !== null) {
childChanges.y = convertToNum('y', childY)
} else {
// If 'y' is not set, inherit from parent
childChanges.y = changes.y
if (hasX || hasY) {
assignAttributes(child, childChanges, 1000, true)
}
const childPt = remap(childChanges.x, childChanges.y)
childChanges.x = childPt.x
childChanges.y = childPt.y
assignAttributes(child, childChanges, 1000, true)
}
}
break
Expand Down

0 comments on commit 023b41b

Please sign in to comment.