async generateDataURL(boardLayout) {
    const canvas = createCanvas(this.size, this.size);
    const ctx = canvas.getContext("2d");

    ctx.beginPath();
    ctx.rect(0, 0, this.size, this.size);
    ctx.fillStyle = this.light;
    ctx.fill();

    const row = this.flipped ? (r) => r + 1 : (r) => 7 - r + 1;
    const col = this.flipped ? (c) => c : (c) => 7 - c;

    for (let i = 0; i < 8; i += 1) {
      for (let j = 0; j < 8; j += 1) {
        if ((i + j) % 2 === 0) {
          ctx.beginPath();
          ctx.rect(
            (this.size / 8) * (7 - j + 1) - this.size / 8,
            (this.size / 8) * i,
            this.size / 8,
            this.size / 8,
          );
          ctx.fillStyle = this.dark;
          ctx.fill();
        }
        const piece = boardLayout[cols[col(j)] + row(i)];
        if (
          piece
          && piece.type !== ""
          && black.includes(piece.type.toLowerCase())
        ) {
          const image = `resources/${this.style}/${
            filePaths[`${piece.color}${piece.type}`]
          }.png`;
          let imagePath = `/${image}`;
          // Left in to enable testing (node environment)
          if (isNode) imagePath = `${__dirname}/${image}`;
          const imageFile = await loadImage(imagePath);
          await ctx.drawImage(
            imageFile,
            (this.size / 8) * (7 - j + 1) - this.size / 8,
            (this.size / 8) * i,
            this.size / 8,
            this.size / 8,
          );
        }
      }
    }
    return canvas.toDataURL();
  }
/**
   * Generates buffer image based on position
   * @param {string} boardLayout Pre-computed board layout object
   * @returns {Promise<Buffer>} Image buffer
   */
Generates buffer image based on position
@param {string} boardLayout Pre-computed board layout object
@returns {Promise} Image buffer
Generates buffer image based on position @param { string } boardLayout Pre - computed board layout object @returns { Promise } Image buffer
async generateDataURL(boardLayout) {
    const canvas = createCanvas(this.size, this.size);
    const ctx = canvas.getContext("2d");
    ctx.beginPath();
    ctx.rect(0, 0, this.size, this.size);
    ctx.fillStyle = this.light;
    ctx.fill();
    const row = this.flipped ? (r) => r + 1 : (r) => 7 - r + 1;
    const col = this.flipped ? (c) => c : (c) => 7 - c;
    for (let i = 0; i < 8; i += 1) {
      for (let j = 0; j < 8; j += 1) {
        if ((i + j) % 2 === 0) {
          ctx.beginPath();
          ctx.rect(
            (this.size / 8) * (7 - j + 1) - this.size / 8,
            (this.size / 8) * i,
            this.size / 8,
            this.size / 8,
          );
          ctx.fillStyle = this.dark;
          ctx.fill();
        }
        const piece = boardLayout[cols[col(j)] + row(i)];
        if (
          piece
          && piece.type !== ""
          && black.includes(piece.type.toLowerCase())
        ) {
          const image = `resources/${this.style}/${
            filePaths[`${piece.color}${piece.type}`]
          }.png`;
          let imagePath = `/${image}`;
          if (isNode) imagePath = `${__dirname}/${image}`;
          const imageFile = await loadImage(imagePath);
          await ctx.drawImage(
            imageFile,
            (this.size / 8) * (7 - j + 1) - this.size / 8,
            (this.size / 8) * i,
            this.size / 8,
            this.size / 8,
          );
        }
      }
    }
    return canvas.toDataURL();
  }
async generateDataURL ( boardLayout ) { const canvas = createCanvas ( this . size , this . size ) ; const ctx = canvas . getContext ( "2d" ) ; ctx . beginPath ( ) ; ctx . rect ( 0 , 0 , this . size , this . size ) ; ctx . fillStyle = this . light ; ctx . fill ( ) ; const row = this . flipped ? ( r ) => r + 1 : ( r ) => 7 - r + 1 ; const col = this . flipped ? ( c ) => c : ( c ) => 7 - c ; for ( let i = 0 ; i < 8 ; i += 1 ) { for ( let j = 0 ; j < 8 ; j += 1 ) { if ( ( i + j ) % 2 === 0 ) { ctx . beginPath ( ) ; ctx . rect ( ( this . size / 8 ) * ( 7 - j + 1 ) - this . size / 8 , ( this . size / 8 ) * i , this . size / 8 , this . size / 8 , ) ; ctx . fillStyle = this . dark ; ctx . fill ( ) ; } const piece = boardLayout [ cols [ col ( j ) ] + row ( i ) ] ; if ( piece && piece . type !== "" && black . includes ( piece . type . toLowerCase ( ) ) ) { const image = ` ${ this . style } ${ filePaths [ ` ${ piece . color } ${ piece . type } ` ] } ` ; let imagePath = ` ${ image } ` ; if ( isNode ) imagePath = ` ${ __dirname } ${ image } ` ; const imageFile = await loadImage ( imagePath ) ; await ctx . drawImage ( imageFile , ( this . size / 8 ) * ( 7 - j + 1 ) - this . size / 8 , ( this . size / 8 ) * i , this . size / 8 , this . size / 8 , ) ; } } } return canvas . toDataURL ( ) ; }
Generates buffer image based on position
 @param {string} boardLayout Pre-computed board layout object
 @returns {Promise<Buffer>} Image buffer
Generates buffer image based on position @param { string } boardLayout Pre - computed board layout object @returns { Promise<Buffer > } Image buffer
// Left in to enable testing (node environment)