mist.js
Version:
Motion Design in Modular CSS
8 lines • 9.69 kB
JavaScript
/*!
* @copyright AI428
* @description Motion Design in Modular CSS
* @license http://opensource.org/licenses/MIT
* @namespace Mist
* @version 0.8.9
*/
function mist(t){return Mist.Component.create(Mist.Statement,t)}var __extends=this&&this.__extends||function(t,n){function e(){this.constructor=t}for(var r in n)n.hasOwnProperty(r)&&(t[r]=n[r]);t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)},Mist;!function(t){function n(t){return JSON.stringify(t.map(function(t){return t instanceof Object?t.sessid||(t.sessid=r++):t}))}var e=function(){function t(){}return t.create=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];var o=n([t]),i=n(e);return this.responses[o]||(this.responses[o]={}),this.responses[o][i]||(this.responses[o][i]=new(t.bind.apply(t,[t].concat([].slice.apply(e))))),this.responses[o][i]},t}();e.responses={},t.Component=e;var r=0}(Mist||(Mist={})),function(){var t=Element.prototype;t.matches=t.matches||t.mozMatchesSelector||t.msMatchesSelector||t.webkitMatchesSelector}(),function(){var t=Element.prototype;t.closest=t.closest||function(t){for(var n=this;n&&!n.matches(t);)n=n.parentElement;return n}}();var Mist;!function(t){var n=function(){function n(t){this.statement=t,this.emits={},this.obss={}}return n.customize=function(t,n){void 0===n&&(n={});var e=document.createEvent("CustomEvent");return e.initCustomEvent(t,n.bubbles||!0,n.cancelable||!0,n.detail),e},n.prototype.add=function(t,n){this.obss[t]||(this.obss[t]=[]),this.obss[t].push(n),this.on(t)},n.prototype.emit=function(t,n){for(var e in this.obss[t])this.obss[t][e](n)},n.prototype.remove=function(t,n){function e(){var t=r.indexOf(n);t<0||r.splice(t,1)}var r=this.obss[t];r&&n?e():r=null},n.prototype.on=function(t){var n=this,e=this.emits;e[t]||document.addEventListener(t,e[t]=function(e){var r=e.target;r instanceof Element&&r.closest(n.selector())&&n.emit(t,e instanceof CustomEvent?e.detail:e)})},n.prototype.selector=function(){var n,e=this.statement;return n=e instanceof t.Statement?e.selector():e},n}();t.Emitter=n}(Mist||(Mist={}));var Mist;!function(t){var n=function(){function t(t){var n=this.succeed,e=this.erred;this.resume(),t(n.bind(this),e.bind(this))}return t.all=function(n){return new t(function(t,e){function r(n){if(i.push(n)>o){try{t(i)}catch(t){e(t)}i=[]}}var o,i=[];n.map(function(t,n){t.when(r),o=n})})},t.race=function(n){return new t(function(t,e){n.forEach(function(n){n.when(function(n){try{t(n)}catch(t){e(t)}})})})},t.prototype.catch=function(n){var e=this;return new t(function(t,r){e.err=function(e){try{t(n(e))}catch(t){r(t)}},e.tx()})},t.prototype.resume=function(){this.txd=!1,this.txr=null},t.prototype.then=function(n,e){var r=this;return new t(function(t,o){r.err=o,r.success=function(r){try{t(n(r))}catch(n){e?t(e(n)):o(n)}},r.tx()})},t.prototype.when=function(t,n){var e=this,r=function(n){var r=t(n);return e.resume(),r},o=n?function(t){var r=n(t);return e.resume(),r}:n;return this.then(r,o)},t.prototype.erred=function(n){var e=this;this.txd||(this.err?(this.txd=!0,n instanceof t?n.when(this.err):this.err(n)):this.txr=function(){e.erred(n)}),console.log(n)},t.prototype.succeed=function(n){var e=this;this.txd||(this.success?(this.txd=!0,n instanceof t?n.when(this.success):this.success(n)):this.txr=function(){e.succeed(n)})},t.prototype.tx=function(){var t=this.txr;t&&t()},t}();t.Promise=n}(Mist||(Mist={}));var Mist;!function(t){var n=function(t){function n(n,e){var r=t.call(this,function(t,r){n.add(e,function(n){try{t(n)}catch(t){r(t)}})})||this;return r.emitter=n,r.name=e,r}return __extends(n,t),n}(t.Promise);t.Emission=n}(Mist||(Mist={}));var Mist;!function(t){function n(t){for(var n={},e=0,r=t;e<r.length;e++){var o=r[e];for(var i in o)n[i]=o[i]}return n}function e(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})}var r=function(){function r(t){this.statement=t,this.main={},this.mask={}}return r.prototype.clear=function(){this.main={},this.mask={},this.modify()},r.prototype.clearAll=function(){this.statement.elements().map(function(n){t.Component.create(t.Statement,n).style.clear()})},r.prototype.modify=function(){this.node().innerHTML=[this.inner(this.main),this.inner(this.mask)].join("")},r.prototype.pause=function(){this.statement.elements().map(function(n){var e=t.Component.create(t.Statement,n).style,r=getComputedStyle(n);e.mask={},e.mask.background=r.background,e.mask.borderBottom=r.borderBottom,e.mask.borderLeft=r.borderLeft,e.mask.borderRadius=r.borderRadius,e.mask.borderRight=r.borderRight,e.mask.borderSpacing=r.borderSpacing,e.mask.borderTop=r.borderTop,e.mask.bottom=r.bottom,e.mask.boxShadow=r.boxShadow,e.mask.color=r.color,e.mask.fill=r.fill,e.mask.font=r.font,e.mask.left=r.left,e.mask.margin=r.margin,e.mask.opacity=r.opacity,e.mask.outline=r.outline,e.mask.padding=r.padding,e.mask.right=r.right,e.mask.stroke=r.stroke,e.mask.top=r.top,e.mask.transform=r.transform,e.mask.transition="none",e.modify()})},r.prototype.resume=function(){this.statement.elements().map(function(n){var e=t.Component.create(t.Statement,n).style;e.mask={},e.modify()})},r.prototype.set=function(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];var r=n(t),o=this.main;for(var i in r){var s=r[i];s instanceof Function?o[i]=s(o):o[i]=s}this.modify()},r.prototype.setAll=function(){for(var e=[],r=0;r<arguments.length;r++)e[r-0]=arguments[r];var o=n(e);this.statement.elements().map(function(n,e,r){var i={};for(var s in o){var c=o[s];c instanceof Function?i[s]=c(n,e,r):i[s]=c}t.Component.create(t.Statement,n).style.set(i)})},r.prototype.inner=function(t){var n=[];for(var r in t)n.push(e(r)+":"+t[r]);return this.statement.selector()+"{"+n.join(";")+"}"},r.prototype.node=function(){if(!this.e){var t=document.createElement("style"),n=document.createTextNode("");t.appendChild(n),document.head.appendChild(t),this.e=t}return this.e},r}();t.Style=r}(Mist||(Mist={}));var Mist;!function(t){var n=function(){function t(t){this.statement=t,this.id=0}return t.prototype.pause=function(){},t.prototype.resume=function(){},t.prototype.set=function(t,n){var e=this;clearTimeout(this.id),requestAnimationFrame(function(){e.id=setTimeout(function(){e.pause=function(){},e.resume=function(){},t.bind(e.statement)()},n)});var r=Date.now();this.pause=function(){var o=Date.now();clearTimeout(e.id),e.resume=e.set.bind(e,t,n-(o-r))}},t}();t.Timer=n}(Mist||(Mist={}));var Mist;!function(t){var n;!function(t){var n=function(){function t(t){this._component=t;var n=this;for(var e in t)t[e]instanceof Function?n[e]=n._composer.bind(n,e):Object.defineProperty(n,e,{get:n._accessor.bind(n,e)})}return t.prototype._accessor=function(t){return this._component[t]},t.prototype._composer=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return this._component[t].apply(this._component,n)},t}();t.Voker=n}(n=t.Wrapper||(t.Wrapper={}))}(Mist||(Mist={}));var Mist;!function(t){var n;!function(t){var n=function(n){function e(t,e){var r=n.call(this,t)||this;return r._commit=e,r}return __extends(e,n),e.prototype.catch=function(t){return new e(this._component,this._commit.catch(t))},e.prototype._composer=function(n){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];var i=this;return new e(i._component,i._commit.when(function(o){var s=o instanceof t.Voker?o:i._component,c=s[n].apply(s,r);return c instanceof e?c._commit:c}))},e}(t.Voker);t.Defer=n}(n=t.Wrapper||(t.Wrapper={}))}(Mist||(Mist={}));var Mist;!function(t){var n;!function(n){var e=function(e){function r(t,n){var r=e.call(this,t)||this;return r._dur=n,r}return __extends(r,e),r.prototype._composer=function(e){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];var i=this;return new n.Defer(i._component,new t.Promise(function(t,n){i._component.timer.set(function(){try{t(i._component[e].apply(i._component,r))}catch(t){n(t)}},i._dur)}))},r}(n.Voker);n.Timer=e}(n=t.Wrapper||(t.Wrapper={}))}(Mist||(Mist={}));var Mist;!function(t){function n(t){return t.id?"#"+t.id:function(){var n;return t.hasAttribute("mid")&&(n='[mid="'+t.getAttribute("mid")+'"]'),n}()||function(){var n=r++;return t.setAttribute("mid",""+n),'[mid="'+n+'"]'}()}var e=function(){function e(n){this.statement=n,this.emitter=new t.Emitter(this),this.style=new t.Style(this),this.timer=new t.Timer(this)}return e.prototype.any=function(n){return t.Component.create(e,this.selector().split(",").map(function(t){return n.split(",").map(function(n){return t.trim()+n.trim()}).join()}).join())},e.prototype.call=function(t){return t.bind(this)(),this},e.prototype.clear=function(){return this.style.clear(),this},e.prototype.clearAll=function(){return this.style.clearAll(),this},e.prototype.elements=function(){var t,n=this.statement;return t=n instanceof Element?[n]:[].map.call(document.querySelectorAll(n),function(t){return t})},e.prototype.not=function(t){return this.any(t.split(",").map(function(t){return":not("+t.trim()+")"}).join())},e.prototype.on=function(n){return new t.Emission(this.emitter,n)},e.prototype.pause=function(){return this.style.pause(),this.timer.pause(),this},e.prototype.resume=function(){return this.style.resume(),this.timer.resume(),this},e.prototype.selector=function(){var t,e=this.statement;return t=e instanceof Element?n(e):e},e.prototype.set=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];var e=this.style,r=this.style.set;return r.apply(e,t),this},e.prototype.setAll=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];var e=this.style,r=this.style.setAll;return r.apply(e,t),this},e.prototype.time=function(n){return t.Component.create(t.Wrapper.Timer,this,n)},e}();t.Statement=e;var r=0}(Mist||(Mist={}));