Compare commits

...

4 Commits

Author SHA1 Message Date
e1ff86820c v3.6.6
- Improvements to how aspect ratio is handled. Use `aspect-ratio` CSS property instead of the legacy method (still used as fallback). Also automatically determined aspect ratios are rounded to the nearast standard ratio. This fixes issues with the YouTube embeds showing a 1-2px black bar.
- Hide the YouTube poster image container when paused so that the controls underneath can be used.
2021-04-18 17:49:23 +10:00
7d22c361d1 chore: remove fastly purging logic (#2173) 2021-04-18 17:41:58 +10:00
951cccb6b0 fix: youtube poster allow clickthrough while paused (#2172) 2021-04-18 16:59:00 +10:00
438e425838 fix: aspect ratio improvements (#2171)
- Use CSS aspect-ratio (retain fallback for legacy browsers)
- Round aspect ratios (fixes YouTube black border issue)
2021-04-18 16:58:44 +10:00
13 changed files with 87 additions and 73 deletions

View File

@ -1,3 +1,8 @@
### v3.6.6
- Improvements to how aspect ratio is handled. Use `aspect-ratio` CSS property instead of the legacy method (still used as fallback). Also automatically determined aspect ratios are rounded to the nearast standard ratio. This fixes issues with the YouTube embeds showing a 1-2px black bar.
- Hide the YouTube poster image container when paused so that the controls underneath can be used.
### v3.6.5
- Migrate color formatting to colorette (thanks @jorgebucaran)

View File

@ -134,13 +134,13 @@ See [initialising](#initialising) for more information on advanced setups.
You can use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript. There's 2 versions; one with and one without [polyfills](#polyfills). My recommendation would be to manage polyfills seperately as part of your application but to make life easier you can use the polyfilled build.
```html
<script src="https://cdn.plyr.io/3.6.5/plyr.js"></script>
<script src="https://cdn.plyr.io/3.6.6/plyr.js"></script>
```
...or...
```html
<script src="https://cdn.plyr.io/3.6.5/plyr.polyfilled.js"></script>
<script src="https://cdn.plyr.io/3.6.6/plyr.polyfilled.js"></script>
```
## CSS
@ -154,13 +154,13 @@ Include the `plyr.css` stylsheet into your `<head>`.
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following:
```html
<link rel="stylesheet" href="https://cdn.plyr.io/3.6.5/plyr.css" />
<link rel="stylesheet" href="https://cdn.plyr.io/3.6.6/plyr.css" />
```
## SVG Sprite
The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.6.5/plyr.svg`.
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.6.6/plyr.svg`.
# Ads

View File

@ -2,4 +2,4 @@
// Layout
// ==========================================================================
$container-max-width: 1260px;
$container-max-width: 1240px;

View File

@ -1,6 +1,6 @@
{
"name": "plyr",
"version": "3.6.5",
"version": "3.6.6",
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
"homepage": "https://plyr.io",
"author": "Sam Potts <sam@potts.es>",
@ -52,7 +52,6 @@
"del": "^6.0.0",
"eslint": "^7.23.0",
"fancy-log": "^1.3.3",
"fastly-purge": "^1.0.1",
"git-branch": "^2.0.1",
"gulp": "^4.0.2",
"gulp-awspublish": "^4.1.2",
@ -88,8 +87,7 @@
"stylelint-config-sass-guidelines": "^8.0.0",
"stylelint-order": "^4.1.0",
"stylelint-scss": "^3.19.0",
"stylelint-selector-bem-pattern": "^2.1.0",
"through2": "^4.0.2"
"stylelint-selector-bem-pattern": "^2.1.0"
},
"dependencies": {
"core-js": "^3.10.1",

View File

@ -61,7 +61,7 @@ const defaults = {
// Sprite (for icons)
loadSprite: true,
iconPrefix: 'plyr',
iconUrl: 'https://cdn.plyr.io/3.6.5/plyr.svg',
iconUrl: 'https://cdn.plyr.io/3.6.6/plyr.svg',
// Blank video (used to prevent errors on source change)
blankVideo: 'https://cdn.plyr.io/static/blank.mp4',

View File

@ -11,7 +11,7 @@ import fetch from '../utils/fetch';
import is from '../utils/is';
import loadScript from '../utils/load-script';
import { format, stripHTML } from '../utils/strings';
import { setAspectRatio } from '../utils/style';
import { roundAspectRatio, setAspectRatio } from '../utils/style';
import { buildUrlParams } from '../utils/urls';
// Parse Vimeo ID from URL
@ -294,7 +294,7 @@ const vimeo = {
// Set aspect ratio based on video size
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then((dimensions) => {
const [width, height] = dimensions;
player.embed.ratio = [width, height];
player.embed.ratio = roundAspectRatio(width, height);
setAspectRatio.call(this);
});

View File

@ -11,7 +11,7 @@ import loadImage from '../utils/load-image';
import loadScript from '../utils/load-script';
import { extend } from '../utils/objects';
import { format, generateId } from '../utils/strings';
import { setAspectRatio } from '../utils/style';
import { roundAspectRatio, setAspectRatio } from '../utils/style';
// Parse YouTube ID from URL
function parseId(url) {
@ -90,7 +90,7 @@ const youtube = {
ui.setTitle.call(this);
// Set aspect ratio
this.embed.ratio = [width, height];
this.embed.ratio = roundAspectRatio(width, height);
}
setAspectRatio.call(this);

View File

@ -1,6 +1,6 @@
// ==========================================================================
// Plyr
// plyr.js v3.6.5
// plyr.js v3.6.6
// https://github.com/sampotts/plyr
// License: The MIT License (MIT)
// ==========================================================================
@ -29,7 +29,7 @@ import loadSprite from './utils/load-sprite';
import { clamp } from './utils/numbers';
import { cloneDeep, extend } from './utils/objects';
import { silencePromise } from './utils/promise';
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style';
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateAspectRatio } from './utils/style';
import { parseUrl } from './utils/urls';
// Private properties
@ -916,12 +916,12 @@ class Plyr {
return;
}
if (!is.string(input) || !validateRatio(input)) {
if (!is.string(input) || !validateAspectRatio(input)) {
this.debug.error(`Invalid aspect ratio specified (${input})`);
return;
}
this.config.ratio = input;
this.config.ratio = reduceAspectRatio(input);
setAspectRatio.call(this);
}

View File

@ -1,6 +1,6 @@
// ==========================================================================
// Plyr Polyfilled Build
// plyr.js v3.6.5
// plyr.js v3.6.6
// https://github.com/sampotts/plyr
// License: The MIT License (MIT)
// ==========================================================================

View File

@ -2,9 +2,30 @@
// Style utils
// ==========================================================================
import { closest } from './arrays';
import is from './is';
export function validateRatio(input) {
// Standard/common aspect ratios
const standardRatios = [
[1, 1],
[4, 3],
[3, 4],
[5, 4],
[4, 5],
[3, 2],
[2, 3],
[16, 10],
[10, 16],
[16, 9],
[9, 16],
[21, 9],
[9, 21],
[32, 9],
[9, 32],
].reduce((out, [x, y]) => ({ ...out, [x / y]: [x, y] }), {});
// Validate an aspect ratio
export function validateAspectRatio(input) {
if (!is.array(input) && (!is.string(input) || !input.includes(':'))) {
return false;
}
@ -14,6 +35,7 @@ export function validateRatio(input) {
return ratio.map(Number).every(is.number);
}
// Reduce an aspect ratio to it's lowest form
export function reduceAspectRatio(ratio) {
if (!is.array(ratio) || !ratio.every(is.number)) {
return null;
@ -26,8 +48,9 @@ export function reduceAspectRatio(ratio) {
return [width / divider, height / divider];
}
// Calculate an aspect ratio
export function getAspectRatio(input) {
const parse = (ratio) => (validateRatio(ratio) ? ratio.split(':').map(Number) : null);
const parse = (ratio) => (validateAspectRatio(ratio) ? ratio.split(':').map(Number) : null);
// Try provided ratio
let ratio = parse(input);
@ -58,10 +81,20 @@ export function setAspectRatio(input) {
const { wrapper } = this.elements;
const ratio = getAspectRatio.call(this, input);
const [w, h] = is.array(ratio) ? ratio : [0, 0];
const padding = (100 / w) * h;
wrapper.style.paddingBottom = `${padding}%`;
if (!is.array(ratio)) {
return {};
}
const [x, y] = ratio;
const useNative = window.CSS?.supports(`aspect-ratio: ${x} / ${y}`) ?? false;
const padding = (100 / x) * y;
if (useNative) {
wrapper.style.aspectRatio = `${x}/${y}`;
} else {
wrapper.style.paddingBottom = `${padding}%`;
}
// For Vimeo we have an extra <div> to hide the standard controls and UI
if (this.isVimeo && !this.config.vimeo.premium && this.supported.ui) {
@ -80,4 +113,18 @@ export function setAspectRatio(input) {
return { padding, ratio };
}
// Round an aspect ratio to closest standard ratio
export function roundAspectRatio(x, y, tolerance = 0.05) {
const ratio = x / y;
const closestRatio = closest(Object.keys(standardRatios), ratio);
// Check match is within tolerance
if (Math.abs(closestRatio - ratio) <= tolerance) {
return standardRatios[closestRatio];
}
// No match
return [x, y];
}
export default { setAspectRatio };

View File

@ -20,3 +20,8 @@
.plyr--stopped.plyr__poster-enabled .plyr__poster {
opacity: 1;
}
// Allow interaction with YouTube controls while paused
.plyr--youtube.plyr--paused.plyr__poster-enabled:not(.plyr--stopped) .plyr__poster {
display: none;
}

View File

@ -26,9 +26,13 @@ $embed-padding: ((100 / 16) * 9);
.plyr__video-embed,
.plyr__video-wrapper--fixed-ratio {
height: 0;
padding-bottom: to-percentage($embed-padding);
position: relative;
@supports not (aspect-ratio: 16 / 9) {
height: 0;
padding-bottom: to-percentage($embed-padding);
position: relative;
}
aspect-ratio: 16 / 9;
}
.plyr__video-embed iframe,

View File

@ -14,11 +14,9 @@ const { green, cyan, bold } = require('colorette');
const log = require('fancy-log');
const open = require('gulp-open');
const size = require('gulp-size');
const through = require('through2');
// Deployment
const aws = require('aws-sdk');
const publish = require('gulp-awspublish');
const FastlyPurge = require('fastly-purge');
// Configs
const pkg = require('../package.json');
const deploy = require('../deploy.json');
@ -53,14 +51,6 @@ const paths = {
],
};
// Get credentials
let credentials = {};
try {
credentials = require('../credentials.json'); //eslint-disable-line
} catch (e) {
// Do nothing
}
// Get branch info
const branch = {
current: gitbranch.sync(),
@ -177,41 +167,6 @@ gulp.task('cdn', (done) => {
);
});
// Purge the fastly cache incase any 403/404 are cached
gulp.task('purge', () => {
if (!Object.keys(credentials).includes('fastly')) {
throw new Error('Fastly credentials required to purge cache.');
}
const { fastly } = credentials;
const list = [];
return gulp
.src(paths.upload)
.pipe(
through.obj((file, enc, cb) => {
const filename = file.path.split('/').pop();
list.push(`${versionPath}${filename.replace(minSuffix, '')}`);
cb(null);
}),
)
.on('end', () => {
const purge = new FastlyPurge(fastly.token);
list.forEach((url) => {
log(`Purging ${cyan(url)}...`);
purge.url(url, (error, result) => {
if (error) {
log.error(error);
} else if (result) {
log(result);
}
});
});
});
});
// Publish to demo bucket
gulp.task('demo', (done) => {
if (!canDeploy()) {
@ -271,4 +226,4 @@ gulp.task('open', () => {
});
// Do everything
gulp.task('deploy', gulp.series('cdn', 'demo', 'purge', 'open'));
gulp.task('deploy', gulp.series('cdn', 'demo', 'open'));