{
  "version": 3,
  "sources": ["/cdn/shop/t/261/assets/btk-style-previews.js?cb=3"],
  "sourcesContent": ["/**\n * btk-style-previews.js - per-style (colour \u2192 image) lookup, fetched on demand\n * ----------------------------------------------------------------\n *   window.BTKStylePreviewsReady(styleHandle) -> Promise (loads that style)\n *   window.BTKStylePreviewFor(styleHandle, colourHandle) -> {p,d,a} | null\n *\n * WHY (measured 2026-08-17): /pages/kitchens returned HTTP 500 after ~3.2s on\n * live AND staging. The cause was this imagery being built into the page:\n * every style x every colour preview, three image_url calls each \u2014 ~2,100\n * calls across 66 styles and ~703 previews, before a byte was sent.\n *\n * Two dead ends worth recording, so nobody retries them:\n *   1. Moving the whole map to /cart?view=stylepreviews just relocated the\n *      work; that endpoint 500'd at ~3.2s in the same way.\n *   2. Paginating it with ?page= did nothing \u2014 the cart route ignores the page\n *      parameter, so every page returned the same first 8 styles.\n *\n * So it is fetched ONE STYLE AT A TIME from\n * /collections/<units-collection-handle>?view=stylepreviews (~54 image_url\n * calls, well inside the timeout), and only for styles whose swatches the\n * shopper actually clicks. Cached per style for the session.\n *\n * The collection handle comes from window.BTKStyleData, which sections/\n * header.liquid still emits on every page for exactly this kind of lookup.\n */\n(function () {\n  const CACHE_PREFIX = 'btk_style_previews_v2:';\n  const inflight = {};\n\n  window.BTKStylePreviews = window.BTKStylePreviews || {};\n\n  function collectionHandleFor(styleHandle) {\n    const d = window.BTKStyleData;\n    return (d && d[styleHandle] && d[styleHandle].collectionHandle) || null;\n  }\n\n  function fetchStyle(styleHandle) {\n    const handle = collectionHandleFor(styleHandle);\n    if (!handle) return Promise.resolve(null);\n    const url = '/collections/' + encodeURIComponent(handle) + '?view=stylepreviews';\n    return fetch(url, { credentials: 'same-origin' })\n      .then(function (r) {\n        if (!r.ok) throw new Error('style previews ' + r.status + ' for ' + styleHandle);\n        return r.text();\n      })\n      .then(function (text) {\n        // Sandbox-eval: the endpoint sets its own global and must not reach\n        // anything else on the page.\n        const sandbox = {};\n        try { (new Function('window', text))(sandbox); } catch (e) { return null; }\n        const map = sandbox.BTKStylePreviews;\n        return (map && map[styleHandle]) || null;\n      });\n  }\n\n  window.BTKStylePreviewsReady = function ensureStylePreviews(styleHandle) {\n    if (!styleHandle) return Promise.resolve();\n    if (window.BTKStylePreviews[styleHandle]) return Promise.resolve();\n    if (inflight[styleHandle]) return inflight[styleHandle];\n\n    const key = CACHE_PREFIX + styleHandle;\n    let cached = null;\n    try { cached = JSON.parse(sessionStorage.getItem(key) || 'null'); } catch (e) {}\n    if (cached) {\n      window.BTKStylePreviews[styleHandle] = cached;\n      return Promise.resolve();\n    }\n\n    inflight[styleHandle] = fetchStyle(styleHandle)\n      .then(function (colours) {\n        if (colours) {\n          window.BTKStylePreviews[styleHandle] = colours;\n          try { sessionStorage.setItem(key, JSON.stringify(colours)); } catch (e) {}\n          try {\n            document.dispatchEvent(new CustomEvent('btk:style-previews-ready', {\n              detail: { style: styleHandle }\n            }));\n          } catch (e) {}\n        }\n      })\n      .catch(function (e) {\n        // Decorative: a failure means a swatch click does not change the photo,\n        // never a broken page.\n        console.warn('[BTK] style previews unavailable:', e);\n      })\n      .then(function () { delete inflight[styleHandle]; });\n\n    return inflight[styleHandle];\n  };\n\n  // Synchronous lookup for the common (already-warmed) case. Returns null\n  // before the fetch lands; every caller tolerates a missing image.\n  window.BTKStylePreviewFor = function (styleHandle, colourHandle) {\n    if (!styleHandle || !colourHandle) return null;\n    const s = window.BTKStylePreviews[styleHandle];\n    return (s && s[colourHandle]) || null;\n  };\n})();\n"],
  "mappings": "CAyBC,UAAY,CACX,MAAM,aAAe,yBACf,SAAW,CAAC,EAElB,OAAO,iBAAmB,OAAO,kBAAoB,CAAC,EAEtD,SAAS,oBAAoB,YAAa,CACxC,MAAM,EAAI,OAAO,aACjB,OAAQ,GAAK,EAAE,WAAW,GAAK,EAAE,WAAW,EAAE,kBAAqB,IACrE,CAEA,SAAS,WAAW,YAAa,CAC/B,MAAM,OAAS,oBAAoB,WAAW,EAC9C,GAAI,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