@sparkle-learning/core 0.0.23 → 0.0.24
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.
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/sparkle-animation-player.cjs.entry.js +5 -3
- package/dist/cjs/sparkle-core.cjs.js +1 -1
- package/dist/cjs/sparkle-youtube.cjs.entry.js +14 -168
- package/dist/collection/assets/img/forward.svg +5 -0
- package/dist/collection/assets/img/pause.svg +5 -0
- package/dist/collection/assets/img/play-symbol.svg +8 -0
- package/dist/collection/assets/img/play.svg +4 -0
- package/dist/collection/assets/img/rewind.svg +5 -0
- package/dist/collection/components/sparkle-animation-player/sparkle-animation-player.css +1 -1
- package/dist/collection/components/sparkle-animation-player/sparkle-animation-player.js +6 -4
- package/dist/collection/components/sparkle-youtube/sparkle-youtube.css +16 -0
- package/dist/collection/components/sparkle-youtube/sparkle-youtube.js +25 -307
- package/dist/collection/pages/course/welcome-to-mind-body/introduction/animation/m4l1p1_part1.js +2727 -0
- package/dist/collection/pages/course/welcome-to-mind-body/introduction/animation/m4l1p1_part2.js +2042 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/sparkle-animation-player.entry.js +5 -3
- package/dist/esm/sparkle-core.js +1 -1
- package/dist/esm/sparkle-youtube.entry.js +15 -169
- package/dist/sparkle-core/p-1e1f5e98.entry.js +1 -0
- package/dist/sparkle-core/{p-0bd3e81f.entry.js → p-d75003d2.entry.js} +1 -1
- package/dist/sparkle-core/sparkle-core.esm.js +1 -1
- package/dist/types/components/sparkle-youtube/sparkle-youtube.d.ts +6 -20
- package/dist/types/components.d.ts +3 -14
- package/package.json +1 -1
- package/dist/sparkle-core/p-d069b834.entry.js +0 -1
@@ -4,188 +4,34 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
const index = require('./index-fbf4d3bf.js');
|
6
6
|
|
7
|
-
const sparkleYoutubeCss = ":host(.loaded) div.youtube-container{opacity:var(--sparkle-youtube-opacity-loaded, 1)}div.youtube-container{opacity:var(--sparkle-youtube-opacity-not-loaded, 0);transition:var(--sparkle-youtube-transition, opacity 0.15s linear)}";
|
7
|
+
const sparkleYoutubeCss = ":host(.loaded) div.youtube-container{opacity:var(--sparkle-youtube-opacity-loaded, 1)}div.youtube-container{opacity:var(--sparkle-youtube-opacity-not-loaded, 0);transition:var(--sparkle-youtube-transition, opacity 0.15s linear)}.embed-container{position:relative;padding-bottom:56.25%;height:0;overflow:hidden;max-width:100%}.embed-container iframe,.embed-container object,.embed-container embed{position:absolute;top:0;left:0;width:100%;height:100%}";
|
8
8
|
|
9
9
|
const SparkleYoutube = class {
|
10
10
|
constructor(hostRef) {
|
11
11
|
index.registerInstance(this, hostRef);
|
12
|
-
this.
|
13
|
-
this.instant = false;
|
14
|
-
this.loading = false;
|
15
|
-
this.loaded = false;
|
12
|
+
this.video_thumbnail = '';
|
16
13
|
}
|
17
|
-
|
18
|
-
|
14
|
+
componentDidLoad() {
|
15
|
+
this.classMode = this.initialClassMode;
|
16
|
+
this.classModeChanged();
|
19
17
|
}
|
20
|
-
|
21
|
-
if (this.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
async updateIFrame(width, height) {
|
26
|
-
const iframe = this.el.shadowRoot.querySelector('iframe');
|
27
|
-
if (iframe) {
|
28
|
-
iframe.width = '' + width;
|
29
|
-
iframe.height = '' + height;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
lazyLoadContent() {
|
33
|
-
return this.createIFrame();
|
34
|
-
}
|
35
|
-
async onSrcUpdate() {
|
36
|
-
await this.createIFrame();
|
37
|
-
}
|
38
|
-
play() {
|
39
|
-
return this.playPauseVideo(true);
|
40
|
-
}
|
41
|
-
pause() {
|
42
|
-
return this.playPauseVideo(false);
|
43
|
-
}
|
44
|
-
addPreconnectLink() {
|
45
|
-
return new Promise((resolve) => {
|
46
|
-
if (!this.src || !document) {
|
47
|
-
resolve();
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
const links = document.head.querySelectorAll("link[rel='preconnect'][youtube]");
|
51
|
-
if (links && links.length > 0) {
|
52
|
-
resolve();
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
const link = document.createElement('link');
|
56
|
-
link.rel = 'preconnect';
|
57
|
-
link.href = 'https://www.youtube.com';
|
58
|
-
link.setAttribute('youtube', '');
|
59
|
-
document.head.appendChild(link);
|
60
|
-
resolve();
|
61
|
-
});
|
62
|
-
}
|
63
|
-
createIFrame() {
|
64
|
-
return new Promise(async (resolve) => {
|
65
|
-
if (!this.src) {
|
66
|
-
resolve();
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
if (this.loading) {
|
70
|
-
resolve();
|
71
|
-
return;
|
18
|
+
classModeChanged() {
|
19
|
+
if (this.classMode) {
|
20
|
+
var youtube_video_id = this.src.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/).pop();
|
21
|
+
if (youtube_video_id.length == 11) {
|
22
|
+
this.video_thumbnail = '//img.youtube.com/vi/' + youtube_video_id + '/0.jpg';
|
72
23
|
}
|
73
|
-
const iframe = this.el.shadowRoot.querySelector('iframe');
|
74
|
-
if (iframe && !iframe.parentElement) {
|
75
|
-
resolve();
|
76
|
-
return;
|
77
|
-
}
|
78
|
-
this.loading = true;
|
79
|
-
this.loaded = false;
|
80
|
-
if (iframe) {
|
81
|
-
iframe.parentElement.removeChild(iframe);
|
82
|
-
}
|
83
|
-
const element = document.createElement('iframe');
|
84
|
-
const allow = document.createAttribute('allow');
|
85
|
-
allow.value = 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture';
|
86
|
-
this.setAttributeNode(element, allow);
|
87
|
-
if (this.allowFullscreen) {
|
88
|
-
const allowFullScreen = document.createAttribute('allowfullscreen');
|
89
|
-
allowFullScreen.value = '';
|
90
|
-
this.setAttributeNode(element, allowFullScreen);
|
91
|
-
}
|
92
|
-
let src = await this.formatSrc();
|
93
|
-
if (!this.allowFullscreen) {
|
94
|
-
// Not auto fullscreen on iOS: https://developers.google.com/youtube/player_parameters
|
95
|
-
const playsinline = document.createAttribute('playsinline');
|
96
|
-
playsinline.value = '1';
|
97
|
-
this.setAttributeNode(element, playsinline);
|
98
|
-
const split = src.split('?');
|
99
|
-
src += `${split && split.length > 0 ? '&' : '?'}playsinline=1`;
|
100
|
-
}
|
101
|
-
element.src = src;
|
102
|
-
element.width = '' + this.width;
|
103
|
-
element.height = '' + this.height;
|
104
|
-
element.frameBorder = '0';
|
105
|
-
element.title = this.frameTitle;
|
106
|
-
const div = this.el.shadowRoot.querySelector('div');
|
107
|
-
if (!div) {
|
108
|
-
resolve();
|
109
|
-
return;
|
110
|
-
}
|
111
|
-
div.appendChild(element);
|
112
|
-
this.loading = false;
|
113
|
-
this.loaded = true;
|
114
|
-
resolve();
|
115
|
-
});
|
116
|
-
}
|
117
|
-
setAttributeNode(element, attr) {
|
118
|
-
// Stencil prerendering
|
119
|
-
if (element.setAttributeNode === 'function') {
|
120
|
-
element.setAttributeNode(attr);
|
121
24
|
}
|
122
25
|
}
|
123
|
-
|
124
|
-
|
125
|
-
// Direct URL can't be embedded, like https://www.youtube.com/watch?v=oUOjJIfPIjw or https://youtu.be/e63Cgln6Yag
|
126
|
-
const videoId = await this.findVideoId();
|
127
|
-
if (videoId) {
|
128
|
-
// In such a case return a link which could be embedded
|
129
|
-
resolve('https://www.youtube.com/embed/' + videoId + '?enablejsapi=1');
|
130
|
-
}
|
131
|
-
else {
|
132
|
-
// Otherwise we try the provided url
|
133
|
-
if (!this.src) {
|
134
|
-
resolve(this.src);
|
135
|
-
return;
|
136
|
-
}
|
137
|
-
// But first, if an embed link, like https://www.youtube.com/embed/PnSNT5WpauE, would be passed, a parameter to enable js should be added otherwise play and pause could not be triggered
|
138
|
-
// Therefore we add enablejsapi if needed in any case
|
139
|
-
const url = new URL(this.src);
|
140
|
-
if (!url.searchParams.get('enablejsapi')) {
|
141
|
-
url.searchParams.append('enablejsapi', '1');
|
142
|
-
}
|
143
|
-
resolve(url.href);
|
144
|
-
}
|
145
|
-
});
|
146
|
-
}
|
147
|
-
findVideoId() {
|
148
|
-
return new Promise((resolve) => {
|
149
|
-
const url = new URL(this.src);
|
150
|
-
let videoId = url.searchParams.get('v');
|
151
|
-
if (!videoId) {
|
152
|
-
const host = url.host;
|
153
|
-
if (host === 'youtu.be') {
|
154
|
-
// For shortened url
|
155
|
-
const pathname = url.pathname;
|
156
|
-
if (pathname) {
|
157
|
-
const split = url.pathname.split('/');
|
158
|
-
if (split && split.length >= 2) {
|
159
|
-
videoId = url.pathname.split('/')[1];
|
160
|
-
}
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
resolve(videoId);
|
165
|
-
});
|
166
|
-
}
|
167
|
-
playPauseVideo(play) {
|
168
|
-
return new Promise(async (resolve) => {
|
169
|
-
const iframe = this.el.shadowRoot.querySelector('iframe');
|
170
|
-
if (!iframe) {
|
171
|
-
resolve();
|
172
|
-
return;
|
173
|
-
}
|
174
|
-
iframe.contentWindow.postMessage(JSON.stringify({
|
175
|
-
event: 'command',
|
176
|
-
func: play ? 'playVideo' : 'pauseVideo',
|
177
|
-
args: '',
|
178
|
-
}), '*');
|
179
|
-
resolve();
|
180
|
-
});
|
26
|
+
classRoomModeChanged(val) {
|
27
|
+
this.classMode = val;
|
181
28
|
}
|
182
29
|
render() {
|
183
|
-
|
184
|
-
return (index.h(index.Host, { class: hostClass }, index.h("div", { class: "youtube-container" })));
|
30
|
+
return (index.h("div", null, !this.classMode ? (index.h("div", { class: "embed-container" }, index.h("iframe", { src: this.src.replace("watch?v=", "embed/"), frameborder: "0", allowFullScreen: true }))) : (index.h("div", null, index.h("img", { src: this.video_thumbnail })))));
|
185
31
|
}
|
186
32
|
get el() { return index.getElement(this); }
|
187
33
|
static get watchers() { return {
|
188
|
-
"
|
34
|
+
"classMode": ["classModeChanged"]
|
189
35
|
}; }
|
190
36
|
};
|
191
37
|
SparkleYoutube.style = sparkleYoutubeCss;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 220.682 220.682" style="enable-background:new 0 0 220.682 220.682;" xml:space="preserve"><g><g>
|
3
|
+
<polygon points="92.695,38.924 164.113,110.341 92.695,181.758 120.979,210.043 220.682,110.341 120.979,10.639 " data-original="#E5053A" fill="#E5053A"/>
|
4
|
+
<polygon points="28.284,210.043 127.986,110.341 28.284,10.639 0,38.924 71.417,110.341 0,181.758 " data-original="#E5053A" fill="#E5053A"/>
|
5
|
+
</g></g> </svg>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 365 365" style="enable-background:new 0 0 365 365;" xml:space="preserve" width="512px" height="512px" class=""><g><g>
|
3
|
+
<rect x="74.5" width="73" height="365" data-original="#E5053A" class="active-path" fill="#E5053A"/>
|
4
|
+
<rect x="217.5" width="73" height="365" data-original="#E5053A" class="active-path" fill="#E5053A"/>
|
5
|
+
</g></g> </svg>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 307.046 307.046" style="enable-background:new 0 0 307.046 307.046;" xml:space="preserve"><g><g>
|
3
|
+
<g id="_x34_84._Forward">
|
4
|
+
<g>
|
5
|
+
<path d="M239.087,142.427L101.259,4.597c-6.133-6.129-16.073-6.129-22.203,0L67.955,15.698c-6.129,6.133-6.129,16.076,0,22.201 l115.621,115.626L67.955,269.135c-6.129,6.136-6.129,16.086,0,22.209l11.101,11.101c6.13,6.136,16.07,6.136,22.203,0 l137.828-137.831C245.222,158.487,245.222,148.556,239.087,142.427z" data-original="#E5053A" fill="#E5053A"/>
|
6
|
+
</g>
|
7
|
+
</g>
|
8
|
+
</g></g> </svg>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 314.41 314.41" style="enable-background:new 0 0 314.41 314.41;" xml:space="preserve"><g><g>
|
3
|
+
<path d="M288.318,145.307L39.832,1.841c-4.253-2.454-9.486-2.454-13.74,0c-4.249,2.452-6.871,6.991-6.871,11.898v286.93 c0,4.908,2.622,9.447,6.871,11.898c2.128,1.229,4.5,1.843,6.87,1.843c2.372,0,4.743-0.614,6.87-1.843l248.487-143.464 c4.25-2.452,6.871-6.991,6.871-11.898C295.189,152.297,292.568,147.759,288.318,145.307z M46.702,276.868V37.541l207.265,119.664 L46.702,276.868z" data-original="#E5053A" class="active-path" fill="#E5053A"/>
|
4
|
+
</g></g> </svg>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 220.682 220.682" style="enable-background:new 0 0 220.682 220.682;" xml:space="preserve"><g><g>
|
3
|
+
<polygon points="99.702,210.043 127.986,181.758 56.569,110.341 127.986,38.924 99.702,10.639 0,110.341 " data-original="#E5053A" class="active-path" fill="#E5053A"/>
|
4
|
+
<polygon points="192.398,10.639 92.695,110.341 192.398,210.043 220.682,181.758 149.264,110.341 220.682,38.924 " data-original="#E5053A" class="active-path" fill="#E5053A"/>
|
5
|
+
</g></g> </svg>
|
@@ -405,17 +405,19 @@ export class SparkleAnimationPlayer {
|
|
405
405
|
h("div", { class: "button-panel" },
|
406
406
|
h("ion-button", { size: "small", color: "transperant", onClick: () => this.rewind5Sec() },
|
407
407
|
" ",
|
408
|
-
h("ion-icon", {
|
408
|
+
h("ion-icon", { name: "play-back-outline" }),
|
409
409
|
" "),
|
410
410
|
h("ion-button", { size: "small", color: "transperant", onClick: () => this.playButtonAction() },
|
411
411
|
" ",
|
412
|
-
this.paused ? (h("ion-icon", { name: "pause" })) : (h("ion-icon", {
|
412
|
+
this.paused ? (h("ion-icon", { name: "pause-outline" })) : (h("ion-icon", { name: "play-outline" })
|
413
|
+
// <ion-icon src="/assets/img/play-symbol.svg"></ion-icon>
|
414
|
+
)),
|
413
415
|
h("ion-button", { size: "small", color: "transperant", onClick: () => this.fastForward5Sec() },
|
414
416
|
" ",
|
415
|
-
h("ion-icon", {
|
417
|
+
h("ion-icon", { name: "play-forward-outline" }))))) : (""),
|
416
418
|
(this.dataLoaded && this.captionText) ?
|
417
419
|
h("div", { class: "closed-caption" },
|
418
|
-
h("ion-item",
|
420
|
+
h("ion-item", { lines: "none" },
|
419
421
|
h("ion-label", null, "Closed Caption"),
|
420
422
|
h("ion-toggle", { slot: "end", color: "primary", checked: this.showCaption }))) : ""));
|
421
423
|
}
|
@@ -5,4 +5,20 @@
|
|
5
5
|
div.youtube-container {
|
6
6
|
opacity: var(--sparkle-youtube-opacity-not-loaded, 0);
|
7
7
|
transition: var(--sparkle-youtube-transition, opacity 0.15s linear);
|
8
|
+
}
|
9
|
+
|
10
|
+
.embed-container {
|
11
|
+
position: relative;
|
12
|
+
padding-bottom: 56.25%;
|
13
|
+
height: 0;
|
14
|
+
overflow: hidden;
|
15
|
+
max-width: 100%;
|
16
|
+
}
|
17
|
+
|
18
|
+
.embed-container iframe, .embed-container object, .embed-container embed {
|
19
|
+
position: absolute;
|
20
|
+
top: 0;
|
21
|
+
left: 0;
|
22
|
+
width: 100%;
|
23
|
+
height: 100%;
|
8
24
|
}
|
@@ -1,183 +1,29 @@
|
|
1
|
-
import { Component, Element, Prop, State, Watch, Method,
|
1
|
+
import { Component, Element, Prop, State, Watch, Method, h } from '@stencil/core';
|
2
2
|
export class SparkleYoutube {
|
3
3
|
constructor() {
|
4
|
-
this.
|
5
|
-
this.instant = false;
|
6
|
-
this.loading = false;
|
7
|
-
this.loaded = false;
|
4
|
+
this.video_thumbnail = '';
|
8
5
|
}
|
9
|
-
|
10
|
-
|
6
|
+
componentDidLoad() {
|
7
|
+
this.classMode = this.initialClassMode;
|
8
|
+
this.classModeChanged();
|
11
9
|
}
|
12
|
-
|
13
|
-
if (this.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
async updateIFrame(width, height) {
|
18
|
-
const iframe = this.el.shadowRoot.querySelector('iframe');
|
19
|
-
if (iframe) {
|
20
|
-
iframe.width = '' + width;
|
21
|
-
iframe.height = '' + height;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
lazyLoadContent() {
|
25
|
-
return this.createIFrame();
|
26
|
-
}
|
27
|
-
async onSrcUpdate() {
|
28
|
-
await this.createIFrame();
|
29
|
-
}
|
30
|
-
play() {
|
31
|
-
return this.playPauseVideo(true);
|
32
|
-
}
|
33
|
-
pause() {
|
34
|
-
return this.playPauseVideo(false);
|
35
|
-
}
|
36
|
-
addPreconnectLink() {
|
37
|
-
return new Promise((resolve) => {
|
38
|
-
if (!this.src || !document) {
|
39
|
-
resolve();
|
40
|
-
return;
|
41
|
-
}
|
42
|
-
const links = document.head.querySelectorAll("link[rel='preconnect'][youtube]");
|
43
|
-
if (links && links.length > 0) {
|
44
|
-
resolve();
|
45
|
-
return;
|
46
|
-
}
|
47
|
-
const link = document.createElement('link');
|
48
|
-
link.rel = 'preconnect';
|
49
|
-
link.href = 'https://www.youtube.com';
|
50
|
-
link.setAttribute('youtube', '');
|
51
|
-
document.head.appendChild(link);
|
52
|
-
resolve();
|
53
|
-
});
|
54
|
-
}
|
55
|
-
createIFrame() {
|
56
|
-
return new Promise(async (resolve) => {
|
57
|
-
if (!this.src) {
|
58
|
-
resolve();
|
59
|
-
return;
|
60
|
-
}
|
61
|
-
if (this.loading) {
|
62
|
-
resolve();
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
const iframe = this.el.shadowRoot.querySelector('iframe');
|
66
|
-
if (iframe && !iframe.parentElement) {
|
67
|
-
resolve();
|
68
|
-
return;
|
10
|
+
classModeChanged() {
|
11
|
+
if (this.classMode) {
|
12
|
+
var youtube_video_id = this.src.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/).pop();
|
13
|
+
if (youtube_video_id.length == 11) {
|
14
|
+
this.video_thumbnail = '//img.youtube.com/vi/' + youtube_video_id + '/0.jpg';
|
69
15
|
}
|
70
|
-
this.loading = true;
|
71
|
-
this.loaded = false;
|
72
|
-
if (iframe) {
|
73
|
-
iframe.parentElement.removeChild(iframe);
|
74
|
-
}
|
75
|
-
const element = document.createElement('iframe');
|
76
|
-
const allow = document.createAttribute('allow');
|
77
|
-
allow.value = 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture';
|
78
|
-
this.setAttributeNode(element, allow);
|
79
|
-
if (this.allowFullscreen) {
|
80
|
-
const allowFullScreen = document.createAttribute('allowfullscreen');
|
81
|
-
allowFullScreen.value = '';
|
82
|
-
this.setAttributeNode(element, allowFullScreen);
|
83
|
-
}
|
84
|
-
let src = await this.formatSrc();
|
85
|
-
if (!this.allowFullscreen) {
|
86
|
-
// Not auto fullscreen on iOS: https://developers.google.com/youtube/player_parameters
|
87
|
-
const playsinline = document.createAttribute('playsinline');
|
88
|
-
playsinline.value = '1';
|
89
|
-
this.setAttributeNode(element, playsinline);
|
90
|
-
const split = src.split('?');
|
91
|
-
src += `${split && split.length > 0 ? '&' : '?'}playsinline=1`;
|
92
|
-
}
|
93
|
-
element.src = src;
|
94
|
-
element.width = '' + this.width;
|
95
|
-
element.height = '' + this.height;
|
96
|
-
element.frameBorder = '0';
|
97
|
-
element.title = this.frameTitle;
|
98
|
-
const div = this.el.shadowRoot.querySelector('div');
|
99
|
-
if (!div) {
|
100
|
-
resolve();
|
101
|
-
return;
|
102
|
-
}
|
103
|
-
div.appendChild(element);
|
104
|
-
this.loading = false;
|
105
|
-
this.loaded = true;
|
106
|
-
resolve();
|
107
|
-
});
|
108
|
-
}
|
109
|
-
setAttributeNode(element, attr) {
|
110
|
-
// Stencil prerendering
|
111
|
-
if (element.setAttributeNode === 'function') {
|
112
|
-
element.setAttributeNode(attr);
|
113
16
|
}
|
114
17
|
}
|
115
|
-
|
116
|
-
|
117
|
-
// Direct URL can't be embedded, like https://www.youtube.com/watch?v=oUOjJIfPIjw or https://youtu.be/e63Cgln6Yag
|
118
|
-
const videoId = await this.findVideoId();
|
119
|
-
if (videoId) {
|
120
|
-
// In such a case return a link which could be embedded
|
121
|
-
resolve('https://www.youtube.com/embed/' + videoId + '?enablejsapi=1');
|
122
|
-
}
|
123
|
-
else {
|
124
|
-
// Otherwise we try the provided url
|
125
|
-
if (!this.src) {
|
126
|
-
resolve(this.src);
|
127
|
-
return;
|
128
|
-
}
|
129
|
-
// But first, if an embed link, like https://www.youtube.com/embed/PnSNT5WpauE, would be passed, a parameter to enable js should be added otherwise play and pause could not be triggered
|
130
|
-
// Therefore we add enablejsapi if needed in any case
|
131
|
-
const url = new URL(this.src);
|
132
|
-
if (!url.searchParams.get('enablejsapi')) {
|
133
|
-
url.searchParams.append('enablejsapi', '1');
|
134
|
-
}
|
135
|
-
resolve(url.href);
|
136
|
-
}
|
137
|
-
});
|
138
|
-
}
|
139
|
-
findVideoId() {
|
140
|
-
return new Promise((resolve) => {
|
141
|
-
const url = new URL(this.src);
|
142
|
-
let videoId = url.searchParams.get('v');
|
143
|
-
if (!videoId) {
|
144
|
-
const host = url.host;
|
145
|
-
if (host === 'youtu.be') {
|
146
|
-
// For shortened url
|
147
|
-
const pathname = url.pathname;
|
148
|
-
if (pathname) {
|
149
|
-
const split = url.pathname.split('/');
|
150
|
-
if (split && split.length >= 2) {
|
151
|
-
videoId = url.pathname.split('/')[1];
|
152
|
-
}
|
153
|
-
}
|
154
|
-
}
|
155
|
-
}
|
156
|
-
resolve(videoId);
|
157
|
-
});
|
158
|
-
}
|
159
|
-
playPauseVideo(play) {
|
160
|
-
return new Promise(async (resolve) => {
|
161
|
-
const iframe = this.el.shadowRoot.querySelector('iframe');
|
162
|
-
if (!iframe) {
|
163
|
-
resolve();
|
164
|
-
return;
|
165
|
-
}
|
166
|
-
iframe.contentWindow.postMessage(JSON.stringify({
|
167
|
-
event: 'command',
|
168
|
-
func: play ? 'playVideo' : 'pauseVideo',
|
169
|
-
args: '',
|
170
|
-
}), '*');
|
171
|
-
resolve();
|
172
|
-
});
|
18
|
+
classRoomModeChanged(val) {
|
19
|
+
this.classMode = val;
|
173
20
|
}
|
174
21
|
render() {
|
175
|
-
|
176
|
-
|
177
|
-
h("
|
22
|
+
return (h("div", null, !this.classMode ? (h("div", { class: "embed-container" },
|
23
|
+
h("iframe", { src: this.src.replace("watch?v=", "embed/"), frameborder: "0", allowFullScreen: true }))) : (h("div", null,
|
24
|
+
h("img", { src: this.video_thumbnail })))));
|
178
25
|
}
|
179
26
|
static get is() { return "sparkle-youtube"; }
|
180
|
-
static get encapsulation() { return "shadow"; }
|
181
27
|
static get originalStyleUrls() { return {
|
182
28
|
"$": ["sparkle-youtube.scss"]
|
183
29
|
}; }
|
@@ -202,76 +48,7 @@ export class SparkleYoutube {
|
|
202
48
|
"attribute": "src",
|
203
49
|
"reflect": false
|
204
50
|
},
|
205
|
-
"
|
206
|
-
"type": "number",
|
207
|
-
"mutable": false,
|
208
|
-
"complexType": {
|
209
|
-
"original": "number",
|
210
|
-
"resolved": "number",
|
211
|
-
"references": {}
|
212
|
-
},
|
213
|
-
"required": false,
|
214
|
-
"optional": false,
|
215
|
-
"docs": {
|
216
|
-
"tags": [],
|
217
|
-
"text": ""
|
218
|
-
},
|
219
|
-
"attribute": "width",
|
220
|
-
"reflect": false
|
221
|
-
},
|
222
|
-
"height": {
|
223
|
-
"type": "number",
|
224
|
-
"mutable": false,
|
225
|
-
"complexType": {
|
226
|
-
"original": "number",
|
227
|
-
"resolved": "number",
|
228
|
-
"references": {}
|
229
|
-
},
|
230
|
-
"required": false,
|
231
|
-
"optional": false,
|
232
|
-
"docs": {
|
233
|
-
"tags": [],
|
234
|
-
"text": ""
|
235
|
-
},
|
236
|
-
"attribute": "height",
|
237
|
-
"reflect": false
|
238
|
-
},
|
239
|
-
"frameTitle": {
|
240
|
-
"type": "string",
|
241
|
-
"mutable": false,
|
242
|
-
"complexType": {
|
243
|
-
"original": "string",
|
244
|
-
"resolved": "string",
|
245
|
-
"references": {}
|
246
|
-
},
|
247
|
-
"required": false,
|
248
|
-
"optional": false,
|
249
|
-
"docs": {
|
250
|
-
"tags": [],
|
251
|
-
"text": ""
|
252
|
-
},
|
253
|
-
"attribute": "frame-title",
|
254
|
-
"reflect": false
|
255
|
-
},
|
256
|
-
"allowFullscreen": {
|
257
|
-
"type": "boolean",
|
258
|
-
"mutable": false,
|
259
|
-
"complexType": {
|
260
|
-
"original": "boolean",
|
261
|
-
"resolved": "boolean",
|
262
|
-
"references": {}
|
263
|
-
},
|
264
|
-
"required": false,
|
265
|
-
"optional": false,
|
266
|
-
"docs": {
|
267
|
-
"tags": [],
|
268
|
-
"text": ""
|
269
|
-
},
|
270
|
-
"attribute": "allow-fullscreen",
|
271
|
-
"reflect": false,
|
272
|
-
"defaultValue": "true"
|
273
|
-
},
|
274
|
-
"instant": {
|
51
|
+
"initialClassMode": {
|
275
52
|
"type": "boolean",
|
276
53
|
"mutable": false,
|
277
54
|
"complexType": {
|
@@ -285,82 +62,23 @@ export class SparkleYoutube {
|
|
285
62
|
"tags": [],
|
286
63
|
"text": ""
|
287
64
|
},
|
288
|
-
"attribute": "
|
289
|
-
"reflect": false
|
290
|
-
"defaultValue": "false"
|
65
|
+
"attribute": "initial-class-mode",
|
66
|
+
"reflect": false
|
291
67
|
}
|
292
68
|
}; }
|
293
69
|
static get states() { return {
|
294
|
-
"
|
295
|
-
"
|
70
|
+
"classMode": {},
|
71
|
+
"video_thumbnail": {}
|
296
72
|
}; }
|
297
73
|
static get methods() { return {
|
298
|
-
"
|
74
|
+
"classRoomModeChanged": {
|
299
75
|
"complexType": {
|
300
|
-
"signature": "(
|
76
|
+
"signature": "(val: any) => Promise<void>",
|
301
77
|
"parameters": [{
|
302
78
|
"tags": [],
|
303
79
|
"text": ""
|
304
|
-
}, {
|
305
|
-
"tags": [],
|
306
|
-
"text": ""
|
307
80
|
}],
|
308
|
-
"references": {
|
309
|
-
"Promise": {
|
310
|
-
"location": "global"
|
311
|
-
},
|
312
|
-
"HTMLIFrameElement": {
|
313
|
-
"location": "global"
|
314
|
-
}
|
315
|
-
},
|
316
|
-
"return": "Promise<void>"
|
317
|
-
},
|
318
|
-
"docs": {
|
319
|
-
"text": "",
|
320
|
-
"tags": []
|
321
|
-
}
|
322
|
-
},
|
323
|
-
"lazyLoadContent": {
|
324
|
-
"complexType": {
|
325
|
-
"signature": "() => Promise<void>",
|
326
|
-
"parameters": [],
|
327
|
-
"references": {
|
328
|
-
"Promise": {
|
329
|
-
"location": "global"
|
330
|
-
}
|
331
|
-
},
|
332
|
-
"return": "Promise<void>"
|
333
|
-
},
|
334
|
-
"docs": {
|
335
|
-
"text": "",
|
336
|
-
"tags": []
|
337
|
-
}
|
338
|
-
},
|
339
|
-
"play": {
|
340
|
-
"complexType": {
|
341
|
-
"signature": "() => Promise<void>",
|
342
|
-
"parameters": [],
|
343
|
-
"references": {
|
344
|
-
"Promise": {
|
345
|
-
"location": "global"
|
346
|
-
}
|
347
|
-
},
|
348
|
-
"return": "Promise<void>"
|
349
|
-
},
|
350
|
-
"docs": {
|
351
|
-
"text": "",
|
352
|
-
"tags": []
|
353
|
-
}
|
354
|
-
},
|
355
|
-
"pause": {
|
356
|
-
"complexType": {
|
357
|
-
"signature": "() => Promise<void>",
|
358
|
-
"parameters": [],
|
359
|
-
"references": {
|
360
|
-
"Promise": {
|
361
|
-
"location": "global"
|
362
|
-
}
|
363
|
-
},
|
81
|
+
"references": {},
|
364
82
|
"return": "Promise<void>"
|
365
83
|
},
|
366
84
|
"docs": {
|
@@ -371,7 +89,7 @@ export class SparkleYoutube {
|
|
371
89
|
}; }
|
372
90
|
static get elementRef() { return "el"; }
|
373
91
|
static get watchers() { return [{
|
374
|
-
"propName": "
|
375
|
-
"methodName": "
|
92
|
+
"propName": "classMode",
|
93
|
+
"methodName": "classModeChanged"
|
376
94
|
}]; }
|
377
95
|
}
|