{"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 Streamable URL and extract video ID\n * Supports various Streamable URL formats:\n * - https://streamable.com/VIDEO_ID\n * - https://streamable.com/e/VIDEO_ID\n * @param url - Streamable video URL\n * @returns Video ID or null if not found\n */\nexport function parseStreamableVideoId(url: string): string | null {\n  if (!url) return null;\n\n  // Try different Streamable URL patterns\n  const patterns = [/streamable\\.com\\/e\\/([a-zA-Z0-9]+)/, /streamable\\.com\\/([a-zA-Z0-9]+)/];\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 Streamable video thumbnail URL\n * @param videoUrl - Streamable video URL\n * @returns Thumbnail URL\n */\nexport function getStreamableThumbnail(videoUrl: string): string {\n  const videoId = parseStreamableVideoId(videoUrl);\n  if (!videoId) {\n    throw new Error('Invalid Streamable video URL');\n  }\n\n  return `https://cdn-cf-east.streamable.com/image/${videoId}.jpg`;\n}\n\nexport class VistaStreamableVideo 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    const image = document.createElement('img');\n    div.appendChild(image);\n    image.src = this.origin?.image.src || getStreamableThumbnail(url);\n    image.style.width = '100%';\n    image.style.height = '100%';\n    image.style.objectFit = 'cover';\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://streamable.com/e/${parseStreamableVideoId(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 streamableVideo(): VistaExtension {\n  return {\n    name: 'streamableVideo',\n    onInitializeImage: (params: VistaImageParams) => {\n      const url = params.elm.config.src;\n      const videoId = parseStreamableVideoId(url);\n      if (!videoId) return;\n\n      return new VistaStreamableVideo(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 VistaStreamableVideo) {\n        v.deactivateUi(['download', 'zoomIn', 'zoomOut'], mainData);\n      }\n    },\n  };\n}\n"],"mappings":"gRAWA,SAAgB,EAAuB,EAA4B,CACjE,GAAI,CAAC,EAAK,OAAO,KAKjB,IAAK,IAAM,IAFM,CAAC,qCAAsC,kCAAkC,CAE1D,CAC9B,IAAM,EAAQ,EAAI,MAAM,EAAQ,CACh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