from pathlib import Path
import json


def parse_annotation_background_width(bpmn_path: Path):
    """Get the width the image was resized to when annotating in the BPMN Annotator tool"""
    assert bpmn_path.suffix == ".bpmn", f"{bpmn_path}"
    img_meta_line = bpmn_path.read_text().split("\n")[1]
    assert img_meta_line.startswith(
        "<!--"
    ), f"{bpmn_path} has no meta line, line 1: {img_meta_line}"
    img_meta = json.loads(img_meta_line.replace("<!-- ", "").replace(" -->", ""))
    return img_meta["backgroundSize"]