탐색

v2.1.0
미디어

미디어 플레이어

네이티브 오디오나 동영상 요소 위에 페이지 자체의 컨트롤을 둡니다.

이 페이지의 내용

미디어 플레이어는 네이티브 <audio>나 <video> 위에 페이지 자체의 컨트롤을 둡니다. 재생하는 요소는 여전히 미디어 요소이므로, 요소의 시맨틱과 브라우저 미디어 컨트롤과의 연동, 그리고 폴백 역할을 하는 controls 속성이 모두 유지됩니다. player 동작은 연결할 때 이 속성을 제거하고, 그 뒤로는 미디어의 상태를 컨트롤 행에 그대로 반영합니다. 재생 버튼은 재생 중에 눌린 상태가 되고, 탐색 트랙은 슬라이더의 범위 입력 요소로 재생된 부분 아래에 불러온 부분을 그리며, 시간은 숫자가 바뀌어도 너비가 유지되는 작은 고정폭 숫자로 표시됩니다.

미디어 플레이어

<div class="player w-full max-w(480)" role="group" aria-label="A short recording">  <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M7.633 4.7883L14.865 8.9606A1.2 1.2 0 0 1 14.865 11.0394L7.633 15.2117A1.2 1.2 0 0 1 5.8333 14.1723L5.8333 5.8277A1.2 1.2 0 0 1 7.633 4.7883Z" />      </svg>      <svg class="icon player-on" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="5" y="3.75" width="3.3333" height="12.5" rx="0.8" /><rect x="11.6667" y="3.75" width="3.3333" height="12.5" rx="0.8" />      </svg>    </button>    <span class="player-elapsed">0:00</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">    <span class="player-duration">0:00</span>    <button type="button" class="player-button player-mute" aria-label="Mute" aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M10.3333 6C11.3333 7 11.3333 9 10.3333 10" /><path d="M12.3333 3.6667C14.6667 6 14.6667 10 12.3333 12.3333" />      </svg>      <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M11 6.3333L14.3333 9.6667" /><path d="M14.3333 6.3333L11 9.6667" />      </svg>    </button>    <input type="range" class="slider player-volume" min="0" max="1" step="0.05" value="1" aria-label="Volume">    <button type="button" class="player-button player-speed" popovertarget="recording-speed" aria-label="Playback speed">      1×    </button>    <div id="recording-speed" popover class="menu menu-top menu-end">      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="0.75">0.75×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="1" checked>1×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="1.25">1.25×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="1.5">1.5×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="2">2×      </label>    </div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import PlayIcon from '@master/icons-react/native/20/soft/play'import PauseIcon from '@master/icons-react/native/20/soft/pause'import VolumeIcon from '@master/icons-react/native/16/soft/volume'import VolumeOffIcon from '@master/icons-react/native/16/soft/volume-off'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="player w-full max-w(480)" role="group" aria-label="A short recording">      <audio className="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>      <div className="player-controls">        <button type="button" className="player-button player-play" aria-label="Play" aria-pressed="false">          <PlayIcon className="icon player-off" />          <PauseIcon className="icon player-on" />        </button>        <span className="player-elapsed">0:00</span>        <input type="range" className="slider player-seek" min="0" max="0" step="any" defaultValue="0" aria-label="Seek" />        <span className="player-duration">0:00</span>        <button type="button" className="player-button player-mute" aria-label="Mute" aria-pressed="false">          <VolumeIcon className="icon player-off" />          <VolumeOffIcon className="icon player-on" />        </button>        <input type="range" className="slider player-volume" min="0" max="1" step="0.05" defaultValue="1" aria-label="Volume" />        <button type="button" className="player-button player-speed" popoverTarget="recording-speed" aria-label="Playback speed">          1×        </button>        <div id="recording-speed" popover="" className="menu menu-top menu-end">          <label className="menu-item">            <input className="menu-input" type="radio" name="recording-speed" value="0.75" />0.75×          </label>          <label className="menu-item">            <input className="menu-input" type="radio" name="recording-speed" value="1" defaultChecked />1×          </label>          <label className="menu-item">            <input className="menu-input" type="radio" name="recording-speed" value="1.25" />1.25×          </label>          <label className="menu-item">            <input className="menu-input" type="radio" name="recording-speed" value="1.5" />1.5×          </label>          <label className="menu-item">            <input className="menu-input" type="radio" name="recording-speed" value="2" />2×          </label>        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import PlayIcon from '@master/icons-svelte/native/20/soft/play'  import PauseIcon from '@master/icons-svelte/native/20/soft/pause'  import VolumeIcon from '@master/icons-svelte/native/16/soft/volume'  import VolumeOffIcon from '@master/icons-svelte/native/16/soft/volume-off'</script><div class="player w-full max-w(480)" role="group" aria-label="A short recording" {@attach attach}>  <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">      <PlayIcon class="icon player-off" />      <PauseIcon class="icon player-on" />    </button>    <span class="player-elapsed">0:00</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">    <span class="player-duration">0:00</span>    <button type="button" class="player-button player-mute" aria-label="Mute" aria-pressed="false">      <VolumeIcon class="icon player-off" />      <VolumeOffIcon class="icon player-on" />    </button>    <input type="range" class="slider player-volume" min="0" max="1" step="0.05" value="1" aria-label="Volume">    <button type="button" class="player-button player-speed" popovertarget="recording-speed" aria-label="Playback speed">      1×    </button>    <div id="recording-speed" popover class="menu menu-top menu-end">      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="0.75">0.75×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="1" checked>1×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="1.25">1.25×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="1.5">1.5×      </label>      <label class="menu-item">        <input class="menu-input" type="radio" name="recording-speed" value="2">2×      </label>    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import PlayIcon from '@master/icons-vue/native/20/soft/play'import PauseIcon from '@master/icons-vue/native/20/soft/pause'import VolumeIcon from '@master/icons-vue/native/16/soft/volume'import VolumeOffIcon from '@master/icons-vue/native/16/soft/volume-off'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="player w-full max-w(480)" role="group" aria-label="A short recording">    <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>    <div class="player-controls">      <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">        <PlayIcon class="icon player-off" />        <PauseIcon class="icon player-on" />      </button>      <span class="player-elapsed">0:00</span>      <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">      <span class="player-duration">0:00</span>      <button type="button" class="player-button player-mute" aria-label="Mute" aria-pressed="false">        <VolumeIcon class="icon player-off" />        <VolumeOffIcon class="icon player-on" />      </button>      <input type="range" class="slider player-volume" min="0" max="1" step="0.05" value="1" aria-label="Volume">      <button type="button" class="player-button player-speed" popovertarget="recording-speed" aria-label="Playback speed">        1×      </button>      <div id="recording-speed" popover class="menu menu-top menu-end">        <label class="menu-item">          <input class="menu-input" type="radio" name="recording-speed" value="0.75">0.75×        </label>        <label class="menu-item">          <input class="menu-input" type="radio" name="recording-speed" value="1" checked>1×        </label>        <label class="menu-item">          <input class="menu-input" type="radio" name="recording-speed" value="1.25">1.25×        </label>        <label class="menu-item">          <input class="menu-input" type="radio" name="recording-speed" value="1.5">1.5×        </label>        <label class="menu-item">          <input class="menu-input" type="radio" name="recording-speed" value="2">2×        </label>      </div>    </div>  </div></template>
재생 버튼을 누르거나 트랙을 따라 드래그하거나, 컨트롤에 포커스를 두고 Space, 방향키, J와 L, M, Home, End 키를 사용해 보세요. 속도 버튼을 누르면 그 위에 메뉴가 열립니다.

#동영상

player-video를 적용하면 미디어 플레이어가 동영상의 프레임이 됩니다. 영상은 표면과 같은 모서리 반경을 가진 어두운 영역을 채우고, 같은 컨트롤 행이 아래 가장자리에서 올라오는 그림자 위로 영상 아래쪽에 놓입니다. 화면은 어둡기 마련이므로 컨트롤 행은 어느 테마에서든 어두운 색 구성으로 그려집니다. 동영상에는 세 가지 컨트롤이 추가되며, 각각 작동할 수 있는 경우에만 표시됩니다. 자막 버튼은 동영상에 자막 트랙(captions 또는 subtitles)이 있을 때, 화면 속 화면 버튼은 브라우저가 지원할 때, 전체 화면 버튼은 브라우저가 허용할 때 표시됩니다. 영상을 클릭하면 재생과 일시 정지가 전환되고, 더블클릭하면 전체 화면이 됩니다.

