{
  "version": 3,
  "sources": ["/cdn/shop/t/87/assets/hk-b4b-order.js?r=step9"],
  "sourcesContent": ["/* ------------------------------------------------------------------\n   Hanakini B4B order keeper (TEST step 9, Oct 2026)\n\n   Why: with a size filter on, B4B adds some colorways to the END of the\n   grid instead of their spot in your B4B sort list. This happens when that\n   colorway's spot is pinned to a different size (e.g. Tavares Lagoon is\n   pinned to S, so with L selected B4B shows it last).\n\n   What this does, ONLY while a filter is active:\n   - The moment B4B adds such a card (before the screen repaints), it is\n     moved to where that colorway sits in your B4B sort list.\n   - Each time B4B loads another batch it pushes those cards to the end\n     again; they are put back in their spot in the same instant, so the\n     shopper never sees them move.\n   - If the safety net already placed a copy there, B4B's card takes its\n     place (never two of the same).\n   - The shopper's scroll position is held, so nothing on screen jumps.\n   - Only moves B4B's own cards. Never adds, hides or duplicates anything.\n   - Colorways that are not on the B4B list stay where B4B puts them.\n   Safeguards: each card is put in place at most 10 times; a move that would\n   change nothing is skipped; if it ever tries more than 40 moves within\n   2 seconds it switches itself off and leaves the page as B4B drew it.\n   With no filter on, it does nothing.\n   Deleting the one script line in snippets/shop-your-size-styles.liquid\n   turns it off completely.\n------------------------------------------------------------------- */\n(function () {\n  if (window.__hkB4bOrder) return;\n  window.__hkB4bOrder = true;\n\n  var match = window.location.pathname.match(/\\/collections\\/([^\\/?#]+)/);\n  if (!match || window.location.pathname.indexOf('/products/') > -1) return;\n  var collectionHandle = match[1];\n\n  var MAX_PER_CARD = 10;\n  var disabled = false;\n  var moveTimes = [];\n\n  function filterActive() {\n    return /[?&]filter\\./.test(window.location.search);\n  }\n\n  function getGrid() {\n    return document.querySelector('#CollectionAjaxContent .grid--uniform');\n  }\n\n  // Your B4B sort list: [{ vid, color, i }]\n  var sorting = null;\n  function getSorting() {\n    if (sorting) return sorting;\n    var cols = window.VariableCollections || [];\n    var col = null;\n    for (var c = 0; c < cols.length; c++) if (cols[c].handle === collectionHandle) { col = cols[c]; break; }\n    if (!col || !col.manualSorting || !col.manualSorting.length) return null;\n    sorting = col.manualSorting.map(function (e, i) {\n      var colorOpt = (e.options || []).filter(function (o) { return /colou?r/i.test(o.name); })[0];\n      return { vid: String(e.vid), color: colorOpt ? String(colorOpt.value).toUpperCase() : '', i: i };\n    });\n    return sorting;\n  }\n\n  function cardColor(card) {\n    var c = card.getAttribute('data-b4b-color');\n    if (c) return String(c).toUpperCase();\n    var key = card.getAttribute('data-hk-key');\n    if (key && key.indexOf('|') > -1) return key.split('|')[1];\n    return '';\n  }\n\n  function cardVariantIds(card) {\n    var el = card.querySelector('script[data-selected-variant]');\n    if (!el) return null;\n    var text = el.textContent;\n    if (card.__hkOrderSrc === text) return card.__hkOrderIds;\n    var ids = null;\n    try {\n      var list = JSON.parse(text);\n      if (Array.isArray(list)) { ids = {}; list.forEach(function (v) { ids[String(v.id)] = true; }); }\n    } catch (e) {}\n    card.__hkOrderSrc = text;\n    card.__hkOrderIds = ids;\n    return ids;\n  }\n\n  // Where this card's colorway first appears in your B4B list (null = not on the list)\n  function cardPos(card, list) {\n    var color = cardColor(card);\n    if (!color) return null;\n    var ids = cardVariantIds(card);\n    if (!ids) return null;\n    for (var k = 0; k < list.length; k++) {\n      var e = list[k];\n      if (ids[e.vid] && (!e.color || e.color === color)) return e.i;\n    }\n    return null;\n  }\n\n  function cardHandle(card) {\n    var a = card.querySelector('a[href*=\"/products/\"]');\n    if (!a) return '';\n    return ((a.getAttribute('href') || '').split('/products/')[1] || '').split('?')[0].split('#')[0];\n  }\n\n  function tooManyMoves(count) {\n    var now = Date.now();\n    for (var t = 0; t < count; t++) moveTimes.push(now);\n    moveTimes = moveTimes.filter(function (x) { return now - x < 2000; });\n    if (moveTimes.length > 40) { disabled = true; return true; }\n    return false;\n  }\n\n  var busy = false;\n  function fix() {\n    if (disabled || busy || !filterActive()) return;\n    var grid = getGrid();\n    var list = getSorting();\n    if (!grid || !list) return;\n\n    var cards = [];\n    for (var n = 0; n < grid.children.length; n++) {\n      var el = grid.children[n];\n      if (el.classList && el.classList.contains('grid-product') && el.offsetParent) cards.push(el);\n    }\n\n    // B4B cards sitting after a card that comes later in your list = out of place\n    var maxSoFar = -1;\n    var movers = [];\n    cards.forEach(function (card) {\n      var pos = cardPos(card, list);\n      card.__hkPos = pos;\n      if (pos == null) return;\n      if (pos < maxSoFar && card.classList.contains('variable-products') && (card.__hkMoves || 0) < MAX_PER_CARD) movers.push(card);\n      else if (pos > maxSoFar) maxSoFar = pos;\n    });\n    if (!movers.length) return;\n    if (tooManyMoves(movers.length)) return;\n\n    busy = true;\n    try {\n      // Remember where the shopper is looking, so the view doesn't jump\n      var anchor = null, anchorTop = 0;\n      for (var a = 0; a < cards.length; a++) {\n        if (movers.indexOf(cards[a]) > -1) continue;\n        var r = cards[a].getBoundingClientRect();\n        if (r.bottom > 0) { anchor = cards[a]; anchorTop = r.top; break; }\n      }\n\n      movers.forEach(function (card) {\n        card.__hkMoves = (card.__hkMoves || 0) + 1;\n        var pos = card.__hkPos;\n        var color = cardColor(card);\n        var handle = cardHandle(card);\n        // A copy the safety net placed for this colorway? Take its exact spot.\n        var copy = grid.querySelector('.grid-product.hk-restored[data-hk-key=\"' + (handle + '|' + color).replace(/\"/g, '\\\\\"') + '\"]');\n        if (copy && copy !== card) {\n          if (card.nextElementSibling !== copy) grid.insertBefore(card, copy);\n          copy.remove();\n          return;\n        }\n        // Otherwise: just before the first card that comes later in your list\n        var before = null, bestPos = Infinity;\n        for (var b = 0; b < grid.children.length; b++) {\n          var other = grid.children[b];\n          if (other === card || movers.indexOf(other) > -1 || !other.classList || !other.classList.contains('grid-product') || !other.offsetParent) continue;\n          var op = other.__hkPos !== undefined ? other.__hkPos : cardPos(other, list);\n          if (op != null && op > pos && op < bestPos) { bestPos = op; before = other; }\n        }\n        if (before && card.nextElementSibling !== before) grid.insertBefore(card, before);\n      });\n\n      if (anchor) {\n        var delta = anchor.getBoundingClientRect().top - anchorTop;\n        if (Math.abs(delta) > 0.5) window.scrollBy(0, delta);\n      }\n      if (typeof window.hkRefreshCards === 'function') window.hkRefreshCards();\n    } catch (e) {\n      disabled = true; /* never break the page */\n    }\n    busy = false;\n  }\n\n  // Runs right after B4B changes the grid, before the screen repaints\n  if (window.MutationObserver) {\n    var target = document.getElementById('CollectionAjaxContent') || document.body;\n    new MutationObserver(fix).observe(target, { childList: true, subtree: true });\n  }\n  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', fix);\n  else fix();\n})();\n"],
  "mappings": "CA0BC,UAAY,CACX,GAAI,OAAO,aAAc,OACzB,OAAO,aAAe,GAEtB,IAAI,MAAQ,OAAO,SAAS,SAAS,MAAM,2BAA2B,EACtE,GAAI,CAAC,OAAS,OAAO,SAAS,SAAS,QAAQ,YAAY,EAAI,GAAI,OACnE,IAAI,iBAAmB,MAAM,CAAC,EAE1B,aAAe,GACf,SAAW,GACX,UAAY,CAAC,EAEjB,SAAS,cAAe,CACtB,MAAO,eAAe,KAAK,OAAO,SAAS,MAAM,CACnD,CAEA,SAAS,SAAU,CACjB,OAAO,SAAS,cAAc,uCAAuC,CACvE,CAGA,IAAI,QAAU,KACd,SAAS,YAAa,CACpB,GAAI,QAAS,OAAO,QAGpB,QAFI,KAAO,OAAO,qBAAuB,CAAC,EACtC,IAAM,KACD,EAAI,EAAG,EAAI,KAAK,OAAQ,IAAK,GAAI,KAAK,CAAC,EAAE,SAAW,iBAAkB,CAAE,IAAM,KAAK,CAAC,EAAG,KAAO,CACvG,MAAI,CAAC,KAAO,CAAC,IAAI,eAAiB,CAAC,IAAI,cAAc,OAAe,MACpE,QAAU,IAAI,cAAc,IAAI,SAAU,EAAG,EAAG,CAC9C,IAAI,UAAY,EAAE,SAAW,CAAC,GAAG,OAAO,SAAU,EAAG,CAAE,MAAO,WAAW,KAAK,EAAE,IAAI,CAAG,CAAC,EAAE,CAAC,EAC3F,MAAO,CAAE,IAAK,OAAO,EAAE,GAAG,EAAG,MAAO,SAAW,OAAO,SAAS,KAAK,EAAE,YAAY,EAAI,GAAI,EAAG,CAAE,CACjG,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