{
  "version": 3,
  "sources": ["/cdn/shop/t/129/assets/olaben-cart-autoopen.js?cb=x62998"],
  "sourcesContent": ["/* Olaben cart helpers (classic script, not a module, so Shopify's asset\n   pipeline won't rewrite it).\n\n   1) AUTO-OPEN: open the cart drawer after any add-to-cart, including the\n      collection-card quick add. Subscribes to Dawn's cartUpdate pub/sub event\n      and opens the drawer if it isn't already open. Safe/idempotent: if the\n      theme's own renderContents() already opened the drawer, this is a no-op.\n\n   2) BADGE RECONCILE: keep the header cart-count bubble honest. The header\n      badge and the drawer are independent server-rendered snapshots of the\n      cart. They only stay in sync when a shopper edits quantity through the\n      drawer's own controls. Anything that changes the cart out-of-band --\n      Shopify Shop cart sync on page load, a second browser tab, or a line\n      auto-removed at checkout -- leaves the header badge stale (e.g. it shows\n      3 while the cart actually holds 1). This re-reads /cart.js (the source of\n      truth) and repaints .cart-count-bubble to match. It only touches the\n      little count bubble, never the custom .hp02 cart icon. */\n(function () {\n  'use strict';\n\n  /* ---------- 1. Auto-open drawer ---------- */\n  function openDrawer() {\n    var drawer = document.querySelector('cart-drawer');\n    if (drawer && typeof drawer.open === 'function' && !drawer.classList.contains('active')) {\n      drawer.open();\n    }\n  }\n\n  /* ---------- 2. Badge reconcile ---------- */\n  var reconciling = false;\n  var pending = false;\n\n  function paintBubble(count) {\n    var link = document.getElementById('cart-icon-bubble');\n    if (!link) return;\n    var bubble = link.querySelector('.cart-count-bubble');\n\n    // Empty cart -> no bubble at all (matches the theme's {% if cart != empty %}).\n    if (!count || count < 1) {\n      if (bubble) bubble.remove();\n      return;\n    }\n\n    if (!bubble) {\n      bubble = document.createElement('div');\n      bubble.className = 'cart-count-bubble';\n      link.appendChild(bubble);\n    }\n\n    // Visible number, only when < 100 (matches the theme Liquid).\n    var numSpan = bubble.querySelector('span[aria-hidden=\"true\"]');\n    if (count < 100) {\n      if (!numSpan) {\n        numSpan = document.createElement('span');\n        numSpan.setAttribute('aria-hidden', 'true');\n        bubble.insertBefore(numSpan, bubble.firstChild);\n      }\n      if (numSpan.textContent !== String(count)) numSpan.textContent = String(count);\n    } else if (numSpan) {\n      numSpan.remove();\n    }\n\n    // Screen-reader count. Keep the existing locale wording if present and just\n    // swap the number; otherwise fall back to a plain English label.\n    var hidden = bubble.querySelector('.visually-hidden');\n    if (!hidden) {\n      hidden = document.createElement('span');\n      hidden.className = 'visually-hidden';\n      bubble.appendChild(hidden);\n    }\n    if (/\\d/.test(hidden.textContent)) {\n      hidden.textContent = hidden.textContent.replace(/\\d[\\d.,]*/, String(count));\n    } else {\n      hidden.textContent = count + ' item' + (count === 1 ? '' : 's');\n    }\n  }\n\n  function reconcileBadge() {\n    if (reconciling) { pending = true; return; }\n    reconciling = true;\n    fetch('/cart.js', { headers: { 'Accept': 'application/json' }, credentials: 'same-origin' })\n      .then(function (r) { return r.json(); })\n      .then(function (cart) {\n        paintBubble(cart && typeof cart.item_count === 'number' ? cart.item_count : 0);\n      })\n      .catch(function () { /* network error: leave the badge as-is */ })\n      .then(function () {\n        reconciling = false;\n        if (pending) { pending = false; setTimeout(reconcileBadge, 150); }\n      });\n  }\n\n  /* ---------- wiring ---------- */\n  function bind() {\n    if (typeof subscribe !== 'function' || typeof PUB_SUB_EVENTS === 'undefined' || !PUB_SUB_EVENTS.cartUpdate) {\n      return false;\n    }\n    subscribe(PUB_SUB_EVENTS.cartUpdate, function () {\n      setTimeout(openDrawer, 80);      // let the theme render the drawer first\n      setTimeout(reconcileBadge, 120); // then correct the badge from the source of truth\n    });\n    return true;\n  }\n\n  // Reconcile on load, then again shortly after: Shop cart sync reconciles the\n  // cart asynchronously after page load, so a single pass can run too early.\n  function initReconcile() {\n    reconcileBadge();\n    setTimeout(reconcileBadge, 1500);\n    setTimeout(reconcileBadge, 3500);\n  }\n\n  // Catch cross-tab cart edits and returning to the tab / bfcache restores.\n  window.addEventListener('pageshow', reconcileBadge);\n  document.addEventListener('visibilitychange', function () {\n    if (document.visibilityState === 'visible') reconcileBadge();\n  });\n\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', function () {\n      if (!bind()) setTimeout(bind, 500);\n      initReconcile();\n    });\n  } else {\n    if (!bind()) setTimeout(bind, 500);\n    initReconcile();\n  }\n})();\n"],
  "mappings": "CAiBC,UAAY,CACX,aAGA,SAAS,YAAa,CACpB,IAAI,OAAS,SAAS,cAAc,aAAa,EAC7C,QAAU,OAAO,OAAO,MAAS,YAAc,CAAC,OAAO,UAAU,SAAS,QAAQ,GACpF,OAAO,KAAK,CAEhB,CAGA,IAAI,YAAc,GACd,QAAU,GAEd,SAAS,YAAY,MAAO,CAC1B,IAAI,KAAO,SAAS,eAAe,kBAAkB,EACrD,GAAK,KACL,KAAI,OAAS,KAAK,cAAc,oBAAoB,EAGpD,GAAI,CAAC,OAAS,MAAQ,EAAG,CACnB,QAAQ,OAAO,OAAO,EAC1B,MACF,CAEK,SACH,OAAS,SAAS,cAAc,KAAK,EACrC,OAAO,UAAY,oBACnB,KAAK,YAAY,MAAM,GAIzB,IAAI,QAAU,OAAO,cAAc,0BAA0B,EACzD,MAAQ,KACL,UACH,QAAU,SAAS,cAAc,MAAM,EACvC,QAAQ,aAAa,cAAe,MAAM,EAC1C,OAAO,aAAa,QAAS,OAAO,UAAU,GAE5C,QAAQ,cAAgB,OAAO,KAAK,IAAG,QAAQ,YAAc,OAAO,KAAK,IACpE,SACT,QAAQ,OAAO,EAKjB,IAAI,OAAS,OAAO,cAAc,kBAAkB,EAC/C,SACH,OAAS,SAAS,cAAc,MAAM,EACtC,OAAO,UAAY,kBACnB,OAAO,YAAY,MAAM,GAEvB,KAAK,KAAK,OAAO,WAAW,EAC9B,OAAO,YAAc,OAAO,YAAY,QAAQ,YAAa,OAAO,KAAK,CAAC,EAE1E,OAAO,YAAc,MAAQ,SAAW,QAAU,EAAI,GAAK,KAE/D,CAEA,SAAS,gBAAiB,CACxB,GAAI,YAAa,CAAE,QAAU,GAAM,MAAQ,CAC3C,YAAc,GACd,MAAM,WAAY,CAAE,QAAS,CAAE,O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