Merge upstream

With a few minor changes, intentional omissions, and further changes, this incorporates all of the upstream changes since the last commit on master except the automatic build of main.js and related changes, and the output ref drag-and-drop feature.