// // 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, resolveMediaElement } 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. `allow-presentation` only where the * engine knows it: WebKit rejects it with a console error for every embed. Without a DOM (a server render) * the flag is left out. */ const IFRAME_SANDBOX = 'allow-scripts allow-same-origin'; let iframeSandbox: string | undefined; const getIframeSandbox = (): string => { if (typeof document === 'undefined') { return IFRAME_SANDBOX; } return (iframeSandbox ??= document.createElement('iframe').sandbox.supports('allow-presentation') ? `${IFRAME_SANDBOX} allow-presentation` : IFRAME_SANDBOX); }; 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 `