File size: 483 Bytes
f66643d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from __future__ import annotations

import re

_HTML_TAG = re.compile(r"</?(?:b|i|u|strong|em)>", re.IGNORECASE)


def strip_html_tags(s: str) -> str:
    return _HTML_TAG.sub("", s)


def inflate(bbox: list[float], pad: float) -> list[float]:
    x0, y0, x1, y1 = bbox
    return [x0 - pad, y0 - pad, x1 + pad, y1 + pad]


def clamp(bbox: list[float], pw: float, ph: float) -> list[float]:
    x0, y0, x1, y1 = bbox
    return [max(0.0, x0), max(0.0, y0), min(pw, x1), min(ph, y1)]