suada 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +51 -2
- data/lib/suada/assets/motion.js +287 -0
- data/lib/suada/assets/presenter.html +1 -1
- data/lib/suada/assets/presenter.js +4 -4
- data/lib/suada/assets/shell.js +12 -11
- data/lib/suada/assets/viewer.js +103 -45
- data/lib/suada/attributes.rb +57 -0
- data/lib/suada/browser_output.rb +23 -10
- data/lib/suada/checker.rb +2 -2
- data/lib/suada/cli.rb +8 -4
- data/lib/suada/defaults/css/base.css +22 -0
- data/lib/suada/diagnostics.rb +1 -1
- data/lib/suada/emitter/distribution.rb +10 -5
- data/lib/suada/errors.rb +5 -4
- data/lib/suada/fragment.rb +18 -1
- data/lib/suada/frontmatter.rb +5 -2
- data/lib/suada/layout_parser.rb +12 -1
- data/lib/suada/manifest.rb +2 -1
- data/lib/suada/mapper.rb +32 -29
- data/lib/suada/motion/diff.rb +57 -0
- data/lib/suada/motion/glyphs.rb +158 -0
- data/lib/suada/motion/keyer.rb +111 -0
- data/lib/suada/parser/block_classifier.rb +10 -7
- data/lib/suada/parser/code_attributes.rb +41 -0
- data/lib/suada/parser/inline_spans.rb +112 -0
- data/lib/suada/parser/page_settings.rb +3 -1
- data/lib/suada/parser/slot_fence.rb +25 -13
- data/lib/suada/parser/step_splitter.rb +38 -0
- data/lib/suada/parser.rb +68 -14
- data/lib/suada/pipeline.rb +17 -13
- data/lib/suada/renderer.rb +54 -14
- data/lib/suada/server.rb +2 -2
- data/lib/suada/slot_contract.rb +1 -1
- data/lib/suada/theme.rb +26 -6
- data/lib/suada/version.rb +1 -1
- data/sig/compiler.rbs +25 -11
- data/sig/motion.rbs +56 -0
- data/sig/parser.rbs +28 -2
- metadata +10 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b19b8eada5c498e34946cccda5de30cd00c5f3ce4d80890a025232ae2228601b
|
|
4
|
+
data.tar.gz: 23bb273485f8b0c0727b88116a40fc7dd7e0c39154c8e5afe52d91b1809078d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c2cdfd9882270a2b1aea75da709135a7aeb9dab69f0a6b3b20e86f442d2fd9c5502b41a04354c4534812507cdcffa655ff5b6cb5005f22e8d6f0ed6997317c6
|
|
7
|
+
data.tar.gz: 08f5f37ea82b9934b407322dca7a08b1053f7f94194dadf57200ed5ec1830150480b2d355b10f167bfdfe0171565b74a188349d017f534993e3a5ad6de318461
|
data/README.md
CHANGED
|
@@ -37,7 +37,54 @@ puts "Hello"
|
|
|
37
37
|
```
|
|
38
38
|
````
|
|
39
39
|
|
|
40
|
-
Set deck-wide options in YAML frontmatter. Supported keys are `layouts`, `css`, `aspect_ratio`, `time`, `breaks` and `
|
|
40
|
+
Set deck-wide options in YAML frontmatter. Supported keys are `layouts`, `css`, `aspect_ratio`, `time`, `breaks`, `lang` and `transition`. A slide can specify `layout`, `skip` (jump over it during presentation) or `draft` (omit it from the output). Pair each section name with a duration. Sections start on the first slide and their durations must add up to the deck's planned time when supplied.
|
|
41
|
+
|
|
42
|
+
## Show a slide in steps
|
|
43
|
+
|
|
44
|
+
A line containing `+++` starts another state of the same slide. Each state is checked against its layout. Use `carry` to keep slots that you did not replace. For example, the second step below keeps the title and changes the body.
|
|
45
|
+
|
|
46
|
+
```markdown
|
|
47
|
+
<!-- {"key":"sum"} -->
|
|
48
|
+
# Add two terms
|
|
49
|
+
|
|
50
|
+
Start with 2.
|
|
51
|
+
|
|
52
|
+
+++ {carry}
|
|
53
|
+
|
|
54
|
+
Add 3. The result is 5.
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Open `#sum/2` to link directly to the second step. Arrow keys navigate steps before moving to another slide. Speaker notes belong to the whole slide. Run `suada layouts --explain sum/2` to inspect that step's layout. PDF export prints the last step of each slide by default. Pass `--steps all` to print every state.
|
|
58
|
+
|
|
59
|
+
### Animate a change
|
|
60
|
+
|
|
61
|
+
Give content a stable name with `[text]{k=name}`. On a morph transition, a matching name moves between its old and new positions. Use `from=name` for a new element that starts at another element's previous position. Ordinary paragraphs and list items with unchanged text match automatically.
|
|
62
|
+
|
|
63
|
+
Set `transition` to `cut`, `fade` or `morph` on a step or slide. By default, steps morph and slide boundaries cut. A separator such as `+++ {auto=800}` advances to that step after 800 ms. Use `in=rise`, `in=draw`, `in=fade` or `in=none` to choose an entrance, and `delay=200` to delay it by 200 ms. Direct links and reduced-motion preferences display the final state immediately.
|
|
64
|
+
|
|
65
|
+
### Follow a calculation
|
|
66
|
+
|
|
67
|
+
Add `glyphs` to a code fence to track individual characters through an edit. Keep the block's `k` to move the same expression. Use `from` and `flow` on a new block to show which characters produced its result.
|
|
68
|
+
|
|
69
|
+
````markdown
|
|
70
|
+
# Add the terms
|
|
71
|
+
|
|
72
|
+
```text {glyphs k=terms mark-a='3 + 4' wipe=a}
|
|
73
|
+
3 + 4
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
+++ {carry}
|
|
77
|
+
|
|
78
|
+
```text {glyphs k=result from=terms flow}
|
|
79
|
+
7
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
::: {call=result tone=b below}
|
|
83
|
+
The sum of both terms.
|
|
84
|
+
:::
|
|
85
|
+
````
|
|
86
|
+
|
|
87
|
+
A marker can select a unique literal or a one-based line and column range such as `mark-a='2:1-4'`. In prose, use `[a phrase]{k=term mark=a wipe}`. A callout points to a named element in the current step. CSS can style `.suada-plate`, `.suada-mark[data-tone="a"]` and `.suada-call[data-tone="b"]`. Set `--suada-morph-duration` or `--suada-enter-lag` on a slide to change its timing. The [motion catalog](docs/motion-catalog.md) includes a 12-slide example.
|
|
41
88
|
|
|
42
89
|
## Check a layout
|
|
43
90
|
|
|
@@ -65,7 +112,7 @@ CSS files in `css/` are combined in filename order. Use selectors such as `[data
|
|
|
65
112
|
| `suada preview [--no-open]` | Open a live preview on localhost. |
|
|
66
113
|
| `suada present` | Open the presenter view with notes, agenda and timer. Open the audience window from there. |
|
|
67
114
|
| `suada export pdf -o talk.pdf` | Print one page per slide using Chrome. |
|
|
68
|
-
| `suada lint` | Identify
|
|
115
|
+
| `suada lint` | Identify overflowing slots, markers and callouts on each step. |
|
|
69
116
|
| `suada publish -- COMMAND [ARG...]` | Check the distribution for speaker notes and presenter files, then run the deployment command. |
|
|
70
117
|
|
|
71
118
|
PDF export and lint require Chrome or Chromium and the optional `ferrum` gem (`gem install ferrum`). Under Bundler, add `ferrum` to your application's Gemfile. Speaker notes stay in local preview and presenter caches. Serve only the distribution directory.
|
|
@@ -83,6 +130,8 @@ result = Suada.build("deck.md", out: "dist")
|
|
|
83
130
|
puts result.slide_count
|
|
84
131
|
```
|
|
85
132
|
|
|
133
|
+
`slide.steps` contains the rendered states in order. `slide.html` contains all their sections, as does the slide's HTML file in a distribution. Manifest version 2 records the number of steps and the entrance transition for each slide.
|
|
134
|
+
|
|
86
135
|
## Development
|
|
87
136
|
|
|
88
137
|
Run `bundle install` and `bundle exec rake`. Set `SUADA_BROWSER_TEST=1` to include Chrome checks.
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
const transitions = new WeakMap();
|
|
2
|
+
|
|
3
|
+
function cssTime(style, name, fallback) {
|
|
4
|
+
const value = style.getPropertyValue(name).trim();
|
|
5
|
+
const match = /^([\d.]+)(ms|s)$/.exec(value);
|
|
6
|
+
if (!match) return fallback;
|
|
7
|
+
const ms = Number(match[1]) * (match[2] === "s" ? 1000 : 1);
|
|
8
|
+
return Number.isFinite(ms) ? ms : fallback;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function snapshot(section) {
|
|
12
|
+
const keys = new Map();
|
|
13
|
+
for (const el of section.querySelectorAll("[data-k]")) {
|
|
14
|
+
const style = getComputedStyle(el);
|
|
15
|
+
keys.set(el.dataset.k, {el, rect: el.getBoundingClientRect(), color: style.color, bg: style.backgroundColor});
|
|
16
|
+
}
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function units(parent, result = []) {
|
|
21
|
+
for (const el of parent.children) {
|
|
22
|
+
if (el.hasAttribute("data-suada-glyphs")) units(el, result);
|
|
23
|
+
else if (el.hasAttribute("data-k") || !el.querySelector("[data-k]")) result.push(el);
|
|
24
|
+
else units(el, result);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function settle(frame) {
|
|
30
|
+
const state = transitions.get(frame);
|
|
31
|
+
if (!state) return;
|
|
32
|
+
transitions.delete(frame);
|
|
33
|
+
state.animations.forEach(animation => animation.cancel());
|
|
34
|
+
for (const [el, display] of state.inlineDisplays) el.style.display = display;
|
|
35
|
+
state.to.style.opacity = state.opacity;
|
|
36
|
+
state.from?.remove();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function transition(frame, from, to, {scale = 1, direction = 0, reducedMotion = false, sections = []} = {}) {
|
|
40
|
+
settle(frame);
|
|
41
|
+
const state = {from, to, opacity: to.style.opacity, animations: [], inlineDisplays: new Map()};
|
|
42
|
+
transitions.set(frame, state);
|
|
43
|
+
const mode = !from || !direction || reducedMotion ? "cut" :
|
|
44
|
+
(direction < 0 ? from.dataset.transition : to.dataset.transition) || "cut";
|
|
45
|
+
if (from) { from.inert = true; from.setAttribute("aria-hidden", "true"); }
|
|
46
|
+
Object.assign(to.style, {position: "absolute", inset: "0"});
|
|
47
|
+
if (mode !== "cut") to.style.opacity = "0";
|
|
48
|
+
frame.append(to);
|
|
49
|
+
if (mode === "cut") from?.remove();
|
|
50
|
+
await decorate(to, {scale});
|
|
51
|
+
if (transitions.get(frame) !== state) return;
|
|
52
|
+
if (mode === "cut") { settle(frame); return; }
|
|
53
|
+
to.style.opacity = state.opacity;
|
|
54
|
+
|
|
55
|
+
const style = getComputedStyle(to);
|
|
56
|
+
const duration = cssTime(style, "--suada-morph-duration", 420);
|
|
57
|
+
const easing = style.getPropertyValue("--suada-morph-easing").trim() || "cubic-bezier(.22,1,.36,1)";
|
|
58
|
+
const exitTime = cssTime(style, "--suada-exit-duration", 150);
|
|
59
|
+
const enterTime = cssTime(style, "--suada-enter-duration", 220);
|
|
60
|
+
const lag = cssTime(style, "--suada-enter-lag", 110);
|
|
61
|
+
|
|
62
|
+
const play = (el, keyframes, duration, delay = 0, easing = "ease-out") => {
|
|
63
|
+
const animation = el.animate(keyframes, {duration, delay, easing, fill: "backwards"});
|
|
64
|
+
state.animations.push(animation);
|
|
65
|
+
return animation.finished.catch(() => {});
|
|
66
|
+
};
|
|
67
|
+
if (mode === "fade") {
|
|
68
|
+
play(to, [{opacity: 0}, {opacity: 1}], enterTime);
|
|
69
|
+
} else {
|
|
70
|
+
const before = snapshot(from);
|
|
71
|
+
const earlier = new Map();
|
|
72
|
+
if (direction > 0) {
|
|
73
|
+
for (const el of to.querySelectorAll("[data-from-step]")) {
|
|
74
|
+
const step = Number(el.dataset.fromStep);
|
|
75
|
+
if (earlier.has(step) || !sections[step - 1]) continue;
|
|
76
|
+
const ghost = sections[step - 1].cloneNode(true);
|
|
77
|
+
Object.assign(ghost.style, {position: "absolute", inset: "0", visibility: "hidden"});
|
|
78
|
+
ghost.inert = true;
|
|
79
|
+
frame.append(ghost);
|
|
80
|
+
earlier.set(step, snapshot(ghost));
|
|
81
|
+
ghost.remove();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const after = to.querySelector(".suada-call") ? snapshot(to) : null;
|
|
85
|
+
function callDelay(el) {
|
|
86
|
+
const waitFraction = style.getPropertyValue("--suada-call-wait").trim();
|
|
87
|
+
const fraction = waitFraction === "" ? .45 : Number(waitFraction);
|
|
88
|
+
return Math.max(60, ...callTargets(el, to).map(target => {
|
|
89
|
+
const key = target.dataset.k, previous = before.get(key);
|
|
90
|
+
if (!previous) return lag + Number(target.dataset.delay || 0) + enterTime;
|
|
91
|
+
const r = after.get(key).rect, old = previous.rect;
|
|
92
|
+
return ["left", "top", "width", "height"].some(k => Math.abs(old[k] - r[k]) > .5 * scale) ? duration * fraction : 60;
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
const moving = units(to);
|
|
96
|
+
for (const el of moving) {
|
|
97
|
+
if (getComputedStyle(el).display === "inline" && el.getClientRects().length === 1) {
|
|
98
|
+
state.inlineDisplays.set(el, el.style.display);
|
|
99
|
+
el.style.display = "inline-block";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const positions = moving.map(el => el.getBoundingClientRect());
|
|
103
|
+
moving.forEach((el, i) => {
|
|
104
|
+
const key = el.dataset.k, kept = before.get(key);
|
|
105
|
+
const block = el.closest("[data-suada-glyphs]");
|
|
106
|
+
const delay = Number(el.dataset.delay || block?.dataset.delay || 0);
|
|
107
|
+
const source = kept || (direction > 0 && (earlier.get(Number(el.dataset.fromStep)) || before).get(el.dataset.from));
|
|
108
|
+
if (direction > 0 && el.matches(".suada-call") && !kept) {
|
|
109
|
+
el.setAttribute("data-suada-enter", "");
|
|
110
|
+
play(el, [{opacity: 0}, {opacity: 1}], enterTime, callDelay(el), easing);
|
|
111
|
+
} else if (source) {
|
|
112
|
+
if (kept) kept.el.style.visibility = "hidden";
|
|
113
|
+
const r = positions[i], original = source.rect;
|
|
114
|
+
const dx = (original.left - r.left) / scale, dy = (original.top - r.top) / scale;
|
|
115
|
+
const sy = r.height ? original.height / r.height : 1;
|
|
116
|
+
const box = el.matches(".suada-plate,.suada-mark");
|
|
117
|
+
const sx = box && r.width ? original.width / r.width : sy;
|
|
118
|
+
const target = getComputedStyle(el);
|
|
119
|
+
if (Math.abs(dx) < .01 && Math.abs(dy) < .01 && Math.abs(sx - 1) < .001 && Math.abs(sy - 1) < .001 &&
|
|
120
|
+
source.color === target.color && source.bg === target.backgroundColor) return;
|
|
121
|
+
play(el, [{transformOrigin: "0 0", transform: `translate(${dx}px,${dy}px) scale(${sx},${sy})`, color: source.color, backgroundColor: source.bg},
|
|
122
|
+
{transformOrigin: "0 0", transform: "none", color: target.color, backgroundColor: target.backgroundColor}],
|
|
123
|
+
duration, kept ? 0 : delay, easing);
|
|
124
|
+
} else {
|
|
125
|
+
const effect = direction < 0 ? "fade" : el.dataset.in || block?.dataset.in || "fade";
|
|
126
|
+
if (effect === "none") return;
|
|
127
|
+
el.setAttribute("data-suada-enter", "");
|
|
128
|
+
if (effect === "rise") {
|
|
129
|
+
play(el, [{opacity: 0, transform: "translateY(.6em)"}, {opacity: 1, transform: "none"}], enterTime + 140, lag + delay, easing);
|
|
130
|
+
} else if (effect === "draw") {
|
|
131
|
+
play(el, [{transformOrigin: "left", transform: "scaleX(0)"}, {transformOrigin: "left", transform: "scaleX(1)"}],
|
|
132
|
+
enterTime + 80, lag + 50 + delay, "ease-in-out");
|
|
133
|
+
} else {
|
|
134
|
+
play(el, [{opacity: 0}, {opacity: 1}], enterTime, direction < 0 ? 0 : lag + delay);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
from.style.zIndex = "1";
|
|
140
|
+
from.style.pointerEvents = "none";
|
|
141
|
+
play(from, [{opacity: 1}, {opacity: 0}], exitTime).then(() => from.remove());
|
|
142
|
+
await Promise.all(state.animations.map(a => a.finished.catch(() => {})));
|
|
143
|
+
if (transitions.get(frame) === state) settle(frame);
|
|
144
|
+
}
|
|
145
|
+
const canvas = document.createElement("canvas").getContext("2d");
|
|
146
|
+
|
|
147
|
+
function bounds(boxes) {
|
|
148
|
+
return {
|
|
149
|
+
left: Math.min(...boxes.map(r => r.left)), top: Math.min(...boxes.map(r => r.top)),
|
|
150
|
+
right: Math.max(...boxes.map(r => r.right)), bottom: Math.max(...boxes.map(r => r.bottom))
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function place(box, rect, section, scale, padding = 0) {
|
|
155
|
+
const origin = section.getBoundingClientRect();
|
|
156
|
+
Object.assign(box.style, {
|
|
157
|
+
position: "absolute", pointerEvents: "none",
|
|
158
|
+
left: `${(rect.left - origin.left) / scale - section.clientLeft - padding}px`,
|
|
159
|
+
top: `${(rect.top - origin.top) / scale - section.clientTop - padding}px`,
|
|
160
|
+
width: `${(rect.right - rect.left) / scale + 2 * padding}px`,
|
|
161
|
+
height: `${(rect.bottom - rect.top) / scale + 2 * padding}px`
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function textLines(element, scale) {
|
|
166
|
+
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
|
|
167
|
+
const range = document.createRange();
|
|
168
|
+
const lines = [];
|
|
169
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
170
|
+
const style = getComputedStyle(node.parentElement);
|
|
171
|
+
canvas.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
|
|
172
|
+
const size = parseFloat(style.fontSize);
|
|
173
|
+
const cap = canvas.measureText("H").actualBoundingBoxAscent;
|
|
174
|
+
const xHeight = canvas.measureText("x").actualBoundingBoxAscent;
|
|
175
|
+
let offset = 0;
|
|
176
|
+
for (const char of node.textContent) {
|
|
177
|
+
range.setStart(node, offset);
|
|
178
|
+
offset += char.length;
|
|
179
|
+
range.setEnd(node, offset);
|
|
180
|
+
const r = range.getBoundingClientRect();
|
|
181
|
+
if (!r.width || !r.height || !char.trim()) continue;
|
|
182
|
+
const metrics = canvas.measureText(char);
|
|
183
|
+
const baseline = r.top + metrics.fontBoundingBoxAscent * scale;
|
|
184
|
+
const ascent = /\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}|\p{Script=Hangul}/u.test(char) ?
|
|
185
|
+
metrics.actualBoundingBoxAscent : /[a-z]/.test(char) ? xHeight : cap;
|
|
186
|
+
const ink = {left: r.left - metrics.actualBoundingBoxLeft * scale,
|
|
187
|
+
right: r.right - (metrics.width - metrics.actualBoundingBoxRight) * scale,
|
|
188
|
+
top: baseline - ascent * scale, bottom: baseline + Math.max(0, metrics.actualBoundingBoxDescent) * scale};
|
|
189
|
+
const previous = lines.at(-1);
|
|
190
|
+
if (previous && Math.abs(baseline - previous.baseline) < size * .3 * scale) {
|
|
191
|
+
previous.rect = bounds([previous.rect, ink]);
|
|
192
|
+
} else {
|
|
193
|
+
lines.push({rect: ink, baseline, size});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return lines;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function markerBoxes(section, scale) {
|
|
201
|
+
const groups = [];
|
|
202
|
+
for (const block of section.querySelectorAll("[data-suada-glyphs]")) {
|
|
203
|
+
let group;
|
|
204
|
+
for (const glyph of block.querySelectorAll(".suada-g")) {
|
|
205
|
+
const tone = glyph.dataset.mark;
|
|
206
|
+
if (!tone) { group = null; continue; }
|
|
207
|
+
const line = textLines(glyph, scale)[0];
|
|
208
|
+
const rect = glyph.getBoundingClientRect();
|
|
209
|
+
if (!group || tone !== group.tone || Math.abs(rect.top - group.top) >= 4 * scale ||
|
|
210
|
+
Math.abs(rect.left - group.right) >= 4 * scale) {
|
|
211
|
+
group = {tone, key: glyph.dataset.k, top: rect.top, right: rect.right, wipe: false, boxes: [], size: 0};
|
|
212
|
+
groups.push(group);
|
|
213
|
+
}
|
|
214
|
+
group.right = rect.right;
|
|
215
|
+
group.wipe ||= glyph.dataset.markIn === "wipe";
|
|
216
|
+
if (line) { group.boxes.push(line.rect); group.size = line.size; }
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const [i, span] of [...section.querySelectorAll("[data-mark]:not(.suada-g)")].entries()) {
|
|
220
|
+
textLines(span, scale).forEach((line, n) => groups.push({
|
|
221
|
+
tone: span.dataset.mark, key: `${span.dataset.k || `~span${i}`}/${n}`, wipe: span.dataset.markIn === "wipe",
|
|
222
|
+
boxes: [line.rect], size: line.size
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
return groups;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function drawDecorations(section, scale) {
|
|
229
|
+
const output = document.createDocumentFragment();
|
|
230
|
+
function box(name, key) {
|
|
231
|
+
const el = document.createElement("div");
|
|
232
|
+
el.className = name;
|
|
233
|
+
el.dataset.k = key;
|
|
234
|
+
el.setAttribute("aria-hidden", "true");
|
|
235
|
+
el.style.zIndex = name === "suada-plate" ? "-2" : "-1";
|
|
236
|
+
output.append(el);
|
|
237
|
+
return el;
|
|
238
|
+
}
|
|
239
|
+
if (getComputedStyle(section).position === "static") section.style.position = "relative";
|
|
240
|
+
section.style.isolation = "isolate";
|
|
241
|
+
section.querySelectorAll(":scope > .suada-mark, :scope > .suada-plate").forEach(el => el.remove());
|
|
242
|
+
for (const block of section.querySelectorAll("[data-suada-glyphs]")) {
|
|
243
|
+
const plate = box("suada-plate", `plate:${block.dataset.k || block.dataset.plateKey}`);
|
|
244
|
+
place(plate, block.getBoundingClientRect(), section, scale);
|
|
245
|
+
}
|
|
246
|
+
const value = getComputedStyle(section).getPropertyValue("--suada-mark-padding").trim();
|
|
247
|
+
const padding = value === "" ? .14 : Number(value);
|
|
248
|
+
for (const group of markerBoxes(section, scale)) {
|
|
249
|
+
if (!group.boxes.length) continue;
|
|
250
|
+
const mark = box("suada-mark", `mark:${group.key}`);
|
|
251
|
+
mark.dataset.tone = group.tone;
|
|
252
|
+
mark.classList.toggle("suada-tone-b", group.tone === "b");
|
|
253
|
+
if (group.wipe) mark.dataset.in = "draw";
|
|
254
|
+
place(mark, bounds(group.boxes), section, scale, padding * group.size);
|
|
255
|
+
}
|
|
256
|
+
section.prepend(output);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function callTargets(call, section) {
|
|
260
|
+
return call.dataset.on.trim().split(/[\s,]+/).map(key => section.querySelector(`[data-k="${CSS.escape(key)}"]`)).filter(Boolean);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function positionCalls(section, scale) {
|
|
264
|
+
const frame = section.getBoundingClientRect();
|
|
265
|
+
for (const call of section.querySelectorAll(".suada-call")) {
|
|
266
|
+
const targets = callTargets(call, section);
|
|
267
|
+
if (!targets.length) continue;
|
|
268
|
+
call.classList.toggle("suada-tone-b", call.dataset.tone === "b");
|
|
269
|
+
Object.assign(call.style, {position: "absolute", margin: "0", maxWidth: "calc(100% - 24px)", boxSizing: "border-box"});
|
|
270
|
+
const target = bounds(targets.map(el => el.getBoundingClientRect()));
|
|
271
|
+
const center = ((target.left + target.right) / 2 - frame.left) / scale;
|
|
272
|
+
const size = call.getBoundingClientRect();
|
|
273
|
+
const left = Math.max(12, Math.min(center - size.width / (2 * scale), (frame.width - size.width) / scale - 12));
|
|
274
|
+
call.style.left = `${left}px`;
|
|
275
|
+
const below = call.hasAttribute("data-below");
|
|
276
|
+
call.style.top = `${below ? (target.bottom - frame.top) / scale + 8 : (target.top - frame.top - size.height) / scale - 8}px`;
|
|
277
|
+
call.style.setProperty("--suada-call-tail", `${center - left}px`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export async function decorate(section, {scale = 1} = {}) {
|
|
282
|
+
section.getBoundingClientRect(); // Trigger font requests before waiting for them.
|
|
283
|
+
await document.fonts.ready;
|
|
284
|
+
if (!section.querySelector("[data-suada-glyphs], [data-mark], .suada-call")) return;
|
|
285
|
+
drawDecorations(section, scale);
|
|
286
|
+
positionCalls(section, scale);
|
|
287
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*{box-sizing:border-box}body{margin:0;background:#15171a;color:#f1f2f4;font:1rem/1.45 system-ui}header,main,footer{max-width:110rem;margin:auto;padding:1rem clamp(1rem,3vw,3rem)}header,footer{display:flex;gap:1rem;align-items:center;flex-wrap:wrap}header strong{margin-right:auto}button{font:inherit;border:1px solid #747880;border-radius:.3rem;color:inherit;background:#292d32;padding:.35rem .8rem;cursor:pointer}button:focus-visible{outline:3px solid #aad4ff}main{display:grid;grid-template-columns:minmax(0,2fr) minmax(13rem,1fr);gap:1rem 1.5rem}h2{font-size:1rem;font-weight:500;margin:.4rem 0;color:#bec4cb}.screen{position:relative;background:#222529;overflow:hidden;aspect-ratio:16/9}#notes{white-space:pre-wrap;overflow-wrap:anywhere;font:1.15rem/1.6 system-ui;margin:0}ol{padding-left:1.5rem;margin:0}li[aria-current]{font-weight:700;color:#d7ebff}#clock,#position{font-variant-numeric:tabular-nums}#error{white-space:pre-wrap;color:#ffb8ac;padding:1rem}footer{border-top:1px solid #383c41}button[aria-pressed=true]{background:#404b59}@media(max-width:650px){main{grid-template-columns:1fr}#next{max-height:10rem}}
|
|
5
5
|
</style></head><body>
|
|
6
6
|
<header><strong id="title">Presenter view</strong><output id="clock" aria-label="Elapsed time">0:00</output><button id="timer" aria-pressed="false">Start timer</button><button id="audience">Open audience window</button></header>
|
|
7
|
-
<main><section><h2>Current slide</h2><div class="screen" id="stage"></div></section><section><h2>
|
|
7
|
+
<main><section><h2>Current slide</h2><div class="screen" id="stage"></div></section><section><h2>Up next</h2><div class="screen" id="next"></div></section>
|
|
8
8
|
<section><h2>Speaker notes</h2><p id="notes" aria-live="polite"></p></section><section id="agenda-panel" hidden><h2>Agenda</h2><ol id="agenda"></ol></section></main>
|
|
9
9
|
<footer><button data-to="prev" aria-label="Previous slide">←</button><output id="position" aria-label="Slide position"></output><button data-to="next" aria-label="Next slide">→</button><button id="end">End presentation</button></footer><pre id="error" role="alert" hidden></pre>
|
|
10
10
|
<script type="module" src="presenter.js"></script></body></html>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {readJSON, viewport, showError} from "./viewer.js";
|
|
1
|
+
import {adjacent, readJSON, viewport, showError} from "./viewer.js";
|
|
2
2
|
import {start} from "./shell.js";
|
|
3
3
|
|
|
4
4
|
function duration(ms) {
|
|
@@ -10,10 +10,10 @@ async function present() {
|
|
|
10
10
|
document.querySelector("#title").textContent = manifest.title || "Presenter view";
|
|
11
11
|
for (const stage of document.querySelectorAll(".screen")) stage.style.aspectRatio = `${manifest.canvasWidth}/${manifest.canvasHeight}`;
|
|
12
12
|
const next = viewport(document.querySelector("#next"), manifest);
|
|
13
|
-
window.addEventListener("suada:
|
|
13
|
+
window.addEventListener("suada:stepchange", ({detail}) => {
|
|
14
14
|
document.querySelector("#notes").textContent = notes[detail.key] || "";
|
|
15
|
-
const
|
|
16
|
-
next(
|
|
15
|
+
const following = adjacent(manifest.slides, detail, 1, true);
|
|
16
|
+
next(following?.index, following?.step).catch(showError);
|
|
17
17
|
});
|
|
18
18
|
const rows = (manifest.sections || []).map(s => {
|
|
19
19
|
const row = document.createElement("li");
|
data/lib/suada/assets/shell.js
CHANGED
|
@@ -2,10 +2,10 @@ import {readJSON, viewer, issue, showError} from "./viewer.js";
|
|
|
2
2
|
|
|
3
3
|
export async function start(manifest) {
|
|
4
4
|
manifest ||= await readJSON("manifest.json");
|
|
5
|
-
const deck = await viewer(manifest, {skip: true});
|
|
5
|
+
const deck = await viewer(manifest, {skip: true, auto: !window.opener});
|
|
6
6
|
const channel = new BroadcastChannel("suada-sync");
|
|
7
7
|
let timer = {elapsed: 0, since: null, sections: {}};
|
|
8
|
-
let
|
|
8
|
+
let remote = null, closed = false;
|
|
9
9
|
function sectionAt(index) {
|
|
10
10
|
return (manifest.sections || []).findIndex(s => index >= s.start && index <= s.end);
|
|
11
11
|
}
|
|
@@ -18,8 +18,8 @@ export async function start(manifest) {
|
|
|
18
18
|
if (section >= 0) timer.sections[section] = (timer.sections[section] || 0) + delta;
|
|
19
19
|
timer.since = now;
|
|
20
20
|
}
|
|
21
|
-
function sync() {
|
|
22
|
-
channel.postMessage({type: "state", key: manifest.slides[deck.index]?.key, timer});
|
|
21
|
+
function sync(direction = 0) {
|
|
22
|
+
channel.postMessage({type: "state", key: manifest.slides[deck.index]?.key, step: deck.step, direction, timer});
|
|
23
23
|
}
|
|
24
24
|
function finish() {
|
|
25
25
|
if (closed) return;
|
|
@@ -39,16 +39,17 @@ export async function start(manifest) {
|
|
|
39
39
|
if (data.type === "hello") { sync(); return; }
|
|
40
40
|
if (data.type !== "state") return;
|
|
41
41
|
timer = data.timer;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const target = remote || {key: manifest.slides[deck.index]?.key, step: deck.step};
|
|
43
|
+
if (data.key && (data.key !== target.key || data.step !== target.step)) {
|
|
44
|
+
remote = {key: data.key, step: data.step};
|
|
45
|
+
issue(remote, data.direction);
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
|
-
window.addEventListener("suada:
|
|
48
|
-
if (detail.key ===
|
|
49
|
-
|
|
48
|
+
window.addEventListener("suada:stepchange", ({detail}) => {
|
|
49
|
+
if (detail.key === remote?.key && detail.step === remote.step) { remote = null; return; }
|
|
50
|
+
remote = null;
|
|
50
51
|
tick(detail.previousIndex);
|
|
51
|
-
sync();
|
|
52
|
+
sync(detail.direction);
|
|
52
53
|
});
|
|
53
54
|
function timerControl(action) {
|
|
54
55
|
tick(deck.index);
|