Factor out resize-to-viewport logic to allow user customization