{
  "version": 3,
  "sources": ["/cdn/shop/t/68/assets/cart-drawer.js?cb=1791266024"],
  "sourcesContent": ["import { Component } from '@theme/component';\nimport { StandardEvents } from '@shopify/events';\nimport { DrawerOpenEvent } from '@theme/theme-drawer';\nimport { ThemeEvents } from '@theme/events';\n\n/**\n * A custom element that manages cart drawer behavior within a `<theme-drawer>`.\n *\n * Dialog lifecycle (open/close, squeeze, history, animations) is owned by `<theme-drawer>`.\n * The `cart:view` event is auto-dispatched by `CartItemsComponent` via the\n * `view-event-trigger=\"dialog\"` attribute (see `snippets/cart-items-component.liquid`).\n * Cart count announcements are owned by `<header-actions>`.\n * This component handles the remaining cart-specific concerns: auto-open on add-to-cart,\n * sticky summary layout, and the installments CTA close-on-click.\n *\n * @extends {Component}\n */\nclass CartDrawerComponent extends Component {\n  /** @type {number} */\n  #summaryThreshold = 0.5;\n\n  /** @type {import('@theme/theme-drawer').ThemeDrawer | null} */\n  get #themeDrawer() {\n    return /** @type {import('@theme/theme-drawer').ThemeDrawer | null} */ (this.closest('theme-drawer'));\n  }\n\n  /** @type {HTMLDialogElement | null} */\n  get #dialog() {\n    return this.closest('dialog');\n  }\n\n  connectedCallback() {\n    super.connectedCallback();\n    document.addEventListener(StandardEvents.cartLinesUpdate, this.#handleCartLinesUpdate);\n    this.#themeDrawer?.addEventListener(DrawerOpenEvent.eventName, this.#handleDrawerOpen);\n    this.addEventListener(ThemeEvents.cartSectionRestored, this.#handleCartSectionRestored);\n\n    // The restore path sets [open] before this module loads, so the\n    // theme-drawer:open event will have already fired. Use the attribute\n    // check so this works even before <theme-drawer> upgrades.\n    if (this.#themeDrawer?.hasAttribute('open')) {\n      this.#handleDrawerOpen();\n    }\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    document.removeEventListener(StandardEvents.cartLinesUpdate, this.#handleCartLinesUpdate);\n    this.#themeDrawer?.removeEventListener(DrawerOpenEvent.eventName, this.#handleDrawerOpen);\n    this.removeEventListener(ThemeEvents.cartSectionRestored, this.#handleCartSectionRestored);\n  }\n\n  /**\n   * Recomputes the sticky summary after a back/forward cache restore re-renders the cart items.\n   *\n   * On viewports at or above 990px an open drawer survives a navigation and is reopened during\n   * parsing (see the restore script in `snippets/theme-drawer.liquid`), so no open event fires\n   * on the way back and the measurement taken before the shopper left is the one still applied.\n   * An empty drawer measured as unpinned would keep the checkout CTA scrolling away once the\n   * restore fills it with line items.\n   */\n  #handleCartSectionRestored = () => {\n    requestAnimationFrame(() => this.#updateStickyState());\n  };\n\n  /**\n   * Handles the theme-drawer opening \u2014 updates sticky state and wires up the installments CTA.\n   */\n  #handleDrawerOpen = () => {\n    this.#updateStickyState();\n\n    // Close cart drawer when installments CTA is clicked to avoid overlapping dialogs.\n    // Re-queried on every open so it survives cart content re-renders that\n    // replace the shopify-payment-terms shadow root.\n    customElements.whenDefined('shopify-payment-terms').then(() => {\n      const cta = this.querySelector('shopify-payment-terms')?.shadowRoot?.querySelector('#shopify-installments-cta');\n      cta?.addEventListener('click', () => this.#themeDrawer?.close(), { once: true });\n    });\n  };\n\n  /**\n   * @param {import('@shopify/events').CartLinesUpdateEvent} event\n   */\n  #handleCartLinesUpdate = (event) => {\n    const shouldAutoOpen = this.hasAttribute('auto-open') && event.action === 'add' && !this.#themeDrawer?.isOpen;\n\n    // When the event originates inside an open MODAL <dialog> (e.g. quick-add),\n    // defer the auto-open until that dialog's native `close` fires so its focus\n    // restoration runs first \u2014 otherwise we'd capture the wrong\n    // `#previouslyFocused`. Non-modal dialogs (e.g. the hotspot preview) don't\n    // close on add and don't move focus, so `:modal` excludes them.\n    const sourceModal = /** @type {HTMLDialogElement | null} */ (\n      event.target instanceof Element ? event.target.closest('dialog:modal') : null\n    );\n\n    if (shouldAutoOpen && !sourceModal && !this.#isCartEmpty()) {\n      this.#themeDrawer?.open();\n    }\n\n    event.promise\n      ?.then(({ detail }) => {\n        const settle = () => requestAnimationFrame(() => this.#updateStickyState());\n\n        if (!shouldAutoOpen || detail?.didError) {\n          settle();\n          return;\n        }\n\n        const openAndSettle = () => {\n          if (!this.#themeDrawer?.isOpen) this.#themeDrawer?.open();\n          settle();\n        };\n\n        if (sourceModal?.open) {\n          sourceModal.addEventListener('close', openAndSettle, { once: true });\n        } else {\n          openAndSettle();\n        }\n      })\n      .catch((error) => {\n        if (error?.name !== 'AbortError') console.warn('[cart-drawer] Event promise rejected:', error);\n      });\n  };\n\n  #isCartEmpty() {\n    return Boolean(this.querySelector('.cart-drawer--empty'));\n  }\n\n  #updateStickyState() {\n    const dialog = this.#dialog;\n    if (!dialog) return;\n\n    // Refs do not cross nested `*-component` boundaries (e.g., `cart-items-component`), so we query within the dialog.\n    const content = dialog.querySelector('.cart-drawer__content');\n    const summary = dialog.querySelector('.cart-drawer__summary');\n\n    if (!content || !summary) {\n      // Ensure the dialog doesn't get stuck in \"unsticky\" mode when summary disappears (e.g., empty cart).\n      dialog.setAttribute('cart-summary-sticky', 'false');\n      return;\n    }\n\n    const drawerHeight = dialog.getBoundingClientRect().height;\n    const summaryHeight = summary.getBoundingClientRect().height;\n    const ratio = summaryHeight / drawerHeight;\n    dialog.setAttribute('cart-summary-sticky', ratio > this.#summaryThreshold ? 'false' : 'true');\n  }\n}\n\nif (!customElements.get('cart-drawer-component')) {\n  customElements.define('cart-drawer-component', CartDrawerComponent);\n}\n"],
  "mappings": "AAAA,OAAS,cAAiB,mBAC1B,OAAS,mBAAsB,kBAC/B,OAAS,oBAAuB,sBAChC,OAAS,gBAAmB,gBAc5B,MAAM,4BAA4B,SAAU,CAE1C,kBAAoB,GAGpB,GAAI,cAAe,CACjB,OAAwE,KAAK,QAAQ,cAAc,CACrG,CAGA,GAAI,SAAU,CACZ,OAAO,KAAK,QAAQ,QAAQ,CAC9B,CAEA,mBAAoB,CAClB,MAAM,kBAAkB,EACxB,SAAS,iBAAiB,eAAe,gBAAiB,KAAK,sBAAsB,EACrF,KAAK,cAAc,iBAAiB,gBAAgB,UAAW,KAAK,iBAAiB,EACrF,KAAK,iBAAiB,YAAY,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