Skip to content

Commit b195195

Browse files
committed
to v1.0.6
1 parent 657f5dc commit b195195

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

dist/granim.js

+49-24
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
/*! Granim v1.0.5 - https://sarcadass.github.io/granim.js */
1+
/*! Granim v1.0.6 - https://sarcadass.github.io/granim.js */
22
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
33
'use strict';
44

55
function Granim(options) {
6-
if(options.element instanceof HTMLCanvasElement)
7-
this.canvas = options.element
8-
else if (typeof options.element === "string")
9-
this.canvas = document.querySelector(options.element)
10-
else
11-
throw new Error('The element you used is neither a String, nor a HTMLCanvasElement');
12-
if(!this.canvas){
13-
throw new Error('`' + options.element + '` could not be found in the DOM');
14-
}
6+
this.getElement(options.element);
157
this.x1 = 0;
168
this.y1 = 0;
179
this.name = options.name || false;
@@ -24,6 +16,7 @@ function Granim(options) {
2416
this.previousTimeStamp = null;
2517
this.progress = 0;
2618
this.isPaused = false;
19+
this.isCleared = false;
2720
this.isPausedBecauseNotInView = false;
2821
this.iscurrentColorsSet = false;
2922
this.context = this.canvas.getContext('2d');
@@ -91,6 +84,8 @@ Granim.prototype.makeGradient = require('./makeGradient.js');
9184

9285
Granim.prototype.getDimensions = require('./getDimensions.js');
9386

87+
Granim.prototype.getElement = require('./getElement.js');
88+
9489
Granim.prototype.animateColors = require('./animateColors.js');
9590

9691
Granim.prototype.getLightness = require('./getLightness.js');
@@ -113,7 +108,7 @@ Granim.prototype.onResize = require('./onResize.js');
113108

114109
module.exports = Granim;
115110

116-
},{"./animateColors.js":2,"./changeState.js":3,"./clear.js":4,"./colorDiff.js":5,"./eventPolyfill.js":6,"./getCurrentColors.js":7,"./getDimensions.js":8,"./getLightness.js":9,"./hexToRgb.js":10,"./makeGradient.js":11,"./onResize.js":12,"./pause.js":13,"./pauseWhenNotInView.js":14,"./play.js":15,"./refreshColors.js":16,"./setColors.js":17,"./setDirection.js":18}],2:[function(require,module,exports){
111+
},{"./animateColors.js":2,"./changeState.js":3,"./clear.js":4,"./colorDiff.js":5,"./eventPolyfill.js":6,"./getCurrentColors.js":7,"./getDimensions.js":8,"./getElement.js":9,"./getLightness.js":10,"./hexToRgb.js":11,"./makeGradient.js":12,"./onResize.js":13,"./pause.js":14,"./pauseWhenNotInView.js":15,"./play.js":16,"./refreshColors.js":17,"./setColors.js":18,"./setDirection.js":19}],2:[function(require,module,exports){
117112
'use strict';
118113

119114
module.exports = function(timestamp) {
@@ -241,9 +236,16 @@ module.exports = function(state) {
241236
'use strict';
242237

243238
module.exports = function() {
244-
cancelAnimationFrame(this.animation);
239+
if (!this.isPaused) {
240+
cancelAnimationFrame(this.animation);
241+
242+
} else {
243+
this.isPaused = false;
244+
}
245+
this.isCleared = true;
245246
this.context.clearRect(0, 0, this.x1, this.y1);
246247
};
248+
247249
},{}],5:[function(require,module,exports){
248250
'use strict';
249251

@@ -306,6 +308,25 @@ module.exports = function() {
306308
},{}],9:[function(require,module,exports){
307309
'use strict';
308310

311+
module.exports = function(element) {
312+
if (element instanceof HTMLCanvasElement) {
313+
this.canvas = element;
314+
315+
} else if (typeof element === "string") {
316+
this.canvas = document.querySelector(element);
317+
318+
} else {
319+
throw new Error('The element you used is neither a String, nor a HTMLCanvasElement');
320+
}
321+
322+
if (!this.canvas) {
323+
throw new Error('`' + element + '` could not be found in the DOM');
324+
}
325+
};
326+
327+
},{}],10:[function(require,module,exports){
328+
'use strict';
329+
309330
module.exports = function() {
310331
var currentColors = this.getCurrentColors();
311332
var colorsAverage = [];
@@ -337,7 +358,7 @@ module.exports = function() {
337358
return lightnessAverage >= 128 ? 'light' : 'dark';
338359
};
339360

340-
},{}],10:[function(require,module,exports){
361+
},{}],11:[function(require,module,exports){
341362
'use strict';
342363

343364
module.exports = function(hex) {
@@ -355,7 +376,7 @@ module.exports = function(hex) {
355376
] : null;
356377
};
357378

358-
},{}],11:[function(require,module,exports){
379+
},{}],12:[function(require,module,exports){
359380
'use strict';
360381

361382
module.exports = function() {
@@ -392,7 +413,7 @@ module.exports = function() {
392413
this.context.fillRect(0, 0, this.x1, this.y1);
393414
};
394415

395-
},{}],12:[function(require,module,exports){
416+
},{}],13:[function(require,module,exports){
396417
'use strict';
397418

398419
module.exports = function() {
@@ -402,16 +423,17 @@ module.exports = function() {
402423
this.refreshColors();
403424
};
404425

405-
},{}],13:[function(require,module,exports){
426+
},{}],14:[function(require,module,exports){
406427
'use strict';
407428

408429
module.exports = function(state) {
409430
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView';
431+
if (this.isCleared) {return;}
410432
if (!isPausedBecauseNotInView) this.isPaused = true;
411433
cancelAnimationFrame(this.animation);
412434
};
413435

414-
},{}],14:[function(require,module,exports){
436+
},{}],15:[function(require,module,exports){
415437
'use strict';
416438

417439
module.exports = function() {
@@ -447,16 +469,19 @@ module.exports = function() {
447469
}
448470
};
449471

450-
},{}],15:[function(require,module,exports){
472+
},{}],16:[function(require,module,exports){
451473
'use strict';
452474

453475
module.exports = function(state) {
454476
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView';
455-
if (!isPausedBecauseNotInView) this.isPaused = false;
477+
if (!isPausedBecauseNotInView) {
478+
this.isPaused = false;
479+
}
480+
this.isCleared = false;
456481
this.animation = requestAnimationFrame(this.animateColors.bind(this));
457482
};
458483

459-
},{}],16:[function(require,module,exports){
484+
},{}],17:[function(require,module,exports){
460485
'use strict';
461486

462487
module.exports = function(progressPercent) {
@@ -478,7 +503,7 @@ module.exports = function(progressPercent) {
478503
this.makeGradient();
479504
};
480505

481-
},{}],17:[function(require,module,exports){
506+
},{}],18:[function(require,module,exports){
482507
'use strict';
483508

484509
module.exports = function() {
@@ -540,7 +565,7 @@ module.exports = function() {
540565
this.iscurrentColorsSet = true;
541566
};
542567

543-
},{}],18:[function(require,module,exports){
568+
},{}],19:[function(require,module,exports){
544569
'use strict';
545570

546571
module.exports = function() {
@@ -566,7 +591,7 @@ module.exports = function() {
566591
}
567592
};
568593

569-
},{}],19:[function(require,module,exports){
594+
},{}],20:[function(require,module,exports){
570595
window.Granim = require('./lib/Granim.js');
571596

572-
},{"./lib/Granim.js":1}]},{},[19]);
597+
},{"./lib/Granim.js":1}]},{},[20]);

0 commit comments

Comments
 (0)