{
  "version": 3,
  "sources": ["/cdn/shop/t/82/assets/stuburt-bf-ladder.js?cb=1795643457"],
  "sourcesContent": ["/**\n * stuburt-bf-ladder: the Black Friday 2026 spend ladder bar (snippets/stuburt-bf-ladder-pill.liquid).\n *\n * The idea is Oscar Jacobson's bottom ladder bar (oj-prod, sections/oj-bf-dock.liquid), redrawn\n * for Stuburt: a low frosted-white card with the three savings over a thin line, a dot per tier\n * and the spend under each dot; reached tiers turn navy and their dot gets a tick. This script\n * only moves the line and switches the tiers on. Every tier has an equal, centred column, so the\n * dots sit evenly although the steps (\u00A375, \u00A3100, \u00A3150) are not.\n * The full-price subtotal comes from /cart?view=bf-ladder, which applies the same scope as the\n * discounts themselves, so the bar never counts waterproofs or reduced items.\n *\n * While the bar shows it is the add-to-cart feedback, so it switches the cart sheet's automatic\n * open off (see #quietCart); the cart icon still opens it.\n *\n * LIVE since 25 Nov 23:35 (operator): layout/theme.liquid renders it sitewide with data-live. The\n * preview section (sections/stuburt-bf-ladder.liquid, on templates/page.bf-preview.json) sets\n * data-preview instead, where dates are ignored. With data-live it follows the sale's clock:\n *   before Thu 26 Nov 00:00 UK      hidden\n *   Thursday                         signed-in subscribers get the ladder (decided on the server:\n *                                    logged in with marketing on); everyone else gets one line,\n *                                    \"Sign in to unlock\", linking to the sign-in\n *   Fri 27 Nov to Tue 1 Dec 00:00    everyone\n * With neither attribute the element does nothing at all.\n *\n * It lifts itself above any bar fixed to the bottom of the screen (PDP sticky add, pack page price\n * bar) instead of covering it, and steps aside while the cookie card is up.\n */\n\nconst money = (pence) => {\n  const pounds = pence / 100;\n  return `\u00A3${pence % 100 ? pounds.toFixed(2) : pounds}`;\n};\n\nclass StuburtBfLadder extends HTMLElement {\n  #data = null;\n  #abort = null;\n  #timer = 0;\n  #debounce = 0;\n  #member = false;\n  #preview = false;\n  #previewGuest = false; // the preview template with ?bar=guest shows the sign-up prompt\n  #tried = 0; // when the ladder's numbers were last asked for\n  #level = 0;\n  #muted = false; // this element took the cart drawer's auto-open off\n\n  connectedCallback() {\n    this.#preview = this.hasAttribute('data-preview');\n    if (!this.#preview && !this.hasAttribute('data-live')) return;\n\n    const at = (name) => (parseInt(this.dataset[name], 10) || 0) * 1000;\n    this.times = { early: at('early'), open: at('open'), end: at('end') };\n    this.tiers = (this.dataset.tiers || '7500:20,10000:30,15000:40')\n      .split(',')\n      .map((pair) => pair.split(':').map(Number));\n    this.sr = this.querySelector('[data-sr]');\n    this.card = this.querySelector('.stb-ladder__card');\n    this.steps = [...this.querySelectorAll('[data-step]')];\n\n    this.#member = this.hasAttribute('data-member');\n    try {\n      this.#previewGuest = new URL(window.location.href).searchParams.get('bar') === 'guest';\n    } catch {\n      /* no URL: the ladder preview */\n    }\n\n    this.#abort = new AbortController();\n    const signal = this.#abort.signal;\n    document.addEventListener('cart:update', () => this.#refreshSoon(), { signal });\n    document.addEventListener(\n      'visibilitychange',\n      () => {\n        if (!document.hidden) this.#refreshSoon();\n      },\n      { signal }\n    );\n    window.addEventListener('scroll', () => this.#lift(), { passive: true, signal });\n    window.addEventListener('resize', () => this.#lift(), { signal });\n    // Cheap tick: catches midnight without a reload and sticky bars sliding in.\n    this.#timer = window.setInterval(() => {\n      this.#gate();\n      this.#lift();\n    }, 1000);\n\n    this.#refresh();\n  }\n\n  disconnectedCallback() {\n    this.#abort?.abort();\n    window.clearInterval(this.#timer);\n    window.clearTimeout(this.#debounce);\n    this.#quietCart(false);\n  }\n\n  /**\n   * 'off'    outside the sale: nothing shows.\n   * 'guest'  Thursday, not a subscriber: the sign-up prompt, no ladder (operator, 25 Nov: \"this\n   *          is subscribers only ... for non subscribers pill says email signup\").\n   * 'ladder' a subscriber on Thursday, everyone from Friday.\n   */\n  #state() {\n    if (this.#preview) return this.#previewGuest ? 'guest' : 'ladder';\n    const now = Date.now();\n    const { early, open, end } = this.times;\n    if (now < early || now >= end) return 'off';\n    if (now >= open || this.#isMember()) return 'ladder';\n    return 'guest';\n  }\n\n  // A bundle page is any page built on one of the kit sections (each has its own root element; the\n  // pack stage's sign-in or ended notice counts too), or a bundle product page, which the server\n  // marks with data-bundle-page. The packs index only lists bundles, so the bar stays there.\n  #bundlePage() {\n    if (this.hasAttribute('data-bundle-page')) return true;\n    return !!document.querySelector(\n      'stuburt-pack-stage, .sps-over, stuburt-suit, stuburt-wetround, stuburt-pick-pack, stuburt-headtotoe, stuburt-layers'\n    );\n  }\n\n  // A member is whoever the SERVER says is one: signed in with marketing on (data-member). The\n  // early-access discounts are limited to signed-in subscribers at checkout, so a localStorage\n  // flag or ?early=1 must never show the ladder: it would promise prices checkout will not give.\n  #isMember() {\n    return this.#member;\n  }\n\n  #gate() {\n    const state = this.#state();\n    const consent = document.documentElement.classList.contains('stb-consent-open');\n    // The bar no longer steps aside when a bundle's discount is on the basket (operator, 26 Nov:\n    // it \"just disappears randomly after I bought a bundle\"). Bundle lines are left out of the\n    // count instead (templates/cart.bf-ladder.liquid), so the line shows the rest of the basket.\n    let on = false;\n    if (state === 'guest') on = !consent;\n    else if (state === 'ladder') on = this.#data !== null && !consent;\n    // Bundle pages (operator, 26 Nov): no bar there at all. Bundles are outside the spend offers,\n    // and with the bar gone the cart sheet opens after an add as it always did on those pages.\n    if (this.#bundlePage()) on = false;\n\n    if (this.dataset.state !== state) this.dataset.state = state;\n    // The whole bar is one link: to the sign-in for a guest, to the deals otherwise.\n    const href = state === 'guest' ? this.dataset.guestHref : this.dataset.dealsHref;\n    if (this.card && href && this.card.getAttribute('href') !== href) this.card.setAttribute('href', href);\n    // The ladder just became this visitor's (midnight, or a sign-up) and there are no numbers\n    // yet: fetch them, at most every 30 seconds so a failing request is never hammered.\n    if (state === 'ladder' && this.#data === null && Date.now() - this.#tried > 30000) this.#refreshSoon();\n    // Only the ladder replaces the cart sheet as add-to-cart feedback; the sign-up prompt does not.\n    // Operator, 26 Nov (later): every add opens the cart again, bar or no bar. The bar no longer\n    // switches the cart sheet's automatic open off; this only undoes it if an older copy had.\n    this.#quietCart(false);\n    if (on === !this.hidden) return;\n    this.hidden = !on;\n  }\n\n  // While the bar shows, it is the add-to-cart feedback, so the cart sheet must not slide open\n  // over it (operator, 25 Nov). The drawer's `auto-open` attribute is the one switch for every\n  // automatic open (snippets/header-actions.liquid, assets/cart-drawer.js); the cart icon still\n  // opens it. Called every tick, so a re-rendered drawer is caught, and the attribute goes back\n  // the moment the bar steps aside.\n  #quietCart(on) {\n    const drawer = document.querySelector('cart-drawer-component');\n    if (!drawer) return;\n    if (!on && this.#muted) {\n      drawer.setAttribute('auto-open', '');\n      this.#muted = false;\n    }\n  }\n\n  #refreshSoon() {\n    window.clearTimeout(this.#debounce);\n    this.#debounce = window.setTimeout(() => this.#refresh(), 200);\n  }\n\n  async #refresh() {\n    if (this.#state() !== 'ladder') {\n      this.#gate();\n      return;\n    }\n    this.#tried = Date.now();\n    try {\n      // No \"Accept: application/json\" here. With it Shopify skips the bf-ladder view and answers\n      // /cart with its own cart JSON, which has no `eligible`, so the line sat at zero for every\n      // basket (found 26 Nov, an hour after go-live). The view is rendered as an ordinary page.\n      const res = await fetch('/cart?view=bf-ladder', { cache: 'no-store' });\n      if (!res.ok) throw new Error(String(res.status));\n      const data = JSON.parse((await res.text()).trim());\n      // Anything without the view's own field is not the view: show nothing rather than a dead line.\n      if (typeof data.eligible !== 'number') throw new Error('not the ladder view');\n      this.#data = data;\n      this.#render();\n    } catch {\n      // No data, no bar: never show progress we could not check.\n      this.#data = null;\n    }\n    this.#gate();\n    this.#lift();\n  }\n\n  #render() {\n    const eligible = this.#data.eligible || 0;\n    const count = this.tiers.length;\n    const level = this.tiers.filter(([min]) => eligible >= min).length;\n    this.#level = level;\n\n    // Each tier's dot sits in the middle of its own equal column (1/6, 1/2, 5/6 of the line for\n    // three tiers), so the bar is symmetrical. The line runs from the dot behind to the dot ahead,\n    // and to the far end once the last tier is reached.\n    const stop = (index) => (2 * index + 1) / (2 * count);\n    let part = 1;\n    if (level < count) {\n      const from = level ? this.tiers[level - 1][0] : 0;\n      const to = this.tiers[level][0];\n      const start = level ? stop(level - 1) : 0;\n      part = start + ((eligible - from) / (to - from)) * (stop(level) - start);\n    }\n    const value = Math.min(1, Math.max(0, part)).toFixed(3);\n    if (this.style.getPropertyValue('--p') !== value) this.style.setProperty('--p', value);\n\n    this.steps.forEach((node) => node.classList.toggle('is-on', Number(node.dataset.step) <= level));\n\n    if (this.sr) {\n      if (level >= count) this.sr.textContent = `${this.tiers[count - 1][1]}% off reached.`;\n      else {\n        const [to, pct] = this.tiers[level];\n        const have = level ? `${this.tiers[level - 1][1]}% off reached. ` : '';\n        this.sr.textContent = `${have}${money(to - eligible)} more for ${pct}% off.`;\n      }\n    }\n  }\n\n  // Sit above whatever is fixed to the bottom of the screen at its centre (a sticky add bar, a\n  // pack price bar), never on top of it.\n  #lift() {\n    if (this.hidden) return;\n    const vh = window.innerHeight;\n    let lift = 0;\n    for (const el of document.elementsFromPoint(window.innerWidth / 2, vh - 4)) {\n      if (this.contains(el)) continue;\n      let node = el;\n      while (node && node !== document.body) {\n        const pos = getComputedStyle(node).position;\n        if (pos === 'fixed' || pos === 'sticky') {\n          const top = node.getBoundingClientRect().top;\n          if (top > vh * 0.5) lift = Math.max(lift, vh - top);\n          break;\n        }\n        node = node.parentElement;\n      }\n    }\n    const value = `${Math.round(lift)}px`;\n    if (this.style.getPropertyValue('--stb-ladder-lift') !== value) this.style.setProperty('--stb-ladder-lift', value);\n  }\n}\n\nif (!customElements.get('stuburt-bf-ladder')) customElements.define('stuburt-bf-ladder', StuburtBfLadder);\n"],
  "mappings": "AA4BA,MAAM,MAAS,OAAU,CACvB,MAAM,OAAS,MAAQ,IACvB,MAAO,OAAI,MAAQ,IAAM,OAAO,QAAQ,CAAC,EAAI,MAAM,EACrD,EAEA,MAAM,wBAAwB,WAAY,CACxC,MAAQ,KACR,OAAS,KACT,OAAS,EACT,UAAY,EACZ,QAAU,GACV,SAAW,GACX,cAAgB,GAChB,OAAS,EACT,OAAS,EACT,OAAS,GAET,mBAAoB,CAElB,GADA,KAAK,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