react-wavy
Version:
Generates a canvas waveform.
1,423 lines (1,248 loc) • 679 kB
JavaScript
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = setTimeout(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;
clearTimeout(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) {
setTimeout(drainQueue, 0);
}
};
// 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.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; };
},{}],2:[function(require,module,exports){
var React = require('react');
var ReactDOM = require('react-dom');
var Waveform = require('./index');
var data = [0, 1, 58, 88, 105, 115, 117, 118, 116, 116, 117, 112, 115, 112, 115, 117, 113, 113, 114, 112, 115, 107, 110, 109, 108, 105, 109, 88, 111, 111, 106, 116, 111, 108, 92, 96, 89, 108, 103, 99, 92, 101, 101, 99, 99, 106, 104, 99, 100, 102, 99, 96, 98, 104, 100, 106, 113, 113, 120, 113, 115, 113, 111, 117, 112, 106, 117, 114, 116, 113, 107, 106, 101, 115, 92, 101, 101, 86, 109, 115, 105, 114, 110, 109, 100, 108, 96, 87, 94, 92, 86, 105, 105, 102, 99, 99, 102, 92, 97, 95, 118, 119, 112, 110, 113, 120, 115, 122, 118, 118, 126, 114, 110, 115, 116, 108, 123, 116, 124, 116, 121, 117, 117, 125, 111, 114, 125, 115, 107, 109, 117, 116, 117, 111, 117, 110, 91, 91, 89, 115, 101, 101, 102, 81, 86, 119, 86, 98, 100, 88, 78, 117, 115, 113, 115, 111, 115, 114, 111, 113, 109, 121, 113, 117, 120, 118, 113, 120, 121, 118, 113, 115, 115, 108, 108, 116, 111, 121, 115, 113, 120, 120, 117, 113, 114, 105, 115, 107, 101, 116, 92, 90, 101, 96, 78, 86, 104, 102, 117, 123, 112, 115, 116, 118, 113, 118, 116, 121, 114, 124, 120, 112, 126, 108, 111, 114, 111, 112, 112, 117, 114, 122, 111, 116, 112, 94, 90, 105, 119, 117, 120, 119, 119, 98, 125, 103, 119, 117, 108, 113, 126, 117, 111, 115, 107, 111, 118, 109, 102, 119, 112, 109, 105, 120, 115, 102, 110, 116, 124, 125, 118, 123, 122, 110, 107, 111, 116, 120, 115, 117, 115, 118, 112, 109, 98, 105, 90, 86, 112, 116, 116, 119, 118, 113, 105, 113, 114, 118, 117, 105, 108, 127, 112, 115, 124, 107, 104, 123, 114, 123, 115, 121, 111, 114, 118, 122, 114, 118, 112, 119, 129, 119, 117, 117, 119, 111, 123, 127, 126, 124, 114, 124, 130, 131, 130, 121, 125, 120, 121, 127, 131, 132, 120, 121, 126, 129, 121, 120, 127, 112, 107, 103, 126, 126, 128, 124, 110, 122, 133, 130, 123, 130, 113, 125, 136, 132, 130, 128, 123, 127, 136, 131, 130, 127, 123, 131, 123, 132, 124, 125, 121, 115, 125, 134, 133, 132, 126, 128, 134, 128, 132, 138, 137, 127, 128, 129, 134, 126, 132, 127, 121, 122, 124, 125, 124, 133, 127, 120, 123, 109, 111, 114, 105, 112, 111, 109, 111, 111, 139, 136, 133, 138, 129, 136, 134, 109, 114, 121, 139, 134, 136, 137, 137, 131, 135, 137, 139, 133, 121, 133, 135, 124, 131, 139, 138, 136, 136, 137, 137, 137, 129, 107, 108, 139, 137, 134, 136, 138, 123, 130, 135, 138, 137, 123, 120, 137, 136, 136, 136, 138, 136, 128, 124, 126, 137, 132, 112, 113, 139, 139, 133, 139, 138, 130, 137, 135, 137, 138, 124, 129, 136, 138, 134, 137, 139, 137, 127, 134, 137, 137, 136, 125, 107, 102, 117, 135, 136, 112, 114, 127, 135, 129, 105, 116, 108, 129, 134, 135, 135, 137, 139, 131, 139, 120, 126, 137, 128, 113, 114, 137, 138, 136, 139, 137, 133, 136, 137, 137, 138, 119, 127, 138, 134, 134, 136, 138, 135, 135, 138, 137, 140, 130, 116, 110, 136, 137, 135, 136, 139, 124, 135, 136, 138, 136, 125, 112, 130, 138, 136, 135, 137, 137, 126, 127, 130, 131, 136, 116, 110, 103, 139, 137, 136, 139, 138, 119, 131, 132, 138, 136, 119, 125, 136, 117, 123, 138, 139, 135, 137, 136, 135, 115, 123, 113, 107, 119, 134, 137, 135, 105, 122, 134, 133, 134, 107, 114, 116, 130, 133, 139, 137, 128, 92, 90, 88, 82, 84, 82, 75, 73, 66, 65, 65, 118, 137, 122, 129, 125, 124, 124, 122, 108, 110, 131, 124, 136, 125, 121, 124, 139, 137, 129, 130, 124, 125, 133, 131, 132, 134, 137, 128, 122, 123, 124, 129, 131, 112, 116, 120, 128, 138, 130, 113, 115, 127, 136, 122, 111, 122, 120, 119, 125, 121, 128, 139, 137, 127, 127, 125, 124, 123, 125, 107, 108, 126, 136, 138, 124, 121, 115, 138, 135, 135, 132, 124, 127, 129, 126, 128, 132, 138, 125, 123, 121, 127, 133, 123, 114, 113, 137, 128, 139, 132, 117, 122, 135, 137, 122, 113, 128, 117, 118, 133, 127, 137, 130, 116, 110, 116, 120, 111, 122, 117, 110, 106, 108, 136, 135, 120, 114, 110, 138, 130, 119, 123, 111, 114, 120, 115, 102, 139, 137, 121, 117, 112, 110, 101, 107, 91, 88, 101, 137, 138, 106, 88, 94, 135, 121, 105, 120, 101, 87, 120, 115, 113, 119, 138, 124, 111, 116, 117, 110, 107, 116, 107, 107, 116, 137, 123, 124, 116, 115, 136, 128, 111, 125, 109, 108, 110, 108, 105, 136, 130, 120, 113, 114, 117, 120, 114, 80, 92, 102, 138, 129, 106, 89, 85, 137, 120, 105, 118, 101, 106, 97, 117, 106, 129, 119, 118, 129, 127, 129, 133, 117, 109, 116, 136, 128, 133, 129, 120, 120, 129, 120, 126, 133, 116, 105, 128, 125, 129, 125, 117, 105, 105, 136, 121, 135, 120, 111, 121, 134, 128, 122, 120, 112, 109, 124, 123, 122, 121, 117, 110, 118, 121, 121, 123, 127, 120, 116, 132, 127, 133, 134, 110, 110, 120, 133, 130, 131, 125, 123, 128, 130, 129, 128, 128, 105, 108, 129, 123, 126, 116, 119, 110, 119, 136, 133, 124, 120, 117, 121, 133, 123, 124, 120, 99, 116, 124, 133, 132, 121, 111, 106, 111, 123, 117, 120, 119, 113, 112, 129, 120, 118, 122, 117, 112, 120, 117, 120, 131, 116, 123, 127, 135, 133, 116, 118, 117, 117, 132, 127, 135, 130, 118, 120, 134, 126, 117, 125, 113, 106, 97, 130, 132, 133, 119, 110, 125, 131, 132, 131, 124, 111, 118, 124, 128, 124, 121, 122, 126, 129, 132, 128, 127, 122, 122, 133, 127, 133, 130, 120, 121, 130, 134, 132, 136, 118, 123, 126, 125, 130, 136, 133, 125, 128, 127, 129, 128, 129, 133, 123, 119, 122, 123, 125, 129, 113, 114, 111, 109, 113, 115, 121, 87, 108, 105, 103, 106, 137, 138, 133, 135, 128, 132, 130, 123, 115, 106, 138, 137, 136, 139, 135, 134, 135, 136, 139, 138, 117, 133, 132, 121, 138, 136, 138, 131, 129, 139, 139, 138, 127, 111, 108, 137, 138, 137, 139, 138, 122, 137, 137, 137, 138, 129, 124, 135, 135, 137, 135, 138, 138, 135, 134, 124, 131, 124, 110, 111, 138, 138, 134, 134, 139, 126, 136, 137, 137, 138, 122, 124, 136, 135, 129, 136, 139, 138, 124, 129, 129, 137, 138, 126, 111, 105, 121, 126, 135, 133, 110, 133, 135, 137, 132, 124, 121, 135, 136, 135, 134, 127, 138, 137, 135, 136, 130, 137, 135, 108, 106, 138, 137, 133, 138, 139, 130, 136, 139, 138, 139, 121, 129, 135, 131, 134, 137, 138, 137, 128, 133, 132, 137, 136, 127, 108, 137, 137, 136, 128, 139, 134, 132, 135, 138, 137, 124, 121, 131, 134, 134, 135, 138, 137, 129, 133, 115, 131, 132, 128, 112, 106, 139, 134, 130, 139, 135, 135, 137, 138, 137, 138, 120, 132, 139, 119, 133, 137, 139, 136, 135, 137, 138, 135, 137, 112, 109, 121, 124, 135, 136, 103, 114, 133, 136, 137, 111, 128, 134, 134, 139, 137, 136, 121, 113, 111, 118, 115, 107, 103, 111, 109, 112, 113, 114, 109, 105, 107, 91, 90, 91, 80, 89, 80, 80, 84, 80, 80, 84, 86, 84, 82, 114, 117, 109, 113, 114, 107, 113, 111, 114, 117, 106, 97, 89, 111, 106, 103, 119, 109, 115, 116, 116, 110, 113, 106, 91, 112, 112, 103, 116, 114, 112, 108, 121, 115, 107, 115, 108, 104, 112, 109, 110, 106, 101, 116, 112, 113, 110, 92, 90, 85, 116, 113, 108, 114, 114, 109, 107, 112, 113, 103, 113, 91, 88, 117, 106, 108, 109, 112, 108, 109, 116, 111, 118, 113, 92, 93, 112, 112, 115, 116, 99, 94, 109, 113, 113, 118, 112, 116, 128, 111, 111, 105, 105, 116, 113, 127, 109, 109, 123, 114, 114, 116, 116, 114, 118, 107, 85, 99, 91, 122, 115, 116, 112, 114, 110, 111, 109, 113, 107, 111, 117, 110, 102, 114, 115, 114, 116, 115, 112, 116, 102, 92, 85, 121, 98, 115, 114, 113, 110, 118, 114, 113, 123, 114, 116, 124, 116, 114, 126, 105, 105, 101, 101, 101, 91, 107, 84, 89, 121, 89, 91, 98, 90, 98, 121, 111, 103, 115, 114, 108, 101, 111, 112, 110, 121, 108, 110, 131, 124, 122, 119, 117, 110, 116, 126, 119, 124, 121, 121, 127, 134, 128, 120, 127, 114, 118, 132, 124, 130, 127, 129, 125, 130, 123, 118, 120, 113, 104, 101, 127, 118, 125, 121, 110, 128, 129, 127, 130, 116, 116, 114, 126, 123, 123, 116, 125, 124, 127, 128, 126, 126, 136, 123, 130, 131, 120, 129, 121, 118, 126, 135, 132, 128, 120, 127, 122, 118, 133, 130, 134, 125, 129, 127, 127, 130, 128, 130, 124, 124, 123, 126, 119, 126, 115, 115, 118, 107, 108, 117, 111, 102, 100, 100, 110, 113, 139, 137, 134, 136, 125, 134, 136, 117, 112, 107, 138, 137, 135, 139, 138, 134, 125, 103, 139, 132, 123, 135, 137, 121, 136, 137, 138, 131, 132, 134, 139, 138, 125, 116, 106, 136, 134, 136, 139, 136, 125, 127, 131, 138, 138, 132, 124, 133, 136, 135, 136, 138, 135, 129, 132, 127, 133, 135, 113, 108, 131, 138, 138, 136, 139, 138, 125, 134, 138, 139, 136, 121, 127, 136, 116, 125, 139, 138, 131, 135, 138, 138, 136, 126, 110, 107, 118, 132, 136, 135, 105, 125, 135, 137, 133, 119, 117, 122, 128, 130, 137, 137, 138, 135, 134, 136, 133, 134, 128, 114, 116, 136, 137, 135, 135, 138, 132, 136, 137, 136, 139, 129, 130, 137, 137, 129, 135, 138, 137, 124, 136, 138, 137, 136, 124, 111, 112, 138, 136, 133, 137, 136, 132, 135, 136, 137, 128, 122, 133, 137, 138, 135, 134, 137, 130, 131, 119, 134, 136, 119, 116, 114, 138, 136, 136, 137, 137, 120, 130, 137, 138, 138, 115, 128, 137, 109, 124, 129, 138, 137, 134, 137, 134, 137, 136, 110, 110, 117, 120, 133, 135, 108, 119, 133, 132, 131, 113, 116, 115, 124, 131, 134, 137, 133, 113, 108, 105, 96, 90, 90, 90, 85, 82, 75, 71, 66, 69, 69, 68, 60, 62, 54, 53, 55, 56, 57, 48, 48, 51, 46, 48, 47, 45, 42, 41, 39, 41, 42, 42, 37, 39, 36, 35, 36, 37, 35, 33, 33, 30, 31, 34, 31, 29, 29, 27, 29, 29, 29, 28, 27, 26, 24, 26, 27];
var position = 0;
var handleClick = function (x) {
position = x;
};
setInterval(function () {
position += 3;
ReactDOM.render(React.createElement(Waveform, { data: data, color: 'red', width: 900, position: position, onClick: handleClick }), document.getElementById('waveform'));
}, 1000);
},{"./index":3,"react":160,"react-dom":31}],3:[function(require,module,exports){
var React = require('react');
var Wavy = React.createClass({
displayName: 'Wavy',
getDefaultProps: function () {
return {
data: [],
width: 900,
height: 70,
gap: 1,
position: 0,
onClick: function () {},
outerColor: '#ecf0f1',
innerColor: '#29272c',
cursorColor: '#5bcaff'
};
},
propTypes: {
data: React.PropTypes.array.isRequired,
width: React.PropTypes.number,
height: React.PropTypes.number,
gap: React.PropTypes.number,
position: React.PropTypes.number,
innerColor: React.PropTypes.string,
outerColor: React.PropTypes.string,
onClick: React.PropTypes.func
},
getInitialState: function () {
return { cursor: 0 };
},
componentDidMount: function () {
var canvas = this.refs.canvas;
var ctx = canvas.getContext('2d');
this.draw(ctx);
this.listenToMouse(canvas);
},
componentDidUpdate: function () {
this.draw(this.refs.canvas.getContext('2d'));
},
listenToMouse: function (canvas) {
var _this = this;
canvas.addEventListener('mousemove', function (event) {
var rect = canvas.getBoundingClientRect(),
x = event.clientX - rect.left;
_this.setState({ cursor: x });
});
canvas.addEventListener('mouseleave', function (event) {
_this.setState({ cursor: 0 });
});
canvas.addEventListener('click', function (event) {
var rect = canvas.getBoundingClientRect(),
x = event.clientX - rect.left;
_this.props.onClick(x);
});
},
draw: function (ctx) {
var data = this.props.data;
var width = this.props.width;
var height = this.props.height;
var cursor = this.state.cursor;
var position = this.props.position;
var cursorColor = this.props.cursorColor;
var innerColor = this.props.innerColor;
var outerColor = this.props.outerColor;
var step = Math.ceil(data.length / width);;
var gap = this.props.gap;
var max = Math.max.apply(Math, data);
if (max > 1) {
data = data.map(function (i) {
return i / max;
});
}
for (var i = 0; i < width; i += 1) {
if (i % (step + gap) === 0) {
var datum = data[i * step];
if (position >= i) {
if (cursor >= position) {
if (position >= i) {
ctx.fillStyle = innerColor;
} else {
ctx.fillStyle = cursorColor;
}
} else if (cursor >= i) {
ctx.fillStyle = cursorColor;
} else {
ctx.fillStyle = innerColor;
}
} else if (cursor >= i) {
ctx.fillStyle = cursorColor;
} else {
ctx.fillStyle = outerColor;
}
ctx.fillRect(i, height, step, -1 * datum * height);
}
}
},
render: function () {
return React.createElement('canvas', {
ref: 'canvas',
width: this.props.width,
height: this.props.height });
}
});
module.exports = Wavy;
},{"react":160}],4:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @providesModule EventListener
* @typechecks
*/
'use strict';
var emptyFunction = require('./emptyFunction');
/**
* Upstream version of event listener. Does not take into account specific
* nature of platform.
*/
var EventListener = {
/**
* Listen to DOM events during the bubble phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
listen: function (target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, false);
return {
remove: function () {
target.removeEventListener(eventType, callback, false);
}
};
} else if (target.attachEvent) {
target.attachEvent('on' + eventType, callback);
return {
remove: function () {
target.detachEvent('on' + eventType, callback);
}
};
}
},
/**
* Listen to DOM events during the capture phase.
*
* @param {DOMEventTarget} target DOM element to register listener on.
* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
* @param {function} callback Callback function.
* @return {object} Object with a `remove` method.
*/
capture: function (target, eventType, callback) {
if (target.addEventListener) {
target.addEventListener(eventType, callback, true);
return {
remove: function () {
target.removeEventListener(eventType, callback, true);
}
};
} else {
if (process.env.NODE_ENV !== 'production') {
console.error('Attempted to listen to events during the capture phase on a ' + 'browser that does not support the capture phase. Your application ' + 'will not receive some events.');
}
return {
remove: emptyFunction
};
}
},
registerDefault: function () {}
};
module.exports = EventListener;
}).call(this,require('_process'))
},{"./emptyFunction":11,"_process":1}],5:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ExecutionEnvironment
*/
'use strict';
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
/**
* Simple, lightweight module assisting with the detection and context of
* Worker. Helps avoid circular dependencies and allows code to reason about
* whether or not they are in a Worker, even if they never include the main
* `ReactWorker` dependency.
*/
var ExecutionEnvironment = {
canUseDOM: canUseDOM,
canUseWorkers: typeof Worker !== 'undefined',
canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
canUseViewport: canUseDOM && !!window.screen,
isInWorker: !canUseDOM // For now, this is true - might change in the future.
};
module.exports = ExecutionEnvironment;
},{}],6:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule camelize
* @typechecks
*/
"use strict";
var _hyphenPattern = /-(.)/g;
/**
* Camelcases a hyphenated string, for example:
*
* > camelize('background-color')
* < "backgroundColor"
*
* @param {string} string
* @return {string}
*/
function camelize(string) {
return string.replace(_hyphenPattern, function (_, character) {
return character.toUpperCase();
});
}
module.exports = camelize;
},{}],7:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule camelizeStyleName
* @typechecks
*/
'use strict';
var camelize = require('./camelize');
var msPattern = /^-ms-/;
/**
* Camelcases a hyphenated CSS property name, for example:
*
* > camelizeStyleName('background-color')
* < "backgroundColor"
* > camelizeStyleName('-moz-transition')
* < "MozTransition"
* > camelizeStyleName('-ms-transition')
* < "msTransition"
*
* As Andi Smith suggests
* (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
* is converted to lowercase `ms`.
*
* @param {string} string
* @return {string}
*/
function camelizeStyleName(string) {
return camelize(string.replace(msPattern, 'ms-'));
}
module.exports = camelizeStyleName;
},{"./camelize":6}],8:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule containsNode
* @typechecks
*/
'use strict';
var isTextNode = require('./isTextNode');
/*eslint-disable no-bitwise */
/**
* Checks if a given DOM node contains or is another DOM node.
*
* @param {?DOMNode} outerNode Outer DOM node.
* @param {?DOMNode} innerNode Inner DOM node.
* @return {boolean} True if `outerNode` contains or is `innerNode`.
*/
function containsNode(_x, _x2) {
var _again = true;
_function: while (_again) {
var outerNode = _x,
innerNode = _x2;
_again = false;
if (!outerNode || !innerNode) {
return false;
} else if (outerNode === innerNode) {
return true;
} else if (isTextNode(outerNode)) {
return false;
} else if (isTextNode(innerNode)) {
_x = outerNode;
_x2 = innerNode.parentNode;
_again = true;
continue _function;
} else if (outerNode.contains) {
return outerNode.contains(innerNode);
} else if (outerNode.compareDocumentPosition) {
return !!(outerNode.compareDocumentPosition(innerNode) & 16);
} else {
return false;
}
}
}
module.exports = containsNode;
},{"./isTextNode":21}],9:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule createArrayFromMixed
* @typechecks
*/
'use strict';
var toArray = require('./toArray');
/**
* Perform a heuristic test to determine if an object is "array-like".
*
* A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
* Joshu replied: "Mu."
*
* This function determines if its argument has "array nature": it returns
* true if the argument is an actual array, an `arguments' object, or an
* HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
*
* It will return false for other array-like objects like Filelist.
*
* @param {*} obj
* @return {boolean}
*/
function hasArrayNature(obj) {
return(
// not null/false
!!obj && (
// arrays are objects, NodeLists are functions in Safari
typeof obj == 'object' || typeof obj == 'function') &&
// quacks like an array
'length' in obj &&
// not window
!('setInterval' in obj) &&
// no DOM node should be considered an array-like
// a 'select' element has 'length' and 'item' properties on IE8
typeof obj.nodeType != 'number' && (
// a real array
Array.isArray(obj) ||
// arguments
'callee' in obj ||
// HTMLCollection/NodeList
'item' in obj)
);
}
/**
* Ensure that the argument is an array by wrapping it in an array if it is not.
* Creates a copy of the argument if it is already an array.
*
* This is mostly useful idiomatically:
*
* var createArrayFromMixed = require('createArrayFromMixed');
*
* function takesOneOrMoreThings(things) {
* things = createArrayFromMixed(things);
* ...
* }
*
* This allows you to treat `things' as an array, but accept scalars in the API.
*
* If you need to convert an array-like object, like `arguments`, into an array
* use toArray instead.
*
* @param {*} obj
* @return {array}
*/
function createArrayFromMixed(obj) {
if (!hasArrayNature(obj)) {
return [obj];
} else if (Array.isArray(obj)) {
return obj.slice();
} else {
return toArray(obj);
}
}
module.exports = createArrayFromMixed;
},{"./toArray":29}],10:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule createNodesFromMarkup
* @typechecks
*/
/*eslint-disable fb-www/unsafe-html*/
'use strict';
var ExecutionEnvironment = require('./ExecutionEnvironment');
var createArrayFromMixed = require('./createArrayFromMixed');
var getMarkupWrap = require('./getMarkupWrap');
var invariant = require('./invariant');
/**
* Dummy container used to render all markup.
*/
var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
/**
* Pattern used by `getNodeName`.
*/
var nodeNamePattern = /^\s*<(\w+)/;
/**
* Extracts the `nodeName` of the first element in a string of markup.
*
* @param {string} markup String of markup.
* @return {?string} Node name of the supplied markup.
*/
function getNodeName(markup) {
var nodeNameMatch = markup.match(nodeNamePattern);
return nodeNameMatch && nodeNameMatch[1].toLowerCase();
}
/**
* Creates an array containing the nodes rendered from the supplied markup. The
* optionally supplied `handleScript` function will be invoked once for each
* <script> element that is rendered. If no `handleScript` function is supplied,
* an exception is thrown if any <script> elements are rendered.
*
* @param {string} markup A string of valid HTML markup.
* @param {?function} handleScript Invoked once for each rendered <script>.
* @return {array<DOMElement|DOMTextNode>} An array of rendered nodes.
*/
function createNodesFromMarkup(markup, handleScript) {
var node = dummyNode;
!!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup dummy not initialized') : invariant(false) : undefined;
var nodeName = getNodeName(markup);
var wrap = nodeName && getMarkupWrap(nodeName);
if (wrap) {
node.innerHTML = wrap[1] + markup + wrap[2];
var wrapDepth = wrap[0];
while (wrapDepth--) {
node = node.lastChild;
}
} else {
node.innerHTML = markup;
}
var scripts = node.getElementsByTagName('script');
if (scripts.length) {
!handleScript ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup(...): Unexpected <script> element rendered.') : invariant(false) : undefined;
createArrayFromMixed(scripts).forEach(handleScript);
}
var nodes = createArrayFromMixed(node.childNodes);
while (node.lastChild) {
node.removeChild(node.lastChild);
}
return nodes;
}
module.exports = createNodesFromMarkup;
}).call(this,require('_process'))
},{"./ExecutionEnvironment":5,"./createArrayFromMixed":9,"./getMarkupWrap":15,"./invariant":19,"_process":1}],11:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule emptyFunction
*/
"use strict";
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
function emptyFunction() {}
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
},{}],12:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule emptyObject
*/
'use strict';
var emptyObject = {};
if (process.env.NODE_ENV !== 'production') {
Object.freeze(emptyObject);
}
module.exports = emptyObject;
}).call(this,require('_process'))
},{"_process":1}],13:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule focusNode
*/
'use strict';
/**
* @param {DOMElement} node input/textarea to focus
*/
function focusNode(node) {
// IE8 can throw "Can't move focus to the control because it is invisible,
// not enabled, or of a type that does not accept the focus." for all kinds of
// reasons that are too expensive and fragile to test.
try {
node.focus();
} catch (e) {}
}
module.exports = focusNode;
},{}],14:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule getActiveElement
* @typechecks
*/
/* eslint-disable fb-www/typeof-undefined */
/**
* Same as document.activeElement but wraps in a try-catch block. In IE it is
* not safe to call document.activeElement if there is nothing focused.
*
* The activeElement will be null only if the document or document body is not
* yet defined.
*/
'use strict';
function getActiveElement() /*?DOMElement*/{
if (typeof document === 'undefined') {
return null;
}
try {
return document.activeElement || document.body;
} catch (e) {
return document.body;
}
}
module.exports = getActiveElement;
},{}],15:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule getMarkupWrap
*/
/*eslint-disable fb-www/unsafe-html */
'use strict';
var ExecutionEnvironment = require('./ExecutionEnvironment');
var invariant = require('./invariant');
/**
* Dummy container used to detect which wraps are necessary.
*/
var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
/**
* Some browsers cannot use `innerHTML` to render certain elements standalone,
* so we wrap them, render the wrapped nodes, then extract the desired node.
*
* In IE8, certain elements cannot render alone, so wrap all elements ('*').
*/
var shouldWrap = {};
var selectWrap = [1, '<select multiple="true">', '</select>'];
var tableWrap = [1, '<table>', '</table>'];
var trWrap = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
var svgWrap = [1, '<svg xmlns="http://www.w3.org/2000/svg">', '</svg>'];
var markupWrap = {
'*': [1, '?<div>', '</div>'],
'area': [1, '<map>', '</map>'],
'col': [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
'legend': [1, '<fieldset>', '</fieldset>'],
'param': [1, '<object>', '</object>'],
'tr': [2, '<table><tbody>', '</tbody></table>'],
'optgroup': selectWrap,
'option': selectWrap,
'caption': tableWrap,
'colgroup': tableWrap,
'tbody': tableWrap,
'tfoot': tableWrap,
'thead': tableWrap,
'td': trWrap,
'th': trWrap
};
// Initialize the SVG elements since we know they'll always need to be wrapped
// consistently. If they are created inside a <div> they will be initialized in
// the wrong namespace (and will not display).
var svgElements = ['circle', 'clipPath', 'defs', 'ellipse', 'g', 'image', 'line', 'linearGradient', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'text', 'tspan'];
svgElements.forEach(function (nodeName) {
markupWrap[nodeName] = svgWrap;
shouldWrap[nodeName] = true;
});
/**
* Gets the markup wrap configuration for the supplied `nodeName`.
*
* NOTE: This lazily detects which wraps are necessary for the current browser.
*
* @param {string} nodeName Lowercase `nodeName`.
* @return {?array} Markup wrap configuration, if applicable.
*/
function getMarkupWrap(nodeName) {
!!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Markup wrapping node not initialized') : invariant(false) : undefined;
if (!markupWrap.hasOwnProperty(nodeName)) {
nodeName = '*';
}
if (!shouldWrap.hasOwnProperty(nodeName)) {
if (nodeName === '*') {
dummyNode.innerHTML = '<link />';
} else {
dummyNode.innerHTML = '<' + nodeName + '></' + nodeName + '>';
}
shouldWrap[nodeName] = !dummyNode.firstChild;
}
return shouldWrap[nodeName] ? markupWrap[nodeName] : null;
}
module.exports = getMarkupWrap;
}).call(this,require('_process'))
},{"./ExecutionEnvironment":5,"./invariant":19,"_process":1}],16:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule getUnboundedScrollPosition
* @typechecks
*/
'use strict';
/**
* Gets the scroll position of the supplied element or window.
*
* The return values are unbounded, unlike `getScrollPosition`. This means they
* may be negative or exceed the element boundaries (which is possible using
* inertial scrolling).
*
* @param {DOMWindow|DOMElement} scrollable
* @return {object} Map with `x` and `y` keys.
*/
function getUnboundedScrollPosition(scrollable) {
if (scrollable === window) {
return {
x: window.pageXOffset || document.documentElement.scrollLeft,
y: window.pageYOffset || document.documentElement.scrollTop
};
}
return {
x: scrollable.scrollLeft,
y: scrollable.scrollTop
};
}
module.exports = getUnboundedScrollPosition;
},{}],17:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule hyphenate
* @typechecks
*/
'use strict';
var _uppercasePattern = /([A-Z])/g;
/**
* Hyphenates a camelcased string, for example:
*
* > hyphenate('backgroundColor')
* < "background-color"
*
* For CSS style names, use `hyphenateStyleName` instead which works properly
* with all vendor prefixes, including `ms`.
*
* @param {string} string
* @return {string}
*/
function hyphenate(string) {
return string.replace(_uppercasePattern, '-$1').toLowerCase();
}
module.exports = hyphenate;
},{}],18:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule hyphenateStyleName
* @typechecks
*/
'use strict';
var hyphenate = require('./hyphenate');
var msPattern = /^ms-/;
/**
* Hyphenates a camelcased CSS property name, for example:
*
* > hyphenateStyleName('backgroundColor')
* < "background-color"
* > hyphenateStyleName('MozTransition')
* < "-moz-transition"
* > hyphenateStyleName('msTransition')
* < "-ms-transition"
*
* As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
* is converted to `-ms-`.
*
* @param {string} string
* @return {string}
*/
function hyphenateStyleName(string) {
return hyphenate(string).replace(msPattern, '-ms-');
}
module.exports = hyphenateStyleName;
},{"./hyphenate":17}],19:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule invariant
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
function invariant(condition, format, a, b, c, d, e, f) {
if (process.env.NODE_ENV !== 'production') {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
}
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
}).call(this,require('_process'))
},{"_process":1}],20:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule isNode
* @typechecks
*/
/**
* @param {*} object The object to check.
* @return {boolean} Whether or not the object is a DOM node.
*/
'use strict';
function isNode(object) {
return !!(object && (typeof Node === 'function' ? object instanceof Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
}
module.exports = isNode;
},{}],21:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule isTextNode
* @typechecks
*/
'use strict';
var isNode = require('./isNode');
/**
* @param {*} object The object to check.
* @return {boolean} Whether or not the object is a DOM text node.
*/
function isTextNode(object) {
return isNode(object) && object.nodeType == 3;
}
module.exports = isTextNode;
},{"./isNode":20}],22:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule keyMirror
* @typechecks static-only
*/
'use strict';
var invariant = require('./invariant');
/**
* Constructs an enumeration with keys equal to their value.
*
* For example:
*
* var COLORS = keyMirror({blue: null, red: null});
* var myColor = COLORS.blue;
* var isColorValid = !!COLORS[myColor];
*
* The last line could not be performed if the values of the generated enum were
* not equal to their keys.
*
* Input: {key1: val1, key2: val2}
* Output: {key1: key1, key2: key2}
*
* @param {object} obj
* @return {object}
*/
var keyMirror = function (obj) {
var ret = {};
var key;
!(obj instanceof Object && !Array.isArray(obj)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'keyMirror(...): Argument must be an object.') : invariant(false) : undefined;
for (key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
ret[key] = key;
}
return ret;
};
module.exports = keyMirror;
}).call(this,require('_process'))
},{"./invariant":19,"_process":1}],23:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule keyOf
*/
/**
* Allows extraction of a minified key. Let's the build system minify keys
* without losing the ability to dynamically use key strings as values
* themselves. Pass in an object with a single key/val pair and it will return
* you the string key of that single record. Suppose you want to grab the
* value for a key 'className' inside of an object. Key/val minification may
* have aliased that key to be 'xa12'. keyOf({className: null}) will return
* 'xa12' in that case. Resolve keys you want to use once at startup time, then
* reuse those resolutions.
*/
"use strict";
var keyOf = function (oneKeyObj) {
var key;
for (key in oneKeyObj) {
if (!oneKeyObj.hasOwnProperty(key)) {
continue;
}
return key;
}
return null;
};
module.exports = keyOf;
},{}],24:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule mapObject
*/
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Executes the provided `callback` once for each enumerable own property in the
* object and constructs a new object from the results. The `callback` is
* invoked with three arguments:
*
* - the property value
* - the property name
* - the object being traversed
*
* Properties that are added after the call to `mapObject` will not be visited
* by `callback`. If the values of existing properties are changed, the value
* passed to `callback` will be the value at the time `mapObject` visits them.
* Properties that are deleted before being visited are not visited.
*
* @grep function objectMap()
* @grep function objMap()
*
* @param {?object} object
* @param {function} callback
* @param {*} context
* @return {?object}
*/
function mapObject(object, callback, context) {
if (!object) {
return null;
}
var result = {};
for (var name in object) {
if (hasOwnProperty.call(object, name)) {
result[name] = callback.call(context, object[name], name, object);
}
}
return result;
}
module.exports = mapObject;
},{}],25:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule memoizeStringOnly
* @typechecks static-only
*/
'use strict';
/**
* Memoizes the return value of a function that accepts one string argument.
*
* @param {function} callback
* @return {function}
*/
function memoizeStringOnly(callback) {
var cache = {};
return function (string) {
if (!cache.hasOwnProperty(string)) {
cache[string] = callback.call(this, string);
}
return cache[string];
};
}
module.exports = memoizeStringOnly;
},{}],26:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule performance
* @typechecks
*/
'use strict';
var ExecutionEnvironment = require('./ExecutionEnvironment');
var performance;
if (ExecutionEnvironment.canUseDOM) {
performance = window.performance || window.msPerformance || window.webkitPerformance;
}
module.exports = performance || {};
},{"./ExecutionEnvironment":5}],27:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule performanceNow
* @typechecks
*/
'use strict';
var performance = require('./performance');
var performanceNow;
/**
* Detect if we can use `window.performance.now()` and gracefully fallback to
* `Date.now()` if it doesn't exist. We need to support Firefox < 15 for now
* because of Facebook's testing infrastructure.
*/
if (performance.now) {
performanceNow = function () {
return performance.now();
};
} else {
performanceNow = function () {
return Date.now();
};
}
module.exports = performanceNow;
},{"./performance":26}],28:[function(require,module,exports){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule shallowEqual
* @typechecks
*
*/
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Performs equality by iterating through keys on an object and returning false
* when any key has values which are not strictly equal between the arguments.
* Returns true when the values of all keys are strictly equal.
*/
function shallowEqual(objA, objB) {
if (objA === objB) {
return true;
}
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
// Test for A's keys different from B.
var bHasOwnProperty = hasOwnProperty.bind(objB);
for (var i = 0; i < keysA.length; i++) {
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
return false;
}
}
return true;
}
module.exports = shallowEqual;
},{}],29:[function(require,module,exports){
(function (process){
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule toArray
* @typechecks
*/
'use strict';
var invariant = require('./invariant');
/**
* Convert array-like objects to arrays.
*
* This API assumes the caller knows the contents of the data type. For less
* well defined inputs use createArrayFromMixed.
*
* @param {object|function|filelist} obj
* @return {array}
*/
function toArray(obj) {
var length = obj.length;
// Some browse builtin objects can report typeof 'function' (e.g. NodeList in
// old versions of Safari).
!(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Array-like object expected') : invariant(false) : undefined;
!(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object needs a length property') : invariant(false) : undefined;
!(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object should have keys for indices') : invariant(false) : undefined;
// Old IE doesn't give collections access to hasOwnProperty. Assume inputs
// without method will throw during the slice call and skip straight to the
// fallback.
if (obj.hasOwnProperty) {
try {
return Array.prototype.slice.call(obj);
} catch (e) {
// IE < 9 does not support Array#slice on collections objects
}
}
// Fall back to copying key by key. This assumes all keys have a value,
// so wil