Stack Files into a single doc

Is there a way in which I can loop through a list of images the user has selected, and then stack them into a single doc?

const fs = require("uxp").storage.localFileSystem;
const fileTypes = require("uxp").storage.fileTypes;

async function stackImages(files) {
  const app = window.require("photoshop").app;
  if (files.length > 0) {
    const file = files[0];

    // open first image
    const app = require("photoshop").app;
    await app.open(file);

    // stack the rest
  }
}

async function openFileBrowser() {
  const files = await fs.getFileForOpening({
    allowMultiple: true,
    types: fileTypes.images,
  });
  if (files.length > 0) {
    stackImages(files);
  }
}

document.getElementById("btnOpen").addEventListener("click", openFileBrowser);