#!/usr/bin/env bash
# Download Mermaid 10 bundle for offline / CSP-strict explorer hosts.
# Output: explorer-monorepo/frontend/public/thirdparty/mermaid.min.js (gitignored)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT_DIR="$(cd "$SCRIPT_DIR/../frontend/public/thirdparty" && pwd)"
mkdir -p "$OUT_DIR"
URL="${MERMAID_CDN_URL:-https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js}"
echo "Fetching Mermaid → $OUT_DIR/mermaid.min.js"
curl -fsSL -o "$OUT_DIR/mermaid.min.js" "$URL"
wc -c "$OUT_DIR/mermaid.min.js"
echo "Done. Point chain138-command-center.html at /thirdparty/mermaid.min.js and redeploy."
