@kkcompany/player 2.25.0-canary.17 → 2.25.0-canary.19
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/CHANGELOG.md +25 -76
- package/dist/core.mjs +668 -5
- package/dist/index.js +1344 -571
- package/dist/index.mjs +690 -15
- package/dist/modules.mjs +2 -2
- package/dist/react.mjs +691 -16
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -812,7 +812,7 @@ function convertToSeconds(timeString) {
|
|
|
812
812
|
function getVersion() {
|
|
813
813
|
try {
|
|
814
814
|
// eslint-disable-next-line no-undef
|
|
815
|
-
return "2.25.0-canary.
|
|
815
|
+
return "2.25.0-canary.19";
|
|
816
816
|
} catch (e) {
|
|
817
817
|
return undefined;
|
|
818
818
|
}
|
|
@@ -1106,11 +1106,26 @@ const getSettingsData = ({
|
|
|
1106
1106
|
const matchTracks = (tracks, sorted) => {
|
|
1107
1107
|
var _tracks$;
|
|
1108
1108
|
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1109
|
+
const lookup = {};
|
|
1110
|
+
tracks.forEach(track => {
|
|
1111
|
+
lookup[`${track.language}|${track.label}`] = track;
|
|
1112
|
+
lookup[`${track.language}|`] = track;
|
|
1113
|
+
lookup[`|${track.label}`] = track;
|
|
1114
|
+
});
|
|
1115
|
+
const matched = sorted.map(info => {
|
|
1116
|
+
const track = lookup[`${info.language}|${info.label}`] || lookup[`${info.language}|`];
|
|
1117
|
+
return track && { ...track,
|
|
1118
|
+
...info
|
|
1119
|
+
};
|
|
1120
|
+
}).filter(Boolean);
|
|
1121
|
+
|
|
1122
|
+
if (((_tracks$ = tracks[0]) === null || _tracks$ === void 0 ? void 0 : _tracks$.type) === 'audio' && matched.length === 0) {
|
|
1123
|
+
return [{ ...tracks[0],
|
|
1124
|
+
...sorted[0]
|
|
1125
|
+
}];
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
return matched;
|
|
1114
1129
|
};
|
|
1115
1130
|
|
|
1116
1131
|
const getLanguageOptions = (player, sorted) => {
|
|
@@ -2331,7 +2346,7 @@ var ja = {
|
|
|
2331
2346
|
"KKS.QUALITY": "解像度",
|
|
2332
2347
|
"KKS.AUDIO": "音声",
|
|
2333
2348
|
"KKS.SETTING.OFF": "オフ",
|
|
2334
|
-
"KKS.SETTING.none": "
|
|
2349
|
+
"KKS.SETTING.none": "なし",
|
|
2335
2350
|
"KKS.SETTING.ja": "日本語",
|
|
2336
2351
|
"KKS.SETTING.en": "英語",
|
|
2337
2352
|
"KKS.SUBTITLES": "字幕",
|
|
@@ -3132,13 +3147,10 @@ const nativeTextStyle = {
|
|
|
3132
3147
|
};
|
|
3133
3148
|
const customTextStyle = {
|
|
3134
3149
|
'.shaka-text-container': {
|
|
3150
|
+
boxSizing: 'border-box',
|
|
3135
3151
|
padding: '2cqmin',
|
|
3136
3152
|
font: '3cqmin/1 sans-serif',
|
|
3137
3153
|
color: '#ffffff',
|
|
3138
|
-
fontFamily: 'system-ui-monospaced',
|
|
3139
|
-
'unicode-bidi': 'plaintext',
|
|
3140
|
-
'overflow-wrap': 'break-word',
|
|
3141
|
-
textWrap: 'balance',
|
|
3142
3154
|
textShadow: '1px 1px 0.2cqmin #000'
|
|
3143
3155
|
},
|
|
3144
3156
|
'.shaka-text-container > .shaka-cue-horizontal-tb': {
|
|
@@ -6007,7 +6019,7 @@ const makeResponse = (headers, data, status, uri, responseURL, requestType) => {
|
|
|
6007
6019
|
throw new shaka$1.util.Error(severity, shaka$1.util.Error.Category.NETWORK, shaka$1.util.Error.Code.BAD_HTTP_STATUS, uri, status, responseText, headers, requestType);
|
|
6008
6020
|
};
|
|
6009
6021
|
|
|
6010
|
-
const goog$
|
|
6022
|
+
const goog$2 = {
|
|
6011
6023
|
asserts: {
|
|
6012
6024
|
assert: () => {}
|
|
6013
6025
|
}
|
|
@@ -6153,7 +6165,7 @@ class HttpFetchPlugin {
|
|
|
6153
6165
|
}
|
|
6154
6166
|
|
|
6155
6167
|
if (readObj.done) {
|
|
6156
|
-
goog$
|
|
6168
|
+
goog$2.asserts.assert(!readObj.value, 'readObj should be unset when "done" is true.');
|
|
6157
6169
|
controller.close();
|
|
6158
6170
|
} else {
|
|
6159
6171
|
controller.enqueue(readObj.value);
|
|
@@ -6392,6 +6404,664 @@ const fixDashManifest = (data, {
|
|
|
6392
6404
|
return new XMLSerializer().serializeToString(doc);
|
|
6393
6405
|
};
|
|
6394
6406
|
|
|
6407
|
+
/* eslint-disable no-cond-assign */
|
|
6408
|
+
|
|
6409
|
+
/* eslint-disable prefer-destructuring */
|
|
6410
|
+
|
|
6411
|
+
/*! @license
|
|
6412
|
+
* Shaka Player
|
|
6413
|
+
* Copyright 2016 Google LLC
|
|
6414
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6415
|
+
*/
|
|
6416
|
+
const goog$1 = {
|
|
6417
|
+
asserts: {
|
|
6418
|
+
assert: (condition, message) => {
|
|
6419
|
+
if (!condition) {
|
|
6420
|
+
console.warn('GOOG Assert!', message);
|
|
6421
|
+
}
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
};
|
|
6425
|
+
|
|
6426
|
+
const addDefaultTextColor = styles => {
|
|
6427
|
+
const textColor = shaka.text.Cue.defaultTextColor;
|
|
6428
|
+
|
|
6429
|
+
for (const [key, value] of Object.entries(textColor)) {
|
|
6430
|
+
const cue = new shaka.text.Cue(0, 0, '');
|
|
6431
|
+
cue.color = value;
|
|
6432
|
+
styles.set(`.${key}`, cue);
|
|
6433
|
+
}
|
|
6434
|
+
|
|
6435
|
+
const bgColor = shaka.text.Cue.defaultTextBackgroundColor;
|
|
6436
|
+
|
|
6437
|
+
for (const [key, value] of Object.entries(bgColor)) {
|
|
6438
|
+
const cue = new shaka.text.Cue(0, 0, '');
|
|
6439
|
+
cue.backgroundColor = value;
|
|
6440
|
+
styles.set(`.${key}`, cue);
|
|
6441
|
+
}
|
|
6442
|
+
};
|
|
6443
|
+
|
|
6444
|
+
const parseTime = text => {
|
|
6445
|
+
var _Array$from;
|
|
6446
|
+
|
|
6447
|
+
const timeFormat = /(?:(\d{1,}):)?(\d{2}):(\d{2})((\.(\d{1,3})))?/g;
|
|
6448
|
+
const results = (_Array$from = Array.from(text.matchAll(timeFormat))) === null || _Array$from === void 0 ? void 0 : _Array$from[0];
|
|
6449
|
+
|
|
6450
|
+
if (results == null) {
|
|
6451
|
+
return null;
|
|
6452
|
+
} // This capture is optional, but will still be in the array as undefined,
|
|
6453
|
+
// in which case it is 0.
|
|
6454
|
+
|
|
6455
|
+
|
|
6456
|
+
const hours = Number(results[1]) || 0;
|
|
6457
|
+
const minutes = Number(results[2]);
|
|
6458
|
+
const seconds = Number(results[3]);
|
|
6459
|
+
const milliseconds = Number(results[6]) || 0;
|
|
6460
|
+
|
|
6461
|
+
if (minutes > 59 || seconds > 59) {
|
|
6462
|
+
return null;
|
|
6463
|
+
}
|
|
6464
|
+
|
|
6465
|
+
return milliseconds / 1000 + seconds + minutes * 60 + hours * 3600;
|
|
6466
|
+
};
|
|
6467
|
+
|
|
6468
|
+
const parseRegion = block => {
|
|
6469
|
+
if (block[0].trim() !== 'REGION') {
|
|
6470
|
+
return [];
|
|
6471
|
+
}
|
|
6472
|
+
|
|
6473
|
+
const region = new shaka.text.CueRegion();
|
|
6474
|
+
block.slice(1).forEach(word => {
|
|
6475
|
+
let results = null;
|
|
6476
|
+
|
|
6477
|
+
if (results = /^id:(.*)$/.exec(word)) {
|
|
6478
|
+
region.id = results[1];
|
|
6479
|
+
} else if (results = /^width:(\d{1,2}|100)%$/.exec(word)) {
|
|
6480
|
+
region.width = Number(results[1]);
|
|
6481
|
+
} else if (results = /^lines:(\d+)$/.exec(word)) {
|
|
6482
|
+
region.height = Number(results[1]);
|
|
6483
|
+
region.heightUnits = shaka.text.CueRegion.units.LINES;
|
|
6484
|
+
} else if (results = /^regionanchor:(\d{1,2}|100)%,(\d{1,2}|100)%$/.exec(word)) {
|
|
6485
|
+
region.regionAnchorX = Number(results[1]);
|
|
6486
|
+
region.regionAnchorY = Number(results[2]);
|
|
6487
|
+
} else if (results = /^viewportanchor:(\d{1,2}|100)%,(\d{1,2}|100)%$/.exec(word)) {
|
|
6488
|
+
region.viewportAnchorX = Number(results[1]);
|
|
6489
|
+
region.viewportAnchorY = Number(results[2]);
|
|
6490
|
+
} else if (results = /^scroll:up$/.exec(word)) {
|
|
6491
|
+
region.scroll = shaka.text.CueRegion.scrollMode.UP;
|
|
6492
|
+
} else {
|
|
6493
|
+
shaka.log.warning('VTT parser encountered an invalid VTTRegion setting: ', word, ' The setting will be ignored.');
|
|
6494
|
+
}
|
|
6495
|
+
});
|
|
6496
|
+
return [region];
|
|
6497
|
+
};
|
|
6498
|
+
/**
|
|
6499
|
+
* @implements {shaka.extern.TextParser}
|
|
6500
|
+
* @export
|
|
6501
|
+
*/
|
|
6502
|
+
|
|
6503
|
+
|
|
6504
|
+
class VttTextParser {
|
|
6505
|
+
/** Constructs a VTT parser. */
|
|
6506
|
+
constructor() {
|
|
6507
|
+
/** @private {boolean} */
|
|
6508
|
+
this.sequenceMode_ = false;
|
|
6509
|
+
/** @private {string} */
|
|
6510
|
+
|
|
6511
|
+
this.manifestType_ = shaka.media.ManifestParser.UNKNOWN;
|
|
6512
|
+
}
|
|
6513
|
+
/**
|
|
6514
|
+
* @override
|
|
6515
|
+
* @export
|
|
6516
|
+
*/
|
|
6517
|
+
|
|
6518
|
+
|
|
6519
|
+
parseInit() {
|
|
6520
|
+
goog$1.asserts.assert(false, 'VTT does not have init segments');
|
|
6521
|
+
}
|
|
6522
|
+
/**
|
|
6523
|
+
* @override
|
|
6524
|
+
* @export
|
|
6525
|
+
*/
|
|
6526
|
+
|
|
6527
|
+
|
|
6528
|
+
setSequenceMode(sequenceMode) {
|
|
6529
|
+
this.sequenceMode_ = sequenceMode;
|
|
6530
|
+
}
|
|
6531
|
+
/**
|
|
6532
|
+
* @override
|
|
6533
|
+
* @export
|
|
6534
|
+
*/
|
|
6535
|
+
|
|
6536
|
+
|
|
6537
|
+
setManifestType(manifestType) {
|
|
6538
|
+
this.manifestType_ = manifestType;
|
|
6539
|
+
}
|
|
6540
|
+
/**
|
|
6541
|
+
* @override
|
|
6542
|
+
* @export
|
|
6543
|
+
*/
|
|
6544
|
+
|
|
6545
|
+
|
|
6546
|
+
parseMedia(data, time) {
|
|
6547
|
+
// Get the input as a string. Normalize newlines to \n.
|
|
6548
|
+
let str = shaka.util.StringUtils.fromUTF8(data);
|
|
6549
|
+
str = str.replace(/\r\n|\r(?=[^\n]|$)/gm, '\n');
|
|
6550
|
+
const blocks = str.split(/\n{2,}/m);
|
|
6551
|
+
|
|
6552
|
+
if (!/^WEBVTT($|[ \t\n])/m.test(blocks[0])) {
|
|
6553
|
+
throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
|
|
6554
|
+
} // Depending on "segmentRelativeVttTiming" configuration,
|
|
6555
|
+
// "vttOffset" will correspond to either "periodStart" (default)
|
|
6556
|
+
// or "segmentStart", for segmented VTT where timings are relative
|
|
6557
|
+
// to the beginning of each segment.
|
|
6558
|
+
// NOTE: "periodStart" is the timestamp offset applied via TextEngine.
|
|
6559
|
+
// It is no longer closely tied to periods, but the name stuck around.
|
|
6560
|
+
// NOTE: This offset and the flag choosing its meaning have no effect on
|
|
6561
|
+
// HLS content, which should use X-TIMESTAMP-MAP and periodStart instead.
|
|
6562
|
+
|
|
6563
|
+
|
|
6564
|
+
let offset = time.vttOffset;
|
|
6565
|
+
|
|
6566
|
+
if (this.manifestType_ == shaka.media.ManifestParser.HLS) {
|
|
6567
|
+
// Only use 'X-TIMESTAMP-MAP' with HLS.
|
|
6568
|
+
if (blocks[0].includes('X-TIMESTAMP-MAP')) {
|
|
6569
|
+
offset = this.computeHlsOffset_(blocks[0], time);
|
|
6570
|
+
} else if (time.periodStart && time.vttOffset == time.periodStart) {
|
|
6571
|
+
// In the case where X-TIMESTAMP-MAP is not used and it is HLS, we
|
|
6572
|
+
// should not use offset unless segment-relative times are used.
|
|
6573
|
+
offset = 0;
|
|
6574
|
+
}
|
|
6575
|
+
}
|
|
6576
|
+
|
|
6577
|
+
const regions = [];
|
|
6578
|
+
/** @type {!Map<string, !shaka.text.Cue>} */
|
|
6579
|
+
|
|
6580
|
+
const styles = new Map();
|
|
6581
|
+
addDefaultTextColor(styles); // Parse cues.
|
|
6582
|
+
|
|
6583
|
+
const ret = [];
|
|
6584
|
+
|
|
6585
|
+
for (const block of blocks.slice(1)) {
|
|
6586
|
+
const lines = block.split('\n');
|
|
6587
|
+
VttTextParser.parseStyle_(lines, styles);
|
|
6588
|
+
regions.push(...parseRegion(lines));
|
|
6589
|
+
const cue = VttTextParser.parseCue_(lines, offset, regions, styles);
|
|
6590
|
+
|
|
6591
|
+
if (cue) {
|
|
6592
|
+
ret.push(cue);
|
|
6593
|
+
}
|
|
6594
|
+
}
|
|
6595
|
+
|
|
6596
|
+
return ret;
|
|
6597
|
+
}
|
|
6598
|
+
/**
|
|
6599
|
+
* @param {string} headerBlock Contains X-TIMESTAMP-MAP.
|
|
6600
|
+
* @param {shaka.extern.TextParser.TimeContext} time
|
|
6601
|
+
* @return {number}
|
|
6602
|
+
* @private
|
|
6603
|
+
*/
|
|
6604
|
+
|
|
6605
|
+
|
|
6606
|
+
computeHlsOffset_(headerBlock, time) {
|
|
6607
|
+
// https://bit.ly/2K92l7y
|
|
6608
|
+
// The 'X-TIMESTAMP-MAP' header is used in HLS to align text with
|
|
6609
|
+
// the rest of the media.
|
|
6610
|
+
// The header format is 'X-TIMESTAMP-MAP=MPEGTS:n,LOCAL:m'
|
|
6611
|
+
// (the attributes can go in any order)
|
|
6612
|
+
// where n is MPEG-2 time and m is cue time it maps to.
|
|
6613
|
+
// For example 'X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000'
|
|
6614
|
+
// means an offset of 10 seconds
|
|
6615
|
+
// 900000/MPEG_TIMESCALE - cue time.
|
|
6616
|
+
const cueTimeMatch = headerBlock.match(/LOCAL:((?:(\d{1,}):)?(\d{2}):(\d{2})\.(\d{3}))/m);
|
|
6617
|
+
const mpegTimeMatch = headerBlock.match(/MPEGTS:(\d+)/m);
|
|
6618
|
+
|
|
6619
|
+
if (!cueTimeMatch || !mpegTimeMatch) {
|
|
6620
|
+
throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
|
|
6621
|
+
}
|
|
6622
|
+
|
|
6623
|
+
const cueTime = parseTime(cueTimeMatch[1]);
|
|
6624
|
+
|
|
6625
|
+
if (cueTime == null) {
|
|
6626
|
+
throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
|
|
6627
|
+
}
|
|
6628
|
+
|
|
6629
|
+
let mpegTime = Number(mpegTimeMatch[1]);
|
|
6630
|
+
const mpegTimescale = VttTextParser.MPEG_TIMESCALE_;
|
|
6631
|
+
const rolloverSeconds = VttTextParser.TS_ROLLOVER_ / mpegTimescale;
|
|
6632
|
+
let segmentStart = time.segmentStart - time.periodStart;
|
|
6633
|
+
|
|
6634
|
+
while (segmentStart >= rolloverSeconds) {
|
|
6635
|
+
segmentStart -= rolloverSeconds;
|
|
6636
|
+
mpegTime += VttTextParser.TS_ROLLOVER_;
|
|
6637
|
+
}
|
|
6638
|
+
|
|
6639
|
+
return time.periodStart + mpegTime / mpegTimescale - cueTime;
|
|
6640
|
+
}
|
|
6641
|
+
/**
|
|
6642
|
+
* Parses a style block into a Cue object.
|
|
6643
|
+
*
|
|
6644
|
+
* @param {!Array<string>} text
|
|
6645
|
+
* @param {!Map<string, !shaka.text.Cue>} styles
|
|
6646
|
+
* @private
|
|
6647
|
+
*/
|
|
6648
|
+
|
|
6649
|
+
|
|
6650
|
+
static parseStyle_(text, styles) {
|
|
6651
|
+
// Skip empty blocks.
|
|
6652
|
+
if (text.length == 1 && !text[0]) {
|
|
6653
|
+
return;
|
|
6654
|
+
} // Skip comment blocks.
|
|
6655
|
+
|
|
6656
|
+
|
|
6657
|
+
if (/^NOTE($|[ \t])/.test(text[0])) {
|
|
6658
|
+
return;
|
|
6659
|
+
} // Only style block are allowed.
|
|
6660
|
+
|
|
6661
|
+
|
|
6662
|
+
if (text[0] != 'STYLE') {
|
|
6663
|
+
return;
|
|
6664
|
+
}
|
|
6665
|
+
/** @type {!Array<!Array<string>>} */
|
|
6666
|
+
|
|
6667
|
+
|
|
6668
|
+
const styleBlocks = [];
|
|
6669
|
+
let lastBlockIndex = -1;
|
|
6670
|
+
|
|
6671
|
+
for (let i = 1; i < text.length; i++) {
|
|
6672
|
+
if (text[i].includes('::cue')) {
|
|
6673
|
+
styleBlocks.push([]);
|
|
6674
|
+
lastBlockIndex = styleBlocks.length - 1;
|
|
6675
|
+
}
|
|
6676
|
+
|
|
6677
|
+
if (lastBlockIndex == -1) {
|
|
6678
|
+
continue;
|
|
6679
|
+
}
|
|
6680
|
+
|
|
6681
|
+
styleBlocks[lastBlockIndex].push(text[i]);
|
|
6682
|
+
|
|
6683
|
+
if (text[i].includes('}')) {
|
|
6684
|
+
lastBlockIndex = -1;
|
|
6685
|
+
}
|
|
6686
|
+
}
|
|
6687
|
+
|
|
6688
|
+
for (const styleBlock of styleBlocks) {
|
|
6689
|
+
let styleSelector = 'global'; // Look for what is within parentheses. For example:
|
|
6690
|
+
// <code>:: cue (b) {</code>, what we are looking for is <code>b</code>
|
|
6691
|
+
|
|
6692
|
+
const selector = styleBlock[0].match(/\((.*)\)/);
|
|
6693
|
+
|
|
6694
|
+
if (selector) {
|
|
6695
|
+
styleSelector = selector.pop();
|
|
6696
|
+
} // We start at 1 to avoid '::cue' and end earlier to avoid '}'
|
|
6697
|
+
|
|
6698
|
+
|
|
6699
|
+
let propertyLines = styleBlock.slice(1, -1);
|
|
6700
|
+
|
|
6701
|
+
if (styleBlock[0].includes('}')) {
|
|
6702
|
+
const payload = /\{(.*?)\}/.exec(styleBlock[0]);
|
|
6703
|
+
|
|
6704
|
+
if (payload) {
|
|
6705
|
+
propertyLines = payload[1].split(';');
|
|
6706
|
+
}
|
|
6707
|
+
} // Continue styles over multiple selectors if necessary.
|
|
6708
|
+
// For example,
|
|
6709
|
+
// ::cue(b) { background: white; } ::cue(b) { color: blue; }
|
|
6710
|
+
// should set both the background and foreground of bold tags.
|
|
6711
|
+
|
|
6712
|
+
|
|
6713
|
+
let cue = styles.get(styleSelector);
|
|
6714
|
+
|
|
6715
|
+
if (!cue) {
|
|
6716
|
+
cue = new shaka.text.Cue(0, 0, '');
|
|
6717
|
+
}
|
|
6718
|
+
|
|
6719
|
+
let validStyle = false;
|
|
6720
|
+
|
|
6721
|
+
for (let i = 0; i < propertyLines.length; i++) {
|
|
6722
|
+
// We look for CSS properties. As a general rule they are separated by
|
|
6723
|
+
// <code>:</code>. Eg: <code>color: red;</code>
|
|
6724
|
+
const lineParts = /^\s*([^:]+):\s*(.*)/.exec(propertyLines[i]);
|
|
6725
|
+
|
|
6726
|
+
if (lineParts) {
|
|
6727
|
+
const name = lineParts[1].trim();
|
|
6728
|
+
const value = lineParts[2].trim().replace(';', '');
|
|
6729
|
+
|
|
6730
|
+
switch (name) {
|
|
6731
|
+
case 'background-color':
|
|
6732
|
+
case 'background':
|
|
6733
|
+
validStyle = true;
|
|
6734
|
+
cue.backgroundColor = value;
|
|
6735
|
+
break;
|
|
6736
|
+
|
|
6737
|
+
case 'color':
|
|
6738
|
+
validStyle = true;
|
|
6739
|
+
cue.color = value;
|
|
6740
|
+
break;
|
|
6741
|
+
|
|
6742
|
+
case 'font-family':
|
|
6743
|
+
validStyle = true;
|
|
6744
|
+
cue.fontFamily = value;
|
|
6745
|
+
break;
|
|
6746
|
+
|
|
6747
|
+
case 'font-size':
|
|
6748
|
+
validStyle = true;
|
|
6749
|
+
cue.fontSize = value;
|
|
6750
|
+
break;
|
|
6751
|
+
|
|
6752
|
+
case 'font-weight':
|
|
6753
|
+
if (parseInt(value, 10) >= 700 || value == 'bold') {
|
|
6754
|
+
validStyle = true;
|
|
6755
|
+
cue.fontWeight = shaka.text.Cue.fontWeight.BOLD;
|
|
6756
|
+
}
|
|
6757
|
+
|
|
6758
|
+
break;
|
|
6759
|
+
|
|
6760
|
+
case 'font-style':
|
|
6761
|
+
switch (value) {
|
|
6762
|
+
case 'normal':
|
|
6763
|
+
validStyle = true;
|
|
6764
|
+
cue.fontStyle = shaka.text.Cue.fontStyle.NORMAL;
|
|
6765
|
+
break;
|
|
6766
|
+
|
|
6767
|
+
case 'italic':
|
|
6768
|
+
validStyle = true;
|
|
6769
|
+
cue.fontStyle = shaka.text.Cue.fontStyle.ITALIC;
|
|
6770
|
+
break;
|
|
6771
|
+
|
|
6772
|
+
case 'oblique':
|
|
6773
|
+
validStyle = true;
|
|
6774
|
+
cue.fontStyle = shaka.text.Cue.fontStyle.OBLIQUE;
|
|
6775
|
+
break;
|
|
6776
|
+
}
|
|
6777
|
+
|
|
6778
|
+
break;
|
|
6779
|
+
|
|
6780
|
+
case 'opacity':
|
|
6781
|
+
validStyle = true;
|
|
6782
|
+
cue.opacity = parseFloat(value);
|
|
6783
|
+
break;
|
|
6784
|
+
|
|
6785
|
+
case 'text-combine-upright':
|
|
6786
|
+
validStyle = true;
|
|
6787
|
+
cue.textCombineUpright = value;
|
|
6788
|
+
break;
|
|
6789
|
+
|
|
6790
|
+
case 'text-shadow':
|
|
6791
|
+
validStyle = true;
|
|
6792
|
+
cue.textShadow = value;
|
|
6793
|
+
break;
|
|
6794
|
+
|
|
6795
|
+
case 'white-space':
|
|
6796
|
+
validStyle = true;
|
|
6797
|
+
cue.wrapLine = value != 'noWrap';
|
|
6798
|
+
break;
|
|
6799
|
+
|
|
6800
|
+
default:
|
|
6801
|
+
shaka.log.warning('VTT parser encountered an unsupported style: ', lineParts);
|
|
6802
|
+
break;
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6805
|
+
}
|
|
6806
|
+
|
|
6807
|
+
if (validStyle) {
|
|
6808
|
+
styles.set(styleSelector, cue);
|
|
6809
|
+
}
|
|
6810
|
+
}
|
|
6811
|
+
}
|
|
6812
|
+
/**
|
|
6813
|
+
* Parses a text block into a Cue object.
|
|
6814
|
+
*
|
|
6815
|
+
* @param {!Array<string>} text
|
|
6816
|
+
* @param {number} timeOffset
|
|
6817
|
+
* @param {!Array<!shaka.text.CueRegion>} regions
|
|
6818
|
+
* @param {!Map<string, !shaka.text.Cue>} styles
|
|
6819
|
+
* @return {shaka.text.Cue}
|
|
6820
|
+
* @private
|
|
6821
|
+
*/
|
|
6822
|
+
|
|
6823
|
+
|
|
6824
|
+
static parseCue_(text, timeOffset, regions, styles) {
|
|
6825
|
+
// Skip empty blocks.
|
|
6826
|
+
if (text.length == 1 && !text[0]) {
|
|
6827
|
+
return null;
|
|
6828
|
+
} // Skip comment blocks.
|
|
6829
|
+
|
|
6830
|
+
|
|
6831
|
+
if (/^NOTE($|[ \t])/.test(text[0])) {
|
|
6832
|
+
return null;
|
|
6833
|
+
} // Skip style and region blocks.
|
|
6834
|
+
|
|
6835
|
+
|
|
6836
|
+
if (text[0] == 'STYLE' || text[0] == 'REGION') {
|
|
6837
|
+
return null;
|
|
6838
|
+
}
|
|
6839
|
+
|
|
6840
|
+
const skipIndex = text.findIndex(line => /^#/.test(line.trim()));
|
|
6841
|
+
|
|
6842
|
+
if (skipIndex > 0) {
|
|
6843
|
+
text = text.slice(skipIndex);
|
|
6844
|
+
}
|
|
6845
|
+
|
|
6846
|
+
if (text.length < 2) {
|
|
6847
|
+
return;
|
|
6848
|
+
}
|
|
6849
|
+
|
|
6850
|
+
let id = null;
|
|
6851
|
+
|
|
6852
|
+
if (!text[0].includes('-->')) {
|
|
6853
|
+
id = text[0];
|
|
6854
|
+
text.splice(0, 1);
|
|
6855
|
+
} // Parse the times.
|
|
6856
|
+
|
|
6857
|
+
|
|
6858
|
+
let [start, end] = text[0].split('-->').map(part => parseTime(part.trim()));
|
|
6859
|
+
|
|
6860
|
+
if (start == null || end == null) {
|
|
6861
|
+
shaka.log.alwaysWarn('Failed to parse VTT time code. Cue skipped:', id, text);
|
|
6862
|
+
return null;
|
|
6863
|
+
}
|
|
6864
|
+
|
|
6865
|
+
start += timeOffset;
|
|
6866
|
+
end += timeOffset; // Get the payload.
|
|
6867
|
+
|
|
6868
|
+
const payload = text.slice(1).join('\n').trim();
|
|
6869
|
+
let cue = null;
|
|
6870
|
+
|
|
6871
|
+
if (styles.has('global')) {
|
|
6872
|
+
cue = styles.get('global').clone();
|
|
6873
|
+
cue.startTime = start;
|
|
6874
|
+
cue.endTime = end;
|
|
6875
|
+
cue.payload = payload;
|
|
6876
|
+
} else {
|
|
6877
|
+
cue = new shaka.text.Cue(start, end, payload);
|
|
6878
|
+
} // Parse optional settings.
|
|
6879
|
+
|
|
6880
|
+
|
|
6881
|
+
text[0].split(/\s+/g).slice(3).forEach(word => {
|
|
6882
|
+
if (!word.trim()) {
|
|
6883
|
+
return;
|
|
6884
|
+
}
|
|
6885
|
+
|
|
6886
|
+
if (!VttTextParser.parseCueSetting(cue, word, regions)) {
|
|
6887
|
+
shaka.log.warning('VTT parser encountered an invalid VTT setting: ', word, ' The setting will be ignored.');
|
|
6888
|
+
}
|
|
6889
|
+
});
|
|
6890
|
+
shaka.text.Cue.parseCuePayload(cue, styles);
|
|
6891
|
+
|
|
6892
|
+
if (id != null) {
|
|
6893
|
+
cue.id = id;
|
|
6894
|
+
}
|
|
6895
|
+
|
|
6896
|
+
return cue;
|
|
6897
|
+
}
|
|
6898
|
+
/**
|
|
6899
|
+
* Parses a WebVTT setting from the given word.
|
|
6900
|
+
*
|
|
6901
|
+
* @param {!shaka.text.Cue} cue
|
|
6902
|
+
* @param {string} word
|
|
6903
|
+
* @param {!Array<!shaka.text.CueRegion>} regions
|
|
6904
|
+
* @return {boolean} True on success.
|
|
6905
|
+
*/
|
|
6906
|
+
|
|
6907
|
+
|
|
6908
|
+
static parseCueSetting(cue, word, regions) {
|
|
6909
|
+
let results = null;
|
|
6910
|
+
|
|
6911
|
+
if (results = /^align:(start|middle|center|end|left|right)$/.exec(word)) {
|
|
6912
|
+
VttTextParser.setTextAlign_(cue, results[1]);
|
|
6913
|
+
} else if (results = /^vertical:(lr|rl)$/.exec(word)) {
|
|
6914
|
+
VttTextParser.setVerticalWritingMode_(cue, results[1]);
|
|
6915
|
+
} else if (results = /^size:([\d.]+)%$/.exec(word)) {
|
|
6916
|
+
cue.size = Number(results[1]);
|
|
6917
|
+
} else if (results = /^position:([\d.]+)%(?:,(line-left|line-right|middle|center|start|end|auto))?$/.exec(word)) {
|
|
6918
|
+
cue.position = Number(results[1]);
|
|
6919
|
+
|
|
6920
|
+
if (results[2]) {
|
|
6921
|
+
VttTextParser.setPositionAlign_(cue, results[2]);
|
|
6922
|
+
}
|
|
6923
|
+
} else if (results = /^region:(.*)$/.exec(word)) {
|
|
6924
|
+
const region = VttTextParser.getRegionById_(regions, results[1]);
|
|
6925
|
+
|
|
6926
|
+
if (region) {
|
|
6927
|
+
cue.region = region;
|
|
6928
|
+
}
|
|
6929
|
+
} else {
|
|
6930
|
+
return VttTextParser.parsedLineValueAndInterpretation_(cue, word);
|
|
6931
|
+
}
|
|
6932
|
+
|
|
6933
|
+
return true;
|
|
6934
|
+
}
|
|
6935
|
+
/**
|
|
6936
|
+
*
|
|
6937
|
+
* @param {!Array<!shaka.text.CueRegion>} regions
|
|
6938
|
+
* @param {string} id
|
|
6939
|
+
* @return {?shaka.text.CueRegion}
|
|
6940
|
+
* @private
|
|
6941
|
+
*/
|
|
6942
|
+
|
|
6943
|
+
|
|
6944
|
+
static getRegionById_(regions, id) {
|
|
6945
|
+
const regionsWithId = regions.filter(region => region.id == id);
|
|
6946
|
+
|
|
6947
|
+
if (!regionsWithId.length) {
|
|
6948
|
+
shaka.log.warning('VTT parser could not find a region with id: ', id, ' The region will be ignored.');
|
|
6949
|
+
return null;
|
|
6950
|
+
}
|
|
6951
|
+
|
|
6952
|
+
goog$1.asserts.assert(regionsWithId.length == 1, 'VTTRegion ids should be unique!');
|
|
6953
|
+
return regionsWithId[0];
|
|
6954
|
+
}
|
|
6955
|
+
/**
|
|
6956
|
+
* @param {!shaka.text.Cue} cue
|
|
6957
|
+
* @param {string} align
|
|
6958
|
+
* @private
|
|
6959
|
+
*/
|
|
6960
|
+
|
|
6961
|
+
|
|
6962
|
+
static setTextAlign_(cue, align) {
|
|
6963
|
+
const Cue = shaka.text.Cue;
|
|
6964
|
+
|
|
6965
|
+
if (align == 'middle') {
|
|
6966
|
+
cue.textAlign = Cue.textAlign.CENTER;
|
|
6967
|
+
} else {
|
|
6968
|
+
goog$1.asserts.assert(align.toUpperCase() in Cue.textAlign, `${align.toUpperCase()} Should be in Cue.textAlign values!`);
|
|
6969
|
+
cue.textAlign = Cue.textAlign[align.toUpperCase()];
|
|
6970
|
+
}
|
|
6971
|
+
}
|
|
6972
|
+
/**
|
|
6973
|
+
* @param {!shaka.text.Cue} cue
|
|
6974
|
+
* @param {string} align
|
|
6975
|
+
* @private
|
|
6976
|
+
*/
|
|
6977
|
+
|
|
6978
|
+
|
|
6979
|
+
static setPositionAlign_(cue, align) {
|
|
6980
|
+
const Cue = shaka.text.Cue;
|
|
6981
|
+
|
|
6982
|
+
if (align == 'line-left' || align == 'start') {
|
|
6983
|
+
cue.positionAlign = Cue.positionAlign.LEFT;
|
|
6984
|
+
} else if (align == 'line-right' || align == 'end') {
|
|
6985
|
+
cue.positionAlign = Cue.positionAlign.RIGHT;
|
|
6986
|
+
} else if (align == 'center' || align == 'middle') {
|
|
6987
|
+
cue.positionAlign = Cue.positionAlign.CENTER;
|
|
6988
|
+
} else {
|
|
6989
|
+
cue.positionAlign = Cue.positionAlign.AUTO;
|
|
6990
|
+
}
|
|
6991
|
+
}
|
|
6992
|
+
/**
|
|
6993
|
+
* @param {!shaka.text.Cue} cue
|
|
6994
|
+
* @param {string} value
|
|
6995
|
+
* @private
|
|
6996
|
+
*/
|
|
6997
|
+
|
|
6998
|
+
|
|
6999
|
+
static setVerticalWritingMode_(cue, value) {
|
|
7000
|
+
const Cue = shaka.text.Cue;
|
|
7001
|
+
|
|
7002
|
+
if (value == 'lr') {
|
|
7003
|
+
cue.writingMode = Cue.writingMode.VERTICAL_LEFT_TO_RIGHT;
|
|
7004
|
+
} else {
|
|
7005
|
+
cue.writingMode = Cue.writingMode.VERTICAL_RIGHT_TO_LEFT;
|
|
7006
|
+
}
|
|
7007
|
+
}
|
|
7008
|
+
/**
|
|
7009
|
+
* @param {!shaka.text.Cue} cue
|
|
7010
|
+
* @param {string} word
|
|
7011
|
+
* @return {boolean}
|
|
7012
|
+
* @private
|
|
7013
|
+
*/
|
|
7014
|
+
|
|
7015
|
+
|
|
7016
|
+
static parsedLineValueAndInterpretation_(cue, word) {
|
|
7017
|
+
const Cue = shaka.text.Cue;
|
|
7018
|
+
let results = null;
|
|
7019
|
+
|
|
7020
|
+
if (results = /^line:([\d.]+)%(?:,(start|end|center))?$/.exec(word)) {
|
|
7021
|
+
cue.lineInterpretation = Cue.lineInterpretation.PERCENTAGE;
|
|
7022
|
+
cue.line = Number(results[1]);
|
|
7023
|
+
|
|
7024
|
+
if (results[2]) {
|
|
7025
|
+
goog$1.asserts.assert(results[2].toUpperCase() in Cue.lineAlign, `${results[2].toUpperCase()} Should be in Cue.lineAlign values!`);
|
|
7026
|
+
cue.lineAlign = Cue.lineAlign[results[2].toUpperCase()];
|
|
7027
|
+
}
|
|
7028
|
+
} else if (results = /^line:(-?\d+)(?:,(start|end|center))?$/.exec(word)) {
|
|
7029
|
+
cue.lineInterpretation = Cue.lineInterpretation.LINE_NUMBER;
|
|
7030
|
+
cue.line = Number(results[1]);
|
|
7031
|
+
|
|
7032
|
+
if (results[2]) {
|
|
7033
|
+
goog$1.asserts.assert(results[2].toUpperCase() in Cue.lineAlign, `${results[2].toUpperCase()} Should be in Cue.lineAlign values!`);
|
|
7034
|
+
cue.lineAlign = Cue.lineAlign[results[2].toUpperCase()];
|
|
7035
|
+
}
|
|
7036
|
+
} else {
|
|
7037
|
+
return false;
|
|
7038
|
+
}
|
|
7039
|
+
|
|
7040
|
+
return true;
|
|
7041
|
+
}
|
|
7042
|
+
|
|
7043
|
+
}
|
|
7044
|
+
/**
|
|
7045
|
+
* @const {number}
|
|
7046
|
+
* @private
|
|
7047
|
+
*/
|
|
7048
|
+
|
|
7049
|
+
|
|
7050
|
+
VttTextParser.MPEG_TIMESCALE_ = 90000;
|
|
7051
|
+
/**
|
|
7052
|
+
* At this value, timestamps roll over in TS content.
|
|
7053
|
+
* @const {number}
|
|
7054
|
+
* @private
|
|
7055
|
+
*/
|
|
7056
|
+
|
|
7057
|
+
VttTextParser.TS_ROLLOVER_ = 0x200000000;
|
|
7058
|
+
|
|
7059
|
+
VttTextParser.register = shakaNameSpace => {
|
|
7060
|
+
shakaNameSpace.text.TextEngine.registerParser('text/vtt', () => new VttTextParser());
|
|
7061
|
+
shakaNameSpace.text.TextEngine.registerParser('text/vtt; codecs="vtt"', () => new VttTextParser());
|
|
7062
|
+
shakaNameSpace.text.TextEngine.registerParser('text/vtt; codecs="wvtt"', () => new VttTextParser());
|
|
7063
|
+
};
|
|
7064
|
+
|
|
6395
7065
|
/*! @license
|
|
6396
7066
|
* Shaka Player
|
|
6397
7067
|
* Copyright 2016 Google LLC
|
|
@@ -7281,9 +7951,13 @@ class UITextDisplayer {
|
|
|
7281
7951
|
} else if (cue.textAlign == Cue.textAlign.RIGHT || cue.textAlign == Cue.textAlign.END) {
|
|
7282
7952
|
style.width = '100%';
|
|
7283
7953
|
style.alignItems = 'end';
|
|
7284
|
-
}
|
|
7954
|
+
} // in VTT displayAlign can't be set, it defaults to 'after',
|
|
7955
|
+
// but for vertical, it should be 'before'
|
|
7285
7956
|
|
|
7286
|
-
|
|
7957
|
+
|
|
7958
|
+
if (/vertical/.test(cue.writingMode)) {
|
|
7959
|
+
style.justifyContent = 'flex-start';
|
|
7960
|
+
} else if (cue.displayAlign == Cue.displayAlign.BEFORE) {
|
|
7287
7961
|
style.justifyContent = 'flex-start';
|
|
7288
7962
|
} else if (cue.displayAlign == Cue.displayAlign.CENTER) {
|
|
7289
7963
|
style.justifyContent = 'center';
|
|
@@ -7656,6 +8330,7 @@ const loadShaka = async (videoElement, config = {}, options = {}) => {
|
|
|
7656
8330
|
return getQualityItem(activeTrack);
|
|
7657
8331
|
};
|
|
7658
8332
|
|
|
8333
|
+
VttTextParser.register(shaka);
|
|
7659
8334
|
HttpFetchPlugin.register(shaka);
|
|
7660
8335
|
const networkEngine = player.getNetworkingEngine();
|
|
7661
8336
|
networkEngine.registerRequestFilter((type, request) => extensionOptions.requestHandlers.reduce((merged, handler) => handler(type, merged, player, extensionOptions), request));
|