<style>
  :root{
    --wipe-duration: .25s;
    --wipe-ease: cubic-bezier(.22,.61,.36,1);
    --wipe-color: #207495;
  }

  .wipe-overlay{
    position: fixed; inset: 0;
    background: var(--wipe-color);
    z-index: 2147483647;
    pointer-events: none;
    transform: translateY(0);
    transition: transform var(--wipe-duration) ease-in-out;
  }

  .wipe-overlay.no-trans{ transition: none; }
  .wipe-overlay.is-revealing{ transform: translateY(100%); }

  .wipe-overlay.pre-enter{ transform: translateY(-100%); }
  .wipe-overlay.is-covering{ transform: translateY(0); }

  .wipe-overlay{ box-shadow: 0 2px 0 rgba(0,0,0,.03); }

  @media (prefers-reduced-motion: reduce){
    .wipe-overlay{ transition: none !important; transform: translateY(100%) !important; }
  }
</style>

<div class="wipe-overlay no-trans" id="wipe"></div>

<script>
(function () {
  var wipe = document.getElementById('wipe');
  if (!wipe) return;

  function startReveal(){
    wipe.classList.remove('no-trans');
    requestAnimationFrame(function(){
      wipe.classList.add('is-revealing');
    });
  }

  window.addEventListener('pageshow', function () {
    wipe.classList.add('no-trans');
    wipe.classList.remove('pre-enter','is-covering','is-revealing');
    requestAnimationFrame(startReveal);
  });

  function normPath(p){
    if (!p) return '/';
    p = p.replace(/\/index\.html?$/i, '/').replace(/\/+$/,'/');
    return p || '/';
  }

  document.addEventListener('click', function (e) {
    if (e.defaultPrevented) return;

    var a = e.target.closest && e.target.closest('a');
    if (!a) return;

    var here = new URL(window.location.href);
    var url  = new URL(a.href, here);

    // Zelfde origin?
    if (url.origin !== here.origin) return;
    // Modifier keys -> laat browser z'n ding doen
    if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
    // Nieuwe tab / download -> niet wipen
    if (a.target === '_blank' || a.hasAttribute('download')) return;

    // >>> ENIGE VOORWAARDE OM TE WIPEN:
    // alleen als pad of query anders is (hash telt NIET mee)
    var samePath   = normPath(url.pathname) === normPath(here.pathname);
    var sameSearch = url.search === here.search;

    if (samePath && sameSearch) {
      // zelfde document (incl. http://localhost:1313/#) -> GEEN wipe
      return;
    }

    // echte navigatie -> wipe + ga
    e.preventDefault();

    wipe.classList.add('no-trans');
    wipe.classList.remove('is-revealing','is-covering');
    wipe.classList.add('pre-enter');
    void wipe.offsetHeight;

    wipe.classList.remove('no-trans');
    wipe.classList.remove('pre-enter');
    wipe.classList.add('is-covering');

    var go = function () {
      wipe.removeEventListener('transitionend', go);
      window.location.href = a.href;
    };
    wipe.addEventListener('transitionend', go);
  }, { capture: true });
})();
</script>

