(
parent: ShadowRoot | HTMLElement,
callbacks: ControlsCallbacks,
options: ControlsOptions = {},
)
| 47 | } |
| 48 | |
| 49 | export function createControls( |
| 50 | parent: ShadowRoot | HTMLElement, |
| 51 | callbacks: ControlsCallbacks, |
| 52 | options: ControlsOptions = {}, |
| 53 | ): { |
| 54 | updateTime: (current: number, duration: number) => void; |
| 55 | updatePlaying: (playing: boolean) => void; |
| 56 | updateSpeed: (speed: number) => void; |
| 57 | updateMuted: (muted: boolean) => void; |
| 58 | updateVolume: (volume: number) => void; |
| 59 | setVolumeControlsHidden: (hidden: boolean) => void; |
| 60 | show: () => void; |
| 61 | hide: () => void; |
| 62 | destroy: () => void; |
| 63 | } { |
| 64 | const presets = options.speedPresets ?? SPEED_PRESETS; |
| 65 | |
| 66 | const controls = document.createElement("div"); |
| 67 | controls.className = "hfp-controls"; |
| 68 | // Keep overlay interactions from falling through to the host-level click toggle. |
| 69 | controls.addEventListener("click", (e) => { |
| 70 | e.stopPropagation(); |
| 71 | }); |
| 72 | |
| 73 | const playBtn = document.createElement("button"); |
| 74 | playBtn.className = "hfp-play-btn"; |
| 75 | playBtn.type = "button"; |
| 76 | // Both glyphs stay in the DOM, stacked; toggling `hfp-playing` crossfade-morphs |
| 77 | // between them (see styles.ts) instead of swapping innerHTML, which would kill |
| 78 | // the transition. |
| 79 | playBtn.innerHTML = `<span class="hfp-ico hfp-ico-play">${PLAY_ICON}</span><span class="hfp-ico hfp-ico-pause">${PAUSE_ICON}</span>`; |
| 80 | playBtn.setAttribute("aria-label", "Play"); |
| 81 | |
| 82 | const scrubber = document.createElement("div"); |
| 83 | scrubber.className = "hfp-scrubber"; |
| 84 | const progress = document.createElement("div"); |
| 85 | progress.className = "hfp-progress"; |
| 86 | progress.style.width = "0%"; |
| 87 | scrubber.appendChild(progress); |
| 88 | |
| 89 | const time = document.createElement("span"); |
| 90 | time.className = "hfp-time"; |
| 91 | time.textContent = "0:00 / 0:00"; |
| 92 | |
| 93 | const speedWrap = document.createElement("div"); |
| 94 | speedWrap.className = "hfp-speed-wrap"; |
| 95 | |
| 96 | const speedBtn = document.createElement("button"); |
| 97 | speedBtn.className = "hfp-speed-btn"; |
| 98 | speedBtn.type = "button"; |
| 99 | speedBtn.textContent = "1x"; |
| 100 | speedBtn.setAttribute("aria-label", "Playback speed"); |
| 101 | |
| 102 | const speedMenu = document.createElement("div"); |
| 103 | speedMenu.className = "hfp-speed-menu"; |
| 104 | speedMenu.setAttribute("role", "menu"); |
| 105 | for (const preset of presets) { |
| 106 | const item = document.createElement("button"); |
no test coverage detected