Files
html/api/ambre-v10-render.php
2026-04-22 03:35:02 +02:00

79 lines
4.1 KiB
PHP

<?php
header("Content-Type: application/json");
$path = "/var/www/html/wevia.html";
$c = @file_get_contents($path);
$orig = strlen($c);
// The V10 block uses class="mermaid" which triggers the problematic CSS
// Keep class="mermaid" (so mermaid.run picks it up) BUT add an override style in-line
// The issue is font-size:0 !important - we can't override easily
// Better: after mermaid.run, the data-processed=true attribute is set, which UNSETS font-size:0
// So the issue must be that mermaid.run() isn't triggering or the SVG has issues
// Let me use a different approach: use mermaid.render() directly to get SVG as string, insert directly
$old = "var uniqId = \"mmd-\" + Date.now();
var inlineBlock = \"<div style=\\\"margin:12px 0;padding:14px;background:#fafafa;border:1px solid #e5e7eb;border-radius:12px\\\">\" +
\"<div style=\\\"font-weight:600;font-size:13px;color:#6b7280;margin-bottom:10px\\\">📊 \" + topic + \"</div>\" +
\"<div class=\\\"mermaid\\\" id=\\\"\" + uniqId + \"\\\" style=\\\"text-align:center;min-height:200px;font-size:14px;color:#333\\\">\" + mcode + \"</div>\"";
$new = "var uniqId = \"mmd-\" + Date.now();
// Pre-render SVG via mermaid.render() to avoid CSS font-size:0 !important issue
var inlineBlock = \"<div style=\\\"margin:12px 0;padding:14px;background:#fafafa;border:1px solid #e5e7eb;border-radius:12px\\\">\" +
\"<div style=\\\"font-weight:600;font-size:13px;color:#6b7280;margin-bottom:10px\\\">📊 \" + topic + \"</div>\" +
\"<div id=\\\"\" + uniqId + \"\\\" style=\\\"text-align:center;min-height:150px;padding:10px;background:#fff;border-radius:8px\\\">Rendu en cours...</div>\"";
if (strpos($c, $old) === false) {
echo json_encode(["error"=>"V10 pattern not found for CSS fix"]);
exit;
}
$c = str_replace($old, $new, $c);
// And update the render call to use mermaid.render(id, code) API
$old_render = "setTimeout(function(){
try {
if (window.mermaid && typeof window.mermaid.run === \"function\") {
window.mermaid.run({ nodes: [document.getElementById(uniqId)] });
}
} catch(e) { console.warn(\"mermaid render fail\", e); }
}, 300);";
$new_render = "setTimeout(function(){
try {
var target = document.getElementById(uniqId);
if (!target) return;
if (window.mermaid && typeof window.mermaid.render === \"function\") {
// Use render() to get SVG string directly
window.mermaid.render(\"svg-\" + uniqId, mcode).then(function(result) {
if (result && result.svg) {
target.innerHTML = result.svg;
target.style.minHeight = \"auto\";
}
}).catch(function(err){
console.warn(\"mermaid.render error\", err);
target.innerHTML = \"<pre style=\\\"font-size:11px;color:#b00;padding:10px;background:#fee;border-radius:6px\\\">Erreur rendu: \" + String(err).substring(0, 200) + \"</pre>\";
});
} else if (window.mermaid && typeof window.mermaid.init === \"function\") {
target.className = \"mermaid\";
target.textContent = mcode;
window.mermaid.init(undefined, target);
}
} catch(e) { console.warn(\"mermaid render fail\", e); }
}, 500);";
if (strpos($c, $old_render) === false) {
echo json_encode(["error"=>"render pattern not found", "orig_changed" => strlen($c) != $orig]);
exit;
}
$c = str_replace($old_render, $new_render, $c);
$backup = "/opt/wevads/vault/wevia.html.GOLD-" . date("Ymd-His") . "-v10-render";
@copy($path, $backup);
$wrote = @file_put_contents($path, $c);
echo json_encode([
"delta" => strlen($c) - $orig,
"wrote" => $wrote,
"backup" => basename($backup),
]);