| 25 | }; |
| 26 | const BLOCKS = [' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█']; |
| 27 | export function ProgressBar(t0) { |
| 28 | const $ = _c(13); |
| 29 | const { |
| 30 | ratio: inputRatio, |
| 31 | width, |
| 32 | fillColor, |
| 33 | emptyColor |
| 34 | } = t0; |
| 35 | const ratio = Math.min(1, Math.max(0, inputRatio)); |
| 36 | const whole = Math.floor(ratio * width); |
| 37 | let t1; |
| 38 | if ($[0] !== whole) { |
| 39 | t1 = BLOCKS[BLOCKS.length - 1].repeat(whole); |
| 40 | $[0] = whole; |
| 41 | $[1] = t1; |
| 42 | } else { |
| 43 | t1 = $[1]; |
| 44 | } |
| 45 | let segments; |
| 46 | if ($[2] !== ratio || $[3] !== t1 || $[4] !== whole || $[5] !== width) { |
| 47 | segments = [t1]; |
| 48 | if (whole < width) { |
| 49 | const remainder = ratio * width - whole; |
| 50 | const middle = Math.floor(remainder * BLOCKS.length); |
| 51 | segments.push(BLOCKS[middle]); |
| 52 | const empty = width - whole - 1; |
| 53 | if (empty > 0) { |
| 54 | let t2; |
| 55 | if ($[7] !== empty) { |
| 56 | t2 = BLOCKS[0].repeat(empty); |
| 57 | $[7] = empty; |
| 58 | $[8] = t2; |
| 59 | } else { |
| 60 | t2 = $[8]; |
| 61 | } |
| 62 | segments.push(t2); |
| 63 | } |
| 64 | } |
| 65 | $[2] = ratio; |
| 66 | $[3] = t1; |
| 67 | $[4] = whole; |
| 68 | $[5] = width; |
| 69 | $[6] = segments; |
| 70 | } else { |
| 71 | segments = $[6]; |
| 72 | } |
| 73 | const t2 = segments.join(""); |
| 74 | let t3; |
| 75 | if ($[9] !== emptyColor || $[10] !== fillColor || $[11] !== t2) { |
| 76 | t3 = <Text color={fillColor} backgroundColor={emptyColor}>{t2}</Text>; |
| 77 | $[9] = emptyColor; |
| 78 | $[10] = fillColor; |
| 79 | $[11] = t2; |
| 80 | $[12] = t3; |
| 81 | } else { |
| 82 | t3 = $[12]; |
| 83 | } |
| 84 | return t3; |