import React, { Component, ReactNode } from 'react'; /** * Open-Graph metadata returned by the consumer's scrape endpoint. * * The shape MUST match the JSON the OG endpoint serves at `ogEndpointPath`. * The hub's `/api/og-scraper` returns exactly these fields — embedders * with a different endpoint must return the same shape (or adapt at the * route boundary). Keeps the consumer surface trivial: one URL → one card. */ export interface OGData { title: string; description: string; image: string; originalImage?: string; url: string; siteName: string; type: string; favicon: string; } interface ErrorBoundaryProps { children: ReactNode; fallback: ReactNode; } interface ErrorBoundaryState { hasError: boolean; } /** * Tiny error boundary tailored for OG link previews — caught errors quietly * fall back to the `fallback` prop (typically a plain hyperlink) so a single * broken third-party preview can't crash a whole article view. * * Named `OGLinkErrorBoundary` (not the generic `ErrorBoundary`) because the * lib already exports a separate `ErrorBoundary` from * `components/features/error-boundary.tsx`. The top-level `components/index.ts` * barrel re-exports both `./embeds` and `./features` via `export *`, so a * second `ErrorBoundary` here collides as TS2308. */ export declare class OGLinkErrorBoundary extends Component { constructor(props: ErrorBoundaryProps); static getDerivedStateFromError(): ErrorBoundaryState; componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void; render(): React.ReactNode; } /** * Builds a placeholder image URL when the scrape returns no image. Hub passes * its own `buildOgPlaceholderUrl` (which hits `/api/og-placeholder?…&platform=`; * the route resolves the platform's brand colors server-side); other embedders * can omit the prop to disable the placeholder entirely. * * Receives the post-scrape `title` and `siteName` so the placeholder can echo * the actual card content, not a generic graphic. */ export type BuildPlaceholderUrl = (title: string, siteName: string) => string | null; export interface OGLinkPreviewProps { /** The external URL to preview. */ url: string; /** Origin / base URL the OG endpoint is served from. Empty / undefined * means same-origin (hub-direct use). Embed contexts pass the hub's * origin here (e.g. `'https://hub.example.com'`) so the fetch hits * the hub instead of the embedder origin. * * Pattern matches lib's `useNatsDialogSubscription({apiBaseUrl})` + * `buildSuggestionUrl({apiBaseUrl})` so all embed-ready surfaces share * one configuration knob. */ apiBaseUrl?: string; /** Path of the OG endpoint on the configured base. Default * `'/api/og-scraper'` matches the hub's route. Override if the * embedder serves the same `OGData` shape from a different path. */ ogEndpointPath?: string; /** Optional placeholder-builder. Omit to disable the placeholder image * (the card then degrades to a favicon+title chip when no scraped image * is available). The hub injects its `buildOgPlaceholderUrl` here. */ buildPlaceholderUrl?: BuildPlaceholderUrl; /** Override the scraped title (used by publication cards that already know * the title locally — e.g. a CMS-managed press link). */ fallbackTitle?: string; /** Override the scraped description. */ fallbackDescription?: string; /** Override the scraped image — useful when the scrape returns no image but * the embedder has a CMS-stored hero image to fall back to. */ fallbackImage?: string; /** Publication / source name shown alongside the favicon (e.g. "TechCrunch"). */ publicationName?: string; /** Publication logo URL shown alongside the title (defaults to favicon). */ publicationLogo?: string; /** Card variant. `compact` = horizontal layout (~120px tall) suited for * in-doc placements; `default` = larger vertical layout for press / hero * positions. */ variant?: 'default' | 'compact'; /** Disable the synthesized placeholder image even when `buildPlaceholderUrl` * is provided — used by the markdown renderer to keep doc cards lighter. */ enablePlaceholder?: boolean; } /** * Rich Open-Graph link preview card with skeleton, fallback, and image-edge * background detection. * * Flow: * 1. Validate URL early (no network for malformed input, localhost, or * RFC1918 ranges — those render as plain `` tags). * 2. `GET ogEndpointPath?url=` — embedder serves the shape declared * in `OGData`. * 3. Resolve image: scraped og:image → `originalImage` fallback → `fallbackImage` * prop → `buildPlaceholderUrl(title, siteName)`. Each step has its own * error toggle so a 404 / CORS-tainted image gracefully degrades. * 4. Extract a letterbox background color from the resolved image via * `useImageEdgeColor`. Same-origin proxy is REQUIRED for cross-origin * images so the `` extraction doesn't taint. * 5. Render compact (h-[120px] horizontal) or default (vertical w/ aspect-video * hero) variant, with image-less degraded variants for each. */ export declare const OGLinkPreview: React.FC; export {}; //# sourceMappingURL=og-link-preview.d.ts.map