Skip to content

Commit d6d1ca4

Browse files
Merge branch 'dev'
2 parents df4cf8f + a50767e commit d6d1ca4

19 files changed

+4825
-226
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mockups/
22
css/
33
lib/
44
js/
5+
vendor/
56
.editorconfig
67
index.html
78
bower.json

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Oleg Solomka
3+
Copyright (c) 2021 Oleg Solomka, Xavier Foucrier, Jonas Sandstedt
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mojs-player",
3-
"version": "0.43.15",
3+
"version": "0.44.00",
44
"description": "Player controls for [mojs](mojs.io). Intended to help you to craft `mojs` animation sequences.",
55
"main": "build/mojs-player.min.js",
66
"authors": [

build/mojs-player.js

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*!
2+
:: MojsPlayer :: Player controls for [mojs](mojs.io). Intended to help you to craft `mojs` animation sequences.
3+
Oleg Solomka @LegoMushroom 2016 MIT
4+
0.44.0
5+
*/
6+
17
(function webpackUniversalModuleDefinition(root, factory) {
28
if(typeof exports === 'object' && typeof module === 'object')
39
module.exports = factory();
@@ -179,7 +185,9 @@ return /******/ (function(modules) { // webpackBootstrap
179185
this._defaults.onSeekEnd = null;
180186
this._defaults.onProgress = null;
181187

182-
this.revision = '0.43.16';
188+
this._play = this._play.bind(this);
189+
190+
this.revision = '0.44.0';
183191

184192
var str = this._fallbackTo(this._o.name, this._defaults.name);
185193
str += str === this._defaults.name ? '' : '__' + this._defaults.name;
@@ -445,23 +453,26 @@ return /******/ (function(modules) { // webpackBootstrap
445453
var isUndefined = typeof add === 'undefined';
446454

447455
if (!isUndefined) {
448-
add = add.timeline || add;
456+
add = add.timeline || add.tween || add;
449457
}
450458

451-
var isTween = add instanceof mojs.Tween;
452-
var isTimeline = add instanceof mojs.Timeline;
459+
var isAdd = !!add.setProgress;
453460

454-
if (isUndefined || !(isTween || isTimeline)) {
461+
if (isUndefined || !isAdd) {
455462
throw new Error('MojsPlayer expects Tween/Timeline/Module as `add` option in constructor call. [ new MojsPlayer({ add: new mojs.Tween }); ]');
456463
return;
457464
}
458465

459466
this.timeline.add(this._o.add);
460467

468+
var _props = this.timeline._props;
469+
470+
var duration = _props.repeatTime !== void 0 ? _props : _props.delay + _props.duration;
471+
461472
this._sysTween = new mojs.Tween({
462473
easing: 'linear.none',
463-
duration: this.timeline._props.repeatTime,
464-
onProgress: this._onSysProgress.bind(this),
474+
duration: duration,
475+
onUpdate: this._onSysProgress.bind(this),
465476
onComplete: this._onSysTweenComplete.bind(this),
466477
onPlaybackStop: function onPlaybackStop() {
467478
_this3._setPlayState('off');
@@ -492,18 +503,14 @@ return /******/ (function(modules) { // webpackBootstrap
492503
// different when piped thru tween, so add `0.01` gap to soften that
493504
if (p < leftBound - 0.01 && p !== 0) {
494505
this._reset();
495-
requestAnimationFrame(this._play.bind(this));
506+
requestAnimationFrame(this._play);
496507
}
497508

498509
if (p >= rightBound) {
499-
500510
this._reset(rightBound === 1);
501511

502-
// if ( rightBound === 1 ) { this._sysTween.stop( ); }
503-
// else { this._reset() }
504-
505512
if (this._props.isRepeat) {
506-
requestAnimationFrame(this._play.bind(this));
513+
requestAnimationFrame(this._play);
507514
} else {
508515
this._props.isPlaying = false;
509516
}
@@ -516,9 +523,9 @@ return /******/ (function(modules) { // webpackBootstrap
516523

517524

518525
MojsPlayer.prototype._play = function _play() {
519-
var p = this._props,
520-
leftBound = p.isBounds ? p.leftBound : p.progress,
521-
progress = p.progress >= this._getBound('right') ? leftBound : p.progress;
526+
var p = this._props;
527+
var leftBound = p.isBounds ? p.leftBound : p.progress;
528+
var progress = p.progress >= this._getBound('right') ? leftBound : p.progress;
522529

523530
if (progress === 1) {
524531
progress = p.isBounds ? p.leftBound : 0;
@@ -539,19 +546,18 @@ return /******/ (function(modules) { // webpackBootstrap
539546
MojsPlayer.prototype._reset = function _reset(isPause) {
540547
this._sysTween.reset();
541548

542-
if (!isPause) {
543-
// this.timeline.pause();
544-
var p = this._props,
545-
progress = p.progress;
546-
547-
var start = progress,
548-
leftBound = p.isBounds ? p.leftBound : 0;
549-
550-
while (start - p.precision >= leftBound) {
551-
start -= p.precision;
552-
this.timeline.setProgress(start);
553-
}
554-
}
549+
// if ( !isPause ) {
550+
// const p = this._props,
551+
// progress = p.progress;
552+
//
553+
// let start = progress,
554+
// leftBound = (p.isBounds) ? p.leftBound : 0;
555+
//
556+
// // while ( (start - p.precision) >= leftBound ) {
557+
// // start -= p.precision;
558+
// // this.timeline.setProgress( start );
559+
// // }
560+
// }
555561

556562
this.timeline.reset();
557563
};
@@ -713,13 +719,14 @@ return /******/ (function(modules) { // webpackBootstrap
713719
this._props.progress = progress;
714720
// if timeline was reset - refresh it's state
715721
// by incremental updates until progress (0 always)
716-
if (!this.timeline._prevTime && progress > 0) {
717-
var start = 0;
718-
do {
719-
this.timeline.setProgress(start);
720-
start += this._props.precision;
721-
} while (start + this._props.precision < progress);
722-
}
722+
// if ( !this.timeline._prevTime && progress > 0 ) {
723+
// let start = 0;
724+
// do {
725+
// this.timeline.setProgress( start );
726+
// start += this._props.precision;
727+
// } while ( start + this._props.precision < progress );
728+
// }
729+
// console.log(`timeline.setProgress: ${progress}`);
723730
this.timeline.setProgress(progress);
724731

725732
var onProgress = this._props.onProgress;
@@ -3598,7 +3605,7 @@ return /******/ (function(modules) { // webpackBootstrap
35983605
minBound = p.minBound * this._maxWidth,
35993606
maxBound = p.maxBound * this._maxWidth;
36003607

3601-
shift = mojs.h.clamp(shift, minBound, maxBound);
3608+
shift = this.clamp(shift, minBound, maxBound);
36023609
this._applyShift(shift);
36033610
if (isCallback) {
36043611
this._onProgress(shift);
@@ -3607,6 +3614,21 @@ return /******/ (function(modules) { // webpackBootstrap
36073614
}
36083615
return shift;
36093616
};
3617+
3618+
/**
3619+
* clamp - functiboundson to clamp a `value` between `min` and `max`
3620+
*
3621+
* @param {Number} value Value to clamp.
3622+
* @param {Number} min Min bound
3623+
* @param {Number} max Max bound
3624+
* @return {Number} Clamped value.
3625+
*/
3626+
3627+
3628+
Handle.prototype.clamp = function clamp(value, min, max) {
3629+
return Math.min(Math.max(value, min), max);
3630+
};
3631+
36103632
/*
36113633
Method to apply shift to the DOMElement.
36123634
@private
@@ -7041,9 +7063,6 @@ return /******/ (function(modules) { // webpackBootstrap
70417063

70427064
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
70437065

7044-
// require('css/blocks/handle.postcss.css');
7045-
// let CLASSES = require('css/blocks/handle.postcss.css.json');
7046-
70477066
var Ripple = function (_Module) {
70487067
(0, _inherits3.default)(Ripple, _Module);
70497068

@@ -7082,7 +7101,9 @@ return /******/ (function(modules) { // webpackBootstrap
70827101

70837102
this.el.appendChild(this.curtain);
70847103

7085-
this._addRipple();
7104+
if (mojs.Shape) {
7105+
this._addRipple();
7106+
}
70867107
};
70877108
/*
70887109
Method to construct ripple object.
@@ -7120,7 +7141,10 @@ return /******/ (function(modules) { // webpackBootstrap
71207141
}
71217142
if (p >= .15 && this.isStart && !this.isRelease) {
71227143
this.isStart = false;
7123-
this.shape.setSpeed(.02);
7144+
7145+
if (mojs.Shape) {
7146+
this.shape.setSpeed(.02);
7147+
}
71247148
}
71257149
};
71267150
/*
@@ -7134,7 +7158,10 @@ return /******/ (function(modules) { // webpackBootstrap
71347158
return;
71357159
}
71367160
this.isRelease = true;
7137-
this.shape.setSpeed(1).play();
7161+
7162+
if (mojs.Shape) {
7163+
this.shape.setSpeed(1).play();
7164+
}
71387165
};
71397166
/*
71407167
Method that should be run on touch serface hold.
@@ -7148,7 +7175,9 @@ return /******/ (function(modules) { // webpackBootstrap
71487175
y = e.offsetY != null ? e.offsetY : e.layerY;
71497176

71507177
this.isRelease = false;
7151-
this.shape.tune({ x: x, y: y }).replay();
7178+
if (mojs.Shape) {
7179+
this.shape.tune({ x: x, y: y }).replay();
7180+
}
71527181
};
71537182
/*
71547183
Method that should be run on touch serface cancel.
@@ -7161,7 +7190,10 @@ return /******/ (function(modules) { // webpackBootstrap
71617190
return;
71627191
}
71637192
this.isRelease = true;
7164-
this.shape.pause().setSpeed(1).playBackward();
7193+
7194+
if (mojs.Shape) {
7195+
this.shape.pause().setSpeed(1).playBackward();
7196+
}
71657197
};
71667198

71677199
return Ripple;
@@ -8443,7 +8475,7 @@ return /******/ (function(modules) { // webpackBootstrap
84438475

84448476

84458477
// module
8446-
exports.push([module.id, "/*$PX: 1/16rem;*/\n\n._speed-control_1mxm4_4 {\n position: relative;\n display: inline-block;\n height: 40px\n}\n\n._speed-control__slider_1mxm4_1 {\n position: absolute;\n bottom: 100%;\n left: 3px;\n width: 30px;\n height: 120px;\n padding-top: 20px;\n padding-bottom: 20px;\n border-top-right-radius: 3px;\n border-top-left-radius: 3px;\n background: #3A0839;\n -webkit-transform: translate(-99999999px, -99999999px);\n transform: translate(-99999999px, -99999999px);\n -webkit-backface-visibility: hidden;\n backface-visibility: hidden\n}\n\n._speed-control__slider_1mxm4_1:before, ._speed-control__slider_1mxm4_1:after {\n content: '';\n position: absolute;\n top: 50%;\n width: 3px;\n height: 1px;\n background: #FFF\n}\n\n._speed-control__slider_1mxm4_1:before {\n left: 5px\n}\n\n._speed-control__slider_1mxm4_1:after {\n right: 5px\n}\n\n._speed-control__button_1mxm4_1 {\n border: 1px solid cyan\n}\n\n._speed-control_1mxm4_4._is-on_1mxm4_49 ._speed-control__slider_1mxm4_1 {\n -webkit-transform: translate(0, 0);\n transform: translate(0, 0)\n}\n", ""]);
8478+
exports.push([module.id, "/*$PX: 1/16rem;*/\n\n._speed-control_1jd3z_3 {\n position: relative;\n display: inline-block;\n height: 40px\n}\n\n._speed-control__slider_1jd3z_1 {\n position: absolute;\n bottom: 100%;\n left: 3px;\n width: 30px;\n height: 120px;\n padding-top: 20px;\n padding-bottom: 20px;\n border-top-right-radius: 3px;\n border-top-left-radius: 3px;\n background: #3A0839;\n -webkit-transform: translate(-99999999px, -99999999px);\n transform: translate(-99999999px, -99999999px);\n -webkit-backface-visibility: hidden;\n backface-visibility: hidden\n}\n\n._speed-control__slider_1jd3z_1:before, ._speed-control__slider_1jd3z_1:after {\n content: '';\n position: absolute;\n top: 50%;\n width: 3px;\n height: 1px;\n background: #FFF\n}\n\n._speed-control__slider_1jd3z_1:before {\n left: 5px\n}\n\n._speed-control__slider_1jd3z_1:after {\n right: 5px\n}\n\n._speed-control__button_1jd3z_1 {\n border: 1px solid cyan\n}\n\n._speed-control_1jd3z_3._is-on_1jd3z_48 ._speed-control__slider_1jd3z_1 {\n -webkit-transform: translate(0, 0);\n transform: translate(0, 0)\n}\n", ""]);
84478479

84488480
// exports
84498481

@@ -8453,10 +8485,10 @@ return /******/ (function(modules) { // webpackBootstrap
84538485
/***/ function(module, exports) {
84548486

84558487
module.exports = {
8456-
"speed-control": "_speed-control_1mxm4_4",
8457-
"speed-control__slider": "_speed-control__slider_1mxm4_1",
8458-
"speed-control__button": "_speed-control__button_1mxm4_1",
8459-
"is-on": "_is-on_1mxm4_49"
8488+
"speed-control": "_speed-control_1jd3z_3",
8489+
"speed-control__slider": "_speed-control__slider_1jd3z_1",
8490+
"speed-control__button": "_speed-control__button_1jd3z_1",
8491+
"is-on": "_is-on_1jd3z_48"
84608492
};
84618493

84628494
/***/ },

build/mojs-player.min.js

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

css/blocks/speed-control.postcss.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
@import '../assets/globals.postcss.css';
32

43
.speed-control {
@@ -21,8 +20,8 @@
2120

2221
background: $c-purple;
2322

24-
$translateSize : calc( -99999999 * $PX );
25-
transform: translate($translateSize, $translateSize);
23+
$translateSize: calc( -99999999 * $PX );
24+
transform: translate($translateSize, $translateSize);
2625
backface-visibility: hidden;
2726

2827
&:before,
@@ -48,6 +47,5 @@
4847

4948
&.is-on &__slider {
5049
transform: translate(0, 0);
51-
5250
}
5351
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"speed-control":"_speed-control_1mxm4_4","speed-control__slider":"_speed-control__slider_1mxm4_1","speed-control__button":"_speed-control__button_1mxm4_1","is-on":"_is-on_1mxm4_49"}
1+
{"speed-control":"_speed-control_1jd3z_3","speed-control__slider":"_speed-control__slider_1jd3z_1","speed-control__button":"_speed-control__button_1jd3z_1","is-on":"_is-on_1jd3z_48"}

index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@
3636
<script>
3737
var el = document.querySelector( '#js-el' );
3838
var tw = new mojs.Tween({
39-
duration: 4000,
39+
duration: 4000,
4040
onUpdate (p) {
41+
// console.log(p);
4142
el.style.transform = `translateX(${ 1000 * p }px) translateZ(0)`;
4243
}
4344
});
4445

45-
var tm = new mojs.Timeline;
46-
tm.add( tw, new mojs.Shape({ delay: 1000, 'left': '50%', top: '50%' }) );
46+
// var tm = new mojs.Timeline;
47+
// tm.add(tw);
4748

4849
var mojsPlayer = new MojsPlayer({
49-
add: tm,
50+
add: tw,
5051
isPlaying: true,
5152
// progress: .5,
5253
speed: 1,

js/components/handle.babel.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,30 @@ class Handle extends Module {
9292
@param {Boolean} If should invoke onProgress callback.
9393
@returns {Number}.
9494
*/
95-
_setShift ( shift, isCallback = true ) {
95+
_setShift(shift, isCallback = true) {
9696
let p = this._props,
9797
minBound = p.minBound*this._maxWidth,
9898
maxBound = p.maxBound*this._maxWidth;
9999

100-
shift = mojs.h.clamp( shift, minBound, maxBound );
100+
shift = this.clamp(shift, minBound, maxBound );
101101
this._applyShift( shift );
102-
if ( isCallback ) { this._onProgress( shift ); }
102+
if (isCallback) { this._onProgress( shift ); }
103103
else { this._progress = this._shiftToProgress( shift ); }
104104
return shift;
105105
}
106+
107+
/**
108+
* clamp - functiboundson to clamp a `value` between `min` and `max`
109+
*
110+
* @param {Number} value Value to clamp.
111+
* @param {Number} min Min bound
112+
* @param {Number} max Max bound
113+
* @return {Number} Clamped value.
114+
*/
115+
clamp(value, min, max) {
116+
return Math.min(Math.max(value, min), max);
117+
}
118+
106119
/*
107120
Method to apply shift to the DOMElement.
108121
@private
@@ -145,7 +158,7 @@ class Handle extends Module {
145158
_addMainClasses () {
146159
super._addMainClasses();
147160

148-
let p = this._props,
161+
let p = this._props,
149162
classList = this.el.classList;
150163

151164
classList.add( CLASSES.handle );

0 commit comments

Comments
 (0)