@kkcompany/player 2.25.0-canary.17 → 2.25.0-canary.18
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 +7 -0
- package/dist/core.mjs +658 -5
- package/dist/index.js +1316 -565
- package/dist/index.mjs +658 -5
- package/dist/modules.mjs +2 -2
- package/dist/react.mjs +659 -6
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -2420,7 +2420,7 @@ function convertToSeconds(timeString) {
|
|
|
2420
2420
|
function getVersion() {
|
|
2421
2421
|
try {
|
|
2422
2422
|
// eslint-disable-next-line no-undef
|
|
2423
|
-
return "2.25.0-canary.
|
|
2423
|
+
return "2.25.0-canary.18";
|
|
2424
2424
|
} catch (e) {
|
|
2425
2425
|
return undefined;
|
|
2426
2426
|
}
|
|
@@ -6222,7 +6222,7 @@ const makeResponse = (headers, data, status, uri, responseURL, requestType) => {
|
|
|
6222
6222
|
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);
|
|
6223
6223
|
};
|
|
6224
6224
|
|
|
6225
|
-
const goog$
|
|
6225
|
+
const goog$2 = {
|
|
6226
6226
|
asserts: {
|
|
6227
6227
|
assert: () => {}
|
|
6228
6228
|
}
|
|
@@ -6368,7 +6368,7 @@ class HttpFetchPlugin {
|
|
|
6368
6368
|
}
|
|
6369
6369
|
|
|
6370
6370
|
if (readObj.done) {
|
|
6371
|
-
goog$
|
|
6371
|
+
goog$2.asserts.assert(!readObj.value, 'readObj should be unset when "done" is true.');
|
|
6372
6372
|
controller.close();
|
|
6373
6373
|
} else {
|
|
6374
6374
|
controller.enqueue(readObj.value);
|
|
@@ -6607,6 +6607,654 @@ const fixDashManifest = (data, {
|
|
|
6607
6607
|
return new XMLSerializer().serializeToString(doc);
|
|
6608
6608
|
};
|
|
6609
6609
|
|
|
6610
|
+
/* eslint-disable no-cond-assign */
|
|
6611
|
+
|
|
6612
|
+
/* eslint-disable prefer-destructuring */
|
|
6613
|
+
|
|
6614
|
+
/*! @license
|
|
6615
|
+
* Shaka Player
|
|
6616
|
+
* Copyright 2016 Google LLC
|
|
6617
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6618
|
+
*/
|
|
6619
|
+
const goog$1 = {
|
|
6620
|
+
asserts: {
|
|
6621
|
+
assert: (condition, message) => {
|
|
6622
|
+
if (!condition) {
|
|
6623
|
+
console.warn('GOOG Assert!', message);
|
|
6624
|
+
}
|
|
6625
|
+
}
|
|
6626
|
+
}
|
|
6627
|
+
};
|
|
6628
|
+
|
|
6629
|
+
const addDefaultTextColor = styles => {
|
|
6630
|
+
const textColor = shaka.text.Cue.defaultTextColor;
|
|
6631
|
+
|
|
6632
|
+
for (const [key, value] of Object.entries(textColor)) {
|
|
6633
|
+
const cue = new shaka.text.Cue(0, 0, '');
|
|
6634
|
+
cue.color = value;
|
|
6635
|
+
styles.set(`.${key}`, cue);
|
|
6636
|
+
}
|
|
6637
|
+
|
|
6638
|
+
const bgColor = shaka.text.Cue.defaultTextBackgroundColor;
|
|
6639
|
+
|
|
6640
|
+
for (const [key, value] of Object.entries(bgColor)) {
|
|
6641
|
+
const cue = new shaka.text.Cue(0, 0, '');
|
|
6642
|
+
cue.backgroundColor = value;
|
|
6643
|
+
styles.set(`.${key}`, cue);
|
|
6644
|
+
}
|
|
6645
|
+
};
|
|
6646
|
+
|
|
6647
|
+
const parseTime = text => {
|
|
6648
|
+
var _Array$from;
|
|
6649
|
+
|
|
6650
|
+
const timeFormat = /(?:(\d{1,}):)?(\d{2}):(\d{2})((\.(\d{1,3})))?/g;
|
|
6651
|
+
const results = (_Array$from = Array.from(text.matchAll(timeFormat))) === null || _Array$from === void 0 ? void 0 : _Array$from[0];
|
|
6652
|
+
|
|
6653
|
+
if (results == null) {
|
|
6654
|
+
return null;
|
|
6655
|
+
} // This capture is optional, but will still be in the array as undefined,
|
|
6656
|
+
// in which case it is 0.
|
|
6657
|
+
|
|
6658
|
+
|
|
6659
|
+
const hours = Number(results[1]) || 0;
|
|
6660
|
+
const minutes = Number(results[2]);
|
|
6661
|
+
const seconds = Number(results[3]);
|
|
6662
|
+
const milliseconds = Number(results[6]) || 0;
|
|
6663
|
+
|
|
6664
|
+
if (minutes > 59 || seconds > 59) {
|
|
6665
|
+
return null;
|
|
6666
|
+
}
|
|
6667
|
+
|
|
6668
|
+
return milliseconds / 1000 + seconds + minutes * 60 + hours * 3600;
|
|
6669
|
+
};
|
|
6670
|
+
|
|
6671
|
+
const parseRegion = block => {
|
|
6672
|
+
if (block[0].trim() !== 'REGION') {
|
|
6673
|
+
return [];
|
|
6674
|
+
}
|
|
6675
|
+
|
|
6676
|
+
const region = new shaka.text.CueRegion();
|
|
6677
|
+
block.slice(1).forEach(word => {
|
|
6678
|
+
let results = null;
|
|
6679
|
+
|
|
6680
|
+
if (results = /^id:(.*)$/.exec(word)) {
|
|
6681
|
+
region.id = results[1];
|
|
6682
|
+
} else if (results = /^width:(\d{1,2}|100)%$/.exec(word)) {
|
|
6683
|
+
region.width = Number(results[1]);
|
|
6684
|
+
} else if (results = /^lines:(\d+)$/.exec(word)) {
|
|
6685
|
+
region.height = Number(results[1]);
|
|
6686
|
+
region.heightUnits = shaka.text.CueRegion.units.LINES;
|
|
6687
|
+
} else if (results = /^regionanchor:(\d{1,2}|100)%,(\d{1,2}|100)%$/.exec(word)) {
|
|
6688
|
+
region.regionAnchorX = Number(results[1]);
|
|
6689
|
+
region.regionAnchorY = Number(results[2]);
|
|
6690
|
+
} else if (results = /^viewportanchor:(\d{1,2}|100)%,(\d{1,2}|100)%$/.exec(word)) {
|
|
6691
|
+
region.viewportAnchorX = Number(results[1]);
|
|
6692
|
+
region.viewportAnchorY = Number(results[2]);
|
|
6693
|
+
} else if (results = /^scroll:up$/.exec(word)) {
|
|
6694
|
+
region.scroll = shaka.text.CueRegion.scrollMode.UP;
|
|
6695
|
+
} else {
|
|
6696
|
+
shaka.log.warning('VTT parser encountered an invalid VTTRegion setting: ', word, ' The setting will be ignored.');
|
|
6697
|
+
}
|
|
6698
|
+
});
|
|
6699
|
+
return [region];
|
|
6700
|
+
};
|
|
6701
|
+
/**
|
|
6702
|
+
* @implements {shaka.extern.TextParser}
|
|
6703
|
+
* @export
|
|
6704
|
+
*/
|
|
6705
|
+
|
|
6706
|
+
|
|
6707
|
+
class VttTextParser {
|
|
6708
|
+
/** Constructs a VTT parser. */
|
|
6709
|
+
constructor() {
|
|
6710
|
+
/** @private {boolean} */
|
|
6711
|
+
this.sequenceMode_ = false;
|
|
6712
|
+
/** @private {string} */
|
|
6713
|
+
|
|
6714
|
+
this.manifestType_ = shaka.media.ManifestParser.UNKNOWN;
|
|
6715
|
+
}
|
|
6716
|
+
/**
|
|
6717
|
+
* @override
|
|
6718
|
+
* @export
|
|
6719
|
+
*/
|
|
6720
|
+
|
|
6721
|
+
|
|
6722
|
+
parseInit() {
|
|
6723
|
+
goog$1.asserts.assert(false, 'VTT does not have init segments');
|
|
6724
|
+
}
|
|
6725
|
+
/**
|
|
6726
|
+
* @override
|
|
6727
|
+
* @export
|
|
6728
|
+
*/
|
|
6729
|
+
|
|
6730
|
+
|
|
6731
|
+
setSequenceMode(sequenceMode) {
|
|
6732
|
+
this.sequenceMode_ = sequenceMode;
|
|
6733
|
+
}
|
|
6734
|
+
/**
|
|
6735
|
+
* @override
|
|
6736
|
+
* @export
|
|
6737
|
+
*/
|
|
6738
|
+
|
|
6739
|
+
|
|
6740
|
+
setManifestType(manifestType) {
|
|
6741
|
+
this.manifestType_ = manifestType;
|
|
6742
|
+
}
|
|
6743
|
+
/**
|
|
6744
|
+
* @override
|
|
6745
|
+
* @export
|
|
6746
|
+
*/
|
|
6747
|
+
|
|
6748
|
+
|
|
6749
|
+
parseMedia(data, time) {
|
|
6750
|
+
// Get the input as a string. Normalize newlines to \n.
|
|
6751
|
+
let str = shaka.util.StringUtils.fromUTF8(data);
|
|
6752
|
+
str = str.replace(/\r\n|\r(?=[^\n]|$)/gm, '\n');
|
|
6753
|
+
const blocks = str.split(/\n{2,}/m);
|
|
6754
|
+
|
|
6755
|
+
if (!/^WEBVTT($|[ \t\n])/m.test(blocks[0])) {
|
|
6756
|
+
throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
|
|
6757
|
+
} // Depending on "segmentRelativeVttTiming" configuration,
|
|
6758
|
+
// "vttOffset" will correspond to either "periodStart" (default)
|
|
6759
|
+
// or "segmentStart", for segmented VTT where timings are relative
|
|
6760
|
+
// to the beginning of each segment.
|
|
6761
|
+
// NOTE: "periodStart" is the timestamp offset applied via TextEngine.
|
|
6762
|
+
// It is no longer closely tied to periods, but the name stuck around.
|
|
6763
|
+
// NOTE: This offset and the flag choosing its meaning have no effect on
|
|
6764
|
+
// HLS content, which should use X-TIMESTAMP-MAP and periodStart instead.
|
|
6765
|
+
|
|
6766
|
+
|
|
6767
|
+
let offset = time.vttOffset;
|
|
6768
|
+
|
|
6769
|
+
if (this.manifestType_ == shaka.media.ManifestParser.HLS) {
|
|
6770
|
+
// Only use 'X-TIMESTAMP-MAP' with HLS.
|
|
6771
|
+
if (blocks[0].includes('X-TIMESTAMP-MAP')) {
|
|
6772
|
+
offset = this.computeHlsOffset_(blocks[0], time);
|
|
6773
|
+
} else if (time.periodStart && time.vttOffset == time.periodStart) {
|
|
6774
|
+
// In the case where X-TIMESTAMP-MAP is not used and it is HLS, we
|
|
6775
|
+
// should not use offset unless segment-relative times are used.
|
|
6776
|
+
offset = 0;
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
|
|
6780
|
+
const regions = [];
|
|
6781
|
+
/** @type {!Map<string, !shaka.text.Cue>} */
|
|
6782
|
+
|
|
6783
|
+
const styles = new Map();
|
|
6784
|
+
addDefaultTextColor(styles); // Parse cues.
|
|
6785
|
+
|
|
6786
|
+
const ret = [];
|
|
6787
|
+
|
|
6788
|
+
for (const block of blocks.slice(1)) {
|
|
6789
|
+
const lines = block.split('\n');
|
|
6790
|
+
VttTextParser.parseStyle_(lines, styles);
|
|
6791
|
+
regions.push(...parseRegion(lines));
|
|
6792
|
+
const cue = VttTextParser.parseCue_(lines, offset, regions, styles);
|
|
6793
|
+
|
|
6794
|
+
if (cue) {
|
|
6795
|
+
ret.push(cue);
|
|
6796
|
+
}
|
|
6797
|
+
}
|
|
6798
|
+
|
|
6799
|
+
return ret;
|
|
6800
|
+
}
|
|
6801
|
+
/**
|
|
6802
|
+
* @param {string} headerBlock Contains X-TIMESTAMP-MAP.
|
|
6803
|
+
* @param {shaka.extern.TextParser.TimeContext} time
|
|
6804
|
+
* @return {number}
|
|
6805
|
+
* @private
|
|
6806
|
+
*/
|
|
6807
|
+
|
|
6808
|
+
|
|
6809
|
+
computeHlsOffset_(headerBlock, time) {
|
|
6810
|
+
// https://bit.ly/2K92l7y
|
|
6811
|
+
// The 'X-TIMESTAMP-MAP' header is used in HLS to align text with
|
|
6812
|
+
// the rest of the media.
|
|
6813
|
+
// The header format is 'X-TIMESTAMP-MAP=MPEGTS:n,LOCAL:m'
|
|
6814
|
+
// (the attributes can go in any order)
|
|
6815
|
+
// where n is MPEG-2 time and m is cue time it maps to.
|
|
6816
|
+
// For example 'X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000'
|
|
6817
|
+
// means an offset of 10 seconds
|
|
6818
|
+
// 900000/MPEG_TIMESCALE - cue time.
|
|
6819
|
+
const cueTimeMatch = headerBlock.match(/LOCAL:((?:(\d{1,}):)?(\d{2}):(\d{2})\.(\d{3}))/m);
|
|
6820
|
+
const mpegTimeMatch = headerBlock.match(/MPEGTS:(\d+)/m);
|
|
6821
|
+
|
|
6822
|
+
if (!cueTimeMatch || !mpegTimeMatch) {
|
|
6823
|
+
throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
|
|
6824
|
+
}
|
|
6825
|
+
|
|
6826
|
+
const cueTime = parseTime(cueTimeMatch[1]);
|
|
6827
|
+
|
|
6828
|
+
if (cueTime == null) {
|
|
6829
|
+
throw new shaka.util.Error(shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT, shaka.util.Error.Code.INVALID_TEXT_HEADER);
|
|
6830
|
+
}
|
|
6831
|
+
|
|
6832
|
+
let mpegTime = Number(mpegTimeMatch[1]);
|
|
6833
|
+
const mpegTimescale = VttTextParser.MPEG_TIMESCALE_;
|
|
6834
|
+
const rolloverSeconds = VttTextParser.TS_ROLLOVER_ / mpegTimescale;
|
|
6835
|
+
let segmentStart = time.segmentStart - time.periodStart;
|
|
6836
|
+
|
|
6837
|
+
while (segmentStart >= rolloverSeconds) {
|
|
6838
|
+
segmentStart -= rolloverSeconds;
|
|
6839
|
+
mpegTime += VttTextParser.TS_ROLLOVER_;
|
|
6840
|
+
}
|
|
6841
|
+
|
|
6842
|
+
return time.periodStart + mpegTime / mpegTimescale - cueTime;
|
|
6843
|
+
}
|
|
6844
|
+
/**
|
|
6845
|
+
* Parses a style block into a Cue object.
|
|
6846
|
+
*
|
|
6847
|
+
* @param {!Array<string>} text
|
|
6848
|
+
* @param {!Map<string, !shaka.text.Cue>} styles
|
|
6849
|
+
* @private
|
|
6850
|
+
*/
|
|
6851
|
+
|
|
6852
|
+
|
|
6853
|
+
static parseStyle_(text, styles) {
|
|
6854
|
+
// Skip empty blocks.
|
|
6855
|
+
if (text.length == 1 && !text[0]) {
|
|
6856
|
+
return;
|
|
6857
|
+
} // Skip comment blocks.
|
|
6858
|
+
|
|
6859
|
+
|
|
6860
|
+
if (/^NOTE($|[ \t])/.test(text[0])) {
|
|
6861
|
+
return;
|
|
6862
|
+
} // Only style block are allowed.
|
|
6863
|
+
|
|
6864
|
+
|
|
6865
|
+
if (text[0] != 'STYLE') {
|
|
6866
|
+
return;
|
|
6867
|
+
}
|
|
6868
|
+
/** @type {!Array<!Array<string>>} */
|
|
6869
|
+
|
|
6870
|
+
|
|
6871
|
+
const styleBlocks = [];
|
|
6872
|
+
let lastBlockIndex = -1;
|
|
6873
|
+
|
|
6874
|
+
for (let i = 1; i < text.length; i++) {
|
|
6875
|
+
if (text[i].includes('::cue')) {
|
|
6876
|
+
styleBlocks.push([]);
|
|
6877
|
+
lastBlockIndex = styleBlocks.length - 1;
|
|
6878
|
+
}
|
|
6879
|
+
|
|
6880
|
+
if (lastBlockIndex == -1) {
|
|
6881
|
+
continue;
|
|
6882
|
+
}
|
|
6883
|
+
|
|
6884
|
+
styleBlocks[lastBlockIndex].push(text[i]);
|
|
6885
|
+
|
|
6886
|
+
if (text[i].includes('}')) {
|
|
6887
|
+
lastBlockIndex = -1;
|
|
6888
|
+
}
|
|
6889
|
+
}
|
|
6890
|
+
|
|
6891
|
+
for (const styleBlock of styleBlocks) {
|
|
6892
|
+
let styleSelector = 'global'; // Look for what is within parentheses. For example:
|
|
6893
|
+
// <code>:: cue (b) {</code>, what we are looking for is <code>b</code>
|
|
6894
|
+
|
|
6895
|
+
const selector = styleBlock[0].match(/\((.*)\)/);
|
|
6896
|
+
|
|
6897
|
+
if (selector) {
|
|
6898
|
+
styleSelector = selector.pop();
|
|
6899
|
+
} // We start at 1 to avoid '::cue' and end earlier to avoid '}'
|
|
6900
|
+
|
|
6901
|
+
|
|
6902
|
+
let propertyLines = styleBlock.slice(1, -1);
|
|
6903
|
+
|
|
6904
|
+
if (styleBlock[0].includes('}')) {
|
|
6905
|
+
const payload = /\{(.*?)\}/.exec(styleBlock[0]);
|
|
6906
|
+
|
|
6907
|
+
if (payload) {
|
|
6908
|
+
propertyLines = payload[1].split(';');
|
|
6909
|
+
}
|
|
6910
|
+
} // Continue styles over multiple selectors if necessary.
|
|
6911
|
+
// For example,
|
|
6912
|
+
// ::cue(b) { background: white; } ::cue(b) { color: blue; }
|
|
6913
|
+
// should set both the background and foreground of bold tags.
|
|
6914
|
+
|
|
6915
|
+
|
|
6916
|
+
let cue = styles.get(styleSelector);
|
|
6917
|
+
|
|
6918
|
+
if (!cue) {
|
|
6919
|
+
cue = new shaka.text.Cue(0, 0, '');
|
|
6920
|
+
}
|
|
6921
|
+
|
|
6922
|
+
let validStyle = false;
|
|
6923
|
+
|
|
6924
|
+
for (let i = 0; i < propertyLines.length; i++) {
|
|
6925
|
+
// We look for CSS properties. As a general rule they are separated by
|
|
6926
|
+
// <code>:</code>. Eg: <code>color: red;</code>
|
|
6927
|
+
const lineParts = /^\s*([^:]+):\s*(.*)/.exec(propertyLines[i]);
|
|
6928
|
+
|
|
6929
|
+
if (lineParts) {
|
|
6930
|
+
const name = lineParts[1].trim();
|
|
6931
|
+
const value = lineParts[2].trim().replace(';', '');
|
|
6932
|
+
|
|
6933
|
+
switch (name) {
|
|
6934
|
+
case 'background-color':
|
|
6935
|
+
case 'background':
|
|
6936
|
+
validStyle = true;
|
|
6937
|
+
cue.backgroundColor = value;
|
|
6938
|
+
break;
|
|
6939
|
+
|
|
6940
|
+
case 'color':
|
|
6941
|
+
validStyle = true;
|
|
6942
|
+
cue.color = value;
|
|
6943
|
+
break;
|
|
6944
|
+
|
|
6945
|
+
case 'font-family':
|
|
6946
|
+
validStyle = true;
|
|
6947
|
+
cue.fontFamily = value;
|
|
6948
|
+
break;
|
|
6949
|
+
|
|
6950
|
+
case 'font-size':
|
|
6951
|
+
validStyle = true;
|
|
6952
|
+
cue.fontSize = value;
|
|
6953
|
+
break;
|
|
6954
|
+
|
|
6955
|
+
case 'font-weight':
|
|
6956
|
+
if (parseInt(value, 10) >= 700 || value == 'bold') {
|
|
6957
|
+
validStyle = true;
|
|
6958
|
+
cue.fontWeight = shaka.text.Cue.fontWeight.BOLD;
|
|
6959
|
+
}
|
|
6960
|
+
|
|
6961
|
+
break;
|
|
6962
|
+
|
|
6963
|
+
case 'font-style':
|
|
6964
|
+
switch (value) {
|
|
6965
|
+
case 'normal':
|
|
6966
|
+
validStyle = true;
|
|
6967
|
+
cue.fontStyle = shaka.text.Cue.fontStyle.NORMAL;
|
|
6968
|
+
break;
|
|
6969
|
+
|
|
6970
|
+
case 'italic':
|
|
6971
|
+
validStyle = true;
|
|
6972
|
+
cue.fontStyle = shaka.text.Cue.fontStyle.ITALIC;
|
|
6973
|
+
break;
|
|
6974
|
+
|
|
6975
|
+
case 'oblique':
|
|
6976
|
+
validStyle = true;
|
|
6977
|
+
cue.fontStyle = shaka.text.Cue.fontStyle.OBLIQUE;
|
|
6978
|
+
break;
|
|
6979
|
+
}
|
|
6980
|
+
|
|
6981
|
+
break;
|
|
6982
|
+
|
|
6983
|
+
case 'opacity':
|
|
6984
|
+
validStyle = true;
|
|
6985
|
+
cue.opacity = parseFloat(value);
|
|
6986
|
+
break;
|
|
6987
|
+
|
|
6988
|
+
case 'text-combine-upright':
|
|
6989
|
+
validStyle = true;
|
|
6990
|
+
cue.textCombineUpright = value;
|
|
6991
|
+
break;
|
|
6992
|
+
|
|
6993
|
+
case 'text-shadow':
|
|
6994
|
+
validStyle = true;
|
|
6995
|
+
cue.textShadow = value;
|
|
6996
|
+
break;
|
|
6997
|
+
|
|
6998
|
+
case 'white-space':
|
|
6999
|
+
validStyle = true;
|
|
7000
|
+
cue.wrapLine = value != 'noWrap';
|
|
7001
|
+
break;
|
|
7002
|
+
|
|
7003
|
+
default:
|
|
7004
|
+
shaka.log.warning('VTT parser encountered an unsupported style: ', lineParts);
|
|
7005
|
+
break;
|
|
7006
|
+
}
|
|
7007
|
+
}
|
|
7008
|
+
}
|
|
7009
|
+
|
|
7010
|
+
if (validStyle) {
|
|
7011
|
+
styles.set(styleSelector, cue);
|
|
7012
|
+
}
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
7015
|
+
/**
|
|
7016
|
+
* Parses a text block into a Cue object.
|
|
7017
|
+
*
|
|
7018
|
+
* @param {!Array<string>} text
|
|
7019
|
+
* @param {number} timeOffset
|
|
7020
|
+
* @param {!Array<!shaka.text.CueRegion>} regions
|
|
7021
|
+
* @param {!Map<string, !shaka.text.Cue>} styles
|
|
7022
|
+
* @return {shaka.text.Cue}
|
|
7023
|
+
* @private
|
|
7024
|
+
*/
|
|
7025
|
+
|
|
7026
|
+
|
|
7027
|
+
static parseCue_(text, timeOffset, regions, styles) {
|
|
7028
|
+
// Skip empty blocks.
|
|
7029
|
+
if (text.length == 1 && !text[0]) {
|
|
7030
|
+
return null;
|
|
7031
|
+
} // Skip comment blocks.
|
|
7032
|
+
|
|
7033
|
+
|
|
7034
|
+
if (/^NOTE($|[ \t])/.test(text[0])) {
|
|
7035
|
+
return null;
|
|
7036
|
+
} // Skip style and region blocks.
|
|
7037
|
+
|
|
7038
|
+
|
|
7039
|
+
if (text[0] == 'STYLE' || text[0] == 'REGION') {
|
|
7040
|
+
return null;
|
|
7041
|
+
}
|
|
7042
|
+
|
|
7043
|
+
let id = null;
|
|
7044
|
+
|
|
7045
|
+
if (!text[0].includes('-->')) {
|
|
7046
|
+
id = text[0];
|
|
7047
|
+
text.splice(0, 1);
|
|
7048
|
+
} // Parse the times.
|
|
7049
|
+
|
|
7050
|
+
|
|
7051
|
+
let [start, end] = text[0].split('-->').map(part => parseTime(part.trim()));
|
|
7052
|
+
|
|
7053
|
+
if (start == null || end == null) {
|
|
7054
|
+
shaka.log.alwaysWarn('Failed to parse VTT time code. Cue skipped:', id, text);
|
|
7055
|
+
return null;
|
|
7056
|
+
}
|
|
7057
|
+
|
|
7058
|
+
start += timeOffset;
|
|
7059
|
+
end += timeOffset; // Get the payload.
|
|
7060
|
+
|
|
7061
|
+
const payload = text.slice(1).join('\n').trim();
|
|
7062
|
+
let cue = null;
|
|
7063
|
+
|
|
7064
|
+
if (styles.has('global')) {
|
|
7065
|
+
cue = styles.get('global').clone();
|
|
7066
|
+
cue.startTime = start;
|
|
7067
|
+
cue.endTime = end;
|
|
7068
|
+
cue.payload = payload;
|
|
7069
|
+
} else {
|
|
7070
|
+
cue = new shaka.text.Cue(start, end, payload);
|
|
7071
|
+
} // Parse optional settings.
|
|
7072
|
+
|
|
7073
|
+
|
|
7074
|
+
text[0].split(/\s+/g).slice(3).forEach(word => {
|
|
7075
|
+
if (!word.trim()) {
|
|
7076
|
+
return;
|
|
7077
|
+
}
|
|
7078
|
+
|
|
7079
|
+
if (!VttTextParser.parseCueSetting(cue, word, regions)) {
|
|
7080
|
+
shaka.log.warning('VTT parser encountered an invalid VTT setting: ', word, ' The setting will be ignored.');
|
|
7081
|
+
}
|
|
7082
|
+
});
|
|
7083
|
+
shaka.text.Cue.parseCuePayload(cue, styles);
|
|
7084
|
+
|
|
7085
|
+
if (id != null) {
|
|
7086
|
+
cue.id = id;
|
|
7087
|
+
}
|
|
7088
|
+
|
|
7089
|
+
return cue;
|
|
7090
|
+
}
|
|
7091
|
+
/**
|
|
7092
|
+
* Parses a WebVTT setting from the given word.
|
|
7093
|
+
*
|
|
7094
|
+
* @param {!shaka.text.Cue} cue
|
|
7095
|
+
* @param {string} word
|
|
7096
|
+
* @param {!Array<!shaka.text.CueRegion>} regions
|
|
7097
|
+
* @return {boolean} True on success.
|
|
7098
|
+
*/
|
|
7099
|
+
|
|
7100
|
+
|
|
7101
|
+
static parseCueSetting(cue, word, regions) {
|
|
7102
|
+
let results = null;
|
|
7103
|
+
|
|
7104
|
+
if (results = /^align:(start|middle|center|end|left|right)$/.exec(word)) {
|
|
7105
|
+
VttTextParser.setTextAlign_(cue, results[1]);
|
|
7106
|
+
} else if (results = /^vertical:(lr|rl)$/.exec(word)) {
|
|
7107
|
+
VttTextParser.setVerticalWritingMode_(cue, results[1]);
|
|
7108
|
+
} else if (results = /^size:([\d.]+)%$/.exec(word)) {
|
|
7109
|
+
cue.size = Number(results[1]);
|
|
7110
|
+
} else if (results = /^position:([\d.]+)%(?:,(line-left|line-right|middle|center|start|end|auto))?$/.exec(word)) {
|
|
7111
|
+
cue.position = Number(results[1]);
|
|
7112
|
+
|
|
7113
|
+
if (results[2]) {
|
|
7114
|
+
VttTextParser.setPositionAlign_(cue, results[2]);
|
|
7115
|
+
}
|
|
7116
|
+
} else if (results = /^region:(.*)$/.exec(word)) {
|
|
7117
|
+
const region = VttTextParser.getRegionById_(regions, results[1]);
|
|
7118
|
+
|
|
7119
|
+
if (region) {
|
|
7120
|
+
cue.region = region;
|
|
7121
|
+
}
|
|
7122
|
+
} else {
|
|
7123
|
+
return VttTextParser.parsedLineValueAndInterpretation_(cue, word);
|
|
7124
|
+
}
|
|
7125
|
+
|
|
7126
|
+
return true;
|
|
7127
|
+
}
|
|
7128
|
+
/**
|
|
7129
|
+
*
|
|
7130
|
+
* @param {!Array<!shaka.text.CueRegion>} regions
|
|
7131
|
+
* @param {string} id
|
|
7132
|
+
* @return {?shaka.text.CueRegion}
|
|
7133
|
+
* @private
|
|
7134
|
+
*/
|
|
7135
|
+
|
|
7136
|
+
|
|
7137
|
+
static getRegionById_(regions, id) {
|
|
7138
|
+
const regionsWithId = regions.filter(region => region.id == id);
|
|
7139
|
+
|
|
7140
|
+
if (!regionsWithId.length) {
|
|
7141
|
+
shaka.log.warning('VTT parser could not find a region with id: ', id, ' The region will be ignored.');
|
|
7142
|
+
return null;
|
|
7143
|
+
}
|
|
7144
|
+
|
|
7145
|
+
goog$1.asserts.assert(regionsWithId.length == 1, 'VTTRegion ids should be unique!');
|
|
7146
|
+
return regionsWithId[0];
|
|
7147
|
+
}
|
|
7148
|
+
/**
|
|
7149
|
+
* @param {!shaka.text.Cue} cue
|
|
7150
|
+
* @param {string} align
|
|
7151
|
+
* @private
|
|
7152
|
+
*/
|
|
7153
|
+
|
|
7154
|
+
|
|
7155
|
+
static setTextAlign_(cue, align) {
|
|
7156
|
+
const Cue = shaka.text.Cue;
|
|
7157
|
+
|
|
7158
|
+
if (align == 'middle') {
|
|
7159
|
+
cue.textAlign = Cue.textAlign.CENTER;
|
|
7160
|
+
} else {
|
|
7161
|
+
goog$1.asserts.assert(align.toUpperCase() in Cue.textAlign, `${align.toUpperCase()} Should be in Cue.textAlign values!`);
|
|
7162
|
+
cue.textAlign = Cue.textAlign[align.toUpperCase()];
|
|
7163
|
+
}
|
|
7164
|
+
}
|
|
7165
|
+
/**
|
|
7166
|
+
* @param {!shaka.text.Cue} cue
|
|
7167
|
+
* @param {string} align
|
|
7168
|
+
* @private
|
|
7169
|
+
*/
|
|
7170
|
+
|
|
7171
|
+
|
|
7172
|
+
static setPositionAlign_(cue, align) {
|
|
7173
|
+
const Cue = shaka.text.Cue;
|
|
7174
|
+
|
|
7175
|
+
if (align == 'line-left' || align == 'start') {
|
|
7176
|
+
cue.positionAlign = Cue.positionAlign.LEFT;
|
|
7177
|
+
} else if (align == 'line-right' || align == 'end') {
|
|
7178
|
+
cue.positionAlign = Cue.positionAlign.RIGHT;
|
|
7179
|
+
} else if (align == 'center' || align == 'middle') {
|
|
7180
|
+
cue.positionAlign = Cue.positionAlign.CENTER;
|
|
7181
|
+
} else {
|
|
7182
|
+
cue.positionAlign = Cue.positionAlign.AUTO;
|
|
7183
|
+
}
|
|
7184
|
+
}
|
|
7185
|
+
/**
|
|
7186
|
+
* @param {!shaka.text.Cue} cue
|
|
7187
|
+
* @param {string} value
|
|
7188
|
+
* @private
|
|
7189
|
+
*/
|
|
7190
|
+
|
|
7191
|
+
|
|
7192
|
+
static setVerticalWritingMode_(cue, value) {
|
|
7193
|
+
const Cue = shaka.text.Cue;
|
|
7194
|
+
|
|
7195
|
+
if (value == 'lr') {
|
|
7196
|
+
cue.writingMode = Cue.writingMode.VERTICAL_LEFT_TO_RIGHT;
|
|
7197
|
+
} else {
|
|
7198
|
+
cue.writingMode = Cue.writingMode.VERTICAL_RIGHT_TO_LEFT;
|
|
7199
|
+
}
|
|
7200
|
+
}
|
|
7201
|
+
/**
|
|
7202
|
+
* @param {!shaka.text.Cue} cue
|
|
7203
|
+
* @param {string} word
|
|
7204
|
+
* @return {boolean}
|
|
7205
|
+
* @private
|
|
7206
|
+
*/
|
|
7207
|
+
|
|
7208
|
+
|
|
7209
|
+
static parsedLineValueAndInterpretation_(cue, word) {
|
|
7210
|
+
const Cue = shaka.text.Cue;
|
|
7211
|
+
let results = null;
|
|
7212
|
+
|
|
7213
|
+
if (results = /^line:([\d.]+)%(?:,(start|end|center))?$/.exec(word)) {
|
|
7214
|
+
cue.lineInterpretation = Cue.lineInterpretation.PERCENTAGE;
|
|
7215
|
+
cue.line = Number(results[1]);
|
|
7216
|
+
|
|
7217
|
+
if (results[2]) {
|
|
7218
|
+
goog$1.asserts.assert(results[2].toUpperCase() in Cue.lineAlign, `${results[2].toUpperCase()} Should be in Cue.lineAlign values!`);
|
|
7219
|
+
cue.lineAlign = Cue.lineAlign[results[2].toUpperCase()];
|
|
7220
|
+
}
|
|
7221
|
+
} else if (results = /^line:(-?\d+)(?:,(start|end|center))?$/.exec(word)) {
|
|
7222
|
+
cue.lineInterpretation = Cue.lineInterpretation.LINE_NUMBER;
|
|
7223
|
+
cue.line = Number(results[1]);
|
|
7224
|
+
|
|
7225
|
+
if (results[2]) {
|
|
7226
|
+
goog$1.asserts.assert(results[2].toUpperCase() in Cue.lineAlign, `${results[2].toUpperCase()} Should be in Cue.lineAlign values!`);
|
|
7227
|
+
cue.lineAlign = Cue.lineAlign[results[2].toUpperCase()];
|
|
7228
|
+
}
|
|
7229
|
+
} else {
|
|
7230
|
+
return false;
|
|
7231
|
+
}
|
|
7232
|
+
|
|
7233
|
+
return true;
|
|
7234
|
+
}
|
|
7235
|
+
|
|
7236
|
+
}
|
|
7237
|
+
/**
|
|
7238
|
+
* @const {number}
|
|
7239
|
+
* @private
|
|
7240
|
+
*/
|
|
7241
|
+
|
|
7242
|
+
|
|
7243
|
+
VttTextParser.MPEG_TIMESCALE_ = 90000;
|
|
7244
|
+
/**
|
|
7245
|
+
* At this value, timestamps roll over in TS content.
|
|
7246
|
+
* @const {number}
|
|
7247
|
+
* @private
|
|
7248
|
+
*/
|
|
7249
|
+
|
|
7250
|
+
VttTextParser.TS_ROLLOVER_ = 0x200000000;
|
|
7251
|
+
|
|
7252
|
+
VttTextParser.register = shakaNameSpace => {
|
|
7253
|
+
shakaNameSpace.text.TextEngine.registerParser('text/vtt', () => new VttTextParser());
|
|
7254
|
+
shakaNameSpace.text.TextEngine.registerParser('text/vtt; codecs="vtt"', () => new VttTextParser());
|
|
7255
|
+
shakaNameSpace.text.TextEngine.registerParser('text/vtt; codecs="wvtt"', () => new VttTextParser());
|
|
7256
|
+
};
|
|
7257
|
+
|
|
6610
7258
|
/*! @license
|
|
6611
7259
|
* Shaka Player
|
|
6612
7260
|
* Copyright 2016 Google LLC
|
|
@@ -7496,9 +8144,13 @@ class UITextDisplayer {
|
|
|
7496
8144
|
} else if (cue.textAlign == Cue.textAlign.RIGHT || cue.textAlign == Cue.textAlign.END) {
|
|
7497
8145
|
style.width = '100%';
|
|
7498
8146
|
style.alignItems = 'end';
|
|
7499
|
-
}
|
|
8147
|
+
} // in VTT displayAlign can't be set, it defaults to 'after',
|
|
8148
|
+
// but for vertical, it should be 'before'
|
|
7500
8149
|
|
|
7501
|
-
|
|
8150
|
+
|
|
8151
|
+
if (/vertical/.test(cue.writingMode)) {
|
|
8152
|
+
style.justifyContent = 'flex-start';
|
|
8153
|
+
} else if (cue.displayAlign == Cue.displayAlign.BEFORE) {
|
|
7502
8154
|
style.justifyContent = 'flex-start';
|
|
7503
8155
|
} else if (cue.displayAlign == Cue.displayAlign.CENTER) {
|
|
7504
8156
|
style.justifyContent = 'center';
|
|
@@ -7871,6 +8523,7 @@ const loadShaka = async (videoElement, config = {}, options = {}) => {
|
|
|
7871
8523
|
return getQualityItem(activeTrack);
|
|
7872
8524
|
};
|
|
7873
8525
|
|
|
8526
|
+
VttTextParser.register(shaka);
|
|
7874
8527
|
HttpFetchPlugin.register(shaka);
|
|
7875
8528
|
const networkEngine = player.getNetworkingEngine();
|
|
7876
8529
|
networkEngine.registerRequestFilter((type, request) => extensionOptions.requestHandlers.reduce((merged, handler) => handler(type, merged, player, extensionOptions), request));
|
|
@@ -11158,7 +11811,7 @@ const PremiumPlusPlayer = ({
|
|
|
11158
11811
|
const restPlayerName = ['shaka', 'bitmovin'].find(name => name in rest);
|
|
11159
11812
|
logTarget.current = mapLogEvents({
|
|
11160
11813
|
playerName: restPlayerName || 'shaka',
|
|
11161
|
-
version: "2.25.0-canary.
|
|
11814
|
+
version: "2.25.0-canary.18",
|
|
11162
11815
|
video: videoRef.current,
|
|
11163
11816
|
getPlaybackStatus: () => getMediaTime(videoRef.current, {
|
|
11164
11817
|
player: corePlayerRef.current,
|