src/srcset.js
/**
   * Performs selection for specified width and DPR. Here, width is the width
   * in screen pixels and DPR is the device-pixel-ratio or pixel density of
   * the device. Depending on the circumstances, such as low network conditions,
   * it's possible to manipulate the result of this method by passing a lower
   * DPR value.
   *
   * The source selection depends on whether this is width-based or DPR-based
   * srcset.
   *
   * In a width-based source, the source's width is the physical width of a
   * resource (e.g. an image). Depending on the provided DPR, this width is
   * converted to the screen pixels as following:
   *   pixelWidth = sourceWidth / DPR
   *
   * Then, the source closest to the requested "width" is selected using
   * the "pixelWidth". The slight preference is given to the bigger sources to
   * ensure the most optimal quality.
   *
   * In a DPR-based source, the source's DPR is used to return the source that
   * is closest to the requested DPR.
   *
   * Based on
   * http://www.w3.org/html/wg/drafts/html/master/semantics.html#attr-img-srcset.
   * @param {number} width
   * @param {number} dpr
   * @return {!SrcsetSourceDef}
   */
Performs selection for specified width and DPR. Here, width is the width
in screen pixels and DPR is the device-pixel-ratio or pixel density of
the device. Depending on the circumstances, such as low network conditions,
it's possible to manipulate the result of this method by passing a lower
DPR value.

The source selection depends on whether this is width-based or DPR-based
srcset.

In a width-based source, the source's width is the physical width of a
resource . Depending on the provided DPR, this width is
converted to the screen pixels as following:
pixelWidth = sourceWidth / DPR

Then, the source closest to the requested "width" is selected using
the "pixelWidth". The slight preference is given to the bigger sources to
ensure the most optimal quality.

In a DPR-based source, the source's DPR is used to return the source that
is closest to the requested DPR.


Performs selection for specified width and DPR . Here width is the width in screen pixels and DPR is the device - pixel - ratio or pixel density of the device . Depending on the circumstances such as low network conditions it ' s possible to manipulate the result of this method by passing a lower DPR value . The source selection depends on whether this is width - based or DPR - based srcset . In a width - based source the source ' s width is the physical width of a resource . Depending on the provided DPR this width is converted to the screen pixels as following : pixelWidth = sourceWidth / DPR Then the source closest to the requested " width " is selected using the " pixelWidth " . The slight preference is given to the bigger sources to ensure the most optimal quality . In a DPR - based source the source ' s DPR is used to return the source that is closest to the requested DPR .
select(width, dpr) {
    dev().assert(width, 'width=%s', width);
    dev().assert(dpr, 'dpr=%s', dpr);
    let index = -1;
    if (this.widthBased_) {
      index = this.selectByWidth_(width, dpr);
    } else if (this.dprBased_) {
      index = this.selectByDpr_(width, dpr);
    }
    if (index != -1) {
      return this.sources_[index];
    }
    return this.getLast();
  }
select ( width , dpr ) { dev ( ) . assert ( width , 'width=%s' , width ) ; dev ( ) . assert ( dpr , 'dpr=%s' , dpr ) ; let index = - 1 ; if ( this . widthBased_ ) { index = this . selectByWidth_ ( width , dpr ) ; } else if ( this . dprBased_ ) { index = this . selectByDpr_ ( width , dpr ) ; } if ( index != - 1 ) { return this . sources_ [ index ] ; } return this . getLast ( ) ; }
Performs selection for specified width and DPR.
Performs selection for specified width and DPR .