progressbar.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. // ProgressBar.js 1.1.0
  2. // https://kimmobrunfeldt.github.io/progressbar.js
  3. // License: MIT
  4. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ProgressBar = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  5. /*! Shifty 2.8.0 - https://github.com/jeremyckahn/shifty */
  6. !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("shifty",[],n):"object"==typeof exports?exports.shifty=n():t.shifty=n()}(window,function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)e.d(r,i,function(n){return t[n]}.bind(null,i));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=3)}([function(t,n,e){"use strict";(function(t){e.d(n,"e",function(){return d}),e.d(n,"c",function(){return y}),e.d(n,"b",function(){return _}),e.d(n,"a",function(){return g}),e.d(n,"d",function(){return w});var r=e(1);function i(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.forEach(function(n){a(t,n,e[n])})}return t}function a(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}var c="undefined"!=typeof window?window:t,f=c.requestAnimationFrame||c.webkitRequestAnimationFrame||c.oRequestAnimationFrame||c.msRequestAnimationFrame||c.mozCancelRequestAnimationFrame&&c.mozRequestAnimationFrame||setTimeout,s=function(){},l=null,h=null,p=o({},r),d=function(t,n,e,r,i,u,o){var a=t<u?0:(t-u)/i;for(var c in n){var f=o[c],s=f.call?f:p[f],l=e[c];n[c]=l+(r[c]-l)*s(a)}return n},v=function(t,n){var e=t._attachment,r=t._currentState,i=t._delay,u=t._easing,o=t._originalState,a=t._duration,c=t._step,f=t._targetState,s=t._timestamp,l=s+i+a,h=n>l?l:n,p=a-(l-h);h>=l?(c(f,e,p),t.stop(!0)):(t._applyFilter("beforeTween"),h<s+i?(h=1,a=1,s=1):s+=i,d(h,r,o,f,a,s,u),t._applyFilter("afterTween"),c(r,e,p))},y=function(){for(var t=g.now(),n=l;n;){var e=n._next;v(n,t),n=e}},_=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"linear",e={},r=u(n);if("string"===r||"function"===r)for(var i in t)e[i]=n;else for(var o in t)e[o]=n[o]||"linear";return e},m=function(t){if(t===l)(l=t._next)?l._previous=null:h=null;else if(t===h)(h=t._previous)?h._next=null:l=null;else{var n=t._previous,e=t._next;n._next=e,e._previous=n}t._previous=t._next=null},g=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this._currentState=n,this._configured=!1,this._filters=[],this._timestamp=null,this._next=null,this._previous=null,e&&this.setConfig(e)}var n,e,r;return n=t,(e=[{key:"_applyFilter",value:function(t){var n=!0,e=!1,r=void 0;try{for(var i,u=this._filters[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var o=i.value[t];o&&o(this)}}catch(t){e=!0,r=t}finally{try{n||null==u.return||u.return()}finally{if(e)throw r}}}},{key:"tween",value:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,e=this._attachment,r=this._configured;return!n&&r||this.setConfig(n),this._pausedAtTime=null,this._timestamp=t.now(),this._start(this.get(),e),this.resume()}},{key:"setConfig",value:function(){var n=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.attachment,i=e.delay,u=void 0===i?0:i,a=e.duration,c=void 0===a?500:a,f=e.easing,l=e.from,h=e.promise,p=void 0===h?Promise:h,d=e.start,v=void 0===d?s:d,y=e.step,m=void 0===y?s:y,g=e.to;this._configured=!0,this._attachment=r,this._isPlaying=!1,this._pausedAtTime=null,this._scheduleId=null,this._delay=u,this._start=v,this._step=m,this._duration=c,this._currentState=o({},l||this.get()),this._originalState=this.get(),this._targetState=o({},g||this.get());var w=this._currentState;this._targetState=o({},w,this._targetState),this._easing=_(w,f);var b=t.filters;for(var S in this._filters.length=0,b)b[S].doesApply(this)&&this._filters.push(b[S]);return this._applyFilter("tweenCreated"),this._promise=new p(function(t,e){n._resolve=t,n._reject=e}),this._promise.catch(s),this}},{key:"get",value:function(){return o({},this._currentState)}},{key:"set",value:function(t){this._currentState=t}},{key:"pause",value:function(){if(this._isPlaying)return this._pausedAtTime=t.now(),this._isPlaying=!1,m(this),this}},{key:"resume",value:function(){if(null===this._timestamp)return this.tween();if(this._isPlaying)return this._promise;var n=t.now();return this._pausedAtTime&&(this._timestamp+=n-this._pausedAtTime,this._pausedAtTime=null),this._isPlaying=!0,null===l?(l=this,h=this,function t(){l&&(f.call(c,t,1e3/60),y())}()):(this._previous=h,h._next=this,h=this),this._promise}},{key:"seek",value:function(n){n=Math.max(n,0);var e=t.now();return this._timestamp+n===0?this:(this._timestamp=e-n,this._isPlaying||v(this,e),this)}},{key:"stop",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=this._attachment,e=this._currentState,r=this._easing,i=this._originalState,u=this._targetState;if(this._isPlaying)return this._isPlaying=!1,m(this),t?(this._applyFilter("beforeTween"),d(1,e,i,u,1,0,r),this._applyFilter("afterTween"),this._applyFilter("afterTweenEnd"),this._resolve(e,n)):this._reject(e,n),this}},{key:"isPlaying",value:function(){return this._isPlaying}},{key:"setScheduleFunction",value:function(n){t.setScheduleFunction(n)}},{key:"dispose",value:function(){for(var t in this)delete this[t]}}])&&i(n.prototype,e),r&&i(n,r),t}();function w(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=new g,e=n.tween(t);return e.tweenable=n,e}g.setScheduleFunction=function(t){return f=t},g.formulas=p,g.filters={},g.now=Date.now||function(){return+new Date}}).call(this,e(2))},function(t,n,e){"use strict";e.r(n),e.d(n,"linear",function(){return r}),e.d(n,"easeInQuad",function(){return i}),e.d(n,"easeOutQuad",function(){return u}),e.d(n,"easeInOutQuad",function(){return o}),e.d(n,"easeInCubic",function(){return a}),e.d(n,"easeOutCubic",function(){return c}),e.d(n,"easeInOutCubic",function(){return f}),e.d(n,"easeInQuart",function(){return s}),e.d(n,"easeOutQuart",function(){return l}),e.d(n,"easeInOutQuart",function(){return h}),e.d(n,"easeInQuint",function(){return p}),e.d(n,"easeOutQuint",function(){return d}),e.d(n,"easeInOutQuint",function(){return v}),e.d(n,"easeInSine",function(){return y}),e.d(n,"easeOutSine",function(){return _}),e.d(n,"easeInOutSine",function(){return m}),e.d(n,"easeInExpo",function(){return g}),e.d(n,"easeOutExpo",function(){return w}),e.d(n,"easeInOutExpo",function(){return b}),e.d(n,"easeInCirc",function(){return S}),e.d(n,"easeOutCirc",function(){return O}),e.d(n,"easeInOutCirc",function(){return M}),e.d(n,"easeOutBounce",function(){return k}),e.d(n,"easeInBack",function(){return j}),e.d(n,"easeOutBack",function(){return P}),e.d(n,"easeInOutBack",function(){return x}),e.d(n,"elastic",function(){return T}),e.d(n,"swingFromTo",function(){return F}),e.d(n,"swingFrom",function(){return A}),e.d(n,"swingTo",function(){return E}),e.d(n,"bounce",function(){return I}),e.d(n,"bouncePast",function(){return C}),e.d(n,"easeFromTo",function(){return q}),e.d(n,"easeFrom",function(){return Q}),e.d(n,"easeTo",function(){return D});
  7. /*!
  8. * All equations are adapted from Thomas Fuchs'
  9. * [Scripty2](https://github.com/madrobby/scripty2/blob/master/src/effects/transitions/penner.js).
  10. *
  11. * Based on Easing Equations (c) 2003 [Robert
  12. * Penner](http://www.robertpenner.com/), all rights reserved. This work is
  13. * [subject to terms](http://www.robertpenner.com/easing_terms_of_use.html).
  14. */
  15. /*!
  16. * TERMS OF USE - EASING EQUATIONS
  17. * Open source under the BSD License.
  18. * Easing Equations (c) 2003 Robert Penner, all rights reserved.
  19. */
  20. var r=function(t){return t},i=function(t){return Math.pow(t,2)},u=function(t){return-(Math.pow(t-1,2)-1)},o=function(t){return(t/=.5)<1?.5*Math.pow(t,2):-.5*((t-=2)*t-2)},a=function(t){return Math.pow(t,3)},c=function(t){return Math.pow(t-1,3)+1},f=function(t){return(t/=.5)<1?.5*Math.pow(t,3):.5*(Math.pow(t-2,3)+2)},s=function(t){return Math.pow(t,4)},l=function(t){return-(Math.pow(t-1,4)-1)},h=function(t){return(t/=.5)<1?.5*Math.pow(t,4):-.5*((t-=2)*Math.pow(t,3)-2)},p=function(t){return Math.pow(t,5)},d=function(t){return Math.pow(t-1,5)+1},v=function(t){return(t/=.5)<1?.5*Math.pow(t,5):.5*(Math.pow(t-2,5)+2)},y=function(t){return 1-Math.cos(t*(Math.PI/2))},_=function(t){return Math.sin(t*(Math.PI/2))},m=function(t){return-.5*(Math.cos(Math.PI*t)-1)},g=function(t){return 0===t?0:Math.pow(2,10*(t-1))},w=function(t){return 1===t?1:1-Math.pow(2,-10*t)},b=function(t){return 0===t?0:1===t?1:(t/=.5)<1?.5*Math.pow(2,10*(t-1)):.5*(2-Math.pow(2,-10*--t))},S=function(t){return-(Math.sqrt(1-t*t)-1)},O=function(t){return Math.sqrt(1-Math.pow(t-1,2))},M=function(t){return(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},k=function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},j=function(t){var n=1.70158;return t*t*((n+1)*t-n)},P=function(t){var n=1.70158;return(t-=1)*t*((n+1)*t+n)+1},x=function(t){var n=1.70158;return(t/=.5)<1?t*t*((1+(n*=1.525))*t-n)*.5:.5*((t-=2)*t*((1+(n*=1.525))*t+n)+2)},T=function(t){return-1*Math.pow(4,-8*t)*Math.sin((6*t-1)*(2*Math.PI)/2)+1},F=function(t){var n=1.70158;return(t/=.5)<1?t*t*((1+(n*=1.525))*t-n)*.5:.5*((t-=2)*t*((1+(n*=1.525))*t+n)+2)},A=function(t){var n=1.70158;return t*t*((n+1)*t-n)},E=function(t){var n=1.70158;return(t-=1)*t*((n+1)*t+n)+1},I=function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},C=function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?2-(7.5625*(t-=1.5/2.75)*t+.75):t<2.5/2.75?2-(7.5625*(t-=2.25/2.75)*t+.9375):2-(7.5625*(t-=2.625/2.75)*t+.984375)},q=function(t){return(t/=.5)<1?.5*Math.pow(t,4):-.5*((t-=2)*Math.pow(t,3)-2)},Q=function(t){return Math.pow(t,4)},D=function(t){return Math.pow(t,.25)}},function(t,n){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,n,e){"use strict";e.r(n);var r={};e.r(r),e.d(r,"doesApply",function(){return x}),e.d(r,"tweenCreated",function(){return T}),e.d(r,"beforeTween",function(){return F}),e.d(r,"afterTween",function(){return A});var i,u,o=e(0),a=/(\d|-|\.)/,c=/([^\-0-9.]+)/g,f=/[0-9.-]+/g,s=(i=f.source,u=/,\s*/.source,new RegExp("rgb\\(".concat(i).concat(u).concat(i).concat(u).concat(i,"\\)"),"g")),l=/^.*\(/,h=/#([0-9]|[a-f]){3,6}/gi,p=function(t,n){return t.map(function(t,e){return"_".concat(n,"_").concat(e)})};function d(t){return parseInt(t,16)}var v=function(t){return"rgb(".concat((n=t,3===(n=n.replace(/#/,"")).length&&(n=(n=n.split(""))[0]+n[0]+n[1]+n[1]+n[2]+n[2]),[d(n.substr(0,2)),d(n.substr(2,2)),d(n.substr(4,2))]).join(","),")");var n},y=function(t,n,e){var r=n.match(t),i=n.replace(t,"VAL");return r&&r.forEach(function(t){return i=i.replace("VAL",e(t))}),i},_=function(t){for(var n in t){var e=t[n];"string"==typeof e&&e.match(h)&&(t[n]=y(h,e,v))}},m=function(t){var n=t.match(f).map(Math.floor),e=t.match(l)[0];return"".concat(e).concat(n.join(","),")")},g=function(t){return t.match(f)},w=function(t){var n,e,r={};for(var i in t){var u=t[i];"string"==typeof u&&(r[i]={formatString:(n=u,e=void 0,e=n.match(c),e?(1===e.length||n.charAt(0).match(a))&&e.unshift(""):e=["",""],e.join("VAL")),chunkNames:p(g(u),i)})}return r},b=function(t,n){var e=function(e){g(t[e]).forEach(function(r,i){return t[n[e].chunkNames[i]]=+r}),delete t[e]};for(var r in n)e(r)},S=function(t,n){var e={};return n.forEach(function(n){e[n]=t[n],delete t[n]}),e},O=function(t,n){return n.map(function(n){return t[n]})},M=function(t,n){return n.forEach(function(n){return t=t.replace("VAL",+n.toFixed(4))}),t},k=function(t,n){for(var e in n){var r=n[e],i=r.chunkNames,u=r.formatString,o=M(u,O(S(t,i),i));t[e]=y(s,o,m)}},j=function(t,n){var e=function(e){var r=n[e].chunkNames,i=t[e];if("string"==typeof i){var u=i.split(" "),o=u[u.length-1];r.forEach(function(n,e){return t[n]=u[e]||o})}else r.forEach(function(n){return t[n]=i});delete t[e]};for(var r in n)e(r)},P=function(t,n){for(var e in n){var r=n[e].chunkNames,i=t[r[0]];t[e]="string"==typeof i?r.map(function(n){var e=t[n];return delete t[n],e}).join(" "):i}},x=function(t){var n=t._currentState;return Object.keys(n).some(function(t){return"string"==typeof n[t]})};function T(t){var n=t._currentState;[n,t._originalState,t._targetState].forEach(_),t._tokenData=w(n)}function F(t){var n=t._currentState,e=t._originalState,r=t._targetState,i=t._easing,u=t._tokenData;j(i,u),[n,e,r].forEach(function(t){return b(t,u)})}function A(t){var n=t._currentState,e=t._originalState,r=t._targetState,i=t._easing,u=t._tokenData;[n,e,r].forEach(function(t){return k(t,u)}),P(i,u)}function E(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}var I=new o.a,C=o.a.filters,q=function(t,n,e,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,u=function(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.forEach(function(n){E(t,n,e[n])})}return t}({},t),a=Object(o.b)(t,r);for(var c in I._filters.length=0,I.set({}),I._currentState=u,I._originalState=t,I._targetState=n,I._easing=a,C)C[c].doesApply(I)&&I._filters.push(C[c]);I._applyFilter("tweenCreated"),I._applyFilter("beforeTween");var f=Object(o.e)(e,u,t,n,1,i,a);return I._applyFilter("afterTween"),f};function Q(t){return function(t){if(Array.isArray(t)){for(var n=0,e=new Array(t.length);n<t.length;n++)e[n]=t[n];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function D(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function B(t,n){if(!n.has(t))throw new TypeError("attempted to get private field on non-instance");var e=n.get(t);return e.get?e.get.call(t):e.value}var N=function(){function t(){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),R.set(this,{writable:!0,value:[]});for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];e.forEach(this.add.bind(this))}var n,e,r;return n=t,(e=[{key:"add",value:function(t){return B(this,R).push(t),t}},{key:"remove",value:function(t){var n=B(this,R).indexOf(t);return~n&&B(this,R).splice(n,1),t}},{key:"empty",value:function(){return this.tweenables.map(this.remove.bind(this))}},{key:"isPlaying",value:function(){return B(this,R).some(function(t){return t.isPlaying()})}},{key:"play",value:function(){return B(this,R).forEach(function(t){return t.tween()}),this}},{key:"pause",value:function(){return B(this,R).forEach(function(t){return t.pause()}),this}},{key:"resume",value:function(){return B(this,R).forEach(function(t){return t.resume()}),this}},{key:"stop",value:function(t){return B(this,R).forEach(function(n){return n.stop(t)}),this}},{key:"tweenables",get:function(){return Q(B(this,R))}},{key:"promises",get:function(){return B(this,R).map(function(t){return t._promise})}}])&&D(n.prototype,e),r&&D(n,r),t}(),R=new WeakMap;function z(t,n,e,r,i,u){var o=0,a=0,c=0,f=0,s=0,l=0,h=function(t){return((o*t+a)*t+c)*t},p=function(t){return t>=0?t:0-t};return o=1-(c=3*n)-(a=3*(r-n)-c),f=1-(l=3*e)-(s=3*(i-e)-l),function(t,n){return e=function(t,n){var e,r,i,u,f,s,l;for(i=t,s=0;s<8;s++){if(u=h(i)-t,p(u)<n)return i;if(p(f=(3*o*(l=i)+2*a)*l+c)<1e-6)break;i-=u/f}if((i=t)<(e=0))return e;if(i>(r=1))return r;for(;e<r;){if(u=h(i),p(u-t)<n)return i;t>u?e=i:r=i,i=.5*(r-e)+e}return i}(t,n),((f*e+s)*e+l)*e;var e}(t,function(t){return 1/(200*t)}(u))}var L=function(t,n,e,r,i){var u=function(t,n,e,r){return function(i){return z(i,t,n,e,r,1)}}(n,e,r,i);return u.displayName=t,u.x1=n,u.y1=e,u.x2=r,u.y2=i,o.a.formulas[t]=u},V=function(t){return delete o.a.formulas[t]};e.d(n,"processTweens",function(){return o.c}),e.d(n,"Tweenable",function(){return o.a}),e.d(n,"tween",function(){return o.d}),e.d(n,"interpolate",function(){return q}),e.d(n,"Scene",function(){return N}),e.d(n,"setBezierFunction",function(){return L}),e.d(n,"unsetBezierFunction",function(){return V}),o.a.filters.token=r}])});
  21. },{}],2:[function(require,module,exports){
  22. // Circle shaped progress bar
  23. var Shape = require('./shape');
  24. var utils = require('./utils');
  25. var Circle = function Circle(container, options) {
  26. // Use two arcs to form a circle
  27. // See this answer http://stackoverflow.com/a/10477334/1446092
  28. this._pathTemplate =
  29. 'M 50,50 m 0,-{radius}' +
  30. ' a {radius},{radius} 0 1 1 0,{2radius}' +
  31. ' a {radius},{radius} 0 1 1 0,-{2radius}';
  32. this.containerAspectRatio = 1;
  33. Shape.apply(this, arguments);
  34. };
  35. Circle.prototype = new Shape();
  36. Circle.prototype.constructor = Circle;
  37. Circle.prototype._pathString = function _pathString(opts) {
  38. var widthOfWider = opts.strokeWidth;
  39. if (opts.trailWidth && opts.trailWidth > opts.strokeWidth) {
  40. widthOfWider = opts.trailWidth;
  41. }
  42. var r = 50 - widthOfWider / 2;
  43. return utils.render(this._pathTemplate, {
  44. radius: r,
  45. '2radius': r * 2
  46. });
  47. };
  48. Circle.prototype._trailString = function _trailString(opts) {
  49. return this._pathString(opts);
  50. };
  51. module.exports = Circle;
  52. },{"./shape":7,"./utils":9}],3:[function(require,module,exports){
  53. // Line shaped progress bar
  54. var Shape = require('./shape');
  55. var utils = require('./utils');
  56. var Line = function Line(container, options) {
  57. this._pathTemplate = 'M 0,{center} L 100,{center}';
  58. Shape.apply(this, arguments);
  59. };
  60. Line.prototype = new Shape();
  61. Line.prototype.constructor = Line;
  62. Line.prototype._initializeSvg = function _initializeSvg(svg, opts) {
  63. svg.setAttribute('viewBox', '0 0 100 ' + opts.strokeWidth);
  64. svg.setAttribute('preserveAspectRatio', 'none');
  65. };
  66. Line.prototype._pathString = function _pathString(opts) {
  67. return utils.render(this._pathTemplate, {
  68. center: opts.strokeWidth / 2
  69. });
  70. };
  71. Line.prototype._trailString = function _trailString(opts) {
  72. return this._pathString(opts);
  73. };
  74. module.exports = Line;
  75. },{"./shape":7,"./utils":9}],4:[function(require,module,exports){
  76. module.exports = {
  77. // Higher level API, different shaped progress bars
  78. Line: require('./line'),
  79. Circle: require('./circle'),
  80. SemiCircle: require('./semicircle'),
  81. Square: require('./square'),
  82. // Lower level API to use any SVG path
  83. Path: require('./path'),
  84. // Base-class for creating new custom shapes
  85. // to be in line with the API of built-in shapes
  86. // Undocumented.
  87. Shape: require('./shape'),
  88. // Internal utils, undocumented.
  89. utils: require('./utils')
  90. };
  91. },{"./circle":2,"./line":3,"./path":5,"./semicircle":6,"./shape":7,"./square":8,"./utils":9}],5:[function(require,module,exports){
  92. // Lower level API to animate any kind of svg path
  93. var shifty = require('shifty');
  94. var utils = require('./utils');
  95. var Tweenable = shifty.Tweenable;
  96. var EASING_ALIASES = {
  97. easeIn: 'easeInCubic',
  98. easeOut: 'easeOutCubic',
  99. easeInOut: 'easeInOutCubic'
  100. };
  101. var Path = function Path(path, opts) {
  102. // Throw a better error if not initialized with `new` keyword
  103. if (!(this instanceof Path)) {
  104. throw new Error('Constructor was called without new keyword');
  105. }
  106. // Default parameters for animation
  107. opts = utils.extend({
  108. delay: 0,
  109. duration: 800,
  110. easing: 'linear',
  111. from: {},
  112. to: {},
  113. step: function() {}
  114. }, opts);
  115. var element;
  116. if (utils.isString(path)) {
  117. element = document.querySelector(path);
  118. } else {
  119. element = path;
  120. }
  121. // Reveal .path as public attribute
  122. this.path = element;
  123. this._opts = opts;
  124. this._tweenable = null;
  125. // Set up the starting positions
  126. var length = this.path.getTotalLength();
  127. this.path.style.strokeDasharray = length + ' ' + length;
  128. this.set(0);
  129. };
  130. Path.prototype.value = function value() {
  131. var offset = this._getComputedDashOffset();
  132. var length = this.path.getTotalLength();
  133. var progress = 1 - offset / length;
  134. // Round number to prevent returning very small number like 1e-30, which
  135. // is practically 0
  136. return parseFloat(progress.toFixed(6), 10);
  137. };
  138. Path.prototype.set = function set(progress) {
  139. this.stop();
  140. this.path.style.strokeDashoffset = this._progressToOffset(progress);
  141. var step = this._opts.step;
  142. if (utils.isFunction(step)) {
  143. var easing = this._easing(this._opts.easing);
  144. var values = this._calculateTo(progress, easing);
  145. var reference = this._opts.shape || this;
  146. step(values, reference, this._opts.attachment);
  147. }
  148. };
  149. Path.prototype.stop = function stop() {
  150. this._stopTween();
  151. this.path.style.strokeDashoffset = this._getComputedDashOffset();
  152. };
  153. // Method introduced here:
  154. // http://jakearchibald.com/2013/animated-line-drawing-svg/
  155. Path.prototype.animate = function animate(progress, opts, cb) {
  156. opts = opts || {};
  157. if (utils.isFunction(opts)) {
  158. cb = opts;
  159. opts = {};
  160. }
  161. var passedOpts = utils.extend({}, opts);
  162. // Copy default opts to new object so defaults are not modified
  163. var defaultOpts = utils.extend({}, this._opts);
  164. opts = utils.extend(defaultOpts, opts);
  165. var shiftyEasing = this._easing(opts.easing);
  166. var values = this._resolveFromAndTo(progress, shiftyEasing, passedOpts);
  167. this.stop();
  168. // Trigger a layout so styles are calculated & the browser
  169. // picks up the starting position before animating
  170. this.path.getBoundingClientRect();
  171. var offset = this._getComputedDashOffset();
  172. var newOffset = this._progressToOffset(progress);
  173. var self = this;
  174. this._tweenable = new Tweenable();
  175. this._tweenable.tween({
  176. from: utils.extend({ offset: offset }, values.from),
  177. to: utils.extend({ offset: newOffset }, values.to),
  178. duration: opts.duration,
  179. delay: opts.delay,
  180. easing: shiftyEasing,
  181. step: function(state) {
  182. self.path.style.strokeDashoffset = state.offset;
  183. var reference = opts.shape || self;
  184. opts.step(state, reference, opts.attachment);
  185. }
  186. }).then(function(state) {
  187. if (utils.isFunction(cb)) {
  188. cb();
  189. }
  190. });
  191. };
  192. Path.prototype._getComputedDashOffset = function _getComputedDashOffset() {
  193. var computedStyle = window.getComputedStyle(this.path, null);
  194. return parseFloat(computedStyle.getPropertyValue('stroke-dashoffset'), 10);
  195. };
  196. Path.prototype._progressToOffset = function _progressToOffset(progress) {
  197. var length = this.path.getTotalLength();
  198. return length - progress * length;
  199. };
  200. // Resolves from and to values for animation.
  201. Path.prototype._resolveFromAndTo = function _resolveFromAndTo(progress, easing, opts) {
  202. if (opts.from && opts.to) {
  203. return {
  204. from: opts.from,
  205. to: opts.to
  206. };
  207. }
  208. return {
  209. from: this._calculateFrom(easing),
  210. to: this._calculateTo(progress, easing)
  211. };
  212. };
  213. // Calculate `from` values from options passed at initialization
  214. Path.prototype._calculateFrom = function _calculateFrom(easing) {
  215. return shifty.interpolate(this._opts.from, this._opts.to, this.value(), easing);
  216. };
  217. // Calculate `to` values from options passed at initialization
  218. Path.prototype._calculateTo = function _calculateTo(progress, easing) {
  219. return shifty.interpolate(this._opts.from, this._opts.to, progress, easing);
  220. };
  221. Path.prototype._stopTween = function _stopTween() {
  222. if (this._tweenable !== null) {
  223. this._tweenable.stop();
  224. this._tweenable = null;
  225. }
  226. };
  227. Path.prototype._easing = function _easing(easing) {
  228. if (EASING_ALIASES.hasOwnProperty(easing)) {
  229. return EASING_ALIASES[easing];
  230. }
  231. return easing;
  232. };
  233. module.exports = Path;
  234. },{"./utils":9,"shifty":1}],6:[function(require,module,exports){
  235. // Semi-SemiCircle shaped progress bar
  236. var Shape = require('./shape');
  237. var Circle = require('./circle');
  238. var utils = require('./utils');
  239. var SemiCircle = function SemiCircle(container, options) {
  240. // Use one arc to form a SemiCircle
  241. // See this answer http://stackoverflow.com/a/10477334/1446092
  242. this._pathTemplate =
  243. 'M 50,50 m -{radius},0' +
  244. ' a {radius},{radius} 0 1 1 {2radius},0';
  245. this.containerAspectRatio = 2;
  246. Shape.apply(this, arguments);
  247. };
  248. SemiCircle.prototype = new Shape();
  249. SemiCircle.prototype.constructor = SemiCircle;
  250. SemiCircle.prototype._initializeSvg = function _initializeSvg(svg, opts) {
  251. svg.setAttribute('viewBox', '0 0 100 50');
  252. };
  253. SemiCircle.prototype._initializeTextContainer = function _initializeTextContainer(
  254. opts,
  255. container,
  256. textContainer
  257. ) {
  258. if (opts.text.style) {
  259. // Reset top style
  260. textContainer.style.top = 'auto';
  261. textContainer.style.bottom = '0';
  262. if (opts.text.alignToBottom) {
  263. utils.setStyle(textContainer, 'transform', 'translate(-50%, 0)');
  264. } else {
  265. utils.setStyle(textContainer, 'transform', 'translate(-50%, 50%)');
  266. }
  267. }
  268. };
  269. // Share functionality with Circle, just have different path
  270. SemiCircle.prototype._pathString = Circle.prototype._pathString;
  271. SemiCircle.prototype._trailString = Circle.prototype._trailString;
  272. module.exports = SemiCircle;
  273. },{"./circle":2,"./shape":7,"./utils":9}],7:[function(require,module,exports){
  274. // Base object for different progress bar shapes
  275. var Path = require('./path');
  276. var utils = require('./utils');
  277. var DESTROYED_ERROR = 'Object is destroyed';
  278. var Shape = function Shape(container, opts) {
  279. // Throw a better error if progress bars are not initialized with `new`
  280. // keyword
  281. if (!(this instanceof Shape)) {
  282. throw new Error('Constructor was called without new keyword');
  283. }
  284. // Prevent calling constructor without parameters so inheritance
  285. // works correctly. To understand, this is how Shape is inherited:
  286. //
  287. // Line.prototype = new Shape();
  288. //
  289. // We just want to set the prototype for Line.
  290. if (arguments.length === 0) {
  291. return;
  292. }
  293. // Default parameters for progress bar creation
  294. this._opts = utils.extend({
  295. color: '#555',
  296. strokeWidth: 1.0,
  297. trailColor: null,
  298. trailWidth: null,
  299. fill: null,
  300. text: {
  301. style: {
  302. color: null,
  303. position: 'absolute',
  304. left: '50%',
  305. top: '50%',
  306. padding: 0,
  307. margin: 0,
  308. transform: {
  309. prefix: true,
  310. value: 'translate(-50%, -50%)'
  311. }
  312. },
  313. autoStyleContainer: true,
  314. alignToBottom: true,
  315. value: null,
  316. className: 'progressbar-text'
  317. },
  318. svgStyle: {
  319. display: 'block',
  320. width: '100%'
  321. },
  322. warnings: false
  323. }, opts, true); // Use recursive extend
  324. // If user specifies e.g. svgStyle or text style, the whole object
  325. // should replace the defaults to make working with styles easier
  326. if (utils.isObject(opts) && opts.svgStyle !== undefined) {
  327. this._opts.svgStyle = opts.svgStyle;
  328. }
  329. if (utils.isObject(opts) && utils.isObject(opts.text) && opts.text.style !== undefined) {
  330. this._opts.text.style = opts.text.style;
  331. }
  332. var svgView = this._createSvgView(this._opts);
  333. var element;
  334. if (utils.isString(container)) {
  335. element = document.querySelector(container);
  336. } else {
  337. element = container;
  338. }
  339. if (!element) {
  340. throw new Error('Container does not exist: ' + container);
  341. }
  342. this._container = element;
  343. this._container.appendChild(svgView.svg);
  344. if (this._opts.warnings) {
  345. this._warnContainerAspectRatio(this._container);
  346. }
  347. if (this._opts.svgStyle) {
  348. utils.setStyles(svgView.svg, this._opts.svgStyle);
  349. }
  350. // Expose public attributes before Path initialization
  351. this.svg = svgView.svg;
  352. this.path = svgView.path;
  353. this.trail = svgView.trail;
  354. this.text = null;
  355. var newOpts = utils.extend({
  356. attachment: undefined,
  357. shape: this
  358. }, this._opts);
  359. this._progressPath = new Path(svgView.path, newOpts);
  360. if (utils.isObject(this._opts.text) && this._opts.text.value !== null) {
  361. this.setText(this._opts.text.value);
  362. }
  363. };
  364. Shape.prototype.animate = function animate(progress, opts, cb) {
  365. if (this._progressPath === null) {
  366. throw new Error(DESTROYED_ERROR);
  367. }
  368. this._progressPath.animate(progress, opts, cb);
  369. };
  370. Shape.prototype.stop = function stop() {
  371. if (this._progressPath === null) {
  372. throw new Error(DESTROYED_ERROR);
  373. }
  374. // Don't crash if stop is called inside step function
  375. if (this._progressPath === undefined) {
  376. return;
  377. }
  378. this._progressPath.stop();
  379. };
  380. Shape.prototype.pause = function pause() {
  381. if (this._progressPath === null) {
  382. throw new Error(DESTROYED_ERROR);
  383. }
  384. if (this._progressPath === undefined) {
  385. return;
  386. }
  387. if (!this._progressPath._tweenable) {
  388. // It seems that we can't pause this
  389. return;
  390. }
  391. this._progressPath._tweenable.pause();
  392. };
  393. Shape.prototype.resume = function resume() {
  394. if (this._progressPath === null) {
  395. throw new Error(DESTROYED_ERROR);
  396. }
  397. if (this._progressPath === undefined) {
  398. return;
  399. }
  400. if (!this._progressPath._tweenable) {
  401. // It seems that we can't resume this
  402. return;
  403. }
  404. this._progressPath._tweenable.resume();
  405. };
  406. Shape.prototype.destroy = function destroy() {
  407. if (this._progressPath === null) {
  408. throw new Error(DESTROYED_ERROR);
  409. }
  410. this.stop();
  411. this.svg.parentNode.removeChild(this.svg);
  412. this.svg = null;
  413. this.path = null;
  414. this.trail = null;
  415. this._progressPath = null;
  416. if (this.text !== null) {
  417. this.text.parentNode.removeChild(this.text);
  418. this.text = null;
  419. }
  420. };
  421. Shape.prototype.set = function set(progress) {
  422. if (this._progressPath === null) {
  423. throw new Error(DESTROYED_ERROR);
  424. }
  425. this._progressPath.set(progress);
  426. };
  427. Shape.prototype.value = function value() {
  428. if (this._progressPath === null) {
  429. throw new Error(DESTROYED_ERROR);
  430. }
  431. if (this._progressPath === undefined) {
  432. return 0;
  433. }
  434. return this._progressPath.value();
  435. };
  436. Shape.prototype.setText = function setText(newText) {
  437. if (this._progressPath === null) {
  438. throw new Error(DESTROYED_ERROR);
  439. }
  440. if (this.text === null) {
  441. // Create new text node
  442. this.text = this._createTextContainer(this._opts, this._container);
  443. this._container.appendChild(this.text);
  444. }
  445. // Remove previous text and add new
  446. if (utils.isObject(newText)) {
  447. utils.removeChildren(this.text);
  448. this.text.appendChild(newText);
  449. } else {
  450. this.text.innerHTML = newText;
  451. }
  452. };
  453. Shape.prototype._createSvgView = function _createSvgView(opts) {
  454. var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  455. this._initializeSvg(svg, opts);
  456. var trailPath = null;
  457. // Each option listed in the if condition are 'triggers' for creating
  458. // the trail path
  459. if (opts.trailColor || opts.trailWidth) {
  460. trailPath = this._createTrail(opts);
  461. svg.appendChild(trailPath);
  462. }
  463. var path = this._createPath(opts);
  464. svg.appendChild(path);
  465. return {
  466. svg: svg,
  467. path: path,
  468. trail: trailPath
  469. };
  470. };
  471. Shape.prototype._initializeSvg = function _initializeSvg(svg, opts) {
  472. svg.setAttribute('viewBox', '0 0 100 100');
  473. };
  474. Shape.prototype._createPath = function _createPath(opts) {
  475. var pathString = this._pathString(opts);
  476. return this._createPathElement(pathString, opts);
  477. };
  478. Shape.prototype._createTrail = function _createTrail(opts) {
  479. // Create path string with original passed options
  480. var pathString = this._trailString(opts);
  481. // Prevent modifying original
  482. var newOpts = utils.extend({}, opts);
  483. // Defaults for parameters which modify trail path
  484. if (!newOpts.trailColor) {
  485. newOpts.trailColor = '#eee';
  486. }
  487. if (!newOpts.trailWidth) {
  488. newOpts.trailWidth = newOpts.strokeWidth;
  489. }
  490. newOpts.color = newOpts.trailColor;
  491. newOpts.strokeWidth = newOpts.trailWidth;
  492. // When trail path is set, fill must be set for it instead of the
  493. // actual path to prevent trail stroke from clipping
  494. newOpts.fill = null;
  495. return this._createPathElement(pathString, newOpts);
  496. };
  497. Shape.prototype._createPathElement = function _createPathElement(pathString, opts) {
  498. var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  499. path.setAttribute('d', pathString);
  500. path.setAttribute('stroke', opts.color);
  501. path.setAttribute('stroke-width', opts.strokeWidth);
  502. if (opts.fill) {
  503. path.setAttribute('fill', opts.fill);
  504. } else {
  505. path.setAttribute('fill-opacity', '0');
  506. }
  507. return path;
  508. };
  509. Shape.prototype._createTextContainer = function _createTextContainer(opts, container) {
  510. var textContainer = document.createElement('div');
  511. textContainer.className = opts.text.className;
  512. var textStyle = opts.text.style;
  513. if (textStyle) {
  514. if (opts.text.autoStyleContainer) {
  515. container.style.position = 'relative';
  516. }
  517. utils.setStyles(textContainer, textStyle);
  518. // Default text color to progress bar's color
  519. if (!textStyle.color) {
  520. textContainer.style.color = opts.color;
  521. }
  522. }
  523. this._initializeTextContainer(opts, container, textContainer);
  524. return textContainer;
  525. };
  526. // Give custom shapes possibility to modify text element
  527. Shape.prototype._initializeTextContainer = function(opts, container, element) {
  528. // By default, no-op
  529. // Custom shapes should respect API options, such as text.style
  530. };
  531. Shape.prototype._pathString = function _pathString(opts) {
  532. throw new Error('Override this function for each progress bar');
  533. };
  534. Shape.prototype._trailString = function _trailString(opts) {
  535. throw new Error('Override this function for each progress bar');
  536. };
  537. Shape.prototype._warnContainerAspectRatio = function _warnContainerAspectRatio(container) {
  538. if (!this.containerAspectRatio) {
  539. return;
  540. }
  541. var computedStyle = window.getComputedStyle(container, null);
  542. var width = parseFloat(computedStyle.getPropertyValue('width'), 10);
  543. var height = parseFloat(computedStyle.getPropertyValue('height'), 10);
  544. if (!utils.floatEquals(this.containerAspectRatio, width / height)) {
  545. console.warn(
  546. 'Incorrect aspect ratio of container',
  547. '#' + container.id,
  548. 'detected:',
  549. computedStyle.getPropertyValue('width') + '(width)',
  550. '/',
  551. computedStyle.getPropertyValue('height') + '(height)',
  552. '=',
  553. width / height
  554. );
  555. console.warn(
  556. 'Aspect ratio of should be',
  557. this.containerAspectRatio
  558. );
  559. }
  560. };
  561. module.exports = Shape;
  562. },{"./path":5,"./utils":9}],8:[function(require,module,exports){
  563. // Square shaped progress bar
  564. // Note: Square is not core part of API anymore. It's left here
  565. // for reference. square is not included to the progressbar
  566. // build anymore
  567. var Shape = require('./shape');
  568. var utils = require('./utils');
  569. var Square = function Square(container, options) {
  570. this._pathTemplate =
  571. 'M 0,{halfOfStrokeWidth}' +
  572. ' L {width},{halfOfStrokeWidth}' +
  573. ' L {width},{width}' +
  574. ' L {halfOfStrokeWidth},{width}' +
  575. ' L {halfOfStrokeWidth},{strokeWidth}';
  576. this._trailTemplate =
  577. 'M {startMargin},{halfOfStrokeWidth}' +
  578. ' L {width},{halfOfStrokeWidth}' +
  579. ' L {width},{width}' +
  580. ' L {halfOfStrokeWidth},{width}' +
  581. ' L {halfOfStrokeWidth},{halfOfStrokeWidth}';
  582. Shape.apply(this, arguments);
  583. };
  584. Square.prototype = new Shape();
  585. Square.prototype.constructor = Square;
  586. Square.prototype._pathString = function _pathString(opts) {
  587. var w = 100 - opts.strokeWidth / 2;
  588. return utils.render(this._pathTemplate, {
  589. width: w,
  590. strokeWidth: opts.strokeWidth,
  591. halfOfStrokeWidth: opts.strokeWidth / 2
  592. });
  593. };
  594. Square.prototype._trailString = function _trailString(opts) {
  595. var w = 100 - opts.strokeWidth / 2;
  596. return utils.render(this._trailTemplate, {
  597. width: w,
  598. strokeWidth: opts.strokeWidth,
  599. halfOfStrokeWidth: opts.strokeWidth / 2,
  600. startMargin: opts.strokeWidth / 2 - opts.trailWidth / 2
  601. });
  602. };
  603. module.exports = Square;
  604. },{"./shape":7,"./utils":9}],9:[function(require,module,exports){
  605. // Utility functions
  606. var PREFIXES = 'Webkit Moz O ms'.split(' ');
  607. var FLOAT_COMPARISON_EPSILON = 0.001;
  608. // Copy all attributes from source object to destination object.
  609. // destination object is mutated.
  610. function extend(destination, source, recursive) {
  611. destination = destination || {};
  612. source = source || {};
  613. recursive = recursive || false;
  614. for (var attrName in source) {
  615. if (source.hasOwnProperty(attrName)) {
  616. var destVal = destination[attrName];
  617. var sourceVal = source[attrName];
  618. if (recursive && isObject(destVal) && isObject(sourceVal)) {
  619. destination[attrName] = extend(destVal, sourceVal, recursive);
  620. } else {
  621. destination[attrName] = sourceVal;
  622. }
  623. }
  624. }
  625. return destination;
  626. }
  627. // Renders templates with given variables. Variables must be surrounded with
  628. // braces without any spaces, e.g. {variable}
  629. // All instances of variable placeholders will be replaced with given content
  630. // Example:
  631. // render('Hello, {message}!', {message: 'world'})
  632. function render(template, vars) {
  633. var rendered = template;
  634. for (var key in vars) {
  635. if (vars.hasOwnProperty(key)) {
  636. var val = vars[key];
  637. var regExpString = '\\{' + key + '\\}';
  638. var regExp = new RegExp(regExpString, 'g');
  639. rendered = rendered.replace(regExp, val);
  640. }
  641. }
  642. return rendered;
  643. }
  644. function setStyle(element, style, value) {
  645. var elStyle = element.style; // cache for performance
  646. for (var i = 0; i < PREFIXES.length; ++i) {
  647. var prefix = PREFIXES[i];
  648. elStyle[prefix + capitalize(style)] = value;
  649. }
  650. elStyle[style] = value;
  651. }
  652. function setStyles(element, styles) {
  653. forEachObject(styles, function(styleValue, styleName) {
  654. // Allow disabling some individual styles by setting them
  655. // to null or undefined
  656. if (styleValue === null || styleValue === undefined) {
  657. return;
  658. }
  659. // If style's value is {prefix: true, value: '50%'},
  660. // Set also browser prefixed styles
  661. if (isObject(styleValue) && styleValue.prefix === true) {
  662. setStyle(element, styleName, styleValue.value);
  663. } else {
  664. element.style[styleName] = styleValue;
  665. }
  666. });
  667. }
  668. function capitalize(text) {
  669. return text.charAt(0).toUpperCase() + text.slice(1);
  670. }
  671. function isString(obj) {
  672. return typeof obj === 'string' || obj instanceof String;
  673. }
  674. function isFunction(obj) {
  675. return typeof obj === 'function';
  676. }
  677. function isArray(obj) {
  678. return Object.prototype.toString.call(obj) === '[object Array]';
  679. }
  680. // Returns true if `obj` is object as in {a: 1, b: 2}, not if it's function or
  681. // array
  682. function isObject(obj) {
  683. if (isArray(obj)) {
  684. return false;
  685. }
  686. var type = typeof obj;
  687. return type === 'object' && !!obj;
  688. }
  689. function forEachObject(object, callback) {
  690. for (var key in object) {
  691. if (object.hasOwnProperty(key)) {
  692. var val = object[key];
  693. callback(val, key);
  694. }
  695. }
  696. }
  697. function floatEquals(a, b) {
  698. return Math.abs(a - b) < FLOAT_COMPARISON_EPSILON;
  699. }
  700. // https://coderwall.com/p/nygghw/don-t-use-innerhtml-to-empty-dom-elements
  701. function removeChildren(el) {
  702. while (el.firstChild) {
  703. el.removeChild(el.firstChild);
  704. }
  705. }
  706. module.exports = {
  707. extend: extend,
  708. render: render,
  709. setStyle: setStyle,
  710. setStyles: setStyles,
  711. capitalize: capitalize,
  712. isString: isString,
  713. isFunction: isFunction,
  714. isObject: isObject,
  715. forEachObject: forEachObject,
  716. floatEquals: floatEquals,
  717. removeChildren: removeChildren
  718. };
  719. },{}]},{},[4])(4)
  720. });