Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Audio: render the native control as-is; add 'media from a link' insert

nyblnet74dc8e30a9e0
diff --git a/scripts/build-example-decks.mjs b/scripts/build-example-decks.mjs
index a298c21d..b3ce3fda 100644
--- a/scripts/build-example-decks.mjs
+++ b/scripts/build-example-decks.mjs
@@ -597,7 +597,7 @@ function deckPicnic() {
// build-example-decks.mjs, so it's unambiguously public domain. Demos the
// media element's embed path: the sound travels inside the .bento.html.
text({ x: 130, y: 556, w: 360, h: 26, html: '▶ press play — the picnic jingle', fontSize: 15, fontWeight: 800, color: INK, rotation: -1 }),
- media({ id: 'pic-jingle', kind: 'audio', src: mediaFile('chime.wav', 'audio/wav'), x: 130, y: 588, w: 300, h: 56, radius: 999, controls: true }),
+ media({ id: 'pic-jingle', kind: 'audio', src: mediaFile('chime.wav', 'audio/wav'), x: 130, y: 588, w: 300, h: 56, controls: true }),
text({ x: 130, y: 682, w: 700, h: 20, html: 'PHOTOS: JACK DELANO, 1941 · LIBRARY OF CONGRESS — PUBLIC DOMAIN', fontSize: 9, fontWeight: 700, letterSpacing: 2, color: 'rgba(32,26,49,0.55)' }),
],
})
diff --git a/slides/package.json b/slides/package.json
index 1768816a..ac6a5ae7 100644
--- a/slides/package.json
+++ b/slides/package.json
@@ -1,7 +1,7 @@
{
"name": "bento-slides",
"private": true,
- "version": "0.9.19",
+ "version": "0.9.20",
"license": "MIT",
"type": "module",
"scripts": {
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index ca920676..6f3001a8 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -194,8 +194,7 @@ export class Editor {
this.shapeDropdown(),
btn(ICONS.image, t('Image'), () => this.pickImage(),
t('Add an image — or just paste one (⌘V) straight onto the slide')),
- btn(ICONS.media, t('Media'), () => this.pickMedia(),
- t('Add video or audio — small clips embed in the file; for big ones, paste a hosted URL in the panel to keep the deck small')),
+ this.mediaDropdown(),
btn(ICONS.table, t('Table'), () => this.canvas.insert(defaultTable()),
t('Add a table — edit cells inline; turn it into a live chart from the panel')),
btn(ICONS.chart, t('Chart'), () => this.canvas.insert(defaultChart(applyChartPalette(CHART_PRESETS.bar(), this.store.doc.theme))),
@@ -1035,6 +1034,33 @@ export class Editor {
// --- insert media (video / audio) --------------------------------------------------
+ /** Media insert menu: a file (embeds) or a link (stays a URL — keeps the
+ * deck small; good for big clips that shouldn't ride inside the file). */
+ private mediaDropdown(): HTMLElement {
+ const wrap = div('ed-dropdown')
+ const trigger = btn(ICONS.media, t('Media'), () => wrap.classList.toggle('open'),
+ t('Add video or audio — from a file (embeds it) or a link (stays a URL)'))
+ const menu = div('ed-menu')
+ const item = (label: string, onClick: () => void) => {
+ menu.appendChild(btn(ICONS.media, t(label), () => { wrap.classList.remove('open'); onClick() }))
+ }
+ item('Video or audio file…', () => this.pickMedia())
+ item('Video from a link…', () => this.promptMediaUrl('video'))
+ item('Audio from a link…', () => this.promptMediaUrl('audio'))
+ wrap.append(trigger, menu)
+ document.addEventListener('pointerdown', (ev) => {
+ if (!wrap.contains(ev.target as Node)) wrap.classList.remove('open')
+ })
+ return wrap
+ }
+
+ /** Insert a media element that REFERENCES a URL (not embedded). */
+ private promptMediaUrl(kind: 'video' | 'audio') {
+ const url = window.prompt(t('Paste the {kind} URL — it stays a link, the file is not embedded:', { kind }))?.trim()
+ if (!url) return
+ this.insertMedia(kind, url)
+ }
+
private pickMedia() {
const input = document.createElement('input')
input.type = 'file'
diff --git a/slides/src/i18n/de.ts b/slides/src/i18n/de.ts
index 52424149..cbe1c325 100644
--- a/slides/src/i18n/de.ts
+++ b/slides/src/i18n/de.ts
@@ -458,4 +458,10 @@ export const de: Catalog = {
"Save as presentation package…": "Als Präsentationspaket speichern…",
"This is a presentation package — view and present only.": "Dies ist ein Präsentationspaket — nur ansehen und präsentieren.",
"Turn on live sharing first — a read-only copy follows the session": "Zuerst Live-Freigabe einschalten — eine Nur-Lese-Kopie folgt der Sitzung",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "Video- oder Audiodatei…",
+ "Video from a link…": "Video aus einem Link…",
+ "Audio from a link…": "Audio aus einem Link…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "Video oder Audio hinzufügen — aus einer Datei (eingebettet) oder einem Link (bleibt eine URL)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "Füge die {kind}-URL ein — sie bleibt ein Link, die Datei wird nicht eingebettet:",
}
diff --git a/slides/src/i18n/es.ts b/slides/src/i18n/es.ts
index dfbe682e..7fb86963 100644
--- a/slides/src/i18n/es.ts
+++ b/slides/src/i18n/es.ts
@@ -458,4 +458,10 @@ export const es: Catalog = {
"Save as presentation package…": "Guardar como paquete de presentación…",
"This is a presentation package — view and present only.": "Esto es un paquete de presentación — solo ver y presentar.",
"Turn on live sharing first — a read-only copy follows the session": "Primero activa el uso compartido en vivo — una copia de solo lectura sigue la sesión",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "Archivo de vídeo o audio…",
+ "Video from a link…": "Vídeo desde un enlace…",
+ "Audio from a link…": "Audio desde un enlace…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "Añadir vídeo o audio — desde un archivo (se incrusta) o un enlace (se queda como URL)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "Pega la URL del {kind} — se queda como enlace, el archivo no se incrusta:",
}
diff --git a/slides/src/i18n/fr.ts b/slides/src/i18n/fr.ts
index 6570c7a4..616a3d77 100644
--- a/slides/src/i18n/fr.ts
+++ b/slides/src/i18n/fr.ts
@@ -458,4 +458,10 @@ export const fr: Catalog = {
"Save as presentation package…": "Enregistrer comme paquet de présentation…",
"This is a presentation package — view and present only.": "Ceci est un paquet de présentation — lecture et présentation uniquement.",
"Turn on live sharing first — a read-only copy follows the session": "Activez d’abord le partage en direct — une copie en lecture seule suit la session",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "Fichier vidéo ou audio…",
+ "Video from a link…": "Vidéo depuis un lien…",
+ "Audio from a link…": "Audio depuis un lien…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "Ajouter une vidéo ou un audio — depuis un fichier (intégré) ou un lien (reste une URL)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "Collez l’URL du {kind} — elle reste un lien, le fichier n’est pas intégré :",
}
diff --git a/slides/src/i18n/it.ts b/slides/src/i18n/it.ts
index 604ece2d..51cea13c 100644
--- a/slides/src/i18n/it.ts
+++ b/slides/src/i18n/it.ts
@@ -458,4 +458,10 @@ export const it: Catalog = {
"Save as presentation package…": "Salva come pacchetto di presentazione…",
"This is a presentation package — view and present only.": "Questo è un pacchetto di presentazione — solo visualizzazione e presentazione.",
"Turn on live sharing first — a read-only copy follows the session": "Attiva prima la condivisione live — una copia in sola lettura segue la sessione",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "File video o audio…",
+ "Video from a link…": "Video da un link…",
+ "Audio from a link…": "Audio da un link…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "Aggiungi video o audio — da un file (incorporato) o un link (resta un URL)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "Incolla l’URL del {kind} — resta un link, il file non viene incorporato:",
}
diff --git a/slides/src/i18n/ja.ts b/slides/src/i18n/ja.ts
index 50b6405e..467a3c09 100644
--- a/slides/src/i18n/ja.ts
+++ b/slides/src/i18n/ja.ts
@@ -458,4 +458,10 @@ export const ja: Catalog = {
"Save as presentation package…": "プレゼンテーションパッケージとして保存…",
"This is a presentation package — view and present only.": "これはプレゼンテーションパッケージです — 閲覧とプレゼンのみ。",
"Turn on live sharing first — a read-only copy follows the session": "先にライブ共有をオンにしてください — 読み取り専用コピーはセッションに追従します",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "動画または音声ファイル…",
+ "Video from a link…": "リンクから動画…",
+ "Audio from a link…": "リンクから音声…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "動画または音声を追加 — ファイルから(埋め込み)またはリンクから(URL のまま)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "{kind} の URL を貼り付け — リンクのままで、ファイルは埋め込まれません:",
}
diff --git a/slides/src/i18n/zh-Hans.ts b/slides/src/i18n/zh-Hans.ts
index 895e75f5..d64039bb 100644
--- a/slides/src/i18n/zh-Hans.ts
+++ b/slides/src/i18n/zh-Hans.ts
@@ -458,4 +458,10 @@ export const zhHans: Catalog = {
"Save as presentation package…": "另存为演示文稿包…",
"This is a presentation package — view and present only.": "这是一个演示文稿包——仅供查看和演示。",
"Turn on live sharing first — a read-only copy follows the session": "请先开启实时共享——只读副本会跟随该会话",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "视频或音频文件…",
+ "Video from a link…": "从链接添加视频…",
+ "Audio from a link…": "从链接添加音频…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "添加视频或音频 — 从文件(嵌入)或链接(保留为 URL)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "粘贴 {kind} URL — 它保留为链接,文件不会被嵌入:",
}
diff --git a/slides/src/i18n/zh-Hant.ts b/slides/src/i18n/zh-Hant.ts
index 7adfb33d..b4b1d912 100644
--- a/slides/src/i18n/zh-Hant.ts
+++ b/slides/src/i18n/zh-Hant.ts
@@ -458,4 +458,10 @@ export const zhHant: Catalog = {
"Save as presentation package…": "另存為簡報套件…",
"This is a presentation package — view and present only.": "這是一個簡報套件——僅供檢視與演示。",
"Turn on live sharing first — a read-only copy follows the session": "請先開啟即時共享——唯讀副本會跟隨此工作階段",
+ // media insert menu (v0.9.20)
+ "Video or audio file…": "影片或音訊檔案…",
+ "Video from a link…": "從連結新增影片…",
+ "Audio from a link…": "從連結新增音訊…",
+ "Add video or audio — from a file (embeds it) or a link (stays a URL)": "新增影片或音訊 — 從檔案(嵌入)或連結(保留為 URL)",
+ "Paste the {kind} URL — it stays a link, the file is not embedded:": "貼上 {kind} URL — 它保留為連結,檔案不會被嵌入:",
}
diff --git a/slides/src/render.ts b/slides/src/render.ts
index 017914a2..b5b38f8b 100644
--- a/slides/src/render.ts
+++ b/slides/src/render.ts
@@ -450,22 +450,22 @@ export function renderElement(el: SlideElement, doc: BentoDoc, opts: RenderOpts
}
const inert = opts.liveMedia ? '' : ';pointer-events:none'
if (el.kind === 'audio') {
- // The native <audio controls> is an opinionated pill with its own
- // surface and a fixed intrinsic height (~54px). Don't wrap it in a
- // SECOND background — that reads as a doubled box. Just centre it and
- // clip to the element's own radius. (A too-short box was the "funny
- // shape" bug; authors should size the box ≥ the control's height.)
+ // Render the browser's native <audio controls> AS-IS: it's already a
+ // self-contained pill with its own surface. We add nothing behind it
+ // and don't clip it to a radius (that just cut the control's own shape
+ // and looked odd) — only centre it in the element box. Size the box to
+ // the control's ~54px intrinsic height (defaultMedia audio uses 56).
const audio = document.createElement('audio')
if (el.src) audio.src = resolveAsset(doc, el.src)
audio.controls = el.controls !== false
audio.loop = !!el.loop
audio.preload = 'metadata'
audio.dataset.autoplay = el.autoplay ? '1' : ''
- audio.style.cssText = `width:100%;display:block;border-radius:${radius}px` + inert
+ audio.style.cssText = 'width:100%;display:block' + inert
const wrap = document.createElement('div')
- wrap.style.cssText = `width:100%;height:100%;display:flex;align-items:center;justify-content:center;overflow:hidden;border-radius:${radius}px`
+ wrap.style.cssText = 'width:100%;height:100%;display:flex;align-items:center;justify-content:center'
if (!el.src) {
- wrap.style.cssText += ';background:#eef2f7;color:#93a2b6;font-size:13px'
+ wrap.style.cssText += ';background:#eef2f7;border-radius:10px;color:#93a2b6;font-size:13px'
wrap.textContent = '♪ ' + 'No audio source'
} else wrap.appendChild(audio)
node.appendChild(wrap)