| 8 | } |
| 9 | |
| 10 | export class LinearGradient { |
| 11 | public angle: number; |
| 12 | public colorStops: ColorStop[]; |
| 13 | |
| 14 | public static parse(value: CSSLinearGradient): LinearGradient { |
| 15 | const result = new LinearGradient(); |
| 16 | result.angle = value.angle; |
| 17 | result.colorStops = value.colors.map((color) => { |
| 18 | const offset = color.offset || null; |
| 19 | let offsetUnit: CoreTypes.LengthPercentUnit; |
| 20 | |
| 21 | if (offset && offset.unit === '%') { |
| 22 | offsetUnit = { |
| 23 | unit: '%', |
| 24 | value: offset.value, |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | return { |
| 29 | color: color.color, |
| 30 | offset: offsetUnit, |
| 31 | }; |
| 32 | }); |
| 33 | |
| 34 | return result; |
| 35 | } |
| 36 | |
| 37 | public static equals(first: LinearGradient, second: LinearGradient): boolean { |
| 38 | if (!first && !second) { |
| 39 | return true; |
| 40 | } else if (!first || !second) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | if (first.angle !== second.angle) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | if (first.colorStops.length !== second.colorStops.length) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | for (let i = 0; i < first.colorStops.length; i++) { |
| 53 | const firstStop = first.colorStops[i]; |
| 54 | const secondStop = second.colorStops[i]; |
| 55 | if (firstStop.offset !== secondStop.offset) { |
| 56 | return false; |
| 57 | } |
| 58 | if (!Color.equals(firstStop.color, secondStop.color)) { |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | } |
nothing calls this directly
no outgoing calls
no test coverage detected