@sparkle-learning/core 0.0.23 → 0.0.26

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.
Files changed (42) hide show
  1. package/dist/cjs/header-mobile-collapse_60.cjs.entry.js +1 -1
  2. package/dist/cjs/{index.es-c12b0714.js → index.es-91493ac6.js} +1 -1
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/{purify-e34cd5cf.js → purify-ed567052.js} +1 -1
  5. package/dist/cjs/sparkle-animation-player.cjs.entry.js +5 -2
  6. package/dist/cjs/sparkle-core.cjs.js +1 -1
  7. package/dist/cjs/sparkle-youtube.cjs.entry.js +14 -168
  8. package/dist/collection/assets/img/forward.svg +5 -0
  9. package/dist/collection/assets/img/pause.svg +5 -0
  10. package/dist/collection/assets/img/play-symbol.svg +8 -0
  11. package/dist/collection/assets/img/play.svg +4 -0
  12. package/dist/collection/assets/img/rewind.svg +5 -0
  13. package/dist/collection/components/sparkle-animation-player/assets/play-button-disabled-overlay.png +0 -0
  14. package/dist/collection/components/sparkle-animation-player/assets/play-button-overlay.png +0 -0
  15. package/dist/collection/components/sparkle-animation-player/sparkle-animation-player.js +10 -7
  16. package/dist/collection/components/sparkle-course-root/sparkle-course-root.js +14 -0
  17. package/dist/collection/components/sparkle-youtube/sparkle-youtube.css +16 -0
  18. package/dist/collection/components/sparkle-youtube/sparkle-youtube.js +25 -307
  19. package/dist/collection/pages/course/welcome-to-mind-body/introduction/animation/m4l1p1_part1.js +2727 -0
  20. package/dist/collection/pages/course/welcome-to-mind-body/introduction/animation/m4l1p1_part2.js +2042 -0
  21. package/dist/esm/header-mobile-collapse_60.entry.js +1 -1
  22. package/dist/esm/{index.es-34d81aa0.js → index.es-32e2f407.js} +1 -1
  23. package/dist/esm/loader.js +1 -1
  24. package/dist/esm/{purify-76414f98.js → purify-f1a55787.js} +1 -1
  25. package/dist/esm/sparkle-animation-player.entry.js +6 -3
  26. package/dist/esm/sparkle-core.js +1 -1
  27. package/dist/esm/sparkle-youtube.entry.js +15 -169
  28. package/dist/sparkle-core/assets/play-button-disabled-overlay.png +0 -0
  29. package/dist/sparkle-core/assets/play-button-overlay.png +0 -0
  30. package/dist/sparkle-core/{p-315af535.js → p-0d3fe46c.js} +1 -1
  31. package/dist/sparkle-core/{p-fc739e6b.js → p-14ff8097.js} +4 -4
  32. package/dist/sparkle-core/p-1e1f5e98.entry.js +1 -0
  33. package/dist/sparkle-core/p-82d95fcd.entry.js +1 -0
  34. package/dist/sparkle-core/{p-ba79a250.js → p-ab5cdfeb.js} +1 -1
  35. package/dist/sparkle-core/{p-1af89970.entry.js → p-f6ce91f2.entry.js} +1 -1
  36. package/dist/sparkle-core/sparkle-core.esm.js +1 -1
  37. package/dist/types/components/sparkle-course-root/sparkle-course-root.d.ts +1 -0
  38. package/dist/types/components/sparkle-youtube/sparkle-youtube.d.ts +6 -20
  39. package/dist/types/components.d.ts +3 -14
  40. package/package.json +2 -2
  41. package/dist/sparkle-core/p-0bd3e81f.entry.js +0 -1
  42. package/dist/sparkle-core/p-d069b834.entry.js +0 -1
@@ -1,183 +1,29 @@
1
- import { Component, Element, Prop, State, Watch, Method, Host, h } from '@stencil/core';
1
+ import { Component, Element, Prop, State, Watch, Method, h } from '@stencil/core';
2
2
  export class SparkleYoutube {
3
3
  constructor() {
4
- this.allowFullscreen = true;
5
- this.instant = false;
6
- this.loading = false;
7
- this.loaded = false;
4
+ this.video_thumbnail = '';
8
5
  }
9
- async componentWillLoad() {
10
- await this.addPreconnectLink();
6
+ componentDidLoad() {
7
+ this.classMode = this.initialClassMode;
8
+ this.classModeChanged();
11
9
  }
12
- async componentDidLoad() {
13
- if (this.instant) {
14
- await this.lazyLoadContent();
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
- formatSrc() {
116
- return new Promise(async (resolve) => {
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
- const hostClass = this.loaded ? 'loaded' : '';
176
- return (h(Host, { class: hostClass },
177
- h("div", { class: "youtube-container" })));
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
- "width": {
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": "instant",
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
- "loading": {},
295
- "loaded": {}
70
+ "classMode": {},
71
+ "video_thumbnail": {}
296
72
  }; }
297
73
  static get methods() { return {
298
- "updateIFrame": {
74
+ "classRoomModeChanged": {
299
75
  "complexType": {
300
- "signature": "(width: number, height: number) => Promise<void>",
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": "src",
375
- "methodName": "onSrcUpdate"
92
+ "propName": "classMode",
93
+ "methodName": "classModeChanged"
376
94
  }]; }
377
95
  }