{"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 Dailymotion URL and extract video ID\n * Supports various Dailymotion URL formats:\n * - https://www.dailymotion.com/video/VIDEO_ID\n * - https://dai.ly/VIDEO_ID\n * - https://www.dailymotion.com/embed/video/VIDEO_ID\n * @param url - Dailymotion video URL\n * @returns Video ID or null if not found\n */\nexport function parseDailymotionVideoId(url: string): string | null {\n  if (!url) return null;\n\n  // Try different Dailymotion URL patterns\n  const patterns = [\n    /dailymotion\\.com\\/video\\/([a-zA-Z0-9]+)/,\n    /dai\\.ly\\/([a-zA-Z0-9]+)/,\n    /dailymotion\\.com\\/embed\\/video\\/([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 Dailymotion video thumbnail URL\n * @param videoUrl - Dailymotion video URL\n * @param quality - Thumbnail quality: 'large' | 'medium' | 'small'\n * @returns Thumbnail URL\n */\nexport function getDailymotionThumbnail(videoUrl: string): string {\n  const videoId = parseDailymotionVideoId(videoUrl);\n  if (!videoId) {\n    throw new Error('Invalid Dailymotion video URL');\n  }\n\n  // Dailymotion thumbnail URL pattern\n  return `https://www.dailymotion.com/thumbnail/video/${videoId}`;\n}\n\nexport class VistaDailymotionVideo 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 || getDailymotionThumbnail(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; picture-in-picture';\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://www.dailymotion.com/embed/video/${parseDailymotionVideoId(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 dailymotionVideo(): VistaExtension {\n  return {\n    name: 'dailymotionVideo',\n    onInitializeImage: (params: VistaImageParams) => {\n      const url = params.elm.config.src;\n      const videoId = parseDailymotionVideoId(url);\n      if (!videoId) return;\n\n      return new VistaDailymotionVideo(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 VistaDailymotionVideo) {\n        v.deactivateUi(['download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