// // Copyright 2026 DXOS.org // import React, { useState } from 'react'; import { mx } from '@dxos/ui-theme'; import { type ThemedClassName } from '@dxos/ui-types'; import { recipes } from '../../recipes.ts'; import { type MediaKind, detectMediaKind, isEmbedUrl } from './media-kind.ts'; export type MediaPlayerKind = MediaKind; export type MediaPlayerFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down'; type MediaPlayerStatus = 'loading' | 'loaded' | 'error'; /** iframe sandbox flags compatible with typical oEmbed-style players. */ const IFRAME_SANDBOX = 'allow-scripts allow-same-origin allow-presentation'; /** Cloudflare Stream `/iframe` embeds: `https://customer-.cloudflarestream.com/<32-hex-uid>/iframe[?…]`. */ const CLOUDFLARE_STREAM_IFRAME_PATTERN = /^https:\/\/[a-z0-9-]+\.cloudflarestream\.com\/[a-f0-9]{32}\/iframe(?:[/?#]|$)/i; export type MediaPlayerProps = ThemedClassName<{ 'src': string; /** Names the media (`aria-label`, an image's `alt`, an embed's `title`). */ 'alt'?: string; /** Forces native playback; otherwise detected from the URL's extension, and anything else is an image. */ 'kind'?: MediaPlayerKind; 'controls'?: boolean; 'autoPlay'?: boolean; 'loop'?: boolean; 'muted'?: boolean; /** CORS mode for `