{"size": 1234, "ext": "js", "max_stars_repo_path": "src/util/transformDOM.js", "max_stars_repo_name": "c4710n/ft", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/util/transformDOM.js", "max_issues_repo_name": "c4710n/ft", "max_issues_repo_issues_event_min_datetime": "2020-08-07T13:57:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-07T13:57:01.000Z", "max_forks_repo_path": "src/util/transformDOM.js", "max_forks_repo_name": "c4710n/ft", "max_forks_repo_forks_event_min_datetime": "2021-04-05T08:06:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-05T08:06:51.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 30.0975609756, "max_line_length": 92, "alphanum_fraction": 0.6863857374}
import app from '../app'

/**
 * Transform DOMElement's position and size according given DisplayObject.
 *
 * @param {DOMElement} dom the DOM to be transformed.
 * @param {DisplayObject} displayObject the display object which provides position and size.
 */
function transformDOM(dom, displayObject, layer) {
  const { width, height, worldAlpha: alpha, angle, visible } = displayObject

  const { x: $x, y: $y } = displayObject.getGlobalPosition()

  let pivotX, pivotY
  if (displayObject.anchor) {
    const { x: anchorX, y: anchorY } = displayObject.anchor
    pivotX = width * anchorX
    pivotY = height * anchorY
  } else {
    pivotX = displayObject.pivot.x
    pivotY = displayObject.pivot.y
  }

  const stagePosition = app.stage.getGlobalPosition()
  const x = $x - stagePosition.x - pivotX
  const y = $y - stagePosition.y - pivotY

  dom.style.position = 'absolute'
  dom.style.display = visible ? '' : 'none'
  dom.style.width = `${width}px`
  dom.style.height = `${height}px`
  dom.style.left = `${x}px`
  dom.style.top = `${y}px`
  dom.style.zIndex = layer
  dom.style.opacity = alpha
  dom.style.transformOrigin = `${pivotX}px ${pivotY}px`
  dom.style.transform = `rotate(${angle}deg)`
}

export default transformDOM
