{"version":3,"file":"main.umd.cjs","names":[],"sources":["../src/main.ts"],"sourcesContent":["import type { VistaData, VistaExtension, VistaImageParams, VistaView } from 'vistaview';\nimport { VistaBox } from 'vistaview';\n\n/**\n * Parse Wistia URL and extract video ID\n * Supports various Wistia URL formats:\n * - https://home.wistia.com/medias/VIDEO_ID\n * - https://fast.wistia.net/embed/iframe/VIDEO_ID\n * - https://ACCOUNT.wistia.com/medias/VIDEO_ID\n * @param url - Wistia video URL\n * @returns Video ID or null if not found\n */\nexport function parseWistiaVideoId(url: string): string | null {\n  if (!url) return null;\n\n  // Try different Wistia URL patterns\n  const patterns = [\n    /wistia\\.com\\/medias\\/([a-zA-Z0-9]+)/,\n    /wistia\\.net\\/embed\\/iframe\\/([a-zA-Z0-9]+)/,\n  ];\n\n  for (const pattern of patterns) {\n    const match = url.match(pattern);\n    if (match && match[1]) {\n      return match[1];\n    }\n  }\n\n  return null;\n}\n\n/**\n * Get Wistia video thumbnail URL using oEmbed API\n * Note: This fetches data asynchronously from Wistia's oEmbed endpoint\n * @param videoUrl - Wistia video URL\n * @returns Promise with thumbnail URL\n */\nexport async function getWistiaThumbnail(videoUrl: string): Promise<string> {\n  const videoId = parseWistiaVideoId(videoUrl);\n\n  if (!videoId) {\n    throw new Error('Invalid Wistia video URL');\n  }\n\n  try {\n    const response = await fetch(\n      `https://fast.wistia.com/oembed?url=https://home.wistia.com/medias/${videoId}`\n    );\n    const data = await response.json();\n    return data.thumbnail_url;\n  } catch (error) {\n    // Fallback: return a placeholder or rethrow\n    console.error('Failed to fetch Wistia thumbnail:', error);\n    throw new Error('Failed to fetch Wistia thumbnail');\n  }\n}\n\nexport class VistaWistiaVideo extends VistaBox {\n  element: HTMLDivElement;\n  url: string;\n\n  constructor(par: VistaImageParams) {\n    super(par);\n\n    const url = par.elm.config.src;\n    this.url = url;\n\n    const div = document.createElement('div');\n    div.style.position = 'relative';\n    div.style.overflow = 'hidden';\n    div.style.borderRadius = '14px';\n    const image = document.createElement('img');\n    div.appendChild(image);\n    image.style.width = '100%';\n    image.style.height = '100%';\n    image.style.objectFit = 'cover';\n    image.src = this.origin?.image.src || ''; // use existing thumbnail if available\n    image.classList.add('vvw--pulsing');\n\n    this.element = div;\n\n    this.element.classList.add('vvw-img-hi');\n\n    // set sizes\n    const { width: fullWidth, height: fullHeight } = this.getFullSizeDim();\n    this.fullH = fullHeight;\n    this.fullW = fullWidth;\n    this.minW = this.fullW * 0.5;\n    this.maxW = this.fullW; // no scaling\n    this.element.style.width = `${fullWidth}px`;\n    this.element.style.height = `${fullHeight}px`;\n\n    // trigger setSizes to setup thumb and iframe initial style\n    this.setSizes({ stableSize: false, initDimension: true });\n\n    if (this.pos === 0) {\n      const iframe = document.createElement('iframe');\n      iframe.frameBorder = '0';\n      iframe.allow = 'autoplay; fullscreen';\n      iframe.allowFullscreen = true;\n      iframe.width = '100%';\n      iframe.height = '100%';\n      iframe.style.position = 'absolute';\n      iframe.style.top = '0';\n      iframe.style.left = '0';\n      iframe.style.opacity = '0';\n      iframe.style.transition = 'opacity 333ms ease';\n      iframe.src = `https://fast.wistia.net/embed/iframe/${parseWistiaVideoId(url)}?autoPlay=1`;\n      div.appendChild(iframe);\n\n      iframe.onload = () => {\n        iframe.style.opacity = '1';\n        image.classList.remove('vvw--pulsing');\n      };\n    }\n\n    this.isLoadedResolved!(true);\n  }\n\n  // the default full size is the scaled thumbnail size\n  // so we change it to 16:9 full window width size (or max 800px)\n  protected getFullSizeDim(): { width: number; height: number } {\n    const maxWidth = Math.min(window.innerWidth, 800);\n    return {\n      width: maxWidth,\n      height: (maxWidth * 9) / 16,\n    };\n  }\n\n  // override to avoid propagating content change event\n  // (because no change will happen on iframe)\n  setFinalTransform() {\n    return super.setFinalTransform({ propagateEvent: false });\n  }\n}\n\nexport function wistiaVideo(): VistaExtension {\n  return {\n    name: 'wistiaVideo',\n    onInitializeImage: (params: VistaImageParams) => {\n      const url = params.elm.config.src;\n      const videoId = parseWistiaVideoId(url);\n      if (!videoId) return;\n\n      return new VistaWistiaVideo(params);\n    },\n    onImageView: async (data: VistaData, v: VistaView) => {\n      const mainData = data.images.to![Math.floor(data.images.to!.length / 2)];\n      if (mainData instanceof VistaWistiaVideo) {\n        v.deactivateUi(['download', 'zoomIn', 'zoomOut'], mainData);\n      }\n    },\n  };\n}\n"],"mappings":"gRAYA,SAAgB,EAAmB,EAA4B,CAC7D,GAAI,CAAC,EAAK,OAAO,KAQjB,IAAK,IAAM,IALM,CACf,sCACA,6CACD,CAE+B,CAC9B,IAAM,EAAQ,EAAI,MAAM,EAAQ,CAChC,GAAI,GAAS,EAAM,GACjB,OAAO,EAAM,GAIjB,OAAO,KAST,eAAsB,EAAmB,EAAmC,CAC1E,IAAM,EAAU,EAAmB,EAAS,CAE5C,GAAI,CAAC,EACH,MAAU,MAAM,2BAA2B,CAG7C,GAAI,CAKF,OADa,MAHI,MAAM,MACrB,qEAAqE,IACtE,EAC2B,MAAM,EACtB,oBACL,EAAO,CAGd,MADA,QAAQ,MAAM,oCAAqC,EAAM,CAC/C,MAAM,mCAAmC,EAIvD,IAAa,EAAb,cAAsC,EAAA,QAAS,CAC7C,QACA,IAEA,YAAY,EAAuB,CACjC,MAAM,EAAI,CAEV,IAAM,EAAM,EAAI,IAAI,OAAO,IAC3B,KAAK,IAAM,EAEX,IAAM,EAAM,SAAS,cAAc,MAAM,CACzC,EAAI,MAAM,SAAW,WACrB,EAAI,MAAM,SAAW,SACrB,EAAI,MAAM,aAAe,OACzB,IAAM,EAAQ,SAAS,cAAc,MAAM,CAC3C,EAAI,YAAY,EAAM,CACtB,EAAM,MAAM,MAAQ,OACpB,EAAM,MAAM,OAAS,OACrB,EAAM,MAAM,UAAY,QACxB,EAAM,IAAM,KAAK,QAAQ,MAAM,KAAO,GACtC,EAAM,UAAU,IAAI,eAAe,CAEnC,KAAK,QAAU,EAEf,KAAK,QAAQ,UAAU,IAAI,aAAa,CAGxC,GAAM,CAAE,MAAO,EAAW,OAAQ,GAAe,KAAK,gBAAgB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