동영상이 재생 중이고 포인터가 2.5초 동안 움직이지 않거나 프레임을 벗어나면, 컨트롤 행이 영상에서 서서히 사라지고 포인터도 함께 사라집니다. 포인터를 조금이라도 움직이면 다시 나타납니다. 컨트롤에 키보드 포커스가 있거나 속도 메뉴가 열려 있는 동안에는 사라지지 않으며, 동작 줄이기를 요청한 사용자에게는 사라지지 않습니다. 터치 화면에서 컨트롤이 사라진 영상을 탭하면 컨트롤만 다시 나타납니다.

동영상

<div class="player player-video w-full max-w(560)" role="group" aria-label="Moonrise" style="--player-ratio: 16 / 9">  <video class="player-media" src="/demo/moonrise.mp4" poster="/demo/moonrise.jpg" controls preload="metadata" playsinline>    <track kind="captions" src="/demo/recording.vtt" srclang="en" label="English">  </video>  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M7.633 4.7883L14.865 8.9606A1.2 1.2 0 0 1 14.865 11.0394L7.633 15.2117A1.2 1.2 0 0 1 5.8333 14.1723L5.8333 5.8277A1.2 1.2 0 0 1 7.633 4.7883Z" />      </svg>      <svg class="icon player-on" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="5" y="3.75" width="3.3333" height="12.5" rx="0.8" /><rect x="11.6667" y="3.75" width="3.3333" height="12.5" rx="0.8" />      </svg>    </button>    <span class="player-elapsed">0:00</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">    <span class="player-duration">0:00</span>    <button type="button" class="player-button player-mute" aria-label="Mute" aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M10.3333 6C11.3333 7 11.3333 9 10.3333 10" /><path d="M12.3333 3.6667C14.6667 6 14.6667 10 12.3333 12.3333" />      </svg>      <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M11 6.3333L14.3333 9.6667" /><path d="M14.3333 6.3333L11 9.6667" />      </svg>    </button>    <button type="button" class="player-button player-captions" aria-label="Captions" aria-pressed="false">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="2" y="3" width="12" height="10" rx="1" /><path d="M4.6667 6.6667L6 6.6667" /><path d="M8.6667 6.6667L11.3333 6.6667" /><path d="M4.6667 9.6667L7.3333 9.6667" /><path d="M10 9.6667L11.3333 9.6667" />      </svg>    </button>    <button type="button" class="player-button player-pip" aria-label="Picture in picture" aria-pressed="false">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M5.5 12L2.3333 12A1 1 0 0 1 1.3333 11L1.3333 3.6667A1 1 0 0 1 2.3333 2.6667L13 2.6667A1 1 0 0 1 14 3.6667L14 6.1667" /><rect x="8" y="8.6667" width="6.6667" height="4.6667" rx="1" />      </svg>    </button>    <button type="button" class="player-button player-fullscreen" aria-label="Full screen" aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6667 6L2.6667 3.6667A1 1 0 0 1 3.6667 2.6667L6 2.6667" /><path d="M10 2.6667L12.3333 2.6667A1 1 0 0 1 13.3333 3.6667L13.3333 6" /><path d="M13.3333 10L13.3333 12.3333A1 1 0 0 1 12.3333 13.3333L10 13.3333" /><path d="M6 13.3333L3.6667 13.3333A1 1 0 0 1 2.6667 12.3333L2.6667 10" />      </svg>      <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6667 6L5 6A1 1 0 0 0 6 5L6 2.6667" /><path d="M10 2.6667L10 5A1 1 0 0 0 11 6L13.3333 6" /><path d="M13.3333 10L11 10A1 1 0 0 0 10 11L10 13.3333" /><path d="M6 13.3333L6 11A1 1 0 0 0 5 10L2.6667 10" />      </svg>    </button>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import PlayIcon from '@master/icons-react/native/20/soft/play'import PauseIcon from '@master/icons-react/native/20/soft/pause'import VolumeIcon from '@master/icons-react/native/16/soft/volume'import VolumeOffIcon from '@master/icons-react/native/16/soft/volume-off'import SubtitlesIcon from '@master/icons-react/native/16/soft/subtitles'import PictureInPictureIcon from '@master/icons-react/native/16/soft/picture-in-picture'import MaximizeIcon from '@master/icons-react/native/16/soft/maximize'import MinimizeIcon from '@master/icons-react/native/16/soft/minimize'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="player player-video w-full max-w(560)" role="group" aria-label="Moonrise" style={{ '--player-ratio': '16 / 9' } as React.CSSProperties}>      <video className="player-media" src="/demo/moonrise.mp4" poster="/demo/moonrise.jpg" controls preload="metadata" playsInline>        <track kind="captions" src="/demo/recording.vtt" srcLang="en" label="English" />      </video>      <div className="player-controls">        <button type="button" className="player-button player-play" aria-label="Play" aria-pressed="false">          <PlayIcon className="icon player-off" />          <PauseIcon className="icon player-on" />        </button>        <span className="player-elapsed">0:00</span>        <input type="range" className="slider player-seek" min="0" max="0" step="any" defaultValue="0" aria-label="Seek" />        <span className="player-duration">0:00</span>        <button type="button" className="player-button player-mute" aria-label="Mute" aria-pressed="false">          <VolumeIcon className="icon player-off" />          <VolumeOffIcon className="icon player-on" />        </button>        <button type="button" className="player-button player-captions" aria-label="Captions" aria-pressed="false">          <SubtitlesIcon className="icon" />        </button>        <button type="button" className="player-button player-pip" aria-label="Picture in picture" aria-pressed="false">          <PictureInPictureIcon className="icon" />        </button>        <button type="button" className="player-button player-fullscreen" aria-label="Full screen" aria-pressed="false">          <MaximizeIcon className="icon player-off" />          <MinimizeIcon className="icon player-on" />        </button>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import PlayIcon from '@master/icons-svelte/native/20/soft/play'  import PauseIcon from '@master/icons-svelte/native/20/soft/pause'  import VolumeIcon from '@master/icons-svelte/native/16/soft/volume'  import VolumeOffIcon from '@master/icons-svelte/native/16/soft/volume-off'  import SubtitlesIcon from '@master/icons-svelte/native/16/soft/subtitles'  import PictureInPictureIcon from '@master/icons-svelte/native/16/soft/picture-in-picture'  import MaximizeIcon from '@master/icons-svelte/native/16/soft/maximize'  import MinimizeIcon from '@master/icons-svelte/native/16/soft/minimize'</script><div class="player player-video w-full max-w(560)" role="group" aria-label="Moonrise" style="--player-ratio: 16 / 9" {@attach attach}>  <video class="player-media" src="/demo/moonrise.mp4" poster="/demo/moonrise.jpg" controls preload="metadata" playsinline>    <track kind="captions" src="/demo/recording.vtt" srclang="en" label="English">  </video>  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">      <PlayIcon class="icon player-off" />      <PauseIcon class="icon player-on" />    </button>    <span class="player-elapsed">0:00</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">    <span class="player-duration">0:00</span>    <button type="button" class="player-button player-mute" aria-label="Mute" aria-pressed="false">      <VolumeIcon class="icon player-off" />      <VolumeOffIcon class="icon player-on" />    </button>    <button type="button" class="player-button player-captions" aria-label="Captions" aria-pressed="false">      <SubtitlesIcon class="icon" />    </button>    <button type="button" class="player-button player-pip" aria-label="Picture in picture" aria-pressed="false">      <PictureInPictureIcon class="icon" />    </button>    <button type="button" class="player-button player-fullscreen" aria-label="Full screen" aria-pressed="false">      <MaximizeIcon class="icon player-off" />      <MinimizeIcon class="icon player-on" />    </button>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import PlayIcon from '@master/icons-vue/native/20/soft/play'import PauseIcon from '@master/icons-vue/native/20/soft/pause'import VolumeIcon from '@master/icons-vue/native/16/soft/volume'import VolumeOffIcon from '@master/icons-vue/native/16/soft/volume-off'import SubtitlesIcon from '@master/icons-vue/native/16/soft/subtitles'import PictureInPictureIcon from '@master/icons-vue/native/16/soft/picture-in-picture'import MaximizeIcon from '@master/icons-vue/native/16/soft/maximize'import MinimizeIcon from '@master/icons-vue/native/16/soft/minimize'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="player player-video w-full max-w(560)" role="group" aria-label="Moonrise" style="--player-ratio: 16 / 9">    <video class="player-media" src="/demo/moonrise.mp4" poster="/demo/moonrise.jpg" controls preload="metadata" playsinline>      <track kind="captions" src="/demo/recording.vtt" srclang="en" label="English">    </video>    <div class="player-controls">      <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">        <PlayIcon class="icon player-off" />        <PauseIcon class="icon player-on" />      </button>      <span class="player-elapsed">0:00</span>      <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">      <span class="player-duration">0:00</span>      <button type="button" class="player-button player-mute" aria-label="Mute" aria-pressed="false">        <VolumeIcon class="icon player-off" />        <VolumeOffIcon class="icon player-on" />      </button>      <button type="button" class="player-button player-captions" aria-label="Captions" aria-pressed="false">        <SubtitlesIcon class="icon" />      </button>      <button type="button" class="player-button player-pip" aria-label="Picture in picture" aria-pressed="false">        <PictureInPictureIcon class="icon" />      </button>      <button type="button" class="player-button player-fullscreen" aria-label="Full screen" aria-pressed="false">        <MaximizeIcon class="icon player-off" />        <MinimizeIcon class="icon player-on" />      </button>    </div>  </div></template>
재생한 뒤 포인터를 가만히 두면 컨트롤 행이 사라집니다. 버튼이나 C 키로 자막을 켜 보세요.

