()
| 190 | } |
| 191 | |
| 192 | function runSweep(): { total: number, mismatches: Mismatch[], rows: AccuracyRow[] } { |
| 193 | const container = document.createElement('div') |
| 194 | container.style.cssText = 'position:absolute;top:-9999px;left:-9999px;visibility:hidden' |
| 195 | document.body.appendChild(container) |
| 196 | |
| 197 | const mismatches: Mismatch[] = [] |
| 198 | const rows: AccuracyRow[] = [] |
| 199 | let total = 0 |
| 200 | |
| 201 | for (const fontFamily of FONTS) { |
| 202 | for (const fontSize of SIZES) { |
| 203 | const font = `${fontSize}px ${fontFamily}` |
| 204 | const lineHeight = Math.round(fontSize * 1.2) |
| 205 | clearCache() |
| 206 | |
| 207 | for (const maxWidth of WIDTHS) { |
| 208 | const divs: HTMLDivElement[] = [] |
| 209 | const prepared: PreparedTextWithSegments[] = [] |
| 210 | |
| 211 | for (const { text } of TEXTS) { |
| 212 | const div = document.createElement('div') |
| 213 | div.style.font = font |
| 214 | div.style.lineHeight = `${lineHeight}px` |
| 215 | div.style.width = `${maxWidth}px` |
| 216 | div.style.wordWrap = 'break-word' |
| 217 | div.style.overflowWrap = 'break-word' |
| 218 | div.textContent = text |
| 219 | container.appendChild(div) |
| 220 | divs.push(div) |
| 221 | prepared.push(prepareWithSegments(text, font)) |
| 222 | } |
| 223 | |
| 224 | for (let i = 0; i < TEXTS.length; i++) { |
| 225 | const { label, text } = TEXTS[i]! |
| 226 | const actual = divs[i]!.getBoundingClientRect().height |
| 227 | const predicted = layout(prepared[i]!, maxWidth, lineHeight).height |
| 228 | rows.push({ |
| 229 | label, |
| 230 | font: fontFamily, |
| 231 | fontSize, |
| 232 | lineHeight, |
| 233 | width: maxWidth, |
| 234 | actual, |
| 235 | predicted, |
| 236 | diff: predicted - actual, |
| 237 | }) |
| 238 | total++ |
| 239 | if (Math.abs(actual - predicted) >= 1) { |
| 240 | const browserLines = getBrowserLines(prepared[i]!, divs[i]!) |
| 241 | const ourLayout = layoutWithLines(prepared[i]!, maxWidth, lineHeight) |
| 242 | |
| 243 | const lineDetails: string[] = [] |
| 244 | const maxLines = Math.max(browserLines.length, ourLayout.lines.length) |
| 245 | for (let li = 0; li < maxLines; li++) { |
| 246 | const ours = (ourLayout.lines[li]?.text ?? '').trimEnd() |
| 247 | const theirs = (browserLines[li] ?? '').trimEnd() |
| 248 | if (ours !== theirs) { |
| 249 | lineDetails.push(`L${li+1} ours="${ours.slice(0,40)}" browser="${theirs.slice(0,40)}"`) |
no test coverage detected
searching dependent graphs…