1 | import { css, html, LitElement, unsafeCSS } from 'lit';
|
2 | import themeCss from '../styles/theme.css?type=css';
|
3 |
|
4 | class PresenterMode extends LitElement {
|
5 |
|
6 | static get properties() {
|
7 | return {
|
8 | slides: {
|
9 | type: Array
|
10 | },
|
11 | index: Number
|
12 | };
|
13 | }
|
14 |
|
15 | static get styles() {
|
16 | return css`
|
17 | ${unsafeCSS(themeCss)}
|
18 |
|
19 | .fullscreen-container {
|
20 | display: none;
|
21 | }
|
22 |
|
23 | .fullscreen-container-on {
|
24 | background-color: var(--color-primary);
|
25 | display: block;
|
26 | z-index: 100;
|
27 | position: absolute;
|
28 | top: 0;
|
29 | left: 0;
|
30 | width: 100%;
|
31 | height: 100%;
|
32 | }
|
33 |
|
34 | iframe {
|
35 | background-color: var(--color-primary);
|
36 | min-width: 100%;
|
37 | min-height: 100%;
|
38 | width: 100%;
|
39 | height: 100%;
|
40 | }
|
41 | `;
|
42 | }
|
43 |
|
44 | constructor() {
|
45 | super();
|
46 | this.slides = [];
|
47 | this.index = 0;
|
48 | }
|
49 |
|
50 | connectedCallback() {
|
51 | super.connectedCallback();
|
52 |
|
53 | window.addEventListener('message', (postMessage) => {
|
54 | this.slideNavigationKeyHander(postMessage.data);
|
55 | });
|
56 |
|
57 | document.addEventListener('keydown', (event) => {
|
58 | this.slideNavigationKeyHander(event.key);
|
59 | });
|
60 | }
|
61 |
|
62 | enablePresenterMode() {
|
63 | this.setCurrentSlide();
|
64 | this.shadowRoot.querySelector('div').classList.add('fullscreen-container-on');
|
65 | }
|
66 |
|
67 | setCurrentSlide(index = 0) {
|
68 | this.shadowRoot.querySelector('iframe').setAttribute('src', this.slides[index].route);
|
69 | }
|
70 |
|
71 | slideNavigationKeyHander(keyName) {
|
72 | if (keyName === 'ArrowRight' || keyName === 'Spacebar' || keyName === 'Enter') {
|
73 | if ((this.index + 1) !== this.slides.length) {
|
74 | this.index = this.index += 1;
|
75 | this.setCurrentSlide(this.index);
|
76 | }
|
77 | } else if (keyName === 'ArrowLeft') {
|
78 | if (this.index > 0) {
|
79 | this.index = this.index -= 1;
|
80 | this.setCurrentSlide(this.index);
|
81 | }
|
82 | } else if (keyName === 'Escape') {
|
83 | this.shadowRoot.querySelector('div').classList.remove('fullscreen-container-on');
|
84 | }
|
85 | }
|
86 |
|
87 | render() {
|
88 | return html`
|
89 | <button @click=${this.enablePresenterMode}>Presenter Mode</button>
|
90 |
|
91 | <div class="fullscreen-container">
|
92 | <iframe></iframe>
|
93 | </div>
|
94 | `;
|
95 | }
|
96 | }
|
97 |
|
98 | customElements.define('presenter-mode', PresenterMode); |
\ | No newline at end of file |