동영상을 불러오기 전에도 프레임이 그 비율을 유지하도록 --player-ratio를 동영상의 비율로 설정하세요. 컨트롤 행은 미디어 플레이어에 주어진 공간에 따라 달라집니다. 26rem보다 좁으면 볼륨 슬라이더가 빠지고 음소거 버튼은 남으며, 24rem보다 좁으면 화면 속 화면과 경과 시간도 빠집니다. 따라서 휴대폰에서도 남은 컨트롤은 손가락으로 조작하는 데 필요한 44px의 조작 영역을 유지합니다.

#스크립트 없이

동작이 연결되기 전까지 미디어는 controls 속성을 유지하고 스타일시트는 미디어 플레이어의 컨트롤 행을 숨기므로, 미디어는 브라우저 자체의 컨트롤로 재생할 수 있습니다. 아래는 첫 번째 예시와 같은 마크업에서 스크립트만 뺀 것입니다.

스크립트 없이

<div class="player w-full max-w(480)" role="group" aria-label="A short recording">  <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M7.633 4.7883L14.865 8.9606A1.2 1.2 0 0 1 14.865 11.0394L7.633 15.2117A1.2 1.2 0 0 1 5.8333 14.1723L5.8333 5.8277A1.2 1.2 0 0 1 7.633 4.7883Z" />      </svg>      <svg class="icon player-on" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <rect x="5" y="3.75" width="3.3333" height="12.5" rx="0.8" /><rect x="11.6667" y="3.75" width="3.3333" height="12.5" rx="0.8" />      </svg>    </button>    <span class="player-elapsed">0:00</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">    <span class="player-duration">0:00</span>  </div></div>
import PlayIcon from '@master/icons-react/native/20/soft/play'import PauseIcon from '@master/icons-react/native/20/soft/pause'<div className="player w-full max-w(480)" role="group" aria-label="A short recording">  <audio className="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>  <div className="player-controls">    <button type="button" className="player-button player-play" aria-label="Play" aria-pressed="false">      <PlayIcon className="icon player-off" />      <PauseIcon className="icon player-on" />    </button>    <span className="player-elapsed">0:00</span>    <input type="range" className="slider player-seek" min="0" max="0" step="any" defaultValue="0" aria-label="Seek" />    <span className="player-duration">0:00</span>  </div></div>
<script>  import PlayIcon from '@master/icons-svelte/native/20/soft/play'  import PauseIcon from '@master/icons-svelte/native/20/soft/pause'</script><div class="player w-full max-w(480)" role="group" aria-label="A short recording">  <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">      <PlayIcon class="icon player-off" />      <PauseIcon class="icon player-on" />    </button>    <span class="player-elapsed">0:00</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">    <span class="player-duration">0:00</span>  </div></div>
<script setup>import PlayIcon from '@master/icons-vue/native/20/soft/play'import PauseIcon from '@master/icons-vue/native/20/soft/pause'</script><template>  <div class="player w-full max-w(480)" role="group" aria-label="A short recording">    <audio class="player-media" src="/demo/recording.m4a" controls preload="metadata"></audio>    <div class="player-controls">      <button type="button" class="player-button player-play" aria-label="Play" aria-pressed="false">        <PlayIcon class="icon player-off" />        <PauseIcon class="icon player-on" />      </button>      <span class="player-elapsed">0:00</span>      <input type="range" class="slider player-seek" min="0" max="0" step="any" value="0" aria-label="Seek">      <span class="player-duration">0:00</span>    </div>  </div></template>

#동작

player는 player 클래스가 있는 루트 요소를 받아, 연결한 동작을 해제하고 미디어에 컨트롤을 돌려주는 함수를 반환합니다.

app.js
import { player } from '@master/ui/behaviors/player.js'const detach = player(document.querySelector('.player'))

미디어가 유일한 기준입니다. 동작은 미디어 요소의 이벤트를 수신해 미디어 상태를 스타일시트가 읽는 속성에 반영하고, 모든 컨트롤은 스스로 바뀌는 대신 미디어에 변경을 요청합니다. 따라서 시스템의 미디어 키나 다른 스크립트처럼 다른 곳에서 미디어를 재생해도 컨트롤에 같은 상태가 표시됩니다.

  • 토글. 재생 버튼은 미디어가 재생되는 동안, 음소거 버튼은 음소거된 동안, 자막 버튼은 첫 번째 자막 트랙(captions 또는 subtitles)이 표시되는 동안, 화면 속 화면 버튼과 전체 화면 버튼은 동영상이 각 상태에 있는 동안 aria-pressed="true"가 됩니다. 토글은 ‘재생’이나 ‘음소거’처럼 하나의 이름을 유지하며, 상태는 aria-pressed가 알립니다. player-off와 player-on 두 면이 있으면 상태에 맞는 면을 보여 주고, 면이 하나뿐이면 켜져 있는 동안 오목한 영역 안으로 들어갑니다.
  • 시간. 탐색 트랙의 max는 재생 시간이고 value는 현재 시간이며, 문구로 된 aria-valuetext가 함께 설정됩니다. 경과 시간과 재생 시간은 각자의 요소에 작성되며, 미디어의 전체 길이가 한 시간 이상이면 시 단위까지 표시합니다. 사용자가 트랙을 드래그하는 동안에는 미디어가 손가락 아래의 손잡이를 움직이지 않습니다.
  • 불러온 부분. 현재 시간 주변에서 불러온 부분은 루트의 --player-buffered에 0부터 1까지의 값으로 설정되며, 트랙에서 재생된 부분 아래에 그려집니다.
  • 볼륨과 속도. 볼륨 슬라이더는 볼륨 값을 담으며, 미디어가 음소거된 동안에도 그 값을 유지한 채 한 단계 흐리게 표시됩니다. 기기 자체의 버튼으로만 볼륨을 조절하는 기기에서는 숨겨집니다. 속도 버튼은 popovertarget이 가리키는 메뉴를 엽니다. 메뉴 안의 각 menu-input 라디오 버튼이 재생 속도이며, 동작은 버튼에 속도를 작성하고 해당 라디오 버튼을 선택합니다.
  • 자막. 자막을 끄면 트랙은 disabled가 아니라 hidden이 되므로, 같은 트랙을 읽는 트랜스크립트는 큐를 그대로 유지합니다.
  • 전체 화면의 대상은 동영상이 아니라 미디어 플레이어이므로, 컨트롤 행이 영상 위에 남습니다. 동영상만 전체 화면으로 표시할 수 있는 iPhone에서는 시스템 자체의 플레이어가 사용됩니다.
  • 값. 반환된 함수에는 현재 시간을 초 단위로 나타내는 value가 있습니다. 이 값을 설정하면 그 위치로 이동합니다.
옵션기본값
step5방향키로 이동하는 초
jump10J와 L 키로 이동하는 초
volumeStep0.1ArrowUp과 ArrowDown 키로 볼륨이 바뀌는 크기
idle2500재생 중인 동영상의 컨트롤이 사라지기 전까지 포인터가 멈춰 있어야 하는 밀리초
valueText영어현재 재생 위치와 전체 재생 시간으로 만드는 탐색 트랙의 aria-valuetext로, 페이지 언어로 작성합니다
rateText1.5×속도 버튼이 각 재생 속도를 표시하는 문구

#키보드

키는 미디어 플레이어 안 어디에 포커스가 있든 작동하며, 동영상 화면을 클릭한 뒤에도 작동합니다. 컨트롤에 필요한 키는 그 컨트롤이 처리합니다. 포커스가 있는 버튼에서 Space 키를 누르면 버튼이 눌리고, 볼륨 슬라이더에서는 방향키가 볼륨을 조절하며, 속도 메뉴에서는 메뉴의 키를 사용합니다.

