<commit_before>function loadImage(dataUrl) {
  return new Promise(resolve => {
    const image = new Image();
    image.onload = () => resolve(image);
    image.src = dataUrl;
  });
}

function generateBaseCanvas(baseImage) {
  return loadImage(baseImage).then(image => {
    const canvas = document.createElement('canvas');
    canvas.width = image.width;
    canvas.height = image.height;
    const ctx = canvas.getContext('2d');
    ctx.drawImage(image, 0, 0, image.width, image.height);
    return {canvas, ctx};
  });
}

export default function synthesizeImages(dataUrlList) {
  return generateBaseCanvas(dataUrlList[0])
    .then(({canvas, ctx}) => {
      dataUrlList.shift();
      return Promise.all(
        dataUrlList.map(data => loadImage(data))
      ).then(images => ({canvas, ctx, images}));
    })
    .then(({canvas, ctx, images}) => {
      images.forEach(image => {<commit_msg>add Flow<commit_after>// @flow
function loadImage(dataUrl: string): Promise<Image> {
  return new Promise(resolve => {
    const image = new Image();
    image.onload = () => resolve(image);
    image.src = dataUrl;
  });
}

function generateBaseCanvas(
  baseImage: string
): Promise<{canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D}> {
  return loadImage(baseImage).then(image => {
    const canvas = document.createElement('canvas');
    canvas.width = image.width;
    canvas.height = image.height;
    const ctx = canvas.getContext('2d');
    ctx.drawImage(image, 0, 0, image.width, image.height);
    return {canvas, ctx};
  });
}

export default function synthesizeImages(
  dataUrlList: string[]
): Promise<string> {
  return generateBaseCanvas(dataUrlList[0])
    .then(({canvas, ctx}) => {
      dataUrlList.shift();
      return Promise.all(
        dataUrlList.map(data => loadImage(data))
      ).then(images => ({canvas, ctx, images}));
    })
    .then(({canvas, ctx, images}) => {
      images.forEach(image => {
{'fraction_non_alphanumeric': 0.15718717683557393, 'fraction_numerical': 0.004653567735263702, 'mean_word_length': 3.685230024213075, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2815128', 'n_tokens_mistral': 595, 'n_tokens_neox': 589, 'n_words': 126}