{
  "version": 3,
  "sources": ["/cdn/shop/t/17/assets/custom.js?rev=20260410-otp-cart-fix"],
  "sourcesContent": ["/**\n * DEVELOPER DOCUMENTATION\n *\n * Include your custom JavaScript here.\n *\n * The theme Zalify has been developed to be easily extensible through the usage of a lot of different JavaScript\n * events, as well as the usage of custom elements (https://developers.google.com/web/fundamentals/web-components/customelements)\n * to easily extend the theme and re-use the theme infrastructure for your own code.\n *\n * The technical documentation is summarized here.\n *\n * ------------------------------------------------------------------------------------------------------------\n * BEING NOTIFIED WHEN A VARIANT HAS CHANGED\n * ------------------------------------------------------------------------------------------------------------\n *\n * This event is fired whenever a the user has changed the variant in a selector. The target get you the form\n * that triggered this event.\n *\n * Example:\n *\n * document.addEventListener('variant:changed', function(event) {\n *   let variant = event.detail.variant; // Gives you access to the whole variant details\n *   let form = event.target;\n * });\n *\n * ------------------------------------------------------------------------------------------------------------\n * MANUALLY CHANGE A VARIANT\n * ------------------------------------------------------------------------------------------------------------\n *\n * You may want to manually change the variant, and let the theme automatically adjust all the selectors. To do\n * that, you can get the DOM element of type \"<product-variants>\", and call the selectVariant method on it with\n * the variant ID.\n *\n * Example:\n *\n * const productVariantElement = document.querySelector('product-variants');\n * productVariantElement.selectVariant(12345);\n *\n * ------------------------------------------------------------------------------------------------------------\n * BEING NOTIFIED WHEN A NEW VARIANT IS ADDED TO THE CART\n * ------------------------------------------------------------------------------------------------------------\n *\n * This event is fired whenever a variant is added to the cart through a form selector (product page, quick\n * view...). This event DOES NOT include any change done through the cart on an existing variant. For that,\n * please refer to the \"cart:updated\" event.\n *\n * Example:\n *\n * document.addEventListener('variant:added', function(event) {\n *   var variant = event.detail.variant; // Get the variant that was added\n * });\n *\n * ------------------------------------------------------------------------------------------------------------\n * BEING NOTIFIED WHEN THE CART CONTENT HAS CHANGED\n * ------------------------------------------------------------------------------------------------------------\n *\n * This event is fired whenever the cart content has changed (if the quantity of a variant has changed, if a variant\n * has been removed, if the note has changed...). This event will also be emitted when a new variant has been\n * added (so you will receive both \"variant:added\" and \"cart:updated\"). Contrary to the variant:added event,\n * this event will give you the complete details of the cart.\n *\n * Example:\n *\n * document.addEventListener('cart:updated', function(event) {\n *   var cart = event.detail.cart; // Get the updated content of the cart\n * });\n *\n * ------------------------------------------------------------------------------------------------------------\n * REFRESH THE CART/MINI-CART\n * ------------------------------------------------------------------------------------------------------------\n *\n * If you are adding variants to the cart and would like to instruct the theme to re-render the cart, you cart\n * send the cart:refresh event, as shown below:\n *\n * document.documentElement.dispatchEvent(new CustomEvent('cart:refresh', {\n *   bubbles: true\n * }));\n *\n * ------------------------------------------------------------------------------------------------------------\n * USAGE OF CUSTOM ELEMENTS\n * ------------------------------------------------------------------------------------------------------------\n *\n * Our theme makes extensive use of HTML custom elements. Custom elements are an awesome way to extend HTML\n * by creating new elements that carry their own JavaScript for adding new behavior. The theme uses a large\n * number of custom elements, but the two most useful are drawer and popover. Each of those components add\n * a \"open\" attribute that you can toggle on and off. For instance, let's say you would like to open the cart\n * drawer, whose id is \"mini-cart\", you simply need to retrieve it and set its \"open\" attribute to true (or\n * false to close it):\n *\n * document.getElementById('mini-cart').open = true;\n *\n * Thanks to the power of custom elements, the theme will take care automagically of trapping focus, maintaining\n * proper accessibility attributes...\n *\n * If you would like to create your own drawer, you can re-use the <drawer-content> content. Here is a simple\n * example:\n *\n * // Make sure you add \"aria-controls\", \"aria-expanded\" and \"is\" HTML attributes to your button:\n * <button type=\"button\" is=\"toggle-button\" aria-controls=\"id-of-drawer\" aria-expanded=\"false\">Open drawer</button>\n *\n * <drawer-content id=\"id-of-drawer\">\n *   Your content\n * </drawer-content>\n *\n * The nice thing with custom elements is that you do not actually need to instantiate JavaScript yourself: this\n * is done automatically as soon as the element is inserted to the DOM.\n *\n * ------------------------------------------------------------------------------------------------------------\n * THEME DEPENDENCIES\n * ------------------------------------------------------------------------------------------------------------\n *\n * While the theme tries to keep outside dependencies as small as possible, the theme still uses third-party code\n * to power some of its features. Here is the list of all dependencies:\n *\n * \"vendor.js\":\n *\n * The vendor.js contains required dependencies. This file is loaded in parallel of the theme file.\n *\n * - custom-elements polyfill (used for built-in elements on Safari - v1.0.0): https://github.com/ungap/custom-elements\n * - web-animations-polyfill (used for polyfilling WebAnimations on Safari 12, this polyfill will be removed in 1 year - v2.3.2): https://github.com/web-animations/web-animations-js\n * - instant-page (v5.1.0): https://github.com/instantpage/instant.page\n * - tocca (v2.0.9); https://github.com/GianlucaGuarini/Tocca.js/\n * - seamless-scroll-polyfill (v2.0.0): https://github.com/magic-akari/seamless-scroll-polyfill\n *\n * \"flickity.js\": v2.2.0 (with the \"fade\" package). Flickity is only loaded on demand if there is a product image\n * carousel on the page. Otherwise it is not loaded.\n *\n * \"photoswipe\": v4.1.3. PhotoSwipe is only loaded on demand to power the zoom feature on product page. If the zoom\n * feature is disabled, then this script is never loaded.\n */\n\nconst OTP_LOGIN_LINK_SELECTOR = [\n  '[data-otp-login-trigger]',\n  'a[href=\"/account\"]',\n  'a[href*=\"/customer_authentication/redirect\"]',\n  'a[href*=\"/customer_authentication/login\"]',\n  'a[href*=\"/account/login\"]',\n].join(', ');\n\nconst SHOPIFY_ACCOUNT_PATH_PATTERN =\n  /^\\/(?:account(?:\\/login)?|customer_authentication\\/(?:redirect|login))(?:\\/)?$/;\n\nconst getOtpReturnPath = () => {\n  const currentPath = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n\n  return currentPath || window.themeVariables?.routes?.rootUrl || '/';\n};\n\nconst normalizeOtpRedirectTarget = (target) => {\n  if (typeof target !== 'string' || target.trim() === '') {\n    return getOtpReturnPath();\n  }\n\n  try {\n    const parsedTarget = new URL(target, window.location.origin);\n\n    if (SHOPIFY_ACCOUNT_PATH_PATTERN.test(parsedTarget.pathname)) {\n      return getOtpReturnPath();\n    }\n\n    return `${parsedTarget.pathname}${parsedTarget.search}${parsedTarget.hash}`;\n  } catch (error) {\n    return target;\n  }\n};\n\nconst patchOtpLoginHandlers = () => {\n  if (\n    typeof window.handleKpAndShopifyLogin === 'function' &&\n    !window.handleKpAndShopifyLogin.__otpRedirectPatched\n  ) {\n    const originalHandleKpAndShopifyLogin = window.handleKpAndShopifyLogin;\n\n    const patchedHandleKpAndShopifyLogin = (...args) => {\n      if (args.length === 0 || args[0] == null || typeof args[0] === 'string') {\n        args[0] = normalizeOtpRedirectTarget(args[0]);\n      }\n\n      return originalHandleKpAndShopifyLogin.apply(window, args);\n    };\n\n    patchedHandleKpAndShopifyLogin.__otpRedirectPatched = true;\n    window.handleKpAndShopifyLogin = patchedHandleKpAndShopifyLogin;\n  }\n\n  if (typeof window.kpHandleLogin === 'function' && !window.kpHandleLogin.__otpRedirectPatched) {\n    const originalKpHandleLogin = window.kpHandleLogin;\n\n    const patchedKpHandleLogin = (...args) => {\n      if (args.length === 0 || args[0] == null || typeof args[0] === 'string') {\n        args[0] = normalizeOtpRedirectTarget(args[0]);\n      }\n\n      return originalKpHandleLogin.apply(window, args);\n    };\n\n    patchedKpHandleLogin.__otpRedirectPatched = true;\n    window.kpHandleLogin = patchedKpHandleLogin;\n  }\n\n  if (typeof window.handleShopifyLogin === 'function' && !window.handleShopifyLogin.__otpRedirectPatched) {\n    const originalHandleShopifyLogin = window.handleShopifyLogin;\n\n    const patchedHandleShopifyLogin = (...args) => {\n      if (args.length < 2 || args[1] == null || typeof args[1] === 'string') {\n        args[1] = normalizeOtpRedirectTarget(args[1]);\n      }\n\n      return originalHandleShopifyLogin.apply(window, args);\n    };\n\n    patchedHandleShopifyLogin.__otpRedirectPatched = true;\n    window.handleShopifyLogin = patchedHandleShopifyLogin;\n  }\n\n  if (typeof window.hndlRedrctn === 'function' && !window.hndlRedrctn.__otpRedirectPatched) {\n    const originalRedirectHandler = window.hndlRedrctn;\n\n    const patchedRedirectHandler = (...args) => {\n      if (args.length === 0 || args[0] == null || typeof args[0] === 'string') {\n        args[0] = normalizeOtpRedirectTarget(args[0]);\n      }\n\n      return originalRedirectHandler.apply(window, args);\n    };\n\n    patchedRedirectHandler.__otpRedirectPatched = true;\n    window.hndlRedrctn = patchedRedirectHandler;\n  }\n};\n\npatchOtpLoginHandlers();\n\ndocument.addEventListener('DOMContentLoaded', patchOtpLoginHandlers);\nwindow.addEventListener('load', patchOtpLoginHandlers);\nwindow.addEventListener('update-dom', patchOtpLoginHandlers);\n\nwindow.setTimeout(patchOtpLoginHandlers, 500);\nwindow.setTimeout(patchOtpLoginHandlers, 1500);\nwindow.setTimeout(patchOtpLoginHandlers, 3000);\n\nconst waitForOtpLoginHandler = async (timeoutMs = 2500) => {\n  const startedAt = Date.now();\n\n  while (Date.now() - startedAt < timeoutMs) {\n    patchOtpLoginHandlers();\n\n    if (typeof window.handleKpAndShopifyLogin === 'function') {\n      return () => window.handleKpAndShopifyLogin(getOtpReturnPath());\n    }\n\n    if (typeof window.kpHandleLogin === 'function') {\n      return () => window.kpHandleLogin(getOtpReturnPath());\n    }\n\n    await new Promise((resolve) => window.setTimeout(resolve, 100));\n  }\n\n  return null;\n};\n\ndocument.addEventListener(\n  'click',\n  async (event) => {\n    const loginTrigger = event.target.closest(OTP_LOGIN_LINK_SELECTOR);\n\n    if (!loginTrigger || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {\n      return;\n    }\n\n    if (loginTrigger.hasAttribute('data-otp-login-pending')) {\n      event.preventDefault();\n      return;\n    }\n\n    event.preventDefault();\n    loginTrigger.setAttribute('data-otp-login-pending', 'true');\n\n    try {\n      const openOtpLogin = await waitForOtpLoginHandler();\n\n      if (openOtpLogin) {\n        openOtpLogin();\n        return;\n      }\n\n      const fallbackUrl = loginTrigger.getAttribute('data-login-fallback-url') || loginTrigger.href;\n\n      if (fallbackUrl) {\n        window.location.href = fallbackUrl;\n      }\n    } finally {\n      loginTrigger.removeAttribute('data-otp-login-pending');\n    }\n  },\n  { capture: true }\n);\n"],
  "mappings": "AAmIA,MAAM,wBAA0B,CAC9B,2BACA,qBACA,+CACA,4CACA,2BACF,EAAE,KAAK,IAAI,EAEL,6BACJ,iFAEI,iBAAmB,IAC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