kute.js/demo/src/kute-base.min.js
thednp 933d61de19 Changes:
* added ESLint and updated all code base 
* updated SVGPathCommander, CubicBezier, shorter-js, minifill
* updated polyfills
* minor CSS fixes
2021-03-30 09:23:29 +00:00

3 lines
7.6 KiB
JavaScript

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