kute.js/demo/src/kute-base.min.js
thednp be367debe0 Changes:
* updated `shorter-js`
* improved scrollProperty for lighter size
2020-06-18 08:25:35 +00:00

3 lines
7.4 KiB
JavaScript

// KUTE.js Base v2.0.51 | thednp © 2020 | MIT-License
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).KUTE=n()}(this,(function(){"use strict";var t={},n=[],e="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function i(t,n,e){return(t=+t)+(n-=t)*e}function r(t,n,e){for(var i=[],r=0,o=n.length;r<o;r++)i[r]=(1e3*(t[r]+(n[r]-t[r])*e)>>0)/1e3;return i}var o={numbers:i,units:function(t,n,e,i){return(t=+t)+(n-=t)*i+e},arrays:r},a={},s={};"undefined"==typeof self&&"undefined"!=typeof process&&process.hrtime?s.now=function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:"undefined"!=typeof self&&void 0!==self.performance&&void 0!==self.performance.now&&(s.now=self.performance.now.bind(self.performance));var u=0,f=function(t){for(var e=0;e<n.length;)n[e].update(t)?e++:n.splice(e,1);u=requestAnimationFrame(f)};function c(){setTimeout((function(){if(!n.length&&u){for(var e in cancelAnimationFrame(u),u=null,a)if("function"==typeof a[e])t[e]&&delete t[e];else for(var i in a[e])t[i]&&delete t[i];for(var r in o)t[r]&&delete t[r]}}),64)}var l={Tick:u,Ticker:f,Tweens:n,Time:s};for(var p in l)t[p]||(t[p]="Time"===p?s.now:l[p]);e._KUTE=t;var d={duration:700,delay:0,easing:"linear"},h={},v={},y={defaultOptions:d,linkProperty:h,onStart:a,onComplete:v},m={};var g={linear:function(t){return t},easingQuadraticIn:function(t){return t*t},easingQuadraticOut:function(t){return t*(2-t)},easingQuadraticInOut:function(t){return t<.5?2*t*t:(4-2*t)*t-1},easingCubicIn:function(t){return t*t*t},easingCubicOut:function(t){return--t*t*t+1},easingCubicInOut:function(t){return t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1},easingCircularIn:function(t){return-(Math.sqrt(1-t*t)-1)},easingCircularOut:function(t){return Math.sqrt(1-(t-=1)*t)},easingCircularInOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},easingBackIn:function(t){var n=1.70158;return t*t*((n+1)*t-n)},easingBackOut:function(t){var n=1.70158;return--t*t*((n+1)*t+n)+1},easingBackInOut:function(t){var n=2.5949095;return(t*=2)<1?t*t*((n+1)*t-n)*.5:.5*((t-=2)*t*((n+1)*t+n)+2)}};function _(t){return n.push(t)}function S(t){var e=n.indexOf(t);-1!==e&&n.splice(e,1)}m.processEasing=function(t){return"function"==typeof t?t:"function"==typeof g[t]?g[t]:g.linear};var w={};function T(){var n=this,e=function(e){var i=h[e],r=w[e];for(var o in i)if("function"==typeof i[o]&&Object.keys(n.valuesEnd).some((function(t){return r&&r.includes(t)||"attr"===t&&Object.keys(n.valuesEnd[t]).some((function(t){return r&&r.includes(t)}))})))!t[o]&&(t[o]=i[o]);else for(var a in n.valuesEnd)for(var s in n.valuesEnd[a])if("function"==typeof i[s])!t[s]&&(t[s]=i[s]);else for(var u in i[o])i[s]&&"function"==typeof i[s][u]&&!t[u]&&(t[u]=i[s][u])};for(var i in h)e(i)}var C={add:_,remove:S,getAll:function(){return n},removeAll:function(){n.length=0},stop:c,linkInterpolation:T};function M(t,n){try{return n?t instanceof HTMLCollection||t instanceof NodeList||t instanceof Array&&t.every((function(t){return t instanceof Element}))?t:document.querySelectorAll(t):t instanceof Element||t===window?t:document.querySelector(t)}catch(n){console.error("KUTE.js - Element(s) not found: "+t+".")}}var E=function(t){return this.setComponent(t)};E.prototype.setComponent=function(t){var n=t.component,e={onStart:a,onComplete:v},i=t.category,r=t.property;if(w[n]=t.properties||t.subProperties||t.property,t.defaultOptions)for(var s in t.defaultOptions)d[s]=t.defaultOptions[s];if(t.functions)for(var u in e)if(u in t.functions)if("function"==typeof t.functions[u])!e[u][n]&&(e[u][n]={}),!e[u][n][i||r]&&(e[u][n][i||r]=t.functions[u]);else for(var f in t.functions[u])!e[u][n]&&(e[u][n]={}),!e[u][n][f]&&(e[u][n][f]=t.functions[u][f]);if(t.Interpolate){for(var c in t.Interpolate){var l=t.Interpolate[c];if("function"!=typeof l||o[c])for(var p in l)"function"!=typeof l[p]||o[c]||(o[c]=l[p]);else o[c]=l}h[n]=t.Interpolate}if(t.Util)for(var y in t.Util)!m[y]&&(m[y]=t.Util[y]);return{name:n}};var O={},b=function(n,e,i,r){for(var o in this.element=n,this.playing=!1,this._startTime=null,this._startFired=!1,this.valuesEnd=i,this.valuesStart=e,r=r||{},this._resetStart=r.resetStart||0,this._easing="function"==typeof r.easing?r.easing:m.processEasing(r.easing),this._duration=r.duration||d.duration,this._delay=r.delay||d.delay,r){var s="_"+o;s in this||(this[s]=r[o])}var u=this._easing.name;return a[u]||(a[u]=function(n){!t[n]&&n===this._easing.name&&(t[n]=this._easing)}),this};b.prototype.start=function(n){if(_(this),this.playing=!0,this._startTime=n||t.Time(),this._startTime+=this._delay,!this._startFired){for(var e in this._onStart&&this._onStart.call(this),a)if("function"==typeof a[e])a[e].call(this,e);else for(var i in a[e])a[e][i].call(this,i);T.call(this),this._startFired=!0}return!u&&f(),this},b.prototype.stop=function(){return this.playing&&(S(this),this.playing=!1,this._onStop&&this._onStop.call(this),this.close()),this},b.prototype.close=function(){for(var t in v)for(var n in v[t])v[t][n].call(this,n);this._startFired=!1,c.call(this)},b.prototype.chain=function(t){return this._chain=[],this._chain=t.length?t:this._chain.concat(t),this},b.prototype.stopChainedTweens=function(){this._chain&&this._chain.length&&this._chain.map((function(t){return t.stop()}))},b.prototype.update=function(n){var e,i;if((n=void 0!==n?n:t.Time())<this._startTime&&this.playing)return!0;for(var r in e=(n-this._startTime)/this._duration,e=0===this._duration||e>1?1:e,i=this._easing(e),this.valuesEnd)t[r](this.element,this.valuesStart[r],this.valuesEnd[r],i);return this._onUpdate&&this._onUpdate.call(this),1!==e||(this._onComplete&&this._onComplete.call(this),this.playing=!1,this.close(),void 0!==this._chain&&this._chain.length&&this._chain.map((function(t){return t.start()})),!1)},O.Tween=b;var I=O.Tween;var k="undefined"!=typeof DOMMatrix?DOMMatrix:"undefined"!=typeof WebKitCSSMatrix?WebKitCSSMatrix:"undefined"!=typeof CSSMatrix?CSSMatrix:"undefined"!=typeof MSCSSMatrix?MSCSSMatrix:null,x={component:"transformMatrix",property:"transform",functions:{onStart:{transform:function(n){this.valuesEnd[n]&&!t[n]&&(t[n]=function(t,e,o,a){var s=new k,u={};for(var f in o)u[f]="perspective"===f?i(e[f],o[f],a):r(e[f],o[f],a);u.perspective&&(s.m34=-1/u.perspective),s=u.translate3d?s.translate(u.translate3d[0],u.translate3d[1],u.translate3d[2]):s,s=u.rotate3d?s.rotate(u.rotate3d[0],u.rotate3d[1],u.rotate3d[2]):s,u.skew&&(s=u.skew[0]?s.skewX(u.skew[0]):s,s=u.skew[1]?s.skewY(u.skew[1]):s),s=u.scale3d?s.scale(u.scale3d[0],u.scale3d[1],u.scale3d[2]):s,t.style[n]=s.toString()})},CSS3Matrix:function(n){this.valuesEnd.transform&&!t[n]&&(t[n]=k)}}},Interpolate:{perspective:i,translate3d:r,rotate3d:r,skew:r,scale3d:r}};function U(n){n in this.valuesEnd&&!t[n]&&(t[n]=function(t,e,r,o){t.style[n]=(o>.99||o<.01?(10*i(e,r,o)>>0)/10:i(e,r,o)>>0)+"px"})}var q=["top","left","width","height"],A={};q.map((function(t){return A[t]=U}));var B={component:"baseBoxModel",category:"boxModel",properties:q,Interpolate:{numbers:i},functions:{onStart:A}};var F={component:"baseOpacity",property:"opacity",Interpolate:{numbers:i},functions:{onStart:function(n){n in this.valuesEnd&&!t[n]&&(t[n]=function(t,e,r,o){t.style[n]=(1e3*i(e,r,o)>>0)/1e3})}}},j=new E(x),K=new E(B),Q=new E(F);return{Animation:E,Components:{Transform:j,BoxModel:K,Opacity:Q},TweenBase:b,fromTo:function(t,n,e,i){return i=i||{},new I(M(t),n,e,i)},Objects:y,Easing:g,Util:m,Render:l,Interpolate:o,Internals:C,Selector:M,Version:"2.0.51"}}));