react-show
Version:
react-show React component
971 lines (840 loc) • 30.7 kB
JavaScript
/*!
* react-show v3.0.4 - https://react-show.js.org
* MIT Licensed
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("prop-types"));
else if(typeof define === 'function' && define.amd)
define(["react", "prop-types"], factory);
else if(typeof exports === 'object')
exports["ReactShow"] = factory(require("react"), require("prop-types"));
else
root["ReactShow"] = factory(root["React"], root["PropTypes"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
;
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "easings", function() { return easings; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Animate", function() { return Animate; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_react__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_prop_types__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_raf__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_raf___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_raf__);
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _class, _temp, _initialiseProps;
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/* eslint-disable no-restricted-syntax, react/forbid-prop-types */
var easings = {
// Cubic
easeInCubic: 'cubic-bezier(0.550, 0.055, 0.675, 0.190)',
easeOutCubic: 'cubic-bezier(0.215, 0.610, 0.355, 1.000)',
easeInOutCubic: 'cubic-bezier(0.645, 0.045, 0.355, 1.000)',
// Circ
easeInCirc: 'cubic-bezier(0.600, 0.040, 0.980, 0.335)',
easeOutCirc: 'cubic-bezier(0.075, 0.820, 0.165, 1.000)',
easeInOutCirc: 'cubic-bezier(0.785, 0.135, 0.150, 0.860)',
// Expo
easeInExpo: 'cubic-bezier(0.950, 0.050, 0.795, 0.035)',
easeOutExpo: 'cubic-bezier(0.190, 1.000, 0.220, 1.000)',
easeInOutExpo: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)',
// Quad
easeInQuad: 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
easeOutQuad: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
easeInOutQuad: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
// Quart
easeInQuart: 'cubic-bezier(0.895, 0.030, 0.685, 0.220)',
easeOutQuart: 'cubic-bezier(0.165, 0.840, 0.440, 1.000)',
easeInOutQuart: 'cubic-bezier(0.770, 0.000, 0.175, 1.000)',
// Quint
easeInQuint: 'cubic-bezier(0.755, 0.050, 0.855, 0.060)',
easeOutQuint: 'cubic-bezier(0.230, 1.000, 0.320, 1.000)',
easeInOutQuint: 'cubic-bezier(0.860, 0.000, 0.070, 1.000)',
// Sine
easeInSine: 'cubic-bezier(0.470, 0.000, 0.745, 0.715)',
easeOutSine: 'cubic-bezier(0.390, 0.575, 0.565, 1.000)',
easeInOutSine: 'cubic-bezier(0.445, 0.050, 0.550, 0.950)',
// Back
easeInBack: 'cubic-bezier(0.600, -0.280, 0.735, 0.045)',
easeOutBack: 'cubic-bezier(0.175, 0.885, 0.320, 1.275)',
easeInOutBack: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)'
};
var Animate = (_temp = _class = function (_React$Component) {
_inherits(Animate, _React$Component);
function Animate(props) {
_classCallCheck(this, Animate);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_initialiseProps.call(_this);
var _this$props = _this.props,
show = _this$props.show,
preMount = _this$props.preMount,
transitionOnMount = _this$props.transitionOnMount,
start = _this$props.start,
enter = _this$props.enter;
_this.stage = false;
_this.stageStyles = {};
_this.transitioning = false;
_this.state = {
mountContent: preMount || show,
currentStyle: transitionOnMount ? start : enter,
styleOverrides: {}
};
return _this;
}
Animate.prototype.componentDidMount = function componentDidMount() {
var _props = this.props,
transitionOnMount = _props.transitionOnMount,
show = _props.show,
enter = _props.enter;
if (transitionOnMount && show) {
this.transition('enter', enter);
}
};
Animate.prototype.componentDidUpdate = function componentDidUpdate(oldProps) {
var _props2 = this.props,
show = _props2.show,
enter = _props2.enter,
leave = _props2.leave,
start = _props2.start,
stage = this.stage;
if (show) {
// Entering
if (!oldProps.show) {
if (stage === 'leave') {
return this.transition('clean');
}
if (enter) {
return this.transition('enter', enter);
}
return this.transition('clean');
}
// Did Enter
if (stage === 'didEnter') {
return this.transition('clean');
}
} else if (oldProps.show) {
// Leaving
return this.transition('leave', leave || start);
}
};
Animate.prototype.render = function render() {
var _this2 = this;
var _props3 = this.props,
Comp = _props3.component,
children = _props3.children,
originalShow = _props3.show,
easing = _props3.easing,
duration = _props3.duration,
transitionProperty = _props3.transitionProperty,
stayMounted = _props3.stayMounted,
transitionOnMount = _props3.transitionOnMount,
show = _props3.show,
style = _props3.style,
leave = _props3.leave,
enter = _props3.enter,
innerRef = _props3.innerRef,
onFinish = _props3.onFinish,
preMount = _props3.preMount,
rest = _objectWithoutProperties(_props3, ['component', 'children', 'show', 'easing', 'duration', 'transitionProperty', 'stayMounted', 'transitionOnMount', 'show', 'style', 'leave', 'enter', 'innerRef', 'onFinish', 'preMount']);
var _state = this.state,
mountContent = _state.mountContent,
currentStyle = _state.currentStyle,
styleOverrides = _state.styleOverrides;
return mountContent ? __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement(
Comp,
_extends({
ref: function ref(el) {
_this2.handleRef(el);
if (innerRef) {
innerRef(el);
}
},
onTransitionEnd: this.transitionEnd,
style: this.makeStyles(currentStyle, styleOverrides)
}, rest),
children
) : null;
};
return Animate;
}(__WEBPACK_IMPORTED_MODULE_0_react___default.a.Component), _class.easings = easings, _class.propTypes = {
component: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string,
show: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.oneOfType([__WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool, __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.number]),
easing: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string,
duration: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.number,
preMount: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool,
transitionProperty: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.string,
stayMounted: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool,
style: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.object,
start: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.object,
enter: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.object,
leave: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.object,
onFinish: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.func,
transitionOnMount: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool,
children: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.node.isRequired
}, _class.defaultProps = {
component: 'div',
show: true,
easing: 'easeOutQuad',
duration: 300,
transitionProperty: 'all',
preMount: false,
stayMounted: true,
transitionOnMount: false,
style: undefined,
start: undefined,
enter: undefined,
leave: undefined,
onFinish: function onFinish() {}
}, _initialiseProps = function _initialiseProps() {
var _this3 = this;
this.ensureMounted = function () {
return new Promise(function (resolve) {
var check = function check() {
if (_this3.el) {
return resolve();
}
__WEBPACK_IMPORTED_MODULE_2_raf___default()(function () {
_this3.setState({
mountContent: true
}, check);
});
};
check();
});
};
this.setCurrentStyle = function (style) {
return _this3.setState({
currentStyle: style
});
};
this.overrideStyle = function (style) {
return new Promise(function (resolve) {
var check = function check() {
_this3.setState({
styleOverrides: style
}, function () {
__WEBPACK_IMPORTED_MODULE_2_raf___default()(function () {
if (Object.keys(style).some(function (key) {
return !_this3.el || _this3.el.style[key] !== style[key];
})) {
return check();
}
resolve();
});
});
};
check();
});
};
this.transition = function (stage) {
var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var show = _this3.props.show;
_this3.stage = stage;
_this3.stageStyles = styles;
_this3.transitioning = true;
var wasAutoWidth = void 0;
var wasAutoHeight = void 0;
var isAutoWidth = void 0;
var isAutoHeight = void 0;
var isAutoChanged = void 0;
return Promise.resolve().then(function () {
if (show) {
return _this3.ensureMounted();
}
}).then(function () {
var _state2 = _this3.state,
currentStyle = _state2.currentStyle,
styleOverrides = _state2.styleOverrides;
var previousStyle = _this3.makeStyles(currentStyle, styleOverrides);
var nextStyle = _this3.makeStyles(styles);
wasAutoWidth = _this3.isProp(previousStyle, 'width', 'auto');
wasAutoHeight = _this3.isProp(previousStyle, 'height', 'auto');
isAutoWidth = _this3.isProp(nextStyle, 'width', 'auto');
isAutoHeight = _this3.isProp(nextStyle, 'height', 'auto');
var isAutoWidthChanged = wasAutoWidth !== isAutoWidth;
var isAutoHeightChanged = wasAutoHeight !== isAutoHeight;
isAutoChanged = isAutoWidthChanged || isAutoHeightChanged;
if (isAutoChanged) {
// First we have to make sure we are measuring an
// inline-block element that is overflow hidden, otherwise measurements
// can get very inaccurate
return _this3.overrideStyle({
display: 'block',
overflow: 'hidden'
}).then(function () {
// Then we measure
var measurements = _this3.measure();
// Make sure overflow is hidden while we animate
return _this3.overrideStyle(_extends({}, isAutoWidthChanged ? { width: measurements.width + 'px' } : {}, isAutoHeightChanged ? { height: measurements.height + 'px' } : {}));
});
}
}).then(function () {
__WEBPACK_IMPORTED_MODULE_2_raf___default()(function () {
_this3.setState(function (_ref) {
var styleOverrides = _ref.styleOverrides;
styleOverrides = isAutoChanged ? _extends({}, styleOverrides, wasAutoWidth ? { width: styles.width } : {}, wasAutoHeight ? { height: styles.height } : {}) : styleOverrides;
return {
mountContent: true,
currentStyle: styles,
styleOverrides: styleOverrides
};
}, function () {
// If no styles were applied, then we need to manually complete the transition
// TODO: this might also need to be done if the transitionProperty doesn't
// match any of the styles provided.
// if (!styles) {
// this.completeTransition();
// }
});
});
});
};
this.transitionEnd = function (e) {
if (e) {
e.persist();
// Only handle transitionEnd for this element
if (e.target !== _this3.el) {
return;
}
}
// We have to debounce the action of stopping
// the "transition" state, since onTransitionEnd
// will fire more than once if there are multiple
// properties that were transitioned.
if (_this3.transitionRAF) {
__WEBPACK_IMPORTED_MODULE_2_raf___default.a.cancel(_this3.transitionRAF);
}
_this3.transitionRAF = __WEBPACK_IMPORTED_MODULE_2_raf___default()(_this3.completeTransition);
};
this.completeTransition = function () {
var _props4 = _this3.props,
stayMounted = _props4.stayMounted,
onFinish = _props4.onFinish;
var shouldHide = _this3.stage === 'leave';
_this3.transitioning = false;
if (_this3.stage === 'enter') {
_this3.stage = 'didEnter';
} else if (_this3.stage === 'mount') {
_this3.stage = 'mounted';
} else {
_this3.stage = false;
}
_this3.setState({
mountContent: !(shouldHide && !stayMounted),
styleOverrides: {} // This is to make sure the auto/hidden overrides are gone
}, onFinish);
};
this.handleRef = function (el) {
_this3.el = el;
};
this.isProp = function (style, prop, value) {
return style[prop] === value;
};
this.measure = function () {
if (!_this3.el) {
return {};
}
return {
width: _this3.el.scrollWidth,
height: _this3.el.scrollHeight
};
};
this.makeStyles = function () {
var currentStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _props5 = _this3.props,
style = _props5.style,
transitionProperty = _props5.transitionProperty,
duration = _props5.duration,
easing = _props5.easing;
var resolvedEasing = easings[easing] || easing || 'ease-out';
return _extends({
transitionProperty: transitionProperty,
transitionDuration: duration + 'ms',
transitionTimingFunction: '' + resolvedEasing
}, style, currentStyle, overrides);
};
}, _temp);
// I'll let someone smarter than me figure out how to do this ;)
// export class AnimateGroup extends React.Component {
// constructor (props) {
// super(props)
// const { data } = props
// this.nodes = this.makeNodes(data)
// }
// componentDidUpdate () {
// const { data } = this.props
// const newNodes = this.makeNodes(data)
// let needsUpdate
// if (newNodes.some(node => !this.nodes.find(d => d.key === node.key))) {
// needsUpdate = 'diff'
// }
// if (needsUpdate) {
// console.log(needsUpdate, newNodes, this.nodes)
// this.nodes = this.updateNodes(newNodes)
// this.forceUpdate()
// }
// }
// makeNodes = data => {
// const { getKey } = this.props
// return data.map(datum => ({
// key: getKey(datum),
// data: datum,
// show: true,
// }))
// }
// updateNodes = next => {
// const nodes = []
// this.nodes.forEach(node => {
// if (next.find(d => d.key === node.key)) {
// return
// }
// exiting.push({
// ...node,
// show: false,
// })
// })
// return [...next, ...exiting]
// }
// removeNode = node => {
// this.nodes = this.nodes.filter(d => d.key !== node.key)
// this.forceUpdate()
// }
// render () {
// const {
// data,
// getKey,
// children,
// render,
// start,
// enter,
// update,
// leave,
// duration,
// easing,
// ...rest
// } = this.props
// return (
// <React.Fragment>
// {this.nodes.map((node, i) => (
// <Animate
// key={node.key}
// show={node.show}
// start={typeof start === 'function' ? start(node.data, node.key, i) : start}
// enter={typeof enter === 'function' ? enter(node.data, node.key, i) : enter}
// update={typeof update === 'function' ? update(node.data, node.key, i) : update}
// leave={typeof leave === 'function' ? leave(node.data, node.key, i) : leave}
// onFinish={() => {
// if (!node.show) {
// this.removeNode(node)
// }
// }}
// {...rest}
// >
// {(render || children)(node.data)}
// </Animate>
// ))}
// </React.Fragment>
// )
// }
// }
// function mergeNodes (left, right) {
// let nodes = []
// let lastRightIndex = 0
// left.forEach(l => {
// const index = right.findIndex(r => r.key === l.key)
// if (index === -1) {
// return nodes.push(l)
// }
// nodes = [...nodes, ...right.slice(lastRightIndex, index)]
// lastRightIndex = index
// })
// return nodes
// }
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {var now = __webpack_require__(6)
, root = typeof window === 'undefined' ? global : window
, vendors = ['moz', 'webkit']
, suffix = 'AnimationFrame'
, raf = root['request' + suffix]
, caf = root['cancel' + suffix] || root['cancelRequest' + suffix]
for(var i = 0; !raf && i < vendors.length; i++) {
raf = root[vendors[i] + 'Request' + suffix]
caf = root[vendors[i] + 'Cancel' + suffix]
|| root[vendors[i] + 'CancelRequest' + suffix]
}
// Some versions of FF have rAF but not cAF
if(!raf || !caf) {
var last = 0
, id = 0
, queue = []
, frameDuration = 1000 / 60
raf = function(callback) {
if(queue.length === 0) {
var _now = now()
, next = Math.max(0, frameDuration - (_now - last))
last = next + _now
setTimeout(function() {
var cp = queue.slice(0)
// Clear queue here to prevent
// callbacks from appending listeners
// to the current frame's queue
queue.length = 0
for(var i = 0; i < cp.length; i++) {
if(!cp[i].cancelled) {
try{
cp[i].callback(last)
} catch(e) {
setTimeout(function() { throw e }, 0)
}
}
}
}, Math.round(next))
}
queue.push({
handle: ++id,
callback: callback,
cancelled: false
})
return id
}
caf = function(handle) {
for(var i = 0; i < queue.length; i++) {
if(queue[i].handle === handle) {
queue[i].cancelled = true
}
}
}
}
module.exports = function(fn) {
// Wrap in a new function to prevent
// `cancel` potentially being assigned
// to the native rAF function
return raf.call(root, fn)
}
module.exports.cancel = function() {
caf.apply(root, arguments)
}
module.exports.polyfill = function(object) {
if (!object) {
object = root;
}
object.requestAnimationFrame = raf
object.cancelAnimationFrame = caf
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 5 */
/***/ (function(module, exports) {
var g;
// This works in non-strict mode
g = (function() {
return this;
})();
try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this");
} catch(e) {
// This works if the window reference is available
if(typeof window === "object")
g = window;
}
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {// Generated by CoffeeScript 1.12.2
(function() {
var getNanoSeconds, hrtime, loadTime, moduleLoadTime, nodeLoadTime, upTime;
if ((typeof performance !== "undefined" && performance !== null) && performance.now) {
module.exports = function() {
return performance.now();
};
} else if ((typeof process !== "undefined" && process !== null) && process.hrtime) {
module.exports = function() {
return (getNanoSeconds() - nodeLoadTime) / 1e6;
};
hrtime = process.hrtime;
getNanoSeconds = function() {
var hr;
hr = hrtime();
return hr[0] * 1e9 + hr[1];
};
moduleLoadTime = getNanoSeconds();
upTime = process.uptime() * 1e9;
nodeLoadTime = moduleLoadTime - upTime;
} else if (Date.now) {
module.exports = function() {
return Date.now() - loadTime;
};
loadTime = Date.now();
} else {
module.exports = function() {
return new Date().getTime() - loadTime;
};
loadTime = new Date().getTime();
}
}).call(this);
//# sourceMappingURL=performance-now.js.map
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7)))
/***/ }),
/* 7 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ })
/******/ ]);
});