oficina / slides Public

Presenter: draw Now and Next at the projector's layout; Next half of Now

Review fixes for Task 9. Live slides are laid out in a 1920x1080 box
and scaled whole to their frame (CSS only), so a small frame is never
taken for a phone: columns stay side by side, phone-hidden boxes stay,
nothing is clipped. A registered --p-now length, worked out from the
panels' box, keeps Next at half of Now in the default window, with Now
leaving Next room for it. The menu is sized against the space left
under the header, whatever its height.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 24fbcb091c3cc9034ebae25230de9010abed8afa parent 55560cc
4 files changed, +238 −7
  • internal/slides/presenter_window.go +16 −0
  • internal/slides/static/presenter.css +57 −3
  • internal/slides/templates/presenter.html +2 −2
  • internal/slidestest/presenter_window_browser_test.go +163 −2
diff --git a/internal/slides/presenter_window.go b/internal/slides/presenter_window.go
index 3a060f6..3bf0fbc 100644
--- a/internal/slides/presenter_window.go
+++ b/internal/slides/presenter_window.go
@@ -162,6 +162,22 @@ func (p presenterPrefs) css() template.CSS {
fmt.Fprintf(&b, " [presenter-panel=%q] { grid-area: %d / %d / span %d / span %d; }\n",
name, pl.Y+1, pl.X+1, pl.H, pl.W)
}
+ // The width the slide on screen is drawn at (--p-now): Now's cells
+ // of the panels' box, less the panel's padding (16px each side, 8px
+ // top and bottom), at 16:9. In the default window Next is half of it
+ // (presenter.css), so Now also leaves Next's panel, under its 24px
+ // label and 10px gap, room for that half. In a window somebody
+ // arranged, Next fills its own panel.
+ now, next := p.Panels[0], p.Panels[1]
+ room := fmt.Sprintf("%d / %d * 100cqw - 32px, (%d / %d * 100cqh - 16px) * 16 / 9",
+ now.W, presenterGrid, now.H, presenterGrid)
+ if p.Panels == defaultPresenterPrefs.Panels {
+ room += fmt.Sprintf(", (%d / %d * 100cqh - 50px) * 2 * 16 / 9", next.H, presenterGrid)
+ }
+ fmt.Fprintf(&b, " [presenter-panel] { --p-now: min(%s); }\n", room)
+ if p.Panels != defaultPresenterPrefs.Panels {
+ b.WriteString(" [presenter-panel=\"next\"] [presenter-frame] { inline-size: min(100cqw, 100cqh * 16 / 9); }\n")
+ }
b.WriteString("}\n")
fmt.Fprintf(&b, "[presenter-notes] { font-size: %dpx; }\n", p.Size)
return template.CSS(b.String())
diff --git a/internal/slides/static/presenter.css b/internal/slides/static/presenter.css
index e4634ef..1bb73ad 100644
--- a/internal/slides/static/presenter.css
+++ b/internal/slides/static/presenter.css
@@ -280,7 +280,10 @@ body {
inset-inline-end: 0;
min-inline-size: min(280px, 100%);
max-inline-size: 100%;
- max-block-size: calc(100dvh - 96px);
+ /* What is left under the header, whatever its height: 100% is the
+ header's own (the menu's containing block), and 32px is the
+ window's top padding, the 8px above and 8px below. */
+ max-block-size: calc(100dvh - 100% - 32px);
overflow-y: auto;
padding: 8px;
display: grid;
@@ -315,8 +318,21 @@ body {
}
/* ---- the panels ---- */
+/* --p-now is the width the slide on screen is drawn at, worked out on
+ every panel from the panels' own box (a container), so the slide
+ coming next can be half of it however the window is shaped (the
+ mockup's Next is half its Now). Registered, so it is a length by the
+ time it is inherited: an unregistered one would carry its cqw down
+ and resolve them against the frame instead. */
+@property --p-now {
+ syntax: "<length>";
+ inherits: true;
+ initial-value: 0px;
+}
+
/* Stacked, in a fixed order: now, next, notes. */
[presenter-panels] {
+ container-type: size;
min-block-size: 0;
min-inline-size: 0;
display: grid;
@@ -339,6 +355,11 @@ body {
}
[presenter-panel] {
+ /* Stacked: rows 5fr 3fr 6fr with two 12px gaps. Now is as wide as
+ its row allows, and no wider than leaves Next, under its 24px label
+ and 10px gap, room for half of it. The arranged window's page
+ <style> says the same for its own grid. */
+ --p-now: min(100cqw, (100cqh - 24px) * 5 / 14 * 16 / 9, ((100cqh - 24px) * 3 / 14 - 34px) * 2 * 16 / 9);
position: relative;
min-inline-size: 0;
min-block-size: 0;
@@ -356,7 +377,9 @@ body {
}
[presenter-frame] {
- inline-size: min(100cqw, 100cqh * 16 / 9);
+ position: relative;
+ container-type: inline-size;
+ inline-size: min(100cqw, 100cqh * 16 / 9, var(--p-now));
aspect-ratio: 16 / 9;
overflow: hidden;
border-radius: 4px;
@@ -364,12 +387,38 @@ body {
box-shadow: 0 8px 16px rgb(0 0 0 / 0.45);
}
-[presenter-frame] > [slides-slide] {
+/* The slide is laid out exactly as the projector lays it out on a
+ 1920×1080 screen, and the whole of it is scaled down to the frame.
+ Laid out at the frame's own size instead, a small frame is a narrow
+ slide container, which slides.css answers with its phone layer
+ (columns collapsed, phone-hidden boxes gone, the 16:9 dropped), and
+ Now and Next would not be what the room sees. Every size in a slide
+ is cqw or a percentage, so 1920 is the projector's layout at any
+ size. tan(atan2(a, b)) is a / b as a plain number. The scaled box
+ is a wrapper (presenter-scale) rather than the section itself. */
+[presenter-scale] {
+ position: absolute;
+ top: 0;
+ left: 0;
+ inline-size: 1920px;
+ block-size: 1080px;
+ transform-origin: 0 0;
+ transform: scale(tan(atan2(100cqw, 1920px)));
+}
+
+/* The section fills the 1920 box, so its padding, a percentage of what
+ holds it, is the projector's too. */
+[presenter-scale] > [slides-slide] {
inline-size: 100%;
+ max-inline-size: none;
block-size: 100%;
+ aspect-ratio: auto;
+ overflow: auto;
}
+/* Next is half of Now (the mockup's proportion). */
[presenter-panel="next"] [presenter-frame] {
+ inline-size: min(100cqw, 100cqh * 16 / 9, var(--p-now) / 2);
opacity: 0.92;
}
@@ -389,6 +438,7 @@ body {
}
[presenter-next-label] {
+ block-size: 24px;
display: flex;
align-items: center;
gap: 8px;
@@ -563,6 +613,10 @@ body {
block-size: 36px;
}
+ [presenter-menu] {
+ max-block-size: calc(100dvh - 100% - 26px);
+ }
+
[presenter-notes] {
padding: 52px 16px 12px;
}
diff --git a/internal/slides/templates/presenter.html b/internal/slides/templates/presenter.html
index a0b603a..ed8f496 100644
--- a/internal/slides/templates/presenter.html
+++ b/internal/slides/templates/presenter.html
@@ -90,14 +90,14 @@
<div presenter-panels>
<div presenter-panel="now">
<div presenter-fit>
- <div presenter-frame{{if .Blackout}} data-black{{end}}>{{.Now}}</div>
+ <div presenter-frame{{if .Blackout}} data-black{{end}}><div presenter-scale>{{.Now}}</div></div>
</div>
</div>
<div presenter-panel="next">
<p presenter-next-label>{{icon "arrow-right"}}<span>{{.NextLabel}}</span></p>
<div presenter-fit>
{{- if .Next}}
- <div presenter-frame>{{.Next}}</div>
+ <div presenter-frame><div presenter-scale>{{.Next}}</div></div>
{{- else}}
<div presenter-frame data-end></div>
{{- end}}
diff --git a/internal/slidestest/presenter_window_browser_test.go b/internal/slidestest/presenter_window_browser_test.go
index d0a44eb..3411237 100644
--- a/internal/slidestest/presenter_window_browser_test.go
+++ b/internal/slidestest/presenter_window_browser_test.go
@@ -9,6 +9,7 @@ package slidestest
import (
"fmt"
+ "net/http"
"net/url"
"strconv"
"strings"
@@ -81,9 +82,13 @@ func TestPresenterNeverScrolls(t *testing.T) {
rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false))
// Each step as the session reaches it: with scripts on, a
// page naming a state the talk is not in goes to where it is.
- press(t, app, session, token, url.Values{"op": {"goto"}, "slide": {"1"}, "press": {newPressID(t)}}, nil)
for step := range 5 {
- if step > 0 {
+ // Off the window before the talk moves, so its stream's
+ // reload cannot race this navigation.
+ rig.Run(chromedp.Navigate("about:blank"))
+ if step == 0 {
+ press(t, app, session, token, url.Values{"op": {"goto"}, "slide": {"1"}, "press": {newPressID(t)}}, nil)
+ } else {
press(t, app, session, token, op(t, "next"), nil)
}
var g presenterGeometry
@@ -122,3 +127,159 @@ func TestPresenterNeverScrolls(t *testing.T) {
})
}
}
+
+// columnsDeck is two two-column slides, each with a box hidden on a
+// phone: what slides.css's phone layer would change if a small frame
+// were taken for a phone.
+func columnsDeck(t *testing.T, a *testApp, cookies []*http.Cookie) string {
+ t.Helper()
+ token := mintAgent(t, a, cookies, "columns-deck")
+ sqid := apiDeck(t, a, token, "Columns")
+ view := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK)
+ var ops []string
+ for _, s := range view["slides"].([]any) {
+ ops = append(ops, `{"op":"remove_slide","id":`+quote(s.(map[string]any)["id"].(string))+`}`)
+ }
+ for _, id := range []string{"colsone", "colstwo"} {
+ ops = append(ops,
+ `{"op":"add_slide","id":"`+id+`","layout":"flow","template":"two-column"}`,
+ `{"op":"add_block","slide":"`+id+`","id":"`+id+`h","type":"heading","region":"heading","props":{"level":1},"markdown":"Two columns"}`,
+ `{"op":"add_block","slide":"`+id+`","id":"`+id+`l","type":"text","region":"body","markdown":"The left column, long enough to wrap onto a second line at the projector's size."}`,
+ `{"op":"add_block","slide":"`+id+`","id":"`+id+`r","type":"text","region":"aside","markdown":"The right column."}`,
+ `{"op":"add_block","slide":"`+id+`","id":"`+id+`x","type":"text","region":"aside","markdown":"Hidden on a phone."}`,
+ `{"op":"set_phone","slide":"`+id+`","id":"`+id+`x","phone":{"hidden":true}}`)
+ }
+ apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK)
+ return "/d/" + sqid
+}
+
+// blockLayoutJS is each box of the first slide under root, as fractions
+// of the slide: where it is, how big, and whether it is drawn at all.
+const blockLayoutJS = `((root) => {
+ const s = document.querySelector(root + ' [slides-slide]');
+ const r = s.getBoundingClientRect();
+ return [...s.querySelectorAll('[slides-block]')].map(b => {
+ const q = b.getBoundingClientRect();
+ return { id: b.getAttribute('data-id'), shown: getComputedStyle(b).display !== 'none',
+ x: (q.left - r.left) / r.width, y: (q.top - r.top) / r.height,
+ w: q.width / r.width, h: q.height / r.height };
+ }).concat([{ id: 'clipped', shown: s.scrollHeight > s.clientHeight + 1 }]);
+})`
+
+type blockBox struct {
+ ID string
+ Shown bool
+ X, Y, W, H float64
+}
+
+func sameBoxes(want, got []blockBox) string {
+ if len(want) != len(got) {
+ return fmt.Sprintf("%d boxes, want %d", len(got), len(want))
+ }
+ for i := range want {
+ w, g := want[i], got[i]
+ off := func(a, b float64) bool { return a-b > 0.005 || b-a > 0.005 }
+ if w.ID != g.ID || w.Shown != g.Shown || off(w.X, g.X) || off(w.Y, g.Y) || off(w.W, g.W) || off(w.H, g.H) {
+ return fmt.Sprintf("%s: %+v, the projector has %+v", w.ID, g, w)
+ }
+ }
+ return ""
+}
+
+// TestPresenterDrawsWhatTheProjectorShows: Now and Next are the
+// projector's own layout scaled down, at any window size: two columns
+// stay side by side, a box hidden on a phone is still there, and
+// nothing is cut off. A small frame is not a phone.
+func TestPresenterDrawsWhatTheProjectorShows(t *testing.T) {
+ rig, app := newRigApp(t, nil)
+ cookies := signedIn(t, app, allowedAddress)
+ session, token := startPresenting(t, app, columnsDeck(t, app, cookies), cookies)
+
+ // The projector at 1920×1080, on the session's own slide: a page
+ // named for another slide is put back on the session's by its stream.
+ projector := func(n string) []blockBox {
+ var out []blockBox
+ rig.Run(chromedp.Navigate("about:blank"))
+ press(t, app, session, token, url.Values{"op": {"goto"}, "slide": {n}, "press": {newPressID(t)}}, nil)
+ rig.Run(emulation.SetDeviceMetricsOverride(1920, 1080, 1, false),
+ chromedp.Navigate(rig.Origin+"/p/"+session),
+ waitFor(`document.querySelector('[slides-surface]')?.getAttribute('data-slide') === '`+n+`' && document.querySelector('[slides-stage] [slides-slide]')`),
+ chromedp.Evaluate(blockLayoutJS+`('[slides-stage]')`, &out))
+ return out
+ }
+ two, one := projector("2"), projector("1")
+ if len(one) < 4 || !one[3].Shown || one[2].X < 0.4 || one[1].X > 0.1 {
+ t.Fatalf("the projector itself does not draw two columns with the phone-hidden box: %+v", one)
+ }
+
+ window := rig.Origin + "/p/" + session + "/notes?t=" + url.QueryEscape(token)
+ for _, size := range presenterSizes {
+ var now, next []blockBox
+ rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false),
+ chromedp.Navigate(window),
+ waitFor(`document.querySelector('[presenter-panel="next"] [slides-slide]')`),
+ chromedp.Evaluate(blockLayoutJS+`('[presenter-panel="now"]')`, &now),
+ chromedp.Evaluate(blockLayoutJS+`('[presenter-panel="next"]')`, &next))
+ if diff := sameBoxes(one, now); diff != "" {
+ t.Errorf("%dx%d: Now is not the projector's slide 1: %s", size.w, size.h, diff)
+ }
+ if diff := sameBoxes(two, next); diff != "" {
+ t.Errorf("%dx%d: Next is not the projector's slide 2: %s", size.w, size.h, diff)
+ }
+ }
+}
+
+// TestPresenterNextIsHalfOfNow: in the default window Next is drawn at
+// half the width of Now, tall windows and short, stacked or arranged.
+func TestPresenterNextIsHalfOfNow(t *testing.T) {
+ rig, app := newRigApp(t, nil)
+ cookies := signedIn(t, app, allowedAddress)
+ session, token := startPresenting(t, app, stepsDeck(t, app, cookies), cookies)
+ window := rig.Origin + "/p/" + session + "/notes?t=" + url.QueryEscape(token)
+ for _, size := range presenterSizes {
+ var w struct{ Now, Next float64 }
+ rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false),
+ chromedp.Navigate(window),
+ waitFor(`document.querySelector('[presenter-panel="next"] [presenter-frame]')`),
+ chromedp.Evaluate(`({ Now: document.querySelector('[presenter-panel="now"] [presenter-frame]').getBoundingClientRect().width,
+ Next: document.querySelector('[presenter-panel="next"] [presenter-frame]').getBoundingClientRect().width })`, &w))
+ if d := w.Next - w.Now/2; d > 1 || d < -1 {
+ t.Errorf("%dx%d: Now is %.1fpx wide and Next %.1fpx, want half", size.w, size.h, w.Now, w.Next)
+ }
+ }
+}
+
+// TestPresenterMenuFitsTheWindow: the ⋯ menu, open, lies inside the
+// window at every size, and every row of it can be reached.
+func TestPresenterMenuFitsTheWindow(t *testing.T) {
+ rig, app := newRigApp(t, nil)
+ cookies := signedIn(t, app, allowedAddress)
+ session, token := startPresenting(t, app, stepsDeck(t, app, cookies), cookies)
+ window := rig.Origin + "/p/" + session + "/notes?t=" + url.QueryEscape(token)
+ for _, size := range presenterSizes {
+ var m struct {
+ Top, Bottom, Left, Right, VW, VH float64
+ Rows int
+ Reach bool
+ SH float64
+ }
+ rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false),
+ chromedp.Navigate(window),
+ waitFor(`document.querySelector('[presenter-more]')`),
+ chromedp.Click(`[presenter-more]`, chromedp.ByQuery),
+ waitFor(`document.querySelector('[presenter-more-menu]').open`),
+ chromedp.Evaluate(`(() => { const menu = document.querySelector('[presenter-menu]'); const r = menu.getBoundingClientRect();
+ const rows = menu.querySelectorAll('button, a');
+ const style = getComputedStyle(menu);
+ return { Top: r.top, Bottom: r.bottom, Left: r.left, Right: r.right, VW: innerWidth, VH: innerHeight,
+ Rows: rows.length, SH: document.documentElement.scrollHeight,
+ Reach: menu.scrollHeight <= menu.clientHeight + 1 || style.overflowY === 'auto' }; })()`, &m))
+ if m.Rows != 6 {
+ t.Errorf("%dx%d: the menu has %d rows, want 6", size.w, size.h, m.Rows)
+ }
+ if m.Top < 0 || m.Left < 0 || m.Bottom > m.VH || m.Right > m.VW || !m.Reach || m.SH != m.VH {
+ t.Errorf("%dx%d: the open menu at (%.0f,%.0f)-(%.0f,%.0f) leaves the %.0f×%.0f window, or cannot reach its rows (document %.0f tall)",
+ size.w, size.h, m.Left, m.Top, m.Right, m.Bottom, m.VW, m.VH, m.SH)
+ }
+ }
+}