{"version":3,"file":"embed-BYNUxkTz.mjs","names":["PaymentCheckoutClass"],"sources":["../../src/embed/scriptLoader.ts","../../src/embed/index.ts"],"sourcesContent":["/**\n * Script loading and initialization utilities\n */\n\ninterface ScriptLoadOptions {\n  url?: string;\n  async?: boolean;\n  defer?: boolean;\n  crossorigin?: string;\n  integrity?: string;\n}\n\n/**\n * Load a script dynamically\n */\nexport function loadScript(options: ScriptLoadOptions = {}): Promise<void> {\n  return new Promise((resolve, reject) => {\n    const {\n      url = 'https://cdn.fanbasis.com/checkout/latest.js',\n      async = true,\n      defer = false,\n      crossorigin,\n      integrity\n    } = options;\n\n    // Check if script is already loaded\n    const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n    if (existingScript) {\n      resolve();\n      return;\n    }\n\n    const script = document.createElement('script');\n    script.src = url;\n    script.async = async;\n    script.defer = defer;\n    \n    if (crossorigin) {\n      script.crossOrigin = crossorigin;\n    }\n    \n    if (integrity) {\n      script.integrity = integrity;\n    }\n\n    script.onload = () => resolve();\n    script.onerror = () => reject(new Error(`Failed to load script: ${url}`));\n    \n    document.head.appendChild(script);\n  });\n}\n\n/**\n * Load checkout script with default configuration\n */\nexport function loadCheckoutScript(version?: string): Promise<void> {\n  const url = version \n    ? `https://cdn.fanbasis.com/checkout/v${version}/checkout.js`\n    : 'https://cdn.fanbasis.com/checkout/latest.js';\n  \n  return loadScript({ url });\n}\n\n/**\n * Initialize checkout when DOM is ready\n */\nexport function initializeOnReady(callback: () => void): void {\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', callback);\n  } else {\n    callback();\n  }\n}\n\n/**\n * Auto-initialize checkout elements\n */\nexport function autoInitializeCheckout(): void {\n  const elements = document.querySelectorAll('[data-checkout]');\n  \n  elements.forEach((element) => {\n    if (!(element as any).__checkoutInitialized) {\n      try {\n        // Import dynamically to avoid circular dependencies\n        import('./attributeParser').then(({ autoInitialize }) => {\n          autoInitialize();\n        });\n        (element as any).__checkoutInitialized = true;\n      } catch (error) {\n        console.error('Failed to initialize checkout element:', error);\n      }\n    }\n  });\n}\n\n/**\n * Set up global checkout initialization\n */\nexport function setupGlobalInitialization(): void {\n  // Auto-initialize on DOM ready\n  initializeOnReady(() => {\n    if (document.querySelector('[data-checkout-auto]')) {\n      autoInitializeCheckout();\n    }\n  });\n\n  // Auto-initialize on new elements (MutationObserver)\n  if (typeof MutationObserver !== 'undefined') {\n    const observer = new MutationObserver((mutations) => {\n      mutations.forEach((mutation) => {\n        mutation.addedNodes.forEach((node) => {\n          if (node.nodeType === Node.ELEMENT_NODE) {\n            const element = node as Element;\n            if (element.hasAttribute('data-checkout') || element.querySelector('[data-checkout]')) {\n              autoInitializeCheckout();\n            }\n          }\n        });\n      });\n    });\n\n    observer.observe(document.body, {\n      childList: true,\n      subtree: true\n    });\n  }\n}\n\n/**\n * Check if checkout script is loaded\n */\nexport function isCheckoutLoaded(): boolean {\n  return typeof window !== 'undefined' && \n         (window.PaymentCheckout !== undefined || window.FanbasisCheckout !== undefined);\n}\n\n/**\n * Wait for checkout to be available\n */\nexport function waitForCheckout(timeout = 10000): Promise<void> {\n  return new Promise((resolve, reject) => {\n    if (isCheckoutLoaded()) {\n      resolve();\n      return;\n    }\n\n    const startTime = Date.now();\n    const checkInterval = setInterval(() => {\n      if (isCheckoutLoaded()) {\n        clearInterval(checkInterval);\n        resolve();\n      } else if (Date.now() - startTime > timeout) {\n        clearInterval(checkInterval);\n        reject(new Error('Checkout failed to load within timeout'));\n      }\n    }, 100);\n  });\n} ","// Embed integration exports\nexport { PaymentCheckout } from '../PaymentCheckout';\nexport { EventEmitter } from '../events/EventEmitter';\n\n// Type exports\nexport type {\n  CheckoutConfig,\n  CheckoutState,\n  CheckoutEvents,\n  CheckoutEventName,\n  CheckoutEventListener,\n  CustomizationParams,\n  Theme,\n  ProductLayout,\n} from '../types';\n\n// Class and enum exports\nexport { PaymentError, PaymentErrorCode } from '../types';\n\n// Embed-specific utilities\nimport { PaymentCheckout as PaymentCheckoutClass } from '../PaymentCheckout';\nexport const createEmbeddedCheckout = (element: HTMLElement, config: any) => {\n  return PaymentCheckoutClass.fromElement(element, config);\n};\n\n// Global constructor and script loading\nexport { initializeGlobalConstructor } from './globalConstructor';\nexport { \n  loadScript, \n  loadCheckoutScript, \n  setupGlobalInitialization,\n  isCheckoutLoaded,\n  waitForCheckout \n} from './scriptLoader';\n\n\n// Auto-initialize global constructor\nif (typeof window !== 'undefined') {\n  import('./globalConstructor').then(({ initializeGlobalConstructor }) => {\n    initializeGlobalConstructor();\n  });\n} "],"mappings":"4KAeA,SAAgB,EAAW,EAA6B,EAAE,CAAiB,CACzE,OAAO,IAAI,SAAS,EAAS,IAAW,CACtC,GAAM,CACJ,MAAM,8CACN,QAAQ,GACR,QAAQ,GACR,cACA,aACE,EAIJ,GADuB,SAAS,cAAc,eAAe,EAAI,IAC/C,CAAE,CAClB,GAAS,CACT,OAGF,IAAM,EAAS,SAAS,cAAc,SAAS,CAC/C,EAAO,IAAM,EACb,EAAO,MAAQ,EACf,EAAO,MAAQ,EAEX,IACF,EAAO,YAAc,GAGnB,IACF,EAAO,UAAY,GAGrB,EAAO,WAAe,GAAS,CAC/B,EAAO,YAAgB,EAAW,MAAM,0BAA0B,IAAM,CAAC,CAEzE,SAAS,KAAK,YAAY,EAAO,EACjC,CAMJ,SAAgB,EAAmB,EAAiC,CAKlE,OAAO,EAAW,CAAE,IAJR,EACR,sCAAsC,EAAQ,cAC9C,8CAEqB,CAAC,CAM5B,SAAgB,EAAkB,EAA4B,CACxD,SAAS,aAAe,UAC1B,SAAS,iBAAiB,mBAAoB,EAAS,CAEvD,GAAU,CAOd,SAAgB,GAA+B,CAC5B,SAAS,iBAAiB,kBAEnC,CAAC,QAAS,GAAY,CAC5B,GAAI,CAAE,EAAgB,sBACpB,GAAI,CAEF,OAAO,kCAAA,KAAA,GAAA,EAAA,EAAA,CAAqB,MAAM,CAAE,oBAAqB,CACvD,GAAgB,EAChB,CACD,EAAgB,sBAAwB,SAClC,EAAO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