{
  "version": 3,
  "sources": ["/cdn/shop/t/8/assets/dialog.js?ddd=74105"],
  "sourcesContent": ["import { Component } from '@theme/component';\nimport { debounce, isClickedOutside, lockScroll, onAnimationEnd, unlockScroll } from '@theme/utilities';\nimport { getScrollTop, scrollTo } from '@theme/scroll-container';\n\n/**\n * A custom element that manages a dialog.\n *\n * @typedef {object} Refs\n * @property {HTMLDialogElement} dialog \u2013 The dialog element.\n *\n * @extends Component<Refs>\n */\nexport class DialogComponent extends Component {\n  requiredRefs = ['dialog'];\n\n  connectedCallback() {\n    super.connectedCallback();\n\n    if (this.minWidth || this.maxWidth) {\n      window.addEventListener('resize', this.#handleResize);\n    }\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    if (this.minWidth || this.maxWidth) {\n      window.removeEventListener('resize', this.#handleResize);\n    }\n    unlockScroll(this.refs.dialog);\n  }\n\n  #handleResize = debounce(() => {\n    const { minWidth, maxWidth } = this;\n\n    if (!minWidth && !maxWidth) return;\n\n    const windowWidth = window.innerWidth;\n    if (windowWidth < minWidth || windowWidth > maxWidth) {\n      this.closeDialog();\n    }\n  }, 50);\n\n  #previousScrollY = 0;\n\n  /**\n   * Shows the dialog.\n   */\n  showDialog() {\n    const { dialog } = this.refs;\n\n    if (dialog.open) return;\n\n    this.#previousScrollY = getScrollTop();\n\n    // Prevent layout thrashing by separating DOM reads from DOM writes\n    requestAnimationFrame(() => {\n      lockScroll(dialog);\n\n      dialog.showModal();\n      this.dispatchEvent(new DialogOpenEvent());\n\n      this.addEventListener('click', this.#handleClick);\n      this.addEventListener('keydown', this.#handleKeyDown);\n    });\n  }\n\n  /**\n   * Closes the dialog.\n   */\n  closeDialog = async () => {\n    const { dialog } = this.refs;\n\n    if (!dialog.open) return;\n\n    this.removeEventListener('click', this.#handleClick);\n    this.removeEventListener('keydown', this.#handleKeyDown);\n\n    // Force browser to restart animation by resetting it\n    // Temporarily remove any existing animation state\n    dialog.style.animation = 'none';\n\n    // Force a reflow\n    void dialog.offsetWidth;\n\n    // Now add the closing class and restore animation\n    dialog.classList.add('dialog-closing');\n    dialog.style.animation = '';\n\n    await onAnimationEnd(dialog, undefined, {\n      subtree: false,\n    });\n\n    unlockScroll(dialog);\n    scrollTo({ top: this.#previousScrollY, behavior: 'instant' });\n\n    dialog.close();\n    dialog.classList.remove('dialog-closing');\n\n    this.dispatchEvent(new DialogCloseEvent());\n  };\n\n  /**\n   * Toggles the dialog.\n   */\n  toggleDialog = () => {\n    if (this.refs.dialog.open) {\n      this.closeDialog();\n    } else {\n      this.showDialog();\n    }\n  };\n\n  /**\n   * Closes the dialog when the user clicks outside of it.\n   *\n   * @param {MouseEvent} event - The mouse event.\n   */\n  #handleClick(event) {\n    const { dialog } = this.refs;\n\n    if (isClickedOutside(event, dialog)) {\n      this.closeDialog();\n    }\n  }\n\n  /**\n   * Closes the dialog when the user presses the escape key.\n   *\n   * @param {KeyboardEvent} event - The keyboard event.\n   */\n  #handleKeyDown(event) {\n    if (event.key !== 'Escape') return;\n\n    event.preventDefault();\n    this.closeDialog();\n  }\n\n  /**\n   * Gets the minimum width of the dialog.\n   *\n   * @returns {number} The minimum width of the dialog.\n   */\n  get minWidth() {\n    return Number(this.getAttribute('dialog-active-min-width'));\n  }\n\n  /**\n   * Gets the maximum width of the dialog.\n   *\n   * @returns {number} The maximum width of the dialog.\n   */\n  get maxWidth() {\n    return Number(this.getAttribute('dialog-active-max-width'));\n  }\n}\n\nif (!customElements.get('dialog-component')) customElements.define('dialog-component', DialogComponent);\n\nexport class DialogOpenEvent extends CustomEvent {\n  constructor() {\n    super(DialogOpenEvent.eventName);\n  }\n\n  static eventName = 'dialog:open';\n}\n\nexport class DialogCloseEvent extends CustomEvent {\n  constructor() {\n    super(DialogCloseEvent.eventName);\n  }\n\n  static eventName = 'dialog:close';\n}\n\ndocument.addEventListener(\n  'toggle',\n  (event) => {\n    if (event.target instanceof HTMLDetailsElement) {\n      if (event.target.hasAttribute('scroll-lock')) {\n        const { open } = event.target;\n        if (open) {\n          lockScroll(event.target);\n        } else {\n          unlockScroll(event.target);\n        }\n      }\n    }\n  },\n  { capture: true }\n);\n"],
  "mappings": "AAAA,OAAS,cAAiB,mBAC1B,OAAS,SAAU,iBAAkB,WAAY,eAAgB,iBAAoB,mBACrF,OAAS,aAAc,aAAgB,0BAUhC,aAAM,wBAAwB,SAAU,CAC7C,aAAe,CAAC,QAAQ,EAExB,mBAAoB,CAClB,MAAM,kBAAkB,GAEpB,KAAK,UAAY,KAAK,WACxB,OAAO,iBAAiB,SAAU,KAAK,aAAa,CAExD,CAEA,sBAAuB,CACrB,MAAM,qBAAqB,GACvB,KAAK,UAAY,KAAK,WACxB,OAAO,oBAAoB,SAAU,KAAK,aAAa,EAEzD,aAAa,KAAK,KAAK,MAAM,CAC/B,CAEA,cAAgB,SAAS,IAAM,CAC7B,KAAM,CAAE,SAAU,QAAS,EAAI,KAE/B,GAAI,CAAC,UAAY,CAAC,SAAU,OAE5B,MAAM,YAAc,OAAO,YACvB,YAAc,UAAY,YAAc,WAC1C,KAAK,YAAY,CAErB,EAAG,EAAE,EAEL,iBAAmB,EAKnB,YAAa,CACX,KAAM,CAAE,MAAO,EAAI,KAAK,KAEpB,OAAO,OAEX,KAAK,iBAAmB,aAAa,EAGrC,sBAAsB,IAAM,CAC1B,WAAW,MAAM,EAEjB,OAAO,UAAU,EACjB,KAAK,cAAc,IAAI,eAAiB,EAExC,KAAK,iBAAiB,QAAS,KAAK,YAAY,EAChD,KAAK,iBAAiB,UAAW,KAAK,cAAc,CACtD,CAAC,EACH,CAKA,YAAc,SAAY,CACxB,KAAM,CAAE,MAAO,EAAI,KAAK,KAEnB,OAAO,OAEZ,KAAK,oBAAoB,QAAS,KAAK,YAAY,EACnD,KAAK,oBAAoB,UAAW,KAAK,cAAc,EAIvD,OAAO,MAAM,UAAY,OAGpB,OAAO,YAGZ,OAAO,UAAU,IAAI,gBAAgB,EACrC,OAAO,MAAM,UAAY,GAEzB,MAAM,eAAe,OAAQ,OAAW,CAC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