* @param {Array } sources
(sources)
| 95 | * @param {Array<SourceDef>} sources |
| 96 | */ |
| 97 | constructor(sources) { |
| 98 | userAssert(sources.length > 0, 'Srcset must have at least one source'); |
| 99 | /** @private @const {Array<SourceDef>} */ |
| 100 | this.sources_ = sources; |
| 101 | |
| 102 | // Only one type of source specified can be used - width or DPR. |
| 103 | let hasWidth = false; |
| 104 | let hasDpr = false; |
| 105 | for (let i = 0; i < sources.length; i++) { |
| 106 | /** @type {?} */ |
| 107 | const source = sources[i]; |
| 108 | hasWidth = hasWidth || !!source.width; |
| 109 | hasDpr = hasDpr || !!source.dpr; |
| 110 | } |
| 111 | userAssert( |
| 112 | !!(hasWidth !== hasDpr), |
| 113 | 'Srcset must have width or dpr sources, but not both' |
| 114 | ); |
| 115 | |
| 116 | // Source and assert duplicates. |
| 117 | sources.sort( |
| 118 | /** @type {function(SourceDef, SourceDef):number} */ ( |
| 119 | /** @type {?} */ (hasWidth ? sortByWidth : sortByDpr) |
| 120 | ) |
| 121 | ); |
| 122 | |
| 123 | /** @private @const {boolean} */ |
| 124 | this.widthBased_ = hasWidth; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Performs selection for specified width and DPR. Here, width is the width |
nothing calls this directly
no test coverage detected