Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 97b9e47

Browse files
authored
Miscellaneous cleanup (#10)
* Make global a development dependency * Simplify trim function * Remove ancient backwards compatibility * Remove empty listener * Remove unneeded mkdirp dependency * Remove empty changelog file and related dependencies * The CSS is simple enough to not need sass * Fix build and semicolons
1 parent ceaae1b commit 97b9e47

File tree

8 files changed

+133
-4998
lines changed

8 files changed

+133
-4998
lines changed

CHANGELOG.md

Whitespace-only changes.

package-lock.json

Lines changed: 93 additions & 4890 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
"scripts": {
1818
"prebuild": "npm run clean",
1919
"build": "npm-run-all -p build:*",
20-
"build:css": "npm-run-all build:css:sass build:css:bannerize",
20+
"build:css": "npm-run-all build:css:copy build:css:bannerize",
21+
"build:css:copy": "node scripts/copy-css.js",
2122
"build:css:bannerize": "bannerize dist/videojs-vtt-thumbnails.css --banner=scripts/banner.ejs",
22-
"build:css:sass": "node-sass src/plugin.scss dist/videojs-vtt-thumbnails.css --output-style=compressed --linefeed=lf",
2323
"build:js": "npm-run-all build:js:rollup-modules build:js:rollup-umd build:js:bannerize build:js:uglify",
2424
"build:js:bannerize": "bannerize dist/videojs-vtt-thumbnails.js --banner=scripts/banner.ejs",
2525
"build:js:rollup-modules": "rollup -c scripts/modules.rollup.config.js",
2626
"build:js:rollup-umd": "rollup -c scripts/umd.rollup.config.js",
2727
"build:js:uglify": "uglifyjs dist/videojs-vtt-thumbnails.js --comments --mangle --compress -o dist/videojs-vtt-thumbnails.min.js",
2828
"build:test": "rollup -c scripts/test.rollup.config.js",
2929
"clean": "rimraf dist test/dist",
30-
"postclean": "mkdirp dist test/dist",
3130
"docs": "npm-run-all docs:*",
3231
"docs:api": "jsdoc src -r -c jsdoc.json -d docs/api",
3332
"docs:toc": "doctoc README.md",
@@ -36,11 +35,8 @@
3635
"start:server": "static -a 0.0.0.0 -p 9999 -H '{\"Cache-Control\": \"no-cache, must-revalidate\"}' .",
3736
"pretest": "npm-run-all lint build",
3837
"test": "karma start test/karma.conf.js",
39-
"preversion": "npm test",
40-
"version": "node scripts/version.js",
4138
"watch": "npm-run-all -p watch:*",
42-
"watch:css": "npm-run-all build:css:sass watch:css:sass",
43-
"watch:css:sass": "node-sass src/plugin.scss dist/videojs-vtt-thumbnails.css --output-style=compressed --linefeed=lf --watch src/**/*.scss",
39+
"watch:css": "node scripts/copy-css.js --watch",
4440
"watch:js-modules": "rollup -c scripts/modules.rollup.config.js -w",
4541
"watch:js-umd": "rollup -c scripts/umd.rollup.config.js -w",
4642
"watch:test": "rollup -c scripts/test.rollup.config.js -w",
@@ -82,7 +78,6 @@
8278
"test/"
8379
],
8480
"dependencies": {
85-
"global": "^4.4.0",
8681
"video.js": "^7"
8782
},
8883
"devDependencies": {
@@ -95,23 +90,19 @@
9590
"@rollup/plugin-multi-entry": "^4.1.0",
9691
"@rollup/plugin-node-resolve": "^14.0.1",
9792
"bannerize": "^1.1.4",
98-
"conventional-changelog-cli": "^2.2.2",
99-
"conventional-changelog-videojs": "^3.0.2",
10093
"doctoc": "^2.2.1",
10194
"eslint": "^8.24.0",
10295
"eslint-plugin-jsdoc": "^39.3.6",
96+
"global": "^4.4.0",
10397
"jsdoc": "^3.6.11",
10498
"karma": "^6.4.1",
10599
"karma-chrome-launcher": "^3.1.1",
106100
"karma-qunit": "^4.1.2",
107-
"mkdirp": "^1.0.4",
108-
"node-sass": "^7.0.3",
109101
"node-static": "github:cloudhead/node-static#bd48e282d831745d0721158d1752d31d8fa602a6",
110102
"npm-run-all": "^4.1.5",
111103
"qunit": "^2.19.1",
112104
"rimraf": "^3.0.2",
113105
"rollup": "^2.79.1",
114-
"semver": "^7.3.7",
115106
"sinon": "^14.0.1",
116107
"uglify-js": "^3.17.2",
117108
"videojs-standard": "^9.0.1"

scripts/copy-css.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { copyFileSync, existsSync, mkdirSync, watchFile } = require('fs');
2+
3+
function copy() {
4+
if (!existsSync(`${__dirname}/../dist/`)) {
5+
mkdirSync(`${__dirname}/../dist/`, { recursive: true });
6+
}
7+
copyFileSync(`${__dirname}/../src/plugin.css`, `${__dirname}/../dist/videojs-vtt-thumbnails.css`);
8+
}
9+
10+
copy();
11+
12+
if (process.argv[1] === '--watch') {
13+
watchFile(`${__dirname}/../src/plugin.css`, { persistent: true }, (curr, prev) => {
14+
if (curr.mtimeMs !== prev.mtimeMs) {
15+
copy();
16+
}
17+
});
18+
}

scripts/version.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/plugin.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.video-js.vjs-vtt-thumbnails {
2+
display: block;
3+
}
4+
5+
.video-js .vjs-vtt-thumbnail-display {
6+
position: absolute;
7+
transition: transform .1s, opacity .2s;
8+
bottom: 85%;
9+
pointer-events: none;
10+
box-shadow: 0 0 7px rgba(0, 0, 0, .6);
11+
}

src/plugin.js

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const defaults = {};
88
// Cache for image elements
99
const cache = {};
1010

11-
// Cross-compatibility for Video.js 5 and 6.
12-
const registerPlugin = videojs.registerPlugin || videojs.plugin;
13-
// const dom = videojs.dom || videojs;
14-
1511
/**
1612
* Function to invoke when the player is ready.
1713
*
@@ -72,7 +68,6 @@ class vttThumbnailsPlugin {
7268
constructor(player, options) {
7369
this.player = player;
7470
this.options = options;
75-
this.listenForDurationChange();
7671
this.initializeThumbnails();
7772
this.registeredEvents = {};
7873
return this;
@@ -108,15 +103,6 @@ class vttThumbnailsPlugin {
108103
delete this.lastStyle;
109104
}
110105

111-
/**
112-
* Set event listener for when player's duration changes
113-
*/
114-
listenForDurationChange() {
115-
this.player.on('durationchange', () => {
116-
117-
});
118-
}
119-
120106
/**
121107
* Bootstrap the plugin.
122108
*/
@@ -346,16 +332,16 @@ class vttThumbnailsPlugin {
346332
// be careful with trimming.
347333
return [
348334
base.replace(/\/$/gi, ''),
349-
this.trim(path, '/')
335+
this.trimSlashes(path)
350336
].join('/');
351337
}
352338

353339
if (base.indexOf('//') > 0) {
354340
// We don't have a fully qualified path, and should
355341
// trim both sides of base and path.
356342
return [
357-
this.trim(base, '/'),
358-
this.trim(path, '/')
343+
this.trimSlashes(base),
344+
this.trimSlashes(path)
359345
].join('/');
360346
}
361347

@@ -443,65 +429,19 @@ class vttThumbnailsPlugin {
443429
}
444430

445431
/**
446-
* trim
432+
* trims whitespace and forward slashes from strings
447433
*
448434
* @param {string} str source string
449-
* @param {string} charlist characters to trim from text
450435
* @return {string} trimmed string
451436
*/
452-
trim(str, charlist) {
453-
let whitespace = [
454-
' ',
455-
'\n',
456-
'\r',
457-
'\t',
458-
'\f',
459-
'\x0b',
460-
'\xa0',
461-
'\u2000',
462-
'\u2001',
463-
'\u2002',
464-
'\u2003',
465-
'\u2004',
466-
'\u2005',
467-
'\u2006',
468-
'\u2007',
469-
'\u2008',
470-
'\u2009',
471-
'\u200a',
472-
'\u200b',
473-
'\u2028',
474-
'\u2029',
475-
'\u3000'
476-
].join('');
477-
let l = 0;
478-
let i = 0;
479-
480-
str += '';
481-
if (charlist) {
482-
whitespace = (charlist + '').replace(/([[\]().?/*{}+$^:])/g, '$1');
483-
}
484-
l = str.length;
485-
for (i = 0; i < l; i++) {
486-
if (whitespace.indexOf(str.charAt(i)) === -1) {
487-
str = str.substring(i);
488-
break;
489-
}
490-
}
491-
l = str.length;
492-
for (i = l - 1; i >= 0; i--) {
493-
if (whitespace.indexOf(str.charAt(i)) === -1) {
494-
str = str.substring(0, i + 1);
495-
break;
496-
}
497-
}
498-
return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
437+
trimSlashes(str) {
438+
return str.replace(/^\s*\/+\s*|\s*\/+\s*$/g, '');
499439
}
500440

501441
}
502442

503443
// Register the plugin with video.js.
504-
registerPlugin('vttThumbnails', vttThumbnails);
444+
videojs.registerPlugin('vttThumbnails', vttThumbnails);
505445

506446
// Include the version number.
507447
vttThumbnails.VERSION = VERSION;

src/plugin.scss

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)