{"version":3,"file":"main.umd.cjs","names":["embedUrl: string"],"sources":["../src/main.ts"],"sourcesContent":["import type { VistaData, VistaExtension, VistaImageParams, VistaView } from 'vistaview';\nimport { VistaBox } from 'vistaview';\n\nexport interface GoogleMapsConfig {\n  apiKey?: string;\n  zoom?: number; // Default zoom level (1-20)\n  width?: number; // Map width in pixels\n  height?: number; // Map height in pixels\n  mapType?: 'roadmap' | 'satellite' | 'hybrid' | 'terrain';\n}\n\nexport interface GoogleMapsLocation {\n  lat: number;\n  lng: number;\n  zoom?: number;\n  query?: string;\n}\n\n/**\n * Parse Google Maps URL and extract location data\n * Supports various Google Maps URL formats:\n * - https://www.google.com/maps?q=40.7128,-74.0060\n * - https://www.google.com/maps/@40.7128,-74.0060,15z\n * - https://maps.google.com?q=40.7128,-74.0060\n * - https://goo.gl/maps/...\n * @param url - Google Maps URL\n * @returns Location data or null if not found\n */\nexport function parseGoogleMapsLocation(url: string): GoogleMapsLocation | null {\n  if (!url) return null;\n\n  try {\n    const urlObj = new URL(url);\n\n    // Check for @lat,lng,zoom format\n    const atMatch = url.match(/@(-?\\d+\\.?\\d*),(-?\\d+\\.?\\d*),?(\\d+\\.?\\d*)?z?/);\n    if (atMatch) {\n      return {\n        lat: parseFloat(atMatch[1]),\n        lng: parseFloat(atMatch[2]),\n        zoom: atMatch[3] ? parseFloat(atMatch[3]) : undefined,\n      };\n    }\n\n    // Check for q=lat,lng format\n    const qParam = urlObj.searchParams.get('q');\n    if (qParam) {\n      const coordMatch = qParam.match(/(-?\\d+\\.?\\d*),\\s*(-?\\d+\\.?\\d*)/);\n      if (coordMatch) {\n        return {\n          lat: parseFloat(coordMatch[1]),\n          lng: parseFloat(coordMatch[2]),\n          query: qParam,\n        };\n      }\n      // If q param doesn't contain coordinates, store it as a query\n      return { lat: 0, lng: 0, query: qParam };\n    }\n\n    // Check for ll= parameter (lat,lng)\n    const llParam = urlObj.searchParams.get('ll');\n    if (llParam) {\n      const [lat, lng] = llParam.split(',').map(parseFloat);\n      if (!isNaN(lat) && !isNaN(lng)) {\n        return { lat, lng };\n      }\n    }\n  } catch (error) {\n    console.error('Failed to parse Google Maps URL:', error);\n  }\n\n  return null;\n}\n\n/**\n * Get Google Maps static image URL\n * @param location - Location data\n * @param config - Google Maps configuration\n * @returns Static map image URL\n */\nexport function getGoogleMapsStaticImage(\n  location: GoogleMapsLocation,\n  config: GoogleMapsConfig\n): string {\n  if (!config.apiKey) {\n    throw new Error('Google Maps API key is required');\n  }\n\n  const zoom = location.zoom || config.zoom || 15;\n  const width = config.width || 800;\n  const height = config.height || 600;\n  const mapType = config.mapType || 'roadmap';\n\n  const center = location.query || `${location.lat},${location.lng}`;\n  const marker = location.query ? '' : `&markers=color:red|${location.lat},${location.lng}`;\n\n  return `https://maps.googleapis.com/maps/api/staticmap?center=${encodeURIComponent(center)}&zoom=${zoom}&size=${width}x${height}&maptype=${mapType}${marker}&key=${config.apiKey}`;\n}\n\nexport class VistaGoogleMaps extends VistaBox {\n  element: HTMLDivElement;\n  private mapsConfig: GoogleMapsConfig;\n  private location: GoogleMapsLocation;\n\n  constructor(par: VistaImageParams, location: GoogleMapsLocation, config?: GoogleMapsConfig) {\n    super(par);\n\n    this.mapsConfig = config || {};\n    this.location = location;\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 =\n      this.origin?.image.src ||\n      (config && config.apiKey ? getGoogleMapsStaticImage(location, config) : '');\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 = 'geolocation';\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 1s ease';\n\n      // Use standard Google Maps iframe embed\n      let embedUrl: string;\n      if (this.location.query) {\n        embedUrl = `https://www.google.com/maps?q=${encodeURIComponent(this.location.query)}&output=embed`;\n      } else {\n        embedUrl = `https://www.google.com/maps?q=${this.location.lat},${this.location.lng}&output=embed`;\n      }\n      iframe.src = embedUrl;\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  // Use 16:9 aspect ratio with max 800px width\n  protected getFullSizeDim(): { width: number; height: number } {\n    const maxWidth = Math.min(window.innerWidth, this.mapsConfig.width || 800);\n    return {\n      width: maxWidth,\n      height: (maxWidth * 9) / 16,\n    };\n  }\n\n  // Override to avoid propagating content change event\n  setFinalTransform() {\n    return super.setFinalTransform({ propagateEvent: false });\n  }\n}\n\nexport function googleMaps(config?: GoogleMapsConfig): VistaExtension {\n  return {\n    name: 'googleMaps',\n    onInitializeImage: (params: VistaImageParams) => {\n      const url = params.elm.config.src;\n      const location = parseGoogleMapsLocation(url);\n      if (!location) return;\n\n      return new VistaGoogleMaps(params, location, config);\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 VistaGoogleMaps) {\n        v.deactivateUi(['download', 'zoomIn', 'zoomOut'], mainData);\n      }\n    },\n  };\n}\n"],"mappings":"gRA4BA,SAAgB,EAAwB,EAAwC,CAC9E,GAAI,CAAC,EAAK,OAAO,KAEjB,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