<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://theb2bdigital.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://theb2bdigital.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://theb2bdigital.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://theb2bdigital.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap></sitemapindex>

    <span id="cursorani-follower" class="cursorani-cursor-follower"></span>
    <span id="cursorani-follower-dot" class="cursorani-cursor-follower-dot"></span>
    <script>
        (function () {
            var mouseX = 0, mouseY = 0;
            var ringX  = 0, ringY  = 0;
            var dotX   = 0, dotY   = 0;

            var ring = document.getElementById("cursorani-follower");
            var dot  = document.getElementById("cursorani-follower-dot");

            if ( ! ring || ! dot ) return;

            // ── Parse any color string into r,g,b ────────────────────────────
            function cursorani_parse_rgb( str ) {
                if ( ! str ) return null;
                var m = str.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
                if ( ! m ) return null;
                return { r: parseInt(m[1]), g: parseInt(m[2]), b: parseInt(m[3]) };
            }

            // ── YIQ perceived brightness (0–255) ─────────────────────────────
            function cursorani_brightness( rgb ) {
                return ( rgb.r * 299 + rgb.g * 587 + rgb.b * 114 ) / 1000;
            }

            // ── Is this color essentially transparent / not set? ─────────────
            function cursorani_is_transparent( str ) {
                if ( ! str ) return true;
                if ( str === "transparent" ) return true;
                if ( str === "rgba(0, 0, 0, 0)" ) return true;
                // rgba with 0 alpha
                var m = str.match(/rgba\(\d+,\s*\d+,\s*\d+,\s*([\d.]+)\)/);
                if ( m && parseFloat(m[1]) === 0 ) return true;
                return false;
            }

            // ── Walk up DOM to find first opaque background color ────────────
            function cursorani_get_bg( el ) {
                while ( el && el !== document.documentElement ) {
                    var bg = window.getComputedStyle( el ).backgroundColor;
                    if ( ! cursorani_is_transparent( bg ) ) return bg;
                    el = el.parentElement;
                }
                // Fallback: body background
                var bodyBg = window.getComputedStyle( document.body ).backgroundColor;
                if ( ! cursorani_is_transparent( bodyBg ) ) return bodyBg;
                return "rgb(255,255,255)";
            }

            // ── Get text color of element (only if it is a text node host) ───
            function cursorani_get_text_color( el ) {
                if ( ! el ) return null;
                // Only consider leaf-level or near-leaf text elements
                var tag = el.tagName ? el.tagName.toLowerCase() : "";
                var textTags = ["p","h1","h2","h3","h4","h5","h6","span","a","li","td","th","label","strong","em","b","i","small","blockquote"];
                if ( textTags.indexOf(tag) === -1 ) return null;
                return window.getComputedStyle( el ).color;
            }

            // ── Master decision: should cursor be white? ─────────────────────
            function cursorani_should_be_light( el ) {
                if ( ! el ) return false;

                // 1. Check background going up the DOM
                var bgStr = cursorani_get_bg( el );
                var bgRgb = cursorani_parse_rgb( bgStr );
                if ( bgRgb && cursorani_brightness( bgRgb ) < 100 ) {
                    // Clearly dark background — go white
                    return true;
                }

                // 2. If background is mid-dark (100–160), also go white
                if ( bgRgb && cursorani_brightness( bgRgb ) < 160 ) {
                    return true;
                }

                // 3. Check text color of the element directly under cursor
                var textStr = cursorani_get_text_color( el );
                if ( textStr ) {
                    var textRgb = cursorani_parse_rgb( textStr );
                    if ( textRgb && cursorani_brightness( textRgb ) < 80 ) {
                        // Dark navy / black text on a light bg
                        // Keep cursor black — it will be visible
                        return false;
                    }
                    // Light text on any bg → cursor should be white? 
                    // Only if bg is also not very light
                    if ( textRgb && cursorani_brightness( textRgb ) > 180 ) {
                        // Light-colored text — bg is likely dark
                        return true;
                    }
                }

                return false;
            }

            // ── Throttle helper ──────────────────────────────────────────────
            var cursorani_last_check = 0;

            document.addEventListener("mousemove", function (e) {
                mouseX = e.clientX;
                mouseY = e.clientY;

                var now = Date.now();
                if ( now - cursorani_last_check < 50 ) return; // check every 50ms max
                cursorani_last_check = now;

                // Hide cursor elements so elementFromPoint sees what is beneath
                ring.style.visibility = "hidden";
                dot.style.visibility  = "hidden";

                var el = document.elementFromPoint( e.clientX, e.clientY );

                ring.style.visibility = "";
                dot.style.visibility  = "";

                var light = cursorani_should_be_light( el );

                if ( light ) {
                    ring.classList.add("cursorani-light");
                    dot.classList.add("cursorani-light");
                } else {
                    ring.classList.remove("cursorani-light");
                    dot.classList.remove("cursorani-light");
                }
            });

            // ── Animation loop ───────────────────────────────────────────────
            function animate() {
                ringX += ( mouseX - ringX ) / 8;
                ringY += ( mouseY - ringY ) / 8;

                dotX += ( mouseX - dotX ) / 2;
                dotY += ( mouseY - dotY ) / 2;

                ring.style.left = ringX + "px";
                ring.style.top  = ringY + "px";

                dot.style.left = dotX + "px";
                dot.style.top  = dotY + "px";

                requestAnimationFrame( animate );
            }

            animate();
        })();
    </script>