@mattebox/player 0.6.0 → 0.7.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/dist/cdn/mattebox-player.min.js +3 -435
- package/dist/controls/airplay.js +28 -44
- package/dist/controls/airplay.js.map +1 -1
- package/dist/controls/chapters.d.ts +22 -11
- package/dist/controls/chapters.d.ts.map +1 -1
- package/dist/controls/chapters.js +87 -73
- package/dist/controls/chapters.js.map +1 -1
- package/dist/controls/cues.d.ts +0 -22
- package/dist/controls/cues.d.ts.map +1 -1
- package/dist/controls/cues.js +161 -191
- package/dist/controls/cues.js.map +1 -1
- package/dist/controls/fullscreen.js +52 -70
- package/dist/controls/fullscreen.js.map +1 -1
- package/dist/controls/icons.d.ts +1 -1
- package/dist/controls/icons.d.ts.map +1 -1
- package/dist/controls/icons.js +46 -70
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/menu.d.ts +7 -4
- package/dist/controls/menu.d.ts.map +1 -1
- package/dist/controls/menu.js +241 -223
- package/dist/controls/menu.js.map +1 -1
- package/dist/controls/pip.js +35 -49
- package/dist/controls/pip.js.map +1 -1
- package/dist/controls/ranges.js +42 -37
- package/dist/controls/ranges.js.map +1 -1
- package/dist/controls/session.d.ts +6 -1
- package/dist/controls/session.d.ts.map +1 -1
- package/dist/controls/session.js +41 -26
- package/dist/controls/session.js.map +1 -1
- package/dist/controls/slider.d.ts +2 -2
- package/dist/controls/slider.d.ts.map +1 -1
- package/dist/controls/slider.js +151 -159
- package/dist/controls/slider.js.map +1 -1
- package/dist/controls/time.js +17 -17
- package/dist/controls/time.js.map +1 -1
- package/dist/dom.d.ts +6 -0
- package/dist/dom.d.ts.map +1 -1
- package/dist/dom.js +28 -19
- package/dist/dom.js.map +1 -1
- package/dist/element-entry.js +9 -6
- package/dist/element-entry.js.map +1 -1
- package/dist/element.d.ts +4 -2
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +384 -443
- package/dist/element.js.map +1 -1
- package/dist/elements/airplay-button.js +51 -53
- package/dist/elements/airplay-button.js.map +1 -1
- package/dist/elements/audio-menu.js +62 -63
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/chapters-menu.d.ts.map +1 -1
- package/dist/elements/chapters-menu.js +75 -65
- package/dist/elements/chapters-menu.js.map +1 -1
- package/dist/elements/component.d.ts +1 -1
- package/dist/elements/component.d.ts.map +1 -1
- package/dist/elements/component.js +86 -89
- package/dist/elements/component.js.map +1 -1
- package/dist/elements/control-bar.d.ts +18 -5
- package/dist/elements/control-bar.d.ts.map +1 -1
- package/dist/elements/control-bar.js +282 -319
- package/dist/elements/control-bar.js.map +1 -1
- package/dist/elements/current-time.js +26 -25
- package/dist/elements/current-time.js.map +1 -1
- package/dist/elements/drm-badge.d.ts.map +1 -1
- package/dist/elements/drm-badge.js +107 -141
- package/dist/elements/drm-badge.js.map +1 -1
- package/dist/elements/duration.d.ts.map +1 -1
- package/dist/elements/duration.js +24 -21
- package/dist/elements/duration.js.map +1 -1
- package/dist/elements/error-screen.d.ts.map +1 -1
- package/dist/elements/error-screen.js +68 -102
- package/dist/elements/error-screen.js.map +1 -1
- package/dist/elements/fullscreen-button.js +48 -54
- package/dist/elements/fullscreen-button.js.map +1 -1
- package/dist/elements/live-button.d.ts.map +1 -1
- package/dist/elements/live-button.js +67 -94
- package/dist/elements/live-button.js.map +1 -1
- package/dist/elements/menu-element.js +31 -28
- package/dist/elements/menu-element.js.map +1 -1
- package/dist/elements/mute-button.js +58 -59
- package/dist/elements/mute-button.js.map +1 -1
- package/dist/elements/pip-button.js +54 -54
- package/dist/elements/pip-button.js.map +1 -1
- package/dist/elements/play-button.d.ts.map +1 -1
- package/dist/elements/play-button.js +73 -58
- package/dist/elements/play-button.js.map +1 -1
- package/dist/elements/quality-menu.js +66 -69
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/remaining-time.d.ts.map +1 -1
- package/dist/elements/remaining-time.js +27 -24
- package/dist/elements/remaining-time.js.map +1 -1
- package/dist/elements/scan-button.d.ts +17 -0
- package/dist/elements/scan-button.d.ts.map +1 -0
- package/dist/elements/scan-button.js +117 -0
- package/dist/elements/scan-button.js.map +1 -0
- package/dist/elements/seek-bar.d.ts +93 -14
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +475 -335
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.d.ts +3 -11
- package/dist/elements/shared.d.ts.map +1 -1
- package/dist/elements/shared.js +44 -144
- package/dist/elements/shared.js.map +1 -1
- package/dist/elements/skip-button.d.ts.map +1 -1
- package/dist/elements/skip-button.js +54 -55
- package/dist/elements/skip-button.js.map +1 -1
- package/dist/elements/spacer.d.ts.map +1 -1
- package/dist/elements/spacer.js +12 -7
- package/dist/elements/spacer.js.map +1 -1
- package/dist/elements/speed-menu.js +60 -55
- package/dist/elements/speed-menu.js.map +1 -1
- package/dist/elements/spinner.d.ts.map +1 -1
- package/dist/elements/spinner.js +52 -78
- package/dist/elements/spinner.js.map +1 -1
- package/dist/elements/start-button.d.ts.map +1 -1
- package/dist/elements/start-button.js +107 -120
- package/dist/elements/start-button.js.map +1 -1
- package/dist/elements/subtitles-menu.js +95 -103
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/elements/time-element.d.ts.map +1 -1
- package/dist/elements/time-element.js +36 -28
- package/dist/elements/time-element.js.map +1 -1
- package/dist/elements/title.d.ts.map +1 -1
- package/dist/elements/title.js +105 -137
- package/dist/elements/title.js.map +1 -1
- package/dist/elements/volume-slider.d.ts.map +1 -1
- package/dist/elements/volume-slider.js +47 -45
- package/dist/elements/volume-slider.js.map +1 -1
- package/dist/elements/volume.d.ts.map +1 -1
- package/dist/elements/volume.js +42 -50
- package/dist/elements/volume.js.map +1 -1
- package/dist/entries/airplay-button.js +7 -7
- package/dist/entries/airplay-button.js.map +1 -1
- package/dist/entries/audio-menu.js +7 -6
- package/dist/entries/audio-menu.js.map +1 -1
- package/dist/entries/chapters-menu.js +7 -7
- package/dist/entries/chapters-menu.js.map +1 -1
- package/dist/entries/control-bar.js +7 -6
- package/dist/entries/control-bar.js.map +1 -1
- package/dist/entries/current-time.js +7 -6
- package/dist/entries/current-time.js.map +1 -1
- package/dist/entries/drm-badge.js +7 -6
- package/dist/entries/drm-badge.js.map +1 -1
- package/dist/entries/duration.js +7 -6
- package/dist/entries/duration.js.map +1 -1
- package/dist/entries/error-screen.js +7 -6
- package/dist/entries/error-screen.js.map +1 -1
- package/dist/entries/fullscreen-button.js +7 -6
- package/dist/entries/fullscreen-button.js.map +1 -1
- package/dist/entries/live-button.js +7 -6
- package/dist/entries/live-button.js.map +1 -1
- package/dist/entries/mute-button.js +7 -6
- package/dist/entries/mute-button.js.map +1 -1
- package/dist/entries/pip-button.js +7 -6
- package/dist/entries/pip-button.js.map +1 -1
- package/dist/entries/play-button.js +7 -6
- package/dist/entries/play-button.js.map +1 -1
- package/dist/entries/quality-menu.js +7 -6
- package/dist/entries/quality-menu.js.map +1 -1
- package/dist/entries/remaining-time.js +7 -7
- package/dist/entries/remaining-time.js.map +1 -1
- package/dist/entries/scan-button.d.ts +5 -0
- package/dist/entries/scan-button.d.ts.map +1 -0
- package/dist/entries/scan-button.js +9 -0
- package/dist/entries/scan-button.js.map +1 -0
- package/dist/entries/seek-bar.js +7 -6
- package/dist/entries/seek-bar.js.map +1 -1
- package/dist/entries/skip-button.js +7 -6
- package/dist/entries/skip-button.js.map +1 -1
- package/dist/entries/spacer.js +7 -6
- package/dist/entries/spacer.js.map +1 -1
- package/dist/entries/speed-menu.js +7 -6
- package/dist/entries/speed-menu.js.map +1 -1
- package/dist/entries/spinner.js +7 -7
- package/dist/entries/spinner.js.map +1 -1
- package/dist/entries/start-button.js +7 -6
- package/dist/entries/start-button.js.map +1 -1
- package/dist/entries/subtitles-menu.js +7 -6
- package/dist/entries/subtitles-menu.js.map +1 -1
- package/dist/entries/title.js +7 -7
- package/dist/entries/title.js.map +1 -1
- package/dist/entries/volume-slider.js +7 -6
- package/dist/entries/volume-slider.js.map +1 -1
- package/dist/entries/volume.js +9 -8
- package/dist/entries/volume.js.map +1 -1
- package/dist/es2015/controls/chapters.js +40 -7
- package/dist/es2015/controls/cues.js +1 -8
- package/dist/es2015/controls/icons.js +3 -1
- package/dist/es2015/controls/menu.js +27 -8
- package/dist/es2015/controls/session.js +16 -4
- package/dist/es2015/controls/slider.js +5 -4
- package/dist/es2015/dom.js +10 -1
- package/dist/es2015/element.js +23 -7
- package/dist/es2015/elements/chapters-menu.js +18 -10
- package/dist/es2015/elements/control-bar.js +41 -35
- package/dist/es2015/elements/drm-badge.js +1 -25
- package/dist/es2015/elements/duration.js +2 -1
- package/dist/es2015/elements/error-screen.js +1 -30
- package/dist/es2015/elements/live-button.js +1 -29
- package/dist/es2015/elements/menu-element.js +2 -2
- package/dist/es2015/elements/play-button.js +10 -3
- package/dist/es2015/elements/remaining-time.js +2 -1
- package/dist/es2015/elements/scan-button.js +118 -0
- package/dist/es2015/elements/seek-bar.js +264 -71
- package/dist/es2015/elements/shared.js +5 -106
- package/dist/es2015/elements/skip-button.js +2 -1
- package/dist/es2015/elements/spacer.js +2 -1
- package/dist/es2015/elements/spinner.js +1 -32
- package/dist/es2015/elements/start-button.js +8 -26
- package/dist/es2015/elements/time-element.js +1 -4
- package/dist/es2015/elements/title.js +1 -45
- package/dist/es2015/elements/volume-slider.js +2 -1
- package/dist/es2015/elements/volume.js +1 -11
- package/dist/es2015/entries/scan-button.js +7 -0
- package/dist/es2015/index.js +3 -1
- package/dist/es2015/style.js +1 -101
- package/dist/es2015/tags.js +2 -1
- package/dist/host.js +19 -17
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -27
- package/dist/labels.js +13 -9
- package/dist/labels.js.map +1 -1
- package/dist/namespaces.d.ts +9 -26
- package/dist/namespaces.d.ts.map +1 -1
- package/dist/namespaces.js +6 -2
- package/dist/namespaces.js.map +1 -1
- package/dist/presets.js +33 -28
- package/dist/presets.js.map +1 -1
- package/dist/style.d.ts +1 -20
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +4 -100
- package/dist/style.js.map +1 -1
- package/dist/surface.js +25 -21
- package/dist/surface.js.map +1 -1
- package/dist/tags.d.ts +1 -0
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js +31 -26
- package/dist/tags.js.map +1 -1
- package/package.json +4 -4
- package/dist/index.js.map +0 -1
package/dist/controls/cues.js
CHANGED
|
@@ -1,204 +1,174 @@
|
|
|
1
|
+
//#region src/controls/cues.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
* Subtitles and the bar. Two things.
|
|
4
|
+
*
|
|
5
|
+
* The lift: the browser draws native cues at the bottom of the video, under
|
|
6
|
+
* the bar. While the bar shows, every active cue the author left
|
|
7
|
+
* unpositioned is moved above it, and put back when the bar hides. The
|
|
8
|
+
* position is a negative line count, the one form every browser wraps at
|
|
9
|
+
* the video's width; a percentage does not wrap in Chromium. Chromium
|
|
10
|
+
* anchors the box's top on the count and Gecko its bottom, and their
|
|
11
|
+
* overlap avoidance pushes in opposite directions, so nothing is left to
|
|
12
|
+
* them: subtitles often show two cues at once, and the cues stack by their
|
|
13
|
+
* own measured heights, wrapping included, clear under both readings. A
|
|
14
|
+
* cue with a position of its own is the author's and is not touched.
|
|
15
|
+
*
|
|
16
|
+
* The look: `::cue` can only be styled from the document that holds the
|
|
17
|
+
* video, which is the page and not the shadow root, and it takes no custom
|
|
18
|
+
* properties. So a small sheet goes into the document, once, with one rule
|
|
19
|
+
* per look the host's `subtitle-size` and `subtitle-background` attributes
|
|
20
|
+
* can take. Sizes are percentages of the browser's own cue size, which
|
|
21
|
+
* already follows the video's height, in the page and in fullscreen alike.
|
|
22
|
+
* A page that wants more writes its own `mattebox-player > video::cue`.
|
|
23
|
+
*/
|
|
24
|
+
const CUE_RULES = "mattebox-player[subtitle-size=small]>video::cue{font-size:75%}mattebox-player[subtitle-size=large]>video::cue{font-size:150%}mattebox-player[subtitle-size=xlarge]>video::cue{font-size:200%}mattebox-player[subtitle-background=none]>video::cue{background-color:#0000}mattebox-player[subtitle-background=solid]>video::cue{background-color:#000}mattebox-player[subtitle-background=none]>video::-webkit-media-text-track-display-backdrop{background-color:#0000}mattebox-player[subtitle-background=solid]>video::-webkit-media-text-track-display-backdrop{background-color:#000}";
|
|
23
25
|
/** How the sizes scale the browser's own cue size; the lift counts lines by it. */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const SCALES = {
|
|
27
|
+
small: .75,
|
|
28
|
+
medium: 1,
|
|
29
|
+
large: 1.5,
|
|
30
|
+
xlarge: 2
|
|
29
31
|
};
|
|
30
|
-
const BACKDROP = 'video::-webkit-media-text-track-display-backdrop';
|
|
31
32
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
mattebox-player[subtitle-size="large"] > video::cue { font-size: 150%; }
|
|
39
|
-
mattebox-player[subtitle-size="xlarge"] > video::cue { font-size: 200%; }
|
|
40
|
-
mattebox-player[subtitle-background="none"] > video::cue { background-color: transparent; }
|
|
41
|
-
mattebox-player[subtitle-background="solid"] > video::cue { background-color: #000; }
|
|
42
|
-
mattebox-player[subtitle-background="none"] > ${BACKDROP} { background-color: transparent; }
|
|
43
|
-
mattebox-player[subtitle-background="solid"] > ${BACKDROP} { background-color: #000; }`;
|
|
44
|
-
const MARK = 'data-mattebox-cue';
|
|
33
|
+
* The sheet in the document. `mattebox-player` is the element's tag. The
|
|
34
|
+
* background goes on `::cue` and on the backdrop pseudo-element Chromium
|
|
35
|
+
* and WebKit have, both: which of the two paints it differs by browser and
|
|
36
|
+
* version, and a selector a browser does not know only voids its own rule.
|
|
37
|
+
*/
|
|
38
|
+
const MARK = "data-mattebox-cue";
|
|
45
39
|
/** The browser's cue size against the video's height, per WebVTT, and its line against the size. */
|
|
46
|
-
const CUE_SIZE =
|
|
40
|
+
const CUE_SIZE = .05;
|
|
47
41
|
const LINE_HEIGHT = 1.2;
|
|
48
42
|
/** What a cue box spans of the video's width by default, so wrapping is measured against it. */
|
|
49
|
-
const CUE_WIDTH =
|
|
43
|
+
const CUE_WIDTH = .96;
|
|
50
44
|
/** Pixels of air between the bar and the cue above it, before rounding up to a line. */
|
|
51
45
|
const AIR = 6;
|
|
52
46
|
/** Puts the cue rules in the document, once. */
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
document.head.append(style);
|
|
47
|
+
function cueStyle() {
|
|
48
|
+
if (document.head.querySelector(`style[${MARK}]`) !== null) return;
|
|
49
|
+
const style = document.createElement("style");
|
|
50
|
+
style.setAttribute(MARK, "");
|
|
51
|
+
style.textContent = CUE_RULES;
|
|
52
|
+
document.head.append(style);
|
|
60
53
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function watch() {
|
|
180
|
-
for (const track of video.textTracks) {
|
|
181
|
-
track.removeEventListener('cuechange', apply);
|
|
182
|
-
track.addEventListener('cuechange', apply);
|
|
183
|
-
}
|
|
184
|
-
apply();
|
|
185
|
-
}
|
|
186
|
-
video.textTracks.addEventListener('change', watch);
|
|
187
|
-
video.textTracks.addEventListener('addtrack', watch);
|
|
188
|
-
watch();
|
|
189
|
-
return {
|
|
190
|
-
lifted(next) {
|
|
191
|
-
on = next;
|
|
192
|
-
apply();
|
|
193
|
-
},
|
|
194
|
-
dispose() {
|
|
195
|
-
on = false;
|
|
196
|
-
apply();
|
|
197
|
-
video.textTracks.removeEventListener('change', watch);
|
|
198
|
-
video.textTracks.removeEventListener('addtrack', watch);
|
|
199
|
-
for (const track of video.textTracks)
|
|
200
|
-
track.removeEventListener('cuechange', apply);
|
|
201
|
-
},
|
|
202
|
-
};
|
|
54
|
+
function cueLift(video, host, covered) {
|
|
55
|
+
/** The cues moved, with what they were, so they and only they are put back. */
|
|
56
|
+
const lifted = /* @__PURE__ */ new Map();
|
|
57
|
+
let on = false;
|
|
58
|
+
let canvas;
|
|
59
|
+
function showing() {
|
|
60
|
+
const out = [];
|
|
61
|
+
for (const track of video.textTracks) if (track.mode === "showing") out.push(track);
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/** The browser's cue font size, in pixels, from the video's height and the host's scale. */
|
|
65
|
+
function fontSize(height) {
|
|
66
|
+
const scale = SCALES[host.getAttribute("subtitle-size") ?? ""] ?? 1;
|
|
67
|
+
return height * CUE_SIZE * scale;
|
|
68
|
+
}
|
|
69
|
+
/** Measures text the way the browser draws cues, to count the lines a cue wraps into. */
|
|
70
|
+
function measure() {
|
|
71
|
+
if (canvas === void 0) canvas = document.createElement("canvas").getContext("2d");
|
|
72
|
+
return canvas;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A cue's text without its tags, for measuring: `<b>`, `<c.name>`, the
|
|
76
|
+
* timestamps and their closers. Brackets are counted, so a tag inside
|
|
77
|
+
* another's brackets goes with it.
|
|
78
|
+
*/
|
|
79
|
+
function plain(text) {
|
|
80
|
+
let out = "";
|
|
81
|
+
let depth = 0;
|
|
82
|
+
for (const char of text) if (char === "<") depth += 1;
|
|
83
|
+
else if (char === ">") depth = Math.max(0, depth - 1);
|
|
84
|
+
else if (depth === 0) out += char;
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/** The lines a cue takes: its own, each wrapped at the cue box's width. */
|
|
88
|
+
function lines(cue, font, width) {
|
|
89
|
+
const context = measure();
|
|
90
|
+
let total = 0;
|
|
91
|
+
for (const line of plain(cue.text).split("\n")) {
|
|
92
|
+
if (context === null) {
|
|
93
|
+
total += 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
context.font = `${font}px sans-serif`;
|
|
97
|
+
total += Math.max(1, Math.ceil(context.measureText(line).width / (width * CUE_WIDTH)));
|
|
98
|
+
}
|
|
99
|
+
return total;
|
|
100
|
+
}
|
|
101
|
+
function apply() {
|
|
102
|
+
const box = video.getBoundingClientRect();
|
|
103
|
+
const height = box.height;
|
|
104
|
+
const span = covered();
|
|
105
|
+
const pixels = span.bottom - span.top;
|
|
106
|
+
const lift = on && height > 0 && pixels > 0 && pixels < height;
|
|
107
|
+
const font = fontSize(height);
|
|
108
|
+
const unit = font * LINE_HEIGHT;
|
|
109
|
+
const base = Math.ceil((pixels + AIR) / unit);
|
|
110
|
+
for (const track of showing()) {
|
|
111
|
+
const active = [...track.activeCues ?? []].filter((cue) => cue instanceof VTTCue).sort((a, b) => a.startTime - b.startTime);
|
|
112
|
+
let previous = null;
|
|
113
|
+
let changed = false;
|
|
114
|
+
for (const cue of active) {
|
|
115
|
+
const was = lifted.get(cue);
|
|
116
|
+
if (!lift) {
|
|
117
|
+
if (was === void 0) continue;
|
|
118
|
+
cue.line = was.line;
|
|
119
|
+
cue.snapToLines = was.snapToLines;
|
|
120
|
+
cue.lineAlign = was.lineAlign;
|
|
121
|
+
lifted.delete(cue);
|
|
122
|
+
changed = true;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (was === void 0 && cue.line !== "auto") continue;
|
|
126
|
+
if (was === void 0) lifted.set(cue, {
|
|
127
|
+
line: cue.line,
|
|
128
|
+
snapToLines: cue.snapToLines,
|
|
129
|
+
lineAlign: cue.lineAlign
|
|
130
|
+
});
|
|
131
|
+
const own = lines(cue, font, box.width);
|
|
132
|
+
const line = previous === null ? base + own : previous.line + Math.max(own, previous.height);
|
|
133
|
+
if (cue.line !== -line || !cue.snapToLines) changed = true;
|
|
134
|
+
cue.snapToLines = true;
|
|
135
|
+
cue.line = -line;
|
|
136
|
+
previous = {
|
|
137
|
+
line,
|
|
138
|
+
height: own
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (changed) {
|
|
142
|
+
track.mode = "hidden";
|
|
143
|
+
track.mode = "showing";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function watch() {
|
|
148
|
+
for (const track of video.textTracks) {
|
|
149
|
+
track.removeEventListener("cuechange", apply);
|
|
150
|
+
track.addEventListener("cuechange", apply);
|
|
151
|
+
}
|
|
152
|
+
apply();
|
|
153
|
+
}
|
|
154
|
+
video.textTracks.addEventListener("change", watch);
|
|
155
|
+
video.textTracks.addEventListener("addtrack", watch);
|
|
156
|
+
watch();
|
|
157
|
+
return {
|
|
158
|
+
lifted(next) {
|
|
159
|
+
on = next;
|
|
160
|
+
apply();
|
|
161
|
+
},
|
|
162
|
+
dispose() {
|
|
163
|
+
on = false;
|
|
164
|
+
apply();
|
|
165
|
+
video.textTracks.removeEventListener("change", watch);
|
|
166
|
+
video.textTracks.removeEventListener("addtrack", watch);
|
|
167
|
+
for (const track of video.textTracks) track.removeEventListener("cuechange", apply);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
203
170
|
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { SCALES, cueLift, cueStyle };
|
|
173
|
+
|
|
204
174
|
//# sourceMappingURL=cues.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cues.js","sourceRoot":"","sources":["../../src/controls/cues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,mFAAmF;AACnF,MAAM,CAAC,MAAM,MAA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AM,KAAK,IAAI,KAAK,CAAC,UAAU;gBAAE,KAAK,CAAC,mBAAmB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"cues.js","names":[],"sources":["../../src/controls/cues.ts"],"sourcesContent":["/**\n * Subtitles and the bar. Two things.\n *\n * The lift: the browser draws native cues at the bottom of the video, under\n * the bar. While the bar shows, every active cue the author left\n * unpositioned is moved above it, and put back when the bar hides. The\n * position is a negative line count, the one form every browser wraps at\n * the video's width; a percentage does not wrap in Chromium. Chromium\n * anchors the box's top on the count and Gecko its bottom, and their\n * overlap avoidance pushes in opposite directions, so nothing is left to\n * them: subtitles often show two cues at once, and the cues stack by their\n * own measured heights, wrapping included, clear under both readings. A\n * cue with a position of its own is the author's and is not touched.\n *\n * The look: `::cue` can only be styled from the document that holds the\n * video, which is the page and not the shadow root, and it takes no custom\n * properties. So a small sheet goes into the document, once, with one rule\n * per look the host's `subtitle-size` and `subtitle-background` attributes\n * can take. Sizes are percentages of the browser's own cue size, which\n * already follows the video's height, in the page and in fullscreen alike.\n * A page that wants more writes its own `mattebox-player > video::cue`.\n */\nimport CUE_RULES from './cues.css?inline';\n/** How the sizes scale the browser's own cue size; the lift counts lines by it. */\nexport const SCALES: Readonly<Record<string, number>> = {\n small: 0.75,\n medium: 1,\n large: 1.5,\n xlarge: 2,\n};\n\n/**\n * The sheet in the document. `mattebox-player` is the element's tag. The\n * background goes on `::cue` and on the backdrop pseudo-element Chromium\n * and WebKit have, both: which of the two paints it differs by browser and\n * version, and a selector a browser does not know only voids its own rule.\n */\n\nconst MARK = 'data-mattebox-cue';\n\n/** The browser's cue size against the video's height, per WebVTT, and its line against the size. */\nconst CUE_SIZE = 0.05;\nconst LINE_HEIGHT = 1.2;\n/** What a cue box spans of the video's width by default, so wrapping is measured against it. */\nconst CUE_WIDTH = 0.96;\n/** Pixels of air between the bar and the cue above it, before rounding up to a line. */\nconst AIR = 6;\n\n/** Puts the cue rules in the document, once. */\nexport function cueStyle(): void {\n if (document.head.querySelector(`style[${MARK}]`) !== null) return;\n const style = document.createElement('style');\n style.setAttribute(MARK, '');\n style.textContent = CUE_RULES;\n document.head.append(style);\n}\n\n/** What a lifted cue looked like before, to put back. */\ninterface Placed {\n readonly line: number | 'auto';\n readonly snapToLines: boolean;\n readonly lineAlign: LineAlignSetting;\n}\n\nexport interface CueLift {\n /** Whether the bar is showing, so the cues move above it or back. */\n lifted(on: boolean): void;\n dispose(): void;\n}\n\n/** What the bar covers of the picture: from its first row's top, not its gradient run-in, to its bottom. */\nexport type Covered = () => { readonly top: number; readonly bottom: number };\n\nexport function cueLift(video: HTMLVideoElement, host: HTMLElement, covered: Covered): CueLift {\n /** The cues moved, with what they were, so they and only they are put back. */\n const lifted = new Map<VTTCue, Placed>();\n let on = false;\n let canvas: CanvasRenderingContext2D | null | undefined;\n\n function showing(): TextTrack[] {\n const out: TextTrack[] = [];\n for (const track of video.textTracks) if (track.mode === 'showing') out.push(track);\n return out;\n }\n\n /** The browser's cue font size, in pixels, from the video's height and the host's scale. */\n function fontSize(height: number): number {\n const scale = SCALES[host.getAttribute('subtitle-size') ?? ''] ?? 1;\n return height * CUE_SIZE * scale;\n }\n\n /** Measures text the way the browser draws cues, to count the lines a cue wraps into. */\n function measure(): CanvasRenderingContext2D | null {\n if (canvas === undefined) canvas = document.createElement('canvas').getContext('2d');\n return canvas;\n }\n\n /**\n * A cue's text without its tags, for measuring: `<b>`, `<c.name>`, the\n * timestamps and their closers. Brackets are counted, so a tag inside\n * another's brackets goes with it.\n */\n function plain(text: string): string {\n let out = '';\n let depth = 0;\n for (const char of text) {\n if (char === '<') depth += 1;\n else if (char === '>') depth = Math.max(0, depth - 1);\n else if (depth === 0) out += char;\n }\n return out;\n }\n\n /** The lines a cue takes: its own, each wrapped at the cue box's width. */\n function lines(cue: VTTCue, font: number, width: number): number {\n const context = measure();\n let total = 0;\n for (const line of plain(cue.text).split('\\n')) {\n if (context === null) {\n total += 1;\n continue;\n }\n context.font = `${font}px sans-serif`;\n total += Math.max(1, Math.ceil(context.measureText(line).width / (width * CUE_WIDTH)));\n }\n return total;\n }\n\n function apply(): void {\n const box = video.getBoundingClientRect();\n const height = box.height;\n const span = covered();\n const pixels = span.bottom - span.top;\n const lift = on && height > 0 && pixels > 0 && pixels < height;\n const font = fontSize(height);\n const unit = font * LINE_HEIGHT;\n // The lines the bar covers, with a little air, rounded up to whole lines.\n const base = Math.ceil((pixels + AIR) / unit);\n for (const track of showing()) {\n // Earliest first, the order the browser stacks them in, so the first\n // sits lowest and the rest climb.\n const active = [...(track.activeCues ?? [])]\n .filter((cue): cue is VTTCue => cue instanceof VTTCue)\n .sort((a, b) => a.startTime - b.startTime);\n let previous: { line: number; height: number } | null = null;\n let changed = false;\n for (const cue of active) {\n const was = lifted.get(cue);\n if (!lift) {\n if (was === undefined) continue;\n cue.line = was.line;\n cue.snapToLines = was.snapToLines;\n cue.lineAlign = was.lineAlign;\n lifted.delete(cue);\n changed = true;\n continue;\n }\n // The author's own placement is the author's.\n if (was === undefined && cue.line !== 'auto') continue;\n if (was === undefined) {\n lifted.set(cue, {\n line: cue.line,\n snapToLines: cue.snapToLines,\n lineAlign: cue.lineAlign,\n });\n }\n // A negative line count, which every browser wraps at the video's\n // width, unlike a percentage. Chromium anchors the box's top on it\n // and Gecko its bottom, so the count clears the bar and the cue\n // below under both readings, with a little air to spare in one.\n const own = lines(cue, font, box.width);\n const line: number =\n previous === null ? base + own : previous.line + Math.max(own, previous.height);\n if (cue.line !== -line || !cue.snapToLines) changed = true;\n cue.snapToLines = true;\n cue.line = -line;\n previous = { line, height: own };\n }\n // Chromium lays a changed line out again only when the track's display\n // is rebuilt, which neither time nor a seek does for a cue already\n // showing; the mode flipped off and on in one task rebuilds it with no\n // paint in between. Only on a change, so the change event this fires\n // finds nothing to do and the loop ends there.\n if (changed) {\n track.mode = 'hidden';\n track.mode = 'showing';\n }\n }\n }\n\n function watch(): void {\n for (const track of video.textTracks) {\n track.removeEventListener('cuechange', apply);\n track.addEventListener('cuechange', apply);\n }\n apply();\n }\n\n video.textTracks.addEventListener('change', watch);\n video.textTracks.addEventListener('addtrack', watch);\n watch();\n\n return {\n lifted(next: boolean): void {\n on = next;\n apply();\n },\n dispose(): void {\n on = false;\n apply();\n video.textTracks.removeEventListener('change', watch);\n video.textTracks.removeEventListener('addtrack', watch);\n for (const track of video.textTracks) track.removeEventListener('cuechange', apply);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAA,YAAA;;AAEA,MAAA,SAAA;CACA,OAAA;CACA,QAAA;CACA,OAAA;CACA,QAAA;AACA;;;;;;;AASA,MAAA,OAAA;;AAGA,MAAA,WAAA;AACA,MAAA,cAAA;;AAEA,MAAA,YAAA;;AAEA,MAAA,MAAA;;AAGA,SAAA,WAAA;CACA,IAAA,SAAA,KAAA,cAAA,SAAA,KAAA,EAAA,MAAA,MAAA;CACA,MAAA,QAAA,SAAA,cAAA,OAAA;CACA,MAAA,aAAA,MAAA,EAAA;CACA,MAAA,cAAA;CACA,SAAA,KAAA,OAAA,KAAA;AACA;AAkBA,SAAA,QAAA,OAAA,MAAA,SAAA;;CAEA,MAAA,yBAAA,IAAA,IAAA;CACA,IAAA,KAAA;CACA,IAAA;CAEA,SAAA,UAAA;EACA,MAAA,MAAA,CAAA;EACA,KAAA,MAAA,SAAA,MAAA,YAAA,IAAA,MAAA,SAAA,WAAA,IAAA,KAAA,KAAA;EACA,OAAA;CACA;;CAGA,SAAA,SAAA,QAAA;EACA,MAAA,QAAA,OAAA,KAAA,aAAA,eAAA,KAAA,OAAA;EACA,OAAA,SAAA,WAAA;CACA;;CAGA,SAAA,UAAA;EACA,IAAA,WAAA,KAAA,GAAA,SAAA,SAAA,cAAA,QAAA,CAAA,CAAA,WAAA,IAAA;EACA,OAAA;CACA;;;;;;CAOA,SAAA,MAAA,MAAA;EACA,IAAA,MAAA;EACA,IAAA,QAAA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AAA,KAAA,IAAA,SAAA,QAAA;IACA,IAAA,QAAA,KAAA,GACA,OAAA,IAAA,KAAA;KACA,MAAA,IAAA;KACA,aAAA,IAAA;KACA,WAAA,IAAA;IACA,CAAA;IAMA,MAAA,MAAA,MAAA,KAAA,MAAA,IAAA,KAAA;IACA,MAAA,OACA,aAAA,OAAA,OAAA,MAAA,SAAA,OAAA,KAAA,IAAA,KAAA,SAAA,MAAA;IACA,IAAA,IAAA,SAAA,CAAA,QAAA,CAAA,IAAA,aAAA,UAAA;IACA,IAAA,cAAA;IACA,IAAA,OAAA,CAAA;IACA,WAAA;KAAA;KAAA,QAAA;IAAA;GACA;GAMA,IAAA,SAAA;IACA,MAAA,OAAA;IACA,MAAA,OAAA;GACA;EACA;CACA;CAEA,SAAA,QAAA;EACA,KAAA,MAAA,SAAA,MAAA,YAAA;GACA,MAAA,oBAAA,aAAA,KAAA;GACA,MAAA,iBAAA,aAAA,KAAA;EACA;EACA,MAAA;CACA;CAEA,MAAA,WAAA,iBAAA,UAAA,KAAA;CACA,MAAA,WAAA,iBAAA,YAAA,KAAA;CACA,MAAA;CAEA,OAAA;EACA,OAAA,MAAA;GACA,KAAA;GACA,MAAA;EACA;EACA,UAAA;GACA,KAAA;GACA,MAAA;GACA,MAAA,WAAA,oBAAA,UAAA,KAAA;GACA,MAAA,WAAA,oBAAA,YAAA,KAAA;GACA,KAAA,MAAA,SAAA,MAAA,YAAA,MAAA,oBAAA,aAAA,KAAA;EACA;CACA;AACA"}
|
|
@@ -1,74 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
* Fullscreen on the player itself, so the video and every control in it
|
|
3
|
-
* come along, through whichever API the browser has. Three shapes, tried
|
|
4
|
-
* in order: the standard one; the `webkit` prefix on elements, which
|
|
5
|
-
* Safari kept until 16.4; and the iPhone, which has fullscreen on the
|
|
6
|
-
* video alone. None of them means no button.
|
|
7
|
-
*
|
|
8
|
-
* "Active" is whether the host is the fullscreen element, which `:fullscreen`
|
|
9
|
-
* answers whatever tree the host is in: `document.fullscreenElement` is
|
|
10
|
-
* retargeted when the host sits in a shadow root, and the pseudo-class is not.
|
|
11
|
-
*/
|
|
1
|
+
//#region src/controls/fullscreen.ts
|
|
12
2
|
function watching(target, names) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
};
|
|
3
|
+
return (fn) => {
|
|
4
|
+
for (const name of names) target.addEventListener(name, fn);
|
|
5
|
+
return () => {
|
|
6
|
+
for (const name of names) target.removeEventListener(name, fn);
|
|
7
|
+
};
|
|
8
|
+
};
|
|
21
9
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
watch: watching(video, ['webkitbeginfullscreen', 'webkitendfullscreen']),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
supported: false,
|
|
69
|
-
active: () => false,
|
|
70
|
-
toggle() { },
|
|
71
|
-
watch: () => () => { },
|
|
72
|
-
};
|
|
10
|
+
function fullscreen(host, video) {
|
|
11
|
+
const doc = document;
|
|
12
|
+
const prefixed = host;
|
|
13
|
+
const phone = video;
|
|
14
|
+
if (typeof host.requestFullscreen === "function") {
|
|
15
|
+
const active = () => host.matches(":fullscreen");
|
|
16
|
+
return {
|
|
17
|
+
supported: true,
|
|
18
|
+
active,
|
|
19
|
+
toggle() {
|
|
20
|
+
(active() ? document.exitFullscreen() : host.requestFullscreen()).catch(() => void 0);
|
|
21
|
+
},
|
|
22
|
+
watch: watching(document, ["fullscreenchange"])
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (typeof prefixed.webkitRequestFullscreen === "function") {
|
|
26
|
+
const active = () => doc.webkitFullscreenElement === host;
|
|
27
|
+
return {
|
|
28
|
+
supported: true,
|
|
29
|
+
active,
|
|
30
|
+
toggle() {
|
|
31
|
+
if (active()) doc.webkitExitFullscreen?.();
|
|
32
|
+
else prefixed.webkitRequestFullscreen?.();
|
|
33
|
+
},
|
|
34
|
+
watch: watching(document, ["webkitfullscreenchange"])
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (typeof phone.webkitEnterFullscreen === "function") return {
|
|
38
|
+
supported: true,
|
|
39
|
+
active: () => phone.webkitDisplayingFullscreen === true,
|
|
40
|
+
toggle() {
|
|
41
|
+
if (phone.webkitDisplayingFullscreen === true) phone.webkitExitFullscreen?.();
|
|
42
|
+
else phone.webkitEnterFullscreen?.();
|
|
43
|
+
},
|
|
44
|
+
watch: watching(video, ["webkitbeginfullscreen", "webkitendfullscreen"])
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
supported: false,
|
|
48
|
+
active: () => false,
|
|
49
|
+
toggle() {},
|
|
50
|
+
watch: () => () => {}
|
|
51
|
+
};
|
|
73
52
|
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { fullscreen };
|
|
55
|
+
|
|
74
56
|
//# sourceMappingURL=fullscreen.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fullscreen.js","
|
|
1
|
+
{"version":3,"file":"fullscreen.js","names":[],"sources":["../../src/controls/fullscreen.ts"],"sourcesContent":["/**\n * Fullscreen on the player itself, so the video and every control in it\n * come along, through whichever API the browser has. Three shapes, tried\n * in order: the standard one; the `webkit` prefix on elements, which\n * Safari kept until 16.4; and the iPhone, which has fullscreen on the\n * video alone. None of them means no button.\n *\n * \"Active\" is whether the host is the fullscreen element, which `:fullscreen`\n * answers whatever tree the host is in: `document.fullscreenElement` is\n * retargeted when the host sits in a shadow root, and the pseudo-class is not.\n */\n\ninterface PrefixedElement {\n webkitRequestFullscreen?: () => void;\n}\n\ninterface PrefixedVideo {\n webkitEnterFullscreen?: () => void;\n webkitExitFullscreen?: () => void;\n readonly webkitDisplayingFullscreen?: boolean;\n}\n\ninterface PrefixedDocument {\n readonly webkitFullscreenElement?: Element | null;\n webkitExitFullscreen?: () => void;\n}\n\nexport interface Fullscreen {\n /** Whether any API exists. Without one the button is hidden. */\n readonly supported: boolean;\n active(): boolean;\n toggle(): void;\n /** Runs `fn` on every change. Returns the unsubscribe. */\n watch(fn: () => void): () => void;\n}\n\nfunction watching(target: EventTarget, names: readonly string[]) {\n return (fn: () => void): (() => void) => {\n for (const name of names) target.addEventListener(name, fn);\n return () => {\n for (const name of names) target.removeEventListener(name, fn);\n };\n };\n}\n\nexport function fullscreen(host: HTMLElement, video: HTMLVideoElement): Fullscreen {\n const doc = document as Document & PrefixedDocument;\n const prefixed = host as HTMLElement & PrefixedElement;\n const phone = video as HTMLVideoElement & PrefixedVideo;\n\n if (typeof host.requestFullscreen === 'function') {\n const active = (): boolean => host.matches(':fullscreen');\n return {\n supported: true,\n active,\n toggle(): void {\n // Both return promises that reject outside a user gesture or where\n // the page forbids it; there is nothing to do with that but drop it.\n const request = active() ? document.exitFullscreen() : host.requestFullscreen();\n request.catch(() => undefined);\n },\n watch: watching(document, ['fullscreenchange']),\n };\n }\n\n if (typeof prefixed.webkitRequestFullscreen === 'function') {\n const active = (): boolean => doc.webkitFullscreenElement === host;\n return {\n supported: true,\n active,\n toggle(): void {\n if (active()) doc.webkitExitFullscreen?.();\n else prefixed.webkitRequestFullscreen?.();\n },\n watch: watching(document, ['webkitfullscreenchange']),\n };\n }\n\n if (typeof phone.webkitEnterFullscreen === 'function') {\n return {\n supported: true,\n active: () => phone.webkitDisplayingFullscreen === true,\n toggle(): void {\n if (phone.webkitDisplayingFullscreen === true) phone.webkitExitFullscreen?.();\n else phone.webkitEnterFullscreen?.();\n },\n watch: watching(video, ['webkitbeginfullscreen', 'webkitendfullscreen']),\n };\n }\n\n return {\n supported: false,\n active: () => false,\n toggle(): void {},\n watch: () => () => {},\n };\n}\n"],"mappings":";AAoCA,SAAS,SAAS,QAAqB,OAA0B;CAC/D,QAAQ,OAAiC;EACvC,KAAK,MAAM,QAAQ,OAAO,OAAO,iBAAiB,MAAM,EAAE;EAC1D,aAAa;GACX,KAAK,MAAM,QAAQ,OAAO,OAAO,oBAAoB,MAAM,EAAE;EAC/D;CACF;AACF;AAEA,SAAgB,WAAW,MAAmB,OAAqC;CACjF,MAAM,MAAM;CACZ,MAAM,WAAW;CACjB,MAAM,QAAQ;CAEd,IAAI,OAAO,KAAK,sBAAsB,YAAY;EAChD,MAAM,eAAwB,KAAK,QAAQ,aAAa;EACxD,OAAO;GACL,WAAW;GACX;GACA,SAAe;IAIb,CADgB,OAAO,IAAI,SAAS,eAAe,IAAI,KAAK,kBAAkB,EAAA,CACtE,YAAY,KAAA,CAAS;GAC/B;GACA,OAAO,SAAS,UAAU,CAAC,kBAAkB,CAAC;EAChD;CACF;CAEA,IAAI,OAAO,SAAS,4BAA4B,YAAY;EAC1D,MAAM,eAAwB,IAAI,4BAA4B;EAC9D,OAAO;GACL,WAAW;GACX;GACA,SAAe;IACb,IAAI,OAAO,GAAG,IAAI,uBAAuB;SACpC,SAAS,0BAA0B;GAC1C;GACA,OAAO,SAAS,UAAU,CAAC,wBAAwB,CAAC;EACtD;CACF;CAEA,IAAI,OAAO,MAAM,0BAA0B,YACzC,OAAO;EACL,WAAW;EACX,cAAc,MAAM,+BAA+B;EACnD,SAAe;GACb,IAAI,MAAM,+BAA+B,MAAM,MAAM,uBAAuB;QACvE,MAAM,wBAAwB;EACrC;EACA,OAAO,SAAS,OAAO,CAAC,yBAAyB,qBAAqB,CAAC;CACzE;CAGF,OAAO;EACL,WAAW;EACX,cAAc;EACd,SAAe,CAAC;EAChB,mBAAmB,CAAC;CACtB;AACF"}
|
package/dist/controls/icons.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
28
|
* SOFTWARE.
|
|
29
29
|
*/
|
|
30
|
-
export type IconName = 'play' | 'pause' | 'replay' | 'mute' | 'volume-low' | 'volume-high' | 'fullscreen' | 'fullscreen-exit' | 'settings' | 'music' | 'closed-captions' | 'closed-captions-on' | 'lock-closed' | 'seek-backward' | 'seek-forward' | 'seek-backward-10' | 'seek-forward-10' | 'seek-backward-30' | 'seek-forward-30' | 'playback-speed' | 'picture-in-picture' | 'picture-in-picture-exit' | 'airplay' | 'airplay-active' | 'chapters';
|
|
30
|
+
export type IconName = 'play' | 'pause' | 'replay' | 'mute' | 'volume-low' | 'volume-high' | 'fullscreen' | 'fullscreen-exit' | 'settings' | 'music' | 'closed-captions' | 'closed-captions-on' | 'lock-closed' | 'seek-backward' | 'seek-forward' | 'seek-backward-10' | 'seek-forward-10' | 'seek-backward-30' | 'seek-forward-30' | 'playback-speed' | 'picture-in-picture' | 'picture-in-picture-exit' | 'airplay' | 'airplay-active' | 'chapters' | 'fast-forward' | 'fast-backward';
|
|
31
31
|
/** A glyph, hidden from the accessibility tree: the button it sits in carries the name. */
|
|
32
32
|
export declare function icon(name: IconName): SVGSVGElement;
|
|
33
33
|
//# sourceMappingURL=icons.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../src/controls/icons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,iBAAiB,GACjB,UAAU,GACV,OAAO,GACP,iBAAiB,GACjB,oBAAoB,GACpB,aAAa,GACb,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,oBAAoB,GACpB,yBAAyB,GACzB,SAAS,GACT,gBAAgB,GAChB,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../src/controls/icons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,iBAAiB,GACjB,UAAU,GACV,OAAO,GACP,iBAAiB,GACjB,oBAAoB,GACpB,aAAa,GACb,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,oBAAoB,GACpB,yBAAyB,GACzB,SAAS,GACT,gBAAgB,GAChB,UAAU,GACV,cAAc,GACd,eAAe,CAAC;AAiEpB,2FAA2F;AAC3F,wBAAgB,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,aAAa,CAUlD"}
|