키동작
Space, K재생하거나 일시 정지합니다. 버튼에 포커스가 있으면 Space는 그 버튼을 누릅니다.
ArrowLeft, ArrowRight5초 뒤로 또는 앞으로 이동합니다. 탐색 트랙에서는 ArrowDown과 ArrowUp으로도 각각 뒤로 또는 앞으로 이동할 수 있습니다. 오른쪽에서 왼쪽으로 표시되는 플레이어에서는 좌우 방향키의 역할이 바뀝니다. 볼륨 슬라이더에서는 네이티브 입력처럼 방향키로 볼륨을 조절합니다.
J, L10초 뒤로 또는 앞으로 이동합니다.
ArrowUp, ArrowDown탐색 트랙과 볼륨 슬라이더 밖에서 볼륨을 10분의 1씩 높이거나 낮춥니다.
M음소거하거나 음소거를 해제합니다.
C동영상에 captions 또는 subtitles 트랙이 있으면 자막을 켜거나 끕니다.
F브라우저가 허용하는 경우 동영상의 전체 화면을 시작하거나 종료합니다.
Home, End처음이나 끝으로 이동합니다. 볼륨 슬라이더에서는 최소 볼륨과 최대 볼륨으로 설정합니다.

#접근성

  • 루트에 role="group"과 미디어의 이름을 담은 aria-label을 설정해 해당 미디어의 컨트롤임을 알리세요.
  • 모든 버튼의 기능을 페이지 언어로 이름에 표시하고, 상태가 바뀌어도 이름을 유지하세요. 상태는 aria-pressed가 나타냅니다.
  • 말소리가 있는 동영상에는 자막이 필요합니다. <track kind="captions">를 추가하세요. 영상이 없는 녹음에는 트랜스크립트가 필요합니다.
  • 소리가 있는 미디어를 자동으로 재생하지 마세요. 미디어 플레이어는 사용자가 요청할 때 재생합니다.
  • 버튼은 포인터 종류와 관계없이 32px이며, 터치 화면에서는 각 버튼의 조작 영역은 버튼 위아래로 확장되어 높이가 44px이 됩니다. 시간은 숫자가 바뀌어도 너비를 유지하므로 재생 중에 트랙이 흔들리지 않습니다.

#React, Svelte, Vue

player 컴포넌트는 src, video, poster, tracks로 미디어와 컨트롤 행을 렌더링하고 동작을 연결하며, 현재 시간과 재생 여부를 받아 외부로 전달합니다. React에서는 time과 playing을 onTimeChange, onPlayingChange와 함께 사용하고, Svelte에서는 바인딩 가능한 prop을, Vue에서는 v-model:time과 v-model:playing을 사용합니다. 외부에서 시간을 설정하면 그 위치로 이동하고, playing으로 재생과 일시 정지를 제어합니다. npx master-ui add player 명령을 실행해 프로젝트에 복사하세요. 컴포넌트의 구성과 사용 방법은 React, Svelte, Vue에서 확인할 수 있습니다.

