| 1 | package render |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | |
| 6 | "amadan.net/oficina/slides/internal/slides/deck" |
| 7 | ) |
| 8 | |
| 9 | // reveal is a slide drawn at a press: which presses its boxes and list |
| 10 | // items arrive on, and which press this is. A renderer without one |
| 11 | // (Options.Reveal nil, or the editor's stage) draws the finished slide |
| 12 | // and writes none of what is here. |
| 13 | type reveal struct { |
| 14 | at int |
| 15 | arrival map[deck.Reveal]int |
| 16 | } |
| 17 | |
| 18 | // newReveal is nil when the slide is not being drawn at a press. scenes |
| 19 | // is the deck's, which a scene block's presses count. |
| 20 | func newReveal(s deck.Slide, scenes map[string]deck.Scene, opt Options) *reveal { |
| 21 | if opt.Reveal == nil || opt.Editing { |
| 22 | return nil |
| 23 | } |
| 24 | return &reveal{at: *opt.Reveal, arrival: deck.ArrivalOf(s, scenes)} |
| 25 | } |
| 26 | |
| 27 | // attrs is data-press for a box (item -1) or a list item that arrives |
| 28 | // on a press, and data-waiting too while that press has not come. |
| 29 | func (r *reveal) attrs(id string, item int) []attr { |
| 30 | if r == nil { |
| 31 | return nil |
| 32 | } |
| 33 | n, ok := r.arrival[deck.Reveal{Block: id, Item: item}] |
| 34 | if !ok { |
| 35 | return nil |
| 36 | } |
| 37 | out := []attr{{name: "data-press", value: strconv.Itoa(n)}} |
| 38 | if n > r.at { |
| 39 | out = append(out, attr{name: "data-waiting", bare: true}) |
| 40 | } |
| 41 | return out |
| 42 | } |
| 43 | |
| 44 | // sectionAttrs is data-arrive: the deck's effect, said only when the |
| 45 | // slide is drawn at a press and the deck has one. |
| 46 | func (r *reveal) sectionAttrs(arrive string) []attr { |
| 47 | if r == nil || (arrive != "fade" && arrive != "rise") { |
| 48 | return nil |
| 49 | } |
| 50 | return []attr{{name: "data-arrive", value: arrive}} |
| 51 | } |
| 52 | |