_inlineImages (callback) {
    // Get any images
    const images = this.element.querySelectorAll('image');

    // If there are no images, immediately call the callback
    if (images.length === 0) {
      callback();
      return;
    }

    const promises = [];

    // Iterate over the images
    images.forEach((image) => {
      // Get the href for the image
      const href = image.getAttribute('xlink:href') || image.getAttribute('href');

      // If no href for this image, skip this image
      if (href === null) return;

      // If we had a href, check if it's external
      if (href && this._isExternal(href)) {
        throw new Error('Cannot render embedded images linking to external hosts: ' + href);
      }

      // Create a canvas and image
      const canvas = document.createElement('canvas');
      const ctx = canvas.getContext('2d');
      const img = new window.Image();

      // Create a promise and push it to the promises array
      promises.push(new Promise((resolve, reject) => {
        // Set the image source
        img.src = href;

        // Image load callback
        img.onload = function () {
          // Set the canvases size
          canvas.width = img.width;
          canvas.height = img.height;

          // Draw it onto the canvas
          ctx.drawImage(img, 0, 0);

          // Update the href attribute of the image element
          image.setAttribute('xlink:href', canvas.toDataURL('image/png'));
          image.setAttribute('href', canvas.toDataURL('image/png'));

          // Resolve the promise
          resolve();
        }

        // Image error callback
        img.onerror = function () {
          // Image couldn't be loaded, reject the promise
          reject('Could not load image: ' + href);
        }
      }));
    });

    // Wait for promises to resolve and call the callback
    Promise.all(promises)
           .then(callback)
           .catch(e => { throw new Error(e) });
  }
/**
   * Inlines all images
   *
   * @param {function} callback - The callback to run after images have been loaded and inlined
   */
Inlines all images
@param {function} callback - The callback to run after images have been loaded and inlined
Inlines all images @param { function } callback - The callback to run after images have been loaded and inlined
_inlineImages (callback) {
    const images = this.element.querySelectorAll('image');
    if (images.length === 0) {
      callback();
      return;
    }
    const promises = [];
    images.forEach((image) => {
      const href = image.getAttribute('xlink:href') || image.getAttribute('href');
      if (href === null) return;
      if (href && this._isExternal(href)) {
        throw new Error('Cannot render embedded images linking to external hosts: ' + href);
      }
      const canvas = document.createElement('canvas');
      const ctx = canvas.getContext('2d');
      const img = new window.Image();
      promises.push(new Promise((resolve, reject) => {
        img.src = href;
        img.onload = function () {
          canvas.width = img.width;
          canvas.height = img.height;
          ctx.drawImage(img, 0, 0);
          image.setAttribute('xlink:href', canvas.toDataURL('image/png'));
          image.setAttribute('href', canvas.toDataURL('image/png'));
          resolve();
        }
        img.onerror = function () {
          reject('Could not load image: ' + href);
        }
      }));
    });
    Promise.all(promises)
           .then(callback)
           .catch(e => { throw new Error(e) });
  }
_inlineImages ( callback ) { const images = this . element . querySelectorAll ( 'image' ) ; if ( images . length === 0 ) { callback ( ) ; return ; } const promises = [ ] ; images . forEach ( ( image ) => { const href = image . getAttribute ( 'xlink:href' ) || image . getAttribute ( 'href' ) ; if ( href === null ) return ; if ( href && this . _isExternal ( href ) ) { throw new Error ( 'Cannot render embedded images linking to external hosts: ' + href ) ; } const canvas = document . createElement ( 'canvas' ) ; const ctx = canvas . getContext ( '2d' ) ; const img = new window . Image ( ) ; promises . push ( new Promise ( ( resolve , reject ) => { img . src = href ; img . onload = function ( ) { canvas . width = img . width ; canvas . height = img . height ; ctx . drawImage ( img , 0 , 0 ) ; image . setAttribute ( 'xlink:href' , canvas . toDataURL ( 'image/png' ) ) ; image . setAttribute ( 'href' , canvas . toDataURL ( 'image/png' ) ) ; resolve ( ) ; } img . onerror = function ( ) { reject ( 'Could not load image: ' + href ) ; } } ) ) ; } ) ; Promise . all ( promises ) . then ( callback ) . catch ( e => { throw new Error ( e ) } ) ; }
Inlines all images
 @param {function} callback - The callback to run after images have been loaded and inlined
Inlines all images @param { function } callback - The callback to run after images have been loaded and inlined
// Get any images // If there are no images, immediately call the callback // Iterate over the images // Get the href for the image // If no href for this image, skip this image // If we had a href, check if it's external // Create a canvas and image // Create a promise and push it to the promises array // Set the image source // Image load callback // Set the canvases size // Draw it onto the canvas // Update the href attribute of the image element // Resolve the promise // Image error callback // Image couldn't be loaded, reject the promise // Wait for promises to resolve and call the callback