ui/player.tsx
'use client'import { useEffect, useId, useRef, useState, type ComponentProps } from 'react'import { clock, player } from '@master/ui/behaviors/player.js'import { useBehavior } from './use-behavior'export interface PlayerTrack {  src: string  /** Captions carry the sounds as well as the words; subtitles only the words. */  kind?: 'captions' | 'subtitles'  srcLang: string  label: string  default?: boolean}export interface PlayerProps extends Omit<ComponentProps<'div'>, 'children' | 'ref'> {  /** The recording. */  src: string  /** A video: the frame, with the controls over its lower edge. Without it, an audio player. */  video?: boolean  /** The picture a video shows before it plays. */  poster?: string  /** Text tracks of a video; the first captions or subtitles track is what the captions button turns on. */  tracks?: PlayerTrack[]  /** What the recording is: the name of the player. */  label: string  /** The current time in seconds, when this component is told it. Setting it seeks. */  time?: number  defaultTime?: number  /** Called as the time moves, while it plays and when the reader seeks. */  onTimeChange?: (time: number) => void  /** Whether it plays, when this component is told it. */  playing?: boolean  /** Called when it starts or stops playing, by the reader or by the browser. */  onPlayingChange?: (playing: boolean) => void  /** The speeds of the speed menu. */  rates?: number[]  /** The names of the controls, in the page's language. */  labels?: Partial<typeof names>  /** What the seek track says for a time, in the page's language: its `aria-valuetext`. */  valueText?: (time: number, duration: number) => string  /** What the speed button says for a rate. */  rateText?: (rate: number) => string}/** The behavior finds its media as it attaches. Audio and video are two elements, so it attaches again when `video` changes. */const seen = (root: HTMLElement, options?: { video?: boolean, valueText?: (time: number, duration: number) => string, rateText?: (rate: number) => string }) => player(root, { ...(options?.valueText && { valueText: options.valueText }), ...(options?.rateText && { rateText: options.rateText }) })const names = { play: 'Play', seek: 'Seek', mute: 'Mute', volume: 'Volume', speed: 'Playback speed', captions: 'Captions', pip: 'Picture in picture', fullscreen: 'Full screen' }/** A recording with the page's own controls over the native element, which keeps its controls until the behavior attaches. */export function Player({ src, video, poster, tracks = [], label, time, defaultTime = 0, onTimeChange, playing, onPlayingChange, rates = [0.5, 0.75, 1, 1.25, 1.5, 2], labels, valueText, rateText, className, ...root }: PlayerProps) {  const name = { ...names, ...labels }  const speeds = `${useId()}-speeds`  const [first] = useState(time ?? defaultTime)  const media = useRef<HTMLVideoElement & HTMLAudioElement>(null)  const ref = useBehavior(seen, { video, valueText, rateText })  const live = useRef({ onTimeChange, onPlayingChange })  live.current = { onTimeChange, onPlayingChange }  /** What the owner and this component last agreed on: what was said, either way, is not said again. */  const said = useRef({ time: time ?? defaultTime, playing })  // What the media does comes out: its time and whether it plays. What the owner set is not said back.  useEffect(() => {    const element = media.current    if (!element) return    const controller = new AbortController()    const tell = () => {      const now = element.currentTime      if (now === said.current.time) return      said.current.time = now      live.current.onTimeChange?.(now)    }    const told = () => {      const now = !element.paused      if (now === said.current.playing) return      said.current.playing = now      live.current.onPlayingChange?.(now)    }    for (const type of ['timeupdate', 'seeked']) element.addEventListener(type, tell, { signal: controller.signal })    for (const type of ['play', 'pause', 'ended']) element.addEventListener(type, told, { signal: controller.signal })    if (first && element.currentTime !== first) element.currentTime = first    return () => controller.abort()  // The media is another element once `video` changes: its events are heard on the one that is there.  }, [first, video])  // What the owner sets goes in: a time a quarter second or more from the media's seeks, and playing plays.  useEffect(() => {    const element = media.current    if (time === undefined) return    said.current.time = time    if (element && Math.abs(element.currentTime - time) >= 0.25) element.currentTime = time  }, [time])  useEffect(() => {    const element = media.current    if (playing === undefined) return    said.current.playing = playing    if (!element || playing === !element.paused) return    if (playing) element.play()?.catch?.(() => {})    else element.pause()  }, [playing])  const Media = video ? 'video' : 'audio'  const rate = rates.includes(1) ? 1 : rates[0]  return (    <div className={[ 'player', video && 'player-video', className ].filter(Boolean).join(' ')} role="group" aria-label={label} ref={ref} {...root}>      <Media className="player-media" src={src} poster={video ? poster : undefined} controls preload="metadata" playsInline={video || undefined} ref={media}>        {video && tracks.map(track => <track key={track.src} src={track.src} kind={track.kind ?? 'captions'} srcLang={track.srcLang} label={track.label} default={track.default} />)}      </Media>      <div className="player-controls">        <button type="button" className="player-button player-play" aria-label={name.play} aria-pressed="false">          <svg className="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M6.1664 3.8652L11.8319 7.1338A1 1 0 0 1 11.8319 8.8662L6.1664 12.1348A1 1 0 0 1 4.6667 11.2686L4.6667 4.7314A1 1 0 0 1 6.1664 3.8652Z" /></svg>          <svg className="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><rect x="4" y="3" width="2.6667" height="10" rx="0.8" /><rect x="9.3333" y="3" width="2.6667" height="10" rx="0.8" /></svg>        </button>        <span className="player-elapsed">{clock(first)}</span>        <input type="range" className="slider player-seek" min={0} max={0} step="any" defaultValue={first} aria-label={name.seek} />        <span className="player-duration">{clock(0)}</span>        <button type="button" className="player-button player-mute" aria-label={name.mute} aria-pressed="false">          <svg className="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M10.3333 6C11.3333 7 11.3333 9 10.3333 10" /><path d="M12.3333 3.6667C14.6667 6 14.6667 10 12.3333 12.3333" /></svg>          <svg className="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M11 6.3333L14.3333 9.6667" /><path d="M14.3333 6.3333L11 9.6667" /></svg>        </button>        <input type="range" className="slider player-volume" min={0} max={1} step={0.05} defaultValue={1} aria-label={name.volume} />        <button type="button" className="player-button player-speed" popoverTarget={speeds} aria-label={name.speed}>{`${rate}×`}</button>        <div id={speeds} popover="auto" className="menu menu-top menu-end">          {rates.map(each => (            <label className="menu-item" key={each}>              <input className="menu-input" type="radio" name={speeds} value={each} defaultChecked={each === rate} />              {`${each}×`}            </label>          ))}        </div>        {video && tracks.length > 0 && (          <button type="button" className="player-button player-captions" aria-label={name.captions} aria-pressed="false">            <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="1" /><path d="M4.6667 6.6667L6 6.6667" /><path d="M8.6667 6.6667L11.3333 6.6667" /><path d="M4.6667 9.6667L7.3333 9.6667" /><path d="M10 9.6667L11.3333 9.6667" /></svg>          </button>        )}        {video && (          <button type="button" className="player-button player-pip" aria-label={name.pip} aria-pressed="false">            <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5.5 12L2.3333 12A1 1 0 0 1 1.3333 11L1.3333 3.6667A1 1 0 0 1 2.3333 2.6667L13 2.6667A1 1 0 0 1 14 3.6667L14 6.1667" /><rect x="8" y="8.6667" width="6.6667" height="4.6667" rx="1" /></svg>          </button>        )}        {video && (          <button type="button" className="player-button player-fullscreen" aria-label={name.fullscreen} aria-pressed="false">            <svg className="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.6667 6L2.6667 3.6667A1 1 0 0 1 3.6667 2.6667L6 2.6667" /><path d="M10 2.6667L12.3333 2.6667A1 1 0 0 1 13.3333 3.6667L13.3333 6" /><path d="M13.3333 10L13.3333 12.3333A1 1 0 0 1 12.3333 13.3333L10 13.3333" /><path d="M6 13.3333L3.6667 13.3333A1 1 0 0 1 2.6667 12.3333L2.6667 10" /></svg>            <svg className="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.6667 6L5 6A1 1 0 0 0 6 5L6 2.6667" /><path d="M10 2.6667L10 5A1 1 0 0 0 11 6L13.3333 6" /><path d="M13.3333 10L11 10A1 1 0 0 0 10 11L10 13.3333" /><path d="M6 13.3333L6 11A1 1 0 0 0 5 10L2.6667 10" /></svg>          </button>        )}      </div>    </div>  )}
ui/Player.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  export interface PlayerTrack {    src: string    /** Captions carry the sounds as well as the words; subtitles only the words. */    kind?: 'captions' | 'subtitles'    srclang: string    label: string    default?: boolean  }  export interface PlayerLabels {    play: string    seek: string    mute: string    volume: string    speed: string    captions: string    pip: string    fullscreen: string  }  export interface PlayerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    /** The recording. */    src: string    /** A video: the frame, with the controls over its lower edge. Without it, an audio player. */    video?: boolean    /** The picture a video shows before it plays. */    poster?: string    /** Text tracks of a video; the first captions or subtitles track is what the captions button turns on. */    tracks?: PlayerTrack[]    /** What the recording is: the name of the player. */    label: string    /** The current time in seconds. Bind it, or leave it out: it starts at 0. Setting it seeks. */    time?: number    onTimeChange?: (time: number) => void    /** Whether it plays. Bind it to play and pause from outside. */    playing?: boolean    onPlayingChange?: (playing: boolean) => void    /** The speeds of the speed menu. */    rates?: number[]    /** The names of the controls, in the page's language. */    labels?: Partial<PlayerLabels>    /** What the seek track says for a time, in the page's language: its `aria-valuetext`. */    valueText?: (time: number, duration: number) => string    /** What the speed button says for a rate. */    rateText?: (rate: number) => string  }</script><script lang="ts">  import { untrack } from 'svelte'  import { clock, player } from '@master/ui/behaviors/player.js'  import { behavior } from './behavior.svelte.js'  let { src, video, poster, tracks = [], label, time = $bindable(), onTimeChange, playing = $bindable(), onPlayingChange, rates = [0.5, 0.75, 1, 1.25, 1.5, 2], labels, valueText, rateText, class: className, ...root }: PlayerProps = $props()  const name = $derived({ play: 'Play', seek: 'Seek', mute: 'Mute', volume: 'Volume', speed: 'Playback speed', captions: 'Captions', pip: 'Picture in picture', fullscreen: 'Full screen', ...labels })  const id = $props.id()  const speeds = `${id}-speeds`  const first = untrack(() => time) ?? 0  const rate = $derived(rates.includes(1) ? 1 : rates[0])  let media = $state<HTMLMediaElement>()  // The behavior finds its media as it attaches. Audio and video are two elements, so it attaches again when `video` changes.  const seen = (element: HTMLElement, options?: { video?: boolean, valueText?: (time: number, duration: number) => string, rateText?: (rate: number) => string }) => player(element, { ...(options?.valueText && { valueText: options.valueText }), ...(options?.rateText && { rateText: options.rateText }) })  const attach = behavior(seen, () => ({ video, valueText, rateText }))  // What the owner sets goes in: a time a quarter second or more from the media's seeks, and playing plays.  $effect(() => {    const at = time    if (media && at !== undefined && Math.abs(media.currentTime - at) >= 0.25) media.currentTime = at  })  $effect(() => {    const play = playing    if (!media || play === undefined || play === !media.paused) return    if (play) media.play()?.catch?.(() => {})    else media.pause()  })  // What the media does comes out: its time and whether it plays. What the owner set is not said back.  const tell = () => {    const now = media!.currentTime    if (now === time) return    time = now    onTimeChange?.(now)  }  const told = () => {    const now = !media!.paused    if (now === playing) return    playing = now    onPlayingChange?.(now)  }</script>{#snippet controls()}  <div class="player-controls">    <button type="button" class="player-button player-play" aria-label={name.play} aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6.1664 3.8652L11.8319 7.1338A1 1 0 0 1 11.8319 8.8662L6.1664 12.1348A1 1 0 0 1 4.6667 11.2686L4.6667 4.7314A1 1 0 0 1 6.1664 3.8652Z" /></svg>      <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="3" width="2.6667" height="10" rx="0.8" /><rect x="9.3333" y="3" width="2.6667" height="10" rx="0.8" /></svg>    </button>    <span class="player-elapsed">{clock(first)}</span>    <input type="range" class="slider player-seek" min="0" max="0" step="any" value={first} aria-label={name.seek} />    <span class="player-duration">{clock(0)}</span>    <button type="button" class="player-button player-mute" aria-label={name.mute} aria-pressed="false">      <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M10.3333 6C11.3333 7 11.3333 9 10.3333 10" /><path d="M12.3333 3.6667C14.6667 6 14.6667 10 12.3333 12.3333" /></svg>      <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M11 6.3333L14.3333 9.6667" /><path d="M14.3333 6.3333L11 9.6667" /></svg>    </button>    <input type="range" class="slider player-volume" min="0" max="1" step="0.05" value="1" aria-label={name.volume} />    <button type="button" class="player-button player-speed" popovertarget={speeds} aria-label={name.speed}>{rate}×</button>    <div id={speeds} popover="auto" class="menu menu-top menu-end">      {#each rates as each (each)}        <label class="menu-item">          <input class="menu-input" type="radio" name={speeds} value={each} checked={each === rate} />          {each}×        </label>      {/each}    </div>    {#if video && tracks.length}      <button type="button" class="player-button player-captions" aria-label={name.captions} aria-pressed="false">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="1" /><path d="M4.6667 6.6667L6 6.6667" /><path d="M8.6667 6.6667L11.3333 6.6667" /><path d="M4.6667 9.6667L7.3333 9.6667" /><path d="M10 9.6667L11.3333 9.6667" /></svg>      </button>    {/if}    {#if video}      <button type="button" class="player-button player-pip" aria-label={name.pip} aria-pressed="false">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 12L2.3333 12A1 1 0 0 1 1.3333 11L1.3333 3.6667A1 1 0 0 1 2.3333 2.6667L13 2.6667A1 1 0 0 1 14 3.6667L14 6.1667" /><rect x="8" y="8.6667" width="6.6667" height="4.6667" rx="1" /></svg>      </button>      <button type="button" class="player-button player-fullscreen" aria-label={name.fullscreen} aria-pressed="false">        <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6667 6L2.6667 3.6667A1 1 0 0 1 3.6667 2.6667L6 2.6667" /><path d="M10 2.6667L12.3333 2.6667A1 1 0 0 1 13.3333 3.6667L13.3333 6" /><path d="M13.3333 10L13.3333 12.3333A1 1 0 0 1 12.3333 13.3333L10 13.3333" /><path d="M6 13.3333L3.6667 13.3333A1 1 0 0 1 2.6667 12.3333L2.6667 10" /></svg>        <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6667 6L5 6A1 1 0 0 0 6 5L6 2.6667" /><path d="M10 2.6667L10 5A1 1 0 0 0 11 6L13.3333 6" /><path d="M13.3333 10L11 10A1 1 0 0 0 10 11L10 13.3333" /><path d="M6 13.3333L6 11A1 1 0 0 0 5 10L2.6667 10" /></svg>      </button>    {/if}  </div>{/snippet}<!--  @component  A recording with the page's own controls over the native element, which keeps its controls until the behavior attaches.--><div class={['player', video && 'player-video', className]} role="group" aria-label={label} {@attach attach} {...root}>  {#if video}    <!-- The captions are the page's to give, in `tracks`; a video without speech needs none. -->    <!-- svelte-ignore a11y_media_has_caption -->    <video class="player-media" {src} {poster} controls preload="metadata" playsinline bind:this={media} ontimeupdate={tell} onseeked={tell} onplay={told} onpause={told} onended={told}>      {#each tracks as track (track.src)}        <track src={track.src} kind={track.kind ?? 'captions'} srclang={track.srclang} label={track.label} default={track.default} />      {/each}    </video>  {:else}    <audio class="player-media" {src} controls preload="metadata" bind:this={media} ontimeupdate={tell} onseeked={tell} onplay={told} onpause={told} onended={told}></audio>  {/if}  {@render controls()}</div>
ui/Player.vue
<script setup lang="ts">import { computed, onMounted, useId, useTemplateRef, watch } from 'vue'import { clock, player } from '@master/ui/behaviors/player.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })export interface PlayerTrack {  src: string  /** Captions carry the sounds as well as the words; subtitles only the words. */  kind?: 'captions' | 'subtitles'  srclang: string  label: string  default?: boolean}const { video, tracks = [], rates = [0.5, 0.75, 1, 1.25, 1.5, 2], labels, valueText, rateText } = defineProps<{  /** The recording. */  src: string  /** A video: the frame, with the controls over its lower edge. Without it, an audio player. */  video?: boolean  /** The picture a video shows before it plays. */  poster?: string  /** Text tracks of a video; the first captions or subtitles track is what the captions button turns on. */  tracks?: PlayerTrack[]  /** What the recording is: the name of the player. */  label: string  /** The speeds of the speed menu. */  rates?: number[]  /** The names of the controls, in the page's language. */  labels?: Partial<Record<'play' | 'seek' | 'mute' | 'volume' | 'speed' | 'captions' | 'pip' | 'fullscreen', string>>  /** What the seek track says for a time, in the page's language: its `aria-valuetext`. */  valueText?: (time: number, duration: number) => string  /** What the speed button says for a rate. */  rateText?: (rate: number) => string}>()/** The current time in seconds: `v-model:time`. It moves as the media plays; setting it seeks. */const time = defineModel<number>('time')/** Whether it plays: `v-model:playing`. */const playing = defineModel<boolean>('playing')/* A recording with the page's own controls over the native element, which keeps its controls until the behavior attaches. */const name = computed(() => ({ play: 'Play', seek: 'Seek', mute: 'Mute', volume: 'Volume', speed: 'Playback speed', captions: 'Captions', pip: 'Picture in picture', fullscreen: 'Full screen', ...labels }))const speeds = `${useId()}-speeds`const first = time.value ?? 0const rate = computed(() => (rates.includes(1) ? 1 : rates[0]))const root = useTemplateRef<HTMLDivElement>('root')const media = useTemplateRef<HTMLMediaElement>('media')// The behavior finds its media as it attaches. Audio and video are two elements, so it attaches again when `video` changes.const seen = (element: HTMLElement, options?: { video?: boolean, valueText?: (time: number, duration: number) => string, rateText?: (rate: number) => string }) => player(element, { ...(options?.valueText && { valueText: options.valueText }), ...(options?.rateText && { rateText: options.rateText }) })useBehavior(root, seen, () => ({ video, valueText, rateText }))// What the owner sets goes in: a time a quarter second or more from the media's seeks, and playing plays./** What the owner and this component last agreed on: what was said, either way, is not said again. */const said: { time?: number, playing?: boolean } = { time: time.value, playing: playing.value }const seek = () => {  if (time.value === undefined) return  said.time = time.value  if (media.value && Math.abs(media.value.currentTime - time.value) >= 0.25) media.value.currentTime = time.value}const play = () => {  const element = media.value  if (playing.value === undefined) return  said.playing = playing.value  if (!element || playing.value === !element.paused) return  if (playing.value) element.play()?.catch?.(() => {})  else element.pause()}onMounted(() => { seek(); play() })watch(time, seek, { flush: 'post' })watch(playing, play, { flush: 'post' })// What the media does comes out: its time and whether it plays. What the owner set is not said back.const tell = () => {  if (!media.value || media.value.currentTime === said.time) return  said.time = media.value.currentTime  time.value = said.time}const told = () => {  if (!media.value || !media.value.paused === said.playing) return  said.playing = !media.value.paused  playing.value = said.playing}</script><template>  <div class="player" :class="{ 'player-video': video }" role="group" :aria-label="label" ref="root" v-bind="$attrs">    <video v-if="video" class="player-media" ref="media" :src="src" :poster="poster" controls preload="metadata" playsinline @timeupdate="tell" @seeked="tell" @play="told" @pause="told" @ended="told">      <track v-for="track in tracks" :key="track.src" :src="track.src" :kind="track.kind ?? 'captions'" :srclang="track.srclang" :label="track.label" :default="track.default">    </video>    <audio v-else class="player-media" ref="media" :src="src" controls preload="metadata" @timeupdate="tell" @seeked="tell" @play="told" @pause="told" @ended="told" />    <div class="player-controls">      <button type="button" class="player-button player-play" :aria-label="name.play" aria-pressed="false">        <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6.1664 3.8652L11.8319 7.1338A1 1 0 0 1 11.8319 8.8662L6.1664 12.1348A1 1 0 0 1 4.6667 11.2686L4.6667 4.7314A1 1 0 0 1 6.1664 3.8652Z" /></svg>        <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="3" width="2.6667" height="10" rx="0.8" /><rect x="9.3333" y="3" width="2.6667" height="10" rx="0.8" /></svg>      </button>      <span class="player-elapsed">{{ clock(first) }}</span>      <input type="range" class="slider player-seek" min="0" max="0" step="any" :value.attr="first" :aria-label="name.seek">      <span class="player-duration">{{ clock(0) }}</span>      <button type="button" class="player-button player-mute" :aria-label="name.mute" aria-pressed="false">        <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M10.3333 6C11.3333 7 11.3333 9 10.3333 10" /><path d="M12.3333 3.6667C14.6667 6 14.6667 10 12.3333 12.3333" /></svg>        <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6 6L4.4365 6A0.6 0.6 0 0 0 4.8378 5.846L6.9986 3.9013A0.6 0.6 0 0 1 8 4.3472L8 11.6528A0.6 0.6 0 0 1 6.9986 12.0987L4.8378 10.154A0.6 0.6 0 0 0 4.4365 10L2.6 10A0.6 0.6 0 0 1 2 9.4L2 6.6A0.6 0.6 0 0 1 2.6 6Z" /><path d="M11 6.3333L14.3333 9.6667" /><path d="M14.3333 6.3333L11 9.6667" /></svg>      </button>      <input type="range" class="slider player-volume" min="0" max="1" step="0.05" value="1" :aria-label="name.volume">      <button type="button" class="player-button player-speed" :popovertarget="speeds" :aria-label="name.speed">{{ rate }}×</button>      <div :id="speeds" popover="auto" class="menu menu-top menu-end">        <label v-for="each in rates" :key="each" class="menu-item">          <input class="menu-input" type="radio" :name="speeds" :value="each" :checked="each === rate">          {{ each }}×        </label>      </div>      <button v-if="video && tracks.length" type="button" class="player-button player-captions" :aria-label="name.captions" aria-pressed="false">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="3" width="12" height="10" rx="1" /><path d="M4.6667 6.6667L6 6.6667" /><path d="M8.6667 6.6667L11.3333 6.6667" /><path d="M4.6667 9.6667L7.3333 9.6667" /><path d="M10 9.6667L11.3333 9.6667" /></svg>      </button>      <template v-if="video">        <button type="button" class="player-button player-pip" :aria-label="name.pip" aria-pressed="false">          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5.5 12L2.3333 12A1 1 0 0 1 1.3333 11L1.3333 3.6667A1 1 0 0 1 2.3333 2.6667L13 2.6667A1 1 0 0 1 14 3.6667L14 6.1667" /><rect x="8" y="8.6667" width="6.6667" height="4.6667" rx="1" /></svg>        </button>        <button type="button" class="player-button player-fullscreen" :aria-label="name.fullscreen" aria-pressed="false">          <svg class="icon player-off" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6667 6L2.6667 3.6667A1 1 0 0 1 3.6667 2.6667L6 2.6667" /><path d="M10 2.6667L12.3333 2.6667A1 1 0 0 1 13.3333 3.6667L13.3333 6" /><path d="M13.3333 10L13.3333 12.3333A1 1 0 0 1 12.3333 13.3333L10 13.3333" /><path d="M6 13.3333L3.6667 13.3333A1 1 0 0 1 2.6667 12.3333L2.6667 10" /></svg>          <svg class="icon player-on" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6667 6L5 6A1 1 0 0 0 6 5L6 2.6667" /><path d="M10 2.6667L10 5A1 1 0 0 0 11 6L13.3333 6" /><path d="M13.3333 10L11 10A1 1 0 0 0 10 11L10 13.3333" /><path d="M6 13.3333L6 11A1 1 0 0 0 5 10L2.6667 10" /></svg>        </button>      </template>    </div>  </div></template>

