@outbook/webcomponents-player-timeline 1.0.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 +100 -0
- package/_i18n/af.json +8 -0
- package/_i18n/ar.json +8 -0
- package/_i18n/bg.json +8 -0
- package/_i18n/bn.json +8 -0
- package/_i18n/ca.json +8 -0
- package/_i18n/cs.json +8 -0
- package/_i18n/da.json +8 -0
- package/_i18n/de.json +8 -0
- package/_i18n/el.json +8 -0
- package/_i18n/en.json +8 -0
- package/_i18n/es.json +8 -0
- package/_i18n/eu.json +8 -0
- package/_i18n/fa.json +8 -0
- package/_i18n/fi.json +8 -0
- package/_i18n/fr.json +8 -0
- package/_i18n/gl.json +8 -0
- package/_i18n/ha.json +8 -0
- package/_i18n/hi.json +8 -0
- package/_i18n/hu.json +8 -0
- package/_i18n/i18n.js +97 -0
- package/_i18n/id.json +8 -0
- package/_i18n/it.json +8 -0
- package/_i18n/ja.json +8 -0
- package/_i18n/km.json +8 -0
- package/_i18n/ko.json +8 -0
- package/_i18n/lo.json +8 -0
- package/_i18n/ms.json +8 -0
- package/_i18n/nl.json +8 -0
- package/_i18n/no.json +8 -0
- package/_i18n/pl.json +8 -0
- package/_i18n/pt.json +8 -0
- package/_i18n/ro.json +8 -0
- package/_i18n/ru.json +8 -0
- package/_i18n/sk.json +8 -0
- package/_i18n/sv.json +8 -0
- package/_i18n/sw.json +8 -0
- package/_i18n/th.json +8 -0
- package/_i18n/tl.json +8 -0
- package/_i18n/tr.json +8 -0
- package/_i18n/uk.json +8 -0
- package/_i18n/vi.json +8 -0
- package/_i18n/zh.json +8 -0
- package/_i18n/zu.json +8 -0
- package/_lib/a11y-time.js +22 -0
- package/_lib/constants.js +1 -0
- package/_lib/handle-timeline-position.js +15 -0
- package/_lib/is-touch.js +3 -0
- package/_style/player-timeline.style.js +4 -0
- package/package.json +38 -0
- package/player-timeline.js +259 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Antonio Rodríguez Ruiz
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @outbook/webcomponents-player-timeline
|
|
2
|
+
|
|
3
|
+
This package provides a web component for a customizable player timeline, displaying playback progress and chapter markers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @outbook/webcomponents-player-timeline
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### As a Lit Element
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import {html} from 'lit';
|
|
17
|
+
import {PlayerTimeline} from '@outbook/webcomponents-player-timeline';
|
|
18
|
+
|
|
19
|
+
function render() {
|
|
20
|
+
const duration = 120; // Example duration in seconds
|
|
21
|
+
const currentTime = 30; // Example current time in seconds
|
|
22
|
+
const currentItem = {
|
|
23
|
+
metadata: {
|
|
24
|
+
chapters: [
|
|
25
|
+
{start: 0, end: 30000, tags: {title: 'Introduction'}},
|
|
26
|
+
{start: 30000, end: 60000, tags: {title: 'Chapter 1'}},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return html`
|
|
32
|
+
${PlayerTimeline({
|
|
33
|
+
duration: duration,
|
|
34
|
+
props: {
|
|
35
|
+
currentTime: currentTime,
|
|
36
|
+
currentItem: currentItem,
|
|
37
|
+
},
|
|
38
|
+
})}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Direct HTML Usage
|
|
44
|
+
|
|
45
|
+
You can also use the custom element directly in your HTML. Remember to import the component's JavaScript for the custom element to be defined. The `duration` attribute represents the total duration of the media in seconds. The component's internal state (like `currentTime` and `currentItem`) is passed via the `.props` property when used directly, which is less common for simple HTML usage but possible for framework integration.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import '@outbook/webcomponents-player-timeline';
|
|
49
|
+
|
|
50
|
+
// Example of setting props if needed, typically handled by a framework
|
|
51
|
+
const playerTimeline = document.querySelector('outbook-player-timeline');
|
|
52
|
+
playerTimeline.duration = 120; // Total duration in seconds
|
|
53
|
+
playerTimeline.props = {
|
|
54
|
+
currentTime: 30, // Current playback time in seconds
|
|
55
|
+
currentItem: {
|
|
56
|
+
metadata: {
|
|
57
|
+
chapters: [
|
|
58
|
+
{start: 0, end: 30000, tags: {title: 'Introduction'}},
|
|
59
|
+
{start: 30000, end: 60000, tags: {title: 'Chapter 1'}},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<outbook-player-timeline duration="120"></outbook-player-timeline>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Component Usage
|
|
71
|
+
|
|
72
|
+
The component is best used via its wrapper function `PlayerTimeline`, which simplifies passing complex properties like `props`.
|
|
73
|
+
|
|
74
|
+
### Properties
|
|
75
|
+
|
|
76
|
+
| Attribute | Property | Type | Default | Description |
|
|
77
|
+
|---|---|---|---|---|
|
|
78
|
+
| `duration` | `duration` | `Number` | `undefined` | The total duration of the media in seconds. (Required) |
|
|
79
|
+
| `lang` | `lang` | `String` | `'en'` | The language to use for internationalization. |
|
|
80
|
+
| `extraClasses` | `extraClasses` | `String` | `undefined` | Classes to add to the host element. |
|
|
81
|
+
| `props` | `props` | `Object` | `{}` | An object containing dynamic properties like `currentTime` (current playback time in seconds) and `currentItem` (an object that can contain `metadata.chapters` for chapter markers). |
|
|
82
|
+
|
|
83
|
+
## Styling
|
|
84
|
+
|
|
85
|
+
This component uses Shadow DOM, and its styles are self-contained. The component's styles are automatically applied and encapsulated, so there is no need to import any additional stylesheets.
|
|
86
|
+
|
|
87
|
+
### Custom Properties
|
|
88
|
+
|
|
89
|
+
Can be used with css `light-dark` function.
|
|
90
|
+
|
|
91
|
+
| Custom Property | Description |
|
|
92
|
+
|-------------------------------------------------------|---------------------------------------------------|
|
|
93
|
+
| `--outbook-player-timeline--background` | The background color of the timeline track. |
|
|
94
|
+
| `--outbook-player-timeline--background-completed` | The background color of the completed part of the timeline track. |
|
|
95
|
+
| `--outbook-player-timeline--chapter-mark-color` | The color of chapter markers. |
|
|
96
|
+
| `--outbook-player-timeline--chapter-played-mark-color`| The color of chapter markers for played chapters. |
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
This component is licensed under the Apache-2.0 License.
|
package/_i18n/af.json
ADDED
package/_i18n/ar.json
ADDED
package/_i18n/bg.json
ADDED
package/_i18n/bn.json
ADDED
package/_i18n/ca.json
ADDED
package/_i18n/cs.json
ADDED
package/_i18n/da.json
ADDED
package/_i18n/de.json
ADDED
package/_i18n/el.json
ADDED
package/_i18n/en.json
ADDED
package/_i18n/es.json
ADDED
package/_i18n/eu.json
ADDED
package/_i18n/fa.json
ADDED
package/_i18n/fi.json
ADDED
package/_i18n/fr.json
ADDED
package/_i18n/gl.json
ADDED
package/_i18n/ha.json
ADDED
package/_i18n/hi.json
ADDED
package/_i18n/hu.json
ADDED
package/_i18n/i18n.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import defaultLiterals from './en.json';
|
|
2
|
+
import af from './af.json';
|
|
3
|
+
import ar from './ar.json';
|
|
4
|
+
import bg from './bg.json';
|
|
5
|
+
import bn from './bn.json';
|
|
6
|
+
import ca from './ca.json';
|
|
7
|
+
import cs from './cs.json';
|
|
8
|
+
import da from './da.json';
|
|
9
|
+
import de from './de.json';
|
|
10
|
+
import el from './el.json';
|
|
11
|
+
import es from './es.json';
|
|
12
|
+
import eu from './eu.json';
|
|
13
|
+
import fa from './fa.json';
|
|
14
|
+
import fi from './fi.json';
|
|
15
|
+
import fr from './fr.json';
|
|
16
|
+
import gl from './gl.json';
|
|
17
|
+
import ha from './ha.json';
|
|
18
|
+
import hi from './hi.json';
|
|
19
|
+
import hu from './hu.json';
|
|
20
|
+
import id from './id.json';
|
|
21
|
+
import it from './it.json';
|
|
22
|
+
import ja from './ja.json';
|
|
23
|
+
import km from './km.json';
|
|
24
|
+
import ko from './ko.json';
|
|
25
|
+
import lo from './lo.json';
|
|
26
|
+
import ms from './ms.json';
|
|
27
|
+
import nl from './nl.json';
|
|
28
|
+
import no from './no.json';
|
|
29
|
+
import pl from './pl.json';
|
|
30
|
+
import pt from './pt.json';
|
|
31
|
+
import ro from './ro.json';
|
|
32
|
+
import ru from './ru.json';
|
|
33
|
+
import sk from './sk.json';
|
|
34
|
+
import sv from './sv.json';
|
|
35
|
+
import sw from './sw.json';
|
|
36
|
+
import th from './th.json';
|
|
37
|
+
import tl from './tl.json';
|
|
38
|
+
import tr from './tr.json';
|
|
39
|
+
import uk from './uk.json';
|
|
40
|
+
import vi from './vi.json';
|
|
41
|
+
import zh from './zh.json';
|
|
42
|
+
import zu from './zu.json';
|
|
43
|
+
|
|
44
|
+
const literals = {
|
|
45
|
+
en: defaultLiterals,
|
|
46
|
+
af,
|
|
47
|
+
ar,
|
|
48
|
+
bg,
|
|
49
|
+
bn,
|
|
50
|
+
ca,
|
|
51
|
+
cs,
|
|
52
|
+
da,
|
|
53
|
+
de,
|
|
54
|
+
el,
|
|
55
|
+
es,
|
|
56
|
+
eu,
|
|
57
|
+
fa,
|
|
58
|
+
fi,
|
|
59
|
+
fr,
|
|
60
|
+
gl,
|
|
61
|
+
ha,
|
|
62
|
+
hi,
|
|
63
|
+
hu,
|
|
64
|
+
id,
|
|
65
|
+
it,
|
|
66
|
+
ja,
|
|
67
|
+
km,
|
|
68
|
+
ko,
|
|
69
|
+
lo,
|
|
70
|
+
ms,
|
|
71
|
+
nl,
|
|
72
|
+
no,
|
|
73
|
+
pl,
|
|
74
|
+
pt,
|
|
75
|
+
ro,
|
|
76
|
+
ru,
|
|
77
|
+
sk,
|
|
78
|
+
sv,
|
|
79
|
+
sw,
|
|
80
|
+
th,
|
|
81
|
+
tl,
|
|
82
|
+
tr,
|
|
83
|
+
uk,
|
|
84
|
+
vi,
|
|
85
|
+
zh,
|
|
86
|
+
zu
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} lang - ISO language code (e.g. "fr", "de").
|
|
91
|
+
* @returns {Promise<Object>} Resolved with the language object.
|
|
92
|
+
*/
|
|
93
|
+
export async function loadLiterals(lang) {
|
|
94
|
+
const key = String(lang).trim().toLowerCase();
|
|
95
|
+
const loadedLiterals = literals[key] || defaultLiterals;
|
|
96
|
+
return Promise.resolve(loadedLiterals);
|
|
97
|
+
}
|
package/_i18n/id.json
ADDED
package/_i18n/it.json
ADDED
package/_i18n/ja.json
ADDED
package/_i18n/km.json
ADDED
package/_i18n/ko.json
ADDED
package/_i18n/lo.json
ADDED
package/_i18n/ms.json
ADDED
package/_i18n/nl.json
ADDED
package/_i18n/no.json
ADDED
package/_i18n/pl.json
ADDED
package/_i18n/pt.json
ADDED
package/_i18n/ro.json
ADDED
package/_i18n/ru.json
ADDED
package/_i18n/sk.json
ADDED
package/_i18n/sv.json
ADDED
package/_i18n/sw.json
ADDED
package/_i18n/th.json
ADDED
package/_i18n/tl.json
ADDED
package/_i18n/tr.json
ADDED
package/_i18n/uk.json
ADDED
package/_i18n/vi.json
ADDED
package/_i18n/zh.json
ADDED
package/_i18n/zu.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function a11yTime({ time: _time, literals }) {
|
|
2
|
+
const time = Math.floor(_time);
|
|
3
|
+
const hours = Math.floor(time / 3600);
|
|
4
|
+
const minutes = Math.floor((time % 3600) / 60);
|
|
5
|
+
const seconds = time % 60;
|
|
6
|
+
|
|
7
|
+
const parts = [];
|
|
8
|
+
|
|
9
|
+
if (hours) {
|
|
10
|
+
parts.push(`${hours} ${hours === 1 ? literals.hour : literals.hours}`);
|
|
11
|
+
}
|
|
12
|
+
if (minutes) {
|
|
13
|
+
parts.push(
|
|
14
|
+
`${minutes} ${minutes === 1 ? literals.minute : literals.minutes}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
parts.push(
|
|
18
|
+
`${seconds} ${seconds === 1 ? literals.second : literals.seconds}`
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return parts.join(' ');
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SKIP_TIME = 10;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function handleTimelinePositionBase({ ev, isTouchEvent }) {
|
|
2
|
+
const clientX = isTouchEvent ? ev.changedTouches[0].clientX : ev.clientX;
|
|
3
|
+
const target = ev.currentTarget;
|
|
4
|
+
const rect = target.getBoundingClientRect();
|
|
5
|
+
const x = clientX - rect.left;
|
|
6
|
+
return (100 * x) / target.offsetWidth;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function handleTimelinePosition(ev) {
|
|
10
|
+
return handleTimelinePositionBase({ ev, isTouchEvent: false });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function handleTimelinePositionTouch(ev) {
|
|
14
|
+
return handleTimelinePositionBase({ ev, isTouchEvent: true });
|
|
15
|
+
}
|
package/_lib/is-touch.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { css } from 'lit';
|
|
3
|
+
|
|
4
|
+
export default css`:host{color-scheme:inherit;display:block;width:100%;container-name:player-timeline;container-type:inline-size;--_background: var( --outbook-player-timeline--background, light-dark( var(--color-accent-200), var(--color-accent-800) ) );--_background-completed: var( --outbook-player-timeline--background-completed, light-dark( var(--color-accent-800), var(--color-accent-200) ) );--_chapter-mark-color: var( --outbook-player-timeline--chapter-mark-color, light-dark( oklch(14.5% 0 0deg), oklch(98.5% 0 0deg) ) );--_text-size: 0.75rem;--_numbers-spacing: 0.125rem}:host .player-timeline__chapter-limit--played{--_chapter-mark-color: var( --outbook-player-timeline--chapter-played-mark-color, light-dark( oklch(98.5% 0 0deg), oklch(14.5% 0 0deg) ) )}@container player (width >= 740px){--_text-size: 0.875rem;--_numbers-spacing: 0.25rem}@container player (width >= 820px){--_text-size: 1rem;--_numbers-spacing: 0.5rem}*{box-sizing:border-box}.player-timeline{position:relative}.player-timeline__track{position:relative;height:1rem;display:flex;align-items:center}.player-timeline__track-real{width:100%;height:100%;cursor:pointer;position:absolute;top:0;left:0;z-index:4}.player-timeline__track-real:focus-visible{outline:var(--outbook-outline--color, light-dark(oklch(48.8% 0.243 264.376deg), oklch(88.2% 0.059 254.128deg))) solid 2px;outline-offset:2px}.player-timeline__track-fake{height:0.25rem;background-color:var(--_background);width:100%;position:relative;border-radius:0.25rem}.player-timeline__completed{height:100%;position:relative;background-color:var(--_background-completed);border-radius:0.25rem 0 0 0.25rem}.player-timeline__thumb{height:0.625rem;width:0.625rem;border-radius:50%;background-color:var(--_background-completed);position:absolute;top:-0.1875rem;right:-0.1875rem;z-index:3}.player-timeline__numbers{display:flex;justify-content:space-between;padding-top:var(--_numbers-spacing);font-size:var(--_text-size)}.player-timeline__tooltip{position:absolute;top:0;transform:translate(-50%, -100%);left:var(--timeline-tooltip-position);padding-bottom:0.5rem;z-index:999}.player-timeline__tooltip-inner{background-color:oklch(100% 0 0deg);color:oklch(37.1% 0 0deg);padding:0.25rem;position:relative;max-width:8rem;display:flex;flex-direction:column;align-items:center;filter:drop-shadow(0 0 1px oklch(14.5% 0 0deg))}.player-timeline__tooltip-inner:after{content:"";position:absolute;background-color:oklch(100% 0 0deg);width:0.75rem;height:0.75rem;bottom:-0.375rem;left:50%;transform:translateX(-50%) rotate(45deg)}.player-timeline__tooltip-time{font-size:1rem}.player-timeline__tooltip-chapter-title{font-size:0.75rem;margin-bottom:0.25rem}.player-timeline__chapter-limit{width:1px;height:0.25rem;background-color:var(--_chapter-mark-color);position:absolute;top:50%;transform:translateY(-50%);left:var(--timeline--chapter-limit-position);z-index:2}`;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@outbook/webcomponents-player-timeline",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "player-timeline.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"scripts": {},
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://gitlab.com/arr2019/web-components/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://gitlab.com/arr2019/web-components/pkg/web-components/player-timeline#readme",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://gitlab.com/arr2019/web-components.git",
|
|
16
|
+
"folder": "pkg/web-components/player-timeline"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"registry": "https://registry.npmjs.com/"
|
|
20
|
+
},
|
|
21
|
+
"author": "Antonio Rodríguez",
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"description": "Web component player-timeline",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@outbook/webcomponents-type-icon": ">=1.1.2",
|
|
26
|
+
"@outbook/icons": ">=1.3.0",
|
|
27
|
+
"@outbook/hooks": ">=1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@outbook/colorful": ">=1.1.2",
|
|
31
|
+
"@outbook/design-decisions": ">=1.1.5"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"sass": "^1.97.2",
|
|
35
|
+
"lit": "^3.0.0",
|
|
36
|
+
"haunted": "^5.0.0 || ^6.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { adoptStyles, html, nothing } from 'lit';
|
|
2
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
3
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
4
|
+
import { component, useState, useMemo, useEffect } from 'haunted';
|
|
5
|
+
import { readable as formatTime } from 'mystic-format-time';
|
|
6
|
+
import { a11yTime } from './_lib/a11y-time.js';
|
|
7
|
+
import { loadLiterals } from './_i18n/i18n.js';
|
|
8
|
+
import _literals from './_i18n/en.json' with { type: 'json' };
|
|
9
|
+
import { useLangObserver } from '@outbook/hooks';
|
|
10
|
+
import styleComponent from './_style/player-timeline.style.js';
|
|
11
|
+
import {
|
|
12
|
+
isEventClick,
|
|
13
|
+
isKeyArrowLeft,
|
|
14
|
+
isKeyArrowRight
|
|
15
|
+
} from 'a11y-key-conjurer';
|
|
16
|
+
import {
|
|
17
|
+
handleTimelinePosition,
|
|
18
|
+
handleTimelinePositionTouch
|
|
19
|
+
} from './_lib/handle-timeline-position.js';
|
|
20
|
+
import { isTouch } from './_lib/is-touch.js';
|
|
21
|
+
import { SKIP_TIME } from './_lib/constants.js';
|
|
22
|
+
|
|
23
|
+
function getChapter({ targetTime, chapters }) {
|
|
24
|
+
const selected = chapters.find(
|
|
25
|
+
chapter =>
|
|
26
|
+
targetTime >= chapter.start / 1000 && targetTime < chapter.end / 1000
|
|
27
|
+
);
|
|
28
|
+
return selected?.tags?.title || null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function ComponentPlayerTimeline(element) {
|
|
32
|
+
const { props, duration: totalTime } = element;
|
|
33
|
+
const { currentTime, currentItem } = props;
|
|
34
|
+
|
|
35
|
+
const currentLang = useLangObserver(element);
|
|
36
|
+
const [literals, setLiterals] = useState(_literals);
|
|
37
|
+
const [timePosition, setTimePosition] = useState(null);
|
|
38
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
39
|
+
const chapters = currentItem?.metadata?.chapters || [];
|
|
40
|
+
|
|
41
|
+
const progress = useMemo(() => {
|
|
42
|
+
return (100 / totalTime) * currentTime;
|
|
43
|
+
}, [totalTime, currentTime]);
|
|
44
|
+
|
|
45
|
+
const progressVisible = useMemo(() => {
|
|
46
|
+
return (
|
|
47
|
+
(100 / totalTime) *
|
|
48
|
+
(timePosition?.number ? timePosition.number : currentTime)
|
|
49
|
+
);
|
|
50
|
+
}, [totalTime, currentTime, timePosition]);
|
|
51
|
+
|
|
52
|
+
function dispatchReposition(newTime) {
|
|
53
|
+
// Ensure to not dispatch times outside bounds of media
|
|
54
|
+
const safeTime = Math.max(0, Math.min(newTime, totalTime));
|
|
55
|
+
|
|
56
|
+
element.dispatchEvent(
|
|
57
|
+
new CustomEvent('reposition', {
|
|
58
|
+
bubbles: true,
|
|
59
|
+
composed: true,
|
|
60
|
+
detail: { currentTime: safeTime }
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleTimeline(ev) {
|
|
66
|
+
if (isEventClick(ev)) {
|
|
67
|
+
const percent = handleTimelinePosition(ev);
|
|
68
|
+
const targetTime = (totalTime / 100) * percent;
|
|
69
|
+
dispatchReposition(targetTime);
|
|
70
|
+
} else if (isKeyArrowLeft(ev)) {
|
|
71
|
+
ev.preventDefault();
|
|
72
|
+
dispatchReposition(currentTime - SKIP_TIME);
|
|
73
|
+
} else if (isKeyArrowRight(ev)) {
|
|
74
|
+
ev.preventDefault();
|
|
75
|
+
dispatchReposition(currentTime + SKIP_TIME);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function handleTimelineIn(ev) {
|
|
80
|
+
const target = ev.currentTarget;
|
|
81
|
+
const leftPosition = ev.layerX;
|
|
82
|
+
const targetWidth = target.offsetWidth;
|
|
83
|
+
const targetTime = (leftPosition * totalTime) / targetWidth;
|
|
84
|
+
setTimePosition({
|
|
85
|
+
number: targetTime,
|
|
86
|
+
visual: formatTime(targetTime),
|
|
87
|
+
chapter:
|
|
88
|
+
chapters.length > 0 ? getChapter({ targetTime, chapters }) : null,
|
|
89
|
+
left: leftPosition
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function handleThumbMouseMove(ev) {
|
|
94
|
+
if (isDragging) {
|
|
95
|
+
const targetTime = (totalTime / 100) * handleTimelinePosition(ev);
|
|
96
|
+
setTimePosition({
|
|
97
|
+
number: targetTime,
|
|
98
|
+
visual: formatTime(targetTime),
|
|
99
|
+
chapter:
|
|
100
|
+
chapters.length > 0 ? getChapter({ targetTime, chapters }) : null,
|
|
101
|
+
left: ev.layerX
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
handleTimelineIn(ev);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function handleThumbTouchMove(ev) {
|
|
109
|
+
const targetTime = (totalTime / 100) * handleTimelinePositionTouch(ev);
|
|
110
|
+
setTimePosition({
|
|
111
|
+
number: targetTime,
|
|
112
|
+
visual: formatTime(targetTime),
|
|
113
|
+
chapter:
|
|
114
|
+
chapters.length > 0 ? getChapter({ targetTime, chapters }) : null,
|
|
115
|
+
left: ev.changedTouches[0].clientX
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function handleTimelineOut() {
|
|
120
|
+
setTimePosition(null);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function handleThumbMouseDown() {
|
|
124
|
+
setIsDragging(true);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function handleThumbMouseUp() {
|
|
128
|
+
setTimeout(() => {
|
|
129
|
+
setIsDragging(false);
|
|
130
|
+
}, 100);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function handleThumbTouchEnd(ev) {
|
|
134
|
+
const percent = handleTimelinePositionTouch(ev);
|
|
135
|
+
const targetTime = (totalTime / 100) * percent;
|
|
136
|
+
dispatchReposition(targetTime);
|
|
137
|
+
|
|
138
|
+
handleTimelineOut();
|
|
139
|
+
handleThumbMouseUp();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (element.shadowRoot) {
|
|
144
|
+
adoptStyles(element.shadowRoot, [styleComponent]);
|
|
145
|
+
}
|
|
146
|
+
}, []);
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
let isMounted = true;
|
|
150
|
+
|
|
151
|
+
loadLiterals(currentLang).then(data => {
|
|
152
|
+
if (isMounted) {
|
|
153
|
+
setLiterals(data);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
isMounted = false;
|
|
159
|
+
};
|
|
160
|
+
}, [currentLang]);
|
|
161
|
+
|
|
162
|
+
return html`
|
|
163
|
+
<div class="player-timeline">
|
|
164
|
+
<div class="player-timeline__track">
|
|
165
|
+
<div class="player-timeline__track-fake">
|
|
166
|
+
${chapters.map(chapter => {
|
|
167
|
+
const limitClasses = {
|
|
168
|
+
'player-timeline__chapter-limit': true,
|
|
169
|
+
'player-timeline__chapter-limit--played':
|
|
170
|
+
(timePosition?.number || currentTime) > chapter.start / 1000
|
|
171
|
+
};
|
|
172
|
+
const position = (100 / totalTime) * (chapter.start / 1000);
|
|
173
|
+
return html`
|
|
174
|
+
<div
|
|
175
|
+
class="${classMap(limitClasses)}"
|
|
176
|
+
style="--timeline--chapter-limit-position: ${position}%;"
|
|
177
|
+
></div>
|
|
178
|
+
`;
|
|
179
|
+
})}
|
|
180
|
+
<div
|
|
181
|
+
class="player-timeline__completed"
|
|
182
|
+
style="width:${isDragging ? progressVisible : progress}%;"
|
|
183
|
+
>
|
|
184
|
+
<div class="player-timeline__thumb"></div>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
<div
|
|
188
|
+
class="player-timeline__track-real"
|
|
189
|
+
@click="${handleTimeline}"
|
|
190
|
+
@keydown="${handleTimeline}"
|
|
191
|
+
@mousemove="${handleThumbMouseMove}"
|
|
192
|
+
@touchmove="${ifDefined(
|
|
193
|
+
isTouch() ? handleThumbTouchMove : undefined
|
|
194
|
+
)}"
|
|
195
|
+
@mouseout="${handleTimelineOut}"
|
|
196
|
+
@mousedown="${handleThumbMouseDown}"
|
|
197
|
+
@touchstart="${ifDefined(
|
|
198
|
+
isTouch() ? handleThumbMouseDown : undefined
|
|
199
|
+
)}"
|
|
200
|
+
@mouseup="${handleThumbMouseUp}"
|
|
201
|
+
@touchend="${ifDefined(isTouch() ? handleThumbTouchEnd : undefined)}"
|
|
202
|
+
aria-valuemin="0"
|
|
203
|
+
aria-valuemax="100"
|
|
204
|
+
aria-valuenow="${progress}"
|
|
205
|
+
aria-valuetext="${a11yTime({ time: currentTime, literals })}"
|
|
206
|
+
role="slider"
|
|
207
|
+
tabindex="0"
|
|
208
|
+
></div>
|
|
209
|
+
</div>
|
|
210
|
+
<div class="player-timeline__numbers">
|
|
211
|
+
<div>${formatTime(currentTime)}</div>
|
|
212
|
+
<div>${formatTime(totalTime)}</div>
|
|
213
|
+
</div>
|
|
214
|
+
${timePosition === null
|
|
215
|
+
? nothing
|
|
216
|
+
: html`
|
|
217
|
+
<div
|
|
218
|
+
class="player-timeline__tooltip"
|
|
219
|
+
style="--timeline-tooltip-position: ${timePosition.left}px;"
|
|
220
|
+
>
|
|
221
|
+
<div class="player-timeline__tooltip-inner">
|
|
222
|
+
${timePosition.chapter
|
|
223
|
+
? html`
|
|
224
|
+
<span class="player-timeline__tooltip-chapter-title">
|
|
225
|
+
${timePosition.chapter}
|
|
226
|
+
</span>
|
|
227
|
+
`
|
|
228
|
+
: nothing}
|
|
229
|
+
<span class="player-timeline__tooltip-time">
|
|
230
|
+
${timePosition.visual}
|
|
231
|
+
</span>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
`}
|
|
235
|
+
</div>
|
|
236
|
+
`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!customElements.get('outbook-player-timeline')) {
|
|
240
|
+
customElements.define(
|
|
241
|
+
'outbook-player-timeline',
|
|
242
|
+
component(ComponentPlayerTimeline, {
|
|
243
|
+
observedAttributes: ['lang', 'duration'],
|
|
244
|
+
useShadowDOM: true
|
|
245
|
+
})
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function PlayerTimeline(props) {
|
|
250
|
+
const { duration, lang = 'en', extraClasses } = props;
|
|
251
|
+
return html`
|
|
252
|
+
<outbook-player-timeline
|
|
253
|
+
duration=${duration}
|
|
254
|
+
lang="${lang}"
|
|
255
|
+
class="${extraClasses}"
|
|
256
|
+
.props="${props}"
|
|
257
|
+
></outbook-player-timeline>
|
|
258
|
+
`;
|
|
259
|
+
}
|