oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1package slides
2
3// scene_pages.go is what a page that runs scenes is handed for them
4// (scenes and clips spec §3): for each scene its slides show, the
5// bundle's address under the page's own surface (scenes.go's sealed
6// routes), and the scene's name, words and data, which the frame is
7// told in its init. fixtures/scene-layer.mjs reads it: from the talk
8// payload in the presenting windows (presenting_talk.go), and from a
9// <script type="application/json" slides-scenes> on the viewer and the
10// follow view, inside what those pages swap when the slide changes.
11// The editor reads its own document instead.
12
13import (
14 "net/url"
15 "regexp"
16
17 "amadan.net/oficina/slides/internal/slides/deck"
18)
19
20// pageScene is one scene as a page runs it.
21type pageScene struct {
22 Src string `json:"src"`
23 Name string `json:"name"`
24 Words map[string]string `json:"words"`
25 Data any `json:"data"`
26}
27
28// sceneCode is a bundle's ref as it may stand in a path: the hash the
29// store minted, never anything a URL would have to escape.
30var sceneCode = regexp.MustCompile(`^[0-9a-f]{64}$`)
31
32// scenesShown is every scene the slides at indices show, by id, as a
33// page reading the deck under base ("/d/{sqid}", "/s/{token}",
34// "/p/{session}") runs it. nil when they show none, so a page without
35// scenes is what it was before there were any.
36func scenesShown(d *deck.Deck, base string, indices ...int) map[string]pageScene {
37 var out map[string]pageScene
38 for _, i := range indices {
39 if i < 0 || i >= len(d.Slides) {
40 continue
41 }
42 for _, b := range d.Slides[i].Blocks {
43 id, _ := b.Props["scene"].(string)
44 if b.Type != "scene" || !deck.SceneID(id) {
45 continue
46 }
47 sc, ok := d.Scenes[id]
48 if _, done := out[id]; done || !ok || !sceneCode.MatchString(sc.Code) {
49 continue
50 }
51 if out == nil {
52 out = map[string]pageScene{}
53 }
54 words := sc.Words
55 if words == nil {
56 words = map[string]string{}
57 }
58 out[id] = pageScene{
59 Src: base + "/scenes/" + url.PathEscape(id) + "/" + url.PathEscape(sc.Code),
60 Name: sc.Name,
61 Words: words,
62 Data: sc.Data,
63 }
64 }
65 }
66 return out
67}
68