#클래스

클래스설명
player오디오 녹음의 플레이어입니다. 컨트롤 행을 6px 안쪽에 담은 떠 있는 표면입니다. role="group"과 녹음을 나타내는 aria-label을 지정하세요.
player-video동영상의 플레이어입니다. 프레임 자체가 표면 모서리 반경을 가진 어두운 영역이 되고, 컨트롤은 아래쪽 가장자리 위에 어두운 색 구성표로 놓입니다. 동영상이 재생 중이고 포인터가 움직이지 않으면 컨트롤이 서서히 사라집니다.적용할 클래스는 player입니다
player-mediacontrols 속성이 있는 네이티브 audio 또는 video 요소입니다. 이 속성은 동작이 연결될 때 제거하는 대체 수단입니다.
player-controls버튼, 시간, 탐색 트랙을 담은 행입니다. 미디어에 controls 속성이 있는 동안에는 숨겨집니다.
player-button아이콘 하나를 담은 32px 크기의 강조를 줄인 컨트롤로, 터치 화면에서는 조작 영역의 높이가 44px입니다. 토글에는 aria-pressed와 고정된 이름을 지정합니다. player-off와 player-on 면이 있으면 상태에 맞는 면을 표시하고, 면이 하나면 켜져 있는 동안 오목한 영역 안으로 들어갑니다.
player-play재생과 일시 정지 버튼으로, 아이콘이 한 단계 더 큽니다. 미디어가 재생 중이면 눌린 상태입니다. 이름은 Play로 지정하세요.적용할 클래스는 player-button입니다
player-mute소리와 음소거 버튼으로, 미디어가 음소거되어 있으면 눌린 상태입니다. 이름은 Mute로 지정하세요.적용할 클래스는 player-button입니다
player-speed재생 속도를 숫자로 표시하며, popovertarget으로 속도 메뉴를 엽니다. 메뉴는 label 항목으로 구성되며, 각 항목은 재생 속도를 value로 가진 라디오 menu-input을 감쌉니다.적용할 클래스는 player-button입니다
player-captions자막 켜기·끄기 버튼으로, 첫 번째 captions 또는 subtitles 트랙이 표시되는 동안 눌린 상태입니다. 동영상에 해당 트랙이 없으면 숨겨집니다.적용할 클래스는 player-button입니다
player-pip화면 속 화면 버튼으로, 동영상이 별도 창에서 재생되는 동안 눌린 상태입니다. 브라우저가 지원하지 않거나 플레이어 너비가 24rem보다 좁으면 숨겨집니다.적용할 클래스는 player-button입니다
player-fullscreen전체 화면 버튼으로, 플레이어가 화면을 가득 채우는 동안 눌린 상태입니다. 브라우저가 허용하지 않으면 숨겨집니다.적용할 클래스는 player-button입니다
player-off토글이 꺼져 있을 때의 면으로, 재생, 소리, 전체 화면 진입 아이콘입니다.
player-on토글이 켜져 있을 때의 면으로, 일시 정지, 음소거, 전체 화면 종료 아이콘입니다.
player-elapsed재생된 시간을 작은 고정폭 숫자로 표시합니다. 플레이어 너비가 24rem보다 좁으면 생략됩니다. 동작이 기록합니다.
player-duration미디어의 전체 길이를 작은 고정폭 숫자로 표시합니다. 미디어의 길이를 확인할 수 있게 되면 동작이 값을 표시합니다.
player-seek탐색 트랙은 행에서 사용할 수 있는 너비를 채우는 슬라이더입니다. 로드된 구간을 바탕에 표시하고 재생된 구간을 그 위에 겹쳐 그립니다. 동작이 max, value, 그리고 말로 풀어 쓴 aria-valuetext를 설정합니다.
player-volume볼륨입니다. 음소거 버튼 옆의 0부터 1까지의 짧은 슬라이더로, 플레이어 너비가 26rem보다 좁으면 생략되고 기기가 페이지에서 볼륨을 설정하도록 허용하지 않으면 숨겨집니다.

