From 46a069c750c11ae72e3788686a1912b8d2a338a7 Mon Sep 17 00:00:00 2001 From: kynd Date: Sun, 17 Apr 2016 12:48:36 -0700 Subject: [PATCH] adopted new GlslGallery --- examples_proto/05/README.md | 2 +- examples_proto/06/README.md | 2 +- examples_proto/07/README.md | 2 +- examples_proto/08/README.md | 2 +- examples_proto/09/README.md | 2 +- examples_proto/10/README.md | 2 +- examples_proto/11/README.md | 2 +- examples_proto/advanced/README.md | 2 +- examples_proto/header.php | 2 +- examples_proto/src/_glslGallery.js | 4069 +++++++++++++++++ .../src/{shaderList.js => examples.js} | 22 +- examples_proto/src/glslGallery.js | 126 +- 12 files changed, 4125 insertions(+), 110 deletions(-) create mode 100644 examples_proto/src/_glslGallery.js rename examples_proto/src/{shaderList.js => examples.js} (79%) mode change 100644 => 100755 examples_proto/src/glslGallery.js diff --git a/examples_proto/05/README.md b/examples_proto/05/README.md index 93970bd..ec0c1dc 100644 --- a/examples_proto/05/README.md +++ b/examples_proto/05/README.md @@ -6,4 +6,4 @@ Shaping functions is fundamental technique that is recursively used throughout t Read [Shaping functions](../05) to learn more. -
\ No newline at end of file +
\ No newline at end of file diff --git a/examples_proto/06/README.md b/examples_proto/06/README.md index 1b42575..225e9ef 100644 --- a/examples_proto/06/README.md +++ b/examples_proto/06/README.md @@ -7,4 +7,4 @@ In GLSL, colors are simply just vectors, which means you can easily apply the co Read [Colors](../06) to learn more. -
\ No newline at end of file +
\ No newline at end of file diff --git a/examples_proto/07/README.md b/examples_proto/07/README.md index 7794a6c..76d2041 100644 --- a/examples_proto/07/README.md +++ b/examples_proto/07/README.md @@ -6,4 +6,4 @@ Let's look at how to draw simple shapes in a parallel procedural way. In a nutsh Read [Shapes](../07) to learn more. -
\ No newline at end of file +
\ No newline at end of file diff --git a/examples_proto/08/README.md b/examples_proto/08/README.md index 808ff8b..1953156 100644 --- a/examples_proto/08/README.md +++ b/examples_proto/08/README.md @@ -7,4 +7,4 @@ Matrices may look complex at a first glance, but you'll find it very handy and u Read [Matrix](../08) to learn more. -
+
diff --git a/examples_proto/09/README.md b/examples_proto/09/README.md index fc3b1e6..aeed911 100644 --- a/examples_proto/09/README.md +++ b/examples_proto/09/README.md @@ -6,4 +6,4 @@ Repetitive patterns are perfect theme for computational sketching. Different fro Read [Patterns](../09) to learn more. -
+
diff --git a/examples_proto/10/README.md b/examples_proto/10/README.md index 0f4571e..51b0a43 100644 --- a/examples_proto/10/README.md +++ b/examples_proto/10/README.md @@ -6,4 +6,4 @@ Life is boring if everything was predictable. Though nothing is truly random in Read [Random](../10) to learn more. -
\ No newline at end of file +
\ No newline at end of file diff --git a/examples_proto/11/README.md b/examples_proto/11/README.md index a4ac13f..b09d09c 100644 --- a/examples_proto/11/README.md +++ b/examples_proto/11/README.md @@ -7,4 +7,4 @@ Since Ken Perlin invented his first noise algorithm in 80s, the technique has be Read [Noise](../11) to learn more. -
\ No newline at end of file +
\ No newline at end of file diff --git a/examples_proto/advanced/README.md b/examples_proto/advanced/README.md index 7b400c3..eec00d4 100644 --- a/examples_proto/advanced/README.md +++ b/examples_proto/advanced/README.md @@ -4,4 +4,4 @@ In this section, we gathered relatively advanced examples from different chapters. Try if you can read and understand all the examples here to test yourself. -
\ No newline at end of file +
\ No newline at end of file diff --git a/examples_proto/header.php b/examples_proto/header.php index f5e2975..acaa074 100644 --- a/examples_proto/header.php +++ b/examples_proto/header.php @@ -27,8 +27,8 @@ echo ' - + diff --git a/examples_proto/src/_glslGallery.js b/examples_proto/src/_glslGallery.js new file mode 100644 index 0000000..e329839 --- /dev/null +++ b/examples_proto/src/_glslGallery.js @@ -0,0 +1,4069 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.glslGallery = f()}})(function(){var define,module,exports;return (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 1 ? arguments[1] : undefined, 3) + , entry; + while(entry = entry ? entry.n : this._f){ + f(entry.v, entry.k, this); + // revert to the last existing entry + while(entry && entry.r)entry = entry.p; + } + }, + // 23.1.3.7 Map.prototype.has(key) + // 23.2.3.7 Set.prototype.has(value) + has: function has(key){ + return !!getEntry(this, key); + } + }); + if(DESCRIPTORS)$.setDesc(C.prototype, 'size', { + get: function(){ + return defined(this[SIZE]); + } + }); + return C; + }, + def: function(that, key, value){ + var entry = getEntry(that, key) + , prev, index; + // change existing entry + if(entry){ + entry.v = value; + // create new entry + } else { + that._l = entry = { + i: index = fastKey(key, true), // <- index + k: key, // <- key + v: value, // <- value + p: prev = that._l, // <- previous entry + n: undefined, // <- next entry + r: false // <- removed + }; + if(!that._f)that._f = entry; + if(prev)prev.n = entry; + that[SIZE]++; + // add to index + if(index !== 'F')that._i[index] = entry; + } return that; + }, + getEntry: getEntry, + setStrong: function(C, NAME, IS_MAP){ + // add .keys, .values, .entries, [@@iterator] + // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11 + $iterDefine(C, NAME, function(iterated, kind){ + this._t = iterated; // target + this._k = kind; // kind + this._l = undefined; // previous + }, function(){ + var that = this + , kind = that._k + , entry = that._l; + // revert to the last existing entry + while(entry && entry.r)entry = entry.p; + // get next entry + if(!that._t || !(that._l = entry = entry ? entry.n : that._t._f)){ + // or finish the iteration + that._t = undefined; + return step(1); + } + // return step by kind + if(kind == 'keys' )return step(0, entry.k); + if(kind == 'values')return step(0, entry.v); + return step(0, [entry.k, entry.v]); + }, IS_MAP ? 'entries' : 'values' , !IS_MAP, true); + + // add [@@species], 23.1.2.2, 23.2.2.2 + setSpecies(NAME); + } +}; +},{"./$":49,"./$.ctx":28,"./$.defined":29,"./$.descriptors":30,"./$.for-of":34,"./$.has":36,"./$.hide":37,"./$.is-object":42,"./$.iter-define":45,"./$.iter-step":47,"./$.redefine-all":55,"./$.set-species":59,"./$.strict-new":63,"./$.uid":70}],25:[function(_dereq_,module,exports){ +// https://github.com/DavidBruant/Map-Set.prototype.toJSON +var forOf = _dereq_('./$.for-of') + , classof = _dereq_('./$.classof'); +module.exports = function(NAME){ + return function toJSON(){ + if(classof(this) != NAME)throw TypeError(NAME + "#toJSON isn't generic"); + var arr = []; + forOf(this, false, arr.push, arr); + return arr; + }; +}; +},{"./$.classof":22,"./$.for-of":34}],26:[function(_dereq_,module,exports){ +'use strict'; +var $ = _dereq_('./$') + , global = _dereq_('./$.global') + , $export = _dereq_('./$.export') + , fails = _dereq_('./$.fails') + , hide = _dereq_('./$.hide') + , redefineAll = _dereq_('./$.redefine-all') + , forOf = _dereq_('./$.for-of') + , strictNew = _dereq_('./$.strict-new') + , isObject = _dereq_('./$.is-object') + , setToStringTag = _dereq_('./$.set-to-string-tag') + , DESCRIPTORS = _dereq_('./$.descriptors'); + +module.exports = function(NAME, wrapper, methods, common, IS_MAP, IS_WEAK){ + var Base = global[NAME] + , C = Base + , ADDER = IS_MAP ? 'set' : 'add' + , proto = C && C.prototype + , O = {}; + if(!DESCRIPTORS || typeof C != 'function' || !(IS_WEAK || proto.forEach && !fails(function(){ + new C().entries().next(); + }))){ + // create collection constructor + C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER); + redefineAll(C.prototype, methods); + } else { + C = wrapper(function(target, iterable){ + strictNew(target, C, NAME); + target._c = new Base; + if(iterable != undefined)forOf(iterable, IS_MAP, target[ADDER], target); + }); + $.each.call('add,clear,delete,forEach,get,has,set,keys,values,entries'.split(','),function(KEY){ + var IS_ADDER = KEY == 'add' || KEY == 'set'; + if(KEY in proto && !(IS_WEAK && KEY == 'clear'))hide(C.prototype, KEY, function(a, b){ + if(!IS_ADDER && IS_WEAK && !isObject(a))return KEY == 'get' ? undefined : false; + var result = this._c[KEY](a === 0 ? 0 : a, b); + return IS_ADDER ? this : result; + }); + }); + if('size' in proto)$.setDesc(C.prototype, 'size', { + get: function(){ + return this._c.size; + } + }); + } + + setToStringTag(C, NAME); + + O[NAME] = C; + $export($export.G + $export.W + $export.F, O); + + if(!IS_WEAK)common.setStrong(C, NAME, IS_MAP); + + return C; +}; +},{"./$":49,"./$.descriptors":30,"./$.export":32,"./$.fails":33,"./$.for-of":34,"./$.global":35,"./$.hide":37,"./$.is-object":42,"./$.redefine-all":55,"./$.set-to-string-tag":60,"./$.strict-new":63}],27:[function(_dereq_,module,exports){ +var core = module.exports = {version: '1.2.6'}; +if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef +},{}],28:[function(_dereq_,module,exports){ +// optional / simple context binding +var aFunction = _dereq_('./$.a-function'); +module.exports = function(fn, that, length){ + aFunction(fn); + if(that === undefined)return fn; + switch(length){ + case 1: return function(a){ + return fn.call(that, a); + }; + case 2: return function(a, b){ + return fn.call(that, a, b); + }; + case 3: return function(a, b, c){ + return fn.call(that, a, b, c); + }; + } + return function(/* ...args */){ + return fn.apply(that, arguments); + }; +}; +},{"./$.a-function":19}],29:[function(_dereq_,module,exports){ +// 7.2.1 RequireObjectCoercible(argument) +module.exports = function(it){ + if(it == undefined)throw TypeError("Can't call method on " + it); + return it; +}; +},{}],30:[function(_dereq_,module,exports){ +// Thank's IE8 for his funny defineProperty +module.exports = !_dereq_('./$.fails')(function(){ + return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; +}); +},{"./$.fails":33}],31:[function(_dereq_,module,exports){ +var isObject = _dereq_('./$.is-object') + , document = _dereq_('./$.global').document + // in old IE typeof document.createElement is 'object' + , is = isObject(document) && isObject(document.createElement); +module.exports = function(it){ + return is ? document.createElement(it) : {}; +}; +},{"./$.global":35,"./$.is-object":42}],32:[function(_dereq_,module,exports){ +var global = _dereq_('./$.global') + , core = _dereq_('./$.core') + , ctx = _dereq_('./$.ctx') + , PROTOTYPE = 'prototype'; + +var $export = function(type, name, source){ + var IS_FORCED = type & $export.F + , IS_GLOBAL = type & $export.G + , IS_STATIC = type & $export.S + , IS_PROTO = type & $export.P + , IS_BIND = type & $export.B + , IS_WRAP = type & $export.W + , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) + , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE] + , key, own, out; + if(IS_GLOBAL)source = name; + for(key in source){ + // contains in native + own = !IS_FORCED && target && key in target; + if(own && key in exports)continue; + // export native or passed + out = own ? target[key] : source[key]; + // prevent global pollution for namespaces + exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] + // bind timers to global for call from export context + : IS_BIND && own ? ctx(out, global) + // wrap global constructors for prevent change them in library + : IS_WRAP && target[key] == out ? (function(C){ + var F = function(param){ + return this instanceof C ? new C(param) : C(param); + }; + F[PROTOTYPE] = C[PROTOTYPE]; + return F; + // make static versions for prototype methods + })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; + if(IS_PROTO)(exports[PROTOTYPE] || (exports[PROTOTYPE] = {}))[key] = out; + } +}; +// type bitmap +$export.F = 1; // forced +$export.G = 2; // global +$export.S = 4; // static +$export.P = 8; // proto +$export.B = 16; // bind +$export.W = 32; // wrap +module.exports = $export; +},{"./$.core":27,"./$.ctx":28,"./$.global":35}],33:[function(_dereq_,module,exports){ +module.exports = function(exec){ + try { + return !!exec(); + } catch(e){ + return true; + } +}; +},{}],34:[function(_dereq_,module,exports){ +var ctx = _dereq_('./$.ctx') + , call = _dereq_('./$.iter-call') + , isArrayIter = _dereq_('./$.is-array-iter') + , anObject = _dereq_('./$.an-object') + , toLength = _dereq_('./$.to-length') + , getIterFn = _dereq_('./core.get-iterator-method'); +module.exports = function(iterable, entries, fn, that){ + var iterFn = getIterFn(iterable) + , f = ctx(fn, that, entries ? 2 : 1) + , index = 0 + , length, step, iterator; + if(typeof iterFn != 'function')throw TypeError(iterable + ' is not iterable!'); + // fast case for arrays with default iterator + if(isArrayIter(iterFn))for(length = toLength(iterable.length); length > index; index++){ + entries ? f(anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); + } else for(iterator = iterFn.call(iterable); !(step = iterator.next()).done; ){ + call(iterator, f, step.value, entries); + } +}; +},{"./$.an-object":21,"./$.ctx":28,"./$.is-array-iter":41,"./$.iter-call":43,"./$.to-length":68,"./core.get-iterator-method":72}],35:[function(_dereq_,module,exports){ +// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 +var global = module.exports = typeof window != 'undefined' && window.Math == Math + ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); +if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef +},{}],36:[function(_dereq_,module,exports){ +var hasOwnProperty = {}.hasOwnProperty; +module.exports = function(it, key){ + return hasOwnProperty.call(it, key); +}; +},{}],37:[function(_dereq_,module,exports){ +var $ = _dereq_('./$') + , createDesc = _dereq_('./$.property-desc'); +module.exports = _dereq_('./$.descriptors') ? function(object, key, value){ + return $.setDesc(object, key, createDesc(1, value)); +} : function(object, key, value){ + object[key] = value; + return object; +}; +},{"./$":49,"./$.descriptors":30,"./$.property-desc":54}],38:[function(_dereq_,module,exports){ +module.exports = _dereq_('./$.global').document && document.documentElement; +},{"./$.global":35}],39:[function(_dereq_,module,exports){ +// fast apply, http://jsperf.lnkit.com/fast-apply/5 +module.exports = function(fn, args, that){ + var un = that === undefined; + switch(args.length){ + case 0: return un ? fn() + : fn.call(that); + case 1: return un ? fn(args[0]) + : fn.call(that, args[0]); + case 2: return un ? fn(args[0], args[1]) + : fn.call(that, args[0], args[1]); + case 3: return un ? fn(args[0], args[1], args[2]) + : fn.call(that, args[0], args[1], args[2]); + case 4: return un ? fn(args[0], args[1], args[2], args[3]) + : fn.call(that, args[0], args[1], args[2], args[3]); + } return fn.apply(that, args); +}; +},{}],40:[function(_dereq_,module,exports){ +// fallback for non-array-like ES3 and non-enumerable old V8 strings +var cof = _dereq_('./$.cof'); +module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){ + return cof(it) == 'String' ? it.split('') : Object(it); +}; +},{"./$.cof":23}],41:[function(_dereq_,module,exports){ +// check on default Array iterator +var Iterators = _dereq_('./$.iterators') + , ITERATOR = _dereq_('./$.wks')('iterator') + , ArrayProto = Array.prototype; + +module.exports = function(it){ + return it !== undefined && (Iterators.Array === it || ArrayProto[ITERATOR] === it); +}; +},{"./$.iterators":48,"./$.wks":71}],42:[function(_dereq_,module,exports){ +module.exports = function(it){ + return typeof it === 'object' ? it !== null : typeof it === 'function'; +}; +},{}],43:[function(_dereq_,module,exports){ +// call something on iterator step with safe closing on error +var anObject = _dereq_('./$.an-object'); +module.exports = function(iterator, fn, value, entries){ + try { + return entries ? fn(anObject(value)[0], value[1]) : fn(value); + // 7.4.6 IteratorClose(iterator, completion) + } catch(e){ + var ret = iterator['return']; + if(ret !== undefined)anObject(ret.call(iterator)); + throw e; + } +}; +},{"./$.an-object":21}],44:[function(_dereq_,module,exports){ +'use strict'; +var $ = _dereq_('./$') + , descriptor = _dereq_('./$.property-desc') + , setToStringTag = _dereq_('./$.set-to-string-tag') + , IteratorPrototype = {}; + +// 25.1.2.1.1 %IteratorPrototype%[@@iterator]() +_dereq_('./$.hide')(IteratorPrototype, _dereq_('./$.wks')('iterator'), function(){ return this; }); + +module.exports = function(Constructor, NAME, next){ + Constructor.prototype = $.create(IteratorPrototype, {next: descriptor(1, next)}); + setToStringTag(Constructor, NAME + ' Iterator'); +}; +},{"./$":49,"./$.hide":37,"./$.property-desc":54,"./$.set-to-string-tag":60,"./$.wks":71}],45:[function(_dereq_,module,exports){ +'use strict'; +var LIBRARY = _dereq_('./$.library') + , $export = _dereq_('./$.export') + , redefine = _dereq_('./$.redefine') + , hide = _dereq_('./$.hide') + , has = _dereq_('./$.has') + , Iterators = _dereq_('./$.iterators') + , $iterCreate = _dereq_('./$.iter-create') + , setToStringTag = _dereq_('./$.set-to-string-tag') + , getProto = _dereq_('./$').getProto + , ITERATOR = _dereq_('./$.wks')('iterator') + , BUGGY = !([].keys && 'next' in [].keys()) // Safari has buggy iterators w/o `next` + , FF_ITERATOR = '@@iterator' + , KEYS = 'keys' + , VALUES = 'values'; + +var returnThis = function(){ return this; }; + +module.exports = function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED){ + $iterCreate(Constructor, NAME, next); + var getMethod = function(kind){ + if(!BUGGY && kind in proto)return proto[kind]; + switch(kind){ + case KEYS: return function keys(){ return new Constructor(this, kind); }; + case VALUES: return function values(){ return new Constructor(this, kind); }; + } return function entries(){ return new Constructor(this, kind); }; + }; + var TAG = NAME + ' Iterator' + , DEF_VALUES = DEFAULT == VALUES + , VALUES_BUG = false + , proto = Base.prototype + , $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] + , $default = $native || getMethod(DEFAULT) + , methods, key; + // Fix native + if($native){ + var IteratorPrototype = getProto($default.call(new Base)); + // Set @@toStringTag to native iterators + setToStringTag(IteratorPrototype, TAG, true); + // FF fix + if(!LIBRARY && has(proto, FF_ITERATOR))hide(IteratorPrototype, ITERATOR, returnThis); + // fix Array#{values, @@iterator}.name in V8 / FF + if(DEF_VALUES && $native.name !== VALUES){ + VALUES_BUG = true; + $default = function values(){ return $native.call(this); }; + } + } + // Define iterator + if((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])){ + hide(proto, ITERATOR, $default); + } + // Plug for library + Iterators[NAME] = $default; + Iterators[TAG] = returnThis; + if(DEFAULT){ + methods = { + values: DEF_VALUES ? $default : getMethod(VALUES), + keys: IS_SET ? $default : getMethod(KEYS), + entries: !DEF_VALUES ? $default : getMethod('entries') + }; + if(FORCED)for(key in methods){ + if(!(key in proto))redefine(proto, key, methods[key]); + } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); + } + return methods; +}; +},{"./$":49,"./$.export":32,"./$.has":36,"./$.hide":37,"./$.iter-create":44,"./$.iterators":48,"./$.library":50,"./$.redefine":56,"./$.set-to-string-tag":60,"./$.wks":71}],46:[function(_dereq_,module,exports){ +var ITERATOR = _dereq_('./$.wks')('iterator') + , SAFE_CLOSING = false; + +try { + var riter = [7][ITERATOR](); + riter['return'] = function(){ SAFE_CLOSING = true; }; + Array.from(riter, function(){ throw 2; }); +} catch(e){ /* empty */ } + +module.exports = function(exec, skipClosing){ + if(!skipClosing && !SAFE_CLOSING)return false; + var safe = false; + try { + var arr = [7] + , iter = arr[ITERATOR](); + iter.next = function(){ safe = true; }; + arr[ITERATOR] = function(){ return iter; }; + exec(arr); + } catch(e){ /* empty */ } + return safe; +}; +},{"./$.wks":71}],47:[function(_dereq_,module,exports){ +module.exports = function(done, value){ + return {value: value, done: !!done}; +}; +},{}],48:[function(_dereq_,module,exports){ +module.exports = {}; +},{}],49:[function(_dereq_,module,exports){ +var $Object = Object; +module.exports = { + create: $Object.create, + getProto: $Object.getPrototypeOf, + isEnum: {}.propertyIsEnumerable, + getDesc: $Object.getOwnPropertyDescriptor, + setDesc: $Object.defineProperty, + setDescs: $Object.defineProperties, + getKeys: $Object.keys, + getNames: $Object.getOwnPropertyNames, + getSymbols: $Object.getOwnPropertySymbols, + each: [].forEach +}; +},{}],50:[function(_dereq_,module,exports){ +module.exports = true; +},{}],51:[function(_dereq_,module,exports){ +var global = _dereq_('./$.global') + , macrotask = _dereq_('./$.task').set + , Observer = global.MutationObserver || global.WebKitMutationObserver + , process = global.process + , Promise = global.Promise + , isNode = _dereq_('./$.cof')(process) == 'process' + , head, last, notify; + +var flush = function(){ + var parent, domain, fn; + if(isNode && (parent = process.domain)){ + process.domain = null; + parent.exit(); + } + while(head){ + domain = head.domain; + fn = head.fn; + if(domain)domain.enter(); + fn(); // <- currently we use it only for Promise - try / catch not required + if(domain)domain.exit(); + head = head.next; + } last = undefined; + if(parent)parent.enter(); +}; + +// Node.js +if(isNode){ + notify = function(){ + process.nextTick(flush); + }; +// browsers with MutationObserver +} else if(Observer){ + var toggle = 1 + , node = document.createTextNode(''); + new Observer(flush).observe(node, {characterData: true}); // eslint-disable-line no-new + notify = function(){ + node.data = toggle = -toggle; + }; +// environments with maybe non-completely correct, but existent Promise +} else if(Promise && Promise.resolve){ + notify = function(){ + Promise.resolve().then(flush); + }; +// for other environments - macrotask based on: +// - setImmediate +// - MessageChannel +// - window.postMessag +// - onreadystatechange +// - setTimeout +} else { + notify = function(){ + // strange IE + webpack dev server bug - use .call(global) + macrotask.call(global, flush); + }; +} + +module.exports = function asap(fn){ + var task = {fn: fn, next: undefined, domain: isNode && process.domain}; + if(last)last.next = task; + if(!head){ + head = task; + notify(); + } last = task; +}; +},{"./$.cof":23,"./$.global":35,"./$.task":65}],52:[function(_dereq_,module,exports){ +// 19.1.2.1 Object.assign(target, source, ...) +var $ = _dereq_('./$') + , toObject = _dereq_('./$.to-object') + , IObject = _dereq_('./$.iobject'); + +// should work with symbols and should have deterministic property order (V8 bug) +module.exports = _dereq_('./$.fails')(function(){ + var a = Object.assign + , A = {} + , B = {} + , S = Symbol() + , K = 'abcdefghijklmnopqrst'; + A[S] = 7; + K.split('').forEach(function(k){ B[k] = k; }); + return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K; +}) ? function assign(target, source){ // eslint-disable-line no-unused-vars + var T = toObject(target) + , $$ = arguments + , $$len = $$.length + , index = 1 + , getKeys = $.getKeys + , getSymbols = $.getSymbols + , isEnum = $.isEnum; + while($$len > index){ + var S = IObject($$[index++]) + , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S) + , length = keys.length + , j = 0 + , key; + while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key]; + } + return T; +} : Object.assign; +},{"./$":49,"./$.fails":33,"./$.iobject":40,"./$.to-object":69}],53:[function(_dereq_,module,exports){ +// most Object methods by ES6 should accept primitives +var $export = _dereq_('./$.export') + , core = _dereq_('./$.core') + , fails = _dereq_('./$.fails'); +module.exports = function(KEY, exec){ + var fn = (core.Object || {})[KEY] || Object[KEY] + , exp = {}; + exp[KEY] = exec(fn); + $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp); +}; +},{"./$.core":27,"./$.export":32,"./$.fails":33}],54:[function(_dereq_,module,exports){ +module.exports = function(bitmap, value){ + return { + enumerable : !(bitmap & 1), + configurable: !(bitmap & 2), + writable : !(bitmap & 4), + value : value + }; +}; +},{}],55:[function(_dereq_,module,exports){ +var redefine = _dereq_('./$.redefine'); +module.exports = function(target, src){ + for(var key in src)redefine(target, key, src[key]); + return target; +}; +},{"./$.redefine":56}],56:[function(_dereq_,module,exports){ +module.exports = _dereq_('./$.hide'); +},{"./$.hide":37}],57:[function(_dereq_,module,exports){ +// 7.2.9 SameValue(x, y) +module.exports = Object.is || function is(x, y){ + return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; +}; +},{}],58:[function(_dereq_,module,exports){ +// Works with __proto__ only. Old v8 can't work with null proto objects. +/* eslint-disable no-proto */ +var getDesc = _dereq_('./$').getDesc + , isObject = _dereq_('./$.is-object') + , anObject = _dereq_('./$.an-object'); +var check = function(O, proto){ + anObject(O); + if(!isObject(proto) && proto !== null)throw TypeError(proto + ": can't set as prototype!"); +}; +module.exports = { + set: Object.setPrototypeOf || ('__proto__' in {} ? // eslint-disable-line + function(test, buggy, set){ + try { + set = _dereq_('./$.ctx')(Function.call, getDesc(Object.prototype, '__proto__').set, 2); + set(test, []); + buggy = !(test instanceof Array); + } catch(e){ buggy = true; } + return function setPrototypeOf(O, proto){ + check(O, proto); + if(buggy)O.__proto__ = proto; + else set(O, proto); + return O; + }; + }({}, false) : undefined), + check: check +}; +},{"./$":49,"./$.an-object":21,"./$.ctx":28,"./$.is-object":42}],59:[function(_dereq_,module,exports){ +'use strict'; +var core = _dereq_('./$.core') + , $ = _dereq_('./$') + , DESCRIPTORS = _dereq_('./$.descriptors') + , SPECIES = _dereq_('./$.wks')('species'); + +module.exports = function(KEY){ + var C = core[KEY]; + if(DESCRIPTORS && C && !C[SPECIES])$.setDesc(C, SPECIES, { + configurable: true, + get: function(){ return this; } + }); +}; +},{"./$":49,"./$.core":27,"./$.descriptors":30,"./$.wks":71}],60:[function(_dereq_,module,exports){ +var def = _dereq_('./$').setDesc + , has = _dereq_('./$.has') + , TAG = _dereq_('./$.wks')('toStringTag'); + +module.exports = function(it, tag, stat){ + if(it && !has(it = stat ? it : it.prototype, TAG))def(it, TAG, {configurable: true, value: tag}); +}; +},{"./$":49,"./$.has":36,"./$.wks":71}],61:[function(_dereq_,module,exports){ +var global = _dereq_('./$.global') + , SHARED = '__core-js_shared__' + , store = global[SHARED] || (global[SHARED] = {}); +module.exports = function(key){ + return store[key] || (store[key] = {}); +}; +},{"./$.global":35}],62:[function(_dereq_,module,exports){ +// 7.3.20 SpeciesConstructor(O, defaultConstructor) +var anObject = _dereq_('./$.an-object') + , aFunction = _dereq_('./$.a-function') + , SPECIES = _dereq_('./$.wks')('species'); +module.exports = function(O, D){ + var C = anObject(O).constructor, S; + return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? D : aFunction(S); +}; +},{"./$.a-function":19,"./$.an-object":21,"./$.wks":71}],63:[function(_dereq_,module,exports){ +module.exports = function(it, Constructor, name){ + if(!(it instanceof Constructor))throw TypeError(name + ": use the 'new' operator!"); + return it; +}; +},{}],64:[function(_dereq_,module,exports){ +var toInteger = _dereq_('./$.to-integer') + , defined = _dereq_('./$.defined'); +// true -> String#at +// false -> String#codePointAt +module.exports = function(TO_STRING){ + return function(that, pos){ + var s = String(defined(that)) + , i = toInteger(pos) + , l = s.length + , a, b; + if(i < 0 || i >= l)return TO_STRING ? '' : undefined; + a = s.charCodeAt(i); + return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff + ? TO_STRING ? s.charAt(i) : a + : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; + }; +}; +},{"./$.defined":29,"./$.to-integer":66}],65:[function(_dereq_,module,exports){ +var ctx = _dereq_('./$.ctx') + , invoke = _dereq_('./$.invoke') + , html = _dereq_('./$.html') + , cel = _dereq_('./$.dom-create') + , global = _dereq_('./$.global') + , process = global.process + , setTask = global.setImmediate + , clearTask = global.clearImmediate + , MessageChannel = global.MessageChannel + , counter = 0 + , queue = {} + , ONREADYSTATECHANGE = 'onreadystatechange' + , defer, channel, port; +var run = function(){ + var id = +this; + if(queue.hasOwnProperty(id)){ + var fn = queue[id]; + delete queue[id]; + fn(); + } +}; +var listner = function(event){ + run.call(event.data); +}; +// Node.js 0.9+ & IE10+ has setImmediate, otherwise: +if(!setTask || !clearTask){ + setTask = function setImmediate(fn){ + var args = [], i = 1; + while(arguments.length > i)args.push(arguments[i++]); + queue[++counter] = function(){ + invoke(typeof fn == 'function' ? fn : Function(fn), args); + }; + defer(counter); + return counter; + }; + clearTask = function clearImmediate(id){ + delete queue[id]; + }; + // Node.js 0.8- + if(_dereq_('./$.cof')(process) == 'process'){ + defer = function(id){ + process.nextTick(ctx(run, id, 1)); + }; + // Browsers with MessageChannel, includes WebWorkers + } else if(MessageChannel){ + channel = new MessageChannel; + port = channel.port2; + channel.port1.onmessage = listner; + defer = ctx(port.postMessage, port, 1); + // Browsers with postMessage, skip WebWorkers + // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' + } else if(global.addEventListener && typeof postMessage == 'function' && !global.importScripts){ + defer = function(id){ + global.postMessage(id + '', '*'); + }; + global.addEventListener('message', listner, false); + // IE8- + } else if(ONREADYSTATECHANGE in cel('script')){ + defer = function(id){ + html.appendChild(cel('script'))[ONREADYSTATECHANGE] = function(){ + html.removeChild(this); + run.call(id); + }; + }; + // Rest old browsers + } else { + defer = function(id){ + setTimeout(ctx(run, id, 1), 0); + }; + } +} +module.exports = { + set: setTask, + clear: clearTask +}; +},{"./$.cof":23,"./$.ctx":28,"./$.dom-create":31,"./$.global":35,"./$.html":38,"./$.invoke":39}],66:[function(_dereq_,module,exports){ +// 7.1.4 ToInteger +var ceil = Math.ceil + , floor = Math.floor; +module.exports = function(it){ + return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); +}; +},{}],67:[function(_dereq_,module,exports){ +// to indexed object, toObject with fallback for non-array-like ES3 strings +var IObject = _dereq_('./$.iobject') + , defined = _dereq_('./$.defined'); +module.exports = function(it){ + return IObject(defined(it)); +}; +},{"./$.defined":29,"./$.iobject":40}],68:[function(_dereq_,module,exports){ +// 7.1.15 ToLength +var toInteger = _dereq_('./$.to-integer') + , min = Math.min; +module.exports = function(it){ + return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 +}; +},{"./$.to-integer":66}],69:[function(_dereq_,module,exports){ +// 7.1.13 ToObject(argument) +var defined = _dereq_('./$.defined'); +module.exports = function(it){ + return Object(defined(it)); +}; +},{"./$.defined":29}],70:[function(_dereq_,module,exports){ +var id = 0 + , px = Math.random(); +module.exports = function(key){ + return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); +}; +},{}],71:[function(_dereq_,module,exports){ +var store = _dereq_('./$.shared')('wks') + , uid = _dereq_('./$.uid') + , Symbol = _dereq_('./$.global').Symbol; +module.exports = function(name){ + return store[name] || (store[name] = + Symbol && Symbol[name] || (Symbol || uid)('Symbol.' + name)); +}; +},{"./$.global":35,"./$.shared":61,"./$.uid":70}],72:[function(_dereq_,module,exports){ +var classof = _dereq_('./$.classof') + , ITERATOR = _dereq_('./$.wks')('iterator') + , Iterators = _dereq_('./$.iterators'); +module.exports = _dereq_('./$.core').getIteratorMethod = function(it){ + if(it != undefined)return it[ITERATOR] + || it['@@iterator'] + || Iterators[classof(it)]; +}; +},{"./$.classof":22,"./$.core":27,"./$.iterators":48,"./$.wks":71}],73:[function(_dereq_,module,exports){ +var anObject = _dereq_('./$.an-object') + , get = _dereq_('./core.get-iterator-method'); +module.exports = _dereq_('./$.core').getIterator = function(it){ + var iterFn = get(it); + if(typeof iterFn != 'function')throw TypeError(it + ' is not iterable!'); + return anObject(iterFn.call(it)); +}; +},{"./$.an-object":21,"./$.core":27,"./core.get-iterator-method":72}],74:[function(_dereq_,module,exports){ +'use strict'; +var ctx = _dereq_('./$.ctx') + , $export = _dereq_('./$.export') + , toObject = _dereq_('./$.to-object') + , call = _dereq_('./$.iter-call') + , isArrayIter = _dereq_('./$.is-array-iter') + , toLength = _dereq_('./$.to-length') + , getIterFn = _dereq_('./core.get-iterator-method'); +$export($export.S + $export.F * !_dereq_('./$.iter-detect')(function(iter){ Array.from(iter); }), 'Array', { + // 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined) + from: function from(arrayLike/*, mapfn = undefined, thisArg = undefined*/){ + var O = toObject(arrayLike) + , C = typeof this == 'function' ? this : Array + , $$ = arguments + , $$len = $$.length + , mapfn = $$len > 1 ? $$[1] : undefined + , mapping = mapfn !== undefined + , index = 0 + , iterFn = getIterFn(O) + , length, result, step, iterator; + if(mapping)mapfn = ctx(mapfn, $$len > 2 ? $$[2] : undefined, 2); + // if object isn't iterable or it's array with default iterator - use simple case + if(iterFn != undefined && !(C == Array && isArrayIter(iterFn))){ + for(iterator = iterFn.call(O), result = new C; !(step = iterator.next()).done; index++){ + result[index] = mapping ? call(iterator, mapfn, [step.value, index], true) : step.value; + } + } else { + length = toLength(O.length); + for(result = new C(length); length > index; index++){ + result[index] = mapping ? mapfn(O[index], index) : O[index]; + } + } + result.length = index; + return result; + } +}); + +},{"./$.ctx":28,"./$.export":32,"./$.is-array-iter":41,"./$.iter-call":43,"./$.iter-detect":46,"./$.to-length":68,"./$.to-object":69,"./core.get-iterator-method":72}],75:[function(_dereq_,module,exports){ +'use strict'; +var addToUnscopables = _dereq_('./$.add-to-unscopables') + , step = _dereq_('./$.iter-step') + , Iterators = _dereq_('./$.iterators') + , toIObject = _dereq_('./$.to-iobject'); + +// 22.1.3.4 Array.prototype.entries() +// 22.1.3.13 Array.prototype.keys() +// 22.1.3.29 Array.prototype.values() +// 22.1.3.30 Array.prototype[@@iterator]() +module.exports = _dereq_('./$.iter-define')(Array, 'Array', function(iterated, kind){ + this._t = toIObject(iterated); // target + this._i = 0; // next index + this._k = kind; // kind +// 22.1.5.2.1 %ArrayIteratorPrototype%.next() +}, function(){ + var O = this._t + , kind = this._k + , index = this._i++; + if(!O || index >= O.length){ + this._t = undefined; + return step(1); + } + if(kind == 'keys' )return step(0, index); + if(kind == 'values')return step(0, O[index]); + return step(0, [index, O[index]]); +}, 'values'); + +// argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7) +Iterators.Arguments = Iterators.Array; + +addToUnscopables('keys'); +addToUnscopables('values'); +addToUnscopables('entries'); +},{"./$.add-to-unscopables":20,"./$.iter-define":45,"./$.iter-step":47,"./$.iterators":48,"./$.to-iobject":67}],76:[function(_dereq_,module,exports){ +// 19.1.3.1 Object.assign(target, source) +var $export = _dereq_('./$.export'); + +$export($export.S + $export.F, 'Object', {assign: _dereq_('./$.object-assign')}); +},{"./$.export":32,"./$.object-assign":52}],77:[function(_dereq_,module,exports){ +// 19.1.2.14 Object.keys(O) +var toObject = _dereq_('./$.to-object'); + +_dereq_('./$.object-sap')('keys', function($keys){ + return function keys(it){ + return $keys(toObject(it)); + }; +}); +},{"./$.object-sap":53,"./$.to-object":69}],78:[function(_dereq_,module,exports){ + +},{}],79:[function(_dereq_,module,exports){ +'use strict'; +var $ = _dereq_('./$') + , LIBRARY = _dereq_('./$.library') + , global = _dereq_('./$.global') + , ctx = _dereq_('./$.ctx') + , classof = _dereq_('./$.classof') + , $export = _dereq_('./$.export') + , isObject = _dereq_('./$.is-object') + , anObject = _dereq_('./$.an-object') + , aFunction = _dereq_('./$.a-function') + , strictNew = _dereq_('./$.strict-new') + , forOf = _dereq_('./$.for-of') + , setProto = _dereq_('./$.set-proto').set + , same = _dereq_('./$.same-value') + , SPECIES = _dereq_('./$.wks')('species') + , speciesConstructor = _dereq_('./$.species-constructor') + , asap = _dereq_('./$.microtask') + , PROMISE = 'Promise' + , process = global.process + , isNode = classof(process) == 'process' + , P = global[PROMISE] + , Wrapper; + +var testResolve = function(sub){ + var test = new P(function(){}); + if(sub)test.constructor = Object; + return P.resolve(test) === test; +}; + +var USE_NATIVE = function(){ + var works = false; + function P2(x){ + var self = new P(x); + setProto(self, P2.prototype); + return self; + } + try { + works = P && P.resolve && testResolve(); + setProto(P2, P); + P2.prototype = $.create(P.prototype, {constructor: {value: P2}}); + // actual Firefox has broken subclass support, test that + if(!(P2.resolve(5).then(function(){}) instanceof P2)){ + works = false; + } + // actual V8 bug, https://code.google.com/p/v8/issues/detail?id=4162 + if(works && _dereq_('./$.descriptors')){ + var thenableThenGotten = false; + P.resolve($.setDesc({}, 'then', { + get: function(){ thenableThenGotten = true; } + })); + works = thenableThenGotten; + } + } catch(e){ works = false; } + return works; +}(); + +// helpers +var sameConstructor = function(a, b){ + // library wrapper special case + if(LIBRARY && a === P && b === Wrapper)return true; + return same(a, b); +}; +var getConstructor = function(C){ + var S = anObject(C)[SPECIES]; + return S != undefined ? S : C; +}; +var isThenable = function(it){ + var then; + return isObject(it) && typeof (then = it.then) == 'function' ? then : false; +}; +var PromiseCapability = function(C){ + var resolve, reject; + this.promise = new C(function($$resolve, $$reject){ + if(resolve !== undefined || reject !== undefined)throw TypeError('Bad Promise constructor'); + resolve = $$resolve; + reject = $$reject; + }); + this.resolve = aFunction(resolve), + this.reject = aFunction(reject) +}; +var perform = function(exec){ + try { + exec(); + } catch(e){ + return {error: e}; + } +}; +var notify = function(record, isReject){ + if(record.n)return; + record.n = true; + var chain = record.c; + asap(function(){ + var value = record.v + , ok = record.s == 1 + , i = 0; + var run = function(reaction){ + var handler = ok ? reaction.ok : reaction.fail + , resolve = reaction.resolve + , reject = reaction.reject + , result, then; + try { + if(handler){ + if(!ok)record.h = true; + result = handler === true ? value : handler(value); + if(result === reaction.promise){ + reject(TypeError('Promise-chain cycle')); + } else if(then = isThenable(result)){ + then.call(result, resolve, reject); + } else resolve(result); + } else reject(value); + } catch(e){ + reject(e); + } + }; + while(chain.length > i)run(chain[i++]); // variable length - can't use forEach + chain.length = 0; + record.n = false; + if(isReject)setTimeout(function(){ + var promise = record.p + , handler, console; + if(isUnhandled(promise)){ + if(isNode){ + process.emit('unhandledRejection', value, promise); + } else if(handler = global.onunhandledrejection){ + handler({promise: promise, reason: value}); + } else if((console = global.console) && console.error){ + console.error('Unhandled promise rejection', value); + } + } record.a = undefined; + }, 1); + }); +}; +var isUnhandled = function(promise){ + var record = promise._d + , chain = record.a || record.c + , i = 0 + , reaction; + if(record.h)return false; + while(chain.length > i){ + reaction = chain[i++]; + if(reaction.fail || !isUnhandled(reaction.promise))return false; + } return true; +}; +var $reject = function(value){ + var record = this; + if(record.d)return; + record.d = true; + record = record.r || record; // unwrap + record.v = value; + record.s = 2; + record.a = record.c.slice(); + notify(record, true); +}; +var $resolve = function(value){ + var record = this + , then; + if(record.d)return; + record.d = true; + record = record.r || record; // unwrap + try { + if(record.p === value)throw TypeError("Promise can't be resolved itself"); + if(then = isThenable(value)){ + asap(function(){ + var wrapper = {r: record, d: false}; // wrap + try { + then.call(value, ctx($resolve, wrapper, 1), ctx($reject, wrapper, 1)); + } catch(e){ + $reject.call(wrapper, e); + } + }); + } else { + record.v = value; + record.s = 1; + notify(record, false); + } + } catch(e){ + $reject.call({r: record, d: false}, e); // wrap + } +}; + +// constructor polyfill +if(!USE_NATIVE){ + // 25.4.3.1 Promise(executor) + P = function Promise(executor){ + aFunction(executor); + var record = this._d = { + p: strictNew(this, P, PROMISE), // <- promise + c: [], // <- awaiting reactions + a: undefined, // <- checked in isUnhandled reactions + s: 0, // <- state + d: false, // <- done + v: undefined, // <- value + h: false, // <- handled rejection + n: false // <- notify + }; + try { + executor(ctx($resolve, record, 1), ctx($reject, record, 1)); + } catch(err){ + $reject.call(record, err); + } + }; + _dereq_('./$.redefine-all')(P.prototype, { + // 25.4.5.3 Promise.prototype.then(onFulfilled, onRejected) + then: function then(onFulfilled, onRejected){ + var reaction = new PromiseCapability(speciesConstructor(this, P)) + , promise = reaction.promise + , record = this._d; + reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; + reaction.fail = typeof onRejected == 'function' && onRejected; + record.c.push(reaction); + if(record.a)record.a.push(reaction); + if(record.s)notify(record, false); + return promise; + }, + // 25.4.5.1 Promise.prototype.catch(onRejected) + 'catch': function(onRejected){ + return this.then(undefined, onRejected); + } + }); +} + +$export($export.G + $export.W + $export.F * !USE_NATIVE, {Promise: P}); +_dereq_('./$.set-to-string-tag')(P, PROMISE); +_dereq_('./$.set-species')(PROMISE); +Wrapper = _dereq_('./$.core')[PROMISE]; + +// statics +$export($export.S + $export.F * !USE_NATIVE, PROMISE, { + // 25.4.4.5 Promise.reject(r) + reject: function reject(r){ + var capability = new PromiseCapability(this) + , $$reject = capability.reject; + $$reject(r); + return capability.promise; + } +}); +$export($export.S + $export.F * (!USE_NATIVE || testResolve(true)), PROMISE, { + // 25.4.4.6 Promise.resolve(x) + resolve: function resolve(x){ + // instanceof instead of internal slot check because we should fix it without replacement native Promise core + if(x instanceof P && sameConstructor(x.constructor, this))return x; + var capability = new PromiseCapability(this) + , $$resolve = capability.resolve; + $$resolve(x); + return capability.promise; + } +}); +$export($export.S + $export.F * !(USE_NATIVE && _dereq_('./$.iter-detect')(function(iter){ + P.all(iter)['catch'](function(){}); +})), PROMISE, { + // 25.4.4.1 Promise.all(iterable) + all: function all(iterable){ + var C = getConstructor(this) + , capability = new PromiseCapability(C) + , resolve = capability.resolve + , reject = capability.reject + , values = []; + var abrupt = perform(function(){ + forOf(iterable, false, values.push, values); + var remaining = values.length + , results = Array(remaining); + if(remaining)$.each.call(values, function(promise, index){ + var alreadyCalled = false; + C.resolve(promise).then(function(value){ + if(alreadyCalled)return; + alreadyCalled = true; + results[index] = value; + --remaining || resolve(results); + }, reject); + }); + else resolve(results); + }); + if(abrupt)reject(abrupt.error); + return capability.promise; + }, + // 25.4.4.4 Promise.race(iterable) + race: function race(iterable){ + var C = getConstructor(this) + , capability = new PromiseCapability(C) + , reject = capability.reject; + var abrupt = perform(function(){ + forOf(iterable, false, function(promise){ + C.resolve(promise).then(capability.resolve, reject); + }); + }); + if(abrupt)reject(abrupt.error); + return capability.promise; + } +}); +},{"./$":49,"./$.a-function":19,"./$.an-object":21,"./$.classof":22,"./$.core":27,"./$.ctx":28,"./$.descriptors":30,"./$.export":32,"./$.for-of":34,"./$.global":35,"./$.is-object":42,"./$.iter-detect":46,"./$.library":50,"./$.microtask":51,"./$.redefine-all":55,"./$.same-value":57,"./$.set-proto":58,"./$.set-species":59,"./$.set-to-string-tag":60,"./$.species-constructor":62,"./$.strict-new":63,"./$.wks":71}],80:[function(_dereq_,module,exports){ +'use strict'; +var strong = _dereq_('./$.collection-strong'); + +// 23.2 Set Objects +_dereq_('./$.collection')('Set', function(get){ + return function Set(){ return get(this, arguments.length > 0 ? arguments[0] : undefined); }; +}, { + // 23.2.3.1 Set.prototype.add(value) + add: function add(value){ + return strong.def(this, value = value === 0 ? 0 : value, value); + } +}, strong); +},{"./$.collection":26,"./$.collection-strong":24}],81:[function(_dereq_,module,exports){ +'use strict'; +var $at = _dereq_('./$.string-at')(true); + +// 21.1.3.27 String.prototype[@@iterator]() +_dereq_('./$.iter-define')(String, 'String', function(iterated){ + this._t = String(iterated); // target + this._i = 0; // next index +// 21.1.5.2.1 %StringIteratorPrototype%.next() +}, function(){ + var O = this._t + , index = this._i + , point; + if(index >= O.length)return {value: undefined, done: true}; + point = $at(O, index); + this._i += point.length; + return {value: point, done: false}; +}); +},{"./$.iter-define":45,"./$.string-at":64}],82:[function(_dereq_,module,exports){ +// https://github.com/DavidBruant/Map-Set.prototype.toJSON +var $export = _dereq_('./$.export'); + +$export($export.P, 'Set', {toJSON: _dereq_('./$.collection-to-json')('Set')}); +},{"./$.collection-to-json":25,"./$.export":32}],83:[function(_dereq_,module,exports){ +_dereq_('./es6.array.iterator'); +var Iterators = _dereq_('./$.iterators'); +Iterators.NodeList = Iterators.HTMLCollection = Iterators.Array; +},{"./$.iterators":48,"./es6.array.iterator":75}],84:[function(_dereq_,module,exports){ +var isFunction = _dereq_('is-function') + +module.exports = forEach + +var toString = Object.prototype.toString +var hasOwnProperty = Object.prototype.hasOwnProperty + +function forEach(list, iterator, context) { + if (!isFunction(iterator)) { + throw new TypeError('iterator must be a function') + } + + if (arguments.length < 3) { + context = this + } + + if (toString.call(list) === '[object Array]') + forEachArray(list, iterator, context) + else if (typeof list === 'string') + forEachString(list, iterator, context) + else + forEachObject(list, iterator, context) +} + +function forEachArray(array, iterator, context) { + for (var i = 0, len = array.length; i < len; i++) { + if (hasOwnProperty.call(array, i)) { + iterator.call(context, array[i], i, array) + } + } +} + +function forEachString(string, iterator, context) { + for (var i = 0, len = string.length; i < len; i++) { + // no such thing as a sparse string. + iterator.call(context, string.charAt(i), i, string) + } +} + +function forEachObject(object, iterator, context) { + for (var k in object) { + if (hasOwnProperty.call(object, k)) { + iterator.call(context, object[k], k, object) + } + } +} + +},{"is-function":86}],85:[function(_dereq_,module,exports){ +(function (global){ +if (typeof window !== "undefined") { + module.exports = window; +} else if (typeof global !== "undefined") { + module.exports = global; +} else if (typeof self !== "undefined"){ + module.exports = self; +} else { + module.exports = {}; +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{}],86:[function(_dereq_,module,exports){ +module.exports = isFunction + +var toString = Object.prototype.toString + +function isFunction (fn) { + var string = toString.call(fn) + return string === '[object Function]' || + (typeof fn === 'function' && string !== '[object RegExp]') || + (typeof window !== 'undefined' && + // IE8 and below + (fn === window.setTimeout || + fn === window.alert || + fn === window.confirm || + fn === window.prompt)) +}; + +},{}],87:[function(_dereq_,module,exports){ +var trim = _dereq_('trim') + , forEach = _dereq_('for-each') + , isArray = function(arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + } + +module.exports = function (headers) { + if (!headers) + return {} + + var result = {} + + forEach( + trim(headers).split('\n') + , function (row) { + var index = row.indexOf(':') + , key = trim(row.slice(0, index)).toLowerCase() + , value = trim(row.slice(index + 1)) + + if (typeof(result[key]) === 'undefined') { + result[key] = value + } else if (isArray(result[key])) { + result[key].push(value) + } else { + result[key] = [ result[key], value ] + } + } + ) + + return result +} +},{"for-each":84,"trim":88}],88:[function(_dereq_,module,exports){ + +exports = module.exports = trim; + +function trim(str){ + return str.replace(/^\s*|\s*$/g, ''); +} + +exports.left = function(str){ + return str.replace(/^\s*/, ''); +}; + +exports.right = function(str){ + return str.replace(/\s*$/, ''); +}; + +},{}],89:[function(_dereq_,module,exports){ +"use strict"; +var window = _dereq_("global/window") +var once = _dereq_("once") +var isFunction = _dereq_("is-function") +var parseHeaders = _dereq_("parse-headers") +var xtend = _dereq_("xtend") + +module.exports = createXHR +createXHR.XMLHttpRequest = window.XMLHttpRequest || noop +createXHR.XDomainRequest = "withCredentials" in (new createXHR.XMLHttpRequest()) ? createXHR.XMLHttpRequest : window.XDomainRequest + +forEachArray(["get", "put", "post", "patch", "head", "delete"], function(method) { + createXHR[method === "delete" ? "del" : method] = function(uri, options, callback) { + options = initParams(uri, options, callback) + options.method = method.toUpperCase() + return _createXHR(options) + } +}) + +function forEachArray(array, iterator) { + for (var i = 0; i < array.length; i++) { + iterator(array[i]) + } +} + +function isEmpty(obj){ + for(var i in obj){ + if(obj.hasOwnProperty(i)) return false + } + return true +} + +function initParams(uri, options, callback) { + var params = uri + + if (isFunction(options)) { + callback = options + if (typeof uri === "string") { + params = {uri:uri} + } + } else { + params = xtend(options, {uri: uri}) + } + + params.callback = callback + return params +} + +function createXHR(uri, options, callback) { + options = initParams(uri, options, callback) + return _createXHR(options) +} + +function _createXHR(options) { + var callback = options.callback + if(typeof callback === "undefined"){ + throw new Error("callback argument missing") + } + callback = once(callback) + + function readystatechange() { + if (xhr.readyState === 4) { + loadFunc() + } + } + + function getBody() { + // Chrome with requestType=blob throws errors arround when even testing access to responseText + var body = undefined + + if (xhr.response) { + body = xhr.response + } else if (xhr.responseType === "text" || !xhr.responseType) { + body = xhr.responseText || xhr.responseXML + } + + if (isJson) { + try { + body = JSON.parse(body) + } catch (e) {} + } + + return body + } + + var failureResponse = { + body: undefined, + headers: {}, + statusCode: 0, + method: method, + url: uri, + rawRequest: xhr + } + + function errorFunc(evt) { + clearTimeout(timeoutTimer) + if(!(evt instanceof Error)){ + evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") ) + } + evt.statusCode = 0 + callback(evt, failureResponse) + } + + // will load the data & process the response in a special response object + function loadFunc() { + if (aborted) return + var status + clearTimeout(timeoutTimer) + if(options.useXDR && xhr.status===undefined) { + //IE8 CORS GET successful response doesn't have a status field, but body is fine + status = 200 + } else { + status = (xhr.status === 1223 ? 204 : xhr.status) + } + var response = failureResponse + var err = null + + if (status !== 0){ + response = { + body: getBody(), + statusCode: status, + method: method, + headers: {}, + url: uri, + rawRequest: xhr + } + if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE + response.headers = parseHeaders(xhr.getAllResponseHeaders()) + } + } else { + err = new Error("Internal XMLHttpRequest Error") + } + callback(err, response, response.body) + + } + + var xhr = options.xhr || null + + if (!xhr) { + if (options.cors || options.useXDR) { + xhr = new createXHR.XDomainRequest() + }else{ + xhr = new createXHR.XMLHttpRequest() + } + } + + var key + var aborted + var uri = xhr.url = options.uri || options.url + var method = xhr.method = options.method || "GET" + var body = options.body || options.data || null + var headers = xhr.headers = options.headers || {} + var sync = !!options.sync + var isJson = false + var timeoutTimer + + if ("json" in options) { + isJson = true + headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json") //Don't override existing accept header declared by user + if (method !== "GET" && method !== "HEAD") { + headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json") //Don't override existing accept header declared by user + body = JSON.stringify(options.json) + } + } + + xhr.onreadystatechange = readystatechange + xhr.onload = loadFunc + xhr.onerror = errorFunc + // IE9 must have onprogress be set to a unique function. + xhr.onprogress = function () { + // IE must die + } + xhr.ontimeout = errorFunc + xhr.open(method, uri, !sync, options.username, options.password) + //has to be after open + if(!sync) { + xhr.withCredentials = !!options.withCredentials + } + // Cannot set timeout with sync request + // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly + // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent + if (!sync && options.timeout > 0 ) { + timeoutTimer = setTimeout(function(){ + aborted=true//IE9 may still call readystatechange + xhr.abort("timeout") + var e = new Error("XMLHttpRequest timeout") + e.code = "ETIMEDOUT" + errorFunc(e) + }, options.timeout ) + } + + if (xhr.setRequestHeader) { + for(key in headers){ + if(headers.hasOwnProperty(key)){ + xhr.setRequestHeader(key, headers[key]) + } + } + } else if (options.headers && !isEmpty(options.headers)) { + throw new Error("Headers cannot be set on an XDomainRequest object") + } + + if ("responseType" in options) { + xhr.responseType = options.responseType + } + + if ("beforeSend" in options && + typeof options.beforeSend === "function" + ) { + options.beforeSend(xhr) + } + + xhr.send(body) + + return xhr + + +} + +function noop() {} + +},{"global/window":85,"is-function":86,"once":90,"parse-headers":87,"xtend":91}],90:[function(_dereq_,module,exports){ +module.exports = once + +once.proto = once(function () { + Object.defineProperty(Function.prototype, 'once', { + value: function () { + return once(this) + }, + configurable: true + }) +}) + +function once (fn) { + var called = false + return function () { + if (called) return + called = true + return fn.apply(this, arguments) + } +} + +},{}],91:[function(_dereq_,module,exports){ +module.exports = extend + +var hasOwnProperty = Object.prototype.hasOwnProperty; + +function extend() { + var target = {} + + for (var i = 0; i < arguments.length; i++) { + var source = arguments[i] + + for (var key in source) { + if (hasOwnProperty.call(source, key)) { + target[key] = source[key] + } + } + } + + return target +} + +},{}],92:[function(_dereq_,module,exports){ +/* +The MIT License (MIT) + +Copyright (c) 2015 Patricio Gonzalez Vivo ( http://www.patriciogonzalezvivo.com ) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the 'Software'), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +'use strict'; + +var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; + +var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; + +var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _xhr = _dereq_('xhr'); + +var _xhr2 = _interopRequireDefault(_xhr); + +var _glGl = _dereq_('./gl/gl'); + +var _glTexture = _dereq_('./gl/Texture'); + +var _glTexture2 = _interopRequireDefault(_glTexture); + +var _toolsCommon = _dereq_('./tools/common'); + +var _toolsMixin = _dereq_('./tools/mixin'); + +var GlslCanvas = (function () { + function GlslCanvas(canvas, options) { + var _this = this; + + _classCallCheck(this, GlslCanvas); + + (0, _toolsMixin.subscribeMixin)(this); + + options = options || {}; + + this.width = canvas.clientWidth; + this.height = canvas.clientHeight; + + this.canvas = canvas; + this.gl = undefined; + this.program = undefined; + this.uniforms = {}; + this.vbo = {}; + this.isValid = false; + + this.vertexString = options.vertexString || '\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nattribute vec2 a_position;\nattribute vec2 a_texcoord;\n\nvarying vec2 v_texcoord;\n\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texcoord = a_texcoord;\n}\n'; + this.fragmentString = options.fragmentString || '\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvarying vec2 v_texcoord;\n\nvoid main(){\n gl_FragColor = vec4(0.0);\n}\n'; + + // GL Context + var gl = (0, _glGl.setupWebGL)(canvas, options); + if (!gl) { + return; + } + this.gl = gl; + this.timeLoad = Date.now(); + this.forceRender = true; + + // Allow alpha + canvas.style.backgroundColor = options.backgroundColor || 'rgba(1,1,1,0)'; + + // Load shader + if (canvas.hasAttribute('data-fragment')) { + this.fragmentString = canvas.getAttribute('data-fragment'); + } else if (canvas.hasAttribute('data-fragment-url')) { + var source = canvas.getAttribute('data-fragment-url'); + _xhr2['default'].get(source, function (error, response, body) { + _this.load(body, _this.vertexString); + }); + } + + // Load shader + if (canvas.hasAttribute('data-vertex')) { + this.vertexString = canvas.getAttribute('data-vertex'); + } else if (canvas.hasAttribute('data-vertex-url')) { + var source = canvas.getAttribute('data-vertex-url'); + _xhr2['default'].get(source, function (error, response, body) { + _this.load(_this.fragmentString, body); + }); + } + + this.load(); + + if (!this.program) { + return; + } + + // Define Vertex buffer + var texCoordsLoc = gl.getAttribLocation(this.program, 'a_texcoord'); + this.vbo.texCoords = gl.createBuffer(); + this.gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo.texCoords); + this.gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW); + this.gl.enableVertexAttribArray(texCoordsLoc); + this.gl.vertexAttribPointer(texCoordsLoc, 2, gl.FLOAT, false, 0, 0); + + var verticesLoc = gl.getAttribLocation(this.program, 'a_position'); + this.vbo.vertices = gl.createBuffer(); + this.gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo.vertices); + this.gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0]), gl.STATIC_DRAW); + this.gl.enableVertexAttribArray(verticesLoc); + this.gl.vertexAttribPointer(verticesLoc, 2, gl.FLOAT, false, 0, 0); + + // load TEXTURES + this.textures = {}; + if (canvas.hasAttribute('data-textures')) { + var imgList = canvas.getAttribute('data-textures').split(','); + for (var nImg in imgList) { + this.setUniform('u_tex' + nImg, imgList[nImg]); + } + } + + // ========================== EVENTS + var mouse = { + x: 0, + y: 0 + }; + document.addEventListener('mousemove', function (e) { + mouse.x = e.clientX || e.pageX; + mouse.y = e.clientY || e.pageY; + }, false); + + var sandbox = this; + function RenderLoop() { + sandbox.setMouse(mouse); + sandbox.render(); + sandbox.forceRender = sandbox.resize(); + window.requestAnimationFrame(RenderLoop); + } + + // Start + this.setMouse({ x: 0, y: 0 }); + RenderLoop(); + return this; + } + + _createClass(GlslCanvas, [{ + key: 'destroy', + value: function destroy() { + this.animated = false; + this.isValid = false; + for (var tex in this.textures) { + this.gl.deleteTexture(tex); + } + this.textures = {}; + for (var att in this.attribs) { + this.gl.deleteBuffer(this.attribs[att]); + } + this.gl.useProgram(null); + this.gl.deleteProgram(this.program); + this.program = null; + this.gl = null; + } + }, { + key: 'load', + value: function load(fragString, vertString) { + // Load vertex shader if there is one + if (vertString) { + this.vertexString = vertString; + } + + // Load fragment shader if there is one + if (fragString) { + this.fragmentString = fragString; + } + + this.animated = false; + var nTimes = (this.fragmentString.match(/u_time/g) || []).length; + var nMouse = (this.fragmentString.match(/u_mouse/g) || []).length; + this.animated = nTimes > 1 || nMouse > 1; + + var vertexShader = (0, _glGl.createShader)(this, this.vertexString, this.gl.VERTEX_SHADER); + var fragmentShader = (0, _glGl.createShader)(this, this.fragmentString, this.gl.FRAGMENT_SHADER); + + // If Fragment shader fails load a empty one to sign the error + if (!fragmentShader) { + fragmentShader = (0, _glGl.createShader)(this, 'void main(){\n\tgl_FragColor = vec4(1.0);\n}', this.gl.FRAGMENT_SHADER); + this.isValid = false; + } else { + this.isValid = true; + } + + // Create and use program + var program = (0, _glGl.createProgram)(this, [vertexShader, fragmentShader]); //, [0,1],['a_texcoord','a_position']); + this.gl.useProgram(program); + + // Delete shaders + // this.gl.detachShader(program, vertexShader); + // this.gl.detachShader(program, fragmentShader); + this.gl.deleteShader(vertexShader); + this.gl.deleteShader(fragmentShader); + + this.program = program; + this.change = true; + + // Trigger event + this.trigger('load', {}); + + this.forceRender = true; + } + }, { + key: 'loadTexture', + value: function loadTexture(name, urlElementOrData, options) { + var _this2 = this; + + if (!options) { + options = {}; + } + + if (typeof urlElementOrData === 'string') { + options.url = urlElementOrData; + } else if (typeof urlElementOrData === 'object' && urlElementOrData.data && urlElementOrData.width && urlElementOrData.height) { + options.data = urlElementOrData.data; + options.width = urlElementOrData.width; + options.height = urlElementOrData.height; + } else if (typeof urlElementOrData === 'object') { + options.element = urlElementOrData; + } + this.textures[name] = new _glTexture2['default'](this.gl, name, options); + this.textures[name].on('loaded', function (args) { + _this2.forceRender = true; + }); + } + }, { + key: 'refreshUniforms', + value: function refreshUniforms() { + this.uniforms = {}; + } + }, { + key: 'setUniform', + value: function setUniform(name) { + var u = {}; + + for (var _len = arguments.length, value = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + value[_key - 1] = arguments[_key]; + } + + u[name] = value; + this.setUniforms(u); + } + }, { + key: 'setUniforms', + value: function setUniforms(uniforms) { + var parsed = (0, _glGl.parseUniforms)(uniforms); + // Set each uniform + for (var u in parsed) { + if (parsed[u].type === 'sampler2D') { + // For textures, we need to track texture units, so we have a special setter + this.uniformTexture(parsed[u].name, parsed[u].value[0]); + } else { + this.uniform(parsed[u].method, parsed[u].type, parsed[u].name, parsed[u].value); + this.forceRender = true; + } + } + } + }, { + key: 'setMouse', + value: function setMouse(mouse) { + // set the mouse uniform + var rect = this.canvas.getBoundingClientRect(); + if (mouse && mouse.x && mouse.x >= rect.left && mouse.x <= rect.right && mouse.y && mouse.y >= rect.top && mouse.y <= rect.bottom) { + this.uniform('2f', 'vec2', 'u_mouse', mouse.x - rect.left, this.canvas.height - (mouse.y - rect.top)); + } + } + + // ex: program.uniform('3f', 'position', x, y, z); + }, { + key: 'uniform', + value: function uniform(method, type, name) { + // 'value' is a method-appropriate arguments list + this.uniforms[name] = this.uniforms[name] || {}; + var uniform = this.uniforms[name]; + + for (var _len2 = arguments.length, value = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) { + value[_key2 - 3] = arguments[_key2]; + } + + var change = (0, _toolsCommon.isDiff)(uniform.value, value); + if (change || this.change || uniform.location === undefined || uniform.value === undefined) { + uniform.name = name; + uniform.value = value; + uniform.type = type; + uniform.method = 'uniform' + method; + uniform.location = this.gl.getUniformLocation(this.program, name); + + this.gl[uniform.method].apply(this.gl, [uniform.location].concat(uniform.value)); + } + } + }, { + key: 'uniformTexture', + value: function uniformTexture(name, texture, options) { + if (this.textures[name] === undefined) { + this.loadTexture(name, texture, options); + } else { + this.uniform('1i', 'sampler2D', name, this.texureIndex); + this.textures[name].bind(this.texureIndex); + this.uniform('2f', 'vec2', name + 'Resolution', this.textures[name].width, this.textures[name].height); + this.texureIndex++; + } + } + }, { + key: 'resize', + value: function resize() { + if (this.width !== this.canvas.clientWidth || this.height !== this.canvas.clientHeight) { + var realToCSSPixels = window.devicePixelRatio || 1; + + // Lookup the size the browser is displaying the canvas in CSS pixels + // and compute a size needed to make our drawingbuffer match it in + // device pixels. + var displayWidth = Math.floor(this.gl.canvas.clientWidth * realToCSSPixels); + var displayHeight = Math.floor(this.gl.canvas.clientHeight * realToCSSPixels); + + // Check if the canvas is not the same size. + if (this.gl.canvas.width !== displayWidth || this.gl.canvas.height !== displayHeight) { + // Make the canvas the same size + this.gl.canvas.width = displayWidth; + this.gl.canvas.height = displayHeight; + // Set the viewport to match + this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height); + // this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight); + } + this.width = this.canvas.clientWidth; + this.height = this.canvas.clientHeight; + return true; + } else { + return false; + } + } + }, { + key: 'render', + value: function render() { + this.visible = (0, _toolsCommon.isCanvasVisible)(this.canvas); + if (this.forceRender || this.animated && this.visible) { + // set the time uniform + var timeFrame = Date.now(); + var time = (timeFrame - this.timeLoad) / 1000.0; + this.uniform('1f', 'float', 'u_time', time); + + // set the resolution uniform + this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width, this.canvas.height); + + this.texureIndex = 0; + for (var tex in this.textures) { + this.uniformTexture(tex); + } + + // Draw the rectangle. + this.gl.drawArrays(this.gl.TRIANGLES, 0, 6); + + // Trigger event + this.trigger('render', {}); + + this.change = false; + this.forceRender = false; + } + } + }, { + key: 'version', + value: function version() { + return '0.0.3'; + } + }]); + + return GlslCanvas; +})(); + +exports['default'] = GlslCanvas; + +window.GlslCanvas = GlslCanvas; + +function loadAllGlslCanvas() { + var list = document.getElementsByClassName('glslCanvas'); + if (list.length > 0) { + window.glslCanvases = []; + for (var i = 0; i < list.length; i++) { + var sandbox = new GlslCanvas(list[i]); + if (sandbox.isValid) { + window.glslCanvases.push(sandbox); + } + } + } +} + +window.onload = function () { + loadAllGlslCanvas(); +}; +module.exports = exports['default']; + +},{"./gl/Texture":93,"./gl/gl":94,"./tools/common":95,"./tools/mixin":96,"babel-runtime/helpers/class-call-check":8,"babel-runtime/helpers/create-class":9,"babel-runtime/helpers/interop-require-default":10,"xhr":89}],93:[function(_dereq_,module,exports){ +// Texture management +'use strict'; + +var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; + +var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; + +var _Promise = _dereq_('babel-runtime/core-js/promise')['default']; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _toolsCommon = _dereq_('../tools/common'); + +var _toolsMixin = _dereq_('../tools/mixin'); + +// GL texture wrapper object for keeping track of a global set of textures, keyed by a unique user-defined name + +var Texture = (function () { + function Texture(gl, name) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + _classCallCheck(this, Texture); + + (0, _toolsMixin.subscribeMixin)(this); + + this.gl = gl; + this.texture = gl.createTexture(); + if (this.texture) { + this.valid = true; + } + this.bind(); + + this.name = name; + this.source = null; + this.sourceType = null; + this.loading = null; // a Promise object to track the loading state of this texture + + // Default to a 1-pixel black texture so we can safely render while we wait for an image to load + // See: http://stackoverflow.com/questions/19722247/webgl-wait-for-texture-to-load + this.setData(1, 1, new Uint8Array([0, 0, 0, 255]), { filtering: 'linear' }); + this.setFiltering(options.filtering); + + this.load(options); + } + + // Report max texture size for a GL context + + // Destroy a single texture instance + + _createClass(Texture, [{ + key: 'destroy', + value: function destroy() { + if (!this.valid) { + return; + } + this.gl.deleteTexture(this.texture); + this.texture = null; + delete this.data; + this.data = null; + this.valid = false; + } + }, { + key: 'bind', + value: function bind(unit) { + if (!this.valid) { + return; + } + if (typeof unit === 'number') { + if (Texture.activeUnit !== unit) { + this.gl.activeTexture(this.gl.TEXTURE0 + unit); + Texture.activeUnit = unit; + } + } + if (Texture.activeTexture !== this.texture) { + this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture); + Texture.activeTexture = this.texture; + } + } + }, { + key: 'load', + value: function load() { + var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + this.loading = null; + + if (typeof options.url === 'string') { + this.setUrl(options.url, options); + } else if (options.element) { + this.setElement(options.element, options); + } else if (options.data && options.width && options.height) { + this.setData(options.width, options.height, options.data, options); + } + } + + // Sets texture from an url + }, { + key: 'setUrl', + value: function setUrl(url) { + var _this = this; + + var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + if (!this.valid) { + return; + } + + this.url = url; // save URL reference (will be overwritten when element is loaded below) + this.source = this.url; + this.sourceType = 'url'; + + this.loading = new _Promise(function (resolve, reject) { + var image = new Image(); + image.onload = function () { + try { + _this.setElement(image, options); + } catch (e) { + console.log('Texture \'' + _this.name + '\': failed to load url: \'' + _this.source + '\'', e, options); + } + + resolve(_this); + }; + image.onerror = function (e) { + // Warn and resolve on error + console.log('Texture \'' + _this.name + '\': failed to load url: \'' + _this.source + '\'', e, options); + resolve(_this); + }; + image.crossOrigin = 'anonymous'; + image.src = _this.source; + }); + return this.loading; + } + + // Sets texture to a raw image buffer + }, { + key: 'setData', + value: function setData(width, height, data) { + var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; + + this.width = width; + this.height = height; + + this.source = data; + this.sourceType = 'data'; + + this.update(options); + this.setFiltering(options); + + this.loading = _Promise.resolve(this); + return this.loading; + } + + // Sets the texture to track a element (canvas/image) + }, { + key: 'setElement', + value: function setElement(element, options) { + var el = element; + + // a string element is interpeted as a CSS selector + if (typeof element === 'string') { + element = document.querySelector(element); + } + + if (element instanceof HTMLCanvasElement || element instanceof HTMLImageElement || element instanceof HTMLVideoElement) { + this.source = element; + this.sourceType = 'element'; + + this.update(options); + this.setFiltering(options); + } else { + var msg = 'the \'element\' parameter (`element: ' + JSON.stringify(el) + '`) must be a CSS '; + msg += 'selector string, or a , or