diff --git a/src/index.html b/src/index.html index 428de7a..5d5a669 100644 --- a/src/index.html +++ b/src/index.html @@ -2,16 +2,18 @@ Supersaber - + - + @@ -30,7 +32,7 @@ - + 0) { + this._tweensAddedDuringUpdate = {}; + + for (var i = 0; i < tweenIds.length; i++) { + + if (this._tweens[tweenIds[i]].update(time) === false) { + this._tweens[tweenIds[i]]._isPlaying = false; + + if (!preserve) { + delete this._tweens[tweenIds[i]]; + } + } + } + + tweenIds = Object.keys(this._tweensAddedDuringUpdate); + } + + return true; + + } +}; + +var TWEEN = new _Group(); + +TWEEN.Group = _Group; +TWEEN._nextId = 0; +TWEEN.nextId = function () { + return TWEEN._nextId++; +}; + + +// Include a performance.now polyfill. +// In node.js, use process.hrtime. +if (typeof (window) === 'undefined' && typeof (process) !== 'undefined') { + TWEEN.now = function () { + var time = process.hrtime(); + + // Convert [seconds, nanoseconds] to milliseconds. + return time[0] * 1000 + time[1] / 1000000; + }; +} +// In a browser, use window.performance.now if it is available. +else if (typeof (window) !== 'undefined' && + window.performance !== undefined && + window.performance.now !== undefined) { + // This must be bound, because directly assigning this function + // leads to an invocation exception in Chrome. + TWEEN.now = window.performance.now.bind(window.performance); +} +// Use Date.now if it is available. +else if (Date.now !== undefined) { + TWEEN.now = Date.now; +} +// Otherwise, use 'new Date().getTime()'. +else { + TWEEN.now = function () { + return new Date().getTime(); + }; +} + + +TWEEN.Tween = function (object, group) { + this._object = object; + this._valuesStart = {}; + this._valuesEnd = {}; + this._valuesStartRepeat = {}; + this._duration = 1000; + this._repeat = 0; + this._repeatDelayTime = undefined; + this._yoyo = false; + this._isPlaying = false; + this._reversed = false; + this._delayTime = 0; + this._startTime = null; + this._easingFunction = TWEEN.Easing.Linear.None; + this._interpolationFunction = TWEEN.Interpolation.Linear; + this._chainedTweens = []; + this._onStartCallback = null; + this._onStartCallbackFired = false; + this._onUpdateCallback = null; + this._onCompleteCallback = null; + this._onStopCallback = null; + this._group = group || TWEEN; + this._id = TWEEN.nextId(); + +}; + +TWEEN.Tween.prototype = { + getId: function getId() { + return this._id; + }, + + isPlaying: function isPlaying() { + return this._isPlaying; + }, + + to: function to(properties, duration) { + + this._valuesEnd = properties; + + if (duration !== undefined) { + this._duration = duration; + } + + return this; + + }, + + start: function start(time) { + + this._group.add(this); + + this._isPlaying = true; + + this._onStartCallbackFired = false; + + this._startTime = time !== undefined ? time : TWEEN.now(); + this._startTime += this._delayTime; + + for (var property in this._valuesEnd) { + + // Check if an Array was provided as property value + if (this._valuesEnd[property] instanceof Array) { + + if (this._valuesEnd[property].length === 0) { + continue; + } + + // Create a local copy of the Array with the start value at the front + this._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]); + + } + + // If `to()` specifies a property that doesn't exist in the source object, + // we should not set that property in the object + if (this._object[property] === undefined) { + continue; + } + + // Save the starting value. + this._valuesStart[property] = this._object[property]; + + if ((this._valuesStart[property] instanceof Array) === false) { + this._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings + } + + this._valuesStartRepeat[property] = this._valuesStart[property] || 0; + + } + + return this; + + }, + + stop: function stop() { + + if (!this._isPlaying) { + return this; + } + + this._group.remove(this); + this._isPlaying = false; + + if (this._onStopCallback !== null) { + this._onStopCallback.call(this._object, this._object); + } + + this.stopChainedTweens(); + return this; + + }, + + end: function end() { + + this.update(this._startTime + this._duration); + return this; + + }, + + stopChainedTweens: function stopChainedTweens() { + + for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) { + this._chainedTweens[i].stop(); + } + + }, + + delay: function delay(amount) { + + this._delayTime = amount; + return this; + + }, + + repeat: function repeat(times) { + + this._repeat = times; + return this; + + }, + + repeatDelay: function repeatDelay(amount) { + + this._repeatDelayTime = amount; + return this; + + }, + + yoyo: function yoyo(yoyo) { + + this._yoyo = yoyo; + return this; + + }, + + easing: function easing(easing) { + + this._easingFunction = easing; + return this; + + }, + + interpolation: function interpolation(interpolation) { + + this._interpolationFunction = interpolation; + return this; + + }, + + chain: function chain() { + + this._chainedTweens = arguments; + return this; + + }, + + onStart: function onStart(callback) { + + this._onStartCallback = callback; + return this; + + }, + + onUpdate: function onUpdate(callback) { + + this._onUpdateCallback = callback; + return this; + + }, + + onComplete: function onComplete(callback) { + + this._onCompleteCallback = callback; + return this; + + }, + + onStop: function onStop(callback) { + + this._onStopCallback = callback; + return this; + + }, + + update: function update(time) { + + var property; + var elapsed; + var value; + + if (time < this._startTime) { + return true; + } + + if (this._onStartCallbackFired === false) { + + if (this._onStartCallback !== null) { + this._onStartCallback.call(this._object, this._object); + } + + this._onStartCallbackFired = true; + } + + elapsed = (time - this._startTime) / this._duration; + elapsed = elapsed > 1 ? 1 : elapsed; + + value = this._easingFunction(elapsed); + + for (property in this._valuesEnd) { + + // Don't update properties that do not exist in the source object + if (this._valuesStart[property] === undefined) { + continue; + } + + var start = this._valuesStart[property] || 0; + var end = this._valuesEnd[property]; + + if (end instanceof Array) { + + this._object[property] = this._interpolationFunction(end, value); + + } else { + + // Parses relative end values with start as base (e.g.: +10, -3) + if (typeof (end) === 'string') { + + if (end.charAt(0) === '+' || end.charAt(0) === '-') { + end = start + parseFloat(end); + } else { + end = parseFloat(end); + } + } + + // Protect against non numeric properties. + if (typeof (end) === 'number') { + this._object[property] = start + (end - start) * value; + } + + } + + } + + if (this._onUpdateCallback !== null) { + this._onUpdateCallback.call(this._object, value); + } + + if (elapsed === 1) { + + if (this._repeat > 0) { + + if (isFinite(this._repeat)) { + this._repeat--; + } + + // Reassign starting values, restart by making startTime = now + for (property in this._valuesStartRepeat) { + + if (typeof (this._valuesEnd[property]) === 'string') { + this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]); + } + + if (this._yoyo) { + var tmp = this._valuesStartRepeat[property]; + + this._valuesStartRepeat[property] = this._valuesEnd[property]; + this._valuesEnd[property] = tmp; + } + + this._valuesStart[property] = this._valuesStartRepeat[property]; + + } + + if (this._yoyo) { + this._reversed = !this._reversed; + } + + if (this._repeatDelayTime !== undefined) { + this._startTime = time + this._repeatDelayTime; + } else { + this._startTime = time + this._delayTime; + } + + return true; + + } else { + + if (this._onCompleteCallback !== null) { + + this._onCompleteCallback.call(this._object, this._object); + } + + for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) { + // Make the chained tweens start exactly at the time they should, + // even if the `update()` method was called way past the duration of the tween + this._chainedTweens[i].start(this._startTime + this._duration); + } + + return false; + + } + + } + + return true; + + } +}; + + +TWEEN.Easing = { + + Linear: { + + None: function (k) { + + return k; + + } + + }, + + Quadratic: { + + In: function (k) { + + return k * k; + + }, + + Out: function (k) { + + return k * (2 - k); + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k; + } + + return - 0.5 * (--k * (k - 2) - 1); + + } + + }, + + Cubic: { + + In: function (k) { + + return k * k * k; + + }, + + Out: function (k) { + + return --k * k * k + 1; + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k * k; + } + + return 0.5 * ((k -= 2) * k * k + 2); + + } + + }, + + Quartic: { + + In: function (k) { + + return k * k * k * k; + + }, + + Out: function (k) { + + return 1 - (--k * k * k * k); + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k * k * k; + } + + return - 0.5 * ((k -= 2) * k * k * k - 2); + + } + + }, + + Quintic: { + + In: function (k) { + + return k * k * k * k * k; + + }, + + Out: function (k) { + + return --k * k * k * k * k + 1; + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return 0.5 * k * k * k * k * k; + } + + return 0.5 * ((k -= 2) * k * k * k * k + 2); + + } + + }, + + Sinusoidal: { + + In: function (k) { + + return 1 - Math.cos(k * Math.PI / 2); + + }, + + Out: function (k) { + + return Math.sin(k * Math.PI / 2); + + }, + + InOut: function (k) { + + return 0.5 * (1 - Math.cos(Math.PI * k)); + + } + + }, + + Exponential: { + + In: function (k) { + + return k === 0 ? 0 : Math.pow(1024, k - 1); + + }, + + Out: function (k) { + + return k === 1 ? 1 : 1 - Math.pow(2, - 10 * k); + + }, + + InOut: function (k) { + + if (k === 0) { + return 0; + } + + if (k === 1) { + return 1; + } + + if ((k *= 2) < 1) { + return 0.5 * Math.pow(1024, k - 1); + } + + return 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2); + + } + + }, + + Circular: { + + In: function (k) { + + return 1 - Math.sqrt(1 - k * k); + + }, + + Out: function (k) { + + return Math.sqrt(1 - (--k * k)); + + }, + + InOut: function (k) { + + if ((k *= 2) < 1) { + return - 0.5 * (Math.sqrt(1 - k * k) - 1); + } + + return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); + + } + + }, + + Elastic: { + + In: function (k) { + + if (k === 0) { + return 0; + } + + if (k === 1) { + return 1; + } + + return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); + + }, + + Out: function (k) { + + if (k === 0) { + return 0; + } + + if (k === 1) { + return 1; + } + + return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1; + + }, + + InOut: function (k) { + + if (k === 0) { + return 0; + } + + if (k === 1) { + return 1; + } + + k *= 2; + + if (k < 1) { + return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); + } + + return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; + + } + + }, + + Back: { + + In: function (k) { + + var s = 1.70158; + + return k * k * ((s + 1) * k - s); + + }, + + Out: function (k) { + + var s = 1.70158; + + return --k * k * ((s + 1) * k + s) + 1; + + }, + + InOut: function (k) { + + var s = 1.70158 * 1.525; + + if ((k *= 2) < 1) { + return 0.5 * (k * k * ((s + 1) * k - s)); + } + + return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2); + + } + + }, + + Bounce: { + + In: function (k) { + + return 1 - TWEEN.Easing.Bounce.Out(1 - k); + + }, + + Out: function (k) { + + if (k < (1 / 2.75)) { + return 7.5625 * k * k; + } else if (k < (2 / 2.75)) { + return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75; + } else if (k < (2.5 / 2.75)) { + return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375; + } else { + return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375; + } + + }, + + InOut: function (k) { + + if (k < 0.5) { + return TWEEN.Easing.Bounce.In(k * 2) * 0.5; + } + + return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; + + } + + } + +}; + +TWEEN.Interpolation = { + + Linear: function (v, k) { + + var m = v.length - 1; + var f = m * k; + var i = Math.floor(f); + var fn = TWEEN.Interpolation.Utils.Linear; + + if (k < 0) { + return fn(v[0], v[1], f); + } + + if (k > 1) { + return fn(v[m], v[m - 1], m - f); + } + + return fn(v[i], v[i + 1 > m ? m : i + 1], f - i); + + }, + + Bezier: function (v, k) { + + var b = 0; + var n = v.length - 1; + var pw = Math.pow; + var bn = TWEEN.Interpolation.Utils.Bernstein; + + for (var i = 0; i <= n; i++) { + b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); + } + + return b; + + }, + + CatmullRom: function (v, k) { + + var m = v.length - 1; + var f = m * k; + var i = Math.floor(f); + var fn = TWEEN.Interpolation.Utils.CatmullRom; + + if (v[0] === v[m]) { + + if (k < 0) { + i = Math.floor(f = m * (1 + k)); + } + + return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i); + + } else { + + if (k < 0) { + return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]); + } + + if (k > 1) { + return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]); + } + + return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i); + + } + + }, + + Utils: { + + Linear: function (p0, p1, t) { + + return (p1 - p0) * t + p0; + + }, + + Bernstein: function (n, i) { + + var fc = TWEEN.Interpolation.Utils.Factorial; + + return fc(n) / fc(i) / fc(n - i); + + }, + + Factorial: (function () { + + var a = [1]; + + return function (n) { + + var s = 1; + + if (a[n]) { + return a[n]; + } + + for (var i = n; i > 1; i--) { + s *= i; + } + + a[n] = s; + return s; + + }; + + })(), + + CatmullRom: function (p0, p1, p2, p3, t) { + + var v0 = (p2 - p0) * 0.5; + var v1 = (p3 - p1) * 0.5; + var t2 = t * t; + var t3 = t * t2; + + return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; + + } + + } + +}; + +// UMD (Universal Module Definition) +(function (root) { + + if (typeof define === 'function' && define.amd) { + + // AMD + define([], function () { + return TWEEN; + }); + + } else if (typeof module !== 'undefined' && typeof exports === 'object') { + + // Node.js + module.exports = TWEEN; + + } else if (root !== undefined) { + + // Global variable + root.TWEEN = TWEEN; + + } + +})(this); + +}).call(this,_dereq_('_process')) + +},{"_process":6}],2:[function(_dereq_,module,exports){ +var str = Object.prototype.toString + +module.exports = anArray + +function anArray(arr) { + return ( + arr.BYTES_PER_ELEMENT + && str.call(arr.buffer) === '[object ArrayBuffer]' + || Array.isArray(arr) + ) +} + +},{}],3:[function(_dereq_,module,exports){ +module.exports = function numtype(num, def) { + return typeof num === 'number' + ? num + : (typeof def === 'number' ? def : 0) +} +},{}],4:[function(_dereq_,module,exports){ +'use strict' + +exports.byteLength = byteLength +exports.toByteArray = toByteArray +exports.fromByteArray = fromByteArray + +var lookup = [] +var revLookup = [] +var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array + +var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' +for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i] + revLookup[code.charCodeAt(i)] = i +} + +revLookup['-'.charCodeAt(0)] = 62 +revLookup['_'.charCodeAt(0)] = 63 + +function placeHoldersCount (b64) { + var len = b64.length + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 +} + +function byteLength (b64) { + // base64 is 4/3 + up to two characters of the original data + return (b64.length * 3 / 4) - placeHoldersCount(b64) +} + +function toByteArray (b64) { + var i, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) + + arr = new Arr((len * 3 / 4) - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? len - 4 : len + + var L = 0 + + for (i = 0; i < l; i += 4) { + tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] + arr[L++] = (tmp >> 16) & 0xFF + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + if (placeHolders === 2) { + tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[L++] = tmp & 0xFF + } else if (placeHolders === 1) { + tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + return arr +} + +function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] +} + +function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output.push(tripletToBase64(tmp)) + } + return output.join('') +} + +function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var output = '' + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + output += lookup[tmp >> 2] + output += lookup[(tmp << 4) & 0x3F] + output += '==' + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) + output += lookup[tmp >> 10] + output += lookup[(tmp >> 4) & 0x3F] + output += lookup[(tmp << 2) & 0x3F] + output += '=' + } + + parts.push(output) + + return parts.join('') +} + +},{}],5:[function(_dereq_,module,exports){ +'use strict'; +// For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field. + +module.exports = { + // Create a tag with optional data attributes + createLink: function(href, attributes) { + var head = document.head || document.getElementsByTagName('head')[0]; + var link = document.createElement('link'); + + link.href = href; + link.rel = 'stylesheet'; + + for (var key in attributes) { + if ( ! attributes.hasOwnProperty(key)) { + continue; + } + var value = attributes[key]; + link.setAttribute('data-' + key, value); + } + + head.appendChild(link); + }, + // Create a