#!/usr/bin/env python3
"""Render a full-canvas SVG to PNG through macOS Quick Look square tiles."""
from __future__ import annotations
import argparse
import math
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
class RenderError(RuntimeError):
pass
def normalize_svg(text: str) -> str:
text = re.sub(r"
]*)?>", lambda m: m.group(0)[:-1] + "/>" if not m.group(0).endswith("/>") else m.group(0), text, flags=re.IGNORECASE)
return text.replace(" ", " ")
def attr(root_tag: str, name: str) -> str | None:
match = re.search(rf"\b{name}\s*=\s*(['\"])(.*?)\1", root_tag, flags=re.IGNORECASE | re.DOTALL)
return match.group(2) if match else None
def parse_length(value: str | None) -> float | None:
if not value:
return None
match = re.match(r"\s*([0-9]+(?:\.[0-9]+)?)", value)
return float(match.group(1)) if match else None
def detect_size(svg_text: str) -> tuple[int, int]:
root_match = re.search(r"