{"version":3,"sources":["../../components/ui/map/adapters/leaflet.ts"],"names":["LEAFLET_CSS_HREF","CSS_LINK_ID","ensureLeafletCss","link","CARTO_STYLE","cartoUrl","style","CARTO_ATTRIBUTION","createLeafletAdapter","container","opts","callbacks","L","err","toLatLng","c","showZoom","leafletCorner","map","addTiles","appearance","layer","tiles","applyAppearance","resizeObserver","markers","z","sw","ne","a","enabled","handlers","k","ctl","list","pad","b","id","coords","anchor","element","e","handle","icon","marker","iconEl","hovered","next"],"mappings":"AAwBA,IAAMA,EAAmB,kDAAA,CACnBC,CAAAA,CAAc,kBAEpB,SAASC,CAAAA,EAAmB,CAM1B,GALI,OAAO,QAAA,CAAa,GAAA,EAGnB,WAAsD,wBAAA,EAEvD,QAAA,CAAS,eAAeD,CAAW,CAAA,CAAG,OAC1C,IAAME,CAAAA,CAAO,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA,CAC1CA,CAAAA,CAAK,GAAKF,CAAAA,CACVE,CAAAA,CAAK,IAAM,YAAA,CACXA,CAAAA,CAAK,KAAOH,CAAAA,CACZ,QAAA,CAAS,KAAK,WAAA,CAAYG,CAAI,EAChC,CAOA,IAAMC,EAA8D,CAClE,KAAA,CAAO,qBAAA,CACP,IAAA,CAAM,uBACN,SAAA,CAAW,qBACb,EACMC,CAAAA,CAAYC,CAAAA,EAChB,qCAAqCA,CAAK,CAAA,mBAAA,CAAA,CACtCC,EAAoB,4CAAA,CAEbC,CAAAA,CAAuC,MAClDC,CAAAA,CACAC,CAAAA,CACAC,IACG,CACHT,CAAAA,GAGA,IAAIU,CAAAA,CACJ,GAAI,CAMFA,EAAI,MAAM,OAAO,SAAS,CAAA,CACtBA,CAAAA,CAAE,UAASA,CAAAA,CAAIA,CAAAA,CAAE,SACvB,CAAA,MAASC,CAAAA,CAAK,CACZ,MAAAF,CAAAA,CAAU,QAAQ,CAChB,IAAA,CAAM,cACN,OAAA,CACE,6GAAA,CACF,KAAA,CAAOE,CACT,CAAC,CAAA,CACKA,CACR,C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n * Leaflet adapter — a WORKER-FREE raster-tile renderer.\n *\n * Why this exists alongside the maplibre adapter: maplibre-gl does all of its\n * rendering in a Web Worker (spawned from a `blob:` URL). Inside a strictly\n * sandboxed MCP App panel the default CSP is `default-src 'none'`, workers\n * fall back to that, and the MCP Apps CSP vocabulary has no `worker-src`\n * knob — so maplibre simply cannot run there. Leaflet paints raster tiles as\n * plain `<img>` elements on the main thread (no worker), so it runs fine; the\n * only thing it needs is network access to the tile host, which IS grantable\n * via the resource's `connectDomains` / `resourceDomains`.\n *\n * Keyless: OSM raster tiles, no API key, no referrer lock. The MCP View\n * forces this adapter (see the provider override in map.tsx); Studio and the\n * embed keep maplibre.\n */\n\nconst LEAFLET_CSS_HREF = \"https://unpkg.com/leaflet@1.9.4/dist/leaflet.css\";\nconst CSS_LINK_ID = \"gds-leaflet-css\";\n\nfunction ensureLeafletCss() {\n  if (typeof document === \"undefined\") return;\n  // The MCP View bundles Leaflet's CSS inline and sets this flag, so we skip\n  // the network <link> there (it would be CSP-blocked anyway).\n  if ((globalThis as { __gradeLeafletCssBundled?: boolean }).__gradeLeafletCssBundled)\n    return;\n  if (document.getElementById(CSS_LINK_ID)) return;\n  const link = document.createElement(\"link\");\n  link.id = CSS_LINK_ID;\n  link.rel = \"stylesheet\";\n  link.href = LEAFLET_CSS_HREF;\n  document.head.appendChild(link);\n}\n\n// Keyless CARTO raster basemaps (built on OSM data). Much closer to Google\n// Maps' default look than raw OSM: `voyager` is the light, road-forward style;\n// `dark_all` is a real dark style (no CSS-invert hack). Served from the\n// a–d.basemaps.cartocdn.com CDN; those hosts are declared in the MCP View's\n// resource CSP. Free with attribution.\nconst CARTO_STYLE: Record<\"light\" | \"dark\" | \"satellite\", string> = {\n  light: \"rastertiles/voyager\",\n  dark: \"rastertiles/dark_all\",\n  satellite: \"rastertiles/voyager\",\n};\nconst cartoUrl = (style: string) =>\n  `https://{s}.basemaps.cartocdn.com/${style}/{z}/{x}/{y}{r}.png`;\nconst CARTO_ATTRIBUTION = \"© OpenStreetMap contributors © CARTO\";\n\nexport const createLeafletAdapter: AdapterFactory = async (\n  container,\n  opts,\n  callbacks\n) => {\n  ensureLeafletCss();\n\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  let L: any;\n  try {\n    // leaflet is resolved + bundled by the consumer (the MCP preview View);\n    // it's intentionally NOT a dependency of @gradeui/ui, so the dts build\n    // can't resolve its types here. The value is `any`, so suppress the\n    // module-resolution error rather than pull leaflet into this package.\n    // @ts-ignore -- optional peer, resolved by the bundling consumer\n    L = await import(\"leaflet\");\n    if (L.default) L = L.default;\n  } catch (err) {\n    callbacks.onError({\n      code: \"sdk-missing\",\n      message:\n        '@gradeui/ui Map: `leaflet` is not installed. Run `pnpm add leaflet` to use the worker-free Leaflet adapter.',\n      cause: err,\n    });\n    throw err;\n  }\n\n  // Grade coords are [lng, lat]; Leaflet wants [lat, lng].\n  const toLatLng = (c: Coords): [number, number] => [c[1], c[0]];\n\n  // Tools — one vocabulary across providers (see MapTools/MapToolsPosition\n  // in types.ts). \"auto\" follows `interactive`; the position maps to\n  // Leaflet's squashed corner names. Zoom is added as an explicit control\n  // (zoomControl: false at init) so it can dock to any corner.\n  const showZoom =\n    opts.tools === \"zoom\" || (opts.tools === \"auto\" && opts.interactive);\n  const leafletCorner: Record<string, string> = {\n    \"top-left\": \"topleft\",\n    \"top-right\": \"topright\",\n    \"bottom-left\": \"bottomleft\",\n    \"bottom-right\": \"bottomright\",\n  };\n\n  const map = L.map(container, {\n    center: toLatLng(opts.center),\n    zoom: opts.zoom,\n    zoomControl: false,\n    attributionControl: true,\n    dragging: opts.interactive,\n    scrollWheelZoom: opts.interactive,\n    doubleClickZoom: opts.interactive,\n    boxZoom: opts.interactive,\n    keyboard: opts.interactive,\n    touchZoom: opts.interactive,\n  });\n\n  if (showZoom) {\n    L.control\n      .zoom({ position: leafletCorner[opts.toolsPosition] ?? \"topleft\" })\n      .addTo(map);\n  }\n\n  // Appearance is a different tile STYLE (not a CSS filter), so switching it\n  // swaps the layer. `{r}` is Leaflet's retina suffix; `detectRetina` fills it.\n  const addTiles = (appearance: \"light\" | \"dark\" | \"satellite\") => {\n    const layer = L.tileLayer(cartoUrl(CARTO_STYLE[appearance] ?? CARTO_STYLE.light), {\n      maxZoom: 20,\n      subdomains: \"abcd\",\n      detectRetina: true,\n      attribution: CARTO_ATTRIBUTION,\n      crossOrigin: true,\n    });\n    layer.on(\"tileerror\", () =>\n      callbacks.onError({\n        code: \"tile-load-failed\",\n        message: \"map tile failed to load (is the tile host allowed by CSP?)\",\n      })\n    );\n    layer.addTo(map);\n    return layer;\n  };\n\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  let tiles: any = addTiles(opts.appearance);\n  const applyAppearance = (appearance: \"light\" | \"dark\" | \"satellite\") => {\n    if (tiles) map.removeLayer(tiles);\n    tiles = addTiles(appearance);\n  };\n\n  if (opts.bounds) {\n    map.fitBounds([toLatLng(opts.bounds[0]), toLatLng(opts.bounds[1])], {\n      animate: false,\n    });\n  }\n\n  // Leaflet initialises synchronously — signal ready immediately.\n  callbacks.onLoad();\n\n  // CRITICAL for sandboxed/absolute-inset containers (the MCP preview panel):\n  // the iframe is frequently sized AFTER the map mounts, so Leaflet's initial\n  // measurement is 0×0 and it renders NOTHING — no tiles, no markers. Re-measure\n  // on the next frames and whenever the container resizes.\n  const resizeObserver =\n    typeof ResizeObserver !== \"undefined\"\n      ? new ResizeObserver(() => map.invalidateSize(false))\n      : null;\n  resizeObserver?.observe(container);\n  requestAnimationFrame(() => map.invalidateSize(false));\n  window.setTimeout(() => map.invalidateSize(false), 200);\n  window.setTimeout(() => map.invalidateSize(false), 600);\n\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  const markers = new globalThis.Map<string, { marker: any; handle: MarkerHandle }>();\n\n  const adapter: AdapterInstance = {\n    setCenter: (c) => map.panTo(toLatLng(c), { animate: false }),\n    setZoom: (z) => map.setZoom(z),\n    setBounds: (sw, ne) =>\n      map.fitBounds([toLatLng(sw), toLatLng(ne)], { animate: false }),\n    setAppearance: (a) => applyAppearance(a),\n    setInteractive: (enabled) => {\n      const handlers = [\n        \"dragging\",\n        \"scrollWheelZoom\",\n        \"doubleClickZoom\",\n        \"boxZoom\",\n        \"keyboard\",\n        \"touchZoom\",\n      ] as const;\n      for (const k of handlers) {\n        const ctl = map[k];\n        if (ctl) (enabled ? ctl.enable() : ctl.disable());\n      }\n    },\n    flyTo: (c, o) =>\n      map.flyTo(toLatLng(c), o?.zoom ?? map.getZoom(), {\n        duration: (o?.durationMs ?? 800) / 1000,\n      }),\n    panTo: (c, o) =>\n      map.panTo(toLatLng(c), { duration: (o?.durationMs ?? 600) / 1000 }),\n    fitBounds: (list, o) => {\n      if (list.length === 0) return;\n      const pad = o?.paddingPx ?? 40;\n      map.fitBounds(list.map(toLatLng), {\n        padding: [pad, pad],\n        duration: (o?.durationMs ?? 800) / 1000,\n      });\n    },\n    getCenter: () => {\n      const c = map.getCenter();\n      return [c.lng, c.lat];\n    },\n    getZoom: () => map.getZoom(),\n    getBounds: () => {\n      const b = map.getBounds();\n      const sw = b.getSouthWest();\n      const ne = b.getNorthEast();\n      return [\n        [sw.lng, sw.lat],\n        [ne.lng, ne.lat],\n      ];\n    },\n    addMarker: (id, coords, anchor) => {\n      // Live DOM marker: <MapMarker> portals its React children into\n      // `element`. Leaflet positions the icon container's top-left at the\n      // coord (iconAnchor [0,0]); our absolutely-positioned element then\n      // offsets via transform so its bottom-centre (or centre) sits on the\n      // point — matching the maplibre adapter's anchor semantics.\n      const element = document.createElement(\"div\");\n      element.dataset.gdsPart = \"map-marker\";\n      element.dataset.gdsState = \"idle\";\n      element.style.position = \"absolute\";\n      element.style.cursor = \"pointer\";\n      element.style.transform =\n        anchor === \"center\"\n          ? \"translate(-50%, -50%)\"\n          : \"translate(-50%, -100%)\";\n\n      element.addEventListener(\"mouseenter\", () => callbacks.onMarkerHover(id));\n      element.addEventListener(\"mouseleave\", () => callbacks.onMarkerHover(null));\n      element.addEventListener(\"click\", (e) =>\n        callbacks.onMarkerClick(id, handle.coords, e)\n      );\n\n      const icon = L.divIcon({\n        className: \"gds-leaflet-marker\",\n        html: \"\",\n        iconSize: [0, 0],\n        iconAnchor: [0, 0],\n      });\n      const marker = L.marker(toLatLng(coords), {\n        icon,\n        interactive: true,\n        keyboard: false,\n      }).addTo(map);\n\n      const iconEl: HTMLElement | undefined = marker.getElement();\n      if (iconEl) {\n        iconEl.style.pointerEvents = \"auto\";\n        iconEl.appendChild(element);\n      }\n\n      const handle: MarkerHandle = {\n        element,\n        coords,\n        setHovered: (hovered) => {\n          element.dataset.gdsState = hovered ? \"hovered\" : \"idle\";\n          if (iconEl) iconEl.style.zIndex = hovered ? \"1000\" : \"\";\n        },\n        setPosition: (next) => {\n          handle.coords = next;\n          marker.setLatLng(toLatLng(next));\n        },\n        remove: () => {\n          map.removeLayer(marker);\n          markers.delete(id);\n        },\n      };\n\n      markers.set(id, { marker, handle });\n      return handle;\n    },\n    destroy: () => {\n      resizeObserver?.disconnect();\n      markers.forEach(({ marker }) => map.removeLayer(marker));\n      markers.clear();\n      map.remove();\n    },\n    instance: map,\n  };\n\n  return adapter;\n};\n"]}