From 80f1b6c729ebfec2bbfcedb17adab18f9dce6e1f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Nov 2026 22:14:26 -0700 Subject: PAFF songs and albums play in a bar that stays while you go about the app. "Can you work with PAFF again to make songs embed nicely in nostr posts?" … "From the start please" (Adam, 2026-11-17). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A paff.club song or album link in a post (/song/, /album/, also under /play/) is a slim card: cover art, "Song · Artist" and its line from the page's preview, a ▶ and a ↗ out to PAFF. The tap doesn't play it in the post. PAFF's 64 px bar player (/embed/song|album/?bar=1, the link's query kept) loads into a music bar pinned above the bottom nav, or under the feed column on desktop. The bar lives in the document body outside render(), so the feed's windowing never drops it: the music carries on through scrolling, threads and other tabs. The bar is never moved, because a moved iframe reloads. Another song changes its src, and × removes it. The card shows "Playing below" with an equaliser while its song is in the bar. The Post button, the new-posts pill and the page's bottom padding move up while the bar is open. link-preview-test (stand-in paff.club): the song card has its cover and title with no frame; a tap opens the bar above the nav at /embed/song/abc123?bar=1; the bar is still there on the Wallet page; × closes it. Checked against the real paff.club: the bar player for Daft Punk's Harder, Better, Faster, Stronger played in a frame and answered a pause command. features-smoke and feed-when pass. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- src/features/messages.js | 82 +++++++++++++++++++++++++++++++++++++++++++++- src/i18n.js | 3 ++ src/style.css | 48 +++++++++++++++++++++++++++ tools/link-preview-test.js | 31 ++++++++++++++++-- 4 files changed, 161 insertions(+), 3 deletions(-) diff --git a/src/features/messages.js b/src/features/messages.js index 797534e..8f8bdd4 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -7483,7 +7483,7 @@ export function messagesFeature(ctx) { if (!url) continue; if ((md && md[1]) || /\.(png|jpe?g|gif|webp|avif)(\?[^\s]*)?$/i.test(url)) urls.push(url); else if (youtubeId(url)) urls.push('https://i.ytimg.com/vi/' + youtubeId(url) + '/hqdefault.jpg'); - else if (paffEmbedUrl(url) && previews.get(url)?.image) urls.push(previews.get(url).image); + else if ((paffEmbedUrl(url) || paffMusicUrl(url)) && previews.get(url)?.image) urls.push(previews.get(url).image); } return urls; } @@ -9054,6 +9054,78 @@ export function messagesFeature(ctx) { }, { threshold: [0, 0.5] }); paffObserver.observe(box); } + // A PAFF song or album link: a slim card in the post (cover, title, ▶). + // The tap doesn't play it there: PAFF's slim player loads into a bar + // pinned above the bottom nav, outside the page, so the music carries on + // while you scroll, open threads, change tabs ("make songs embed nicely + // in nostr posts" … "From the start please", Adam, 2026-11-17). The bar + // is never moved (a moved iframe reloads); a new song changes its src, + // its × removes it. + function paffMusicUrl(url) { + let u; + try { u = new URL(url); } catch { return null; } + if (u.hostname !== 'paff.club' && u.hostname !== 'www.paff.club') return null; + const m = u.pathname.match(/^\/(?:play\/)?(song|album)\/([^/]+)\/?$/i); + if (!m) return null; + const q = new URLSearchParams(u.search); + q.set('bar', '1'); + return 'https://paff.club/embed/' + m[1].toLowerCase() + '/' + m[2] + '?' + q; + } + let musicBar = null, musicUrl = null; + function playInBar(url, title) { + if (typeof document === 'undefined') return; + if (!musicBar) { + musicBar = document.createElement('div'); + musicBar.className = 'music-bar'; + const f = document.createElement('iframe'); + f.allow = 'autoplay; fullscreen; picture-in-picture'; + f.referrerPolicy = 'strict-origin-when-cross-origin'; + const x = document.createElement('button'); + x.type = 'button'; x.className = 'music-close'; x.textContent = '×'; + x.setAttribute('aria-label', t('musicClose')); x.title = t('musicClose'); + x.onclick = (e) => { e.stopPropagation(); closeMusic(); }; + musicBar.append(f, x); + document.body.append(musicBar); + } + const f = musicBar.querySelector('iframe'); + f.title = title || 'PAFF'; + if (musicUrl !== url) f.src = paffMusicUrl(url); + musicUrl = url; + document.body.classList.add('music-open'); + render(); + } + function closeMusic() { + if (musicBar) { musicBar.remove(); musicBar = null; } + musicUrl = null; + document.body.classList.remove('music-open'); + render(); + } + function paffSongCard(url, pv) { + const on = musicUrl === url; + return h('div', { + class: 'paff-song' + (on ? ' on' : ''), role: 'button', tabindex: '0', + onClick: (e) => { + if (e.target.closest('.paff-song-open')) return; + e.stopPropagation(); e.preventDefault(); + playInBar(url, pv?.title); + }, + }, + pv?.image ? h('img', { + class: 'paff-song-cover', loading: 'lazy', alt: '', + src: !feedPaint || feedMedia(pv.image) ? pv.image : undefined, + onError: (e) => { e.target.style.visibility = 'hidden'; }, + }) : h('div', { class: 'paff-song-cover' }), + h('div', { class: 'paff-song-meta' }, + h('div', { class: 'paff-song-title' }, pv?.title || t('musicSong')), + h('div', { class: 'small faint' }, on ? t('musicPlayingBelow') : pv?.description || 'paff.club')), + h('span', { class: 'paff-song-play', 'aria-hidden': 'true', html: on + ? '' + : '' }), + h('a', { + class: 'paff-song-open', href: url, target: '_blank', rel: 'noopener noreferrer', + title: t('openOnPaff'), onClick: (e) => e.stopPropagation(), + }, '↗')); + } function paffEmbed(url, pv) { const embed = paffEmbedUrl(url); const load = (box) => { @@ -10893,6 +10965,14 @@ export function messagesFeature(ctx) { }); } if (youtubeId(url)) return youtubeEmbed(url, youtubeId(url)); + if (!label && paffMusicUrl(url)) { + let pv = previews.get(url) || null; + if (feedPaint) { + if (!feedPaint.media.has('pv:' + url)) feedPaint.media.set('pv:' + url, pv); + pv = feedPaint.media.get('pv:' + url); + } + return paffSongCard(url, pv); + } if (!label && paffEmbedUrl(url)) { let pv = previews.get(url) || null; if (feedPaint) { diff --git a/src/i18n.js b/src/i18n.js index d83633f..76efc72 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -353,6 +353,9 @@ const STR = { videoMute: 'Mute', openInYouTube: 'Open on YouTube', openOnPaff: 'Open on PAFF', + musicClose: 'Stop and close', + musicSong: 'Song on PAFF', + musicPlayingBelow: 'Playing below', accountsThisOne: 'signed in', worthThen: 'Worth then', worthNow: 'Worth now', diff --git a/src/style.css b/src/style.css index 38aa2ac..f036fb8 100644 --- a/src/style.css +++ b/src/style.css @@ -2218,3 +2218,51 @@ html:has(.call-overlay:not(.call-min)) { overflow: hidden; scrollbar-gutter: aut pointer-events: none; opacity: 0; transition: opacity .12s, transform .12s; } .feed-when.on { opacity: 1; transform: translate(-50%, 0); transition-duration: .08s; } + +/* A PAFF song or album in a post: cover, title, play. It plays in the + music bar, not here (paffSongCard / playInBar in messages.js). */ +.paff-song { + display: flex; align-items: center; gap: 12px; margin-top: 6px; padding: 8px; + border: 1px solid var(--line); border-radius: 10px; background: var(--surface2); + cursor: pointer; position: relative; +} +.paff-song:hover { border-color: var(--line-strong); } +.paff-song.on { border-color: var(--accent, var(--line-strong)); } +.paff-song-cover { width: 64px; height: 64px; flex: none; border-radius: 6px; object-fit: cover; background: var(--line); } +.paff-song-meta { min-width: 0; flex: 1; } +.paff-song-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.paff-song-meta .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.paff-song-play { + flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; + background: var(--fill); color: var(--fill-fg); +} +.paff-song-open { position: absolute; top: 4px; right: 8px; font-size: 13px; color: var(--faint); text-decoration: none; } + +/* The music bar: PAFF's slim player, pinned above the bottom nav and + outside the page, so a song plays on wherever you go. */ +.music-bar { + position: fixed; z-index: 29; left: 50%; transform: translateX(-50%); + bottom: env(safe-area-inset-bottom, 0px); + width: min(560px, 100%); height: 64px; box-sizing: border-box; + display: flex; align-items: stretch; + background: #0a0b0e; /* PAFF's player's own */ border: 1px solid var(--line); border-bottom: 0; + border-radius: 12px 12px 0 0; box-shadow: 0 -4px 18px rgba(0, 0, 0, .08); overflow: hidden; +} +body:has(.app-bottom-nav) .music-bar { bottom: calc(env(safe-area-inset-bottom, 0px) + 65px); } +.music-bar iframe { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; } +.music-close { + flex: none; width: 40px; margin: 0; padding: 0; border: 0; border-radius: 0; + background: none; color: rgba(255, 255, 255, .6); font-size: 22px; cursor: pointer; +} +.music-close:hover { color: #fff; background: none; } +body.music-open .feed-post-fab, body.music-open .feed-new-pill { bottom: calc(env(safe-area-inset-bottom, 0px) + 82px + 68px); } +body.music-open #app { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); } +body.music-open #app:has(> .app-bottom-nav) { padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px)); } +@media (min-width: 900px) { + .music-bar, body:has(.app-bottom-nav) .music-bar { + left: calc(50% + var(--col-mid)); bottom: 16px; width: min(600px, calc(100% - 32px)); + border-radius: 12px; border-bottom: 1px solid var(--line); + } + body.music-open .feed-post-fab, body.music-open .feed-new-pill { bottom: 96px; } + body.music-open #app:has(> .app-bottom-nav) { padding-bottom: 96px; } +} diff --git a/tools/link-preview-test.js b/tools/link-preview-test.js index fb83dae..3b2aad3 100644 --- a/tools/link-preview-test.js +++ b/tools/link-preview-test.js @@ -20,6 +20,7 @@ const POSTS = [ finalizeEvent({ kind: 1, created_at: now - 60, tags: [], content: 'nothing here https://blank.example/page' }, AUTHOR), finalizeEvent({ kind: 1, created_at: now - 90, tags: [], content: 'a picture http://localhost:5311/pic.png' }, AUTHOR), finalizeEvent({ kind: 1, created_at: now - 120, tags: [], content: 'film night https://paff.club/movie/1382-hackers-1995/play?q=1080p&t=4910' }, AUTHOR), + finalizeEvent({ kind: 1, created_at: now - 150, tags: [], content: 'on repeat https://paff.club/song/abc123' }, AUTHOR), ]; const PROFILE = finalizeEvent({ kind: 0, created_at: now - 100, tags: [], content: JSON.stringify({ name: 'Linker', picture: 'http://localhost:5311/face.png' }) }, AUTHOR); @@ -33,6 +34,8 @@ const server = Bun.serve({ port: 5311, fetch: (req) => { ? { url: target, title: 'Lawmakers doubt the plan', description: 'A story in one line.', image: 'http://localhost:5311/card.png', site: 'News Example' } : target === 'https://movies.example/movie/1382/play?t=4910' || target.startsWith('https://paff.club/movie/1382') ? { url: target, title: 'Hackers (1995) · from 1:21:50', description: 'Teenage hackers.', image: 'http://localhost:5311/movie.png', site: 'PAFF' } + : target === 'https://paff.club/song/abc123' + ? { url: target, title: 'Halcyon · Orbital', description: 'Orbital 2 · 1993', image: 'http://localhost:5311/cover.png', site: 'PAFF' } : {}; return new Response(JSON.stringify(meta), { headers: { 'content-type': 'application/json', 'access-control-allow-origin': '*' } }); } @@ -159,10 +162,34 @@ try { for (let i = 0; i < 20 && !paffLog.includes('play'); i++) await sleep(150); check('...and carries on when it comes back', paffLog.join() === 'pause,play', JSON.stringify(paffLog)); await page.evaluate(() => { document.getElementById('pad')?.remove(); scrollTo(0, 0); }); + // a PAFF song plays in the bar above the nav, and keeps playing as you go + const song = await page.evaluate(() => { + const c = document.querySelector('.paff-song'); + return c && { title: c.querySelector('.paff-song-title')?.textContent, cover: !!c.querySelector('img.paff-song-cover'), frame: !!c.querySelector('iframe') }; + }); + check('a PAFF song link is a card with its cover and title', !!song && song.cover && song.title === 'Halcyon · Orbital' && !song.frame, JSON.stringify(song)); + await page.evaluate(() => { const c = document.querySelector('.paff-song'); c.scrollIntoView({ block: 'center' }); c.click(); }); + await sleep(300); + const bar = await page.evaluate(() => { + const b = document.querySelector('.music-bar'), f = b?.querySelector('iframe'), nav = document.querySelector('.app-bottom-nav'); + const r = b?.getBoundingClientRect(), n = nav?.getBoundingClientRect(); + return b && { src: f?.getAttribute('src'), above: !n || r.bottom <= n.top + 1, playing: document.querySelector('.paff-song')?.textContent.includes('Playing below') }; + }); + check('a tap plays it in the bar above the nav', !!bar && bar.src === 'https://paff.club/embed/song/abc123?bar=1' && bar.above, JSON.stringify(bar)); + check('...and the card says it is playing', !!bar?.playing); + if (process.env.SHOT) await page.screenshot({ path: process.env.SHOT }); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Wallet"]')?.click()); + await sleep(500); + const still = await page.evaluate(() => document.querySelector('.music-bar iframe')?.getAttribute('src')); + check('the song carries on on another page', still === 'https://paff.club/embed/song/abc123?bar=1', still); + await page.evaluate(() => document.querySelector('.music-close').click()); + check('× stops and closes it', await page.evaluate(() => !document.querySelector('.music-bar') && !document.body.classList.contains('music-open'))); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]').click()); + await sleep(500); check('the registrar was asked once per link', previewHits.filter((u) => u === 'https://news.example/story/1').length === 1 && !previewHits.some((u) => u.endsWith('.png')), JSON.stringify(previewHits)); let kept = 0; // written behind, a second after the card was learned - for (let i = 0; i < 12 && kept < 2; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (kept < 2) await sleep(300); } - check('the cards are remembered for next time', kept === 2, kept + ' kept'); // the story's and the film's + for (let i = 0; i < 12 && kept < 3; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (kept < 3) await sleep(300); } + check('the cards are remembered for next time', kept === 3, kept + ' kept'); // the story's, the film's and the song's // a draft's preview shows the card too (Adam, 2026-11-17: a paff.club // movie link stayed a bare URL in Preview), once the typing settles const opened = await page.evaluate(() => { const b = [...document.querySelectorAll('button')].find((n) => (n.getAttribute('aria-label') || n.textContent).trim().toLowerCase() === 'new post'); if (b) { b.click(); return true; } return false; }); -- cgit v1.2.3