HEX
Server: Apache
System: Linux p3plzcpnl506847.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: slfopp7cb1df (5698090)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/slfopp7cb1df/public_html/sitepacket.com/src/editor/src/scripts/visualDebug.js
let context = undefined
let canvas = undefined

export function clear() {
  if (!context) init()

  context.clearRect(0, 0, canvas.width, canvas.height)
}

export function drawPoint({ x, y, color }) {
  if (!context) init()

  context.fillStyle = color || getRandomColor()
  context.fillRect(x - 5, y - 5, 10, 10)
}
export function drawRect({ x, y, width, height, color }) {
  if (!context) init()

  context.fillStyle = color || getRandomColor()
  context.fillRect(x, y, width || canvas.width, height)
}

export function drawGuideHorizontal({ y, color }) {
  if (!context) init()

  context.strokeStyle = color || getRandomColor()
  context.beginPath()
  context.moveTo(0, y)
  context.lineTo(canvas.width, y)
  context.stroke()
}
export function drawGuideVertical({ x, color }) {
  if (!context) init()

  context.strokeStyle = color || getRandomColor()
  context.beginPath()
  context.moveTo(x, 0)
  context.lineTo(x, canvas.height)
  context.stroke()
}

export function highlightElement({ selector, color }) {
  let element = document.querySelector(selector)
  if (!element) return

  drawRect({
    x: element.getBoundingClientRect().x,
    y: element.getBoundingClientRect().y + window.scrollY,
    width: element.getBoundingClientRect().width,
    height: element.getBoundingClientRect().height,
    color: color
  })
}

function init() {
  if (!canvas) {
    canvas = document.createElement('canvas')
    canvas.setAttribute('id', 'visual-debug-canvas')
    canvas.style.position = 'absolute'
    canvas.style.left = 0
    canvas.style.top = 0
    canvas.style.zIndex = 99999999
    canvas.setAttribute('width', document.documentElement.offsetWidth)
    canvas.setAttribute('height', document.documentElement.offsetHeight)
    canvas.style.pointerEvents = 'none'
    document.body.appendChild(canvas)
    context = canvas.getContext('2d')
  }
}

function getRandomColor() {
  return `rgba(${255 * Math.random()}, ${255 * Math.random()}, ${255 * Math.random()}, 0.25)`
}