탐색 트랙과 볼륨은 slider 입력 요소이며, 속도 메뉴는 menu-input 라디오 버튼이 있는 label 항목으로 구성된 menu입니다.

#사용자 지정 속성

속성기본값설명
--player-buffered0미디어가 로드된 비율을 0부터 1까지의 값으로 탐색 트랙에 표시합니다. 동작이 값을 설정합니다.player에 설정합니다
--player-idle0재생 중인 동영상에서 한동안 포인터 움직임이 없어 컨트롤이 사라질 때는 1, 그 외에는 0입니다. 동작이 설정합니다.player에 설정합니다
--player-ratio동영상이 로드되기 전에 확보하는 가로세로 비율입니다. 지정하지 않으면 프레임이 동영상 고유의 비율을 따릅니다.player-video에 설정합니다
--player-inset6px오디오 플레이어의 표면과 컨트롤 사이의 간격player에 설정합니다
--player-radiuscalc(var(--radius-control-sm) + var(--player-inset) / var(--corner-scale))플레이어의 모서리 반경입니다. 작은 컨트롤의 모서리 반경에 안쪽 여백을 더한 값이어서 모서리에 있는 32px 버튼과 동심을 이루며, 동영상에서는 표면의 모서리 반경입니다.player에 설정합니다

#소스

