From d8c4ee6b51f0ea5670a8b35a91eda12b9041f246 Mon Sep 17 00:00:00 2001 From: Denis Radin Date: Thu, 2 Apr 2015 23:39:49 +0200 Subject: [PATCH 01/40] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 144cb51..16306f2 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ How to use? Include HTMLGL.js into project. Use tag name `````` or jQuery plugin ```$(myElement).htmlgl()``` for elements you are going to animate. These elements will be rendered in WebGL and their CSS Transform properties will be mapped to WebGL representation transformations. So DOM node itself will not be animated or displayed in order to avoid resources consuming. HTML GL is framework agnostic and is easy to inject into existing project which needs performance tweaking. +Rasterization API +----------------- +In order to imporove technology we are trying to promote standardization of native Rasterization API for browsers. Help us to be better and to add this cool feature to the spec by spreading the [article](http://pixelscommander.com/en/javascript/state-of-html-content-rasterization-draw-html-to-canvas-image/) and [proposal draft](https://docs.google.com/document/d/1eqNtrkhf8WEDJC2J82eQmjSrR1YRs0Iic496ASeE6dI/pub). + License ------- MIT: http://mit-license.org/ From fcff37b165fda5fb9d2605ac42bd59d770ef8110 Mon Sep 17 00:00:00 2001 From: Denis Radin Date: Fri, 3 Apr 2015 01:00:13 +0200 Subject: [PATCH 02/40] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16306f2..46b5af6 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ HTML GL is framework agnostic and is easy to inject into existing project which Rasterization API ----------------- -In order to imporove technology we are trying to promote standardization of native Rasterization API for browsers. Help us to be better and to add this cool feature to the spec by spreading the [article](http://pixelscommander.com/en/javascript/state-of-html-content-rasterization-draw-html-to-canvas-image/) and [proposal draft](https://docs.google.com/document/d/1eqNtrkhf8WEDJC2J82eQmjSrR1YRs0Iic496ASeE6dI/pub). +In order to improve technology we are trying to promote standardized native Rasterization API for JavaScript. Help us to be better and to add this cool feature to browsers by spreading the [article](http://pixelscommander.com/en/javascript/state-of-html-content-rasterization-draw-html-to-canvas-image/) and [proposal draft](https://docs.google.com/document/d/1eqNtrkhf8WEDJC2J82eQmjSrR1YRs0Iic496ASeE6dI/pub). License ------- From 2e0c8be7cab8328dbe738c35eae261397b8c9d95 Mon Sep 17 00:00:00 2001 From: PixelsCommander Date: Fri, 3 Apr 2015 01:14:46 +0200 Subject: [PATCH 03/40] #25 Added jQuery snippet --- bower.json | 3 +- demo/assets/css/style.css | 1 + demo/basic-webgl-jquery.html | 69 ++++++++++++++++++++++++++++ demo/filters.html | 6 +-- demo/js/vendor/html2canvas.js | 21 ++++++--- dist/htmlgl.js | 84 ++++++++++++++++++++++++++--------- dist/htmlgl.min.js | 14 +++--- page/js/htmlgl.min.js | 14 +++--- src/gl-context.js | 3 +- src/gl-element.js | 60 ++++++++++++++++++------- 10 files changed, 214 insertions(+), 61 deletions(-) create mode 100644 demo/basic-webgl-jquery.html mode change 100755 => 100644 demo/js/vendor/html2canvas.js diff --git a/bower.json b/bower.json index c6d0990..4f3400d 100644 --- a/bower.json +++ b/bower.json @@ -15,6 +15,7 @@ "dependencies": { "pixi": "~2.2.5", "webcomponents.js": "~0.5.5", - "promise-polyfill": "~2.0.0" + "promise-polyfill": "~2.0.0", + "jquery": "~2.1.3" } } diff --git a/demo/assets/css/style.css b/demo/assets/css/style.css index ea0cfd5..865b399 100644 --- a/demo/assets/css/style.css +++ b/demo/assets/css/style.css @@ -58,6 +58,7 @@ body { html-gl { display: block; } + h1 { font-family: verdana, sans-serif; font-size: 16px; diff --git a/demo/basic-webgl-jquery.html b/demo/basic-webgl-jquery.html new file mode 100644 index 0000000..59ceeb0 --- /dev/null +++ b/demo/basic-webgl-jquery.html @@ -0,0 +1,69 @@ + + + + + HTML GL demo + + + + + + + + + + + + + + + +

HTML GL demo

+ +
+ This layer is rendered in

WebGL

because it have tag name html-gl +
+ + + +

+ TODO +

+
    +
  • Add retina support in order to avoid blurry content
  • +
+ + + \ No newline at end of file diff --git a/demo/filters.html b/demo/filters.html index 500da7c..7d740ad 100644 --- a/demo/filters.html +++ b/demo/filters.html @@ -12,12 +12,9 @@

MENU RENDERED IN DOM

- -
-

SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

- -
  • -
    - - -

    - Select me with DevTools -

    - -

    - - 7.8/10 -

    -
  • -
  • -
    - - -

    - Change me in DevTools -

    - -

    - - 8.0/10 -

    -
  • -
  • -
    - - -

    - Breaking bad -

    - -

    - - 9.6/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 6.7/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 7.4/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 7.4/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 7.4/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 7.4/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 7.4/10 -

    -
  • -
  • -
    - - -

    - Quantum of solace -

    - -

    - - 7.4/10 -

    -
  • -
    - -
    -
    -
    - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/demo/filters.html b/demo/filters.html index c21fa63..88d77c1 100644 --- a/demo/filters.html +++ b/demo/filters.html @@ -174,7 +174,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    - + @@ -190,8 +190,11 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    var gui = new dat.GUI({}); - var displacementTexture = PIXI.Texture.fromImage("assets/img/displacement_map.jpg"); - var displacementFilter = new PIXI.DisplacementFilter(displacementTexture); + + + var displacementSprite = new PIXI.TilingSprite.fromImage("assets/img/displacement_map.jpg"); + window.HTMLGL.stage.addChild(displacementSprite); + var displacementFilter = new PIXI.filters.DisplacementFilter(displacementSprite); var displacementFolder = gui.addFolder('Displacement'); displacementFolder.add(filtersSwitchs, '0').name("apply"); @@ -199,7 +202,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    displacementFolder.add(displacementFilter.scale, 'y', 1, 200).name("scaleY"); displacementFolder.open(); - var blurFilter = new PIXI.BlurFilter(); + var blurFilter = new PIXI.filters.BlurFilter(); var blurFolder = gui.addFolder('Blur'); blurFolder.add(filtersSwitchs, '1').name("apply"); @@ -208,7 +211,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var pixelateFilter = new PIXI.PixelateFilter(); + var pixelateFilter = new PIXI.filters.PixelateFilter(); var pixelateFolder = gui.addFolder('Pixelate'); pixelateFolder.add(filtersSwitchs, '2').name("apply"); @@ -217,7 +220,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var invertFilter = new PIXI.InvertFilter(); + var invertFilter = new PIXI.filters.InvertFilter(); var invertFolder = gui.addFolder('Invert'); invertFolder.add(filtersSwitchs, '3').name("apply"); @@ -225,7 +228,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var grayFilter = new PIXI.GrayFilter(); + var grayFilter = new PIXI.filters.GrayFilter(); var grayFolder = gui.addFolder('Gray'); grayFolder.add(filtersSwitchs, '4').name("apply"); @@ -233,7 +236,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var sepiaFilter = new PIXI.SepiaFilter(); + var sepiaFilter = new PIXI.filters.SepiaFilter(); var sepiaFolder = gui.addFolder('Sepia'); sepiaFolder.add(filtersSwitchs, '5').name("apply"); @@ -241,7 +244,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var twistFilter = new PIXI.TwistFilter(); + var twistFilter = new PIXI.filters.TwistFilter(); var twistFolder = gui.addFolder('Twist'); twistFolder.add(filtersSwitchs, '6').name("apply"); @@ -253,7 +256,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var dotScreenFilter = new PIXI.DotScreenFilter(); + var dotScreenFilter = new PIXI.filters.DotScreenFilter(); var dotScreenFolder = gui.addFolder('DotScreen'); dotScreenFolder.add(filtersSwitchs, '7').name("apply"); @@ -262,7 +265,7 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var colorStepFilter = new PIXI.ColorStepFilter(); + var colorStepFilter = new PIXI.filters.ColorStepFilter(); var colorStepFolder = gui.addFolder('ColorStep'); colorStepFolder.add(filtersSwitchs, '8').name("apply"); @@ -272,12 +275,16 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    //// - var crossHatchFilter = new PIXI.CrossHatchFilter(); + var crossHatchFilter = new PIXI.filters.CrossHatchFilter(); var crossHatchFolder = gui.addFolder('CrossHatch'); crossHatchFolder.add(filtersSwitchs, '9').name("apply"); - var rgbSplitterFilter = new PIXI.RGBSplitFilter(); + var rgbSplitterFilter = new PIXI.filters.RGBSplitFilter(); + + rgbSplitterFilter.blue = new PIXI.Point(10, 10); + rgbSplitterFilter.green = new PIXI.Point(-10, 10); + rgbSplitterFilter.red = new PIXI.Point(10, -10); var rgbSplitFolder = gui.addFolder('RGB Splitter'); rgbSplitFolder.add(filtersSwitchs, '10').name("apply"); @@ -293,40 +300,8 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    stage.interactive = true; - //var bg = PIXI.Sprite.fromImage("assets/img/displacement_BG.jpg"); - //pondContainer.addChild(bg); - - //var fish = PIXI.Sprite.fromImage("displacement_fish2.jpg");// - //littleDudes.position.y = 100; var padding = 100; var bounds = new PIXI.Rectangle(-padding, -padding, window.HTMLGL.renderer.width + padding * 2, window.HTMLGL.renderer.height + padding * 2) - var fishs = []; - - - /*for (var i = 0; i < 20; i++) - { - var fishId = i % 4; - fishId += 1; - - //console.log("displacement_fish"+fishId+".png") - var fish = PIXI.Sprite.fromImage("assets/img/displacement_fish"+fishId+".png"); - fish.anchor.x = fish.anchor.y = 0.5; - pondContainer.addChild(fish); - - //var direction - //var speed = - fish.direction = Math.random() * Math.PI * 2; - fish.speed = 2 + Math.random() * 2; - fish.turnSpeed = Math.random() - 0.8; - - fish.position.x = Math.random() * bounds.width; - fish.position.y = Math.random() * bounds.height; - //fish.speed = new PIXI.Point(0,0) - - fish.scale.x = fish.scale.y = 0.8 + Math.random() * 0.3; - fishs.push(fish); - - };*/ var overlay = new PIXI.TilingSprite(PIXI.Texture.fromImage("assets/img/zeldaWaves.png"), window.HTMLGL.renderer.width, window.HTMLGL.renderer.height); overlay.alpha = 0.1//0.2 @@ -353,20 +328,34 @@

    SLIDER BELOW IS RENDERED IN WEBGL, DRAG IT

    if(filtersSwitchs[i])filtersToApply.push(filterCollection[i]); }; + var rgbFilterIndex = filtersToApply.indexOf(rgbSplitterFilter); + + if (rgbFilterIndex !== -1) { + HTMLGL.elements[0].sprite.filters = [rgbSplitterFilter]; + filtersToApply.splice(rgbFilterIndex, 1); + } else { + if (HTMLGL.elements[0].sprite.filters) { + var rgbFilterIndexOnSlider = HTMLGL.elements[0].sprite.filters.indexOf(rgbSplitterFilter); + if (rgbFilterIndexOnSlider !== -1) { + HTMLGL.elements[0].sprite.filters = null; + } + } + } + pondContainer.filters = filtersToApply.length > 0 ? filtersToApply : null; - displacementFilter.offset.x = count * 10//blurAmount * 40; - displacementFilter.offset.y = count * 10 + displacementSprite.x = count * 10; + displacementSprite.y = count * 10; - overlay.tilePosition.x = count * -10//blurAmount * 40; - overlay.tilePosition.y = count * -10 + overlay.tilePosition.x = count * -10; + overlay.tilePosition.y = count * -10; renderer.render(stage); - requestAnimFrame( animate ); + requestAnimationFrame( animate ); } renderer.render(stage); - requestAnimFrame( animate ); + requestAnimationFrame( animate ); diff --git a/demo/js/vendor/html2canvas.js b/demo/js/vendor/html2canvas.js old mode 100644 new mode 100755 index 4744e9e..0370eea --- a/demo/js/vendor/html2canvas.js +++ b/demo/js/vendor/html2canvas.js @@ -1,582 +1,596 @@ /* - html2canvas 0.5.0-alpha2 - Copyright (c) 2015 Niklas von Hertzen - - Released under MIT License + html2canvas 0.5.0-alpha2 + Copyright (c) 2015 Niklas von Hertzen + + Released under MIT License +*/ + +(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.html2canvas = 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) { - throw new Error('Second argument not supported'); - } - if (typeof o !== 'object') { - throw new TypeError('Argument must be an object'); - } - $$utils$$F.prototype = o; - return new $$utils$$F(); - }); + var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray; + var lib$es6$promise$asap$$len = 0; + var lib$es6$promise$asap$$toString = {}.toString; + var lib$es6$promise$asap$$vertxNext; + var lib$es6$promise$asap$$customSchedulerFn; + + var lib$es6$promise$asap$$asap = function asap(callback, arg) { + lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback; + lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg; + lib$es6$promise$asap$$len += 2; + if (lib$es6$promise$asap$$len === 2) { + // If len is 2, that means that we need to schedule an async flush. + // If additional callbacks are queued before the queue is flushed, they + // will be processed by this flush that we are scheduling. + if (lib$es6$promise$asap$$customSchedulerFn) { + lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush); + } else { + lib$es6$promise$asap$$scheduleFlush(); + } + } + } - var $$asap$$len = 0; - - var $$asap$$default = function asap(callback, arg) { - $$asap$$queue[$$asap$$len] = callback; - $$asap$$queue[$$asap$$len + 1] = arg; - $$asap$$len += 2; - if ($$asap$$len === 2) { - // If len is 1, that means that we need to schedule an async flush. - // If additional callbacks are queued before the queue is flushed, they - // will be processed by this flush that we are scheduling. - $$asap$$scheduleFlush(); - } - }; + function lib$es6$promise$asap$$setScheduler(scheduleFn) { + lib$es6$promise$asap$$customSchedulerFn = scheduleFn; + } - var $$asap$$browserGlobal = (typeof window !== 'undefined') ? window : {}; - var $$asap$$BrowserMutationObserver = $$asap$$browserGlobal.MutationObserver || $$asap$$browserGlobal.WebKitMutationObserver; + function lib$es6$promise$asap$$setAsap(asapFn) { + lib$es6$promise$asap$$asap = asapFn; + } - // test for web worker but not in IE10 - var $$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' && - typeof importScripts !== 'undefined' && - typeof MessageChannel !== 'undefined'; + var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined; + var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {}; + var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver; + var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; + + // test for web worker but not in IE10 + var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' && + typeof importScripts !== 'undefined' && + typeof MessageChannel !== 'undefined'; + + // node + function lib$es6$promise$asap$$useNextTick() { + var nextTick = process.nextTick; + // node version 0.10.x displays a deprecation warning when nextTick is used recursively + // setImmediate should be used instead instead + var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/); + if (Array.isArray(version) && version[1] === '0' && version[2] === '10') { + nextTick = setImmediate; + } + return function() { + nextTick(lib$es6$promise$asap$$flush); + }; + } - // node - function $$asap$$useNextTick() { - return function() { - process.nextTick($$asap$$flush); - }; - } + // vertx + function lib$es6$promise$asap$$useVertxTimer() { + return function() { + lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush); + }; + } - function $$asap$$useMutationObserver() { - var iterations = 0; - var observer = new $$asap$$BrowserMutationObserver($$asap$$flush); - var node = document.createTextNode(''); - observer.observe(node, { characterData: true }); + function lib$es6$promise$asap$$useMutationObserver() { + var iterations = 0; + var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush); + var node = document.createTextNode(''); + observer.observe(node, { characterData: true }); - return function() { - node.data = (iterations = ++iterations % 2); - }; - } + return function() { + node.data = (iterations = ++iterations % 2); + }; + } - // web worker - function $$asap$$useMessageChannel() { - var channel = new MessageChannel(); - channel.port1.onmessage = $$asap$$flush; - return function () { - channel.port2.postMessage(0); - }; - } + // web worker + function lib$es6$promise$asap$$useMessageChannel() { + var channel = new MessageChannel(); + channel.port1.onmessage = lib$es6$promise$asap$$flush; + return function () { + channel.port2.postMessage(0); + }; + } - function $$asap$$useSetTimeout() { - return function() { - setTimeout($$asap$$flush, 1); - }; - } + function lib$es6$promise$asap$$useSetTimeout() { + return function() { + setTimeout(lib$es6$promise$asap$$flush, 1); + }; + } - var $$asap$$queue = new Array(1000); + var lib$es6$promise$asap$$queue = new Array(1000); + function lib$es6$promise$asap$$flush() { + for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) { + var callback = lib$es6$promise$asap$$queue[i]; + var arg = lib$es6$promise$asap$$queue[i+1]; - function $$asap$$flush() { - for (var i = 0; i < $$asap$$len; i+=2) { - var callback = $$asap$$queue[i]; - var arg = $$asap$$queue[i+1]; + callback(arg); - callback(arg); + lib$es6$promise$asap$$queue[i] = undefined; + lib$es6$promise$asap$$queue[i+1] = undefined; + } - $$asap$$queue[i] = undefined; - $$asap$$queue[i+1] = undefined; - } + lib$es6$promise$asap$$len = 0; + } - $$asap$$len = 0; - } + function lib$es6$promise$asap$$attemptVertex() { + try { + var r = require; + var vertx = r('vertx'); + lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext; + return lib$es6$promise$asap$$useVertxTimer(); + } catch(e) { + return lib$es6$promise$asap$$useSetTimeout(); + } + } - var $$asap$$scheduleFlush; + var lib$es6$promise$asap$$scheduleFlush; + // Decide what async method to use to triggering processing of queued callbacks: + if (lib$es6$promise$asap$$isNode) { + lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick(); + } else if (lib$es6$promise$asap$$BrowserMutationObserver) { + lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver(); + } else if (lib$es6$promise$asap$$isWorker) { + lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel(); + } else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') { + lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertex(); + } else { + lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout(); + } - // Decide what async method to use to triggering processing of queued callbacks: - if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { - $$asap$$scheduleFlush = $$asap$$useNextTick(); - } else if ($$asap$$BrowserMutationObserver) { - $$asap$$scheduleFlush = $$asap$$useMutationObserver(); - } else if ($$asap$$isWorker) { - $$asap$$scheduleFlush = $$asap$$useMessageChannel(); - } else { - $$asap$$scheduleFlush = $$asap$$useSetTimeout(); - } + function lib$es6$promise$$internal$$noop() {} - function $$$internal$$noop() {} - var $$$internal$$PENDING = void 0; - var $$$internal$$FULFILLED = 1; - var $$$internal$$REJECTED = 2; - var $$$internal$$GET_THEN_ERROR = new $$$internal$$ErrorObject(); + var lib$es6$promise$$internal$$PENDING = void 0; + var lib$es6$promise$$internal$$FULFILLED = 1; + var lib$es6$promise$$internal$$REJECTED = 2; - function $$$internal$$selfFullfillment() { - return new TypeError("You cannot resolve a promise with itself"); - } + var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject(); - function $$$internal$$cannotReturnOwn() { - return new TypeError('A promises callback cannot return that same promise.') - } + function lib$es6$promise$$internal$$selfFullfillment() { + return new TypeError("You cannot resolve a promise with itself"); + } - function $$$internal$$getThen(promise) { - try { - return promise.then; - } catch(error) { - $$$internal$$GET_THEN_ERROR.error = error; - return $$$internal$$GET_THEN_ERROR; - } - } + function lib$es6$promise$$internal$$cannotReturnOwn() { + return new TypeError('A promises callback cannot return that same promise.'); + } - function $$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) { - try { - then.call(value, fulfillmentHandler, rejectionHandler); - } catch(e) { - return e; - } - } + function lib$es6$promise$$internal$$getThen(promise) { + try { + return promise.then; + } catch(error) { + lib$es6$promise$$internal$$GET_THEN_ERROR.error = error; + return lib$es6$promise$$internal$$GET_THEN_ERROR; + } + } - function $$$internal$$handleForeignThenable(promise, thenable, then) { - $$asap$$default(function(promise) { - var sealed = false; - var error = $$$internal$$tryThen(then, thenable, function(value) { - if (sealed) { return; } - sealed = true; - if (thenable !== value) { - $$$internal$$resolve(promise, value); - } else { - $$$internal$$fulfill(promise, value); - } - }, function(reason) { - if (sealed) { return; } - sealed = true; + function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) { + try { + then.call(value, fulfillmentHandler, rejectionHandler); + } catch(e) { + return e; + } + } - $$$internal$$reject(promise, reason); - }, 'Settle: ' + (promise._label || ' unknown promise')); + function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) { + lib$es6$promise$asap$$asap(function(promise) { + var sealed = false; + var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) { + if (sealed) { return; } + sealed = true; + if (thenable !== value) { + lib$es6$promise$$internal$$resolve(promise, value); + } else { + lib$es6$promise$$internal$$fulfill(promise, value); + } + }, function(reason) { + if (sealed) { return; } + sealed = true; - if (!sealed && error) { - sealed = true; - $$$internal$$reject(promise, error); - } - }, promise); - } + lib$es6$promise$$internal$$reject(promise, reason); + }, 'Settle: ' + (promise._label || ' unknown promise')); - function $$$internal$$handleOwnThenable(promise, thenable) { - if (thenable._state === $$$internal$$FULFILLED) { - $$$internal$$fulfill(promise, thenable._result); - } else if (promise._state === $$$internal$$REJECTED) { - $$$internal$$reject(promise, thenable._result); - } else { - $$$internal$$subscribe(thenable, undefined, function(value) { - $$$internal$$resolve(promise, value); - }, function(reason) { - $$$internal$$reject(promise, reason); - }); - } - } + if (!sealed && error) { + sealed = true; + lib$es6$promise$$internal$$reject(promise, error); + } + }, promise); + } - function $$$internal$$handleMaybeThenable(promise, maybeThenable) { - if (maybeThenable.constructor === promise.constructor) { - $$$internal$$handleOwnThenable(promise, maybeThenable); - } else { - var then = $$$internal$$getThen(maybeThenable); - - if (then === $$$internal$$GET_THEN_ERROR) { - $$$internal$$reject(promise, $$$internal$$GET_THEN_ERROR.error); - } else if (then === undefined) { - $$$internal$$fulfill(promise, maybeThenable); - } else if ($$utils$$isFunction(then)) { - $$$internal$$handleForeignThenable(promise, maybeThenable, then); - } else { - $$$internal$$fulfill(promise, maybeThenable); - } - } - } + function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) { + if (thenable._state === lib$es6$promise$$internal$$FULFILLED) { + lib$es6$promise$$internal$$fulfill(promise, thenable._result); + } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) { + lib$es6$promise$$internal$$reject(promise, thenable._result); + } else { + lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) { + lib$es6$promise$$internal$$resolve(promise, value); + }, function(reason) { + lib$es6$promise$$internal$$reject(promise, reason); + }); + } + } - function $$$internal$$resolve(promise, value) { - if (promise === value) { - $$$internal$$reject(promise, $$$internal$$selfFullfillment()); - } else if ($$utils$$objectOrFunction(value)) { - $$$internal$$handleMaybeThenable(promise, value); - } else { - $$$internal$$fulfill(promise, value); - } - } + function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) { + if (maybeThenable.constructor === promise.constructor) { + lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable); + } else { + var then = lib$es6$promise$$internal$$getThen(maybeThenable); + + if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) { + lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error); + } else if (then === undefined) { + lib$es6$promise$$internal$$fulfill(promise, maybeThenable); + } else if (lib$es6$promise$utils$$isFunction(then)) { + lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then); + } else { + lib$es6$promise$$internal$$fulfill(promise, maybeThenable); + } + } + } - function $$$internal$$publishRejection(promise) { - if (promise._onerror) { - promise._onerror(promise._result); - } + function lib$es6$promise$$internal$$resolve(promise, value) { + if (promise === value) { + lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFullfillment()); + } else if (lib$es6$promise$utils$$objectOrFunction(value)) { + lib$es6$promise$$internal$$handleMaybeThenable(promise, value); + } else { + lib$es6$promise$$internal$$fulfill(promise, value); + } + } - $$$internal$$publish(promise); - } + function lib$es6$promise$$internal$$publishRejection(promise) { + if (promise._onerror) { + promise._onerror(promise._result); + } - function $$$internal$$fulfill(promise, value) { - if (promise._state !== $$$internal$$PENDING) { return; } + lib$es6$promise$$internal$$publish(promise); + } - promise._result = value; - promise._state = $$$internal$$FULFILLED; + function lib$es6$promise$$internal$$fulfill(promise, value) { + if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; } - if (promise._subscribers.length === 0) { - } else { - $$asap$$default($$$internal$$publish, promise); - } - } + promise._result = value; + promise._state = lib$es6$promise$$internal$$FULFILLED; - function $$$internal$$reject(promise, reason) { - if (promise._state !== $$$internal$$PENDING) { return; } - promise._state = $$$internal$$REJECTED; - promise._result = reason; + if (promise._subscribers.length !== 0) { + lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise); + } + } - $$asap$$default($$$internal$$publishRejection, promise); - } + function lib$es6$promise$$internal$$reject(promise, reason) { + if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; } + promise._state = lib$es6$promise$$internal$$REJECTED; + promise._result = reason; - function $$$internal$$subscribe(parent, child, onFulfillment, onRejection) { - var subscribers = parent._subscribers; - var length = subscribers.length; + lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise); + } - parent._onerror = null; + function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) { + var subscribers = parent._subscribers; + var length = subscribers.length; - subscribers[length] = child; - subscribers[length + $$$internal$$FULFILLED] = onFulfillment; - subscribers[length + $$$internal$$REJECTED] = onRejection; + parent._onerror = null; - if (length === 0 && parent._state) { - $$asap$$default($$$internal$$publish, parent); - } - } + subscribers[length] = child; + subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment; + subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection; - function $$$internal$$publish(promise) { - var subscribers = promise._subscribers; - var settled = promise._state; + if (length === 0 && parent._state) { + lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent); + } + } - if (subscribers.length === 0) { return; } + function lib$es6$promise$$internal$$publish(promise) { + var subscribers = promise._subscribers; + var settled = promise._state; - var child, callback, detail = promise._result; + if (subscribers.length === 0) { return; } - for (var i = 0; i < subscribers.length; i += 3) { - child = subscribers[i]; - callback = subscribers[i + settled]; + var child, callback, detail = promise._result; - if (child) { - $$$internal$$invokeCallback(settled, child, callback, detail); - } else { - callback(detail); - } - } + for (var i = 0; i < subscribers.length; i += 3) { + child = subscribers[i]; + callback = subscribers[i + settled]; - promise._subscribers.length = 0; - } + if (child) { + lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail); + } else { + callback(detail); + } + } - function $$$internal$$ErrorObject() { - this.error = null; - } + promise._subscribers.length = 0; + } - var $$$internal$$TRY_CATCH_ERROR = new $$$internal$$ErrorObject(); + function lib$es6$promise$$internal$$ErrorObject() { + this.error = null; + } - function $$$internal$$tryCatch(callback, detail) { - try { - return callback(detail); - } catch(e) { - $$$internal$$TRY_CATCH_ERROR.error = e; - return $$$internal$$TRY_CATCH_ERROR; - } - } + var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject(); - function $$$internal$$invokeCallback(settled, promise, callback, detail) { - var hasCallback = $$utils$$isFunction(callback), - value, error, succeeded, failed; + function lib$es6$promise$$internal$$tryCatch(callback, detail) { + try { + return callback(detail); + } catch(e) { + lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e; + return lib$es6$promise$$internal$$TRY_CATCH_ERROR; + } + } - if (hasCallback) { - value = $$$internal$$tryCatch(callback, detail); + function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) { + var hasCallback = lib$es6$promise$utils$$isFunction(callback), + value, error, succeeded, failed; - if (value === $$$internal$$TRY_CATCH_ERROR) { - failed = true; - error = value.error; - value = null; - } else { - succeeded = true; - } + if (hasCallback) { + value = lib$es6$promise$$internal$$tryCatch(callback, detail); - if (promise === value) { - $$$internal$$reject(promise, $$$internal$$cannotReturnOwn()); - return; - } + if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) { + failed = true; + error = value.error; + value = null; + } else { + succeeded = true; + } - } else { - value = detail; - succeeded = true; - } + if (promise === value) { + lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn()); + return; + } - if (promise._state !== $$$internal$$PENDING) { - // noop - } else if (hasCallback && succeeded) { - $$$internal$$resolve(promise, value); - } else if (failed) { - $$$internal$$reject(promise, error); - } else if (settled === $$$internal$$FULFILLED) { - $$$internal$$fulfill(promise, value); - } else if (settled === $$$internal$$REJECTED) { - $$$internal$$reject(promise, value); - } - } + } else { + value = detail; + succeeded = true; + } - function $$$internal$$initializePromise(promise, resolver) { - try { - resolver(function resolvePromise(value){ - $$$internal$$resolve(promise, value); - }, function rejectPromise(reason) { - $$$internal$$reject(promise, reason); - }); - } catch(e) { - $$$internal$$reject(promise, e); - } - } + if (promise._state !== lib$es6$promise$$internal$$PENDING) { + // noop + } else if (hasCallback && succeeded) { + lib$es6$promise$$internal$$resolve(promise, value); + } else if (failed) { + lib$es6$promise$$internal$$reject(promise, error); + } else if (settled === lib$es6$promise$$internal$$FULFILLED) { + lib$es6$promise$$internal$$fulfill(promise, value); + } else if (settled === lib$es6$promise$$internal$$REJECTED) { + lib$es6$promise$$internal$$reject(promise, value); + } + } - function $$$enumerator$$makeSettledResult(state, position, value) { - if (state === $$$internal$$FULFILLED) { - return { - state: 'fulfilled', - value: value - }; - } else { - return { - state: 'rejected', - reason: value - }; - } - } + function lib$es6$promise$$internal$$initializePromise(promise, resolver) { + try { + resolver(function resolvePromise(value){ + lib$es6$promise$$internal$$resolve(promise, value); + }, function rejectPromise(reason) { + lib$es6$promise$$internal$$reject(promise, reason); + }); + } catch(e) { + lib$es6$promise$$internal$$reject(promise, e); + } + } - function $$$enumerator$$Enumerator(Constructor, input, abortOnReject, label) { - this._instanceConstructor = Constructor; - this.promise = new Constructor($$$internal$$noop, label); - this._abortOnReject = abortOnReject; - - if (this._validateInput(input)) { - this._input = input; - this.length = input.length; - this._remaining = input.length; - - this._init(); - - if (this.length === 0) { - $$$internal$$fulfill(this.promise, this._result); - } else { - this.length = this.length || 0; - this._enumerate(); - if (this._remaining === 0) { - $$$internal$$fulfill(this.promise, this._result); - } - } - } else { - $$$internal$$reject(this.promise, this._validationError()); - } - } + function lib$es6$promise$enumerator$$Enumerator(Constructor, input) { + var enumerator = this; - $$$enumerator$$Enumerator.prototype._validateInput = function(input) { - return $$utils$$isArray(input); - }; + enumerator._instanceConstructor = Constructor; + enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop); - $$$enumerator$$Enumerator.prototype._validationError = function() { - return new Error('Array Methods must be provided an Array'); - }; + if (enumerator._validateInput(input)) { + enumerator._input = input; + enumerator.length = input.length; + enumerator._remaining = input.length; - $$$enumerator$$Enumerator.prototype._init = function() { - this._result = new Array(this.length); - }; + enumerator._init(); - var $$$enumerator$$default = $$$enumerator$$Enumerator; + if (enumerator.length === 0) { + lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result); + } else { + enumerator.length = enumerator.length || 0; + enumerator._enumerate(); + if (enumerator._remaining === 0) { + lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result); + } + } + } else { + lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError()); + } + } - $$$enumerator$$Enumerator.prototype._enumerate = function() { - var length = this.length; - var promise = this.promise; - var input = this._input; + lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) { + return lib$es6$promise$utils$$isArray(input); + }; - for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) { - this._eachEntry(input[i], i); - } - }; + lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() { + return new Error('Array Methods must be provided an Array'); + }; - $$$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) { - var c = this._instanceConstructor; - if ($$utils$$isMaybeThenable(entry)) { - if (entry.constructor === c && entry._state !== $$$internal$$PENDING) { - entry._onerror = null; - this._settledAt(entry._state, i, entry._result); - } else { - this._willSettleAt(c.resolve(entry), i); - } - } else { - this._remaining--; - this._result[i] = this._makeResult($$$internal$$FULFILLED, i, entry); - } - }; + lib$es6$promise$enumerator$$Enumerator.prototype._init = function() { + this._result = new Array(this.length); + }; - $$$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) { - var promise = this.promise; + var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator; - if (promise._state === $$$internal$$PENDING) { - this._remaining--; + lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() { + var enumerator = this; - if (this._abortOnReject && state === $$$internal$$REJECTED) { - $$$internal$$reject(promise, value); - } else { - this._result[i] = this._makeResult(state, i, value); - } - } + var length = enumerator.length; + var promise = enumerator.promise; + var input = enumerator._input; - if (this._remaining === 0) { - $$$internal$$fulfill(promise, this._result); - } - }; + for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) { + enumerator._eachEntry(input[i], i); + } + }; - $$$enumerator$$Enumerator.prototype._makeResult = function(state, i, value) { - return value; - }; + lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) { + var enumerator = this; + var c = enumerator._instanceConstructor; - $$$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) { - var enumerator = this; + if (lib$es6$promise$utils$$isMaybeThenable(entry)) { + if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) { + entry._onerror = null; + enumerator._settledAt(entry._state, i, entry._result); + } else { + enumerator._willSettleAt(c.resolve(entry), i); + } + } else { + enumerator._remaining--; + enumerator._result[i] = entry; + } + }; - $$$internal$$subscribe(promise, undefined, function(value) { - enumerator._settledAt($$$internal$$FULFILLED, i, value); - }, function(reason) { - enumerator._settledAt($$$internal$$REJECTED, i, reason); - }); - }; + lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) { + var enumerator = this; + var promise = enumerator.promise; - var $$promise$all$$default = function all(entries, label) { - return new $$$enumerator$$default(this, entries, true /* abort on reject */, label).promise; - }; + if (promise._state === lib$es6$promise$$internal$$PENDING) { + enumerator._remaining--; - var $$promise$race$$default = function race(entries, label) { - /*jshint validthis:true */ - var Constructor = this; + if (state === lib$es6$promise$$internal$$REJECTED) { + lib$es6$promise$$internal$$reject(promise, value); + } else { + enumerator._result[i] = value; + } + } - var promise = new Constructor($$$internal$$noop, label); + if (enumerator._remaining === 0) { + lib$es6$promise$$internal$$fulfill(promise, enumerator._result); + } + }; - if (!$$utils$$isArray(entries)) { - $$$internal$$reject(promise, new TypeError('You must pass an array to race.')); - return promise; - } + lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) { + var enumerator = this; - var length = entries.length; + lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) { + enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value); + }, function(reason) { + enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason); + }); + }; + function lib$es6$promise$promise$all$$all(entries) { + return new lib$es6$promise$enumerator$$default(this, entries).promise; + } + var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all; + function lib$es6$promise$promise$race$$race(entries) { + /*jshint validthis:true */ + var Constructor = this; - function onFulfillment(value) { - $$$internal$$resolve(promise, value); - } + var promise = new Constructor(lib$es6$promise$$internal$$noop); - function onRejection(reason) { - $$$internal$$reject(promise, reason); - } + if (!lib$es6$promise$utils$$isArray(entries)) { + lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.')); + return promise; + } - for (var i = 0; promise._state === $$$internal$$PENDING && i < length; i++) { - $$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection); - } + var length = entries.length; - return promise; - }; + function onFulfillment(value) { + lib$es6$promise$$internal$$resolve(promise, value); + } - var $$promise$resolve$$default = function resolve(object, label) { - /*jshint validthis:true */ - var Constructor = this; + function onRejection(reason) { + lib$es6$promise$$internal$$reject(promise, reason); + } - if (object && typeof object === 'object' && object.constructor === Constructor) { - return object; - } + for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) { + lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection); + } - var promise = new Constructor($$$internal$$noop, label); - $$$internal$$resolve(promise, object); - return promise; - }; + return promise; + } + var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race; + function lib$es6$promise$promise$resolve$$resolve(object) { + /*jshint validthis:true */ + var Constructor = this; - var $$promise$reject$$default = function reject(reason, label) { - /*jshint validthis:true */ - var Constructor = this; - var promise = new Constructor($$$internal$$noop, label); - $$$internal$$reject(promise, reason); - return promise; - }; + if (object && typeof object === 'object' && object.constructor === Constructor) { + return object; + } - var $$es6$promise$promise$$counter = 0; + var promise = new Constructor(lib$es6$promise$$internal$$noop); + lib$es6$promise$$internal$$resolve(promise, object); + return promise; + } + var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve; + function lib$es6$promise$promise$reject$$reject(reason) { + /*jshint validthis:true */ + var Constructor = this; + var promise = new Constructor(lib$es6$promise$$internal$$noop); + lib$es6$promise$$internal$$reject(promise, reason); + return promise; + } + var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject; - function $$es6$promise$promise$$needsResolver() { - throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); - } + var lib$es6$promise$promise$$counter = 0; - function $$es6$promise$promise$$needsNew() { - throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); - } + function lib$es6$promise$promise$$needsResolver() { + throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); + } - var $$es6$promise$promise$$default = $$es6$promise$promise$$Promise; + function lib$es6$promise$promise$$needsNew() { + throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); + } - /** - Promise objects represent the eventual result of an asynchronous operation. The - primary way of interacting with a promise is through its `then` method, which - registers callbacks to receive either a promise’s eventual value or the reason - why the promise cannot be fulfilled. + var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise; + /** + Promise objects represent the eventual result of an asynchronous operation. The + primary way of interacting with a promise is through its `then` method, which + registers callbacks to receive either a promise's eventual value or the reason + why the promise cannot be fulfilled. - Terminology - ----------- + Terminology + ----------- - - `promise` is an object or function with a `then` method whose behavior conforms to this specification. - - `thenable` is an object or function that defines a `then` method. - - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). - - `exception` is a value that is thrown using the throw statement. - - `reason` is a value that indicates why a promise was rejected. - - `settled` the final resting state of a promise, fulfilled or rejected. + - `promise` is an object or function with a `then` method whose behavior conforms to this specification. + - `thenable` is an object or function that defines a `then` method. + - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). + - `exception` is a value that is thrown using the throw statement. + - `reason` is a value that indicates why a promise was rejected. + - `settled` the final resting state of a promise, fulfilled or rejected. - A promise can be in one of three states: pending, fulfilled, or rejected. + A promise can be in one of three states: pending, fulfilled, or rejected. - Promises that are fulfilled have a fulfillment value and are in the fulfilled - state. Promises that are rejected have a rejection reason and are in the - rejected state. A fulfillment value is never a thenable. + Promises that are fulfilled have a fulfillment value and are in the fulfilled + state. Promises that are rejected have a rejection reason and are in the + rejected state. A fulfillment value is never a thenable. - Promises can also be said to *resolve* a value. If this value is also a - promise, then the original promise's settled state will match the value's - settled state. So a promise that *resolves* a promise that rejects will - itself reject, and a promise that *resolves* a promise that fulfills will - itself fulfill. + Promises can also be said to *resolve* a value. If this value is also a + promise, then the original promise's settled state will match the value's + settled state. So a promise that *resolves* a promise that rejects will + itself reject, and a promise that *resolves* a promise that fulfills will + itself fulfill. - Basic Usage: - ------------ + Basic Usage: + ------------ - ```js - var promise = new Promise(function(resolve, reject) { + ```js + var promise = new Promise(function(resolve, reject) { // on success resolve(value); @@ -584,21 +598,21 @@ reject(reason); }); - promise.then(function(value) { + promise.then(function(value) { // on fulfillment }, function(reason) { // on rejection }); - ``` + ``` - Advanced Usage: - --------------- + Advanced Usage: + --------------- - Promises shine when abstracting away asynchronous interactions such as - `XMLHttpRequest`s. + Promises shine when abstracting away asynchronous interactions such as + `XMLHttpRequest`s. - ```js - function getJSON(url) { + ```js + function getJSON(url) { return new Promise(function(resolve, reject){ var xhr = new XMLHttpRequest(); @@ -620,81 +634,84 @@ }); } - getJSON('/posts.json').then(function(json) { + getJSON('/posts.json').then(function(json) { // on fulfillment }, function(reason) { // on rejection }); - ``` + ``` - Unlike callbacks, promises are great composable primitives. + Unlike callbacks, promises are great composable primitives. - ```js - Promise.all([ - getJSON('/posts'), - getJSON('/comments') - ]).then(function(values){ + ```js + Promise.all([ + getJSON('/posts'), + getJSON('/comments') + ]).then(function(values){ values[0] // => postsJSON values[1] // => commentsJSON return values; }); - ``` - - @class Promise - @param {function} resolver - Useful for tooling. - @constructor - */ - function $$es6$promise$promise$$Promise(resolver) { - this._id = $$es6$promise$promise$$counter++; - this._state = undefined; - this._result = undefined; - this._subscribers = []; - - if ($$$internal$$noop !== resolver) { - if (!$$utils$$isFunction(resolver)) { - $$es6$promise$promise$$needsResolver(); - } + ``` + + @class Promise + @param {function} resolver + Useful for tooling. + @constructor + */ + function lib$es6$promise$promise$$Promise(resolver) { + this._id = lib$es6$promise$promise$$counter++; + this._state = undefined; + this._result = undefined; + this._subscribers = []; + + if (lib$es6$promise$$internal$$noop !== resolver) { + if (!lib$es6$promise$utils$$isFunction(resolver)) { + lib$es6$promise$promise$$needsResolver(); + } - if (!(this instanceof $$es6$promise$promise$$Promise)) { - $$es6$promise$promise$$needsNew(); - } + if (!(this instanceof lib$es6$promise$promise$$Promise)) { + lib$es6$promise$promise$$needsNew(); + } - $$$internal$$initializePromise(this, resolver); - } - } + lib$es6$promise$$internal$$initializePromise(this, resolver); + } + } - $$es6$promise$promise$$Promise.all = $$promise$all$$default; - $$es6$promise$promise$$Promise.race = $$promise$race$$default; - $$es6$promise$promise$$Promise.resolve = $$promise$resolve$$default; - $$es6$promise$promise$$Promise.reject = $$promise$reject$$default; + lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default; + lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default; + lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default; + lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default; + lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler; + lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap; + lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap; - $$es6$promise$promise$$Promise.prototype = { - constructor: $$es6$promise$promise$$Promise, + lib$es6$promise$promise$$Promise.prototype = { + constructor: lib$es6$promise$promise$$Promise, - /** - The primary way of interacting with a promise is through its `then` method, - which registers callbacks to receive either a promise's eventual value or the - reason why the promise cannot be fulfilled. + /** + The primary way of interacting with a promise is through its `then` method, + which registers callbacks to receive either a promise's eventual value or the + reason why the promise cannot be fulfilled. - ```js - findUser().then(function(user){ + ```js + findUser().then(function(user){ // user is available }, function(reason){ // user is unavailable, and you are given the reason why }); - ``` + ``` - Chaining - -------- + Chaining + -------- - The return value of `then` is itself a promise. This second, 'downstream' - promise is resolved with the return value of the first promise's fulfillment - or rejection handler, or rejected if the handler throws an exception. + The return value of `then` is itself a promise. This second, 'downstream' + promise is resolved with the return value of the first promise's fulfillment + or rejection handler, or rejected if the handler throws an exception. - ```js - findUser().then(function (user) { + ```js + findUser().then(function (user) { return user.name; }, function (reason) { return 'default name'; @@ -703,7 +720,7 @@ // will be `'default name'` }); - findUser().then(function (user) { + findUser().then(function (user) { throw new Error('Found user, but still unhappy'); }, function (reason) { throw new Error('`findUser` rejected and we're unhappy'); @@ -713,11 +730,11 @@ // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. }); - ``` - If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. + ``` + If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. - ```js - findUser().then(function (user) { + ```js + findUser().then(function (user) { throw new PedagogicalException('Upstream error'); }).then(function (value) { // never reached @@ -726,104 +743,104 @@ }, function (reason) { // The `PedgagocialException` is propagated all the way down to here }); - ``` + ``` - Assimilation - ------------ + Assimilation + ------------ - Sometimes the value you want to propagate to a downstream promise can only be - retrieved asynchronously. This can be achieved by returning a promise in the - fulfillment or rejection handler. The downstream promise will then be pending - until the returned promise is settled. This is called *assimilation*. + Sometimes the value you want to propagate to a downstream promise can only be + retrieved asynchronously. This can be achieved by returning a promise in the + fulfillment or rejection handler. The downstream promise will then be pending + until the returned promise is settled. This is called *assimilation*. - ```js - findUser().then(function (user) { + ```js + findUser().then(function (user) { return findCommentsByAuthor(user); }).then(function (comments) { // The user's comments are now available }); - ``` + ``` - If the assimliated promise rejects, then the downstream promise will also reject. + If the assimliated promise rejects, then the downstream promise will also reject. - ```js - findUser().then(function (user) { + ```js + findUser().then(function (user) { return findCommentsByAuthor(user); }).then(function (comments) { // If `findCommentsByAuthor` fulfills, we'll have the value here }, function (reason) { // If `findCommentsByAuthor` rejects, we'll have the reason here }); - ``` + ``` - Simple Example - -------------- + Simple Example + -------------- - Synchronous Example + Synchronous Example - ```javascript - var result; + ```javascript + var result; - try { + try { result = findResult(); // success } catch(reason) { // failure } - ``` + ``` - Errback Example + Errback Example - ```js - findResult(function(result, err){ + ```js + findResult(function(result, err){ if (err) { // failure } else { // success } }); - ``` + ``` - Promise Example; + Promise Example; - ```javascript - findResult().then(function(result){ + ```javascript + findResult().then(function(result){ // success }, function(reason){ // failure }); - ``` + ``` - Advanced Example - -------------- + Advanced Example + -------------- - Synchronous Example + Synchronous Example - ```javascript - var author, books; + ```javascript + var author, books; - try { + try { author = findAuthor(); books = findBooksByAuthor(author); // success } catch(reason) { // failure } - ``` + ``` - Errback Example + Errback Example - ```js + ```js - function foundBooks(books) { + function foundBooks(books) { } - function failure(reason) { + function failure(reason) { } - findAuthor(function(author, err){ + findAuthor(function(author, err){ if (err) { failure(err); // failure @@ -846,3700 +863,3842 @@ // success } }); - ``` + ``` - Promise Example; + Promise Example; - ```javascript - findAuthor(). - then(findBooksByAuthor). - then(function(books){ + ```javascript + findAuthor(). + then(findBooksByAuthor). + then(function(books){ // found books }).catch(function(reason){ // something went wrong }); - ``` - - @method then - @param {Function} onFulfilled - @param {Function} onRejected - Useful for tooling. - @return {Promise} - */ - then: function(onFulfillment, onRejection) { - var parent = this; - var state = parent._state; - - if (state === $$$internal$$FULFILLED && !onFulfillment || state === $$$internal$$REJECTED && !onRejection) { - return this; - } + ``` + + @method then + @param {Function} onFulfilled + @param {Function} onRejected + Useful for tooling. + @return {Promise} + */ + then: function(onFulfillment, onRejection) { + var parent = this; + var state = parent._state; + + if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) { + return this; + } - var child = new this.constructor($$$internal$$noop); - var result = parent._result; + var child = new this.constructor(lib$es6$promise$$internal$$noop); + var result = parent._result; - if (state) { - var callback = arguments[state - 1]; - $$asap$$default(function(){ - $$$internal$$invokeCallback(state, child, callback, result); - }); - } else { - $$$internal$$subscribe(parent, child, onFulfillment, onRejection); - } + if (state) { + var callback = arguments[state - 1]; + lib$es6$promise$asap$$asap(function(){ + lib$es6$promise$$internal$$invokeCallback(state, child, callback, result); + }); + } else { + lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection); + } - return child; - }, + return child; + }, - /** - `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same - as the catch block of a try/catch statement. + /** + `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same + as the catch block of a try/catch statement. - ```js - function findAuthor(){ + ```js + function findAuthor(){ throw new Error('couldn't find that author'); } - // synchronous - try { + // synchronous + try { findAuthor(); } catch(reason) { // something went wrong } - // async with promises - findAuthor().catch(function(reason){ + // async with promises + findAuthor().catch(function(reason){ // something went wrong }); - ``` - - @method catch - @param {Function} onRejection - Useful for tooling. - @return {Promise} - */ - 'catch': function(onRejection) { - return this.then(null, onRejection); - } - }; + ``` + + @method catch + @param {Function} onRejection + Useful for tooling. + @return {Promise} + */ + 'catch': function(onRejection) { + return this.then(null, onRejection); + } + }; + function lib$es6$promise$polyfill$$polyfill() { + var local; - var $$es6$promise$polyfill$$default = function polyfill() { - var local; + if (typeof global !== 'undefined') { + local = global; + } else if (typeof self !== 'undefined') { + local = self; + } else { + try { + local = Function('return this')(); + } catch (e) { + throw new Error('polyfill failed because global object is unavailable in this environment'); + } + } - if (typeof global !== 'undefined') { - local = global; - } else if (typeof window !== 'undefined' && window.document) { - local = window; - } else { - local = self; - } + var P = local.Promise; - var es6PromiseSupport = - "Promise" in local && - // Some of these methods are missing from - // Firefox/Chrome experimental implementations - "resolve" in local.Promise && - "reject" in local.Promise && - "all" in local.Promise && - "race" in local.Promise && - // Older version of the spec had a resolver object - // as the arg rather than a function - (function() { - var resolve; - new local.Promise(function(r) { resolve = r; }); - return $$utils$$isFunction(resolve); - }()); - - if (!es6PromiseSupport) { - local.Promise = $$es6$promise$promise$$default; - } - }; + if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) { + return; + } - var es6$promise$umd$$ES6Promise = { - 'Promise': $$es6$promise$promise$$default, - 'polyfill': $$es6$promise$polyfill$$default - }; + local.Promise = lib$es6$promise$promise$$default; + } + var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill; - /* global define:true module:true window: true */ - if (typeof define === 'function' && define['amd']) { - define(function() { return es6$promise$umd$$ES6Promise; }); - } else if (typeof module !== 'undefined' && module['exports']) { - module['exports'] = es6$promise$umd$$ES6Promise; - } else if (typeof this !== 'undefined') { - this['ES6Promise'] = es6$promise$umd$$ES6Promise; - } - }).call(this); - }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + var lib$es6$promise$umd$$ES6Promise = { + 'Promise': lib$es6$promise$promise$$default, + 'polyfill': lib$es6$promise$polyfill$$default + }; + + /* global define:true module:true window: true */ + if (typeof define === 'function' && define['amd']) { + define(function() { return lib$es6$promise$umd$$ES6Promise; }); + } else if (typeof module !== 'undefined' && module['exports']) { + module['exports'] = lib$es6$promise$umd$$ES6Promise; + } else if (typeof this !== 'undefined') { + this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise; + } + + lib$es6$promise$polyfill$$default(); +}).call(this); + + +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"_process":2}],2:[function(require,module,exports){ // shim for using process in browser - var process = module.exports = {}; - var queue = []; - var draining = false; +var process = module.exports = {}; +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} - function drainQueue() { - if (draining) { - return; - } - draining = true; - var currentQueue; - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - var i = -1; - while (++i < len) { - currentQueue[i](); - } - len = queue.length; +function drainQueue() { + if (draining) { + return; + } + var timeout = setTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + currentQueue[queueIndex].run(); } - draining = false; + queueIndex = -1; + len = queue.length; } - process.nextTick = function (fun) { - queue.push(fun); - if (!draining) { - setTimeout(drainQueue, 0); + currentQueue = null; + draining = false; + clearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; } - }; - - process.title = 'browser'; - process.browser = true; - process.env = {}; - process.argv = []; - process.version = ''; // empty string to avoid regexp issues - - function noop() {} - - process.on = noop; - process.addListener = noop; - process.once = noop; - process.off = noop; - process.removeListener = noop; - process.removeAllListeners = noop; - process.emit = noop; - - process.binding = function (name) { - throw new Error('process.binding is not supported'); - }; + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + setTimeout(drainQueue, 0); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; // TODO(shtylman) - process.cwd = function () { return '/' }; - process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); - }; - process.umask = function() { return 0; }; +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; },{}],3:[function(require,module,exports){ - (function (global){ - /*! http://mths.be/punycode v1.2.4 by @mathias */ - ;(function(root) { - - /** Detect free variables */ - var freeExports = typeof exports == 'object' && exports; - var freeModule = typeof module == 'object' && module && - module.exports == freeExports && module; - var freeGlobal = typeof global == 'object' && global; - if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { - root = freeGlobal; - } +(function (global){ +/*! https://mths.be/punycode v1.3.2 by @mathias */ +;(function(root) { + + /** Detect free variables */ + var freeExports = typeof exports == 'object' && exports && + !exports.nodeType && exports; + var freeModule = typeof module == 'object' && module && + !module.nodeType && module; + var freeGlobal = typeof global == 'object' && global; + if ( + freeGlobal.global === freeGlobal || + freeGlobal.window === freeGlobal || + freeGlobal.self === freeGlobal + ) { + root = freeGlobal; + } + + /** + * The `punycode` object. + * @name punycode + * @type Object + */ + var punycode, + + /** Highest positive signed 32-bit float value */ + maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 + + /** Bootstring parameters */ + base = 36, + tMin = 1, + tMax = 26, + skew = 38, + damp = 700, + initialBias = 72, + initialN = 128, // 0x80 + delimiter = '-', // '\x2D' + + /** Regular expressions */ + regexPunycode = /^xn--/, + regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars + regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators + + /** Error messages */ + errors = { + 'overflow': 'Overflow: input needs wider integers to process', + 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', + 'invalid-input': 'Invalid input' + }, + + /** Convenience shortcuts */ + baseMinusTMin = base - tMin, + floor = Math.floor, + stringFromCharCode = String.fromCharCode, + + /** Temporary variable */ + key; + + /*--------------------------------------------------------------------------*/ + + /** + * A generic error utility function. + * @private + * @param {String} type The error type. + * @returns {Error} Throws a `RangeError` with the applicable error message. + */ + function error(type) { + throw RangeError(errors[type]); + } + + /** + * A generic `Array#map` utility function. + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function that gets called for every array + * item. + * @returns {Array} A new array of values returned by the callback function. + */ + function map(array, fn) { + var length = array.length; + var result = []; + while (length--) { + result[length] = fn(array[length]); + } + return result; + } + + /** + * A simple `Array#map`-like wrapper to work with domain name strings or email + * addresses. + * @private + * @param {String} domain The domain name or email address. + * @param {Function} callback The function that gets called for every + * character. + * @returns {Array} A new string of characters returned by the callback + * function. + */ + function mapDomain(string, fn) { + var parts = string.split('@'); + var result = ''; + if (parts.length > 1) { + // In email addresses, only the domain name should be punycoded. Leave + // the local part (i.e. everything up to `@`) intact. + result = parts[0] + '@'; + string = parts[1]; + } + // Avoid `split(regex)` for IE8 compatibility. See #17. + string = string.replace(regexSeparators, '\x2E'); + var labels = string.split('.'); + var encoded = map(labels, fn).join('.'); + return result + encoded; + } + + /** + * Creates an array containing the numeric code points of each Unicode + * character in the string. While JavaScript uses UCS-2 internally, + * this function will convert a pair of surrogate halves (each of which + * UCS-2 exposes as separate characters) into a single code point, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. + */ + function ucs2decode(string) { + var output = [], + counter = 0, + length = string.length, + value, + extra; + while (counter < length) { + value = string.charCodeAt(counter++); + if (value >= 0xD800 && value <= 0xDBFF && counter < length) { + // high surrogate, and there is a next character + extra = string.charCodeAt(counter++); + if ((extra & 0xFC00) == 0xDC00) { // low surrogate + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + // unmatched surrogate; only append this code unit, in case the next + // code unit is the high surrogate of a surrogate pair + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; + } + + /** + * Creates a string based on an array of numeric code points. + * @see `punycode.ucs2.decode` + * @memberOf punycode.ucs2 + * @name encode + * @param {Array} codePoints The array of numeric code points. + * @returns {String} The new Unicode string (UCS-2). + */ + function ucs2encode(array) { + return map(array, function(value) { + var output = ''; + if (value > 0xFFFF) { + value -= 0x10000; + output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); + value = 0xDC00 | value & 0x3FF; + } + output += stringFromCharCode(value); + return output; + }).join(''); + } + + /** + * Converts a basic code point into a digit/integer. + * @see `digitToBasic()` + * @private + * @param {Number} codePoint The basic numeric code point value. + * @returns {Number} The numeric value of a basic code point (for use in + * representing integers) in the range `0` to `base - 1`, or `base` if + * the code point does not represent a value. + */ + function basicToDigit(codePoint) { + if (codePoint - 48 < 10) { + return codePoint - 22; + } + if (codePoint - 65 < 26) { + return codePoint - 65; + } + if (codePoint - 97 < 26) { + return codePoint - 97; + } + return base; + } + + /** + * Converts a digit/integer into a basic code point. + * @see `basicToDigit()` + * @private + * @param {Number} digit The numeric value of a basic code point. + * @returns {Number} The basic code point whose value (when used for + * representing integers) is `digit`, which needs to be in the range + * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is + * used; else, the lowercase form is used. The behavior is undefined + * if `flag` is non-zero and `digit` has no uppercase form. + */ + function digitToBasic(digit, flag) { + // 0..25 map to ASCII a..z or A..Z + // 26..35 map to ASCII 0..9 + return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); + } + + /** + * Bias adaptation function as per section 3.4 of RFC 3492. + * http://tools.ietf.org/html/rfc3492#section-3.4 + * @private + */ + function adapt(delta, numPoints, firstTime) { + var k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); + } + + /** + * Converts a Punycode string of ASCII-only symbols to a string of Unicode + * symbols. + * @memberOf punycode + * @param {String} input The Punycode string of ASCII-only symbols. + * @returns {String} The resulting string of Unicode symbols. + */ + function decode(input) { + // Don't use UCS-2 + var output = [], + inputLength = input.length, + out, + i = 0, + n = initialN, + bias = initialBias, + basic, + j, + index, + oldi, + w, + k, + digit, + t, + /** Cached calculation results */ + baseMinusT; + + // Handle the basic code points: let `basic` be the number of input code + // points before the last delimiter, or `0` if there is none, then copy + // the first basic code points to the output. + + basic = input.lastIndexOf(delimiter); + if (basic < 0) { + basic = 0; + } + + for (j = 0; j < basic; ++j) { + // if it's not a basic code point + if (input.charCodeAt(j) >= 0x80) { + error('not-basic'); + } + output.push(input.charCodeAt(j)); + } + + // Main decoding loop: start just after the last delimiter if any basic code + // points were copied; start at the beginning otherwise. + + for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { + + // `index` is the index of the next character to be consumed. + // Decode a generalized variable-length integer into `delta`, + // which gets added to `i`. The overflow checking is easier + // if we increase `i` as we go, then subtract off its starting + // value at the end to obtain `delta`. + for (oldi = i, w = 1, k = base; /* no condition */; k += base) { + + if (index >= inputLength) { + error('invalid-input'); + } + + digit = basicToDigit(input.charCodeAt(index++)); + + if (digit >= base || digit > floor((maxInt - i) / w)) { + error('overflow'); + } + + i += digit * w; + t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + + if (digit < t) { + break; + } + + baseMinusT = base - t; + if (w > floor(maxInt / baseMinusT)) { + error('overflow'); + } + + w *= baseMinusT; + + } + + out = output.length + 1; + bias = adapt(i - oldi, out, oldi == 0); + + // `i` was supposed to wrap around from `out` to `0`, + // incrementing `n` each time, so we'll fix that now: + if (floor(i / out) > maxInt - n) { + error('overflow'); + } + + n += floor(i / out); + i %= out; + + // Insert `n` at position `i` of the output + output.splice(i++, 0, n); + + } + + return ucs2encode(output); + } + + /** + * Converts a string of Unicode symbols (e.g. a domain name label) to a + * Punycode string of ASCII-only symbols. + * @memberOf punycode + * @param {String} input The string of Unicode symbols. + * @returns {String} The resulting Punycode string of ASCII-only symbols. + */ + function encode(input) { + var n, + delta, + handledCPCount, + basicLength, + bias, + j, + m, + q, + k, + t, + currentValue, + output = [], + /** `inputLength` will hold the number of code points in `input`. */ + inputLength, + /** Cached calculation results */ + handledCPCountPlusOne, + baseMinusT, + qMinusT; + + // Convert the input in UCS-2 to Unicode + input = ucs2decode(input); + + // Cache the length + inputLength = input.length; + + // Initialize the state + n = initialN; + delta = 0; + bias = initialBias; + + // Handle the basic code points + for (j = 0; j < inputLength; ++j) { + currentValue = input[j]; + if (currentValue < 0x80) { + output.push(stringFromCharCode(currentValue)); + } + } + + handledCPCount = basicLength = output.length; + + // `handledCPCount` is the number of code points that have been handled; + // `basicLength` is the number of basic code points. + + // Finish the basic string - if it is not empty - with a delimiter + if (basicLength) { + output.push(delimiter); + } + + // Main encoding loop: + while (handledCPCount < inputLength) { + + // All non-basic code points < n have been handled already. Find the next + // larger one: + for (m = maxInt, j = 0; j < inputLength; ++j) { + currentValue = input[j]; + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + + // Increase `delta` enough to advance the decoder's state to , + // but guard against overflow + handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + error('overflow'); + } + + delta += (m - n) * handledCPCountPlusOne; + n = m; + + for (j = 0; j < inputLength; ++j) { + currentValue = input[j]; + + if (currentValue < n && ++delta > maxInt) { + error('overflow'); + } + + if (currentValue == n) { + // Represent delta as a generalized variable-length integer + for (q = delta, k = base; /* no condition */; k += base) { + t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); + if (q < t) { + break; + } + qMinusT = q - t; + baseMinusT = base - t; + output.push( + stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) + ); + q = floor(qMinusT / baseMinusT); + } + + output.push(stringFromCharCode(digitToBasic(q, 0))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); + delta = 0; + ++handledCPCount; + } + } + + ++delta; + ++n; + + } + return output.join(''); + } + + /** + * Converts a Punycode string representing a domain name or an email address + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. + * it doesn't matter if you call it on a string that has already been + * converted to Unicode. + * @memberOf punycode + * @param {String} input The Punycoded domain name or email address to + * convert to Unicode. + * @returns {String} The Unicode representation of the given Punycode + * string. + */ + function toUnicode(input) { + return mapDomain(input, function(string) { + return regexPunycode.test(string) + ? decode(string.slice(4).toLowerCase()) + : string; + }); + } + + /** + * Converts a Unicode string representing a domain name or an email address to + * Punycode. Only the non-ASCII parts of the domain name will be converted, + * i.e. it doesn't matter if you call it with a domain that's already in + * ASCII. + * @memberOf punycode + * @param {String} input The domain name or email address to convert, as a + * Unicode string. + * @returns {String} The Punycode representation of the given domain name or + * email address. + */ + function toASCII(input) { + return mapDomain(input, function(string) { + return regexNonASCII.test(string) + ? 'xn--' + encode(string) + : string; + }); + } + + /*--------------------------------------------------------------------------*/ + + /** Define the public API */ + punycode = { + /** + * A string representing the current Punycode.js version number. + * @memberOf punycode + * @type String + */ + 'version': '1.3.2', + /** + * An object of methods to convert from JavaScript's internal character + * representation (UCS-2) to Unicode code points, and back. + * @see + * @memberOf punycode + * @type Object + */ + 'ucs2': { + 'decode': ucs2decode, + 'encode': ucs2encode + }, + 'decode': decode, + 'encode': encode, + 'toASCII': toASCII, + 'toUnicode': toUnicode + }; + + /** Expose `punycode` */ + // Some AMD build optimizers, like r.js, check for specific condition patterns + // like the following: + if ( + typeof define == 'function' && + typeof define.amd == 'object' && + define.amd + ) { + define('punycode', function() { + return punycode; + }); + } else if (freeExports && freeModule) { + if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+ + freeModule.exports = punycode; + } else { // in Narwhal or RingoJS v0.7.0- + for (key in punycode) { + punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); + } + } + } else { // in Rhino or a web browser + root.punycode = punycode; + } + +}(this)); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],4:[function(require,module,exports){ +var log = require('./log'); +var Promise = require('./promise'); - /** - * The `punycode` object. - * @name punycode - * @type Object - */ - var punycode, - - /** Highest positive signed 32-bit float value */ - maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 - - /** Bootstring parameters */ - base = 36, - tMin = 1, - tMax = 26, - skew = 38, - damp = 700, - initialBias = 72, - initialN = 128, // 0x80 - delimiter = '-', // '\x2D' - - /** Regular expressions */ - regexPunycode = /^xn--/, - regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars - regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators - - /** Error messages */ - errors = { - 'overflow': 'Overflow: input needs wider integers to process', - 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', - 'invalid-input': 'Invalid input' - }, - - /** Convenience shortcuts */ - baseMinusTMin = base - tMin, - floor = Math.floor, - stringFromCharCode = String.fromCharCode, - - /** Temporary variable */ - key; - - /*--------------------------------------------------------------------------*/ - - /** - * A generic error utility function. - * @private - * @param {String} type The error type. - * @returns {Error} Throws a `RangeError` with the applicable error message. - */ - function error(type) { - throw RangeError(errors[type]); - } +function restoreOwnerScroll(ownerDocument, x, y) { + if (ownerDocument.defaultView && (x !== ownerDocument.defaultView.pageXOffset || y !== ownerDocument.defaultView.pageYOffset)) { + ownerDocument.defaultView.scrollTo(x, y); + } +} + +function cloneCanvasContents(canvas, clonedCanvas) { + try { + if (clonedCanvas) { + clonedCanvas.width = canvas.width; + clonedCanvas.height = canvas.height; + clonedCanvas.getContext("2d").putImageData(canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height), 0, 0); + } + } catch(e) { + log("Unable to copy canvas content from", canvas, e); + } +} - /** - * A generic `Array#map` utility function. - * @private - * @param {Array} array The array to iterate over. - * @param {Function} callback The function that gets called for every array - * item. - * @returns {Array} A new array of values returned by the callback function. - */ - function map(array, fn) { - var length = array.length; - while (length--) { - array[length] = fn(array[length]); - } - return array; - } +function cloneNode(node, javascriptEnabled) { + var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false); - /** - * A simple `Array#map`-like wrapper to work with domain name strings. - * @private - * @param {String} domain The domain name. - * @param {Function} callback The function that gets called for every - * character. - * @returns {Array} A new string of characters returned by the callback - * function. - */ - function mapDomain(string, fn) { - return map(string.split(regexSeparators), fn).join('.'); - } - - /** - * Creates an array containing the numeric code points of each Unicode - * character in the string. While JavaScript uses UCS-2 internally, - * this function will convert a pair of surrogate halves (each of which - * UCS-2 exposes as separate characters) into a single code point, - * matching UTF-16. - * @see `punycode.ucs2.encode` - * @see - * @memberOf punycode.ucs2 - * @name decode - * @param {String} string The Unicode input string (UCS-2). - * @returns {Array} The new array of code points. - */ - function ucs2decode(string) { - var output = [], - counter = 0, - length = string.length, - value, - extra; - while (counter < length) { - value = string.charCodeAt(counter++); - if (value >= 0xD800 && value <= 0xDBFF && counter < length) { - // high surrogate, and there is a next character - extra = string.charCodeAt(counter++); - if ((extra & 0xFC00) == 0xDC00) { // low surrogate - output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); - } else { - // unmatched surrogate; only append this code unit, in case the next - // code unit is the high surrogate of a surrogate pair - output.push(value); - counter--; - } - } else { - output.push(value); - } - } - return output; - } - - /** - * Creates a string based on an array of numeric code points. - * @see `punycode.ucs2.decode` - * @memberOf punycode.ucs2 - * @name encode - * @param {Array} codePoints The array of numeric code points. - * @returns {String} The new Unicode string (UCS-2). - */ - function ucs2encode(array) { - return map(array, function(value) { - var output = ''; - if (value > 0xFFFF) { - value -= 0x10000; - output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); - value = 0xDC00 | value & 0x3FF; - } - output += stringFromCharCode(value); - return output; - }).join(''); - } - - /** - * Converts a basic code point into a digit/integer. - * @see `digitToBasic()` - * @private - * @param {Number} codePoint The basic numeric code point value. - * @returns {Number} The numeric value of a basic code point (for use in - * representing integers) in the range `0` to `base - 1`, or `base` if - * the code point does not represent a value. - */ - function basicToDigit(codePoint) { - if (codePoint - 48 < 10) { - return codePoint - 22; - } - if (codePoint - 65 < 26) { - return codePoint - 65; - } - if (codePoint - 97 < 26) { - return codePoint - 97; - } - return base; - } - - /** - * Converts a digit/integer into a basic code point. - * @see `basicToDigit()` - * @private - * @param {Number} digit The numeric value of a basic code point. - * @returns {Number} The basic code point whose value (when used for - * representing integers) is `digit`, which needs to be in the range - * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is - * used; else, the lowercase form is used. The behavior is undefined - * if `flag` is non-zero and `digit` has no uppercase form. - */ - function digitToBasic(digit, flag) { - // 0..25 map to ASCII a..z or A..Z - // 26..35 map to ASCII 0..9 - return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); - } - - /** - * Bias adaptation function as per section 3.4 of RFC 3492. - * http://tools.ietf.org/html/rfc3492#section-3.4 - * @private - */ - function adapt(delta, numPoints, firstTime) { - var k = 0; - delta = firstTime ? floor(delta / damp) : delta >> 1; - delta += floor(delta / numPoints); - for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { - delta = floor(delta / baseMinusTMin); - } - return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); - } - - /** - * Converts a Punycode string of ASCII-only symbols to a string of Unicode - * symbols. - * @memberOf punycode - * @param {String} input The Punycode string of ASCII-only symbols. - * @returns {String} The resulting string of Unicode symbols. - */ - function decode(input) { - // Don't use UCS-2 - var output = [], - inputLength = input.length, - out, - i = 0, - n = initialN, - bias = initialBias, - basic, - j, - index, - oldi, - w, - k, - digit, - t, - /** Cached calculation results */ - baseMinusT; - - // Handle the basic code points: let `basic` be the number of input code - // points before the last delimiter, or `0` if there is none, then copy - // the first basic code points to the output. - - basic = input.lastIndexOf(delimiter); - if (basic < 0) { - basic = 0; - } - - for (j = 0; j < basic; ++j) { - // if it's not a basic code point - if (input.charCodeAt(j) >= 0x80) { - error('not-basic'); - } - output.push(input.charCodeAt(j)); - } - - // Main decoding loop: start just after the last delimiter if any basic code - // points were copied; start at the beginning otherwise. - - for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { - - // `index` is the index of the next character to be consumed. - // Decode a generalized variable-length integer into `delta`, - // which gets added to `i`. The overflow checking is easier - // if we increase `i` as we go, then subtract off its starting - // value at the end to obtain `delta`. - for (oldi = i, w = 1, k = base; /* no condition */; k += base) { - - if (index >= inputLength) { - error('invalid-input'); - } - - digit = basicToDigit(input.charCodeAt(index++)); - - if (digit >= base || digit > floor((maxInt - i) / w)) { - error('overflow'); - } - - i += digit * w; - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); - - if (digit < t) { - break; - } - - baseMinusT = base - t; - if (w > floor(maxInt / baseMinusT)) { - error('overflow'); - } - - w *= baseMinusT; - - } - - out = output.length + 1; - bias = adapt(i - oldi, out, oldi == 0); - - // `i` was supposed to wrap around from `out` to `0`, - // incrementing `n` each time, so we'll fix that now: - if (floor(i / out) > maxInt - n) { - error('overflow'); - } - - n += floor(i / out); - i %= out; - - // Insert `n` at position `i` of the output - output.splice(i++, 0, n); - - } - - return ucs2encode(output); - } - - /** - * Converts a string of Unicode symbols to a Punycode string of ASCII-only - * symbols. - * @memberOf punycode - * @param {String} input The string of Unicode symbols. - * @returns {String} The resulting Punycode string of ASCII-only symbols. - */ - function encode(input) { - var n, - delta, - handledCPCount, - basicLength, - bias, - j, - m, - q, - k, - t, - currentValue, - output = [], - /** `inputLength` will hold the number of code points in `input`. */ - inputLength, - /** Cached calculation results */ - handledCPCountPlusOne, - baseMinusT, - qMinusT; - - // Convert the input in UCS-2 to Unicode - input = ucs2decode(input); - - // Cache the length - inputLength = input.length; - - // Initialize the state - n = initialN; - delta = 0; - bias = initialBias; - - // Handle the basic code points - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue < 0x80) { - output.push(stringFromCharCode(currentValue)); - } - } - - handledCPCount = basicLength = output.length; - - // `handledCPCount` is the number of code points that have been handled; - // `basicLength` is the number of basic code points. - - // Finish the basic string - if it is not empty - with a delimiter - if (basicLength) { - output.push(delimiter); - } - - // Main encoding loop: - while (handledCPCount < inputLength) { - - // All non-basic code points < n have been handled already. Find the next - // larger one: - for (m = maxInt, j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue >= n && currentValue < m) { - m = currentValue; - } - } - - // Increase `delta` enough to advance the decoder's state to , - // but guard against overflow - handledCPCountPlusOne = handledCPCount + 1; - if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { - error('overflow'); - } - - delta += (m - n) * handledCPCountPlusOne; - n = m; - - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - - if (currentValue < n && ++delta > maxInt) { - error('overflow'); - } - - if (currentValue == n) { - // Represent delta as a generalized variable-length integer - for (q = delta, k = base; /* no condition */; k += base) { - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); - if (q < t) { - break; - } - qMinusT = q - t; - baseMinusT = base - t; - output.push( - stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) - ); - q = floor(qMinusT / baseMinusT); - } - - output.push(stringFromCharCode(digitToBasic(q, 0))); - bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); - delta = 0; - ++handledCPCount; - } - } - - ++delta; - ++n; - - } - return output.join(''); - } - - /** - * Converts a Punycode string representing a domain name to Unicode. Only the - * Punycoded parts of the domain name will be converted, i.e. it doesn't - * matter if you call it on a string that has already been converted to - * Unicode. - * @memberOf punycode - * @param {String} domain The Punycode domain name to convert to Unicode. - * @returns {String} The Unicode representation of the given Punycode - * string. - */ - function toUnicode(domain) { - return mapDomain(domain, function(string) { - return regexPunycode.test(string) - ? decode(string.slice(4).toLowerCase()) - : string; - }); - } - - /** - * Converts a Unicode string representing a domain name to Punycode. Only the - * non-ASCII parts of the domain name will be converted, i.e. it doesn't - * matter if you call it with a domain that's already in ASCII. - * @memberOf punycode - * @param {String} domain The domain name to convert, as a Unicode string. - * @returns {String} The Punycode representation of the given domain name. - */ - function toASCII(domain) { - return mapDomain(domain, function(string) { - return regexNonASCII.test(string) - ? 'xn--' + encode(string) - : string; - }); - } - - /*--------------------------------------------------------------------------*/ - - /** Define the public API */ - punycode = { - /** - * A string representing the current Punycode.js version number. - * @memberOf punycode - * @type String - */ - 'version': '1.2.4', - /** - * An object of methods to convert from JavaScript's internal character - * representation (UCS-2) to Unicode code points, and back. - * @see - * @memberOf punycode - * @type Object - */ - 'ucs2': { - 'decode': ucs2decode, - 'encode': ucs2encode - }, - 'decode': decode, - 'encode': encode, - 'toASCII': toASCII, - 'toUnicode': toUnicode - }; - - /** Expose `punycode` */ - // Some AMD build optimizers, like r.js, check for specific condition patterns - // like the following: - if ( - typeof define == 'function' && - typeof define.amd == 'object' && - define.amd - ) { - define('punycode', function() { - return punycode; - }); - } else if (freeExports && !freeExports.nodeType) { - if (freeModule) { // in Node.js or RingoJS v0.8.0+ - freeModule.exports = punycode; - } else { // in Narwhal or RingoJS v0.7.0- - for (key in punycode) { - punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); - } - } - } else { // in Rhino or a web browser - root.punycode = punycode; - } - - }(this)); - - }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],4:[function(require,module,exports){ - var log = require('./log'); - var Promise = require('./promise'); - - var html2canvasCanvasCloneAttribute = "data-html2canvas-canvas-clone"; - var html2canvasCanvasCloneIndex = 0; - - function cloneNodeValues(document, clone, nodeName) { - var originalNodes = document.getElementsByTagName(nodeName); - var clonedNodes = clone.getElementsByTagName(nodeName); - var count = originalNodes.length; - for (var i = 0; i < count; i++) { - clonedNodes[i].value = originalNodes[i].value; + var child = node.firstChild; + while(child) { + if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') { + clone.appendChild(cloneNode(child, javascriptEnabled)); } + child = child.nextSibling; } - function restoreOwnerScroll(ownerDocument, x, y) { - if (ownerDocument.defaultView && (x !== ownerDocument.defaultView.pageXOffset || y !== ownerDocument.defaultView.pageYOffset)) { - ownerDocument.defaultView.scrollTo(x, y); + if (node.nodeType === 1 && node.tagName !== 'BODY') { + clone._scrollTop = node.scrollTop; + clone._scrollLeft = node.scrollLeft; + if (node.nodeName === "CANVAS") { + cloneCanvasContents(node, clone); + } else if (node.nodeName === "TEXTAREA" || node.nodeName === "SELECT") { + clone.value = node.value; } } - function labelCanvasElements(ownerDocument) { - [].slice.call(ownerDocument.querySelectorAll("canvas"), 0).forEach(function(canvas) { - canvas.setAttribute(html2canvasCanvasCloneAttribute, "canvas-" + html2canvasCanvasCloneIndex++); - }); - } - - function cloneCanvasContents(ownerDocument, documentClone) { - [].slice.call(ownerDocument.querySelectorAll("[" + html2canvasCanvasCloneAttribute + "]"), 0).forEach(function(canvas) { - try { - var clonedCanvas = documentClone.querySelector('[' + html2canvasCanvasCloneAttribute + '="' + canvas.getAttribute(html2canvasCanvasCloneAttribute) + '"]'); - if (clonedCanvas) { - clonedCanvas.width = canvas.width; - clonedCanvas.height = canvas.height; - clonedCanvas.getContext("2d").putImageData(canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height), 0, 0); - } - } catch(e) { - log("Unable to copy canvas content from", canvas, e); - } - canvas.removeAttribute(html2canvasCanvasCloneAttribute); - }); - } - - function removeScriptNodes(parent) { - [].slice.call(parent.childNodes, 0).filter(isElementNode).forEach(function(node) { - if (node.tagName === "SCRIPT") { - parent.removeChild(node); - } else { - removeScriptNodes(node); - } - }); - return parent; - } - - function isIE9() { - return document.documentMode && document.documentMode <= 9; - } + return clone; +} -// https://github.com/niklasvh/html2canvas/issues/503 - function cloneNodeIE9(node, javascriptEnabled) { - var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false); +function initNode(node) { + if (node.nodeType === 1) { + node.scrollTop = node._scrollTop; + node.scrollLeft = node._scrollLeft; var child = node.firstChild; while(child) { - if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') { - clone.appendChild(cloneNodeIE9(child, javascriptEnabled)); - } + initNode(child); child = child.nextSibling; } - - return clone; } - - - - function isElementNode(node) { - return node.nodeType === Node.ELEMENT_NODE; - } - - module.exports = function(ownerDocument, containerDocument, width, height, options, x ,y) { - labelCanvasElements(ownerDocument); - var documentElement = isIE9() ? cloneNodeIE9(ownerDocument.documentElement, options.javascriptEnabled) : ownerDocument.documentElement.cloneNode(true); - var container = containerDocument.createElement("iframe"); - - container.className = "html2canvas-container"; - container.style.visibility = "hidden"; - container.style.position = "fixed"; - container.style.left = "-10000px"; - container.style.top = "0px"; - container.style.border = "0"; - container.width = width; - container.height = height; - container.scrolling = "no"; // ios won't scroll without it - containerDocument.body.appendChild(container); - - return new Promise(function(resolve) { - var documentClone = container.contentWindow.document; - - cloneNodeValues(ownerDocument.documentElement, documentElement, "textarea"); - cloneNodeValues(ownerDocument.documentElement, documentElement, "select"); - - /* Chrome doesn't detect relative background-images assigned in inline