{
  "version": 3,
  "sources": ["/cdn/shop/t/2/assets/cart-drawer.js?x=1791547530626"],
  "sourcesContent": ["import { DialogComponent, DialogOpenEvent, DialogCloseEvent } from '@theme/dialog';\nimport { CartAddEvent } from '@theme/events';\nimport { isMobileBreakpoint } from '@theme/utilities';\n\n/**\n * A custom element that manages a cart drawer.\n *\n * @typedef {object} Refs\n * @property {HTMLDialogElement} dialog - The dialog element.\n * @property {HTMLElement} [liveRegion] - The live region for cart announcements when dialog is open.\n *\n * @extends {DialogComponent}\n */\nclass CartDrawerComponent extends DialogComponent {\n  /** @type {number} */\n  #summaryThreshold = 0.5;\n\n  /** @type {AbortController | null} */\n  #historyAbortController = null;\n\n  connectedCallback() {\n    super.connectedCallback();\n    document.addEventListener(CartAddEvent.eventName, this.#handleCartAdd);\n    this.addEventListener(DialogOpenEvent.eventName, this.#updateStickyState);\n    this.addEventListener(DialogOpenEvent.eventName, this.#handleHistoryOpen);\n    this.addEventListener(DialogCloseEvent.eventName, this.#handleHistoryClose);\n\n    if (history.state?.cartDrawerOpen) {\n      history.replaceState(null, '');\n    }\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    document.removeEventListener(CartAddEvent.eventName, this.#handleCartAdd);\n    this.removeEventListener(DialogOpenEvent.eventName, this.#updateStickyState);\n    this.removeEventListener(DialogOpenEvent.eventName, this.#handleHistoryOpen);\n    this.removeEventListener(DialogCloseEvent.eventName, this.#handleHistoryClose);\n    this.#historyAbortController?.abort();\n  }\n\n  #handleHistoryOpen = () => {\n    if (!isMobileBreakpoint()) return;\n\n    if (!history.state?.cartDrawerOpen) {\n      history.pushState({ cartDrawerOpen: true }, '');\n    }\n\n    this.#historyAbortController = new AbortController();\n    window.addEventListener('popstate', this.#handlePopState, { signal: this.#historyAbortController.signal });\n  };\n\n  #handleHistoryClose = () => {\n    this.#historyAbortController?.abort();\n    if (history.state?.cartDrawerOpen) {\n      history.back();\n    }\n  };\n\n  #handlePopState = async () => {\n    if (this.refs.dialog?.open) {\n      this.refs.dialog.style.setProperty('--dialog-drawer-closing-animation', 'none');\n      await this.closeDialog();\n      this.refs.dialog.style.removeProperty('--dialog-drawer-closing-animation');\n    }\n  };\n\n  /**\n   * Handles cart add events - opens drawer if auto-open and announces count when open.\n   * @param {CustomEvent<{ resource?: { item_count?: number } }>} event\n   */\n  #handleCartAdd = (event) => {\n    if (this.hasAttribute('auto-open')) {\n      this.showDialog();\n    }\n\n    this.#announceCartCount(event.detail.resource?.item_count);\n  };\n\n  /**\n   * Announces cart count to screen readers when dialog is open.\n   * @param {number | undefined} cartCount\n   */\n  #announceCartCount(cartCount) {\n    const liveRegion = /** @type {HTMLElement | undefined} */ (this.refs.liveRegion);\n    if (!this.refs.dialog?.open || !liveRegion || cartCount === undefined) return;\n\n    liveRegion.textContent = `${Theme.translations.cart_count}: ${cartCount}`;\n  }\n\n  open() {\n    this.showDialog();\n\n    /**\n     * Close cart drawer when installments CTA is clicked to avoid overlapping dialogs\n     */\n    customElements.whenDefined('shopify-payment-terms').then(() => {\n      const installmentsContent = document.querySelector('shopify-payment-terms')?.shadowRoot;\n      const cta = installmentsContent?.querySelector('#shopify-installments-cta');\n      cta?.addEventListener('click', this.closeDialog, { once: true });\n    });\n  }\n\n  close() {\n    this.closeDialog();\n  }\n\n  #updateStickyState() {\n    const { dialog } = /** @type {Refs} */ (this.refs);\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// ORIK: close cart drawer when Shiprocket checkout is tapped\ndocument.addEventListener('click', (e) => { const btn = e.target.closest('.shiprocket-headless .sr-headless-checkout'); if (!btn) return; const drawer = btn.closest('cart-drawer-component'); if (drawer && typeof drawer.close === 'function') setTimeout(() => drawer.close(), 50); }, true);\n"],
  "mappings": "AAAA,OAAS,gBAAiB,gBAAiB,qBAAwB,gBACnE,OAAS,iBAAoB,gBAC7B,OAAS,uBAA0B,mBAWnC,MAAM,4BAA4B,eAAgB,CAEhD,kBAAoB,GAGpB,wBAA0B,KAE1B,mBAAoB,CAClB,MAAM,kBAAkB,EACxB,SAAS,iBAAiB,aAAa,UAAW,KAAK,cAAc,EACrE,KAAK,iBAAiB,gBAAgB,UAAW,KAAK,kBAAkB,EACxE,KAAK,iBAAiB,gBAAgB,UAAW,KAAK,kBAAkB,EACxE,KAAK,iBAAiB,iBAAiB,UAAW,KAAK,mBAAmB,EAEtE,QAAQ,OAAO,gBACjB,QAAQ,aAAa,KAAM,EAAE,CAEjC,CAEA,sBAAuB,CACrB,MAAM,qBAAqB,EAC3B,SAAS,oBAAoB,aAAa,UAAW,KAAK,cAAc,EACxE,KAAK,oBAAoB,gBAAgB,UAAW,KAAK,kBAAkB,EAC3E,KAAK,oBAAoB,gBAAgB,UAAW,KAAK,kBAAkB,EAC3E,KAAK,oBAAoB,iBAAiB,UAAW,KAAK,mBAAmB,EAC7E,KAAK,yBAAyB,MAAM,CACtC,CAEA,mBAAqB,IAAM,CACpB,mBAAmB,IAEnB,QAAQ,OAAO,gBAClB,QAAQ,UAAU,CAAE,eAAgB,EAAK,EAAG,EAAE,EAGhD,KAAK,wBAA0B,IAAI,gBACnC,OAAO,iBAAiB,WAAY,KAAK,gBAAiB,CAAE,OAAQ,KAAK,wBAAwB,MAAO,CAAC,EAC3G,EAEA,oBAAsB,IAAM,CAC1B,KAAK,yBA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