% see lua-visual-debug.lua file for copyright information (MIT License)

\ifx\ProvidesPackage\undefined
  \input ifluatex.sty\relax
\else
  \NeedsTeXFormat{LaTeX2e}
  \ProvidesPackage{lua-visual-debug}[2026-04-24 v1.1
      Visual debugging in LuaLaTeX (PGU)]
  \RequirePackage{ifluatex}
\fi

\ifx\ProvidesPackage\undefined
  \ifluatex
   \input atbegshi.sty\relax
   \directlua{
     local resolved = kpse.find_file("luakeyval.lua")
     if resolved then
         require("lua-visual-debug-keys")
     end  
     lvd = require("lua-visual-debug")}
   \AtBeginShipout {\directlua{lvd.show_page_elements(tex.box["AtBeginShipoutBox"])}}%
   \AtBeginShipoutInit
  \else
    \message{Warning: lua-visual-debug only works with LuaTeX (plain and LaTeX format)}
  \fi
\else
  \ifluatex
    \directlua{
      local resolved = kpse.find_file("luakeyval.lua")
      if resolved then
          require("lua-visual-debug-keys")
      end
      local lvd = require("lua-visual-debug").show_page_elements
      luatexbase.add_to_callback('pre_shipout_filter', lvd, 'lvd')
    }
  \else
    \PackageWarning{lua-visual-debug}{You are using this package without LuaTeX. This is not supported, so you don't get any visual debugging.}
  \fi
\fi

