{
  "version": 3,
  "sources": ["/cdn/shop/t/40/assets/eg-reward-cart.js?cb=1794350615453"],
  "sourcesContent": ["/* EG REWARD LINES - the drawer script of snippets/eg-reward-cart.liquid (RFC 0007 S70).\n *\n * WHAT IT DOES. It marks the UpCart drawer row of every one-time EG reward line - a cart line that\n * carries the property the snippet names, _Gifted, and is on no selling plan - with the attribute\n * data-eg-reward, and the snippet's style then hides that row's \"Upgrade to Subscribe & Save\"\n * section and any select in it. Every other row is left exactly as UpCart drew it, and so is a\n * reward line that is already on a plan: it has lost its reward already, and its plan select is the\n * drawer's only sign that it renews and its only way back to one-time purchase. It never writes to\n * the cart: its only request is a GET of cart.js.\n *\n * WHY A CACHED ASSET, NOT INLINE. Its code is about 4 KB once the comments are stripped (as Shopify's\n * CDN serves theme JS; under 2 KB compressed), the same on every page, so as a file it is downloaded\n * once and cached across pages, while an inline script is sent again with every page's HTML, comments\n * included (inline scripts are not minified). That is not tiny next to the inline precedent,\n * snippets/hide-internal-cart-properties.liquid (under 1 KB). Deferred is early enough: it runs before\n * UpCart's own bundle, and no flash needs preventing. If the file fails to load, nothing is hidden,\n * which is exactly the state before this fix. The snippet keeps the 150-byte style inline (a\n * stylesheet would cost a request on every page for nothing). The same split as assets/bfcm-sub-cart.js\n * (PR 3b, RFC 0007 S57), six-pack-cart.js and loop-plan-guard.js.\n *\n * ITS DATA. The loader tag carries three attributes, all from Liquid: data-eg-reward-prop (the\n * property name), data-eg-reward-lines (every line key of the cart the page was rendered with) and\n * data-eg-reward-gifted (the keys among them of one-time reward lines: the rows to mark). Shopify\n * builds a line key from the variant id and a hash of the line's properties and selling plan (a plan\n * change gives the line a new key, as assets/six-pack-cart.js notes), so a key never changes what it\n * names: once seen, it is known for good. Nothing in this file is Liquid.\n *\n * WHEN IT READS THE CART. Never while the drawer has no rows. Otherwise only when the drawer's row\n * signature (each row's id and quantity, as assets/bfcm-sub-cart.js and six-pack-cart.js sign it) has\n * changed AND a row holds a line key this page does not know yet: a line added after the page was\n * rendered. DEBOUNCE ms after the last such change, one read at a time; a change that lands during a\n * read gets one more read afterwards, and only if a row is still unknown then. When the rows go away\n * (UpCart draws none while its drawer is closed) the signature is cleared, so the same rows drawn\n * again count as a change: a read whose timer fired while no row was there is not lost. A read that\n * has not answered after READ_LIMIT ms is given up: aborted, its answer unused, the lock released.\n * A failed, unreadable or given-up answer changes nothing - every row keeps what UpCart drew - and is\n * not retried until the drawer changes again, and a key is read for at most TRIES times while it\n * stays unknown, so no read ever repeats by itself or keeps feeding on UpCart's redraws. A pageview\n * whose drawer shows the cart the page was rendered with therefore makes no request at all.\n *\n * TIMING. Loaded with defer from the layout, it runs once the page is parsed and before UpCart's own\n * deferred app-embed bundle further down the body, so its observer is already watching when UpCart\n * draws the rows. Rows already drawn are marked at once, later ones within a frame of each change.\n * The observer also sees a row's id change in place, so a row node UpCart reuses for another line is\n * marked or unmarked for its new line.\n *\n * SHARED WITH Q32. assets/bfcm-3pack-cart.js (RFC 0007 Q32, BFCM only) carries a copy of this file's\n * read logic, so a fix here must be made there too while that file exists.\n *\n * LIMITS. Rows are UpCart V1's .upcart-product-item in the document (the light DOM this store\n * renders), whose id holds the line key \"<variant id>:<32 hex>\", the shape assets/bfcm-sub-cart.js and\n * six-pack-cart.js rely on. A V2 drawer or a shadow-root drawer shows no such row, and then this file\n * reads nothing and hides nothing. Display only, and only once a row is classified: a reward EG adds\n * after the page loaded shows UpCart's button for DEBOUNCE ms plus one cart.js round trip, and keeps\n * it after a failed read until the drawer changes again. A cart request made some other way can still\n * put a plan on a reward line.\n */\n(function () {\n  'use strict';\n  try {\n    if (window.egRewardCart) return;\n    var loader = document.querySelector('script[data-eg-reward-prop]');\n    var PROP = loader ? String(loader.getAttribute('data-eg-reward-prop') || '').trim() : '';\n    if (!PROP) return;\n    var MARK = 'data-eg-reward';\n    var ROW = '.upcart-product-item';\n    var KEY = /\\d+:[0-9a-f]{32}/i;\n    var DEBOUNCE = 250;\n    var READ_LIMIT = 8000;\n    var TRIES = 2;\n\n    /* Line key -> true: every key this page has classified, and the one-time reward keys among them\n     * (the rows to mark). */\n    var known = {};\n    var gifted = {};\n    /* Line key -> the reads made while that key was unknown (TRIES caps them). */\n    var tries = {};\n    function keyList(attribute) {\n      return String(loader.getAttribute(attribute) || '')\n        .split(',')\n        .map(function (key) { return key.trim().toLowerCase(); })\n        .filter(Boolean);\n    }\n    keyList('data-eg-reward-lines').forEach(function (key) { known[key] = true; });\n    keyList('data-eg-reward-gifted').forEach(function (key) {\n      known[key] = true;\n      gifted[key] = true;\n    });\n\n    function root() {\n      return (window.Shopify && window.Shopify.routes && window.Shopify.routes.root) || '/';\n    }\n    function rows() {\n      return Array.prototype.slice.call(document.querySelectorAll(ROW));\n    }\n    function rowKey(row) {\n      var match = String(row.id || '').match(KEY);\n      return match ? match[0].toLowerCase() : '';\n    }\n    function rowQty(row) {\n      var input = row.querySelector('.upcart-product-quantity-input');\n      return input ? String(input.value) : '';\n    }\n    /* A row worth a read: its key is not classified yet and has not used up its reads. */\n    function unknownRow(row) {\n      var key = rowKey(row);\n      return !!key && !known[key] && (tries[key] || 0) < TRIES;\n    }\n    /* A reward line: the property is there with a value (EG writes the rule name). The same test as\n     * the snippet's Liquid (the value, stripped, not blank). */\n    function isReward(line) {\n      var props = line && line.properties;\n      if (!props || typeof props !== 'object') return false;\n      if (!Object.prototype.hasOwnProperty.call(props, PROP)) return false;\n      var value = props[PROP];\n      return value !== null && value !== undefined && String(value).trim() !== '';\n    }\n    /* On a selling plan: cart.js gives a one-time line no selling_plan_allocation. The same test as\n     * the snippet's Liquid. */\n    function onPlan(line) {\n      return !!(line && line.selling_plan_allocation);\n    }\n    /* Compare-then-set: a row is written only when its mark is wrong for its line. */\n    function paint(list) {\n      list.forEach(function (row) {\n        var on = !!gifted[rowKey(row)];\n        if (row.hasAttribute(MARK) === on) return;\n        if (on) row.setAttribute(MARK, '');\n        else row.removeAttribute(MARK);\n      });\n    }\n\n    var timer = null;\n    var busy = false;\n    var again = false;\n    function schedule() {\n      window.clearTimeout(timer);\n      timer = window.setTimeout(read, DEBOUNCE);\n    }\n    function read() {\n      timer = null;\n      if (busy) {\n        again = true;\n        return;\n      }\n      var list = rows();\n      if (!list.some(unknownRow)) return;\n      var counted = {};\n      list.forEach(function (row) {\n        if (!unknownRow(row)) return;\n        var key = rowKey(row);\n        if (counted[key]) return;\n        counted[key] = true;\n        tries[key] = (tries[key] || 0) + 1;\n      });\n      busy = true;\n      var done = false;\n      var ctl = typeof window.AbortController === 'function' ? new window.AbortController() : null;\n      /* A stalled connection would otherwise hold the one-at-a-time lock, and with it every later\n       * reward's read, for as long as the browser keeps the request open. */\n      var limit = window.setTimeout(function () {\n        if (ctl) ctl.abort();\n        finish();\n      }, READ_LIMIT);\n      function finish() {\n        if (done) return;\n        done = true;\n        window.clearTimeout(limit);\n        busy = false;\n        if (again) {\n          again = false;\n          schedule();\n        }\n      }\n      var init = { cache: 'no-store', headers: { Accept: 'application/json' } };\n      if (ctl) init.signal = ctl.signal;\n      fetch(root() + 'cart.js', init)\n        .then(function (response) {\n          return !done && response && response.ok ? response.json() : null;\n        })\n        .then(function (cart) {\n          if (done || !cart || !Array.isArray(cart.items)) return;\n          cart.items.forEach(function (line) {\n            var key = line && line.key ? String(line.key).toLowerCase() : '';\n            if (!key) return;\n            known[key] = true;\n            if (isReward(line) && !onPlan(line)) gifted[key] = true;\n            else delete gifted[key];\n          });\n          paint(rows());\n        })\n        .catch(function () {\n          /* Nothing changes: every row keeps what UpCart drew. */\n        })\n        .then(finish);\n    }\n\n    var lastSig = '';\n    function pass() {\n      var list = rows();\n      if (!list.length) {\n        /* No rows: the drawer is closed or loading. Forget the signature, so the rows drawn next\n         * are a change even when they are the same lines. */\n        lastSig = '';\n        return;\n      }\n      paint(list);\n      var sig = list.map(function (row) { return row.id + '@' + rowQty(row); }).sort().join('|');\n      if (sig === lastSig) return;\n      lastSig = sig;\n      if (list.some(unknownRow)) schedule();\n    }\n    var queued = false;\n    function onMutate() {\n      if (queued) return;\n      queued = true;\n      window.requestAnimationFrame(function () {\n        queued = false;\n        pass();\n      });\n    }\n    /* Its own writes are the mark attribute, which this observer does not watch: it cannot feed itself. */\n    new MutationObserver(onMutate).observe(document.documentElement, {\n      childList: true,\n      subtree: true,\n      attributes: true,\n      attributeFilter: ['id']\n    });\n    pass();\n    if (document.readyState !== 'complete') {\n      document.addEventListener('DOMContentLoaded', pass, { once: true });\n      window.addEventListener('load', pass, { once: true });\n    }\n\n    /* For a console check on the live theme: the one-time reward line keys this page knows (the rows\n     * it marks). */\n    window.egRewardCart = {\n      rewardKeys: function () { return Object.keys(gifted); }\n    };\n  } catch (error) {\n    if (window.console) console.warn('[eg-reward-cart] not started', error);\n  }\n})();\n"],
  "mappings": "CAyDC,UAAY,CACX,aACA,GAAI,CAkBF,IAAS,QAAT,SAAiB,UAAW,CAC1B,OAAO,OAAO,OAAO,aAAa,SAAS,GAAK,EAAE,EAC/C,MAAM,GAAG,EACT,IAAI,SAAU,IAAK,CAAE,OAAO,IAAI,KAAK,EAAE,YAAY,CAAG,CAAC,EACvD,OAAO,OAAO,CACnB,EAOS,KAAT,UAAgB,CACd,OAAQ,OAAO,SAAW,OAAO,QAAQ,QAAU,OAAO,QAAQ,OAAO,MAAS,GACpF,EACS,KAAT,UAAgB,CACd,OAAO,MAAM,UAAU,MAAM,KAAK,SAAS,iBAAiB,GAAG,CAAC,CAClE,EACS,OAAT,SAAgB,IAAK,CACnB,IAAI,MAAQ,OAAO,IAAI,IAAM,EAAE,EAAE,MAAM,GAAG,EAC1C,OAAO,MAAQ,MAAM,CAAC,EAAE,YAAY,EAAI,EAC1C,EACS,OAAT,SAAgB,IAAK,CACnB,IAAI,MAAQ,IAAI,cAAc,gCAAgC,EAC9D,OAAO,MAAQ,OAAO,MAAM,KAAK,EAAI,EACvC,EAES,WAAT,SAAoB,IAAK,CACvB,IAAI,IAAM,OAAO,GAAG,EACpB,MAAO,CAAC,CAAC,KAAO,CAAC,MAAM,GAAG,IAAM,MAAM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