kute.js/demo/src/kute-base.min.js
2020-06-09 20:06:26 +00:00

3 lines
9.3 KiB
JavaScript

// KUTE.js Base v2.0.0 | thednp © 2020 | MIT-License
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).KUTE=e()}(this,(function(){"use strict";var t=[],e={},n={duration:700,delay:0,easing:"linear"},r={},o={},i={},s={},a={},u={defaultOptions:n,linkProperty:s,onComplete:o,onStart:i,supportedProperties:e};var l={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 e=1.70158;return t*t*((e+1)*t-e)},easingBackOut:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},easingBackInOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}};a.processEasing=function(t){return"function"==typeof t?t:"string"==typeof t?l[t]:l.linear};var c="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},f={},p={};function d(t,e,n){return(t=+t)+(e-=t)*n}var v={numbers:d,units:function(t,e,n,r){return(t=+t)+(e-=t)*r+n},arrays:function(t,e,n){for(var r=[],o=0,i=e.length;o<i;o++)r[o]=(1e3*(t[o]+(e[o]-t[o])*n)>>0)/1e3;return r}},h=function(e){t.push(e)},m=function(e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)},y=0;function g(e){for(var n=0;n<t.length;)t[n].update(e)?n++:t.splice(n,1);y=requestAnimationFrame(g)}var w={};function _(){setTimeout((function(){if(!t.length&&y){for(var e in cancelAnimationFrame(y),y=null,i)if("function"==typeof i[e])p[e]&&delete p[e];else for(var n in i[e])p[n]&&delete p[n];for(var r in v)p[r]&&delete p[r]}}),64)}function E(){var t=this,n=function(n){var r=s[n],o=e[n];for(var i in r)if("function"==typeof r[i]&&Object.keys(t.valuesEnd).some((function(e){return o.includes(e)||"attr"===e&&Object.keys(t.valuesEnd[e]).some((function(t){return o.includes(t)}))})))!p[i]&&(p[i]=r[i]);else for(var a in t.valuesEnd)for(var u in t.valuesEnd[a])if("function"==typeof r[u])!p[u]&&(p[u]=r[u]);else for(var l in r[i])r[u]&&"function"==typeof r[u][l]&&!p[l]&&(p[l]=r[u][l])};for(var r in s)n(r)}"undefined"==typeof self&&"undefined"!=typeof process&&process.hrtime?w.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&&(w.now=self.performance.now.bind(self.performance));var T={Tick:y,Ticker:g,Tweens:t,Time:w};for(var b in T)p[b]||(p[b]="Time"===b?w.now:T[b]);c._KUTE=p;var C={add:h,remove:m,getAll:function(){return t},removeAll:function(){t.length=0},stop:_,linkInterpolation:E};function S(t,e){try{return e?t instanceof HTMLCollection||t instanceof NodeList||t instanceof Array&&t[0]instanceof Element?t:document.querySelectorAll(t):t instanceof Element||t===window?t:document.querySelector(t)}catch(e){console.error("KUTE.js - Element(s) not found: "+t+".")}}var I=function(t){return this.Component=t,this.setComponent()};I.prototype.setComponent=function(){var t=this.Component,u=t.component,l={onStart:i,onComplete:o,crossCheck:r},c=t.category,f=t.property;if(e[u]=t.properties||t.subProperties||t.property,t.defaultOptions)for(var p in t.defaultOptions)n[p]=t.defaultOptions[p];if(t.functions)for(var d in l)if(d in t.functions&&["onStart","onComplete"].includes(d))if("function"==typeof t.functions[d])!l[d][u]&&(l[d][u]={}),!l[d][u][c||f]&&(l[d][u][c||f]=t.functions[d]);else for(var h in t.functions[d])!l[d][u]&&(l[d][u]={}),!l[d][u][h]&&(l[d][u][h]=t.functions[d][h]);if(t.Interpolate){for(var m in t.Interpolate)v[m]||(v[m]=t.Interpolate[m]);s[u]=t.Interpolate}if(t.Util)for(var y in t.Util)!a[y]&&(a[y]=t.Util[y]);return{name:u}};var O=function(t,e,r,o){for(var s in this.element=t,this.playing=!1,this._startTime=null,this._startFired=!1,this.valuesEnd=r,this.valuesStart=e,o=o||{},this._resetStart=o.resetStart||0,this._easing="function"==typeof o.easing?o.easing:a.processEasing(o.easing),this._duration=o.duration||n.duration,this._delay=o.delay||n.delay,o){var u="_"+s;u in this||(this[u]=o[s])}var l=this._easing.name;return i[l]||(i[l]=function(t){!p[t]&&t===this._easing.name&&(p[t]=this._easing)}),this};O.prototype.start=function(t){if(h(this),this.playing=!0,this._startTime=t||p.Time(),this._startTime+=this._delay,!this._startFired){for(var e in this._onStart&&this._onStart.call(this),i)if("function"==typeof i[e])i[e].call(this,e);else for(var n in i[e])i[e][n].call(this,n);E.call(this),this._startFired=!0}return!y&&g(),this},O.prototype.stop=function(){return this.playing&&(m(this),this.playing=!1,this._onStop&&this._onStop.call(this),this.close()),this},O.prototype.close=function(){for(var t in o)for(var e in o[t])o[t][e].call(this,e);this._startFired=!1,_.call(this)},O.prototype.update=function(t){var e,n;if((t=void 0!==t?t:p.Time())<this._startTime&&this.playing)return!0;for(var r in e=(t-this._startTime)/this._duration,e=0===this._duration||e>1?1:e,n=this._easing(e),this.valuesEnd)p[r](this.element,this.valuesStart[r],this.valuesEnd[r],n);return this._onUpdate&&this._onUpdate.call(this),1!==e||(this._onComplete&&this._onComplete.call(this),this.playing=!1,this.close(),!1)},f.Tween=O;var k=f.Tween;function M(t,e,n,r){return"perspective("+(1e3*(t+(e-t)*r)>>0)/1e3+n+")"}function x(t,e,n,r){for(var o=[],i=0;i<3;i++)o[i]=(t[i]||e[i]?(1e3*(t[i]+(e[i]-t[i])*r)>>0)/1e3:0)+n;return"translate3d("+o.join(",")+")"}function B(t,e,n,r){var o="";return o+=t[0]||e[0]?"rotateX("+(1e3*(t[0]+(e[0]-t[0])*r)>>0)/1e3+n+")":"",o+=t[1]||e[1]?"rotateY("+(1e3*(t[1]+(e[1]-t[1])*r)>>0)/1e3+n+")":"",o+=t[2]||e[2]?"rotateZ("+(1e3*(t[2]+(e[2]-t[2])*r)>>0)/1e3+n+")":""}function U(t,e,n,r){var o=[];return o[0]=(t[0]===e[0]?e[0]:(1e3*(t[0]+(e[0]-t[0])*r)>>0)/1e3)+n,o[1]=t[1]||e[1]?(t[1]===e[1]?e[1]:(1e3*(t[1]+(e[1]-t[1])*r)>>0)/1e3)+n:"0","translate("+o.join(",")+")"}function j(t,e,n,r){return"rotate("+(1e3*(t+(e-t)*r)>>0)/1e3+n+")"}function P(t,e,n,r){var o=[];return o[0]=(t[0]===e[0]?e[0]:(1e3*(t[0]+(e[0]-t[0])*r)>>0)/1e3)+n,o[1]=t[1]||e[1]?(t[1]===e[1]?e[1]:(1e3*(t[1]+(e[1]-t[1])*r)>>0)/1e3)+n:"0","skew("+o.join(",")+")"}function A(t,e,n){return"scale("+(1e3*(t+(e-t)*n)>>0)/1e3+")"}var q={component:"transformFunctions",property:"transform",subProperties:["perspective","translate3d","translateX","translateY","translateZ","translate","rotate3d","rotateX","rotateY","rotateZ","rotate","skewX","skewY","skew","scale"],functions:{onStart:function(t){!p[t]&&this.valuesEnd[t]&&(p[t]=function(e,n,r,o){e.style[t]=(n.perspective||r.perspective?M(n.perspective,r.perspective,"px",o):"")+(n.translate3d?x(n.translate3d,r.translate3d,"px",o):"")+(n.translate?U(n.translate,r.translate,"px",o):"")+(n.rotate3d?B(n.rotate3d,r.rotate3d,"deg",o):"")+(n.rotate||r.rotate?j(n.rotate,r.rotate,"deg",o):"")+(n.skew?P(n.skew,r.skew,"deg",o):"")+(n.scale||r.scale?A(n.scale,r.scale,o):"")})}},Interpolate:{perspective:M,translate3d:x,rotate3d:B,translate:U,rotate:j,scale:A,skew:P}};function F(t){t in this.valuesEnd&&!p[t]&&(p[t]=function(e,n,r,o){e.style[t]=(o>.99||o<.01?(10*d(n,r,o)>>0)/10:d(n,r,o)>>0)+"px"})}var L=["top","left","width","height"],X={};L.map((function(t){return X[t]=F}));var Y={component:"boxModelProps",category:"boxModel",properties:L,Interpolate:{numbers:d},functions:{onStart:X}};var D={component:"opacityProperty",property:"opacity",Interpolate:{numbers:d},functions:{onStart:function(t){t in this.valuesEnd&&!p[t]&&(p[t]=function(e,n,r,o){e.style[t]=(1e3*d(n,r,o)>>0)/1e3})}}};function H(t,e,n,r){r=r||!1,t.addEventListener(e,n,r)}function K(t,e,n,r){r=r||!1,t.removeEventListener(e,n,r)}var Q=function(){var t,e,n,r,o=!1;try{var i=Object.defineProperty({},"passive",{get:function(){o=!0}});t=document,n=function(){},H(t,e="DOMContentLoaded",(function o(i){i.target===t&&(n(i),K(t,e,o,r))}),r=i)}catch(t){}return o}(),Z="onmouseleave"in document?["mouseenter","mouseleave"]:["mouseover","mouseout"],N="ontouchstart"in window||navigator&&navigator.msMaxTouchPoints||!1?"touchstart":"mousewheel",G=navigator&&/(EDGE|Mac)/i.test(navigator.userAgent)?document.body:document.getElementsByTagName("HTML")[0],R=!!Q&&{passive:!1};function V(t){this.scrolling&&t.preventDefault()}function z(){var t=this.element;return t===G?{el:document,st:document.body}:{el:t,st:t}}function J(){var t=z.call(this);"scroll"in this.valuesEnd&&t.el.scrolling&&(t.el.scrolling=0,K(t.el,Z[0],V,R),K(t.el,N,V,R),t.st.style.pointerEvents="")}var W={component:"scrollProperty",property:"scroll",Interpolate:{numbers:d},functions:{onStart:function(t){t in this.valuesEnd&&!p[t]&&(p[t]=function(t,e,n,r){t.scrollTop=d(e,n,r)>>0})},onComplete:function(t){J.call(this)}},Util:{preventScroll:V,scrollIn:function(){var t=z.call(this);"scroll"in this.valuesEnd&&!t.el.scrolling&&(t.el.scrolling=1,H(t.el,Z[0],V,R),H(t.el,N,V,R),t.st.style.pointerEvents="none")},scrollOut:J,scrollContainer:G,passiveHandler:R,getScrollTargets:z}},$=new I(q),tt=new I(Y),et=new I(D),nt=new I(W);return{Animation:I,Components:{BaseTransform:$,BaseBoxModel:tt,BaseScroll:nt,BaseOpacity:et},TweenBase:O,fromTo:function(t,e,n,r){return r=r||{},new k(S(t),e,n,r)},Objects:u,Easing:l,Util:a,Render:T,Interpolate:v,Internals:C,Selector:S,Version:"2.0.0"}}));