///|
extern "js" fn js_build_synthetic_print_details_json(
current_url : String,
params_json : String,
page_width_cm : Double,
page_height_cm : Double,
) -> String =
#| (currentUrl, paramsJson, pageWidthCm, pageHeightCm) => {
#| const parseJson = (text, fallback) => {
#| try {
#| const parsed = JSON.parse(String(text || ""));
#| return parsed && typeof parsed === "object" ? parsed : fallback;
#| } catch (_err) {
#| return fallback;
#| }
#| };
#| const params = parseJson(paramsJson, {});
#| const decodeDataHtml = (url) => {
#| const text = String(url || "");
#| if (!text.startsWith("data:text/html")) return "";
#| const comma = text.indexOf(",");
#| if (comma < 0) return "";
#| const meta = text.slice(5, comma).toLowerCase();
#| let encoded = text.slice(comma + 1);
#| const hash = encoded.indexOf("#");
#| if (hash >= 0) encoded = encoded.slice(0, hash);
#| try {
#| if (meta.includes(";base64")) {
#| return decodeURIComponent(escape(atob(encoded)));
#| }
#| return decodeURIComponent(encoded);
#| } catch (_err) {
#| return "";
#| }
#| };
#| const html = (() => {
#| const decoded = decodeDataHtml(currentUrl);
#| if (decoded) return decoded;
#| try {
#| const body = globalThis.document && globalThis.document.body ? globalThis.document.body : null;
#| return body && typeof body.innerHTML === "string" ? body.innerHTML : "";
#| } catch (_err) {
#| return "";
#| }
#| })();
#| const normalizeText = (text) => String(text || "").replace(/\s+/g, " ").trim();
#| const stripDecorators = (text) =>
#| String(text || "")
#| .replace(/