forked from astefanutti/decktape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbespoke.js
78 lines (68 loc) · 2.13 KB
/
bespoke.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
export const help =
`Requires the bespoke-extern module to expose the Bespoke.js API to a global variable named
'bespoke' and provides access to the collection of deck instances via 'bespoke.decks
and the most recent deck via 'bespoke.deck'.`;
export const create = page => new Bespoke(page);
class Bespoke {
constructor(page) {
this.page = page;
}
getName() {
return 'Bespoke.js';
}
isActive() {
return this.page.evaluate(_ => (window.bespoke || {}).deck ? (deck = bespoke.deck) : false);
}
configure() {
return this.page.evaluate(_ => {
document.body.classList.add('export');
if (deck.parent.classList.contains('bespoke-overview'))
deck.fire('overview');
deck.slide(0);
// Advance to last build on first slide (internal state in bespoke-bullets makes this tricky)
let builds = 0;
const one = deck.slides.length === 1;
if (one)
deck.slides.push(document.createElement('section'));
do
++builds && deck.next();
while (deck.slide() === 0);
for (let i = 0; i < builds; i++)
i === 0 ? deck.slide(0) : deck.next();
if (one)
deck.slides.splice(-1, 1);
});
}
size() {
return this.page.evaluate(_ => {
const style = getComputedStyle(deck.slides[0]);
return {
width : parseInt(style.width, 10),
height : parseInt(style.height, 10),
};
});
}
slideCount() {
return this.page.evaluate(_ => deck.slides.length);
}
currentSlideIndex() {
return this.page.evaluate(_ => deck.slide() + 1);
}
nextSlide() {
return this.page.evaluate(_ => {
// Advance to last build on next slide (internal state in bespoke-bullets makes this tricky)
const next = deck.slide() + 1;
const beforeLast = next === deck.slides.length - 1;
let builds = 0;
if (beforeLast)
deck.slides.push(document.createElement('section'));
do
++builds && deck.next();
while (deck.slide() <= next);
for (let i = 1; i < builds; i++)
i === 1 ? deck.slide(next) : deck.next();
if (beforeLast)
deck.slides.splice(-1, 1);
});
}
}