@master/ui/components/player.css
/* * Player: controls of the page's own over a native <audio> or <video>, which keeps its semantics, its keys in * the browser's menus and its fallback. * The media keeps the controls attribute in the markup. While it has it the browser's controls are what is seen * and the player's are hidden, so a page without the script still plays; the behavior removes the attribute as it * attaches and puts it back as it detaches. * An audio player is one raised sheet: a row of quiet 32px buttons, the times in small tabular figures and a seek * track that is the slider's own native range input, 6px inside a corner of the small control's radius plus that * inset, so a 32px button in a corner of the row is concentric with it. * A video player is the frame itself: the picture covers a dark field with a surface's corner, and the same row * stands over its lower edge on a shade that rises from the edge. That row is drawn in the dark scheme in both * themes, as a screen is dark, so every token it reads resolves to its obsidian value. * State is drawn from attributes. A toggle has aria-pressed: one with two faces (play and pause, sound and * silence, into and out of full screen) shows the face for its state, one with a single face (captions, picture in * picture) sinks into a well while it is on. The behavior mirrors the media into them: the play button is pressed * while the media plays, the mute button while it is muted. What has loaded is --player-buffered, from 0 to 1, * drawn on the seek track under what has played. * Over a video the row fades while the media plays and the pointer has not moved for a while (--player-idle, set * by the behavior). It never fades while anything in the player has keyboard focus or its speed menu is open, and * never for a reader who asks for reduced motion. * The row answers the room the player is given: narrower than 26rem the volume slider steps out and the mute * button stays; narrower than 24rem picture in picture and the time so far step out too. * Without the behavior the media keeps the browser's controls. Without container queries the row keeps every * control at every width. */@layer components.ui {  .player {    --player-inset: 6px;    /* The inset is added after the corner scale, so it is passed divided by it. */    --player-radius: calc(var(--radius-control-sm) + var(--player-inset) / var(--corner-scale));    --player-buffered: 0;    --player-idle: 0;    --surface-color: var(--color-surface-raised);    position: relative;    display: grid;    min-width: 0;    margin: 0;    padding: var(--player-inset);    border-radius: calc(var(--player-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    @apply --surface-sheet;    color: var(--color-text-body);    box-shadow: var(--shadow-raised);    container-type: inline-size;    /*     * The frame of a video. The picture fills it and the controls stand over its lower edge. A corner of a     * surface, the dark field around the picture, and an inward hairline so a pale frame does not bleed out.     */    &.player-video {      --player-radius: var(--radius-surface);      --surface-color: var(--color-surface-media);      padding: 0;      overflow: hidden;      background: var(--color-surface-media);      box-shadow: var(--shadow-raised);      /* The inward line every picture gets, drawn over the picture and the controls alike. */      outline: 1px solid var(--color-line-image);      outline-offset: -1px;      .player-media {        grid-area: 1 / 1;        width: 100%;        height: auto;        aspect-ratio: var(--player-ratio, auto);        object-fit: contain;      }      .player-controls {        grid-area: 1 / 1;        align-self: end;        /* 8px from the frame's edges, so a corner button's corner is concentric with the frame's 16. */        padding: 2.5rem .5rem .5rem;        background: linear-gradient(to top, var(--color-on-image-scrim), transparent);        /* A screen is dark: the controls over it read every token as obsidian, in both themes. */        color-scheme: dark;        color: var(--color-on-image);        transition: opacity var(--duration-base) var(--easing-glide);      }      /* The times read on any picture: white, with a shade under the figures. */      .player-elapsed,      .player-duration {        color: var(--color-on-image);        text-shadow: 0 1px 2px var(--color-on-image-shade);      }    }    /* Full screen: the frame becomes the screen, square and with no edge. */    &:fullscreen {      grid-template-rows: minmax(0, 1fr);      border-radius: 0;      box-shadow: none;      outline: 0;      .player-media {        height: 100%;      }    }    /* While the media keeps the browser's controls, they are the controls: the script has not attached. */    &:has(.player-media[controls]) .player-controls {      display: none;    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /*   * While the video plays, the pointer is still and nothing in the player has keyboard focus or an open menu,   * the controls fade out of the picture, and the pointer with them. Any movement brings them back at once.   */  @media (prefers-reduced-motion: no-preference) {    .player-video:has(.player-play[aria-pressed="true"]):not(:has(:focus-visible, .menu:popover-open)) .player-controls {      opacity: calc(1 - var(--player-idle));    }    @container style(--player-idle: 1) {      .player-video:has(.player-play[aria-pressed="true"]):not(:has(:focus-visible, .menu:popover-open)) .player-media {        cursor: none;      }    }  }  /*   * Captions the browser draws over the picture rise above the controls while they show, and settle to the   * edge as they fade. Chromium and WebKit name the box the cues stand in; elsewhere they stay at the edge.   */  .player-video .player-media::-webkit-media-text-track-container {    translate: 0 calc(-1 * var(--player-cue-lift, 2.75rem));    transition: translate var(--duration-base) var(--easing-glide);  }  @media (prefers-reduced-motion: no-preference) {    .player-video:has(.player-play[aria-pressed="true"]):not(:has(:focus-visible, .menu:popover-open)) .player-media {      --player-cue-lift: calc(2.75rem * (1 - var(--player-idle)));    }  }  /* The native element. Audio without controls draws nothing; a video is the picture. */  .player-media {    display: block;    width: 100%;    max-width: 100%;    margin: 0;    border: 0;    outline: 0;  }  /* The row of controls: buttons, the times and the seek track between them. */  .player-controls {    display: flex;    align-items: center;    gap: .25rem;    min-width: 0;    margin: 0;  }  /*   * A control of the player: a quiet 32px square with one icon, or the speed as a few figures. It answers the   * pointer as a quiet button does, rising onto a sheet; it is never a hue.   */  .player-button {    --icon-size: 1rem;    position: relative;    display: inline-flex;    flex: none;    align-items: center;    justify-content: center;    min-width: 2rem;    height: 2rem;    margin: 0;    padding: 0;    border: 0;    border-radius: calc(var(--radius-control-sm) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: transparent;    color: inherit;    font: var(--font-weight-control) .75rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    appearance: none;    cursor: pointer;    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    touch-action: manipulation;    transition-property: box-shadow, color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    &[hidden] {      display: none;    }    @media (hover: hover) {      &:hover:not(:disabled) {        @apply --surface-sheet;        color: var(--color-text-strong);        box-shadow: var(--shadow-raised);      }    }    /* Held, and a toggle with one face that is on: sunk into a well. */    &:active:not(:disabled),    &[aria-pressed="true"]:not(:has(.player-on)),    &:has(+ .menu:popover-open) {      background: var(--color-surface-inset);      color: var(--color-text-strong);      box-shadow: var(--shadow-pressed);      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;    }    &:disabled {      color: var(--color-text-disabled);      cursor: not-allowed;    }    /* Controls stand 4px apart, so on touch a target reaches 44px above and below and keeps its width. */    @media (pointer: coarse) {      &::after {        @apply --touch-target-block;      }    }    /*     * The well of a toggle that is on, or of the speed while its menu is open, is gone with its shadow: a firmer     * outline in the highlight keeps it, and gives way to the focus ring, as a quiet button's does.     */    @media (forced-colors: active) {      &:is([aria-pressed="true"]:not(:has(.player-on)), :has(+ .menu:popover-open)):not(:focus-visible) {        outline: 2px solid Highlight;        outline-offset: -2px;      }      &:focus-visible {        outline-color: Highlight;      }      &:disabled {        color: GrayText;      }    }  }  /* The speed: a few figures, a little wider than an icon. */  .player-speed {    padding-inline: .5rem;  }  /* Play is the control a reader looks for first: its icon is a size up. */  .player-play {    --icon-size: 1.125rem;  }  /* Mute stands close to its volume slider, so the two read as one control. */  .player-mute {    margin-inline-end: -.125rem;  }  /* Captions, picture in picture and full screen belong to a picture: an audio player leaves them out. */  .player-captions,  .player-pip,  .player-fullscreen {    .player:not(.player-video) & {      display: none;    }  }  /*   * In a player narrower than 24rem, picture in picture and the time so far step out of the row, the length   * stays, and the controls close up.   */  @container (width < 24rem) {    .player-pip,    .player-elapsed {      display: none;    }    .player-controls {      gap: 0;    }  }  /* Muted, the volume slider keeps the level it will return to, a step quieter. */  .player-controls:has(.player-mute[aria-pressed="true"]) .player-volume {    opacity: .45;  }  /*   * The two faces of a toggle: the one for off (play, sound, into full screen) and the one for on (pause,   * silence, out of full screen). Only the face for the button's aria-pressed is shown.   */  .player-on {    display: none;  }  .player-button[aria-pressed="true"] {    .player-on {      display: inline-block;    }    .player-off {      display: none;    }  }  /* How much has played, and how long it is: small tabular figures, as wide whatever the digits. */  .player-elapsed,  .player-duration {    flex: none;    min-width: 2.25rem;    margin: 0;    color: var(--color-text-muted);    font-size: .75rem;    line-height: 1;    font-variant-numeric: tabular-nums;    text-align: center;    white-space: nowrap;  }  /*   * The seek track: the slider's own range input, as long as the row allows. Under what has played, what has   * loaded is a quiet share of the same ink, as far as --player-buffered.   */  .player-seek {    /* What has loaded and not played: a quiet share of the fill's own ink, read where the slider sets that ink. */    --player-buffer-color: color-mix(in oklab, var(--slider-color, var(--color-surface-inverse)) 24%, transparent);    flex: 1 1 0;    width: auto;    min-width: 3rem;    margin-inline: .25rem;    &::-webkit-slider-runnable-track {      background:        linear-gradient(90deg, var(--slider-color) var(--slider-fill), transparent 0),        linear-gradient(90deg, var(--player-buffer-color) calc(var(--player-buffered) * 100%), transparent 0)        var(--color-surface-inset);    }    &::-moz-range-track {      background: linear-gradient(90deg, var(--player-buffer-color) calc(var(--player-buffered) * 100%), transparent 0) var(--color-surface-inset);    }    &:dir(rtl)::-webkit-slider-runnable-track {      background:        linear-gradient(270deg, var(--slider-color) var(--slider-fill), transparent 0),        linear-gradient(270deg, var(--player-buffer-color) calc(var(--player-buffered) * 100%), transparent 0)        var(--color-surface-inset);    }    &:dir(rtl)::-moz-range-track {      background: linear-gradient(270deg, var(--player-buffer-color) calc(var(--player-buffered) * 100%), transparent 0) var(--color-surface-inset);    }    @media (forced-colors: active) {      &::-webkit-slider-runnable-track {        background: linear-gradient(90deg, Highlight var(--slider-fill), transparent 0) Canvas;      }      &:dir(rtl)::-webkit-slider-runnable-track {        background: linear-gradient(270deg, Highlight var(--slider-fill), transparent 0) Canvas;      }      &::-moz-range-track,      &:dir(rtl)::-moz-range-track {        background: Canvas;      }    }  }  /* The volume: a short slider beside the mute button. Where the player is narrow, the mute button is enough. */  .player-volume {    flex: none;    width: 4.5rem;    margin-inline: .25rem .5rem;    &[hidden] {      display: none;    }    @container (width < 26rem) {      display: none;    }  }}