Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

spaces: the top bar is slides' bar (replaces #567) (#651)

nyblnet0d621cb6b87b
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index c1127103..09fd51d7 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -8412,3 +8412,52 @@ lands, this method is the only caller to move.
**D5 in spaces:** under a coarse pointer the bar's buttons, the Live control,
the page-tree rows and their ⋯, the format bar and every menu row are 44px
(`--tap`). The bar was 40px.
+
+## 2026-09-26 — The spaces top bar is slides' bar, and the fit is one algorithm
+
+The maintainer's complaint was that spaces' interface "is not fully following
+slides", and the chrome work before this barely touched the bar. Measured on
+the #565 build at 1440: padding 8/12 against slides' 8/14, gap 6 against 10,
+groups at 2 and 4 against 6, a bold 136×30 wordmark button against slides'
+15px/400 lockup, a 240px semibold title with an 8px corner against 220px,
+regular, 6px. Each of those is slides' value now, and
+`scripts/test-spaces-chrome.ts` reads the padding, the gap, the title floor and
+the phone width out of SLIDES' SOURCE and compares, so the two cannot part
+silently.
+
+**Language and Help are in the bar, as in slides.** The globe opens the list
+slides' globe shows (`localeChoices()`, the one in force ticked,
+`menuitemradio`), and choosing one rebuilds the chrome. Slides' last row,
+"Manage languages…", has no spaces counterpart because spaces has no language
+packs. When the bar folds, both move into ⋯ as rows. "Keyboard shortcuts" is no
+longer in ⋯ at widths where `?` is on screen: one home per command per width.
+
+**One fit, shaped for the kernel.** `spaces/src/topbar.ts`
+(`createTopbarFit`) is slides' `fitTopbar` with the app taken out: tier
+classes, the title, and the "a menu is open" test are options. The hand-copy it
+replaces had drifted in three ways (§3.2 of the chrome audit): a 110px title
+floor where slides uses 120, a fold on a squeezed title rather than on real
+overflow, and no phone rule. So spaces changed tier at 800/720/600 where slides
+changes at 1360/880/720. Now it follows slides' rules:
+- compact and tight step down while the bar overflows or the title is under
+ 120px;
+- fold waits for true overflow;
+- at 700px or below the bar folds unconditionally.
+
+Spaces has fewer controls, so its measured thresholds are 900/800/700.
+
+**Below the fold's floor the bar scrolls** (≤700px). A folded spaces bar needs
+about 370px (measured: ⋯ ends at 366 plus 6px padding). The app root clips, so without this the excess was cut off with ⋯
+inside it. A scroll container clips both axes, so the bar's menus go
+`position: fixed` under `--sp-bar-bottom`, which the fit publishes. The bar
+takes no `z-index`, so it never becomes a ceiling for them (slides' hard-won
+detail 9).
+
+**This reverses one line of 2026-08-10:** a phone no longer gives up the
+wordmark. The mark stays in the corner, as slides' does, and it is a 44px
+target there because it is a button (D5). Undo and redo stay in ⋯ on a phone,
+as that entry ruled. The Pages button moves from before the mark to after the
+title, where slides puts its Slides button.
+
+A kernel line proposes `kernel/src/ui/topbar.ts`. When it lands, this file
+becomes an import and slides' `fitTopbar` its second caller.
diff --git a/scripts/test-spaces-chrome.ts b/scripts/test-spaces-chrome.ts
index dab44714..23d1b275 100644
--- a/scripts/test-spaces-chrome.ts
+++ b/scripts/test-spaces-chrome.ts
@@ -81,6 +81,34 @@ ok(handDialogs.length === 0, `no file hand-builds a modal overlay any more — e
ok(/createPanel\(/.test(editor) && !/private makeResizer\(/.test(editor) && !/sp-pane-tab/.test(css),
'both side panels are the kernel panel; spaces\' own resizer and chevron are gone')
+// THE TOP BAR IS SLIDES' BAR. Its numbers are read out of slides' own source,
+// so the day slides changes its bar this rig says the two apps have parted,
+// rather than asserting a copy of a number that has already moved.
+const slidesCss = readFileSync(join(root, 'slides/src/styles.css'), 'utf8')
+const slidesEd = readFileSync(join(root, 'slides/src/editor/editor.ts'), 'utf8')
+const edBar = /\n\.ed-topbar \{([\s\S]*?)\n\}/.exec(slidesCss)?.[1] ?? ''
+const SLIDES_BAR = {
+ gap: /\bgap:\s*(\d+px)/.exec(edBar)?.[1],
+ // padding: max(8px, …top…) max(14px, …right…) 8px max(14px, …left…)
+ padY: /padding:\s*max\((\d+px)/.exec(edBar)?.[1],
+ padX: [...(/padding:([^;]*);/.exec(edBar)?.[1] ?? '').matchAll(/max\((\d+px)/g)][1]?.[1],
+}
+ok(!!(SLIDES_BAR.gap && SLIDES_BAR.padY && SLIDES_BAR.padX), `slides' bar values can be read from its stylesheet (${JSON.stringify(SLIDES_BAR)})`)
+const spBar = /\n\.sp-bar \{([\s\S]*?)\n\}/.exec(css)?.[1] ?? ''
+ok(new RegExp(`\\bgap:\\s*${SLIDES_BAR.gap}`).test(spBar) && new RegExp(`padding:\\s*${SLIDES_BAR.padY} max\\(${SLIDES_BAR.padX}`).test(spBar),
+ `.sp-bar declares slides' padding and gap (${SLIDES_BAR.padY}/${SLIDES_BAR.padX}, gap ${SLIDES_BAR.gap})`)
+// …and slides' fit: the title floor and the phone width are its constants
+const edFit = slidesEd.slice(slidesEd.indexOf(' private fitTopbar() {'))
+const slidesFloor = /getBoundingClientRect\(\)\.width < (\d+)/.exec(edFit)?.[1]
+const slidesPhone = /innerWidth <= (\d+)/.exec(edFit)?.[1]
+const topbar = read('topbar.ts')
+ok(!!slidesFloor && !!slidesPhone &&
+ new RegExp(`titleFloor \\?\\? ${slidesFloor}\\b`).test(topbar) && new RegExp(`phoneWidth \\?\\? ${slidesPhone}\\b`).test(topbar) &&
+ new RegExp(`max-width: ${slidesPhone}px\\) \\{\\n \\.sp-bar, \\.sp-bar\\.sp-bar-compact`).test(css),
+ `the fit is slides': title floor ${slidesFloor}px, phone ${slidesPhone}px, the same width in the phone stylesheet`)
+ok(/createTopbarFit\(bar,/.test(editor) && !/private fitTopbar\(/.test(editor),
+ 'the editor fits its bar through topbar.ts, not a private hand-copy')
+
// ————— browser half ————————————————————————————————————————————————————————
console.log('\nthe built shell, driven with trusted input\n')
const CHROME = [process.env.BENTO_CHROME, '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
@@ -371,6 +399,99 @@ async function browser(chrome: string, html: string): Promise<void> {
const afterNav = await js<any>(`({ w: document.querySelector('.sp-side').closest('.bkp').getBoundingClientRect().width, scrim: !!document.querySelector('.sp-scrim'), stored: localStorage.getItem('bento-sp-pane-closed') })`)
ok(afterNav.w === 0 && !afterNav.scrim && afterNav.stored === null,
`following a page shuts the drawer and its scrim, and writes nothing to the desktop preference (${JSON.stringify(afterNav)})`)
+
+ // ——— the top bar is slides' bar ———
+ await open(false)
+ const BAR = `document.querySelector('.sp-bar')`
+ const geo = await js<any>(`(() => { const c = getComputedStyle(${BAR}); return { gap: c.columnGap, padY: c.paddingTop, padX: c.paddingInlineStart, padE: c.paddingInlineEnd, tier: ${BAR}.className } })()`)
+ ok(geo.gap === SLIDES_BAR.gap && geo.padY === SLIDES_BAR.padY && geo.padX === SLIDES_BAR.padX && geo.padE === SLIDES_BAR.padX,
+ `at 1440 the bar's padding and gap are slides' (${geo.padY}/${geo.padX}, gap ${geo.gap}; slides ${SLIDES_BAR.padY}/${SLIDES_BAR.padX}, gap ${SLIDES_BAR.gap}; ${geo.tier})`)
+
+ // Language: the globe opens the list slides' globe shows, and choosing one rebuilds the chrome in it
+ await tap(TRIG('Language'))
+ const langs = await js<any>(`(() => { const m = ${OPEN}; if (!m) return null; const rows = [...m.querySelectorAll('.bkm-item')]; return { n: rows.length, names: rows.map(r => r.textContent.trim()), on: rows.filter(r => r.getAttribute('aria-checked') === 'true').map(r => r.textContent.trim()) } })()`)
+ ok(langs && langs.n >= 8 && langs.names.includes('English') && langs.names.includes('Deutsch') && langs.on.length === 1 && langs.on[0] === 'English',
+ `the globe opens the language list, the one in force checked (${JSON.stringify(langs)})`)
+ await tap(`[...(${OPEN}).querySelectorAll('.bkm-item')].find(b => b.textContent.trim() === 'Deutsch')`)
+ const de = await js<any>(`({ lang: document.documentElement.lang, insert: document.querySelector('.sp-bar .sp-group-insert .sp-btnlabel')?.textContent, share: !!document.querySelector('.sp-bar .sp-live') })`)
+ ok(de.lang === 'de' && de.insert === 'Einfügen' && de.share,
+ `choosing Deutsch rebuilds the bar in German and keeps the Share control (${JSON.stringify(de)})`)
+ await tap(`document.querySelector('.sp-bar .sp-lang > button')`)
+ await tap(`[...(${OPEN}).querySelectorAll('.bkm-item')].find(b => b.textContent.trim() === 'English')`)
+ // Help: `?` in the bar opens the shortcut sheet
+ await tap(`document.querySelector('.sp-bar .sp-help')`)
+ const help = await js<string | null>(`(() => { const d = [...document.querySelectorAll('[aria-modal="true"]')].find(d => d.getBoundingClientRect().height > 0); return d?.querySelector('.bkd-title')?.textContent ?? null })()`)
+ ok(help === 'Keyboard shortcuts', `the bar's ? opens the keyboard shortcuts (${help})`)
+ await key('Escape', 0, 'Escape')
+
+ // Every control, at every width, can be reached and pressed: on screen (the
+ // bar scrolled to it when it scrolls) and topmost at its own centre.
+ const REACH = `(() => { const bar = ${BAR}; const vis = (e) => { const r = e.getBoundingClientRect(); if (r.width < 1 || r.height < 1) return false; for (let n = e; n && n !== bar; n = n.parentElement) { const c = getComputedStyle(n); if (c.display === 'none' || c.visibility === 'hidden') return false } return true }
+ const ctl = [...bar.querySelectorAll('button, input')].filter(e => !e.closest('.bkm-menu')).filter(vis)
+ const bad = []
+ // Scroll ONLY the bar, and only if a person could: overflow:hidden on
+ // the app root is still scrollable from script, so scrollIntoView would
+ // 'reach' a control that is clipped for every real reader.
+ const scrolls = /auto|scroll/.test(getComputedStyle(bar).overflowX)
+ for (const e of ctl) { let r = e.getBoundingClientRect(); if (scrolls && (r.right > innerWidth || r.left < 0)) { bar.scrollLeft += r.right > innerWidth ? r.right - innerWidth + 2 : r.left - 2; r = e.getBoundingClientRect() } const top = document.elementsFromPoint(r.x + r.width / 2, r.y + r.height / 2)[0]
+ if (r.left < -0.5 || r.right > innerWidth + 0.5 || r.top < 0 || !top || !(e === top || e.contains(top))) bad.push((e.getAttribute('aria-label') || e.className).slice(0, 18) + '@' + Math.round(r.left) + '..' + Math.round(r.right)) }
+ bar.scrollLeft = 0
+ const app = document.querySelector('.sp-app'); if (app.scrollLeft || scrollX) bad.push('page scrolled sideways')
+ return { n: ctl.length, bad, tier: [...bar.classList].filter(c => /compact|tight|fold/.test(c)).map(c => c.slice(7)).join('+') || 'full', over: bar.scrollWidth - bar.clientWidth, scrolls: getComputedStyle(bar).overflowX } })()`
+ const reach: string[] = []
+ for (const w of [1440, 1280, 1024, 900, 800, 700, 600, 480, 390, 360, 320]) {
+ const phone = w <= 390
+ await send('Emulation.setDeviceMetricsOverride', { width: w, height: phone ? 844 : 900, deviceScaleFactor: phone ? 2 : 1, mobile: phone })
+ await send('Emulation.setTouchEmulationEnabled', { enabled: phone, maxTouchPoints: phone ? 5 : 1 })
+ await sleep(250)
+ const r = await js<any>(REACH)
+ reach.push(`${w}:${r.tier}${r.bad.length ? ' UNREACHABLE ' + r.bad.join(',') : ''}`)
+ if (r.bad.length) ok(false, `at ${w}px every bar control can be reached and pressed (${r.bad.join(', ')})`)
+ }
+ ok(!reach.some(s => s.includes('UNREACHABLE')), `every bar control is on screen and topmost at its centre, 320–1440 (${reach.join(' · ')})`)
+
+ // The fold engages BEFORE the bar overflows: no width where an unfolded bar
+ // is wider than itself, and every phone width folded.
+ const over: string[] = []
+ let foldAt = 0
+ for (let w = 1440; w >= 320; w -= 20) {
+ await send('Emulation.setDeviceMetricsOverride', { width: w, height: 900, deviceScaleFactor: 1, mobile: false })
+ await send('Emulation.setTouchEmulationEnabled', { enabled: false, maxTouchPoints: 1 })
+ await sleep(90)
+ const r = await js<any>(`(() => { const b = ${BAR}; return { fold: b.classList.contains('sp-bar-fold'), over: b.scrollWidth - b.clientWidth } })()`)
+ if (r.fold && !foldAt) foldAt = w
+ if (!r.fold && r.over > 1) over.push(`${w}:+${r.over}`)
+ if (w <= 700 && !r.fold) over.push(`${w}:unfolded`)
+ }
+ ok(over.length === 0 && foldAt > 0, `the fold tier engages before the bar overflows (first fold at ${foldAt}px; ${over.join(' ') || 'no overflow unfolded'})`)
+ // …and under browser zoom, where the viewport is wide but the bar is not: the
+ // phone rule cannot fire, so only MEASURING folds it (150%, 1440 → 720).
+ await js(`document.documentElement.style.zoom = '1.5'; 1`)
+ const zover: string[] = []
+ let zfold = 0
+ for (let w = 1440; w >= 720; w -= 40) {
+ await send('Emulation.setDeviceMetricsOverride', { width: w, height: 900, deviceScaleFactor: 1, mobile: false })
+ await sleep(90)
+ const r = await js<any>(`(() => { const b = ${BAR}; return { fold: b.classList.contains('sp-bar-fold'), over: b.scrollWidth - b.clientWidth } })()`)
+ if (r.fold && !zfold) zfold = w
+ if (!r.fold && r.over > 1) zover.push(`${w}:+${r.over}`)
+ }
+ await js(`document.documentElement.style.zoom = ''; 1`)
+ ok(zover.length === 0 && zfold > 700, `at 150% zoom the measured fold engages before the bar overflows (first fold at ${zfold}px; ${zover.join(' ') || 'no overflow unfolded'})`)
+
+ // Below the fold's floor the bar scrolls, and ⋯ still opens a menu you can press
+ await send('Emulation.setDeviceMetricsOverride', { width: 320, height: 844, deviceScaleFactor: 2, mobile: true })
+ await send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 })
+ await sleep(250)
+ const moreAt = await js<any>(`(() => { const bar = ${BAR}; const b = ${TRIG('More')}; if (/auto|scroll/.test(getComputedStyle(bar).overflowX)) bar.scrollLeft = bar.scrollWidth; const r = b.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2, on: r.right <= innerWidth } })()`)
+ await click(moreAt.x, moreAt.y)
+ const se = await js<any>(`(() => { const m = ${OPEN}; if (!m) return null; const r = m.getBoundingClientRect(); const rows = [...m.querySelectorAll('.bkm-item')]; const f = rows[0].getBoundingClientRect(); const hit = document.elementsFromPoint(f.x + f.width / 2, f.y + f.height / 2)[0]; return { left: Math.round(r.left), right: Math.round(r.right), vw: innerWidth, first: rows[0].contains(hit), lang: rows.some(x => x.textContent.trim() === 'Language'), help: rows.some(x => x.textContent.trim().startsWith('Keyboard shortcuts')) } })()`)
+ ok(se && moreAt.on && se.left >= 0 && se.right <= se.vw && se.first && se.lang && se.help,
+ `at 320px ⋯ opens on screen, its rows pressable, carrying Language and Keyboard shortcuts (${JSON.stringify(se)})`)
+ await tap(`[...(${OPEN}).querySelectorAll('.bkm-item')].find(b => b.textContent.trim() === 'Language')`)
+ const sheet2 = await js<any>(`(() => { const m = ${OPEN}; if (!m) return null; const rows = [...m.querySelectorAll('.bkm-item')]; const r = m.getBoundingClientRect(); return { n: rows.length, onScreen: r.top >= 0 && r.bottom <= innerHeight, on: rows.filter(x => x.getAttribute('aria-checked') === 'true').length } })()`)
+ ok(sheet2 && sheet2.n >= 8 && sheet2.onScreen && sheet2.on === 1, `⋯ → Language opens the same list, on screen (${JSON.stringify(sheet2)})`)
+ await key('Escape', 0, 'Escape')
ws.close()
} finally {
try { child.kill('SIGKILL') } catch { /* gone */ }
diff --git a/scripts/test-spaces-model.ts b/scripts/test-spaces-model.ts
index aafd0a0e..2ea365e4 100644
--- a/scripts/test-spaces-model.ts
+++ b/scripts/test-spaces-model.ts
@@ -871,7 +871,10 @@ for (const [label, input, err] of [
ok(/^\.sp-more \{ display: inline-flex/m.test(css),
'⋯ is in the bar at EVERY width, being a home and not only an overflow')
ok(!/\.sp-bar-fold \.sp-more \{ display/.test(css), '…so it is not gated on the fold any more')
- ok(inTier('fold', /\.sp-mark \{ display: none/), '…and the mark goes (About is in ⋯)')
+ // The mark STAYS when folded, as slides' does (DECISIONS 2026-09-26, which
+ // reverses the 2026-08-10 line that gave it up on a phone).
+ ok(!/\.sp-bar-fold \.sp-mark \{ display: none/.test(css), '…but the mark stays in the corner, as slides\' does')
+ ok(/\.sp-bar-fold \.sp-lang, \.sp-bar-fold \.sp-help \{ display: none/.test(css), '…and the globe and ? go into ⋯')
ok(inTier('fold', /\.sp-group-history \{ display: none/), '…and the history pair')
ok(inTier('fold', /\.sp-split \.sp-caret \{ display: none/), '…and the save caret')
ok(/\.sp-bar-fold \.sp-status \{\n\s*position: absolute/.test(css),
@@ -880,7 +883,7 @@ for (const [label, input, err] of [
// NO px query may govern the fold any more. A stray one would re-introduce
// exactly the disagreement this replaced: CSS folding at one width while the
// menu decides its contents at another.
- const foldSelectors = [/\.sp-sec \{ display: none/, /\.sp-mark \{ display: none/,
+ const foldSelectors = [/\.sp-sec \{ display: none/, /\.sp-help \{ display: none/,
/\.sp-group-history \{ display: none/, /\.sp-split \.sp-caret \{ display: none/]
for (const sel of foldSelectors) {
const i = css.search(sel)
@@ -892,14 +895,17 @@ for (const [label, input, err] of [
// The bar is sized by MEASUREMENT, and the measurement is the overflow of
// the bar's own box — not a number written down twice.
- ok(/private fitTopbar\(\): void \{/.test(ed), 'fitTopbar exists')
- ok(/bar\.scrollWidth - bar\.clientWidth/.test(ed), '…and it measures overflow rather than matching a width')
- ok(/new ResizeObserver\(\(\) => this\.fitTopbar\(\)\)/.test(ed), 'a ResizeObserver drives it on viewport change')
- ok(/new MutationObserver\(\(\) => this\.fitTopbar\(\)\)/.test(ed),
+ // The fit lives in topbar.ts (slides' algorithm, shaped to move to the kernel).
+ const tb = fs.readFileSync(new URL('../spaces/src/topbar.ts', import.meta.url), 'utf8')
+ ok(/export function createTopbarFit\(/.test(tb) && /createTopbarFit\(bar,/.test(ed), 'the editor fits its bar with createTopbarFit')
+ ok(/bar\.scrollWidth - bar\.clientWidth/.test(tb), '…and it measures overflow rather than matching a width')
+ ok(/new ResizeObserver\(\(\) => fit\(\)\)/.test(tb), 'a ResizeObserver drives it on viewport change')
+ ok(/new MutationObserver\(\(\) => fit\(\)\)/.test(tb),
'…and a MutationObserver for content that changes width at a fixed viewport')
- ok(/attributeFilter: \['style', 'hidden'\]/.test(ed),
+ ok(/attributeFilter: \['style', 'hidden'\]/.test(tb),
"…which does NOT watch 'class', or its own tier flips would feed it")
- ok(/this\.barMO\?\.takeRecords\(\)/.test(ed), '…and it drops the records its own mutations queue')
+ ok(/mo\.takeRecords\(\)/.test(tb), '…and it drops the records its own mutations queue')
+ ok(/this\.barFit\?\.destroy\(\)/.test(ed), '…and a rebuilt bar disposes the old fit (no observer or window listener left behind)')
// THE JS GATE ASKS THE DOM. It used to be matchMedia with the phone number
// written down a second time, and the comment beside it admitted as much;
diff --git a/spaces/CHANGELOG.md b/spaces/CHANGELOG.md
index 685ebe87..218ea27c 100644
--- a/spaces/CHANGELOG.md
+++ b/spaces/CHANGELOG.md
@@ -609,6 +609,27 @@ Versions follow `0.MINOR.PATCH` while pre-1.0.
disclosure caret, where the old one rendered as a dot. The share panel sets
"Reset access…" apart from the rows above it.
+- **The top bar is slides' top bar.** Same padding (8/14) and spacing (10
+ between groups, 6 inside one), the same mark at the same size, a 220px title
+ in regular weight, and every button on the same 30px grid. The Save half is
+ slides' width with its caret; it stays the dark primary button. The unsaved
+ dot is a badge on Save's corner at every width. Language (the globe) and the
+ keyboard shortcuts (`?`) now sit in the bar's corner, as in slides. The globe
+ opens the same list of languages slides shows, with the current one ticked.
+ Choosing one rebuilds the chrome in that language. Share is labelled "Share".
+ + Insert stays one menu, next to undo and redo where slides keeps its insert
+ tools, and ⋯ closes the row.
+ - **It narrows as slides' does.** Labels go first, then the word beside the
+ mark, then controls fold into ⋯. On a phone the bar always folds. Below
+ what even a folded bar needs (about 370px), it scrolls sideways instead of
+ cutting off ⋯, and its menus still open fully on screen. Before, spaces
+ dropped its labels only at 800px, where slides drops them at 1360.
+ - **On a phone** the mark stays in the corner as a 44px button to About, and
+ the Pages button follows the title. Language and Keyboard shortcuts are in
+ ⋯ once the bar has folded.
+ - **Fixed:** changing the language in About took the Share button out of the
+ bar until you reloaded.
+
## [0.1.0] — 2026-08-03
First release.
diff --git a/spaces/src/collabui.ts b/spaces/src/collabui.ts
index 7ef71dd3..5073fc85 100644
--- a/spaces/src/collabui.ts
+++ b/spaces/src/collabui.ts
@@ -137,7 +137,11 @@ export class CollabUi {
const b = document.createElement('button')
b.type = 'button'
b.className = 'sp-live'
- b.innerHTML = `<span class="sp-ico">${ICONS.people}</span><span class="sp-live-n"></span>`
+ b.innerHTML = `<span class="sp-ico">${ICONS.people}</span><span class="sp-btnlabel"></span><span class="sp-live-n"></span>`
+ // The word, as slides' "Share" carries it: an icon of two heads is not a
+ // name for "share this space". It collapses with the bar's compact tier
+ // like every other label; the tooltip still says the state.
+ b.querySelector('.sp-btnlabel')!.textContent = t('Share')
b.addEventListener('click', () => this.openPanel(b))
this.btn = b
this.sync()
diff --git a/spaces/src/editor.ts b/spaces/src/editor.ts
index 905c586e..e030772f 100644
--- a/spaces/src/editor.ts
+++ b/spaces/src/editor.ts
@@ -34,7 +34,7 @@ import { planImport, type SourceFile } from './markdown'
import { extractSpace, planGraft } from './portable'
import { countOutsideTags, replaceOutsideTags } from './findreplace'
import { asksForAnswer, evaluate, format, pageContext } from './calc'
-import { t, locale } from './i18n'
+import { t, locale, localeChoices, setLocale, applyDirection } from './i18n'
import { openAbout } from './about'
import { openGraphView } from './graph.ts'
import {
@@ -46,6 +46,7 @@ import { startSharing } from '../../kernel/src/sync/online.ts'
import * as shareModule from './share.ts'
import { ICONS, type IconName } from './icons'
import { barMenu, anchoredMenu, row, caption, extra, keys, type Menu } from './menus.ts'
+import { createTopbarFit, type TopbarFit } from './topbar.ts'
import { createDialog, type Dialog } from '../../kernel/src/ui/dialog.ts'
import '../../kernel/src/ui/dialog.css'
import { createPanel, type Panel } from '../../kernel/src/ui/panel.ts'
@@ -393,11 +394,21 @@ export class Editor {
{ icon: 'graph', label: t('Graph'), run: () => this.openGraph() },
{ icon: 'print', label: t('Print or save as PDF'), kbd: keys('mod', 'P'), run: () => this.openPrint() },
{ icon: 'info', label: t('About this space'), run: () => this.openAbout() },
- // A help screen only reachable by pressing the key it documents is a
- // help screen for people who did not need it.
- { icon: 'help', label: t('Keyboard shortcuts'), kbd: '?', run: () => this.openHelp() },
]
+ // In the bar's corner as in slides — the globe and the `?` — and in ⋯ only
+ // once the bar has folded them away. A help screen only reachable by
+ // pressing the key it documents is a help screen for people who did not
+ // need it, which is why `?` is a button at all.
+ const helpB = iconBtn('help', `${t('Keyboard shortcuts')} (?)`, () => this.openHelp())
+ helpB.classList.add('sp-help')
+ // slides' glyph — a bold `?`, the key it stands for — not a circled icon
+ helpB.innerHTML = '<b class="sp-help-q" aria-hidden="true">?</b>'
+ const lang = barMenu({
+ icon: ICONS.globe, label: '', tip: t('Language'), end: true, scroll: true, className: 'sp-lang',
+ fill: (m) => this.fillLanguages(m),
+ }).root
+
const inlineSecondary = barActions.map((a) => {
const b = iconBtn(a.icon, a.kbd ? `${a.label} (${a.kbd})` : a.label, a.run)
b.classList.add('sp-sec')
@@ -447,16 +458,27 @@ export class Editor {
// unconditionally is what made ⋯ a duplicate of the visible row.
if (folded) {
for (const a of barActions) row(m, { icon: ICONS[a.icon], label: a.label, kbd: a.kbd, run: a.run })
+ // The globe's list, one tap further: a menu cannot hold a menu, so
+ // the row opens the same list as its own popup (a sheet on a phone).
+ const moreB = m.trigger
+ row(m, { icon: ICONS.globe, label: t('Language'), run: () => {
+ queueMicrotask(() => anchoredMenu(moreB, (lm) => this.fillLanguages(lm),
+ { label: t('Language'), sheet: this.isDrawer(), returnFocus: moreB }))
+ } })
+ row(m, { icon: ICONS.help, label: t('Keyboard shortcuts'), kbd: '?', run: () => this.openHelp() })
m.separator()
saveRows(m)
}
},
}).root
- // The live control sits BEFORE ⋯ and is replaced in place once the session
- // exists (connectSync). A placeholder rather than a conditional build, so
- // the bar's widths do not shift when a document turns out to be shared.
- this.liveSlot = el('span', 'sp-live-slot')
+ // The live control is replaced in place once the session exists
+ // (connectSync). A placeholder rather than a conditional build, so the
+ // bar's widths do not shift when a document turns out to be shared — and
+ // on a REBUILD (a language change) the session already exists, so the
+ // button goes straight in. It used to stay a placeholder: switching
+ // language in About took the Share control out of the bar until reload.
+ this.liveSlot = this.collab ? this.collab.button() : el('span', 'sp-live-slot')
// save is a split control, as in slides: the common action, and the
// less-common ways of writing this document somewhere else
@@ -489,41 +511,45 @@ export class Editor {
() => this.toggleInsp())
inspB.classList.add('sp-insp-toggle')
+ // Slides' layout, group for group (chrome-unification §2.1): LEFT is the
+ // document (mark · title · history), then the insert tools — here the one
+ // + Insert, which is right for a document — then the RIGHT group, doing
+ // things with it, ending in the language globe and `?` as slides' does.
+ // ⋯ closes the row: it is a home at every width here (slides has it only
+ // folded), and last is where slides' folded bar puts it.
+ const insertGroup = el('div', 'sp-group sp-group-insert')
+ insertGroup.append(insert)
const right = el('div', 'sp-group sp-group-right')
- right.append(insert, search, ...inlineSecondary, inspB, this.liveSlot, more, saveGroup)
-
- // The status goes AFTER undo/redo, never before. It is transient text that
- // grows from nothing to a whole sentence, and anything downstream of it in
- // the flex flow gets shoved sideways every time it changes — measured at
- // 36px on a plain edit and 246px entering reading view, which is more than
- // a button's width, so undo lands where redo just was. Past the history
- // group it grows into the slack the right group's margin-auto already
- // holds, and nothing before it can move. Reported against slides as #300.
- bar.append(pagesB, mark, title, history, this.statusEl, right)
+ right.append(search, ...inlineSecondary, inspB, this.liveSlot, saveGroup, lang, helpB, more)
+
+ // The status goes AFTER the history and the insert tools, never before.
+ // It is transient text that grows from nothing to a whole sentence, and
+ // anything downstream of it in the flex flow gets shoved sideways every
+ // time it changes — measured at 36px on a plain edit and 246px entering
+ // reading view, so undo landed where redo just was. Here it grows into the
+ // slack the right group's margin-auto already holds, and nothing before it
+ // can move. Reported against slides as #300.
+ //
+ // The Pages button (drawer widths only) follows the title, as slides'
+ // Slides button does: the corner is the suite's mark, at every width.
+ bar.append(mark, title, pagesB, history, insertGroup, this.statusEl, right)
// Drive the fit now, and again whenever the bar's size or its CONTENT
- // changes. The ResizeObserver is the primary width signal — it fires for
- // every viewport change, including a phone rotating, where matchMedia
- // change events are unreliable under a driven viewport. The MutationObserver
- // catches the constant-width case: the people count appearing when someone
- // joins, the "Saved" tag flashing, the update chip arriving. Each of those
- // clipped the end of the bar under the old breakpoints.
+ // changes — topbar.ts, slides' algorithm with its tiers, its 120px title
+ // floor and its 700px phone. A rebuilt bar gets a fresh fit; the old one's
+ // observers and its window listener go with it.
this.topbar = bar
- this.barRO?.disconnect()
- this.barRO = new ResizeObserver(() => this.fitTopbar())
- this.barRO.observe(bar)
- this.barMO?.disconnect()
- this.barMO = new MutationObserver(() => this.fitTopbar())
- this.barMO.observe(bar, {
- childList: true, subtree: true, characterData: true,
- // NOT 'class': fitTopbar's own tier flips are class changes on this very
- // element, and observing them makes the fix for the loop (takeRecords)
- // the only thing standing between here and a spin. Slides omits it for
- // the same reason.
- attributes: true, attributeFilter: ['style', 'hidden'],
+ this.barFit?.destroy()
+ this.barFit = createTopbarFit(bar, {
+ tiers: ['sp-bar-compact', 'sp-bar-tight', 'sp-bar-fold'],
+ title: () => bar.querySelector<HTMLElement>('.sp-doctitle'),
+ // Re-fitting starts by UNFOLDING, which would slam shut a menu somebody
+ // is reading — and ⋯'s contents depend on the tier, so rebuilding it
+ // mid-read would change it under them. The next resize runs it again.
+ busy: () => !!this.overlay || !!bar.querySelector('.bkm-open'),
+ bottomVar: '--sp-bar-bottom',
+ varHost: this.root,
})
- // …and once the bar is actually in the document and has a width to measure
- queueMicrotask(() => this.fitTopbar())
this.sidebar = el('nav', 'sp-side')
this.sidebar.setAttribute('aria-label', t('Pages'))
@@ -718,7 +744,7 @@ export class Editor {
*
* This used to be `matchMedia('(max-width: 600px)')`, with a comment saying
* the number was duplicated from the stylesheet on purpose. It is not needed
- * at all now: fitTopbar puts the tier on the bar as a class, so the menu can
+ * at all now: the fit (topbar.ts) puts the tier on the bar as a class, so the menu can
* ASK what is on screen instead of re-deriving it from a width and hoping
* the two agree. When they disagreed the symptom was a menu offering Undo
* while Undo sat in the bar two centimetres away.
@@ -728,44 +754,28 @@ export class Editor {
}
/**
- * Size the topbar by MEASURING it, not by width breakpoints.
- *
- * A px guess cannot answer the question being asked. The same buttons need
- * different room at the same viewport width depending on browser zoom, OS
- * text scaling, and how long the labels are in the reader's language — eight
- * catalogs ship inside every file, and "Insert" is 76px in English and
- * nothing like that in German. The bar's own CONTENT changes width too, at a
- * fixed viewport: the people count appears when somebody joins a session.
- * Each of those cases clipped the end of the bar under the old 820/600
- * breakpoints. Slides settled this first (#239); this is its pattern.
- *
- * Start from the widest layout, step down a tier while the bar still
- * overflows its own box.
+ * The language list — the globe's, and ⋯'s once the bar has folded. The same
+ * rows slides' globe shows: every language this build carries, each in its
+ * own name, the one in force checked. Language follows the READER, never
+ * the file (PLATFORM §8): nothing here touches the document.
*/
- private fitTopbar(): void {
- const bar = this.topbar
- if (!bar || !bar.isConnected) return
- const tiers = ['sp-bar-compact', 'sp-bar-tight', 'sp-bar-fold']
- // Re-fitting starts by UNFOLDING, which would slam shut a menu somebody is
- // reading — and the ⋯ menu's contents depend on the tier, so rebuilding it
- // mid-read would change it under them. The next resize runs this again.
- if (this.overlay || bar.querySelector('.bkm-open')) return
- // scrollWidth counts content sticking out of the padding box even with
- // overflow visible, so this IS the clipped-controls condition. 1px of
- // slack absorbs subpixel rounding at fractional zoom.
- const overflow = () => bar.scrollWidth - bar.clientWidth > 1
- // The title is the only shrinkable thing in the bar, so flexbox crushes it
- // toward its floor before anything overflows. Waiting for hard overflow
- // would mean full labels beside an unreadable document title.
- const title = bar.querySelector<HTMLElement>('.sp-doctitle')
- const cramped = () => overflow() || (!!title && title.getBoundingClientRect().width < 110)
- bar.classList.remove(...tiers)
- if (cramped()) bar.classList.add('sp-bar-compact')
- if (cramped()) bar.classList.add('sp-bar-tight')
- if (cramped()) bar.classList.add('sp-bar-fold')
- // the class flips above queued mutation records of their own; drop them,
- // or the observer re-runs this forever
- this.barMO?.takeRecords()
+ private fillLanguages(m: Menu): void {
+ const now = locale()
+ for (const c of localeChoices()) {
+ const b = row(m, { label: c.label, selected: c.code === now, run: () => this.chooseLanguage(c.code) })
+ b.setAttribute('role', 'menuitemradio')
+ b.setAttribute('aria-checked', String(c.code === now))
+ b.lang = c.code
+ b.classList.toggle('sp-lang-on', c.code === now)
+ }
+ }
+
+ private chooseLanguage(code: string): void {
+ if (code === locale()) return
+ setLocale(code)
+ applyDirection()
+ // the chrome is built in the reader's language, so it is built again
+ this.build()
}
/**
@@ -2803,8 +2813,7 @@ export class Editor {
private session: import('./sync/session.ts').SyncSession | null = null
private liveSlot!: HTMLElement
private topbar: HTMLElement | null = null
- private barRO: ResizeObserver | null = null
- private barMO: MutationObserver | null = null
+ private barFit: TopbarFit | null = null
private treeTimer: ReturnType<typeof setTimeout> | undefined
private paintTreeSoon(): void {
clearTimeout(this.treeTimer)
diff --git a/spaces/src/i18n/de.ts b/spaces/src/i18n/de.ts
index 7361d33a..d720d8fc 100644
--- a/spaces/src/i18n/de.ts
+++ b/spaces/src/i18n/de.ts
@@ -233,6 +233,7 @@ export const de: Catalog = {
"Journal date": "Journaldatum",
"Key-verified identity": "Schlüssel-verifizierte Identität",
"Language": "Sprache",
+ "Share": "Teilen",
"Language follows whoever opens the file. It is never written into the document.": "Die Sprache richtet sich danach, wer die Datei öffnet. Sie wird nie ins Dokument geschrieben.",
"Language — what this block is highlighted as": "Sprache — wie dieser Block hervorgehoben wird",
"Last saved": "Zuletzt gespeichert",
diff --git a/spaces/src/i18n/es.ts b/spaces/src/i18n/es.ts
index d53df9bb..617417fc 100644
--- a/spaces/src/i18n/es.ts
+++ b/spaces/src/i18n/es.ts
@@ -233,6 +233,7 @@ export const es: Catalog = {
"Journal date": "Fecha del diario",
"Key-verified identity": "Identidad verificada por clave",
"Language": "Idioma",
+ "Share": "Compartir",
"Language follows whoever opens the file. It is never written into the document.": "El idioma sigue a quien abre el archivo. Nunca se escribe en el documento.",
"Language — what this block is highlighted as": "Lenguaje — cómo se colorea este bloque",
"Last saved": "Última vez guardado",
diff --git a/spaces/src/i18n/fr.ts b/spaces/src/i18n/fr.ts
index 1af37120..eefe8be2 100644
--- a/spaces/src/i18n/fr.ts
+++ b/spaces/src/i18n/fr.ts
@@ -233,6 +233,7 @@ export const fr: Catalog = {
"Journal date": "Date du journal",
"Key-verified identity": "Identité vérifiée par clé",
"Language": "Langue",
+ "Share": "Partager",
"Language follows whoever opens the file. It is never written into the document.": "La langue suit la personne qui ouvre le fichier. Elle n’est jamais écrite dans le document.",
"Language — what this block is highlighted as": "Langage — la coloration de ce bloc",
"Last saved": "Dernier enregistrement",
diff --git a/spaces/src/i18n/it.ts b/spaces/src/i18n/it.ts
index b6a13267..76f406b4 100644
--- a/spaces/src/i18n/it.ts
+++ b/spaces/src/i18n/it.ts
@@ -233,6 +233,7 @@ export const it: Catalog = {
"Journal date": "Data del diario",
"Key-verified identity": "Identità verificata da chiave",
"Language": "Lingua",
+ "Share": "Condividi",
"Language follows whoever opens the file. It is never written into the document.": "La lingua segue chi apre il file. Non viene mai scritta nel documento.",
"Language — what this block is highlighted as": "Linguaggio — come viene evidenziato questo blocco",
"Last saved": "Ultimo salvataggio",
diff --git a/spaces/src/i18n/ja.ts b/spaces/src/i18n/ja.ts
index e2bb6399..0346feea 100644
--- a/spaces/src/i18n/ja.ts
+++ b/spaces/src/i18n/ja.ts
@@ -233,6 +233,7 @@ export const ja: Catalog = {
"Journal date": "ジャーナルの日付",
"Key-verified identity": "鍵で検証済みのアイデンティティ",
"Language": "言語",
+ "Share": "共有",
"Language follows whoever opens the file. It is never written into the document.": "言語はファイルを開いた人に従います。ドキュメントには書き込まれません。",
"Language — what this block is highlighted as": "言語 — このブロックを何として色分けするか",
"Last saved": "最終保存",
diff --git a/spaces/src/i18n/packed.ts b/spaces/src/i18n/packed.ts
index 390b7d61..762040be 100644
--- a/spaces/src/i18n/packed.ts
+++ b/spaces/src/i18n/packed.ts
@@ -410,6 +410,7 @@ export const PACKED: Record<string, ReadonlyArray<string | 0>> = {
"Search this space": ["このスペースを検索","搜索此空间","搜尋此空間","Buscar en este espacio","Rechercher dans cet espace","Diesen Space durchsuchen","Cerca in questo spazio","Pesquisar neste espaço"],
"Select": ["選択","单选","單選","Selección","Sélection","Auswahl","Selezione","Seleção"],
"Set a password…": ["パスワードを設定…","设置密码…","設定密碼…","Establecer una contraseña…","Définir un mot de passe…","Passwort festlegen…","Imposta una password…","Definir uma palavra-passe…"],
+ "Share": ["共有","共享","共用","Compartir","Partager","Teilen","Condividi","Compartilhar"],
"Share this space": ["このスペースを共有","共享此空间","分享此空間","Compartir este espacio","Partager cet espace","Diesen Space teilen","Condividi questo spazio","Partilhar este espaço"],
"Show as a board": ["ボードで表示","以看板显示","以看板顯示","Mostrar como tablero","Afficher en tableau","Als Board anzeigen","Mostra come bacheca","Mostrar como quadro"],
"Show as a gallery": ["ギャラリーで表示","以图库显示","以圖庫顯示","Mostrar como galería","Afficher en galerie","Als Galerie anzeigen","Mostra come galleria","Mostrar como galeria"],
diff --git a/spaces/src/i18n/pt.ts b/spaces/src/i18n/pt.ts
index e91b3eab..f409512b 100644
--- a/spaces/src/i18n/pt.ts
+++ b/spaces/src/i18n/pt.ts
@@ -233,6 +233,7 @@ export const pt: Catalog = {
"Journal date": "Data do diário",
"Key-verified identity": "Identidade verificada por chave",
"Language": "Idioma",
+ "Share": "Compartilhar",
"Language follows whoever opens the file. It is never written into the document.": "O idioma segue quem abre o ficheiro. Nunca é escrito no documento.",
"Language — what this block is highlighted as": "Linguagem — como este bloco é realçado",
"Last saved": "Última gravação",
diff --git a/spaces/src/i18n/zh-Hans.ts b/spaces/src/i18n/zh-Hans.ts
index cd72a1ce..409c8110 100644
--- a/spaces/src/i18n/zh-Hans.ts
+++ b/spaces/src/i18n/zh-Hans.ts
@@ -233,6 +233,7 @@ export const zh_Hans: Catalog = {
"Journal date": "日志日期",
"Key-verified identity": "密钥验证的身份",
"Language": "语言",
+ "Share": "共享",
"Language follows whoever opens the file. It is never written into the document.": "语言跟随打开文件的人,绝不会写入文档。",
"Language — what this block is highlighted as": "语言 — 这个块按什么语言着色",
"Last saved": "上次保存",
diff --git a/spaces/src/i18n/zh-Hant.ts b/spaces/src/i18n/zh-Hant.ts
index ea784695..74568d88 100644
--- a/spaces/src/i18n/zh-Hant.ts
+++ b/spaces/src/i18n/zh-Hant.ts
@@ -233,6 +233,7 @@ export const zh_Hant: Catalog = {
"Journal date": "日誌日期",
"Key-verified identity": "金鑰驗證的身份",
"Language": "語言",
+ "Share": "共用",
"Language follows whoever opens the file. It is never written into the document.": "語言取決於開啟檔案的人,永遠不會寫入文件中。",
"Language — what this block is highlighted as": "語言 — 這個區塊以什麼語言上色",
"Last saved": "上次儲存",
diff --git a/spaces/src/styles.css b/spaces/src/styles.css
index 21717073..bc49ac75 100644
--- a/spaces/src/styles.css
+++ b/spaces/src/styles.css
@@ -258,21 +258,29 @@ option { background: var(--field); color: var(--ink); }
/* ————— shell ————— */
.sp-app { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
+/* THE BAR IS SLIDES' BAR (`.ed-topbar`), value for value: 8/14 padding, 10
+ between groups, 6 inside one, the mark at 15px/400, a 220px title at
+ 14px/400 with a 6px corner, and every button on the 30px grid. Measured
+ before (chrome-unification §2.1, and again on #565): 8/12, gap 6, a bold
+ 136×30 wordmark button, a 240px semibold title with an 8px corner, groups at
+ 2 and 4. Two apps of one suite should not teach two toolbars. */
.sp-bar {
- display: flex; align-items: center; gap: 6px;
- padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
+ display: flex; align-items: center; gap: 10px; min-width: 0;
+ padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
background: var(--surface); border-bottom: 1px solid var(--line);
flex: 0 0 auto;
}
+/* A BUTTON (it opens About, and a keyboard reaches it) drawn as slides' mark,
+ which is a plain lockup: no frame, no fill, 15px/400 with the word in bold. */
.sp-mark {
- display: inline-flex; align-items: center; gap: 7px;
- font: inherit; font-weight: 700; font-size: 14px; letter-spacing: -0.01em;
- white-space: nowrap; padding: 4px 7px 4px 4px; user-select: none;
- background: transparent; border: 1px solid transparent; border-radius: 8px;
+ display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0;
+ font: inherit; font-size: 15px; font-weight: 400; line-height: normal;
+ white-space: nowrap; padding: 0; user-select: none;
+ background: transparent; border: 0; border-radius: 5px;
color: var(--ink); cursor: pointer;
}
-.sp-mark:hover { background: var(--chrome-2); }
-.sp-mark-svg { display: block; flex: 0 0 auto; }
+.sp-mark:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
+.sp-mark-svg { display: block; flex: 0 0 auto; border-radius: 5px; }
/* the coral is BRAND: the splash's `.bs-word b`, and the mark in every app
of the suite. It reads on both grounds, so it is one value, not two. */
.sp-mark-word span { color: var(--brand); }
@@ -280,12 +288,12 @@ option { background: var(--field); color: var(--ink); }
/* Sized, not greedy: a title input that eats the slack pushed undo/redo away
from the document they belong to and left them floating mid-bar. The
spacer is the right group's margin-inline-start:auto. */
- flex: 0 1 240px; min-width: 0;
- font: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
+ flex: 0 1 220px; width: 220px; min-width: 48px;
+ font: inherit; font-size: 14px; font-weight: 400; color: var(--ink);
background: transparent; border: 1px solid transparent;
- border-radius: 8px; padding: 5px 8px;
+ border-radius: 6px; padding: 5px 8px;
}
-.sp-doctitle:hover { background: var(--chrome); }
+.sp-doctitle:hover { border-color: var(--line); }
.sp-doctitle:focus { background: var(--field); border-color: var(--blue); outline: none; }
.sp-status {
font-size: 12px; color: var(--muted); white-space: nowrap;
@@ -1226,7 +1234,6 @@ button.sp-callout-chip:hover { text-decoration: underline; text-underline-offset
.sp-dditem:hover { background: var(--chrome-2); }
.sp-dditem strong { display: block; font-size: 13.5px; font-weight: 600; }
.sp-dditem span span { display: block; color: var(--muted); font-size: 12px; }
-.sp-caret .sp-btn { padding: 6px 5px; }
.sp-panel-toggle { display: inline-flex; }
/* ————— page icon ————— */
@@ -1466,12 +1473,6 @@ button.sp-callout-chip:hover { text-decoration: underline; text-underline-offset
border-radius: 6px; white-space: nowrap;
}
-/* ————— narrow topbar: hide, never scroll —————
- Measured at 375px: the bar wanted 678px, so seven of eleven controls sat off
- the right edge — Save among them, which made the file unsaveable on a phone.
- The rule is slides' rule: drop text and fold the less-used controls into ⋯,
- so every action stays reachable at every width. A horizontally scrolling
- toolbar hides the same controls, just less honestly. */
/* ⋯ IS A HOME, NOT JUST AN OVERFLOW. It used to be display:none until the bar
folded, which was right while every command it held also had a button in the
bar. It no longer does: the commands you reach for once a session live here
@@ -1480,56 +1481,47 @@ button.sp-callout-chip:hover { text-decoration: underline; text-underline-offset
whatever the bar drops as the window narrows. */
.sp-more { display: inline-flex; }
-/* The tier starts at the DRAWER breakpoint (820px), not at 720. It was 720, and
- measured at 768 — an iPad in portrait — the bar still laid out 795px wide: the
- save caret ended at x = 795, 27px off the screen. 721–820 is the band where
- the page list is already an overlay rather than a column, which is exactly the
- band where the bar is competing with the document for width. One breakpoint,
- one meaning. */
/* ————— the topbar fits itself by MEASURING —————
- These three tiers are applied by editor.ts fitTopbar(), which steps down
- while the bar still overflows its own box. They were px media queries (820
- and 600) until it became clear a px guess cannot answer the question being
- asked: the same buttons need different room at the same viewport width
- depending on browser zoom, OS text scaling, how long the labels are in the
- reader's language — eight catalogs ship in every file — and live content
- like the people count appearing when somebody joins. Slides settled this
- first (#239); this is its pattern, with this app's controls. */
-
-/* compact: the words beside the icons go. Measured: Insert 76.6px labelled
- against 40px as an icon; Save's word costs 44px and says nothing the icon
- does not. */
+ Slides' tiers, stepped through by slides' algorithm (topbar.ts, the port of
+ slides' fitTopbar): each is tried only while the bar still does not fit.
+ They were px media queries once (820 and 600), and then a hand-copy of
+ slides' algorithm that had drifted to other thresholds (§3.2: spaces went
+ compact at 800 where slides goes at 1360). A px guess cannot answer the
+ question: the same buttons need different room at the same width under
+ browser zoom, OS text scaling, and eight catalogs of labels. The PADDING and
+ GAP of each tier are slides' too. */
+
+/* compact: the words beside the icons go. */
.sp-bar-compact .sp-primary span.sp-savelabel { display: none; }
.sp-bar-compact .sp-btnlabel { display: none; }
-.sp-bar-compact { gap: 2px; }
-.sp-bar-compact .sp-doctitle { font-size: 13px; }
+.sp-bar.sp-bar-compact {
+ gap: 6px;
+ padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
+}
/* tight: the wordmark loses its word, keeping the mark — which is the route
- to About, and the corner every app in the suite puts it in. */
+ to About, and the corner every app in the suite puts it in. Narrower
+ horizontally only, as in slides: the bar must not change height as a window
+ is dragged. */
+.sp-bar.sp-bar-tight {
+ gap: 4px;
+ padding: 8px max(6px, env(safe-area-inset-right)) 8px max(6px, env(safe-area-inset-left));
+}
.sp-bar-tight .sp-mark-word { display: none; }
/* fold: whole controls move into ⋯. Nothing is lost, everything is one tap
away, and the editor asks the DOM which tier is live rather than re-deriving
- it from a width — see fitTopbar. */
+ it from a width. The mark stays, as slides' does: it is the corner. */
.sp-bar-fold .sp-sec { display: none; }
-.sp-bar-fold .sp-mark { display: none; }
.sp-bar-fold .sp-group-history { display: none; }
.sp-bar-fold .sp-split .sp-caret { display: none; }
+.sp-bar-fold .sp-lang, .sp-bar-fold .sp-help { display: none; }
/* with the caret gone Save is one button again, not the left half of two —
- and a SQUARE one: the icon centred, the padding even. It was a 66×40 slab
- with the icon at its left and ~26px of empty fill on its right, because the
- label's end padding (and the unsaved dot's slot) outlived the label. */
+ and a SQUARE one, the icon centred. */
.sp-bar-fold .sp-split > .sp-btn:first-child {
border-start-end-radius: 8px; border-end-end-radius: 8px;
padding-inline: 9px; justify-content: center;
}
-/* once the word is gone, the unsaved dot is a BADGE on the corner of the icon
- button — the slides treatment — not a slot that holds the button wide */
-.sp-bar-compact .sp-primary { position: relative; }
-.sp-bar-compact .sp-primary .sp-dirty {
- position: absolute; top: 5px; inset-inline-end: 5px; margin: 0;
- box-shadow: 0 0 0 2px var(--ink);
-}
/* THE STATUS LINE LEAVES THE FLOW. It is a nowrap span, so a long message
("Reading view — press Esc or the eye to edit" is ~250px) would shove the
bar into overflow for the 1.8s it is up and put Save off-screen again.
@@ -1568,7 +1560,7 @@ button.sp-callout-chip:hover { text-decoration: underline; text-underline-offset
HIG, and slides' phone bar): measured, five bar buttons were 40×40, the
Live button 35×29, a page row 28px tall and its ⋯ 20×20. */
@media (pointer: coarse) {
- .sp-bar .sp-btn, .sp-bar .sp-live { min-width: var(--tap); min-height: var(--tap); justify-content: center; }
+ .sp-bar .sp-btn, .sp-bar .sp-live, .sp-bar .sp-mark { min-width: var(--tap); min-height: var(--tap); justify-content: center; }
.sp-treelink { min-height: var(--tap); padding-inline-end: 40px; }
.sp-treelink .sp-rowmore { width: 36px; height: var(--tap); inset-inline-end: 2px; }
.sp-fmt-btn { min-height: var(--tap); }
@@ -1599,54 +1591,94 @@ button.sp-callout-chip:hover { text-decoration: underline; text-underline-offset
}
/* ————— the toolbar, grouped as slides groups it —————
- LEFT is the document (mark · title · save state · history); RIGHT is what you
- do with it. Two apps in one suite should not teach two different toolbars. */
-.sp-group { display: flex; align-items: center; gap: 6px; }
-.sp-group-right { margin-inline-start: auto; gap: 4px; }
-.sp-group-history { gap: 2px; }
+ LEFT is the document (mark · title · history), then the insert tools, then
+ RIGHT, what you do with it. 6px inside a group, as slides' `.ed-group` —
+ history was 2 and the right group 4, which made spaces' bar the denser of
+ two bars that were meant to be one. */
+.sp-group { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
+.sp-group-right { margin-inline-start: auto; }
/* Save is ONE control with two halves, fused — not two buttons that happen to
- be adjacent. The caret is visibly part of the thing it modifies. */
+ be adjacent. The caret is visibly part of the thing it modifies. Slides'
+ proportions (a 70×30 half and a 21px caret, where spaces' were 97 and 30);
+ spaces' fill, because Save is the primary action in both apps (D1). */
.sp-split { display: inline-flex; align-items: stretch; }
.sp-split > .sp-btn:first-child {
+ position: relative;
border-start-end-radius: 0; border-end-end-radius: 0;
- padding-inline-end: 10px;
+ padding: 6px 9px;
}
.sp-split .sp-caret > .sp-btn {
- height: 100%; padding: 6px 6px;
+ height: 100%; padding: 6px 4px;
border-start-start-radius: 0; border-end-start-radius: 0;
margin-inline-start: 1px;
background: var(--ink); color: var(--bg);
}
+.sp-split .sp-caret > .sp-btn svg { width: 12px; height: 12px; }
.sp-split .sp-caret > .sp-btn:hover { background: var(--ink-2); }
/* The unsaved dot lives ON Save: the place you look to find out whether you
- need to press it is the button itself. */
+ need to press it is the button itself. A BADGE on the corner, as slides'
+ `.ed-dirty` — not a slot that holds the button 14px wider for a dot that is
+ usually not there. Ringed in the button's own fill so it reads on it. */
.sp-dirty {
+ position: absolute; top: 3px; inset-inline-end: 3px;
width: 7px; height: 7px; border-radius: 50%;
- background: var(--accent); margin-inline-start: 7px;
- opacity: 0; transition: opacity .18s;
+ background: var(--accent); box-shadow: 0 0 0 2px var(--ink);
+ opacity: 0; transition: opacity .18s; pointer-events: none;
}
.sp-dirty.sp-on { opacity: 1; }
-/* ————— phone topbar: the second tier —————
- The first tier folds the six secondary actions into ⋯. That was not enough:
- measured on a 390×844 viewport with a coarse pointer, the bar still laid out
- 467px wide inside 390px and Save's right edge landed at x = 426 — the primary
- action, 36px off the screen. What is left after ⋯ is still eleven controls'
- worth of 40px touch targets, and eleven of those do not fit in 390.
-
- So a phone gives up, in this order and for these reasons:
- · the wordmark — About is the first thing in ⋯, and the mark is only a
- route to it (35px)
- · undo/redo — added to ⋯ instead, where they carry their shortcut and
- their disabled state (84px)
- · the save caret — every one of its four items is in ⋯ or in About: Print
- and About directly, Save-a-copy and Export-as-Markdown appended there on
- a phone, Password inside About (48px)
- Save itself never moves. Measured after, coarse pointer, scrollWidth ==
- clientWidth at every one: 320 (Save's right edge 308), 375 (363), 390 (378),
- 768 (725, and the rightmost control at 756). */
+/* `?` is slides' glyph, on the bar's grid: slides' own is 28×29 because a
+ 16px-wide slot was never reserved for it; here it is a 36×30 button like
+ its neighbours, the glyph centred in a 16px box. */
+.sp-help { justify-content: center; }
+.sp-help-q { display: block; width: 16px; font-size: 15px; font-weight: 800; line-height: 16px; text-align: center; }
+
+/* the language in force, marked as slides marks it */
+.sp-lang-on .bkm-text::after { content: ' ✓'; color: var(--accent-ink); }
+
+/* ————— the phone bar —————
+ Viewport-scoped, like slides' `@media (max-width: 700px)`: this is about
+ touch and small screens, not about whether the bar fits, so it stays a media
+ query. topbar.ts folds unconditionally at the same 700.
+
+ The tighter padding is listed with the tier classes: a media query adds no
+ specificity, so a bare `.sp-bar` here loses to `.sp-bar.sp-bar-tight` and the
+ phone bar silently keeps the desktop padding (slides measured exactly that). */
+@media (max-width: 700px) {
+ .sp-bar, .sp-bar.sp-bar-compact, .sp-bar.sp-bar-tight {
+ padding: 6px max(6px, env(safe-area-inset-right)) 6px max(6px, env(safe-area-inset-left));
+ }
+ .sp-bar .sp-btn, .sp-bar .sp-live { min-width: var(--tap); min-height: var(--tap); justify-content: center; }
+ /* the mark is a button (About), so it is a 44px target like the rest (D5);
+ the glyph stays slides' 20px, centred in it */
+ .sp-bar .sp-mark { min-width: var(--tap); min-height: var(--tap); justify-content: center; }
+ .sp-doctitle { min-width: 0; }
+
+ /* BELOW THE FOLD'S FLOOR THE BAR SCROLLS. Fully folded it still needs the
+ mark, the title and seven 44px targets — about 330px — and a 320px screen
+ (an iPhone SE, any iPhone with Display Zoom) does not have them. The app
+ root clips, so the excess used to be simply cut off; in slides that hid ⋯,
+ the only route to half the commands. A partly visible button is its own
+ affordance. (slides' CLAUDE.md, hard-won detail 10.) */
+ .sp-bar {
+ overflow-x: auto; overscroll-behavior-x: contain;
+ scrollbar-width: none; -webkit-overflow-scrolling: touch;
+ }
+ .sp-bar::-webkit-scrollbar { display: none; }
+ /* …and a scroll container clips BOTH axes, so every menu hanging off the bar
+ would now be cut off by the bar itself. `fixed` takes it out of that clip;
+ it is pinned to the end of the screen, under the bar's bottom edge, which
+ topbar.ts publishes because it moves with the safe-area insets. */
+ .sp-bar .bkm.bkm-open > .bkm-menu {
+ position: fixed;
+ top: calc(var(--sp-bar-bottom, 57px) + 4px);
+ inset-inline-end: max(6px, env(safe-area-inset-right));
+ inset-inline-start: auto;
+ }
+}
+
/* About opens with the suite's mark, as slides does — a dialog that starts on a
section heading does not say what you are looking at. */
.sp-about-head { margin-bottom: 4px; }
@@ -1673,7 +1705,8 @@ body.sp-col-resizing { cursor: col-resize; user-select: none; }
LEFT of the wordmark, pushing the suite's mark out of the corner every app in
the suite puts it in. Slides has no topbar panel toggle at all, for the same
reason. Below the breakpoint there is no strip to hang a chevron on, so the
- button is the only way in and it leads the bar. */
+ button is the only way in; it follows the title, where slides' phone bar
+ puts its Slides button, and the mark keeps the corner. */
.sp-panel-toggle { display: none; }
@media (max-width: 820px) {
.sp-panel-toggle { display: inline-flex; }
diff --git a/spaces/src/topbar.ts b/spaces/src/topbar.ts
new file mode 100644
index 00000000..34161b50
--- /dev/null
+++ b/spaces/src/topbar.ts
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// THE TOP BAR FITS ITSELF BY MEASURING — slides' algorithm, ported whole.
+//
+// Slides settled this first (#239, slides/src/editor/editor.ts fitTopbar) and
+// spaces hand-copied it, then drifted: a 110px title floor against slides'
+// 120, a fold that fired on a squeezed title rather than on real overflow, and
+// no phone rule, so the two apps changed tier at different widths for the same
+// reasons (measured, chrome-unification §3.2: slides compact ≤1360 / tight ≤880
+// / fold ≤720; spaces ≤800 / ≤720 / ≤600). This is the one algorithm, written
+// so that it has no spaces in it: class names, the title and the "is something
+// open" test come in as options. It is meant to move to the kernel as
+// kernel/src/ui/topbar.ts, at which point slides' copy is the second caller and
+// this file becomes an import.
+//
+// The tiers, in order, each tried only while the previous one still does not fit:
+//
+// compact labels hide (icons + tooltips take over)
+// tight the wordmark's word hides (the mark stays: it is the brand)
+// fold low-use controls leave the bar for ⋯
+//
+// Below the fold's floor the bar SCROLLS. That lives in CSS (a phone media
+// rule), because it is the one thing measuring cannot fix: fully folded the
+// bar still needs its irreducible handful of 44px targets, and a 320px screen
+// does not have them. Two consequences the stylesheet has to honour, both
+// learned in slides (CLAUDE.md "Hard-won details" 9 and 10): a scroll container
+// clips BOTH axes, so menus hanging off the bar go `position: fixed` against
+// `--bar-bottom` published here; and a z-index on the bar is a CEILING for
+// every menu inside it.
+
+export interface TopbarFitOpts {
+ /** the three tier classes, in the order they apply */
+ tiers: readonly [compact: string, tight: string, fold: string]
+ /** the one shrinkable item. Squeezed below `titleFloor` counts as cramped. */
+ title?: () => HTMLElement | null
+ /** slides' 120px: below it a title is too narrow to read */
+ titleFloor?: number
+ /**
+ * At or below this viewport width the bar folds without measuring. It is the
+ * phone, where 44px targets decide the layout, not whether labels fit.
+ * Slides' constant, 700.
+ */
+ phoneWidth?: number
+ /**
+ * True while re-fitting would slam something shut under the reader — a menu
+ * open off the bar, a dialog. Unfolding moves controls, and a menu whose
+ * contents depend on the tier would change under them.
+ */
+ busy?: () => boolean
+ /** called when the fold tier turns on or off (slides reparents here) */
+ onFold?: (on: boolean) => void
+ /** the custom property the bar's bottom edge is published under */
+ bottomVar?: string
+ /** the element that carries `bottomVar` (default: the bar's parent) */
+ varHost?: HTMLElement
+}
+
+export interface TopbarFit {
+ /** measure now */
+ fit(): void
+ /** stop observing (a rebuilt bar makes a new fit) */
+ destroy(): void
+}
+
+export function createTopbarFit(bar: HTMLElement, o: TopbarFitOpts): TopbarFit {
+ const [compact, tight, fold] = o.tiers
+ const floor = o.titleFloor ?? 120
+ const phone = o.phoneWidth ?? 700
+ let folded: boolean | null = null
+ const setFold = (on: boolean) => {
+ if (folded === on) return
+ folded = on
+ o.onFold?.(on)
+ }
+
+ const fit = (): void => {
+ if (!bar.isConnected) return
+ // Phones fold unconditionally, as in slides.
+ if (window.innerWidth <= phone) {
+ bar.classList.add(compact, tight, fold)
+ setFold(true)
+ mo.takeRecords()
+ return
+ }
+ if (o.busy?.()) return
+ // scrollWidth counts content that sticks out of the padding box even with
+ // overflow visible, so this IS the clipped-controls condition. 1px of slack
+ // absorbs subpixel rounding at fractional zoom.
+ const overflow = () => bar.scrollWidth - bar.clientWidth > 1
+ // The title is the bar's only shrinkable item, so flexbox crushes it toward
+ // its floor before anything overflows: full labels beside an unreadable
+ // title. Labels and the word go while the title is squeezed, not only on
+ // hard overflow. The FOLD waits for real overflow — moving whole controls
+ // into a menu is a bigger step than dropping words, and slides takes it
+ // only when nothing else will do.
+ const t = o.title?.()
+ const cramped = () => overflow() || (!!t && t.getBoundingClientRect().width < floor)
+ bar.classList.remove(compact, tight, fold)
+ setFold(false)
+ if (cramped()) bar.classList.add(compact)
+ if (cramped()) bar.classList.add(tight)
+ if (overflow()) {
+ bar.classList.add(fold)
+ setFold(true)
+ }
+ // the class flips queued mutation records of their own; drop them, or the
+ // observer re-runs this forever
+ mo.takeRecords()
+ }
+
+ // A ResizeObserver on the bar is the primary width signal: it fires for every
+ // viewport change, a phone rotating included, where matchMedia change events
+ // do not fire under a driven viewport. The MutationObserver catches the
+ // constant-width case — the people count appearing, a label changing
+ // language. NOT 'class': the tier flips above are class changes on this very
+ // element.
+ const ro = new ResizeObserver(() => fit())
+ ro.observe(bar)
+ const mo = new MutationObserver(() => fit())
+ mo.observe(bar, {
+ childList: true, subtree: true, characterData: true,
+ attributes: true, attributeFilter: ['style', 'hidden'],
+ })
+ // Where the bar ends, for the menus that must go `fixed` once it scrolls. Its
+ // height moves with the safe-area insets and with the 44px phone targets.
+ const host = o.varHost ?? bar.parentElement ?? document.documentElement
+ const publish = () => host.style.setProperty(o.bottomVar ?? '--bar-bottom', `${Math.round(bar.getBoundingClientRect().bottom)}px`)
+ const bottomRO = new ResizeObserver(publish)
+ bottomRO.observe(bar)
+ const onResize = () => { fit(); publish() }
+ window.addEventListener('resize', onResize)
+ queueMicrotask(() => { fit(); publish() })
+
+ return {
+ fit,
+ destroy() {
+ ro.disconnect()
+ mo.disconnect()
+ bottomRO.disconnect()
+ window.removeEventListener('resize', onResize)
+ },
+ }
+}