vendor: 1,342 bytes, lines 1-53
1/* 2 Normalize an array of color stop positions for a gradient 3 based on the rules defined in the CSS Images Module 4 spec: 4 5 1. make the first position 0 and the last position 1 if missing 6 2. sequences of unpositioned color stops should be spread out evenly 7 3. no position can be smaller than any of the ones preceding it 8 9 Reference: https://drafts.csswg.org/css-images-4/#color-stop-fixup 10 11 Note: this method does not make a defensive copy of the array 12 it receives as argument. Instead, it adjusts the values in-place. 13 */ 14const normalizePositions = arr => { 15 // 1. fix up first/last position if missing 16 if (arr[0] === undefined) { 17 arr[0] = 0; 18 } 19 if (arr[arr.length - 1] === undefined) { 20 arr[arr.length - 1] = 1; 21 } 22 23 let i = 1; 24 let j; 25 let from_idx; 26 let from_pos; 27 let inc; 28 while (i < arr.length) { 29 // 2. fill up undefined positions 30 if (arr[i] === undefined) { 31 from_idx = i; 32 from_pos = arr[i - 1]; 33 j = i; 34 35 // find end of `undefined` sequence... 36 while (arr[j] === undefined) j++; 37 38 // ...and add evenly-spread positions 39 inc = (arr[j] - from_pos) / (j - i + 1); 40 while (i < j) { 41 arr[i] = from_pos + (i + 1 - from_idx) * inc; 42 i++; 43 } 44 } else if (arr[i] < arr[i - 1]) { 45 // 3. make positions increase 46 arr[i] = arr[i - 1]; 47 } 48 i++; 49 } 50 return arr; 51}; 52 53export default normalizePositions;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.