New approach to duality-invariant nonlinear electrodynamics