preact-css-transition-group-copy
Version:
Apply CSS transitions when adding or removing Preact components/elements.
2 lines • 8.76 kB
JavaScript
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("preact")):"function"==typeof define&&define.amd?define(["preact"],t):n.PreactCSSTransitionGroup=t(n.preact)}(this,function(n){"use strict";function t(n){return n.attributes&&n.attributes.key}function e(n){return n.base}function i(n){return n&&n[0]}function r(n){return n&&n.filter(function(n){return null!==n})}function o(n,t){for(var e=n.length;e--;)if(t(n[e]))return!0;return!1}function s(n,e){return o(n,function(n){return t(n)===e})}function a(n,e){return s(n,t(e))}function u(n,e,i){return o(n,function(n){return t(n)===e&&n.props[i]})}function c(n,e,i){return u(n,t(e),i)}function l(n,e){var i=[],r={},o=[];return n.forEach(function(n){var i=t(n);s(e,i)?o.length&&(r[i]=o,o=[]):o.push(n)}),e.forEach(function(n){var e=t(n);r.hasOwnProperty(e)&&(i=i.concat(r[e])),i.push(n)}),i.concat(o)}function p(n,t){if(n.classList){var e;(e=n.classList).add.apply(e,t.split(" "))}else n.className+=" "+t}function f(n,t){if(t=t.trim(),n.classList){var e;(e=n.classList).remove.apply(e,t.split(" "))}else{var i=n.className.trim(),r=T(i);for(t=v+t+v;r.indexOf(t)>=0;)r=r.replace(t,v);n.className=r.trim()}}function h(n,t){if(!L.length)return window.setTimeout(t,0);L.forEach(function(e){n.addEventListener(e,t,!1)})}function m(n,t){L.length&&L.forEach(function(e){n.removeEventListener(e,t,!1)})}var d=function(n){"undefined"!=typeof window&&window.requestAnimationFrame?window.requestAnimationFrame(n):setTimeout(n,17)},v=" ",y=/[\n\t\r]+/g,T=function(n){return(v+n+v).replace(y,v)},E={transitionend:{transition:"transitionend",WebkitTransition:"webkitTransitionEnd",MozTransition:"mozTransitionEnd",OTransition:"oTransitionEnd",msTransition:"MSTransitionEnd"},animationend:{animation:"animationend",WebkitAnimation:"webkitAnimationEnd",MozAnimation:"mozAnimationEnd",OAnimation:"oAnimationEnd",msAnimation:"MSAnimationEnd"}},L=[];"undefined"!=typeof window&&function(){var n=document.createElement("div"),t=n.style;"AnimationEvent"in window||delete E.animationend.animation,"TransitionEvent"in window||delete E.transitionend.transition;for(var e in E){var i=E[e];for(var r in i)if(r in t){L.push(i[r]);break}}}();var w=(function(){function n(n){this.value=n}function t(t){function e(n,t){return new Promise(function(e,r){var a={key:n,arg:t,resolve:e,reject:r,next:null};s?s=s.next=a:(o=s=a,i(n,t))})}function i(e,o){try{var s=t[e](o),a=s.value;a instanceof n?Promise.resolve(a.value).then(function(n){i("next",n)},function(n){i("throw",n)}):r(s.done?"return":"normal",s.value)}catch(n){r("throw",n)}}function r(n,t){switch(n){case"return":o.resolve({value:t,done:!0});break;case"throw":o.reject(t);break;default:o.resolve({value:t,done:!1})}o=o.next,o?i(o.key,o.arg):s=null}var o,s;this._invoke=e,"function"!=typeof t.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(n){return this._invoke("next",n)},t.prototype.throw=function(n){return this._invoke("throw",n)},t.prototype.return=function(n){return this._invoke("return",n)}}(),function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}),g=function(n,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);n.prototype=Object.create(t&&t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(n,t):n.__proto__=t)},k=function(n,t){var e={};for(var i in n)t.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e},b=function(n,t){if(!n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?n:t},N=function(n){function t(){var i,r,o;w(this,t);for(var s=arguments.length,a=Array(s),u=0;u<s;u++)a[u]=arguments[u];return i=r=b(this,n.call.apply(n,[this].concat(a))),r.flushClassNameQueue=function(){e(r)&&p(e(r),r.classNameQueue.join(" ")),r.classNameQueue.length=0,r.rafHandle=null},o=i,b(r,o)}return g(t,n),t.prototype.transition=function(n,t,i){var r=this;i||this.raiseTimeoutConsoleError(n);var o=e(this),s=this.props.name[n]||this.props.name+"-"+n,a=this.props.name[n+"Active"]||s+"-active",u=null;this.endListener&&this.endListener(),this.endListener=function(n){n&&n.target!==o||(clearTimeout(u),f(o,s),f(o,a),m(o,r.endListener),r.endListener=null,t&&t())},i?(u=setTimeout(this.endListener,i),this.transitionTimeouts.push(u)):h(o,this.endListener),p(o,s),this.queueClass(a)},t.prototype.raiseTimeoutConsoleError=function(n){var t="enter"===n?"transitionEnterTimeout":"transitionLeaveTimeout";console.error(t+" should be specified")},t.prototype.queueClass=function(n){this.classNameQueue.push(n),this.rafHandle||(this.rafHandle=d(this.flushClassNameQueue))},t.prototype.stop=function(){this.rafHandle&&(this.classNameQueue.length=0,this.rafHandle=null),this.endListener&&this.endListener()},t.prototype.componentWillMount=function(){this.classNameQueue=[],this.transitionTimeouts=[]},t.prototype.componentWillUnmount=function(){this.classNameQueue.length=0,this.rafHandle=null,this.transitionTimeouts.forEach(function(n){clearTimeout(n)})},t.prototype.componentWillEnter=function(n){this.props.enter?this.transition("enter",n,this.props.enterTimeout):n()},t.prototype.componentWillLeave=function(n){this.props.leave?this.transition("leave",n,this.props.leaveTimeout):n()},t.prototype.render=function(){return i(this.props.children)},t}(n.Component),_=function(e){function i(r){w(this,i);var o=b(this,e.call(this));return o.renderChild=function(e){var i=o.props,r=i.transitionName,s=i.transitionEnter,a=i.transitionLeave,u=i.transitionEnterTimeout,c=i.transitionLeaveTimeout,l=t(e);return n.h(N,{key:l,ref:function(n){(o.refs[l]=n)||(e=null)},name:r,enter:s,leave:a,enterTimeout:u,leaveTimeout:c},e)},o.refs={},o.state={children:(r.children||[]).slice()},o}return g(i,e),i.prototype.shouldComponentUpdate=function(n,t){return t.children!==this.state.children},i.prototype.componentWillMount=function(){this.currentlyTransitioningKeys={},this.keysToEnter=[],this.keysToLeave=[]},i.prototype.componentWillReceiveProps=function(e){var i=this,o=e.children,s=e.exclusive,u=e.showProp,p=r(o||[]).slice(),f=r(s?this.props.children:this.state.children),h=l(f,p);u&&(h=h.map(function(t){if(!t.props[u]&&c(f,t,u)){var e;t=n.cloneElement(t,(e={},e[u]=!0,e))}return t})),s&&h.forEach(function(n){return i.stop(t(n))}),this.setState({children:h}),this.forceUpdate(),p.forEach(function(n){var t=n.key,e=f&&a(f,n);if(u){if(e){var r=c(f,n,u),o=n.props[u];r||!o||i.currentlyTransitioningKeys[t]||i.keysToEnter.push(t)}}else e||i.currentlyTransitioningKeys[t]||i.keysToEnter.push(t)}),f.forEach(function(n){var t=n.key,e=p&&a(p,n);if(u){if(e){var r=c(p,n,u),o=n.props[u];r||!o||i.currentlyTransitioningKeys[t]||i.keysToLeave.push(t)}}else e||i.currentlyTransitioningKeys[t]||i.keysToLeave.push(t)})},i.prototype.performEnter=function(n){var t=this;this.currentlyTransitioningKeys[n]=!0;var e=this.refs[n];e.componentWillEnter?e.componentWillEnter(function(){return t._handleDoneEntering(n)}):this._handleDoneEntering(n)},i.prototype._handleDoneEntering=function(n){delete this.currentlyTransitioningKeys[n];var t=r(this.props.children),e=this.props.showProp;!t||!e&&!s(t,n)||e&&!u(t,n,e)?this.performLeave(n):this.setState({children:t})},i.prototype.stop=function(n){delete this.currentlyTransitioningKeys[n];var t=this.refs[n];t&&t.stop()},i.prototype.performLeave=function(n){var t=this;this.currentlyTransitioningKeys[n]=!0;var e=this.refs[n];e&&e.componentWillLeave?e.componentWillLeave(function(){return t._handleDoneLeaving(n)}):this._handleDoneLeaving(n)},i.prototype._handleDoneLeaving=function(n){delete this.currentlyTransitioningKeys[n];var t=this.props.showProp,e=r(this.props.children);t&&e&&u(e,n,t)?this.performEnter(n):!t&&e&&s(e,n)?this.performEnter(n):this.setState({children:e})},i.prototype.componentDidUpdate=function(){var n=this,t=this.keysToEnter,e=this.keysToLeave;this.keysToEnter=[],t.forEach(function(t){return n.performEnter(t)}),this.keysToLeave=[],e.forEach(function(t){return n.performLeave(t)})},i.prototype.render=function(t,e){var i=e.children,o=t.component,s=(t.transitionName,t.transitionEnter,t.transitionLeave,t.transitionEnterTimeout,t.transitionLeaveTimeout,t.children,k(t,["component","transitionName","transitionEnter","transitionLeave","transitionEnterTimeout","transitionLeaveTimeout","children"]));return n.h(o,s,r(i).map(this.renderChild))},i}(n.Component);return _.defaultProps={component:"span",transitionEnter:!0,transitionLeave:!0},_});
//# sourceMappingURL=preact-css-transition-group.min.js.map