j1-template 2024.3.23 → 2024.3.24
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.
- checksums.yaml +4 -4
- data/assets/data/gallery_app.html +102 -14
- data/assets/theme/j1/adapter/js/gallery.js +13 -2
- data/assets/theme/j1/core/css/themes/unolight/bootstrap.css +29 -0
- data/assets/theme/j1/core/css/themes/unolight/bootstrap.min.css +1 -1
- data/assets/theme/j1/core/css/vendor.css +1 -1
- data/assets/theme/j1/core/css/vendor.min.css +1 -1
- data/assets/theme/j1/modules/lightGallery/js/lightgallery.js +36 -17
- data/assets/theme/j1/modules/lightGallery/js/lightgallery.min.js +1 -8
- data/assets/theme/j1/modules/lightGallery/js/plugins/lg-video.js +423 -297
- data/assets/theme/j1/modules/lightGallery/js/plugins/lg-video.min.js +1 -8
- data/assets/theme/j1/modules/rtable/css/theme/uno/rtable.css +11 -1
- data/assets/theme/j1/modules/videojs/css/themes/uno.css +41 -29
- data/assets/theme/j1/modules/videojs/css/themes/uno.min.css +1 -1
- data/assets/theme/j1/modules/videojs/plugins/controls/aspect-ratio-panel/!examples/index.html +4 -9
- data/assets/theme/j1/modules/videojs/plugins/controls/hotkeys/!examples/example.html +1 -1
- data/assets/theme/j1/modules/videojs/plugins/controls/persist-settings/!examples/index.html +3 -7
- data/assets/theme/j1/modules/videojs/plugins/controls/playbackrate-adjuster/!examples/index.html +3 -8
- data/assets/theme/j1/modules/videojs/plugins/players/dm/!examples/dailymotion-controls.html +4 -4
- data/assets/theme/j1/modules/videojs/plugins/players/dm/!examples/dailymotion-javascript.html +3 -3
- data/assets/theme/j1/modules/videojs/plugins/players/dm/!examples/dailymotion-playlist.html +3 -3
- data/assets/theme/j1/modules/videojs/plugins/players/dm/!examples/global-parameters.html +3 -3
- data/assets/theme/j1/modules/videojs/plugins/players/dm/!examples/simple.html +15 -4
- data/assets/theme/j1/modules/videojs/plugins/players/dm/!examples/switch.html +3 -3
- data/assets/theme/j1/modules/videojs/plugins/players/vm/!examples/index.html +3 -3
- data/assets/theme/j1/modules/videojs/plugins/players/vm/!examples/player/index.html +3 -3
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/global-parameters.html +5 -5
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/simple.html +5 -5
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/switch.html +5 -5
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/youtube-controls.html +5 -5
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/youtube-javascript.html +5 -5
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/youtube-list.html +5 -5
- data/assets/theme/j1/modules/videojs/plugins/players/yt/!examples/youtube-playlist.html +5 -5
- data/lib/j1/version.rb +1 -1
- data/lib/starter_web/README.md +5 -5
- data/lib/starter_web/_config.yml +1 -1
- data/lib/starter_web/_data/blocks/banner.yml +2 -2
- data/lib/starter_web/_data/modules/attics.yml +11 -0
- data/lib/starter_web/_data/modules/carousel.yml +1 -1
- data/lib/starter_web/_data/modules/defaults/masonry.yml +115 -22
- data/lib/starter_web/_data/modules/gallery.yml +163 -215
- data/lib/starter_web/_data/modules/masonry.yml +6 -0
- data/lib/starter_web/_data/templates/feed.xml +1 -1
- data/lib/starter_web/_includes/attributes.asciidoc +7 -0
- data/lib/starter_web/_plugins/index/lunr.rb +1 -1
- data/lib/starter_web/assets/image/module/attic/1920x1280/alexander-redl.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/alexander-shatov.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/alexey-ruban.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/andrea-badino.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/bootstrap-modal.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/bp-miller.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/brad-neathery.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/brigitta-schneiter.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/build-with-gemini.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/clem-onojeghuo.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/crawford-jolly.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/eleni-afiontzi.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/fly-d.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/guillaume-bolduc.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/ideas-start-here-1920x1280.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/isaac-davis.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/j1-content-mockup-2.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/j1-content-mockup-3.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/j1-starter-mockup-1.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/john-schnobrich-2.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/josep-martins.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/josh-liu.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/kelly-sikkemal.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/kira-auf-der-heide.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/kristopher-roller.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/markus-spiske.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/martin-sanchez.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/material_symbols.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/matthaeus.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/melanie-deziel.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/milad-fakurian.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/mohammad-rahmani.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/nasa.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/quino-al-2.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/stories-ink-tattoo-care.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/towfiqu-barbhuiya.jpg +0 -0
- data/lib/starter_web/assets/image/page/tour/bootswatch-themes.jpg +0 -0
- data/lib/starter_web/index.html +3 -2
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/public/panels/intro_panel/_includes/attributes.asciidoc +1 -1
- data/lib/starter_web/pages/public/tools/previewer/preview_bootstrap_theme.adoc +5 -5
- data/lib/starter_web/pages/public/tools/tester/app_tester_amplitudejs_yt.adoc +7 -3
- data/lib/starter_web/pages/public/tools/tester/app_tester_swiperjs.adoc +7 -3
- data/lib/starter_web/pages/public/tools/tester/videojs_macro_tester.adoc +18 -3
- data/lib/starter_web/pages/public/tour/_includes/attributes.asciidoc +1 -2
- data/lib/starter_web/pages/public/tour/_includes/documents/themes_bootstrap.asciidoc +1 -1
- data/lib/starter_web/pages/public/tour/asciidoc_extensions.adoc +7 -3
- data/lib/starter_web/pages/public/tour/bootstrap_themes.adoc +62 -7
- data/lib/starter_web/pages/public/tour/icon_fonts.adoc +4 -8
- data/lib/starter_web/pages/public/tour/modal_extentions.adoc +2 -2
- data/lib/starter_web/pages/public/tour/responsive_tables.adoc +21 -15
- data/lib/starter_web/pages/public/tour/typography.adoc +5 -5
- data/lib/starter_web/pages/public/tour/video_data.adoc +24 -5
- metadata +11 -102
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/lg-transitions.css +0 -984
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/lg-transitions.min.css +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/lightgallery-bundle.css +0 -1627
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/lightgallery-bundle.min.css +0 -25
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/animation-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/customize-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/dynamic-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/facebook-icon.svg +0 -10
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/googleplus-icon.svg +0 -30
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/html5-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/linked-in.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/module-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/play-button-hover.svg +0 -94
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/play-button.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/play-button.svg +0 -93
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/responsive-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/thumb-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/touch-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/twitter-icon.svg +0 -15
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/twitter.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/video1-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/zoom-w.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/icons/zoom.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/uno.css +0 -140
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/css/themes/uno/uno.min.css +0 -19
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/fonts/lg.svg +0 -54
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/fonts/lg.ttf +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/fonts/lg.woff +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/fonts/lg.woff2 +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/images/loading.gif +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/img/loading.gif +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/img/video-play.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/img/vimeo-play.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/img/youtube-play.png +0 -0
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/lightgallery.js +0 -2782
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/lightgallery.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/parser/webvtt/LICENSE.md +0 -44
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/parser/webvtt/README.md +0 -37
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/parser/webvtt/parser.js +0 -890
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/parser/webvtt/parser.min.js +0 -8
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/j1/j1-video.js +0 -402
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/j1/j1-video.min.js +0 -7
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/j1/lg-video.1.js +0 -585
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-autoplay.js +0 -275
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-autoplay.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-comment.js +0 -230
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-comment.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-fullscreen.js +0 -160
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-fullscreen.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-hash.js +0 -223
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-hash.min.js +0 -27
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-medium-zoom.js +0 -157
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-medium-zoom.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-pager.js +0 -164
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-pager.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-rotate.js +0 -299
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-rotate.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-share.js +0 -244
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-share.min.js +0 -27
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-thumbnail.js +0 -509
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-thumbnail.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-video.js +0 -909
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-video.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-vimeo-thumbnail.js +0 -207
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-vimeo-thumbnail.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-zoom.js +0 -999
- data/assets/theme/j1/modules/lightGallery/!v2.7.2/js/plugins/lg-zoom.min.js +0 -26
- data/assets/theme/j1/modules/lightGallery/js/plugins/j1/lg-thumbnail.0.js +0 -495
- data/assets/theme/j1/modules/lightGallery/js/plugins/j1/lg-thumbnail.1.js +0 -513
- data/assets/theme/j1/modules/lightGallery/js/plugins/j1/lg-video.0.js +0 -553
- data/assets/theme/j1/modules/lightGallery/js/plugins/j1/lg-video.1.js +0 -585
- data/assets/theme/j1/modules/lightGallery/js/plugins/j1/lg-video.2.js +0 -914
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/font/README.md +0 -151
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/font/VideoJS.svg +0 -150
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/font/video-js-cdn.css +0 -2012
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/city.css +0 -147
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/city.min.css +0 -5
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/fantasy.css +0 -113
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/fantasy.min.css +0 -5
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/forest.css +0 -166
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/forest.min.css +0 -5
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/sea.css +0 -72
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/sea.min.css +0 -5
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/uno.css +0 -311
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/themes/uno.min.css +0 -19
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/videojs.css +0 -1686
- data/assets/theme/j1/modules/videojs/!v8.12.0/css/videojs.min.css +0 -13
- data/assets/theme/j1/modules/videojs/!v8.12.0/js/video.js +0 -65226
- data/assets/theme/j1/modules/videojs/!v8.12.0/js/video.min.js +0 -55
- data/lib/starter_web/_data/modules/gallery_app.yml +0 -1002
- data/lib/starter_web/_data/modules/gallery_playlists.yml +0 -534
- data/lib/starter_web/assets/image/module/attic/1920x1280/alina-grubnyak.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/bruno-figueiredo.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/harpal-singh.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/hayden-mills-2.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/j1-content-mockup-1.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/recha-oktaviani.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/1920x1280/tiny_desk.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/ideas-start-here-1920x1280-bw.jpg +0 -0
- data/lib/starter_web/assets/image/module/attic/ideas-start-here-1920x1280.jpg +0 -0
@@ -1,890 +0,0 @@
|
|
1
|
-
// https://github.com/w3c/webvtt.js
|
2
|
-
//
|
3
|
-
// Any copyright is dedicated to the Public Domain.
|
4
|
-
// http://creativecommons.org/publicdomain/zero/1.0/
|
5
|
-
|
6
|
-
// Not intended to be fast, but if you can make it faster, please help out!
|
7
|
-
|
8
|
-
(function () {
|
9
|
-
var defaultCueSettings = {
|
10
|
-
direction:"horizontal",
|
11
|
-
snapToLines:true,
|
12
|
-
linePosition:"auto",
|
13
|
-
lineAlign:"start",
|
14
|
-
textPosition:"auto",
|
15
|
-
positionAlign:"auto",
|
16
|
-
size:100,
|
17
|
-
alignment:"center",
|
18
|
-
};
|
19
|
-
|
20
|
-
var WebVTTParser = function(entities) {
|
21
|
-
if (!entities) {
|
22
|
-
entities = {
|
23
|
-
"&": "&",
|
24
|
-
"<": "<",
|
25
|
-
">": ">",
|
26
|
-
"&lrm": "\u200e",
|
27
|
-
"&rlm": "\u200f",
|
28
|
-
" ": "\u00A0"
|
29
|
-
}
|
30
|
-
}
|
31
|
-
this.entities = entities
|
32
|
-
this.parse = function(input, mode) {
|
33
|
-
// global search and replace for \0
|
34
|
-
input = input.replace(/\0/g, '\uFFFD');
|
35
|
-
var NEWLINE = /\r\n|\r|\n/,
|
36
|
-
startTime = Date.now(),
|
37
|
-
linePos = 0,
|
38
|
-
lines = input.split(NEWLINE),
|
39
|
-
alreadyCollected = false,
|
40
|
-
styles = [],
|
41
|
-
cues = [],
|
42
|
-
errors = []
|
43
|
-
function err(message, col) {
|
44
|
-
errors.push({message:message, line:linePos+1, col:col})
|
45
|
-
}
|
46
|
-
|
47
|
-
var line = lines[linePos],
|
48
|
-
lineLength = line.length,
|
49
|
-
signature = "WEBVTT",
|
50
|
-
bom = 0,
|
51
|
-
signature_length = signature.length
|
52
|
-
|
53
|
-
/* Byte order mark */
|
54
|
-
if (line[0] === "\ufeff") {
|
55
|
-
bom = 1
|
56
|
-
signature_length += 1
|
57
|
-
}
|
58
|
-
/* SIGNATURE */
|
59
|
-
if (
|
60
|
-
lineLength < signature_length ||
|
61
|
-
line.indexOf(signature) !== 0+bom ||
|
62
|
-
lineLength > signature_length &&
|
63
|
-
line[signature_length] !== " " &&
|
64
|
-
line[signature_length] !== "\t"
|
65
|
-
) {
|
66
|
-
err("No valid signature. (File needs to start with \"WEBVTT\".)")
|
67
|
-
}
|
68
|
-
|
69
|
-
linePos++
|
70
|
-
|
71
|
-
/* HEADER */
|
72
|
-
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
73
|
-
err("No blank line after the signature.")
|
74
|
-
if(lines[linePos].indexOf("-->") != -1) {
|
75
|
-
alreadyCollected = true
|
76
|
-
break
|
77
|
-
}
|
78
|
-
linePos++
|
79
|
-
}
|
80
|
-
|
81
|
-
/* CUE LOOP */
|
82
|
-
while(lines[linePos] != undefined) {
|
83
|
-
var cue
|
84
|
-
while(!alreadyCollected && lines[linePos] == "") {
|
85
|
-
linePos++
|
86
|
-
}
|
87
|
-
if(!alreadyCollected && lines[linePos] == undefined)
|
88
|
-
break
|
89
|
-
|
90
|
-
/* CUE CREATION */
|
91
|
-
cue = Object.assign({}, defaultCueSettings, {
|
92
|
-
id:"",
|
93
|
-
startTime:0,
|
94
|
-
endTime:0,
|
95
|
-
pauseOnExit:false,
|
96
|
-
direction:"horizontal",
|
97
|
-
snapToLines:true,
|
98
|
-
linePosition:"auto",
|
99
|
-
lineAlign:"start",
|
100
|
-
textPosition:"auto",
|
101
|
-
positionAlign:"auto",
|
102
|
-
size:100,
|
103
|
-
alignment:"center",
|
104
|
-
text:"",
|
105
|
-
tree:null
|
106
|
-
})
|
107
|
-
|
108
|
-
var parseTimings = true
|
109
|
-
|
110
|
-
if(lines[linePos].indexOf("-->") == -1) {
|
111
|
-
cue.id = lines[linePos]
|
112
|
-
|
113
|
-
/* COMMENTS
|
114
|
-
Not part of the specification's parser as these would just be ignored. However,
|
115
|
-
we want them to be conforming and not get "Cue identifier cannot be standalone".
|
116
|
-
*/
|
117
|
-
if(/^NOTE($|[ \t])/.test(cue.id)) { // .startsWith fails in Chrome
|
118
|
-
linePos++
|
119
|
-
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
120
|
-
if(lines[linePos].indexOf("-->") != -1)
|
121
|
-
err("Cannot have timestamp in a comment.")
|
122
|
-
linePos++
|
123
|
-
}
|
124
|
-
continue
|
125
|
-
}
|
126
|
-
|
127
|
-
/* STYLES */
|
128
|
-
if(/^STYLE($|[ \t])/.test(cue.id)) {
|
129
|
-
var style = []
|
130
|
-
var invalid = false
|
131
|
-
linePos++
|
132
|
-
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
133
|
-
if(lines[linePos].indexOf("-->") != -1) {
|
134
|
-
err("Cannot have timestamp in a style block.")
|
135
|
-
invalid = true
|
136
|
-
}
|
137
|
-
style.push(lines[linePos])
|
138
|
-
linePos++
|
139
|
-
}
|
140
|
-
if(cues.length) {
|
141
|
-
err("Style blocks cannot appear after the first cue.")
|
142
|
-
continue
|
143
|
-
}
|
144
|
-
if (!invalid) {
|
145
|
-
styles.push(style.join('\n'))
|
146
|
-
}
|
147
|
-
continue
|
148
|
-
}
|
149
|
-
|
150
|
-
linePos++
|
151
|
-
|
152
|
-
if(lines[linePos] == "" || lines[linePos] == undefined) {
|
153
|
-
err("Cue identifier cannot be standalone.")
|
154
|
-
continue
|
155
|
-
}
|
156
|
-
|
157
|
-
if(lines[linePos].indexOf("-->") == -1) {
|
158
|
-
parseTimings = false
|
159
|
-
err("Cue identifier needs to be followed by timestamp.")
|
160
|
-
continue
|
161
|
-
}
|
162
|
-
}
|
163
|
-
|
164
|
-
/* TIMINGS */
|
165
|
-
alreadyCollected = false
|
166
|
-
var timings = new WebVTTCueTimingsAndSettingsParser(lines[linePos], err)
|
167
|
-
var previousCueStart = 0
|
168
|
-
if(cues.length > 0) {
|
169
|
-
previousCueStart = cues[cues.length-1].startTime
|
170
|
-
}
|
171
|
-
if(parseTimings && !timings.parse(cue, previousCueStart)) {
|
172
|
-
/* BAD CUE */
|
173
|
-
|
174
|
-
cue = null
|
175
|
-
linePos++
|
176
|
-
|
177
|
-
/* BAD CUE LOOP */
|
178
|
-
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
179
|
-
if(lines[linePos].indexOf("-->") != -1) {
|
180
|
-
alreadyCollected = true
|
181
|
-
break
|
182
|
-
}
|
183
|
-
linePos++
|
184
|
-
}
|
185
|
-
continue
|
186
|
-
}
|
187
|
-
linePos++
|
188
|
-
|
189
|
-
/* CUE TEXT LOOP */
|
190
|
-
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
191
|
-
if(lines[linePos].indexOf("-->") != -1) {
|
192
|
-
err("Blank line missing before cue.")
|
193
|
-
alreadyCollected = true
|
194
|
-
break
|
195
|
-
}
|
196
|
-
if(cue.text != "")
|
197
|
-
cue.text += "\n"
|
198
|
-
cue.text += lines[linePos]
|
199
|
-
linePos++
|
200
|
-
}
|
201
|
-
|
202
|
-
/* CUE TEXT PROCESSING */
|
203
|
-
var cuetextparser = new WebVTTCueTextParser(cue.text, err, mode, entities)
|
204
|
-
cue.tree = cuetextparser.parse(cue.startTime, cue.endTime)
|
205
|
-
cues.push(cue)
|
206
|
-
}
|
207
|
-
cues.sort(function(a, b) {
|
208
|
-
if (a.startTime < b.startTime)
|
209
|
-
return -1
|
210
|
-
if (a.startTime > b.startTime)
|
211
|
-
return 1
|
212
|
-
if (a.endTime > b.endTime)
|
213
|
-
return -1
|
214
|
-
if (a.endTime < b.endTime)
|
215
|
-
return 1
|
216
|
-
return 0
|
217
|
-
})
|
218
|
-
/* END */
|
219
|
-
return {cues:cues, errors:errors, time:Date.now()-startTime, styles: styles}
|
220
|
-
}
|
221
|
-
}
|
222
|
-
|
223
|
-
var WebVTTCueTimingsAndSettingsParser = function(line, errorHandler) {
|
224
|
-
var SPACE = /[\u0020\t\f]/,
|
225
|
-
NOSPACE = /[^\u0020\t\f]/,
|
226
|
-
line = line,
|
227
|
-
pos = 0,
|
228
|
-
err = function(message) {
|
229
|
-
errorHandler(message, pos+1)
|
230
|
-
},
|
231
|
-
spaceBeforeSetting = true
|
232
|
-
function skip(pattern) {
|
233
|
-
while(
|
234
|
-
line[pos] != undefined &&
|
235
|
-
pattern.test(line[pos])
|
236
|
-
) {
|
237
|
-
pos++
|
238
|
-
}
|
239
|
-
}
|
240
|
-
function collect(pattern) {
|
241
|
-
var str = ""
|
242
|
-
while(
|
243
|
-
line[pos] != undefined &&
|
244
|
-
pattern.test(line[pos])
|
245
|
-
) {
|
246
|
-
str += line[pos]
|
247
|
-
pos++
|
248
|
-
}
|
249
|
-
return str
|
250
|
-
}
|
251
|
-
/* http://dev.w3.org/html5/webvtt/#collect-a-webvtt-timestamp */
|
252
|
-
function timestamp() {
|
253
|
-
var units = "minutes",
|
254
|
-
val1,
|
255
|
-
val2,
|
256
|
-
val3,
|
257
|
-
val4
|
258
|
-
// 3
|
259
|
-
if(line[pos] == undefined) {
|
260
|
-
err("No timestamp found.")
|
261
|
-
return
|
262
|
-
}
|
263
|
-
// 4
|
264
|
-
if(!/\d/.test(line[pos])) {
|
265
|
-
err("Timestamp must start with a character in the range 0-9.")
|
266
|
-
return
|
267
|
-
}
|
268
|
-
// 5-7
|
269
|
-
val1 = collect(/\d/)
|
270
|
-
if(val1.length > 2 || parseInt(val1, 10) > 59) {
|
271
|
-
units = "hours"
|
272
|
-
}
|
273
|
-
// 8
|
274
|
-
if(line[pos] != ":") {
|
275
|
-
err("No time unit separator found.")
|
276
|
-
return
|
277
|
-
}
|
278
|
-
pos++
|
279
|
-
// 9-11
|
280
|
-
val2 = collect(/\d/)
|
281
|
-
if(val2.length != 2) {
|
282
|
-
err("Must be exactly two digits.")
|
283
|
-
return
|
284
|
-
}
|
285
|
-
// 12
|
286
|
-
if(units == "hours" || line[pos] == ":") {
|
287
|
-
if(line[pos] != ":") {
|
288
|
-
err("No seconds found or minutes is greater than 59.")
|
289
|
-
return
|
290
|
-
}
|
291
|
-
pos++
|
292
|
-
val3 = collect(/\d/)
|
293
|
-
if(val3.length != 2) {
|
294
|
-
err("Must be exactly two digits.")
|
295
|
-
return
|
296
|
-
}
|
297
|
-
} else {
|
298
|
-
if (val1.length != 2) {
|
299
|
-
err("Must be exactly two digits.")
|
300
|
-
return
|
301
|
-
}
|
302
|
-
val3 = val2
|
303
|
-
val2 = val1
|
304
|
-
val1 = "0"
|
305
|
-
}
|
306
|
-
// 13
|
307
|
-
if(line[pos] != ".") {
|
308
|
-
err("No decimal separator (\".\") found.")
|
309
|
-
return
|
310
|
-
}
|
311
|
-
pos++
|
312
|
-
// 14-16
|
313
|
-
val4 = collect(/\d/)
|
314
|
-
if(val4.length != 3) {
|
315
|
-
err("Milliseconds must be given in three digits.")
|
316
|
-
return
|
317
|
-
}
|
318
|
-
// 17
|
319
|
-
if(parseInt(val2, 10) > 59) {
|
320
|
-
err("You cannot have more than 59 minutes.")
|
321
|
-
return
|
322
|
-
}
|
323
|
-
if(parseInt(val3, 10) > 59) {
|
324
|
-
err("You cannot have more than 59 seconds.")
|
325
|
-
return
|
326
|
-
}
|
327
|
-
return parseInt(val1, 10) * 60 * 60 + parseInt(val2, 10) * 60 + parseInt(val3, 10) + parseInt(val4, 10) / 1000
|
328
|
-
}
|
329
|
-
|
330
|
-
/* http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings */
|
331
|
-
function parseSettings(input, cue) {
|
332
|
-
var settings = input.split(SPACE),
|
333
|
-
seen = []
|
334
|
-
for(var i=0; i < settings.length; i++) {
|
335
|
-
if(settings[i] == "")
|
336
|
-
continue
|
337
|
-
|
338
|
-
var index = settings[i].indexOf(':'),
|
339
|
-
setting = settings[i].slice(0, index),
|
340
|
-
value = settings[i].slice(index + 1)
|
341
|
-
|
342
|
-
if(seen.indexOf(setting) != -1) {
|
343
|
-
err("Duplicate setting.")
|
344
|
-
}
|
345
|
-
seen.push(setting)
|
346
|
-
|
347
|
-
if(value == "") {
|
348
|
-
err("No value for setting defined.")
|
349
|
-
return
|
350
|
-
}
|
351
|
-
|
352
|
-
if(setting == "vertical") { // writing direction
|
353
|
-
if(value != "rl" && value != "lr") {
|
354
|
-
err("Writing direction can only be set to 'rl' or 'rl'.")
|
355
|
-
continue
|
356
|
-
}
|
357
|
-
cue.direction = value
|
358
|
-
} else if(setting == "line") { // line position and optionally line alignment
|
359
|
-
if (/,/.test(value)) {
|
360
|
-
var comp = value.split(',')
|
361
|
-
value = comp[0]
|
362
|
-
var lineAlign = comp[1]
|
363
|
-
}
|
364
|
-
if(!/^[-\d](\d*)(\.\d+)?%?$/.test(value)) {
|
365
|
-
err("Line position takes a number or percentage.")
|
366
|
-
continue
|
367
|
-
}
|
368
|
-
if(value.indexOf("-", 1) != -1) {
|
369
|
-
err("Line position can only have '-' at the start.")
|
370
|
-
continue
|
371
|
-
}
|
372
|
-
if(value.indexOf("%") != -1 && value.indexOf("%") != value.length-1) {
|
373
|
-
err("Line position can only have '%' at the end.")
|
374
|
-
continue
|
375
|
-
}
|
376
|
-
if(value[0] == "-" && value[value.length-1] == "%") {
|
377
|
-
err("Line position cannot be a negative percentage.")
|
378
|
-
continue
|
379
|
-
}
|
380
|
-
var numVal = value;
|
381
|
-
var isPercent = false;
|
382
|
-
if(value[value.length-1] == "%") {
|
383
|
-
isPercent = true;
|
384
|
-
numVal = value.slice(0, value.length-1)
|
385
|
-
if(parseInt(value, 10) > 100) {
|
386
|
-
err("Line position cannot be >100%.")
|
387
|
-
continue
|
388
|
-
}
|
389
|
-
}
|
390
|
-
if (numVal === '' || isNaN(numVal) || !isFinite(numVal)) {
|
391
|
-
err("Line position needs to be a number")
|
392
|
-
continue
|
393
|
-
}
|
394
|
-
if (lineAlign !== undefined) {
|
395
|
-
if (!["start", "center", "end"].includes(lineAlign)) {
|
396
|
-
err("Line alignment needs to be one of start, center or end")
|
397
|
-
continue
|
398
|
-
}
|
399
|
-
cue.lineAlign = lineAlign
|
400
|
-
}
|
401
|
-
cue.snapToLines = !isPercent;
|
402
|
-
cue.linePosition = parseFloat(numVal)
|
403
|
-
if (parseFloat(numVal).toString() !== numVal) {
|
404
|
-
cue.nonSerializable = true;
|
405
|
-
}
|
406
|
-
} else if(setting == "position") { // text position and optional positionAlign
|
407
|
-
if (/,/.test(value)) {
|
408
|
-
var comp = value.split(',')
|
409
|
-
value = comp[0]
|
410
|
-
var positionAlign = comp[1]
|
411
|
-
}
|
412
|
-
if(value[value.length-1] != "%") {
|
413
|
-
err("Text position must be a percentage.")
|
414
|
-
continue
|
415
|
-
}
|
416
|
-
if(parseInt(value, 10) > 100 || parseInt(value, 10) < 0) {
|
417
|
-
err("Text position needs to be between 0 and 100%.")
|
418
|
-
continue
|
419
|
-
}
|
420
|
-
numVal = value.slice(0, value.length-1)
|
421
|
-
if (numVal === '' || isNaN(numVal) || !isFinite(numVal)) {
|
422
|
-
err("Line position needs to be a number")
|
423
|
-
continue
|
424
|
-
}
|
425
|
-
if (positionAlign !== undefined) {
|
426
|
-
if (!["line-left", "center", "line-right"].includes(positionAlign)) {
|
427
|
-
err("Position alignment needs to be one of line-left, center or line-right")
|
428
|
-
continue
|
429
|
-
}
|
430
|
-
cue.positionAlign = positionAlign
|
431
|
-
}
|
432
|
-
cue.textPosition = parseFloat(numVal)
|
433
|
-
} else if(setting == "size") { // size
|
434
|
-
if(value[value.length-1] != "%") {
|
435
|
-
err("Size must be a percentage.")
|
436
|
-
continue
|
437
|
-
}
|
438
|
-
if(parseInt(value, 10) > 100) {
|
439
|
-
err("Size cannot be >100%.")
|
440
|
-
continue
|
441
|
-
}
|
442
|
-
var size = value.slice(0, value.length -1)
|
443
|
-
if (size === undefined || size === "" || isNaN(size)) {
|
444
|
-
err("Size needs to be a number")
|
445
|
-
size = 100
|
446
|
-
continue
|
447
|
-
} else {
|
448
|
-
size = parseFloat(size)
|
449
|
-
if (size < 0 || size > 100) {
|
450
|
-
err("Size needs to be between 0 and 100%.")
|
451
|
-
continue;
|
452
|
-
}
|
453
|
-
}
|
454
|
-
cue.size = size
|
455
|
-
} else if(setting == "align") { // alignment
|
456
|
-
var alignValues = ["start", "center", "end", "left", "right"]
|
457
|
-
if(alignValues.indexOf(value) == -1) {
|
458
|
-
err("Alignment can only be set to one of " + alignValues.join(", ") + ".")
|
459
|
-
continue
|
460
|
-
}
|
461
|
-
cue.alignment = value
|
462
|
-
} else {
|
463
|
-
err("Invalid setting.")
|
464
|
-
}
|
465
|
-
}
|
466
|
-
}
|
467
|
-
|
468
|
-
this.parse = function(cue, previousCueStart) {
|
469
|
-
skip(SPACE)
|
470
|
-
cue.startTime = timestamp()
|
471
|
-
if(cue.startTime == undefined) {
|
472
|
-
return
|
473
|
-
}
|
474
|
-
if(cue.startTime < previousCueStart) {
|
475
|
-
err("Start timestamp is not greater than or equal to start timestamp of previous cue.")
|
476
|
-
}
|
477
|
-
if(NOSPACE.test(line[pos])) {
|
478
|
-
err("Timestamp not separated from '-->' by whitespace.")
|
479
|
-
}
|
480
|
-
skip(SPACE)
|
481
|
-
// 6-8
|
482
|
-
if(line[pos] != "-") {
|
483
|
-
err("No valid timestamp separator found.")
|
484
|
-
return
|
485
|
-
}
|
486
|
-
pos++
|
487
|
-
if(line[pos] != "-") {
|
488
|
-
err("No valid timestamp separator found.")
|
489
|
-
return
|
490
|
-
}
|
491
|
-
pos++
|
492
|
-
if(line[pos] != ">") {
|
493
|
-
err("No valid timestamp separator found.")
|
494
|
-
return
|
495
|
-
}
|
496
|
-
pos++
|
497
|
-
if(NOSPACE.test(line[pos])) {
|
498
|
-
err("'-->' not separated from timestamp by whitespace.")
|
499
|
-
}
|
500
|
-
skip(SPACE)
|
501
|
-
cue.endTime = timestamp()
|
502
|
-
if(cue.endTime == undefined) {
|
503
|
-
return
|
504
|
-
}
|
505
|
-
if(cue.endTime <= cue.startTime) {
|
506
|
-
err("End timestamp is not greater than start timestamp.")
|
507
|
-
}
|
508
|
-
|
509
|
-
if(NOSPACE.test(line[pos])) {
|
510
|
-
spaceBeforeSetting = false
|
511
|
-
}
|
512
|
-
skip(SPACE)
|
513
|
-
parseSettings(line.substring(pos), cue)
|
514
|
-
return true
|
515
|
-
}
|
516
|
-
this.parseTimestamp = function() {
|
517
|
-
var ts = timestamp()
|
518
|
-
if(line[pos] != undefined) {
|
519
|
-
err("Timestamp must not have trailing characters.")
|
520
|
-
return
|
521
|
-
}
|
522
|
-
return ts
|
523
|
-
}
|
524
|
-
}
|
525
|
-
|
526
|
-
var WebVTTCueTextParser = function(line, errorHandler, mode, entities) {
|
527
|
-
this.entities = entities
|
528
|
-
var self = this
|
529
|
-
var line = line,
|
530
|
-
pos = 0,
|
531
|
-
err = function(message) {
|
532
|
-
if(mode == "metadata")
|
533
|
-
return
|
534
|
-
errorHandler(message, pos+1)
|
535
|
-
}
|
536
|
-
|
537
|
-
this.parse = function(cueStart, cueEnd) {
|
538
|
-
function removeCycles(tree) {
|
539
|
-
const cyclelessTree = {...tree};
|
540
|
-
if (tree.children) {
|
541
|
-
cyclelessTree.children = tree.children.map(removeCycles);
|
542
|
-
}
|
543
|
-
if (cyclelessTree.parent) {
|
544
|
-
delete cyclelessTree.parent;
|
545
|
-
}
|
546
|
-
return cyclelessTree;
|
547
|
-
}
|
548
|
-
|
549
|
-
var result = {children:[]},
|
550
|
-
current = result,
|
551
|
-
timestamps = []
|
552
|
-
|
553
|
-
function attach(token) {
|
554
|
-
current.children.push({type:"object", name:token[1], classes:token[2], children:[], parent:current})
|
555
|
-
current = current.children[current.children.length-1]
|
556
|
-
}
|
557
|
-
function inScope(name) {
|
558
|
-
var node = current
|
559
|
-
while(node) {
|
560
|
-
if(node.name == name)
|
561
|
-
return true
|
562
|
-
node = node.parent
|
563
|
-
}
|
564
|
-
return
|
565
|
-
}
|
566
|
-
|
567
|
-
while(line[pos] != undefined) {
|
568
|
-
var token = nextToken()
|
569
|
-
if(token[0] == "text") {
|
570
|
-
current.children.push({type:"text", value:token[1], parent:current})
|
571
|
-
} else if(token[0] == "start tag") {
|
572
|
-
if(mode == "chapters")
|
573
|
-
err("Start tags not allowed in chapter title text.")
|
574
|
-
var name = token[1]
|
575
|
-
if(name != "v" && name != "lang" && token[3] != "") {
|
576
|
-
err("Only <v> and <lang> can have an annotation.")
|
577
|
-
}
|
578
|
-
if(
|
579
|
-
name == "c" ||
|
580
|
-
name == "i" ||
|
581
|
-
name == "b" ||
|
582
|
-
name == "u" ||
|
583
|
-
name == "ruby"
|
584
|
-
) {
|
585
|
-
attach(token)
|
586
|
-
} else if(name == "rt" && current.name == "ruby") {
|
587
|
-
attach(token)
|
588
|
-
} else if(name == "v") {
|
589
|
-
if(inScope("v")) {
|
590
|
-
err("<v> cannot be nested inside itself.")
|
591
|
-
}
|
592
|
-
attach(token)
|
593
|
-
current.value = token[3] // annotation
|
594
|
-
if(!token[3]) {
|
595
|
-
err("<v> requires an annotation.")
|
596
|
-
}
|
597
|
-
} else if(name == "lang") {
|
598
|
-
attach(token)
|
599
|
-
current.value = token[3] // language
|
600
|
-
} else {
|
601
|
-
err("Incorrect start tag.")
|
602
|
-
}
|
603
|
-
} else if(token[0] == "end tag") {
|
604
|
-
if(mode == "chapters")
|
605
|
-
err("End tags not allowed in chapter title text.")
|
606
|
-
// XXX check <ruby> content
|
607
|
-
if(token[1] == current.name) {
|
608
|
-
current = current.parent
|
609
|
-
} else if(token[1] == "ruby" && current.name == "rt") {
|
610
|
-
current = current.parent.parent
|
611
|
-
} else {
|
612
|
-
err("Incorrect end tag.")
|
613
|
-
}
|
614
|
-
} else if(token[0] == "timestamp") {
|
615
|
-
if(mode == "chapters")
|
616
|
-
err("Timestamp not allowed in chapter title text.")
|
617
|
-
var timings = new WebVTTCueTimingsAndSettingsParser(token[1], err),
|
618
|
-
timestamp = timings.parseTimestamp()
|
619
|
-
if(timestamp != undefined) {
|
620
|
-
if(timestamp <= cueStart || timestamp >= cueEnd) {
|
621
|
-
err("Timestamp must be between start timestamp and end timestamp.")
|
622
|
-
}
|
623
|
-
if(timestamps.length > 0 && timestamps[timestamps.length-1] >= timestamp) {
|
624
|
-
err("Timestamp must be greater than any previous timestamp.")
|
625
|
-
}
|
626
|
-
current.children.push({type:"timestamp", value:timestamp, parent:current})
|
627
|
-
timestamps.push(timestamp)
|
628
|
-
}
|
629
|
-
}
|
630
|
-
}
|
631
|
-
while(current.parent) {
|
632
|
-
if(current.name != "v") {
|
633
|
-
err("Required end tag missing.")
|
634
|
-
}
|
635
|
-
current = current.parent
|
636
|
-
}
|
637
|
-
return removeCycles(result)
|
638
|
-
}
|
639
|
-
|
640
|
-
function nextToken() {
|
641
|
-
var state = "data",
|
642
|
-
result = "",
|
643
|
-
buffer = "",
|
644
|
-
classes = []
|
645
|
-
while(line[pos-1] != undefined || pos == 0) {
|
646
|
-
var c = line[pos]
|
647
|
-
if(state == "data") {
|
648
|
-
if(c == "&") {
|
649
|
-
buffer = c
|
650
|
-
state = "escape"
|
651
|
-
} else if(c == "<" && result == "") {
|
652
|
-
state = "tag"
|
653
|
-
} else if(c == "<" || c == undefined) {
|
654
|
-
return ["text", result]
|
655
|
-
} else {
|
656
|
-
result += c
|
657
|
-
}
|
658
|
-
} else if(state == "escape") {
|
659
|
-
if(c == "<" || c == undefined) {
|
660
|
-
err("Incorrect escape.")
|
661
|
-
let m;
|
662
|
-
if (m = buffer.match(/^&#([0-9]+)$/)) {
|
663
|
-
result += String.fromCharCode(m[1])
|
664
|
-
} else {
|
665
|
-
if(self.entities[buffer]) {
|
666
|
-
result += self.entities[buffer]
|
667
|
-
} else {
|
668
|
-
result += buffer
|
669
|
-
}
|
670
|
-
}
|
671
|
-
return ["text", result]
|
672
|
-
} else if(c == "&") {
|
673
|
-
err("Incorrect escape.")
|
674
|
-
result += buffer
|
675
|
-
buffer = c
|
676
|
-
} else if(/[a-z#0-9]/i.test(c)) {
|
677
|
-
buffer += c
|
678
|
-
} else if(c == ";") {
|
679
|
-
let m;
|
680
|
-
if (m = buffer.match(/^&#(x?[0-9]+)$/)) {
|
681
|
-
// we prepend "0" so that x20 be interpreted as hexadecim (0x20)
|
682
|
-
result += String.fromCharCode("0" + m[1])
|
683
|
-
} else if(self.entities[buffer + c]) {
|
684
|
-
result += self.entities[buffer + c]
|
685
|
-
} else if (m = Object.keys(entities).find(n => buffer.startsWith(n))) { // partial match
|
686
|
-
result += self.entities[m] + buffer.slice(m.length) + c
|
687
|
-
} else {
|
688
|
-
err("Incorrect escape.")
|
689
|
-
result += buffer + ";"
|
690
|
-
}
|
691
|
-
state = "data"
|
692
|
-
} else {
|
693
|
-
err("Incorrect escape.")
|
694
|
-
result += buffer + c
|
695
|
-
state = "data"
|
696
|
-
}
|
697
|
-
} else if(state == "tag") {
|
698
|
-
if(c == "\t" || c == "\n" || c == "\f" || c == " ") {
|
699
|
-
state = "start tag annotation"
|
700
|
-
} else if(c == ".") {
|
701
|
-
state = "start tag class"
|
702
|
-
} else if(c == "/") {
|
703
|
-
state = "end tag"
|
704
|
-
} else if(/\d/.test(c)) {
|
705
|
-
result = c
|
706
|
-
state = "timestamp tag"
|
707
|
-
} else if(c == ">" || c == undefined) {
|
708
|
-
if(c == ">") {
|
709
|
-
pos++
|
710
|
-
}
|
711
|
-
return ["start tag", "", [], ""]
|
712
|
-
} else {
|
713
|
-
result = c
|
714
|
-
state = "start tag"
|
715
|
-
}
|
716
|
-
} else if(state == "start tag") {
|
717
|
-
if(c == "\t" || c == "\f" || c == " ") {
|
718
|
-
state = "start tag annotation"
|
719
|
-
} else if(c == "\n") {
|
720
|
-
buffer = c
|
721
|
-
state = "start tag annotation"
|
722
|
-
} else if(c == ".") {
|
723
|
-
state = "start tag class"
|
724
|
-
} else if(c == ">" || c == undefined) {
|
725
|
-
if(c == ">") {
|
726
|
-
pos++
|
727
|
-
}
|
728
|
-
return ["start tag", result, [], ""]
|
729
|
-
} else {
|
730
|
-
result += c
|
731
|
-
}
|
732
|
-
} else if(state == "start tag class") {
|
733
|
-
if(c == "\t" || c == "\f" || c == " ") {
|
734
|
-
if (buffer) {
|
735
|
-
classes.push(buffer)
|
736
|
-
}
|
737
|
-
buffer = ""
|
738
|
-
state = "start tag annotation"
|
739
|
-
} else if(c == "\n") {
|
740
|
-
if (buffer) {
|
741
|
-
classes.push(buffer)
|
742
|
-
}
|
743
|
-
buffer = c
|
744
|
-
state = "start tag annotation"
|
745
|
-
} else if(c == ".") {
|
746
|
-
if (buffer) {
|
747
|
-
classes.push(buffer)
|
748
|
-
}
|
749
|
-
buffer = ""
|
750
|
-
} else if(c == ">" || c == undefined) {
|
751
|
-
if(c == ">") {
|
752
|
-
pos++
|
753
|
-
}
|
754
|
-
if (buffer) {
|
755
|
-
classes.push(buffer)
|
756
|
-
}
|
757
|
-
return ["start tag", result, classes, ""]
|
758
|
-
} else {
|
759
|
-
buffer += c
|
760
|
-
}
|
761
|
-
} else if(state == "start tag annotation") {
|
762
|
-
if(c == ">" || c == undefined) {
|
763
|
-
if(c == ">") {
|
764
|
-
pos++
|
765
|
-
}
|
766
|
-
buffer = buffer.split(/[\u0020\t\f\r\n]+/).filter(function(item) { if(item) return true }).join(" ")
|
767
|
-
return ["start tag", result, classes, buffer]
|
768
|
-
} else {
|
769
|
-
buffer +=c
|
770
|
-
}
|
771
|
-
} else if(state == "end tag") {
|
772
|
-
if(c == ">" || c == undefined) {
|
773
|
-
if(c == ">") {
|
774
|
-
pos++
|
775
|
-
}
|
776
|
-
return ["end tag", result]
|
777
|
-
} else {
|
778
|
-
result += c
|
779
|
-
}
|
780
|
-
} else if(state == "timestamp tag") {
|
781
|
-
if(c == ">" || c == undefined) {
|
782
|
-
if(c == ">") {
|
783
|
-
pos++
|
784
|
-
}
|
785
|
-
return ["timestamp", result]
|
786
|
-
} else {
|
787
|
-
result += c
|
788
|
-
}
|
789
|
-
} else {
|
790
|
-
err("Never happens.") // The joke is it might.
|
791
|
-
}
|
792
|
-
// 8
|
793
|
-
pos++
|
794
|
-
}
|
795
|
-
}
|
796
|
-
}
|
797
|
-
|
798
|
-
var WebVTTSerializer = function() {
|
799
|
-
function serializeTimestamp(seconds) {
|
800
|
-
const ms = ("00" + (seconds - Math.floor(seconds)).toFixed(3)*1000).slice(-3);
|
801
|
-
let h = 0, m = 0, s = 0;
|
802
|
-
if (seconds >= 3600) {
|
803
|
-
h = Math.floor(seconds/3600);
|
804
|
-
}
|
805
|
-
m = Math.floor((seconds - 3600*h) / 60);
|
806
|
-
s = Math.floor(seconds - 3600*h - 60*m);
|
807
|
-
return (h ? h + ":" : "") + ("" + m).padStart(2, "0") + ":" + ("" + s).padStart(2, "0") + "." + ms;
|
808
|
-
}
|
809
|
-
function serializeCueSettings(cue) {
|
810
|
-
var result = ""
|
811
|
-
const nonDefaultSettings = Object.keys(defaultCueSettings).filter(s => cue[s] !== defaultCueSettings[s]);
|
812
|
-
if (nonDefaultSettings.includes("direction")) {
|
813
|
-
result+= " vertical:" + cue.direction
|
814
|
-
}
|
815
|
-
if (nonDefaultSettings.includes("alignment")) {
|
816
|
-
result+= " align:" + cue.alignment
|
817
|
-
}
|
818
|
-
if (nonDefaultSettings.includes("size")) {
|
819
|
-
result+= " size:" + cue.size + "%"
|
820
|
-
}
|
821
|
-
if (nonDefaultSettings.includes("lineAlign") || nonDefaultSettings.includes("linePosition")) {
|
822
|
-
result += " line:" + cue.linePosition + (cue.snapToLines ? "" : "%") + (cue.lineAlign && cue.lineAlign != defaultCueSettings.lineAlign ? "," + cue.lineAlign : "")
|
823
|
-
}
|
824
|
-
if (nonDefaultSettings.includes("textPosition") || nonDefaultSettings.includes("positionAlign")) {
|
825
|
-
result += " position:" + cue.textPosition + "%" + (cue.positionAlign && cue.positionAlign !== defaultCueSettings.positionAlign ? "," + cue.positionAlign : "")
|
826
|
-
}
|
827
|
-
return result
|
828
|
-
}
|
829
|
-
function serializeTree(tree) {
|
830
|
-
var result = ""
|
831
|
-
for (var i = 0; i < tree.length; i++) {
|
832
|
-
var node = tree[i]
|
833
|
-
if(node.type == "text") {
|
834
|
-
result += node.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
835
|
-
} else if(node.type == "object") {
|
836
|
-
result += "<" + node.name
|
837
|
-
if(node.classes) {
|
838
|
-
for(var y = 0; y < node.classes.length; y++) {
|
839
|
-
result += "." + node.classes[y]
|
840
|
-
}
|
841
|
-
}
|
842
|
-
if(node.value) {
|
843
|
-
result += " " + node.value
|
844
|
-
}
|
845
|
-
result += ">"
|
846
|
-
if(node.children)
|
847
|
-
result += serializeTree(node.children)
|
848
|
-
result += "</" + node.name + ">"
|
849
|
-
} else if(node.type == "timestamp") {
|
850
|
-
result += "<" + serializeTimestamp(node.value) + ">"
|
851
|
-
} else {
|
852
|
-
result += "<" + node.value + ">"
|
853
|
-
}
|
854
|
-
}
|
855
|
-
return result
|
856
|
-
}
|
857
|
-
function serializeCue(cue) {
|
858
|
-
return (cue.id !== undefined ? cue.id + "\n" : "")
|
859
|
-
+ serializeTimestamp(cue.startTime)
|
860
|
-
+ " --> "
|
861
|
-
+ serializeTimestamp(cue.endTime)
|
862
|
-
+ serializeCueSettings(cue)
|
863
|
-
+ "\n" + serializeTree(cue.tree.children) + "\n\n"
|
864
|
-
}
|
865
|
-
function serializeStyle(style) {
|
866
|
-
return "STYLE\n" + style + "\n\n"
|
867
|
-
}
|
868
|
-
this.serialize = function(cues, styles) {
|
869
|
-
var result = "WEBVTT\n\n"
|
870
|
-
if (styles) {
|
871
|
-
for(var i=0;i<styles.length;i++) {
|
872
|
-
result += serializeStyle(styles[i])
|
873
|
-
}
|
874
|
-
}
|
875
|
-
for(var i=0;i<cues.length;i++) {
|
876
|
-
result += serializeCue(cues[i])
|
877
|
-
}
|
878
|
-
return result
|
879
|
-
}
|
880
|
-
}
|
881
|
-
|
882
|
-
function exportify(object) {
|
883
|
-
object.WebVTTParser = WebVTTParser
|
884
|
-
object.WebVTTCueTimingsAndSettingsParser = WebVTTCueTimingsAndSettingsParser
|
885
|
-
object.WebVTTCueTextParser = WebVTTCueTextParser
|
886
|
-
object.WebVTTSerializer = WebVTTSerializer
|
887
|
-
}
|
888
|
-
if (typeof window !== 'undefined') exportify(window);
|
889
|
-
if (typeof exports !== 'undefined') exportify(exports);
|
890
|
-
})()
|