@outbook/webcomponents-player 1.3.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.
- package/LICENSE +202 -0
- package/README.md +126 -0
- package/_i18n/af.json +12 -0
- package/_i18n/ar.json +12 -0
- package/_i18n/bg.json +12 -0
- package/_i18n/bn.json +12 -0
- package/_i18n/ca.json +12 -0
- package/_i18n/cs.json +12 -0
- package/_i18n/da.json +12 -0
- package/_i18n/de.json +12 -0
- package/_i18n/el.json +12 -0
- package/_i18n/en.json +12 -0
- package/_i18n/es.json +12 -0
- package/_i18n/eu.json +12 -0
- package/_i18n/fa.json +12 -0
- package/_i18n/fi.json +12 -0
- package/_i18n/fr.json +12 -0
- package/_i18n/gl.json +12 -0
- package/_i18n/ha.json +12 -0
- package/_i18n/hi.json +12 -0
- package/_i18n/hu.json +12 -0
- package/_i18n/i18n.js +95 -0
- package/_i18n/id.json +12 -0
- package/_i18n/it.json +12 -0
- package/_i18n/ja.json +12 -0
- package/_i18n/km.json +12 -0
- package/_i18n/ko.json +12 -0
- package/_i18n/lo.json +12 -0
- package/_i18n/ms.json +12 -0
- package/_i18n/nl.json +12 -0
- package/_i18n/no.json +12 -0
- package/_i18n/pl.json +12 -0
- package/_i18n/pt.json +12 -0
- package/_i18n/ro.json +12 -0
- package/_i18n/ru.json +12 -0
- package/_i18n/sk.json +12 -0
- package/_i18n/sv.json +12 -0
- package/_i18n/sw.json +12 -0
- package/_i18n/th.json +12 -0
- package/_i18n/tl.json +12 -0
- package/_i18n/tr.json +12 -0
- package/_i18n/uk.json +12 -0
- package/_i18n/vi.json +12 -0
- package/_i18n/zh.json +12 -0
- package/_i18n/zu.json +12 -0
- package/_lib/background.js +28 -0
- package/_lib/controls/index.js +91 -0
- package/_lib/cover-fallback/index.js +48 -0
- package/_lib/get-cover.js +4 -0
- package/_lib/hooks.js +23 -0
- package/_lib/order-by-luminance.js +9 -0
- package/_lib/playlist/index.js +105 -0
- package/_lib/playlist/modules/item-duration.js +17 -0
- package/_lib/playlist/modules/show-cover.js +14 -0
- package/_lib/rgb-to-hex.js +13 -0
- package/_lib/setup-media-session.js +29 -0
- package/_lib/timeline/_lib/handle-timeline.js +42 -0
- package/_lib/timeline/index.js +121 -0
- package/_lib/track-info/index.js +36 -0
- package/_lib/track-text/index.js +20 -0
- package/_style/_lib/_variables.scss +5 -0
- package/_style/_modules/_controls.scss +50 -0
- package/_style/_modules/_cover-fallback.scss +52 -0
- package/_style/_modules/_playlist.scss +119 -0
- package/_style/_modules/_timeline.scss +125 -0
- package/_style/_modules/_track-info.scss +54 -0
- package/_style/player.style.js +4 -0
- package/package.json +48 -0
- package/player.js +324 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
@use '@outbook/design-decisions/measures';
|
|
2
|
+
@use '@outbook/design-decisions/outline';
|
|
3
|
+
@use '../_lib/variables';
|
|
4
|
+
@use '@outbook/colorful/palettes-oklch' as colors;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@mixin style() {
|
|
8
|
+
|
|
9
|
+
.timeline {
|
|
10
|
+
--timeline--background: var(--_accent-200);
|
|
11
|
+
--timeline--completed-background: var(--_accent-800);
|
|
12
|
+
--timeline--font-size: #{measures.$baseline * 1.5};
|
|
13
|
+
--timeline--numbers-separation: #{measures.$baseline * 0.25};
|
|
14
|
+
--timeline--chapter-limit-color: #{colors.$neutral_950};
|
|
15
|
+
.timeline__chapter-limit--played {
|
|
16
|
+
--timeline--chapter-limit-color: #{colors.$neutral_50};
|
|
17
|
+
}
|
|
18
|
+
.ambient-dark & {
|
|
19
|
+
--timeline--background: var(--_accent-800);
|
|
20
|
+
--timeline--chapter-limit-color: #{colors.$neutral_50};
|
|
21
|
+
--timeline--completed-background: var(--_accent-200);
|
|
22
|
+
.timeline__chapter-limit--played {
|
|
23
|
+
--timeline--chapter-limit-color: #{colors.$neutral_950};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
@container player (width >= #{variables.$player-widht-m}) {
|
|
28
|
+
.timeline {
|
|
29
|
+
--timeline--font-size: #{measures.$baseline * 1.75};
|
|
30
|
+
--timeline--numbers-separation: #{measures.$baseline * 0.5};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@container player (width >= #{variables.$player-widht-l}) {
|
|
35
|
+
.timeline {
|
|
36
|
+
--timeline--font-size: #{measures.$baseline * 2};
|
|
37
|
+
--timeline--numbers-separation: #{measures.$baseline};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
mythical-player-timeline {
|
|
42
|
+
display: block;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.timeline {
|
|
46
|
+
position: relative;
|
|
47
|
+
padding: 0 #{measures.$baseline};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.timeline__track {
|
|
51
|
+
height: #{measures.$baseline};
|
|
52
|
+
width: 100%;
|
|
53
|
+
background-color: var(--timeline--background);
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
&:focus-visible {
|
|
56
|
+
@include outline.outside();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.timeline__completed {
|
|
62
|
+
height: 100%;
|
|
63
|
+
background-color: var(--timeline--completed-background);
|
|
64
|
+
//transition: width 0.35s;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.timeline__numbers {
|
|
68
|
+
display: flex;
|
|
69
|
+
justify-content: space-between;
|
|
70
|
+
padding-top: var(--timeline--numbers-separation);
|
|
71
|
+
font-size: var(--timeline--font-size);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.timeline__tooltip {
|
|
75
|
+
position: absolute;
|
|
76
|
+
top: 0;
|
|
77
|
+
transform: translate(-50%, -100%);
|
|
78
|
+
left: var(--timeline-tooltip-position);
|
|
79
|
+
padding-bottom: #{measures.$baseline};
|
|
80
|
+
z-index: 3;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.timeline__tooltip-inner {
|
|
84
|
+
background-color: #{colors.$white};
|
|
85
|
+
color: #{colors.$neutral_700};
|
|
86
|
+
padding: #{measures.$baseline * 0.5};
|
|
87
|
+
position: relative;
|
|
88
|
+
border-width: 1px 1px 0 1px;
|
|
89
|
+
border-color: colors.$neutral_200;
|
|
90
|
+
border-style: solid;
|
|
91
|
+
max-width: #{measures.$baseline * 16};
|
|
92
|
+
display: flex;
|
|
93
|
+
flex-direction: column;
|
|
94
|
+
align-items: center;
|
|
95
|
+
&:after {
|
|
96
|
+
content: "";
|
|
97
|
+
width: 0;
|
|
98
|
+
height: 0;
|
|
99
|
+
border-style: solid;
|
|
100
|
+
border-width: 0 4px 6.9px 4px;
|
|
101
|
+
border-color: transparent transparent #{colors.$white} transparent;
|
|
102
|
+
position: absolute;
|
|
103
|
+
top: 100%;
|
|
104
|
+
left: 50%;
|
|
105
|
+
transform: translateX(-50%) rotate(180deg);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.timeline__tooltip-time {
|
|
110
|
+
font-size: #{measures.$baseline * 2};
|
|
111
|
+
}
|
|
112
|
+
.timeline__tooltip-chapter-title {
|
|
113
|
+
font-size: #{measures.$baseline * 1.5};
|
|
114
|
+
margin-bottom: #{measures.$baseline * 0.5};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.timeline__chapter-limit {
|
|
118
|
+
width: 1px;
|
|
119
|
+
height: #{measures.$baseline};
|
|
120
|
+
background-color: var(--timeline--chapter-limit-color);
|
|
121
|
+
position: absolute;
|
|
122
|
+
top: 0;
|
|
123
|
+
left: var(--timeline--chapter-limit-position);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
@use '@outbook/design-decisions/measures';
|
|
2
|
+
@use '../_lib/variables';
|
|
3
|
+
|
|
4
|
+
@mixin style() {
|
|
5
|
+
$height-xs: measures.$baseline * 8;
|
|
6
|
+
|
|
7
|
+
.myth-track-info {
|
|
8
|
+
--track-info--flex-direction: row;
|
|
9
|
+
--track-info--image-width: #{measures.$baseline * 8};
|
|
10
|
+
--track-info--image-separation-horizontal: #{measures.$baseline * 2};
|
|
11
|
+
--track-info--image-separation-vertical: 0;
|
|
12
|
+
--track-info--height: #{$height-xs};
|
|
13
|
+
}
|
|
14
|
+
@container player (width >= #{variables.$player-widht-m}) {
|
|
15
|
+
.myth-track-info {
|
|
16
|
+
--track-info--flex-direction: column;
|
|
17
|
+
--track-info--image-width: 100%;
|
|
18
|
+
--track-info--image-separation-horizontal: 0;
|
|
19
|
+
--track-info--image-separation-vertical: #{measures.$baseline * 2};
|
|
20
|
+
--track-info--height: auto;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
.myth-track-info__inner {
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: var(--track-info--flex-direction);
|
|
28
|
+
height: var(--track-info--height);
|
|
29
|
+
.myth-item-text {
|
|
30
|
+
font-size: #{measures.$baseline * 2};
|
|
31
|
+
line-height: 150%;
|
|
32
|
+
&.size-small {
|
|
33
|
+
font-size: #{measures.$baseline * 1.5}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.myth-track-info__image {
|
|
39
|
+
width: var(--track-info--image-width);
|
|
40
|
+
flex-shrink: 0;
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
margin-right: var(--track-info--image-separation-horizontal);
|
|
44
|
+
margin-bottom: var(--track-info--image-separation-vertical);
|
|
45
|
+
& > * {
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.myth-track-info__data {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { css } from 'lit';
|
|
3
|
+
|
|
4
|
+
export default css`.skeleton-loader{--pulse-bg-start: blue;--pulse-bg-end: red}@keyframes colorPulse{from{background-color:var(--pulse-bg-start)}to{background-color:var(--pulse-bg-end)}}.skeleton-loader{background-color:var(--pulse-bg-start);animation:colorPulse 3.2s ease infinite alternate-reverse;opacity:.3}:host{display:block;color-scheme:inherit;--_accent-0: var(--outbook-player--color-accent-0, oklch(100% 0 0deg));--_accent-50: var(--outbook-player--color-accent-50, oklch(98.5% 0 0deg));--_accent-100: var(--outbook-player--color-accent-100, oklch(97% 0 0deg));--_accent-200: var(--outbook-player--color-accent-200, oklch(92.2% 0 0deg));--_accent-300: var(--outbook-player--color-accent-300, oklch(87% 0 0deg));--_accent-400: var(--outbook-player--color-accent-400, oklch(70.8% 0 0deg));--_accent-500: var(--outbook-player--color-accent-500, oklch(55.6% 0 0deg));--_accent-600: var(--outbook-player--color-accent-600, oklch(43.9% 0 0deg));--_accent-700: var(--outbook-player--color-accent-700, oklch(37.1% 0 0deg));--_accent-800: var(--outbook-player--color-accent-800, oklch(26.9% 0 0deg));--_accent-900: var(--outbook-player--color-accent-900, oklch(20.5% 0 0deg));--_accent-950: var(--outbook-player--color-accent-950, oklch(14.5% 0 0deg));--_accent-1000: var(--outbook-player--color-accent-1000, oklch(0% 0 0deg));--pulse-bg-start: light-dark( var(--_accent-100), var(--_accent-600) );--pulse-bg-end: light-dark( var(--_accent-600), var(--_accent-500) );--outbook-badge-file-extension--border-color: light-dark( oklch(37.1% 0 0deg), oklch(87% 0 0deg) );--outbook-badge-file-extension--text-color: light-dark( oklch(14.5% 0 0deg), oklch(100% 0 0deg) );--outbook-scrollable--indicator-color: light-dark( var(--_accent-900), var(--_accent-200) );--_text-color: light-dark(oklch(20.5% 0 0deg), oklch(100% 0 0deg));--_background-color: light-dark(oklch(98.5% 0 0deg), oklch(20.5% 0 0deg));--_separator-color: light-dark(oklch(92.2% 0 0deg), oklch(43.9% 0 0deg));--_link-color: light-dark(var(--_accent-700), var(--_accent-200));--_link-color-hover: light-dark(var(--_accent-500), var(--_accent-50))}*{box-sizing:border-box;padding:0;margin:0}ul,ol,li{list-style:none}a,button,[role=button],[role=link]{cursor:pointer}a[disabled],button[disabled],[role=button][disabled],[role=link][disabled]{cursor:default}.mythical-player{container-name:player;container-type:inline-size;height:var(--_main-height, 32rem);background-color:var(--_background-color);position:relative}.mythical-player::after,.mythical-player::before{content:"";height:100%;width:100%;position:absolute;left:0;top:0}.mythical-player.has-gradient::after{opacity:.65;background-color:var(--_background-color)}.mythical-player::before{opacity:.45;background:linear-gradient(145deg, var(--_accent-400) 0%, var(--_accent-500) 25%, var(--_accent-600) 50%, var(--_accent-700) 75%, var(--_accent-800) 100%)}.mythical-player.has-gradient::before{opacity:1;background:linear-gradient(145deg, var(--player--main-color-0) 0%, var(--player--main-color-1) 25%, var(--player--main-color-2) 50%, var(--player--main-color-3) 75%, var(--player--main-color-4) 100%)}@container player (width < 768px){.mythical-player__inner{--player--flex-direction: column;--_secondary-block-width: unset;--_secondary-block-min-width: unset}}@container player (width >= 768px){.mythical-player__inner{--player--flex-direction: row;--_secondary-block-width: 25%;--_secondary-block-min-width: 20rem}}.mythical-player__inner{display:flex;flex-direction:column;height:100%;color:var(--_text-color);position:relative;z-index:2}.mythical-player__body{display:flex;flex-direction:var(--player--flex-direction);flex:1 0 0;overflow:hidden;padding:0.5rem 0}.mythical-player__playlist{overflow:hidden;padding:0 0 0 0.5rem;display:flex;flex:1 0 0}.mythical-player__track-info{width:var(--_secondary-block-width);min-width:var(--_secondary-block-min-width);padding:0.5rem}.mythical-player__controls{display:flex;justify-content:center;margin-top:-1rem}.mythical-player__controls,.mythical-player__timeline{position:relative}mythical-cover-fallback{display:block}.cover-fallback{--_cover-fallback-bg-color: light-dark(var(--_accent-200), var(--_accent-700));--_cover-fallback-font-size: 2rem}.cover-fallback.cover-fallback--in-file-item{--_cover-fallback-font-size: 2rem}@container player (width >= 768px){.cover-fallback{--_cover-fallback-font-size: 10rem}.cover-fallback.cover-fallback--in-file-item{--_cover-fallback-font-size: 2rem}}.cover-fallback{width:inherit;padding-top:100%;background-color:var(--_cover-fallback-bg-color);display:flex;align-items:center;justify-content:center;position:relative}.cover-fallback__icon{width:80%;height:80%;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);color:var(--_text-color);display:flex;justify-content:center;align-items:center}.cover-fallback__icon-inner{width:100%;height:100%}.myth-controls{--_controls-color: light-dark( var(--_accent-950), var(--_accent-100) );--_controls-size: 3rem}@container player (width >= 768px){.myth-controls{--_controls-size: 3.5rem}}@container player (width >= 1024px){.myth-controls{--_controls-size: 4rem}}.myth-controls,.myth-controls__items{width:auto}.myth-controls__items{display:flex}.myth-controls__button{background:rgba(0,0,0,0);border:0;color:var(--_controls-color)}.myth-controls__button:focus-visible{outline:light-dark(oklch(48.8% 0.243 264.376deg), oklch(88.2% 0.059 254.128deg)) solid 2px;outline-offset:-4px}.myth-controls__button.is-disabled{opacity:.4}.myth-controls__icon{width:var(--_controls-size);height:var(--_controls-size)}.myth-playlist{--_playlist-font-weight: normal;--_playlist-font-size: 0.75rem;--_playlist-font-size-small: 0.625rem;--_playlist-item-background-color: transparent;--_playlist-item-image-size: 3rem}.myth-playlist .is-playing{--_playlist-font-weight: 600;--_playlist-item-background-color: var(--_accent-200)}.ambient-dark .myth-playlist .is-playing{--_playlist-item-background-color: var(--_accent-700)}@container player (width >= 1024px){.myth-playlist{--_playlist-font-size: 1rem;--_playlist-font-size-small: 0.75rem;--_playlist-item-image-size: 4rem}}.myth-playlist .myth-item-text{font-weight:var(--_playlist-font-weight);font-size:var(--_playlist-font-size);line-height:150%}.myth-playlist .myth-item-text.size-small{font-size:var(--_playlist-font-size-small)}.myth-playlist__items{padding:0;position:relative}.myth-playlist__item{position:relative;border-bottom:1px solid var(--_separator-color)}.myth-playlist__item.is-playing:before{content:"";position:absolute;top:0;left:0;width:100%;height:100%;opacity:.45}@keyframes colorPulse{from{background-color:var(--pulse-bg-start)}to{background-color:var(--pulse-bg-end)}}.myth-playlist__item.is-playing:before{background-color:var(--pulse-bg-start);animation:colorPulse 3.2s ease infinite alternate-reverse;opacity:.3}.myth-playlist__item:last-child{border-bottom:0}.myth-playlist__item-button{display:flex;padding:0.5rem;position:relative;align-items:center}.myth-playlist__item-button:focus-visible{outline:light-dark(oklch(48.8% 0.243 264.376deg), oklch(88.2% 0.059 254.128deg)) solid 2px;outline-offset:-4px}.myth-playlist__item-group,.myth-playlist__item-block{margin-left:1rem}.myth-playlist__item-group:first-child,.myth-playlist__item-block:first-child{margin-left:0}.myth-playlist__item-group.is-last-right,.myth-playlist__item-block.is-last-right{margin-left:auto;padding-left:0.5rem}.myth-playlist__item-group{display:flex;align-items:center}.myth-playlist__item-image{width:var(--_playlist-item-image-size);height:var(--_playlist-item-image-size);position:relative;overflow:hidden;flex-shrink:0}.myth-playlist__item-image img{height:100%;position:absolute;top:0;left:50%;transform:translateX(-50%)}.myth-playlist__item-playing-icon{width:1rem;height:1rem;display:flex;align-items:center}.myth-playlist__item-playing-icon-inner{width:100%;aspect-ratio:1/1}.timeline{--timeline--background: var(--_accent-200);--timeline--completed-background: var(--_accent-800);--timeline--font-size: 0.75rem;--timeline--numbers-separation: 0.125rem;--timeline--chapter-limit-color: oklch(14.5% 0 0deg)}.timeline .timeline__chapter-limit--played{--timeline--chapter-limit-color: oklch(98.5% 0 0deg)}.ambient-dark .timeline{--timeline--background: var(--_accent-800);--timeline--chapter-limit-color: oklch(98.5% 0 0deg);--timeline--completed-background: var(--_accent-200)}.ambient-dark .timeline .timeline__chapter-limit--played{--timeline--chapter-limit-color: oklch(14.5% 0 0deg)}@container player (width >= 768px){.timeline{--timeline--font-size: 0.875rem;--timeline--numbers-separation: 0.25rem}}@container player (width >= 1024px){.timeline{--timeline--font-size: 1rem;--timeline--numbers-separation: 0.5rem}}mythical-player-timeline{display:block}.timeline{position:relative;padding:0 0.5rem}.timeline__track{height:0.5rem;width:100%;background-color:var(--timeline--background);cursor:pointer}.timeline__track:focus-visible{outline:light-dark(oklch(48.8% 0.243 264.376deg), oklch(88.2% 0.059 254.128deg)) solid 2px;outline-offset:2px}.timeline__completed{height:100%;background-color:var(--timeline--completed-background)}.timeline__numbers{display:flex;justify-content:space-between;padding-top:var(--timeline--numbers-separation);font-size:var(--timeline--font-size)}.timeline__tooltip{position:absolute;top:0;transform:translate(-50%, -100%);left:var(--timeline-tooltip-position);padding-bottom:0.5rem;z-index:3}.timeline__tooltip-inner{background-color:oklch(100% 0 0deg);color:oklch(37.1% 0 0deg);padding:0.25rem;position:relative;border-width:1px 1px 0 1px;border-color:oklch(.922 0 0);border-style:solid;max-width:8rem;display:flex;flex-direction:column;align-items:center}.timeline__tooltip-inner:after{content:"";width:0;height:0;border-style:solid;border-width:0 4px 6.9px 4px;border-color:rgba(0,0,0,0) rgba(0,0,0,0) oklch(100% 0 0deg) rgba(0,0,0,0);position:absolute;top:100%;left:50%;transform:translateX(-50%) rotate(180deg)}.timeline__tooltip-time{font-size:1rem}.timeline__tooltip-chapter-title{font-size:0.75rem;margin-bottom:0.25rem}.timeline__chapter-limit{width:1px;height:0.5rem;background-color:var(--timeline--chapter-limit-color);position:absolute;top:0;left:var(--timeline--chapter-limit-position)}.myth-track-info{--track-info--flex-direction: row;--track-info--image-width: 4rem;--track-info--image-separation-horizontal: 1rem;--track-info--image-separation-vertical: 0;--track-info--height: 4rem}@container player (width >= 768px){.myth-track-info{--track-info--flex-direction: column;--track-info--image-width: 100%;--track-info--image-separation-horizontal: 0;--track-info--image-separation-vertical: 1rem;--track-info--height: auto}}.myth-track-info__inner{display:flex;flex-direction:var(--track-info--flex-direction);height:var(--track-info--height)}.myth-track-info__inner .myth-item-text{font-size:1rem;line-height:150%}.myth-track-info__inner .myth-item-text.size-small{font-size:0.75rem}.myth-track-info__image{width:var(--track-info--image-width);flex-shrink:0;display:flex;align-items:center;margin-right:var(--track-info--image-separation-horizontal);margin-bottom:var(--track-info--image-separation-vertical)}.myth-track-info__image>*{width:100%}.myth-track-info__data{display:flex;align-items:center}`;
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@outbook/webcomponents-player",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"main": "player.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"scripts": {},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"web player",
|
|
10
|
+
"audio player",
|
|
11
|
+
"audio",
|
|
12
|
+
"playlist"
|
|
13
|
+
],
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://gitlab.com/arr2019/web-components/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://gitlab.com/arr2019/web-components/pkg/player#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://gitlab.com/arr2019/web-components.git",
|
|
21
|
+
"folder": "pkg/player"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org/"
|
|
25
|
+
},
|
|
26
|
+
"author": "Antonio Rodríguez",
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"description": "Web component media player (formerly mythical-player)",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"a11y-key-conjurer": "1.1.2",
|
|
31
|
+
"color.js": "1.2.0",
|
|
32
|
+
"custom-event-conjurer": "1.0.0",
|
|
33
|
+
"mystic-format-time": "1.0.2",
|
|
34
|
+
"@outbook/webcomponents-scrollable": ">=1.0.0",
|
|
35
|
+
"@outbook/webcomponents-type-icon": ">=1.1.2",
|
|
36
|
+
"@outbook/webcomponents-badge-file-extension": ">=1.2.0",
|
|
37
|
+
"@outbook/icons": ">=1.3.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@outbook/colorful": ">=1.1.2",
|
|
41
|
+
"@outbook/design-decisions": ">=1.1.5"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"sass": "^1.97.2",
|
|
45
|
+
"lit": "^3.0.0",
|
|
46
|
+
"haunted": "^5.0.0 || ^6.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/player.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { adoptStyles, html, nothing } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { component, useEffect, useState } from 'haunted';
|
|
4
|
+
import { customEventConjurer } from 'custom-event-conjurer';
|
|
5
|
+
import styleComponent from './_style/player.style.js';
|
|
6
|
+
import { setupMediaSession } from './_lib/setup-media-session.js';
|
|
7
|
+
import { emptyBackground, getBackgroundColor } from './_lib/background.js';
|
|
8
|
+
import { getCover } from './_lib/get-cover.js';
|
|
9
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
10
|
+
import { Scrollable } from '@outbook/webcomponents-scrollable';
|
|
11
|
+
import { Playlist as ComponentPlaylist } from './_lib/playlist/index.js';
|
|
12
|
+
import { TrackInfo } from './_lib/track-info/index.js';
|
|
13
|
+
import { Controls } from './_lib/controls/index.js';
|
|
14
|
+
import { Timeline } from './_lib/timeline/index.js';
|
|
15
|
+
import { readable as formatTime } from 'mystic-format-time';
|
|
16
|
+
import { loadLiterals } from './_i18n/i18n.js';
|
|
17
|
+
import _literals from './_i18n/en.json' with { type: 'json' };
|
|
18
|
+
import { useLangObserver } from '@outbook/hooks';
|
|
19
|
+
|
|
20
|
+
function ComponentPlayer(element) {
|
|
21
|
+
const { playlist = [], list } = element;
|
|
22
|
+
const mediaId = 'mythical-media-element';
|
|
23
|
+
const listId = 'mythical-list';
|
|
24
|
+
const playlistScrollId = 'mythical-playlist-scroll';
|
|
25
|
+
const timelineUniqueId = 'mythical-timeline';
|
|
26
|
+
|
|
27
|
+
function getMediaElement() {
|
|
28
|
+
const el = element.shadowRoot.getElementById(mediaId);
|
|
29
|
+
if (!el) {
|
|
30
|
+
console.warn('Media element not found yet');
|
|
31
|
+
}
|
|
32
|
+
return el;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const currentLang = useLangObserver(element);
|
|
36
|
+
const [literals, setLiterals] = useState(_literals);
|
|
37
|
+
const [indexSelected, setIndexSelected] = useState(null);
|
|
38
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
|
39
|
+
const [totalTime, setTotalTime] = useState(0);
|
|
40
|
+
const [prominentColors, setProminentColors] = useState('');
|
|
41
|
+
const [hasProminentColors, setHasProminentColors] = useState(false);
|
|
42
|
+
const [coverUrl, setCoverUrl] = useState(null);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
let isActive = true; // 1. Flag to track if component is alive
|
|
46
|
+
|
|
47
|
+
if (coverUrl) {
|
|
48
|
+
setHasProminentColors(true);
|
|
49
|
+
|
|
50
|
+
getBackgroundColor(coverUrl)
|
|
51
|
+
.then(colorString => {
|
|
52
|
+
if (isActive) {
|
|
53
|
+
setProminentColors(colorString);
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.catch(err => {
|
|
57
|
+
console.warn('Color extraction failed', err);
|
|
58
|
+
if (isActive) {
|
|
59
|
+
setHasProminentColors(false);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
setHasProminentColors(false);
|
|
64
|
+
setProminentColors(emptyBackground);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
isActive = false;
|
|
69
|
+
};
|
|
70
|
+
}, [coverUrl]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (element.shadowRoot) {
|
|
74
|
+
adoptStyles(element.shadowRoot, [styleComponent]);
|
|
75
|
+
}
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (navigator.mediaSession && indexSelected !== null) {
|
|
80
|
+
setupMediaSession({
|
|
81
|
+
index: indexSelected,
|
|
82
|
+
playlist,
|
|
83
|
+
handleAudio: {
|
|
84
|
+
stop: handleAudio.stop,
|
|
85
|
+
play: handleAudio.play,
|
|
86
|
+
pause: handleSessionPause,
|
|
87
|
+
next: handleSessionNext,
|
|
88
|
+
previous: handleSessionPrevious
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
} else if (navigator.mediaSession) {
|
|
92
|
+
navigator.mediaSession.metadata = null;
|
|
93
|
+
}
|
|
94
|
+
}, [indexSelected]);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
let isMounted = true;
|
|
98
|
+
|
|
99
|
+
loadLiterals(currentLang).then(data => {
|
|
100
|
+
if (isMounted) {
|
|
101
|
+
setLiterals(data);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return () => {
|
|
106
|
+
isMounted = false;
|
|
107
|
+
};
|
|
108
|
+
}, [currentLang]);
|
|
109
|
+
|
|
110
|
+
function handleSessionPrevious() {
|
|
111
|
+
handleAudio.setTrack({ index: indexSelected - 1, fromControls: true });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleSessionNext() {
|
|
115
|
+
handleAudio.setTrack({ index: indexSelected + 1, fromControls: true });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function handleSessionPause() {
|
|
119
|
+
getMediaElement().pause();
|
|
120
|
+
if (navigator.mediaSession) {
|
|
121
|
+
navigator.mediaSession.playbackState = 'paused';
|
|
122
|
+
}
|
|
123
|
+
setIsPlaying(false);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleSessionPlay() {
|
|
127
|
+
getMediaElement().play();
|
|
128
|
+
setIsPlaying(true);
|
|
129
|
+
if (navigator.mediaSession) {
|
|
130
|
+
navigator.mediaSession.playbackState = 'playing';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function handleSessionStop() {
|
|
135
|
+
if (navigator.mediaSession) {
|
|
136
|
+
navigator.mediaSession.playbackState = 'none';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const media = getMediaElement();
|
|
140
|
+
|
|
141
|
+
if (media) {
|
|
142
|
+
media.pause();
|
|
143
|
+
media.currentTime = 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setTotalTime(0);
|
|
147
|
+
setHasProminentColors(false);
|
|
148
|
+
|
|
149
|
+
if (navigator.mediaSession) {
|
|
150
|
+
navigator.mediaSession.metadata = null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
setIndexSelected(null);
|
|
154
|
+
setCoverUrl(null);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function handleScroll({ index }) {
|
|
158
|
+
customEventConjurer({
|
|
159
|
+
name: 'scrollToPlayingItem',
|
|
160
|
+
detail: {
|
|
161
|
+
selectedItem: element.shadowRoot
|
|
162
|
+
.getElementById(listId)
|
|
163
|
+
.querySelector(`[data-playlist-item="${index}"]`)
|
|
164
|
+
},
|
|
165
|
+
bubbles: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const handleAudio = {
|
|
170
|
+
next: handleSessionNext,
|
|
171
|
+
previous: handleSessionPrevious,
|
|
172
|
+
setTrack({ index, fromControls = false }) {
|
|
173
|
+
setIndexSelected(index);
|
|
174
|
+
if (fromControls) {
|
|
175
|
+
handleScroll({ index });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (playlist[index]?.cover?.name) {
|
|
179
|
+
setCoverUrl(getCover(playlist[index]?.cover));
|
|
180
|
+
} else {
|
|
181
|
+
setCoverUrl(null);
|
|
182
|
+
}
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
this.playInitial();
|
|
185
|
+
}, 100);
|
|
186
|
+
},
|
|
187
|
+
stop: handleSessionStop,
|
|
188
|
+
play: handleSessionPlay,
|
|
189
|
+
playInitial() {
|
|
190
|
+
const mediaElement = getMediaElement();
|
|
191
|
+
if (!mediaElement) {
|
|
192
|
+
console.warn('Audio element not ready yet, retrying...');
|
|
193
|
+
setTimeout(() => this.playInitial(), 50);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
mediaElement.currentTime = 0;
|
|
197
|
+
|
|
198
|
+
mediaElement
|
|
199
|
+
.play()
|
|
200
|
+
.then(function () {
|
|
201
|
+
setTotalTime(mediaElement.duration);
|
|
202
|
+
if (navigator.mediaSession) {
|
|
203
|
+
navigator.mediaSession.playbackState = 'playing';
|
|
204
|
+
}
|
|
205
|
+
setIsPlaying(true);
|
|
206
|
+
})
|
|
207
|
+
.catch(err => console.error('Autoplay blocked:', err));
|
|
208
|
+
},
|
|
209
|
+
pause: handleSessionPause
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
function handleAudioEnd() {
|
|
213
|
+
if (playlist.length - 1 === indexSelected) {
|
|
214
|
+
handleAudio.stop();
|
|
215
|
+
} else {
|
|
216
|
+
handleAudio.setTrack({ index: indexSelected + 1, fromControls: true });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function handleTimeUpdate(ev) {
|
|
221
|
+
const media = ev.currentTarget;
|
|
222
|
+
const currentSecs = media.currentTime;
|
|
223
|
+
const duration = media.duration || totalTime; // fallback to state totalTime
|
|
224
|
+
|
|
225
|
+
const bar = element.shadowRoot.getElementById(`bar-${timelineUniqueId}`);
|
|
226
|
+
const txt = element.shadowRoot.getElementById(`txt-${timelineUniqueId}`);
|
|
227
|
+
|
|
228
|
+
if (bar && duration > 0) {
|
|
229
|
+
const percent = (currentSecs / duration) * 100;
|
|
230
|
+
bar.style.width = `${percent}%`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (txt) {
|
|
234
|
+
txt.textContent = formatTime(currentSecs);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const mainClasses = classMap({
|
|
239
|
+
'mythical-player': true,
|
|
240
|
+
'root-container': true,
|
|
241
|
+
'has-gradient': hasProminentColors
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return literals
|
|
245
|
+
? html`
|
|
246
|
+
<div class="${mainClasses}" style="${prominentColors}">
|
|
247
|
+
<div class="mythical-player__inner">
|
|
248
|
+
<div class="mythical-player__body">
|
|
249
|
+
<div class="mythical-player__playlist">
|
|
250
|
+
${Scrollable({
|
|
251
|
+
extraClasses: 'scrollable--default',
|
|
252
|
+
eventScrollToPlayingItem: true,
|
|
253
|
+
id: playlistScrollId,
|
|
254
|
+
content: function () {
|
|
255
|
+
return ComponentPlaylist({
|
|
256
|
+
playlist,
|
|
257
|
+
list,
|
|
258
|
+
indexSelected,
|
|
259
|
+
isPlaying,
|
|
260
|
+
handleAudio,
|
|
261
|
+
listId
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
})}
|
|
265
|
+
</div>
|
|
266
|
+
<div class="mythical-player__track-info">
|
|
267
|
+
${TrackInfo({
|
|
268
|
+
indexSelected,
|
|
269
|
+
track: playlist[indexSelected],
|
|
270
|
+
literals: literals.trackInfo
|
|
271
|
+
})}
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
<div class="mythical-player__timeline">
|
|
275
|
+
${Timeline({
|
|
276
|
+
totalTime,
|
|
277
|
+
currentTime: 0,
|
|
278
|
+
getMediaElement,
|
|
279
|
+
id: timelineUniqueId
|
|
280
|
+
})}
|
|
281
|
+
</div>
|
|
282
|
+
<div class="mythical-player__controls">
|
|
283
|
+
${Controls({
|
|
284
|
+
props: { isPlaying, playlist, indexSelected },
|
|
285
|
+
handleAudio,
|
|
286
|
+
literals: literals.controls
|
|
287
|
+
})}
|
|
288
|
+
</div>
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
${Number.isInteger(indexSelected)
|
|
292
|
+
? html`
|
|
293
|
+
<audio
|
|
294
|
+
src="${playlist[indexSelected]?.file}"
|
|
295
|
+
id="${mediaId}"
|
|
296
|
+
@ended="${handleAudioEnd}"
|
|
297
|
+
@timeupdate="${handleTimeUpdate}"
|
|
298
|
+
></audio>
|
|
299
|
+
`
|
|
300
|
+
: nothing}
|
|
301
|
+
`
|
|
302
|
+
: html`Loading...`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (!customElements.get('outbook-player')) {
|
|
306
|
+
customElements.define(
|
|
307
|
+
'outbook-player',
|
|
308
|
+
component(ComponentPlayer, {
|
|
309
|
+
observedAttributes: ['lang'],
|
|
310
|
+
useShadowDOM: true
|
|
311
|
+
})
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function Player(props) {
|
|
316
|
+
const { extraClasses, lang = 'en', playlist = [] } = props;
|
|
317
|
+
return html`
|
|
318
|
+
<outbook-player
|
|
319
|
+
class="${ifDefined(extraClasses || undefined)}"
|
|
320
|
+
lang="${lang}"
|
|
321
|
+
.playlist="${playlist}"
|
|
322
|
+
></outbook-player>
|
|
323
|
+
`;
|
|
324
|
+
}
|