@meuuhdia/video-player 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 +661 -0
- package/README.md +126 -0
- package/icons.js +14 -0
- package/locale/fr.js +47 -0
- package/meuuhdia-css.js +1 -0
- package/meuuhdia.js +34 -0
- package/modules/caption.js +429 -0
- package/modules/controls.js +328 -0
- package/modules/disclosure.js +99 -0
- package/modules/icon.js +32 -0
- package/modules/player.js +95 -0
- package/modules/time.js +64 -0
- package/modules/transcription.js +142 -0
- package/package.json +41 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { MeuuhdiaTime } from "./time.js";
|
|
2
|
+
import { MeuuhdiaIcon } from "./icon.js";
|
|
3
|
+
|
|
4
|
+
class MeuuhdiaTranscription {
|
|
5
|
+
static addTranscription(locale, meuuhdia_wrapper, descriptions, video) {
|
|
6
|
+
let wrapper = document.createElement("div");
|
|
7
|
+
wrapper.classList.add("meuuhdia_transcription");
|
|
8
|
+
wrapper.style.maxWidth = video.videoWidth + "px";
|
|
9
|
+
|
|
10
|
+
let heading = document.createElement("div");
|
|
11
|
+
heading.classList.add("meuuhdia_transcription_heading");
|
|
12
|
+
|
|
13
|
+
let selectorContainer = document.createElement("div");
|
|
14
|
+
selectorContainer.classList.add("meuuhdia_transcription_heading_lang");
|
|
15
|
+
|
|
16
|
+
let label = document.createElement("label");
|
|
17
|
+
label.setAttribute("for", "transcription_lang");
|
|
18
|
+
label.textContent = locale.cc.transcriptionLabel;
|
|
19
|
+
|
|
20
|
+
let selector = document.createElement("select");
|
|
21
|
+
selector.setAttribute("id", "transcription_lang");
|
|
22
|
+
selector.setAttribute("name", "transcription_lang");
|
|
23
|
+
selector.addEventListener("change", (evt) => MeuuhdiaTranscription.switchTranscription(locale, evt, video));
|
|
24
|
+
|
|
25
|
+
let transcriptionOff = document.createElement("option");
|
|
26
|
+
transcriptionOff.setAttribute("value", "off");
|
|
27
|
+
transcriptionOff.textContent = locale.words.disable;
|
|
28
|
+
selector.appendChild(transcriptionOff);
|
|
29
|
+
|
|
30
|
+
descriptions.forEach(desc => {
|
|
31
|
+
let opt = document.createElement("option");
|
|
32
|
+
opt.setAttribute("value", desc.language);
|
|
33
|
+
opt.setAttribute("lang", desc.language);
|
|
34
|
+
opt.textContent = desc.label;
|
|
35
|
+
selector.appendChild(opt);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
selectorContainer.appendChild(label);
|
|
39
|
+
selectorContainer.appendChild(selector);
|
|
40
|
+
|
|
41
|
+
let transcriptionSide = document.createElement("ul");
|
|
42
|
+
transcriptionSide.classList.add("meuuhdia_transcription_heading_side");
|
|
43
|
+
transcriptionSide.classList.add("list-unstyled");
|
|
44
|
+
|
|
45
|
+
let sides = [
|
|
46
|
+
{
|
|
47
|
+
"label": locale.cc.transcriptionBottom,
|
|
48
|
+
"side": "bottom",
|
|
49
|
+
"icon": MeuuhdiaIcon.createIcon("transcript_bottom")
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"label": locale.cc.transcriptionRight,
|
|
53
|
+
"side": "right",
|
|
54
|
+
"icon": MeuuhdiaIcon.createIcon("transcript_right")
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
sides.forEach(side => {
|
|
59
|
+
let item = document.createElement("li");
|
|
60
|
+
let isPressed = "bottom" == side.side ? "true" : "false";
|
|
61
|
+
|
|
62
|
+
let btn = document.createElement("button");
|
|
63
|
+
btn.dataset.side = side.side;
|
|
64
|
+
btn.setAttribute("type", "button");
|
|
65
|
+
btn.setAttribute("aria-pressed", isPressed);
|
|
66
|
+
btn.setAttribute("title", side.label);
|
|
67
|
+
btn.addEventListener("click", MeuuhdiaTranscription.moveTranscription);
|
|
68
|
+
|
|
69
|
+
let label = document.createElement("span");
|
|
70
|
+
label.textContent = side.label;
|
|
71
|
+
label.classList.add("sr-only");
|
|
72
|
+
|
|
73
|
+
btn.appendChild(label);
|
|
74
|
+
btn.appendChild(side.icon);
|
|
75
|
+
item.appendChild(btn);
|
|
76
|
+
|
|
77
|
+
transcriptionSide.appendChild(item);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
heading.appendChild(selectorContainer);
|
|
81
|
+
heading.appendChild(transcriptionSide);
|
|
82
|
+
wrapper.appendChild(heading);
|
|
83
|
+
meuuhdia_wrapper.insertAdjacentElement("afterend", wrapper);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static switchTranscription(locale, evt, video) {
|
|
87
|
+
let desc = evt.currentTarget;
|
|
88
|
+
let container = desc.closest(".meuuhdia_transcription");
|
|
89
|
+
|
|
90
|
+
let previous_transcription = container.querySelector(".meuuhdia_transcription_container");
|
|
91
|
+
if(previous_transcription) previous_transcription.remove();
|
|
92
|
+
|
|
93
|
+
let track = desc.closest(".meuuhdia").querySelector("track[kind='descriptions'][srclang='"+desc.value+"']");
|
|
94
|
+
|
|
95
|
+
if(track) {
|
|
96
|
+
fetch(track.getAttribute("src"))
|
|
97
|
+
.then(response => response.text())
|
|
98
|
+
.then(text => {
|
|
99
|
+
let transcription_lines = JSON.parse(text);
|
|
100
|
+
let lines_container = document.createElement("ol");
|
|
101
|
+
lines_container.classList.add("meuuhdia_transcription_container");
|
|
102
|
+
lines_container.classList.add("list-unstyled");
|
|
103
|
+
lines_container.setAttribute("lang", desc.value);
|
|
104
|
+
|
|
105
|
+
for(let line in transcription_lines) {
|
|
106
|
+
let paragraph = document.createElement("li");
|
|
107
|
+
|
|
108
|
+
let infos_data = line.split(" ");
|
|
109
|
+
let infos = document.createElement("button");
|
|
110
|
+
infos.dataset.time = MeuuhdiaTime.convertTextToSeconds(infos_data[0]);
|
|
111
|
+
infos.classList.add("meuuhdia_transcription_info");
|
|
112
|
+
infos.addEventListener("click", (evt) => video.currentTime = evt.currentTarget.dataset.time);
|
|
113
|
+
MeuuhdiaTime.populateTimeNode(locale, infos, null, infos_data[0]);
|
|
114
|
+
let infos_voice = document.createElement("span");
|
|
115
|
+
infos_voice.textContent = (2 === infos_data.length) ? (" " + infos_data[1] + ":") : ":";
|
|
116
|
+
infos.appendChild(infos_voice);
|
|
117
|
+
paragraph.appendChild(infos);
|
|
118
|
+
|
|
119
|
+
let text = document.createElement("span");
|
|
120
|
+
text.textContent = transcription_lines[line];
|
|
121
|
+
paragraph.appendChild(text);
|
|
122
|
+
|
|
123
|
+
lines_container.appendChild(paragraph);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
container.appendChild(lines_container);
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static moveTranscription(evt) {
|
|
132
|
+
let currentPosition = evt.currentTarget.closest(".meuuhdia_transcription_heading_side").querySelector("button[aria-pressed='true']");
|
|
133
|
+
let container = evt.currentTarget.closest(".meuuhdia");
|
|
134
|
+
let targetPosition = evt.currentTarget == currentPosition ? evt.currentTarget.closest(".meuuhdia_transcription_heading_side").querySelector("button[aria-pressed='false']") : evt.currentTarget;
|
|
135
|
+
|
|
136
|
+
container.classList.toggle("meuuhdia--row");
|
|
137
|
+
currentPosition.setAttribute("aria-pressed", "false");
|
|
138
|
+
targetPosition.setAttribute("aria-pressed", "true");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { MeuuhdiaTranscription };
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meuuhdia/video-player",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "inclusive video player",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "meuuhdia.js",
|
|
7
|
+
"author": "Séverine Féret",
|
|
8
|
+
"license": "AGPL-3.0-or-later",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./meuuhdia.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"meuuhdia-css.js",
|
|
14
|
+
"meuuhdia.js",
|
|
15
|
+
"locale",
|
|
16
|
+
"modules",
|
|
17
|
+
"icons.js"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "node buildMeuuhdiaStyles",
|
|
21
|
+
"prepack": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Meuuhdia/video-player.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"video",
|
|
29
|
+
"player",
|
|
30
|
+
"media",
|
|
31
|
+
"accessibility",
|
|
32
|
+
"a11y"
|
|
33
|
+
],
|
|
34
|
+
"homepage": "https://github.com/Meuuhdia/video-player#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Meuuhdia/video-player/issues"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"sass": "^1.80.7"
|
|
40
|
+
}
|
|
41
|
+
}
|