A quantum tunneling theory for nanophotonics