()
| 160 | const maxFrames = 40; // 约 650ms 兜底 |
| 161 | |
| 162 | const tick = () => { |
| 163 | totalFrames += 1; |
| 164 | if (totalFrames > maxFrames) { |
| 165 | onTimeout?.(); |
| 166 | callback(); |
| 167 | return; |
| 168 | } |
| 169 | const h = measure(); |
| 170 | if (h === last) { |
| 171 | stableFrames += 1; |
| 172 | if (stableFrames >= 3) { |
| 173 | callback(); |
| 174 | return; |
| 175 | } |
| 176 | } else { |
| 177 | last = h; |
| 178 | stableFrames = 0; |
| 179 | } |
| 180 | requestAnimationFrame(tick); |
| 181 | }; |
| 182 | requestAnimationFrame(tick); |
| 183 | } |
| 184 |