55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Sync frontend/src/app/globals.css -> redmini/tool/nomadro.css (Chrome 61 sanitize)."""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SRC = ROOT / "frontend" / "src" / "app" / "globals.css"
|
|
OUT = ROOT / "redmini" / "tool" / "nomadro.css"
|
|
|
|
|
|
def unwrap_layers(text: str) -> str:
|
|
while True:
|
|
m = re.search(r"@layer\s+[\w-]+\s*\{", text)
|
|
if not m:
|
|
break
|
|
start = m.start()
|
|
i = m.end()
|
|
depth = 1
|
|
while i < len(text) and depth:
|
|
if text[i] == "{":
|
|
depth += 1
|
|
elif text[i] == "}":
|
|
depth -= 1
|
|
i += 1
|
|
text = text[:start] + text[m.end() : i - 1] + text[i:]
|
|
return text
|
|
|
|
|
|
def main() -> int:
|
|
src = SRC.read_text(encoding="utf-8")
|
|
src = re.sub(
|
|
r"html:has\(\[data-ebook-root\]\)[^{]*\{(?:[^{}]|\{[^{}]*\})*\}",
|
|
"",
|
|
src,
|
|
)
|
|
src = re.sub(
|
|
r"html:has\(\[data-ebook-root\]\)\s+body\s*\{(?:[^{}]|\{[^{}]*\})*\}",
|
|
"",
|
|
src,
|
|
)
|
|
src = unwrap_layers(src)
|
|
src = src.replace("var(--font-outfit), ", "").replace(", var(--font-outfit)", "")
|
|
OUT.write_text(
|
|
"/* Mirror of frontend/src/app/globals.css — synced for XHS offline H5 */\n" + src,
|
|
encoding="utf-8",
|
|
)
|
|
print(f"wrote {OUT} ({OUT.stat().st_size} bytes) open={src.count('{')} close={src.count('}')}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|